-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Non-functional auto-format refactoring
This commit is a no-op refactoring using an automatic Javascript code formatting tool Signed-off-by: Daniel D’Aquino <[email protected]>
- Loading branch information
1 parent
d7fc32a
commit 17832b5
Showing
2 changed files
with
58 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
const { current_time } = require('./utils') | ||
|
||
function check_account(api, pubkey) { | ||
const id = Buffer.from(pubkey) | ||
const account = api.dbs.accounts.get(id) | ||
const id = Buffer.from(pubkey) | ||
const account = api.dbs.accounts.get(id) | ||
|
||
if (!account) | ||
return { ok: false, message: 'Account not found' } | ||
if (!account) | ||
return { ok: false, message: 'Account not found' } | ||
|
||
if (!account.expiry || current_time() >= account.expiry) | ||
return { ok: false, message: 'Account expired' } | ||
if (!account.expiry || current_time() >= account.expiry) | ||
return { ok: false, message: 'Account expired' } | ||
|
||
return { ok: true, message: null } | ||
return { ok: true, message: null } | ||
} | ||
|
||
function create_account(api, pubkey, expiry) { | ||
const id = Buffer.from(pubkey) | ||
const account = api.dbs.accounts.get(id) | ||
const id = Buffer.from(pubkey) | ||
const account = api.dbs.accounts.get(id) | ||
|
||
if (account) | ||
return { request_error: 'account already exists' } | ||
if (account) | ||
return { request_error: 'account already exists' } | ||
|
||
const new_account = { | ||
pubkey: pubkey, | ||
created_at: current_time(), | ||
expiry: expiry, | ||
} | ||
const new_account = { | ||
pubkey: pubkey, | ||
created_at: current_time(), | ||
expiry: expiry, | ||
} | ||
|
||
api.dbs.accounts.put(id, new_account) | ||
return { account: new_account, request_error: null } | ||
api.dbs.accounts.put(id, new_account) | ||
return { account: new_account, request_error: null } | ||
} | ||
|
||
function get_account_info_payload(account) { | ||
if (!account) | ||
return null | ||
|
||
return { | ||
pubkey: account.pubkey, | ||
created_at: account.created_at, | ||
expiry: account.expiry ? account.expiry : null, | ||
active: (account.expiry && current_time() < account.expiry) ? true : false, | ||
} | ||
if (!account) | ||
return null | ||
|
||
return { | ||
pubkey: account.pubkey, | ||
created_at: account.created_at, | ||
expiry: account.expiry ? account.expiry : null, | ||
active: (account.expiry && current_time() < account.expiry) ? true : false, | ||
} | ||
} | ||
|
||
module.exports = { check_account, create_account, get_account_info_payload } |