From 80d47b8db401a5cb4db16ac2dc8f72be4228eed6 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 29 Jan 2017 17:21:16 -0800 Subject: [PATCH] wallet: more failsafes for sending. --- lib/primitives/address.js | 9 +++++++++ lib/wallet/wallet.js | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/primitives/address.js b/lib/primitives/address.js index 9aa476f0..520ac8cf 100644 --- a/lib/primitives/address.js +++ b/lib/primitives/address.js @@ -141,6 +141,15 @@ Address.prototype.verifyNetwork = function verifyNetwork(network) { return this.getPrefix() === this.getPrefix(network); }; +/** + * Test whether the address is null. + * @returns {Boolean} + */ + +Address.prototype.isNull = function isNull() { + return util.equal(this.hash, encoding.ZERO_HASH160); +}; + /** * Get the address type as a string. * @returns {AddressPrefix} diff --git a/lib/wallet/wallet.js b/lib/wallet/wallet.js index 05738a87..2b3dc20b 100644 --- a/lib/wallet/wallet.js +++ b/lib/wallet/wallet.js @@ -1553,7 +1553,7 @@ Wallet.prototype.estimateSize = co(function* estimateSize(prev) { Wallet.prototype.createTX = co(function* createTX(options, force) { var outputs = options.outputs; var mtx = new MTX(); - var i, output, total; + var i, output, addr, total; assert(Array.isArray(outputs), 'Outputs must be an array.'); assert(outputs.length > 0, 'No outputs available.'); @@ -1561,10 +1561,19 @@ Wallet.prototype.createTX = co(function* createTX(options, force) { // Add the outputs for (i = 0; i < outputs.length; i++) { output = new Output(outputs[i]); + addr = output.getAddress(); if (output.isDust()) throw new Error('Output is dust.'); + if (output.value > 0) { + if (!addr) + throw new Error('Cannot send to unknown address.'); + + if (addr.isNull()) + throw new Error('Cannot send to null address.'); + } + mtx.outputs.push(output); }