@ledgerhq/coin-xrp 0.8.0-nightly.6 → 0.8.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.
Files changed (52) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +35 -32
  3. package/lib/api/index.js +7 -3
  4. package/lib/api/index.js.map +1 -1
  5. package/lib/api/index.test.js +30 -12
  6. package/lib/api/index.test.js.map +1 -1
  7. package/lib/bridge/synchronization.js +1 -1
  8. package/lib/bridge/synchronization.js.map +1 -1
  9. package/lib/bridge/synchronization.test.js +5 -4
  10. package/lib/bridge/synchronization.test.js.map +1 -1
  11. package/lib/logic/listOperations.d.ts.map +1 -1
  12. package/lib/logic/listOperations.js +25 -8
  13. package/lib/logic/listOperations.js.map +1 -1
  14. package/lib/logic/listOperations.test.js +21 -9
  15. package/lib/logic/listOperations.test.js.map +1 -1
  16. package/lib/network/index.js +2 -2
  17. package/lib/network/index.js.map +1 -1
  18. package/lib/network/types.d.ts +4 -3
  19. package/lib/network/types.d.ts.map +1 -1
  20. package/lib/network/types.js.map +1 -1
  21. package/lib/types/model.d.ts +2 -0
  22. package/lib/types/model.d.ts.map +1 -1
  23. package/lib-es/api/index.js +7 -3
  24. package/lib-es/api/index.js.map +1 -1
  25. package/lib-es/api/index.test.js +30 -12
  26. package/lib-es/api/index.test.js.map +1 -1
  27. package/lib-es/bridge/synchronization.js +1 -1
  28. package/lib-es/bridge/synchronization.js.map +1 -1
  29. package/lib-es/bridge/synchronization.test.js +5 -4
  30. package/lib-es/bridge/synchronization.test.js.map +1 -1
  31. package/lib-es/logic/listOperations.d.ts.map +1 -1
  32. package/lib-es/logic/listOperations.js +25 -8
  33. package/lib-es/logic/listOperations.js.map +1 -1
  34. package/lib-es/logic/listOperations.test.js +21 -9
  35. package/lib-es/logic/listOperations.test.js.map +1 -1
  36. package/lib-es/network/index.js +2 -2
  37. package/lib-es/network/index.js.map +1 -1
  38. package/lib-es/network/types.d.ts +4 -3
  39. package/lib-es/network/types.d.ts.map +1 -1
  40. package/lib-es/network/types.js.map +1 -1
  41. package/lib-es/types/model.d.ts +2 -0
  42. package/lib-es/types/model.d.ts.map +1 -1
  43. package/package.json +5 -5
  44. package/src/api/index.test.ts +30 -12
  45. package/src/api/index.ts +10 -3
  46. package/src/bridge/synchronization.test.ts +5 -4
  47. package/src/bridge/synchronization.ts +1 -1
  48. package/src/logic/listOperations.test.ts +21 -9
  49. package/src/logic/listOperations.ts +38 -11
  50. package/src/network/index.ts +2 -2
  51. package/src/network/types.ts +4 -3
  52. package/src/types/model.ts +2 -0
@@ -41,12 +41,14 @@ describe("listOperations", () => {
41
41
  const fee = 10;
42
42
  mockGetTransactions.mockResolvedValue([
43
43
  {
44
+ ledger_hash: "HASH_VALUE_BLOCK",
45
+ hash: "HASH_VALUE",
46
+ close_time_iso: "2000-01-01T00:00:01Z",
44
47
  meta: { delivered_amount: deliveredAmount.toString() },
45
- tx: {
48
+ tx_json: {
46
49
  TransactionType: "Payment",
47
50
  Fee: fee.toString(),
48
- hash: "HASH_VALUE",
49
- inLedger: 1,
51
+ ledger_index: 1,
50
52
  date: 1000,
51
53
  Account: opSender,
52
54
  Destination: opDestination,
@@ -54,12 +56,14 @@ describe("listOperations", () => {
54
56
  },
55
57
  },
56
58
  {
59
+ ledger_hash: "HASH_VALUE_BLOCK",
60
+ hash: "HASH_VALUE",
61
+ close_time_iso: "2000-01-01T00:00:01Z",
57
62
  meta: { delivered_amount: deliveredAmount.toString() },
58
- tx: {
63
+ tx_json: {
59
64
  TransactionType: "Payment",
60
65
  Fee: fee.toString(),
61
- hash: "HASH_VALUE",
62
- inLedger: 1,
66
+ ledger_index: 1,
63
67
  date: 1000,
64
68
  Account: opSender,
65
69
  Destination: opDestination,
@@ -68,12 +72,14 @@ describe("listOperations", () => {
68
72
  },
69
73
  },
70
74
  {
75
+ ledger_hash: "HASH_VALUE_BLOCK",
76
+ hash: "HASH_VALUE",
77
+ close_time_iso: "2000-01-01T00:00:01Z",
71
78
  meta: { delivered_amount: deliveredAmount.toString() },
72
- tx: {
79
+ tx_json: {
73
80
  TransactionType: "Payment",
74
81
  Fee: fee.toString(),
75
- hash: "HASH_VALUE",
76
- inLedger: 1,
82
+ ledger_index: 1,
77
83
  date: 1000,
78
84
  Account: opSender,
79
85
  Destination: opDestination,
@@ -106,7 +112,11 @@ describe("listOperations", () => {
106
112
  type: "Payment",
107
113
  value: expectedValue,
108
114
  fee: BigInt(10),
109
- blockHeight: 1,
115
+ block: {
116
+ hash: "HASH_VALUE_BLOCK",
117
+ height: 1,
118
+ time: new Date("2000-01-01T00:00:01Z"),
119
+ },
110
120
  senders: [opSender],
111
121
  recipients: [opDestination],
112
122
  date: new Date(1000000 + RIPPLE_EPOCH * 1000),
@@ -118,7 +128,11 @@ describe("listOperations", () => {
118
128
  type: "Payment",
119
129
  value: expectedValue,
120
130
  fee: BigInt(10),
121
- blockHeight: 1,
131
+ block: {
132
+ hash: "HASH_VALUE_BLOCK",
133
+ height: 1,
134
+ time: new Date("2000-01-01T00:00:01Z"),
135
+ },
122
136
  senders: [opSender],
123
137
  recipients: [opDestination],
124
138
  date: new Date(1000000 + RIPPLE_EPOCH * 1000),
@@ -133,7 +147,11 @@ describe("listOperations", () => {
133
147
  type: "Payment",
134
148
  value: expectedValue,
135
149
  fee: BigInt(10),
136
- blockHeight: 1,
150
+ block: {
151
+ hash: "HASH_VALUE_BLOCK",
152
+ height: 1,
153
+ time: new Date("2000-01-01T00:00:01Z"),
154
+ },
137
155
  senders: [opSender],
138
156
  recipients: [opDestination],
139
157
  date: new Date(1000000 + RIPPLE_EPOCH * 1000),
package/src/api/index.ts CHANGED
@@ -45,11 +45,18 @@ async function operations(
45
45
  address: string,
46
46
  { limit, start }: Pagination,
47
47
  ): Promise<[Operation[], number]> {
48
- const [ops, index] = await listOperations(address, { limit, mostRecentIndex: start });
48
+ const [ops, index] = await listOperations(address, { limit, startAt: start ?? 0 });
49
49
  return [
50
50
  ops.map(op => {
51
- const { simpleType, ...rest } = op;
52
- return { ...rest } satisfies Operation;
51
+ const { simpleType, blockHash, blockTime, blockHeight, ...rest } = op;
52
+ return {
53
+ ...rest,
54
+ block: {
55
+ height: blockHeight,
56
+ hash: blockHash,
57
+ time: blockTime,
58
+ },
59
+ } satisfies Operation;
53
60
  }),
54
61
  index,
55
62
  ];
@@ -78,12 +78,13 @@ describe("getAccountShape", () => {
78
78
  });
79
79
  mockGetTransactions.mockResolvedValue([
80
80
  {
81
+ ledger_hash: "HASH_VALUE_BLOCK",
82
+ hash: "HASH_VALUE",
81
83
  meta: { delivered_amount: "100" },
82
- tx: {
84
+ tx_json: {
83
85
  TransactionType: "Payment",
84
86
  Fee: "10",
85
- hash: "HASH_VALUE",
86
- inLedger: 1,
87
+ ledger_index: 1,
87
88
  date: 1000,
88
89
  Account: "account_addr",
89
90
  Destination: "destination_addr",
@@ -117,7 +118,7 @@ describe("getAccountShape", () => {
117
118
  operations: [
118
119
  {
119
120
  accountId: "js:2:ripple:address:",
120
- blockHash: null,
121
+ blockHash: "HASH_VALUE_BLOCK",
121
122
  blockHeight: 1,
122
123
  date: new Date("2000-01-01T00:16:40.000Z"),
123
124
  hash: "HASH_VALUE",
@@ -74,7 +74,7 @@ async function filterOperations(
74
74
  type: op.simpleType,
75
75
  value: new BigNumber(op.value.toString()),
76
76
  fee: new BigNumber(op.fee.toString()),
77
- blockHash: null,
77
+ blockHash: op.blockHash,
78
78
  blockHeight: op.blockHeight,
79
79
  senders: op.senders,
80
80
  recipients: op.recipients,
@@ -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,
@@ -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),
@@ -26,9 +26,16 @@ export async function listOperations(
26
26
  const minLedgerVersion = Number(ledgers[0]);
27
27
  const maxLedgerVersion = Number(ledgers[1]);
28
28
 
29
- let options: { ledger_index_min?: number; ledger_index_max?: number; limit?: number } = {
29
+ let options: {
30
+ ledger_index_min?: number;
31
+ ledger_index_max?: number;
32
+ limit?: number;
33
+ tx_type?: string;
34
+ } = {
30
35
  ledger_index_max: mostRecentIndex ?? maxLedgerVersion,
36
+ tx_type: "Payment",
31
37
  };
38
+
32
39
  if (limit) {
33
40
  options = {
34
41
  ...options,
@@ -39,17 +46,33 @@ export async function listOperations(
39
46
  options = {
40
47
  ...options,
41
48
  // if there is no ops, it might be after a clear and we prefer to pull from the oldest possible history
42
- ledger_index_min: Math.max(startAt ?? 0, minLedgerVersion),
49
+ ledger_index_min: Math.max(startAt, minLedgerVersion),
43
50
  };
44
51
  }
45
52
 
46
- const transactions = await getTransactions(address, options);
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
+ );
47
72
 
48
73
  return [
49
- transactions
50
- .filter(op => op.tx.TransactionType === "Payment")
51
- .map(convertToCoreOperation(address)),
52
- transactions.slice(-1)[0].tx.ledger_index - 1, // Returns the next index to start from for pagination
74
+ transactions.map(convertToCoreOperation(address)),
75
+ transactions.slice(-1)[0].tx_json.ledger_index - 1, // Returns the next index to start from for pagination
53
76
  ];
54
77
  }
55
78
 
@@ -57,18 +80,20 @@ const convertToCoreOperation =
57
80
  (address: string) =>
58
81
  (operation: XrplOperation): XrpOperation => {
59
82
  const {
83
+ ledger_hash,
84
+ hash,
85
+ close_time_iso,
60
86
  meta: { delivered_amount },
61
- tx: {
87
+ tx_json: {
62
88
  TransactionType,
63
89
  Fee,
64
- hash,
65
- inLedger,
66
90
  date,
67
91
  Account,
68
92
  Destination,
69
93
  DestinationTag,
70
94
  Sequence,
71
95
  Memos,
96
+ ledger_index,
72
97
  },
73
98
  } = operation;
74
99
 
@@ -112,13 +137,15 @@ const convertToCoreOperation =
112
137
  }
113
138
 
114
139
  let op: XrpOperation = {
140
+ blockTime: new Date(close_time_iso),
141
+ blockHash: ledger_hash,
115
142
  hash,
116
143
  address,
117
144
  type: TransactionType,
118
145
  simpleType: type,
119
146
  value,
120
147
  fee,
121
- blockHeight: inLedger,
148
+ blockHeight: ledger_index,
122
149
  senders: [Account],
123
150
  recipients: [Destination],
124
151
  date: new Date(toEpochDate),
@@ -72,8 +72,8 @@ export const getTransactions = async (
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;