Skip to content

Commit

Permalink
More usage of tx bareid instead of full tx hash so we can link tx wit…
Browse files Browse the repository at this point in the history
…h different signatures.
  • Loading branch information
caedesvvv committed Oct 25, 2014
1 parent 4f06860 commit 6311a1a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions js/backend/services/multisig_track.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ define(['backend/port', 'util/protocol', 'util/btc', 'dwutil/multisig', 'bitcoin
*/
MultisigTrackService.prototype.processTx = function(serializedTx) {
var identity = this.core.getCurrentIdentity();
var txHash = BtcUtils.hash256(serializedTx);
var txHash = BtcUtils.getBareTxId(Bitcoin.Transaction.fromHex(serializedTx));

var tasks = identity.tasks.getTasks('multisig');
tasks = tasks.concat(identity.tasks.getTasks('multisig-sign'));

tasks.forEach(function(task) {
if ((task.tx === serializedTx) || (task.hash === txHash)) {
if ((task.tx === serializedTx) || (task.hash === txHash) || (BtcUtils.getBareTxId(Bitcoin.Transaction.fromHex(task.tx)) === txHash)) {
task.state = 'finished';
}
});
Expand All @@ -119,11 +119,11 @@ define(['backend/port', 'util/protocol', 'util/btc', 'dwutil/multisig', 'bitcoin

tasks.forEach(function(task) {
// Generate the tx hash to check or get it from the task if available
var hash = task.hash || BtcUtils.hash256(task.tx);
var hash = task.hash || BtcUtils.getBareTxId(Bitcoin.Transaction.fromHex(task.tx));

// Check if some row references this
identity.history.history.some(function(row) {
if (row.hash === hash) {
if (row.bareid === hash) {
task.state = 'finished';
return true;
}
Expand Down Expand Up @@ -214,7 +214,7 @@ define(['backend/port', 'util/protocol', 'util/btc', 'dwutil/multisig', 'bitcoin
*/
MultisigTrackService.prototype.sign = function(multisig, tx, sigHex) {
var task = this.prepareTask({}, multisig);
task.hash = tx.getId();
task.hash = BtcUtils.getBareTxId(tx);
task.signature = sigHex;

// Add the task
Expand Down
2 changes: 1 addition & 1 deletion js/dwutil/multisig.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ MultisigFund.prototype.importSignature = function(sigHex, spend) {
MultisigFund.prototype.getSpend = function(txHash) {
for(var i=0; i<this.tasks.length; i++) {
var spend = this.tasks[i];
var hash = spend.tx.getId();
var hash = BtcUtils.getBareTxId(spend.tx);
if (hash === txHash) {
return spend;
}
Expand Down
2 changes: 1 addition & 1 deletion js/model/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ History.prototype.buildHistoryRow = function(transaction, height) {
}
// Create a row representing this change (if already referenced will
// be replaced)
var newRow = {hash: txHash, tx: txObj, inMine: inMine, outAddresses: outAddresses, myInValue: myInValue, myOutValue: myOutValue, height: height, address: txAddr, isStealth: isStealth, total: myOutValue-myInValue, outPocket: outPocket, inPocket: inPocket, impact: pocketImpact, label: this.identity.txdb.getLabel(txHash), internal: internal};
var newRow = {hash: txHash, tx: txObj, inMine: inMine, outAddresses: outAddresses, myInValue: myInValue, myOutValue: myOutValue, height: height, address: txAddr, isStealth: isStealth, total: myOutValue-myInValue, outPocket: outPocket, inPocket: inPocket, impact: pocketImpact, label: this.identity.txdb.getLabel(txHash), internal: internal, bareid: BtcUtils.getBareTxId(txObj)};
return newRow;
};

Expand Down
2 changes: 1 addition & 1 deletion test/unit/dwutil/multisigSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ define(['testUtils', 'bitcoinjs-lib'], function (testUtils, Bitcoin) {

it('gets a spend', function() {
var fund = new MultisigFund(multisig);
var spend = fund.getSpend("b1fbe6f084c97fb51550358a7569273507d3469754f75559b3e93a825af0b10e");
var spend = fund.getSpend("3f01e20c4b44745663bd6ef2c6b46aa6e344528d5e80af540085021acab2c17f");
expect(spend.task.tx).toBe(txIn);
});

Expand Down

0 comments on commit 6311a1a

Please sign in to comment.