Skip to main content
Glama
accounts.js2.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.accountFromAny = void 0; const math_1 = require("@cosmjs/math"); const proto_signing_1 = require("@cosmjs/proto-signing"); const utils_1 = require("@cosmjs/utils"); const auth_1 = require("cosmjs-types/cosmos/auth/v1beta1/auth"); const vesting_1 = require("cosmjs-types/cosmos/vesting/v1beta1/vesting"); function uint64FromProto(input) { return math_1.Uint64.fromString(input.toString()); } function accountFromBaseAccount(input) { const { address, pubKey, accountNumber, sequence } = input; const pubkey = pubKey ? (0, proto_signing_1.decodePubkey)(pubKey) : null; return { address: address, pubkey: pubkey, accountNumber: uint64FromProto(accountNumber).toNumber(), sequence: uint64FromProto(sequence).toNumber(), }; } /** * Basic implementation of AccountParser. 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) { const { typeUrl, value } = input; switch (typeUrl) { // auth case "/cosmos.auth.v1beta1.BaseAccount": return accountFromBaseAccount(auth_1.BaseAccount.decode(value)); case "/cosmos.auth.v1beta1.ModuleAccount": { const baseAccount = auth_1.ModuleAccount.decode(value).baseAccount; (0, utils_1.assert)(baseAccount); return accountFromBaseAccount(baseAccount); } // vesting case "/cosmos.vesting.v1beta1.BaseVestingAccount": { const baseAccount = vesting_1.BaseVestingAccount.decode(value)?.baseAccount; (0, utils_1.assert)(baseAccount); return accountFromBaseAccount(baseAccount); } case "/cosmos.vesting.v1beta1.ContinuousVestingAccount": { const baseAccount = vesting_1.ContinuousVestingAccount.decode(value)?.baseVestingAccount?.baseAccount; (0, utils_1.assert)(baseAccount); return accountFromBaseAccount(baseAccount); } case "/cosmos.vesting.v1beta1.DelayedVestingAccount": { const baseAccount = vesting_1.DelayedVestingAccount.decode(value)?.baseVestingAccount?.baseAccount; (0, utils_1.assert)(baseAccount); return accountFromBaseAccount(baseAccount); } case "/cosmos.vesting.v1beta1.PeriodicVestingAccount": { const baseAccount = vesting_1.PeriodicVestingAccount.decode(value)?.baseVestingAccount?.baseAccount; (0, utils_1.assert)(baseAccount); return accountFromBaseAccount(baseAccount); } default: throw new Error(`Unsupported type: '${typeUrl}'`); } } exports.accountFromAny = accountFromAny; //# sourceMappingURL=accounts.js.map

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MyronKoch-dev/osmosis-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server