xrpl 2.12.0 → 3.0.0-beta.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/README.md +114 -5
- package/build/xrpl-latest-min.js +1 -1
- package/build/xrpl-latest-min.js.map +1 -1
- package/build/xrpl-latest.js +18365 -75189
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/Wallet/authorizeChannel.d.ts +3 -0
- package/dist/npm/Wallet/authorizeChannel.d.ts.map +1 -0
- package/dist/npm/Wallet/authorizeChannel.js +14 -0
- package/dist/npm/Wallet/authorizeChannel.js.map +1 -0
- package/dist/npm/Wallet/defaultFaucets.d.ts.map +1 -1
- package/dist/npm/Wallet/defaultFaucets.js +1 -4
- package/dist/npm/Wallet/defaultFaucets.js.map +1 -1
- package/dist/npm/Wallet/fundWallet.d.ts +17 -3
- package/dist/npm/Wallet/fundWallet.d.ts.map +1 -1
- package/dist/npm/Wallet/fundWallet.js +53 -78
- package/dist/npm/Wallet/fundWallet.js.map +1 -1
- package/dist/npm/Wallet/index.d.ts.map +1 -1
- package/dist/npm/Wallet/index.js +24 -23
- package/dist/npm/Wallet/index.js.map +1 -1
- package/dist/npm/Wallet/signer.d.ts +2 -4
- package/dist/npm/Wallet/signer.d.ts.map +1 -1
- package/dist/npm/Wallet/signer.js +17 -13
- package/dist/npm/Wallet/signer.js.map +1 -1
- package/dist/npm/Wallet/walletFromSecretNumbers.js +2 -2
- package/dist/npm/Wallet/walletFromSecretNumbers.js.map +1 -1
- package/dist/npm/client/RequestManager.d.ts +3 -2
- package/dist/npm/client/RequestManager.d.ts.map +1 -1
- package/dist/npm/client/RequestManager.js +25 -1
- package/dist/npm/client/RequestManager.js.map +1 -1
- package/dist/npm/client/connection.d.ts +8 -11
- package/dist/npm/client/connection.d.ts.map +1 -1
- package/dist/npm/client/connection.js +8 -54
- package/dist/npm/client/connection.js.map +1 -1
- package/dist/npm/client/index.d.ts +56 -78
- package/dist/npm/client/index.d.ts.map +1 -1
- package/dist/npm/client/index.js +155 -42
- package/dist/npm/client/index.js.map +1 -1
- package/dist/npm/client/partialPayment.d.ts +4 -2
- package/dist/npm/client/partialPayment.d.ts.map +1 -1
- package/dist/npm/client/partialPayment.js.map +1 -1
- package/dist/npm/errors.d.ts.map +1 -1
- package/dist/npm/errors.js +1 -2
- package/dist/npm/errors.js.map +1 -1
- package/dist/npm/index.d.ts +1 -1
- package/dist/npm/index.d.ts.map +1 -1
- package/dist/npm/index.js +1 -3
- package/dist/npm/index.js.map +1 -1
- package/dist/npm/models/ledger/AMM.d.ts +2 -4
- package/dist/npm/models/ledger/AMM.d.ts.map +1 -1
- package/dist/npm/models/ledger/AccountRoot.d.ts +2 -4
- package/dist/npm/models/ledger/AccountRoot.d.ts.map +1 -1
- package/dist/npm/models/ledger/AccountRoot.js +1 -1
- package/dist/npm/models/ledger/AccountRoot.js.map +1 -1
- package/dist/npm/models/ledger/Amendments.d.ts +2 -2
- package/dist/npm/models/ledger/Amendments.d.ts.map +1 -1
- package/dist/npm/models/ledger/BaseLedgerEntry.d.ts +9 -1
- package/dist/npm/models/ledger/BaseLedgerEntry.d.ts.map +1 -1
- package/dist/npm/models/ledger/Bridge.d.ts +2 -4
- package/dist/npm/models/ledger/Bridge.d.ts.map +1 -1
- package/dist/npm/models/ledger/Check.d.ts +2 -2
- package/dist/npm/models/ledger/Check.d.ts.map +1 -1
- package/dist/npm/models/ledger/DepositPreauth.d.ts +2 -4
- package/dist/npm/models/ledger/DepositPreauth.d.ts.map +1 -1
- package/dist/npm/models/ledger/DirectoryNode.d.ts +2 -2
- package/dist/npm/models/ledger/DirectoryNode.d.ts.map +1 -1
- package/dist/npm/models/ledger/Escrow.d.ts +2 -4
- package/dist/npm/models/ledger/Escrow.d.ts.map +1 -1
- package/dist/npm/models/ledger/FeeSettings.d.ts +2 -2
- package/dist/npm/models/ledger/FeeSettings.d.ts.map +1 -1
- package/dist/npm/models/ledger/Ledger.d.ts +3 -3
- package/dist/npm/models/ledger/Ledger.d.ts.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/ledger/LedgerHashes.d.ts +2 -2
- package/dist/npm/models/ledger/LedgerHashes.d.ts.map +1 -1
- package/dist/npm/models/ledger/NFTokenOffer.d.ts +2 -4
- package/dist/npm/models/ledger/NFTokenOffer.d.ts.map +1 -1
- package/dist/npm/models/ledger/NFTokenPage.d.ts +2 -4
- package/dist/npm/models/ledger/NFTokenPage.d.ts.map +1 -1
- package/dist/npm/models/ledger/NegativeUNL.d.ts +2 -2
- package/dist/npm/models/ledger/NegativeUNL.d.ts.map +1 -1
- package/dist/npm/models/ledger/Offer.d.ts +2 -4
- package/dist/npm/models/ledger/Offer.d.ts.map +1 -1
- package/dist/npm/models/ledger/Offer.js +1 -1
- package/dist/npm/models/ledger/Offer.js.map +1 -1
- package/dist/npm/models/ledger/PayChannel.d.ts +2 -4
- package/dist/npm/models/ledger/PayChannel.d.ts.map +1 -1
- package/dist/npm/models/ledger/RippleState.d.ts +2 -4
- package/dist/npm/models/ledger/RippleState.d.ts.map +1 -1
- package/dist/npm/models/ledger/RippleState.js +1 -1
- package/dist/npm/models/ledger/RippleState.js.map +1 -1
- package/dist/npm/models/ledger/SignerList.d.ts +2 -4
- package/dist/npm/models/ledger/SignerList.d.ts.map +1 -1
- package/dist/npm/models/ledger/SignerList.js +1 -1
- package/dist/npm/models/ledger/SignerList.js.map +1 -1
- package/dist/npm/models/ledger/Ticket.d.ts +2 -4
- package/dist/npm/models/ledger/Ticket.d.ts.map +1 -1
- package/dist/npm/models/ledger/XChainOwnedClaimID.d.ts +2 -4
- package/dist/npm/models/ledger/XChainOwnedClaimID.d.ts.map +1 -1
- package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.d.ts +2 -4
- package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.d.ts.map +1 -1
- package/dist/npm/models/ledger/index.d.ts +2 -2
- package/dist/npm/models/ledger/index.d.ts.map +1 -1
- package/dist/npm/models/ledger/index.js.map +1 -1
- package/dist/npm/models/methods/accountObjects.d.ts +4 -3
- package/dist/npm/models/methods/accountObjects.d.ts.map +1 -1
- package/dist/npm/models/methods/index.d.ts +12 -1
- package/dist/npm/models/methods/index.d.ts.map +1 -1
- package/dist/npm/models/methods/ledger.d.ts +37 -7
- package/dist/npm/models/methods/ledger.d.ts.map +1 -1
- package/dist/npm/models/methods/ledgerData.d.ts +2 -1
- package/dist/npm/models/methods/ledgerData.d.ts.map +1 -1
- package/dist/npm/models/methods/ledgerEntry.d.ts +2 -2
- package/dist/npm/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/models/methods/subscribe.d.ts +3 -0
- package/dist/npm/models/methods/subscribe.d.ts.map +1 -1
- package/dist/npm/models/methods/tx.d.ts +3 -2
- package/dist/npm/models/methods/tx.d.ts.map +1 -1
- package/dist/npm/models/transactions/AMMDeposit.js +1 -1
- package/dist/npm/models/transactions/AMMDeposit.js.map +1 -1
- package/dist/npm/models/transactions/AMMWithdraw.js +1 -1
- package/dist/npm/models/transactions/AMMWithdraw.js.map +1 -1
- package/dist/npm/models/transactions/NFTokenAcceptOffer.d.ts +4 -0
- package/dist/npm/models/transactions/NFTokenAcceptOffer.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenAcceptOffer.js.map +1 -1
- package/dist/npm/models/transactions/NFTokenBurn.d.ts +3 -3
- package/dist/npm/models/transactions/NFTokenBurn.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenBurn.js +2 -4
- package/dist/npm/models/transactions/NFTokenBurn.js.map +1 -1
- package/dist/npm/models/transactions/NFTokenCancelOffer.d.ts +4 -0
- package/dist/npm/models/transactions/NFTokenCancelOffer.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenCancelOffer.js.map +1 -1
- package/dist/npm/models/transactions/NFTokenCreateOffer.d.ts +7 -3
- package/dist/npm/models/transactions/NFTokenCreateOffer.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenCreateOffer.js +3 -1
- package/dist/npm/models/transactions/NFTokenCreateOffer.js.map +1 -1
- package/dist/npm/models/transactions/NFTokenMint.d.ts +6 -2
- package/dist/npm/models/transactions/NFTokenMint.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenMint.js +2 -1
- package/dist/npm/models/transactions/NFTokenMint.js.map +1 -1
- package/dist/npm/models/transactions/UNLModify.d.ts +2 -1
- package/dist/npm/models/transactions/UNLModify.d.ts.map +1 -1
- package/dist/npm/models/transactions/XChainAccountCreateCommit.d.ts +2 -2
- package/dist/npm/models/transactions/XChainAccountCreateCommit.d.ts.map +1 -1
- package/dist/npm/models/transactions/XChainAccountCreateCommit.js +1 -2
- package/dist/npm/models/transactions/XChainAccountCreateCommit.js.map +1 -1
- package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.d.ts +5 -5
- package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.d.ts.map +1 -1
- package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.js +4 -4
- package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.js.map +1 -1
- package/dist/npm/models/transactions/XChainAddClaimAttestation.d.ts +5 -5
- package/dist/npm/models/transactions/XChainAddClaimAttestation.d.ts.map +1 -1
- package/dist/npm/models/transactions/XChainAddClaimAttestation.js +4 -4
- package/dist/npm/models/transactions/XChainAddClaimAttestation.js.map +1 -1
- package/dist/npm/models/transactions/XChainClaim.d.ts +2 -2
- package/dist/npm/models/transactions/XChainClaim.d.ts.map +1 -1
- package/dist/npm/models/transactions/XChainClaim.js +1 -1
- package/dist/npm/models/transactions/XChainClaim.js.map +1 -1
- package/dist/npm/models/transactions/XChainCommit.d.ts +2 -2
- package/dist/npm/models/transactions/XChainCommit.d.ts.map +1 -1
- package/dist/npm/models/transactions/XChainCommit.js +1 -1
- package/dist/npm/models/transactions/XChainCommit.js.map +1 -1
- package/dist/npm/models/transactions/XChainCreateClaimID.d.ts +2 -2
- package/dist/npm/models/transactions/XChainCreateClaimID.d.ts.map +1 -1
- package/dist/npm/models/transactions/XChainCreateClaimID.js +1 -1
- package/dist/npm/models/transactions/XChainCreateClaimID.js.map +1 -1
- package/dist/npm/models/transactions/XChainModifyBridge.js +1 -1
- package/dist/npm/models/transactions/XChainModifyBridge.js.map +1 -1
- package/dist/npm/models/transactions/accountDelete.d.ts +2 -2
- package/dist/npm/models/transactions/accountDelete.d.ts.map +1 -1
- package/dist/npm/models/transactions/accountDelete.js +2 -11
- package/dist/npm/models/transactions/accountDelete.js.map +1 -1
- package/dist/npm/models/transactions/accountSet.d.ts +2 -2
- package/dist/npm/models/transactions/accountSet.d.ts.map +1 -1
- package/dist/npm/models/transactions/accountSet.js +3 -7
- package/dist/npm/models/transactions/accountSet.js.map +1 -1
- package/dist/npm/models/transactions/checkCreate.d.ts +2 -2
- package/dist/npm/models/transactions/checkCreate.d.ts.map +1 -1
- package/dist/npm/models/transactions/checkCreate.js +2 -10
- package/dist/npm/models/transactions/checkCreate.js.map +1 -1
- package/dist/npm/models/transactions/common.d.ts +3 -1
- package/dist/npm/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/models/transactions/common.js +7 -1
- package/dist/npm/models/transactions/common.js.map +1 -1
- package/dist/npm/models/transactions/enableAmendment.js +1 -1
- package/dist/npm/models/transactions/enableAmendment.js.map +1 -1
- package/dist/npm/models/transactions/escrowCancel.d.ts +2 -2
- package/dist/npm/models/transactions/escrowCancel.d.ts.map +1 -1
- package/dist/npm/models/transactions/escrowCancel.js +1 -6
- package/dist/npm/models/transactions/escrowCancel.js.map +1 -1
- package/dist/npm/models/transactions/escrowCreate.d.ts +2 -2
- package/dist/npm/models/transactions/escrowCreate.d.ts.map +1 -1
- package/dist/npm/models/transactions/escrowCreate.js +2 -10
- package/dist/npm/models/transactions/escrowCreate.js.map +1 -1
- package/dist/npm/models/transactions/escrowFinish.d.ts +2 -2
- package/dist/npm/models/transactions/escrowFinish.d.ts.map +1 -1
- package/dist/npm/models/transactions/escrowFinish.js +1 -6
- package/dist/npm/models/transactions/escrowFinish.js.map +1 -1
- package/dist/npm/models/transactions/index.d.ts +1 -1
- package/dist/npm/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/models/transactions/index.js.map +1 -1
- package/dist/npm/models/transactions/metadata.d.ts +9 -1
- package/dist/npm/models/transactions/metadata.d.ts.map +1 -1
- package/dist/npm/models/transactions/metadata.js.map +1 -1
- package/dist/npm/models/transactions/offerCreate.js +1 -1
- package/dist/npm/models/transactions/offerCreate.js.map +1 -1
- package/dist/npm/models/transactions/payment.d.ts +7 -2
- package/dist/npm/models/transactions/payment.d.ts.map +1 -1
- package/dist/npm/models/transactions/payment.js +3 -10
- package/dist/npm/models/transactions/payment.js.map +1 -1
- package/dist/npm/models/transactions/paymentChannelClaim.js +1 -1
- package/dist/npm/models/transactions/paymentChannelClaim.js.map +1 -1
- package/dist/npm/models/transactions/paymentChannelCreate.d.ts +2 -2
- package/dist/npm/models/transactions/paymentChannelCreate.d.ts.map +1 -1
- package/dist/npm/models/transactions/paymentChannelCreate.js +2 -10
- package/dist/npm/models/transactions/paymentChannelCreate.js.map +1 -1
- package/dist/npm/models/transactions/transaction.d.ts +8 -3
- package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/models/transactions/transaction.js.map +1 -1
- package/dist/npm/models/transactions/trustSet.js +1 -1
- package/dist/npm/models/transactions/trustSet.js.map +1 -1
- package/dist/npm/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/models/utils/flags.js +17 -28
- package/dist/npm/models/utils/flags.js.map +1 -1
- package/dist/npm/snippets/src/bridgeTransfer.js +4 -3
- package/dist/npm/snippets/src/bridgeTransfer.js.map +1 -1
- package/dist/npm/snippets/src/getTransaction.js +1 -1
- package/dist/npm/snippets/src/getTransaction.js.map +1 -1
- package/dist/npm/snippets/src/paths.js +2 -3
- package/dist/npm/snippets/src/paths.js.map +1 -1
- package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -0
- package/dist/npm/src/Wallet/authorizeChannel.d.ts +3 -0
- package/dist/npm/src/Wallet/authorizeChannel.d.ts.map +1 -0
- package/dist/npm/src/Wallet/authorizeChannel.js +14 -0
- package/dist/npm/src/Wallet/authorizeChannel.js.map +1 -0
- package/dist/npm/src/Wallet/defaultFaucets.d.ts.map +1 -1
- package/dist/npm/src/Wallet/defaultFaucets.js +1 -4
- package/dist/npm/src/Wallet/defaultFaucets.js.map +1 -1
- package/dist/npm/src/Wallet/fundWallet.d.ts +17 -3
- package/dist/npm/src/Wallet/fundWallet.d.ts.map +1 -1
- package/dist/npm/src/Wallet/fundWallet.js +53 -78
- package/dist/npm/src/Wallet/fundWallet.js.map +1 -1
- package/dist/npm/src/Wallet/index.d.ts.map +1 -1
- package/dist/npm/src/Wallet/index.js +24 -23
- package/dist/npm/src/Wallet/index.js.map +1 -1
- package/dist/npm/src/Wallet/signer.d.ts +2 -4
- package/dist/npm/src/Wallet/signer.d.ts.map +1 -1
- package/dist/npm/src/Wallet/signer.js +17 -13
- package/dist/npm/src/Wallet/signer.js.map +1 -1
- package/dist/npm/src/Wallet/walletFromSecretNumbers.js +2 -2
- package/dist/npm/src/Wallet/walletFromSecretNumbers.js.map +1 -1
- package/dist/npm/src/client/RequestManager.d.ts +3 -2
- package/dist/npm/src/client/RequestManager.d.ts.map +1 -1
- package/dist/npm/src/client/RequestManager.js +25 -1
- package/dist/npm/src/client/RequestManager.js.map +1 -1
- package/dist/npm/src/client/connection.d.ts +8 -11
- package/dist/npm/src/client/connection.d.ts.map +1 -1
- package/dist/npm/src/client/connection.js +8 -54
- package/dist/npm/src/client/connection.js.map +1 -1
- package/dist/npm/src/client/index.d.ts +56 -78
- package/dist/npm/src/client/index.d.ts.map +1 -1
- package/dist/npm/src/client/index.js +155 -42
- package/dist/npm/src/client/index.js.map +1 -1
- package/dist/npm/src/client/partialPayment.d.ts +4 -2
- package/dist/npm/src/client/partialPayment.d.ts.map +1 -1
- package/dist/npm/src/client/partialPayment.js.map +1 -1
- package/dist/npm/src/errors.d.ts.map +1 -1
- package/dist/npm/src/errors.js +1 -2
- package/dist/npm/src/errors.js.map +1 -1
- package/dist/npm/src/index.d.ts +1 -1
- package/dist/npm/src/index.d.ts.map +1 -1
- package/dist/npm/src/index.js +1 -3
- package/dist/npm/src/index.js.map +1 -1
- package/dist/npm/src/models/ledger/AMM.d.ts +2 -4
- package/dist/npm/src/models/ledger/AMM.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/AccountRoot.d.ts +2 -4
- package/dist/npm/src/models/ledger/AccountRoot.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/AccountRoot.js +1 -1
- package/dist/npm/src/models/ledger/AccountRoot.js.map +1 -1
- package/dist/npm/src/models/ledger/Amendments.d.ts +2 -2
- package/dist/npm/src/models/ledger/Amendments.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/BaseLedgerEntry.d.ts +9 -1
- package/dist/npm/src/models/ledger/BaseLedgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/Bridge.d.ts +2 -4
- package/dist/npm/src/models/ledger/Bridge.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/Check.d.ts +2 -2
- package/dist/npm/src/models/ledger/Check.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/DepositPreauth.d.ts +2 -4
- package/dist/npm/src/models/ledger/DepositPreauth.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/DirectoryNode.d.ts +2 -2
- package/dist/npm/src/models/ledger/DirectoryNode.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/Escrow.d.ts +2 -4
- package/dist/npm/src/models/ledger/Escrow.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/FeeSettings.d.ts +2 -2
- package/dist/npm/src/models/ledger/FeeSettings.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/Ledger.d.ts +3 -3
- package/dist/npm/src/models/ledger/Ledger.d.ts.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/ledger/LedgerHashes.d.ts +2 -2
- package/dist/npm/src/models/ledger/LedgerHashes.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/NFTokenOffer.d.ts +2 -4
- package/dist/npm/src/models/ledger/NFTokenOffer.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/NFTokenPage.d.ts +2 -4
- package/dist/npm/src/models/ledger/NFTokenPage.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/NegativeUNL.d.ts +2 -2
- package/dist/npm/src/models/ledger/NegativeUNL.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/Offer.d.ts +2 -4
- package/dist/npm/src/models/ledger/Offer.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/Offer.js +1 -1
- package/dist/npm/src/models/ledger/Offer.js.map +1 -1
- package/dist/npm/src/models/ledger/PayChannel.d.ts +2 -4
- package/dist/npm/src/models/ledger/PayChannel.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/RippleState.d.ts +2 -4
- package/dist/npm/src/models/ledger/RippleState.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/RippleState.js +1 -1
- package/dist/npm/src/models/ledger/RippleState.js.map +1 -1
- package/dist/npm/src/models/ledger/SignerList.d.ts +2 -4
- package/dist/npm/src/models/ledger/SignerList.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/SignerList.js +1 -1
- package/dist/npm/src/models/ledger/SignerList.js.map +1 -1
- package/dist/npm/src/models/ledger/Ticket.d.ts +2 -4
- package/dist/npm/src/models/ledger/Ticket.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/XChainOwnedClaimID.d.ts +2 -4
- package/dist/npm/src/models/ledger/XChainOwnedClaimID.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.d.ts +2 -4
- package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/index.d.ts +2 -2
- package/dist/npm/src/models/ledger/index.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/index.js.map +1 -1
- package/dist/npm/src/models/methods/accountObjects.d.ts +4 -3
- package/dist/npm/src/models/methods/accountObjects.d.ts.map +1 -1
- package/dist/npm/src/models/methods/index.d.ts +12 -1
- package/dist/npm/src/models/methods/index.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ledger.d.ts +37 -7
- package/dist/npm/src/models/methods/ledger.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ledgerData.d.ts +2 -1
- package/dist/npm/src/models/methods/ledgerData.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ledgerEntry.d.ts +2 -2
- package/dist/npm/src/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/methods/subscribe.d.ts +3 -0
- package/dist/npm/src/models/methods/subscribe.d.ts.map +1 -1
- package/dist/npm/src/models/methods/tx.d.ts +3 -2
- package/dist/npm/src/models/methods/tx.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/AMMDeposit.js +1 -1
- package/dist/npm/src/models/transactions/AMMDeposit.js.map +1 -1
- package/dist/npm/src/models/transactions/AMMWithdraw.js +1 -1
- package/dist/npm/src/models/transactions/AMMWithdraw.js.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenAcceptOffer.d.ts +4 -0
- package/dist/npm/src/models/transactions/NFTokenAcceptOffer.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenAcceptOffer.js.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenBurn.d.ts +3 -3
- package/dist/npm/src/models/transactions/NFTokenBurn.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenBurn.js +2 -4
- package/dist/npm/src/models/transactions/NFTokenBurn.js.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenCancelOffer.d.ts +4 -0
- package/dist/npm/src/models/transactions/NFTokenCancelOffer.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenCancelOffer.js.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenCreateOffer.d.ts +7 -3
- package/dist/npm/src/models/transactions/NFTokenCreateOffer.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenCreateOffer.js +3 -1
- package/dist/npm/src/models/transactions/NFTokenCreateOffer.js.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenMint.d.ts +6 -2
- package/dist/npm/src/models/transactions/NFTokenMint.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenMint.js +2 -1
- package/dist/npm/src/models/transactions/NFTokenMint.js.map +1 -1
- package/dist/npm/src/models/transactions/UNLModify.d.ts +2 -1
- package/dist/npm/src/models/transactions/UNLModify.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/XChainAccountCreateCommit.d.ts +2 -2
- package/dist/npm/src/models/transactions/XChainAccountCreateCommit.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/XChainAccountCreateCommit.js +1 -2
- package/dist/npm/src/models/transactions/XChainAccountCreateCommit.js.map +1 -1
- package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.d.ts +5 -5
- package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.js +4 -4
- package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.js.map +1 -1
- package/dist/npm/src/models/transactions/XChainAddClaimAttestation.d.ts +5 -5
- package/dist/npm/src/models/transactions/XChainAddClaimAttestation.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/XChainAddClaimAttestation.js +4 -4
- package/dist/npm/src/models/transactions/XChainAddClaimAttestation.js.map +1 -1
- package/dist/npm/src/models/transactions/XChainClaim.d.ts +2 -2
- package/dist/npm/src/models/transactions/XChainClaim.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/XChainClaim.js +1 -1
- package/dist/npm/src/models/transactions/XChainClaim.js.map +1 -1
- package/dist/npm/src/models/transactions/XChainCommit.d.ts +2 -2
- package/dist/npm/src/models/transactions/XChainCommit.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/XChainCommit.js +1 -1
- package/dist/npm/src/models/transactions/XChainCommit.js.map +1 -1
- package/dist/npm/src/models/transactions/XChainCreateClaimID.d.ts +2 -2
- package/dist/npm/src/models/transactions/XChainCreateClaimID.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/XChainCreateClaimID.js +1 -1
- package/dist/npm/src/models/transactions/XChainCreateClaimID.js.map +1 -1
- package/dist/npm/src/models/transactions/XChainModifyBridge.js +1 -1
- package/dist/npm/src/models/transactions/XChainModifyBridge.js.map +1 -1
- package/dist/npm/src/models/transactions/accountDelete.d.ts +2 -2
- package/dist/npm/src/models/transactions/accountDelete.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/accountDelete.js +2 -11
- package/dist/npm/src/models/transactions/accountDelete.js.map +1 -1
- package/dist/npm/src/models/transactions/accountSet.d.ts +2 -2
- package/dist/npm/src/models/transactions/accountSet.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/accountSet.js +3 -7
- package/dist/npm/src/models/transactions/accountSet.js.map +1 -1
- package/dist/npm/src/models/transactions/checkCreate.d.ts +2 -2
- package/dist/npm/src/models/transactions/checkCreate.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/checkCreate.js +2 -10
- package/dist/npm/src/models/transactions/checkCreate.js.map +1 -1
- package/dist/npm/src/models/transactions/common.d.ts +3 -1
- package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/common.js +7 -1
- package/dist/npm/src/models/transactions/common.js.map +1 -1
- package/dist/npm/src/models/transactions/enableAmendment.js +1 -1
- package/dist/npm/src/models/transactions/enableAmendment.js.map +1 -1
- package/dist/npm/src/models/transactions/escrowCancel.d.ts +2 -2
- package/dist/npm/src/models/transactions/escrowCancel.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/escrowCancel.js +1 -6
- package/dist/npm/src/models/transactions/escrowCancel.js.map +1 -1
- package/dist/npm/src/models/transactions/escrowCreate.d.ts +2 -2
- package/dist/npm/src/models/transactions/escrowCreate.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/escrowCreate.js +2 -10
- package/dist/npm/src/models/transactions/escrowCreate.js.map +1 -1
- package/dist/npm/src/models/transactions/escrowFinish.d.ts +2 -2
- package/dist/npm/src/models/transactions/escrowFinish.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/escrowFinish.js +1 -6
- package/dist/npm/src/models/transactions/escrowFinish.js.map +1 -1
- package/dist/npm/src/models/transactions/index.d.ts +1 -1
- package/dist/npm/src/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/index.js.map +1 -1
- package/dist/npm/src/models/transactions/metadata.d.ts +9 -1
- package/dist/npm/src/models/transactions/metadata.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/metadata.js.map +1 -1
- package/dist/npm/src/models/transactions/offerCreate.js +1 -1
- package/dist/npm/src/models/transactions/offerCreate.js.map +1 -1
- package/dist/npm/src/models/transactions/payment.d.ts +7 -2
- package/dist/npm/src/models/transactions/payment.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/payment.js +3 -10
- package/dist/npm/src/models/transactions/payment.js.map +1 -1
- package/dist/npm/src/models/transactions/paymentChannelClaim.js +1 -1
- package/dist/npm/src/models/transactions/paymentChannelClaim.js.map +1 -1
- package/dist/npm/src/models/transactions/paymentChannelCreate.d.ts +2 -2
- package/dist/npm/src/models/transactions/paymentChannelCreate.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/paymentChannelCreate.js +2 -10
- package/dist/npm/src/models/transactions/paymentChannelCreate.js.map +1 -1
- package/dist/npm/src/models/transactions/transaction.d.ts +8 -3
- package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/transaction.js.map +1 -1
- package/dist/npm/src/models/transactions/trustSet.js +1 -1
- package/dist/npm/src/models/transactions/trustSet.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 -28
- package/dist/npm/src/models/utils/flags.js.map +1 -1
- package/dist/npm/src/sugar/autofill.d.ts +6 -2
- package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/src/sugar/autofill.js +9 -28
- package/dist/npm/src/sugar/autofill.js.map +1 -1
- package/dist/npm/src/sugar/balances.d.ts +2 -17
- package/dist/npm/src/sugar/balances.d.ts.map +1 -1
- package/dist/npm/src/sugar/balances.js +2 -60
- package/dist/npm/src/sugar/balances.js.map +1 -1
- package/dist/npm/src/sugar/getOrderbook.d.ts +19 -5
- package/dist/npm/src/sugar/getOrderbook.d.ts.map +1 -1
- package/dist/npm/src/sugar/getOrderbook.js +72 -53
- package/dist/npm/src/sugar/getOrderbook.js.map +1 -1
- package/dist/npm/src/sugar/index.d.ts +0 -4
- package/dist/npm/src/sugar/index.d.ts.map +1 -1
- package/dist/npm/src/sugar/index.js +0 -13
- package/dist/npm/src/sugar/index.js.map +1 -1
- package/dist/npm/src/sugar/submit.d.ts +6 -9
- package/dist/npm/src/sugar/submit.d.ts.map +1 -1
- package/dist/npm/src/sugar/submit.js +5 -22
- package/dist/npm/src/sugar/submit.js.map +1 -1
- package/dist/npm/src/utils/collections.d.ts +7 -0
- package/dist/npm/src/utils/collections.d.ts.map +1 -0
- package/dist/npm/src/utils/collections.js +22 -0
- package/dist/npm/src/utils/collections.js.map +1 -0
- package/dist/npm/src/utils/getBalanceChanges.d.ts.map +1 -1
- package/dist/npm/src/utils/getBalanceChanges.js +3 -4
- package/dist/npm/src/utils/getBalanceChanges.js.map +1 -1
- package/dist/npm/src/utils/getNFTokenID.d.ts.map +1 -1
- package/dist/npm/src/utils/getNFTokenID.js +8 -8
- package/dist/npm/src/utils/getNFTokenID.js.map +1 -1
- package/dist/npm/src/utils/hashes/SHAMap/node.js +1 -1
- package/dist/npm/src/utils/hashes/SHAMap/node.js.map +1 -1
- package/dist/npm/src/utils/hashes/hashLedger.d.ts +2 -1
- package/dist/npm/src/utils/hashes/hashLedger.d.ts.map +1 -1
- package/dist/npm/src/utils/hashes/hashLedger.js.map +1 -1
- package/dist/npm/src/utils/hashes/sha512Half.d.ts.map +1 -1
- package/dist/npm/src/utils/hashes/sha512Half.js +4 -7
- package/dist/npm/src/utils/hashes/sha512Half.js.map +1 -1
- package/dist/npm/sugar/autofill.d.ts +6 -2
- package/dist/npm/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/sugar/autofill.js +9 -28
- package/dist/npm/sugar/autofill.js.map +1 -1
- package/dist/npm/sugar/balances.d.ts +2 -17
- package/dist/npm/sugar/balances.d.ts.map +1 -1
- package/dist/npm/sugar/balances.js +2 -60
- package/dist/npm/sugar/balances.js.map +1 -1
- package/dist/npm/sugar/getOrderbook.d.ts +19 -5
- package/dist/npm/sugar/getOrderbook.d.ts.map +1 -1
- package/dist/npm/sugar/getOrderbook.js +72 -53
- package/dist/npm/sugar/getOrderbook.js.map +1 -1
- package/dist/npm/sugar/index.d.ts +0 -4
- package/dist/npm/sugar/index.d.ts.map +1 -1
- package/dist/npm/sugar/index.js +0 -13
- package/dist/npm/sugar/index.js.map +1 -1
- package/dist/npm/sugar/submit.d.ts +6 -9
- package/dist/npm/sugar/submit.d.ts.map +1 -1
- package/dist/npm/sugar/submit.js +5 -22
- package/dist/npm/sugar/submit.js.map +1 -1
- package/dist/npm/utils/collections.d.ts +7 -0
- package/dist/npm/utils/collections.d.ts.map +1 -0
- package/dist/npm/utils/collections.js +22 -0
- package/dist/npm/utils/collections.js.map +1 -0
- package/dist/npm/utils/getBalanceChanges.d.ts.map +1 -1
- package/dist/npm/utils/getBalanceChanges.js +3 -4
- package/dist/npm/utils/getBalanceChanges.js.map +1 -1
- package/dist/npm/utils/getNFTokenID.d.ts.map +1 -1
- package/dist/npm/utils/getNFTokenID.js +8 -8
- package/dist/npm/utils/getNFTokenID.js.map +1 -1
- package/dist/npm/utils/hashes/SHAMap/node.js +1 -1
- package/dist/npm/utils/hashes/SHAMap/node.js.map +1 -1
- package/dist/npm/utils/hashes/hashLedger.d.ts +2 -1
- package/dist/npm/utils/hashes/hashLedger.d.ts.map +1 -1
- package/dist/npm/utils/hashes/hashLedger.js.map +1 -1
- package/dist/npm/utils/hashes/sha512Half.d.ts.map +1 -1
- package/dist/npm/utils/hashes/sha512Half.js +4 -7
- package/dist/npm/utils/hashes/sha512Half.js.map +1 -1
- package/package.json +32 -25
- package/src/Wallet/authorizeChannel.ts +26 -0
- package/src/Wallet/defaultFaucets.ts +0 -4
- package/src/Wallet/fundWallet.ts +151 -212
- package/src/Wallet/index.ts +28 -25
- package/src/Wallet/signer.ts +32 -43
- package/src/Wallet/walletFromSecretNumbers.ts +1 -1
- package/src/client/RequestManager.ts +40 -14
- package/src/client/connection.ts +20 -89
- package/src/client/index.ts +704 -269
- package/src/client/partialPayment.ts +20 -10
- package/src/errors.ts +1 -3
- package/src/index.ts +1 -3
- package/src/models/ledger/AMM.ts +2 -10
- package/src/models/ledger/AccountRoot.ts +2 -12
- package/src/models/ledger/Amendments.ts +4 -2
- package/src/models/ledger/BaseLedgerEntry.ts +25 -1
- package/src/models/ledger/Bridge.ts +2 -14
- package/src/models/ledger/Check.ts +2 -2
- package/src/models/ledger/DepositPreauth.ts +4 -12
- package/src/models/ledger/DirectoryNode.ts +4 -2
- package/src/models/ledger/Escrow.ts +2 -12
- package/src/models/ledger/FeeSettings.ts +2 -2
- package/src/models/ledger/Ledger.ts +10 -4
- package/src/models/ledger/LedgerEntry.ts +22 -1
- package/src/models/ledger/LedgerHashes.ts +4 -2
- package/src/models/ledger/NFTokenOffer.ts +2 -4
- package/src/models/ledger/NFTokenPage.ts +2 -4
- package/src/models/ledger/NegativeUNL.ts +4 -2
- package/src/models/ledger/Offer.ts +2 -12
- package/src/models/ledger/PayChannel.ts +2 -12
- package/src/models/ledger/RippleState.ts +2 -12
- package/src/models/ledger/SignerList.ts +2 -12
- package/src/models/ledger/Ticket.ts +2 -12
- package/src/models/ledger/XChainOwnedClaimID.ts +4 -12
- package/src/models/ledger/XChainOwnedCreateAccountClaimID.ts +3 -12
- package/src/models/ledger/index.ts +2 -1
- package/src/models/methods/accountObjects.ts +10 -44
- package/src/models/methods/index.ts +175 -0
- package/src/models/methods/ledger.ts +154 -20
- package/src/models/methods/ledgerData.ts +5 -1
- package/src/models/methods/ledgerEntry.ts +2 -2
- package/src/models/methods/subscribe.ts +36 -0
- package/src/models/methods/tx.ts +6 -3
- package/src/models/transactions/NFTokenAcceptOffer.ts +6 -0
- package/src/models/transactions/NFTokenBurn.ts +13 -9
- package/src/models/transactions/NFTokenCancelOffer.ts +6 -0
- package/src/models/transactions/NFTokenCreateOffer.ts +14 -2
- package/src/models/transactions/NFTokenMint.ts +17 -2
- package/src/models/transactions/UNLModify.ts +3 -1
- package/src/models/transactions/XChainAccountCreateCommit.ts +4 -4
- package/src/models/transactions/XChainAddAccountCreateAttestation.ts +10 -8
- package/src/models/transactions/XChainAddClaimAttestation.ts +10 -8
- package/src/models/transactions/XChainClaim.ts +4 -2
- package/src/models/transactions/XChainCommit.ts +4 -2
- package/src/models/transactions/XChainCreateClaimID.ts +4 -3
- package/src/models/transactions/accountDelete.ts +12 -18
- package/src/models/transactions/accountSet.ts +10 -11
- package/src/models/transactions/checkCreate.ts +8 -15
- package/src/models/transactions/common.ts +20 -1
- package/src/models/transactions/escrowCancel.ts +9 -9
- package/src/models/transactions/escrowCreate.ts +12 -16
- package/src/models/transactions/escrowFinish.ts +9 -9
- package/src/models/transactions/index.ts +6 -1
- package/src/models/transactions/metadata.ts +31 -1
- package/src/models/transactions/payment.ts +14 -14
- package/src/models/transactions/paymentChannelCreate.ts +12 -21
- package/src/models/transactions/transaction.ts +11 -4
- package/src/models/utils/flags.ts +18 -28
- package/src/sugar/autofill.ts +84 -88
- package/src/sugar/balances.ts +8 -116
- package/src/sugar/getOrderbook.ts +138 -61
- package/src/sugar/index.ts +0 -8
- package/src/sugar/submit.ts +114 -132
- package/src/utils/collections.ts +53 -0
- package/src/utils/getBalanceChanges.ts +2 -3
- package/src/utils/getNFTokenID.ts +18 -16
- package/src/utils/hashes/hashLedger.ts +4 -1
- package/src/utils/hashes/sha512Half.ts +4 -7
- package/dist/npm/client/BroadcastClient.d.ts +0 -7
- package/dist/npm/client/BroadcastClient.d.ts.map +0 -1
- package/dist/npm/client/BroadcastClient.js +0 -49
- package/dist/npm/client/BroadcastClient.js.map +0 -1
- package/dist/npm/client/WSWrapper.d.ts +0 -25
- package/dist/npm/client/WSWrapper.d.ts.map +0 -1
- package/dist/npm/client/WSWrapper.js +0 -44
- package/dist/npm/client/WSWrapper.js.map +0 -1
- package/dist/npm/src/client/BroadcastClient.d.ts +0 -7
- package/dist/npm/src/client/BroadcastClient.d.ts.map +0 -1
- package/dist/npm/src/client/BroadcastClient.js +0 -49
- package/dist/npm/src/client/BroadcastClient.js.map +0 -1
- package/dist/npm/src/client/WSWrapper.d.ts +0 -25
- package/dist/npm/src/client/WSWrapper.d.ts.map +0 -1
- package/dist/npm/src/client/WSWrapper.js +0 -44
- package/dist/npm/src/client/WSWrapper.js.map +0 -1
- package/dist/npm/src/sugar/getLedgerIndex.d.ts +0 -3
- package/dist/npm/src/sugar/getLedgerIndex.d.ts.map +0 -1
- package/dist/npm/src/sugar/getLedgerIndex.js +0 -22
- package/dist/npm/src/sugar/getLedgerIndex.js.map +0 -1
- package/dist/npm/sugar/getLedgerIndex.d.ts +0 -3
- package/dist/npm/sugar/getLedgerIndex.d.ts.map +0 -1
- package/dist/npm/sugar/getLedgerIndex.js +0 -22
- package/dist/npm/sugar/getLedgerIndex.js.map +0 -1
- package/src/client/BroadcastClient.ts +0 -84
- package/src/client/WSWrapper.ts +0 -106
- package/src/sugar/getLedgerIndex.ts +0 -15
package/src/client/index.ts
CHANGED
@@ -1,116 +1,81 @@
|
|
1
1
|
/* eslint-disable jsdoc/require-jsdoc -- Request has many aliases, but they don't need unique docs */
|
2
|
-
|
2
|
+
|
3
3
|
/* eslint-disable max-lines -- Client is a large file w/ lots of imports/exports */
|
4
|
-
import
|
5
|
-
import { EventEmitter } from 'events'
|
4
|
+
import { EventEmitter } from 'eventemitter3'
|
6
5
|
|
7
|
-
import {
|
6
|
+
import {
|
7
|
+
RippledError,
|
8
|
+
NotFoundError,
|
9
|
+
ValidationError,
|
10
|
+
XrplError,
|
11
|
+
} from '../errors'
|
12
|
+
import type { LedgerIndex, Balance } from '../models/common'
|
8
13
|
import {
|
9
14
|
Request,
|
10
|
-
Response,
|
11
15
|
// account methods
|
12
16
|
AccountChannelsRequest,
|
13
17
|
AccountChannelsResponse,
|
14
|
-
AccountCurrenciesRequest,
|
15
|
-
AccountCurrenciesResponse,
|
16
18
|
AccountInfoRequest,
|
17
|
-
AccountInfoResponse,
|
18
19
|
AccountLinesRequest,
|
19
20
|
AccountLinesResponse,
|
20
|
-
AccountNFTsRequest,
|
21
|
-
AccountNFTsResponse,
|
22
21
|
AccountObjectsRequest,
|
23
22
|
AccountObjectsResponse,
|
24
23
|
AccountOffersRequest,
|
25
24
|
AccountOffersResponse,
|
26
25
|
AccountTxRequest,
|
27
26
|
AccountTxResponse,
|
28
|
-
GatewayBalancesRequest,
|
29
|
-
GatewayBalancesResponse,
|
30
|
-
NoRippleCheckRequest,
|
31
|
-
NoRippleCheckResponse,
|
32
27
|
// ledger methods
|
33
|
-
LedgerRequest,
|
34
|
-
LedgerResponse,
|
35
|
-
LedgerClosedRequest,
|
36
|
-
LedgerClosedResponse,
|
37
|
-
LedgerCurrentRequest,
|
38
|
-
LedgerCurrentResponse,
|
39
28
|
LedgerDataRequest,
|
40
29
|
LedgerDataResponse,
|
41
|
-
LedgerEntryRequest,
|
42
|
-
LedgerEntryResponse,
|
43
|
-
// transaction methods
|
44
|
-
SubmitRequest,
|
45
|
-
SubmitResponse,
|
46
|
-
SubmitMultisignedRequest,
|
47
|
-
SubmitMultisignedResponse,
|
48
|
-
TransactionEntryRequest,
|
49
|
-
TransactionEntryResponse,
|
50
|
-
TxRequest,
|
51
30
|
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
31
|
} from '../models/methods'
|
102
|
-
import {
|
32
|
+
import type {
|
33
|
+
RequestResponseMap,
|
34
|
+
RequestAllResponseMap,
|
35
|
+
MarkerRequest,
|
36
|
+
MarkerResponse,
|
37
|
+
SubmitResponse,
|
38
|
+
} from '../models/methods'
|
39
|
+
import type { BookOffer, BookOfferCurrency } from '../models/methods/bookOffers'
|
40
|
+
import type {
|
41
|
+
EventTypes,
|
42
|
+
OnEventToListenerMap,
|
43
|
+
} from '../models/methods/subscribe'
|
44
|
+
import type { Transaction } from '../models/transactions'
|
45
|
+
import { setTransactionFlagsToNumber } from '../models/utils/flags'
|
103
46
|
import {
|
104
|
-
autofill,
|
105
47
|
ensureClassicAddress,
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
submit,
|
111
|
-
submitAndWait,
|
48
|
+
submitRequest,
|
49
|
+
getSignedTx,
|
50
|
+
getLastLedgerSequence,
|
51
|
+
waitForFinalTransactionOutcome,
|
112
52
|
} from '../sugar'
|
113
|
-
import
|
53
|
+
import {
|
54
|
+
setValidAddresses,
|
55
|
+
setNextValidSequenceNumber,
|
56
|
+
calculateFeePerTransactionType,
|
57
|
+
setLatestValidatedLedgerSequence,
|
58
|
+
checkAccountDeleteBlockers,
|
59
|
+
txNeedsNetworkID,
|
60
|
+
} from '../sugar/autofill'
|
61
|
+
import { formatBalances } from '../sugar/balances'
|
62
|
+
import {
|
63
|
+
validateOrderbookOptions,
|
64
|
+
createBookOffersRequest,
|
65
|
+
requestAllOffers,
|
66
|
+
reverseRequest,
|
67
|
+
extractOffers,
|
68
|
+
combineOrders,
|
69
|
+
separateBuySellOrders,
|
70
|
+
sortAndLimitOffers,
|
71
|
+
} from '../sugar/getOrderbook'
|
72
|
+
import { dropsToXrp, hashes, isValidClassicAddress } from '../utils'
|
73
|
+
import { Wallet } from '../Wallet'
|
74
|
+
import {
|
75
|
+
type FaucetRequestBody,
|
76
|
+
FundingOptions,
|
77
|
+
requestFunding,
|
78
|
+
} from '../Wallet/fundWallet'
|
114
79
|
|
115
80
|
import {
|
116
81
|
Connection,
|
@@ -125,10 +90,32 @@ import {
|
|
125
90
|
export interface ClientOptions extends ConnectionUserOptions {
|
126
91
|
feeCushion?: number
|
127
92
|
maxFeeXRP?: string
|
128
|
-
proxy?: string
|
129
93
|
timeout?: number
|
130
94
|
}
|
131
95
|
|
96
|
+
// Make sure to update both this and `RequestNextPageReturnMap` at the same time
|
97
|
+
type RequestNextPageType =
|
98
|
+
| AccountChannelsRequest
|
99
|
+
| AccountLinesRequest
|
100
|
+
| AccountObjectsRequest
|
101
|
+
| AccountOffersRequest
|
102
|
+
| AccountTxRequest
|
103
|
+
| LedgerDataRequest
|
104
|
+
|
105
|
+
type RequestNextPageReturnMap<T> = T extends AccountChannelsRequest
|
106
|
+
? AccountChannelsResponse
|
107
|
+
: T extends AccountLinesRequest
|
108
|
+
? AccountLinesResponse
|
109
|
+
: T extends AccountObjectsRequest
|
110
|
+
? AccountObjectsResponse
|
111
|
+
: T extends AccountOffersRequest
|
112
|
+
? AccountOffersResponse
|
113
|
+
: T extends AccountTxRequest
|
114
|
+
? AccountTxResponse
|
115
|
+
: T extends LedgerDataRequest
|
116
|
+
? LedgerDataResponse
|
117
|
+
: never
|
118
|
+
|
132
119
|
/**
|
133
120
|
* Get the response key / property name that contains the listed data for a
|
134
121
|
* command. This varies from command to command, but we need to know it to
|
@@ -158,19 +145,10 @@ function getCollectKeyFromCommand(command: string): string | null {
|
|
158
145
|
}
|
159
146
|
|
160
147
|
function clamp(value: number, min: number, max: number): number {
|
161
|
-
|
162
|
-
|
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
|
148
|
+
if (min > max) {
|
149
|
+
throw new Error('Illegal clamp bounds')
|
173
150
|
}
|
151
|
+
return Math.min(Math.max(value, min), max)
|
174
152
|
}
|
175
153
|
|
176
154
|
const DEFAULT_FEE_CUSHION = 1.2
|
@@ -186,7 +164,7 @@ const NORMAL_DISCONNECT_CODE = 1000
|
|
186
164
|
*
|
187
165
|
* @category Clients
|
188
166
|
*/
|
189
|
-
class Client extends EventEmitter {
|
167
|
+
class Client extends EventEmitter<EventTypes> {
|
190
168
|
/*
|
191
169
|
* Underlying connection to rippled.
|
192
170
|
*/
|
@@ -226,6 +204,12 @@ class Client extends EventEmitter {
|
|
226
204
|
* @param server - URL of the server to connect to.
|
227
205
|
* @param options - Options for client settings.
|
228
206
|
* @category Constructor
|
207
|
+
*
|
208
|
+
* @example
|
209
|
+
* ```ts
|
210
|
+
* import { Client } from "xrpl"
|
211
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
212
|
+
* ```
|
229
213
|
*/
|
230
214
|
// eslint-disable-next-line max-lines-per-function -- okay because we have to set up all the connection handlers
|
231
215
|
public constructor(server: string, options: ClientOptions = {}) {
|
@@ -302,84 +286,34 @@ class Client extends EventEmitter {
|
|
302
286
|
return this.connection.getUrl()
|
303
287
|
}
|
304
288
|
|
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
289
|
/**
|
365
290
|
* Makes a request to the client with the given command and
|
366
291
|
* additional request body parameters.
|
367
292
|
*
|
293
|
+
* @category Network
|
294
|
+
*
|
368
295
|
* @param req - Request to send to the server.
|
369
296
|
* @returns The response from the server.
|
370
|
-
*
|
297
|
+
*
|
298
|
+
* @example
|
299
|
+
* ```ts
|
300
|
+
* const response = await client.request({
|
301
|
+
* command: 'account_info',
|
302
|
+
* account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
303
|
+
* })
|
304
|
+
* console.log(response)
|
305
|
+
* ```
|
371
306
|
*/
|
372
|
-
public async request<R extends Request, T
|
307
|
+
public async request<R extends Request, T = RequestResponseMap<R>>(
|
373
308
|
req: R,
|
374
309
|
): Promise<T> {
|
375
|
-
|
376
|
-
const response = (await this.connection.request({
|
310
|
+
const response = await this.connection.request<R, T>({
|
377
311
|
...req,
|
378
312
|
account: req.account
|
379
313
|
? // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Must be string
|
380
314
|
ensureClassicAddress(req.account as string)
|
381
315
|
: undefined,
|
382
|
-
})
|
316
|
+
})
|
383
317
|
|
384
318
|
// mutates `response` to add warnings
|
385
319
|
handlePartialPayment(req.command, response)
|
@@ -387,44 +321,34 @@ class Client extends EventEmitter {
|
|
387
321
|
return response
|
388
322
|
}
|
389
323
|
|
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
324
|
/**
|
418
325
|
* Requests the next page of data.
|
419
326
|
*
|
327
|
+
* @category Network
|
328
|
+
*
|
420
329
|
* @param req - Request to send.
|
421
330
|
* @param resp - Response with the marker to use in the request.
|
422
331
|
* @returns The response with the next page of data.
|
332
|
+
*
|
333
|
+
* @example
|
334
|
+
* ```ts
|
335
|
+
* const response = await client.request({
|
336
|
+
* command: 'account_tx',
|
337
|
+
* account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
338
|
+
* })
|
339
|
+
* console.log(response)
|
340
|
+
* const nextResponse = await client.requestNextPage({
|
341
|
+
* command: 'account_tx',
|
342
|
+
* account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
343
|
+
* },
|
344
|
+
* response)
|
345
|
+
* console.log(nextResponse)
|
346
|
+
* ```
|
423
347
|
*/
|
424
348
|
public async requestNextPage<
|
425
|
-
T extends
|
426
|
-
U extends
|
427
|
-
>(req: T, resp: U): Promise<
|
349
|
+
T extends RequestNextPageType,
|
350
|
+
U extends RequestNextPageReturnMap<T>,
|
351
|
+
>(req: T, resp: U): Promise<RequestNextPageReturnMap<T>> {
|
428
352
|
if (!resp.result.marker) {
|
429
353
|
return Promise.reject(
|
430
354
|
new NotFoundError('response does not have a next page'),
|
@@ -438,7 +362,13 @@ class Client extends EventEmitter {
|
|
438
362
|
/**
|
439
363
|
* Event handler for subscription streams.
|
440
364
|
*
|
441
|
-
* @
|
365
|
+
* @category Network
|
366
|
+
*
|
367
|
+
* @param eventName - Name of the event. Only forwards streams.
|
368
|
+
* @param listener - Function to run on event.
|
369
|
+
* @returns This, because it inherits from EventEmitter.
|
370
|
+
*
|
371
|
+
* * @example
|
442
372
|
* ```ts
|
443
373
|
* const api = new Client('wss://s.altnet.rippletest.net:51233')
|
444
374
|
*
|
@@ -453,68 +383,15 @@ class Client extends EventEmitter {
|
|
453
383
|
* streams: ['transactions_proposed']
|
454
384
|
* })
|
455
385
|
* ```
|
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
386
|
*/
|
495
|
-
|
496
|
-
|
387
|
+
public on<
|
388
|
+
T extends EventTypes,
|
389
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- needs to be any for overload
|
390
|
+
U extends (...args: any[]) => void = OnEventToListenerMap<T>,
|
391
|
+
>(eventName: T, listener: U): this {
|
497
392
|
return super.on(eventName, listener)
|
498
393
|
}
|
499
394
|
|
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
395
|
/**
|
519
396
|
* Makes multiple paged requests to the client to return a given number of
|
520
397
|
* resources. Multiple paged requests will be made until the `limit`
|
@@ -528,15 +405,27 @@ class Client extends EventEmitter {
|
|
528
405
|
* general use. Instead, use rippled's built-in pagination and make multiple
|
529
406
|
* requests as needed.
|
530
407
|
*
|
408
|
+
* @category Network
|
409
|
+
*
|
531
410
|
* @param request - The initial request to send to the server.
|
532
411
|
* @param collect - (Optional) the param to use to collect the array of resources (only needed if command is unknown).
|
533
412
|
* @returns The array of all responses.
|
534
413
|
* @throws ValidationError if there is no collection key (either from a known command or for the unknown command).
|
414
|
+
*
|
415
|
+
* @example
|
416
|
+
* // Request all ledger data pages
|
417
|
+
* const allResponses = await client.requestAll({ command: 'ledger_data' });
|
418
|
+
* console.log(allResponses);
|
419
|
+
*
|
420
|
+
* @example
|
421
|
+
* // Request all transaction data pages
|
422
|
+
* const allResponses = await client.requestAll({ command: 'transaction_data' });
|
423
|
+
* console.log(allResponses);
|
535
424
|
*/
|
536
|
-
public async requestAll<
|
537
|
-
|
538
|
-
|
539
|
-
): Promise<U[]> {
|
425
|
+
public async requestAll<
|
426
|
+
T extends MarkerRequest,
|
427
|
+
U = RequestAllResponseMap<T>,
|
428
|
+
>(request: T, collect?: string): Promise<U[]> {
|
540
429
|
/*
|
541
430
|
* The data under collection is keyed based on the command. Fail if command
|
542
431
|
* not recognized and collection key not provided.
|
@@ -564,7 +453,7 @@ class Client extends EventEmitter {
|
|
564
453
|
// eslint-disable-next-line no-await-in-loop -- Necessary for this, it really has to wait
|
565
454
|
const singleResponse = await this.connection.request(repeatProps)
|
566
455
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Should be true
|
567
|
-
const singleResult = (singleResponse as
|
456
|
+
const singleResult = (singleResponse as MarkerResponse).result
|
568
457
|
if (!(collectKey in singleResult)) {
|
569
458
|
throw new XrplError(`${collectKey} not in result`)
|
570
459
|
}
|
@@ -586,6 +475,16 @@ class Client extends EventEmitter {
|
|
586
475
|
|
587
476
|
/**
|
588
477
|
* Get networkID and buildVersion from server_info
|
478
|
+
*
|
479
|
+
* @returns void
|
480
|
+
* @example
|
481
|
+
* ```ts
|
482
|
+
* const { Client } = require('xrpl')
|
483
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
484
|
+
* await client.getServerInfo()
|
485
|
+
* console.log(client.networkID)
|
486
|
+
* console.log(client.buildVersion)
|
487
|
+
* ```
|
589
488
|
*/
|
590
489
|
public async getServerInfo(): Promise<void> {
|
591
490
|
try {
|
@@ -618,6 +517,15 @@ class Client extends EventEmitter {
|
|
618
517
|
* before exiting your application.
|
619
518
|
* @returns A promise that resolves with a void value when a connection is established.
|
620
519
|
* @category Network
|
520
|
+
*
|
521
|
+
* @example
|
522
|
+
* ```ts
|
523
|
+
* const { Client } = require('xrpl')
|
524
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
525
|
+
* await client.connect()
|
526
|
+
* // do something with the client
|
527
|
+
* await client.disconnect()
|
528
|
+
* ```
|
621
529
|
*/
|
622
530
|
public async connect(): Promise<void> {
|
623
531
|
return this.connection.connect().then(async () => {
|
@@ -659,54 +567,581 @@ class Client extends EventEmitter {
|
|
659
567
|
*
|
660
568
|
* @returns Whether the client instance is connected.
|
661
569
|
* @category Network
|
570
|
+
* @example
|
571
|
+
* ```ts
|
572
|
+
* const { Client } = require('xrpl')
|
573
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
574
|
+
* await client.connect()
|
575
|
+
* console.log(client.isConnected())
|
576
|
+
* // true
|
577
|
+
* await client.disconnect()
|
578
|
+
* console.log(client.isConnected())
|
579
|
+
* // false
|
580
|
+
* ```
|
662
581
|
*/
|
663
582
|
public isConnected(): boolean {
|
664
583
|
return this.connection.isConnected()
|
665
584
|
}
|
666
585
|
|
667
586
|
/**
|
587
|
+
* Autofills fields in a transaction. This will set `Sequence`, `Fee`,
|
588
|
+
* `lastLedgerSequence` according to the current state of the server this Client
|
589
|
+
* is connected to. It also converts all X-Addresses to classic addresses and
|
590
|
+
* flags interfaces into numbers.
|
591
|
+
*
|
668
592
|
* @category Core
|
593
|
+
*
|
594
|
+
* @example
|
595
|
+
*
|
596
|
+
* ```ts
|
597
|
+
* const { Client } = require('xrpl')
|
598
|
+
*
|
599
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
600
|
+
*
|
601
|
+
* async function createAndAutofillTransaction() {
|
602
|
+
* const transaction = {
|
603
|
+
* TransactionType: 'Payment',
|
604
|
+
* Account: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
605
|
+
* Destination: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
606
|
+
* Amount: '10000000' // 10 XRP in drops (1/1,000,000th of an XRP)
|
607
|
+
* }
|
608
|
+
*
|
609
|
+
* try {
|
610
|
+
* const autofilledTransaction = await client.autofill(transaction)
|
611
|
+
* console.log(autofilledTransaction)
|
612
|
+
* } catch (error) {
|
613
|
+
* console.error(`Failed to autofill transaction: ${error}`)
|
614
|
+
* }
|
615
|
+
* }
|
616
|
+
*
|
617
|
+
* createAndAutofillTransaction()
|
618
|
+
* ```
|
619
|
+
*
|
620
|
+
* Autofill helps fill in fields which should be included in a transaction, but can be determined automatically
|
621
|
+
* such as `LastLedgerSequence` and `Fee`. If you override one of the fields `autofill` changes, your explicit
|
622
|
+
* values will be used instead. By default, this is done as part of `submit` and `submitAndWait` when you pass
|
623
|
+
* in an unsigned transaction along with your wallet to be submitted.
|
624
|
+
*
|
625
|
+
* @template T
|
626
|
+
* @param transaction - A {@link Transaction} in JSON format
|
627
|
+
* @param signersCount - The expected number of signers for this transaction.
|
628
|
+
* Only used for multisigned transactions.
|
629
|
+
* @returns The autofilled transaction.
|
669
630
|
*/
|
670
|
-
public autofill
|
631
|
+
public async autofill<T extends Transaction>(
|
632
|
+
transaction: T,
|
633
|
+
signersCount?: number,
|
634
|
+
): Promise<T> {
|
635
|
+
const tx = { ...transaction }
|
636
|
+
|
637
|
+
setValidAddresses(tx)
|
638
|
+
|
639
|
+
setTransactionFlagsToNumber(tx)
|
640
|
+
|
641
|
+
const promises: Array<Promise<void>> = []
|
642
|
+
if (tx.NetworkID == null) {
|
643
|
+
tx.NetworkID = txNeedsNetworkID(this) ? this.networkID : undefined
|
644
|
+
}
|
645
|
+
if (tx.Sequence == null) {
|
646
|
+
promises.push(setNextValidSequenceNumber(this, tx))
|
647
|
+
}
|
648
|
+
if (tx.Fee == null) {
|
649
|
+
promises.push(calculateFeePerTransactionType(this, tx, signersCount))
|
650
|
+
}
|
651
|
+
if (tx.LastLedgerSequence == null) {
|
652
|
+
promises.push(setLatestValidatedLedgerSequence(this, tx))
|
653
|
+
}
|
654
|
+
if (tx.TransactionType === 'AccountDelete') {
|
655
|
+
promises.push(checkAccountDeleteBlockers(this, tx))
|
656
|
+
}
|
657
|
+
|
658
|
+
return Promise.all(promises).then(() => tx)
|
659
|
+
}
|
671
660
|
|
672
661
|
/**
|
662
|
+
* Submits a signed/unsigned transaction.
|
663
|
+
* Steps performed on a transaction:
|
664
|
+
* 1. Autofill.
|
665
|
+
* 2. Sign & Encode.
|
666
|
+
* 3. Submit.
|
667
|
+
*
|
673
668
|
* @category Core
|
669
|
+
*
|
670
|
+
* @param transaction - A transaction to autofill, sign & encode, and submit.
|
671
|
+
* @param opts - (Optional) Options used to sign and submit a transaction.
|
672
|
+
* @param opts.autofill - If true, autofill a transaction.
|
673
|
+
* @param opts.failHard - If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
|
674
|
+
* @param opts.wallet - A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
|
675
|
+
*
|
676
|
+
* @returns A promise that contains SubmitResponse.
|
677
|
+
* @throws RippledError if submit request fails.
|
678
|
+
*
|
679
|
+
* @example
|
680
|
+
* ```ts
|
681
|
+
* const { Client, Wallet } = require('xrpl')
|
682
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
683
|
+
* await client.connect()
|
684
|
+
* const wallet = Wallet.generate()
|
685
|
+
* const transaction = {
|
686
|
+
* TransactionType: 'Payment',
|
687
|
+
* Account: wallet.classicAddress,
|
688
|
+
* Destination: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
689
|
+
* Amount: '10000000' // 10 XRP in drops (1/1,000,000th of an XRP)
|
690
|
+
* }
|
691
|
+
* const submitResponse = await client.submit(transaction, { wallet })
|
692
|
+
* console.log(submitResponse)
|
693
|
+
* ```
|
674
694
|
*/
|
675
|
-
public
|
695
|
+
public async submit(
|
696
|
+
transaction: Transaction | string,
|
697
|
+
opts?: {
|
698
|
+
// If true, autofill a transaction.
|
699
|
+
autofill?: boolean
|
700
|
+
// If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
|
701
|
+
failHard?: boolean
|
702
|
+
// A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
|
703
|
+
wallet?: Wallet
|
704
|
+
},
|
705
|
+
): Promise<SubmitResponse> {
|
706
|
+
const signedTx = await getSignedTx(this, transaction, opts)
|
707
|
+
return submitRequest(this, signedTx, opts?.failHard)
|
708
|
+
}
|
709
|
+
|
676
710
|
/**
|
711
|
+
* Asynchronously submits a transaction and verifies that it has been included in a
|
712
|
+
* validated ledger (or has errored/will not be included for some reason).
|
713
|
+
* See [Reliable Transaction Submission](https://xrpl.org/reliable-transaction-submission.html).
|
714
|
+
*
|
677
715
|
* @category Core
|
716
|
+
*
|
717
|
+
* @example
|
718
|
+
*
|
719
|
+
* ```ts
|
720
|
+
* const { Client, Wallet } = require('xrpl')
|
721
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
722
|
+
*
|
723
|
+
* async function submitTransaction() {
|
724
|
+
* const senderWallet = client.fundWallet()
|
725
|
+
* const recipientWallet = client.fundWallet()
|
726
|
+
*
|
727
|
+
* const transaction = {
|
728
|
+
* TransactionType: 'Payment',
|
729
|
+
* Account: senderWallet.address,
|
730
|
+
* Destination: recipientWallet.address,
|
731
|
+
* Amount: '10'
|
732
|
+
* }
|
733
|
+
*
|
734
|
+
* try {
|
735
|
+
* await client.submit(signedTransaction, { wallet: senderWallet })
|
736
|
+
* console.log(result)
|
737
|
+
* } catch (error) {
|
738
|
+
* console.error(`Failed to submit transaction: ${error}`)
|
739
|
+
* }
|
740
|
+
* }
|
741
|
+
*
|
742
|
+
* submitTransaction()
|
743
|
+
* ```
|
744
|
+
*
|
745
|
+
* In this example we submit a payment transaction between two newly created testnet accounts.
|
746
|
+
*
|
747
|
+
* Under the hood, `submit` will call `client.autofill` by default, and because we've passed in a `Wallet` it
|
748
|
+
* Will also sign the transaction for us before submitting the signed transaction binary blob to the ledger.
|
749
|
+
*
|
750
|
+
* This is similar to `submitAndWait` which does all of the above, but also waits to see if the transaction has been validated.
|
751
|
+
* @param transaction - A transaction to autofill, sign & encode, and submit.
|
752
|
+
* @param opts - (Optional) Options used to sign and submit a transaction.
|
753
|
+
* @param opts.autofill - If true, autofill a transaction.
|
754
|
+
* @param opts.failHard - If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
|
755
|
+
* @param opts.wallet - A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
|
756
|
+
* @throws Connection errors: If the `Client` object is unable to establish a connection to the specified WebSocket endpoint,
|
757
|
+
* an error will be thrown.
|
758
|
+
* @throws Transaction errors: If the submitted transaction is invalid or cannot be included in a validated ledger for any
|
759
|
+
* reason, the promise returned by `submitAndWait()` will be rejected with an error. This could include issues with insufficient
|
760
|
+
* balance, invalid transaction fields, or other issues specific to the transaction being submitted.
|
761
|
+
* @throws Ledger errors: If the ledger being used to submit the transaction is undergoing maintenance or otherwise unavailable,
|
762
|
+
* an error will be thrown.
|
763
|
+
* @throws Timeout errors: If the transaction takes longer than the specified timeout period to be included in a validated
|
764
|
+
* ledger, the promise returned by `submitAndWait()` will be rejected with an error.
|
765
|
+
* @returns A promise that contains TxResponse, that will return when the transaction has been validated.
|
678
766
|
*/
|
679
|
-
public submitAndWait =
|
767
|
+
public async submitAndWait<T extends Transaction = Transaction>(
|
768
|
+
transaction: T | string,
|
769
|
+
opts?: {
|
770
|
+
// If true, autofill a transaction.
|
771
|
+
autofill?: boolean
|
772
|
+
// If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
|
773
|
+
failHard?: boolean
|
774
|
+
// A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
|
775
|
+
wallet?: Wallet
|
776
|
+
},
|
777
|
+
): Promise<TxResponse<T>> {
|
778
|
+
const signedTx = await getSignedTx(this, transaction, opts)
|
779
|
+
|
780
|
+
const lastLedger = getLastLedgerSequence(signedTx)
|
781
|
+
if (lastLedger == null) {
|
782
|
+
throw new ValidationError(
|
783
|
+
'Transaction must contain a LastLedgerSequence value for reliable submission.',
|
784
|
+
)
|
785
|
+
}
|
786
|
+
|
787
|
+
const response = await submitRequest(this, signedTx, opts?.failHard)
|
788
|
+
|
789
|
+
const txHash = hashes.hashSignedTx(signedTx)
|
790
|
+
return waitForFinalTransactionOutcome(
|
791
|
+
this,
|
792
|
+
txHash,
|
793
|
+
lastLedger,
|
794
|
+
response.result.engine_result,
|
795
|
+
)
|
796
|
+
}
|
680
797
|
|
681
798
|
/**
|
799
|
+
* Deprecated: Use autofill instead, provided for users familiar with v1
|
800
|
+
*
|
801
|
+
* @param transaction - A {@link Transaction} in JSON format
|
802
|
+
* @param signersCount - The expected number of signers for this transaction.
|
803
|
+
* Only used for multisigned transactions.
|
682
804
|
* @deprecated Use autofill instead, provided for users familiar with v1
|
683
805
|
*/
|
684
|
-
public prepareTransaction
|
806
|
+
public async prepareTransaction(
|
807
|
+
transaction: Transaction,
|
808
|
+
signersCount?: number,
|
809
|
+
): ReturnType<Client['autofill']> {
|
810
|
+
return this.autofill(transaction, signersCount)
|
811
|
+
}
|
685
812
|
|
686
813
|
/**
|
814
|
+
* Retrieves the XRP balance of a given account address.
|
815
|
+
*
|
687
816
|
* @category Abstraction
|
817
|
+
*
|
818
|
+
* @example
|
819
|
+
* ```ts
|
820
|
+
* const client = new Client(wss://s.altnet.rippletest.net:51233)
|
821
|
+
* await client.connect()
|
822
|
+
* const balance = await client.getXrpBalance('rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn')
|
823
|
+
* console.log(balance)
|
824
|
+
* await client.disconnect()
|
825
|
+
* /// '200'
|
826
|
+
* ```
|
827
|
+
*
|
828
|
+
* @param address - The XRP address to retrieve the balance for.
|
829
|
+
* @param [options] - Additional options for fetching the balance (optional).
|
830
|
+
* @param [options.ledger_hash] - The hash of the ledger to retrieve the balance from (optional).
|
831
|
+
* @param [options.ledger_index] - The index of the ledger to retrieve the balance from (optional).
|
832
|
+
* @returns A promise that resolves with the XRP balance as a string.
|
688
833
|
*/
|
689
|
-
public
|
834
|
+
public async getXrpBalance(
|
835
|
+
address: string,
|
836
|
+
options: {
|
837
|
+
ledger_hash?: string
|
838
|
+
ledger_index?: LedgerIndex
|
839
|
+
} = {},
|
840
|
+
): Promise<string> {
|
841
|
+
const xrpRequest: AccountInfoRequest = {
|
842
|
+
command: 'account_info',
|
843
|
+
account: address,
|
844
|
+
ledger_index: options.ledger_index ?? 'validated',
|
845
|
+
ledger_hash: options.ledger_hash,
|
846
|
+
}
|
847
|
+
const response = await this.request(xrpRequest)
|
848
|
+
return dropsToXrp(response.result.account_data.Balance)
|
849
|
+
}
|
690
850
|
|
691
851
|
/**
|
852
|
+
* Get XRP/non-XRP balances for an account.
|
853
|
+
*
|
692
854
|
* @category Abstraction
|
855
|
+
*
|
856
|
+
* @example
|
857
|
+
* ```ts
|
858
|
+
* const { Client } = require('xrpl')
|
859
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
860
|
+
* await client.connect()
|
861
|
+
*
|
862
|
+
* async function getAccountBalances(address) {
|
863
|
+
* try {
|
864
|
+
* const options = {
|
865
|
+
* ledger_index: 'validated',
|
866
|
+
* limit: 10
|
867
|
+
* };
|
868
|
+
*
|
869
|
+
* const balances = await xrplClient.getBalances(address, options);
|
870
|
+
*
|
871
|
+
* console.log('Account Balances:');
|
872
|
+
* balances.forEach((balance) => {
|
873
|
+
* console.log(`Currency: ${balance.currency}`);
|
874
|
+
* console.log(`Value: ${balance.value}`);
|
875
|
+
* console.log(`Issuer: ${balance.issuer}`);
|
876
|
+
* console.log('---');
|
877
|
+
* });
|
878
|
+
* } catch (error) {
|
879
|
+
* console.error('Error retrieving account balances:', error);
|
880
|
+
* }
|
881
|
+
* }
|
882
|
+
*
|
883
|
+
* const address = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh';
|
884
|
+
* await getAccountBalances(address);
|
885
|
+
* await client.disconnect();
|
886
|
+
* ```
|
887
|
+
*
|
888
|
+
* @param address - Address of the account to retrieve balances for.
|
889
|
+
* @param options - Allows the client to specify a ledger_hash, ledger_index,
|
890
|
+
* filter by peer, and/or limit number of balances.
|
891
|
+
* @param options.ledger_index - Retrieve the account balances at a given
|
892
|
+
* ledger_index.
|
893
|
+
* @param options.ledger_hash - Retrieve the account balances at the ledger with
|
894
|
+
* a given ledger_hash.
|
895
|
+
* @param options.peer - Filter balances by peer.
|
896
|
+
* @param options.limit - Limit number of balances to return.
|
897
|
+
* @returns An array of XRP/non-XRP balances for the given account.
|
693
898
|
*/
|
694
|
-
|
899
|
+
// eslint-disable-next-line max-lines-per-function -- Longer definition is required for end users to see the definition.
|
900
|
+
public async getBalances(
|
901
|
+
address: string,
|
902
|
+
options: {
|
903
|
+
ledger_hash?: string
|
904
|
+
ledger_index?: LedgerIndex
|
905
|
+
peer?: string
|
906
|
+
limit?: number
|
907
|
+
} = {},
|
908
|
+
): Promise<
|
909
|
+
Array<{ value: string; currency: string; issuer?: string | undefined }>
|
910
|
+
> {
|
911
|
+
const balances: Balance[] = []
|
912
|
+
|
913
|
+
// get XRP balance
|
914
|
+
let xrpPromise: Promise<string> = Promise.resolve('')
|
915
|
+
if (!options.peer) {
|
916
|
+
xrpPromise = this.getXrpBalance(address, {
|
917
|
+
ledger_hash: options.ledger_hash,
|
918
|
+
ledger_index: options.ledger_index,
|
919
|
+
})
|
920
|
+
}
|
921
|
+
|
922
|
+
// get non-XRP balances
|
923
|
+
const linesRequest: AccountLinesRequest = {
|
924
|
+
command: 'account_lines',
|
925
|
+
account: address,
|
926
|
+
ledger_index: options.ledger_index ?? 'validated',
|
927
|
+
ledger_hash: options.ledger_hash,
|
928
|
+
peer: options.peer,
|
929
|
+
limit: options.limit,
|
930
|
+
}
|
931
|
+
const linesPromise = this.requestAll(linesRequest)
|
932
|
+
|
933
|
+
// combine results
|
934
|
+
await Promise.all([xrpPromise, linesPromise]).then(
|
935
|
+
([xrpBalance, linesResponses]) => {
|
936
|
+
const accountLinesBalance = linesResponses.flatMap((response) =>
|
937
|
+
formatBalances(response.result.lines),
|
938
|
+
)
|
939
|
+
if (xrpBalance !== '') {
|
940
|
+
balances.push({ currency: 'XRP', value: xrpBalance })
|
941
|
+
}
|
942
|
+
balances.push(...accountLinesBalance)
|
943
|
+
},
|
944
|
+
)
|
945
|
+
return balances.slice(0, options.limit)
|
946
|
+
}
|
695
947
|
|
696
948
|
/**
|
949
|
+
* Fetch orderbook (buy/sell orders) between two currency pairs. This checks both sides of the orderbook
|
950
|
+
* by making two `order_book` requests (with the second reversing takerPays and takerGets). Returned offers are
|
951
|
+
* not normalized in this function, so either currency could be takerGets or takerPays.
|
952
|
+
*
|
697
953
|
* @category Abstraction
|
954
|
+
*
|
955
|
+
* @param currency1 - Specification of one currency involved. (With a currency code and optionally an issuer)
|
956
|
+
* @param currency2 - Specification of a second currency involved. (With a currency code and optionally an issuer)
|
957
|
+
* @param options - Options allowing the client to specify ledger_index,
|
958
|
+
* ledger_hash, filter by taker, and/or limit number of orders.
|
959
|
+
* @param options.ledger_index - Retrieve the orderbook at a given ledger_index.
|
960
|
+
* @param options.ledger_hash - Retrieve the orderbook at the ledger with a
|
961
|
+
* given ledger_hash.
|
962
|
+
* @param options.taker - Filter orders by taker.
|
963
|
+
* @param options.limit - The limit passed into each book_offers request.
|
964
|
+
* Can return more than this due to two calls being made. Defaults to 20.
|
965
|
+
* @returns An object containing buy and sell objects.
|
698
966
|
*/
|
699
|
-
|
967
|
+
|
968
|
+
public async getOrderbook(
|
969
|
+
currency1: BookOfferCurrency,
|
970
|
+
currency2: BookOfferCurrency,
|
971
|
+
options: {
|
972
|
+
limit?: number
|
973
|
+
ledger_index?: LedgerIndex
|
974
|
+
ledger_hash?: string | null
|
975
|
+
taker?: string | null
|
976
|
+
} = {},
|
977
|
+
): Promise<{
|
978
|
+
buy: BookOffer[]
|
979
|
+
sell: BookOffer[]
|
980
|
+
}> {
|
981
|
+
validateOrderbookOptions(options)
|
982
|
+
|
983
|
+
const request = createBookOffersRequest(currency1, currency2, options)
|
984
|
+
|
985
|
+
const directOfferResults = await requestAllOffers(this, request)
|
986
|
+
const reverseOfferResults = await requestAllOffers(
|
987
|
+
this,
|
988
|
+
reverseRequest(request),
|
989
|
+
)
|
990
|
+
|
991
|
+
const directOffers = extractOffers(directOfferResults)
|
992
|
+
const reverseOffers = extractOffers(reverseOfferResults)
|
993
|
+
|
994
|
+
const orders = combineOrders(directOffers, reverseOffers)
|
995
|
+
|
996
|
+
const { buy, sell } = separateBuySellOrders(orders)
|
997
|
+
|
998
|
+
/*
|
999
|
+
* Sort the orders
|
1000
|
+
* for both buys and sells, lowest quality is closest to mid-market
|
1001
|
+
* we sort the orders so that earlier orders are closer to mid-market
|
1002
|
+
*/
|
1003
|
+
return {
|
1004
|
+
buy: sortAndLimitOffers(buy, options.limit),
|
1005
|
+
sell: sortAndLimitOffers(sell, options.limit),
|
1006
|
+
}
|
1007
|
+
}
|
700
1008
|
|
701
1009
|
/**
|
1010
|
+
* Returns the index of the most recently validated ledger.
|
1011
|
+
*
|
702
1012
|
* @category Abstraction
|
1013
|
+
*
|
1014
|
+
* @returns The most recently validated ledger index.
|
1015
|
+
*
|
1016
|
+
* @example
|
1017
|
+
* ```ts
|
1018
|
+
* const { Client } = require('xrpl')
|
1019
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
1020
|
+
* await client.connect()
|
1021
|
+
* const ledgerIndex = await client.getLedgerIndex()
|
1022
|
+
* console.log(ledgerIndex)
|
1023
|
+
* // 884039
|
1024
|
+
* ```
|
703
1025
|
*/
|
704
|
-
public getLedgerIndex
|
1026
|
+
public async getLedgerIndex(): Promise<number> {
|
1027
|
+
const ledgerResponse = await this.request({
|
1028
|
+
command: 'ledger',
|
1029
|
+
ledger_index: 'validated',
|
1030
|
+
})
|
1031
|
+
return ledgerResponse.result.ledger_index
|
1032
|
+
}
|
705
1033
|
|
706
1034
|
/**
|
1035
|
+
* The fundWallet() method is used to send an amount of XRP (usually 1000) to a new (randomly generated)
|
1036
|
+
* or existing XRP Ledger wallet.
|
1037
|
+
*
|
707
1038
|
* @category Faucet
|
1039
|
+
*
|
1040
|
+
* @example
|
1041
|
+
*
|
1042
|
+
* Example 1: Fund a randomly generated wallet
|
1043
|
+
* const { Client, Wallet } = require('xrpl')
|
1044
|
+
*
|
1045
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
1046
|
+
* await client.connect()
|
1047
|
+
* const { balance, wallet } = await client.fundWallet()
|
1048
|
+
*
|
1049
|
+
* Under the hood, this will use `Wallet.generate()` to create a new random wallet, then ask a testnet faucet
|
1050
|
+
* To send it XRP on ledger to make it a real account. If successful, this will return the new account balance in XRP
|
1051
|
+
* Along with the Wallet object to track the keys for that account. If you'd like, you can also re-fill an existing
|
1052
|
+
* Account by passing in a Wallet you already have.
|
1053
|
+
* ```ts
|
1054
|
+
* const api = new xrpl.Client("wss://s.altnet.rippletest.net:51233")
|
1055
|
+
* await api.connect()
|
1056
|
+
* const { wallet, balance } = await api.fundWallet()
|
1057
|
+
* ```
|
1058
|
+
*
|
1059
|
+
* Example 2: Fund wallet using a custom faucet host and known wallet address
|
1060
|
+
*
|
1061
|
+
* `fundWallet` will try to infer the url of a faucet API from the network your client is connected to.
|
1062
|
+
* There are hardcoded default faucets for popular test networks like testnet and devnet.
|
1063
|
+
* However, if you're working with a newer or more obscure network, you may have to specify the faucetHost
|
1064
|
+
* And faucetPath so `fundWallet` can ask that faucet to fund your wallet.
|
1065
|
+
*
|
1066
|
+
* ```ts
|
1067
|
+
* const newWallet = Wallet.generate()
|
1068
|
+
* const { balance, wallet } = await client.fundWallet(newWallet, {
|
1069
|
+
* amount: '10',
|
1070
|
+
* faucetHost: 'https://custom-faucet.example.com',
|
1071
|
+
* faucetPath: '/accounts'
|
1072
|
+
* })
|
1073
|
+
* console.log(`Sent 10 XRP to wallet: ${address} from the given faucet. Resulting balance: ${balance} XRP`)
|
1074
|
+
* } catch (error) {
|
1075
|
+
* console.error(`Failed to fund wallet: ${error}`)
|
1076
|
+
* }
|
1077
|
+
* }
|
1078
|
+
* ```
|
1079
|
+
*
|
1080
|
+
* @param wallet - An existing XRPL Wallet to fund. If undefined or null, a new Wallet will be created.
|
1081
|
+
* @param options - See below.
|
1082
|
+
* @param options.faucetHost - A custom host for a faucet server. On devnet,
|
1083
|
+
* testnet, AMM devnet, and HooksV3 testnet, `fundWallet` will
|
1084
|
+
* attempt to determine the correct server automatically. In other environments,
|
1085
|
+
* or if you would like to customize the faucet host in devnet or testnet,
|
1086
|
+
* you should provide the host using this option.
|
1087
|
+
* @param options.faucetPath - A custom path for a faucet server. On devnet,
|
1088
|
+
* testnet, AMM devnet, and HooksV3 testnet, `fundWallet` will
|
1089
|
+
* attempt to determine the correct path automatically. In other environments,
|
1090
|
+
* or if you would like to customize the faucet path in devnet or testnet,
|
1091
|
+
* you should provide the path using this option.
|
1092
|
+
* Ex: client.fundWallet(null,{'faucet.altnet.rippletest.net', '/accounts'})
|
1093
|
+
* specifies a request to 'faucet.altnet.rippletest.net/accounts' to fund a new wallet.
|
1094
|
+
* @param options.amount - A custom amount to fund, if undefined or null, the default amount will be 1000.
|
1095
|
+
* @returns A Wallet on the Testnet or Devnet that contains some amount of XRP,
|
1096
|
+
* and that wallet's balance in XRP.
|
1097
|
+
* @throws When either Client isn't connected or unable to fund wallet address.
|
708
1098
|
*/
|
709
|
-
public
|
1099
|
+
public async fundWallet(
|
1100
|
+
this: Client,
|
1101
|
+
wallet?: Wallet | null,
|
1102
|
+
options: FundingOptions = {},
|
1103
|
+
): Promise<{
|
1104
|
+
wallet: Wallet
|
1105
|
+
balance: number
|
1106
|
+
}> {
|
1107
|
+
if (!this.isConnected()) {
|
1108
|
+
throw new RippledError('Client not connected, cannot call faucet')
|
1109
|
+
}
|
1110
|
+
const existingWallet = Boolean(wallet)
|
1111
|
+
|
1112
|
+
// Generate a new Wallet if no existing Wallet is provided or its address is invalid to fund
|
1113
|
+
const walletToFund =
|
1114
|
+
wallet && isValidClassicAddress(wallet.classicAddress)
|
1115
|
+
? wallet
|
1116
|
+
: Wallet.generate()
|
1117
|
+
|
1118
|
+
// Create the POST request body
|
1119
|
+
const postBody: FaucetRequestBody = {
|
1120
|
+
destination: walletToFund.classicAddress,
|
1121
|
+
xrpAmount: options.amount,
|
1122
|
+
usageContext: options.usageContext,
|
1123
|
+
userAgent: 'xrpl.js',
|
1124
|
+
}
|
1125
|
+
|
1126
|
+
let startingBalance = 0
|
1127
|
+
if (existingWallet) {
|
1128
|
+
try {
|
1129
|
+
startingBalance = Number(
|
1130
|
+
await this.getXrpBalance(walletToFund.classicAddress),
|
1131
|
+
)
|
1132
|
+
} catch {
|
1133
|
+
/* startingBalance remains what it was previously */
|
1134
|
+
}
|
1135
|
+
}
|
1136
|
+
|
1137
|
+
return requestFunding(
|
1138
|
+
options,
|
1139
|
+
this,
|
1140
|
+
startingBalance,
|
1141
|
+
walletToFund,
|
1142
|
+
postBody,
|
1143
|
+
)
|
1144
|
+
}
|
710
1145
|
}
|
711
1146
|
|
712
1147
|
export { Client }
|