evernode-js-client 0.4.48 → 0.4.50

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.
Files changed (2) hide show
  1. package/index.js +124 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -11708,7 +11708,7 @@ const codec = __nccwpck_require__(597);
11708
11708
  const { Buffer } = __nccwpck_require__(4300);
11709
11709
  const { XrplApi } = __nccwpck_require__(1850);
11710
11710
  const { XrplAccount } = __nccwpck_require__(9329);
11711
- const { XrplApiEvents } = __nccwpck_require__(3307);
11711
+ const { XrplApiEvents, XrplConstants } = __nccwpck_require__(3307);
11712
11712
  const { EvernodeEvents, MemoTypes, MemoFormats, EvernodeConstants, HookStateKeys } = __nccwpck_require__(9849);
11713
11713
  const { DefaultValues } = __nccwpck_require__(8262);
11714
11714
  const { EncryptionHelper } = __nccwpck_require__(4832);
@@ -12055,6 +12055,19 @@ class BaseEvernodeClient {
12055
12055
  }
12056
12056
  }
12057
12057
  }
12058
+ else if (tx.Memos.length >= 1 &&
12059
+ tx.Memos[0].type === MemoTypes.DEAD_HOST_PRUNE && tx.Memos[0].format === MemoFormats.HEX && tx.Memos[0].data) {
12060
+
12061
+ const addrsBuf = Buffer.from(tx.Memos[0].data, 'hex');
12062
+
12063
+ return {
12064
+ name: EvernodeEvents.DeadHostPrune,
12065
+ data: {
12066
+ transaction: tx,
12067
+ host: codec.encodeAccountID(addrsBuf)
12068
+ }
12069
+ }
12070
+ }
12058
12071
 
12059
12072
  return null;
12060
12073
  }
@@ -12076,11 +12089,11 @@ class BaseEvernodeClient {
12076
12089
  const nftIdStatekey = StateHelpers.generateTokenIdStateKey(addrStateDecoded.nfTokenId);
12077
12090
  const nftIdStateIndex = StateHelpers.getHookStateIndex(this.registryAddress, nftIdStatekey);
12078
12091
  const nftIdLedgerEntry = await this.xrplApi.getLedgerEntry(nftIdStateIndex);
12079
-
12092
+
12080
12093
  const nftIdStateData = nftIdLedgerEntry?.HookStateData;
12081
12094
  if (nftIdStateData) {
12082
12095
  const nftIdStateDecoded = StateHelpers.decodeTokenIdState(Buffer.from(nftIdStateData, 'hex'));
12083
- return {...addrStateDecoded, ...nftIdStateDecoded};
12096
+ return { ...addrStateDecoded, ...nftIdStateDecoded };
12084
12097
  }
12085
12098
  }
12086
12099
  }
@@ -12145,6 +12158,22 @@ class BaseEvernodeClient {
12145
12158
 
12146
12159
  return fullHostList;
12147
12160
  }
12161
+
12162
+ // To prune an inactive host/
12163
+ async pruneDeadHost(hostAddress) {
12164
+ if (this.xrplAcc.address === this.registryAddress)
12165
+ throw 'Invalid function call';
12166
+
12167
+ let memoData = Buffer.allocUnsafe(20);
12168
+ codec.decodeAccountID(hostAddress).copy(memoData);
12169
+
12170
+ await this.xrplAcc.makePayment(this.registryAddress,
12171
+ XrplConstants.MIN_XRP_AMOUNT,
12172
+ XrplConstants.XRP,
12173
+ null,
12174
+ [{ type: MemoTypes.DEAD_HOST_PRUNE, format: MemoFormats.HEX, data: memoData.toString('hex') }]);
12175
+
12176
+ }
12148
12177
  }
12149
12178
 
12150
12179
  module.exports = {
@@ -12529,7 +12558,8 @@ const RegistryEvents = {
12529
12558
  HostRegUpdated: EvernodeEvents.HostRegUpdated,
12530
12559
  RegistryInitialized: EvernodeEvents.RegistryInitialized,
12531
12560
  Heartbeat: EvernodeEvents.Heartbeat,
12532
- HostPostDeregistered: EvernodeEvents.HostPostDeregistered
12561
+ HostPostDeregistered: EvernodeEvents.HostPostDeregistered,
12562
+ DeadHostPrune: EvernodeEvents.DeadHostPrune
12533
12563
  }
12534
12564
 
12535
12565
  class RegistryClient extends BaseEvernodeClient {
@@ -13194,7 +13224,8 @@ const MemoTypes = {
13194
13224
  EXTEND_REF: 'evnExtendRef',
13195
13225
  REGISTRY_INIT: 'evnInitialize',
13196
13226
  REFUND: 'evnRefund',
13197
- REFUND_REF: 'evnRefundRef'
13227
+ REFUND_REF: 'evnRefundRef',
13228
+ DEAD_HOST_PRUNE: 'evnDeadHostPrune'
13198
13229
  }
13199
13230
 
13200
13231
  const MemoFormats = {
@@ -13232,11 +13263,15 @@ const HookStateKeys = {
13232
13263
  HOST_HEARTBEAT_FREQ: "4556520100000000000000000000000000000000000000000000000000000006",
13233
13264
  PURCHASER_TARGET_PRICE: "4556520100000000000000000000000000000000000000000000000000000007",
13234
13265
  LEASE_ACQUIRE_WINDOW: "4556520100000000000000000000000000000000000000000000000000000008",
13266
+ REWARD_CONFIGURATION: "4556520100000000000000000000000000000000000000000000000000000009",
13267
+ MAX_TOLERABLE_DOWNTIME: "455652010000000000000000000000000000000000000000000000000000000A",
13268
+
13235
13269
  // Singleton
13236
13270
  HOST_COUNT: "4556523200000000000000000000000000000000000000000000000000000000",
13237
13271
  MOMENT_BASE_IDX: "4556523300000000000000000000000000000000000000000000000000000000",
13238
13272
  HOST_REG_FEE: "4556523400000000000000000000000000000000000000000000000000000000",
13239
13273
  MAX_REG: "4556523500000000000000000000000000000000000000000000000000000000",
13274
+ REWARD_INFO: "4556523600000000000000000000000000000000000000000000000000000000",
13240
13275
 
13241
13276
  // Prefixes
13242
13277
  PREFIX_HOST_TOKENID: "45565202",
@@ -13256,7 +13291,8 @@ const EvernodeEvents = {
13256
13291
  ExtendError: "ExtendError",
13257
13292
  HostRegUpdated: "HostRegUpdated",
13258
13293
  HostReRegistered: "HostReRegistered",
13259
- RegistryInitialized: "RegistryInitialized"
13294
+ RegistryInitialized: "RegistryInitialized",
13295
+ DeadHostPrune: "DeadHostPrune"
13260
13296
  }
13261
13297
 
13262
13298
  module.exports = {
@@ -13329,6 +13365,13 @@ class FirestoreHandler {
13329
13365
  case 'floatValue':
13330
13366
  parsed = parseFloat(value[type]);
13331
13367
  break;
13368
+ case 'mapValue':
13369
+ parsed = {};
13370
+ for (const [subKey, subValue] of Object.entries(value[type].fields)) {
13371
+ const field = this.#parseValue(subKey, subValue);
13372
+ parsed[field.key] = field.value;
13373
+ }
13374
+ break;
13332
13375
  default:
13333
13376
  parsed = value[type];
13334
13377
  break;
@@ -13536,9 +13579,32 @@ class FirestoreHandler {
13536
13579
  convertValue(key, value) {
13537
13580
  // Convert camelCase to snake_case.
13538
13581
  const uKey = key.replace(/([A-Z])/g, function (g) { return `_${g[0].toLocaleLowerCase()}`; });
13539
- const type = `${typeof value !== 'number' ? 'string' : (value % 1 > 0 ? 'float' : 'integer')}Value`;
13582
+ let val = {};
13583
+ let type
13584
+ switch (typeof value) {
13585
+ case 'number':
13586
+ type = (value % 1 > 0 ? 'float' : 'integer');
13587
+ val = value;
13588
+ break;
13589
+ case 'object':
13590
+ type = 'map';
13591
+ val = {
13592
+ fields: {}
13593
+ }
13594
+ // Prepare the firestore write body with the given data object.
13595
+ for (const [subKey, subValue] of Object.entries(value)) {
13596
+ const field = this.convertValue(subKey, subValue);
13597
+ val.fields[field.key] = field.value;
13598
+ }
13599
+ break;
13600
+ default:
13601
+ type = 'string';
13602
+ val = value;
13603
+ break;
13604
+ }
13605
+ type = `${type}Value`;
13540
13606
  let obj = {};
13541
- obj[type] = value;
13607
+ obj[type] = val;
13542
13608
  return { key: uKey, value: obj };
13543
13609
  }
13544
13610
 
@@ -13626,6 +13692,17 @@ const crypto = __nccwpck_require__(6113);
13626
13692
 
13627
13693
  const NFTOKEN_PREFIX = '00000000';
13628
13694
 
13695
+ const EPOCH_OFFSET = 0;
13696
+ const SAVED_MOMENT_OFFSET = 1;
13697
+ const PREV_MOMENT_ACTIVE_HOST_COUNT_OFFSET = 5;
13698
+ const CUR_MOMENT_ACTIVE_HOST_COUNT_OFFSET = 9;
13699
+ const EPOCH_POOL_OFFSET = 13;
13700
+
13701
+ const EPOCH_COUNT_OFFSET = 0;
13702
+ const FIRST_EPOCH_REWARD_QUOTA_OFFSET = 1;
13703
+ const EPOCH_REWARD_AMOUNT_OFFSET = 5;
13704
+ const REWARD_START_MOMENT_OFFSET = 9;
13705
+
13629
13706
  const HOST_TOKEN_ID_OFFSET = 0;
13630
13707
  const HOST_COUNTRY_CODE_OFFSET = 32;
13631
13708
  const HOST_RESERVED_OFFSET = 34;
@@ -13763,6 +13840,38 @@ class StateHelpers {
13763
13840
  value: val
13764
13841
  }
13765
13842
  }
13843
+ else if (Buffer.from(HookStateKeys.REWARD_CONFIGURATION, 'hex').compare(stateKey) === 0) {
13844
+ return {
13845
+ type: this.StateTypes.CONFIGURATION,
13846
+ key: hexKey,
13847
+ value: {
13848
+ epochCount: stateData.readUInt8(EPOCH_COUNT_OFFSET),
13849
+ firstEpochRewardQuota: stateData.readUInt32BE(FIRST_EPOCH_REWARD_QUOTA_OFFSET),
13850
+ epochRewardAmount: stateData.readUInt32BE(EPOCH_REWARD_AMOUNT_OFFSET),
13851
+ rewardStartMoment: stateData.readUInt32BE(REWARD_START_MOMENT_OFFSET)
13852
+ }
13853
+ }
13854
+ }
13855
+ else if (Buffer.from(HookStateKeys.REWARD_INFO, 'hex').compare(stateKey) === 0) {
13856
+ return {
13857
+ type: this.StateTypes.SIGLETON,
13858
+ key: hexKey,
13859
+ value: {
13860
+ epoch: stateData.readUInt8(EPOCH_OFFSET),
13861
+ savedMoment: stateData.readUInt32BE(SAVED_MOMENT_OFFSET),
13862
+ prevMomentActiveHostCount: stateData.readUInt32BE(PREV_MOMENT_ACTIVE_HOST_COUNT_OFFSET),
13863
+ curMomentActiveHostCount: stateData.readUInt32BE(CUR_MOMENT_ACTIVE_HOST_COUNT_OFFSET),
13864
+ epochPool: XflHelpers.toString(stateData.readBigInt64BE(EPOCH_POOL_OFFSET))
13865
+ }
13866
+ }
13867
+ }
13868
+ else if (Buffer.from(HookStateKeys.MAX_TOLERABLE_DOWNTIME, 'hex').compare(stateKey) === 0) {
13869
+ return {
13870
+ type: this.StateTypes.CONFIGURATION,
13871
+ key: hexKey,
13872
+ value: stateData.readUInt16BE()
13873
+ }
13874
+ }
13766
13875
  else
13767
13876
  throw { type: 'Validation Error', message: 'Invalid state key.' };
13768
13877
  }
@@ -13784,7 +13893,8 @@ class StateHelpers {
13784
13893
  else if (Buffer.from(HookStateKeys.HOST_COUNT, 'hex').compare(stateKey) === 0 ||
13785
13894
  Buffer.from(HookStateKeys.MOMENT_BASE_IDX, 'hex').compare(stateKey) === 0 ||
13786
13895
  Buffer.from(HookStateKeys.HOST_REG_FEE, 'hex').compare(stateKey) === 0 ||
13787
- Buffer.from(HookStateKeys.MAX_REG, 'hex').compare(stateKey) === 0) {
13896
+ Buffer.from(HookStateKeys.MAX_REG, 'hex').compare(stateKey) === 0 ||
13897
+ Buffer.from(HookStateKeys.REWARD_INFO, 'hex').compare(stateKey) === 0) {
13788
13898
  return {
13789
13899
  key: hexKey,
13790
13900
  type: this.STATE_TYPES.SIGLETON
@@ -13797,7 +13907,9 @@ class StateHelpers {
13797
13907
  Buffer.from(HookStateKeys.HOST_HEARTBEAT_FREQ, 'hex').compare(stateKey) ||
13798
13908
  Buffer.from(HookStateKeys.MINT_LIMIT, 'hex').compare(stateKey) === 0 ||
13799
13909
  Buffer.from(HookStateKeys.FIXED_REG_FEE, 'hex').compare(stateKey) === 0 ||
13800
- Buffer.from(HookStateKeys.LEASE_ACQUIRE_WINDOW, 'hex').compare(stateKey) === 0) {
13910
+ Buffer.from(HookStateKeys.LEASE_ACQUIRE_WINDOW, 'hex').compare(stateKey) === 0 ||
13911
+ Buffer.from(HookStateKeys.REWARD_CONFIGURATION, 'hex').compare(stateKey) === 0 ||
13912
+ Buffer.from(HookStateKeys.MAX_TOLERABLE_DOWNTIME, 'hex').compare(stateKey) === 0) {
13801
13913
  return {
13802
13914
  key: hexKey,
13803
13915
  type: this.STATE_TYPES.CONFIGURATION
@@ -13823,7 +13935,7 @@ class StateHelpers {
13823
13935
  let buf = Buffer.allocUnsafe(9);
13824
13936
  buf.writeUInt8(STATE_KEY_TYPES.HOST_ADDR);
13825
13937
  for (let i = 0; i < HOST_ADDR_KEY_ZERO_COUNT; i++) {
13826
- buf.writeUInt8(0, i+1);
13938
+ buf.writeUInt8(0, i + 1);
13827
13939
  }
13828
13940
 
13829
13941
  const addrBuf = Buffer.from(codec.decodeAccountID(address), "hex");
@@ -13831,7 +13943,7 @@ class StateHelpers {
13831
13943
  return stateKeyBuf.toString('hex').toUpperCase();
13832
13944
  }
13833
13945
 
13834
- static getHookStateIndex(hookAccount, stateKey, hookNamespace = EvernodeConstants.HOOK_NAMESPACE) {
13946
+ static getHookStateIndex(hookAccount, stateKey, hookNamespace = EvernodeConstants.HOOK_NAMESPACE) {
13835
13947
  const typeBuf = Buffer.allocUnsafe(2);
13836
13948
  typeBuf.writeInt16BE(HOOK_STATE_LEDGER_TYPE_PREFIX);
13837
13949
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evernode-js-client",
3
- "version": "0.4.48",
3
+ "version": "0.4.50",
4
4
  "dependencies": {
5
5
  "elliptic": "6.5.4",
6
6
  "ripple-address-codec": "4.2.0",