@ledgerhq/coin-celo
Version:
50 lines • 1.57 kB
JavaScript
import { from } from "rxjs";
import { map } from "rxjs/operators";
import { getValidatorGroups } from "../network";
import invariant from "invariant";
import flatMap from "lodash/flatMap";
const options = [
{
name: "mode",
type: String,
desc: "mode of transaction: send, lock, unlock, withdraw, vote, revoke, activate, register",
},
{
name: "transactionIndex",
type: String,
desc: "transaction index of a pending withdraw in case of withdraw mode",
},
];
function inferAccounts(account) {
invariant(account.currency.family === "celo", "celo family");
const accounts = [account];
return accounts;
}
function inferTransactions(transactions, opts) {
const mode = opts.mode || "send";
invariant(["send", "lock", "unlock", "withdraw", "vote", "revoke", "activate", "register"].includes(mode), `Unexpected mode: ${mode}`);
return flatMap(transactions, ({ transaction }) => {
invariant(transaction.family === "celo", "celo family");
return {
...transaction,
family: "celo",
mode,
index: opts.transactionIndex || null,
};
});
}
const celoValidatorGroups = {
args: [],
job: () => from(getValidatorGroups()).pipe(map(validatorGroup => JSON.stringify(validatorGroup))),
};
export default function makeCliTools() {
return {
options,
inferAccounts,
inferTransactions,
commands: {
celoValidatorGroups,
},
};
}
//# sourceMappingURL=cli-transaction.js.map