evernode-js-client 0.4.46 → 0.4.47

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +19 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -12061,17 +12061,24 @@ class BaseEvernodeClient {
12061
12061
 
12062
12062
  // To get Host details from Hook States.
12063
12063
  async getHostInfo(hostAddress = this.xrplAcc.address) {
12064
- const hostAddrStatekey = StateHelpers.generateHostAddrStateKey(hostAddress);
12065
- const stateLedgerIndex = StateHelpers.getHookStateIndex(this.registryAddress, hostAddrStatekey);
12066
- const ledgerEntry = await this.xrplApi.getLedgerEntry(stateLedgerIndex);
12067
- const curMomentStartIdx = await this.getMomentStartIndex();
12068
- if (ledgerEntry?.HookStateData) {
12069
- const hostAddrStateData = ledgerEntry.HookStateData;
12070
- const hostInfo = StateHelpers.decodeHostAddressState(Buffer.from(hostAddrStatekey, 'hex'), Buffer.from(hostAddrStateData, 'hex'));
12071
- hostInfo.active = (hostInfo.lastHeartbeatLedger > (this.config.hostHeartbeatFreq * this.config.momentSize) ?
12072
- (hostInfo.lastHeartbeatLedger >= (curMomentStartIdx - (this.config.hostHeartbeatFreq * this.config.momentSize))) :
12073
- (hostInfo.lastHeartbeatLedger > 0))
12074
- return hostInfo;
12064
+ try {
12065
+ const hostAddrStatekey = StateHelpers.generateHostAddrStateKey(hostAddress);
12066
+ const stateLedgerIndex = StateHelpers.getHookStateIndex(this.registryAddress, hostAddrStatekey);
12067
+ const ledgerEntry = await this.xrplApi.getLedgerEntry(stateLedgerIndex);
12068
+ const curMomentStartIdx = await this.getMomentStartIndex();
12069
+ if (ledgerEntry?.HookStateData) {
12070
+ const hostAddrStateData = ledgerEntry.HookStateData;
12071
+ const hostInfo = StateHelpers.decodeHostAddressState(Buffer.from(hostAddrStatekey, 'hex'), Buffer.from(hostAddrStateData, 'hex'));
12072
+ hostInfo.active = (hostInfo.lastHeartbeatLedger > (this.config.hostHeartbeatFreq * this.config.momentSize) ?
12073
+ (hostInfo.lastHeartbeatLedger >= (curMomentStartIdx - (this.config.hostHeartbeatFreq * this.config.momentSize))) :
12074
+ (hostInfo.lastHeartbeatLedger > 0))
12075
+ return hostInfo;
12076
+ }
12077
+ }
12078
+ catch (e) {
12079
+ // If the exeption is entryNotFound from Rippled there's no entry for the host, So return null.
12080
+ if (e?.data?.error !== 'entryNotFound')
12081
+ throw e;
12075
12082
  }
12076
12083
 
12077
12084
  return null;
@@ -14798,7 +14805,7 @@ class XrplApi {
14798
14805
 
14799
14806
  async getLedgerEntry(index, options) {
14800
14807
  const resp = (await this.#client.request({ command: 'ledger_entry', index: index, ledger_index: "validated", ...options }));
14801
- return resp?.result?.node;
14808
+ return resp?.result?.node;
14802
14809
  }
14803
14810
 
14804
14811
  async submitAndVerify(tx, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evernode-js-client",
3
- "version": "0.4.46",
3
+ "version": "0.4.47",
4
4
  "dependencies": {
5
5
  "elliptic": "6.5.4",
6
6
  "ripple-address-codec": "4.2.0",