Skip to content

Commit

Permalink
wallet: improved date handling
Browse files Browse the repository at this point in the history
  • Loading branch information
braydonf committed Dec 21, 2018
1 parent 06f2863 commit 13b7d03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
10 changes: 4 additions & 6 deletions lib/wallet/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,13 +769,12 @@ class HTTP extends Server {
const reverse = valid.bool('reverse', false);
const limit = valid.u32('limit', 100);
const after = valid.brhash('after');
const date = valid.str('date');
let time = valid.u32('time');
let date = valid.str('date');

if (date && !time) {
date = new Date(date);
enforce(date.toString() !== 'Invalid Date', 'Invalid date.');
time = util.time(date);
enforce(time, 'Invalid date.');
}

enforce(limit <= this.options.maxTxs,
Expand Down Expand Up @@ -819,13 +818,12 @@ class HTTP extends Server {
const reverse = valid.bool('reverse');
const limit = valid.u32('limit');
const after = valid.brhash('after');
const date = valid.str('date');
let time = valid.u32('time');
let date = valid.str('date');

if (date && !time) {
date = new Date(date);
enforce(date.toString() !== 'Invalid Date', 'Invalid date.');
time = util.time(date);
enforce(time, 'Invalid date.');
}

enforce(limit <= this.options.maxTxs,
Expand Down
12 changes: 4 additions & 8 deletions lib/wallet/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1248,12 +1248,10 @@ class RPC extends RPCBase {
throw new RPCError(errs.INVALID_PARAMETER,
`Limit above max of ${this.maxTxs}.`);

const date = new Date(timestamp);
if (date.toString() === 'Invalid Date')
const time = util.time(timestamp);
if (!time)
throw new RPCError(errs.INVALID_PARAMETER, 'Invalid timestamp.');

const time = util.time(date);

const recs = await wallet.listHistoryByTime(name, {time, limit, reverse});

const out = [];
Expand Down Expand Up @@ -1337,12 +1335,10 @@ class RPC extends RPCBase {
if (limit > 100)
throw new RPCError(errs.INVALID_PARAMETER, 'Limit above max of 100.');

const date = new Date(timestamp);
if (date.toString() === 'Invalid Date')
const time = util.time(timestamp);
if (!time)
throw new RPCError(errs.INVALID_PARAMETER, 'Invalid timestamp.');

const time = util.time(date);

const recs = await wallet.listUnconfirmedByTime(
name, {time, limit, reverse}
);
Expand Down

0 comments on commit 13b7d03

Please sign in to comment.