From dd9fb535fa50b33929747a45dc2546073857258c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 2 Jun 2016 11:38:29 -0700 Subject: [PATCH] fill coins before signing. --- lib/bcoin/wallet.js | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index 9355f7be..41bcdfba 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -703,30 +703,40 @@ Wallet.prototype.getInputPaths = function getInputPaths(tx, callback) { var paths = []; var hashes; + function done() { + utils.forEachSerial(hashes, function(hash, next, i) { + self.getPath(hash, function(err, path) { + if (err) + return next(err); + + if (path) + paths.push(path); + + return next(); + }); + }, function(err) { + if (err) + return callback(err); + return callback(null, paths); + }); + } + if (tx instanceof bcoin.input) { if (!tx.coin) return callback(new Error('Not all coins available.')); hashes = [tx.coin.getHash()]; - } else { - if (!tx.hasCoins()) - return callback(new Error('Not all coins available.')); - hashes = tx.getInputHashes(); + return done(); } - utils.forEachSerial(hashes, function(hash, next, i) { - self.getPath(hash, function(err, path) { - if (err) - return next(err); - - if (path) - paths.push(path); - - return next(); - }); - }, function(err) { + this.fillCoins(tx, function(err) { if (err) return callback(err); - return callback(null, paths); + + if (!tx.hasCoins()) + return callback(new Error('Not all coins available.')); + + hashes = tx.getInputHashes(); + done(); }); }; @@ -1013,7 +1023,7 @@ Wallet.prototype.sign = function sign(tx, options, callback) { */ Wallet.prototype.fillCoins = function fillCoins(tx, callback) { - return this.db.fillHistory(tx, callback); + return this.db.fillCoins(tx, callback); }; /**