xrpl 2.10.0 → 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 +728 -28
- 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 +2 -0
- package/dist/npm/models/ledger/AccountRoot.d.ts.map +1 -1
- package/dist/npm/models/ledger/AccountRoot.js +1 -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/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/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 +6 -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 +7 -1
- package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/models/transactions/transaction.js +24 -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 +14 -21
- package/dist/npm/models/utils/flags.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 +2 -0
- package/dist/npm/src/models/ledger/AccountRoot.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/AccountRoot.js +1 -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/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/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 +6 -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 +7 -1
- package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/transaction.js +24 -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 +14 -21
- package/dist/npm/src/models/utils/flags.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,153 @@
|
|
1
|
+
import BigNumber from 'bignumber.js'
|
2
|
+
import { decode } from 'ripple-binary-codec'
|
3
|
+
|
4
|
+
import type {
|
5
|
+
AccountTxResponse,
|
6
|
+
Response,
|
7
|
+
ResponseWarning,
|
8
|
+
TransactionEntryResponse,
|
9
|
+
TransactionStream,
|
10
|
+
TxResponse,
|
11
|
+
} from '..'
|
12
|
+
import type { Amount } from '../models/common'
|
13
|
+
import { PaymentFlags, Transaction } from '../models/transactions'
|
14
|
+
import type { TransactionMetadata } from '../models/transactions/metadata'
|
15
|
+
import { isFlagEnabled } from '../models/utils'
|
16
|
+
|
17
|
+
const WARN_PARTIAL_PAYMENT_CODE = 2001
|
18
|
+
|
19
|
+
function amountsEqual(amt1: Amount, amt2: Amount): boolean {
|
20
|
+
if (typeof amt1 === 'string' && typeof amt2 === 'string') {
|
21
|
+
return amt1 === amt2
|
22
|
+
}
|
23
|
+
|
24
|
+
if (typeof amt1 === 'string' || typeof amt2 === 'string') {
|
25
|
+
return false
|
26
|
+
}
|
27
|
+
|
28
|
+
const aValue = new BigNumber(amt1.value)
|
29
|
+
const bValue = new BigNumber(amt2.value)
|
30
|
+
|
31
|
+
return (
|
32
|
+
amt1.currency === amt2.currency &&
|
33
|
+
amt1.issuer === amt2.issuer &&
|
34
|
+
aValue.isEqualTo(bValue)
|
35
|
+
)
|
36
|
+
}
|
37
|
+
|
38
|
+
function isPartialPayment(
|
39
|
+
tx?: Transaction,
|
40
|
+
metadata?: TransactionMetadata | string,
|
41
|
+
): boolean {
|
42
|
+
if (tx == null || metadata == null || tx.TransactionType !== 'Payment') {
|
43
|
+
return false
|
44
|
+
}
|
45
|
+
|
46
|
+
let meta = metadata
|
47
|
+
if (typeof meta === 'string') {
|
48
|
+
if (meta === 'unavailable') {
|
49
|
+
return false
|
50
|
+
}
|
51
|
+
|
52
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- binary-codec typing */
|
53
|
+
meta = decode(meta) as unknown as TransactionMetadata
|
54
|
+
}
|
55
|
+
|
56
|
+
const tfPartial =
|
57
|
+
typeof tx.Flags === 'number'
|
58
|
+
? isFlagEnabled(tx.Flags, PaymentFlags.tfPartialPayment)
|
59
|
+
: tx.Flags?.tfPartialPayment
|
60
|
+
|
61
|
+
if (!tfPartial) {
|
62
|
+
return false
|
63
|
+
}
|
64
|
+
|
65
|
+
const delivered = meta.delivered_amount
|
66
|
+
const amount = tx.Amount
|
67
|
+
|
68
|
+
if (delivered === undefined) {
|
69
|
+
return false
|
70
|
+
}
|
71
|
+
|
72
|
+
return !amountsEqual(delivered, amount)
|
73
|
+
}
|
74
|
+
|
75
|
+
function txHasPartialPayment(response: TxResponse): boolean {
|
76
|
+
return isPartialPayment(response.result, response.result.meta)
|
77
|
+
}
|
78
|
+
|
79
|
+
function txEntryHasPartialPayment(response: TransactionEntryResponse): boolean {
|
80
|
+
return isPartialPayment(response.result.tx_json, response.result.metadata)
|
81
|
+
}
|
82
|
+
|
83
|
+
function accountTxHasPartialPayment(response: AccountTxResponse): boolean {
|
84
|
+
const { transactions } = response.result
|
85
|
+
const foo = transactions.some((tx) => isPartialPayment(tx.tx, tx.meta))
|
86
|
+
return foo
|
87
|
+
}
|
88
|
+
|
89
|
+
function hasPartialPayment(command: string, response: Response): boolean {
|
90
|
+
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Request type is known at runtime from command */
|
91
|
+
switch (command) {
|
92
|
+
case 'tx':
|
93
|
+
return txHasPartialPayment(response as TxResponse)
|
94
|
+
case 'transaction_entry':
|
95
|
+
return txEntryHasPartialPayment(response as TransactionEntryResponse)
|
96
|
+
case 'account_tx':
|
97
|
+
return accountTxHasPartialPayment(response as AccountTxResponse)
|
98
|
+
default:
|
99
|
+
return false
|
100
|
+
}
|
101
|
+
/* eslint-enable @typescript-eslint/consistent-type-assertions */
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Checks a response for a partial payment.
|
106
|
+
*
|
107
|
+
* @param command - Command from the request, tells us what response to expect.
|
108
|
+
* @param response - Response to check for a partial payment.
|
109
|
+
*/
|
110
|
+
export function handlePartialPayment(
|
111
|
+
command: string,
|
112
|
+
response: Response,
|
113
|
+
): void {
|
114
|
+
if (hasPartialPayment(command, response)) {
|
115
|
+
const warnings: ResponseWarning[] = response.warnings ?? []
|
116
|
+
|
117
|
+
const warning = {
|
118
|
+
id: WARN_PARTIAL_PAYMENT_CODE,
|
119
|
+
message: 'This response contains a Partial Payment',
|
120
|
+
}
|
121
|
+
|
122
|
+
warnings.push(warning)
|
123
|
+
|
124
|
+
response.warnings = warnings
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Check a transaction from a subscription stream for partial payment.
|
130
|
+
*
|
131
|
+
* @param stream - Stream Transaction to check for partial payment.
|
132
|
+
* @param log - The method used for logging by the connection (to report the partial payment).
|
133
|
+
*/
|
134
|
+
export function handleStreamPartialPayment(
|
135
|
+
stream: TransactionStream,
|
136
|
+
log: (id: string, message: string) => void,
|
137
|
+
): void {
|
138
|
+
if (isPartialPayment(stream.transaction, stream.meta)) {
|
139
|
+
const warnings = stream.warnings ?? []
|
140
|
+
|
141
|
+
const warning = {
|
142
|
+
id: WARN_PARTIAL_PAYMENT_CODE,
|
143
|
+
message: 'This response contains a Partial Payment',
|
144
|
+
}
|
145
|
+
|
146
|
+
warnings.push(warning)
|
147
|
+
|
148
|
+
/* eslint-disable-next-line no-param-reassign -- Handles the case where there are no warnings */
|
149
|
+
stream.warnings = warnings
|
150
|
+
|
151
|
+
log('Partial payment received', JSON.stringify(stream))
|
152
|
+
}
|
153
|
+
}
|
package/src/errors.ts
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
/* eslint-disable max-classes-per-file -- Errors can be defined in the same file */
|
2
|
+
import { inspect } from 'util'
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Base Error class for xrpl.js. All Errors thrown by xrpl.js should throw
|
6
|
+
* XrplErrors.
|
7
|
+
*
|
8
|
+
* @category Errors
|
9
|
+
*/
|
10
|
+
class XrplError extends Error {
|
11
|
+
public readonly name: string
|
12
|
+
public readonly message: string
|
13
|
+
public readonly data?: unknown
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Construct an XrplError.
|
17
|
+
*
|
18
|
+
* @param message - The error message.
|
19
|
+
* @param data - The data that caused the error.
|
20
|
+
*/
|
21
|
+
public constructor(message = '', data?: unknown) {
|
22
|
+
super(message)
|
23
|
+
|
24
|
+
this.name = this.constructor.name
|
25
|
+
this.message = message
|
26
|
+
this.data = data
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- `captureStackTrace` can be null in browsers
|
28
|
+
if (Error.captureStackTrace != null) {
|
29
|
+
Error.captureStackTrace(this, this.constructor)
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Converts the Error to a human-readable String form.
|
35
|
+
*
|
36
|
+
* @returns The String output of the Error.
|
37
|
+
*/
|
38
|
+
public toString(): string {
|
39
|
+
let result = `[${this.name}(${this.message}`
|
40
|
+
if (this.data) {
|
41
|
+
result += `, ${inspect(this.data)}`
|
42
|
+
}
|
43
|
+
result += ')]'
|
44
|
+
return result
|
45
|
+
}
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Console.log in node uses util.inspect on object, and util.inspect allows
|
49
|
+
* us to customize its output:
|
50
|
+
* https://nodejs.org/api/util.html#util_custom_inspect_function_on_objects.
|
51
|
+
*
|
52
|
+
* @returns The String output of the Error.
|
53
|
+
*/
|
54
|
+
public inspect(): string {
|
55
|
+
return this.toString()
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Error thrown when rippled responds with an error.
|
61
|
+
*
|
62
|
+
* @category Errors
|
63
|
+
*/
|
64
|
+
class RippledError extends XrplError {}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Error thrown when xrpl.js cannot specify error type.
|
68
|
+
*
|
69
|
+
* @category Errors
|
70
|
+
*/
|
71
|
+
class UnexpectedError extends XrplError {}
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Error thrown when xrpl.js has an error with connection to rippled.
|
75
|
+
*
|
76
|
+
* @category Errors
|
77
|
+
*/
|
78
|
+
class ConnectionError extends XrplError {}
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Error thrown when xrpl.js is not connected to rippled server.
|
82
|
+
*
|
83
|
+
* @category Errors
|
84
|
+
*/
|
85
|
+
class NotConnectedError extends ConnectionError {}
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Error thrown when xrpl.js has disconnected from rippled server.
|
89
|
+
*
|
90
|
+
* @category Errors
|
91
|
+
*/
|
92
|
+
class DisconnectedError extends ConnectionError {}
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Error thrown when rippled is not initialized.
|
96
|
+
*
|
97
|
+
* @category Errors
|
98
|
+
*/
|
99
|
+
class RippledNotInitializedError extends ConnectionError {}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Error thrown when xrpl.js times out.
|
103
|
+
*
|
104
|
+
* @category Errors
|
105
|
+
*/
|
106
|
+
class TimeoutError extends ConnectionError {}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Error thrown when xrpl.js sees a response in the wrong format.
|
110
|
+
*
|
111
|
+
* @category Errors
|
112
|
+
*/
|
113
|
+
class ResponseFormatError extends ConnectionError {}
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Error thrown when xrpl.js sees a malformed transaction.
|
117
|
+
*
|
118
|
+
* @category Errors
|
119
|
+
*/
|
120
|
+
class ValidationError extends XrplError {}
|
121
|
+
|
122
|
+
/**
|
123
|
+
* Error thrown when a client cannot generate a wallet from the testnet/devnet
|
124
|
+
* faucets, or when the client cannot infer the faucet URL (i.e. when the Client
|
125
|
+
* is connected to mainnet).
|
126
|
+
*
|
127
|
+
* @category Errors
|
128
|
+
*/
|
129
|
+
class XRPLFaucetError extends XrplError {}
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Error thrown when xrpl.js cannot retrieve a transaction, ledger, account, etc.
|
133
|
+
* From rippled.
|
134
|
+
*
|
135
|
+
* @category Errors
|
136
|
+
*/
|
137
|
+
class NotFoundError extends XrplError {
|
138
|
+
/**
|
139
|
+
* Construct an XrplError.
|
140
|
+
*
|
141
|
+
* @param message - The error message. Defaults to "Not found".
|
142
|
+
*/
|
143
|
+
public constructor(message = 'Not found') {
|
144
|
+
super(message)
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
export {
|
149
|
+
XrplError,
|
150
|
+
UnexpectedError,
|
151
|
+
ConnectionError,
|
152
|
+
RippledError,
|
153
|
+
NotConnectedError,
|
154
|
+
DisconnectedError,
|
155
|
+
RippledNotInitializedError,
|
156
|
+
TimeoutError,
|
157
|
+
ResponseFormatError,
|
158
|
+
ValidationError,
|
159
|
+
NotFoundError,
|
160
|
+
XRPLFaucetError,
|
161
|
+
}
|
package/src/index.ts
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
// Broadcast client is experimental
|
2
|
+
export { BroadcastClient } from './client/BroadcastClient'
|
3
|
+
|
4
|
+
export { Client, ClientOptions } from './client'
|
5
|
+
|
6
|
+
export * from './models'
|
7
|
+
|
8
|
+
export * from './utils'
|
9
|
+
|
10
|
+
export { default as ECDSA } from './ECDSA'
|
11
|
+
|
12
|
+
export * from './errors'
|
13
|
+
|
14
|
+
export { Wallet } from './Wallet'
|
15
|
+
|
16
|
+
export { walletFromSecretNumbers } from './Wallet/walletFromSecretNumbers'
|
17
|
+
|
18
|
+
export { keyToRFC1751Mnemonic, rfc1751MnemonicToKey } from './Wallet/rfc1751'
|
19
|
+
|
20
|
+
export * from './Wallet/signer'
|
@@ -0,0 +1,149 @@
|
|
1
|
+
export type LedgerIndex = number | ('validated' | 'closed' | 'current')
|
2
|
+
|
3
|
+
export interface XRP {
|
4
|
+
currency: 'XRP'
|
5
|
+
}
|
6
|
+
|
7
|
+
export interface IssuedCurrency {
|
8
|
+
currency: string
|
9
|
+
issuer: string
|
10
|
+
}
|
11
|
+
|
12
|
+
export type Currency = IssuedCurrency | XRP
|
13
|
+
|
14
|
+
export interface IssuedCurrencyAmount extends IssuedCurrency {
|
15
|
+
value: string
|
16
|
+
}
|
17
|
+
|
18
|
+
export type Amount = IssuedCurrencyAmount | string
|
19
|
+
|
20
|
+
export interface Balance {
|
21
|
+
currency: string
|
22
|
+
issuer?: string
|
23
|
+
value: string
|
24
|
+
}
|
25
|
+
|
26
|
+
export interface Signer {
|
27
|
+
Signer: {
|
28
|
+
Account: string
|
29
|
+
TxnSignature: string
|
30
|
+
SigningPubKey: string
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
export interface Memo {
|
35
|
+
Memo: {
|
36
|
+
MemoData?: string
|
37
|
+
MemoType?: string
|
38
|
+
MemoFormat?: string
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
export type StreamType =
|
43
|
+
| 'consensus'
|
44
|
+
| 'ledger'
|
45
|
+
| 'manifests'
|
46
|
+
| 'peer_status'
|
47
|
+
| 'transactions'
|
48
|
+
| 'transactions_proposed'
|
49
|
+
| 'server'
|
50
|
+
| 'validations'
|
51
|
+
|
52
|
+
export interface PathStep {
|
53
|
+
account?: string
|
54
|
+
currency?: string
|
55
|
+
issuer?: string
|
56
|
+
}
|
57
|
+
|
58
|
+
export type Path = PathStep[]
|
59
|
+
|
60
|
+
/**
|
61
|
+
* The object that describes the signer in SignerEntries.
|
62
|
+
*/
|
63
|
+
export interface SignerEntry {
|
64
|
+
/**
|
65
|
+
* The object that describes the signer in SignerEntries.
|
66
|
+
*/
|
67
|
+
SignerEntry: {
|
68
|
+
/**
|
69
|
+
* An XRP Ledger address whose signature contributes to the multi-signature.
|
70
|
+
* It does not need to be a funded address in the ledger.
|
71
|
+
*/
|
72
|
+
Account: string
|
73
|
+
/**
|
74
|
+
* The weight of a signature from this signer.
|
75
|
+
* A multi-signature is only valid if the sum weight of the signatures provided meets
|
76
|
+
* or exceeds the signer list's SignerQuorum value.
|
77
|
+
*/
|
78
|
+
SignerWeight: number
|
79
|
+
/**
|
80
|
+
* An arbitrary 256-bit (32-byte) field that can be used to identify the signer, which
|
81
|
+
* may be useful for smart contracts, or for identifying who controls a key in a large
|
82
|
+
* organization.
|
83
|
+
*/
|
84
|
+
WalletLocator?: string
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* This information is added to Transactions in request responses, but is not part
|
90
|
+
* of the canonical Transaction information on ledger. These fields are denoted with
|
91
|
+
* lowercase letters to indicate this in the rippled responses.
|
92
|
+
*/
|
93
|
+
export interface ResponseOnlyTxInfo {
|
94
|
+
/**
|
95
|
+
* The date/time when this transaction was included in a validated ledger.
|
96
|
+
*/
|
97
|
+
date?: number
|
98
|
+
/**
|
99
|
+
* An identifying hash value unique to this transaction, as a hex string.
|
100
|
+
*/
|
101
|
+
hash?: string
|
102
|
+
/**
|
103
|
+
* The sequence number of the ledger that included this transaction.
|
104
|
+
*/
|
105
|
+
ledger_index?: number
|
106
|
+
/**
|
107
|
+
* @deprecated Alias for ledger_index.
|
108
|
+
*/
|
109
|
+
inLedger?: number
|
110
|
+
}
|
111
|
+
|
112
|
+
/**
|
113
|
+
* One offer that might be returned from either an {@link NFTBuyOffersRequest}
|
114
|
+
* or an {@link NFTSellOffersRequest}.
|
115
|
+
*
|
116
|
+
* @category Responses
|
117
|
+
*/
|
118
|
+
export interface NFTOffer {
|
119
|
+
amount: Amount
|
120
|
+
flags: number
|
121
|
+
nft_offer_index: string
|
122
|
+
owner: string
|
123
|
+
destination?: string
|
124
|
+
expiration?: number
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* One NFToken that might be returned from an {@link NFTInfoResponse}
|
129
|
+
*
|
130
|
+
* @category Responses
|
131
|
+
*/
|
132
|
+
export interface NFToken {
|
133
|
+
nft_id: string
|
134
|
+
ledger_index: number
|
135
|
+
owner: string
|
136
|
+
is_burned: boolean
|
137
|
+
flags: number
|
138
|
+
transfer_fee: number
|
139
|
+
issuer: string
|
140
|
+
nft_taxon: number
|
141
|
+
nft_serial: number
|
142
|
+
uri: string
|
143
|
+
}
|
144
|
+
|
145
|
+
export interface AuthAccount {
|
146
|
+
AuthAccount: {
|
147
|
+
account: string
|
148
|
+
}
|
149
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/**
|
2
|
+
* LedgerEntry type definitions are exported in their own namespace to prevent
|
3
|
+
* collisions of the DepositPreauth SLE and Transaction. LedgerEntries are used
|
4
|
+
* by the client less often, and in most scenarios, like when parsing a
|
5
|
+
* response, the client won't need to import the type. If it is required to use
|
6
|
+
* a Ledger Entry, import `LedgerEntry`, and access individual ledger entry
|
7
|
+
* types on the `LedgerEntry` namespace.
|
8
|
+
*/
|
9
|
+
export * as LedgerEntry from './ledger'
|
10
|
+
export {
|
11
|
+
setTransactionFlagsToNumber,
|
12
|
+
parseAccountRootFlags,
|
13
|
+
} from './utils/flags'
|
14
|
+
export * from './methods'
|
15
|
+
export * from './transactions'
|
16
|
+
export * from './common'
|
@@ -0,0 +1,78 @@
|
|
1
|
+
import { AuthAccount, Currency } from '../common'
|
2
|
+
|
3
|
+
import BaseLedgerEntry from './BaseLedgerEntry'
|
4
|
+
|
5
|
+
export interface VoteSlot {
|
6
|
+
VoteEntry: {
|
7
|
+
Account: string
|
8
|
+
TradingFee: number
|
9
|
+
VoteWeight: number
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* The AMM object type describes a single Automated Market Maker (AMM) instance.
|
15
|
+
*
|
16
|
+
* @category Ledger Entries
|
17
|
+
*/
|
18
|
+
export default interface AMM extends BaseLedgerEntry {
|
19
|
+
LedgerEntryType: 'AMM'
|
20
|
+
/**
|
21
|
+
* The address of the special account that holds this AMM's assets.
|
22
|
+
*/
|
23
|
+
AMMAccount: string
|
24
|
+
/**
|
25
|
+
* The definition for one of the two assets this AMM holds.
|
26
|
+
*/
|
27
|
+
Asset: Currency
|
28
|
+
/**
|
29
|
+
* The definition for the other asset this AMM holds.
|
30
|
+
*/
|
31
|
+
Asset2: Currency
|
32
|
+
/**
|
33
|
+
* Details of the current owner of the auction slot.
|
34
|
+
*/
|
35
|
+
AuctionSlot?: {
|
36
|
+
/**
|
37
|
+
* The current owner of this auction slot.
|
38
|
+
*/
|
39
|
+
Account: string
|
40
|
+
/**
|
41
|
+
* A list of at most 4 additional accounts that are authorized to trade at the discounted fee for this AMM instance.
|
42
|
+
*/
|
43
|
+
AuthAccounts?: AuthAccount[]
|
44
|
+
/**
|
45
|
+
* The trading fee to be charged to the auction owner, in the same format as TradingFee.
|
46
|
+
* By default this is 0, meaning that the auction owner can trade at no fee instead of the standard fee for this AMM.
|
47
|
+
*/
|
48
|
+
DiscountedFee: number
|
49
|
+
/**
|
50
|
+
* The time when this slot expires, in seconds since the Ripple Epoch.
|
51
|
+
*/
|
52
|
+
Expiration: number
|
53
|
+
/**
|
54
|
+
* The amount the auction owner paid to win this slot, in LP Tokens.
|
55
|
+
*/
|
56
|
+
Price: Currency
|
57
|
+
}
|
58
|
+
/**
|
59
|
+
* The total outstanding balance of liquidity provider tokens from this AMM instance.
|
60
|
+
* The holders of these tokens can vote on the AMM's trading fee in proportion to their holdings,
|
61
|
+
* or redeem the tokens for a share of the AMM's assets which grows with the trading fees collected.
|
62
|
+
*/
|
63
|
+
LPTokenBalance: Currency
|
64
|
+
/**
|
65
|
+
* The percentage fee to be charged for trades against this AMM instance, in units of 1/100,000.
|
66
|
+
* The maximum value is 1000, for a 1% fee.
|
67
|
+
*/
|
68
|
+
TradingFee: number
|
69
|
+
/**
|
70
|
+
* A list of vote objects, representing votes on the pool's trading fee.
|
71
|
+
*/
|
72
|
+
VoteSlots?: VoteSlot[]
|
73
|
+
/**
|
74
|
+
* A bit-map of boolean flags. No flags are defined for the AMM object
|
75
|
+
* type, so this value is always 0.
|
76
|
+
*/
|
77
|
+
Flags: 0
|
78
|
+
}
|