UNPKG

@ledgerhq/coin-tron

Version:
69 lines 3.03 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createApi = createApi; const rejectBalanceOptions_1 = require("@ledgerhq/coin-module-framework/api/getBalance/rejectBalanceOptions"); const craftTransactionData_1 = require("@ledgerhq/coin-module-framework/logic/craftTransactionData"); const config_1 = __importDefault(require("../config")); const logic_1 = require("../logic"); const network_1 = require("../network"); const MAX_TRONGRID_LIMIT = 200; function createApi(config) { config_1.default.setCoinConfig(() => ({ ...config, status: { type: "active" } })); return { broadcast: logic_1.broadcast, combine: logic_1.combine, craftTransaction: logic_1.craftTransaction, craftRawTransaction: (_transaction, _sender, _publicKey, _sequence) => { throw new Error("craftRawTransaction is not supported"); }, estimateFees: estimate, getBalance: (address, options) => (0, rejectBalanceOptions_1.rejectBalanceOptions)(() => (0, logic_1.getBalance)(address), options), lastBlock: logic_1.lastBlock, listOperations, getBlock: logic_1.getBlock, getBlockInfo: logic_1.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: logic_1.validateAddress, craftTransactionData: craftTransactionData_1.craftTransactionData, }; } async function estimate(transactionIntent) { const fees = await (0, logic_1.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 = network_1.defaultFetchParams.minTimestamp; if (minHeight > 0) { const block = await (0, network_1.getBlock)(minHeight); minTimestamp = block.time?.getTime() ?? network_1.defaultFetchParams.minTimestamp; } return (0, logic_1.listOperations)(address, { limit: effectiveLimit, minTimestamp, order: effectiveOrder, cursor, }); } //# sourceMappingURL=index.js.map