evernode-js-client 0.5.17-beta-v3.0 → 0.5.17-beta-v3.2
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +56 -5
- package/package.json +1 -1
package/index.js
CHANGED
@@ -12738,7 +12738,7 @@ class FoundationClient extends BaseEvernodeClient {
|
|
12738
12738
|
Buffer.from(candidateId, 'hex').copy(voteBuf, CANDIDATE_VOTE_UNIQUE_ID_MEMO_OFFSET);
|
12739
12739
|
voteBuf.writeUInt8(vote, CANDIDATE_VOTE_VALUE_MEMO_OFFSET)
|
12740
12740
|
|
12741
|
-
return await this.xrplAcc.makePayment(this.
|
12741
|
+
return await this.xrplAcc.makePayment(this.config.heartbeatAddress,
|
12742
12742
|
XrplConstants.MIN_XRP_AMOUNT,
|
12743
12743
|
XrplConstants.XRP,
|
12744
12744
|
null,
|
@@ -12828,7 +12828,6 @@ const GovernorEvents = {
|
|
12828
12828
|
CandidateWithdrew: EvernodeEvents.CandidateWithdrew,
|
12829
12829
|
ChildHookUpdated: EvernodeEvents.ChildHookUpdated,
|
12830
12830
|
GovernanceModeChanged: EvernodeEvents.GovernanceModeChanged,
|
12831
|
-
FoundationVoted: EvernodeEvents.FoundationVoted,
|
12832
12831
|
DudHostReported: EvernodeEvents.DudHostReported,
|
12833
12832
|
DudHostRemoved: EvernodeEvents.DudHostRemoved,
|
12834
12833
|
DudHostStatusChanged: EvernodeEvents.DudHostStatusChanged,
|
@@ -12856,7 +12855,8 @@ const { BaseEvernodeClient } = __nccwpck_require__(6263);
|
|
12856
12855
|
const { EvernodeEvents } = __nccwpck_require__(9849);
|
12857
12856
|
|
12858
12857
|
const HeartbeatEvents = {
|
12859
|
-
Heartbeat: EvernodeEvents.Heartbeat
|
12858
|
+
Heartbeat: EvernodeEvents.Heartbeat,
|
12859
|
+
FoundationVoted: EvernodeEvents.FoundationVoted
|
12860
12860
|
}
|
12861
12861
|
|
12862
12862
|
class HeartbeatClient extends BaseEvernodeClient {
|
@@ -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
|
-
|
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.
|
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