evernode-js-client 0.6.57 → 0.6.59

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 +82 -54
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -59581,7 +59581,7 @@ const codec = __nccwpck_require__(597);
59581
59581
  const { Buffer } = __nccwpck_require__(4300);
59582
59582
  const { XrplApi } = __nccwpck_require__(7609);
59583
59583
  const { XrplAccount } = __nccwpck_require__(6099);
59584
- const { XrplApiEvents, XrplConstants } = __nccwpck_require__(8325);
59584
+ const { XrplApiEvents, XrplConstants, XrplTransactionTypes } = __nccwpck_require__(8325);
59585
59585
  const { EvernodeEvents, EventTypes, MemoFormats, EvernodeConstants, HookStateKeys, HookParamKeys, RegExp, ReputationConstants } = __nccwpck_require__(5732);
59586
59586
  const { Defaults } = __nccwpck_require__(1001);
59587
59587
  const { EncryptionHelper } = __nccwpck_require__(2731);
@@ -59847,7 +59847,7 @@ class BaseEvernodeClient {
59847
59847
  eventType = tx.HookParameters.find(p => p.name === HookParamKeys.PARAM_EVENT_TYPE_KEY)?.value;
59848
59848
  eventData = tx.HookParameters.find(p => p.name === HookParamKeys.PARAM_EVENT_DATA_KEY)?.value ?? '';
59849
59849
  }
59850
- if (tx.TransactionType === 'URITokenBuy' && eventType === EventTypes.ACQUIRE_LEASE && tx.Memos.length &&
59850
+ if (tx.TransactionType === XrplTransactionTypes.URI_TOKEN_BUY_OFFER && eventType === EventTypes.ACQUIRE_LEASE && tx.Memos.length &&
59851
59851
  tx.Memos[0].type === EventTypes.ACQUIRE_LEASE && tx.Memos[0].format === MemoFormats.BASE64 && tx.Memos[0].data) {
59852
59852
 
59853
59853
  // If our account is the destination host account, then decrypt the payload if it is encrypted.
@@ -59880,7 +59880,6 @@ class BaseEvernodeClient {
59880
59880
  }
59881
59881
  }
59882
59882
  }
59883
-
59884
59883
  else if (eventType === EventTypes.ACQUIRE_SUCCESS && eventData && tx.Memos.length &&
59885
59884
  tx.Memos[0].type === EventTypes.ACQUIRE_SUCCESS && tx.Memos[0].data) {
59886
59885
 
@@ -59985,6 +59984,20 @@ class BaseEvernodeClient {
59985
59984
  }
59986
59985
  }
59987
59986
  }
59987
+ else if (eventType === EventTypes.TERMINATE_LEASE && eventData) {
59988
+
59989
+ let uriTokenId = eventData;
59990
+
59991
+ return {
59992
+ name: EvernodeEvents.TerminateLease,
59993
+ data: {
59994
+ transaction: tx,
59995
+ terminateRefId: tx.hash,
59996
+ tenant: tx.Account,
59997
+ uriTokenId: uriTokenId
59998
+ }
59999
+ }
60000
+ }
59988
60001
  else if (eventType === EventTypes.EXTEND_SUCCESS && eventData && tx.Memos.length &&
59989
60002
  tx.Memos[0].type === EventTypes.EXTEND_SUCCESS && tx.Memos[0].format === MemoFormats.HEX && tx.Memos[0].data) {
59990
60003
 
@@ -61103,11 +61116,8 @@ module.exports = {
61103
61116
  /***/ 538:
61104
61117
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
61105
61118
 
61106
- const codec = __nccwpck_require__(597);
61107
61119
  const { StateHelpers } = __nccwpck_require__(3390);
61108
- const { XrplAccount } = __nccwpck_require__(6099);
61109
61120
  const { BaseEvernodeClient } = __nccwpck_require__(4438);
61110
- const { ReputationConstants } = __nccwpck_require__(5732);
61111
61121
 
61112
61122
  const ReputationEvents = {}
61113
61123
 
@@ -61232,7 +61242,8 @@ const OFFER_WAIT_TIMEOUT = 60;
61232
61242
 
61233
61243
  const HostEvents = {
61234
61244
  AcquireLease: EvernodeEvents.AcquireLease,
61235
- ExtendLease: EvernodeEvents.ExtendLease
61245
+ ExtendLease: EvernodeEvents.ExtendLease,
61246
+ TerminateLease: EvernodeEvents.TerminateLease,
61236
61247
  }
61237
61248
 
61238
61249
  const HOST_COUNTRY_CODE_PARAM_OFFSET = 0;
@@ -61645,58 +61656,43 @@ class HostClient extends BaseEvernodeClient {
61645
61656
 
61646
61657
  /**
61647
61658
  * Prepare host reputation score to a common format for submission.
61648
- * @param {object} collectedScores
61649
- * @returns Unified reputation score array.
61650
- */
61651
- async prepareHostReputationScores(collectedScores = {}) {
61652
- const myReputationInfo = await this.getReputationOrderByAddress(this.xrplAcc.address);
61653
- if (!("orderedId" in (myReputationInfo ?? {})))
61654
- return null;
61655
-
61656
- const myOrderId = myReputationInfo.orderedId;
61657
-
61658
- // Deciding universe.
61659
- const universeStartIndex = Math.floor(myOrderId / 64) * 64;
61660
-
61661
- const reputationClient = await HookClientFactory.create(HookTypes.reputation);
61662
- await reputationClient.connect();
61663
- let data = {};
61664
- await Promise.all(Array.from({ length: 64 }, (_, i) => i + universeStartIndex).map(async (i) => {
61665
- try {
61666
- const hostReputationInfo = await reputationClient.getReputationContractInfoByOrderedId(i);
61667
- if (!hostReputationInfo)
61668
- throw 'No reputation info for this order id';
61669
- data[i.toString()] = {
61670
- publicKey: hostReputationInfo.contract?.pubkey ?? "-1",
61671
- orderId: i
61672
- };
61673
- } catch (error) {
61674
- data[i.toString()] = { publicKey: "-1", orderId: i };
61675
- }
61676
- }));
61677
- await reputationClient.disconnect();
61678
-
61679
- return Object.entries(data).map(e => ({
61680
- ...e[1],
61681
- scoreValue: collectedScores[e[1]?.publicKey] || 0
61682
- }));
61683
- }
61684
-
61685
- /**
61686
- * Send reputation scores to the reputation hook.
61687
61659
  * @param {number} scoreVersion Version of the scores.
61688
61660
  * @param {number} clusterSize Size of the cluster.
61689
- * @param {object} scores [Optional] Score object in { host: score } format.
61661
+ * @param {object} collectedScores [Optional] Score object in { host: score } format.
61662
+ * @returns Unified reputation score buffer.
61690
61663
  */
61691
- async sendReputations(scoreVersion, clusterSize, scores = null, options = {}) {
61664
+ async prepareHostReputationScores(scoreVersion, clusterSize, collectedScores = null) {
61692
61665
  let buffer = Buffer.alloc(1);
61693
- if (scores) {
61694
- const preparedScores = await this.prepareHostReputationScores(scores);
61695
- if (preparedScores) {
61666
+ if (collectedScores) {
61667
+ const myReputationInfo = await this.getReputationOrderByAddress(this.xrplAcc.address);
61668
+ if (("orderedId" in (myReputationInfo ?? {}))) {
61669
+ const myOrderId = myReputationInfo.orderedId;
61670
+
61671
+ // Deciding universe.
61672
+ const universeStartIndex = Math.floor(myOrderId / 64) * 64;
61673
+
61674
+ const reputationClient = await HookClientFactory.create(HookTypes.reputation);
61675
+ await reputationClient.connect();
61676
+ let data = {};
61677
+ await Promise.all(Array.from({ length: 64 }, (_, i) => i + universeStartIndex).map(async (i) => {
61678
+ try {
61679
+ const hostReputationInfo = await reputationClient.getReputationContractInfoByOrderedId(i);
61680
+ if (!hostReputationInfo)
61681
+ throw 'No reputation info for this order id';
61682
+ data[i.toString()] = {
61683
+ publicKey: hostReputationInfo.contract?.pubkey ?? "-1",
61684
+ orderId: i
61685
+ };
61686
+ } catch (error) {
61687
+ data[i.toString()] = { publicKey: "-1", orderId: i };
61688
+ }
61689
+ }));
61690
+ await reputationClient.disconnect();
61691
+
61696
61692
  buffer = Buffer.alloc(66, 0);
61697
61693
  let i = 0;
61698
- for (const reputationScore of preparedScores) {
61699
- buffer.writeUIntLE(Number(reputationScore.scoreValue), i + 1, 1);
61694
+ for (const e of Object.entries(data)) {
61695
+ buffer.writeUIntLE(Number(collectedScores[e[1]?.publicKey] || 0), i + 1, 1);
61700
61696
  i++;
61701
61697
  }
61702
61698
  buffer.writeUIntLE(clusterSize, 65, 1);
@@ -61705,10 +61701,18 @@ class HostClient extends BaseEvernodeClient {
61705
61701
 
61706
61702
  buffer.writeUIntLE(scoreVersion, 0, 1);
61707
61703
 
61704
+ return buffer;
61705
+ }
61706
+
61707
+ /**
61708
+ * Send reputation scores to the reputation hook.
61709
+ * @param {string} bufferHex Prepared score buffer as hex string.
61710
+ */
61711
+ async sendReputations(bufferHex, options = {}) {
61708
61712
  const paramData = codec.decodeAccountID(this.xrplAcc.address);
61709
61713
 
61710
61714
  await this.reputationAcc.invoke(this.config.reputationAddress,
61711
- buffer ? { isHex: true, data: buffer.toString('hex') } : null,
61715
+ bufferHex ? { isHex: true, data: bufferHex } : null,
61712
61716
  {
61713
61717
  hookParams: [
61714
61718
  { name: HookParamKeys.PARAM_EVENT_TYPE_KEY, value: EventTypes.HOST_SEND_REPUTATION },
@@ -62621,6 +62625,7 @@ const { XrplAccount } = __nccwpck_require__(6099);
62621
62625
  const { UtilHelpers } = __nccwpck_require__(3726);
62622
62626
  const { EvernodeHelpers } = __nccwpck_require__(6384);
62623
62627
  const { TransactionHelper } = __nccwpck_require__(5358);
62628
+ const { XrplConstants } = __nccwpck_require__(8325);
62624
62629
 
62625
62630
  const DEFAULT_WAIT_TIMEOUT = 300000;
62626
62631
 
@@ -62970,6 +62975,27 @@ class TenantClient extends BaseEvernodeClient {
62970
62975
  }
62971
62976
  });
62972
62977
  }
62978
+
62979
+ /**
62980
+ * Terminate the lease instance.
62981
+ * @param {string} uriTokenId Hex URI token id of the lease.
62982
+ */
62983
+ async terminateLease(uriTokenId, options = {}) {
62984
+ const uriToken = await this.xrplApi.getURITokenByIndex(uriTokenId);
62985
+ if (uriToken && uriToken.Owner === this.xrplAcc.address) {
62986
+ await this.xrplAcc.makePayment(uriToken.Issuer, XrplConstants.MIN_DROPS, null, null, null,
62987
+ {
62988
+ hookParams: [
62989
+ { name: HookParamKeys.PARAM_EVENT_TYPE_KEY, value: EventTypes.TERMINATE_LEASE },
62990
+ { name: HookParamKeys.PARAM_EVENT_DATA_KEY, value: uriTokenId }
62991
+ ],
62992
+ ...options.transactionOptions
62993
+ });
62994
+ }
62995
+ else {
62996
+ console.log(`Uri token ${uriTokenId} not found or already burned. Burn skipped.`);
62997
+ }
62998
+ }
62973
62999
  }
62974
63000
 
62975
63001
  module.exports = {
@@ -63532,6 +63558,7 @@ const EventTypes = {
63532
63558
  EXTEND_SUCCESS: 'evnExtendSuccess',
63533
63559
  EXTEND_ERROR: 'evnExtendError',
63534
63560
  EXTEND_REF: 'evnExtendRef',
63561
+ TERMINATE_LEASE: 'evnTerminateLease',
63535
63562
  INIT: 'evnInitialize',
63536
63563
  REFUND: 'evnRefund',
63537
63564
  REFUND_REF: 'evnRefundRef',
@@ -63644,6 +63671,7 @@ const EvernodeEvents = {
63644
63671
  ExtendLease: "ExtendLease",
63645
63672
  ExtendSuccess: "ExtendSuccess",
63646
63673
  ExtendError: "ExtendError",
63674
+ TerminateLease: 'TerminateLease',
63647
63675
  HostRegUpdated: "HostRegUpdated",
63648
63676
  HostReRegistered: "HostReRegistered",
63649
63677
  Initialized: "Initialized",
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  ],
7
7
  "homepage": "https://github.com/HotPocketDev/evernode-js-client",
8
8
  "license": "SEE LICENSE IN https://raw.githubusercontent.com/EvernodeXRPL/evernode-resources/main/license/evernode-license.pdf",
9
- "version": "0.6.57",
9
+ "version": "0.6.59",
10
10
  "dependencies": {
11
11
  "elliptic": "6.5.4",
12
12
  "libsodium-wrappers": "0.7.10",