Skip to content

Commit

Permalink
Merge pull request #2132 from matiu/bug/signatures-cache
Browse files Browse the repository at this point in the history
fix sig cache
  • Loading branch information
cmgustavo committed Dec 12, 2014
2 parents 88d125e + efd1e96 commit 3ef5643
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ android:
cd cordova/project && cordova run android

chrome:
grunt prod
browser-extensions/chrome/build.sh

4 changes: 3 additions & 1 deletion js/models/PublicKeyRing.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ PublicKeyRing.prototype.getAddressesOrderer = function(pubkey) {
var l = info.length;

var sortedInfo = _.sortBy(info, function(i) {
var goodness = ( (i.copayerIndex !== copayerIndex) ? 2 * l : 0 ) +( i.isChange ? l : 0 ) + l - i.addressIndex;
var goodness = ( (i.copayerIndex !== copayerIndex) ? 2 * l : 0 )
+ ( i.isChange ? l : 0 )
+ l - i.addressIndex;
return goodness;
});

Expand Down
6 changes: 3 additions & 3 deletions js/models/TxProposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ TxProposal.prototype._addSignatureAndVerify = function(signatures) {

var inputsFullySigned = 0;
var newScriptSigs = [];

this.resetCache();
_.each(tx.ins, function(input, index) {
var scriptSig = new Script(input.s);

Expand Down Expand Up @@ -288,11 +290,9 @@ TxProposal.prototype._addSignatureAndVerify = function(signatures) {
input.s = newScriptSigs[index];

// just to keep TransactionBuilder updated
if (tx.ins.length == inputsFullySigned)
if (tx.ins.length == inputsFullySigned)
self.builder.inputsSigned++;
});

this.resetCache();
};

TxProposal.prototype.resetCache = function() {
Expand Down
8 changes: 5 additions & 3 deletions js/models/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,12 @@ Wallet.prototype._checkIfTxIsSent = function(ntxid, cb) {
var tx = txp.builder.build();
var txHex = tx.serialize().toString('hex');


//Use calcHash NOT getHash which could be cached.
var txid = bitcore.util.formatHashFull(tx.calcHash());

log.debug('Checking if transactions was broadcasted... ID:' + txid);

this.blockchain.getTransaction(txid, function(err, tx) {
return cb(err, !err ? txid : null);
});
Expand Down Expand Up @@ -1625,9 +1629,7 @@ Wallet.prototype.broadcastToBitcoinNetwork = function(ntxid, cb) {

this.blockchain.broadcast(txHex, function(err, txid) {
if (err || !txid) {

log.info('Wallet:' + self.getName() + '. Sent failed:' +
err + '. Checking if the TX was sent already');
log.debug('Wallet:' + self.getName() + ' Send failed:' + err );

self._checkIfTxIsSent(ntxid, function(err, txid) {
return cb(err, txid);
Expand Down
7 changes: 6 additions & 1 deletion test/TxProposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ describe('TxProposal', function() {
var SIG0 = '304502200708a381dde585ef7fdfaeaeb5da9b451d3e22b01eac8a5e3d03b959e24a7478022100c90e76e423523a54a9e9c43858337ebcef1a539a7fc685c2698dd8648fcf1b9101';
var SIG1 = '3044022030a77c9613d6ee010717c1abc494668d877e3fa0ae4c520f65cc3b308754c98c02205219d387bcb291bd44805b9468439e4168b02a6a180cdbcc24d84d71d696c1ae01';



/* decoded redeemscript
*
"asm" : "3 03197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d 0380a29968851f93af55e581c43d9ef9294577a439a3ca9fc2bc47d1ca2b3e9127 0392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed03 03a94351fecc4328bb683bf93a1aa67378374904eac5980c7966723a51897c56e3 03e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e4 5 OP_CHECKMULTISIG",
Expand All @@ -41,6 +43,9 @@ describe('TxProposal', function() {
var someKeys = ["03b39d61dc9a504b13ae480049c140dcffa23a6cc9c09d12d6d1f332fee5e18ca5", "022929f515c5cf967474322468c3bd945bb6f281225b2c884b465680ef3052c07e"];


// 3-5


function dummyBuilder(opts) {
opts = opts || {};

Expand Down Expand Up @@ -340,7 +345,7 @@ describe('TxProposal', function() {
});
});

describe('#addSignature', function() {
describe('#addSignature', function() {
it('should add signatures maintaing pubkeys order', function() {
var txp = dummyProposal({
nsig:1
Expand Down

0 comments on commit 3ef5643

Please sign in to comment.