wallet: more failsafes for sending.
This commit is contained in:
parent
3d0254054c
commit
80d47b8db4
@ -141,6 +141,15 @@ Address.prototype.verifyNetwork = function verifyNetwork(network) {
|
|||||||
return this.getPrefix() === this.getPrefix(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.
|
* Get the address type as a string.
|
||||||
* @returns {AddressPrefix}
|
* @returns {AddressPrefix}
|
||||||
|
|||||||
@ -1553,7 +1553,7 @@ Wallet.prototype.estimateSize = co(function* estimateSize(prev) {
|
|||||||
Wallet.prototype.createTX = co(function* createTX(options, force) {
|
Wallet.prototype.createTX = co(function* createTX(options, force) {
|
||||||
var outputs = options.outputs;
|
var outputs = options.outputs;
|
||||||
var mtx = new MTX();
|
var mtx = new MTX();
|
||||||
var i, output, total;
|
var i, output, addr, total;
|
||||||
|
|
||||||
assert(Array.isArray(outputs), 'Outputs must be an array.');
|
assert(Array.isArray(outputs), 'Outputs must be an array.');
|
||||||
assert(outputs.length > 0, 'No outputs available.');
|
assert(outputs.length > 0, 'No outputs available.');
|
||||||
@ -1561,10 +1561,19 @@ Wallet.prototype.createTX = co(function* createTX(options, force) {
|
|||||||
// Add the outputs
|
// Add the outputs
|
||||||
for (i = 0; i < outputs.length; i++) {
|
for (i = 0; i < outputs.length; i++) {
|
||||||
output = new Output(outputs[i]);
|
output = new Output(outputs[i]);
|
||||||
|
addr = output.getAddress();
|
||||||
|
|
||||||
if (output.isDust())
|
if (output.isDust())
|
||||||
throw new Error('Output is dust.');
|
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);
|
mtx.outputs.push(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user