diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 3b4ab64f6..c0f14c11a 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -1133,18 +1133,6 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent) .setUnspent(unspent) .setOutputs(outs); - var selectedUtxos = b.getSelectedUnspent(); - var inputChainPaths = selectedUtxos.map(function(utxo) { - return pkr.pathForAddress(utxo.address); - }); - - b = b.setHashToScriptMap(pkr.getRedeemScriptMap(inputChainPaths)); - - if (priv) { - var keys = priv.getForPaths(inputChainPaths); - var signed = b.sign(keys); - } - merchantData.total = bignum(merchantData.total, 10); merchantData.pr.pd.outputs.forEach(function(output, i) { @@ -1178,6 +1166,18 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent) merchantData.total = merchantData.total.toString(10); + var selectedUtxos = b.getSelectedUnspent(); + var inputChainPaths = selectedUtxos.map(function(utxo) { + return pkr.pathForAddress(utxo.address); + }); + + b = b.setHashToScriptMap(pkr.getRedeemScriptMap(inputChainPaths)); + + if (priv) { + var keys = priv.getForPaths(inputChainPaths); + var signed = b.sign(keys); + } + if (options.fetch) return; this.log(''); diff --git a/test/test.PayPro.js b/test/test.PayPro.js index f8149e990..b78a484eb 100644 --- a/test/test.PayPro.js +++ b/test/test.PayPro.js @@ -246,18 +246,6 @@ describe('PayPro (in Wallet) model', function() { .setUnspent(unspentTest) .setOutputs(outs); - var selectedUtxos = b.getSelectedUnspent(); - var inputChainPaths = selectedUtxos.map(function(utxo) { - return pkr.pathForAddress(utxo.address); - }); - - b = b.setHashToScriptMap(pkr.getRedeemScriptMap(inputChainPaths)); - - if (priv) { - var keys = priv.getForPaths(inputChainPaths); - var signed = b.sign(keys); - } - outputs.forEach(function(output, i) { var amount = output.get('amount'); var script = { @@ -282,6 +270,18 @@ describe('PayPro (in Wallet) model', function() { b.tx.outs[i].s = s; }); + var selectedUtxos = b.getSelectedUnspent(); + var inputChainPaths = selectedUtxos.map(function(utxo) { + return pkr.pathForAddress(utxo.address); + }); + + b = b.setHashToScriptMap(pkr.getRedeemScriptMap(inputChainPaths)); + + if (priv) { + var keys = priv.getForPaths(inputChainPaths); + var signed = b.sign(keys); + } + var tx = b.build(); var refund_outputs = []; @@ -472,18 +472,6 @@ describe('PayPro (in Wallet) model', function() { .setUnspent(unspentTest) .setOutputs(outs); - var selectedUtxos = b.getSelectedUnspent(); - var inputChainPaths = selectedUtxos.map(function(utxo) { - return pkr.pathForAddress(utxo.address); - }); - - b = b.setHashToScriptMap(pkr.getRedeemScriptMap(inputChainPaths)); - - if (priv) { - var keys = priv.getForPaths(inputChainPaths); - var signed = b.sign(keys); - } - outputs.forEach(function(output, i) { var amount = output.get('amount'); var script = { @@ -508,6 +496,18 @@ describe('PayPro (in Wallet) model', function() { b.tx.outs[i].s = s; }); + var selectedUtxos = b.getSelectedUnspent(); + var inputChainPaths = selectedUtxos.map(function(utxo) { + return pkr.pathForAddress(utxo.address); + }); + + b = b.setHashToScriptMap(pkr.getRedeemScriptMap(inputChainPaths)); + + if (priv) { + var keys = priv.getForPaths(inputChainPaths); + var signed = b.sign(keys); + } + var tx = b.build(); var refund_outputs = [];