@ledgerhq/coin-canton 0.4.0 → 0.5.0-nightly.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +21 -0
- package/jest.config.js +1 -0
- package/lib/api/getBalance.integ.test.d.ts +2 -0
- package/lib/api/getBalance.integ.test.d.ts.map +1 -0
- package/lib/api/getBalance.integ.test.js +24 -0
- package/lib/api/getBalance.integ.test.js.map +1 -0
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +1 -1
- package/lib/api/index.js.map +1 -1
- package/lib/api/lastBlock.integ.test.js +3 -1
- package/lib/api/lastBlock.integ.test.js.map +1 -1
- package/lib/api/listOperations.integ.test.d.ts +2 -0
- package/lib/api/listOperations.integ.test.d.ts.map +1 -0
- package/lib/api/listOperations.integ.test.js +23 -0
- package/lib/api/listOperations.integ.test.js.map +1 -0
- package/lib/bridge/signOperation.js +1 -1
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/common-logic/account/getBalance.d.ts +1 -1
- package/lib/common-logic/account/getBalance.d.ts.map +1 -1
- package/lib/common-logic/account/getBalance.js +21 -5
- package/lib/common-logic/account/getBalance.js.map +1 -1
- package/lib/common-logic/account/getBalance.unit.test.d.ts +2 -0
- package/lib/common-logic/account/getBalance.unit.test.d.ts.map +1 -0
- package/lib/common-logic/account/getBalance.unit.test.js +88 -0
- package/lib/common-logic/account/getBalance.unit.test.js.map +1 -0
- package/lib/common-logic/history/lastBlock.d.ts.map +1 -1
- package/lib/common-logic/history/lastBlock.js +7 -1
- package/lib/common-logic/history/lastBlock.js.map +1 -1
- package/lib/common-logic/history/lastBlock.test.d.ts +2 -0
- package/lib/common-logic/history/lastBlock.test.d.ts.map +1 -0
- package/lib/common-logic/history/lastBlock.test.js +43 -0
- package/lib/common-logic/history/lastBlock.test.js.map +1 -0
- package/lib/common-logic/history/listOperations.d.ts +3 -4
- package/lib/common-logic/history/listOperations.d.ts.map +1 -1
- package/lib/common-logic/history/listOperations.js +43 -41
- package/lib/common-logic/history/listOperations.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib/common-logic/transaction/broadcast.js +11 -3
- package/lib/common-logic/transaction/broadcast.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.test.d.ts +2 -0
- package/lib/common-logic/transaction/broadcast.test.d.ts.map +1 -0
- package/lib/common-logic/transaction/broadcast.test.js +68 -0
- package/lib/common-logic/transaction/broadcast.test.js.map +1 -0
- package/lib/common-logic/transaction/combine.d.ts +1 -1
- package/lib/common-logic/transaction/combine.d.ts.map +1 -1
- package/lib/common-logic/transaction/combine.js +6 -3
- package/lib/common-logic/transaction/combine.js.map +1 -1
- package/lib/common-logic/transaction/combine.test.d.ts +2 -0
- package/lib/common-logic/transaction/combine.test.d.ts.map +1 -0
- package/lib/common-logic/transaction/combine.test.js +28 -0
- package/lib/common-logic/transaction/combine.test.js.map +1 -0
- package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib/common-logic/transaction/estimateFees.js +2 -15
- package/lib/common-logic/transaction/estimateFees.js.map +1 -1
- package/lib/common-logic/utils.d.ts +0 -1
- package/lib/common-logic/utils.d.ts.map +1 -1
- package/lib/common-logic/utils.js +1 -6
- package/lib/common-logic/utils.js.map +1 -1
- package/lib/config.d.ts +6 -3
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/network/gateway.d.ts +31 -21
- package/lib/network/gateway.d.ts.map +1 -1
- package/lib/network/gateway.integ.test.js +29 -2
- package/lib/network/gateway.integ.test.js.map +1 -1
- package/lib/network/gateway.js +33 -9
- package/lib/network/gateway.js.map +1 -1
- package/lib/network/node.integ.test.js +4 -2
- package/lib/network/node.integ.test.js.map +1 -1
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib-es/api/getBalance.integ.test.d.ts +2 -0
- package/lib-es/api/getBalance.integ.test.d.ts.map +1 -0
- package/lib-es/api/getBalance.integ.test.js +22 -0
- package/lib-es/api/getBalance.integ.test.js.map +1 -0
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +1 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/lastBlock.integ.test.js +3 -1
- package/lib-es/api/lastBlock.integ.test.js.map +1 -1
- package/lib-es/api/listOperations.integ.test.d.ts +2 -0
- package/lib-es/api/listOperations.integ.test.d.ts.map +1 -0
- package/lib-es/api/listOperations.integ.test.js +21 -0
- package/lib-es/api/listOperations.integ.test.js.map +1 -0
- package/lib-es/bridge/signOperation.js +1 -1
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/common-logic/account/getBalance.d.ts +1 -1
- package/lib-es/common-logic/account/getBalance.d.ts.map +1 -1
- package/lib-es/common-logic/account/getBalance.js +18 -5
- package/lib-es/common-logic/account/getBalance.js.map +1 -1
- package/lib-es/common-logic/account/getBalance.unit.test.d.ts +2 -0
- package/lib-es/common-logic/account/getBalance.unit.test.d.ts.map +1 -0
- package/lib-es/common-logic/account/getBalance.unit.test.js +53 -0
- package/lib-es/common-logic/account/getBalance.unit.test.js.map +1 -0
- package/lib-es/common-logic/history/lastBlock.d.ts.map +1 -1
- package/lib-es/common-logic/history/lastBlock.js +5 -2
- package/lib-es/common-logic/history/lastBlock.js.map +1 -1
- package/lib-es/common-logic/history/lastBlock.test.d.ts +2 -0
- package/lib-es/common-logic/history/lastBlock.test.d.ts.map +1 -0
- package/lib-es/common-logic/history/lastBlock.test.js +38 -0
- package/lib-es/common-logic/history/lastBlock.test.js.map +1 -0
- package/lib-es/common-logic/history/listOperations.d.ts +3 -4
- package/lib-es/common-logic/history/listOperations.d.ts.map +1 -1
- package/lib-es/common-logic/history/listOperations.js +40 -41
- package/lib-es/common-logic/history/listOperations.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.js +8 -3
- package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.test.d.ts +2 -0
- package/lib-es/common-logic/transaction/broadcast.test.d.ts.map +1 -0
- package/lib-es/common-logic/transaction/broadcast.test.js +33 -0
- package/lib-es/common-logic/transaction/broadcast.test.js.map +1 -0
- package/lib-es/common-logic/transaction/combine.d.ts +1 -1
- package/lib-es/common-logic/transaction/combine.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/combine.js +6 -3
- package/lib-es/common-logic/transaction/combine.js.map +1 -1
- package/lib-es/common-logic/transaction/combine.test.d.ts +2 -0
- package/lib-es/common-logic/transaction/combine.test.d.ts.map +1 -0
- package/lib-es/common-logic/transaction/combine.test.js +26 -0
- package/lib-es/common-logic/transaction/combine.test.js.map +1 -0
- package/lib-es/common-logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/estimateFees.js +2 -15
- package/lib-es/common-logic/transaction/estimateFees.js.map +1 -1
- package/lib-es/common-logic/utils.d.ts +0 -1
- package/lib-es/common-logic/utils.d.ts.map +1 -1
- package/lib-es/common-logic/utils.js +0 -4
- package/lib-es/common-logic/utils.js.map +1 -1
- package/lib-es/config.d.ts +6 -3
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/network/gateway.d.ts +31 -21
- package/lib-es/network/gateway.d.ts.map +1 -1
- package/lib-es/network/gateway.integ.test.js +30 -3
- package/lib-es/network/gateway.integ.test.js.map +1 -1
- package/lib-es/network/gateway.js +30 -8
- package/lib-es/network/gateway.js.map +1 -1
- package/lib-es/network/node.integ.test.js +4 -2
- package/lib-es/network/node.integ.test.js.map +1 -1
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/api/getBalance.integ.test.ts +28 -0
- package/src/api/index.ts +3 -2
- package/src/api/lastBlock.integ.test.ts +3 -1
- package/src/api/listOperations.integ.test.ts +27 -0
- package/src/bridge/signOperation.ts +1 -1
- package/src/common-logic/account/getBalance.ts +20 -5
- package/src/common-logic/account/getBalance.unit.test.ts +63 -0
- package/src/common-logic/history/lastBlock.test.ts +47 -0
- package/src/common-logic/history/lastBlock.ts +6 -2
- package/src/common-logic/history/listOperations.ts +43 -52
- package/src/common-logic/transaction/broadcast.test.ts +42 -0
- package/src/common-logic/transaction/broadcast.ts +7 -3
- package/src/common-logic/transaction/combine.test.ts +28 -0
- package/src/common-logic/transaction/combine.ts +7 -4
- package/src/common-logic/transaction/estimateFees.ts +2 -14
- package/src/common-logic/utils.ts +0 -5
- package/src/config.ts +8 -2
- package/src/network/gateway.integ.test.ts +49 -3
- package/src/network/gateway.ts +67 -27
- package/src/network/node.integ.test.ts +4 -2
- package/src/types/bridge.ts +0 -1
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { BlockInfo } from "@ledgerhq/coin-framework/api/index";
|
|
2
|
-
import { getLedgerEnd } from "../../network/node";
|
|
2
|
+
import { getLedgerEnd as nodeGetLedgerEnd } from "../../network/node";
|
|
3
|
+
import { getLedgerEnd } from "../../network/gateway";
|
|
4
|
+
import coinConfig from "../../config";
|
|
5
|
+
|
|
6
|
+
const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
|
|
3
7
|
|
|
4
8
|
export async function lastBlock(): Promise<BlockInfo> {
|
|
5
9
|
return {
|
|
6
|
-
height: await getLedgerEnd(),
|
|
10
|
+
height: useGateway() ? await getLedgerEnd() : await nodeGetLedgerEnd(),
|
|
7
11
|
};
|
|
8
12
|
}
|
|
@@ -1,64 +1,55 @@
|
|
|
1
1
|
import type { Operation, Pagination } from "@ledgerhq/coin-framework/api/index";
|
|
2
|
-
import { getTransactions } from "../../network/
|
|
3
|
-
import
|
|
2
|
+
import { CreatedEvent, getTransactions, TxInfo } from "../../network/gateway";
|
|
3
|
+
import coinConfig from "../../config";
|
|
4
|
+
|
|
5
|
+
const getNativeContractId = () =>
|
|
6
|
+
coinConfig.getCoinConfig().nativeInstrumentId !== undefined
|
|
7
|
+
? coinConfig.getCoinConfig().nativeInstrumentId?.split(".")[0]
|
|
8
|
+
: "";
|
|
4
9
|
|
|
5
10
|
/**
|
|
6
11
|
* Returns list of operations associated to an account.
|
|
7
|
-
* @param
|
|
12
|
+
* @param partyId Account partyId
|
|
8
13
|
* @param pagination Pagination options
|
|
9
14
|
* @returns Operations found and the next "id" or "index" to use for pagination (i.e. `start` property).\
|
|
10
|
-
*
|
|
11
|
-
* This "id" or "index" value, thus it has functional meaning, is different for each blockchain.
|
|
15
|
+
* Impl to finalize when backend is ready
|
|
12
16
|
*/
|
|
13
17
|
export async function listOperations(
|
|
14
|
-
|
|
18
|
+
partyId: string,
|
|
15
19
|
page: Pagination,
|
|
16
20
|
): Promise<[Operation[], string]> {
|
|
17
|
-
const transactions = await getTransactions(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
21
|
+
const { transactions, next } = await getTransactions(partyId, {
|
|
22
|
+
cursor: page.pagingToken !== undefined ? parseInt(page.pagingToken) : undefined,
|
|
23
|
+
minOffset: page.minHeight,
|
|
24
|
+
limit: page.limit,
|
|
25
|
+
});
|
|
26
|
+
const ops: Operation[] = [];
|
|
27
|
+
for (const tx of transactions) {
|
|
28
|
+
for (let i = 0; i < tx.events.length; i++) {
|
|
29
|
+
const event: CreatedEvent = tx.events[i]["CantonCreatedEvent"] as CreatedEvent;
|
|
30
|
+
if (event && event.template_id.module_name === "Splice.Amulet") {
|
|
31
|
+
ops.push({
|
|
32
|
+
id: tx.update_id + "-" + i,
|
|
33
|
+
type: event.signatories.includes(partyId) ? "OUT" : "IN",
|
|
34
|
+
value: BigInt(0), // to be finalized when details are available on backend
|
|
35
|
+
senders: event.signatories.includes(partyId) ? [partyId] : [],
|
|
36
|
+
recipients: event.signatories.includes(partyId) ? [] : [partyId],
|
|
37
|
+
asset:
|
|
38
|
+
event.contract_id === getNativeContractId()
|
|
39
|
+
? { type: "native" }
|
|
40
|
+
: { type: "token", assetReference: event.contract_id },
|
|
41
|
+
tx: {
|
|
42
|
+
hash: tx.update_id,
|
|
43
|
+
fees: BigInt(0), // to be finalized when details are available on backend
|
|
44
|
+
date: new Date(tx.record_time.seconds),
|
|
45
|
+
block: {
|
|
46
|
+
height: tx.offset,
|
|
47
|
+
time: new Date(tx.effective_at.seconds),
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
39
51
|
}
|
|
40
52
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* Note: The operation ID must be concatenated with another
|
|
45
|
-
* value if the transaction hash is not enough to identify it
|
|
46
|
-
*/
|
|
47
|
-
id: hash,
|
|
48
|
-
asset: { type: "native" },
|
|
49
|
-
tx: {
|
|
50
|
-
hash,
|
|
51
|
-
fees: feeValue,
|
|
52
|
-
date: new Date(date),
|
|
53
|
-
block: {
|
|
54
|
-
height: inLedger,
|
|
55
|
-
hash,
|
|
56
|
-
time: new Date(date),
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
type,
|
|
60
|
-
value,
|
|
61
|
-
senders: [Account],
|
|
62
|
-
recipients: [Destination],
|
|
63
|
-
};
|
|
64
|
-
};
|
|
53
|
+
}
|
|
54
|
+
return [ops, next + ""];
|
|
55
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { submit } from "../../network/gateway";
|
|
2
|
+
import * as coinConfigModule from "../../config";
|
|
3
|
+
import { broadcast } from "./broadcast";
|
|
4
|
+
|
|
5
|
+
jest.mock("../../network/gateway", () => ({
|
|
6
|
+
submit: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
const mockSerialized = JSON.stringify({
|
|
10
|
+
serialized: "serialized-tx",
|
|
11
|
+
signature: "signature",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe("broadcast", () => {
|
|
15
|
+
const mockGetCoinConfig = jest.spyOn(coinConfigModule.default, "getCoinConfig");
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
jest.clearAllMocks();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should broadcast", async () => {
|
|
22
|
+
mockGetCoinConfig.mockReturnValue({
|
|
23
|
+
useGateway: true,
|
|
24
|
+
} as any);
|
|
25
|
+
|
|
26
|
+
(submit as jest.Mock).mockResolvedValue({ updateId: "my-update-id" });
|
|
27
|
+
|
|
28
|
+
const result = await broadcast(mockSerialized);
|
|
29
|
+
|
|
30
|
+
expect(submit).toHaveBeenCalledWith("serialized-tx", "signature");
|
|
31
|
+
expect(result).toEqual("my-update-id");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should throw an error when useGateway is false (not implemented with node)", async () => {
|
|
35
|
+
mockGetCoinConfig.mockReturnValue({
|
|
36
|
+
useGateway: false,
|
|
37
|
+
} as any);
|
|
38
|
+
|
|
39
|
+
await expect(broadcast(mockSerialized)).rejects.toThrow("Not implemented");
|
|
40
|
+
expect(submit).not.toHaveBeenCalled();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import coinConfig from "../../config";
|
|
2
|
+
import { submit } from "../../network/gateway";
|
|
3
|
+
|
|
4
|
+
const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
|
|
2
5
|
|
|
3
6
|
export async function broadcast(signedTx: string): Promise<string> {
|
|
4
|
-
const
|
|
5
|
-
return
|
|
7
|
+
const parsed: { serialized: string; signature: string } = JSON.parse(signedTx);
|
|
8
|
+
if (useGateway()) return (await submit(parsed.serialized, parsed.signature)).updateId;
|
|
9
|
+
else throw new Error("Not implemented");
|
|
6
10
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { combine } from "./combine";
|
|
2
|
+
|
|
3
|
+
describe("combine", () => {
|
|
4
|
+
it("responds with a Stringify version of the payload to broadcast", () => {
|
|
5
|
+
// GIVEN
|
|
6
|
+
const transaction = {
|
|
7
|
+
transaction: {
|
|
8
|
+
serialized: "SERIALIZED",
|
|
9
|
+
json: "JSON",
|
|
10
|
+
hash: "HASH",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
const signature = "SIGNATURE";
|
|
14
|
+
|
|
15
|
+
// WHEN
|
|
16
|
+
const result = combine(JSON.stringify(transaction), signature);
|
|
17
|
+
|
|
18
|
+
// THEN
|
|
19
|
+
expect(JSON.parse(result)).toEqual({
|
|
20
|
+
transaction: {
|
|
21
|
+
serialized: "SERIALIZED",
|
|
22
|
+
json: "JSON",
|
|
23
|
+
hash: "HASH",
|
|
24
|
+
},
|
|
25
|
+
signature: "SIGNATURE",
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { encode } from "../utils";
|
|
2
|
-
|
|
3
1
|
// Combines signature with raw transaction
|
|
4
|
-
export function combine(transaction: string, signature: string
|
|
5
|
-
|
|
2
|
+
export function combine(transaction: string, signature: string): string {
|
|
3
|
+
const tx = JSON.parse(transaction);
|
|
4
|
+
|
|
5
|
+
return JSON.stringify({
|
|
6
|
+
...tx,
|
|
7
|
+
signature,
|
|
8
|
+
});
|
|
6
9
|
}
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { SimulationError } from "../../types/errors";
|
|
3
|
-
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4
2
|
export async function estimateFees(serializedTransaction: string): Promise<bigint> {
|
|
5
|
-
|
|
6
|
-
// We call the node to do a dry run and estimate fees
|
|
7
|
-
return BigInt(await simulate(serializedTransaction));
|
|
8
|
-
} catch (e) {
|
|
9
|
-
// default value is required in case of simulation error, else user will encounter an error in the flow
|
|
10
|
-
if (e instanceof SimulationError) {
|
|
11
|
-
return BigInt(1000);
|
|
12
|
-
} else {
|
|
13
|
-
throw new Error("Unexpected error while estimating fees.");
|
|
14
|
-
}
|
|
15
|
-
}
|
|
3
|
+
return Promise.resolve(BigInt(10_000)); // TODO replace with real implementation
|
|
16
4
|
}
|
|
@@ -11,8 +11,3 @@ export const validateTag = (tag: BigNumber) => {
|
|
|
11
11
|
export function isRecipientValid(recipient: string): boolean {
|
|
12
12
|
return recipient.length > 0;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
export const encode = (transaction: string, signature: string, publicKey?: string) => {
|
|
16
|
-
// sample encoding
|
|
17
|
-
return `${transaction}${publicKey}${signature}encodedTx`;
|
|
18
|
-
};
|
package/src/config.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import buildCoinConfig, { type CurrencyConfig } from "@ledgerhq/coin-framework/config";
|
|
1
|
+
import buildCoinConfig, { CoinConfig, type CurrencyConfig } from "@ledgerhq/coin-framework/config";
|
|
2
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
3
|
|
|
3
4
|
export type CantonConfig = {
|
|
4
5
|
nodeUrl?: string;
|
|
6
|
+
nodeId?: string;
|
|
5
7
|
gatewayUrl?: string;
|
|
6
8
|
// TODELETE
|
|
7
9
|
minReserve?: number;
|
|
8
10
|
networkType: "mainnet" | "devnet" | "localnet";
|
|
9
11
|
useGateway?: boolean;
|
|
12
|
+
nativeInstrumentId?: string;
|
|
10
13
|
};
|
|
11
14
|
|
|
12
15
|
export type CantonCoinConfig = CurrencyConfig & CantonConfig;
|
|
13
16
|
|
|
14
|
-
const coinConfig
|
|
17
|
+
const coinConfig: {
|
|
18
|
+
setCoinConfig: (config: CoinConfig<CantonCoinConfig>) => void;
|
|
19
|
+
getCoinConfig: (currency?: CryptoCurrency) => CantonCoinConfig;
|
|
20
|
+
} = buildCoinConfig<CantonCoinConfig>();
|
|
15
21
|
|
|
16
22
|
export default coinConfig;
|
|
@@ -1,32 +1,78 @@
|
|
|
1
1
|
import coinConfig from "../config";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getLedgerEnd,
|
|
4
|
+
prepareOnboarding,
|
|
5
|
+
getBalance,
|
|
6
|
+
getTransactions,
|
|
7
|
+
getPartyById,
|
|
8
|
+
getPartyByPubKey,
|
|
9
|
+
} from "./gateway";
|
|
3
10
|
|
|
4
11
|
describe("gateway (devnet)", () => {
|
|
5
12
|
beforeAll(() => {
|
|
6
13
|
coinConfig.setCoinConfig(() => ({
|
|
7
14
|
gatewayUrl: "https://canton-gateway.api.live.ledger-test.com",
|
|
15
|
+
useGateway: true,
|
|
8
16
|
networkType: "devnet",
|
|
9
17
|
status: {
|
|
10
18
|
type: "active",
|
|
11
19
|
},
|
|
12
20
|
}));
|
|
13
21
|
});
|
|
22
|
+
|
|
14
23
|
describe("prepareOnboarding", () => {
|
|
15
24
|
it("should prepare onboarding", async () => {
|
|
16
25
|
const response = await prepareOnboarding(
|
|
17
|
-
"
|
|
26
|
+
"c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
|
|
18
27
|
"ed25519",
|
|
19
28
|
);
|
|
20
29
|
expect(response).toHaveProperty("party_id");
|
|
21
30
|
expect(response).toHaveProperty("party_name");
|
|
22
31
|
expect(response).toHaveProperty("public_key_fingerprint");
|
|
23
32
|
expect(response).toHaveProperty("topology_transactions_hash");
|
|
24
|
-
});
|
|
33
|
+
}, 30000);
|
|
25
34
|
});
|
|
35
|
+
|
|
26
36
|
describe("getLedgerEnd", () => {
|
|
27
37
|
it("should return ledger end", async () => {
|
|
28
38
|
const end = await getLedgerEnd();
|
|
29
39
|
expect(end).toBeGreaterThanOrEqual(0);
|
|
30
40
|
});
|
|
31
41
|
});
|
|
42
|
+
|
|
43
|
+
describe("getBalance", () => {
|
|
44
|
+
it("should return user balance", async () => {
|
|
45
|
+
const balance = await getBalance(
|
|
46
|
+
"party-4f2e1485107adf5f::122027c6dbbbdbffe0fa3122ae05175f3b9328e879e9ce96b670354deb64a45683c1",
|
|
47
|
+
);
|
|
48
|
+
expect(balance.length).toBeGreaterThanOrEqual(1);
|
|
49
|
+
expect(balance[0].amount).toBeGreaterThanOrEqual(0);
|
|
50
|
+
expect(balance[0].instrument_id.includes("Splice")).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("getPartyById", () => {
|
|
55
|
+
it.skip("should return party info", async () => {
|
|
56
|
+
const party = await getPartyById("4f2e1485107adf5f");
|
|
57
|
+
expect(party).toBeDefined();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("getPartyByPubKey", () => {
|
|
62
|
+
it.skip("should return party info", async () => {
|
|
63
|
+
const party = await getPartyByPubKey(
|
|
64
|
+
"122027c6dbbbdbffe0fa3122ae05175f3b9328e879e9ce96b670354deb64a45683c1",
|
|
65
|
+
);
|
|
66
|
+
expect(party).toBeDefined();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("getTransactions", () => {
|
|
71
|
+
it("should return user transactions", async () => {
|
|
72
|
+
const { transactions } = await getTransactions(
|
|
73
|
+
"party-5f29bb32e9939939::12202becd8062a1d170209956cfd977fca76fcb4d2a892d08c77a7483f35a11d6440",
|
|
74
|
+
);
|
|
75
|
+
expect(transactions.length).toBeGreaterThanOrEqual(0);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
32
78
|
});
|
package/src/network/gateway.ts
CHANGED
|
@@ -26,8 +26,15 @@ type OnboardingSubmitResponse = {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
type
|
|
30
|
-
|
|
29
|
+
type TransactionSubmitRequest = {
|
|
30
|
+
serialized: string;
|
|
31
|
+
signature: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type TransactionSubmitResponse = { updateId: string };
|
|
35
|
+
|
|
36
|
+
export type InstrumentBalance = {
|
|
37
|
+
instrument_id: string;
|
|
31
38
|
amount: number;
|
|
32
39
|
locked: boolean;
|
|
33
40
|
};
|
|
@@ -44,46 +51,47 @@ type Timestamp = {
|
|
|
44
51
|
|
|
45
52
|
type BaseEvent = {
|
|
46
53
|
type: string;
|
|
47
|
-
|
|
54
|
+
contract_id: string;
|
|
48
55
|
details: string;
|
|
49
56
|
};
|
|
50
57
|
|
|
51
|
-
type CreatedEvent = BaseEvent & {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
export type CreatedEvent = BaseEvent & {
|
|
59
|
+
template_id: {
|
|
60
|
+
package_id: string;
|
|
61
|
+
module_name: string;
|
|
62
|
+
entity_name: string;
|
|
56
63
|
};
|
|
57
64
|
signatories: string[];
|
|
58
65
|
observers: string[];
|
|
59
66
|
};
|
|
60
67
|
|
|
61
68
|
type ExercisedEvent = BaseEvent & {
|
|
62
|
-
|
|
69
|
+
template_id: {
|
|
63
70
|
packageId: string;
|
|
64
71
|
moduleName: string;
|
|
65
72
|
entityName: string;
|
|
66
73
|
};
|
|
67
74
|
choice: string;
|
|
68
75
|
consuming: boolean;
|
|
69
|
-
|
|
76
|
+
acting_parties: string[];
|
|
70
77
|
};
|
|
71
78
|
|
|
72
79
|
type Event = BaseEvent | CreatedEvent | ExercisedEvent;
|
|
73
80
|
|
|
74
|
-
type TxInfo = {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
export type TxInfo = {
|
|
82
|
+
update_id: string;
|
|
83
|
+
command_id: string;
|
|
84
|
+
workflow_id: string;
|
|
85
|
+
effective_at: Timestamp;
|
|
79
86
|
offset: number;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
events: Event[];
|
|
83
|
-
|
|
87
|
+
synchronizer_id: string;
|
|
88
|
+
record_time: Timestamp;
|
|
89
|
+
events: Record<string, Event>[];
|
|
90
|
+
trace_context: string;
|
|
84
91
|
};
|
|
85
92
|
|
|
86
93
|
const getGatewayUrl = () => coinConfig.getCoinConfig().gatewayUrl;
|
|
94
|
+
const getNodeId = () => coinConfig.getCoinConfig().nodeId || "ledger-live-devnet-prd";
|
|
87
95
|
|
|
88
96
|
export async function prepareOnboarding(
|
|
89
97
|
pubKey: string,
|
|
@@ -91,7 +99,7 @@ export async function prepareOnboarding(
|
|
|
91
99
|
): Promise<OnboardingPrepareResponse> {
|
|
92
100
|
const { data } = await network<OnboardingPrepareResponse>({
|
|
93
101
|
method: "POST",
|
|
94
|
-
url: `${getGatewayUrl()}/v1/node/
|
|
102
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/prepare`,
|
|
95
103
|
data: {
|
|
96
104
|
public_key: pubKey,
|
|
97
105
|
public_key_type: pubKeyType,
|
|
@@ -107,7 +115,7 @@ export async function submitOnboarding(
|
|
|
107
115
|
) {
|
|
108
116
|
const { data } = await network<OnboardingSubmitResponse>({
|
|
109
117
|
method: "POST",
|
|
110
|
-
url: `${getGatewayUrl()}/v1/node/
|
|
118
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/submit`,
|
|
111
119
|
data: {
|
|
112
120
|
prepare_request: prepareRequest,
|
|
113
121
|
prepare_response: prepareResponse,
|
|
@@ -117,23 +125,54 @@ export async function submitOnboarding(
|
|
|
117
125
|
return data;
|
|
118
126
|
}
|
|
119
127
|
|
|
128
|
+
export async function submit(serializedTx: string, signature: string) {
|
|
129
|
+
const { data } = await network<TransactionSubmitResponse>({
|
|
130
|
+
method: "POST",
|
|
131
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/transaction/submit`,
|
|
132
|
+
data: {
|
|
133
|
+
serialized: serializedTx,
|
|
134
|
+
signature,
|
|
135
|
+
} satisfies TransactionSubmitRequest,
|
|
136
|
+
});
|
|
137
|
+
return data;
|
|
138
|
+
}
|
|
139
|
+
|
|
120
140
|
export async function getBalance(partyId: string): Promise<InstrumentBalance[]> {
|
|
121
141
|
const { data } = await network<InstrumentBalance[]>({
|
|
122
142
|
method: "GET",
|
|
123
|
-
url: `${getGatewayUrl()}/v1/node/
|
|
143
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/balance`,
|
|
124
144
|
});
|
|
125
145
|
return data;
|
|
126
146
|
}
|
|
127
147
|
|
|
128
|
-
export async function
|
|
148
|
+
export async function getPartyById(partyId: string): Promise<PartyInfo> {
|
|
149
|
+
return await getParty(partyId, "ID");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export async function getPartyByPubKey(pubKey: string): Promise<PartyInfo> {
|
|
153
|
+
return await getParty(pubKey, "PK");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function getParty(identifier: string, by: "ID" | "PK"): Promise<PartyInfo> {
|
|
129
157
|
const { data } = await network<PartyInfo>({
|
|
130
158
|
method: "GET",
|
|
131
|
-
url: `${getGatewayUrl()}/v1/node/
|
|
159
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${identifier}`,
|
|
160
|
+
data: {
|
|
161
|
+
by,
|
|
162
|
+
},
|
|
132
163
|
});
|
|
133
164
|
return data;
|
|
134
165
|
}
|
|
135
166
|
|
|
136
|
-
export async function getTransactions(
|
|
167
|
+
export async function getTransactions(
|
|
168
|
+
partyId: string,
|
|
169
|
+
options?: {
|
|
170
|
+
cursor?: number | undefined;
|
|
171
|
+
minOffset?: number | undefined;
|
|
172
|
+
maxOffset?: number | undefined;
|
|
173
|
+
limit?: number | undefined;
|
|
174
|
+
},
|
|
175
|
+
): Promise<{
|
|
137
176
|
next: number;
|
|
138
177
|
transactions: TxInfo[];
|
|
139
178
|
}> {
|
|
@@ -142,7 +181,8 @@ export async function getTransactions(partyId: string): Promise<{
|
|
|
142
181
|
transactions: TxInfo[];
|
|
143
182
|
}>({
|
|
144
183
|
method: "GET",
|
|
145
|
-
url: `${getGatewayUrl()}/v1/node/
|
|
184
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transactions`,
|
|
185
|
+
data: options,
|
|
146
186
|
});
|
|
147
187
|
return data;
|
|
148
188
|
}
|
|
@@ -150,7 +190,7 @@ export async function getTransactions(partyId: string): Promise<{
|
|
|
150
190
|
export async function getLedgerEnd(): Promise<number> {
|
|
151
191
|
const { data } = await network<number>({
|
|
152
192
|
method: "GET",
|
|
153
|
-
url: `${getGatewayUrl()}/v1/node/
|
|
193
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/ledger-end`,
|
|
154
194
|
});
|
|
155
195
|
return data;
|
|
156
196
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import coinConfig from "../config";
|
|
2
2
|
import { getLedgerEnd } from "./node";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// enable manually, as it requires a running node locally
|
|
5
|
+
describe.skip("Node (localnet)", () => {
|
|
5
6
|
beforeAll(() => {
|
|
6
7
|
coinConfig.setCoinConfig(() => ({
|
|
7
8
|
gatewayUrl: "http://gateway.url",
|
|
@@ -19,7 +20,8 @@ describe("Node (localnet)", () => {
|
|
|
19
20
|
});
|
|
20
21
|
});
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
// enable manually, as it requires an auth token in env variable
|
|
24
|
+
describe.skip("Node (devnet)", () => {
|
|
23
25
|
beforeAll(() => {
|
|
24
26
|
coinConfig.setCoinConfig(() => ({
|
|
25
27
|
nodeUrl: "https://wallet-validator-devnet-canton.ledger-test.com/v2",
|