UNPKG

@firmachain/firma-js

Version:

The Official FirmaChain Javascript SDK written in Typescript

70 lines (69 loc) 3.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.accountFromAny = void 0; var math_1 = require("@cosmjs/math"); var proto_signing_1 = require("@cosmjs/proto-signing"); var auth_1 = require("cosmjs-types/cosmos/auth/v1beta1/auth"); var vesting_1 = require("cosmjs-types/cosmos/vesting/v1beta1/vesting"); function uint64FromProto(input) { return math_1.Uint64.fromString(input.toString()); } function accountFromBaseAccount(input) { var address = input.address, pubKey = input.pubKey, accountNumber = input.accountNumber, sequence = input.sequence; var pubkey = proto_signing_1.decodePubkey(pubKey); return { address: address, pubkey: pubkey, accountNumber: uint64FromProto(accountNumber).toNumber(), sequence: uint64FromProto(sequence).toNumber(), }; } /** * Takes an `Any` encoded account from the chain and extracts some common * `Account` information from it. This is supposed to support the most relevant * common Cosmos SDK account types. If you need support for exotic account types, * you'll need to write your own account decoder. */ function accountFromAny(input) { var _a, _b, _c, _d, _e, _f, _g; var typeUrl = input.typeUrl, value = input.value; switch (typeUrl) { // auth case "/cosmos.auth.v1beta1.BaseAccount": return accountFromBaseAccount(auth_1.BaseAccount.decode(value)); case "/cosmos.auth.v1beta1.ModuleAccount": { var baseAccount = auth_1.ModuleAccount.decode(value).baseAccount; return accountFromBaseAccount(baseAccount); } // vesting case "/cosmos.vesting.v1beta1.BaseVestingAccount": { var baseAccount = (_a = vesting_1.BaseVestingAccount.decode(value)) === null || _a === void 0 ? void 0 : _a.baseAccount; return accountFromBaseAccount(baseAccount); } case "/cosmos.vesting.v1beta1.ContinuousVestingAccount": { var baseAccount = (_c = (_b = vesting_1.ContinuousVestingAccount.decode(value)) === null || _b === void 0 ? void 0 : _b.baseVestingAccount) === null || _c === void 0 ? void 0 : _c.baseAccount; return accountFromBaseAccount(baseAccount); } case "/cosmos.vesting.v1beta1.DelayedVestingAccount": { var baseAccount = (_e = (_d = vesting_1.DelayedVestingAccount.decode(value)) === null || _d === void 0 ? void 0 : _d.baseVestingAccount) === null || _e === void 0 ? void 0 : _e.baseAccount; return accountFromBaseAccount(baseAccount); } case "/cosmos.vesting.v1beta1.PeriodicVestingAccount": { var baseAccount = (_g = (_f = vesting_1.PeriodicVestingAccount.decode(value)) === null || _f === void 0 ? void 0 : _f.baseVestingAccount) === null || _g === void 0 ? void 0 : _g.baseAccount; return accountFromBaseAccount(baseAccount); } case "/ethermint.types.v1.EthAccount": { var baseAccount = auth_1.ModuleAccount.decode(value).baseAccount; return accountFromBaseAccount(baseAccount); } default: throw new Error("Unsupported type: '" + typeUrl + "'"); } } exports.accountFromAny = accountFromAny;