@ledgerhq/coin-xrp 0.8.0-nightly.7 → 0.8.1-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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +40 -38
- package/lib/api/index.js +4 -1
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/synchronization.js +1 -1
- package/lib/bridge/synchronization.js.map +1 -1
- package/lib/logic/listOperations.d.ts +3 -3
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +39 -25
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +82 -3
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js +6 -3
- package/lib/network/index.js.map +1 -1
- package/lib-es/api/index.js +4 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/synchronization.js +1 -1
- package/lib-es/bridge/synchronization.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts +3 -3
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +39 -25
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +82 -3
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js +6 -3
- package/lib-es/network/index.js.map +1 -1
- package/package.json +7 -6
- package/src/api/index.ts +6 -1
- package/src/bridge/synchronization.ts +1 -1
- package/src/logic/listOperations.test.ts +94 -3
- package/src/logic/listOperations.ts +51 -32
- package/src/network/index.ts +4 -2
|
@@ -16,44 +16,58 @@ import { RIPPLE_EPOCH } from "./utils";
|
|
|
16
16
|
* @returns
|
|
17
17
|
*/
|
|
18
18
|
export function listOperations(address_1, _a) {
|
|
19
|
-
return __awaiter(this, arguments, void 0, function* (address, { limit,
|
|
19
|
+
return __awaiter(this, arguments, void 0, function* (address, { limit, maxHeight, minHeight, }) {
|
|
20
20
|
const serverInfo = yield getServerInfos();
|
|
21
21
|
const ledgers = serverInfo.info.complete_ledgers.split("-");
|
|
22
22
|
const minLedgerVersion = Number(ledgers[0]);
|
|
23
23
|
const maxLedgerVersion = Number(ledgers[1]);
|
|
24
24
|
let options = {
|
|
25
|
-
ledger_index_max:
|
|
25
|
+
ledger_index_max: maxHeight !== null && maxHeight !== void 0 ? maxHeight : maxLedgerVersion,
|
|
26
26
|
tx_type: "Payment",
|
|
27
27
|
};
|
|
28
28
|
if (limit) {
|
|
29
29
|
options = Object.assign(Object.assign({}, options), { limit });
|
|
30
30
|
}
|
|
31
|
-
if (
|
|
31
|
+
if (minHeight) {
|
|
32
32
|
options = Object.assign(Object.assign({}, options), {
|
|
33
33
|
// if there is no ops, it might be after a clear and we prefer to pull from the oldest possible history
|
|
34
|
-
ledger_index_min: Math.max(
|
|
34
|
+
ledger_index_min: Math.max(minHeight, minLedgerVersion) });
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
];
|
|
36
|
+
function getPaymentTransactions(address, options) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const txs = yield getTransactions(address, options);
|
|
39
|
+
// Filter out the transactions that are not "Payment" type because the filter on "tx_type" of the node RPC is not working as expected.
|
|
40
|
+
const paymentTxs = txs.filter(tx => tx.tx_json.TransactionType === "Payment");
|
|
41
|
+
const shortage = (options.limit && txs.length < options.limit) || false;
|
|
42
|
+
const lastTransaction = txs.slice(-1)[0];
|
|
43
|
+
const nextOptions = Object.assign({}, options);
|
|
44
|
+
if (lastTransaction) {
|
|
45
|
+
nextOptions.ledger_index_max = lastTransaction.tx_json.ledger_index - 1;
|
|
46
|
+
if (nextOptions.limit)
|
|
47
|
+
nextOptions.limit -= paymentTxs.length;
|
|
48
|
+
}
|
|
49
|
+
return [shortage, nextOptions, paymentTxs];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
// TODO BUG: given the number of txs belonging to the SAME block > limit
|
|
53
|
+
// when user loop over pages using the provided token
|
|
54
|
+
// then user misses some txs that doesn't fit the page size limit
|
|
55
|
+
// because the "next token" is a block height (solution is to use an opaque token instead)
|
|
56
|
+
let [txShortage, nextOptions, transactions] = yield getPaymentTransactions(address, options);
|
|
57
|
+
const isEnough = () => txShortage || (limit && transactions.length >= limit);
|
|
58
|
+
// We need to call the node RPC multiple times to get the desired number of transactions by the limiter.
|
|
59
|
+
while (nextOptions.limit && !isEnough()) {
|
|
60
|
+
const [newTxShortage, newNextOptions, newTransactions] = yield getPaymentTransactions(address, nextOptions);
|
|
61
|
+
txShortage = newTxShortage;
|
|
62
|
+
nextOptions = newNextOptions;
|
|
63
|
+
transactions = transactions.concat(newTransactions);
|
|
64
|
+
}
|
|
65
|
+
const lastTransaction = transactions.slice(-1)[0];
|
|
66
|
+
// the next index to start the pagination from
|
|
67
|
+
const nextIndex = lastTransaction
|
|
68
|
+
? Math.max(lastTransaction.tx_json.ledger_index - 1, minLedgerVersion)
|
|
69
|
+
: minLedgerVersion;
|
|
70
|
+
return [transactions.map(convertToCoreOperation(address)), nextIndex];
|
|
57
71
|
});
|
|
58
72
|
}
|
|
59
73
|
const convertToCoreOperation = (address) => (operation) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/logic/listOperations.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;GAKG;AACH,MA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AAC,MAAM,IAAI,CAAC,EAAE,CAAC;QACrC,EAAE,mCACG,EAAE,KACL,OAAO,GACR,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC"}
|
|
@@ -7,11 +7,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { assert } from "console";
|
|
10
11
|
import { listOperations } from "./listOperations";
|
|
11
12
|
import { RIPPLE_EPOCH } from "./utils";
|
|
13
|
+
const maxHeight = 2;
|
|
14
|
+
const minHeight = 1;
|
|
12
15
|
const mockGetServerInfos = jest.fn().mockResolvedValue({
|
|
13
16
|
info: {
|
|
14
|
-
complete_ledgers:
|
|
17
|
+
complete_ledgers: `${minHeight}-${maxHeight}`,
|
|
15
18
|
},
|
|
16
19
|
});
|
|
17
20
|
const mockGetTransactions = jest.fn();
|
|
@@ -24,6 +27,82 @@ describe("listOperations", () => {
|
|
|
24
27
|
mockGetServerInfos.mockClear();
|
|
25
28
|
mockGetTransactions.mockClear();
|
|
26
29
|
});
|
|
30
|
+
it("when there are no transactions then the result is empty", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
// Given
|
|
32
|
+
mockGetTransactions.mockResolvedValue([]);
|
|
33
|
+
// When
|
|
34
|
+
const [results, token] = yield listOperations("any address", { minHeight: 0 });
|
|
35
|
+
// Then
|
|
36
|
+
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
37
|
+
expect(mockGetTransactions).toHaveBeenCalledTimes(1);
|
|
38
|
+
expect(results).toEqual([]);
|
|
39
|
+
expect(token).toEqual(minHeight);
|
|
40
|
+
}));
|
|
41
|
+
it("when there are no transactions and a limit then the result is empty", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
// Given
|
|
43
|
+
mockGetTransactions.mockResolvedValue([]);
|
|
44
|
+
// When
|
|
45
|
+
const [results, token] = yield listOperations("any address", { minHeight: 0, limit: 1 });
|
|
46
|
+
// Then
|
|
47
|
+
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
48
|
+
expect(mockGetTransactions).toHaveBeenCalledTimes(1);
|
|
49
|
+
expect(results).toEqual([]);
|
|
50
|
+
expect(token).toEqual(minHeight);
|
|
51
|
+
}));
|
|
52
|
+
const paymentTx = {
|
|
53
|
+
ledger_hash: "HASH_VALUE_BLOCK",
|
|
54
|
+
hash: "HASH_VALUE",
|
|
55
|
+
close_time_iso: "2000-01-01T00:00:01Z",
|
|
56
|
+
meta: { delivered_amount: "100" },
|
|
57
|
+
tx_json: {
|
|
58
|
+
TransactionType: "Payment",
|
|
59
|
+
Fee: "1",
|
|
60
|
+
ledger_index: 2,
|
|
61
|
+
date: 1000,
|
|
62
|
+
Account: "sender",
|
|
63
|
+
Destination: "dest",
|
|
64
|
+
Sequence: 1,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
const otherTx = Object.assign(Object.assign({}, paymentTx), { tx_json: Object.assign(Object.assign({}, paymentTx.tx_json), { TransactionType: "Other" }) });
|
|
68
|
+
it("should only list operations of type payment", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
// Given
|
|
70
|
+
const lastTransaction = paymentTx;
|
|
71
|
+
mockGetTransactions.mockResolvedValueOnce([paymentTx, otherTx, lastTransaction]);
|
|
72
|
+
mockGetTransactions.mockResolvedValue([]); // subsequent calls
|
|
73
|
+
// When
|
|
74
|
+
const [results, token] = yield listOperations("any address", { minHeight: 0, limit: 3 });
|
|
75
|
+
// Then
|
|
76
|
+
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
77
|
+
// it's called twice because first call yields only 2 transactions, and 3 are asked
|
|
78
|
+
expect(mockGetTransactions).toHaveBeenCalledTimes(2);
|
|
79
|
+
expect(results.length).toEqual(2);
|
|
80
|
+
expect(token).toEqual(lastTransaction.tx_json.ledger_index - 1);
|
|
81
|
+
}));
|
|
82
|
+
it("should make enough calls so that the limit requested is satified", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const lastTransaction = otherTx;
|
|
84
|
+
const txs = [paymentTx, paymentTx, otherTx, otherTx, otherTx, otherTx, otherTx, otherTx];
|
|
85
|
+
assert(txs.length === 8);
|
|
86
|
+
mockGetTransactions.mockResolvedValue(txs);
|
|
87
|
+
const [results, token] = yield listOperations("any address", { minHeight: 0, limit: 8 });
|
|
88
|
+
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
89
|
+
// it's called 4 times because each call yields only 2 transactions, and 8 are asked
|
|
90
|
+
expect(mockGetTransactions).toHaveBeenCalledTimes(4);
|
|
91
|
+
expect(results.length).toEqual(8);
|
|
92
|
+
expect(token).toEqual(lastTransaction.tx_json.ledger_index - 1);
|
|
93
|
+
}));
|
|
94
|
+
it("should make enough calls, even if there is not enough txs to satisfy the limit", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
mockGetTransactions.mockResolvedValueOnce([otherTx, otherTx, otherTx, otherTx]);
|
|
96
|
+
mockGetTransactions.mockResolvedValueOnce([paymentTx, paymentTx]);
|
|
97
|
+
mockGetTransactions.mockResolvedValue([]); // subsequent calls
|
|
98
|
+
const lastTransaction = paymentTx;
|
|
99
|
+
const [results, token] = yield listOperations("any address", { minHeight: 0, limit: 4 });
|
|
100
|
+
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
101
|
+
// it's called 2 times because the second call is a shortage of txs
|
|
102
|
+
expect(mockGetTransactions).toHaveBeenCalledTimes(2);
|
|
103
|
+
expect(results.length).toEqual(2);
|
|
104
|
+
expect(token).toEqual(lastTransaction.tx_json.ledger_index - 1);
|
|
105
|
+
}));
|
|
27
106
|
it.each([
|
|
28
107
|
{
|
|
29
108
|
address: "WHATEVER_ADDRESS",
|
|
@@ -38,7 +117,7 @@ describe("listOperations", () => {
|
|
|
38
117
|
expectedType: "OUT",
|
|
39
118
|
},
|
|
40
119
|
])("should return the list of operations associated to an account", (_a) => __awaiter(void 0, [_a], void 0, function* ({ address, opSender, opDestination, expectedType }) {
|
|
41
|
-
//
|
|
120
|
+
// Given
|
|
42
121
|
const deliveredAmount = 100;
|
|
43
122
|
const fee = 10;
|
|
44
123
|
mockGetTransactions.mockResolvedValue([
|
|
@@ -98,7 +177,7 @@ describe("listOperations", () => {
|
|
|
98
177
|
},
|
|
99
178
|
]);
|
|
100
179
|
// When
|
|
101
|
-
const [results, _] = yield listOperations(address, {
|
|
180
|
+
const [results, _] = yield listOperations(address, { minHeight: 0 });
|
|
102
181
|
// Then
|
|
103
182
|
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
104
183
|
expect(mockGetTransactions).toHaveBeenCalledTimes(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listOperations.test.js","sourceRoot":"","sources":["../../src/logic/listOperations.test.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;IACrD,IAAI,EAAE;QACJ,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"listOperations.test.js","sourceRoot":"","sources":["../../src/logic/listOperations.test.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;IACrD,IAAI,EAAE;QACJ,gBAAgB,EAAE,GAAG,SAA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a,EAAE,CAUzB,CAAC;AAEF,wBAAsB,SAAS,IAAI,OAAO,CAAC,cAAc,CAAC,CAEzD;AAED,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAItD"}
|
package/lib-es/network/index.js
CHANGED
|
@@ -53,7 +53,10 @@ export const getServerInfos = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
53
53
|
return rpcCall("server_info", { ledger_index: "validated" });
|
|
54
54
|
});
|
|
55
55
|
export const getTransactions = (address, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
-
const result = yield rpcCall("account_tx", Object.assign(Object.assign({ account: address
|
|
56
|
+
const result = yield rpcCall("account_tx", Object.assign(Object.assign({ account: address,
|
|
57
|
+
// newest first
|
|
58
|
+
// note that order within the results is not guaranteed (see documentation of account_tx)
|
|
59
|
+
forward: false }, options), { api_version: 2 }));
|
|
57
60
|
return result.transactions;
|
|
58
61
|
});
|
|
59
62
|
export function getLedger() {
|
|
@@ -67,8 +70,8 @@ export function getLedgerIndex() {
|
|
|
67
70
|
return result.ledger_index;
|
|
68
71
|
});
|
|
69
72
|
}
|
|
70
|
-
function rpcCall(
|
|
71
|
-
return __awaiter(this,
|
|
73
|
+
function rpcCall(method_1) {
|
|
74
|
+
return __awaiter(this, arguments, void 0, function* (method, params = {}) {
|
|
72
75
|
const { data: { result }, } = yield network({
|
|
73
76
|
method: "POST",
|
|
74
77
|
url: getNodeUrl(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAC7C,OAAO,UAAU,MAAM,WAAW,CAAC;AAEnC,OAAO,EACL,eAAe,EACf,gBAAgB,GAQjB,MAAM,SAAS,CAAC;AAEjB,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC;AAEzD,MAAM,CA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AM,CAAC,YAAY,CAAC;IAC7B,CAAC;CAAA;AAED,SAAe,OAAO;yDACpB,MAAc,EACd,SAAoD,EAAE;QAEtD,MAAM,EACJ,IAAI,EAAE,EAAE,MAAM,EAAE,GACjB,GAAG,MAAM,OAAO,CAAgB;YAC/B,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,UAAU,EAAE;YACjB,IAAI,EAAE;gBACJ,MAAM;gBACN,MAAM,EAAE;sCAED,MAAM;iBAEZ;aACF;SACF,CAAC,CAAC;QAEH,IAAI,gBAAgB,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC5D,MAAM,IAAI,KAAK,CAAC,kBAAkB,MAAM,gBAAgB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACpF,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-xrp",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1-next.0",
|
|
4
4
|
"description": "Ledger XRP Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -104,12 +104,12 @@
|
|
|
104
104
|
"ripple-address-codec": "^5.0.0",
|
|
105
105
|
"ripple-binary-codec": "^1.3.0",
|
|
106
106
|
"rxjs": "^7.8.1",
|
|
107
|
-
"@ledgerhq/coin-framework": "^0.
|
|
108
|
-
"@ledgerhq/cryptoassets": "^13.
|
|
107
|
+
"@ledgerhq/coin-framework": "^0.22.0-next.0",
|
|
108
|
+
"@ledgerhq/cryptoassets": "^13.9.0-next.0",
|
|
109
109
|
"@ledgerhq/devices": "8.4.4",
|
|
110
110
|
"@ledgerhq/errors": "^6.19.1",
|
|
111
|
-
"@ledgerhq/live-network": "^2.0.
|
|
112
|
-
"@ledgerhq/types-live": "^6.
|
|
111
|
+
"@ledgerhq/live-network": "^2.0.4-next.0",
|
|
112
|
+
"@ledgerhq/types-live": "^6.57.0-next.0"
|
|
113
113
|
},
|
|
114
114
|
"devDependencies": {
|
|
115
115
|
"@faker-js/faker": "^8.4.1",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"ripple-keypairs": "^2.0.0",
|
|
122
122
|
"ts-jest": "^29.1.1",
|
|
123
123
|
"typescript": "^5.4.5",
|
|
124
|
-
"@ledgerhq/types-cryptoassets": "^7.
|
|
124
|
+
"@ledgerhq/types-cryptoassets": "^7.19.0-next.0"
|
|
125
125
|
},
|
|
126
126
|
"scripts": {
|
|
127
127
|
"clean": "rimraf lib lib-es",
|
|
@@ -134,6 +134,7 @@
|
|
|
134
134
|
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
135
135
|
"lint:fix": "pnpm lint --fix",
|
|
136
136
|
"test": "jest",
|
|
137
|
+
"test-watch": "jest --watch",
|
|
137
138
|
"test-integ": "DOTENV_CONFIG_PATH=.env.integ.test jest --config=jest.integ.config.js",
|
|
138
139
|
"typecheck": "tsc --noEmit",
|
|
139
140
|
"unimported": "unimported"
|
package/src/api/index.ts
CHANGED
|
@@ -45,7 +45,12 @@ async function operations(
|
|
|
45
45
|
address: string,
|
|
46
46
|
{ limit, start }: Pagination,
|
|
47
47
|
): Promise<[Operation[], number]> {
|
|
48
|
-
const
|
|
48
|
+
const options: {
|
|
49
|
+
limit?: number;
|
|
50
|
+
minHeight?: number;
|
|
51
|
+
} = { limit: limit };
|
|
52
|
+
if (start) options.minHeight = start;
|
|
53
|
+
const [ops, index] = await listOperations(address, options);
|
|
49
54
|
return [
|
|
50
55
|
ops.map(op => {
|
|
51
56
|
const { simpleType, blockHash, blockTime, blockHeight, ...rest } = op;
|
|
@@ -63,7 +63,7 @@ async function filterOperations(
|
|
|
63
63
|
address: string,
|
|
64
64
|
blockHeight: number,
|
|
65
65
|
): Promise<Operation[]> {
|
|
66
|
-
const [operations, _] = await listOperations(address, {
|
|
66
|
+
const [operations, _] = await listOperations(address, { minHeight: blockHeight });
|
|
67
67
|
|
|
68
68
|
return operations.map(
|
|
69
69
|
op =>
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { assert } from "console";
|
|
1
2
|
import { listOperations } from "./listOperations";
|
|
2
3
|
import { RIPPLE_EPOCH } from "./utils";
|
|
3
4
|
|
|
5
|
+
const maxHeight = 2;
|
|
6
|
+
const minHeight = 1;
|
|
4
7
|
const mockGetServerInfos = jest.fn().mockResolvedValue({
|
|
5
8
|
info: {
|
|
6
|
-
complete_ledgers:
|
|
9
|
+
complete_ledgers: `${minHeight}-${maxHeight}`,
|
|
7
10
|
},
|
|
8
11
|
});
|
|
9
12
|
const mockGetTransactions = jest.fn();
|
|
@@ -18,6 +21,94 @@ describe("listOperations", () => {
|
|
|
18
21
|
mockGetTransactions.mockClear();
|
|
19
22
|
});
|
|
20
23
|
|
|
24
|
+
it("when there are no transactions then the result is empty", async () => {
|
|
25
|
+
// Given
|
|
26
|
+
mockGetTransactions.mockResolvedValue([]);
|
|
27
|
+
// When
|
|
28
|
+
const [results, token] = await listOperations("any address", { minHeight: 0 });
|
|
29
|
+
// Then
|
|
30
|
+
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
31
|
+
expect(mockGetTransactions).toHaveBeenCalledTimes(1);
|
|
32
|
+
expect(results).toEqual([]);
|
|
33
|
+
expect(token).toEqual(minHeight);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("when there are no transactions and a limit then the result is empty", async () => {
|
|
37
|
+
// Given
|
|
38
|
+
mockGetTransactions.mockResolvedValue([]);
|
|
39
|
+
// When
|
|
40
|
+
const [results, token] = await listOperations("any address", { minHeight: 0, limit: 1 });
|
|
41
|
+
// Then
|
|
42
|
+
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
43
|
+
expect(mockGetTransactions).toHaveBeenCalledTimes(1);
|
|
44
|
+
expect(results).toEqual([]);
|
|
45
|
+
expect(token).toEqual(minHeight);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const paymentTx = {
|
|
49
|
+
ledger_hash: "HASH_VALUE_BLOCK",
|
|
50
|
+
hash: "HASH_VALUE",
|
|
51
|
+
close_time_iso: "2000-01-01T00:00:01Z",
|
|
52
|
+
meta: { delivered_amount: "100" },
|
|
53
|
+
tx_json: {
|
|
54
|
+
TransactionType: "Payment",
|
|
55
|
+
Fee: "1",
|
|
56
|
+
ledger_index: 2,
|
|
57
|
+
date: 1000,
|
|
58
|
+
Account: "sender",
|
|
59
|
+
Destination: "dest",
|
|
60
|
+
Sequence: 1,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
const otherTx = { ...paymentTx, tx_json: { ...paymentTx.tx_json, TransactionType: "Other" } };
|
|
64
|
+
|
|
65
|
+
it("should only list operations of type payment", async () => {
|
|
66
|
+
// Given
|
|
67
|
+
const lastTransaction = paymentTx;
|
|
68
|
+
mockGetTransactions.mockResolvedValueOnce([paymentTx, otherTx, lastTransaction]);
|
|
69
|
+
mockGetTransactions.mockResolvedValue([]); // subsequent calls
|
|
70
|
+
|
|
71
|
+
// When
|
|
72
|
+
const [results, token] = await listOperations("any address", { minHeight: 0, limit: 3 });
|
|
73
|
+
|
|
74
|
+
// Then
|
|
75
|
+
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
76
|
+
// it's called twice because first call yields only 2 transactions, and 3 are asked
|
|
77
|
+
expect(mockGetTransactions).toHaveBeenCalledTimes(2);
|
|
78
|
+
expect(results.length).toEqual(2);
|
|
79
|
+
expect(token).toEqual(lastTransaction.tx_json.ledger_index - 1);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should make enough calls so that the limit requested is satified", async () => {
|
|
83
|
+
const lastTransaction = otherTx;
|
|
84
|
+
const txs = [paymentTx, paymentTx, otherTx, otherTx, otherTx, otherTx, otherTx, otherTx];
|
|
85
|
+
assert(txs.length === 8);
|
|
86
|
+
mockGetTransactions.mockResolvedValue(txs);
|
|
87
|
+
|
|
88
|
+
const [results, token] = await listOperations("any address", { minHeight: 0, limit: 8 });
|
|
89
|
+
|
|
90
|
+
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
91
|
+
// it's called 4 times because each call yields only 2 transactions, and 8 are asked
|
|
92
|
+
expect(mockGetTransactions).toHaveBeenCalledTimes(4);
|
|
93
|
+
expect(results.length).toEqual(8);
|
|
94
|
+
expect(token).toEqual(lastTransaction.tx_json.ledger_index - 1);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should make enough calls, even if there is not enough txs to satisfy the limit", async () => {
|
|
98
|
+
mockGetTransactions.mockResolvedValueOnce([otherTx, otherTx, otherTx, otherTx]);
|
|
99
|
+
mockGetTransactions.mockResolvedValueOnce([paymentTx, paymentTx]);
|
|
100
|
+
mockGetTransactions.mockResolvedValue([]); // subsequent calls
|
|
101
|
+
const lastTransaction = paymentTx;
|
|
102
|
+
|
|
103
|
+
const [results, token] = await listOperations("any address", { minHeight: 0, limit: 4 });
|
|
104
|
+
|
|
105
|
+
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
106
|
+
// it's called 2 times because the second call is a shortage of txs
|
|
107
|
+
expect(mockGetTransactions).toHaveBeenCalledTimes(2);
|
|
108
|
+
expect(results.length).toEqual(2);
|
|
109
|
+
expect(token).toEqual(lastTransaction.tx_json.ledger_index - 1);
|
|
110
|
+
});
|
|
111
|
+
|
|
21
112
|
it.each([
|
|
22
113
|
{
|
|
23
114
|
address: "WHATEVER_ADDRESS",
|
|
@@ -34,7 +125,7 @@ describe("listOperations", () => {
|
|
|
34
125
|
])(
|
|
35
126
|
"should return the list of operations associated to an account",
|
|
36
127
|
async ({ address, opSender, opDestination, expectedType }) => {
|
|
37
|
-
//
|
|
128
|
+
// Given
|
|
38
129
|
const deliveredAmount = 100;
|
|
39
130
|
const fee = 10;
|
|
40
131
|
mockGetTransactions.mockResolvedValue([
|
|
@@ -95,7 +186,7 @@ describe("listOperations", () => {
|
|
|
95
186
|
]);
|
|
96
187
|
|
|
97
188
|
// When
|
|
98
|
-
const [results, _] = await listOperations(address, {
|
|
189
|
+
const [results, _] = await listOperations(address, { minHeight: 0 });
|
|
99
190
|
|
|
100
191
|
// Then
|
|
101
192
|
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
@@ -13,12 +13,12 @@ export async function listOperations(
|
|
|
13
13
|
address: string,
|
|
14
14
|
{
|
|
15
15
|
limit,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
maxHeight,
|
|
17
|
+
minHeight,
|
|
18
18
|
}: {
|
|
19
19
|
limit?: number;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
maxHeight?: number | undefined; // used for pagination
|
|
21
|
+
minHeight?: number; // used to retrieve operations from a specific block height until top most
|
|
22
22
|
},
|
|
23
23
|
): Promise<[XrpOperation[], number]> {
|
|
24
24
|
const serverInfo = await getServerInfos();
|
|
@@ -26,13 +26,15 @@ export async function listOperations(
|
|
|
26
26
|
const minLedgerVersion = Number(ledgers[0]);
|
|
27
27
|
const maxLedgerVersion = Number(ledgers[1]);
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
type Options = {
|
|
30
30
|
ledger_index_min?: number;
|
|
31
31
|
ledger_index_max?: number;
|
|
32
32
|
limit?: number;
|
|
33
33
|
tx_type?: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
let options: Options = {
|
|
37
|
+
ledger_index_max: maxHeight ?? maxLedgerVersion,
|
|
36
38
|
tx_type: "Payment",
|
|
37
39
|
};
|
|
38
40
|
|
|
@@ -42,38 +44,55 @@ export async function listOperations(
|
|
|
42
44
|
limit,
|
|
43
45
|
};
|
|
44
46
|
}
|
|
45
|
-
if (
|
|
47
|
+
if (minHeight) {
|
|
46
48
|
options = {
|
|
47
49
|
...options,
|
|
48
50
|
// 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(
|
|
51
|
+
ledger_index_min: Math.max(minHeight, minLedgerVersion),
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
async function getPaymentTransactions(
|
|
56
|
+
address: string,
|
|
57
|
+
options: Options,
|
|
58
|
+
): Promise<[boolean, Options, XrplOperation[]]> {
|
|
59
|
+
const txs = await getTransactions(address, options);
|
|
60
|
+
// Filter out the transactions that are not "Payment" type because the filter on "tx_type" of the node RPC is not working as expected.
|
|
61
|
+
const paymentTxs = txs.filter(tx => tx.tx_json.TransactionType === "Payment");
|
|
62
|
+
const shortage = (options.limit && txs.length < options.limit) || false;
|
|
63
|
+
const lastTransaction = txs.slice(-1)[0];
|
|
64
|
+
const nextOptions = { ...options };
|
|
65
|
+
if (lastTransaction) {
|
|
66
|
+
nextOptions.ledger_index_max = lastTransaction.tx_json.ledger_index - 1;
|
|
67
|
+
if (nextOptions.limit) nextOptions.limit -= paymentTxs.length;
|
|
64
68
|
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
return [shortage, nextOptions, paymentTxs];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// TODO BUG: given the number of txs belonging to the SAME block > limit
|
|
73
|
+
// when user loop over pages using the provided token
|
|
74
|
+
// then user misses some txs that doesn't fit the page size limit
|
|
75
|
+
// because the "next token" is a block height (solution is to use an opaque token instead)
|
|
76
|
+
let [txShortage, nextOptions, transactions] = await getPaymentTransactions(address, options);
|
|
77
|
+
const isEnough = () => txShortage || (limit && transactions.length >= limit);
|
|
78
|
+
// We need to call the node RPC multiple times to get the desired number of transactions by the limiter.
|
|
79
|
+
while (nextOptions.limit && !isEnough()) {
|
|
80
|
+
const [newTxShortage, newNextOptions, newTransactions] = await getPaymentTransactions(
|
|
81
|
+
address,
|
|
82
|
+
nextOptions,
|
|
83
|
+
);
|
|
84
|
+
txShortage = newTxShortage;
|
|
85
|
+
nextOptions = newNextOptions;
|
|
86
|
+
transactions = transactions.concat(newTransactions);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const lastTransaction = transactions.slice(-1)[0];
|
|
90
|
+
// the next index to start the pagination from
|
|
91
|
+
const nextIndex = lastTransaction
|
|
92
|
+
? Math.max(lastTransaction.tx_json.ledger_index - 1, minLedgerVersion)
|
|
93
|
+
: minLedgerVersion;
|
|
94
|
+
|
|
95
|
+
return [transactions.map(convertToCoreOperation(address)), nextIndex];
|
|
77
96
|
}
|
|
78
97
|
|
|
79
98
|
const convertToCoreOperation =
|
package/src/network/index.ts
CHANGED
|
@@ -72,10 +72,12 @@ export const getTransactions = async (
|
|
|
72
72
|
): Promise<XrplOperation[]> => {
|
|
73
73
|
const result = await rpcCall<AccountTxResponse>("account_tx", {
|
|
74
74
|
account: address,
|
|
75
|
+
// newest first
|
|
76
|
+
// note that order within the results is not guaranteed (see documentation of account_tx)
|
|
77
|
+
forward: false,
|
|
75
78
|
...options,
|
|
76
79
|
api_version: 2,
|
|
77
80
|
});
|
|
78
|
-
|
|
79
81
|
return result.transactions;
|
|
80
82
|
};
|
|
81
83
|
|
|
@@ -91,7 +93,7 @@ export async function getLedgerIndex(): Promise<number> {
|
|
|
91
93
|
|
|
92
94
|
async function rpcCall<T extends object>(
|
|
93
95
|
method: string,
|
|
94
|
-
params: Record<string, string | number
|
|
96
|
+
params: Record<string, string | number | boolean> = {},
|
|
95
97
|
): Promise<T> {
|
|
96
98
|
const {
|
|
97
99
|
data: { result },
|