UNPKG

@ledgerhq/coin-tezos

Version:
104 lines 3.47 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = makeCliTools; const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const invariant_1 = __importDefault(require("invariant")); const bignumber_js_1 = require("bignumber.js"); const flatMap_1 = __importDefault(require("lodash/flatMap")); const bakers_1 = require("../network/bakers"); const bakers_whitelist_default_1 = __importDefault(require("../network/bakers.whitelist-default")); const options = [ { name: "mode", type: String, desc: "mode of transaction", }, { name: "storageLimit", type: String, desc: "how much storageLimit. default is estimated with the recipient", }, { name: "subAccount", type: String, desc: "use a sub account instead of the parent by index", multiple: true, }, { name: "fees", type: String, desc: "how much fees", }, { name: "gasLimit", type: String, desc: "how much gasLimit. default is estimated with the recipient", }, ]; function inferAccounts(account, opts) { (0, invariant_1.default)(account.currency.family === "tezos", "tezos family"); if (!opts.subAccount) { const accounts = [account]; return accounts; } const { subAccounts } = account; (0, invariant_1.default)(subAccounts, "no sub accounts"); return opts.subAccount.map((i) => { const acc = subAccounts[i]; (0, invariant_1.default)(acc, "sub account not found (index %s)", i); return acc; }); } function inferTransactions(transactions, opts, { inferAmount }) { return (0, flatMap_1.default)(transactions, ({ transaction, account }) => { (0, invariant_1.default)(transaction.family === "tezos", "tezos family"); let subAccountId; return { ...transaction, mode: opts.mode || "send", subAccountId, fees: opts.fees ? inferAmount(account, opts.fees) : null, gasLimit: opts.gasLimit ? new bignumber_js_1.BigNumber(opts.gasLimit) : null, storageLimit: opts.storageLimit ? new bignumber_js_1.BigNumber(opts.storageLimit) : null, }; }); } const bakersFormatters = { json: (list) => JSON.stringify(list), default: (list) => list .map(b => `${b.address} "${b.name}" ${b.nominalYield} ${b.capacityStatus} ${b.logoURL}`) .join("\n"), }; const tezosListBakers = { args: [ { name: "whitelist", desc: "filter whitelist", type: Boolean, }, { name: "format", desc: Object.keys(bakersFormatters).join(" | "), type: String, }, ], job: ({ whitelist, format, }) => (0, rxjs_1.from)(whitelist ? (0, bakers_1.listBakers)(bakers_whitelist_default_1.default) : (0, bakers_1.fetchAllBakers)()).pipe((0, operators_1.map)((list) => { const f = (format && bakersFormatters[format]) || bakersFormatters.default; return f(list); })), }; function makeCliTools() { return { options, inferAccounts, inferTransactions, commands: { tezosListBakers, }, }; } //# sourceMappingURL=cli.js.map