Added retry promise in bncController
This commit is contained in:
parent
219cc5185a
commit
e27f5c8df2
|
@ -3,6 +3,8 @@
|
|||
set -e
|
||||
set -v
|
||||
|
||||
docker build -t tss ./src/tss
|
||||
|
||||
./demo/start-environment.sh
|
||||
|
||||
cat ./tests/config.json | jq .users[].ethAddress | xargs -I {} ./src/test-services/ethereumSend/run.sh {} 100
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
const axios = require('axios')
|
||||
|
||||
const { retry } = require('./wait')
|
||||
|
||||
const { FOREIGN_URL, FOREIGN_ASSET } = process.env
|
||||
|
||||
const bnc = axios.create({
|
||||
|
@ -9,21 +11,12 @@ const bnc = axios.create({
|
|||
|
||||
module.exports = {
|
||||
getBalance: async function (address) {
|
||||
try {
|
||||
const response = await bnc.get(`/api/v1/account/${address}`)
|
||||
|
||||
return parseFloat(response.data.balances.find(x => x.symbol === FOREIGN_ASSET).free)
|
||||
} catch (e) {
|
||||
return 0
|
||||
}
|
||||
const response = await retry(5, () => bnc.get(`/api/v1/account/${address}`))
|
||||
const tokens = response.data.balances.find(x => x.symbol === FOREIGN_ASSET)
|
||||
return response && tokens ? parseFloat(tokens.free) : 0
|
||||
},
|
||||
getSequence: async function(address) {
|
||||
try {
|
||||
const response = await bnc.get(`/api/v1/account/${address}/sequence`)
|
||||
|
||||
return response.data.sequence
|
||||
} catch (e) {
|
||||
return 0
|
||||
}
|
||||
getSequence: async function (address) {
|
||||
const response = await retry(5, () => bnc.get(`/api/v1/account/${address}/sequence`))
|
||||
return response ? response.data.sequence : 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,18 @@ async function waitPromise (getPromise, checker) {
|
|||
} while (true)
|
||||
}
|
||||
|
||||
async function retry (n, getPromise) {
|
||||
while (n) {
|
||||
try {
|
||||
return await getPromise()
|
||||
} catch (e) {
|
||||
await delay(3000)
|
||||
n--
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
Array.prototype.seqMap = async function (transition) {
|
||||
const results = []
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
|
@ -21,5 +33,6 @@ Array.prototype.seqMap = async function (transition) {
|
|||
|
||||
module.exports = {
|
||||
waitPromise,
|
||||
delay
|
||||
delay,
|
||||
retry
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue