txproposal id = time + uuid

This commit is contained in:
Matias Alejo Garcia 2015-02-07 14:15:04 -03:00
parent 44b9691e3e
commit e1ab87c173
3 changed files with 18 additions and 22 deletions

View File

@ -14,7 +14,7 @@ function TxProposal(opts) {
this.version = VERSION;
this.createdOn = Math.floor(Date.now() / 1000);
this.id = Uuid.v4();
this.id = ('000000000000' + this.createdOn).slice(-12) + Uuid.v4();
this.creatorId = opts.creatorId;
this.toAddress = opts.toAddress;
this.amount = opts.amount;

View File

@ -39,11 +39,8 @@ var KEY = {
TXP: function(walletId, txProposalId) {
return 'txp!' + walletId + opKey(txProposalId);
},
TXP_BY_TS: function(walletId, ts, txProposalId) {
return 'txp-ts!' + walletId + opKeyTs(ts) + opKey(txProposalId);
},
PENDING_TXP_BY_TS: function(walletId, ts, txProposalId) {
return 'pending-txp-ts!' + walletId + opKey(ts) + opKey(txProposalId);
PENDING_TXP: function(walletId, txProposalId) {
return 'pending-txp-ts!' + walletId + opKey(txProposalId);
},
ADDRESS: function(walletId, address) {
return 'address!' + walletId + opKey(address);
@ -107,7 +104,7 @@ Storage.prototype.fetchTx = function(walletId, txProposalId, cb) {
Storage.prototype.fetchPendingTxs = function(walletId, cb) {
var txs = [];
var key = KEY.PENDING_TXP_BY_TS(walletId);
var key = KEY.PENDING_TXP(walletId);
this.db.createReadStream({
gte: key,
lt: key + '~'
@ -135,12 +132,12 @@ Storage.prototype.fetchPendingTxs = function(walletId, cb) {
Storage.prototype.fetchTxs = function(walletId, opts, cb) {
var txs = [];
opts = opts || {};
opts.limit = opts.limit || -1;
opts.minTs = opts.minTs || 0;
opts.maxTs = opts.maxTs || MAX_TS;
opts.limit = _.isNumber(opts.limit) ? parseInt(opts.limit) : -1;
opts.minTs = _.isNumber(opts.minTs) ? ('000000000000' + parseInt(opts.minTs)).slice(-12) : 0;
opts.maxTs = _.isNumber(opts.maxTs) ? ('000000000000' + parseInt(opts.maxTs)).slice(-12) : MAX_TS;
var key = KEY.TXP_BY_TS(walletId, opts.minTs);
var endkey = KEY.TXP_BY_TS(walletId, opts.maxTs);
var key = KEY.TXP(walletId, opts.minTs);
var endkey = KEY.TXP(walletId, opts.maxTs);
this.db.createReadStream({
gt: key,
@ -168,22 +165,18 @@ Storage.prototype.storeTx = function(walletId, txp, cb) {
type: 'put',
key: KEY.TXP(walletId, txp.id),
value: txp,
}, {
type: 'put',
key: KEY.TXP_BY_TS(walletId, txp.createdOn, txp.id),
value: txp,
}];
if (txp.isPending()) {
ops.push({
type: 'put',
key: KEY.PENDING_TXP_BY_TS(walletId, txp.createdOn, txp.id),
key: KEY.PENDING_TXP(walletId, txp.id),
value: txp,
});
} else {
ops.push({
type: 'del',
key: KEY.PENDING_TXP_BY_TS(walletId, txp.createdOn, txp.id),
key: KEY.PENDING_TXP(walletId, txp.id),
});
}
this.db.batch(ops, cb);

View File

@ -710,8 +710,6 @@ describe('Copay server', function() {
it.skip('should fail to create tx when wallet is not complete', function(done) {});
it.skip('should fail to create tx when wallet is not complete', function(done) {});
it('should fail to create tx when insufficient funds', function(done) {
helpers.createUtxos(server, wallet, helpers.toSatoshi([100]), function(utxos) {
helpers.stubBlockExplorer(server, utxos);
@ -1009,6 +1007,10 @@ describe('Copay server', function() {
var server, wallet, clock;
beforeEach(function(done) {
if (server)
return done();
this.timeout(5000);
console.log('\tCreating TXS...');
clock = sinon.useFakeTimers();
helpers.createAndJoinWallet(1, 1, function(s, w) {
@ -1028,8 +1030,9 @@ describe('Copay server', function() {
server.createTx(txOpts, function(err, tx) {
next();
});
},
done
}, function(err) {
return done(err);
}
);
});
});