Skip to content

Commit 284a2c7

Browse files
coin-canton broadcast
1 parent 051706b commit 284a2c7

File tree

6 files changed

+53
-23
lines changed

6 files changed

+53
-23
lines changed

.changeset/angry-bags-notice.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ledgerhq/coin-canton": minor
3+
"@ledgerhq/live-common": minor
4+
---
5+
6+
coin-canton broadcast
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { submit } from "../../network/node";
1+
import coinConfig from "../../config";
2+
import { submit } from "../../network/gateway";
3+
4+
const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
25

36
export async function broadcast(signedTx: string): Promise<string> {
4-
const submittedPayment = await submit(signedTx);
5-
return submittedPayment.tx_hash;
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");
610
}
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
import { simulate } from "../../network/node";
2-
import { SimulationError } from "../../types/errors";
3-
1+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
42
export async function estimateFees(serializedTransaction: string): Promise<bigint> {
5-
try {
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
164
}

libs/coin-modules/coin-canton/src/network/gateway.integ.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe("gateway (devnet)", () => {
1919
},
2020
}));
2121
});
22+
2223
describe("prepareOnboarding", () => {
2324
it("should prepare onboarding", async () => {
2425
const response = await prepareOnboarding(
@@ -31,6 +32,11 @@ describe("gateway (devnet)", () => {
3132
expect(response).toHaveProperty("topology_transactions_hash");
3233
}, 30000);
3334
});
35+
36+
describe("submit", () => {
37+
it("should submit", async () => {}, 30000);
38+
});
39+
3440
describe("getLedgerEnd", () => {
3541
it("should return ledger end", async () => {
3642
const end = await getLedgerEnd();

libs/coin-modules/coin-canton/src/network/gateway.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ type OnboardingSubmitResponse = {
2626
};
2727
};
2828

29+
type TransactionSubmitRequest = {
30+
serialized: string;
31+
signature: string;
32+
};
33+
34+
type TransactionSubmitResponse = { updateId: string };
35+
2936
export type InstrumentBalance = {
3037
instrumentId: string;
3138
amount: number;
@@ -118,6 +125,18 @@ export async function submitOnboarding(
118125
return data;
119126
}
120127

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+
121140
export async function getBalance(partyId: string): Promise<InstrumentBalance[]> {
122141
const { data } = await network<InstrumentBalance[]>({
123142
method: "GET",

libs/ledger-live-common/src/bridge/generic-alpaca/alpaca/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
import { createApi as createXrpApi } from "@ledgerhq/coin-xrp/api/index";
22
import { createApi as createStellarApi } from "@ledgerhq/coin-stellar/api/index";
3+
import { createApi as createCantonApi } from "@ledgerhq/coin-canton/api/index";
4+
import { createApi as createTronApi } from "@ledgerhq/coin-tron/api/index";
35
import { getCurrencyConfiguration } from "../../../config";
46
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
57
import { getNetworkAlpacaApi } from "./network/network-alpaca";
68
import { Api } from "@ledgerhq/coin-framework/api/types";
79
import { XrpCoinConfig } from "@ledgerhq/coin-xrp/config";
810
import { StellarCoinConfig } from "@ledgerhq/coin-stellar/config";
11+
import { CantonCoinConfig } from "@ledgerhq/coin-canton/config";
12+
import { TronCoinConfig } from "@ledgerhq/coin-tron/config";
913

1014
export function getAlpacaApi(network, kind): Api<any> {
15+
const currency = getCryptoCurrencyById(network);
1116
if (kind === "local") {
1217
switch (network) {
1318
case "ripple":
1419
case "xrp":
15-
return createXrpApi(
16-
getCurrencyConfiguration<XrpCoinConfig>(getCryptoCurrencyById("ripple")),
17-
) as Api<any>; // FIXME: createXrpApi returns a strongly typed Api<XrpSender>, fix Api<any> to allow it
20+
return createXrpApi(getCurrencyConfiguration<XrpCoinConfig>(currency)) as Api<any>; // FIXME: createXrpApi returns a strongly typed Api<XrpSender>, fix Api<any> to allow it
1821
case "stellar":
19-
return createStellarApi(
20-
getCurrencyConfiguration<StellarCoinConfig>(getCryptoCurrencyById("stellar")),
21-
) as Api<any>;
22+
return createStellarApi(getCurrencyConfiguration<StellarCoinConfig>(currency)) as Api<any>;
23+
case "canton_network_localnet":
24+
case "canton_network_devnet":
25+
case "canton_network_mainnet":
26+
return createCantonApi(getCurrencyConfiguration<CantonCoinConfig>(currency)) as Api<any>;
27+
case "tron":
28+
return createTronApi(getCurrencyConfiguration<TronCoinConfig>(currency)) as Api<any>;
2229
}
2330
}
2431
return getNetworkAlpacaApi(network) satisfies Partial<Api<any>> as Api<any>;

0 commit comments

Comments
 (0)