add signatureAdded counter

This commit is contained in:
Matias Alejo Garcia 2014-04-10 19:43:28 -03:00
parent a8f5f9fcb8
commit d507e7f3d5
2 changed files with 13 additions and 4 deletions

View File

@ -110,6 +110,7 @@ function TransactionBuilder(opts) {
this.tx = {};
this.inputsSigned= 0;
this.signaturesAdded= 0;
return this;
}
@ -482,7 +483,7 @@ TransactionBuilder.prototype._signPubKey = function(walletKeyMap, input, txSigHa
var scriptSig = new Script();
scriptSig.chunks.push(sig);
scriptSig.updateBuffer();
return {isFullySigned: true, signaturesAdded: true, script: scriptSig.getBuffer()};
return {isFullySigned: true, signaturesAdded: 1, script: scriptSig.getBuffer()};
};
TransactionBuilder.prototype._signPubKeyHash = function(walletKeyMap, input, txSigHash) {
@ -501,7 +502,7 @@ TransactionBuilder.prototype._signPubKeyHash = function(walletKeyMap, input, txS
scriptSig.chunks.push(sig);
scriptSig.chunks.push(wk.privKey.public);
scriptSig.updateBuffer();
return {isFullySigned: true, signaturesAdded: true, script: scriptSig.getBuffer()};
return {isFullySigned: true, signaturesAdded: 1, script: scriptSig.getBuffer()};
};
// FOR TESTING
@ -577,7 +578,7 @@ TransactionBuilder.prototype._signMultiSig = function(walletKeyMap, input, txSig
originalScriptBuf = this.tx.ins[input.i].s;
var scriptSig = new Script (originalScriptBuf);
var signaturesAdded = false;
var signaturesAdded = 0;
for(var j=0; j<l && scriptSig.countMissingSignatures(); j++) {
var wk = this._findWalletKey(walletKeyMap, {pubKeyBuf: pubkeys[j]});
@ -586,7 +587,7 @@ TransactionBuilder.prototype._signMultiSig = function(walletKeyMap, input, txSig
var newScriptSig = this._updateMultiSig(wk, scriptSig, txSigHash, nreq);
if (newScriptSig) {
scriptSig = newScriptSig;
signaturesAdded = true;
signaturesAdded++;
}
}
@ -694,6 +695,7 @@ TransactionBuilder.prototype.sign = function(keys) {
if (ret && ret.script) {
tx.ins[i].s = ret.script;
if (ret.isFullySigned) this.inputsSigned++;
if (ret.signaturesAdded) this.signaturesAdded +=ret.signaturesAdded;
}
}
return this;

View File

@ -605,36 +605,43 @@ describe('TransactionBuilder', function() {
var k2 = testdata.dataUnspentSign.keyStringsP2sh.slice(1,2);
var k5 = testdata.dataUnspentSign.keyStringsP2sh.slice(4,5);
b.isFullySigned().should.equal(false);
b.signaturesAdded.should.equal(0);
b.sign(k1);
b.isFullySigned().should.equal(false);
b.signaturesAdded.should.equal(1);
var tx = b.build();
tx.ins.length.should.equal(1);
tx.outs.length.should.equal(2);
tx.isComplete().should.equal(false);
b.signaturesAdded.should.equal(1);
// Sign with the same
b.sign(k1);
b.isFullySigned().should.equal(false);
tx.isComplete().should.equal(false);
b.signaturesAdded.should.equal(1);
// Sign with k5
b.sign(k5);
///
b.isFullySigned().should.equal(false);
tx.isComplete().should.equal(false);
b.signaturesAdded.should.equal(2);
// Sign with same
b.sign(k5);
b.isFullySigned().should.equal(false);
tx.isComplete().should.equal(false);
b.signaturesAdded.should.equal(2);
// Sign k2
b.sign(k2);
b.isFullySigned().should.equal(true);
tx.isComplete().should.equal(true);
b.signaturesAdded.should.equal(3);
});
it('should sign in steps a p2sh/p2pubkeyhash tx', function() {