evernode-js-client 0.4.14 → 0.4.15
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.
- package/index.js +77 -27
- package/package.json +1 -1
package/index.js
CHANGED
@@ -7,12 +7,12 @@
|
|
7
7
|
const { XrplApi } = __nccwpck_require__(850);
|
8
8
|
const { XrplAccount } = __nccwpck_require__(329);
|
9
9
|
const { XrplApiEvents } = __nccwpck_require__(307);
|
10
|
-
const { EvernodeEvents,
|
10
|
+
const { EvernodeEvents, MemoTypes, MemoFormats, EvernodeConstants, HookStateKeys } = __nccwpck_require__(849);
|
11
11
|
const { DefaultValues } = __nccwpck_require__(262);
|
12
12
|
const { EncryptionHelper } = __nccwpck_require__(832);
|
13
13
|
const { EventEmitter } = __nccwpck_require__(170);
|
14
|
-
const codec = __nccwpck_require__(
|
15
|
-
const { Buffer } = __nccwpck_require__(
|
14
|
+
const codec = __nccwpck_require__(597);
|
15
|
+
const { Buffer } = __nccwpck_require__(300);
|
16
16
|
const { UtilHelpers } = __nccwpck_require__(687);
|
17
17
|
const { FirestoreHandler } = __nccwpck_require__(718);
|
18
18
|
|
@@ -312,8 +312,10 @@ const { BaseEvernodeClient } = __nccwpck_require__(263);
|
|
312
312
|
const { EvernodeEvents, EvernodeConstants, MemoFormats, MemoTypes, ErrorCodes } = __nccwpck_require__(849);
|
313
313
|
const { XrplAccount } = __nccwpck_require__(329);
|
314
314
|
const { EncryptionHelper } = __nccwpck_require__(832);
|
315
|
-
const { Buffer } = __nccwpck_require__(
|
316
|
-
const codec = __nccwpck_require__(
|
315
|
+
const { Buffer } = __nccwpck_require__(300);
|
316
|
+
const codec = __nccwpck_require__(597);
|
317
|
+
|
318
|
+
const OFFER_WAIT_TIMEOUT = 60;
|
317
319
|
|
318
320
|
const HostEvents = {
|
319
321
|
Redeem: EvernodeEvents.Redeem,
|
@@ -353,9 +355,27 @@ class HostClient extends BaseEvernodeClient {
|
|
353
355
|
return null;
|
354
356
|
}
|
355
357
|
|
358
|
+
async getTokenOffer() {
|
359
|
+
const hostingToken = (await this.getRegistration())?.token;
|
360
|
+
if (!hostingToken)
|
361
|
+
throw "Error getting hosting hosting token";
|
362
|
+
const offer = (await this.xrplAcc.getOffers()).find(o => o.taker_gets.currency === hostingToken && o.taker_gets.issuer === this.xrplAcc.address);
|
363
|
+
return offer || null;
|
364
|
+
}
|
365
|
+
|
366
|
+
async createTokenSellOffer(sellAmount, valueInEVRs) {
|
367
|
+
const hostingToken = (await this.getRegistration())?.token;
|
368
|
+
if (!hostingToken)
|
369
|
+
throw "Error getting hosting hosting token";
|
370
|
+
return this.xrplAcc.offerSell(sellAmount, hostingToken, this.xrplAcc.address, valueInEVRs, EvernodeConstants.EVR, this.config.evrIssuerAddress);
|
371
|
+
}
|
372
|
+
|
373
|
+
async cancelOffer(offerIndex) {
|
374
|
+
return this.xrplAcc.cancelOffer(offerIndex);
|
375
|
+
}
|
376
|
+
|
356
377
|
async isRegistered() {
|
357
|
-
|
358
|
-
return (await this.getRegistrationNft()) !== null;
|
378
|
+
return (await this.getRegistration()) !== null;
|
359
379
|
}
|
360
380
|
|
361
381
|
async prepareAccount() {
|
@@ -413,7 +433,7 @@ class HostClient extends BaseEvernodeClient {
|
|
413
433
|
|
414
434
|
let attemps = 0;
|
415
435
|
|
416
|
-
while (attemps <
|
436
|
+
while (attemps < OFFER_WAIT_TIMEOUT) {
|
417
437
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
418
438
|
if (tx.isSellOfferAccepted) {
|
419
439
|
break;
|
@@ -451,6 +471,25 @@ class HostClient extends BaseEvernodeClient {
|
|
451
471
|
null,
|
452
472
|
[{ type: MemoTypes.HOST_DEREG, format: MemoFormats.HEX, data: regNFT.TokenID }],
|
453
473
|
options.transactionOptions);
|
474
|
+
|
475
|
+
console.log('Waiting for the buy offer')
|
476
|
+
const regAcc = new XrplAccount(this.registryAddress);
|
477
|
+
let offer = null;
|
478
|
+
let attempts = 0;
|
479
|
+
while (attempts < OFFER_WAIT_TIMEOUT) {
|
480
|
+
offer = (await regAcc.getNftOffers()).find(o => (o.TokenID == regNFT.TokenID) && (o.Flags === 0));
|
481
|
+
if (offer)
|
482
|
+
break;
|
483
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
484
|
+
attempts++;
|
485
|
+
}
|
486
|
+
if (!offer)
|
487
|
+
throw 'No offer found within timeout.';
|
488
|
+
|
489
|
+
console.log('Accepting buy offer..');
|
490
|
+
await this.xrplAcc.sellNft(offer.index);
|
491
|
+
|
492
|
+
return await this.isRegistered();
|
454
493
|
}
|
455
494
|
|
456
495
|
async redeemSuccess(txHash, userAddress, instanceInfo, options = {}) {
|
@@ -685,12 +724,12 @@ module.exports = {
|
|
685
724
|
// We are using this code file directly because the full eccrypto library causes a conflict with
|
686
725
|
// tiny-secp256k1 used by xrpl libs during ncc/webpack build.
|
687
726
|
|
688
|
-
var EC = __nccwpck_require__(
|
727
|
+
var EC = (__nccwpck_require__(517).ec);
|
689
728
|
var ec = new EC("secp256k1");
|
690
729
|
var browserCrypto = global.crypto || global.msCrypto || {};
|
691
730
|
var subtle = browserCrypto.subtle || browserCrypto.webkitSubtle;
|
692
731
|
|
693
|
-
var nodeCrypto = __nccwpck_require__(
|
732
|
+
var nodeCrypto = __nccwpck_require__(113);
|
694
733
|
|
695
734
|
const EC_GROUP_ORDER = Buffer.from('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141', 'hex');
|
696
735
|
const ZERO32 = Buffer.alloc(32, 0);
|
@@ -1120,7 +1159,7 @@ module.exports = {
|
|
1120
1159
|
/***/ 718:
|
1121
1160
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
1122
1161
|
|
1123
|
-
const https = __nccwpck_require__(
|
1162
|
+
const https = __nccwpck_require__(241);
|
1124
1163
|
const { DefaultValues } = __nccwpck_require__(262);
|
1125
1164
|
|
1126
1165
|
const FirestoreOperations = {
|
@@ -1440,8 +1479,8 @@ module.exports = {
|
|
1440
1479
|
/***/ 860:
|
1441
1480
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
1442
1481
|
|
1443
|
-
const codec = __nccwpck_require__(
|
1444
|
-
const { Buffer } = __nccwpck_require__(
|
1482
|
+
const codec = __nccwpck_require__(597);
|
1483
|
+
const { Buffer } = __nccwpck_require__(300);
|
1445
1484
|
const { HookStateKeys } = __nccwpck_require__(849);
|
1446
1485
|
|
1447
1486
|
const NFTOKEN_PREFIX = '00080000';
|
@@ -1664,7 +1703,7 @@ module.exports = {
|
|
1664
1703
|
/***/ 687:
|
1665
1704
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
1666
1705
|
|
1667
|
-
const { Buffer } = __nccwpck_require__(
|
1706
|
+
const { Buffer } = __nccwpck_require__(300);
|
1668
1707
|
|
1669
1708
|
// Utility helper functions.
|
1670
1709
|
class UtilHelpers {
|
@@ -1839,10 +1878,10 @@ module.exports = {
|
|
1839
1878
|
/***/ 329:
|
1840
1879
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
1841
1880
|
|
1842
|
-
const xrpl = __nccwpck_require__(
|
1843
|
-
const kp = __nccwpck_require__(
|
1844
|
-
const codec = __nccwpck_require__(
|
1845
|
-
const crypto = __nccwpck_require__(
|
1881
|
+
const xrpl = __nccwpck_require__(666);
|
1882
|
+
const kp = __nccwpck_require__(150);
|
1883
|
+
const codec = __nccwpck_require__(597);
|
1884
|
+
const crypto = __nccwpck_require__(113);
|
1846
1885
|
const { XrplConstants } = __nccwpck_require__(307);
|
1847
1886
|
const { TransactionHelper } = __nccwpck_require__(71);
|
1848
1887
|
const { EventEmitter } = __nccwpck_require__(170);
|
@@ -1920,6 +1959,10 @@ class XrplAccount {
|
|
1920
1959
|
});
|
1921
1960
|
}
|
1922
1961
|
|
1962
|
+
async getOffers() {
|
1963
|
+
return await this.xrplApi.getOffers(this.address);
|
1964
|
+
}
|
1965
|
+
|
1923
1966
|
async getNftOffers() {
|
1924
1967
|
const offers = await this.xrplApi.getAccountObjects(this.address);
|
1925
1968
|
// TODO: Pass rippled filter parameter when xrpl.js supports it.
|
@@ -2285,8 +2328,8 @@ module.exports = {
|
|
2285
2328
|
/***/ 850:
|
2286
2329
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
2287
2330
|
|
2288
|
-
const xrpl = __nccwpck_require__(
|
2289
|
-
const kp = __nccwpck_require__(
|
2331
|
+
const xrpl = __nccwpck_require__(666);
|
2332
|
+
const kp = __nccwpck_require__(150);
|
2290
2333
|
const { EventEmitter } = __nccwpck_require__(170);
|
2291
2334
|
const { DefaultValues } = __nccwpck_require__(262);
|
2292
2335
|
const { TransactionHelper } = __nccwpck_require__(71);
|
@@ -2463,6 +2506,13 @@ class XrplApi {
|
|
2463
2506
|
return [];
|
2464
2507
|
}
|
2465
2508
|
|
2509
|
+
async getOffers(address, options) {
|
2510
|
+
const resp = (await this.#client.request({ command: 'account_offers', account: address, ledger_index: "validated", ...options }));
|
2511
|
+
if (resp?.result?.offers)
|
2512
|
+
return resp.result.offers;
|
2513
|
+
return [];
|
2514
|
+
}
|
2515
|
+
|
2466
2516
|
async submitAndVerify(tx, options) {
|
2467
2517
|
return await this.#client.submitAndWait(tx, options);
|
2468
2518
|
}
|
@@ -2514,7 +2564,7 @@ module.exports = {
|
|
2514
2564
|
|
2515
2565
|
/***/ }),
|
2516
2566
|
|
2517
|
-
/***/
|
2567
|
+
/***/ 300:
|
2518
2568
|
/***/ ((module) => {
|
2519
2569
|
|
2520
2570
|
"use strict";
|
@@ -2522,7 +2572,7 @@ module.exports = require("buffer");
|
|
2522
2572
|
|
2523
2573
|
/***/ }),
|
2524
2574
|
|
2525
|
-
/***/
|
2575
|
+
/***/ 113:
|
2526
2576
|
/***/ ((module) => {
|
2527
2577
|
|
2528
2578
|
"use strict";
|
@@ -2530,7 +2580,7 @@ module.exports = require("crypto");
|
|
2530
2580
|
|
2531
2581
|
/***/ }),
|
2532
2582
|
|
2533
|
-
/***/
|
2583
|
+
/***/ 517:
|
2534
2584
|
/***/ ((module) => {
|
2535
2585
|
|
2536
2586
|
"use strict";
|
@@ -2538,7 +2588,7 @@ module.exports = require("elliptic");
|
|
2538
2588
|
|
2539
2589
|
/***/ }),
|
2540
2590
|
|
2541
|
-
/***/
|
2591
|
+
/***/ 241:
|
2542
2592
|
/***/ ((module) => {
|
2543
2593
|
|
2544
2594
|
"use strict";
|
@@ -2546,7 +2596,7 @@ module.exports = require("https");
|
|
2546
2596
|
|
2547
2597
|
/***/ }),
|
2548
2598
|
|
2549
|
-
/***/
|
2599
|
+
/***/ 597:
|
2550
2600
|
/***/ ((module) => {
|
2551
2601
|
|
2552
2602
|
"use strict";
|
@@ -2554,7 +2604,7 @@ module.exports = require("ripple-address-codec");
|
|
2554
2604
|
|
2555
2605
|
/***/ }),
|
2556
2606
|
|
2557
|
-
/***/
|
2607
|
+
/***/ 150:
|
2558
2608
|
/***/ ((module) => {
|
2559
2609
|
|
2560
2610
|
"use strict";
|
@@ -2562,7 +2612,7 @@ module.exports = require("ripple-keypairs");
|
|
2562
2612
|
|
2563
2613
|
/***/ }),
|
2564
2614
|
|
2565
|
-
/***/
|
2615
|
+
/***/ 666:
|
2566
2616
|
/***/ ((module) => {
|
2567
2617
|
|
2568
2618
|
"use strict";
|