UNPKG

@ledgerhq/coin-canton

Version:
92 lines 3.14 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAccountInfo = exports.submit = exports.getLastBlock = exports.getBlockHeight = exports.getNextSequence = exports.simulate = void 0; const errors_1 = require("../types/errors"); const network_1 = __importDefault(require("@ledgerhq/live-network/network")); const live_env_1 = require("@ledgerhq/live-env"); const config_1 = __importDefault(require("../config")); const getNodeUrl = () => config_1.default.getCoinConfig().nodeUrl; // NOTE: add NODE_BOILERPLATE to libs/env/src/env.ts // txPayload needs to be unsigned const simulate = async (serializedTx) => { // @ts-expect-error: add NODE_BOILERPLATE to libs/env/src/env.ts const url = `${(0, live_env_1.getEnv)("NODE_BOILERPLATE")}/simulate`; const { data } = await (0, network_1.default)({ url, method: "POST", data: { txPayload: serializedTx, }, }); if (data.error) { throw new errors_1.SimulationError(); } return data.fees; }; exports.simulate = simulate; // can be called nonce or sequence const getNextSequence = async (address) => { // @ts-expect-error: add NODE_BOILERPLATE to libs/env/src/env.ts const url = `${(0, live_env_1.getEnv)("NODE_BOILERPLATE")}/${address}/sequence`; try { const { data } = await (0, network_1.default)({ url, method: "GET", }); return data.sequence; } catch (e) { return 0; } }; exports.getNextSequence = getNextSequence; const getBlockHeight = async () => { // @ts-expect-error: add NODE_BOILERPLATE to libs/env/src/env.ts const url = `${(0, live_env_1.getEnv)("NODE_BOILERPLATE")}/blockheight`; const { data } = await (0, network_1.default)({ url, method: "GET", }); return data.blockHeight; }; exports.getBlockHeight = getBlockHeight; const getLastBlock = async () => { // @ts-expect-error: add NODE_BOILERPLATE to libs/env/src/env.ts const url = `${(0, live_env_1.getEnv)("NODE_BOILERPLATE")}/block/current`; const { data } = await (0, network_1.default)({ url, method: "GET", }); return data; }; exports.getLastBlock = getLastBlock; const submit = async (signedTx) => { // @ts-expect-error: add NODE_BOILERPLATE to libs/env/src/env.ts const url = `${(0, live_env_1.getEnv)("NODE_BOILERPLATE")}/submit`; const { data } = await (0, network_1.default)({ url, method: "GET", }); return data; }; exports.submit = submit; const getAccountInfo = async (address) => { const { data: { result }, } = await (0, network_1.default)({ method: "POST", url: getNodeUrl(), data: { method: "account_info", params: [ { account: address, }, ], }, }); return result; }; exports.getAccountInfo = getAccountInfo; //# sourceMappingURL=node.js.map