lib: update bn.js and elliptic

This commit is contained in:
Fedor Indutny 2014-05-09 03:53:57 +04:00
parent 048bca0b8a
commit 26516085f2
5 changed files with 16 additions and 5 deletions

View File

@ -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)

View File

@ -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];

View File

@ -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;
}

View File

@ -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": {

View File

@ -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);