evernode-js-client 0.4.47 → 0.4.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +24 -15
- 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
|
12066
|
-
const
|
12067
|
-
const
|
12068
|
-
const
|
12069
|
-
if (
|
12070
|
-
const
|
12071
|
-
const
|
12072
|
-
|
12073
|
-
(
|
12074
|
-
(
|
12075
|
-
|
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 = '
|
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),
|