From 9049053a1e456799c3d7c2d91096528df38886ef Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 19 Oct 2016 15:33:43 -0700 Subject: [PATCH] http: send details after send. --- lib/http/server.js | 3 ++- lib/wallet/txdb.js | 7 +++++-- test/http-test.js | 17 +++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/http/server.js b/lib/http/server.js index 890695c9..3c565251 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -839,7 +839,8 @@ HTTPServer.prototype._init = function _init() { var options = req.options; var passphrase = options.passphrase; var tx = yield req.wallet.send(options, passphrase); - send(200, tx.toJSON()); + var details = yield req.wallet.toDetails(tx); + send(200, details.toJSON()); })); // Create TX diff --git a/lib/wallet/txdb.js b/lib/wallet/txdb.js index 54615bea..770be7c6 100644 --- a/lib/wallet/txdb.js +++ b/lib/wallet/txdb.js @@ -2168,10 +2168,11 @@ TXDB.prototype.getAccountCredits = co(function* getAccountCredits(account, all) */ TXDB.prototype.fillHistory = co(function* fillHistory(tx) { + var coins = []; var i, input, credits, credit; if (tx.isCoinbase()) - return tx; + return coins; credits = yield this.getSpentCredits(tx); @@ -2183,9 +2184,11 @@ TXDB.prototype.fillHistory = co(function* fillHistory(tx) { continue; input.coin = credit.coin; + + coins.push(credit.coin); } - return tx; + return coins; }); /** diff --git a/test/http-test.js b/test/http-test.js index b115f878..1f9ae805 100644 --- a/test/http-test.js +++ b/test/http-test.js @@ -110,7 +110,6 @@ describe('HTTP', function() { assert(balance); assert.equal(utils.satoshi(balance.confirmed), 0); assert.equal(utils.satoshi(balance.unconfirmed), 201840); - assert.equal(utils.satoshi(balance.total), 201840); assert(details); assert.equal(details.hash, t1.rhash); })); @@ -119,11 +118,13 @@ describe('HTTP', function() { var balance = yield wallet.getBalance(); assert.equal(utils.satoshi(balance.confirmed), 0); assert.equal(utils.satoshi(balance.unconfirmed), 201840); - assert.equal(utils.satoshi(balance.total), 201840); })); it('should send a tx', cob(function* () { - var options = { + var value = 0; + var options, tx; + + options = { rate: 10000, outputs: [{ value: 10000, @@ -131,12 +132,16 @@ describe('HTTP', function() { }] }; - var tx = yield wallet.send(options); + tx = yield wallet.send(options); assert(tx); assert.equal(tx.inputs.length, 1); assert.equal(tx.outputs.length, 2); - assert.equal(utils.satoshi(tx.outputs[0].value) + utils.satoshi(tx.outputs[1].value), 48190); + + value += utils.satoshi(tx.outputs[0].value); + value += utils.satoshi(tx.outputs[1].value); + assert.equal(value, 48190); + hash = tx.hash; })); @@ -155,7 +160,7 @@ describe('HTTP', function() { it('should get balance', cob(function* () { var balance = yield wallet.getBalance(); - assert.equal(utils.satoshi(balance.total), 199570); + assert.equal(utils.satoshi(balance.unconfirmed), 199570); })); it('should execute an rpc call', cob(function* () {