evernode-js-client 0.5.17-beta-v3.1 → 0.5.17-beta-v3.2

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 +53 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -13100,7 +13100,20 @@ class HostClient extends BaseEvernodeClient {
13100
13100
  Buffer.from(tosHash, 'hex').copy(uriBuf, prefixLen + 2, 0, halfToSLen);
13101
13101
  uriBuf.writeBigInt64BE(XflHelpers.getXfl(leaseAmount.toString()), prefixLen + 2 + halfToSLen);
13102
13102
  const uri = uriBuf.toString('base64');
13103
- await this.xrplAcc.mintURIToken(uri, null, { isBurnable: true, isHexUri: false });
13103
+
13104
+ try {
13105
+ await this.xrplAcc.mintURIToken(uri, null, { isBurnable: true, isHexUri: false });
13106
+ } catch (e) {
13107
+ // Re-minting the URIToken after burning that sold URIToken.
13108
+ if (e.code === "tecDUPLICATE") {
13109
+ const uriTokenId = this.xrplAcc.generateIssuedURITokenId(uri);
13110
+ console.log(`Burning URIToken related to a previously sold lease.`);
13111
+ await this.xrplAcc.burnURIToken(uriTokenId);
13112
+ console.log("Re-mint the URIToken for the new lease offer.")
13113
+ await this.xrplAcc.mintURIToken(uri, null, { isBurnable: true, isHexUri: false });
13114
+ }
13115
+ }
13116
+
13104
13117
  const uriToken = await this.xrplAcc.getURITokenByUri(uri);
13105
13118
  if (!uriToken)
13106
13119
  throw "Offer lease NFT creation error.";
@@ -13146,6 +13159,15 @@ class HostClient extends BaseEvernodeClient {
13146
13159
  if (await this.isRegistered())
13147
13160
  throw "Host already registered.";
13148
13161
 
13162
+ // Check whether are there lease offers in for the host due to a previous registration.
13163
+ const existingLeaseURITokens = (await this.xrplAcc.getURITokens()).filter(n => EvernodeHelpers.isValidURI(n.URI, EvernodeConstants.LEASE_TOKEN_PREFIX_HEX));
13164
+ if (existingLeaseURITokens) {
13165
+ console.log("Burning unsold URITokens related to the previous leases.");
13166
+ for (const uriToken of existingLeaseURITokens) {
13167
+ await this.xrplAcc.burnURIToken(uriToken.index);
13168
+ }
13169
+ }
13170
+
13149
13171
  // Check whether is there any missed NFT sell offer that needs to be accepted
13150
13172
  // from the client-side in order to complete the registration.
13151
13173
  const registryAcc = new XrplAccount(this.config.registryAddress, null, { xrplApi: this.xrplApi });
@@ -15331,7 +15353,7 @@ class StateHelpers {
15331
15353
  voteBaseCountChangedTimestamp: Number(stateData.readBigUInt64BE(VOTER_BASE_COUNT_CHANGED_TIMESTAMP_OFFSET)),
15332
15354
  foundationLastVotedCandidateIdx: stateData.readUInt32BE(FOUNDATION_LAST_VOTED_CANDIDATE_IDX),
15333
15355
  foundationLastVotedTimestamp: Number(stateData.readBigUInt64BE(FOUNDATION_LAST_VOTED_TIMESTAMP_OFFSET)),
15334
- electedProposalUniqueId: stateData.readUInt32BE(ELECTED_PROPOSAL_UNIQUE_ID_OFFSET),
15356
+ electedProposalUniqueId: stateData.slice(ELECTED_PROPOSAL_UNIQUE_ID_OFFSET, PROPOSAL_ELECTED_TIMESTAMP_OFFSET).toString('hex').toUpperCase(),
15335
15357
  proposalElectedTimestamp: Number(stateData.readBigUInt64BE(PROPOSAL_ELECTED_TIMESTAMP_OFFSET)),
15336
15358
  updatedHookCount: stateData.readUInt8(UPDATED_HOOK_COUNT_OFFSET),
15337
15359
  supportVoteSent: stateData.readUInt8(FOUNDATION_SUPPORT_VOTE_FLAG_OFFSET)
@@ -16437,6 +16459,35 @@ class XrplAccount {
16437
16459
  const hexUri = isHexUri ? uri : TransactionHelper.asciiToHex(uri).toUpperCase();
16438
16460
  return tokens.find(t => t.URI == hexUri);
16439
16461
  }
16462
+
16463
+
16464
+ generateIssuedURITokenId(uri) {
16465
+ if (uri.length < 1 || uri.length > 256)
16466
+ throw 'Invalid URI';
16467
+
16468
+ const URITOKEN_LEDGER_TYPE_PREFIX = 85; // Decimal value of ASCII 'U'
16469
+ const accIdHex = (codec.decodeAccountID(this.address)).toString('hex').toUpperCase();
16470
+ let uriHex = '';
16471
+ for (let n in uri) {
16472
+ let digit = uri.charCodeAt(n).toString(16).toUpperCase();
16473
+ uriHex += (digit.length == 1 ? '0' : '') + digit
16474
+ }
16475
+
16476
+ let hash = crypto.createHash('sha512');
16477
+
16478
+ const typeBuf = Buffer.allocUnsafe(2);
16479
+ typeBuf.writeInt16BE(URITOKEN_LEDGER_TYPE_PREFIX);
16480
+
16481
+ const dataBuf = Buffer.from(`${accIdHex}${uriHex}`, 'hex');
16482
+
16483
+ let output = hash.update(typeBuf);
16484
+ output = hash.update(dataBuf);
16485
+
16486
+ const digest = output.digest('hex');
16487
+
16488
+ // Get the first 32 bytes of hash.
16489
+ return digest.substring(0, 64).toUpperCase();
16490
+ }
16440
16491
  }
16441
16492
 
16442
16493
  function makeAmountObject(amount, currency, issuer) {
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  ],
7
7
  "homepage": "https://github.com/HotPocketDev/evernode-js-client",
8
8
  "license": "MIT",
9
- "version": "0.5.17-beta-v3.1",
9
+ "version": "0.5.17-beta-v3.2",
10
10
  "dependencies": {
11
11
  "elliptic": "6.5.4",
12
12
  "libsodium-wrappers": "0.7.10",