|
|
@ -69,6 +69,15 @@ TxProposal.prototype._updateStatus = function() { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
TxProposal.prototype._getCurrentSignatures = function() { |
|
|
|
return _.map(_.some(this.actions, 'xpub'), function(x) { |
|
|
|
return { |
|
|
|
signatures: x.signatures, |
|
|
|
xpub: xpub, |
|
|
|
}; |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
TxProposal.prototype._getBitcoreTx = function() { |
|
|
|
var self = this; |
|
|
|
|
|
|
@ -81,6 +90,13 @@ TxProposal.prototype._getBitcoreTx = function() { |
|
|
|
.change(this.changeAddress); |
|
|
|
|
|
|
|
t._updateChangeOutput(); |
|
|
|
|
|
|
|
|
|
|
|
var sigs = this._getCurrentSignatures(); |
|
|
|
_.each(sigs, function(x) { |
|
|
|
this._addSignaturesToBitcoreTx(t, x.signatures, x.xpub); |
|
|
|
}); |
|
|
|
|
|
|
|
return t; |
|
|
|
}; |
|
|
|
|
|
|
@ -121,22 +137,20 @@ TxProposal.prototype.getActionBy = function(copayerId) { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
TxProposal.prototype.addAction = function(copayerId, type, signatures) { |
|
|
|
TxProposal.prototype.addAction = function(copayerId, type, signatures, xpub) { |
|
|
|
var action = new TxProposalAction({ |
|
|
|
copayerId: copayerId, |
|
|
|
type: type, |
|
|
|
signatures: signatures, |
|
|
|
xpub: xpub, |
|
|
|
}); |
|
|
|
this.actions[copayerId] = action; |
|
|
|
this._updateStatus(); |
|
|
|
}; |
|
|
|
|
|
|
|
// TODO: no sure we should receive xpub or a list of pubkeys (pre derived)
|
|
|
|
TxProposal.prototype.checkSignatures = function(signatures, xpub) { |
|
|
|
TxProposal.prototype._addSignaturesToBitcoreTx = function(t, signatures, xpub) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var t = this._getBitcoreTx(); |
|
|
|
|
|
|
|
if (signatures.length != this.inputs.length) |
|
|
|
return false; |
|
|
|
|
|
|
@ -159,17 +173,25 @@ TxProposal.prototype.checkSignatures = function(signatures, xpub) { |
|
|
|
|
|
|
|
t.applySignature(s); |
|
|
|
oks++; |
|
|
|
} catch (e) { |
|
|
|
// TODO only for debug now
|
|
|
|
console.log('DEBUG ONLY:', e.message); //TODO
|
|
|
|
}; |
|
|
|
} catch (e) {}; |
|
|
|
}); |
|
|
|
return oks === t.inputs.length; |
|
|
|
|
|
|
|
if (oks != t.inputs.length) |
|
|
|
throw new Error('wrong signatures'); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
TxProposal.prototype.sign = function(copayerId, signatures) { |
|
|
|
this.addAction(copayerId, 'accept', signatures); |
|
|
|
TxProposal.prototype.sign = function(copayerId, signatures, xpub) { |
|
|
|
|
|
|
|
// Tests signatures are OK
|
|
|
|
var t = this._getBitcoreTx(); |
|
|
|
try { |
|
|
|
this._addSignaturesToBitcoreTx(t, signatures, xpub); |
|
|
|
this.addAction(copayerId, 'accept', signatures, xpub); |
|
|
|
return true; |
|
|
|
} catch (e) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
TxProposal.prototype.reject = function(copayerId) { |
|
|
|