Merge pull request #1144 from chaotixkilla/fix-digest-request-queue
Remake digest auth request queueing
This commit is contained in:
commit
58c85a8354
4 changed files with 46 additions and 22 deletions
|
|
@ -4,7 +4,6 @@ const uuid = require('uuid')
|
|||
const fs = require('fs')
|
||||
const _ = require('lodash/fp')
|
||||
const request = require('request-promise')
|
||||
const Queue = require('queue-promise')
|
||||
const { utils: coinUtils } = require('@lamassu/coins')
|
||||
|
||||
const options = require('../../options')
|
||||
|
|
@ -12,7 +11,7 @@ const options = require('../../options')
|
|||
const blockchainDir = options.blockchainDir
|
||||
|
||||
module.exports = {
|
||||
fetch, fetchDigest, createDigestRequest, parseConf, rpcConfig
|
||||
fetch, fetchDigest, parseConf, rpcConfig
|
||||
}
|
||||
|
||||
function fetch (account = {}, method, params) {
|
||||
|
|
@ -50,17 +49,6 @@ function fetch (account = {}, method, params) {
|
|||
})
|
||||
}
|
||||
|
||||
const DIGEST_QUEUE = new Queue({
|
||||
concurrent: 1,
|
||||
interval: 100,
|
||||
start: false
|
||||
})
|
||||
|
||||
function createDigestRequest (account = {}, method, params = []) {
|
||||
DIGEST_QUEUE.enqueue(() => fetchDigest(account, method, params))
|
||||
return DIGEST_QUEUE.dequeue()
|
||||
}
|
||||
|
||||
function generateDigestOptions (account = {}, method, params) {
|
||||
const headers = {
|
||||
'Content-Type': 'application/json'
|
||||
|
|
@ -93,11 +81,6 @@ function fetchDigest(account = {}, method, params = []) {
|
|||
const options = generateDigestOptions(account, method, params)
|
||||
return request(options)
|
||||
})
|
||||
.then((res) => {
|
||||
const r = JSON.parse(res)
|
||||
if (r.error) throw r.error
|
||||
return r.result
|
||||
})
|
||||
}
|
||||
|
||||
function split (str) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
24
package-lock.json
generated
24
package-lock.json
generated
|
|
@ -16652,6 +16652,22 @@
|
|||
"aggregate-error": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"p-queue": {
|
||||
"version": "6.6.2",
|
||||
"resolved": "https://registry.npmjs.org/p-queue/-/p-queue-6.6.2.tgz",
|
||||
"integrity": "sha512-RwFpb72c/BhQLEXIZ5K2e+AhgNVmIejGlTgiB9MzZ0e93GRvqZ7uSi0dvRF7/XIXDeNkra2fNHBxTyPDGySpjQ==",
|
||||
"requires": {
|
||||
"eventemitter3": "^4.0.4",
|
||||
"p-timeout": "^3.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"eventemitter3": {
|
||||
"version": "4.0.7",
|
||||
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
|
||||
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"p-reduce": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-reduce/-/p-reduce-1.0.0.tgz",
|
||||
|
|
@ -16666,6 +16682,14 @@
|
|||
"retry": "^0.12.0"
|
||||
}
|
||||
},
|
||||
"p-timeout": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
|
||||
"integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
|
||||
"requires": {
|
||||
"p-finally": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"p-try": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
"license": "Unlicense",
|
||||
"author": "Lamassu (https://lamassu.is)",
|
||||
"dependencies": {
|
||||
"@lamassu/coins": "1.0.0-beta.2",
|
||||
"@simplewebauthn/server": "^3.0.0",
|
||||
"apollo-server-express": "2.25.1",
|
||||
"argon2": "0.28.2",
|
||||
|
|
@ -45,7 +46,6 @@
|
|||
"helmet": "^3.8.1",
|
||||
"inquirer": "^5.2.0",
|
||||
"json2csv": "^5.0.3",
|
||||
"@lamassu/coins": "1.0.0-beta.2",
|
||||
"libphonenumber-js": "^1.7.38",
|
||||
"lnd-async": "^1.8.0",
|
||||
"lodash": "^4.17.10",
|
||||
|
|
@ -63,6 +63,7 @@
|
|||
"numeral": "^2.0.3",
|
||||
"otplib": "^12.0.1",
|
||||
"p-each-series": "^1.0.0",
|
||||
"p-queue": "^6.6.2",
|
||||
"p-retry": "^4.4.0",
|
||||
"pg-native": "^3.0.0",
|
||||
"pg-promise": "^10.10.2",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue