From 170f429d8ff87f976ecbcb3356df3b56a046b060 Mon Sep 17 00:00:00 2001 From: Kithmini Gunawardhana Date: Fri, 2 Dec 2022 13:03:03 +0530 Subject: [PATCH] Transfer process bug fixes (#209) --- mb-xrpl/app.js | 3 +-- mb-xrpl/lib/setup.js | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/mb-xrpl/app.js b/mb-xrpl/app.js index 829daaa..5c1e85a 100644 --- a/mb-xrpl/app.js +++ b/mb-xrpl/app.js @@ -36,8 +36,7 @@ async function main() { parseInt(process.argv[6]), parseInt(process.argv[7]), parseInt(process.argv[8]), process.argv[9], parseInt(process.argv[10]), parseInt(process.argv[11]), process.argv[12]); } else if (process.argv.length >= 3 && process.argv[2] === 'transfer') { - const transfereeAddress = (process.argv[3]) ? process.argv[3] : null; - await new Setup().transfer(transfereeAddress); + (process.argv[3]) ? await new Setup().transfer(process.argv[3]) : await new Setup().transfer(); } else if (process.argv.length === 3 && process.argv[2] === 'deregister') { await new Setup().deregister(); diff --git a/mb-xrpl/lib/setup.js b/mb-xrpl/lib/setup.js index 449e88e..f183b59 100644 --- a/mb-xrpl/lib/setup.js +++ b/mb-xrpl/lib/setup.js @@ -185,8 +185,25 @@ class Setup { const hostClient = new evernode.HostClient(acc.address, acc.secret); await hostClient.connect(); - if (hostClient.config.hostRegFee > (await hostClient.getEVRBalance())) + let isAReReg = false; + + try { + // Check the availability of an initiated transfer + const stateTransfereeAddrKey = evernode.StateHelpers.generateTransfereeAddrStateKey(acc.address); + const stateTransfereeAddrIndex = evernode.StateHelpers.getHookStateIndex(acc.registryAddress, stateTransfereeAddrKey); + const res = await hostClient.xrplApi.getLedgerEntry(stateTransfereeAddrIndex); + + if (res && res?.HookStateData) + isAReReg = true; + } + catch (e) { + console.log('Error occurred in getting the ledger entires'); + } + + if (!isAReReg && hostClient.config.hostRegFee > (await hostClient.getEVRBalance())) throw `EVR balance in the account is less than the registration fee (${hostClient.config.hostRegFee}EVRs).`; + else if (isAReReg && ((await hostClient.getEVRBalance()) < parseFloat(evernode.EvernodeConstants.NOW_IN_EVRS))) + throw `EVR balance in the account is less than 1 Now for the re-registration.`; // Sometimes we may get 'tecPATH_DRY' error from rippled when some servers in the testnet cluster // haven't still updated the ledger. In such cases, we retry several times before giving up. @@ -325,6 +342,7 @@ class Setup { await hostClient.connect(); await hostClient.transfer(transfereeAddress); await this.burnMintedNfts(hostClient.xrplAcc); + await hostClient.disconnect(); } // Change the message board configurations.