Merge pull request #340 from matiu/feat/rawTx
add transaction raw HEX if tx status is "accepted"
This commit is contained in:
commit
3f1bae6f25
|
@ -260,7 +260,7 @@ TxProposal.prototype.addAction = function(copayerId, type, comment, signatures,
|
|||
this._updateStatus();
|
||||
};
|
||||
|
||||
TxProposal.prototype._addSignaturesToBitcoreTx = function(t, signatures, xpub) {
|
||||
TxProposal.prototype._addSignaturesToBitcoreTx = function(tx, signatures, xpub) {
|
||||
var self = this;
|
||||
|
||||
if (signatures.length != this.inputs.length)
|
||||
|
@ -280,12 +280,12 @@ TxProposal.prototype._addSignaturesToBitcoreTx = function(t, signatures, xpub) {
|
|||
sigtype: Bitcore.crypto.Signature.SIGHASH_ALL,
|
||||
publicKey: pub,
|
||||
};
|
||||
t.inputs[i].addSignature(t, s);
|
||||
tx.inputs[i].addSignature(tx, s);
|
||||
i++;
|
||||
} catch (e) {};
|
||||
});
|
||||
|
||||
if (i != t.inputs.length)
|
||||
if (i != tx.inputs.length)
|
||||
throw new Error('Wrong signatures');
|
||||
};
|
||||
|
||||
|
@ -293,10 +293,14 @@ TxProposal.prototype._addSignaturesToBitcoreTx = function(t, signatures, xpub) {
|
|||
TxProposal.prototype.sign = function(copayerId, signatures, xpub) {
|
||||
try {
|
||||
// Tests signatures are OK
|
||||
var t = this.getBitcoreTx();
|
||||
this._addSignaturesToBitcoreTx(t, signatures, xpub);
|
||||
var tx = this.getBitcoreTx();
|
||||
this._addSignaturesToBitcoreTx(tx, signatures, xpub);
|
||||
|
||||
this.addAction(copayerId, 'accept', null, signatures, xpub);
|
||||
|
||||
if (this.status == 'accepted')
|
||||
this.raw = tx.uncheckedSerialize();
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
|
|
@ -162,6 +162,10 @@ Storage.prototype._completeTxData = function(walletId, txs, cb) {
|
|||
_.each(tx.actions, function(action) {
|
||||
action.copayerName = wallet.getCopayer(action.copayerId).name;
|
||||
});
|
||||
|
||||
if (tx.status=='accepted')
|
||||
tx.raw = tx.getRawTx();
|
||||
|
||||
});
|
||||
return cb(null, txs);
|
||||
});
|
||||
|
|
|
@ -2773,6 +2773,55 @@ describe('Wallet service', function() {
|
|||
});
|
||||
|
||||
describe('#signTx', function() {
|
||||
describe('1-1', function() {
|
||||
var server, wallet, txid;
|
||||
|
||||
beforeEach(function(done) {
|
||||
helpers.createAndJoinWallet(1, 1, function(s, w) {
|
||||
server = s;
|
||||
wallet = w;
|
||||
helpers.stubUtxos(server, wallet, _.range(1, 9), function() {
|
||||
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 20, null, TestData.copayers[0].privKey_1H_0);
|
||||
server.createTx(txOpts, function(err, tx) {
|
||||
should.not.exist(err);
|
||||
should.exist(tx);
|
||||
txid = tx.id;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should sign a TX with multiple inputs, different paths, and return raw', function(done) {
|
||||
server.getPendingTxs({}, function(err, txs) {
|
||||
var tx = txs[0];
|
||||
tx.id.should.equal(txid);
|
||||
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
|
||||
should.not.exist(tx.raw);
|
||||
server.signTx({
|
||||
txProposalId: txid,
|
||||
signatures: signatures,
|
||||
}, function(err, txp) {
|
||||
should.not.exist(err);
|
||||
txp.status.should.equal('accepted');
|
||||
// The raw Tx should contain the Signatures.
|
||||
txp.raw.should.contain(signatures[0]);
|
||||
|
||||
// Get pending should also contains the raw TX
|
||||
server.getPendingTxs({}, function(err, txs) {
|
||||
var tx = txs[0];
|
||||
should.not.exist(err);
|
||||
tx.status.should.equal('accepted');
|
||||
tx.raw.should.contain(signatures[0]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
describe('Multisign 2-3', function() {
|
||||
var server, wallet, txid;
|
||||
|
||||
beforeEach(function(done) {
|
||||
|
@ -2800,8 +2849,9 @@ describe('Wallet service', function() {
|
|||
server.signTx({
|
||||
txProposalId: txid,
|
||||
signatures: signatures,
|
||||
}, function(err) {
|
||||
}, function(err, txp) {
|
||||
should.not.exist(err);
|
||||
should.not.exist(tx.raw);
|
||||
server.getPendingTxs({}, function(err, txs) {
|
||||
should.not.exist(err);
|
||||
var tx = txs[0];
|
||||
|
@ -2818,7 +2868,6 @@ describe('Wallet service', function() {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
it('should fail to sign with a xpriv from other copayer', function(done) {
|
||||
server.getPendingTxs({}, function(err, txs) {
|
||||
var tx = txs[0];
|
||||
|
@ -2977,6 +3026,7 @@ describe('Wallet service', function() {
|
|||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#broadcastTx & #braodcastRawTx', function() {
|
||||
var server, wallet, txpid;
|
||||
|
@ -3017,6 +3067,7 @@ describe('Wallet service', function() {
|
|||
txProposalId: txpid
|
||||
}, function(err, txp) {
|
||||
should.not.exist(err);
|
||||
should.not.exist(txp.raw);
|
||||
txp.txid.should.equal('999');
|
||||
txp.isBroadcasted().should.be.true;
|
||||
txp.broadcastedOn.should.equal(1234);
|
||||
|
|
Loading…
Reference in New Issue