wallet: more failsafes for sending.

This commit is contained in:
Christopher Jeffrey 2017-01-29 17:21:16 -08:00
parent 3d0254054c
commit 80d47b8db4
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 19 additions and 1 deletions

View File

@ -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}

View File

@ -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);
}