Skip to content

Commit d118ff6

Browse files
committed
Only retry failed creation of fwa wallet
1 parent 767f738 commit d118ff6

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

easy-indysdk/src/indy-errors.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
'use strict'
1818

19-
const indyErrorCodeWalletItemNotFound = '212'
19+
const indyErrorWalletItemNotFound = {
20+
indyCode: 212,
21+
indyName: 'WalletItemNotFound',
22+
}
2023

21-
module.exports = { indyErrorCodeWalletItemNotFound }
24+
module.exports = { indyErrorWalletItemNotFound }

easy-indysdk/src/wallet.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
const indy = require('indy-sdk')
2020
const os = require('os')
21-
const { indyErrorCodeWalletItemNotFound } = require('./indy-errors')
21+
const { indyErrorWalletItemNotFound } = require('./indy-errors')
2222

2323
const extension = { darwin: '.dylib', linux: '.so', win32: '.dll' }
2424
const libPath = { darwin: '/usr/local/lib/', linux: '/usr/lib/', win32: 'c:\\windows\\system32\\' }
@@ -132,7 +132,7 @@ async function indyDidExists (wh, did) {
132132
try {
133133
await indy.getMyDidWithMeta(wh, did)
134134
} catch (err) {
135-
if (err.message === indyErrorCodeWalletItemNotFound) {
135+
if (err.indyName === indyErrorWalletItemNotFound.indyName) {
136136
return false
137137
} else {
138138
throw err

vcxagency-node/src/service/entities/fwa/entity-fwa.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@ const sleep = require('sleep-promise')
3535
const FWA_KDF = 'ARGON2I_MOD'
3636

3737
async function assureFwaWalletWasSetUp (serviceIndyWallets, agencyWalletName, agencyWalletKey, agencyDid, agencySeed) {
38-
logger.info(`FWA Assuring its wallet '${agencyWalletName}' exists`)
39-
await serviceIndyWallets.assureWallet(agencyWalletName, agencyWalletKey, FWA_KDF)
40-
4138
logger.info(`Getting '${agencyWalletName}' wallet handle.`)
4239
const wh = await serviceIndyWallets.getWalletHandle(agencyWalletName, agencyWalletKey, FWA_KDF)
40+
logger.info(`Checking if agency did ${agencyDid} exists in wallet`)
4341
const agencyDidWasSetUp = await indyDidExists(wh, agencyDid)
4442
if (!agencyDidWasSetUp) {
4543
logger.info(`Agency DID '${agencyDid}' not found in wallet. Creating.`)
4644
await indyCreateAndStoreMyDid(wh, agencyDid, agencySeed)
4745
logger.debug(`Forward agent create ${agencyDid}`)
46+
} else {
47+
logger.info(`Agency DID '${agencyDid}' was found in wallet.`)
4848
}
49+
4950
const agencyVerkey = await indyKeyForLocalDid(wh, agencyDid)
5051
logger.info(`Agency DID '${agencyWalletName}' has assigned verkey ${agencyVerkey}`)
5152
return agencyVerkey
@@ -60,17 +61,19 @@ async function assureFwaWalletWasSetUp (serviceIndyWallets, agencyWalletName, ag
6061
* This is design trade off to have simple singleton.
6162
*/
6263
async function buildForwardAgent (serviceIndyWallets, serviceStorage, agencyWalletName, agencyWalletKey, agencyDid, agencySeed, waitTime = 1000, attempts = 10) {
63-
let router, resolver, agencyVerkey
64+
let router, resolver
6465

6566
for (let attempt = 0; attempt < attempts; attempt++) {
6667
try {
67-
agencyVerkey = await assureFwaWalletWasSetUp(serviceIndyWallets, agencyWalletName, agencyWalletKey, agencyDid, agencySeed)
68+
logger.info(`FWA Assuring its wallet '${agencyWalletName}' exists`)
69+
await serviceIndyWallets.assureWallet(agencyWalletName, agencyWalletKey, FWA_KDF)
6870
break
6971
} catch (err) {
70-
console.warn(`Failed to build FWA agent: ${err}\nRemaining attempts: ${attempts - attempt - 1}`)
72+
logger.warn(`Failed to assure FWA wallet due to error ${err.stack}. Remaining attempts: ${attempts - attempt - 1}`)
7173
await sleep(waitTime)
7274
}
7375
}
76+
const agencyVerkey = await assureFwaWalletWasSetUp(serviceIndyWallets, agencyWalletName, agencyWalletKey, agencyDid, agencySeed)
7477

7578
const whoami = `[ForwardAgent ${agencyDid}]`
7679

vcxagency-node/src/service/storage/redis-client-builder.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,31 @@ module.exports.buildRedisClients = function buildRedisClients (redisUrl) {
88
redisClientRw.on('error', function (err) {
99
logger.error(`Redis rw-client encountered error: ${err}`)
1010
})
11+
1112
redisClientSubscriber.on('error', function (err) {
1213
logger.error(`Redis subscription-client encountered error: ${err}`)
1314
})
1415

1516
redisClientRw.on('end', () => {
16-
console.log('Redis rw-client disconnected')
17+
logger.warn('Redis rw-client disconnected')
1718
})
19+
1820
redisClientSubscriber.on('end', () => {
19-
console.log('Redis subscription-client disconnected')
21+
logger.warn('Redis subscription-client disconnected')
2022
})
2123

2224
redisClientRw.on('reconnecting', () => {
23-
console.log('Redis rw-client reconnecting')
25+
logger.warn('Redis rw-client reconnecting')
2426
})
2527

2628
redisClientSubscriber.on('reconnecting', () => {
27-
console.log('Redis subscription-client reconnecting')
29+
logger.warn('Redis subscription-client reconnecting')
2830
})
2931

3032
redisClientRw.on('connect', function () {
3133
logger.info('Redis rw-client connected.')
3234
})
35+
3336
redisClientSubscriber.on('connect', function () {
3437
logger.info('Redis subscription-client connected.')
3538
})

0 commit comments

Comments
 (0)