evernode-js-client 0.4.47 → 0.4.48

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 +24 -15
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -12062,17 +12062,26 @@ class BaseEvernodeClient {
12062
12062
  // To get Host details from Hook States.
12063
12063
  async getHostInfo(hostAddress = this.xrplAcc.address) {
12064
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;
12065
+ const addrStateKey = StateHelpers.generateHostAddrStateKey(hostAddress);
12066
+ const addrStateIndex = StateHelpers.getHookStateIndex(this.registryAddress, addrStateKey);
12067
+ const addrLedgerEntry = await this.xrplApi.getLedgerEntry(addrStateIndex);
12068
+ const addrStateData = addrLedgerEntry?.HookStateData;
12069
+ if (addrStateData) {
12070
+ const addrStateDecoded = StateHelpers.decodeHostAddressState(Buffer.from(addrStateKey, 'hex'), Buffer.from(addrStateData, 'hex'));
12071
+ const curMomentStartIdx = await this.getMomentStartIndex();
12072
+ addrStateDecoded.active = (addrStateDecoded.lastHeartbeatLedger > (this.config.hostHeartbeatFreq * this.config.momentSize) ?
12073
+ (addrStateDecoded.lastHeartbeatLedger >= (curMomentStartIdx - (this.config.hostHeartbeatFreq * this.config.momentSize))) :
12074
+ (addrStateDecoded.lastHeartbeatLedger > 0))
12075
+
12076
+ const nftIdStatekey = StateHelpers.generateTokenIdStateKey(addrStateDecoded.nfTokenId);
12077
+ const nftIdStateIndex = StateHelpers.getHookStateIndex(this.registryAddress, nftIdStatekey);
12078
+ const nftIdLedgerEntry = await this.xrplApi.getLedgerEntry(nftIdStateIndex);
12079
+
12080
+ const nftIdStateData = nftIdLedgerEntry?.HookStateData;
12081
+ if (nftIdStateData) {
12082
+ const nftIdStateDecoded = StateHelpers.decodeTokenIdState(Buffer.from(nftIdStateData, 'hex'));
12083
+ return {...addrStateDecoded, ...nftIdStateDecoded};
12084
+ }
12076
12085
  }
12077
12086
  }
12078
12087
  catch (e) {
@@ -12628,9 +12637,9 @@ class TenantClient extends BaseEvernodeClient {
12628
12637
 
12629
12638
  // Check whether active.
12630
12639
  const hostInfo = await this.getHostInfo(host.address);
12631
- if (hostInfo)
12640
+ if (!hostInfo)
12632
12641
  throw { reason: ErrorReasons.HOST_INVALID, error: "Host is not registered." };
12633
- else if (hostInfo.active)
12642
+ else if (!hostInfo.active)
12634
12643
  throw { reason: ErrorReasons.HOST_INACTIVE, error: "Host is not active." };
12635
12644
 
12636
12645
  return host;
@@ -13615,7 +13624,7 @@ const { HookStateKeys, EvernodeConstants } = __nccwpck_require__(9849);
13615
13624
  const { XflHelpers } = __nccwpck_require__(3243);
13616
13625
  const crypto = __nccwpck_require__(6113);
13617
13626
 
13618
- const NFTOKEN_PREFIX = '00080000';
13627
+ const NFTOKEN_PREFIX = '00000000';
13619
13628
 
13620
13629
  const HOST_TOKEN_ID_OFFSET = 0;
13621
13630
  const HOST_COUNTRY_CODE_OFFSET = 32;
@@ -13671,7 +13680,7 @@ class StateHelpers {
13671
13680
  static decodeTokenIdState(stateDataBuf) {
13672
13681
  return {
13673
13682
  address: codec.encodeAccountID(stateDataBuf.slice(HOST_ADDRESS_OFFSET, HOST_CPU_MODEL_NAME_OFFSET)),
13674
- cpuModelName: stateDataBuf.slice(HOST_CPU_MODEL_NAME_OFFSET, HOST_CPU_COUNT_OFFSET).toString(),
13683
+ cpuModelName: stateDataBuf.slice(HOST_CPU_MODEL_NAME_OFFSET, HOST_CPU_COUNT_OFFSET).toString().replace(/\x00+$/, ''), // Remove trailing \x00 characters.
13675
13684
  cpuCount: stateDataBuf.readUInt16BE(HOST_CPU_COUNT_OFFSET),
13676
13685
  cpuMHz: stateDataBuf.readUInt16BE(HOST_CPU_SPEED_OFFSET),
13677
13686
  cpuMicrosec: stateDataBuf.readUInt32BE(HOST_CPU_MICROSEC_OFFSET),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evernode-js-client",
3
- "version": "0.4.47",
3
+ "version": "0.4.48",
4
4
  "dependencies": {
5
5
  "elliptic": "6.5.4",
6
6
  "ripple-address-codec": "4.2.0",