UNPKG

@ledgerhq/coin-casper

Version:
36 lines 1.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAccountShape = void 0; const flatMap_1 = __importDefault(require("lodash/flatMap")); const logs_1 = require("@ledgerhq/logs"); const bignumber_js_1 = __importDefault(require("bignumber.js")); const index_1 = require("@ledgerhq/coin-framework/account/index"); const index_2 = require("../../api/index"); const txn_1 = require("./txn"); const getAccountShape = async (info) => { const { address, currency, derivationMode } = info; const accountId = (0, index_1.encodeAccountId)({ type: "js", version: "2", currencyId: currency.id, xpubOrAddress: address, derivationMode, }); (0, logs_1.log)("debug", `Generation account shape for ${address}`); const { purseUref, accountHash } = await (0, index_2.fetchAccountStateInfo)(address); const blockHeight = await (0, index_2.fetchBlockHeight)(); const balance = purseUref ? await (0, index_2.fetchBalance)(purseUref) : new bignumber_js_1.default(0); const txs = purseUref ? await (0, index_2.fetchTxs)(address) : []; return { id: accountId, balance, spendableBalance: balance, operations: (0, flatMap_1.default)(txs, (0, txn_1.mapTxToOps)(accountId, accountHash ?? "")), blockHeight, }; }; exports.getAccountShape = getAccountShape; //# sourceMappingURL=accountShape.js.map