chore: server code formatting
This commit is contained in:
parent
aedabcbdee
commit
68517170e2
234 changed files with 9824 additions and 6195 deletions
|
|
@ -6,11 +6,13 @@ const { BALANCE_FETCH_SPEED_MULTIPLIER } = require('../../../constants')
|
|||
|
||||
const NAME = 'infura'
|
||||
|
||||
function run (account) {
|
||||
if (!account.endpoint) throw new Error('Need to configure API endpoint for Infura')
|
||||
function run(account) {
|
||||
if (!account.endpoint)
|
||||
throw new Error('Need to configure API endpoint for Infura')
|
||||
|
||||
const endpoint = _.startsWith('https://')(account.endpoint)
|
||||
? account.endpoint : `https://${account.endpoint}`
|
||||
? account.endpoint
|
||||
: `https://${account.endpoint}`
|
||||
|
||||
base.connect(endpoint)
|
||||
}
|
||||
|
|
@ -18,24 +20,35 @@ function run (account) {
|
|||
const txsCache = new NodeCache({
|
||||
stdTTL: T.hour / 1000,
|
||||
checkperiod: T.minute / 1000,
|
||||
deleteOnExpire: true
|
||||
deleteOnExpire: true,
|
||||
})
|
||||
|
||||
function shouldGetStatus (tx) {
|
||||
function shouldGetStatus(tx) {
|
||||
const timePassedSinceTx = Date.now() - new Date(tx.created)
|
||||
const timePassedSinceReq = Date.now() - new Date(txsCache.get(tx.id).lastReqTime)
|
||||
const timePassedSinceReq =
|
||||
Date.now() - new Date(txsCache.get(tx.id).lastReqTime)
|
||||
|
||||
if (timePassedSinceTx < 3 * T.minutes) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 10 * T.seconds
|
||||
if (timePassedSinceTx < 5 * T.minutes) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 20 * T.seconds
|
||||
if (timePassedSinceTx < 30 * T.minutes) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > T.minute
|
||||
if (timePassedSinceTx < 1 * T.hour) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 2 * T.minute
|
||||
if (timePassedSinceTx < 3 * T.hours) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 5 * T.minute
|
||||
if (timePassedSinceTx < 1 * T.day) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > T.hour
|
||||
if (timePassedSinceTx < 3 * T.minutes)
|
||||
return (
|
||||
_.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 10 * T.seconds
|
||||
)
|
||||
if (timePassedSinceTx < 5 * T.minutes)
|
||||
return (
|
||||
_.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 20 * T.seconds
|
||||
)
|
||||
if (timePassedSinceTx < 30 * T.minutes)
|
||||
return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > T.minute
|
||||
if (timePassedSinceTx < 1 * T.hour)
|
||||
return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 2 * T.minute
|
||||
if (timePassedSinceTx < 3 * T.hours)
|
||||
return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 5 * T.minute
|
||||
if (timePassedSinceTx < 1 * T.day)
|
||||
return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > T.hour
|
||||
return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > T.hour
|
||||
}
|
||||
|
||||
// Override geth's getStatus function to allow for different polling timing
|
||||
function getStatus (account, tx, requested, settings, operatorId) {
|
||||
function getStatus(account, tx, requested, settings, operatorId) {
|
||||
if (_.isNil(txsCache.get(tx.id))) {
|
||||
txsCache.set(tx.id, { lastReqTime: Date.now() })
|
||||
}
|
||||
|
|
@ -45,7 +58,8 @@ function getStatus (account, tx, requested, settings, operatorId) {
|
|||
return Promise.resolve(txsCache.get(tx.id).res)
|
||||
}
|
||||
|
||||
return base.getStatus(account, tx, requested, settings, operatorId)
|
||||
return base
|
||||
.getStatus(account, tx, requested, settings, operatorId)
|
||||
.then(res => {
|
||||
if (res.status === 'confirmed') {
|
||||
txsCache.del(tx.id) // Transaction reached final status, can trim it from the caching obj
|
||||
|
|
@ -57,4 +71,9 @@ function getStatus (account, tx, requested, settings, operatorId) {
|
|||
})
|
||||
}
|
||||
|
||||
module.exports = _.merge(base, { NAME, run, getStatus, fetchSpeed: BALANCE_FETCH_SPEED_MULTIPLIER.SLOW })
|
||||
module.exports = _.merge(base, {
|
||||
NAME,
|
||||
run,
|
||||
getStatus,
|
||||
fetchSpeed: BALANCE_FETCH_SPEED_MULTIPLIER.SLOW,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue