@ledgerhq/coin-xrp 0.7.1 → 0.8.0-next.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/CHANGELOG.md +17 -0
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.integ.test.js +13 -4
- package/lib/api/index.integ.test.js.map +1 -1
- package/lib/api/index.js +14 -7
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +31 -13
- package/lib/api/index.test.js.map +1 -1
- package/lib/bridge/index.d.ts +1 -1
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/index.js +2 -1
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/synchronization.js +5 -5
- package/lib/bridge/synchronization.js.map +1 -1
- package/lib/bridge/synchronization.test.js +5 -4
- package/lib/bridge/synchronization.test.js.map +1 -1
- package/lib/logic/listOperations.d.ts +5 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +39 -13
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +22 -10
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/network/index.d.ts +1 -0
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js +2 -2
- package/lib/network/index.js.map +1 -1
- package/lib/network/types.d.ts +4 -3
- package/lib/network/types.d.ts.map +1 -1
- package/lib/network/types.js.map +1 -1
- package/lib/types/model.d.ts +2 -0
- package/lib/types/model.d.ts.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.integ.test.js +13 -4
- package/lib-es/api/index.integ.test.js.map +1 -1
- package/lib-es/api/index.js +14 -7
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +31 -13
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/bridge/index.d.ts +1 -1
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js +3 -2
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/synchronization.js +5 -5
- package/lib-es/bridge/synchronization.js.map +1 -1
- package/lib-es/bridge/synchronization.test.js +5 -4
- package/lib-es/bridge/synchronization.test.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts +5 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +39 -13
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +22 -10
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/network/index.d.ts +1 -0
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js +2 -2
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/network/types.d.ts +4 -3
- package/lib-es/network/types.d.ts.map +1 -1
- package/lib-es/network/types.js.map +1 -1
- package/lib-es/types/model.d.ts +2 -0
- package/lib-es/types/model.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/api/index.integ.test.ts +15 -4
- package/src/api/index.test.ts +31 -13
- package/src/api/index.ts +20 -6
- package/src/bridge/index.ts +4 -2
- package/src/bridge/synchronization.test.ts +5 -4
- package/src/bridge/synchronization.ts +5 -5
- package/src/logic/listOperations.test.ts +22 -10
- package/src/logic/listOperations.ts +64 -15
- package/src/network/index.ts +3 -3
- package/src/network/types.ts +4 -3
- package/src/types/model.ts +2 -0
|
@@ -11,42 +11,89 @@ import { RIPPLE_EPOCH } from "./utils";
|
|
|
11
11
|
*/
|
|
12
12
|
export async function listOperations(
|
|
13
13
|
address: string,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
{
|
|
15
|
+
limit,
|
|
16
|
+
mostRecentIndex,
|
|
17
|
+
startAt,
|
|
18
|
+
}: {
|
|
19
|
+
limit?: number;
|
|
20
|
+
mostRecentIndex?: number | undefined;
|
|
21
|
+
startAt?: number;
|
|
22
|
+
},
|
|
23
|
+
): Promise<[XrpOperation[], number]> {
|
|
16
24
|
const serverInfo = await getServerInfos();
|
|
17
25
|
const ledgers = serverInfo.info.complete_ledgers.split("-");
|
|
18
26
|
const minLedgerVersion = Number(ledgers[0]);
|
|
19
27
|
const maxLedgerVersion = Number(ledgers[1]);
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
let options: {
|
|
30
|
+
ledger_index_min?: number;
|
|
31
|
+
ledger_index_max?: number;
|
|
32
|
+
limit?: number;
|
|
33
|
+
tx_type?: string;
|
|
34
|
+
} = {
|
|
35
|
+
ledger_index_max: mostRecentIndex ?? maxLedgerVersion,
|
|
36
|
+
tx_type: "Payment",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
if (limit) {
|
|
40
|
+
options = {
|
|
41
|
+
...options,
|
|
42
|
+
limit,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (startAt) {
|
|
46
|
+
options = {
|
|
47
|
+
...options,
|
|
48
|
+
// if there is no ops, it might be after a clear and we prefer to pull from the oldest possible history
|
|
49
|
+
ledger_index_min: Math.max(startAt, minLedgerVersion),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
23
52
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
53
|
+
// We need to filter out the transactions that are not "Payment" type because the filter on "tx_type" of the node RPC
|
|
54
|
+
// is not working as expected. It returns all the transactions. We need to call the node RPC multiple times to get the
|
|
55
|
+
// desired number of transactions by the limiter.
|
|
56
|
+
let transactions: XrplOperation[] = [];
|
|
57
|
+
let needToStop = true;
|
|
58
|
+
do {
|
|
59
|
+
const newTransactions = await getTransactions(address, options);
|
|
60
|
+
const newPaymentsTxs = newTransactions.filter(tx => tx.tx_json.TransactionType === "Payment");
|
|
61
|
+
if (options.limit) {
|
|
62
|
+
needToStop = newTransactions.length < options.limit;
|
|
63
|
+
options.ledger_index_max = newTransactions.slice(-1)[0].tx_json.ledger_index - 1;
|
|
64
|
+
}
|
|
65
|
+
transactions = transactions.concat(newPaymentsTxs);
|
|
66
|
+
} while (
|
|
67
|
+
options.limit &&
|
|
68
|
+
!needToStop &&
|
|
69
|
+
transactions.length < options.limit &&
|
|
70
|
+
(options.limit -= transactions.length)
|
|
71
|
+
);
|
|
28
72
|
|
|
29
|
-
return
|
|
30
|
-
.
|
|
31
|
-
.
|
|
73
|
+
return [
|
|
74
|
+
transactions.map(convertToCoreOperation(address)),
|
|
75
|
+
transactions.slice(-1)[0].tx_json.ledger_index - 1, // Returns the next index to start from for pagination
|
|
76
|
+
];
|
|
32
77
|
}
|
|
33
78
|
|
|
34
79
|
const convertToCoreOperation =
|
|
35
80
|
(address: string) =>
|
|
36
81
|
(operation: XrplOperation): XrpOperation => {
|
|
37
82
|
const {
|
|
83
|
+
ledger_hash,
|
|
84
|
+
hash,
|
|
85
|
+
close_time_iso,
|
|
38
86
|
meta: { delivered_amount },
|
|
39
|
-
|
|
87
|
+
tx_json: {
|
|
40
88
|
TransactionType,
|
|
41
89
|
Fee,
|
|
42
|
-
hash,
|
|
43
|
-
inLedger,
|
|
44
90
|
date,
|
|
45
91
|
Account,
|
|
46
92
|
Destination,
|
|
47
93
|
DestinationTag,
|
|
48
94
|
Sequence,
|
|
49
95
|
Memos,
|
|
96
|
+
ledger_index,
|
|
50
97
|
},
|
|
51
98
|
} = operation;
|
|
52
99
|
|
|
@@ -90,13 +137,15 @@ const convertToCoreOperation =
|
|
|
90
137
|
}
|
|
91
138
|
|
|
92
139
|
let op: XrpOperation = {
|
|
140
|
+
blockTime: new Date(close_time_iso),
|
|
141
|
+
blockHash: ledger_hash,
|
|
93
142
|
hash,
|
|
94
143
|
address,
|
|
95
144
|
type: TransactionType,
|
|
96
145
|
simpleType: type,
|
|
97
146
|
value,
|
|
98
147
|
fee,
|
|
99
|
-
blockHeight:
|
|
148
|
+
blockHeight: ledger_index,
|
|
100
149
|
senders: [Account],
|
|
101
150
|
recipients: [Destination],
|
|
102
151
|
date: new Date(toEpochDate),
|
package/src/network/index.ts
CHANGED
|
@@ -68,12 +68,12 @@ export const getServerInfos = async (): Promise<ServerInfoResponse> => {
|
|
|
68
68
|
|
|
69
69
|
export const getTransactions = async (
|
|
70
70
|
address: string,
|
|
71
|
-
options: { ledger_index_min?: number; ledger_index_max?: number } | undefined,
|
|
71
|
+
options: { ledger_index_min?: number; ledger_index_max?: number; limit?: number } | undefined,
|
|
72
72
|
): Promise<XrplOperation[]> => {
|
|
73
73
|
const result = await rpcCall<AccountTxResponse>("account_tx", {
|
|
74
74
|
account: address,
|
|
75
|
-
ledger_index: "validated",
|
|
76
75
|
...options,
|
|
76
|
+
api_version: 2,
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
return result.transactions;
|
|
@@ -109,7 +109,7 @@ async function rpcCall<T extends object>(
|
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
if (isResponseStatus(result) && result.status !== "success") {
|
|
112
|
-
throw new Error(`couldn't fetch ${method} with params ${params}`);
|
|
112
|
+
throw new Error(`couldn't fetch ${method} with params ${JSON.stringify(params)}`);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
return result;
|
package/src/network/types.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export type XrplOperation = {
|
|
2
|
+
ledger_hash: string;
|
|
3
|
+
hash: string;
|
|
4
|
+
close_time_iso: string;
|
|
2
5
|
meta: {
|
|
3
6
|
AffectedNodes: {
|
|
4
7
|
ModifiedNode: {
|
|
@@ -22,7 +25,7 @@ export type XrplOperation = {
|
|
|
22
25
|
TransactionResult: string;
|
|
23
26
|
delivered_amount: string;
|
|
24
27
|
};
|
|
25
|
-
|
|
28
|
+
tx_json: {
|
|
26
29
|
Account: string;
|
|
27
30
|
Amount: string;
|
|
28
31
|
DeliverMax: string;
|
|
@@ -44,8 +47,6 @@ export type XrplOperation = {
|
|
|
44
47
|
TransactionType: string;
|
|
45
48
|
TxnSignature: string;
|
|
46
49
|
date: number;
|
|
47
|
-
hash: string;
|
|
48
|
-
inLedger: number;
|
|
49
50
|
ledger_index: number;
|
|
50
51
|
};
|
|
51
52
|
validated: boolean;
|