add buildermockv0 to show old / obsolete tx proposals

This commit is contained in:
Matias Alejo Garcia 2014-07-25 11:59:13 -03:00
parent 7f11793b96
commit 2008db932b
3 changed files with 36 additions and 3 deletions

View File

@ -0,0 +1,26 @@
'use strict';
var bitcore = require('bitcore');
var Transaction = bitcore.Transaction;
function BuilderMockV0 (data) {
this.vanilla = data;
this.tx = new Transaction();
this.tx.parse(new Buffer(data.tx, 'hex'));
};
BuilderMockV0.prototype.build = function() {
return this.tx;
};
BuilderMockV0.prototype.getSelectedUnspent = function() {
return [];
};
BuilderMockV0.prototype.toObj = function() {
return this.vanilla;
};
module.exports = BuilderMockV0;

View File

@ -6,6 +6,7 @@ var bitcore = require('bitcore');
var util = bitcore.util;
var Transaction = bitcore.Transaction;
var Builder = bitcore.TransactionBuilder;
var BuilderMockV0 = require('./BuilderMockV0');;
var Script = bitcore.Script;
var buffertools = bitcore.buffertools;
@ -45,8 +46,11 @@ TxProposal.fromObj = function(o) {
try {
t.builder = new Builder.fromObj(o.builderObj);
} catch (e) {
if (!process.version)
console.log('Ignoring incompatible stored TxProposal:' + JSON.stringify(o.builderObj));
if (!o.version) {
console.log('Importing old TxProposal V0' + JSON.stringify(o.builderObj));
t.builder = new BuilderMockV0(o.builderObj);
t.readonly = 1;
};
}
return t;
};

View File

@ -488,7 +488,10 @@ Wallet.prototype.getTxProposals = function() {
txp.finallyRejected = true;
}
ret.push(txp);
if (txp.readonly && !txp.finallyRejected && !txp.sentTs) {
} else {
ret.push(txp);
}
}
return ret;
};