fix: digest auth request queue remake
This commit is contained in:
parent
c8f5e471be
commit
35a0512ab5
4 changed files with 46 additions and 22 deletions
|
|
@ -1,14 +1,14 @@
|
|||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const _ = require('lodash/fp')
|
||||
const jsonRpc = require('../../common/json-rpc')
|
||||
|
||||
const { COINS, utils } = require('@lamassu/coins')
|
||||
const { default: PQueue } = require('p-queue')
|
||||
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
const { logger } = require('../../../blockchain/common')
|
||||
const options = require('../../../options')
|
||||
const jsonRpc = require('../../common/json-rpc')
|
||||
|
||||
const blockchainDir = options.blockchainDir
|
||||
|
||||
|
|
@ -16,6 +16,21 @@ const cryptoRec = utils.getCryptoCurrency(COINS.XMR)
|
|||
const configPath = utils.configPath(cryptoRec, blockchainDir)
|
||||
const walletDir = path.resolve(utils.cryptoDir(cryptoRec, blockchainDir), 'wallets')
|
||||
|
||||
const DIGEST_QUEUE = new PQueue({
|
||||
concurrency: 1,
|
||||
interval: 150,
|
||||
})
|
||||
|
||||
function createDigestRequest (account = {}, method, params = []) {
|
||||
return DIGEST_QUEUE.add(() => jsonRpc.fetchDigest(account, method, params)
|
||||
.then(res => {
|
||||
const r = JSON.parse(res)
|
||||
if (r.error) throw r.error
|
||||
return r.result
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
function rpcConfig () {
|
||||
try {
|
||||
const config = jsonRpc.parseConf(configPath)
|
||||
|
|
@ -30,7 +45,7 @@ function rpcConfig () {
|
|||
}
|
||||
|
||||
function fetch (method, params) {
|
||||
return jsonRpc.createDigestRequest(rpcConfig(), method, params)
|
||||
return createDigestRequest(rpcConfig(), method, params)
|
||||
}
|
||||
|
||||
function handleError (error, method) {
|
||||
|
|
@ -81,6 +96,7 @@ function checkCryptoCode (cryptoCode) {
|
|||
|
||||
function refreshWallet () {
|
||||
return fetch('refresh')
|
||||
.catch(err => handleError(err, 'refreshWallet'))
|
||||
}
|
||||
|
||||
function accountBalance (cryptoCode) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue