@ledgerhq/coin-stellar
Version:
Ledger Stellar Coin integration
89 lines • 2.8 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const invariant_1 = __importDefault(require("invariant"));
const helpers_1 = require("@ledgerhq/coin-framework/account/helpers");
const tokens_1 = require("../bridge/tokens");
const options = [
{
name: "fee",
type: String,
desc: "how much fee",
},
{
name: "memoType",
type: String,
desc: "stellar memo type",
},
{
name: "memoValue",
type: String,
desc: "stellar memo value",
},
{
name: "mode",
type: String,
desc: "change operation type",
},
{
name: "assetIssuer",
type: String,
desc: "Asset issuer",
},
{
name: "assetCode",
type: String,
desc: "Same as token",
},
];
function inferTransactions(transactions, opts) {
return transactions.map(({ transaction, account }) => {
(0, invariant_1.default)(transaction.family === "stellar", "stellar family");
return {
...transaction,
subAccountId: account.type === "TokenAccount" ? account.id : null,
memoType: opts.memoType,
memoValue: opts.memoValue,
mode: opts.mode ?? "send",
assetCode: opts.token,
assetIssuer: opts.assetIssuer,
};
});
}
function inferAccounts(account, opts) {
(0, invariant_1.default)(account.currency.family === "stellar", "stellar family");
if (opts.subAccountId) {
const assetSubAccount = account.subAccounts?.find(a => a.id === opts.subAccountId);
if (!assetSubAccount) {
throw new Error(`${opts.subAccountId} asset not found`);
}
return [assetSubAccount];
}
if (opts.assetCode) {
const subAccounts = account.subAccounts || [];
const subAccount = subAccounts.find(sa => {
const currency = (0, helpers_1.getAccountCurrency)(sa);
return (opts.assetCode.toLowerCase() === currency.ticker.toLowerCase() ||
opts.assetCode.toLowerCase() === (0, tokens_1.getAssetIdFromTokenId)(currency.id));
});
if (!subAccount) {
throw new Error("token account '" +
opts.assetCode +
"' not found. Available: " +
subAccounts.map(t => (0, helpers_1.getAccountCurrency)(t).ticker).join(", "));
}
return [subAccount];
}
return [account];
}
function makeCliTools() {
return {
options,
inferTransactions,
inferAccounts,
};
}
exports.default = makeCliTools;
//# sourceMappingURL=cli.js.map