UNPKG

interchainjs

Version:

InterchainJS is a JavaScript library for interacting with Cosmos SDK based blockchains.

1,270 lines 103 kB
import { Header } from "../../../tendermint/types/types"; import { Timestamp } from "../../../google/protobuf/timestamp"; import { Any } from "../../../google/protobuf/any"; import { Duration } from "../../../google/protobuf/duration"; import { Coin } from "../../base/v1beta1/coin"; import { ValidatorUpdate } from "../../../tendermint/abci/types"; import { BinaryReader, BinaryWriter } from "../../../binary"; import { GlobalDecoderRegistry } from "../../../registry"; import { toTimestamp, fromTimestamp, isSet } from "../../../helpers"; import { Decimal } from "@interchainjs/math"; import { encodePubkey, decodePubkey } from "@interchainjs/pubkey"; /** BondStatus is the status of a validator. */ export var BondStatus; (function (BondStatus) { /** BOND_STATUS_UNSPECIFIED - UNSPECIFIED defines an invalid validator status. */ BondStatus[BondStatus["BOND_STATUS_UNSPECIFIED"] = 0] = "BOND_STATUS_UNSPECIFIED"; /** BOND_STATUS_UNBONDED - UNBONDED defines a validator that is not bonded. */ BondStatus[BondStatus["BOND_STATUS_UNBONDED"] = 1] = "BOND_STATUS_UNBONDED"; /** BOND_STATUS_UNBONDING - UNBONDING defines a validator that is unbonding. */ BondStatus[BondStatus["BOND_STATUS_UNBONDING"] = 2] = "BOND_STATUS_UNBONDING"; /** BOND_STATUS_BONDED - BONDED defines a validator that is bonded. */ BondStatus[BondStatus["BOND_STATUS_BONDED"] = 3] = "BOND_STATUS_BONDED"; BondStatus[BondStatus["UNRECOGNIZED"] = -1] = "UNRECOGNIZED"; })(BondStatus || (BondStatus = {})); export const BondStatusAmino = BondStatus; export function bondStatusFromJSON(object) { switch (object) { case 0: case "BOND_STATUS_UNSPECIFIED": return BondStatus.BOND_STATUS_UNSPECIFIED; case 1: case "BOND_STATUS_UNBONDED": return BondStatus.BOND_STATUS_UNBONDED; case 2: case "BOND_STATUS_UNBONDING": return BondStatus.BOND_STATUS_UNBONDING; case 3: case "BOND_STATUS_BONDED": return BondStatus.BOND_STATUS_BONDED; case -1: case "UNRECOGNIZED": default: return BondStatus.UNRECOGNIZED; } } export function bondStatusToJSON(object) { switch (object) { case BondStatus.BOND_STATUS_UNSPECIFIED: return "BOND_STATUS_UNSPECIFIED"; case BondStatus.BOND_STATUS_UNBONDED: return "BOND_STATUS_UNBONDED"; case BondStatus.BOND_STATUS_UNBONDING: return "BOND_STATUS_UNBONDING"; case BondStatus.BOND_STATUS_BONDED: return "BOND_STATUS_BONDED"; case BondStatus.UNRECOGNIZED: default: return "UNRECOGNIZED"; } } /** Infraction indicates the infraction a validator commited. */ export var Infraction; (function (Infraction) { /** INFRACTION_UNSPECIFIED - UNSPECIFIED defines an empty infraction. */ Infraction[Infraction["INFRACTION_UNSPECIFIED"] = 0] = "INFRACTION_UNSPECIFIED"; /** INFRACTION_DOUBLE_SIGN - DOUBLE_SIGN defines a validator that double-signs a block. */ Infraction[Infraction["INFRACTION_DOUBLE_SIGN"] = 1] = "INFRACTION_DOUBLE_SIGN"; /** INFRACTION_DOWNTIME - DOWNTIME defines a validator that missed signing too many blocks. */ Infraction[Infraction["INFRACTION_DOWNTIME"] = 2] = "INFRACTION_DOWNTIME"; Infraction[Infraction["UNRECOGNIZED"] = -1] = "UNRECOGNIZED"; })(Infraction || (Infraction = {})); export const InfractionAmino = Infraction; export function infractionFromJSON(object) { switch (object) { case 0: case "INFRACTION_UNSPECIFIED": return Infraction.INFRACTION_UNSPECIFIED; case 1: case "INFRACTION_DOUBLE_SIGN": return Infraction.INFRACTION_DOUBLE_SIGN; case 2: case "INFRACTION_DOWNTIME": return Infraction.INFRACTION_DOWNTIME; case -1: case "UNRECOGNIZED": default: return Infraction.UNRECOGNIZED; } } export function infractionToJSON(object) { switch (object) { case Infraction.INFRACTION_UNSPECIFIED: return "INFRACTION_UNSPECIFIED"; case Infraction.INFRACTION_DOUBLE_SIGN: return "INFRACTION_DOUBLE_SIGN"; case Infraction.INFRACTION_DOWNTIME: return "INFRACTION_DOWNTIME"; case Infraction.UNRECOGNIZED: default: return "UNRECOGNIZED"; } } function createBaseHistoricalInfo() { return { header: Header.fromPartial({}), valset: [] }; } /** * HistoricalInfo contains header and validator information for a given block. * It is stored as part of staking module's state, which persists the `n` most * recent HistoricalInfo * (`n` is set by the staking module's `historical_entries` parameter). * @name HistoricalInfo * @package cosmos.staking.v1beta1 * @see proto type: cosmos.staking.v1beta1.HistoricalInfo */ export const HistoricalInfo = { typeUrl: "/cosmos.staking.v1beta1.HistoricalInfo", aminoType: "cosmos-sdk/HistoricalInfo", is(o) { return o && (o.$typeUrl === HistoricalInfo.typeUrl || Header.is(o.header) && Array.isArray(o.valset) && (!o.valset.length || Validator.is(o.valset[0]))); }, isAmino(o) { return o && (o.$typeUrl === HistoricalInfo.typeUrl || Header.isAmino(o.header) && Array.isArray(o.valset) && (!o.valset.length || Validator.isAmino(o.valset[0]))); }, encode(message, writer = BinaryWriter.create()) { if (message.header !== undefined) { Header.encode(message.header, writer.uint32(10).fork()).ldelim(); } for (const v of message.valset) { Validator.encode(v, writer.uint32(18).fork()).ldelim(); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseHistoricalInfo(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.header = Header.decode(reader, reader.uint32()); break; case 2: message.valset.push(Validator.decode(reader, reader.uint32())); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseHistoricalInfo(); message.header = object.header !== undefined && object.header !== null ? Header.fromPartial(object.header) : undefined; message.valset = object.valset?.map(e => Validator.fromPartial(e)) || []; return message; }, fromAmino(object) { const message = createBaseHistoricalInfo(); if (object.header !== undefined && object.header !== null) { message.header = Header.fromAmino(object.header); } message.valset = object.valset?.map(e => Validator.fromAmino(e)) || []; return message; }, toAmino(message) { const obj = {}; obj.header = message.header ? Header.toAmino(message.header) : Header.toAmino(Header.fromPartial({})); if (message.valset) { obj.valset = message.valset.map(e => e ? Validator.toAmino(e) : undefined); } else { obj.valset = message.valset; } return obj; }, fromAminoMsg(object) { return HistoricalInfo.fromAmino(object.value); }, toAminoMsg(message) { return { type: "cosmos-sdk/HistoricalInfo", value: HistoricalInfo.toAmino(message) }; }, fromProtoMsg(message) { return HistoricalInfo.decode(message.value); }, toProto(message) { return HistoricalInfo.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/cosmos.staking.v1beta1.HistoricalInfo", value: HistoricalInfo.encode(message).finish() }; }, registerTypeUrl() { if (!GlobalDecoderRegistry.registerExistingTypeUrl(HistoricalInfo.typeUrl)) { return; } Header.registerTypeUrl(); Validator.registerTypeUrl(); } }; function createBaseCommissionRates() { return { rate: "", maxRate: "", maxChangeRate: "" }; } /** * CommissionRates defines the initial commission rates to be used for creating * a validator. * @name CommissionRates * @package cosmos.staking.v1beta1 * @see proto type: cosmos.staking.v1beta1.CommissionRates */ export const CommissionRates = { typeUrl: "/cosmos.staking.v1beta1.CommissionRates", aminoType: "cosmos-sdk/CommissionRates", is(o) { return o && (o.$typeUrl === CommissionRates.typeUrl || typeof o.rate === "string" && typeof o.maxRate === "string" && typeof o.maxChangeRate === "string"); }, isAmino(o) { return o && (o.$typeUrl === CommissionRates.typeUrl || typeof o.rate === "string" && typeof o.max_rate === "string" && typeof o.max_change_rate === "string"); }, encode(message, writer = BinaryWriter.create()) { if (message.rate !== "") { writer.uint32(10).string(Decimal.fromUserInput(message.rate, 18).atomics); } if (message.maxRate !== "") { writer.uint32(18).string(Decimal.fromUserInput(message.maxRate, 18).atomics); } if (message.maxChangeRate !== "") { writer.uint32(26).string(Decimal.fromUserInput(message.maxChangeRate, 18).atomics); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseCommissionRates(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.rate = Decimal.fromAtomics(reader.string(), 18).toString(); break; case 2: message.maxRate = Decimal.fromAtomics(reader.string(), 18).toString(); break; case 3: message.maxChangeRate = Decimal.fromAtomics(reader.string(), 18).toString(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseCommissionRates(); message.rate = object.rate ?? ""; message.maxRate = object.maxRate ?? ""; message.maxChangeRate = object.maxChangeRate ?? ""; return message; }, fromAmino(object) { const message = createBaseCommissionRates(); if (object.rate !== undefined && object.rate !== null) { message.rate = object.rate; } if (object.max_rate !== undefined && object.max_rate !== null) { message.maxRate = object.max_rate; } if (object.max_change_rate !== undefined && object.max_change_rate !== null) { message.maxChangeRate = object.max_change_rate; } return message; }, toAmino(message) { const obj = {}; obj.rate = Decimal.fromUserInput(message.rate, 18).atomics ?? ""; obj.max_rate = Decimal.fromUserInput(message.maxRate, 18).atomics ?? ""; obj.max_change_rate = Decimal.fromUserInput(message.maxChangeRate, 18).atomics ?? ""; return obj; }, fromAminoMsg(object) { return CommissionRates.fromAmino(object.value); }, toAminoMsg(message) { return { type: "cosmos-sdk/CommissionRates", value: CommissionRates.toAmino(message) }; }, fromProtoMsg(message) { return CommissionRates.decode(message.value); }, toProto(message) { return CommissionRates.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/cosmos.staking.v1beta1.CommissionRates", value: CommissionRates.encode(message).finish() }; }, registerTypeUrl() { } }; function createBaseCommission() { return { commissionRates: CommissionRates.fromPartial({}), updateTime: new Date() }; } /** * Commission defines commission parameters for a given validator. * @name Commission * @package cosmos.staking.v1beta1 * @see proto type: cosmos.staking.v1beta1.Commission */ export const Commission = { typeUrl: "/cosmos.staking.v1beta1.Commission", aminoType: "cosmos-sdk/Commission", is(o) { return o && (o.$typeUrl === Commission.typeUrl || CommissionRates.is(o.commissionRates) && Timestamp.is(o.updateTime)); }, isAmino(o) { return o && (o.$typeUrl === Commission.typeUrl || CommissionRates.isAmino(o.commission_rates) && Timestamp.isAmino(o.update_time)); }, encode(message, writer = BinaryWriter.create()) { if (message.commissionRates !== undefined) { CommissionRates.encode(message.commissionRates, writer.uint32(10).fork()).ldelim(); } if (message.updateTime !== undefined) { Timestamp.encode(toTimestamp(message.updateTime), writer.uint32(18).fork()).ldelim(); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseCommission(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.commissionRates = CommissionRates.decode(reader, reader.uint32()); break; case 2: message.updateTime = fromTimestamp(Timestamp.decode(reader, reader.uint32())); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseCommission(); message.commissionRates = object.commissionRates !== undefined && object.commissionRates !== null ? CommissionRates.fromPartial(object.commissionRates) : undefined; message.updateTime = object.updateTime ?? undefined; return message; }, fromAmino(object) { const message = createBaseCommission(); if (object.commission_rates !== undefined && object.commission_rates !== null) { message.commissionRates = CommissionRates.fromAmino(object.commission_rates); } if (object.update_time !== undefined && object.update_time !== null) { message.updateTime = fromTimestamp(Timestamp.fromAmino(object.update_time)); } return message; }, toAmino(message) { const obj = {}; obj.commission_rates = message.commissionRates ? CommissionRates.toAmino(message.commissionRates) : CommissionRates.toAmino(CommissionRates.fromPartial({})); obj.update_time = message.updateTime ? Timestamp.toAmino(toTimestamp(message.updateTime)) : new Date(); return obj; }, fromAminoMsg(object) { return Commission.fromAmino(object.value); }, toAminoMsg(message) { return { type: "cosmos-sdk/Commission", value: Commission.toAmino(message) }; }, fromProtoMsg(message) { return Commission.decode(message.value); }, toProto(message) { return Commission.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/cosmos.staking.v1beta1.Commission", value: Commission.encode(message).finish() }; }, registerTypeUrl() { if (!GlobalDecoderRegistry.registerExistingTypeUrl(Commission.typeUrl)) { return; } CommissionRates.registerTypeUrl(); } }; function createBaseDescription() { return { moniker: "", identity: "", website: "", securityContact: "", details: "" }; } /** * Description defines a validator description. * @name Description * @package cosmos.staking.v1beta1 * @see proto type: cosmos.staking.v1beta1.Description */ export const Description = { typeUrl: "/cosmos.staking.v1beta1.Description", aminoType: "cosmos-sdk/Description", is(o) { return o && (o.$typeUrl === Description.typeUrl || typeof o.moniker === "string" && typeof o.identity === "string" && typeof o.website === "string" && typeof o.securityContact === "string" && typeof o.details === "string"); }, isAmino(o) { return o && (o.$typeUrl === Description.typeUrl || typeof o.moniker === "string" && typeof o.identity === "string" && typeof o.website === "string" && typeof o.security_contact === "string" && typeof o.details === "string"); }, encode(message, writer = BinaryWriter.create()) { if (message.moniker !== "") { writer.uint32(10).string(message.moniker); } if (message.identity !== "") { writer.uint32(18).string(message.identity); } if (message.website !== "") { writer.uint32(26).string(message.website); } if (message.securityContact !== "") { writer.uint32(34).string(message.securityContact); } if (message.details !== "") { writer.uint32(42).string(message.details); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseDescription(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.moniker = reader.string(); break; case 2: message.identity = reader.string(); break; case 3: message.website = reader.string(); break; case 4: message.securityContact = reader.string(); break; case 5: message.details = reader.string(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseDescription(); message.moniker = object.moniker ?? ""; message.identity = object.identity ?? ""; message.website = object.website ?? ""; message.securityContact = object.securityContact ?? ""; message.details = object.details ?? ""; return message; }, fromAmino(object) { const message = createBaseDescription(); if (object.moniker !== undefined && object.moniker !== null) { message.moniker = object.moniker; } if (object.identity !== undefined && object.identity !== null) { message.identity = object.identity; } if (object.website !== undefined && object.website !== null) { message.website = object.website; } if (object.security_contact !== undefined && object.security_contact !== null) { message.securityContact = object.security_contact; } if (object.details !== undefined && object.details !== null) { message.details = object.details; } return message; }, toAmino(message) { const obj = {}; obj.moniker = message.moniker === "" ? undefined : message.moniker; obj.identity = message.identity === "" ? undefined : message.identity; obj.website = message.website === "" ? undefined : message.website; obj.security_contact = message.securityContact === "" ? undefined : message.securityContact; obj.details = message.details === "" ? undefined : message.details; return obj; }, fromAminoMsg(object) { return Description.fromAmino(object.value); }, toAminoMsg(message) { return { type: "cosmos-sdk/Description", value: Description.toAmino(message) }; }, fromProtoMsg(message) { return Description.decode(message.value); }, toProto(message) { return Description.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/cosmos.staking.v1beta1.Description", value: Description.encode(message).finish() }; }, registerTypeUrl() { } }; function createBaseValidator() { return { operatorAddress: "", consensusPubkey: undefined, jailed: false, status: 0, tokens: "", delegatorShares: "", description: Description.fromPartial({}), unbondingHeight: BigInt(0), unbondingTime: new Date(), commission: Commission.fromPartial({}), minSelfDelegation: "", unbondingOnHoldRefCount: BigInt(0), unbondingIds: [] }; } /** * Validator defines a validator, together with the total amount of the * Validator's bond shares and their exchange rate to coins. Slashing results in * a decrease in the exchange rate, allowing correct calculation of future * undelegations without iterating over delegators. When coins are delegated to * this validator, the validator is credited with a delegation whose number of * bond shares is based on the amount of coins delegated divided by the current * exchange rate. Voting power can be calculated as total bonded shares * multiplied by exchange rate. * @name Validator * @package cosmos.staking.v1beta1 * @see proto type: cosmos.staking.v1beta1.Validator */ export const Validator = { typeUrl: "/cosmos.staking.v1beta1.Validator", aminoType: "cosmos-sdk/Validator", is(o) { return o && (o.$typeUrl === Validator.typeUrl || typeof o.operatorAddress === "string" && typeof o.jailed === "boolean" && isSet(o.status) && typeof o.tokens === "string" && typeof o.delegatorShares === "string" && Description.is(o.description) && typeof o.unbondingHeight === "bigint" && Timestamp.is(o.unbondingTime) && Commission.is(o.commission) && typeof o.minSelfDelegation === "string" && typeof o.unbondingOnHoldRefCount === "bigint" && Array.isArray(o.unbondingIds) && (!o.unbondingIds.length || typeof o.unbondingIds[0] === "bigint")); }, isAmino(o) { return o && (o.$typeUrl === Validator.typeUrl || typeof o.operator_address === "string" && typeof o.jailed === "boolean" && isSet(o.status) && typeof o.tokens === "string" && typeof o.delegator_shares === "string" && Description.isAmino(o.description) && typeof o.unbonding_height === "bigint" && Timestamp.isAmino(o.unbonding_time) && Commission.isAmino(o.commission) && typeof o.min_self_delegation === "string" && typeof o.unbonding_on_hold_ref_count === "bigint" && Array.isArray(o.unbonding_ids) && (!o.unbonding_ids.length || typeof o.unbonding_ids[0] === "bigint")); }, encode(message, writer = BinaryWriter.create()) { if (message.operatorAddress !== "") { writer.uint32(10).string(message.operatorAddress); } if (message.consensusPubkey !== undefined) { Any.encode(GlobalDecoderRegistry.wrapAny(message.consensusPubkey), writer.uint32(18).fork()).ldelim(); } if (message.jailed === true) { writer.uint32(24).bool(message.jailed); } if (message.status !== 0) { writer.uint32(32).int32(message.status); } if (message.tokens !== "") { writer.uint32(42).string(message.tokens); } if (message.delegatorShares !== "") { writer.uint32(50).string(Decimal.fromUserInput(message.delegatorShares, 18).atomics); } if (message.description !== undefined) { Description.encode(message.description, writer.uint32(58).fork()).ldelim(); } if (message.unbondingHeight !== BigInt(0)) { writer.uint32(64).int64(message.unbondingHeight); } if (message.unbondingTime !== undefined) { Timestamp.encode(toTimestamp(message.unbondingTime), writer.uint32(74).fork()).ldelim(); } if (message.commission !== undefined) { Commission.encode(message.commission, writer.uint32(82).fork()).ldelim(); } if (message.minSelfDelegation !== "") { writer.uint32(90).string(message.minSelfDelegation); } if (message.unbondingOnHoldRefCount !== BigInt(0)) { writer.uint32(96).int64(message.unbondingOnHoldRefCount); } writer.uint32(106).fork(); for (const v of message.unbondingIds) { writer.uint64(v); } writer.ldelim(); return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseValidator(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.operatorAddress = reader.string(); break; case 2: message.consensusPubkey = GlobalDecoderRegistry.unwrapAny(reader); break; case 3: message.jailed = reader.bool(); break; case 4: message.status = reader.int32(); break; case 5: message.tokens = reader.string(); break; case 6: message.delegatorShares = Decimal.fromAtomics(reader.string(), 18).toString(); break; case 7: message.description = Description.decode(reader, reader.uint32()); break; case 8: message.unbondingHeight = reader.int64(); break; case 9: message.unbondingTime = fromTimestamp(Timestamp.decode(reader, reader.uint32())); break; case 10: message.commission = Commission.decode(reader, reader.uint32()); break; case 11: message.minSelfDelegation = reader.string(); break; case 12: message.unbondingOnHoldRefCount = reader.int64(); break; case 13: if ((tag & 7) === 2) { const end2 = reader.uint32() + reader.pos; while (reader.pos < end2) { message.unbondingIds.push(reader.uint64()); } } else { message.unbondingIds.push(reader.uint64()); } break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseValidator(); message.operatorAddress = object.operatorAddress ?? ""; message.consensusPubkey = object.consensusPubkey !== undefined && object.consensusPubkey !== null ? GlobalDecoderRegistry.fromPartial(object.consensusPubkey) : undefined; message.jailed = object.jailed ?? false; message.status = object.status ?? 0; message.tokens = object.tokens ?? ""; message.delegatorShares = object.delegatorShares ?? ""; message.description = object.description !== undefined && object.description !== null ? Description.fromPartial(object.description) : undefined; message.unbondingHeight = object.unbondingHeight !== undefined && object.unbondingHeight !== null ? BigInt(object.unbondingHeight.toString()) : BigInt(0); message.unbondingTime = object.unbondingTime ?? undefined; message.commission = object.commission !== undefined && object.commission !== null ? Commission.fromPartial(object.commission) : undefined; message.minSelfDelegation = object.minSelfDelegation ?? ""; message.unbondingOnHoldRefCount = object.unbondingOnHoldRefCount !== undefined && object.unbondingOnHoldRefCount !== null ? BigInt(object.unbondingOnHoldRefCount.toString()) : BigInt(0); message.unbondingIds = object.unbondingIds?.map(e => BigInt(e.toString())) || []; return message; }, fromAmino(object) { const message = createBaseValidator(); if (object.operator_address !== undefined && object.operator_address !== null) { message.operatorAddress = object.operator_address; } if (object.consensus_pubkey !== undefined && object.consensus_pubkey !== null) { message.consensusPubkey = encodePubkey(object.consensus_pubkey); } if (object.jailed !== undefined && object.jailed !== null) { message.jailed = object.jailed; } if (object.status !== undefined && object.status !== null) { message.status = object.status; } if (object.tokens !== undefined && object.tokens !== null) { message.tokens = object.tokens; } if (object.delegator_shares !== undefined && object.delegator_shares !== null) { message.delegatorShares = object.delegator_shares; } if (object.description !== undefined && object.description !== null) { message.description = Description.fromAmino(object.description); } if (object.unbonding_height !== undefined && object.unbonding_height !== null) { message.unbondingHeight = BigInt(object.unbonding_height); } if (object.unbonding_time !== undefined && object.unbonding_time !== null) { message.unbondingTime = fromTimestamp(Timestamp.fromAmino(object.unbonding_time)); } if (object.commission !== undefined && object.commission !== null) { message.commission = Commission.fromAmino(object.commission); } if (object.min_self_delegation !== undefined && object.min_self_delegation !== null) { message.minSelfDelegation = object.min_self_delegation; } if (object.unbonding_on_hold_ref_count !== undefined && object.unbonding_on_hold_ref_count !== null) { message.unbondingOnHoldRefCount = BigInt(object.unbonding_on_hold_ref_count); } message.unbondingIds = object.unbonding_ids?.map(e => BigInt(e)) || []; return message; }, toAmino(message) { const obj = {}; obj.operator_address = message.operatorAddress === "" ? undefined : message.operatorAddress; obj.consensus_pubkey = message.consensusPubkey ? decodePubkey(message.consensusPubkey) : undefined; obj.jailed = message.jailed === false ? undefined : message.jailed; obj.status = message.status === 0 ? undefined : message.status; obj.tokens = message.tokens === "" ? undefined : message.tokens; obj.delegator_shares = message.delegatorShares === "" ? undefined : Decimal.fromUserInput(message.delegatorShares, 18).atomics; obj.description = message.description ? Description.toAmino(message.description) : Description.toAmino(Description.fromPartial({})); obj.unbonding_height = message.unbondingHeight !== BigInt(0) ? message.unbondingHeight?.toString() : undefined; obj.unbonding_time = message.unbondingTime ? Timestamp.toAmino(toTimestamp(message.unbondingTime)) : new Date(); obj.commission = message.commission ? Commission.toAmino(message.commission) : Commission.toAmino(Commission.fromPartial({})); obj.min_self_delegation = message.minSelfDelegation === "" ? undefined : message.minSelfDelegation; obj.unbonding_on_hold_ref_count = message.unbondingOnHoldRefCount !== BigInt(0) ? message.unbondingOnHoldRefCount?.toString() : undefined; if (message.unbondingIds) { obj.unbonding_ids = message.unbondingIds.map(e => e.toString()); } else { obj.unbonding_ids = message.unbondingIds; } return obj; }, fromAminoMsg(object) { return Validator.fromAmino(object.value); }, toAminoMsg(message) { return { type: "cosmos-sdk/Validator", value: Validator.toAmino(message) }; }, fromProtoMsg(message) { return Validator.decode(message.value); }, toProto(message) { return Validator.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/cosmos.staking.v1beta1.Validator", value: Validator.encode(message).finish() }; }, registerTypeUrl() { if (!GlobalDecoderRegistry.registerExistingTypeUrl(Validator.typeUrl)) { return; } Description.registerTypeUrl(); Commission.registerTypeUrl(); } }; function createBaseValAddresses() { return { addresses: [] }; } /** * ValAddresses defines a repeated set of validator addresses. * @name ValAddresses * @package cosmos.staking.v1beta1 * @see proto type: cosmos.staking.v1beta1.ValAddresses */ export const ValAddresses = { typeUrl: "/cosmos.staking.v1beta1.ValAddresses", aminoType: "cosmos-sdk/ValAddresses", is(o) { return o && (o.$typeUrl === ValAddresses.typeUrl || Array.isArray(o.addresses) && (!o.addresses.length || typeof o.addresses[0] === "string")); }, isAmino(o) { return o && (o.$typeUrl === ValAddresses.typeUrl || Array.isArray(o.addresses) && (!o.addresses.length || typeof o.addresses[0] === "string")); }, encode(message, writer = BinaryWriter.create()) { for (const v of message.addresses) { writer.uint32(10).string(v); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseValAddresses(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.addresses.push(reader.string()); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseValAddresses(); message.addresses = object.addresses?.map(e => e) || []; return message; }, fromAmino(object) { const message = createBaseValAddresses(); message.addresses = object.addresses?.map(e => e) || []; return message; }, toAmino(message) { const obj = {}; if (message.addresses) { obj.addresses = message.addresses.map(e => e); } else { obj.addresses = message.addresses; } return obj; }, fromAminoMsg(object) { return ValAddresses.fromAmino(object.value); }, toAminoMsg(message) { return { type: "cosmos-sdk/ValAddresses", value: ValAddresses.toAmino(message) }; }, fromProtoMsg(message) { return ValAddresses.decode(message.value); }, toProto(message) { return ValAddresses.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/cosmos.staking.v1beta1.ValAddresses", value: ValAddresses.encode(message).finish() }; }, registerTypeUrl() { } }; function createBaseDVPair() { return { delegatorAddress: "", validatorAddress: "" }; } /** * DVPair is struct that just has a delegator-validator pair with no other data. * It is intended to be used as a marshalable pointer. For example, a DVPair can * be used to construct the key to getting an UnbondingDelegation from state. * @name DVPair * @package cosmos.staking.v1beta1 * @see proto type: cosmos.staking.v1beta1.DVPair */ export const DVPair = { typeUrl: "/cosmos.staking.v1beta1.DVPair", aminoType: "cosmos-sdk/DVPair", is(o) { return o && (o.$typeUrl === DVPair.typeUrl || typeof o.delegatorAddress === "string" && typeof o.validatorAddress === "string"); }, isAmino(o) { return o && (o.$typeUrl === DVPair.typeUrl || typeof o.delegator_address === "string" && typeof o.validator_address === "string"); }, encode(message, writer = BinaryWriter.create()) { if (message.delegatorAddress !== "") { writer.uint32(10).string(message.delegatorAddress); } if (message.validatorAddress !== "") { writer.uint32(18).string(message.validatorAddress); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseDVPair(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.delegatorAddress = reader.string(); break; case 2: message.validatorAddress = reader.string(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseDVPair(); message.delegatorAddress = object.delegatorAddress ?? ""; message.validatorAddress = object.validatorAddress ?? ""; return message; }, fromAmino(object) { const message = createBaseDVPair(); if (object.delegator_address !== undefined && object.delegator_address !== null) { message.delegatorAddress = object.delegator_address; } if (object.validator_address !== undefined && object.validator_address !== null) { message.validatorAddress = object.validator_address; } return message; }, toAmino(message) { const obj = {}; obj.delegator_address = message.delegatorAddress === "" ? undefined : message.delegatorAddress; obj.validator_address = message.validatorAddress === "" ? undefined : message.validatorAddress; return obj; }, fromAminoMsg(object) { return DVPair.fromAmino(object.value); }, toAminoMsg(message) { return { type: "cosmos-sdk/DVPair", value: DVPair.toAmino(message) }; }, fromProtoMsg(message) { return DVPair.decode(message.value); }, toProto(message) { return DVPair.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/cosmos.staking.v1beta1.DVPair", value: DVPair.encode(message).finish() }; }, registerTypeUrl() { } }; function createBaseDVPairs() { return { pairs: [] }; } /** * DVPairs defines an array of DVPair objects. * @name DVPairs * @package cosmos.staking.v1beta1 * @see proto type: cosmos.staking.v1beta1.DVPairs */ export const DVPairs = { typeUrl: "/cosmos.staking.v1beta1.DVPairs", aminoType: "cosmos-sdk/DVPairs", is(o) { return o && (o.$typeUrl === DVPairs.typeUrl || Array.isArray(o.pairs) && (!o.pairs.length || DVPair.is(o.pairs[0]))); }, isAmino(o) { return o && (o.$typeUrl === DVPairs.typeUrl || Array.isArray(o.pairs) && (!o.pairs.length || DVPair.isAmino(o.pairs[0]))); }, encode(message, writer = BinaryWriter.create()) { for (const v of message.pairs) { DVPair.encode(v, writer.uint32(10).fork()).ldelim(); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseDVPairs(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.pairs.push(DVPair.decode(reader, reader.uint32())); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseDVPairs(); message.pairs = object.pairs?.map(e => DVPair.fromPartial(e)) || []; return message; }, fromAmino(object) { const message = createBaseDVPairs(); message.pairs = object.pairs?.map(e => DVPair.fromAmino(e)) || []; return message; }, toAmino(message) { const obj = {}; if (message.pairs) { obj.pairs = message.pairs.map(e => e ? DVPair.toAmino(e) : undefined); } else { obj.pairs = message.pairs; } return obj; }, fromAminoMsg(object) { return DVPairs.fromAmino(object.value); }, toAminoMsg(message) { return { type: "cosmos-sdk/DVPairs", value: DVPairs.toAmino(message) }; }, fromProtoMsg(message) { return DVPairs.decode(message.value); }, toProto(message) { return DVPairs.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/cosmos.staking.v1beta1.DVPairs", value: DVPairs.encode(message).finish() }; }, registerTypeUrl() { if (!GlobalDecoderRegistry.registerExistingTypeUrl(DVPairs.typeUrl)) { return; } DVPair.registerTypeUrl(); } }; function createBaseDVVTriplet() { return { delegatorAddress: "", validatorSrcAddress: "", validatorDstAddress: "" }; } /** * DVVTriplet is struct that just has a delegator-validator-validator triplet * with no other data. It is intended to be used as a marshalable pointer. For * example, a DVVTriplet can be used to construct the key to getting a * Redelegation from state. * @name DVVTriplet * @package cosmos.staking.v1beta1 * @see proto type: cosmos.staking.v1beta1.DVVTriplet */ export const DVVTriplet = { typeUrl: "/cosmos.staking.v1beta1.DVVTriplet", aminoType: "cosmos-sdk/DVVTriplet", is(o) { return o && (o.$typeUrl === DVVTriplet.typeUrl || typeof o.delegatorAddress === "string" && typeof o.validatorSrcAddress === "string" && typeof o.validatorDstAddress === "string"); }, isAmino(o) { return o && (o.$typeUrl === DVVTriplet.typeUrl || typeof o.delegator_address === "string" && typeof o.validator_src_address === "string" && typeof o.validator_dst_address === "string"); }, encode(message, writer = BinaryWriter.create()) { if (message.delegatorAddress !== "") { writer.uint32(10).string(message.delegatorAddress); } if (message.validatorSrcAddress !== "") { writer.uint32(18).string(message.validatorSrcAddress); } if (message.validatorDstAddress !== "") { writer.uint32(26).string(message.validatorDstAddress); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseDVVTriplet(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.delegatorAddress = reader.string(); break; case 2: message.validatorSrcAddress = reader.string(); break; case 3: message.validatorDstAddress = reader.string(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseDVVTriplet(); message.delegatorAddress = object.delegatorAddress ?? ""; message.validatorSrcAddress = object.validatorSrcAddress ?? ""; message.validatorDstAddress = object.validatorDstAddress ?? ""; return message; }, fromAmino(object) { const message = createBaseDVVTriplet(); if (object.delegator_address !== undefined && object.delegator_address !== null) { message.delegatorAddress = object.delegator_address; } if (object.validator_src_address !== undefined && object.validator_src_address !== null) { message.validatorSrcAddress = object.validator_src_address; } if (object.validator_dst_address !== undefined && object.validator_dst_address !== null) { message.validatorDstAddress = object.validator_dst_address; } return message; }, toAmino(message) { const obj = {}; obj.delegator_address = message.delegatorAddress === "" ? undefined : message.delegatorAddress; obj.validator_src_address = message.validatorSrcAddress === "" ? undefined : message.validatorSrcAddress; obj.validator_dst_address = message.validatorDstAddress === "" ? undefined : message.validatorDstAddress; return obj; }, fromAminoMsg(object) { return DVVTriplet.fromAmino(object.value); }, toAminoMsg(message) { return { type: "cosmos-sdk/DVVTriplet", value: DVVTriplet.toAmino(message) }; }, fromProtoMsg(message) { return DVVTriplet.decode(message.value); }, toProto(message) { return DVVTriplet.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/cosmos.staking.v1beta1.DVVTriplet", value: DVVTriplet.encode(message).finish() }; }, registerTypeUrl() { } }; function createBaseDVVTriplets() { return { triplets: [] }; } /** * DVVTriplets defines an array of DVVTriplet objects. * @name DVVTriplets * @package cosmos.staking.v1beta1 * @see proto type: cosmos.staking.v1beta1.DVVTriplets */ export const DVVTriplets = { typeUrl: "/cosmos.staking.v1beta1.DVVTriplets", aminoType: "cosmos-sdk/DVVTriplets", is(o) { return o && (o.$typeUrl === DVVTriplets.typeUrl || Array.isArray(o.triplets) && (!o.triplets.length || DVVTriplet.is(o.triplets[0]))); }, isAmino(o) { return o && (o.$typeUrl === DVVTriplets.typeUrl || Array.isArray(o.triplets) && (!o.triplets.length || DVVTriplet.isAmino(o.triplets[0]))); }, encode(message, writer = BinaryWriter.create()) { for (const v of message.triplets) { DVVTriplet.encode(v, writer.uint32(10).fork()).ldelim(); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseDVVTriplets(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.triplets.push(DVVTriplet.decode(reader, reader.uint32())); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseDVVTriplets(); message.triplets = object.triplets?.map(e => DVVTriplet.fromPartial(e)) || []; return message; }, fromAmino(object) { const message = createBaseDVVTriplets(); message.triplets = object.triplets?.map(e => DVVTriplet.fromAmino(e)) || []; return message; }, toAmino(message) { const obj = {}; if (message.triplets) { obj.triplets = message.triplets.map(e => e ? DVVTriplet.toAmino(e) : undefined); } else { obj.triplets = message.triplets; } return obj; }, fromAminoMsg(object) { return DVVTriplets.fromAmino(object.value); }, toAminoMsg(message) { return { type: "cosmos-sdk/DVVTriplets", value: DVVTriplets.toAmino(message) }; }, fromProtoMsg(message) { return DVVTriplets.decode(message.value); }, toProto(message) { return DVVTriplets.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/cosmos.staking.v1beta1.DVVTriplets", value: DVVTriplets.encode(message).finish() }; }, registerType