@ledgerhq/coin-xrp 0.7.1 → 0.7.2-nightly.1

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.
Files changed (74) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +18 -0
  3. package/lib/api/index.d.ts.map +1 -1
  4. package/lib/api/index.integ.test.js +13 -4
  5. package/lib/api/index.integ.test.js.map +1 -1
  6. package/lib/api/index.js +14 -7
  7. package/lib/api/index.js.map +1 -1
  8. package/lib/api/index.test.js +31 -13
  9. package/lib/api/index.test.js.map +1 -1
  10. package/lib/bridge/index.d.ts +1 -1
  11. package/lib/bridge/index.d.ts.map +1 -1
  12. package/lib/bridge/index.js +2 -1
  13. package/lib/bridge/index.js.map +1 -1
  14. package/lib/bridge/synchronization.js +5 -5
  15. package/lib/bridge/synchronization.js.map +1 -1
  16. package/lib/bridge/synchronization.test.js +5 -4
  17. package/lib/bridge/synchronization.test.js.map +1 -1
  18. package/lib/logic/listOperations.d.ts +5 -1
  19. package/lib/logic/listOperations.d.ts.map +1 -1
  20. package/lib/logic/listOperations.js +39 -13
  21. package/lib/logic/listOperations.js.map +1 -1
  22. package/lib/logic/listOperations.test.js +22 -10
  23. package/lib/logic/listOperations.test.js.map +1 -1
  24. package/lib/network/index.d.ts +1 -0
  25. package/lib/network/index.d.ts.map +1 -1
  26. package/lib/network/index.js +2 -2
  27. package/lib/network/index.js.map +1 -1
  28. package/lib/network/types.d.ts +4 -3
  29. package/lib/network/types.d.ts.map +1 -1
  30. package/lib/network/types.js.map +1 -1
  31. package/lib/types/model.d.ts +2 -0
  32. package/lib/types/model.d.ts.map +1 -1
  33. package/lib-es/api/index.d.ts.map +1 -1
  34. package/lib-es/api/index.integ.test.js +13 -4
  35. package/lib-es/api/index.integ.test.js.map +1 -1
  36. package/lib-es/api/index.js +14 -7
  37. package/lib-es/api/index.js.map +1 -1
  38. package/lib-es/api/index.test.js +31 -13
  39. package/lib-es/api/index.test.js.map +1 -1
  40. package/lib-es/bridge/index.d.ts +1 -1
  41. package/lib-es/bridge/index.d.ts.map +1 -1
  42. package/lib-es/bridge/index.js +3 -2
  43. package/lib-es/bridge/index.js.map +1 -1
  44. package/lib-es/bridge/synchronization.js +5 -5
  45. package/lib-es/bridge/synchronization.js.map +1 -1
  46. package/lib-es/bridge/synchronization.test.js +5 -4
  47. package/lib-es/bridge/synchronization.test.js.map +1 -1
  48. package/lib-es/logic/listOperations.d.ts +5 -1
  49. package/lib-es/logic/listOperations.d.ts.map +1 -1
  50. package/lib-es/logic/listOperations.js +39 -13
  51. package/lib-es/logic/listOperations.js.map +1 -1
  52. package/lib-es/logic/listOperations.test.js +22 -10
  53. package/lib-es/logic/listOperations.test.js.map +1 -1
  54. package/lib-es/network/index.d.ts +1 -0
  55. package/lib-es/network/index.d.ts.map +1 -1
  56. package/lib-es/network/index.js +2 -2
  57. package/lib-es/network/index.js.map +1 -1
  58. package/lib-es/network/types.d.ts +4 -3
  59. package/lib-es/network/types.d.ts.map +1 -1
  60. package/lib-es/network/types.js.map +1 -1
  61. package/lib-es/types/model.d.ts +2 -0
  62. package/lib-es/types/model.d.ts.map +1 -1
  63. package/package.json +6 -6
  64. package/src/api/index.integ.test.ts +15 -4
  65. package/src/api/index.test.ts +31 -13
  66. package/src/api/index.ts +20 -6
  67. package/src/bridge/index.ts +4 -2
  68. package/src/bridge/synchronization.test.ts +5 -4
  69. package/src/bridge/synchronization.ts +5 -5
  70. package/src/logic/listOperations.test.ts +22 -10
  71. package/src/logic/listOperations.ts +64 -15
  72. package/src/network/index.ts +3 -3
  73. package/src/network/types.ts +4 -3
  74. package/src/types/model.ts +2 -0
@@ -39,12 +39,14 @@ describe("listOperations", () => {
39
39
  const fee = 10;
40
40
  mockGetTransactions.mockResolvedValue([
41
41
  {
42
+ ledger_hash: "HASH_VALUE_BLOCK",
43
+ hash: "HASH_VALUE",
44
+ close_time_iso: "2000-01-01T00:00:01Z",
42
45
  meta: { delivered_amount: deliveredAmount.toString() },
43
- tx: {
46
+ tx_json: {
44
47
  TransactionType: "Payment",
45
48
  Fee: fee.toString(),
46
- hash: "HASH_VALUE",
47
- inLedger: 1,
49
+ ledger_index: 1,
48
50
  date: 1000,
49
51
  Account: opSender,
50
52
  Destination: opDestination,
@@ -52,12 +54,14 @@ describe("listOperations", () => {
52
54
  },
53
55
  },
54
56
  {
57
+ ledger_hash: "HASH_VALUE_BLOCK",
58
+ hash: "HASH_VALUE",
59
+ close_time_iso: "2000-01-01T00:00:01Z",
55
60
  meta: { delivered_amount: deliveredAmount.toString() },
56
- tx: {
61
+ tx_json: {
57
62
  TransactionType: "Payment",
58
63
  Fee: fee.toString(),
59
- hash: "HASH_VALUE",
60
- inLedger: 1,
64
+ ledger_index: 1,
61
65
  date: 1000,
62
66
  Account: opSender,
63
67
  Destination: opDestination,
@@ -66,12 +70,14 @@ describe("listOperations", () => {
66
70
  },
67
71
  },
68
72
  {
73
+ ledger_hash: "HASH_VALUE_BLOCK",
74
+ hash: "HASH_VALUE",
75
+ close_time_iso: "2000-01-01T00:00:01Z",
69
76
  meta: { delivered_amount: deliveredAmount.toString() },
70
- tx: {
77
+ tx_json: {
71
78
  TransactionType: "Payment",
72
79
  Fee: fee.toString(),
73
- hash: "HASH_VALUE",
74
- inLedger: 1,
80
+ ledger_index: 1,
75
81
  date: 1000,
76
82
  Account: opSender,
77
83
  Destination: opDestination,
@@ -89,7 +95,7 @@ describe("listOperations", () => {
89
95
  ]);
90
96
 
91
97
  // When
92
- const results = await listOperations(address, 0);
98
+ const [results, _] = await listOperations(address, { startAt: 0 });
93
99
 
94
100
  // Then
95
101
  expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
@@ -106,6 +112,8 @@ describe("listOperations", () => {
106
112
  value: expectedValue,
107
113
  fee: BigInt(10),
108
114
  blockHeight: 1,
115
+ blockHash: "HASH_VALUE_BLOCK",
116
+ blockTime: new Date("2000-01-01T00:00:01Z"),
109
117
  senders: [opSender],
110
118
  recipients: [opDestination],
111
119
  date: new Date(1000000 + RIPPLE_EPOCH * 1000),
@@ -119,6 +127,8 @@ describe("listOperations", () => {
119
127
  value: expectedValue,
120
128
  fee: BigInt(10),
121
129
  blockHeight: 1,
130
+ blockHash: "HASH_VALUE_BLOCK",
131
+ blockTime: new Date("2000-01-01T00:00:01Z"),
122
132
  senders: [opSender],
123
133
  recipients: [opDestination],
124
134
  date: new Date(1000000 + RIPPLE_EPOCH * 1000),
@@ -135,6 +145,8 @@ describe("listOperations", () => {
135
145
  value: expectedValue,
136
146
  fee: BigInt(10),
137
147
  blockHeight: 1,
148
+ blockHash: "HASH_VALUE_BLOCK",
149
+ blockTime: new Date("2000-01-01T00:00:01Z"),
138
150
  senders: [opSender],
139
151
  recipients: [opDestination],
140
152
  date: new Date(1000000 + RIPPLE_EPOCH * 1000),
@@ -11,42 +11,89 @@ import { RIPPLE_EPOCH } from "./utils";
11
11
  */
12
12
  export async function listOperations(
13
13
  address: string,
14
- blockHeight: number,
15
- ): Promise<XrpOperation[]> {
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
- // if there is no ops, it might be after a clear and we prefer to pull from the oldest possible history
22
- const startAt = Math.max(blockHeight, minLedgerVersion);
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
- const transactions = await getTransactions(address, {
25
- ledger_index_min: startAt,
26
- ledger_index_max: maxLedgerVersion,
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 transactions
30
- .filter(op => op.tx.TransactionType === "Payment")
31
- .map(convertToCoreOperation(address));
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
- tx: {
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: inLedger,
148
+ blockHeight: ledger_index,
100
149
  senders: [Account],
101
150
  recipients: [Destination],
102
151
  date: new Date(toEpochDate),
@@ -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;
@@ -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
- tx: {
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;
@@ -11,6 +11,8 @@ export type XrpMemo = {
11
11
  type?: string;
12
12
  };
13
13
  export type XrpOperation = {
14
+ blockTime: Date;
15
+ blockHash: string;
14
16
  hash: string;
15
17
  address: string;
16
18
  type: string;