xrpl 3.1.0 → 4.0.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 +3 -3
- package/build/xrpl-latest.js +36 -693
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/Wallet/defaultFaucets.d.ts +1 -2
- package/dist/npm/Wallet/defaultFaucets.d.ts.map +1 -1
- package/dist/npm/Wallet/defaultFaucets.js +0 -5
- package/dist/npm/Wallet/defaultFaucets.js.map +1 -1
- package/dist/npm/Wallet/fundWallet.d.ts.map +1 -1
- package/dist/npm/Wallet/fundWallet.js +1 -5
- package/dist/npm/Wallet/fundWallet.js.map +1 -1
- package/dist/npm/client/RequestManager.d.ts +5 -4
- package/dist/npm/client/RequestManager.d.ts.map +1 -1
- package/dist/npm/client/RequestManager.js.map +1 -1
- package/dist/npm/client/connection.d.ts +2 -2
- package/dist/npm/client/connection.d.ts.map +1 -1
- package/dist/npm/client/connection.js.map +1 -1
- package/dist/npm/client/index.d.ts +4 -3
- package/dist/npm/client/index.d.ts.map +1 -1
- package/dist/npm/client/index.js +16 -4
- package/dist/npm/client/index.js.map +1 -1
- package/dist/npm/client/partialPayment.d.ts +2 -1
- package/dist/npm/client/partialPayment.d.ts.map +1 -1
- package/dist/npm/client/partialPayment.js +10 -3
- package/dist/npm/client/partialPayment.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/common/index.js +4 -0
- package/dist/npm/models/common/index.js.map +1 -1
- package/dist/npm/models/ledger/AMM.d.ts +2 -2
- package/dist/npm/models/ledger/AMM.d.ts.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 +3 -3
- package/dist/npm/models/ledger/BaseLedgerEntry.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/FeeSettings.d.ts +2 -2
- package/dist/npm/models/ledger/FeeSettings.d.ts.map +1 -1
- package/dist/npm/models/ledger/Ledger.d.ts +11 -2
- package/dist/npm/models/ledger/Ledger.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/NegativeUNL.d.ts +2 -2
- package/dist/npm/models/ledger/NegativeUNL.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/accountInfo.d.ts +17 -4
- package/dist/npm/models/methods/accountInfo.d.ts.map +1 -1
- package/dist/npm/models/methods/accountTx.d.ts +11 -5
- package/dist/npm/models/methods/accountTx.d.ts.map +1 -1
- package/dist/npm/models/methods/feature.d.ts +28 -0
- package/dist/npm/models/methods/feature.d.ts.map +1 -0
- package/dist/npm/models/methods/feature.js +3 -0
- package/dist/npm/models/methods/feature.js.map +1 -0
- package/dist/npm/models/methods/index.d.ts +14 -11
- package/dist/npm/models/methods/index.d.ts.map +1 -1
- package/dist/npm/models/methods/ledger.d.ts +17 -5
- package/dist/npm/models/methods/ledger.d.ts.map +1 -1
- package/dist/npm/models/methods/nftsByIssuer.d.ts +19 -0
- package/dist/npm/models/methods/nftsByIssuer.d.ts.map +1 -0
- package/dist/npm/models/methods/nftsByIssuer.js +3 -0
- package/dist/npm/models/methods/nftsByIssuer.js.map +1 -0
- package/dist/npm/models/methods/submitMultisigned.d.ts +16 -5
- package/dist/npm/models/methods/submitMultisigned.d.ts.map +1 -1
- package/dist/npm/models/methods/tx.d.ts +20 -8
- package/dist/npm/models/methods/tx.d.ts.map +1 -1
- package/dist/npm/snippets/src/claimPayChannel.js +1 -1
- package/dist/npm/snippets/src/claimPayChannel.js.map +1 -1
- package/dist/npm/snippets/src/sendEscrow.js +1 -1
- package/dist/npm/snippets/src/sendEscrow.js.map +1 -1
- package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
- package/dist/npm/src/Wallet/defaultFaucets.d.ts +1 -2
- package/dist/npm/src/Wallet/defaultFaucets.d.ts.map +1 -1
- package/dist/npm/src/Wallet/defaultFaucets.js +0 -5
- package/dist/npm/src/Wallet/defaultFaucets.js.map +1 -1
- package/dist/npm/src/Wallet/fundWallet.d.ts.map +1 -1
- package/dist/npm/src/Wallet/fundWallet.js +1 -5
- package/dist/npm/src/Wallet/fundWallet.js.map +1 -1
- package/dist/npm/src/client/RequestManager.d.ts +5 -4
- package/dist/npm/src/client/RequestManager.d.ts.map +1 -1
- package/dist/npm/src/client/RequestManager.js.map +1 -1
- package/dist/npm/src/client/connection.d.ts +2 -2
- package/dist/npm/src/client/connection.d.ts.map +1 -1
- package/dist/npm/src/client/connection.js.map +1 -1
- package/dist/npm/src/client/index.d.ts +4 -3
- package/dist/npm/src/client/index.d.ts.map +1 -1
- package/dist/npm/src/client/index.js +16 -4
- package/dist/npm/src/client/index.js.map +1 -1
- package/dist/npm/src/client/partialPayment.d.ts +2 -1
- package/dist/npm/src/client/partialPayment.d.ts.map +1 -1
- package/dist/npm/src/client/partialPayment.js +10 -3
- package/dist/npm/src/client/partialPayment.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/common/index.js +4 -0
- package/dist/npm/src/models/common/index.js.map +1 -1
- package/dist/npm/src/models/ledger/AMM.d.ts +2 -2
- package/dist/npm/src/models/ledger/AMM.d.ts.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 +3 -3
- package/dist/npm/src/models/ledger/BaseLedgerEntry.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/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 +11 -2
- package/dist/npm/src/models/ledger/Ledger.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/NegativeUNL.d.ts +2 -2
- package/dist/npm/src/models/ledger/NegativeUNL.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/accountInfo.d.ts +17 -4
- package/dist/npm/src/models/methods/accountInfo.d.ts.map +1 -1
- package/dist/npm/src/models/methods/accountTx.d.ts +11 -5
- package/dist/npm/src/models/methods/accountTx.d.ts.map +1 -1
- package/dist/npm/src/models/methods/feature.d.ts +28 -0
- package/dist/npm/src/models/methods/feature.d.ts.map +1 -0
- package/dist/npm/src/models/methods/feature.js +3 -0
- package/dist/npm/src/models/methods/feature.js.map +1 -0
- package/dist/npm/src/models/methods/index.d.ts +14 -11
- package/dist/npm/src/models/methods/index.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ledger.d.ts +17 -5
- package/dist/npm/src/models/methods/ledger.d.ts.map +1 -1
- package/dist/npm/src/models/methods/nftsByIssuer.d.ts +19 -0
- package/dist/npm/src/models/methods/nftsByIssuer.d.ts.map +1 -0
- package/dist/npm/src/models/methods/nftsByIssuer.js +3 -0
- package/dist/npm/src/models/methods/nftsByIssuer.js.map +1 -0
- package/dist/npm/src/models/methods/submitMultisigned.d.ts +16 -5
- package/dist/npm/src/models/methods/submitMultisigned.d.ts.map +1 -1
- package/dist/npm/src/models/methods/tx.d.ts +20 -8
- package/dist/npm/src/models/methods/tx.d.ts.map +1 -1
- package/dist/npm/src/sugar/autofill.d.ts +1 -1
- package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/src/sugar/autofill.js +2 -4
- package/dist/npm/src/sugar/autofill.js.map +1 -1
- package/dist/npm/src/sugar/getFeeXrp.d.ts +1 -1
- package/dist/npm/src/sugar/getFeeXrp.d.ts.map +1 -1
- package/dist/npm/src/sugar/getFeeXrp.js +3 -2
- package/dist/npm/src/sugar/getFeeXrp.js.map +1 -1
- package/dist/npm/src/sugar/submit.d.ts.map +1 -1
- package/dist/npm/src/sugar/submit.js.map +1 -1
- package/dist/npm/src/utils/hashes/hashLedger.d.ts +4 -3
- 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/index.d.ts +2 -1
- package/dist/npm/src/utils/index.d.ts.map +1 -1
- package/dist/npm/src/utils/index.js.map +1 -1
- package/dist/npm/sugar/autofill.d.ts +1 -1
- package/dist/npm/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/sugar/autofill.js +2 -4
- package/dist/npm/sugar/autofill.js.map +1 -1
- package/dist/npm/sugar/getFeeXrp.d.ts +1 -1
- package/dist/npm/sugar/getFeeXrp.d.ts.map +1 -1
- package/dist/npm/sugar/getFeeXrp.js +3 -2
- package/dist/npm/sugar/getFeeXrp.js.map +1 -1
- package/dist/npm/sugar/submit.d.ts.map +1 -1
- package/dist/npm/sugar/submit.js.map +1 -1
- package/dist/npm/utils/hashes/hashLedger.d.ts +4 -3
- 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/index.d.ts +2 -1
- package/dist/npm/utils/index.d.ts.map +1 -1
- package/dist/npm/utils/index.js.map +1 -1
- package/package.json +5 -6
- package/src/Wallet/defaultFaucets.ts +0 -6
- package/src/Wallet/fundWallet.ts +0 -1
- package/src/client/RequestManager.ts +17 -12
- package/src/client/connection.ts +7 -5
- package/src/client/index.ts +63 -16
- package/src/client/partialPayment.ts +34 -13
- package/src/models/common/index.ts +8 -0
- package/src/models/ledger/AMM.ts +2 -2
- package/src/models/ledger/Amendments.ts +2 -2
- package/src/models/ledger/BaseLedgerEntry.ts +9 -5
- package/src/models/ledger/DirectoryNode.ts +2 -2
- package/src/models/ledger/FeeSettings.ts +4 -2
- package/src/models/ledger/Ledger.ts +46 -9
- package/src/models/ledger/LedgerHashes.ts +2 -4
- package/src/models/ledger/NegativeUNL.ts +2 -2
- package/src/models/ledger/index.ts +2 -1
- package/src/models/methods/accountInfo.ts +58 -12
- package/src/models/methods/accountTx.ts +49 -8
- package/src/models/methods/feature.ts +68 -0
- package/src/models/methods/index.ts +67 -23
- package/src/models/methods/ledger.ts +41 -5
- package/src/models/methods/nftsByIssuer.ts +68 -0
- package/src/models/methods/submitMultisigned.ts +48 -16
- package/src/models/methods/tx.ts +74 -22
- package/src/sugar/autofill.ts +4 -10
- package/src/sugar/getFeeXrp.ts +6 -3
- package/src/sugar/submit.ts +5 -3
- package/src/utils/hashes/hashLedger.ts +8 -5
- package/src/utils/index.ts +2 -1
package/src/client/connection.ts
CHANGED
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
ConnectionError,
|
12
12
|
XrplError,
|
13
13
|
} from '../errors'
|
14
|
-
import type { RequestResponseMap } from '../models'
|
14
|
+
import type { APIVersion, RequestResponseMap } from '../models'
|
15
15
|
import { BaseRequest } from '../models/methods/baseMethod'
|
16
16
|
|
17
17
|
import ConnectionManager from './ConnectionManager'
|
@@ -267,6 +267,7 @@ export class Connection extends EventEmitter {
|
|
267
267
|
|
268
268
|
/**
|
269
269
|
* Disconnect the websocket, then connect again.
|
270
|
+
*
|
270
271
|
*/
|
271
272
|
public async reconnect(): Promise<void> {
|
272
273
|
/*
|
@@ -287,10 +288,10 @@ export class Connection extends EventEmitter {
|
|
287
288
|
* @returns The response from the rippled server.
|
288
289
|
* @throws NotConnectedError if the Connection isn't connected to a server.
|
289
290
|
*/
|
290
|
-
public async request<
|
291
|
-
|
292
|
-
|
293
|
-
): Promise<T> {
|
291
|
+
public async request<
|
292
|
+
R extends BaseRequest,
|
293
|
+
T = RequestResponseMap<R, APIVersion>,
|
294
|
+
>(request: R, timeout?: number): Promise<T> {
|
294
295
|
if (!this.shouldBeConnected || this.ws == null) {
|
295
296
|
throw new NotConnectedError(JSON.stringify(request), request)
|
296
297
|
}
|
@@ -468,6 +469,7 @@ export class Connection extends EventEmitter {
|
|
468
469
|
|
469
470
|
/**
|
470
471
|
* Starts a heartbeat to check the connection with the server.
|
472
|
+
*
|
471
473
|
*/
|
472
474
|
private startHeartbeatInterval(): void {
|
473
475
|
this.clearHeartbeatInterval()
|
package/src/client/index.ts
CHANGED
@@ -9,7 +9,12 @@ import {
|
|
9
9
|
ValidationError,
|
10
10
|
XrplError,
|
11
11
|
} from '../errors'
|
12
|
-
import
|
12
|
+
import {
|
13
|
+
APIVersion,
|
14
|
+
LedgerIndex,
|
15
|
+
Balance,
|
16
|
+
DEFAULT_API_VERSION,
|
17
|
+
} from '../models/common'
|
13
18
|
import {
|
14
19
|
Request,
|
15
20
|
// account methods
|
@@ -213,6 +218,12 @@ class Client extends EventEmitter<EventTypes> {
|
|
213
218
|
*/
|
214
219
|
public buildVersion: string | undefined
|
215
220
|
|
221
|
+
/**
|
222
|
+
* API Version used by the server this client is connected to
|
223
|
+
*
|
224
|
+
*/
|
225
|
+
public apiVersion: APIVersion = DEFAULT_API_VERSION
|
226
|
+
|
216
227
|
/**
|
217
228
|
* Creates a new Client with a websocket connection to a rippled server.
|
218
229
|
*
|
@@ -226,7 +237,7 @@ class Client extends EventEmitter<EventTypes> {
|
|
226
237
|
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
227
238
|
* ```
|
228
239
|
*/
|
229
|
-
|
240
|
+
/* eslint-disable max-lines-per-function -- the constructor requires more lines to implement the logic */
|
230
241
|
public constructor(server: string, options: ClientOptions = {}) {
|
231
242
|
super()
|
232
243
|
if (typeof server !== 'string' || !/wss?(?:\+unix)?:\/\//u.exec(server)) {
|
@@ -290,6 +301,7 @@ class Client extends EventEmitter<EventTypes> {
|
|
290
301
|
this.emit('path_find', path)
|
291
302
|
})
|
292
303
|
}
|
304
|
+
/* eslint-enable max-lines-per-function */
|
293
305
|
|
294
306
|
/**
|
295
307
|
* Get the url that the client is connected to.
|
@@ -306,7 +318,6 @@ class Client extends EventEmitter<EventTypes> {
|
|
306
318
|
* additional request body parameters.
|
307
319
|
*
|
308
320
|
* @category Network
|
309
|
-
*
|
310
321
|
* @param req - Request to send to the server.
|
311
322
|
* @returns The response from the server.
|
312
323
|
*
|
@@ -319,16 +330,20 @@ class Client extends EventEmitter<EventTypes> {
|
|
319
330
|
* console.log(response)
|
320
331
|
* ```
|
321
332
|
*/
|
322
|
-
public async request<
|
323
|
-
|
324
|
-
|
325
|
-
|
333
|
+
public async request<
|
334
|
+
R extends Request,
|
335
|
+
V extends APIVersion = typeof DEFAULT_API_VERSION,
|
336
|
+
T = RequestResponseMap<R, V>,
|
337
|
+
>(req: R): Promise<T> {
|
338
|
+
const request = {
|
326
339
|
...req,
|
327
|
-
account:
|
328
|
-
|
329
|
-
ensureClassicAddress(req.account
|
330
|
-
|
331
|
-
|
340
|
+
account:
|
341
|
+
typeof req.account === 'string'
|
342
|
+
? ensureClassicAddress(req.account)
|
343
|
+
: undefined,
|
344
|
+
api_version: req.api_version ?? this.apiVersion,
|
345
|
+
}
|
346
|
+
const response = await this.connection.request<R, T>(request)
|
332
347
|
|
333
348
|
// mutates `response` to add warnings
|
334
349
|
handlePartialPayment(req.command, response)
|
@@ -437,9 +452,10 @@ class Client extends EventEmitter<EventTypes> {
|
|
437
452
|
* const allResponses = await client.requestAll({ command: 'transaction_data' });
|
438
453
|
* console.log(allResponses);
|
439
454
|
*/
|
455
|
+
|
440
456
|
public async requestAll<
|
441
457
|
T extends MarkerRequest,
|
442
|
-
U = RequestAllResponseMap<T>,
|
458
|
+
U = RequestAllResponseMap<T, APIVersion>,
|
443
459
|
>(request: T, collect?: string): Promise<U[]> {
|
444
460
|
/*
|
445
461
|
* The data under collection is keyed based on the command. Fail if command
|
@@ -467,7 +483,7 @@ class Client extends EventEmitter<EventTypes> {
|
|
467
483
|
// eslint-disable-next-line no-await-in-loop -- Necessary for this, it really has to wait
|
468
484
|
const singleResponse = await this.connection.request(repeatProps)
|
469
485
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Should be true
|
470
|
-
const singleResult = (singleResponse as MarkerResponse).result
|
486
|
+
const singleResult = (singleResponse as MarkerResponse<APIVersion>).result
|
471
487
|
if (!(collectKey in singleResult)) {
|
472
488
|
throw new XrplError(`${collectKey} not in result`)
|
473
489
|
}
|
@@ -638,7 +654,10 @@ class Client extends EventEmitter<EventTypes> {
|
|
638
654
|
* @param signersCount - The expected number of signers for this transaction.
|
639
655
|
* Only used for multisigned transactions.
|
640
656
|
* @returns The autofilled transaction.
|
657
|
+
* @throws ValidationError If Amount and DeliverMax fields are not identical in a Payment Transaction
|
641
658
|
*/
|
659
|
+
|
660
|
+
// eslint-disable-next-line complexity -- handling Payment transaction API v2 requires more logic
|
642
661
|
public async autofill<T extends SubmittableTransaction>(
|
643
662
|
transaction: T,
|
644
663
|
signersCount?: number,
|
@@ -646,7 +665,6 @@ class Client extends EventEmitter<EventTypes> {
|
|
646
665
|
const tx = { ...transaction }
|
647
666
|
|
648
667
|
setValidAddresses(tx)
|
649
|
-
|
650
668
|
setTransactionFlagsToNumber(tx)
|
651
669
|
|
652
670
|
const promises: Array<Promise<void>> = []
|
@@ -666,6 +684,34 @@ class Client extends EventEmitter<EventTypes> {
|
|
666
684
|
promises.push(checkAccountDeleteBlockers(this, tx))
|
667
685
|
}
|
668
686
|
|
687
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ignore type-assertions on the DeliverMax property
|
688
|
+
// @ts-expect-error -- DeliverMax property exists only at the RPC level, not at the protocol level
|
689
|
+
if (tx.TransactionType === 'Payment' && tx.DeliverMax != null) {
|
690
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- This is a valid null check for Amount
|
691
|
+
if (tx.Amount == null) {
|
692
|
+
// If only DeliverMax is provided, use it to populate the Amount field
|
693
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ignore type-assertions on the DeliverMax property
|
694
|
+
// @ts-expect-error -- DeliverMax property exists only at the RPC level, not at the protocol level
|
695
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- DeliverMax is a known RPC-level property
|
696
|
+
tx.Amount = tx.DeliverMax
|
697
|
+
}
|
698
|
+
|
699
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ignore type-assertions on the DeliverMax property
|
700
|
+
// @ts-expect-error -- DeliverMax property exists only at the RPC level, not at the protocol level
|
701
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- This is a valid null check for Amount
|
702
|
+
if (tx.Amount != null && tx.Amount !== tx.DeliverMax) {
|
703
|
+
return Promise.reject(
|
704
|
+
new ValidationError(
|
705
|
+
'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided',
|
706
|
+
),
|
707
|
+
)
|
708
|
+
}
|
709
|
+
|
710
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ignore type-assertions on the DeliverMax property
|
711
|
+
// @ts-expect-error -- DeliverMax property exists only at the RPC level, not at the protocol level
|
712
|
+
delete tx.DeliverMax
|
713
|
+
}
|
714
|
+
|
669
715
|
return Promise.all(promises).then(() => tx)
|
670
716
|
}
|
671
717
|
|
@@ -909,7 +955,7 @@ class Client extends EventEmitter<EventTypes> {
|
|
909
955
|
* @param options.limit - Limit number of balances to return.
|
910
956
|
* @returns An array of XRP/non-XRP balances for the given account.
|
911
957
|
*/
|
912
|
-
|
958
|
+
/* eslint-disable max-lines-per-function -- getBalances requires more lines to implement logic */
|
913
959
|
public async getBalances(
|
914
960
|
address: string,
|
915
961
|
options: {
|
@@ -957,6 +1003,7 @@ class Client extends EventEmitter<EventTypes> {
|
|
957
1003
|
)
|
958
1004
|
return balances.slice(0, options.limit)
|
959
1005
|
}
|
1006
|
+
/* eslint-enable max-lines-per-function */
|
960
1007
|
|
961
1008
|
/**
|
962
1009
|
* Fetch orderbook (buy/sell orders) between two currency pairs. This checks both sides of the orderbook
|
@@ -2,13 +2,16 @@ import BigNumber from 'bignumber.js'
|
|
2
2
|
import { decode } from 'ripple-binary-codec'
|
3
3
|
|
4
4
|
import type {
|
5
|
-
AccountTxResponse,
|
6
5
|
TransactionEntryResponse,
|
7
6
|
TransactionStream,
|
8
7
|
TxResponse,
|
9
8
|
} from '..'
|
10
|
-
import type { Amount } from '../models/common'
|
11
|
-
import type {
|
9
|
+
import type { Amount, APIVersion, DEFAULT_API_VERSION } from '../models/common'
|
10
|
+
import type {
|
11
|
+
AccountTxTransaction,
|
12
|
+
RequestResponseMap,
|
13
|
+
} from '../models/methods'
|
14
|
+
import { AccountTxVersionResponseMap } from '../models/methods/accountTx'
|
12
15
|
import { BaseRequest, BaseResponse } from '../models/methods/baseMethod'
|
13
16
|
import { PaymentFlags, Transaction } from '../models/transactions'
|
14
17
|
import type { TransactionMetadata } from '../models/transactions/metadata'
|
@@ -63,7 +66,10 @@ function isPartialPayment(
|
|
63
66
|
}
|
64
67
|
|
65
68
|
const delivered = meta.delivered_amount
|
66
|
-
|
69
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- DeliverMax is a valid field on Payment response
|
70
|
+
// @ts-expect-error -- DeliverMax is a valid field on Payment response
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- DeliverMax is a valid field on Payment response
|
72
|
+
const amount = tx.DeliverMax
|
67
73
|
|
68
74
|
if (delivered === undefined) {
|
69
75
|
return false
|
@@ -73,23 +79,36 @@ function isPartialPayment(
|
|
73
79
|
}
|
74
80
|
|
75
81
|
function txHasPartialPayment(response: TxResponse): boolean {
|
76
|
-
return isPartialPayment(response.result, response.result.meta)
|
82
|
+
return isPartialPayment(response.result.tx_json, response.result.meta)
|
77
83
|
}
|
78
84
|
|
79
85
|
function txEntryHasPartialPayment(response: TransactionEntryResponse): boolean {
|
80
86
|
return isPartialPayment(response.result.tx_json, response.result.metadata)
|
81
87
|
}
|
82
88
|
|
83
|
-
function accountTxHasPartialPayment
|
89
|
+
function accountTxHasPartialPayment<
|
90
|
+
Version extends APIVersion = typeof DEFAULT_API_VERSION,
|
91
|
+
>(response: AccountTxVersionResponseMap<Version>): boolean {
|
84
92
|
const { transactions } = response.result
|
85
|
-
const foo = transactions.some((tx) =>
|
93
|
+
const foo = transactions.some((tx) => {
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- required to check API version model
|
95
|
+
if (tx.tx_json != null) {
|
96
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- use API v2 model
|
97
|
+
const transaction = tx as AccountTxTransaction
|
98
|
+
return isPartialPayment(transaction.tx_json, transaction.meta)
|
99
|
+
}
|
100
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- use API v1 model
|
101
|
+
const transaction = tx as AccountTxTransaction<1>
|
102
|
+
return isPartialPayment(transaction.tx, transaction.meta)
|
103
|
+
})
|
86
104
|
return foo
|
87
105
|
}
|
88
106
|
|
89
|
-
function hasPartialPayment<
|
90
|
-
|
91
|
-
|
92
|
-
|
107
|
+
function hasPartialPayment<
|
108
|
+
R extends BaseRequest,
|
109
|
+
V extends APIVersion = typeof DEFAULT_API_VERSION,
|
110
|
+
T = RequestResponseMap<R, V>,
|
111
|
+
>(command: string, response: T): boolean {
|
93
112
|
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Request type is known at runtime from command */
|
94
113
|
switch (command) {
|
95
114
|
case 'tx':
|
@@ -97,7 +116,9 @@ function hasPartialPayment<R extends BaseRequest, T = RequestResponseMap<R>>(
|
|
97
116
|
case 'transaction_entry':
|
98
117
|
return txEntryHasPartialPayment(response as TransactionEntryResponse)
|
99
118
|
case 'account_tx':
|
100
|
-
return accountTxHasPartialPayment(
|
119
|
+
return accountTxHasPartialPayment(
|
120
|
+
response as AccountTxVersionResponseMap<V>,
|
121
|
+
)
|
101
122
|
default:
|
102
123
|
return false
|
103
124
|
}
|
@@ -112,7 +133,7 @@ function hasPartialPayment<R extends BaseRequest, T = RequestResponseMap<R>>(
|
|
112
133
|
*/
|
113
134
|
export function handlePartialPayment<
|
114
135
|
R extends BaseRequest,
|
115
|
-
T = RequestResponseMap<R>,
|
136
|
+
T = RequestResponseMap<R, APIVersion>,
|
116
137
|
>(command: string, response: T): void {
|
117
138
|
if (hasPartialPayment(command, response)) {
|
118
139
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- We are checking dynamically and safely.
|
@@ -1,3 +1,7 @@
|
|
1
|
+
export const RIPPLED_API_V1 = 1
|
2
|
+
export const RIPPLED_API_V2 = 2
|
3
|
+
export const DEFAULT_API_VERSION = RIPPLED_API_V2
|
4
|
+
export type APIVersion = typeof RIPPLED_API_V1 | typeof RIPPLED_API_V2
|
1
5
|
export type LedgerIndex = number | ('validated' | 'closed' | 'current')
|
2
6
|
|
3
7
|
export interface XRP {
|
@@ -104,6 +108,10 @@ export interface ResponseOnlyTxInfo {
|
|
104
108
|
* The sequence number of the ledger that included this transaction.
|
105
109
|
*/
|
106
110
|
ledger_index?: number
|
111
|
+
/**
|
112
|
+
* The hash of the ledger included this transaction.
|
113
|
+
*/
|
114
|
+
ledger_hash?: string
|
107
115
|
/**
|
108
116
|
* @deprecated Alias for ledger_index.
|
109
117
|
*/
|
package/src/models/ledger/AMM.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { AuthAccount, Currency, IssuedCurrencyAmount } from '../common'
|
2
2
|
|
3
|
-
import { BaseLedgerEntry,
|
3
|
+
import { BaseLedgerEntry, HasOptionalPreviousTxnID } from './BaseLedgerEntry'
|
4
4
|
|
5
5
|
export interface VoteSlot {
|
6
6
|
VoteEntry: {
|
@@ -15,7 +15,7 @@ export interface VoteSlot {
|
|
15
15
|
*
|
16
16
|
* @category Ledger Entries
|
17
17
|
*/
|
18
|
-
export default interface AMM extends BaseLedgerEntry,
|
18
|
+
export default interface AMM extends BaseLedgerEntry, HasOptionalPreviousTxnID {
|
19
19
|
LedgerEntryType: 'AMM'
|
20
20
|
/**
|
21
21
|
* The address of the special account that holds this AMM's assets.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BaseLedgerEntry,
|
1
|
+
import { BaseLedgerEntry, HasOptionalPreviousTxnID } from './BaseLedgerEntry'
|
2
2
|
|
3
3
|
/**
|
4
4
|
* The unique id for the Amendments object https://xrpl.org/amendments-object.html#amendments-id-format
|
@@ -26,7 +26,7 @@ export interface Majority {
|
|
26
26
|
*/
|
27
27
|
export default interface Amendments
|
28
28
|
extends BaseLedgerEntry,
|
29
|
-
|
29
|
+
HasOptionalPreviousTxnID {
|
30
30
|
LedgerEntryType: 'Amendments'
|
31
31
|
/**
|
32
32
|
* Array of 256-bit amendment IDs for all currently-enabled amendments. If
|
@@ -15,13 +15,17 @@ export interface HasPreviousTxnID {
|
|
15
15
|
PreviousTxnLgrSeq: number
|
16
16
|
}
|
17
17
|
|
18
|
-
export interface
|
18
|
+
export interface HasOptionalPreviousTxnID {
|
19
19
|
/**
|
20
|
-
*
|
20
|
+
* The identifying hash of the transaction that most recently modified this
|
21
|
+
* object. This field was added in the `fixPreviousTxnID` amendment, so it
|
22
|
+
* may not be present in every object.
|
21
23
|
*/
|
22
|
-
PreviousTxnID
|
24
|
+
PreviousTxnID?: string
|
23
25
|
/**
|
24
|
-
*
|
26
|
+
* The index of the ledger that contains the transaction that most recently
|
27
|
+
* modified this object. This field was added in the `fixPreviousTxnID`
|
28
|
+
* amendment, so it may not be present in every object.
|
25
29
|
*/
|
26
|
-
PreviousTxnLgrSeq
|
30
|
+
PreviousTxnLgrSeq?: number
|
27
31
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BaseLedgerEntry,
|
1
|
+
import { BaseLedgerEntry, HasOptionalPreviousTxnID } from './BaseLedgerEntry'
|
2
2
|
|
3
3
|
/**
|
4
4
|
* The DirectoryNode object type provides a list of links to other objects in
|
@@ -8,7 +8,7 @@ import { BaseLedgerEntry, MissingPreviousTxnID } from './BaseLedgerEntry'
|
|
8
8
|
*/
|
9
9
|
export default interface DirectoryNode
|
10
10
|
extends BaseLedgerEntry,
|
11
|
-
|
11
|
+
HasOptionalPreviousTxnID {
|
12
12
|
LedgerEntryType: 'DirectoryNode'
|
13
13
|
/**
|
14
14
|
* A bit-map of boolean flags enabled for this directory. Currently, the
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BaseLedgerEntry,
|
1
|
+
import { BaseLedgerEntry, HasOptionalPreviousTxnID } from './BaseLedgerEntry'
|
2
2
|
|
3
3
|
/**
|
4
4
|
* The unique id for the FeeSettings object https://xrpl.org/feesettings.html#feesettings-id-format
|
@@ -26,7 +26,9 @@ export interface FeeSettingsPostAmendmentFields {
|
|
26
26
|
ReserveIncrementDrops: string
|
27
27
|
}
|
28
28
|
|
29
|
-
export interface FeeSettingsBase
|
29
|
+
export interface FeeSettingsBase
|
30
|
+
extends BaseLedgerEntry,
|
31
|
+
HasOptionalPreviousTxnID {
|
30
32
|
LedgerEntryType: 'FeeSettings'
|
31
33
|
/**
|
32
34
|
* A bit-map of boolean flags for this object. No flags are defined for this type.
|
@@ -1,14 +1,14 @@
|
|
1
|
+
import { APIVersion, DEFAULT_API_VERSION, RIPPLED_API_V1 } from '../common'
|
1
2
|
import { Transaction, TransactionMetadata } from '../transactions'
|
2
3
|
|
3
4
|
import { LedgerEntry } from './LedgerEntry'
|
4
5
|
|
5
6
|
/**
|
6
|
-
*
|
7
|
-
* header that describes its contents using cryptographic hashes.
|
7
|
+
* Common properties for ledger entries.
|
8
8
|
*
|
9
9
|
* @category Ledger Entries
|
10
10
|
*/
|
11
|
-
|
11
|
+
interface BaseLedger {
|
12
12
|
/** The SHA-512Half of this ledger's state tree information. */
|
13
13
|
account_hash: string
|
14
14
|
/** All the state information in this ledger. Admin only. */
|
@@ -38,11 +38,6 @@ export default interface Ledger {
|
|
38
38
|
* for this ledger and all its contents.
|
39
39
|
*/
|
40
40
|
ledger_hash: string
|
41
|
-
/**
|
42
|
-
* The ledger index of the ledger. Some API methods display this as a quoted
|
43
|
-
* integer; some display it as a native JSON number.
|
44
|
-
*/
|
45
|
-
ledger_index: string
|
46
41
|
/** The approximate time at which the previous ledger was closed. */
|
47
42
|
parent_close_time: number
|
48
43
|
/**
|
@@ -61,5 +56,47 @@ export default interface Ledger {
|
|
61
56
|
* either JSON or binary depending on whether the request specified binary
|
62
57
|
* as true.
|
63
58
|
*/
|
64
|
-
transactions?: Array<
|
59
|
+
transactions?: Array<
|
60
|
+
Transaction & {
|
61
|
+
hash: string
|
62
|
+
metaData?: TransactionMetadata
|
63
|
+
}
|
64
|
+
>
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
* A ledger is a block of transactions and shared state data. It has a unique
|
69
|
+
* header that describes its contents using cryptographic hashes.
|
70
|
+
*
|
71
|
+
* @category Ledger Entries
|
72
|
+
*/
|
73
|
+
export interface Ledger extends BaseLedger {
|
74
|
+
/**
|
75
|
+
* The ledger index of the ledger. Represented as a number.
|
76
|
+
*/
|
77
|
+
ledger_index: number
|
65
78
|
}
|
79
|
+
|
80
|
+
/**
|
81
|
+
* A ledger is a block of transactions and shared state data. It has a unique
|
82
|
+
* header that describes its contents using cryptographic hashes. This is used
|
83
|
+
* in api_version 1.
|
84
|
+
*
|
85
|
+
* @category Ledger Entries
|
86
|
+
*/
|
87
|
+
export interface LedgerV1 extends BaseLedger {
|
88
|
+
/**
|
89
|
+
* The ledger index of the ledger. Some API methods display this as a quoted
|
90
|
+
* integer; some display it as a number.
|
91
|
+
*/
|
92
|
+
ledger_index: string
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Type to map between the API version and the Ledger type.
|
97
|
+
*
|
98
|
+
* @category Responses
|
99
|
+
*/
|
100
|
+
export type LedgerVersionMap<
|
101
|
+
Version extends APIVersion = typeof DEFAULT_API_VERSION,
|
102
|
+
> = Version extends typeof RIPPLED_API_V1 ? LedgerV1 : Ledger
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BaseLedgerEntry
|
1
|
+
import { BaseLedgerEntry } from './BaseLedgerEntry'
|
2
2
|
|
3
3
|
/**
|
4
4
|
* The LedgerHashes objects exist to make it possible to look up a previous
|
@@ -7,9 +7,7 @@ import { BaseLedgerEntry, MissingPreviousTxnID } from './BaseLedgerEntry'
|
|
7
7
|
*
|
8
8
|
* @category Ledger Entries
|
9
9
|
*/
|
10
|
-
export default interface LedgerHashes
|
11
|
-
extends BaseLedgerEntry,
|
12
|
-
MissingPreviousTxnID {
|
10
|
+
export default interface LedgerHashes extends BaseLedgerEntry {
|
13
11
|
LedgerEntryType: 'LedgerHashes'
|
14
12
|
/** The Ledger Index of the last entry in this object's Hashes array. */
|
15
13
|
LastLedgerSequence?: number
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BaseLedgerEntry,
|
1
|
+
import { BaseLedgerEntry, HasOptionalPreviousTxnID } from './BaseLedgerEntry'
|
2
2
|
|
3
3
|
/**
|
4
4
|
* The unique id for the nUNL object https://xrpl.org/negativeunl.html#negativeunl-id-format
|
@@ -14,7 +14,7 @@ export const NEGATIVE_UNL_ID =
|
|
14
14
|
*/
|
15
15
|
export default interface NegativeUNL
|
16
16
|
extends BaseLedgerEntry,
|
17
|
-
|
17
|
+
HasOptionalPreviousTxnID {
|
18
18
|
LedgerEntryType: 'NegativeUNL'
|
19
19
|
/**
|
20
20
|
* A list of trusted validators that are currently disabled.
|
@@ -15,7 +15,7 @@ import FeeSettings, {
|
|
15
15
|
FeeSettingsPostAmendmentFields,
|
16
16
|
FEE_SETTINGS_ID,
|
17
17
|
} from './FeeSettings'
|
18
|
-
import Ledger from './Ledger'
|
18
|
+
import { Ledger, LedgerV1 } from './Ledger'
|
19
19
|
import { LedgerEntry, LedgerEntryFilter } from './LedgerEntry'
|
20
20
|
import LedgerHashes from './LedgerHashes'
|
21
21
|
import NegativeUNL, { NEGATIVE_UNL_ID } from './NegativeUNL'
|
@@ -48,6 +48,7 @@ export {
|
|
48
48
|
FeeSettingsPreAmendmentFields,
|
49
49
|
FeeSettingsPostAmendmentFields,
|
50
50
|
Ledger,
|
51
|
+
LedgerV1,
|
51
52
|
LedgerEntryFilter,
|
52
53
|
LedgerEntry,
|
53
54
|
LedgerHashes,
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { APIVersion, DEFAULT_API_VERSION, RIPPLED_API_V1 } from '../common'
|
1
2
|
import { AccountRoot, SignerList } from '../ledger'
|
2
3
|
|
3
4
|
import { BaseRequest, BaseResponse, LookupByLedgerRequest } from './baseMethod'
|
@@ -133,23 +134,13 @@ export interface AccountInfoAccountFlags {
|
|
133
134
|
allowTrustLineClawback: boolean
|
134
135
|
}
|
135
136
|
|
136
|
-
|
137
|
-
* Response expected from an {@link AccountInfoRequest}.
|
138
|
-
*
|
139
|
-
* @category Responses
|
140
|
-
*/
|
141
|
-
export interface AccountInfoResponse extends BaseResponse {
|
137
|
+
interface BaseAccountInfoResponse extends BaseResponse {
|
142
138
|
result: {
|
143
139
|
/**
|
144
140
|
* The AccountRoot ledger object with this account's information, as stored
|
145
141
|
* in the ledger.
|
146
|
-
* If requested, also includes Array of SignerList ledger objects
|
147
|
-
* associated with this account for Multi-Signing. Since an account can own
|
148
|
-
* at most one SignerList, this array must have exactly one member if it is
|
149
|
-
* present.
|
150
142
|
*/
|
151
|
-
account_data: AccountRoot
|
152
|
-
|
143
|
+
account_data: AccountRoot
|
153
144
|
/**
|
154
145
|
* A map of account flags parsed out. This will only be available for rippled nodes 1.11.0 and higher.
|
155
146
|
*/
|
@@ -180,3 +171,58 @@ export interface AccountInfoResponse extends BaseResponse {
|
|
180
171
|
validated?: boolean
|
181
172
|
}
|
182
173
|
}
|
174
|
+
|
175
|
+
/**
|
176
|
+
* Response expected from a {@link AccountInfoRequest}.
|
177
|
+
*
|
178
|
+
* @category Responses
|
179
|
+
*/
|
180
|
+
export interface AccountInfoResponse extends BaseAccountInfoResponse {
|
181
|
+
result: BaseAccountInfoResponse['result'] & {
|
182
|
+
/**
|
183
|
+
* If requested, array of SignerList ledger objects associated with this account for Multi-Signing.
|
184
|
+
* Since an account can own at most one SignerList, this array must have exactly one
|
185
|
+
* member if it is present.
|
186
|
+
*/
|
187
|
+
signer_lists?: SignerList[]
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
/**
|
192
|
+
* Response expected from a {@link AccountInfoRequest} using API version 1.
|
193
|
+
*
|
194
|
+
* @category ResponsesV1
|
195
|
+
*/
|
196
|
+
export interface AccountInfoV1Response extends BaseAccountInfoResponse {
|
197
|
+
result: BaseAccountInfoResponse['result'] & {
|
198
|
+
/**
|
199
|
+
* The AccountRoot ledger object with this account's information, as stored
|
200
|
+
* in the ledger.
|
201
|
+
* If requested, also includes Array of SignerList ledger objects
|
202
|
+
* associated with this account for Multi-Signing. Since an account can own
|
203
|
+
* at most one SignerList, this array must have exactly one member if it is
|
204
|
+
* present.
|
205
|
+
*/
|
206
|
+
account_data: BaseAccountInfoResponse['result']['account_data'] & {
|
207
|
+
/**
|
208
|
+
* Array of SignerList ledger objects associated with this account for Multi-Signing.
|
209
|
+
* Since an account can own at most one SignerList, this array must have exactly one
|
210
|
+
* member if it is present.
|
211
|
+
* Quirk: In API version 1, this field is nested under account_data. For this method,
|
212
|
+
* Clio implements the API version 2 behavior where is field is not nested under account_data.
|
213
|
+
*/
|
214
|
+
signer_lists?: SignerList[]
|
215
|
+
}
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
/**
|
220
|
+
* Type to map between the API version and the response type.
|
221
|
+
*
|
222
|
+
* @category Responses
|
223
|
+
*/
|
224
|
+
export type AccountInfoVersionResponseMap<
|
225
|
+
Version extends APIVersion = typeof DEFAULT_API_VERSION,
|
226
|
+
> = Version extends typeof RIPPLED_API_V1
|
227
|
+
? AccountInfoV1Response
|
228
|
+
: AccountInfoResponse
|