xrpl 2.9.1 → 2.11.0
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/build/xrpl-latest-min.js +1 -1
- package/build/xrpl-latest-min.js.map +1 -1
- package/build/xrpl-latest.js +2680 -481
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/Wallet/walletFromSecretNumbers.d.ts +7 -0
- package/dist/npm/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
- package/dist/npm/Wallet/walletFromSecretNumbers.js +27 -0
- package/dist/npm/Wallet/walletFromSecretNumbers.js.map +1 -0
- package/dist/npm/client/index.d.ts +2 -1
- package/dist/npm/client/index.d.ts.map +1 -1
- package/dist/npm/client/index.js.map +1 -1
- package/dist/npm/index.d.ts +1 -0
- package/dist/npm/index.d.ts.map +1 -1
- package/dist/npm/index.js +3 -1
- package/dist/npm/index.js.map +1 -1
- package/dist/npm/models/common/index.d.ts +5 -0
- package/dist/npm/models/common/index.d.ts.map +1 -1
- package/dist/npm/models/ledger/AMM.d.ts +27 -0
- package/dist/npm/models/ledger/AMM.d.ts.map +1 -0
- package/dist/npm/models/ledger/AMM.js +3 -0
- package/dist/npm/models/ledger/AMM.js.map +1 -0
- package/dist/npm/models/ledger/AccountRoot.d.ts +5 -1
- package/dist/npm/models/ledger/AccountRoot.d.ts.map +1 -1
- package/dist/npm/models/ledger/AccountRoot.js +2 -0
- package/dist/npm/models/ledger/AccountRoot.js.map +1 -1
- package/dist/npm/models/ledger/LedgerEntry.d.ts +2 -1
- package/dist/npm/models/ledger/LedgerEntry.d.ts.map +1 -1
- package/dist/npm/models/methods/accountInfo.d.ts +1 -0
- package/dist/npm/models/methods/accountInfo.d.ts.map +1 -1
- package/dist/npm/models/methods/ammInfo.d.ts +39 -0
- package/dist/npm/models/methods/ammInfo.d.ts.map +1 -0
- package/dist/npm/models/methods/ammInfo.js +3 -0
- package/dist/npm/models/methods/ammInfo.js.map +1 -0
- package/dist/npm/models/methods/index.d.ts +4 -3
- package/dist/npm/models/methods/index.d.ts.map +1 -1
- package/dist/npm/models/methods/ledgerEntry.d.ts +10 -0
- package/dist/npm/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/models/transactions/AMMBid.d.ts +12 -0
- package/dist/npm/models/transactions/AMMBid.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMBid.js +56 -0
- package/dist/npm/models/transactions/AMMBid.js.map +1 -0
- package/dist/npm/models/transactions/AMMCreate.d.ts +11 -0
- package/dist/npm/models/transactions/AMMCreate.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMCreate.js +32 -0
- package/dist/npm/models/transactions/AMMCreate.js.map +1 -0
- package/dist/npm/models/transactions/AMMDelete.d.ts +9 -0
- package/dist/npm/models/transactions/AMMDelete.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMDelete.js +22 -0
- package/dist/npm/models/transactions/AMMDelete.js.map +1 -0
- package/dist/npm/models/transactions/AMMDeposit.d.ts +27 -0
- package/dist/npm/models/transactions/AMMDeposit.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMDeposit.js +51 -0
- package/dist/npm/models/transactions/AMMDeposit.js.map +1 -0
- package/dist/npm/models/transactions/AMMVote.d.ts +10 -0
- package/dist/npm/models/transactions/AMMVote.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMVote.js +32 -0
- package/dist/npm/models/transactions/AMMVote.js.map +1 -0
- package/dist/npm/models/transactions/AMMWithdraw.d.ts +31 -0
- package/dist/npm/models/transactions/AMMWithdraw.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMWithdraw.js +50 -0
- package/dist/npm/models/transactions/AMMWithdraw.js.map +1 -0
- package/dist/npm/models/transactions/accountSet.d.ts +2 -1
- package/dist/npm/models/transactions/accountSet.d.ts.map +1 -1
- package/dist/npm/models/transactions/accountSet.js +1 -0
- package/dist/npm/models/transactions/accountSet.js.map +1 -1
- package/dist/npm/models/transactions/clawback.d.ts +9 -0
- package/dist/npm/models/transactions/clawback.d.ts.map +1 -0
- package/dist/npm/models/transactions/clawback.js +19 -0
- package/dist/npm/models/transactions/clawback.js.map +1 -0
- package/dist/npm/models/transactions/common.d.ts +2 -1
- package/dist/npm/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/models/transactions/common.js +12 -1
- package/dist/npm/models/transactions/common.js.map +1 -1
- package/dist/npm/models/transactions/index.d.ts +7 -0
- package/dist/npm/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/models/transactions/index.js +5 -1
- package/dist/npm/models/transactions/index.js.map +1 -1
- package/dist/npm/models/transactions/transaction.d.ts +8 -1
- package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/models/transactions/transaction.js +28 -0
- package/dist/npm/models/transactions/transaction.js.map +1 -1
- package/dist/npm/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/models/utils/flags.js +17 -23
- package/dist/npm/models/utils/flags.js.map +1 -1
- package/dist/npm/models/utils/index.js +1 -1
- package/dist/npm/models/utils/index.js.map +1 -1
- package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
- package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts +7 -0
- package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
- package/dist/npm/src/Wallet/walletFromSecretNumbers.js +27 -0
- package/dist/npm/src/Wallet/walletFromSecretNumbers.js.map +1 -0
- package/dist/npm/src/client/index.d.ts +2 -1
- package/dist/npm/src/client/index.d.ts.map +1 -1
- package/dist/npm/src/client/index.js.map +1 -1
- package/dist/npm/src/index.d.ts +1 -0
- package/dist/npm/src/index.d.ts.map +1 -1
- package/dist/npm/src/index.js +3 -1
- package/dist/npm/src/index.js.map +1 -1
- package/dist/npm/src/models/common/index.d.ts +5 -0
- package/dist/npm/src/models/common/index.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/AMM.d.ts +27 -0
- package/dist/npm/src/models/ledger/AMM.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/AMM.js +3 -0
- package/dist/npm/src/models/ledger/AMM.js.map +1 -0
- package/dist/npm/src/models/ledger/AccountRoot.d.ts +5 -1
- package/dist/npm/src/models/ledger/AccountRoot.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/AccountRoot.js +2 -0
- package/dist/npm/src/models/ledger/AccountRoot.js.map +1 -1
- package/dist/npm/src/models/ledger/LedgerEntry.d.ts +2 -1
- package/dist/npm/src/models/ledger/LedgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/methods/accountInfo.d.ts +1 -0
- package/dist/npm/src/models/methods/accountInfo.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ammInfo.d.ts +39 -0
- package/dist/npm/src/models/methods/ammInfo.d.ts.map +1 -0
- package/dist/npm/src/models/methods/ammInfo.js +3 -0
- package/dist/npm/src/models/methods/ammInfo.js.map +1 -0
- package/dist/npm/src/models/methods/index.d.ts +4 -3
- package/dist/npm/src/models/methods/index.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ledgerEntry.d.ts +10 -0
- package/dist/npm/src/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/AMMBid.d.ts +12 -0
- package/dist/npm/src/models/transactions/AMMBid.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMBid.js +56 -0
- package/dist/npm/src/models/transactions/AMMBid.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMCreate.d.ts +11 -0
- package/dist/npm/src/models/transactions/AMMCreate.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMCreate.js +32 -0
- package/dist/npm/src/models/transactions/AMMCreate.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMDelete.d.ts +9 -0
- package/dist/npm/src/models/transactions/AMMDelete.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMDelete.js +22 -0
- package/dist/npm/src/models/transactions/AMMDelete.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMDeposit.d.ts +27 -0
- package/dist/npm/src/models/transactions/AMMDeposit.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMDeposit.js +51 -0
- package/dist/npm/src/models/transactions/AMMDeposit.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMVote.d.ts +10 -0
- package/dist/npm/src/models/transactions/AMMVote.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMVote.js +32 -0
- package/dist/npm/src/models/transactions/AMMVote.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.d.ts +31 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.js +50 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.js.map +1 -0
- package/dist/npm/src/models/transactions/accountSet.d.ts +2 -1
- package/dist/npm/src/models/transactions/accountSet.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/accountSet.js +1 -0
- package/dist/npm/src/models/transactions/accountSet.js.map +1 -1
- package/dist/npm/src/models/transactions/clawback.d.ts +9 -0
- package/dist/npm/src/models/transactions/clawback.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/clawback.js +19 -0
- package/dist/npm/src/models/transactions/clawback.js.map +1 -0
- package/dist/npm/src/models/transactions/common.d.ts +2 -1
- package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/common.js +12 -1
- package/dist/npm/src/models/transactions/common.js.map +1 -1
- package/dist/npm/src/models/transactions/index.d.ts +7 -0
- package/dist/npm/src/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/index.js +5 -1
- package/dist/npm/src/models/transactions/index.js.map +1 -1
- package/dist/npm/src/models/transactions/transaction.d.ts +8 -1
- package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/transaction.js +28 -0
- package/dist/npm/src/models/transactions/transaction.js.map +1 -1
- package/dist/npm/src/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/src/models/utils/flags.js +17 -23
- package/dist/npm/src/models/utils/flags.js.map +1 -1
- package/dist/npm/src/models/utils/index.js +1 -1
- package/dist/npm/src/models/utils/index.js.map +1 -1
- package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/src/sugar/autofill.js +4 -3
- package/dist/npm/src/sugar/autofill.js.map +1 -1
- package/dist/npm/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/sugar/autofill.js +4 -3
- package/dist/npm/sugar/autofill.js.map +1 -1
- package/package.json +8 -6
- package/src/ECDSA.ts +6 -0
- package/src/Wallet/defaultFaucets.ts +82 -0
- package/src/Wallet/fundWallet.ts +344 -0
- package/src/Wallet/index.ts +504 -0
- package/src/Wallet/rfc1751.ts +190 -0
- package/src/Wallet/rfc1751Words.json +243 -0
- package/src/Wallet/signer.ts +173 -0
- package/src/Wallet/walletFromSecretNumbers.ts +37 -0
- package/src/client/BroadcastClient.ts +84 -0
- package/src/client/ConnectionManager.ts +40 -0
- package/src/client/ExponentialBackoff.ts +71 -0
- package/src/client/RequestManager.ts +194 -0
- package/src/client/WSWrapper.ts +106 -0
- package/src/client/connection.ts +593 -0
- package/src/client/index.ts +712 -0
- package/src/client/partialPayment.ts +153 -0
- package/src/errors.ts +161 -0
- package/src/index.ts +20 -0
- package/src/models/common/index.ts +149 -0
- package/src/models/index.ts +16 -0
- package/src/models/ledger/AMM.ts +78 -0
- package/src/models/ledger/AccountRoot.ts +217 -0
- package/src/models/ledger/Amendments.ts +45 -0
- package/src/models/ledger/BaseLedgerEntry.ts +3 -0
- package/src/models/ledger/Check.ts +70 -0
- package/src/models/ledger/DepositPreauth.ts +35 -0
- package/src/models/ledger/DirectoryNode.ts +46 -0
- package/src/models/ledger/Escrow.ts +74 -0
- package/src/models/ledger/FeeSettings.ts +52 -0
- package/src/models/ledger/Ledger.ts +65 -0
- package/src/models/ledger/LedgerEntry.ts +34 -0
- package/src/models/ledger/LedgerHashes.ts +24 -0
- package/src/models/ledger/NFTokenOffer.ts +16 -0
- package/src/models/ledger/NFTokenPage.ts +20 -0
- package/src/models/ledger/NegativeUNL.ts +34 -0
- package/src/models/ledger/Offer.ts +52 -0
- package/src/models/ledger/PayChannel.ts +107 -0
- package/src/models/ledger/RippleState.ts +88 -0
- package/src/models/ledger/SignerList.ts +56 -0
- package/src/models/ledger/Ticket.ts +36 -0
- package/src/models/ledger/index.ts +58 -0
- package/src/models/methods/accountChannels.ts +93 -0
- package/src/models/methods/accountCurrencies.ts +45 -0
- package/src/models/methods/accountInfo.ts +182 -0
- package/src/models/methods/accountLines.ts +137 -0
- package/src/models/methods/accountNFTs.ts +72 -0
- package/src/models/methods/accountObjects.ts +120 -0
- package/src/models/methods/accountOffers.ts +100 -0
- package/src/models/methods/accountTx.ts +109 -0
- package/src/models/methods/ammInfo.ts +145 -0
- package/src/models/methods/baseMethod.ts +58 -0
- package/src/models/methods/bookOffers.ts +96 -0
- package/src/models/methods/channelVerify.ts +41 -0
- package/src/models/methods/depositAuthorized.ts +56 -0
- package/src/models/methods/fee.ts +91 -0
- package/src/models/methods/gatewayBalances.ts +85 -0
- package/src/models/methods/index.ts +391 -0
- package/src/models/methods/ledger.ts +125 -0
- package/src/models/methods/ledgerClosed.ts +32 -0
- package/src/models/methods/ledgerCurrent.ts +31 -0
- package/src/models/methods/ledgerData.ts +78 -0
- package/src/models/methods/ledgerEntry.ts +177 -0
- package/src/models/methods/manifest.ts +54 -0
- package/src/models/methods/nftBuyOffers.ts +37 -0
- package/src/models/methods/nftHistory.ts +113 -0
- package/src/models/methods/nftInfo.ts +25 -0
- package/src/models/methods/nftSellOffers.ts +37 -0
- package/src/models/methods/norippleCheck.ts +82 -0
- package/src/models/methods/pathFind.ts +116 -0
- package/src/models/methods/ping.ts +21 -0
- package/src/models/methods/random.ts +23 -0
- package/src/models/methods/ripplePathFind.ts +81 -0
- package/src/models/methods/serverInfo.ts +257 -0
- package/src/models/methods/serverState.ts +77 -0
- package/src/models/methods/submit.ts +94 -0
- package/src/models/methods/submitMultisigned.ts +51 -0
- package/src/models/methods/subscribe.ts +435 -0
- package/src/models/methods/transactionEntry.ts +47 -0
- package/src/models/methods/tx.ts +69 -0
- package/src/models/methods/unsubscribe.ts +49 -0
- package/src/models/transactions/AMMBid.ts +140 -0
- package/src/models/transactions/AMMCreate.ts +80 -0
- package/src/models/transactions/AMMDelete.ts +55 -0
- package/src/models/transactions/AMMDeposit.ts +130 -0
- package/src/models/transactions/AMMVote.ts +71 -0
- package/src/models/transactions/AMMWithdraw.ts +126 -0
- package/src/models/transactions/NFTokenAcceptOffer.ts +104 -0
- package/src/models/transactions/NFTokenBurn.ts +48 -0
- package/src/models/transactions/NFTokenCancelOffer.ts +45 -0
- package/src/models/transactions/NFTokenCreateOffer.ts +145 -0
- package/src/models/transactions/NFTokenMint.ts +123 -0
- package/src/models/transactions/UNLModify.ts +20 -0
- package/src/models/transactions/accountDelete.ts +50 -0
- package/src/models/transactions/accountSet.ts +228 -0
- package/src/models/transactions/checkCancel.ts +34 -0
- package/src/models/transactions/checkCash.ts +73 -0
- package/src/models/transactions/checkCreate.ts +90 -0
- package/src/models/transactions/clawback.ts +49 -0
- package/src/models/transactions/common.ts +295 -0
- package/src/models/transactions/depositPreauth.ts +68 -0
- package/src/models/transactions/enableAmendment.ts +26 -0
- package/src/models/transactions/escrowCancel.ts +45 -0
- package/src/models/transactions/escrowCreate.ts +100 -0
- package/src/models/transactions/escrowFinish.ts +63 -0
- package/src/models/transactions/index.ts +66 -0
- package/src/models/transactions/metadata.ts +69 -0
- package/src/models/transactions/offerCancel.ts +37 -0
- package/src/models/transactions/offerCreate.ts +144 -0
- package/src/models/transactions/payment.ts +278 -0
- package/src/models/transactions/paymentChannelClaim.ts +165 -0
- package/src/models/transactions/paymentChannelCreate.ts +116 -0
- package/src/models/transactions/paymentChannelFund.ts +65 -0
- package/src/models/transactions/setFee.ts +48 -0
- package/src/models/transactions/setRegularKey.ts +33 -0
- package/src/models/transactions/signerListSet.ts +89 -0
- package/src/models/transactions/ticketCreate.ts +50 -0
- package/src/models/transactions/transaction.ts +303 -0
- package/src/models/transactions/trustSet.ts +146 -0
- package/src/models/utils/flags.ts +98 -0
- package/src/models/utils/index.ts +37 -0
- package/src/sugar/autofill.ts +373 -0
- package/src/sugar/balances.ts +123 -0
- package/src/sugar/getFeeXrp.ts +45 -0
- package/src/sugar/getLedgerIndex.ts +15 -0
- package/src/sugar/getOrderbook.ts +152 -0
- package/src/sugar/index.ts +11 -0
- package/src/sugar/submit.ts +305 -0
- package/src/sugar/utils.ts +29 -0
- package/src/utils/derive.ts +23 -0
- package/src/utils/getBalanceChanges.ts +186 -0
- package/src/utils/getNFTokenID.ts +97 -0
- package/src/utils/hashes/HashPrefix.ts +40 -0
- package/src/utils/hashes/README.md +65 -0
- package/src/utils/hashes/SHAMap/InnerNode.ts +124 -0
- package/src/utils/hashes/SHAMap/LeafNode.ts +69 -0
- package/src/utils/hashes/SHAMap/index.ts +41 -0
- package/src/utils/hashes/SHAMap/node.ts +14 -0
- package/src/utils/hashes/hashLedger.ts +236 -0
- package/src/utils/hashes/index.ts +187 -0
- package/src/utils/hashes/ledgerSpaces.ts +34 -0
- package/src/utils/hashes/sha512Half.ts +19 -0
- package/src/utils/index.ts +223 -0
- package/src/utils/parseNFTokenID.ts +84 -0
- package/src/utils/quality.ts +169 -0
- package/src/utils/signPaymentChannelClaim.ts +27 -0
- package/src/utils/stringConversion.ts +27 -0
- package/src/utils/timeConversion.ts +53 -0
- package/src/utils/verifyPaymentChannelClaim.ts +30 -0
- package/src/utils/xrpConversion.ts +104 -0
@@ -0,0 +1,712 @@
|
|
1
|
+
/* eslint-disable jsdoc/require-jsdoc -- Request has many aliases, but they don't need unique docs */
|
2
|
+
/* eslint-disable @typescript-eslint/member-ordering -- TODO: remove when instance methods aren't members */
|
3
|
+
/* eslint-disable max-lines -- Client is a large file w/ lots of imports/exports */
|
4
|
+
import * as assert from 'assert'
|
5
|
+
import { EventEmitter } from 'events'
|
6
|
+
|
7
|
+
import { NotFoundError, ValidationError, XrplError } from '../errors'
|
8
|
+
import {
|
9
|
+
Request,
|
10
|
+
Response,
|
11
|
+
// account methods
|
12
|
+
AccountChannelsRequest,
|
13
|
+
AccountChannelsResponse,
|
14
|
+
AccountCurrenciesRequest,
|
15
|
+
AccountCurrenciesResponse,
|
16
|
+
AccountInfoRequest,
|
17
|
+
AccountInfoResponse,
|
18
|
+
AccountLinesRequest,
|
19
|
+
AccountLinesResponse,
|
20
|
+
AccountNFTsRequest,
|
21
|
+
AccountNFTsResponse,
|
22
|
+
AccountObjectsRequest,
|
23
|
+
AccountObjectsResponse,
|
24
|
+
AccountOffersRequest,
|
25
|
+
AccountOffersResponse,
|
26
|
+
AccountTxRequest,
|
27
|
+
AccountTxResponse,
|
28
|
+
GatewayBalancesRequest,
|
29
|
+
GatewayBalancesResponse,
|
30
|
+
NoRippleCheckRequest,
|
31
|
+
NoRippleCheckResponse,
|
32
|
+
// ledger methods
|
33
|
+
LedgerRequest,
|
34
|
+
LedgerResponse,
|
35
|
+
LedgerClosedRequest,
|
36
|
+
LedgerClosedResponse,
|
37
|
+
LedgerCurrentRequest,
|
38
|
+
LedgerCurrentResponse,
|
39
|
+
LedgerDataRequest,
|
40
|
+
LedgerDataResponse,
|
41
|
+
LedgerEntryRequest,
|
42
|
+
LedgerEntryResponse,
|
43
|
+
// transaction methods
|
44
|
+
SubmitRequest,
|
45
|
+
SubmitResponse,
|
46
|
+
SubmitMultisignedRequest,
|
47
|
+
SubmitMultisignedResponse,
|
48
|
+
TransactionEntryRequest,
|
49
|
+
TransactionEntryResponse,
|
50
|
+
TxRequest,
|
51
|
+
TxResponse,
|
52
|
+
// path and order book methods
|
53
|
+
BookOffersRequest,
|
54
|
+
BookOffersResponse,
|
55
|
+
DepositAuthorizedRequest,
|
56
|
+
DepositAuthorizedResponse,
|
57
|
+
PathFindRequest,
|
58
|
+
PathFindResponse,
|
59
|
+
RipplePathFindRequest,
|
60
|
+
RipplePathFindResponse,
|
61
|
+
// payment channel methods
|
62
|
+
ChannelVerifyRequest,
|
63
|
+
ChannelVerifyResponse,
|
64
|
+
// server info methods
|
65
|
+
FeeRequest,
|
66
|
+
FeeResponse,
|
67
|
+
ManifestRequest,
|
68
|
+
ManifestResponse,
|
69
|
+
ServerInfoRequest,
|
70
|
+
ServerInfoResponse,
|
71
|
+
ServerStateRequest,
|
72
|
+
ServerStateResponse,
|
73
|
+
// utility methods
|
74
|
+
PingRequest,
|
75
|
+
PingResponse,
|
76
|
+
RandomRequest,
|
77
|
+
RandomResponse,
|
78
|
+
LedgerStream,
|
79
|
+
ValidationStream,
|
80
|
+
TransactionStream,
|
81
|
+
PathFindStream,
|
82
|
+
PeerStatusStream,
|
83
|
+
ConsensusStream,
|
84
|
+
SubscribeRequest,
|
85
|
+
SubscribeResponse,
|
86
|
+
UnsubscribeRequest,
|
87
|
+
UnsubscribeResponse,
|
88
|
+
// NFT methods
|
89
|
+
NFTBuyOffersRequest,
|
90
|
+
NFTBuyOffersResponse,
|
91
|
+
NFTSellOffersRequest,
|
92
|
+
NFTSellOffersResponse,
|
93
|
+
// clio only methods
|
94
|
+
NFTInfoRequest,
|
95
|
+
NFTInfoResponse,
|
96
|
+
NFTHistoryRequest,
|
97
|
+
NFTHistoryResponse,
|
98
|
+
// AMM methods
|
99
|
+
AMMInfoRequest,
|
100
|
+
AMMInfoResponse,
|
101
|
+
} from '../models/methods'
|
102
|
+
import { BaseRequest, BaseResponse } from '../models/methods/baseMethod'
|
103
|
+
import {
|
104
|
+
autofill,
|
105
|
+
ensureClassicAddress,
|
106
|
+
getLedgerIndex,
|
107
|
+
getOrderbook,
|
108
|
+
getBalances,
|
109
|
+
getXrpBalance,
|
110
|
+
submit,
|
111
|
+
submitAndWait,
|
112
|
+
} from '../sugar'
|
113
|
+
import fundWallet from '../Wallet/fundWallet'
|
114
|
+
|
115
|
+
import {
|
116
|
+
Connection,
|
117
|
+
ConnectionUserOptions,
|
118
|
+
INTENTIONAL_DISCONNECT_CODE,
|
119
|
+
} from './connection'
|
120
|
+
import {
|
121
|
+
handlePartialPayment,
|
122
|
+
handleStreamPartialPayment,
|
123
|
+
} from './partialPayment'
|
124
|
+
|
125
|
+
export interface ClientOptions extends ConnectionUserOptions {
|
126
|
+
feeCushion?: number
|
127
|
+
maxFeeXRP?: string
|
128
|
+
proxy?: string
|
129
|
+
timeout?: number
|
130
|
+
}
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Get the response key / property name that contains the listed data for a
|
134
|
+
* command. This varies from command to command, but we need to know it to
|
135
|
+
* properly count across many requests.
|
136
|
+
*
|
137
|
+
* @param command - The rippled request command.
|
138
|
+
* @returns The property key corresponding to the command.
|
139
|
+
*/
|
140
|
+
function getCollectKeyFromCommand(command: string): string | null {
|
141
|
+
switch (command) {
|
142
|
+
case 'account_channels':
|
143
|
+
return 'channels'
|
144
|
+
case 'account_lines':
|
145
|
+
return 'lines'
|
146
|
+
case 'account_objects':
|
147
|
+
return 'account_objects'
|
148
|
+
case 'account_tx':
|
149
|
+
return 'transactions'
|
150
|
+
case 'account_offers':
|
151
|
+
case 'book_offers':
|
152
|
+
return 'offers'
|
153
|
+
case 'ledger_data':
|
154
|
+
return 'state'
|
155
|
+
default:
|
156
|
+
return null
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
function clamp(value: number, min: number, max: number): number {
|
161
|
+
assert.ok(min <= max, 'Illegal clamp bounds')
|
162
|
+
return Math.min(Math.max(value, min), max)
|
163
|
+
}
|
164
|
+
|
165
|
+
interface MarkerRequest extends BaseRequest {
|
166
|
+
limit?: number
|
167
|
+
marker?: unknown
|
168
|
+
}
|
169
|
+
|
170
|
+
interface MarkerResponse extends BaseResponse {
|
171
|
+
result: {
|
172
|
+
marker?: unknown
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
const DEFAULT_FEE_CUSHION = 1.2
|
177
|
+
const DEFAULT_MAX_FEE_XRP = '2'
|
178
|
+
|
179
|
+
const MIN_LIMIT = 10
|
180
|
+
const MAX_LIMIT = 400
|
181
|
+
|
182
|
+
const NORMAL_DISCONNECT_CODE = 1000
|
183
|
+
|
184
|
+
/**
|
185
|
+
* Client for interacting with rippled servers.
|
186
|
+
*
|
187
|
+
* @category Clients
|
188
|
+
*/
|
189
|
+
class Client extends EventEmitter {
|
190
|
+
/*
|
191
|
+
* Underlying connection to rippled.
|
192
|
+
*/
|
193
|
+
public readonly connection: Connection
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Factor to multiply estimated fee by to provide a cushion in case the
|
197
|
+
* required fee rises during submission of a transaction. Defaults to 1.2.
|
198
|
+
*
|
199
|
+
* @category Fee
|
200
|
+
*/
|
201
|
+
public readonly feeCushion: number
|
202
|
+
|
203
|
+
/**
|
204
|
+
* Maximum transaction cost to allow, in decimal XRP. Must be a string-encoded
|
205
|
+
* number. Defaults to '2'.
|
206
|
+
*
|
207
|
+
* @category Fee
|
208
|
+
*/
|
209
|
+
public readonly maxFeeXRP: string
|
210
|
+
|
211
|
+
/**
|
212
|
+
* Network ID of the server this client is connected to
|
213
|
+
*
|
214
|
+
*/
|
215
|
+
public networkID: number | undefined
|
216
|
+
|
217
|
+
/**
|
218
|
+
* Rippled Version used by the server this client is connected to
|
219
|
+
*
|
220
|
+
*/
|
221
|
+
public buildVersion: string | undefined
|
222
|
+
|
223
|
+
/**
|
224
|
+
* Creates a new Client with a websocket connection to a rippled server.
|
225
|
+
*
|
226
|
+
* @param server - URL of the server to connect to.
|
227
|
+
* @param options - Options for client settings.
|
228
|
+
* @category Constructor
|
229
|
+
*/
|
230
|
+
// eslint-disable-next-line max-lines-per-function -- okay because we have to set up all the connection handlers
|
231
|
+
public constructor(server: string, options: ClientOptions = {}) {
|
232
|
+
super()
|
233
|
+
if (typeof server !== 'string' || !/wss?(?:\+unix)?:\/\//u.exec(server)) {
|
234
|
+
throw new ValidationError(
|
235
|
+
'server URI must start with `wss://`, `ws://`, `wss+unix://`, or `ws+unix://`.',
|
236
|
+
)
|
237
|
+
}
|
238
|
+
|
239
|
+
this.feeCushion = options.feeCushion ?? DEFAULT_FEE_CUSHION
|
240
|
+
this.maxFeeXRP = options.maxFeeXRP ?? DEFAULT_MAX_FEE_XRP
|
241
|
+
|
242
|
+
this.connection = new Connection(server, options)
|
243
|
+
|
244
|
+
this.connection.on('error', (errorCode, errorMessage, data) => {
|
245
|
+
this.emit('error', errorCode, errorMessage, data)
|
246
|
+
})
|
247
|
+
|
248
|
+
this.connection.on('reconnect', () => {
|
249
|
+
this.connection.on('connected', () => this.emit('connected'))
|
250
|
+
})
|
251
|
+
|
252
|
+
this.connection.on('disconnected', (code: number) => {
|
253
|
+
let finalCode = code
|
254
|
+
/*
|
255
|
+
* 4000: Connection uses a 4000 code internally to indicate a manual disconnect/close
|
256
|
+
* Since 4000 is a normal disconnect reason, we convert this to the standard exit code 1000
|
257
|
+
*/
|
258
|
+
if (finalCode === INTENTIONAL_DISCONNECT_CODE) {
|
259
|
+
finalCode = NORMAL_DISCONNECT_CODE
|
260
|
+
}
|
261
|
+
this.emit('disconnected', finalCode)
|
262
|
+
})
|
263
|
+
|
264
|
+
this.connection.on('ledgerClosed', (ledger) => {
|
265
|
+
this.emit('ledgerClosed', ledger)
|
266
|
+
})
|
267
|
+
|
268
|
+
this.connection.on('transaction', (tx) => {
|
269
|
+
// mutates `tx` to add warnings
|
270
|
+
handleStreamPartialPayment(tx, this.connection.trace)
|
271
|
+
this.emit('transaction', tx)
|
272
|
+
})
|
273
|
+
|
274
|
+
this.connection.on('validationReceived', (validation) => {
|
275
|
+
this.emit('validationReceived', validation)
|
276
|
+
})
|
277
|
+
|
278
|
+
this.connection.on('manifestReceived', (manifest) => {
|
279
|
+
this.emit('manifestReceived', manifest)
|
280
|
+
})
|
281
|
+
|
282
|
+
this.connection.on('peerStatusChange', (status) => {
|
283
|
+
this.emit('peerStatusChange', status)
|
284
|
+
})
|
285
|
+
|
286
|
+
this.connection.on('consensusPhase', (consensus) => {
|
287
|
+
this.emit('consensusPhase', consensus)
|
288
|
+
})
|
289
|
+
|
290
|
+
this.connection.on('path_find', (path) => {
|
291
|
+
this.emit('path_find', path)
|
292
|
+
})
|
293
|
+
}
|
294
|
+
|
295
|
+
/**
|
296
|
+
* Get the url that the client is connected to.
|
297
|
+
*
|
298
|
+
* @returns The URL of the server this client is connected to.
|
299
|
+
* @category Network
|
300
|
+
*/
|
301
|
+
public get url(): string {
|
302
|
+
return this.connection.getUrl()
|
303
|
+
}
|
304
|
+
|
305
|
+
/**
|
306
|
+
* @category Network
|
307
|
+
*/
|
308
|
+
public async request(
|
309
|
+
r: AccountChannelsRequest,
|
310
|
+
): Promise<AccountChannelsResponse>
|
311
|
+
public async request(
|
312
|
+
r: AccountCurrenciesRequest,
|
313
|
+
): Promise<AccountCurrenciesResponse>
|
314
|
+
public async request(r: AccountInfoRequest): Promise<AccountInfoResponse>
|
315
|
+
public async request(r: AccountLinesRequest): Promise<AccountLinesResponse>
|
316
|
+
public async request(r: AccountNFTsRequest): Promise<AccountNFTsResponse>
|
317
|
+
public async request(
|
318
|
+
r: AccountObjectsRequest,
|
319
|
+
): Promise<AccountObjectsResponse>
|
320
|
+
public async request(r: AccountOffersRequest): Promise<AccountOffersResponse>
|
321
|
+
public async request(r: AccountTxRequest): Promise<AccountTxResponse>
|
322
|
+
public async request(r: AMMInfoRequest): Promise<AMMInfoResponse>
|
323
|
+
public async request(r: BookOffersRequest): Promise<BookOffersResponse>
|
324
|
+
public async request(r: ChannelVerifyRequest): Promise<ChannelVerifyResponse>
|
325
|
+
public async request(
|
326
|
+
r: DepositAuthorizedRequest,
|
327
|
+
): Promise<DepositAuthorizedResponse>
|
328
|
+
public async request(r: FeeRequest): Promise<FeeResponse>
|
329
|
+
public async request(
|
330
|
+
r: GatewayBalancesRequest,
|
331
|
+
): Promise<GatewayBalancesResponse>
|
332
|
+
public async request(r: LedgerRequest): Promise<LedgerResponse>
|
333
|
+
public async request(r: LedgerClosedRequest): Promise<LedgerClosedResponse>
|
334
|
+
public async request(r: LedgerCurrentRequest): Promise<LedgerCurrentResponse>
|
335
|
+
public async request(r: LedgerDataRequest): Promise<LedgerDataResponse>
|
336
|
+
public async request(r: LedgerEntryRequest): Promise<LedgerEntryResponse>
|
337
|
+
public async request(r: ManifestRequest): Promise<ManifestResponse>
|
338
|
+
public async request(r: NFTBuyOffersRequest): Promise<NFTBuyOffersResponse>
|
339
|
+
public async request(r: NFTSellOffersRequest): Promise<NFTSellOffersResponse>
|
340
|
+
public async request(r: NFTInfoRequest): Promise<NFTInfoResponse>
|
341
|
+
public async request(r: NFTHistoryRequest): Promise<NFTHistoryResponse>
|
342
|
+
public async request(r: NoRippleCheckRequest): Promise<NoRippleCheckResponse>
|
343
|
+
public async request(r: PathFindRequest): Promise<PathFindResponse>
|
344
|
+
public async request(r: PingRequest): Promise<PingResponse>
|
345
|
+
public async request(r: RandomRequest): Promise<RandomResponse>
|
346
|
+
public async request(
|
347
|
+
r: RipplePathFindRequest,
|
348
|
+
): Promise<RipplePathFindResponse>
|
349
|
+
public async request(r: ServerInfoRequest): Promise<ServerInfoResponse>
|
350
|
+
public async request(r: ServerStateRequest): Promise<ServerStateResponse>
|
351
|
+
public async request(r: SubmitRequest): Promise<SubmitResponse>
|
352
|
+
public async request(
|
353
|
+
r: SubmitMultisignedRequest,
|
354
|
+
): Promise<SubmitMultisignedResponse>
|
355
|
+
public request(r: SubscribeRequest): Promise<SubscribeResponse>
|
356
|
+
public request(r: UnsubscribeRequest): Promise<UnsubscribeResponse>
|
357
|
+
public async request(
|
358
|
+
r: TransactionEntryRequest,
|
359
|
+
): Promise<TransactionEntryResponse>
|
360
|
+
public async request(r: TxRequest): Promise<TxResponse>
|
361
|
+
public async request<R extends BaseRequest, T extends BaseResponse>(
|
362
|
+
r: R,
|
363
|
+
): Promise<T>
|
364
|
+
/**
|
365
|
+
* Makes a request to the client with the given command and
|
366
|
+
* additional request body parameters.
|
367
|
+
*
|
368
|
+
* @param req - Request to send to the server.
|
369
|
+
* @returns The response from the server.
|
370
|
+
* @category Network
|
371
|
+
*/
|
372
|
+
public async request<R extends Request, T extends Response>(
|
373
|
+
req: R,
|
374
|
+
): Promise<T> {
|
375
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Necessary for overloading
|
376
|
+
const response = (await this.connection.request({
|
377
|
+
...req,
|
378
|
+
account: req.account
|
379
|
+
? // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Must be string
|
380
|
+
ensureClassicAddress(req.account as string)
|
381
|
+
: undefined,
|
382
|
+
})) as T
|
383
|
+
|
384
|
+
// mutates `response` to add warnings
|
385
|
+
handlePartialPayment(req.command, response)
|
386
|
+
|
387
|
+
return response
|
388
|
+
}
|
389
|
+
|
390
|
+
/**
|
391
|
+
* @category Network
|
392
|
+
*/
|
393
|
+
public async requestNextPage(
|
394
|
+
req: AccountChannelsRequest,
|
395
|
+
resp: AccountChannelsResponse,
|
396
|
+
): Promise<AccountChannelsResponse>
|
397
|
+
public async requestNextPage(
|
398
|
+
req: AccountLinesRequest,
|
399
|
+
resp: AccountLinesResponse,
|
400
|
+
): Promise<AccountLinesResponse>
|
401
|
+
public async requestNextPage(
|
402
|
+
req: AccountObjectsRequest,
|
403
|
+
resp: AccountObjectsResponse,
|
404
|
+
): Promise<AccountObjectsResponse>
|
405
|
+
public async requestNextPage(
|
406
|
+
req: AccountOffersRequest,
|
407
|
+
resp: AccountOffersResponse,
|
408
|
+
): Promise<AccountOffersResponse>
|
409
|
+
public async requestNextPage(
|
410
|
+
req: AccountTxRequest,
|
411
|
+
resp: AccountTxResponse,
|
412
|
+
): Promise<AccountTxResponse>
|
413
|
+
public async requestNextPage(
|
414
|
+
req: LedgerDataRequest,
|
415
|
+
resp: LedgerDataResponse,
|
416
|
+
): Promise<LedgerDataResponse>
|
417
|
+
/**
|
418
|
+
* Requests the next page of data.
|
419
|
+
*
|
420
|
+
* @param req - Request to send.
|
421
|
+
* @param resp - Response with the marker to use in the request.
|
422
|
+
* @returns The response with the next page of data.
|
423
|
+
*/
|
424
|
+
public async requestNextPage<
|
425
|
+
T extends MarkerRequest,
|
426
|
+
U extends MarkerResponse,
|
427
|
+
>(req: T, resp: U): Promise<U> {
|
428
|
+
if (!resp.result.marker) {
|
429
|
+
return Promise.reject(
|
430
|
+
new NotFoundError('response does not have a next page'),
|
431
|
+
)
|
432
|
+
}
|
433
|
+
const nextPageRequest = { ...req, marker: resp.result.marker }
|
434
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Necessary for overloading
|
435
|
+
return this.request(nextPageRequest) as unknown as U
|
436
|
+
}
|
437
|
+
|
438
|
+
/**
|
439
|
+
* Event handler for subscription streams.
|
440
|
+
*
|
441
|
+
* @example
|
442
|
+
* ```ts
|
443
|
+
* const api = new Client('wss://s.altnet.rippletest.net:51233')
|
444
|
+
*
|
445
|
+
* api.on('transaction', (tx: TransactionStream) => {
|
446
|
+
* console.log("Received Transaction")
|
447
|
+
* console.log(tx)
|
448
|
+
* })
|
449
|
+
*
|
450
|
+
* await api.connect()
|
451
|
+
* const response = await api.request({
|
452
|
+
* command: 'subscribe',
|
453
|
+
* streams: ['transactions_proposed']
|
454
|
+
* })
|
455
|
+
* ```
|
456
|
+
*
|
457
|
+
* @category Network
|
458
|
+
*/
|
459
|
+
public on(event: 'connected', listener: () => void): this
|
460
|
+
public on(event: 'disconnected', listener: (code: number) => void): this
|
461
|
+
public on(
|
462
|
+
event: 'ledgerClosed',
|
463
|
+
listener: (ledger: LedgerStream) => void,
|
464
|
+
): this
|
465
|
+
public on(
|
466
|
+
event: 'validationReceived',
|
467
|
+
listener: (validation: ValidationStream) => void,
|
468
|
+
): this
|
469
|
+
public on(
|
470
|
+
event: 'transaction',
|
471
|
+
listener: (tx: TransactionStream) => void,
|
472
|
+
): this
|
473
|
+
public on(
|
474
|
+
event: 'peerStatusChange',
|
475
|
+
listener: (status: PeerStatusStream) => void,
|
476
|
+
): this
|
477
|
+
public on(
|
478
|
+
event: 'consensusPhase',
|
479
|
+
listener: (phase: ConsensusStream) => void,
|
480
|
+
): this
|
481
|
+
public on(
|
482
|
+
event: 'manifestReceived',
|
483
|
+
listener: (manifest: ManifestResponse) => void,
|
484
|
+
): this
|
485
|
+
public on(event: 'path_find', listener: (path: PathFindStream) => void): this
|
486
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- needs to be any for overload
|
487
|
+
public on(event: 'error', listener: (...err: any[]) => void): this
|
488
|
+
/**
|
489
|
+
* Event handler for subscription streams.
|
490
|
+
*
|
491
|
+
* @param eventName - Name of the event. Only forwards streams.
|
492
|
+
* @param listener - Function to run on event.
|
493
|
+
* @returns This, because it inherits from EventEmitter.
|
494
|
+
*/
|
495
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- needs to be any for overload
|
496
|
+
public on(eventName: string, listener: (...args: any[]) => void): this {
|
497
|
+
return super.on(eventName, listener)
|
498
|
+
}
|
499
|
+
|
500
|
+
/**
|
501
|
+
* @category Network
|
502
|
+
*/
|
503
|
+
public async requestAll(
|
504
|
+
req: AccountChannelsRequest,
|
505
|
+
): Promise<AccountChannelsResponse[]>
|
506
|
+
public async requestAll(
|
507
|
+
req: AccountLinesRequest,
|
508
|
+
): Promise<AccountLinesResponse[]>
|
509
|
+
public async requestAll(
|
510
|
+
req: AccountObjectsRequest,
|
511
|
+
): Promise<AccountObjectsResponse[]>
|
512
|
+
public async requestAll(
|
513
|
+
req: AccountOffersRequest,
|
514
|
+
): Promise<AccountOffersResponse[]>
|
515
|
+
public async requestAll(req: AccountTxRequest): Promise<AccountTxResponse[]>
|
516
|
+
public async requestAll(req: BookOffersRequest): Promise<BookOffersResponse[]>
|
517
|
+
public async requestAll(req: LedgerDataRequest): Promise<LedgerDataResponse[]>
|
518
|
+
/**
|
519
|
+
* Makes multiple paged requests to the client to return a given number of
|
520
|
+
* resources. Multiple paged requests will be made until the `limit`
|
521
|
+
* number of resources is reached (if no `limit` is provided, a single request
|
522
|
+
* will be made).
|
523
|
+
*
|
524
|
+
* If the command is unknown, an additional `collect` property is required to
|
525
|
+
* know which response key contains the array of resources.
|
526
|
+
*
|
527
|
+
* NOTE: This command is used by existing methods and is not recommended for
|
528
|
+
* general use. Instead, use rippled's built-in pagination and make multiple
|
529
|
+
* requests as needed.
|
530
|
+
*
|
531
|
+
* @param request - The initial request to send to the server.
|
532
|
+
* @param collect - (Optional) the param to use to collect the array of resources (only needed if command is unknown).
|
533
|
+
* @returns The array of all responses.
|
534
|
+
* @throws ValidationError if there is no collection key (either from a known command or for the unknown command).
|
535
|
+
*/
|
536
|
+
public async requestAll<T extends MarkerRequest, U extends MarkerResponse>(
|
537
|
+
request: T,
|
538
|
+
collect?: string,
|
539
|
+
): Promise<U[]> {
|
540
|
+
/*
|
541
|
+
* The data under collection is keyed based on the command. Fail if command
|
542
|
+
* not recognized and collection key not provided.
|
543
|
+
*/
|
544
|
+
const collectKey = collect ?? getCollectKeyFromCommand(request.command)
|
545
|
+
if (!collectKey) {
|
546
|
+
throw new ValidationError(`no collect key for command ${request.command}`)
|
547
|
+
}
|
548
|
+
/*
|
549
|
+
* If limit is not provided, fetches all data over multiple requests.
|
550
|
+
* NOTE: This may return much more than needed. Set limit when possible.
|
551
|
+
*/
|
552
|
+
const countTo: number = request.limit == null ? Infinity : request.limit
|
553
|
+
let count = 0
|
554
|
+
let marker: unknown = request.marker
|
555
|
+
let lastBatchLength: number
|
556
|
+
const results: U[] = []
|
557
|
+
do {
|
558
|
+
const countRemaining = clamp(countTo - count, MIN_LIMIT, MAX_LIMIT)
|
559
|
+
const repeatProps = {
|
560
|
+
...request,
|
561
|
+
limit: countRemaining,
|
562
|
+
marker,
|
563
|
+
}
|
564
|
+
// eslint-disable-next-line no-await-in-loop -- Necessary for this, it really has to wait
|
565
|
+
const singleResponse = await this.connection.request(repeatProps)
|
566
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Should be true
|
567
|
+
const singleResult = (singleResponse as U).result
|
568
|
+
if (!(collectKey in singleResult)) {
|
569
|
+
throw new XrplError(`${collectKey} not in result`)
|
570
|
+
}
|
571
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Should be true
|
572
|
+
const collectedData = singleResult[collectKey]
|
573
|
+
marker = singleResult.marker
|
574
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Should be true
|
575
|
+
results.push(singleResponse as U)
|
576
|
+
// Make sure we handle when no data (not even an empty array) is returned.
|
577
|
+
if (Array.isArray(collectedData)) {
|
578
|
+
count += collectedData.length
|
579
|
+
lastBatchLength = collectedData.length
|
580
|
+
} else {
|
581
|
+
lastBatchLength = 0
|
582
|
+
}
|
583
|
+
} while (Boolean(marker) && count < countTo && lastBatchLength !== 0)
|
584
|
+
return results
|
585
|
+
}
|
586
|
+
|
587
|
+
/**
|
588
|
+
* Get networkID and buildVersion from server_info
|
589
|
+
*/
|
590
|
+
public async getServerInfo(): Promise<void> {
|
591
|
+
try {
|
592
|
+
const response = await this.request({
|
593
|
+
command: 'server_info',
|
594
|
+
})
|
595
|
+
this.networkID = response.result.info.network_id ?? undefined
|
596
|
+
this.buildVersion = response.result.info.build_version
|
597
|
+
} catch (error) {
|
598
|
+
// eslint-disable-next-line no-console -- Print the error to console but allows client to be connected.
|
599
|
+
console.error(error)
|
600
|
+
}
|
601
|
+
}
|
602
|
+
|
603
|
+
/**
|
604
|
+
* Tells the Client instance to connect to its rippled server.
|
605
|
+
*
|
606
|
+
* @example
|
607
|
+
*
|
608
|
+
* Client.connect() establishes a connection between a Client object and the server.
|
609
|
+
*
|
610
|
+
* ```ts
|
611
|
+
* const { Client } = require('xrpl')
|
612
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
613
|
+
* await client.connect()
|
614
|
+
* // do something with the client
|
615
|
+
* await client.disconnect()
|
616
|
+
* ```
|
617
|
+
* If you open a client connection, be sure to close it with `await client.disconnect()`
|
618
|
+
* before exiting your application.
|
619
|
+
* @returns A promise that resolves with a void value when a connection is established.
|
620
|
+
* @category Network
|
621
|
+
*/
|
622
|
+
public async connect(): Promise<void> {
|
623
|
+
return this.connection.connect().then(async () => {
|
624
|
+
await this.getServerInfo()
|
625
|
+
this.emit('connected')
|
626
|
+
})
|
627
|
+
}
|
628
|
+
|
629
|
+
/**
|
630
|
+
* Disconnects the XRPL client from the server and cancels all pending requests and subscriptions. Call when
|
631
|
+
* you want to disconnect the client from the server, such as when you're finished using the client or when you
|
632
|
+
* need to switch to a different server.
|
633
|
+
*
|
634
|
+
* @example
|
635
|
+
*
|
636
|
+
* To use the disconnect() method, you first need to create a new Client object and connect it to a server:
|
637
|
+
*
|
638
|
+
* ```ts
|
639
|
+
* const { Client } = require('xrpl')
|
640
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
641
|
+
* await client.connect()
|
642
|
+
* // do something with the client
|
643
|
+
* await client.disconnect()
|
644
|
+
* ```
|
645
|
+
*
|
646
|
+
* @returns A promise that resolves with a void value when a connection is destroyed.
|
647
|
+
* @category Network
|
648
|
+
*/
|
649
|
+
public async disconnect(): Promise<void> {
|
650
|
+
/*
|
651
|
+
* backwards compatibility: connection.disconnect() can return a number, but
|
652
|
+
* this method returns nothing. SO we await but don't return any result.
|
653
|
+
*/
|
654
|
+
await this.connection.disconnect()
|
655
|
+
}
|
656
|
+
|
657
|
+
/**
|
658
|
+
* Checks if the Client instance is connected to its rippled server.
|
659
|
+
*
|
660
|
+
* @returns Whether the client instance is connected.
|
661
|
+
* @category Network
|
662
|
+
*/
|
663
|
+
public isConnected(): boolean {
|
664
|
+
return this.connection.isConnected()
|
665
|
+
}
|
666
|
+
|
667
|
+
/**
|
668
|
+
* @category Core
|
669
|
+
*/
|
670
|
+
public autofill = autofill
|
671
|
+
|
672
|
+
/**
|
673
|
+
* @category Core
|
674
|
+
*/
|
675
|
+
public submit = submit
|
676
|
+
/**
|
677
|
+
* @category Core
|
678
|
+
*/
|
679
|
+
public submitAndWait = submitAndWait
|
680
|
+
|
681
|
+
/**
|
682
|
+
* @deprecated Use autofill instead, provided for users familiar with v1
|
683
|
+
*/
|
684
|
+
public prepareTransaction = autofill
|
685
|
+
|
686
|
+
/**
|
687
|
+
* @category Abstraction
|
688
|
+
*/
|
689
|
+
public getXrpBalance = getXrpBalance
|
690
|
+
|
691
|
+
/**
|
692
|
+
* @category Abstraction
|
693
|
+
*/
|
694
|
+
public getBalances = getBalances
|
695
|
+
|
696
|
+
/**
|
697
|
+
* @category Abstraction
|
698
|
+
*/
|
699
|
+
public getOrderbook = getOrderbook
|
700
|
+
|
701
|
+
/**
|
702
|
+
* @category Abstraction
|
703
|
+
*/
|
704
|
+
public getLedgerIndex = getLedgerIndex
|
705
|
+
|
706
|
+
/**
|
707
|
+
* @category Faucet
|
708
|
+
*/
|
709
|
+
public fundWallet = fundWallet
|
710
|
+
}
|
711
|
+
|
712
|
+
export { Client }
|