diff --git a/lib/bcoin/mtx.js b/lib/bcoin/mtx.js index dec96216..1346f37c 100644 --- a/lib/bcoin/mtx.js +++ b/lib/bcoin/mtx.js @@ -803,13 +803,8 @@ MTX.prototype.maxSize = function maxSize(maxM, maxN) { }; MTX.prototype.selectCoins = function selectCoins(coins, options) { - var tx = this.clone(); - var outputValue = tx.getOutputValue(); - var chosen = []; - var lastAdded = 0; - var tryFree, minValue, i, size, change, fee; - - assert(tx.inputs.length === 0); + var chosen, lastAdded, tx, outputValue; + var i, size, change, fee, tryFree, minValue; if (!options || typeof options !== 'object') { options = { @@ -818,6 +813,13 @@ MTX.prototype.selectCoins = function selectCoins(coins, options) { }; } + tx = this.clone(); + tx.inputs.length = 0; + + chosen = []; + lastAdded = 0; + + outputValue = tx.getOutputValue(); tryFree = options.free; if (!options.selection || options.selection === 'age') { @@ -957,6 +959,7 @@ MTX.prototype.fill = function fill(coins, options) { var result, err; assert(this.ts === 0, 'Cannot modify a confirmed tx.'); + assert(this.inputs.length === 0, 'TX is already filled.'); if (!options || typeof options !== 'object') { options = {