diff --git a/js/models/PrivateKey.js b/js/models/PrivateKey.js index db727c3ed..c1ea17561 100644 --- a/js/models/PrivateKey.js +++ b/js/models/PrivateKey.js @@ -13,7 +13,6 @@ function PrivateKey(opts) { this.network = opts.networkName === 'testnet' ? networks.testnet : networks.livenet; var init = opts.extendedPrivateKeyString || this.network.name; -console.log('[PrivateKey.js.15:init:]',init); //TODO this.BIP32 = opts.BIP32 || new BIP32(init); this._calcId(); }; diff --git a/js/models/TxProposals.js b/js/models/TxProposals.js index 326af3664..5140fbb46 100644 --- a/js/models/TxProposals.js +++ b/js/models/TxProposals.js @@ -14,9 +14,9 @@ var Storage = imports.Storage || require('./Storage'); var storage = Storage.default(); function TxProposal(opts) { - this.tx = opts.tx; this.seenBy = opts.seenBy || {}; this.signedBy = opts.signedBy || {}; + this.builder = opts.builder; }; module.exports = require('soop')(TxProposal); @@ -36,12 +36,10 @@ TxProposals.fromObj = function(o) { walletId: o.walletId, }); o.txps.forEach(function(t) { - var tx = new Transaction; - tx.parse(new Buffer(t.txHex,'hex')); ret.txps.push({ seenBy: t.seenBy, signedBy: t.signedBy, - tx: tx, + builder: new Builder.fromObj(t.builderObj), }); }); return ret; @@ -54,7 +52,7 @@ TxProposals.prototype.toObj = function() { ret.push({ seenBy: t.seenBy, signedBy: t.signedBy, - txHex: t.tx.serialize(), + builderObj: t.builder.toObj(), }); }); return { @@ -68,7 +66,7 @@ TxProposals.prototype.toObj = function() { TxProposals.prototype._getNormHash = function(txps) { var ret = {}; txps.forEach(function(txp) { - var hash = txp.tx.getNormalizedHash().toString('hex'); + var hash = txp.builder.build().getNormalizedHash().toString('hex'); ret[hash]=txp; }); return ret; @@ -126,107 +124,18 @@ TxProposals.prototype._mergeMetadata = function(myTxps, theirTxps, mergeInfo) { }; -TxProposals.prototype._chunkIsEmpty = function(chunk) { - return chunk === 0 || // when serializing and back, EMPTY_BUFFER becomes 0 - buffertools.compare(chunk, util.EMPTY_BUFFER) === 0; -}; -// -// function d(s,l) { -// console.log('DUMP'); //TODO -// for (var i=0; i 0).should.equal(true); (w2.txps[0].seenBy[priv.id] - ts > 0).should.equal(true); @@ -240,8 +245,9 @@ describe('TxProposals model', function() { w.merge(w2); w.txps.length.should.equal(1); - w.txps[0].tx.isComplete().should.equal(false); - w.txps[0].tx.countInputMissingSignatures(0).should.equal(2); + var tx = w.txps[0].builder.build(); + tx.isComplete().should.equal(false); + tx.countInputMissingSignatures(0).should.equal(2); (w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true); (w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true); @@ -280,8 +286,9 @@ var _dumpChunks = function (scriptSig, label) { opts ); - w.txps[0].tx.isComplete().should.equal(false); - w.txps[0].tx.countInputMissingSignatures(0).should.equal(1); + var tx = w.txps[0].builder.build(); + tx.isComplete().should.equal(false); + tx.countInputMissingSignatures(0).should.equal(1); Object.keys(w.txps[0].signedBy).length.should.equal(0); Object.keys(w.txps[0].seenBy).length.should.equal(1); @@ -300,16 +307,19 @@ var _dumpChunks = function (scriptSig, label) { priv, opts ); - w2.txps[0].tx.isComplete().should.equal(false); - w2.txps[0].tx.countInputMissingSignatures(0).should.equal(2); + tx = w2.txps[0].builder.build(); + tx.isComplete().should.equal(false); + tx.countInputMissingSignatures(0).should.equal(2); (w2.txps[0].signedBy[priv.id] - ts > 0).should.equal(true); (w2.txps[0].seenBy[priv.id] - ts > 0).should.equal(true); w.merge(w2); w.txps.length.should.equal(1); - w.txps[0].tx.isComplete().should.equal(false); - w.txps[0].tx.countInputMissingSignatures(0).should.equal(2); + + tx = w.txps[0].builder.build(); + tx.isComplete().should.equal(false); + tx.countInputMissingSignatures(0).should.equal(2); (w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true); (w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true); @@ -327,8 +337,9 @@ var _dumpChunks = function (scriptSig, label) { priv2, opts ); - w3.txps[0].tx.isComplete().should.equal(false); - w3.txps[0].tx.countInputMissingSignatures(0).should.equal(2); + tx = w3.txps[0].builder.build(); + tx.isComplete().should.equal(false); + tx.countInputMissingSignatures(0).should.equal(2); (w3.txps[0].signedBy[priv2.id] - ts > 0).should.equal(true); (w3.txps[0].seenBy[priv2.id] - ts > 0).should.equal(true); @@ -341,8 +352,9 @@ var _dumpChunks = function (scriptSig, label) { (w.txps[0].signedBy[priv2.id] - ts > 0).should.equal(true); (w.txps[0].seenBy[priv2.id] - ts > 0).should.equal(true); - w.txps[0].tx.isComplete().should.equal(false); - w.txps[0].tx.countInputMissingSignatures(0).should.equal(1); + tx = w.txps[0].builder.build(); + tx.isComplete().should.equal(false); + tx.countInputMissingSignatures(0).should.equal(1); }); @@ -370,8 +382,9 @@ var _dumpChunks = function (scriptSig, label) { priv, opts ); - w.txps[0].tx.isComplete().should.equal(false); - w.txps[0].tx.countInputMissingSignatures(0).should.equal(2); + var tx = w.txps[0].builder.build(); + tx.isComplete().should.equal(false); + tx.countInputMissingSignatures(0).should.equal(2); (w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true); (w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true); @@ -389,8 +402,9 @@ var _dumpChunks = function (scriptSig, label) { priv2, opts ); - w2.txps[0].tx.isComplete().should.equal(false); - w2.txps[0].tx.countInputMissingSignatures(0).should.equal(2); + var tx = w2.txps[0].builder.build(); + tx.isComplete().should.equal(false); + tx.countInputMissingSignatures(0).should.equal(2); (w2.txps[0].signedBy[priv2.id] - ts > 0).should.equal(true); (w2.txps[0].seenBy[priv2.id] - ts > 0).should.equal(true); @@ -408,15 +422,17 @@ var _dumpChunks = function (scriptSig, label) { priv3, opts ); - w3.txps[0].tx.isComplete().should.equal(false); - w3.txps[0].tx.countInputMissingSignatures(0).should.equal(2); + var tx = w3.txps[0].builder.build(); + tx.isComplete().should.equal(false); + tx.countInputMissingSignatures(0).should.equal(2); (w3.txps[0].signedBy[priv3.id] - ts > 0).should.equal(true); (w3.txps[0].seenBy[priv3.id] - ts > 0).should.equal(true); w.merge(w2); w.txps.length.should.equal(1); - w.txps[0].tx.isComplete().should.equal(false); - w.txps[0].tx.countInputMissingSignatures(0).should.equal(1); + var tx = w.txps[0].builder.build(); + tx.isComplete().should.equal(false); + tx.countInputMissingSignatures(0).should.equal(1); (w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true); (w.txps[0].seenBy[priv2.id] - ts > 0).should.equal(true); (w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true); @@ -424,8 +440,9 @@ var _dumpChunks = function (scriptSig, label) { w.merge(w3); - w.txps[0].tx.isComplete().should.equal(true); - w.txps[0].tx.countInputMissingSignatures(0).should.equal(0); + var tx = w.txps[0].builder.build(); + tx.isComplete().should.equal(true); + tx.countInputMissingSignatures(0).should.equal(0); w.txps.length.should.equal(1); (w.txps[0].seenBy[priv.id] - ts > 0).should.equal(true); (w.txps[0].seenBy[priv2.id] - ts > 0).should.equal(true); @@ -451,12 +468,13 @@ var _dumpChunks = function (scriptSig, label) { unspentTest[0].address = w.publicKeyRing.getAddress(index, isChange).toString(); unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(index, isChange); - var tx = w.create( + w.create( '15q6HKjWHAksHcH91JW23BJEuzZgFwydBt', '123456789', unspentTest, priv ); + var tx = w.txps[0].builder.build(); tx.isComplete().should.equal(false); tx.countInputMissingSignatures(0).should.equal(2); (w.txps[0].signedBy[priv.id] - ts > 0).should.equal(true); @@ -465,19 +483,23 @@ var _dumpChunks = function (scriptSig, label) { var o = w.toObj(); should.exist(o); o.txps.length.should.equal(1); - should.exist(o.txps[0].txHex); + should.exist(o.txps[0]); should.exist(o.txps[0].signedBy); should.exist(o.txps[0].seenBy); + should.exist(o.txps[0].builderObj); + should.exist(o.txps[0].builderObj.valueInSat); should.exist(o.txps[0].signedBy[priv.id]); var w2 = TxProposals.fromObj(o); w2.walletId.should.equal(w.walletId); - var tx2 = w2.txps[0].tx; + var tx2 = w2.txps[0].builder.build(); tx2.isComplete().should.equal(false); tx2.countInputMissingSignatures(0).should.equal(2); (w2.txps[0].signedBy[priv.id] - ts > 0).should.equal(true); (w2.txps[0].seenBy[priv.id] - ts > 0).should.equal(true); - + should.exist(w2.txps[0].builder); + should.exist(w2.txps[0].builder.valueInSat); + w2.merge(w); });