add zeroPad
This commit is contained in:
parent
0d36c3481b
commit
f9a2ec27a9
|
@ -20,6 +20,9 @@ var Storage = function(opts) {
|
|||
});
|
||||
};
|
||||
|
||||
var zeroPad = function(x, length) {
|
||||
return (Array(length).join('0') + parseInt(x)).slice(-length);
|
||||
};
|
||||
|
||||
var walletPrefix = function(id) {
|
||||
return 'w!' + id;
|
||||
|
@ -29,9 +32,9 @@ var opKey = function(key) {
|
|||
return key ? '!' + key : '';
|
||||
};
|
||||
|
||||
var MAX_TS = '999999999999';
|
||||
var MAX_TS = Array(14).join('9');
|
||||
var opKeyTs = function(key) {
|
||||
return key ? '!' + ('00000000000000' + key).slice(-14) : '';
|
||||
return key ? '!' + zeroPad(key, 14) : '';
|
||||
};
|
||||
|
||||
|
||||
|
@ -155,8 +158,8 @@ Storage.prototype.fetchTxs = function(walletId, opts, cb) {
|
|||
var txs = [];
|
||||
opts = opts || {};
|
||||
opts.limit = _.isNumber(opts.limit) ? parseInt(opts.limit) : -1;
|
||||
opts.minTs = _.isNumber(opts.minTs) ? ('00000000000' + parseInt(opts.minTs)).slice(-11) : 0;
|
||||
opts.maxTs = _.isNumber(opts.maxTs) ? ('00000000000' + parseInt(opts.maxTs)).slice(-11) : MAX_TS;
|
||||
opts.minTs = _.isNumber(opts.minTs) ? zeroPad(opts.minTs, 11) : 0;
|
||||
opts.maxTs = _.isNumber(opts.maxTs) ? zeroPad(opts.maxTs, 11) : MAX_TS;
|
||||
|
||||
var key = KEY.TXP(walletId, opts.minTs);
|
||||
var endkey = KEY.TXP(walletId, opts.maxTs);
|
||||
|
@ -192,8 +195,8 @@ Storage.prototype.fetchNotifications = function(walletId, opts, cb) {
|
|||
var txs = [];
|
||||
opts = opts || {};
|
||||
opts.limit = _.isNumber(opts.limit) ? parseInt(opts.limit) : -1;
|
||||
opts.minTs = _.isNumber(opts.minTs) ? ('00000000000000' + parseInt(opts.minTs)).slice(-14) : 0;
|
||||
opts.maxTs = _.isNumber(opts.maxTs) ? ('00000000000000' + parseInt(opts.maxTs)).slice(-14) : MAX_TS;
|
||||
opts.minTs = _.isNumber(opts.minTs) ? zeroPad(opts.minTs,11) : 0;
|
||||
opts.maxTs = _.isNumber(opts.maxTs) ? zeroPad(opts.maxTs,11) : MAX_TS;
|
||||
|
||||
var key = KEY.NOTIFICATION(walletId, opts.minTs);
|
||||
var endkey = KEY.NOTIFICATION(walletId, opts.maxTs);
|
||||
|
|
Loading…
Reference in New Issue