send tx (publish) + tests

This commit is contained in:
Ivan Socolsky 2015-11-26 11:28:07 -03:00
parent 5755b965e8
commit 30c8072b8b
2 changed files with 72 additions and 1 deletions

View File

@ -1348,7 +1348,6 @@ WalletService.prototype.createTx = function(opts, cb) {
/**
* Creates a new transaction proposal.
* @param {Object} opts
* @param {string} opts.type - Proposal type.
* @param {Array} opts.outputs - List of outputs.
* @param {string} opts.outputs[].toAddress - Destination address.
* @param {number} opts.outputs[].amount - Amount to transfer in satoshi.
@ -1426,6 +1425,34 @@ WalletService.prototype.createTx2 = function(opts, cb) {
});
};
/**
* Send an already created tx proposal to other copayers in the wallet.
* @param {Object} opts
* @param {string} opts.txProposalId - The tx id.
* @param {string} opts.proposalSignature - S(raw tx). Used by other copayers to verify the proposal.
* @param {string} opts.proposalSignaturePubKey - The public key needed to verify the proposal signature.
* @param {string} opts.proposalSignaturePubKeySig - A signature of the public key used to validate that the public key belongs to the creator.
*/
WalletService.prototype.sendTx = function(opts, cb) {
var self = this;
if (!Utils.checkRequired(opts, ['txProposalId', 'proposalSignature', 'proposalSignaturePubKey', 'proposalSignaturePubKeySig']))
return cb(new ClientError('Required argument missing'));
self._runLocked(cb, function(cb) {
self.storage.fetchTx(self.walletId, opts.txProposalId, function(err, txp) {
if (err) return cb(err);
if (!txp) return cb(Errors.TX_NOT_FOUND);
if (!txp.isTemporary()) return cb();
txp.status = 'pending';
self.storage.storeTx(self.walletId, txp, function(err) {
if (err) return cb(err);
return cb();
});
});
});
};
/**
* Retrieves a tx from storage.

View File

@ -2365,6 +2365,50 @@ describe('Wallet service', function() {
});
});
});
it('should be able to send a temporary tx proposal', function(done) {
helpers.stubUtxos(server, wallet, [1, 2], function() {
var txOpts = helpers.createProposalOpts2([{
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
amount: 0.8
}], {
message: 'some message',
customData: 'some custom data',
});
server.createTx2(txOpts, function(err, tx) {
should.not.exist(err);
should.exist(tx);
server.sendTx({
txProposalId: tx.id,
proposalSignature: 'dummy',
proposalSignaturePubKey: 'dummy',
proposalSignaturePubKeySig: 'dummy',
}, function(err) {
should.not.exist(err);
server.getPendingTxs({}, function(err, txs) {
should.not.exist(err);
txs.length.should.equal(1);
done();
});
});
});
});
});
it('should fail to send non-existent tx proposal', function(done) {
server.sendTx({
txProposalId: 'wrong-id',
proposalSignature: 'dummy',
proposalSignaturePubKey: 'dummy',
proposalSignaturePubKeySig: 'dummy',
}, function(err) {
should.exist(err);
server.getPendingTxs({}, function(err, txs) {
should.not.exist(err);
txs.should.be.empty;
done();
});
});
});
});
describe('#createTx backoff time', function(done) {
var server, wallet, txid;