@ledgerhq/coin-xrp 3.1.0 → 3.2.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 +16 -0
- package/jest.config.js +1 -0
- package/lib/api/index.integ.test.js +69 -37
- package/lib/api/index.integ.test.js.map +1 -1
- package/lib/api/index.js +7 -3
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +60 -4
- package/lib/api/index.test.js.map +1 -1
- package/lib/logic/estimateFees.js +1 -1
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib-es/api/index.integ.test.js +69 -37
- package/lib-es/api/index.integ.test.js.map +1 -1
- package/lib-es/api/index.js +7 -3
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +37 -4
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/logic/estimateFees.js +1 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/package.json +7 -5
- package/src/api/index.integ.test.ts +59 -27
- package/src/api/index.test.ts +53 -6
- package/src/api/index.ts +10 -3
- package/src/logic/estimateFees.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @ledgerhq/coin-xrp
|
|
2
2
|
|
|
3
|
+
## 3.2.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#9666](https://github.com/LedgerHQ/ledger-live/pull/9666) [`8ce7b0a`](https://github.com/LedgerHQ/ledger-live/commit/8ce7b0ab2d1d73ef071102f795e7c868c676b1f4) Thanks [@Moustafa-Koterba](https://github.com/Moustafa-Koterba)! - update the following modules for an optional fees parameter on craft transaction functions: coin-stellar, coin-tezos, coin-tron, coin-xrp, coin-framework
|
|
8
|
+
|
|
9
|
+
- [#9648](https://github.com/LedgerHQ/ledger-live/pull/9648) [`f1732a7`](https://github.com/LedgerHQ/ledger-live/commit/f1732a795e54f666b67e7686d59926037412caca) Thanks [@sprohaszka-ledger](https://github.com/sprohaszka-ledger)! - Remove SubAccount as it is an alias to TokenAccount
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`44ae74c`](https://github.com/LedgerHQ/ledger-live/commit/44ae74c272ba803bed7c9f4fc3351e3ce8a15531), [`71bb6a9`](https://github.com/LedgerHQ/ledger-live/commit/71bb6a9adb4ac83172be5def5b25d2836380df1d), [`8ce7b0a`](https://github.com/LedgerHQ/ledger-live/commit/8ce7b0ab2d1d73ef071102f795e7c868c676b1f4), [`46a9620`](https://github.com/LedgerHQ/ledger-live/commit/46a9620b4ea6343efc28792d3b57bf84ee2a23e8), [`1e7d454`](https://github.com/LedgerHQ/ledger-live/commit/1e7d454d99f1f39880f39a120c59020725d26475), [`f1732a7`](https://github.com/LedgerHQ/ledger-live/commit/f1732a795e54f666b67e7686d59926037412caca), [`d694069`](https://github.com/LedgerHQ/ledger-live/commit/d6940698a49b7a0ed48f84d6e8184d80760cca4f)]:
|
|
14
|
+
- @ledgerhq/coin-framework@2.6.0-next.0
|
|
15
|
+
- @ledgerhq/types-live@6.66.0-next.0
|
|
16
|
+
- @ledgerhq/cryptoassets@13.14.1-next.0
|
|
17
|
+
- @ledgerhq/live-network@2.0.7-next.0
|
|
18
|
+
|
|
3
19
|
## 3.1.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/jest.config.js
CHANGED
|
@@ -14,6 +14,7 @@ module.exports = {
|
|
|
14
14
|
coverageReporters: ["json", ["lcov", { file: "xrp-lcov.info", projectRoot: "../" }], "text"],
|
|
15
15
|
workerThreads: true,
|
|
16
16
|
reporters: [
|
|
17
|
+
"default",
|
|
17
18
|
[
|
|
18
19
|
"jest-sonar",
|
|
19
20
|
{ outputName: "xrp-sonar-executionTests-report.xml", reportedFilePath: "absolute" },
|
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const _1 = require(".");
|
|
4
3
|
const ripple_binary_codec_1 = require("ripple-binary-codec");
|
|
5
|
-
const
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
//import { decode, encodeForSigning } from "ripple-binary-codec";
|
|
6
|
+
//import { sign } from "ripple-keypairs";
|
|
6
7
|
describe("Xrp Api", () => {
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const bigAddress = "rUxSkt6hQpWxXQwTNRUCYYRQ7BC2yRA3F8"; // An account with more that 4000 txs
|
|
10
|
-
const emptyAddress = "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB"; // Account with no transaction (at the time of this writing)
|
|
11
|
-
const xrpPubKey = process.env["PUB_KEY"];
|
|
12
|
-
const xrpSecretKey = process.env["SECRET_KEY"];
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
module = (0, _1.createApi)({ node: "https://s.altnet.rippletest.net:51234" });
|
|
15
|
-
});
|
|
8
|
+
const SENDER = "rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb";
|
|
9
|
+
const api = (0, _1.createApi)({ node: "https://s.altnet.rippletest.net:51234" });
|
|
16
10
|
describe("estimateFees", () => {
|
|
17
11
|
it("returns a default value", async () => {
|
|
18
12
|
// Given
|
|
19
13
|
const amount = BigInt(100);
|
|
20
14
|
// When
|
|
21
|
-
const result = await
|
|
15
|
+
const result = await api.estimateFees({
|
|
22
16
|
type: "send",
|
|
23
|
-
sender:
|
|
17
|
+
sender: SENDER,
|
|
24
18
|
amount,
|
|
25
19
|
recipient: "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB",
|
|
26
20
|
});
|
|
@@ -31,19 +25,21 @@ describe("Xrp Api", () => {
|
|
|
31
25
|
describe("listOperations", () => {
|
|
32
26
|
it.skip("returns a list regarding address parameter", async () => {
|
|
33
27
|
// When
|
|
34
|
-
const [tx, _] = await
|
|
28
|
+
const [tx, _] = await api.listOperations(SENDER, { minHeight: 200 });
|
|
35
29
|
// https://blockexplorer.one/xrp/testnet/address/rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb
|
|
36
30
|
// as of 2025-03-18, the address has 287 transactions
|
|
37
31
|
expect(tx.length).toBeGreaterThanOrEqual(287);
|
|
38
32
|
tx.forEach(operation => {
|
|
39
|
-
const isSenderOrReceipt = operation.senders.includes(
|
|
33
|
+
const isSenderOrReceipt = operation.senders.includes(SENDER) || operation.recipients.includes(SENDER);
|
|
40
34
|
expect(isSenderOrReceipt).toBeTruthy();
|
|
41
35
|
});
|
|
42
36
|
});
|
|
43
37
|
// TO FIX, ops length is 0 for some reason
|
|
44
38
|
it.skip("returns all operations", async () => {
|
|
39
|
+
// An account with more that 4000 txs
|
|
40
|
+
const SENDER_WITH_TRANSACTIONS = "rUxSkt6hQpWxXQwTNRUCYYRQ7BC2yRA3F8";
|
|
45
41
|
// When
|
|
46
|
-
const [ops, _] = await
|
|
42
|
+
const [ops, _] = await api.listOperations(SENDER_WITH_TRANSACTIONS, { minHeight: 0 });
|
|
47
43
|
// Then
|
|
48
44
|
const checkSet = new Set(ops.map(elt => elt.tx.hash));
|
|
49
45
|
expect(checkSet.size).toEqual(ops.length);
|
|
@@ -58,7 +54,7 @@ describe("Xrp Api", () => {
|
|
|
58
54
|
describe("lastBlock", () => {
|
|
59
55
|
it("returns last block info", async () => {
|
|
60
56
|
// When
|
|
61
|
-
const result = await
|
|
57
|
+
const result = await api.lastBlock();
|
|
62
58
|
// Then
|
|
63
59
|
expect(result.hash).toBeDefined();
|
|
64
60
|
expect(result.height).toBeDefined();
|
|
@@ -66,47 +62,83 @@ describe("Xrp Api", () => {
|
|
|
66
62
|
});
|
|
67
63
|
});
|
|
68
64
|
describe("getBalance", () => {
|
|
65
|
+
// Account with no transaction (at the time of this writing)
|
|
66
|
+
const SENDER_WITH_NO_TRANSACTION = "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB";
|
|
69
67
|
it("returns an amount above 0 when address has transactions", async () => {
|
|
70
68
|
// When
|
|
71
|
-
const result = await
|
|
69
|
+
const result = await api.getBalance(SENDER);
|
|
72
70
|
// Then
|
|
73
71
|
expect(result).toBeGreaterThan(BigInt(0));
|
|
74
72
|
});
|
|
75
73
|
it("returns 0 when address has no transaction", async () => {
|
|
76
74
|
// When
|
|
77
|
-
const result = await
|
|
75
|
+
const result = await api.getBalance(SENDER_WITH_NO_TRANSACTION);
|
|
78
76
|
// Then
|
|
79
77
|
expect(result).toBe(BigInt(0));
|
|
80
78
|
});
|
|
81
79
|
});
|
|
82
80
|
describe("craftTransaction", () => {
|
|
81
|
+
const RECIPIENT = "rKRtUG15iBsCQRgrkeUEg5oX4Ae2zWZ89z";
|
|
83
82
|
it("returns a raw transaction", async () => {
|
|
84
83
|
// When
|
|
85
|
-
const result = await
|
|
84
|
+
const result = await api.craftTransaction({
|
|
86
85
|
type: "send",
|
|
87
|
-
sender:
|
|
88
|
-
recipient:
|
|
86
|
+
sender: SENDER,
|
|
87
|
+
recipient: RECIPIENT,
|
|
89
88
|
amount: BigInt(10),
|
|
90
89
|
});
|
|
91
90
|
// Then
|
|
92
91
|
expect(result.length).toEqual(162);
|
|
93
92
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
SigningPubKey: xrpPubKey,
|
|
104
|
-
}), xrpSecretKey);
|
|
105
|
-
// When
|
|
106
|
-
const result = await module.combine(rawTx, signedTx);
|
|
107
|
-
// Then
|
|
108
|
-
expect(result).toEqual("120000228000000024001BCDA6201B001F018161400000000000000A68400000000000000174473045022100D3B9B37F40961A8DBDE48535F9EF333E87F9D98BE90F7141E133541874826BDB0220065E9CA4D218F16087656BC30D66672F6103B03717A59FFC04C837A2157CE47C8114CF30F590D7A9067B2604D80D46090FBF342EBE988314CA26FB6B0EF6859436C2037BA0A9913208A59B98");
|
|
93
|
+
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
94
|
+
const result = await api.craftTransaction({
|
|
95
|
+
type: "send",
|
|
96
|
+
sender: SENDER,
|
|
97
|
+
recipient: RECIPIENT,
|
|
98
|
+
amount: BigInt(10),
|
|
99
|
+
});
|
|
100
|
+
const decodedTransaction = (0, ripple_binary_codec_1.decode)(result);
|
|
101
|
+
expect(decodedTransaction.Fee).toEqual("10");
|
|
109
102
|
});
|
|
103
|
+
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
104
|
+
const customFees = 99n;
|
|
105
|
+
const result = await api.craftTransaction({
|
|
106
|
+
type: "send",
|
|
107
|
+
sender: SENDER,
|
|
108
|
+
recipient: RECIPIENT,
|
|
109
|
+
amount: BigInt(10),
|
|
110
|
+
}, customFees);
|
|
111
|
+
const decodedTransaction = (0, ripple_binary_codec_1.decode)(result);
|
|
112
|
+
expect(decodedTransaction.Fee).toEqual(customFees.toString());
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
// To enable this test, you need to fill an `.env` file at the root of this package. Example can be found in `.env.integ.test.example`.
|
|
117
|
+
// The value hardcoded here depends on the value filled in the `.env` file.
|
|
118
|
+
/*describe.skip("combine", () => {
|
|
119
|
+
//const xrpPubKey = process.env["PUB_KEY"]!;
|
|
120
|
+
//const xrpSecretKey = process.env["SECRET_KEY"]!;
|
|
121
|
+
it("returns a signed raw transaction", async () => {
|
|
122
|
+
// Given
|
|
123
|
+
const rawTx =
|
|
124
|
+
"120000228000000024001BCDA6201B001F018161400000000000000A6840000000000000018114CF30F590D7A9067B2604D80D46090FBF342EBE988314CA26FB6B0EF6859436C2037BA0A9913208A59B98";
|
|
125
|
+
const signedTx = sign(
|
|
126
|
+
encodeForSigning({
|
|
127
|
+
...decode(rawTx),
|
|
128
|
+
SigningPubKey: xrpPubKey,
|
|
129
|
+
}),
|
|
130
|
+
xrpSecretKey,
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
// When
|
|
134
|
+
const result = await module.combine(rawTx, signedTx);
|
|
135
|
+
|
|
136
|
+
// Then
|
|
137
|
+
expect(result).toEqual(
|
|
138
|
+
"120000228000000024001BCDA6201B001F018161400000000000000A68400000000000000174473045022100D3B9B37F40961A8DBDE48535F9EF333E87F9D98BE90F7141E133541874826BDB0220065E9CA4D218F16087656BC30D66672F6103B03717A59FFC04C837A2157CE47C8114CF30F590D7A9067B2604D80D46090FBF342EBE988314CA26FB6B0EF6859436C2037BA0A9913208A59B98",
|
|
139
|
+
);
|
|
110
140
|
});
|
|
141
|
+
});
|
|
111
142
|
});
|
|
143
|
+
*/
|
|
112
144
|
//# sourceMappingURL=index.integ.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.integ.test.js","sourceRoot":"","sources":["../../src/api/index.integ.test.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.integ.test.js","sourceRoot":"","sources":["../../src/api/index.integ.test.ts"],"names":[],"mappings":";;AAAA,6DAA6C;AAC7C,wBAA8B;AAC9B,iEAAiE;AACjE,yCAAyC;AAEzC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,MAAM,MAAM,GAAG,oCAAoC,CAAC;IACpD,MAAM,GAAG,GAAG,IAAA,YAAS,EAAC,EAAE,IAAI,EAAE,uCAAuC,EAAE,CAAC,CAAC;IAEzE,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;QAC5B,EAAE,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;YACvC,QAAQ;YACR,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAE3B,OAAO;YACP,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,YAAY,CAAC;gBACpC,IAAI,EAAE,MAAM;gBACZ,MAAM,EAAE,MAAM;gBACd,MAAM;gBACN,SAAS,EAAE,oCAAoC;aAChD,CAAC,CAAC;YAEH,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;Q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GAAG,CAAC,gBAAgB,CACvC;gBACE,IAAI,EAAE,MAAM;gBACZ,MAAM,EAAE,MAAM;gBACd,SAAS,EAAE,SAAS;gBACpB,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;aACnB,EACD,UAAU,CACX,CAAC;YAEF,MAAM,kBAAkB,GAAG,IAAA,4BAAM,EAAC,MAAM,CAAoB,CAAC;YAC7D,MAAM,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,uIAAuI;AACvI,2EAA2E;AAC3E;;;;;;;;;;;;;;;;;;;;;;;;;IAyBI"}
|
package/lib/api/index.js
CHANGED
|
@@ -19,10 +19,14 @@ function createApi(config) {
|
|
|
19
19
|
listOperations: operations,
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
async function craft(transactionIntent) {
|
|
22
|
+
async function craft(transactionIntent, customFees) {
|
|
23
23
|
const nextSequenceNumber = await (0, logic_1.getNextValidSequence)(transactionIntent.sender);
|
|
24
|
-
const
|
|
25
|
-
const tx = await (0, logic_1.craftTransaction)({ address: transactionIntent.sender, nextSequenceNumber }, {
|
|
24
|
+
const estimatedFees = customFees !== undefined ? customFees : (await (0, logic_1.estimateFees)()).fee;
|
|
25
|
+
const tx = await (0, logic_1.craftTransaction)({ address: transactionIntent.sender, nextSequenceNumber }, {
|
|
26
|
+
recipient: transactionIntent.recipient,
|
|
27
|
+
amount: transactionIntent.amount,
|
|
28
|
+
fee: estimatedFees,
|
|
29
|
+
});
|
|
26
30
|
return tx.serializedTransaction;
|
|
27
31
|
}
|
|
28
32
|
async function operationsFromHeight(address, minHeight) {
|
package/lib/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";;;;;A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,0CAA0C,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;YACjF,iBAAiB,GAAG,KAAK,CAAC;QAC5B,CAAC;QACD,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACzD,OAAO;YACL,GAAG,KAAK;YACR,gBAAgB,EAAE,mBAAmB;YACrC,kBAAkB,EAAE,iBAAiB;YACrC,aAAa,EAAE,aAAa;YAC5B,WAAW,EAAE,WAAW;SACzB,CAAC;IACJ,CAAC;IAED,MAAM,UAAU,GAAoB;QAClC,QAAQ,EAAE,GAAG;QACb,aAAa,EAAE,EAAE;QACjB,gBAAgB,EAAE,CAAC;QACnB,SAAS,EAAE,SAAS;QACpB,kBAAkB,EAAE,IAAI;QACxB,WAAW,EAAE,EAAE;KAChB,CAAC;IAEF,IAAI,KAAK,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC;IAC5C,OAAO,KAAK,CAAC,kBAAkB,EAAE,CAAC;QAChC,KAAK,GAAG,MAAM,aAAa,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;AACxD,CAAC;AAED,KAAK,UAAU,UAAU,CACvB,OAAe,EACf,EAAE,SAAS,EAAc;IAEzB,iFAAiF;IACjF,OAAO,MAAM,oBAAoB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACxD,CAAC"}
|
package/lib/api/index.test.js
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
26
|
+
const LogicFunctions = __importStar(require("../logic"));
|
|
4
27
|
const index_1 = require("./index");
|
|
5
28
|
const mockGetServerInfos = jest.fn().mockResolvedValue({
|
|
6
29
|
info: {
|
|
@@ -158,7 +181,7 @@ describe("listOperations", () => {
|
|
|
158
181
|
tx: {
|
|
159
182
|
hash: "HASH_VALUE",
|
|
160
183
|
fees: fee,
|
|
161
|
-
date: new Date(1000000 +
|
|
184
|
+
date: new Date(1000000 + LogicFunctions.RIPPLE_EPOCH * 1000),
|
|
162
185
|
block: {
|
|
163
186
|
hash: "HASH_VALUE_BLOCK",
|
|
164
187
|
height: 1,
|
|
@@ -185,7 +208,7 @@ describe("listOperations", () => {
|
|
|
185
208
|
tx: {
|
|
186
209
|
hash: "HASH_VALUE",
|
|
187
210
|
fees: fee,
|
|
188
|
-
date: new Date(1000000 +
|
|
211
|
+
date: new Date(1000000 + LogicFunctions.RIPPLE_EPOCH * 1000),
|
|
189
212
|
block: {
|
|
190
213
|
hash: "HASH_VALUE_BLOCK",
|
|
191
214
|
height: 1,
|
|
@@ -207,7 +230,7 @@ describe("listOperations", () => {
|
|
|
207
230
|
tx: {
|
|
208
231
|
hash: "HASH_VALUE",
|
|
209
232
|
fees: fee,
|
|
210
|
-
date: new Date(1000000 +
|
|
233
|
+
date: new Date(1000000 + LogicFunctions.RIPPLE_EPOCH * 1000),
|
|
211
234
|
block: {
|
|
212
235
|
hash: "HASH_VALUE_BLOCK",
|
|
213
236
|
height: 1,
|
|
@@ -226,4 +249,37 @@ describe("listOperations", () => {
|
|
|
226
249
|
]);
|
|
227
250
|
});
|
|
228
251
|
});
|
|
252
|
+
describe("Testing craftTransaction function", () => {
|
|
253
|
+
const DEFAULT_ESTIMATED_FEES = 100n;
|
|
254
|
+
const api = (0, index_1.createApi)({ node: "https://localhost" });
|
|
255
|
+
const logicCraftTransactionSpy = jest
|
|
256
|
+
.spyOn(LogicFunctions, "craftTransaction")
|
|
257
|
+
.mockImplementation((_address, _transaction, _publicKey) => {
|
|
258
|
+
return Promise.resolve({ xrplTransaction: {}, serializedTransaction: "" });
|
|
259
|
+
});
|
|
260
|
+
beforeAll(() => {
|
|
261
|
+
jest
|
|
262
|
+
.spyOn(LogicFunctions, "getNextValidSequence")
|
|
263
|
+
.mockImplementation(_address => Promise.resolve(0));
|
|
264
|
+
jest.spyOn(LogicFunctions, "estimateFees").mockImplementation(_networkInfo => {
|
|
265
|
+
return Promise.resolve({
|
|
266
|
+
networkInfo: {},
|
|
267
|
+
fee: DEFAULT_ESTIMATED_FEES,
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
272
|
+
const customFees = 99n;
|
|
273
|
+
await api.craftTransaction({}, customFees);
|
|
274
|
+
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(expect.any(Object), expect.objectContaining({
|
|
275
|
+
fee: customFees,
|
|
276
|
+
}));
|
|
277
|
+
});
|
|
278
|
+
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
279
|
+
await api.craftTransaction({});
|
|
280
|
+
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(expect.any(Object), expect.objectContaining({
|
|
281
|
+
fee: DEFAULT_ESTIMATED_FEES,
|
|
282
|
+
}));
|
|
283
|
+
});
|
|
284
|
+
});
|
|
229
285
|
//# sourceMappingURL=index.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/api/index.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/api/index.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,yDAA2C;AAG3C,mCAAoC;AAEpC,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;IACrD,IAAI,EAAE;QACJ,gBAAgB,EAAE,KAAK;KACxB;CACF,CAAC,CAAC;AACH,MAAM,mBAAmB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACtC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7B,cAAc,EAAE,GAAG,EAAE,CAAC,kBAAkB,EAAE;IAC1C,eAAe,EAAE,CAAC,OAAe,EAAE,OAA+B,EAAE,EAAE,CACpE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC;CACxC,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,MAAM,GAAG,GAAG,IAAA,iBAAS,EAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAC;IAErD,SAAS,CAAC,GAAG,EAAE;QACb,kBAAkB,CAAC,SAAS,EAAE,CAAC;QAC/B,mBAAmB,CAAC,SAAS,EAAE,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,EAAE,MAAM,EA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CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8EAA8E,EAAE,KAAK,IAAI,EAAE;QAC5F,MAAM,UAAU,GAAG,GAAG,CAAC;QACvB,MAAM,GAAG,CAAC,gBAAgB,CAAC,EAA6B,EAAE,UAAU,CAAC,CAAC;QAEtE,MAAM,CAAC,wBAAwB,CAAC,CAAC,oBAAoB,CACnD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAClB,MAAM,CAAC,gBAAgB,CAAC;YACtB,GAAG,EAAE,UAAU;SAChB,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oFAAoF,EAAE,KAAK,IAAI,EAAE;QAClG,MAAM,GAAG,CAAC,gBAAgB,CAAC,EAA6B,CAAC,CAAC;QAE1D,MAAM,CAAC,wBAAwB,CAAC,CAAC,oBAAoB,CACnD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAClB,MAAM,CAAC,gBAAgB,CAAC;YACtB,GAAG,EAAE,sBAAsB;SAC5B,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.estimateFees = estimateFees;
|
|
7
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
7
|
const errors_1 = require("@ledgerhq/errors");
|
|
8
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
9
|
const network_1 = require("../network");
|
|
10
10
|
const common_1 = require("./common");
|
|
11
11
|
// FIXME this could be cleaner
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateFees.js","sourceRoot":"","sources":["../../src/logic/estimateFees.ts"],"names":[],"mappings":";;;;;AAiBA,oCAqBC;AAtCD,
|
|
1
|
+
{"version":3,"file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
import { createApi } from ".";
|
|
2
|
-
import { decode, encodeForSigning } from "ripple-binary-codec";
|
|
3
|
-
import { sign } from "ripple-keypairs";
|
|
3
|
+
//import { decode, encodeForSigning } from "ripple-binary-codec";
|
|
4
|
+
//import { sign } from "ripple-keypairs";
|
|
4
5
|
describe("Xrp Api", () => {
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const bigAddress = "rUxSkt6hQpWxXQwTNRUCYYRQ7BC2yRA3F8"; // An account with more that 4000 txs
|
|
8
|
-
const emptyAddress = "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB"; // Account with no transaction (at the time of this writing)
|
|
9
|
-
const xrpPubKey = process.env["PUB_KEY"];
|
|
10
|
-
const xrpSecretKey = process.env["SECRET_KEY"];
|
|
11
|
-
beforeAll(() => {
|
|
12
|
-
module = createApi({ node: "https://s.altnet.rippletest.net:51234" });
|
|
13
|
-
});
|
|
6
|
+
const SENDER = "rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb";
|
|
7
|
+
const api = createApi({ node: "https://s.altnet.rippletest.net:51234" });
|
|
14
8
|
describe("estimateFees", () => {
|
|
15
9
|
it("returns a default value", async () => {
|
|
16
10
|
// Given
|
|
17
11
|
const amount = BigInt(100);
|
|
18
12
|
// When
|
|
19
|
-
const result = await
|
|
13
|
+
const result = await api.estimateFees({
|
|
20
14
|
type: "send",
|
|
21
|
-
sender:
|
|
15
|
+
sender: SENDER,
|
|
22
16
|
amount,
|
|
23
17
|
recipient: "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB",
|
|
24
18
|
});
|
|
@@ -29,19 +23,21 @@ describe("Xrp Api", () => {
|
|
|
29
23
|
describe("listOperations", () => {
|
|
30
24
|
it.skip("returns a list regarding address parameter", async () => {
|
|
31
25
|
// When
|
|
32
|
-
const [tx, _] = await
|
|
26
|
+
const [tx, _] = await api.listOperations(SENDER, { minHeight: 200 });
|
|
33
27
|
// https://blockexplorer.one/xrp/testnet/address/rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb
|
|
34
28
|
// as of 2025-03-18, the address has 287 transactions
|
|
35
29
|
expect(tx.length).toBeGreaterThanOrEqual(287);
|
|
36
30
|
tx.forEach(operation => {
|
|
37
|
-
const isSenderOrReceipt = operation.senders.includes(
|
|
31
|
+
const isSenderOrReceipt = operation.senders.includes(SENDER) || operation.recipients.includes(SENDER);
|
|
38
32
|
expect(isSenderOrReceipt).toBeTruthy();
|
|
39
33
|
});
|
|
40
34
|
});
|
|
41
35
|
// TO FIX, ops length is 0 for some reason
|
|
42
36
|
it.skip("returns all operations", async () => {
|
|
37
|
+
// An account with more that 4000 txs
|
|
38
|
+
const SENDER_WITH_TRANSACTIONS = "rUxSkt6hQpWxXQwTNRUCYYRQ7BC2yRA3F8";
|
|
43
39
|
// When
|
|
44
|
-
const [ops, _] = await
|
|
40
|
+
const [ops, _] = await api.listOperations(SENDER_WITH_TRANSACTIONS, { minHeight: 0 });
|
|
45
41
|
// Then
|
|
46
42
|
const checkSet = new Set(ops.map(elt => elt.tx.hash));
|
|
47
43
|
expect(checkSet.size).toEqual(ops.length);
|
|
@@ -56,7 +52,7 @@ describe("Xrp Api", () => {
|
|
|
56
52
|
describe("lastBlock", () => {
|
|
57
53
|
it("returns last block info", async () => {
|
|
58
54
|
// When
|
|
59
|
-
const result = await
|
|
55
|
+
const result = await api.lastBlock();
|
|
60
56
|
// Then
|
|
61
57
|
expect(result.hash).toBeDefined();
|
|
62
58
|
expect(result.height).toBeDefined();
|
|
@@ -64,47 +60,83 @@ describe("Xrp Api", () => {
|
|
|
64
60
|
});
|
|
65
61
|
});
|
|
66
62
|
describe("getBalance", () => {
|
|
63
|
+
// Account with no transaction (at the time of this writing)
|
|
64
|
+
const SENDER_WITH_NO_TRANSACTION = "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB";
|
|
67
65
|
it("returns an amount above 0 when address has transactions", async () => {
|
|
68
66
|
// When
|
|
69
|
-
const result = await
|
|
67
|
+
const result = await api.getBalance(SENDER);
|
|
70
68
|
// Then
|
|
71
69
|
expect(result).toBeGreaterThan(BigInt(0));
|
|
72
70
|
});
|
|
73
71
|
it("returns 0 when address has no transaction", async () => {
|
|
74
72
|
// When
|
|
75
|
-
const result = await
|
|
73
|
+
const result = await api.getBalance(SENDER_WITH_NO_TRANSACTION);
|
|
76
74
|
// Then
|
|
77
75
|
expect(result).toBe(BigInt(0));
|
|
78
76
|
});
|
|
79
77
|
});
|
|
80
78
|
describe("craftTransaction", () => {
|
|
79
|
+
const RECIPIENT = "rKRtUG15iBsCQRgrkeUEg5oX4Ae2zWZ89z";
|
|
81
80
|
it("returns a raw transaction", async () => {
|
|
82
81
|
// When
|
|
83
|
-
const result = await
|
|
82
|
+
const result = await api.craftTransaction({
|
|
84
83
|
type: "send",
|
|
85
|
-
sender:
|
|
86
|
-
recipient:
|
|
84
|
+
sender: SENDER,
|
|
85
|
+
recipient: RECIPIENT,
|
|
87
86
|
amount: BigInt(10),
|
|
88
87
|
});
|
|
89
88
|
// Then
|
|
90
89
|
expect(result.length).toEqual(162);
|
|
91
90
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const result = await
|
|
105
|
-
|
|
106
|
-
|
|
91
|
+
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
92
|
+
const result = await api.craftTransaction({
|
|
93
|
+
type: "send",
|
|
94
|
+
sender: SENDER,
|
|
95
|
+
recipient: RECIPIENT,
|
|
96
|
+
amount: BigInt(10),
|
|
97
|
+
});
|
|
98
|
+
const decodedTransaction = decode(result);
|
|
99
|
+
expect(decodedTransaction.Fee).toEqual("10");
|
|
100
|
+
});
|
|
101
|
+
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
102
|
+
const customFees = 99n;
|
|
103
|
+
const result = await api.craftTransaction({
|
|
104
|
+
type: "send",
|
|
105
|
+
sender: SENDER,
|
|
106
|
+
recipient: RECIPIENT,
|
|
107
|
+
amount: BigInt(10),
|
|
108
|
+
}, customFees);
|
|
109
|
+
const decodedTransaction = decode(result);
|
|
110
|
+
expect(decodedTransaction.Fee).toEqual(customFees.toString());
|
|
107
111
|
});
|
|
108
112
|
});
|
|
109
113
|
});
|
|
114
|
+
// To enable this test, you need to fill an `.env` file at the root of this package. Example can be found in `.env.integ.test.example`.
|
|
115
|
+
// The value hardcoded here depends on the value filled in the `.env` file.
|
|
116
|
+
/*describe.skip("combine", () => {
|
|
117
|
+
//const xrpPubKey = process.env["PUB_KEY"]!;
|
|
118
|
+
//const xrpSecretKey = process.env["SECRET_KEY"]!;
|
|
119
|
+
it("returns a signed raw transaction", async () => {
|
|
120
|
+
// Given
|
|
121
|
+
const rawTx =
|
|
122
|
+
"120000228000000024001BCDA6201B001F018161400000000000000A6840000000000000018114CF30F590D7A9067B2604D80D46090FBF342EBE988314CA26FB6B0EF6859436C2037BA0A9913208A59B98";
|
|
123
|
+
const signedTx = sign(
|
|
124
|
+
encodeForSigning({
|
|
125
|
+
...decode(rawTx),
|
|
126
|
+
SigningPubKey: xrpPubKey,
|
|
127
|
+
}),
|
|
128
|
+
xrpSecretKey,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
// When
|
|
132
|
+
const result = await module.combine(rawTx, signedTx);
|
|
133
|
+
|
|
134
|
+
// Then
|
|
135
|
+
expect(result).toEqual(
|
|
136
|
+
"120000228000000024001BCDA6201B001F018161400000000000000A68400000000000000174473045022100D3B9B37F40961A8DBDE48535F9EF333E87F9D98BE90F7141E133541874826BDB0220065E9CA4D218F16087656BC30D66672F6103B03717A59FFC04C837A2157CE47C8114CF30F590D7A9067B2604D80D46090FBF342EBE988314CA26FB6B0EF6859436C2037BA0A9913208A59B98",
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
*/
|
|
110
142
|
//# sourceMappingURL=index.integ.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.integ.test.js","sourceRoot":"","sources":["../../src/api/index.integ.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.integ.test.js","sourceRoot":"","sources":["../../src/api/index.integ.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC;AAC9B,iEAAiE;AACjE,yCAAyC;AAEzC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,MAAM,MAAM,GAAG,oCAAoC,CAAC;IACpD,MAAM,GAAG,GAAG,SAAS,CAAC,EAAE,IAAI,EAAE,uCAAuC,EAAE,CAAC,CAAC;IAEzE,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;QAC5B,EAAE,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;YACvC,QAAQ;YACR,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAE3B,OAAO;YACP,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,YAAY,CAAC;gBACpC,IAAI,EAAE,MAAM;gBACZ,MAAM,EAAE,MAAM;gBACd,MAAM;gBACN,SAAS,EAAE,oCAAoC;aAChD,CAAC,CAAC;YAEH,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,IAAI,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;YAC/D,OAAO;YACP,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,CAA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CAAC,QAAQ,EAAE,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,uIAAuI;AACvI,2EAA2E;AAC3E;;;;;;;;;;;;;;;;;;;;;;;;;IAyBI"}
|
package/lib-es/api/index.js
CHANGED
|
@@ -13,10 +13,14 @@ export function createApi(config) {
|
|
|
13
13
|
listOperations: operations,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
async function craft(transactionIntent) {
|
|
16
|
+
async function craft(transactionIntent, customFees) {
|
|
17
17
|
const nextSequenceNumber = await getNextValidSequence(transactionIntent.sender);
|
|
18
|
-
const
|
|
19
|
-
const tx = await craftTransaction({ address: transactionIntent.sender, nextSequenceNumber }, {
|
|
18
|
+
const estimatedFees = customFees !== undefined ? customFees : (await estimateFees()).fee;
|
|
19
|
+
const tx = await craftTransaction({ address: transactionIntent.sender, nextSequenceNumber }, {
|
|
20
|
+
recipient: transactionIntent.recipient,
|
|
21
|
+
amount: transactionIntent.amount,
|
|
22
|
+
fee: estimatedFees,
|
|
23
|
+
});
|
|
20
24
|
return tx.serializedTransaction;
|
|
21
25
|
}
|
|
22
26
|
async function operationsFromHeight(address, minHeight) {
|
package/lib-es/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,UAA8B,MAAM,WAAW,CAAC;AACvD,OAAO,EACL,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,SAAS,EACT,cAAc,GACf,MAAM,UAAU,CAAC;AAGlB,MAAM,UAAU,SAAS,CAAC,MAAiB;IACzC,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,EA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AAO;YACL,GAAG,KAAK;YACR,gBAAgB,EAAE,mBAAmB;YACrC,kBAAkB,EAAE,iBAAiB;YACrC,aAAa,EAAE,aAAa;YAC5B,WAAW,EAAE,WAAW;SACzB,CAAC;IACJ,CAAC;IAED,MAAM,UAAU,GAAoB;QAClC,QAAQ,EAAE,GAAG;QACb,aAAa,EAAE,EAAE;QACjB,gBAAgB,EAAE,CAAC;QACnB,SAAS,EAAE,SAAS;QACpB,kBAAkB,EAAE,IAAI;QACxB,WAAW,EAAE,EAAE;KAChB,CAAC;IAEF,IAAI,KAAK,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC;IAC5C,OAAO,KAAK,CAAC,kBAAkB,EAAE,CAAC;QAChC,KAAK,GAAG,MAAM,aAAa,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;AACxD,CAAC;AAED,KAAK,UAAU,UAAU,CACvB,OAAe,EACf,EAAE,SAAS,EAAc;IAEzB,iFAAiF;IACjF,OAAO,MAAM,oBAAoB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACxD,CAAC"}
|
package/lib-es/api/index.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as LogicFunctions from "../logic";
|
|
2
2
|
import { createApi } from "./index";
|
|
3
3
|
const mockGetServerInfos = jest.fn().mockResolvedValue({
|
|
4
4
|
info: {
|
|
@@ -156,7 +156,7 @@ describe("listOperations", () => {
|
|
|
156
156
|
tx: {
|
|
157
157
|
hash: "HASH_VALUE",
|
|
158
158
|
fees: fee,
|
|
159
|
-
date: new Date(1000000 + RIPPLE_EPOCH * 1000),
|
|
159
|
+
date: new Date(1000000 + LogicFunctions.RIPPLE_EPOCH * 1000),
|
|
160
160
|
block: {
|
|
161
161
|
hash: "HASH_VALUE_BLOCK",
|
|
162
162
|
height: 1,
|
|
@@ -183,7 +183,7 @@ describe("listOperations", () => {
|
|
|
183
183
|
tx: {
|
|
184
184
|
hash: "HASH_VALUE",
|
|
185
185
|
fees: fee,
|
|
186
|
-
date: new Date(1000000 + RIPPLE_EPOCH * 1000),
|
|
186
|
+
date: new Date(1000000 + LogicFunctions.RIPPLE_EPOCH * 1000),
|
|
187
187
|
block: {
|
|
188
188
|
hash: "HASH_VALUE_BLOCK",
|
|
189
189
|
height: 1,
|
|
@@ -205,7 +205,7 @@ describe("listOperations", () => {
|
|
|
205
205
|
tx: {
|
|
206
206
|
hash: "HASH_VALUE",
|
|
207
207
|
fees: fee,
|
|
208
|
-
date: new Date(1000000 + RIPPLE_EPOCH * 1000),
|
|
208
|
+
date: new Date(1000000 + LogicFunctions.RIPPLE_EPOCH * 1000),
|
|
209
209
|
block: {
|
|
210
210
|
hash: "HASH_VALUE_BLOCK",
|
|
211
211
|
height: 1,
|
|
@@ -224,4 +224,37 @@ describe("listOperations", () => {
|
|
|
224
224
|
]);
|
|
225
225
|
});
|
|
226
226
|
});
|
|
227
|
+
describe("Testing craftTransaction function", () => {
|
|
228
|
+
const DEFAULT_ESTIMATED_FEES = 100n;
|
|
229
|
+
const api = createApi({ node: "https://localhost" });
|
|
230
|
+
const logicCraftTransactionSpy = jest
|
|
231
|
+
.spyOn(LogicFunctions, "craftTransaction")
|
|
232
|
+
.mockImplementation((_address, _transaction, _publicKey) => {
|
|
233
|
+
return Promise.resolve({ xrplTransaction: {}, serializedTransaction: "" });
|
|
234
|
+
});
|
|
235
|
+
beforeAll(() => {
|
|
236
|
+
jest
|
|
237
|
+
.spyOn(LogicFunctions, "getNextValidSequence")
|
|
238
|
+
.mockImplementation(_address => Promise.resolve(0));
|
|
239
|
+
jest.spyOn(LogicFunctions, "estimateFees").mockImplementation(_networkInfo => {
|
|
240
|
+
return Promise.resolve({
|
|
241
|
+
networkInfo: {},
|
|
242
|
+
fee: DEFAULT_ESTIMATED_FEES,
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
247
|
+
const customFees = 99n;
|
|
248
|
+
await api.craftTransaction({}, customFees);
|
|
249
|
+
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(expect.any(Object), expect.objectContaining({
|
|
250
|
+
fee: customFees,
|
|
251
|
+
}));
|
|
252
|
+
});
|
|
253
|
+
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
254
|
+
await api.craftTransaction({});
|
|
255
|
+
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(expect.any(Object), expect.objectContaining({
|
|
256
|
+
fee: DEFAULT_ESTIMATED_FEES,
|
|
257
|
+
}));
|
|
258
|
+
});
|
|
259
|
+
});
|
|
227
260
|
//# sourceMappingURL=index.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/api/index.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/api/index.test.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,cAAc,MAAM,UAAU,CAAC;AAG3C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;IACrD,IAAI,EAAE;QACJ,gBAAgB,EAAE,KAAK;KACxB;CACF,CAAC,CAAC;AACH,MAAM,mBAAmB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACtC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7B,cAAc,EAAE,GAAG,EAAE,CAAC,kBAAkB,EAAE;IAC1C,eAAe,EAAE,CAAC,OAAe,EAAE,OAA+B,EAAE,EAAE,CACpE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC;CACxC,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,gBAAgB,E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C,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAEtD,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE;YAC3E,OAAO,OAAO,CAAC,OAAO,CAAC;gBACrB,WAAW,EAAE,EAAiB;gBAC9B,GAAG,EAAE,sBAAsB;aAC5B,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8EAA8E,EAAE,KAAK,IAAI,EAAE;QAC5F,MAAM,UAAU,GAAG,GAAG,CAAC;QACvB,MAAM,GAAG,CAAC,gBAAgB,CAAC,EAA6B,EAAE,UAAU,CAAC,CAAC;QAEtE,MAAM,CAAC,wBAAwB,CAAC,CAAC,oBAAoB,CACnD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAClB,MAAM,CAAC,gBAAgB,CAAC;YACtB,GAAG,EAAE,UAAU;SAChB,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oFAAoF,EAAE,KAAK,IAAI,EAAE;QAClG,MAAM,GAAG,CAAC,gBAAgB,CAAC,EAA6B,CAAC,CAAC;QAE1D,MAAM,CAAC,wBAAwB,CAAC,CAAC,oBAAoB,CACnD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAClB,MAAM,CAAC,gBAAgB,CAAC;YACtB,GAAG,EAAE,sBAAsB;SAC5B,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateFees.js","sourceRoot":"","sources":["../../src/logic/estimateFees.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"estimateFees.js","sourceRoot":"","sources":["../../src/logic/estimateFees.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CA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/coin-xrp",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0-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": "^2.
|
|
108
|
-
"@ledgerhq/cryptoassets": "^13.14.0",
|
|
107
|
+
"@ledgerhq/coin-framework": "^2.6.0-next.0",
|
|
108
|
+
"@ledgerhq/cryptoassets": "^13.14.1-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.7-next.0",
|
|
112
|
+
"@ledgerhq/types-live": "^6.66.0-next.0",
|
|
113
113
|
"@ledgerhq/logs": "^6.12.0"
|
|
114
114
|
},
|
|
115
115
|
"devDependencies": {
|
|
@@ -136,8 +136,10 @@
|
|
|
136
136
|
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
137
137
|
"lint:fix": "pnpm lint --fix",
|
|
138
138
|
"test": "jest",
|
|
139
|
+
"test:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand",
|
|
139
140
|
"test-watch": "jest --watch",
|
|
140
141
|
"test-integ": "DOTENV_CONFIG_PATH=.env.integ.test jest --config=jest.integ.config.js",
|
|
142
|
+
"test-integ:debug": "DOTENV_CONFIG_PATH=.env.integ.test node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --config=jest.integ.config.js",
|
|
141
143
|
"typecheck": "tsc --noEmit",
|
|
142
144
|
"unimported": "unimported"
|
|
143
145
|
}
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { decode } from "ripple-binary-codec";
|
|
2
2
|
import { createApi } from ".";
|
|
3
|
-
import { decode, encodeForSigning } from "ripple-binary-codec";
|
|
4
|
-
import { sign } from "ripple-keypairs";
|
|
3
|
+
//import { decode, encodeForSigning } from "ripple-binary-codec";
|
|
4
|
+
//import { sign } from "ripple-keypairs";
|
|
5
5
|
|
|
6
6
|
describe("Xrp Api", () => {
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const bigAddress = "rUxSkt6hQpWxXQwTNRUCYYRQ7BC2yRA3F8"; // An account with more that 4000 txs
|
|
10
|
-
const emptyAddress = "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB"; // Account with no transaction (at the time of this writing)
|
|
11
|
-
const xrpPubKey = process.env["PUB_KEY"]!;
|
|
12
|
-
const xrpSecretKey = process.env["SECRET_KEY"]!;
|
|
13
|
-
|
|
14
|
-
beforeAll(() => {
|
|
15
|
-
module = createApi({ node: "https://s.altnet.rippletest.net:51234" });
|
|
16
|
-
});
|
|
7
|
+
const SENDER = "rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb";
|
|
8
|
+
const api = createApi({ node: "https://s.altnet.rippletest.net:51234" });
|
|
17
9
|
|
|
18
10
|
describe("estimateFees", () => {
|
|
19
11
|
it("returns a default value", async () => {
|
|
@@ -21,9 +13,9 @@ describe("Xrp Api", () => {
|
|
|
21
13
|
const amount = BigInt(100);
|
|
22
14
|
|
|
23
15
|
// When
|
|
24
|
-
const result = await
|
|
16
|
+
const result = await api.estimateFees({
|
|
25
17
|
type: "send",
|
|
26
|
-
sender:
|
|
18
|
+
sender: SENDER,
|
|
27
19
|
amount,
|
|
28
20
|
recipient: "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB",
|
|
29
21
|
});
|
|
@@ -36,22 +28,25 @@ describe("Xrp Api", () => {
|
|
|
36
28
|
describe("listOperations", () => {
|
|
37
29
|
it.skip("returns a list regarding address parameter", async () => {
|
|
38
30
|
// When
|
|
39
|
-
const [tx, _] = await
|
|
31
|
+
const [tx, _] = await api.listOperations(SENDER, { minHeight: 200 });
|
|
40
32
|
|
|
41
33
|
// https://blockexplorer.one/xrp/testnet/address/rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb
|
|
42
34
|
// as of 2025-03-18, the address has 287 transactions
|
|
43
35
|
expect(tx.length).toBeGreaterThanOrEqual(287);
|
|
44
36
|
tx.forEach(operation => {
|
|
45
37
|
const isSenderOrReceipt =
|
|
46
|
-
operation.senders.includes(
|
|
38
|
+
operation.senders.includes(SENDER) || operation.recipients.includes(SENDER);
|
|
47
39
|
expect(isSenderOrReceipt).toBeTruthy();
|
|
48
40
|
});
|
|
49
41
|
});
|
|
50
42
|
|
|
51
43
|
// TO FIX, ops length is 0 for some reason
|
|
52
44
|
it.skip("returns all operations", async () => {
|
|
45
|
+
// An account with more that 4000 txs
|
|
46
|
+
const SENDER_WITH_TRANSACTIONS = "rUxSkt6hQpWxXQwTNRUCYYRQ7BC2yRA3F8";
|
|
47
|
+
|
|
53
48
|
// When
|
|
54
|
-
const [ops, _] = await
|
|
49
|
+
const [ops, _] = await api.listOperations(SENDER_WITH_TRANSACTIONS, { minHeight: 0 });
|
|
55
50
|
// Then
|
|
56
51
|
const checkSet = new Set(ops.map(elt => elt.tx.hash));
|
|
57
52
|
expect(checkSet.size).toEqual(ops.length);
|
|
@@ -69,7 +64,7 @@ describe("Xrp Api", () => {
|
|
|
69
64
|
describe("lastBlock", () => {
|
|
70
65
|
it("returns last block info", async () => {
|
|
71
66
|
// When
|
|
72
|
-
const result = await
|
|
67
|
+
const result = await api.lastBlock();
|
|
73
68
|
|
|
74
69
|
// Then
|
|
75
70
|
expect(result.hash).toBeDefined();
|
|
@@ -79,9 +74,12 @@ describe("Xrp Api", () => {
|
|
|
79
74
|
});
|
|
80
75
|
|
|
81
76
|
describe("getBalance", () => {
|
|
77
|
+
// Account with no transaction (at the time of this writing)
|
|
78
|
+
const SENDER_WITH_NO_TRANSACTION = "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB";
|
|
79
|
+
|
|
82
80
|
it("returns an amount above 0 when address has transactions", async () => {
|
|
83
81
|
// When
|
|
84
|
-
const result = await
|
|
82
|
+
const result = await api.getBalance(SENDER);
|
|
85
83
|
|
|
86
84
|
// Then
|
|
87
85
|
expect(result).toBeGreaterThan(BigInt(0));
|
|
@@ -89,7 +87,7 @@ describe("Xrp Api", () => {
|
|
|
89
87
|
|
|
90
88
|
it("returns 0 when address has no transaction", async () => {
|
|
91
89
|
// When
|
|
92
|
-
const result = await
|
|
90
|
+
const result = await api.getBalance(SENDER_WITH_NO_TRANSACTION);
|
|
93
91
|
|
|
94
92
|
// Then
|
|
95
93
|
expect(result).toBe(BigInt(0));
|
|
@@ -97,23 +95,56 @@ describe("Xrp Api", () => {
|
|
|
97
95
|
});
|
|
98
96
|
|
|
99
97
|
describe("craftTransaction", () => {
|
|
98
|
+
const RECIPIENT = "rKRtUG15iBsCQRgrkeUEg5oX4Ae2zWZ89z";
|
|
99
|
+
|
|
100
100
|
it("returns a raw transaction", async () => {
|
|
101
101
|
// When
|
|
102
|
-
const result = await
|
|
102
|
+
const result = await api.craftTransaction({
|
|
103
103
|
type: "send",
|
|
104
|
-
sender:
|
|
105
|
-
recipient:
|
|
104
|
+
sender: SENDER,
|
|
105
|
+
recipient: RECIPIENT,
|
|
106
106
|
amount: BigInt(10),
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
// Then
|
|
110
110
|
expect(result.length).toEqual(162);
|
|
111
111
|
});
|
|
112
|
+
|
|
113
|
+
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
114
|
+
const result = await api.craftTransaction({
|
|
115
|
+
type: "send",
|
|
116
|
+
sender: SENDER,
|
|
117
|
+
recipient: RECIPIENT,
|
|
118
|
+
amount: BigInt(10),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const decodedTransaction = decode(result) as { Fee: string };
|
|
122
|
+
expect(decodedTransaction.Fee).toEqual("10");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
126
|
+
const customFees = 99n;
|
|
127
|
+
const result = await api.craftTransaction(
|
|
128
|
+
{
|
|
129
|
+
type: "send",
|
|
130
|
+
sender: SENDER,
|
|
131
|
+
recipient: RECIPIENT,
|
|
132
|
+
amount: BigInt(10),
|
|
133
|
+
},
|
|
134
|
+
customFees,
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const decodedTransaction = decode(result) as { Fee: string };
|
|
138
|
+
expect(decodedTransaction.Fee).toEqual(customFees.toString());
|
|
139
|
+
});
|
|
112
140
|
});
|
|
141
|
+
});
|
|
113
142
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
143
|
+
// To enable this test, you need to fill an `.env` file at the root of this package. Example can be found in `.env.integ.test.example`.
|
|
144
|
+
// The value hardcoded here depends on the value filled in the `.env` file.
|
|
145
|
+
/*describe.skip("combine", () => {
|
|
146
|
+
//const xrpPubKey = process.env["PUB_KEY"]!;
|
|
147
|
+
//const xrpSecretKey = process.env["SECRET_KEY"]!;
|
|
117
148
|
it("returns a signed raw transaction", async () => {
|
|
118
149
|
// Given
|
|
119
150
|
const rawTx =
|
|
@@ -136,3 +167,4 @@ describe("Xrp Api", () => {
|
|
|
136
167
|
});
|
|
137
168
|
});
|
|
138
169
|
});
|
|
170
|
+
*/
|
package/src/api/index.test.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { Operation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
2
|
+
import * as LogicFunctions from "../logic";
|
|
3
3
|
import { GetTransactionsOptions } from "../network";
|
|
4
|
-
import {
|
|
4
|
+
import { NetworkInfo } from "../types";
|
|
5
|
+
import { createApi } from "./index";
|
|
5
6
|
|
|
6
7
|
const mockGetServerInfos = jest.fn().mockResolvedValue({
|
|
7
8
|
info: {
|
|
@@ -186,7 +187,7 @@ describe("listOperations", () => {
|
|
|
186
187
|
tx: {
|
|
187
188
|
hash: "HASH_VALUE",
|
|
188
189
|
fees: fee,
|
|
189
|
-
date: new Date(1000000 + RIPPLE_EPOCH * 1000),
|
|
190
|
+
date: new Date(1000000 + LogicFunctions.RIPPLE_EPOCH * 1000),
|
|
190
191
|
block: {
|
|
191
192
|
hash: "HASH_VALUE_BLOCK",
|
|
192
193
|
height: 1,
|
|
@@ -213,7 +214,7 @@ describe("listOperations", () => {
|
|
|
213
214
|
tx: {
|
|
214
215
|
hash: "HASH_VALUE",
|
|
215
216
|
fees: fee,
|
|
216
|
-
date: new Date(1000000 + RIPPLE_EPOCH * 1000),
|
|
217
|
+
date: new Date(1000000 + LogicFunctions.RIPPLE_EPOCH * 1000),
|
|
217
218
|
block: {
|
|
218
219
|
hash: "HASH_VALUE_BLOCK",
|
|
219
220
|
height: 1,
|
|
@@ -235,7 +236,7 @@ describe("listOperations", () => {
|
|
|
235
236
|
tx: {
|
|
236
237
|
hash: "HASH_VALUE",
|
|
237
238
|
fees: fee,
|
|
238
|
-
date: new Date(1000000 + RIPPLE_EPOCH * 1000),
|
|
239
|
+
date: new Date(1000000 + LogicFunctions.RIPPLE_EPOCH * 1000),
|
|
239
240
|
block: {
|
|
240
241
|
hash: "HASH_VALUE_BLOCK",
|
|
241
242
|
height: 1,
|
|
@@ -255,3 +256,49 @@ describe("listOperations", () => {
|
|
|
255
256
|
},
|
|
256
257
|
);
|
|
257
258
|
});
|
|
259
|
+
|
|
260
|
+
describe("Testing craftTransaction function", () => {
|
|
261
|
+
const DEFAULT_ESTIMATED_FEES = 100n;
|
|
262
|
+
const api = createApi({ node: "https://localhost" });
|
|
263
|
+
const logicCraftTransactionSpy = jest
|
|
264
|
+
.spyOn(LogicFunctions, "craftTransaction")
|
|
265
|
+
.mockImplementation((_address, _transaction, _publicKey) => {
|
|
266
|
+
return Promise.resolve({ xrplTransaction: {} as never, serializedTransaction: "" });
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
beforeAll(() => {
|
|
270
|
+
jest
|
|
271
|
+
.spyOn(LogicFunctions, "getNextValidSequence")
|
|
272
|
+
.mockImplementation(_address => Promise.resolve(0));
|
|
273
|
+
|
|
274
|
+
jest.spyOn(LogicFunctions, "estimateFees").mockImplementation(_networkInfo => {
|
|
275
|
+
return Promise.resolve({
|
|
276
|
+
networkInfo: {} as NetworkInfo,
|
|
277
|
+
fee: DEFAULT_ESTIMATED_FEES,
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
283
|
+
const customFees = 99n;
|
|
284
|
+
await api.craftTransaction({} as TransactionIntent<void>, customFees);
|
|
285
|
+
|
|
286
|
+
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(
|
|
287
|
+
expect.any(Object),
|
|
288
|
+
expect.objectContaining({
|
|
289
|
+
fee: customFees,
|
|
290
|
+
}),
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
295
|
+
await api.craftTransaction({} as TransactionIntent<void>);
|
|
296
|
+
|
|
297
|
+
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(
|
|
298
|
+
expect.any(Object),
|
|
299
|
+
expect.objectContaining({
|
|
300
|
+
fee: DEFAULT_ESTIMATED_FEES,
|
|
301
|
+
}),
|
|
302
|
+
);
|
|
303
|
+
});
|
|
304
|
+
});
|
package/src/api/index.ts
CHANGED
|
@@ -32,12 +32,19 @@ export function createApi(config: XrpConfig): Api<void> {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
async function craft(
|
|
35
|
+
async function craft(
|
|
36
|
+
transactionIntent: TransactionIntent<void>,
|
|
37
|
+
customFees?: bigint,
|
|
38
|
+
): Promise<string> {
|
|
36
39
|
const nextSequenceNumber = await getNextValidSequence(transactionIntent.sender);
|
|
37
|
-
const
|
|
40
|
+
const estimatedFees = customFees !== undefined ? customFees : (await estimateFees()).fee;
|
|
38
41
|
const tx = await craftTransaction(
|
|
39
42
|
{ address: transactionIntent.sender, nextSequenceNumber },
|
|
40
|
-
{
|
|
43
|
+
{
|
|
44
|
+
recipient: transactionIntent.recipient,
|
|
45
|
+
amount: transactionIntent.amount,
|
|
46
|
+
fee: estimatedFees,
|
|
47
|
+
},
|
|
41
48
|
);
|
|
42
49
|
return tx.serializedTransaction;
|
|
43
50
|
}
|