diff --git a/lib/bcoin/tx-pool.js b/lib/bcoin/tx-pool.js index aa5a4e88..65499d29 100644 --- a/lib/bcoin/tx-pool.js +++ b/lib/bcoin/tx-pool.js @@ -74,7 +74,7 @@ TXPool.prototype.add = function add(tx, noWrite) { continue; // Add orphan, if no parent transaction is yet known - this._orphans[key] = { tx: tx, index: i }; + this._orphans[key] = { tx: tx, index: input.out.index }; } if (!own) diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index f4a3dca8..2e1808ae 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -17,6 +17,7 @@ function TX(data, block) { this.outputs = []; this.lock = data.lock || 0; this.ts = data.ts || 0; + this.funds = new bn(0); this._hash = null; this._raw = data._raw || null; @@ -77,6 +78,9 @@ TX.prototype.input = function input(i, index) { seq: i.seq === undefined ? 0xffffffff : i.seq }; + if (input.out.tx) + this.funds.iadd(input.out.tx.outputs[input.out.index].value); + // Try modifying existing input first for (var i = 0; i < this.inputs.length; i++) { var ex = this.inputs[i]; diff --git a/lib/bcoin/utils.js b/lib/bcoin/utils.js index 9e1336fb..99f440d9 100644 --- a/lib/bcoin/utils.js +++ b/lib/bcoin/utils.js @@ -60,7 +60,7 @@ utils.toBase58 = function toBase58(arr) { var r = n.mod(mod); n = n.div(mod); - var end = n.cmp(0) === 0; + var end = n.cmpn(0) === 0; assert.equal(r.length, 1); r = r.words[0]; @@ -106,7 +106,7 @@ utils.fromBase58 = function fromBase58(str) { w *= 58; w += c; if (i === str.length - 1 || q === 0xacad10) { - res = res.mul(q).add(w); + res = res.mul(new bn(q)).add(new bn(w)); q = 1; w = 0; } diff --git a/package.json b/package.json index a2b91137..f6b4d258 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "homepage": "https://github.com/indutny/bcoin", "dependencies": { "async": "^0.8.0", - "bn.js": "^0.3.0", - "elliptic": "^0.9.0", + "bn.js": "^0.4.0", + "elliptic": "^0.10.0", "hash.js": "^0.2.0" }, "devDependencies": { diff --git a/test/wallet-test.js b/test/wallet-test.js index 72992549..eafea0be 100644 --- a/test/wallet-test.js +++ b/test/wallet-test.js @@ -85,6 +85,13 @@ describe('Wallet', function() { var t4 = bcoin.tx().input(t2.hash(), 1) .input(t3.hash(), 0) .out(w, 22000); + + // Just for debugging + t1.hint = 't1'; + t2.hint = 't2'; + t3.hint = 't3'; + t4.hint = 't4'; + w.addTX(t4); assert.equal(w.balance().toString(10), '22000'); w.addTX(t1);