@ledgerhq/coin-tron
Version:
Ledger Tron Coin integration
63 lines • 2.66 kB
JavaScript
import { rejectBalanceOptions } from "@ledgerhq/coin-module-framework/api/getBalance/rejectBalanceOptions";
import { craftTransactionData } from "@ledgerhq/coin-module-framework/logic/craftTransactionData";
import coinConfig from "../config";
import { broadcast, combine, craftTransaction, estimateFees, getBalance, getBlock, getBlockInfo, lastBlock, listOperations as listOperationsLogic, validateAddress, } from "../logic";
import { defaultFetchParams, getBlock as getBlockNetwork } from "../network";
const MAX_TRONGRID_LIMIT = 200;
export function createApi(config) {
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
return {
broadcast,
combine,
craftTransaction,
craftRawTransaction: (_transaction, _sender, _publicKey, _sequence) => {
throw new Error("craftRawTransaction is not supported");
},
estimateFees: estimate,
getBalance: (address, options) => rejectBalanceOptions(() => getBalance(address), options),
lastBlock,
listOperations,
getBlock,
getBlockInfo,
getStakes(_address, _cursor) {
throw new Error("getStakes is not supported");
},
getRewards(_address, _cursor) {
throw new Error("getRewards is not supported");
},
getValidators(_cursor) {
throw new Error("getValidators is not supported");
},
validateIntent: async (_transactionIntent, _balances, _customFees) => {
throw new Error("validateIntent is not supported");
},
getNextSequence: async (_address) => {
throw new Error("getNextSequence is not supported");
},
validateAddress,
craftTransactionData,
};
}
async function estimate(transactionIntent) {
const fees = await estimateFees(transactionIntent);
return { value: fees };
}
async function listOperations(address, { minHeight, order, cursor, limit }) {
if (limit !== undefined && limit > MAX_TRONGRID_LIMIT) {
throw new Error(`limit must be <= ${MAX_TRONGRID_LIMIT} for Tron (TronGrid API restriction)`);
}
const effectiveLimit = limit ?? MAX_TRONGRID_LIMIT;
const effectiveOrder = order ?? "asc";
let minTimestamp = defaultFetchParams.minTimestamp;
if (minHeight > 0) {
const block = await getBlockNetwork(minHeight);
minTimestamp = block.time?.getTime() ?? defaultFetchParams.minTimestamp;
}
return listOperationsLogic(address, {
limit: effectiveLimit,
minTimestamp,
order: effectiveOrder,
cursor,
});
}
//# sourceMappingURL=index.js.map