evernode-js-client 0.4.38 → 0.4.39
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 +36 -4
- package/package.json +1 -1
package/index.js
CHANGED
@@ -11814,9 +11814,9 @@ class BaseEvernodeClient {
|
|
11814
11814
|
|
11815
11815
|
async getHookStates() {
|
11816
11816
|
const regAcc = new XrplAccount(this.registryAddress, null, { xrplApi: this.xrplApi });
|
11817
|
-
const
|
11818
|
-
if (
|
11819
|
-
const configs = await regAcc.getNamespaceEntries(
|
11817
|
+
const hookNamespaces = (await regAcc.getInfo())?.HookNamespaces;
|
11818
|
+
if (hookNamespaces) {
|
11819
|
+
const configs = await regAcc.getNamespaceEntries(hookNamespaces[0]);
|
11820
11820
|
return configs.filter(c => c.LedgerEntryType === 'HookState').map(c => { return { key: c.HookStateKey, data: c.HookStateData } });
|
11821
11821
|
}
|
11822
11822
|
return [];
|
@@ -13503,6 +13503,14 @@ const HOST_CPU_MICROSEC_OFFSET = 64;
|
|
13503
13503
|
const HOST_RAM_MB_OFFSET = 68;
|
13504
13504
|
const HOST_DISK_MB_OFFSET = 72;
|
13505
13505
|
|
13506
|
+
const STATE_KEY_TYPES = {
|
13507
|
+
TOKEN_ID: 2,
|
13508
|
+
HOST_ADDR: 3
|
13509
|
+
}
|
13510
|
+
|
13511
|
+
const EVERNODE_PREFIX = 'EVR';
|
13512
|
+
const HOST_ADDR_KEY_ZERO_COUNT = 8;
|
13513
|
+
|
13506
13514
|
class StateHelpers {
|
13507
13515
|
static StateTypes = {
|
13508
13516
|
TOKEN_ID: 'tokenId',
|
@@ -13535,7 +13543,7 @@ class StateHelpers {
|
|
13535
13543
|
cpuMicrosec: stateDataBuf.readUInt32BE(HOST_CPU_MICROSEC_OFFSET),
|
13536
13544
|
ramMb: stateDataBuf.readUInt32BE(HOST_RAM_MB_OFFSET),
|
13537
13545
|
diskMb: stateDataBuf.readUInt32BE(HOST_DISK_MB_OFFSET)
|
13538
|
-
|
13546
|
+
}
|
13539
13547
|
}
|
13540
13548
|
|
13541
13549
|
static decodeStateData(stateKey, stateData) {
|
@@ -13655,6 +13663,30 @@ class StateHelpers {
|
|
13655
13663
|
else
|
13656
13664
|
throw { type: 'Validation Error', message: 'Invalid state key.' };
|
13657
13665
|
}
|
13666
|
+
|
13667
|
+
static generateTokenIdStateKey(nfTokenId) {
|
13668
|
+
// 1 byte - Key Type.
|
13669
|
+
let buf = Buffer.allocUnsafe(1);
|
13670
|
+
buf.writeUInt8(STATE_KEY_TYPES.TOKEN_ID);
|
13671
|
+
|
13672
|
+
const nfTokenIdBuf = Buffer.from(nfTokenId, "hex");
|
13673
|
+
const stateKeyBuf = (Buffer.concat([Buffer.from(EVERNODE_PREFIX, "utf-8"), buf, nfTokenIdBuf.slice(4, 32)]));
|
13674
|
+
return stateKeyBuf.toString('hex').toUpperCase();
|
13675
|
+
}
|
13676
|
+
|
13677
|
+
static generateHostAddrStateKey(address) {
|
13678
|
+
// 1 byte - Key Type.
|
13679
|
+
// 8 bytes - Zeros.
|
13680
|
+
let buf = Buffer.allocUnsafe(9);
|
13681
|
+
buf.writeUInt8(STATE_KEY_TYPES.HOST_ADDR);
|
13682
|
+
for (let i = 0; i < HOST_ADDR_KEY_ZERO_COUNT; i++) {
|
13683
|
+
buf.writeUInt8(0, i+1);
|
13684
|
+
}
|
13685
|
+
|
13686
|
+
const addrBuf = Buffer.from(codec.decodeAccountID(address), "hex");
|
13687
|
+
const stateKeyBuf = Buffer.concat([Buffer.from(EVERNODE_PREFIX, "utf-8"), buf, addrBuf]);
|
13688
|
+
return stateKeyBuf.toString('hex').toUpperCase();
|
13689
|
+
}
|
13658
13690
|
}
|
13659
13691
|
|
13660
13692
|
module.exports = {
|