diff --git a/installer/jshelper/package-lock.json b/installer/jshelper/package-lock.json index 90e3428..da781ee 100644 --- a/installer/jshelper/package-lock.json +++ b/installer/jshelper/package-lock.json @@ -6,7 +6,7 @@ "": { "name": "evernode-setup-helper", "dependencies": { - "evernode-js-client": "0.6.24", + "evernode-js-client": "0.6.25", "ip6addr": "0.2.5", "ripple-keypairs": "1.3.1" } @@ -364,9 +364,9 @@ } }, "node_modules/evernode-js-client": { - "version": "0.6.24", - "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.6.24.tgz", - "integrity": "sha512-sT7eoN796ueo0+yZl6KpQOzINuXrYW88YlZCm2PxzRqv5G4TqgqUGFgs+GSESkxuVRkw2LBX9WcUCGwbAt6K9g==", + "version": "0.6.25", + "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.6.25.tgz", + "integrity": "sha512-VC+WVCLciuXICaAbwOsl5/xmENYgBaS9UESrUykWS1JZgZ8KlWgIcwJ/AhQSwiGDGk6+6xAh0EMVeBHvMqNb9A==", "dependencies": { "elliptic": "6.5.4", "libsodium-wrappers": "0.7.10", @@ -1543,9 +1543,9 @@ } }, "evernode-js-client": { - "version": "0.6.24", - "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.6.24.tgz", - "integrity": "sha512-sT7eoN796ueo0+yZl6KpQOzINuXrYW88YlZCm2PxzRqv5G4TqgqUGFgs+GSESkxuVRkw2LBX9WcUCGwbAt6K9g==", + "version": "0.6.25", + "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.6.25.tgz", + "integrity": "sha512-VC+WVCLciuXICaAbwOsl5/xmENYgBaS9UESrUykWS1JZgZ8KlWgIcwJ/AhQSwiGDGk6+6xAh0EMVeBHvMqNb9A==", "requires": { "elliptic": "6.5.4", "libsodium-wrappers": "0.7.10", diff --git a/installer/jshelper/package.json b/installer/jshelper/package.json index edd39eb..c04eae7 100644 --- a/installer/jshelper/package.json +++ b/installer/jshelper/package.json @@ -4,7 +4,7 @@ "build": "ncc build index.js --minify -o dist" }, "dependencies": { - "evernode-js-client": "0.6.24", + "evernode-js-client": "0.6.25", "ip6addr": "0.2.5", "ripple-keypairs": "1.3.1" } diff --git a/installer/setup.sh b/installer/setup.sh index 054074e..c620fe1 100755 --- a/installer/setup.sh +++ b/installer/setup.sh @@ -233,8 +233,12 @@ function install_nodejs_utility() { apt-get -y install nodejs } -function check_prereq() { - echomult "\nChecking initial level pre-requisites..." +function check_common_prereq() { + # Check jq command is installed. + if ! command -v jq &>/dev/null; then + echo "jq command not found. Installing.." + apt-get install -y jq >/dev/null + fi if ! command -v node &>/dev/null; then echo "Installing nodejs..." @@ -247,6 +251,12 @@ function check_prereq() { exit 1 fi fi +} + +function check_prereq() { + echomult "\nChecking initial level prerequisites..." + + check_common_prereq # Check bc command is installed. if ! command -v bc &>/dev/null; then @@ -265,12 +275,6 @@ function check_prereq() { echo "qrencode command not found. Installing.." apt-get install -y qrencode >/dev/null fi - - # Check jq command is installed. - if ! command -v jq &>/dev/null; then - echo "jq command not found. Installing.." - apt-get install -y jq >/dev/null - fi } function check_sys_req() { @@ -1612,18 +1616,23 @@ function delete_instance() { [ "$EUID" -ne 0 ] && echo "Please run with root privileges (sudo)." && exit 1 - instance_name=$1 - echo "Deleting instance $instance_name" - ! sudo -u $MB_XRPL_USER MB_DATA_DIR=$MB_XRPL_DATA node $MB_XRPL_BIN delete $instance_name && - echo "There was an error in deleting the instance." && exit 1 - # Restart the message board to update the instance count local mb_user_id=$(id -u "$MB_XRPL_USER") local mb_user_runtime_dir="/run/user/$mb_user_id" - sudo -u "$MB_XRPL_USER" XDG_RUNTIME_DIR="$mb_user_runtime_dir" systemctl --user restart $MB_XRPL_SERVICE + echomult "Stopping the message board..." + sudo -u "$MB_XRPL_USER" XDG_RUNTIME_DIR="$mb_user_runtime_dir" systemctl --user stop $MB_XRPL_SERVICE - echo "Instance deletion completed." + local has_error=0 + instance_name=$1 + echo "Deleting instance $instance_name" + ! sudo -u $MB_XRPL_USER MB_DATA_DIR=$MB_XRPL_DATA node $MB_XRPL_BIN delete $instance_name && + echo "There was an error in deleting the instance." && has_error=1 + + echomult "Starting the message board..." + sudo -u "$MB_XRPL_USER" XDG_RUNTIME_DIR="$mb_user_runtime_dir" systemctl --user start $MB_XRPL_SERVICE + + [ $has_error == 0 ] && echo "Instance deletion completed." } # Begin setup execution flow -------------------- @@ -1765,6 +1774,8 @@ elif [ "$mode" == "transfer" ]; then rippled_server=${6} # Rippled server URL fi + check_common_prereq + set_environment_configs init_setup_helpers diff --git a/mb-xrpl/lib/message-board.js b/mb-xrpl/lib/message-board.js index 334b01f..c36e0e8 100644 --- a/mb-xrpl/lib/message-board.js +++ b/mb-xrpl/lib/message-board.js @@ -91,13 +91,13 @@ class MessageBoard { // Get moment only if heartbeat info is not 0. this.lastHeartbeatMoment = hostInfo.lastHeartbeatIndex ? await this.hostClient.getMoment(hostInfo.lastHeartbeatIndex) : 0; + this.lastValidatedLedgerIndex = this.xrplApi.ledgerIndex; this.db.open(); // Create lease table if not exist. await this.createLeaseTableIfNotExists(); await this.createUtilDataTableIfNotExists(); - this.lastValidatedLedgerIndex = this.xrplApi.ledgerIndex; const leaseRecords = (await this.getLeaseRecords()).filter(r => (r.status === LeaseStatus.ACQUIRED || r.status === LeaseStatus.EXTENDED)); for (const lease of leaseRecords) @@ -657,12 +657,20 @@ class MessageBoard { for (const tx of transactions) { // Skip, if this transaction was previously considered. - const acquireRef = this.#getTrxHookParams(tx, evernode.EventTypes.ACQUIRE_SUCCESS); - if (acquireRef === trx.hash) + const acquireSucRef = this.#getTrxHookParams(tx, evernode.EventTypes.ACQUIRE_SUCCESS); + if (acquireSucRef === trx.hash) continue loop1; - const extendRef = this.#getTrxHookParams(tx, evernode.EventTypes.EXTEND_SUCCESS); - if (extendRef === trx.hash) + const acquireErrRef = this.#getTrxHookParams(tx, evernode.EventTypes.ACQUIRE_ERROR); + if (acquireErrRef === trx.hash) + continue loop1; + + const extendSucRef = this.#getTrxHookParams(tx, evernode.EventTypes.EXTEND_SUCCESS); + if (extendSucRef === trx.hash) + continue loop1; + + const extendErrRef = this.#getTrxHookParams(tx, evernode.EventTypes.EXTEND_ERROR); + if (extendErrRef === trx.hash) continue loop1; const refundRef = this.#getTrxHookParams(tx, evernode.EventTypes.REFUND); @@ -687,7 +695,7 @@ class MessageBoard { if (!lease) { const tenantXrplAcc = new evernode.XrplAccount(eventInfo.data.tenant); - const uriToken = (await tenantXrplAcc.getURITokens()).find(n => evernode.EvernodeHelpers.isValidURI(n.URI, evernode.EvernodeConstants.LEASE_TOKEN_PREFIX_HEX) && n.index === eventInfo.data.uriTokenId); + const uriToken = (await tenantXrplAcc.getURITokens()).find(n => n.Issuer == this.cfg.xrpl.address && evernode.EvernodeHelpers.isValidURI(n.URI, evernode.EvernodeConstants.LEASE_TOKEN_PREFIX_HEX) && n.index === eventInfo.data.uriTokenId); if (uriToken) { const uriInfo = evernode.UtilHelpers.decodeLeaseTokenUri(uriToken.URI); // Have to recreate the URIToken Offer for the lease as previous one was not utilized. @@ -708,7 +716,7 @@ class MessageBoard { if (lease) { const tenantXrplAcc = new evernode.XrplAccount(eventInfo.data.tenant); - const uriToken = (await tenantXrplAcc.getURITokens()).find(n => evernode.EvernodeHelpers.isValidURI(n.URI, evernode.EvernodeConstants.LEASE_TOKEN_PREFIX_HEX) && n.index === eventInfo.data.uriTokenId); + const uriToken = (await tenantXrplAcc.getURITokens()).find(n => n.Issuer == this.cfg.xrpl.address && evernode.EvernodeHelpers.isValidURI(n.URI, evernode.EvernodeConstants.LEASE_TOKEN_PREFIX_HEX) && n.index === eventInfo.data.uriTokenId); if (uriToken) { await this.#queueAction(async () => { // The refund for the extension, if tenant still own the URIToken. @@ -1009,7 +1017,7 @@ class MessageBoard { async createLastWatchedLedgerEntryIfNotExists() { const ret = await this.db.getValues(this.utilTable, { name: appenv.LAST_WATCHED_LEDGER }); if (ret.length === 0) { - await this.db.insertValue(this.utilTable, { name: appenv.LAST_WATCHED_LEDGER, value: -1 }); + await this.db.insertValue(this.utilTable, { name: appenv.LAST_WATCHED_LEDGER, value: this.lastValidatedLedgerIndex }); } } diff --git a/mb-xrpl/lib/setup.js b/mb-xrpl/lib/setup.js index 031f99e..0d10ca3 100644 --- a/mb-xrpl/lib/setup.js +++ b/mb-xrpl/lib/setup.js @@ -283,7 +283,7 @@ class Setup { .map(o => { return { uriTokenId: o.index, ownerAddress: xrplAcc.address }; }); // Get sold URITokens. - // We check for db existance since db is created by message board (not setup). + // We check for db existence since db is created by message board (not setup). const dbPath = appenv.DB_PATH; if (fs.existsSync(dbPath)) { // This local initialization can be changed according to the DB access requirement. @@ -293,7 +293,7 @@ class Setup { db.open(); try { - // We check for table existance since table is created by message board (not setup). + // We check for table existence since table is created by message board (not setup). if (db.isTableExists(leaseTable)) { uriTokens.push(...(await db.getValues(leaseTable)).filter(i => (i.status === "Acquired" || i.status === "Extended")) .map(o => { return { uriTokenId: o.container_name, ownerAddress: o.tenant_xrp_address }; })) diff --git a/mb-xrpl/package-lock.json b/mb-xrpl/package-lock.json index e3ef0be..332894d 100644 --- a/mb-xrpl/package-lock.json +++ b/mb-xrpl/package-lock.json @@ -6,7 +6,7 @@ "": { "name": "mb-xrpl", "dependencies": { - "evernode-js-client": "0.6.24", + "evernode-js-client": "0.6.25", "ip6addr": "0.2.5", "sqlite3": "5.0.2" }, @@ -980,9 +980,9 @@ } }, "node_modules/evernode-js-client": { - "version": "0.6.24", - "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.6.24.tgz", - "integrity": "sha512-sT7eoN796ueo0+yZl6KpQOzINuXrYW88YlZCm2PxzRqv5G4TqgqUGFgs+GSESkxuVRkw2LBX9WcUCGwbAt6K9g==", + "version": "0.6.25", + "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.6.25.tgz", + "integrity": "sha512-VC+WVCLciuXICaAbwOsl5/xmENYgBaS9UESrUykWS1JZgZ8KlWgIcwJ/AhQSwiGDGk6+6xAh0EMVeBHvMqNb9A==", "dependencies": { "elliptic": "6.5.4", "libsodium-wrappers": "0.7.10", @@ -4010,9 +4010,9 @@ "dev": true }, "evernode-js-client": { - "version": "0.6.24", - "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.6.24.tgz", - "integrity": "sha512-sT7eoN796ueo0+yZl6KpQOzINuXrYW88YlZCm2PxzRqv5G4TqgqUGFgs+GSESkxuVRkw2LBX9WcUCGwbAt6K9g==", + "version": "0.6.25", + "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.6.25.tgz", + "integrity": "sha512-VC+WVCLciuXICaAbwOsl5/xmENYgBaS9UESrUykWS1JZgZ8KlWgIcwJ/AhQSwiGDGk6+6xAh0EMVeBHvMqNb9A==", "requires": { "elliptic": "6.5.4", "libsodium-wrappers": "0.7.10", diff --git a/mb-xrpl/package.json b/mb-xrpl/package.json index 086e03a..9d14c09 100644 --- a/mb-xrpl/package.json +++ b/mb-xrpl/package.json @@ -5,7 +5,7 @@ "build": "npm run lint && ncc build app.js --minify -o dist" }, "dependencies": { - "evernode-js-client": "0.6.24", + "evernode-js-client": "0.6.25", "sqlite3": "5.0.2", "ip6addr": "0.2.5" },