evernode-js-client 0.4.42 → 0.4.43
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +50 -19
- package/package.json +1 -1
package/index.js
CHANGED
@@ -12090,6 +12090,7 @@ const { EncryptionHelper } = __nccwpck_require__(1247);
|
|
12090
12090
|
const { Buffer } = __nccwpck_require__(4300);
|
12091
12091
|
const codec = __nccwpck_require__(597);
|
12092
12092
|
const { XflHelpers } = __nccwpck_require__(9281);
|
12093
|
+
const { EvernodeHelpers } = __nccwpck_require__(7498);
|
12093
12094
|
|
12094
12095
|
const OFFER_WAIT_TIMEOUT = 60;
|
12095
12096
|
|
@@ -12131,6 +12132,10 @@ class HostClient extends BaseEvernodeClient {
|
|
12131
12132
|
return null;
|
12132
12133
|
}
|
12133
12134
|
|
12135
|
+
async getLeaseOffers() {
|
12136
|
+
return await EvernodeHelpers.getLeaseOffers(this.xrplAcc);
|
12137
|
+
}
|
12138
|
+
|
12134
12139
|
async cancelOffer(offerIndex) {
|
12135
12140
|
return this.xrplAcc.cancelOffer(offerIndex);
|
12136
12141
|
}
|
@@ -12477,6 +12482,7 @@ const { XrplAccount } = __nccwpck_require__(6962);
|
|
12477
12482
|
const { UtilHelpers } = __nccwpck_require__(4954);
|
12478
12483
|
const { Buffer } = __nccwpck_require__(4300);
|
12479
12484
|
const codec = __nccwpck_require__(597);
|
12485
|
+
const { EvernodeHelpers } = __nccwpck_require__(7498);
|
12480
12486
|
|
12481
12487
|
const ACQUIRE_WATCH_PREFIX = 'acquire_';
|
12482
12488
|
const EXTEND_WATCH_PREFIX = 'extend_';
|
@@ -12546,25 +12552,30 @@ class TenantClient extends BaseEvernodeClient {
|
|
12546
12552
|
}
|
12547
12553
|
|
12548
12554
|
async acquireLeaseSubmit(hostAddress, requirement, options = {}) {
|
12549
|
-
|
12550
|
-
const
|
12551
|
-
|
12552
|
-
|
12553
|
-
|
12554
|
-
|
12555
|
-
|
12556
|
-
|
12557
|
-
|
12558
|
-
if (!
|
12559
|
-
throw { reason: ErrorReasons.
|
12560
|
-
|
12561
|
-
|
12562
|
-
|
12563
|
-
|
12564
|
-
|
12565
|
-
|
12566
|
-
|
12567
|
-
|
12555
|
+
|
12556
|
+
const hostAcc = await this.getLeaseHost(hostAddress);
|
12557
|
+
let selectedOfferIndex = options.leaseOfferIndex;
|
12558
|
+
|
12559
|
+
// Attempt to get first available offer, if offer is not specified in options.
|
12560
|
+
if (!selectedOfferIndex) {
|
12561
|
+
const nftOffers = EvernodeHelpers.getLeaseOffers(hostAcc);
|
12562
|
+
selectedOfferIndex = nftOffers && nftOffers[0] && nftOffers[0].index;
|
12563
|
+
|
12564
|
+
if (!selectedOfferIndex)
|
12565
|
+
throw { reason: ErrorReasons.NO_OFFER, error: "No offers available." };
|
12566
|
+
}
|
12567
|
+
|
12568
|
+
// Encrypt the requirements with the host's encryption key (Specified in MessageKey field of the host account).
|
12569
|
+
const encKey = await hostAcc.getMessageKey();
|
12570
|
+
if (!encKey)
|
12571
|
+
throw { reason: ErrorReasons.INTERNAL_ERR, error: "Host encryption key not set." };
|
12572
|
+
|
12573
|
+
const ecrypted = await EncryptionHelper.encrypt(encKey, requirement, {
|
12574
|
+
iv: options.iv, // Must be null or 16 bytes.
|
12575
|
+
ephemPrivateKey: options.ephemPrivateKey // Must be null or 32 bytes.
|
12576
|
+
});
|
12577
|
+
|
12578
|
+
return this.xrplAcc.buyNft(selectedOfferIndex, [{ type: MemoTypes.ACQUIRE_LEASE, format: MemoFormats.BASE64, data: ecrypted }], options.transactionOptions);
|
12568
12579
|
}
|
12569
12580
|
|
12570
12581
|
watchAcquireResponse(tx, options = {}) {
|
@@ -13163,6 +13174,26 @@ module.exports = {
|
|
13163
13174
|
|
13164
13175
|
/***/ }),
|
13165
13176
|
|
13177
|
+
/***/ 7498:
|
13178
|
+
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
13179
|
+
|
13180
|
+
const { EvernodeConstants } = __nccwpck_require__(5716);
|
13181
|
+
|
13182
|
+
class EvernodeHelpers {
|
13183
|
+
static async getLeaseOffers(xrplAcc) {
|
13184
|
+
const hostNfts = (await xrplAcc.getNfts()).filter(nft => nft.URI.startsWith(EvernodeConstants.LEASE_NFT_PREFIX_HEX));
|
13185
|
+
const hostTokenIDs = hostNfts.map(nft => nft.NFTokenID);
|
13186
|
+
const nftOffers = (await xrplAcc.getNftOffers())?.filter(offer => (offer.Flags == 1 && hostTokenIDs.includes(offer.NFTokenID))); // Filter only sell offers
|
13187
|
+
return nftOffers;
|
13188
|
+
}
|
13189
|
+
}
|
13190
|
+
|
13191
|
+
module.exports = {
|
13192
|
+
EvernodeHelpers
|
13193
|
+
}
|
13194
|
+
|
13195
|
+
/***/ }),
|
13196
|
+
|
13166
13197
|
/***/ 2092:
|
13167
13198
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
13168
13199
|
|