diff --git a/CHANGELOG.md b/CHANGELOG.md index b9b539a7..a5a6e5fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ and this project adheres to and `StargateClient`. Added `ModuleAccount` and vesting accounts `BaseVestingAccount`, `ContinuousVestingAccount`, `DelayedVestingAccount` and `PeriodicVestingAccount`. +- @cosmjs/stargate: Add codecs for IBC channel tx, client query/tx, and + connection tx, as well as Tendermint. +- @cosmjs/stargate: Add support for IBC message types in + `SigningStargateClient`. ### Changed @@ -29,6 +33,8 @@ and this project adheres to - @cosmjs/stargate: Remove `accountFromProto` in favour of `accountFromAny`. - @cosmjs/stargate: Rename `Rpc` interface to `ProtobufRpcClient` and `createRpc` to `createProtobufRpcClient`. +- @cosmjs/stargate: Reorganize nesting structure of IBC query client and add + support for more methods. - @cosmjs/tendermint-rpc: The fields `CommitSignature.validatorAddress`, `.timestamp` and `.signature` are now optional. They are unset when `blockIdFlag` is `BlockIdFlag.Absent`. The decoding into `CommitSignature` is diff --git a/packages/stargate/scripts/define-proto.sh b/packages/stargate/scripts/define-proto.sh index d5a88522..9cbfb813 100755 --- a/packages/stargate/scripts/define-proto.sh +++ b/packages/stargate/scripts/define-proto.sh @@ -36,10 +36,15 @@ protoc \ "$COSMOS_PROTO_DIR/cosmos/vesting/v1beta1/vesting.proto" \ "$COSMOS_PROTO_DIR/ibc/core/channel/v1/channel.proto" \ "$COSMOS_PROTO_DIR/ibc/core/channel/v1/query.proto" \ + "$COSMOS_PROTO_DIR/ibc/core/channel/v1/tx.proto" \ "$COSMOS_PROTO_DIR/ibc/core/client/v1/client.proto" \ + "$COSMOS_PROTO_DIR/ibc/core/client/v1/query.proto" \ + "$COSMOS_PROTO_DIR/ibc/core/client/v1/tx.proto" \ "$COSMOS_PROTO_DIR/ibc/core/commitment/v1/commitment.proto" \ "$COSMOS_PROTO_DIR/ibc/core/connection/v1/connection.proto" \ "$COSMOS_PROTO_DIR/ibc/core/connection/v1/query.proto" \ + "$COSMOS_PROTO_DIR/ibc/core/connection/v1/tx.proto" \ + "$COSMOS_PROTO_DIR/ibc/lightclients/tendermint/v1/tendermint.proto" \ "$THIRD_PARTY_PROTO_DIR/confio/proofs.proto" \ "$THIRD_PARTY_PROTO_DIR/tendermint/abci/types.proto" \ "$THIRD_PARTY_PROTO_DIR/tendermint/crypto/keys.proto" \ diff --git a/packages/stargate/src/codec/ibc/core/channel/v1/tx.ts b/packages/stargate/src/codec/ibc/core/channel/v1/tx.ts new file mode 100644 index 00000000..a63d8a14 --- /dev/null +++ b/packages/stargate/src/codec/ibc/core/channel/v1/tx.ts @@ -0,0 +1,1925 @@ +/* eslint-disable */ +import { Channel, Packet } from "../../../../ibc/core/channel/v1/channel"; +import { Height } from "../../../../ibc/core/client/v1/client"; +import Long from "long"; +import _m0 from "protobufjs/minimal"; + +export const protobufPackage = "ibc.core.channel.v1"; + +/** + * MsgChannelOpenInit defines an sdk.Msg to initialize a channel handshake. It + * is called by a relayer on Chain A. + */ +export interface MsgChannelOpenInit { + portId: string; + channel?: Channel; + signer: string; +} + +/** MsgChannelOpenInitResponse defines the Msg/ChannelOpenInit response type. */ +export interface MsgChannelOpenInitResponse {} + +/** + * MsgChannelOpenInit defines a msg sent by a Relayer to try to open a channel + * on Chain B. + */ +export interface MsgChannelOpenTry { + portId: string; + /** + * in the case of crossing hello's, when both chains call OpenInit, we need the channel identifier + * of the previous channel in state INIT + */ + previousChannelId: string; + channel?: Channel; + counterpartyVersion: string; + proofInit: Uint8Array; + proofHeight?: Height; + signer: string; +} + +/** MsgChannelOpenTryResponse defines the Msg/ChannelOpenTry response type. */ +export interface MsgChannelOpenTryResponse {} + +/** + * MsgChannelOpenAck defines a msg sent by a Relayer to Chain A to acknowledge + * the change of channel state to TRYOPEN on Chain B. + */ +export interface MsgChannelOpenAck { + portId: string; + channelId: string; + counterpartyChannelId: string; + counterpartyVersion: string; + proofTry: Uint8Array; + proofHeight?: Height; + signer: string; +} + +/** MsgChannelOpenAckResponse defines the Msg/ChannelOpenAck response type. */ +export interface MsgChannelOpenAckResponse {} + +/** + * MsgChannelOpenConfirm defines a msg sent by a Relayer to Chain B to + * acknowledge the change of channel state to OPEN on Chain A. + */ +export interface MsgChannelOpenConfirm { + portId: string; + channelId: string; + proofAck: Uint8Array; + proofHeight?: Height; + signer: string; +} + +/** MsgChannelOpenConfirmResponse defines the Msg/ChannelOpenConfirm response type. */ +export interface MsgChannelOpenConfirmResponse {} + +/** + * MsgChannelCloseInit defines a msg sent by a Relayer to Chain A + * to close a channel with Chain B. + */ +export interface MsgChannelCloseInit { + portId: string; + channelId: string; + signer: string; +} + +/** MsgChannelCloseInitResponse defines the Msg/ChannelCloseInit response type. */ +export interface MsgChannelCloseInitResponse {} + +/** + * MsgChannelCloseConfirm defines a msg sent by a Relayer to Chain B + * to acknowledge the change of channel state to CLOSED on Chain A. + */ +export interface MsgChannelCloseConfirm { + portId: string; + channelId: string; + proofInit: Uint8Array; + proofHeight?: Height; + signer: string; +} + +/** MsgChannelCloseConfirmResponse defines the Msg/ChannelCloseConfirm response type. */ +export interface MsgChannelCloseConfirmResponse {} + +/** MsgRecvPacket receives incoming IBC packet */ +export interface MsgRecvPacket { + packet?: Packet; + proofCommitment: Uint8Array; + proofHeight?: Height; + signer: string; +} + +/** MsgRecvPacketResponse defines the Msg/RecvPacket response type. */ +export interface MsgRecvPacketResponse {} + +/** MsgTimeout receives timed-out packet */ +export interface MsgTimeout { + packet?: Packet; + proofUnreceived: Uint8Array; + proofHeight?: Height; + nextSequenceRecv: Long; + signer: string; +} + +/** MsgTimeoutResponse defines the Msg/Timeout response type. */ +export interface MsgTimeoutResponse {} + +/** MsgTimeoutOnClose timed-out packet upon counterparty channel closure. */ +export interface MsgTimeoutOnClose { + packet?: Packet; + proofUnreceived: Uint8Array; + proofClose: Uint8Array; + proofHeight?: Height; + nextSequenceRecv: Long; + signer: string; +} + +/** MsgTimeoutOnCloseResponse defines the Msg/TimeoutOnClose response type. */ +export interface MsgTimeoutOnCloseResponse {} + +/** MsgAcknowledgement receives incoming IBC acknowledgement */ +export interface MsgAcknowledgement { + packet?: Packet; + acknowledgement: Uint8Array; + proofAcked: Uint8Array; + proofHeight?: Height; + signer: string; +} + +/** MsgAcknowledgementResponse defines the Msg/Acknowledgement response type. */ +export interface MsgAcknowledgementResponse {} + +const baseMsgChannelOpenInit: object = { portId: "", signer: "" }; + +export const MsgChannelOpenInit = { + encode(message: MsgChannelOpenInit, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.portId !== "") { + writer.uint32(10).string(message.portId); + } + if (message.channel !== undefined) { + Channel.encode(message.channel, writer.uint32(18).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(26).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgChannelOpenInit { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgChannelOpenInit } as MsgChannelOpenInit; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.portId = reader.string(); + break; + case 2: + message.channel = Channel.decode(reader, reader.uint32()); + break; + case 3: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgChannelOpenInit { + const message = { ...baseMsgChannelOpenInit } as MsgChannelOpenInit; + if (object.portId !== undefined && object.portId !== null) { + message.portId = String(object.portId); + } else { + message.portId = ""; + } + if (object.channel !== undefined && object.channel !== null) { + message.channel = Channel.fromJSON(object.channel); + } else { + message.channel = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgChannelOpenInit): unknown { + const obj: any = {}; + message.portId !== undefined && (obj.portId = message.portId); + message.channel !== undefined && + (obj.channel = message.channel ? Channel.toJSON(message.channel) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgChannelOpenInit { + const message = { ...baseMsgChannelOpenInit } as MsgChannelOpenInit; + if (object.portId !== undefined && object.portId !== null) { + message.portId = object.portId; + } else { + message.portId = ""; + } + if (object.channel !== undefined && object.channel !== null) { + message.channel = Channel.fromPartial(object.channel); + } else { + message.channel = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgChannelOpenInitResponse: object = {}; + +export const MsgChannelOpenInitResponse = { + encode(_: MsgChannelOpenInitResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgChannelOpenInitResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgChannelOpenInitResponse } as MsgChannelOpenInitResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgChannelOpenInitResponse { + const message = { ...baseMsgChannelOpenInitResponse } as MsgChannelOpenInitResponse; + return message; + }, + + toJSON(_: MsgChannelOpenInitResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgChannelOpenInitResponse { + const message = { ...baseMsgChannelOpenInitResponse } as MsgChannelOpenInitResponse; + return message; + }, +}; + +const baseMsgChannelOpenTry: object = { + portId: "", + previousChannelId: "", + counterpartyVersion: "", + signer: "", +}; + +export const MsgChannelOpenTry = { + encode(message: MsgChannelOpenTry, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.portId !== "") { + writer.uint32(10).string(message.portId); + } + if (message.previousChannelId !== "") { + writer.uint32(18).string(message.previousChannelId); + } + if (message.channel !== undefined) { + Channel.encode(message.channel, writer.uint32(26).fork()).ldelim(); + } + if (message.counterpartyVersion !== "") { + writer.uint32(34).string(message.counterpartyVersion); + } + if (message.proofInit.length !== 0) { + writer.uint32(42).bytes(message.proofInit); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(50).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(58).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgChannelOpenTry { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgChannelOpenTry } as MsgChannelOpenTry; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.portId = reader.string(); + break; + case 2: + message.previousChannelId = reader.string(); + break; + case 3: + message.channel = Channel.decode(reader, reader.uint32()); + break; + case 4: + message.counterpartyVersion = reader.string(); + break; + case 5: + message.proofInit = reader.bytes(); + break; + case 6: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + case 7: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgChannelOpenTry { + const message = { ...baseMsgChannelOpenTry } as MsgChannelOpenTry; + if (object.portId !== undefined && object.portId !== null) { + message.portId = String(object.portId); + } else { + message.portId = ""; + } + if (object.previousChannelId !== undefined && object.previousChannelId !== null) { + message.previousChannelId = String(object.previousChannelId); + } else { + message.previousChannelId = ""; + } + if (object.channel !== undefined && object.channel !== null) { + message.channel = Channel.fromJSON(object.channel); + } else { + message.channel = undefined; + } + if (object.counterpartyVersion !== undefined && object.counterpartyVersion !== null) { + message.counterpartyVersion = String(object.counterpartyVersion); + } else { + message.counterpartyVersion = ""; + } + if (object.proofInit !== undefined && object.proofInit !== null) { + message.proofInit = bytesFromBase64(object.proofInit); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgChannelOpenTry): unknown { + const obj: any = {}; + message.portId !== undefined && (obj.portId = message.portId); + message.previousChannelId !== undefined && (obj.previousChannelId = message.previousChannelId); + message.channel !== undefined && + (obj.channel = message.channel ? Channel.toJSON(message.channel) : undefined); + message.counterpartyVersion !== undefined && (obj.counterpartyVersion = message.counterpartyVersion); + message.proofInit !== undefined && + (obj.proofInit = base64FromBytes( + message.proofInit !== undefined ? message.proofInit : new Uint8Array(), + )); + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgChannelOpenTry { + const message = { ...baseMsgChannelOpenTry } as MsgChannelOpenTry; + if (object.portId !== undefined && object.portId !== null) { + message.portId = object.portId; + } else { + message.portId = ""; + } + if (object.previousChannelId !== undefined && object.previousChannelId !== null) { + message.previousChannelId = object.previousChannelId; + } else { + message.previousChannelId = ""; + } + if (object.channel !== undefined && object.channel !== null) { + message.channel = Channel.fromPartial(object.channel); + } else { + message.channel = undefined; + } + if (object.counterpartyVersion !== undefined && object.counterpartyVersion !== null) { + message.counterpartyVersion = object.counterpartyVersion; + } else { + message.counterpartyVersion = ""; + } + if (object.proofInit !== undefined && object.proofInit !== null) { + message.proofInit = object.proofInit; + } else { + message.proofInit = new Uint8Array(); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgChannelOpenTryResponse: object = {}; + +export const MsgChannelOpenTryResponse = { + encode(_: MsgChannelOpenTryResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgChannelOpenTryResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgChannelOpenTryResponse } as MsgChannelOpenTryResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgChannelOpenTryResponse { + const message = { ...baseMsgChannelOpenTryResponse } as MsgChannelOpenTryResponse; + return message; + }, + + toJSON(_: MsgChannelOpenTryResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgChannelOpenTryResponse { + const message = { ...baseMsgChannelOpenTryResponse } as MsgChannelOpenTryResponse; + return message; + }, +}; + +const baseMsgChannelOpenAck: object = { + portId: "", + channelId: "", + counterpartyChannelId: "", + counterpartyVersion: "", + signer: "", +}; + +export const MsgChannelOpenAck = { + encode(message: MsgChannelOpenAck, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.portId !== "") { + writer.uint32(10).string(message.portId); + } + if (message.channelId !== "") { + writer.uint32(18).string(message.channelId); + } + if (message.counterpartyChannelId !== "") { + writer.uint32(26).string(message.counterpartyChannelId); + } + if (message.counterpartyVersion !== "") { + writer.uint32(34).string(message.counterpartyVersion); + } + if (message.proofTry.length !== 0) { + writer.uint32(42).bytes(message.proofTry); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(50).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(58).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgChannelOpenAck { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgChannelOpenAck } as MsgChannelOpenAck; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.portId = reader.string(); + break; + case 2: + message.channelId = reader.string(); + break; + case 3: + message.counterpartyChannelId = reader.string(); + break; + case 4: + message.counterpartyVersion = reader.string(); + break; + case 5: + message.proofTry = reader.bytes(); + break; + case 6: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + case 7: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgChannelOpenAck { + const message = { ...baseMsgChannelOpenAck } as MsgChannelOpenAck; + if (object.portId !== undefined && object.portId !== null) { + message.portId = String(object.portId); + } else { + message.portId = ""; + } + if (object.channelId !== undefined && object.channelId !== null) { + message.channelId = String(object.channelId); + } else { + message.channelId = ""; + } + if (object.counterpartyChannelId !== undefined && object.counterpartyChannelId !== null) { + message.counterpartyChannelId = String(object.counterpartyChannelId); + } else { + message.counterpartyChannelId = ""; + } + if (object.counterpartyVersion !== undefined && object.counterpartyVersion !== null) { + message.counterpartyVersion = String(object.counterpartyVersion); + } else { + message.counterpartyVersion = ""; + } + if (object.proofTry !== undefined && object.proofTry !== null) { + message.proofTry = bytesFromBase64(object.proofTry); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgChannelOpenAck): unknown { + const obj: any = {}; + message.portId !== undefined && (obj.portId = message.portId); + message.channelId !== undefined && (obj.channelId = message.channelId); + message.counterpartyChannelId !== undefined && + (obj.counterpartyChannelId = message.counterpartyChannelId); + message.counterpartyVersion !== undefined && (obj.counterpartyVersion = message.counterpartyVersion); + message.proofTry !== undefined && + (obj.proofTry = base64FromBytes(message.proofTry !== undefined ? message.proofTry : new Uint8Array())); + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgChannelOpenAck { + const message = { ...baseMsgChannelOpenAck } as MsgChannelOpenAck; + if (object.portId !== undefined && object.portId !== null) { + message.portId = object.portId; + } else { + message.portId = ""; + } + if (object.channelId !== undefined && object.channelId !== null) { + message.channelId = object.channelId; + } else { + message.channelId = ""; + } + if (object.counterpartyChannelId !== undefined && object.counterpartyChannelId !== null) { + message.counterpartyChannelId = object.counterpartyChannelId; + } else { + message.counterpartyChannelId = ""; + } + if (object.counterpartyVersion !== undefined && object.counterpartyVersion !== null) { + message.counterpartyVersion = object.counterpartyVersion; + } else { + message.counterpartyVersion = ""; + } + if (object.proofTry !== undefined && object.proofTry !== null) { + message.proofTry = object.proofTry; + } else { + message.proofTry = new Uint8Array(); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgChannelOpenAckResponse: object = {}; + +export const MsgChannelOpenAckResponse = { + encode(_: MsgChannelOpenAckResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgChannelOpenAckResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgChannelOpenAckResponse } as MsgChannelOpenAckResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgChannelOpenAckResponse { + const message = { ...baseMsgChannelOpenAckResponse } as MsgChannelOpenAckResponse; + return message; + }, + + toJSON(_: MsgChannelOpenAckResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgChannelOpenAckResponse { + const message = { ...baseMsgChannelOpenAckResponse } as MsgChannelOpenAckResponse; + return message; + }, +}; + +const baseMsgChannelOpenConfirm: object = { portId: "", channelId: "", signer: "" }; + +export const MsgChannelOpenConfirm = { + encode(message: MsgChannelOpenConfirm, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.portId !== "") { + writer.uint32(10).string(message.portId); + } + if (message.channelId !== "") { + writer.uint32(18).string(message.channelId); + } + if (message.proofAck.length !== 0) { + writer.uint32(26).bytes(message.proofAck); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(34).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(42).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgChannelOpenConfirm { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgChannelOpenConfirm } as MsgChannelOpenConfirm; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.portId = reader.string(); + break; + case 2: + message.channelId = reader.string(); + break; + case 3: + message.proofAck = reader.bytes(); + break; + case 4: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + case 5: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgChannelOpenConfirm { + const message = { ...baseMsgChannelOpenConfirm } as MsgChannelOpenConfirm; + if (object.portId !== undefined && object.portId !== null) { + message.portId = String(object.portId); + } else { + message.portId = ""; + } + if (object.channelId !== undefined && object.channelId !== null) { + message.channelId = String(object.channelId); + } else { + message.channelId = ""; + } + if (object.proofAck !== undefined && object.proofAck !== null) { + message.proofAck = bytesFromBase64(object.proofAck); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgChannelOpenConfirm): unknown { + const obj: any = {}; + message.portId !== undefined && (obj.portId = message.portId); + message.channelId !== undefined && (obj.channelId = message.channelId); + message.proofAck !== undefined && + (obj.proofAck = base64FromBytes(message.proofAck !== undefined ? message.proofAck : new Uint8Array())); + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgChannelOpenConfirm { + const message = { ...baseMsgChannelOpenConfirm } as MsgChannelOpenConfirm; + if (object.portId !== undefined && object.portId !== null) { + message.portId = object.portId; + } else { + message.portId = ""; + } + if (object.channelId !== undefined && object.channelId !== null) { + message.channelId = object.channelId; + } else { + message.channelId = ""; + } + if (object.proofAck !== undefined && object.proofAck !== null) { + message.proofAck = object.proofAck; + } else { + message.proofAck = new Uint8Array(); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgChannelOpenConfirmResponse: object = {}; + +export const MsgChannelOpenConfirmResponse = { + encode(_: MsgChannelOpenConfirmResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgChannelOpenConfirmResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgChannelOpenConfirmResponse } as MsgChannelOpenConfirmResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgChannelOpenConfirmResponse { + const message = { ...baseMsgChannelOpenConfirmResponse } as MsgChannelOpenConfirmResponse; + return message; + }, + + toJSON(_: MsgChannelOpenConfirmResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgChannelOpenConfirmResponse { + const message = { ...baseMsgChannelOpenConfirmResponse } as MsgChannelOpenConfirmResponse; + return message; + }, +}; + +const baseMsgChannelCloseInit: object = { portId: "", channelId: "", signer: "" }; + +export const MsgChannelCloseInit = { + encode(message: MsgChannelCloseInit, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.portId !== "") { + writer.uint32(10).string(message.portId); + } + if (message.channelId !== "") { + writer.uint32(18).string(message.channelId); + } + if (message.signer !== "") { + writer.uint32(26).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgChannelCloseInit { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgChannelCloseInit } as MsgChannelCloseInit; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.portId = reader.string(); + break; + case 2: + message.channelId = reader.string(); + break; + case 3: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgChannelCloseInit { + const message = { ...baseMsgChannelCloseInit } as MsgChannelCloseInit; + if (object.portId !== undefined && object.portId !== null) { + message.portId = String(object.portId); + } else { + message.portId = ""; + } + if (object.channelId !== undefined && object.channelId !== null) { + message.channelId = String(object.channelId); + } else { + message.channelId = ""; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgChannelCloseInit): unknown { + const obj: any = {}; + message.portId !== undefined && (obj.portId = message.portId); + message.channelId !== undefined && (obj.channelId = message.channelId); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgChannelCloseInit { + const message = { ...baseMsgChannelCloseInit } as MsgChannelCloseInit; + if (object.portId !== undefined && object.portId !== null) { + message.portId = object.portId; + } else { + message.portId = ""; + } + if (object.channelId !== undefined && object.channelId !== null) { + message.channelId = object.channelId; + } else { + message.channelId = ""; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgChannelCloseInitResponse: object = {}; + +export const MsgChannelCloseInitResponse = { + encode(_: MsgChannelCloseInitResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgChannelCloseInitResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgChannelCloseInitResponse } as MsgChannelCloseInitResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgChannelCloseInitResponse { + const message = { ...baseMsgChannelCloseInitResponse } as MsgChannelCloseInitResponse; + return message; + }, + + toJSON(_: MsgChannelCloseInitResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgChannelCloseInitResponse { + const message = { ...baseMsgChannelCloseInitResponse } as MsgChannelCloseInitResponse; + return message; + }, +}; + +const baseMsgChannelCloseConfirm: object = { portId: "", channelId: "", signer: "" }; + +export const MsgChannelCloseConfirm = { + encode(message: MsgChannelCloseConfirm, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.portId !== "") { + writer.uint32(10).string(message.portId); + } + if (message.channelId !== "") { + writer.uint32(18).string(message.channelId); + } + if (message.proofInit.length !== 0) { + writer.uint32(26).bytes(message.proofInit); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(34).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(42).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgChannelCloseConfirm { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgChannelCloseConfirm } as MsgChannelCloseConfirm; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.portId = reader.string(); + break; + case 2: + message.channelId = reader.string(); + break; + case 3: + message.proofInit = reader.bytes(); + break; + case 4: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + case 5: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgChannelCloseConfirm { + const message = { ...baseMsgChannelCloseConfirm } as MsgChannelCloseConfirm; + if (object.portId !== undefined && object.portId !== null) { + message.portId = String(object.portId); + } else { + message.portId = ""; + } + if (object.channelId !== undefined && object.channelId !== null) { + message.channelId = String(object.channelId); + } else { + message.channelId = ""; + } + if (object.proofInit !== undefined && object.proofInit !== null) { + message.proofInit = bytesFromBase64(object.proofInit); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgChannelCloseConfirm): unknown { + const obj: any = {}; + message.portId !== undefined && (obj.portId = message.portId); + message.channelId !== undefined && (obj.channelId = message.channelId); + message.proofInit !== undefined && + (obj.proofInit = base64FromBytes( + message.proofInit !== undefined ? message.proofInit : new Uint8Array(), + )); + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgChannelCloseConfirm { + const message = { ...baseMsgChannelCloseConfirm } as MsgChannelCloseConfirm; + if (object.portId !== undefined && object.portId !== null) { + message.portId = object.portId; + } else { + message.portId = ""; + } + if (object.channelId !== undefined && object.channelId !== null) { + message.channelId = object.channelId; + } else { + message.channelId = ""; + } + if (object.proofInit !== undefined && object.proofInit !== null) { + message.proofInit = object.proofInit; + } else { + message.proofInit = new Uint8Array(); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgChannelCloseConfirmResponse: object = {}; + +export const MsgChannelCloseConfirmResponse = { + encode(_: MsgChannelCloseConfirmResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgChannelCloseConfirmResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgChannelCloseConfirmResponse } as MsgChannelCloseConfirmResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgChannelCloseConfirmResponse { + const message = { ...baseMsgChannelCloseConfirmResponse } as MsgChannelCloseConfirmResponse; + return message; + }, + + toJSON(_: MsgChannelCloseConfirmResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgChannelCloseConfirmResponse { + const message = { ...baseMsgChannelCloseConfirmResponse } as MsgChannelCloseConfirmResponse; + return message; + }, +}; + +const baseMsgRecvPacket: object = { signer: "" }; + +export const MsgRecvPacket = { + encode(message: MsgRecvPacket, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.packet !== undefined) { + Packet.encode(message.packet, writer.uint32(10).fork()).ldelim(); + } + if (message.proofCommitment.length !== 0) { + writer.uint32(18).bytes(message.proofCommitment); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(26).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(34).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgRecvPacket { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgRecvPacket } as MsgRecvPacket; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.packet = Packet.decode(reader, reader.uint32()); + break; + case 2: + message.proofCommitment = reader.bytes(); + break; + case 3: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + case 4: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgRecvPacket { + const message = { ...baseMsgRecvPacket } as MsgRecvPacket; + if (object.packet !== undefined && object.packet !== null) { + message.packet = Packet.fromJSON(object.packet); + } else { + message.packet = undefined; + } + if (object.proofCommitment !== undefined && object.proofCommitment !== null) { + message.proofCommitment = bytesFromBase64(object.proofCommitment); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgRecvPacket): unknown { + const obj: any = {}; + message.packet !== undefined && (obj.packet = message.packet ? Packet.toJSON(message.packet) : undefined); + message.proofCommitment !== undefined && + (obj.proofCommitment = base64FromBytes( + message.proofCommitment !== undefined ? message.proofCommitment : new Uint8Array(), + )); + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgRecvPacket { + const message = { ...baseMsgRecvPacket } as MsgRecvPacket; + if (object.packet !== undefined && object.packet !== null) { + message.packet = Packet.fromPartial(object.packet); + } else { + message.packet = undefined; + } + if (object.proofCommitment !== undefined && object.proofCommitment !== null) { + message.proofCommitment = object.proofCommitment; + } else { + message.proofCommitment = new Uint8Array(); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgRecvPacketResponse: object = {}; + +export const MsgRecvPacketResponse = { + encode(_: MsgRecvPacketResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgRecvPacketResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgRecvPacketResponse } as MsgRecvPacketResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgRecvPacketResponse { + const message = { ...baseMsgRecvPacketResponse } as MsgRecvPacketResponse; + return message; + }, + + toJSON(_: MsgRecvPacketResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgRecvPacketResponse { + const message = { ...baseMsgRecvPacketResponse } as MsgRecvPacketResponse; + return message; + }, +}; + +const baseMsgTimeout: object = { nextSequenceRecv: Long.UZERO, signer: "" }; + +export const MsgTimeout = { + encode(message: MsgTimeout, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.packet !== undefined) { + Packet.encode(message.packet, writer.uint32(10).fork()).ldelim(); + } + if (message.proofUnreceived.length !== 0) { + writer.uint32(18).bytes(message.proofUnreceived); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(26).fork()).ldelim(); + } + if (!message.nextSequenceRecv.isZero()) { + writer.uint32(32).uint64(message.nextSequenceRecv); + } + if (message.signer !== "") { + writer.uint32(42).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgTimeout { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgTimeout } as MsgTimeout; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.packet = Packet.decode(reader, reader.uint32()); + break; + case 2: + message.proofUnreceived = reader.bytes(); + break; + case 3: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + case 4: + message.nextSequenceRecv = reader.uint64() as Long; + break; + case 5: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgTimeout { + const message = { ...baseMsgTimeout } as MsgTimeout; + if (object.packet !== undefined && object.packet !== null) { + message.packet = Packet.fromJSON(object.packet); + } else { + message.packet = undefined; + } + if (object.proofUnreceived !== undefined && object.proofUnreceived !== null) { + message.proofUnreceived = bytesFromBase64(object.proofUnreceived); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.nextSequenceRecv !== undefined && object.nextSequenceRecv !== null) { + message.nextSequenceRecv = Long.fromString(object.nextSequenceRecv); + } else { + message.nextSequenceRecv = Long.UZERO; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgTimeout): unknown { + const obj: any = {}; + message.packet !== undefined && (obj.packet = message.packet ? Packet.toJSON(message.packet) : undefined); + message.proofUnreceived !== undefined && + (obj.proofUnreceived = base64FromBytes( + message.proofUnreceived !== undefined ? message.proofUnreceived : new Uint8Array(), + )); + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + message.nextSequenceRecv !== undefined && + (obj.nextSequenceRecv = (message.nextSequenceRecv || Long.UZERO).toString()); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgTimeout { + const message = { ...baseMsgTimeout } as MsgTimeout; + if (object.packet !== undefined && object.packet !== null) { + message.packet = Packet.fromPartial(object.packet); + } else { + message.packet = undefined; + } + if (object.proofUnreceived !== undefined && object.proofUnreceived !== null) { + message.proofUnreceived = object.proofUnreceived; + } else { + message.proofUnreceived = new Uint8Array(); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.nextSequenceRecv !== undefined && object.nextSequenceRecv !== null) { + message.nextSequenceRecv = object.nextSequenceRecv as Long; + } else { + message.nextSequenceRecv = Long.UZERO; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgTimeoutResponse: object = {}; + +export const MsgTimeoutResponse = { + encode(_: MsgTimeoutResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgTimeoutResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgTimeoutResponse } as MsgTimeoutResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgTimeoutResponse { + const message = { ...baseMsgTimeoutResponse } as MsgTimeoutResponse; + return message; + }, + + toJSON(_: MsgTimeoutResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgTimeoutResponse { + const message = { ...baseMsgTimeoutResponse } as MsgTimeoutResponse; + return message; + }, +}; + +const baseMsgTimeoutOnClose: object = { nextSequenceRecv: Long.UZERO, signer: "" }; + +export const MsgTimeoutOnClose = { + encode(message: MsgTimeoutOnClose, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.packet !== undefined) { + Packet.encode(message.packet, writer.uint32(10).fork()).ldelim(); + } + if (message.proofUnreceived.length !== 0) { + writer.uint32(18).bytes(message.proofUnreceived); + } + if (message.proofClose.length !== 0) { + writer.uint32(26).bytes(message.proofClose); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(34).fork()).ldelim(); + } + if (!message.nextSequenceRecv.isZero()) { + writer.uint32(40).uint64(message.nextSequenceRecv); + } + if (message.signer !== "") { + writer.uint32(50).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgTimeoutOnClose { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgTimeoutOnClose } as MsgTimeoutOnClose; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.packet = Packet.decode(reader, reader.uint32()); + break; + case 2: + message.proofUnreceived = reader.bytes(); + break; + case 3: + message.proofClose = reader.bytes(); + break; + case 4: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + case 5: + message.nextSequenceRecv = reader.uint64() as Long; + break; + case 6: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgTimeoutOnClose { + const message = { ...baseMsgTimeoutOnClose } as MsgTimeoutOnClose; + if (object.packet !== undefined && object.packet !== null) { + message.packet = Packet.fromJSON(object.packet); + } else { + message.packet = undefined; + } + if (object.proofUnreceived !== undefined && object.proofUnreceived !== null) { + message.proofUnreceived = bytesFromBase64(object.proofUnreceived); + } + if (object.proofClose !== undefined && object.proofClose !== null) { + message.proofClose = bytesFromBase64(object.proofClose); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.nextSequenceRecv !== undefined && object.nextSequenceRecv !== null) { + message.nextSequenceRecv = Long.fromString(object.nextSequenceRecv); + } else { + message.nextSequenceRecv = Long.UZERO; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgTimeoutOnClose): unknown { + const obj: any = {}; + message.packet !== undefined && (obj.packet = message.packet ? Packet.toJSON(message.packet) : undefined); + message.proofUnreceived !== undefined && + (obj.proofUnreceived = base64FromBytes( + message.proofUnreceived !== undefined ? message.proofUnreceived : new Uint8Array(), + )); + message.proofClose !== undefined && + (obj.proofClose = base64FromBytes( + message.proofClose !== undefined ? message.proofClose : new Uint8Array(), + )); + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + message.nextSequenceRecv !== undefined && + (obj.nextSequenceRecv = (message.nextSequenceRecv || Long.UZERO).toString()); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgTimeoutOnClose { + const message = { ...baseMsgTimeoutOnClose } as MsgTimeoutOnClose; + if (object.packet !== undefined && object.packet !== null) { + message.packet = Packet.fromPartial(object.packet); + } else { + message.packet = undefined; + } + if (object.proofUnreceived !== undefined && object.proofUnreceived !== null) { + message.proofUnreceived = object.proofUnreceived; + } else { + message.proofUnreceived = new Uint8Array(); + } + if (object.proofClose !== undefined && object.proofClose !== null) { + message.proofClose = object.proofClose; + } else { + message.proofClose = new Uint8Array(); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.nextSequenceRecv !== undefined && object.nextSequenceRecv !== null) { + message.nextSequenceRecv = object.nextSequenceRecv as Long; + } else { + message.nextSequenceRecv = Long.UZERO; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgTimeoutOnCloseResponse: object = {}; + +export const MsgTimeoutOnCloseResponse = { + encode(_: MsgTimeoutOnCloseResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgTimeoutOnCloseResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgTimeoutOnCloseResponse } as MsgTimeoutOnCloseResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgTimeoutOnCloseResponse { + const message = { ...baseMsgTimeoutOnCloseResponse } as MsgTimeoutOnCloseResponse; + return message; + }, + + toJSON(_: MsgTimeoutOnCloseResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgTimeoutOnCloseResponse { + const message = { ...baseMsgTimeoutOnCloseResponse } as MsgTimeoutOnCloseResponse; + return message; + }, +}; + +const baseMsgAcknowledgement: object = { signer: "" }; + +export const MsgAcknowledgement = { + encode(message: MsgAcknowledgement, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.packet !== undefined) { + Packet.encode(message.packet, writer.uint32(10).fork()).ldelim(); + } + if (message.acknowledgement.length !== 0) { + writer.uint32(18).bytes(message.acknowledgement); + } + if (message.proofAcked.length !== 0) { + writer.uint32(26).bytes(message.proofAcked); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(34).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(42).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgAcknowledgement { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgAcknowledgement } as MsgAcknowledgement; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.packet = Packet.decode(reader, reader.uint32()); + break; + case 2: + message.acknowledgement = reader.bytes(); + break; + case 3: + message.proofAcked = reader.bytes(); + break; + case 4: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + case 5: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgAcknowledgement { + const message = { ...baseMsgAcknowledgement } as MsgAcknowledgement; + if (object.packet !== undefined && object.packet !== null) { + message.packet = Packet.fromJSON(object.packet); + } else { + message.packet = undefined; + } + if (object.acknowledgement !== undefined && object.acknowledgement !== null) { + message.acknowledgement = bytesFromBase64(object.acknowledgement); + } + if (object.proofAcked !== undefined && object.proofAcked !== null) { + message.proofAcked = bytesFromBase64(object.proofAcked); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgAcknowledgement): unknown { + const obj: any = {}; + message.packet !== undefined && (obj.packet = message.packet ? Packet.toJSON(message.packet) : undefined); + message.acknowledgement !== undefined && + (obj.acknowledgement = base64FromBytes( + message.acknowledgement !== undefined ? message.acknowledgement : new Uint8Array(), + )); + message.proofAcked !== undefined && + (obj.proofAcked = base64FromBytes( + message.proofAcked !== undefined ? message.proofAcked : new Uint8Array(), + )); + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgAcknowledgement { + const message = { ...baseMsgAcknowledgement } as MsgAcknowledgement; + if (object.packet !== undefined && object.packet !== null) { + message.packet = Packet.fromPartial(object.packet); + } else { + message.packet = undefined; + } + if (object.acknowledgement !== undefined && object.acknowledgement !== null) { + message.acknowledgement = object.acknowledgement; + } else { + message.acknowledgement = new Uint8Array(); + } + if (object.proofAcked !== undefined && object.proofAcked !== null) { + message.proofAcked = object.proofAcked; + } else { + message.proofAcked = new Uint8Array(); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgAcknowledgementResponse: object = {}; + +export const MsgAcknowledgementResponse = { + encode(_: MsgAcknowledgementResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgAcknowledgementResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgAcknowledgementResponse } as MsgAcknowledgementResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgAcknowledgementResponse { + const message = { ...baseMsgAcknowledgementResponse } as MsgAcknowledgementResponse; + return message; + }, + + toJSON(_: MsgAcknowledgementResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgAcknowledgementResponse { + const message = { ...baseMsgAcknowledgementResponse } as MsgAcknowledgementResponse; + return message; + }, +}; + +/** Msg defines the ibc/channel Msg service. */ +export interface Msg { + /** ChannelOpenInit defines a rpc handler method for MsgChannelOpenInit. */ + ChannelOpenInit(request: MsgChannelOpenInit): Promise; + /** ChannelOpenTry defines a rpc handler method for MsgChannelOpenTry. */ + ChannelOpenTry(request: MsgChannelOpenTry): Promise; + /** ChannelOpenAck defines a rpc handler method for MsgChannelOpenAck. */ + ChannelOpenAck(request: MsgChannelOpenAck): Promise; + /** ChannelOpenConfirm defines a rpc handler method for MsgChannelOpenConfirm. */ + ChannelOpenConfirm(request: MsgChannelOpenConfirm): Promise; + /** ChannelCloseInit defines a rpc handler method for MsgChannelCloseInit. */ + ChannelCloseInit(request: MsgChannelCloseInit): Promise; + /** ChannelCloseConfirm defines a rpc handler method for MsgChannelCloseConfirm. */ + ChannelCloseConfirm(request: MsgChannelCloseConfirm): Promise; + /** RecvPacket defines a rpc handler method for MsgRecvPacket. */ + RecvPacket(request: MsgRecvPacket): Promise; + /** Timeout defines a rpc handler method for MsgTimeout. */ + Timeout(request: MsgTimeout): Promise; + /** TimeoutOnClose defines a rpc handler method for MsgTimeoutOnClose. */ + TimeoutOnClose(request: MsgTimeoutOnClose): Promise; + /** Acknowledgement defines a rpc handler method for MsgAcknowledgement. */ + Acknowledgement(request: MsgAcknowledgement): Promise; +} + +export class MsgClientImpl implements Msg { + private readonly rpc: Rpc; + constructor(rpc: Rpc) { + this.rpc = rpc; + } + ChannelOpenInit(request: MsgChannelOpenInit): Promise { + const data = MsgChannelOpenInit.encode(request).finish(); + const promise = this.rpc.request("ibc.core.channel.v1.Msg", "ChannelOpenInit", data); + return promise.then((data) => MsgChannelOpenInitResponse.decode(new _m0.Reader(data))); + } + + ChannelOpenTry(request: MsgChannelOpenTry): Promise { + const data = MsgChannelOpenTry.encode(request).finish(); + const promise = this.rpc.request("ibc.core.channel.v1.Msg", "ChannelOpenTry", data); + return promise.then((data) => MsgChannelOpenTryResponse.decode(new _m0.Reader(data))); + } + + ChannelOpenAck(request: MsgChannelOpenAck): Promise { + const data = MsgChannelOpenAck.encode(request).finish(); + const promise = this.rpc.request("ibc.core.channel.v1.Msg", "ChannelOpenAck", data); + return promise.then((data) => MsgChannelOpenAckResponse.decode(new _m0.Reader(data))); + } + + ChannelOpenConfirm(request: MsgChannelOpenConfirm): Promise { + const data = MsgChannelOpenConfirm.encode(request).finish(); + const promise = this.rpc.request("ibc.core.channel.v1.Msg", "ChannelOpenConfirm", data); + return promise.then((data) => MsgChannelOpenConfirmResponse.decode(new _m0.Reader(data))); + } + + ChannelCloseInit(request: MsgChannelCloseInit): Promise { + const data = MsgChannelCloseInit.encode(request).finish(); + const promise = this.rpc.request("ibc.core.channel.v1.Msg", "ChannelCloseInit", data); + return promise.then((data) => MsgChannelCloseInitResponse.decode(new _m0.Reader(data))); + } + + ChannelCloseConfirm(request: MsgChannelCloseConfirm): Promise { + const data = MsgChannelCloseConfirm.encode(request).finish(); + const promise = this.rpc.request("ibc.core.channel.v1.Msg", "ChannelCloseConfirm", data); + return promise.then((data) => MsgChannelCloseConfirmResponse.decode(new _m0.Reader(data))); + } + + RecvPacket(request: MsgRecvPacket): Promise { + const data = MsgRecvPacket.encode(request).finish(); + const promise = this.rpc.request("ibc.core.channel.v1.Msg", "RecvPacket", data); + return promise.then((data) => MsgRecvPacketResponse.decode(new _m0.Reader(data))); + } + + Timeout(request: MsgTimeout): Promise { + const data = MsgTimeout.encode(request).finish(); + const promise = this.rpc.request("ibc.core.channel.v1.Msg", "Timeout", data); + return promise.then((data) => MsgTimeoutResponse.decode(new _m0.Reader(data))); + } + + TimeoutOnClose(request: MsgTimeoutOnClose): Promise { + const data = MsgTimeoutOnClose.encode(request).finish(); + const promise = this.rpc.request("ibc.core.channel.v1.Msg", "TimeoutOnClose", data); + return promise.then((data) => MsgTimeoutOnCloseResponse.decode(new _m0.Reader(data))); + } + + Acknowledgement(request: MsgAcknowledgement): Promise { + const data = MsgAcknowledgement.encode(request).finish(); + const promise = this.rpc.request("ibc.core.channel.v1.Msg", "Acknowledgement", data); + return promise.then((data) => MsgAcknowledgementResponse.decode(new _m0.Reader(data))); + } +} + +interface Rpc { + request(service: string, method: string, data: Uint8Array): Promise; +} + +declare var self: any | undefined; +declare var window: any | undefined; +var globalThis: any = (() => { + if (typeof globalThis !== "undefined") return globalThis; + if (typeof self !== "undefined") return self; + if (typeof window !== "undefined") return window; + if (typeof global !== "undefined") return global; + throw "Unable to locate global object"; +})(); + +const atob: (b64: string) => string = + globalThis.atob || ((b64) => globalThis.Buffer.from(b64, "base64").toString("binary")); +function bytesFromBase64(b64: string): Uint8Array { + const bin = atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; +} + +const btoa: (bin: string) => string = + globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); +function base64FromBytes(arr: Uint8Array): string { + const bin: string[] = []; + for (let i = 0; i < arr.byteLength; ++i) { + bin.push(String.fromCharCode(arr[i])); + } + return btoa(bin.join("")); +} + +type Builtin = Date | Function | Uint8Array | string | number | undefined | Long; +export type DeepPartial = T extends Builtin + ? T + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; diff --git a/packages/stargate/src/codec/ibc/core/client/v1/query.ts b/packages/stargate/src/codec/ibc/core/client/v1/query.ts new file mode 100644 index 00000000..ac232e7e --- /dev/null +++ b/packages/stargate/src/codec/ibc/core/client/v1/query.ts @@ -0,0 +1,953 @@ +/* eslint-disable */ +import { Any } from "../../../../google/protobuf/any"; +import { + Height, + Params, + IdentifiedClientState, + ConsensusStateWithHeight, +} from "../../../../ibc/core/client/v1/client"; +import { PageRequest, PageResponse } from "../../../../cosmos/base/query/v1beta1/pagination"; +import Long from "long"; +import _m0 from "protobufjs/minimal"; + +export const protobufPackage = "ibc.core.client.v1"; + +/** + * QueryClientStateRequest is the request type for the Query/ClientState RPC + * method + */ +export interface QueryClientStateRequest { + /** client state unique identifier */ + clientId: string; +} + +/** + * QueryClientStateResponse is the response type for the Query/ClientState RPC + * method. Besides the client state, it includes a proof and the height from + * which the proof was retrieved. + */ +export interface QueryClientStateResponse { + /** client state associated with the request identifier */ + clientState?: Any; + /** merkle proof of existence */ + proof: Uint8Array; + /** height at which the proof was retrieved */ + proofHeight?: Height; +} + +/** + * QueryClientStatesRequest is the request type for the Query/ClientStates RPC + * method + */ +export interface QueryClientStatesRequest { + /** pagination request */ + pagination?: PageRequest; +} + +/** + * QueryClientStatesResponse is the response type for the Query/ClientStates RPC + * method. + */ +export interface QueryClientStatesResponse { + /** list of stored ClientStates of the chain. */ + clientStates: IdentifiedClientState[]; + /** pagination response */ + pagination?: PageResponse; +} + +/** + * QueryConsensusStateRequest is the request type for the Query/ConsensusState + * RPC method. Besides the consensus state, it includes a proof and the height + * from which the proof was retrieved. + */ +export interface QueryConsensusStateRequest { + /** client identifier */ + clientId: string; + /** consensus state revision number */ + revisionNumber: Long; + /** consensus state revision height */ + revisionHeight: Long; + /** + * latest_height overrrides the height field and queries the latest stored + * ConsensusState + */ + latestHeight: boolean; +} + +/** + * QueryConsensusStateResponse is the response type for the Query/ConsensusState + * RPC method + */ +export interface QueryConsensusStateResponse { + /** consensus state associated with the client identifier at the given height */ + consensusState?: Any; + /** merkle proof of existence */ + proof: Uint8Array; + /** height at which the proof was retrieved */ + proofHeight?: Height; +} + +/** + * QueryConsensusStatesRequest is the request type for the Query/ConsensusStates + * RPC method. + */ +export interface QueryConsensusStatesRequest { + /** client identifier */ + clientId: string; + /** pagination request */ + pagination?: PageRequest; +} + +/** + * QueryConsensusStatesResponse is the response type for the + * Query/ConsensusStates RPC method + */ +export interface QueryConsensusStatesResponse { + /** consensus states associated with the identifier */ + consensusStates: ConsensusStateWithHeight[]; + /** pagination response */ + pagination?: PageResponse; +} + +/** QueryClientParamsRequest is the request type for the Query/ClientParams RPC method. */ +export interface QueryClientParamsRequest {} + +/** QueryClientParamsResponse is the response type for the Query/ClientParams RPC method. */ +export interface QueryClientParamsResponse { + /** params defines the parameters of the module. */ + params?: Params; +} + +const baseQueryClientStateRequest: object = { clientId: "" }; + +export const QueryClientStateRequest = { + encode(message: QueryClientStateRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.clientId !== "") { + writer.uint32(10).string(message.clientId); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryClientStateRequest { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryClientStateRequest } as QueryClientStateRequest; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.clientId = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryClientStateRequest { + const message = { ...baseQueryClientStateRequest } as QueryClientStateRequest; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = String(object.clientId); + } else { + message.clientId = ""; + } + return message; + }, + + toJSON(message: QueryClientStateRequest): unknown { + const obj: any = {}; + message.clientId !== undefined && (obj.clientId = message.clientId); + return obj; + }, + + fromPartial(object: DeepPartial): QueryClientStateRequest { + const message = { ...baseQueryClientStateRequest } as QueryClientStateRequest; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = object.clientId; + } else { + message.clientId = ""; + } + return message; + }, +}; + +const baseQueryClientStateResponse: object = {}; + +export const QueryClientStateResponse = { + encode(message: QueryClientStateResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.clientState !== undefined) { + Any.encode(message.clientState, writer.uint32(10).fork()).ldelim(); + } + if (message.proof.length !== 0) { + writer.uint32(18).bytes(message.proof); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(26).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryClientStateResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryClientStateResponse } as QueryClientStateResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.clientState = Any.decode(reader, reader.uint32()); + break; + case 2: + message.proof = reader.bytes(); + break; + case 3: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryClientStateResponse { + const message = { ...baseQueryClientStateResponse } as QueryClientStateResponse; + if (object.clientState !== undefined && object.clientState !== null) { + message.clientState = Any.fromJSON(object.clientState); + } else { + message.clientState = undefined; + } + if (object.proof !== undefined && object.proof !== null) { + message.proof = bytesFromBase64(object.proof); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + return message; + }, + + toJSON(message: QueryClientStateResponse): unknown { + const obj: any = {}; + message.clientState !== undefined && + (obj.clientState = message.clientState ? Any.toJSON(message.clientState) : undefined); + message.proof !== undefined && + (obj.proof = base64FromBytes(message.proof !== undefined ? message.proof : new Uint8Array())); + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + return obj; + }, + + fromPartial(object: DeepPartial): QueryClientStateResponse { + const message = { ...baseQueryClientStateResponse } as QueryClientStateResponse; + if (object.clientState !== undefined && object.clientState !== null) { + message.clientState = Any.fromPartial(object.clientState); + } else { + message.clientState = undefined; + } + if (object.proof !== undefined && object.proof !== null) { + message.proof = object.proof; + } else { + message.proof = new Uint8Array(); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + return message; + }, +}; + +const baseQueryClientStatesRequest: object = {}; + +export const QueryClientStatesRequest = { + encode(message: QueryClientStatesRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.pagination !== undefined) { + PageRequest.encode(message.pagination, writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryClientStatesRequest { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryClientStatesRequest } as QueryClientStatesRequest; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.pagination = PageRequest.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryClientStatesRequest { + const message = { ...baseQueryClientStatesRequest } as QueryClientStatesRequest; + if (object.pagination !== undefined && object.pagination !== null) { + message.pagination = PageRequest.fromJSON(object.pagination); + } else { + message.pagination = undefined; + } + return message; + }, + + toJSON(message: QueryClientStatesRequest): unknown { + const obj: any = {}; + message.pagination !== undefined && + (obj.pagination = message.pagination ? PageRequest.toJSON(message.pagination) : undefined); + return obj; + }, + + fromPartial(object: DeepPartial): QueryClientStatesRequest { + const message = { ...baseQueryClientStatesRequest } as QueryClientStatesRequest; + if (object.pagination !== undefined && object.pagination !== null) { + message.pagination = PageRequest.fromPartial(object.pagination); + } else { + message.pagination = undefined; + } + return message; + }, +}; + +const baseQueryClientStatesResponse: object = {}; + +export const QueryClientStatesResponse = { + encode(message: QueryClientStatesResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + for (const v of message.clientStates) { + IdentifiedClientState.encode(v!, writer.uint32(10).fork()).ldelim(); + } + if (message.pagination !== undefined) { + PageResponse.encode(message.pagination, writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryClientStatesResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryClientStatesResponse } as QueryClientStatesResponse; + message.clientStates = []; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.clientStates.push(IdentifiedClientState.decode(reader, reader.uint32())); + break; + case 2: + message.pagination = PageResponse.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryClientStatesResponse { + const message = { ...baseQueryClientStatesResponse } as QueryClientStatesResponse; + message.clientStates = []; + if (object.clientStates !== undefined && object.clientStates !== null) { + for (const e of object.clientStates) { + message.clientStates.push(IdentifiedClientState.fromJSON(e)); + } + } + if (object.pagination !== undefined && object.pagination !== null) { + message.pagination = PageResponse.fromJSON(object.pagination); + } else { + message.pagination = undefined; + } + return message; + }, + + toJSON(message: QueryClientStatesResponse): unknown { + const obj: any = {}; + if (message.clientStates) { + obj.clientStates = message.clientStates.map((e) => (e ? IdentifiedClientState.toJSON(e) : undefined)); + } else { + obj.clientStates = []; + } + message.pagination !== undefined && + (obj.pagination = message.pagination ? PageResponse.toJSON(message.pagination) : undefined); + return obj; + }, + + fromPartial(object: DeepPartial): QueryClientStatesResponse { + const message = { ...baseQueryClientStatesResponse } as QueryClientStatesResponse; + message.clientStates = []; + if (object.clientStates !== undefined && object.clientStates !== null) { + for (const e of object.clientStates) { + message.clientStates.push(IdentifiedClientState.fromPartial(e)); + } + } + if (object.pagination !== undefined && object.pagination !== null) { + message.pagination = PageResponse.fromPartial(object.pagination); + } else { + message.pagination = undefined; + } + return message; + }, +}; + +const baseQueryConsensusStateRequest: object = { + clientId: "", + revisionNumber: Long.UZERO, + revisionHeight: Long.UZERO, + latestHeight: false, +}; + +export const QueryConsensusStateRequest = { + encode(message: QueryConsensusStateRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.clientId !== "") { + writer.uint32(10).string(message.clientId); + } + if (!message.revisionNumber.isZero()) { + writer.uint32(16).uint64(message.revisionNumber); + } + if (!message.revisionHeight.isZero()) { + writer.uint32(24).uint64(message.revisionHeight); + } + if (message.latestHeight === true) { + writer.uint32(32).bool(message.latestHeight); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryConsensusStateRequest { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryConsensusStateRequest } as QueryConsensusStateRequest; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.clientId = reader.string(); + break; + case 2: + message.revisionNumber = reader.uint64() as Long; + break; + case 3: + message.revisionHeight = reader.uint64() as Long; + break; + case 4: + message.latestHeight = reader.bool(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryConsensusStateRequest { + const message = { ...baseQueryConsensusStateRequest } as QueryConsensusStateRequest; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = String(object.clientId); + } else { + message.clientId = ""; + } + if (object.revisionNumber !== undefined && object.revisionNumber !== null) { + message.revisionNumber = Long.fromString(object.revisionNumber); + } else { + message.revisionNumber = Long.UZERO; + } + if (object.revisionHeight !== undefined && object.revisionHeight !== null) { + message.revisionHeight = Long.fromString(object.revisionHeight); + } else { + message.revisionHeight = Long.UZERO; + } + if (object.latestHeight !== undefined && object.latestHeight !== null) { + message.latestHeight = Boolean(object.latestHeight); + } else { + message.latestHeight = false; + } + return message; + }, + + toJSON(message: QueryConsensusStateRequest): unknown { + const obj: any = {}; + message.clientId !== undefined && (obj.clientId = message.clientId); + message.revisionNumber !== undefined && + (obj.revisionNumber = (message.revisionNumber || Long.UZERO).toString()); + message.revisionHeight !== undefined && + (obj.revisionHeight = (message.revisionHeight || Long.UZERO).toString()); + message.latestHeight !== undefined && (obj.latestHeight = message.latestHeight); + return obj; + }, + + fromPartial(object: DeepPartial): QueryConsensusStateRequest { + const message = { ...baseQueryConsensusStateRequest } as QueryConsensusStateRequest; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = object.clientId; + } else { + message.clientId = ""; + } + if (object.revisionNumber !== undefined && object.revisionNumber !== null) { + message.revisionNumber = object.revisionNumber as Long; + } else { + message.revisionNumber = Long.UZERO; + } + if (object.revisionHeight !== undefined && object.revisionHeight !== null) { + message.revisionHeight = object.revisionHeight as Long; + } else { + message.revisionHeight = Long.UZERO; + } + if (object.latestHeight !== undefined && object.latestHeight !== null) { + message.latestHeight = object.latestHeight; + } else { + message.latestHeight = false; + } + return message; + }, +}; + +const baseQueryConsensusStateResponse: object = {}; + +export const QueryConsensusStateResponse = { + encode(message: QueryConsensusStateResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.consensusState !== undefined) { + Any.encode(message.consensusState, writer.uint32(10).fork()).ldelim(); + } + if (message.proof.length !== 0) { + writer.uint32(18).bytes(message.proof); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(26).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryConsensusStateResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryConsensusStateResponse } as QueryConsensusStateResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.consensusState = Any.decode(reader, reader.uint32()); + break; + case 2: + message.proof = reader.bytes(); + break; + case 3: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryConsensusStateResponse { + const message = { ...baseQueryConsensusStateResponse } as QueryConsensusStateResponse; + if (object.consensusState !== undefined && object.consensusState !== null) { + message.consensusState = Any.fromJSON(object.consensusState); + } else { + message.consensusState = undefined; + } + if (object.proof !== undefined && object.proof !== null) { + message.proof = bytesFromBase64(object.proof); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + return message; + }, + + toJSON(message: QueryConsensusStateResponse): unknown { + const obj: any = {}; + message.consensusState !== undefined && + (obj.consensusState = message.consensusState ? Any.toJSON(message.consensusState) : undefined); + message.proof !== undefined && + (obj.proof = base64FromBytes(message.proof !== undefined ? message.proof : new Uint8Array())); + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + return obj; + }, + + fromPartial(object: DeepPartial): QueryConsensusStateResponse { + const message = { ...baseQueryConsensusStateResponse } as QueryConsensusStateResponse; + if (object.consensusState !== undefined && object.consensusState !== null) { + message.consensusState = Any.fromPartial(object.consensusState); + } else { + message.consensusState = undefined; + } + if (object.proof !== undefined && object.proof !== null) { + message.proof = object.proof; + } else { + message.proof = new Uint8Array(); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + return message; + }, +}; + +const baseQueryConsensusStatesRequest: object = { clientId: "" }; + +export const QueryConsensusStatesRequest = { + encode(message: QueryConsensusStatesRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.clientId !== "") { + writer.uint32(10).string(message.clientId); + } + if (message.pagination !== undefined) { + PageRequest.encode(message.pagination, writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryConsensusStatesRequest { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryConsensusStatesRequest } as QueryConsensusStatesRequest; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.clientId = reader.string(); + break; + case 2: + message.pagination = PageRequest.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryConsensusStatesRequest { + const message = { ...baseQueryConsensusStatesRequest } as QueryConsensusStatesRequest; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = String(object.clientId); + } else { + message.clientId = ""; + } + if (object.pagination !== undefined && object.pagination !== null) { + message.pagination = PageRequest.fromJSON(object.pagination); + } else { + message.pagination = undefined; + } + return message; + }, + + toJSON(message: QueryConsensusStatesRequest): unknown { + const obj: any = {}; + message.clientId !== undefined && (obj.clientId = message.clientId); + message.pagination !== undefined && + (obj.pagination = message.pagination ? PageRequest.toJSON(message.pagination) : undefined); + return obj; + }, + + fromPartial(object: DeepPartial): QueryConsensusStatesRequest { + const message = { ...baseQueryConsensusStatesRequest } as QueryConsensusStatesRequest; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = object.clientId; + } else { + message.clientId = ""; + } + if (object.pagination !== undefined && object.pagination !== null) { + message.pagination = PageRequest.fromPartial(object.pagination); + } else { + message.pagination = undefined; + } + return message; + }, +}; + +const baseQueryConsensusStatesResponse: object = {}; + +export const QueryConsensusStatesResponse = { + encode(message: QueryConsensusStatesResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + for (const v of message.consensusStates) { + ConsensusStateWithHeight.encode(v!, writer.uint32(10).fork()).ldelim(); + } + if (message.pagination !== undefined) { + PageResponse.encode(message.pagination, writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryConsensusStatesResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryConsensusStatesResponse } as QueryConsensusStatesResponse; + message.consensusStates = []; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.consensusStates.push(ConsensusStateWithHeight.decode(reader, reader.uint32())); + break; + case 2: + message.pagination = PageResponse.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryConsensusStatesResponse { + const message = { ...baseQueryConsensusStatesResponse } as QueryConsensusStatesResponse; + message.consensusStates = []; + if (object.consensusStates !== undefined && object.consensusStates !== null) { + for (const e of object.consensusStates) { + message.consensusStates.push(ConsensusStateWithHeight.fromJSON(e)); + } + } + if (object.pagination !== undefined && object.pagination !== null) { + message.pagination = PageResponse.fromJSON(object.pagination); + } else { + message.pagination = undefined; + } + return message; + }, + + toJSON(message: QueryConsensusStatesResponse): unknown { + const obj: any = {}; + if (message.consensusStates) { + obj.consensusStates = message.consensusStates.map((e) => + e ? ConsensusStateWithHeight.toJSON(e) : undefined, + ); + } else { + obj.consensusStates = []; + } + message.pagination !== undefined && + (obj.pagination = message.pagination ? PageResponse.toJSON(message.pagination) : undefined); + return obj; + }, + + fromPartial(object: DeepPartial): QueryConsensusStatesResponse { + const message = { ...baseQueryConsensusStatesResponse } as QueryConsensusStatesResponse; + message.consensusStates = []; + if (object.consensusStates !== undefined && object.consensusStates !== null) { + for (const e of object.consensusStates) { + message.consensusStates.push(ConsensusStateWithHeight.fromPartial(e)); + } + } + if (object.pagination !== undefined && object.pagination !== null) { + message.pagination = PageResponse.fromPartial(object.pagination); + } else { + message.pagination = undefined; + } + return message; + }, +}; + +const baseQueryClientParamsRequest: object = {}; + +export const QueryClientParamsRequest = { + encode(_: QueryClientParamsRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryClientParamsRequest { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryClientParamsRequest } as QueryClientParamsRequest; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): QueryClientParamsRequest { + const message = { ...baseQueryClientParamsRequest } as QueryClientParamsRequest; + return message; + }, + + toJSON(_: QueryClientParamsRequest): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): QueryClientParamsRequest { + const message = { ...baseQueryClientParamsRequest } as QueryClientParamsRequest; + return message; + }, +}; + +const baseQueryClientParamsResponse: object = {}; + +export const QueryClientParamsResponse = { + encode(message: QueryClientParamsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.params !== undefined) { + Params.encode(message.params, writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryClientParamsResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryClientParamsResponse } as QueryClientParamsResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.params = Params.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryClientParamsResponse { + const message = { ...baseQueryClientParamsResponse } as QueryClientParamsResponse; + if (object.params !== undefined && object.params !== null) { + message.params = Params.fromJSON(object.params); + } else { + message.params = undefined; + } + return message; + }, + + toJSON(message: QueryClientParamsResponse): unknown { + const obj: any = {}; + message.params !== undefined && (obj.params = message.params ? Params.toJSON(message.params) : undefined); + return obj; + }, + + fromPartial(object: DeepPartial): QueryClientParamsResponse { + const message = { ...baseQueryClientParamsResponse } as QueryClientParamsResponse; + if (object.params !== undefined && object.params !== null) { + message.params = Params.fromPartial(object.params); + } else { + message.params = undefined; + } + return message; + }, +}; + +/** Query provides defines the gRPC querier service */ +export interface Query { + /** ClientState queries an IBC light client. */ + ClientState(request: QueryClientStateRequest): Promise; + /** ClientStates queries all the IBC light clients of a chain. */ + ClientStates(request: QueryClientStatesRequest): Promise; + /** + * ConsensusState queries a consensus state associated with a client state at + * a given height. + */ + ConsensusState(request: QueryConsensusStateRequest): Promise; + /** + * ConsensusStates queries all the consensus state associated with a given + * client. + */ + ConsensusStates(request: QueryConsensusStatesRequest): Promise; + /** ClientParams queries all parameters of the ibc client. */ + ClientParams(request: QueryClientParamsRequest): Promise; +} + +export class QueryClientImpl implements Query { + private readonly rpc: Rpc; + constructor(rpc: Rpc) { + this.rpc = rpc; + } + ClientState(request: QueryClientStateRequest): Promise { + const data = QueryClientStateRequest.encode(request).finish(); + const promise = this.rpc.request("ibc.core.client.v1.Query", "ClientState", data); + return promise.then((data) => QueryClientStateResponse.decode(new _m0.Reader(data))); + } + + ClientStates(request: QueryClientStatesRequest): Promise { + const data = QueryClientStatesRequest.encode(request).finish(); + const promise = this.rpc.request("ibc.core.client.v1.Query", "ClientStates", data); + return promise.then((data) => QueryClientStatesResponse.decode(new _m0.Reader(data))); + } + + ConsensusState(request: QueryConsensusStateRequest): Promise { + const data = QueryConsensusStateRequest.encode(request).finish(); + const promise = this.rpc.request("ibc.core.client.v1.Query", "ConsensusState", data); + return promise.then((data) => QueryConsensusStateResponse.decode(new _m0.Reader(data))); + } + + ConsensusStates(request: QueryConsensusStatesRequest): Promise { + const data = QueryConsensusStatesRequest.encode(request).finish(); + const promise = this.rpc.request("ibc.core.client.v1.Query", "ConsensusStates", data); + return promise.then((data) => QueryConsensusStatesResponse.decode(new _m0.Reader(data))); + } + + ClientParams(request: QueryClientParamsRequest): Promise { + const data = QueryClientParamsRequest.encode(request).finish(); + const promise = this.rpc.request("ibc.core.client.v1.Query", "ClientParams", data); + return promise.then((data) => QueryClientParamsResponse.decode(new _m0.Reader(data))); + } +} + +interface Rpc { + request(service: string, method: string, data: Uint8Array): Promise; +} + +declare var self: any | undefined; +declare var window: any | undefined; +var globalThis: any = (() => { + if (typeof globalThis !== "undefined") return globalThis; + if (typeof self !== "undefined") return self; + if (typeof window !== "undefined") return window; + if (typeof global !== "undefined") return global; + throw "Unable to locate global object"; +})(); + +const atob: (b64: string) => string = + globalThis.atob || ((b64) => globalThis.Buffer.from(b64, "base64").toString("binary")); +function bytesFromBase64(b64: string): Uint8Array { + const bin = atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; +} + +const btoa: (bin: string) => string = + globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); +function base64FromBytes(arr: Uint8Array): string { + const bin: string[] = []; + for (let i = 0; i < arr.byteLength; ++i) { + bin.push(String.fromCharCode(arr[i])); + } + return btoa(bin.join("")); +} + +type Builtin = Date | Function | Uint8Array | string | number | undefined | Long; +export type DeepPartial = T extends Builtin + ? T + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; diff --git a/packages/stargate/src/codec/ibc/core/client/v1/tx.ts b/packages/stargate/src/codec/ibc/core/client/v1/tx.ts new file mode 100644 index 00000000..fae3215e --- /dev/null +++ b/packages/stargate/src/codec/ibc/core/client/v1/tx.ts @@ -0,0 +1,729 @@ +/* eslint-disable */ +import { Any } from "../../../../google/protobuf/any"; +import _m0 from "protobufjs/minimal"; +import Long from "long"; + +export const protobufPackage = "ibc.core.client.v1"; + +/** MsgCreateClient defines a message to create an IBC client */ +export interface MsgCreateClient { + /** light client state */ + clientState?: Any; + /** + * consensus state associated with the client that corresponds to a given + * height. + */ + consensusState?: Any; + /** signer address */ + signer: string; +} + +/** MsgCreateClientResponse defines the Msg/CreateClient response type. */ +export interface MsgCreateClientResponse {} + +/** + * MsgUpdateClient defines an sdk.Msg to update a IBC client state using + * the given header. + */ +export interface MsgUpdateClient { + /** client unique identifier */ + clientId: string; + /** header to update the light client */ + header?: Any; + /** signer address */ + signer: string; +} + +/** MsgUpdateClientResponse defines the Msg/UpdateClient response type. */ +export interface MsgUpdateClientResponse {} + +/** MsgUpgradeClient defines an sdk.Msg to upgrade an IBC client to a new client state */ +export interface MsgUpgradeClient { + /** client unique identifier */ + clientId: string; + /** upgraded client state */ + clientState?: Any; + /** upgraded consensus state, only contains enough information to serve as a basis of trust in update logic */ + consensusState?: Any; + /** proof that old chain committed to new client */ + proofUpgradeClient: Uint8Array; + /** proof that old chain committed to new consensus state */ + proofUpgradeConsensusState: Uint8Array; + /** signer address */ + signer: string; +} + +/** MsgUpgradeClientResponse defines the Msg/UpgradeClient response type. */ +export interface MsgUpgradeClientResponse {} + +/** + * MsgSubmitMisbehaviour defines an sdk.Msg type that submits Evidence for + * light client misbehaviour. + */ +export interface MsgSubmitMisbehaviour { + /** client unique identifier */ + clientId: string; + /** misbehaviour used for freezing the light client */ + misbehaviour?: Any; + /** signer address */ + signer: string; +} + +/** MsgSubmitMisbehaviourResponse defines the Msg/SubmitMisbehaviour response type. */ +export interface MsgSubmitMisbehaviourResponse {} + +const baseMsgCreateClient: object = { signer: "" }; + +export const MsgCreateClient = { + encode(message: MsgCreateClient, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.clientState !== undefined) { + Any.encode(message.clientState, writer.uint32(10).fork()).ldelim(); + } + if (message.consensusState !== undefined) { + Any.encode(message.consensusState, writer.uint32(18).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(26).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgCreateClient { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgCreateClient } as MsgCreateClient; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.clientState = Any.decode(reader, reader.uint32()); + break; + case 2: + message.consensusState = Any.decode(reader, reader.uint32()); + break; + case 3: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgCreateClient { + const message = { ...baseMsgCreateClient } as MsgCreateClient; + if (object.clientState !== undefined && object.clientState !== null) { + message.clientState = Any.fromJSON(object.clientState); + } else { + message.clientState = undefined; + } + if (object.consensusState !== undefined && object.consensusState !== null) { + message.consensusState = Any.fromJSON(object.consensusState); + } else { + message.consensusState = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgCreateClient): unknown { + const obj: any = {}; + message.clientState !== undefined && + (obj.clientState = message.clientState ? Any.toJSON(message.clientState) : undefined); + message.consensusState !== undefined && + (obj.consensusState = message.consensusState ? Any.toJSON(message.consensusState) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgCreateClient { + const message = { ...baseMsgCreateClient } as MsgCreateClient; + if (object.clientState !== undefined && object.clientState !== null) { + message.clientState = Any.fromPartial(object.clientState); + } else { + message.clientState = undefined; + } + if (object.consensusState !== undefined && object.consensusState !== null) { + message.consensusState = Any.fromPartial(object.consensusState); + } else { + message.consensusState = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgCreateClientResponse: object = {}; + +export const MsgCreateClientResponse = { + encode(_: MsgCreateClientResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgCreateClientResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgCreateClientResponse } as MsgCreateClientResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgCreateClientResponse { + const message = { ...baseMsgCreateClientResponse } as MsgCreateClientResponse; + return message; + }, + + toJSON(_: MsgCreateClientResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgCreateClientResponse { + const message = { ...baseMsgCreateClientResponse } as MsgCreateClientResponse; + return message; + }, +}; + +const baseMsgUpdateClient: object = { clientId: "", signer: "" }; + +export const MsgUpdateClient = { + encode(message: MsgUpdateClient, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.clientId !== "") { + writer.uint32(10).string(message.clientId); + } + if (message.header !== undefined) { + Any.encode(message.header, writer.uint32(18).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(26).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateClient { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgUpdateClient } as MsgUpdateClient; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.clientId = reader.string(); + break; + case 2: + message.header = Any.decode(reader, reader.uint32()); + break; + case 3: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgUpdateClient { + const message = { ...baseMsgUpdateClient } as MsgUpdateClient; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = String(object.clientId); + } else { + message.clientId = ""; + } + if (object.header !== undefined && object.header !== null) { + message.header = Any.fromJSON(object.header); + } else { + message.header = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgUpdateClient): unknown { + const obj: any = {}; + message.clientId !== undefined && (obj.clientId = message.clientId); + message.header !== undefined && (obj.header = message.header ? Any.toJSON(message.header) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgUpdateClient { + const message = { ...baseMsgUpdateClient } as MsgUpdateClient; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = object.clientId; + } else { + message.clientId = ""; + } + if (object.header !== undefined && object.header !== null) { + message.header = Any.fromPartial(object.header); + } else { + message.header = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgUpdateClientResponse: object = {}; + +export const MsgUpdateClientResponse = { + encode(_: MsgUpdateClientResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateClientResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgUpdateClientResponse } as MsgUpdateClientResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgUpdateClientResponse { + const message = { ...baseMsgUpdateClientResponse } as MsgUpdateClientResponse; + return message; + }, + + toJSON(_: MsgUpdateClientResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgUpdateClientResponse { + const message = { ...baseMsgUpdateClientResponse } as MsgUpdateClientResponse; + return message; + }, +}; + +const baseMsgUpgradeClient: object = { clientId: "", signer: "" }; + +export const MsgUpgradeClient = { + encode(message: MsgUpgradeClient, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.clientId !== "") { + writer.uint32(10).string(message.clientId); + } + if (message.clientState !== undefined) { + Any.encode(message.clientState, writer.uint32(18).fork()).ldelim(); + } + if (message.consensusState !== undefined) { + Any.encode(message.consensusState, writer.uint32(26).fork()).ldelim(); + } + if (message.proofUpgradeClient.length !== 0) { + writer.uint32(34).bytes(message.proofUpgradeClient); + } + if (message.proofUpgradeConsensusState.length !== 0) { + writer.uint32(42).bytes(message.proofUpgradeConsensusState); + } + if (message.signer !== "") { + writer.uint32(50).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpgradeClient { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgUpgradeClient } as MsgUpgradeClient; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.clientId = reader.string(); + break; + case 2: + message.clientState = Any.decode(reader, reader.uint32()); + break; + case 3: + message.consensusState = Any.decode(reader, reader.uint32()); + break; + case 4: + message.proofUpgradeClient = reader.bytes(); + break; + case 5: + message.proofUpgradeConsensusState = reader.bytes(); + break; + case 6: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgUpgradeClient { + const message = { ...baseMsgUpgradeClient } as MsgUpgradeClient; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = String(object.clientId); + } else { + message.clientId = ""; + } + if (object.clientState !== undefined && object.clientState !== null) { + message.clientState = Any.fromJSON(object.clientState); + } else { + message.clientState = undefined; + } + if (object.consensusState !== undefined && object.consensusState !== null) { + message.consensusState = Any.fromJSON(object.consensusState); + } else { + message.consensusState = undefined; + } + if (object.proofUpgradeClient !== undefined && object.proofUpgradeClient !== null) { + message.proofUpgradeClient = bytesFromBase64(object.proofUpgradeClient); + } + if (object.proofUpgradeConsensusState !== undefined && object.proofUpgradeConsensusState !== null) { + message.proofUpgradeConsensusState = bytesFromBase64(object.proofUpgradeConsensusState); + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgUpgradeClient): unknown { + const obj: any = {}; + message.clientId !== undefined && (obj.clientId = message.clientId); + message.clientState !== undefined && + (obj.clientState = message.clientState ? Any.toJSON(message.clientState) : undefined); + message.consensusState !== undefined && + (obj.consensusState = message.consensusState ? Any.toJSON(message.consensusState) : undefined); + message.proofUpgradeClient !== undefined && + (obj.proofUpgradeClient = base64FromBytes( + message.proofUpgradeClient !== undefined ? message.proofUpgradeClient : new Uint8Array(), + )); + message.proofUpgradeConsensusState !== undefined && + (obj.proofUpgradeConsensusState = base64FromBytes( + message.proofUpgradeConsensusState !== undefined + ? message.proofUpgradeConsensusState + : new Uint8Array(), + )); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgUpgradeClient { + const message = { ...baseMsgUpgradeClient } as MsgUpgradeClient; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = object.clientId; + } else { + message.clientId = ""; + } + if (object.clientState !== undefined && object.clientState !== null) { + message.clientState = Any.fromPartial(object.clientState); + } else { + message.clientState = undefined; + } + if (object.consensusState !== undefined && object.consensusState !== null) { + message.consensusState = Any.fromPartial(object.consensusState); + } else { + message.consensusState = undefined; + } + if (object.proofUpgradeClient !== undefined && object.proofUpgradeClient !== null) { + message.proofUpgradeClient = object.proofUpgradeClient; + } else { + message.proofUpgradeClient = new Uint8Array(); + } + if (object.proofUpgradeConsensusState !== undefined && object.proofUpgradeConsensusState !== null) { + message.proofUpgradeConsensusState = object.proofUpgradeConsensusState; + } else { + message.proofUpgradeConsensusState = new Uint8Array(); + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgUpgradeClientResponse: object = {}; + +export const MsgUpgradeClientResponse = { + encode(_: MsgUpgradeClientResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpgradeClientResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgUpgradeClientResponse } as MsgUpgradeClientResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgUpgradeClientResponse { + const message = { ...baseMsgUpgradeClientResponse } as MsgUpgradeClientResponse; + return message; + }, + + toJSON(_: MsgUpgradeClientResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgUpgradeClientResponse { + const message = { ...baseMsgUpgradeClientResponse } as MsgUpgradeClientResponse; + return message; + }, +}; + +const baseMsgSubmitMisbehaviour: object = { clientId: "", signer: "" }; + +export const MsgSubmitMisbehaviour = { + encode(message: MsgSubmitMisbehaviour, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.clientId !== "") { + writer.uint32(10).string(message.clientId); + } + if (message.misbehaviour !== undefined) { + Any.encode(message.misbehaviour, writer.uint32(18).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(26).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgSubmitMisbehaviour { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgSubmitMisbehaviour } as MsgSubmitMisbehaviour; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.clientId = reader.string(); + break; + case 2: + message.misbehaviour = Any.decode(reader, reader.uint32()); + break; + case 3: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgSubmitMisbehaviour { + const message = { ...baseMsgSubmitMisbehaviour } as MsgSubmitMisbehaviour; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = String(object.clientId); + } else { + message.clientId = ""; + } + if (object.misbehaviour !== undefined && object.misbehaviour !== null) { + message.misbehaviour = Any.fromJSON(object.misbehaviour); + } else { + message.misbehaviour = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgSubmitMisbehaviour): unknown { + const obj: any = {}; + message.clientId !== undefined && (obj.clientId = message.clientId); + message.misbehaviour !== undefined && + (obj.misbehaviour = message.misbehaviour ? Any.toJSON(message.misbehaviour) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgSubmitMisbehaviour { + const message = { ...baseMsgSubmitMisbehaviour } as MsgSubmitMisbehaviour; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = object.clientId; + } else { + message.clientId = ""; + } + if (object.misbehaviour !== undefined && object.misbehaviour !== null) { + message.misbehaviour = Any.fromPartial(object.misbehaviour); + } else { + message.misbehaviour = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgSubmitMisbehaviourResponse: object = {}; + +export const MsgSubmitMisbehaviourResponse = { + encode(_: MsgSubmitMisbehaviourResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgSubmitMisbehaviourResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgSubmitMisbehaviourResponse } as MsgSubmitMisbehaviourResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgSubmitMisbehaviourResponse { + const message = { ...baseMsgSubmitMisbehaviourResponse } as MsgSubmitMisbehaviourResponse; + return message; + }, + + toJSON(_: MsgSubmitMisbehaviourResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgSubmitMisbehaviourResponse { + const message = { ...baseMsgSubmitMisbehaviourResponse } as MsgSubmitMisbehaviourResponse; + return message; + }, +}; + +/** Msg defines the ibc/client Msg service. */ +export interface Msg { + /** CreateClient defines a rpc handler method for MsgCreateClient. */ + CreateClient(request: MsgCreateClient): Promise; + /** UpdateClient defines a rpc handler method for MsgUpdateClient. */ + UpdateClient(request: MsgUpdateClient): Promise; + /** UpgradeClient defines a rpc handler method for MsgUpgradeClient. */ + UpgradeClient(request: MsgUpgradeClient): Promise; + /** SubmitMisbehaviour defines a rpc handler method for MsgSubmitMisbehaviour. */ + SubmitMisbehaviour(request: MsgSubmitMisbehaviour): Promise; +} + +export class MsgClientImpl implements Msg { + private readonly rpc: Rpc; + constructor(rpc: Rpc) { + this.rpc = rpc; + } + CreateClient(request: MsgCreateClient): Promise { + const data = MsgCreateClient.encode(request).finish(); + const promise = this.rpc.request("ibc.core.client.v1.Msg", "CreateClient", data); + return promise.then((data) => MsgCreateClientResponse.decode(new _m0.Reader(data))); + } + + UpdateClient(request: MsgUpdateClient): Promise { + const data = MsgUpdateClient.encode(request).finish(); + const promise = this.rpc.request("ibc.core.client.v1.Msg", "UpdateClient", data); + return promise.then((data) => MsgUpdateClientResponse.decode(new _m0.Reader(data))); + } + + UpgradeClient(request: MsgUpgradeClient): Promise { + const data = MsgUpgradeClient.encode(request).finish(); + const promise = this.rpc.request("ibc.core.client.v1.Msg", "UpgradeClient", data); + return promise.then((data) => MsgUpgradeClientResponse.decode(new _m0.Reader(data))); + } + + SubmitMisbehaviour(request: MsgSubmitMisbehaviour): Promise { + const data = MsgSubmitMisbehaviour.encode(request).finish(); + const promise = this.rpc.request("ibc.core.client.v1.Msg", "SubmitMisbehaviour", data); + return promise.then((data) => MsgSubmitMisbehaviourResponse.decode(new _m0.Reader(data))); + } +} + +interface Rpc { + request(service: string, method: string, data: Uint8Array): Promise; +} + +declare var self: any | undefined; +declare var window: any | undefined; +var globalThis: any = (() => { + if (typeof globalThis !== "undefined") return globalThis; + if (typeof self !== "undefined") return self; + if (typeof window !== "undefined") return window; + if (typeof global !== "undefined") return global; + throw "Unable to locate global object"; +})(); + +const atob: (b64: string) => string = + globalThis.atob || ((b64) => globalThis.Buffer.from(b64, "base64").toString("binary")); +function bytesFromBase64(b64: string): Uint8Array { + const bin = atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; +} + +const btoa: (bin: string) => string = + globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); +function base64FromBytes(arr: Uint8Array): string { + const bin: string[] = []; + for (let i = 0; i < arr.byteLength; ++i) { + bin.push(String.fromCharCode(arr[i])); + } + return btoa(bin.join("")); +} + +type Builtin = Date | Function | Uint8Array | string | number | undefined | Long; +export type DeepPartial = T extends Builtin + ? T + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; diff --git a/packages/stargate/src/codec/ibc/core/connection/v1/tx.ts b/packages/stargate/src/codec/ibc/core/connection/v1/tx.ts new file mode 100644 index 00000000..408f6e35 --- /dev/null +++ b/packages/stargate/src/codec/ibc/core/connection/v1/tx.ts @@ -0,0 +1,1042 @@ +/* eslint-disable */ +import { Counterparty, Version } from "../../../../ibc/core/connection/v1/connection"; +import Long from "long"; +import { Any } from "../../../../google/protobuf/any"; +import { Height } from "../../../../ibc/core/client/v1/client"; +import _m0 from "protobufjs/minimal"; + +export const protobufPackage = "ibc.core.connection.v1"; + +/** + * MsgConnectionOpenInit defines the msg sent by an account on Chain A to + * initialize a connection with Chain B. + */ +export interface MsgConnectionOpenInit { + clientId: string; + counterparty?: Counterparty; + version?: Version; + delayPeriod: Long; + signer: string; +} + +/** MsgConnectionOpenInitResponse defines the Msg/ConnectionOpenInit response type. */ +export interface MsgConnectionOpenInitResponse {} + +/** + * MsgConnectionOpenTry defines a msg sent by a Relayer to try to open a + * connection on Chain B. + */ +export interface MsgConnectionOpenTry { + clientId: string; + /** + * in the case of crossing hello's, when both chains call OpenInit, we need the connection identifier + * of the previous connection in state INIT + */ + previousConnectionId: string; + clientState?: Any; + counterparty?: Counterparty; + delayPeriod: Long; + counterpartyVersions: Version[]; + proofHeight?: Height; + /** + * proof of the initialization the connection on Chain A: `UNITIALIZED -> + * INIT` + */ + proofInit: Uint8Array; + /** proof of client state included in message */ + proofClient: Uint8Array; + /** proof of client consensus state */ + proofConsensus: Uint8Array; + consensusHeight?: Height; + signer: string; +} + +/** MsgConnectionOpenTryResponse defines the Msg/ConnectionOpenTry response type. */ +export interface MsgConnectionOpenTryResponse {} + +/** + * MsgConnectionOpenAck defines a msg sent by a Relayer to Chain A to + * acknowledge the change of connection state to TRYOPEN on Chain B. + */ +export interface MsgConnectionOpenAck { + connectionId: string; + counterpartyConnectionId: string; + version?: Version; + clientState?: Any; + proofHeight?: Height; + /** + * proof of the initialization the connection on Chain B: `UNITIALIZED -> + * TRYOPEN` + */ + proofTry: Uint8Array; + /** proof of client state included in message */ + proofClient: Uint8Array; + /** proof of client consensus state */ + proofConsensus: Uint8Array; + consensusHeight?: Height; + signer: string; +} + +/** MsgConnectionOpenAckResponse defines the Msg/ConnectionOpenAck response type. */ +export interface MsgConnectionOpenAckResponse {} + +/** + * MsgConnectionOpenConfirm defines a msg sent by a Relayer to Chain B to + * acknowledge the change of connection state to OPEN on Chain A. + */ +export interface MsgConnectionOpenConfirm { + connectionId: string; + /** proof for the change of the connection state on Chain A: `INIT -> OPEN` */ + proofAck: Uint8Array; + proofHeight?: Height; + signer: string; +} + +/** MsgConnectionOpenConfirmResponse defines the Msg/ConnectionOpenConfirm response type. */ +export interface MsgConnectionOpenConfirmResponse {} + +const baseMsgConnectionOpenInit: object = { clientId: "", delayPeriod: Long.UZERO, signer: "" }; + +export const MsgConnectionOpenInit = { + encode(message: MsgConnectionOpenInit, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.clientId !== "") { + writer.uint32(10).string(message.clientId); + } + if (message.counterparty !== undefined) { + Counterparty.encode(message.counterparty, writer.uint32(18).fork()).ldelim(); + } + if (message.version !== undefined) { + Version.encode(message.version, writer.uint32(26).fork()).ldelim(); + } + if (!message.delayPeriod.isZero()) { + writer.uint32(32).uint64(message.delayPeriod); + } + if (message.signer !== "") { + writer.uint32(42).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgConnectionOpenInit { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgConnectionOpenInit } as MsgConnectionOpenInit; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.clientId = reader.string(); + break; + case 2: + message.counterparty = Counterparty.decode(reader, reader.uint32()); + break; + case 3: + message.version = Version.decode(reader, reader.uint32()); + break; + case 4: + message.delayPeriod = reader.uint64() as Long; + break; + case 5: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgConnectionOpenInit { + const message = { ...baseMsgConnectionOpenInit } as MsgConnectionOpenInit; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = String(object.clientId); + } else { + message.clientId = ""; + } + if (object.counterparty !== undefined && object.counterparty !== null) { + message.counterparty = Counterparty.fromJSON(object.counterparty); + } else { + message.counterparty = undefined; + } + if (object.version !== undefined && object.version !== null) { + message.version = Version.fromJSON(object.version); + } else { + message.version = undefined; + } + if (object.delayPeriod !== undefined && object.delayPeriod !== null) { + message.delayPeriod = Long.fromString(object.delayPeriod); + } else { + message.delayPeriod = Long.UZERO; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgConnectionOpenInit): unknown { + const obj: any = {}; + message.clientId !== undefined && (obj.clientId = message.clientId); + message.counterparty !== undefined && + (obj.counterparty = message.counterparty ? Counterparty.toJSON(message.counterparty) : undefined); + message.version !== undefined && + (obj.version = message.version ? Version.toJSON(message.version) : undefined); + message.delayPeriod !== undefined && (obj.delayPeriod = (message.delayPeriod || Long.UZERO).toString()); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgConnectionOpenInit { + const message = { ...baseMsgConnectionOpenInit } as MsgConnectionOpenInit; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = object.clientId; + } else { + message.clientId = ""; + } + if (object.counterparty !== undefined && object.counterparty !== null) { + message.counterparty = Counterparty.fromPartial(object.counterparty); + } else { + message.counterparty = undefined; + } + if (object.version !== undefined && object.version !== null) { + message.version = Version.fromPartial(object.version); + } else { + message.version = undefined; + } + if (object.delayPeriod !== undefined && object.delayPeriod !== null) { + message.delayPeriod = object.delayPeriod as Long; + } else { + message.delayPeriod = Long.UZERO; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgConnectionOpenInitResponse: object = {}; + +export const MsgConnectionOpenInitResponse = { + encode(_: MsgConnectionOpenInitResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgConnectionOpenInitResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgConnectionOpenInitResponse } as MsgConnectionOpenInitResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgConnectionOpenInitResponse { + const message = { ...baseMsgConnectionOpenInitResponse } as MsgConnectionOpenInitResponse; + return message; + }, + + toJSON(_: MsgConnectionOpenInitResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgConnectionOpenInitResponse { + const message = { ...baseMsgConnectionOpenInitResponse } as MsgConnectionOpenInitResponse; + return message; + }, +}; + +const baseMsgConnectionOpenTry: object = { + clientId: "", + previousConnectionId: "", + delayPeriod: Long.UZERO, + signer: "", +}; + +export const MsgConnectionOpenTry = { + encode(message: MsgConnectionOpenTry, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.clientId !== "") { + writer.uint32(10).string(message.clientId); + } + if (message.previousConnectionId !== "") { + writer.uint32(18).string(message.previousConnectionId); + } + if (message.clientState !== undefined) { + Any.encode(message.clientState, writer.uint32(26).fork()).ldelim(); + } + if (message.counterparty !== undefined) { + Counterparty.encode(message.counterparty, writer.uint32(34).fork()).ldelim(); + } + if (!message.delayPeriod.isZero()) { + writer.uint32(40).uint64(message.delayPeriod); + } + for (const v of message.counterpartyVersions) { + Version.encode(v!, writer.uint32(50).fork()).ldelim(); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(58).fork()).ldelim(); + } + if (message.proofInit.length !== 0) { + writer.uint32(66).bytes(message.proofInit); + } + if (message.proofClient.length !== 0) { + writer.uint32(74).bytes(message.proofClient); + } + if (message.proofConsensus.length !== 0) { + writer.uint32(82).bytes(message.proofConsensus); + } + if (message.consensusHeight !== undefined) { + Height.encode(message.consensusHeight, writer.uint32(90).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(98).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgConnectionOpenTry { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgConnectionOpenTry } as MsgConnectionOpenTry; + message.counterpartyVersions = []; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.clientId = reader.string(); + break; + case 2: + message.previousConnectionId = reader.string(); + break; + case 3: + message.clientState = Any.decode(reader, reader.uint32()); + break; + case 4: + message.counterparty = Counterparty.decode(reader, reader.uint32()); + break; + case 5: + message.delayPeriod = reader.uint64() as Long; + break; + case 6: + message.counterpartyVersions.push(Version.decode(reader, reader.uint32())); + break; + case 7: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + case 8: + message.proofInit = reader.bytes(); + break; + case 9: + message.proofClient = reader.bytes(); + break; + case 10: + message.proofConsensus = reader.bytes(); + break; + case 11: + message.consensusHeight = Height.decode(reader, reader.uint32()); + break; + case 12: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgConnectionOpenTry { + const message = { ...baseMsgConnectionOpenTry } as MsgConnectionOpenTry; + message.counterpartyVersions = []; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = String(object.clientId); + } else { + message.clientId = ""; + } + if (object.previousConnectionId !== undefined && object.previousConnectionId !== null) { + message.previousConnectionId = String(object.previousConnectionId); + } else { + message.previousConnectionId = ""; + } + if (object.clientState !== undefined && object.clientState !== null) { + message.clientState = Any.fromJSON(object.clientState); + } else { + message.clientState = undefined; + } + if (object.counterparty !== undefined && object.counterparty !== null) { + message.counterparty = Counterparty.fromJSON(object.counterparty); + } else { + message.counterparty = undefined; + } + if (object.delayPeriod !== undefined && object.delayPeriod !== null) { + message.delayPeriod = Long.fromString(object.delayPeriod); + } else { + message.delayPeriod = Long.UZERO; + } + if (object.counterpartyVersions !== undefined && object.counterpartyVersions !== null) { + for (const e of object.counterpartyVersions) { + message.counterpartyVersions.push(Version.fromJSON(e)); + } + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.proofInit !== undefined && object.proofInit !== null) { + message.proofInit = bytesFromBase64(object.proofInit); + } + if (object.proofClient !== undefined && object.proofClient !== null) { + message.proofClient = bytesFromBase64(object.proofClient); + } + if (object.proofConsensus !== undefined && object.proofConsensus !== null) { + message.proofConsensus = bytesFromBase64(object.proofConsensus); + } + if (object.consensusHeight !== undefined && object.consensusHeight !== null) { + message.consensusHeight = Height.fromJSON(object.consensusHeight); + } else { + message.consensusHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgConnectionOpenTry): unknown { + const obj: any = {}; + message.clientId !== undefined && (obj.clientId = message.clientId); + message.previousConnectionId !== undefined && (obj.previousConnectionId = message.previousConnectionId); + message.clientState !== undefined && + (obj.clientState = message.clientState ? Any.toJSON(message.clientState) : undefined); + message.counterparty !== undefined && + (obj.counterparty = message.counterparty ? Counterparty.toJSON(message.counterparty) : undefined); + message.delayPeriod !== undefined && (obj.delayPeriod = (message.delayPeriod || Long.UZERO).toString()); + if (message.counterpartyVersions) { + obj.counterpartyVersions = message.counterpartyVersions.map((e) => (e ? Version.toJSON(e) : undefined)); + } else { + obj.counterpartyVersions = []; + } + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + message.proofInit !== undefined && + (obj.proofInit = base64FromBytes( + message.proofInit !== undefined ? message.proofInit : new Uint8Array(), + )); + message.proofClient !== undefined && + (obj.proofClient = base64FromBytes( + message.proofClient !== undefined ? message.proofClient : new Uint8Array(), + )); + message.proofConsensus !== undefined && + (obj.proofConsensus = base64FromBytes( + message.proofConsensus !== undefined ? message.proofConsensus : new Uint8Array(), + )); + message.consensusHeight !== undefined && + (obj.consensusHeight = message.consensusHeight ? Height.toJSON(message.consensusHeight) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgConnectionOpenTry { + const message = { ...baseMsgConnectionOpenTry } as MsgConnectionOpenTry; + message.counterpartyVersions = []; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = object.clientId; + } else { + message.clientId = ""; + } + if (object.previousConnectionId !== undefined && object.previousConnectionId !== null) { + message.previousConnectionId = object.previousConnectionId; + } else { + message.previousConnectionId = ""; + } + if (object.clientState !== undefined && object.clientState !== null) { + message.clientState = Any.fromPartial(object.clientState); + } else { + message.clientState = undefined; + } + if (object.counterparty !== undefined && object.counterparty !== null) { + message.counterparty = Counterparty.fromPartial(object.counterparty); + } else { + message.counterparty = undefined; + } + if (object.delayPeriod !== undefined && object.delayPeriod !== null) { + message.delayPeriod = object.delayPeriod as Long; + } else { + message.delayPeriod = Long.UZERO; + } + if (object.counterpartyVersions !== undefined && object.counterpartyVersions !== null) { + for (const e of object.counterpartyVersions) { + message.counterpartyVersions.push(Version.fromPartial(e)); + } + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.proofInit !== undefined && object.proofInit !== null) { + message.proofInit = object.proofInit; + } else { + message.proofInit = new Uint8Array(); + } + if (object.proofClient !== undefined && object.proofClient !== null) { + message.proofClient = object.proofClient; + } else { + message.proofClient = new Uint8Array(); + } + if (object.proofConsensus !== undefined && object.proofConsensus !== null) { + message.proofConsensus = object.proofConsensus; + } else { + message.proofConsensus = new Uint8Array(); + } + if (object.consensusHeight !== undefined && object.consensusHeight !== null) { + message.consensusHeight = Height.fromPartial(object.consensusHeight); + } else { + message.consensusHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgConnectionOpenTryResponse: object = {}; + +export const MsgConnectionOpenTryResponse = { + encode(_: MsgConnectionOpenTryResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgConnectionOpenTryResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgConnectionOpenTryResponse } as MsgConnectionOpenTryResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgConnectionOpenTryResponse { + const message = { ...baseMsgConnectionOpenTryResponse } as MsgConnectionOpenTryResponse; + return message; + }, + + toJSON(_: MsgConnectionOpenTryResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgConnectionOpenTryResponse { + const message = { ...baseMsgConnectionOpenTryResponse } as MsgConnectionOpenTryResponse; + return message; + }, +}; + +const baseMsgConnectionOpenAck: object = { connectionId: "", counterpartyConnectionId: "", signer: "" }; + +export const MsgConnectionOpenAck = { + encode(message: MsgConnectionOpenAck, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.connectionId !== "") { + writer.uint32(10).string(message.connectionId); + } + if (message.counterpartyConnectionId !== "") { + writer.uint32(18).string(message.counterpartyConnectionId); + } + if (message.version !== undefined) { + Version.encode(message.version, writer.uint32(26).fork()).ldelim(); + } + if (message.clientState !== undefined) { + Any.encode(message.clientState, writer.uint32(34).fork()).ldelim(); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(42).fork()).ldelim(); + } + if (message.proofTry.length !== 0) { + writer.uint32(50).bytes(message.proofTry); + } + if (message.proofClient.length !== 0) { + writer.uint32(58).bytes(message.proofClient); + } + if (message.proofConsensus.length !== 0) { + writer.uint32(66).bytes(message.proofConsensus); + } + if (message.consensusHeight !== undefined) { + Height.encode(message.consensusHeight, writer.uint32(74).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(82).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgConnectionOpenAck { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgConnectionOpenAck } as MsgConnectionOpenAck; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.connectionId = reader.string(); + break; + case 2: + message.counterpartyConnectionId = reader.string(); + break; + case 3: + message.version = Version.decode(reader, reader.uint32()); + break; + case 4: + message.clientState = Any.decode(reader, reader.uint32()); + break; + case 5: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + case 6: + message.proofTry = reader.bytes(); + break; + case 7: + message.proofClient = reader.bytes(); + break; + case 8: + message.proofConsensus = reader.bytes(); + break; + case 9: + message.consensusHeight = Height.decode(reader, reader.uint32()); + break; + case 10: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgConnectionOpenAck { + const message = { ...baseMsgConnectionOpenAck } as MsgConnectionOpenAck; + if (object.connectionId !== undefined && object.connectionId !== null) { + message.connectionId = String(object.connectionId); + } else { + message.connectionId = ""; + } + if (object.counterpartyConnectionId !== undefined && object.counterpartyConnectionId !== null) { + message.counterpartyConnectionId = String(object.counterpartyConnectionId); + } else { + message.counterpartyConnectionId = ""; + } + if (object.version !== undefined && object.version !== null) { + message.version = Version.fromJSON(object.version); + } else { + message.version = undefined; + } + if (object.clientState !== undefined && object.clientState !== null) { + message.clientState = Any.fromJSON(object.clientState); + } else { + message.clientState = undefined; + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.proofTry !== undefined && object.proofTry !== null) { + message.proofTry = bytesFromBase64(object.proofTry); + } + if (object.proofClient !== undefined && object.proofClient !== null) { + message.proofClient = bytesFromBase64(object.proofClient); + } + if (object.proofConsensus !== undefined && object.proofConsensus !== null) { + message.proofConsensus = bytesFromBase64(object.proofConsensus); + } + if (object.consensusHeight !== undefined && object.consensusHeight !== null) { + message.consensusHeight = Height.fromJSON(object.consensusHeight); + } else { + message.consensusHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgConnectionOpenAck): unknown { + const obj: any = {}; + message.connectionId !== undefined && (obj.connectionId = message.connectionId); + message.counterpartyConnectionId !== undefined && + (obj.counterpartyConnectionId = message.counterpartyConnectionId); + message.version !== undefined && + (obj.version = message.version ? Version.toJSON(message.version) : undefined); + message.clientState !== undefined && + (obj.clientState = message.clientState ? Any.toJSON(message.clientState) : undefined); + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + message.proofTry !== undefined && + (obj.proofTry = base64FromBytes(message.proofTry !== undefined ? message.proofTry : new Uint8Array())); + message.proofClient !== undefined && + (obj.proofClient = base64FromBytes( + message.proofClient !== undefined ? message.proofClient : new Uint8Array(), + )); + message.proofConsensus !== undefined && + (obj.proofConsensus = base64FromBytes( + message.proofConsensus !== undefined ? message.proofConsensus : new Uint8Array(), + )); + message.consensusHeight !== undefined && + (obj.consensusHeight = message.consensusHeight ? Height.toJSON(message.consensusHeight) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgConnectionOpenAck { + const message = { ...baseMsgConnectionOpenAck } as MsgConnectionOpenAck; + if (object.connectionId !== undefined && object.connectionId !== null) { + message.connectionId = object.connectionId; + } else { + message.connectionId = ""; + } + if (object.counterpartyConnectionId !== undefined && object.counterpartyConnectionId !== null) { + message.counterpartyConnectionId = object.counterpartyConnectionId; + } else { + message.counterpartyConnectionId = ""; + } + if (object.version !== undefined && object.version !== null) { + message.version = Version.fromPartial(object.version); + } else { + message.version = undefined; + } + if (object.clientState !== undefined && object.clientState !== null) { + message.clientState = Any.fromPartial(object.clientState); + } else { + message.clientState = undefined; + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.proofTry !== undefined && object.proofTry !== null) { + message.proofTry = object.proofTry; + } else { + message.proofTry = new Uint8Array(); + } + if (object.proofClient !== undefined && object.proofClient !== null) { + message.proofClient = object.proofClient; + } else { + message.proofClient = new Uint8Array(); + } + if (object.proofConsensus !== undefined && object.proofConsensus !== null) { + message.proofConsensus = object.proofConsensus; + } else { + message.proofConsensus = new Uint8Array(); + } + if (object.consensusHeight !== undefined && object.consensusHeight !== null) { + message.consensusHeight = Height.fromPartial(object.consensusHeight); + } else { + message.consensusHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgConnectionOpenAckResponse: object = {}; + +export const MsgConnectionOpenAckResponse = { + encode(_: MsgConnectionOpenAckResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgConnectionOpenAckResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgConnectionOpenAckResponse } as MsgConnectionOpenAckResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgConnectionOpenAckResponse { + const message = { ...baseMsgConnectionOpenAckResponse } as MsgConnectionOpenAckResponse; + return message; + }, + + toJSON(_: MsgConnectionOpenAckResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgConnectionOpenAckResponse { + const message = { ...baseMsgConnectionOpenAckResponse } as MsgConnectionOpenAckResponse; + return message; + }, +}; + +const baseMsgConnectionOpenConfirm: object = { connectionId: "", signer: "" }; + +export const MsgConnectionOpenConfirm = { + encode(message: MsgConnectionOpenConfirm, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.connectionId !== "") { + writer.uint32(10).string(message.connectionId); + } + if (message.proofAck.length !== 0) { + writer.uint32(18).bytes(message.proofAck); + } + if (message.proofHeight !== undefined) { + Height.encode(message.proofHeight, writer.uint32(26).fork()).ldelim(); + } + if (message.signer !== "") { + writer.uint32(34).string(message.signer); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgConnectionOpenConfirm { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgConnectionOpenConfirm } as MsgConnectionOpenConfirm; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.connectionId = reader.string(); + break; + case 2: + message.proofAck = reader.bytes(); + break; + case 3: + message.proofHeight = Height.decode(reader, reader.uint32()); + break; + case 4: + message.signer = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): MsgConnectionOpenConfirm { + const message = { ...baseMsgConnectionOpenConfirm } as MsgConnectionOpenConfirm; + if (object.connectionId !== undefined && object.connectionId !== null) { + message.connectionId = String(object.connectionId); + } else { + message.connectionId = ""; + } + if (object.proofAck !== undefined && object.proofAck !== null) { + message.proofAck = bytesFromBase64(object.proofAck); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromJSON(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = String(object.signer); + } else { + message.signer = ""; + } + return message; + }, + + toJSON(message: MsgConnectionOpenConfirm): unknown { + const obj: any = {}; + message.connectionId !== undefined && (obj.connectionId = message.connectionId); + message.proofAck !== undefined && + (obj.proofAck = base64FromBytes(message.proofAck !== undefined ? message.proofAck : new Uint8Array())); + message.proofHeight !== undefined && + (obj.proofHeight = message.proofHeight ? Height.toJSON(message.proofHeight) : undefined); + message.signer !== undefined && (obj.signer = message.signer); + return obj; + }, + + fromPartial(object: DeepPartial): MsgConnectionOpenConfirm { + const message = { ...baseMsgConnectionOpenConfirm } as MsgConnectionOpenConfirm; + if (object.connectionId !== undefined && object.connectionId !== null) { + message.connectionId = object.connectionId; + } else { + message.connectionId = ""; + } + if (object.proofAck !== undefined && object.proofAck !== null) { + message.proofAck = object.proofAck; + } else { + message.proofAck = new Uint8Array(); + } + if (object.proofHeight !== undefined && object.proofHeight !== null) { + message.proofHeight = Height.fromPartial(object.proofHeight); + } else { + message.proofHeight = undefined; + } + if (object.signer !== undefined && object.signer !== null) { + message.signer = object.signer; + } else { + message.signer = ""; + } + return message; + }, +}; + +const baseMsgConnectionOpenConfirmResponse: object = {}; + +export const MsgConnectionOpenConfirmResponse = { + encode(_: MsgConnectionOpenConfirmResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgConnectionOpenConfirmResponse { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMsgConnectionOpenConfirmResponse } as MsgConnectionOpenConfirmResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): MsgConnectionOpenConfirmResponse { + const message = { ...baseMsgConnectionOpenConfirmResponse } as MsgConnectionOpenConfirmResponse; + return message; + }, + + toJSON(_: MsgConnectionOpenConfirmResponse): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): MsgConnectionOpenConfirmResponse { + const message = { ...baseMsgConnectionOpenConfirmResponse } as MsgConnectionOpenConfirmResponse; + return message; + }, +}; + +/** Msg defines the ibc/connection Msg service. */ +export interface Msg { + /** ConnectionOpenInit defines a rpc handler method for MsgConnectionOpenInit. */ + ConnectionOpenInit(request: MsgConnectionOpenInit): Promise; + /** ConnectionOpenTry defines a rpc handler method for MsgConnectionOpenTry. */ + ConnectionOpenTry(request: MsgConnectionOpenTry): Promise; + /** ConnectionOpenAck defines a rpc handler method for MsgConnectionOpenAck. */ + ConnectionOpenAck(request: MsgConnectionOpenAck): Promise; + /** ConnectionOpenConfirm defines a rpc handler method for MsgConnectionOpenConfirm. */ + ConnectionOpenConfirm(request: MsgConnectionOpenConfirm): Promise; +} + +export class MsgClientImpl implements Msg { + private readonly rpc: Rpc; + constructor(rpc: Rpc) { + this.rpc = rpc; + } + ConnectionOpenInit(request: MsgConnectionOpenInit): Promise { + const data = MsgConnectionOpenInit.encode(request).finish(); + const promise = this.rpc.request("ibc.core.connection.v1.Msg", "ConnectionOpenInit", data); + return promise.then((data) => MsgConnectionOpenInitResponse.decode(new _m0.Reader(data))); + } + + ConnectionOpenTry(request: MsgConnectionOpenTry): Promise { + const data = MsgConnectionOpenTry.encode(request).finish(); + const promise = this.rpc.request("ibc.core.connection.v1.Msg", "ConnectionOpenTry", data); + return promise.then((data) => MsgConnectionOpenTryResponse.decode(new _m0.Reader(data))); + } + + ConnectionOpenAck(request: MsgConnectionOpenAck): Promise { + const data = MsgConnectionOpenAck.encode(request).finish(); + const promise = this.rpc.request("ibc.core.connection.v1.Msg", "ConnectionOpenAck", data); + return promise.then((data) => MsgConnectionOpenAckResponse.decode(new _m0.Reader(data))); + } + + ConnectionOpenConfirm(request: MsgConnectionOpenConfirm): Promise { + const data = MsgConnectionOpenConfirm.encode(request).finish(); + const promise = this.rpc.request("ibc.core.connection.v1.Msg", "ConnectionOpenConfirm", data); + return promise.then((data) => MsgConnectionOpenConfirmResponse.decode(new _m0.Reader(data))); + } +} + +interface Rpc { + request(service: string, method: string, data: Uint8Array): Promise; +} + +declare var self: any | undefined; +declare var window: any | undefined; +var globalThis: any = (() => { + if (typeof globalThis !== "undefined") return globalThis; + if (typeof self !== "undefined") return self; + if (typeof window !== "undefined") return window; + if (typeof global !== "undefined") return global; + throw "Unable to locate global object"; +})(); + +const atob: (b64: string) => string = + globalThis.atob || ((b64) => globalThis.Buffer.from(b64, "base64").toString("binary")); +function bytesFromBase64(b64: string): Uint8Array { + const bin = atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; +} + +const btoa: (bin: string) => string = + globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); +function base64FromBytes(arr: Uint8Array): string { + const bin: string[] = []; + for (let i = 0; i < arr.byteLength; ++i) { + bin.push(String.fromCharCode(arr[i])); + } + return btoa(bin.join("")); +} + +type Builtin = Date | Function | Uint8Array | string | number | undefined | Long; +export type DeepPartial = T extends Builtin + ? T + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; diff --git a/packages/stargate/src/codec/ibc/lightclients/tendermint/v1/tendermint.ts b/packages/stargate/src/codec/ibc/lightclients/tendermint/v1/tendermint.ts new file mode 100644 index 00000000..0e3feb14 --- /dev/null +++ b/packages/stargate/src/codec/ibc/lightclients/tendermint/v1/tendermint.ts @@ -0,0 +1,794 @@ +/* eslint-disable */ +import { Duration } from "../../../../google/protobuf/duration"; +import { Height } from "../../../../ibc/core/client/v1/client"; +import { MerkleRoot } from "../../../../ibc/core/commitment/v1/commitment"; +import { SignedHeader } from "../../../../tendermint/types/types"; +import { ValidatorSet } from "../../../../tendermint/types/validator"; +import Long from "long"; +import { Timestamp } from "../../../../google/protobuf/timestamp"; +import { ProofSpec } from "../../../../confio/proofs"; +import _m0 from "protobufjs/minimal"; + +export const protobufPackage = "ibc.lightclients.tendermint.v1"; + +/** + * ClientState from Tendermint tracks the current validator set, latest height, + * and a possible frozen height. + */ +export interface ClientState { + chainId: string; + trustLevel?: Fraction; + /** + * duration of the period since the LastestTimestamp during which the + * submitted headers are valid for upgrade + */ + trustingPeriod?: Duration; + /** duration of the staking unbonding period */ + unbondingPeriod?: Duration; + /** defines how much new (untrusted) header's Time can drift into the future. */ + maxClockDrift?: Duration; + /** Block height when the client was frozen due to a misbehaviour */ + frozenHeight?: Height; + /** Latest height the client was updated to */ + latestHeight?: Height; + /** Proof specifications used in verifying counterparty state */ + proofSpecs: ProofSpec[]; + /** + * Path at which next upgraded client will be committed. + * Each element corresponds to the key for a single CommitmentProof in the chained proof. + * NOTE: ClientState must stored under `{upgradePath}/{upgradeHeight}/clientState` + * ConsensusState must be stored under `{upgradepath}/{upgradeHeight}/consensusState` + * For SDK chains using the default upgrade module, upgrade_path should be []string{"upgrade", "upgradedIBCState"}` + */ + upgradePath: string[]; + /** + * This flag, when set to true, will allow governance to recover a client + * which has expired + */ + allowUpdateAfterExpiry: boolean; + /** + * This flag, when set to true, will allow governance to unfreeze a client + * whose chain has experienced a misbehaviour event + */ + allowUpdateAfterMisbehaviour: boolean; +} + +/** ConsensusState defines the consensus state from Tendermint. */ +export interface ConsensusState { + /** + * timestamp that corresponds to the block height in which the ConsensusState + * was stored. + */ + timestamp?: Date; + /** commitment root (i.e app hash) */ + root?: MerkleRoot; + nextValidatorsHash: Uint8Array; +} + +/** + * Misbehaviour is a wrapper over two conflicting Headers + * that implements Misbehaviour interface expected by ICS-02 + */ +export interface Misbehaviour { + clientId: string; + header1?: Header; + header2?: Header; +} + +/** + * Header defines the Tendermint client consensus Header. + * It encapsulates all the information necessary to update from a trusted + * Tendermint ConsensusState. The inclusion of TrustedHeight and + * TrustedValidators allows this update to process correctly, so long as the + * ConsensusState for the TrustedHeight exists, this removes race conditions + * among relayers The SignedHeader and ValidatorSet are the new untrusted update + * fields for the client. The TrustedHeight is the height of a stored + * ConsensusState on the client that will be used to verify the new untrusted + * header. The Trusted ConsensusState must be within the unbonding period of + * current time in order to correctly verify, and the TrustedValidators must + * hash to TrustedConsensusState.NextValidatorsHash since that is the last + * trusted validator set at the TrustedHeight. + */ +export interface Header { + signedHeader?: SignedHeader; + validatorSet?: ValidatorSet; + trustedHeight?: Height; + trustedValidators?: ValidatorSet; +} + +/** Fraction defines the protobuf message type for tmmath.Fraction that only supports positive values. */ +export interface Fraction { + numerator: Long; + denominator: Long; +} + +const baseClientState: object = { + chainId: "", + upgradePath: "", + allowUpdateAfterExpiry: false, + allowUpdateAfterMisbehaviour: false, +}; + +export const ClientState = { + encode(message: ClientState, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.chainId !== "") { + writer.uint32(10).string(message.chainId); + } + if (message.trustLevel !== undefined) { + Fraction.encode(message.trustLevel, writer.uint32(18).fork()).ldelim(); + } + if (message.trustingPeriod !== undefined) { + Duration.encode(message.trustingPeriod, writer.uint32(26).fork()).ldelim(); + } + if (message.unbondingPeriod !== undefined) { + Duration.encode(message.unbondingPeriod, writer.uint32(34).fork()).ldelim(); + } + if (message.maxClockDrift !== undefined) { + Duration.encode(message.maxClockDrift, writer.uint32(42).fork()).ldelim(); + } + if (message.frozenHeight !== undefined) { + Height.encode(message.frozenHeight, writer.uint32(50).fork()).ldelim(); + } + if (message.latestHeight !== undefined) { + Height.encode(message.latestHeight, writer.uint32(58).fork()).ldelim(); + } + for (const v of message.proofSpecs) { + ProofSpec.encode(v!, writer.uint32(66).fork()).ldelim(); + } + for (const v of message.upgradePath) { + writer.uint32(74).string(v!); + } + if (message.allowUpdateAfterExpiry === true) { + writer.uint32(80).bool(message.allowUpdateAfterExpiry); + } + if (message.allowUpdateAfterMisbehaviour === true) { + writer.uint32(88).bool(message.allowUpdateAfterMisbehaviour); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): ClientState { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseClientState } as ClientState; + message.proofSpecs = []; + message.upgradePath = []; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.chainId = reader.string(); + break; + case 2: + message.trustLevel = Fraction.decode(reader, reader.uint32()); + break; + case 3: + message.trustingPeriod = Duration.decode(reader, reader.uint32()); + break; + case 4: + message.unbondingPeriod = Duration.decode(reader, reader.uint32()); + break; + case 5: + message.maxClockDrift = Duration.decode(reader, reader.uint32()); + break; + case 6: + message.frozenHeight = Height.decode(reader, reader.uint32()); + break; + case 7: + message.latestHeight = Height.decode(reader, reader.uint32()); + break; + case 8: + message.proofSpecs.push(ProofSpec.decode(reader, reader.uint32())); + break; + case 9: + message.upgradePath.push(reader.string()); + break; + case 10: + message.allowUpdateAfterExpiry = reader.bool(); + break; + case 11: + message.allowUpdateAfterMisbehaviour = reader.bool(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): ClientState { + const message = { ...baseClientState } as ClientState; + message.proofSpecs = []; + message.upgradePath = []; + if (object.chainId !== undefined && object.chainId !== null) { + message.chainId = String(object.chainId); + } else { + message.chainId = ""; + } + if (object.trustLevel !== undefined && object.trustLevel !== null) { + message.trustLevel = Fraction.fromJSON(object.trustLevel); + } else { + message.trustLevel = undefined; + } + if (object.trustingPeriod !== undefined && object.trustingPeriod !== null) { + message.trustingPeriod = Duration.fromJSON(object.trustingPeriod); + } else { + message.trustingPeriod = undefined; + } + if (object.unbondingPeriod !== undefined && object.unbondingPeriod !== null) { + message.unbondingPeriod = Duration.fromJSON(object.unbondingPeriod); + } else { + message.unbondingPeriod = undefined; + } + if (object.maxClockDrift !== undefined && object.maxClockDrift !== null) { + message.maxClockDrift = Duration.fromJSON(object.maxClockDrift); + } else { + message.maxClockDrift = undefined; + } + if (object.frozenHeight !== undefined && object.frozenHeight !== null) { + message.frozenHeight = Height.fromJSON(object.frozenHeight); + } else { + message.frozenHeight = undefined; + } + if (object.latestHeight !== undefined && object.latestHeight !== null) { + message.latestHeight = Height.fromJSON(object.latestHeight); + } else { + message.latestHeight = undefined; + } + if (object.proofSpecs !== undefined && object.proofSpecs !== null) { + for (const e of object.proofSpecs) { + message.proofSpecs.push(ProofSpec.fromJSON(e)); + } + } + if (object.upgradePath !== undefined && object.upgradePath !== null) { + for (const e of object.upgradePath) { + message.upgradePath.push(String(e)); + } + } + if (object.allowUpdateAfterExpiry !== undefined && object.allowUpdateAfterExpiry !== null) { + message.allowUpdateAfterExpiry = Boolean(object.allowUpdateAfterExpiry); + } else { + message.allowUpdateAfterExpiry = false; + } + if (object.allowUpdateAfterMisbehaviour !== undefined && object.allowUpdateAfterMisbehaviour !== null) { + message.allowUpdateAfterMisbehaviour = Boolean(object.allowUpdateAfterMisbehaviour); + } else { + message.allowUpdateAfterMisbehaviour = false; + } + return message; + }, + + toJSON(message: ClientState): unknown { + const obj: any = {}; + message.chainId !== undefined && (obj.chainId = message.chainId); + message.trustLevel !== undefined && + (obj.trustLevel = message.trustLevel ? Fraction.toJSON(message.trustLevel) : undefined); + message.trustingPeriod !== undefined && + (obj.trustingPeriod = message.trustingPeriod ? Duration.toJSON(message.trustingPeriod) : undefined); + message.unbondingPeriod !== undefined && + (obj.unbondingPeriod = message.unbondingPeriod ? Duration.toJSON(message.unbondingPeriod) : undefined); + message.maxClockDrift !== undefined && + (obj.maxClockDrift = message.maxClockDrift ? Duration.toJSON(message.maxClockDrift) : undefined); + message.frozenHeight !== undefined && + (obj.frozenHeight = message.frozenHeight ? Height.toJSON(message.frozenHeight) : undefined); + message.latestHeight !== undefined && + (obj.latestHeight = message.latestHeight ? Height.toJSON(message.latestHeight) : undefined); + if (message.proofSpecs) { + obj.proofSpecs = message.proofSpecs.map((e) => (e ? ProofSpec.toJSON(e) : undefined)); + } else { + obj.proofSpecs = []; + } + if (message.upgradePath) { + obj.upgradePath = message.upgradePath.map((e) => e); + } else { + obj.upgradePath = []; + } + message.allowUpdateAfterExpiry !== undefined && + (obj.allowUpdateAfterExpiry = message.allowUpdateAfterExpiry); + message.allowUpdateAfterMisbehaviour !== undefined && + (obj.allowUpdateAfterMisbehaviour = message.allowUpdateAfterMisbehaviour); + return obj; + }, + + fromPartial(object: DeepPartial): ClientState { + const message = { ...baseClientState } as ClientState; + message.proofSpecs = []; + message.upgradePath = []; + if (object.chainId !== undefined && object.chainId !== null) { + message.chainId = object.chainId; + } else { + message.chainId = ""; + } + if (object.trustLevel !== undefined && object.trustLevel !== null) { + message.trustLevel = Fraction.fromPartial(object.trustLevel); + } else { + message.trustLevel = undefined; + } + if (object.trustingPeriod !== undefined && object.trustingPeriod !== null) { + message.trustingPeriod = Duration.fromPartial(object.trustingPeriod); + } else { + message.trustingPeriod = undefined; + } + if (object.unbondingPeriod !== undefined && object.unbondingPeriod !== null) { + message.unbondingPeriod = Duration.fromPartial(object.unbondingPeriod); + } else { + message.unbondingPeriod = undefined; + } + if (object.maxClockDrift !== undefined && object.maxClockDrift !== null) { + message.maxClockDrift = Duration.fromPartial(object.maxClockDrift); + } else { + message.maxClockDrift = undefined; + } + if (object.frozenHeight !== undefined && object.frozenHeight !== null) { + message.frozenHeight = Height.fromPartial(object.frozenHeight); + } else { + message.frozenHeight = undefined; + } + if (object.latestHeight !== undefined && object.latestHeight !== null) { + message.latestHeight = Height.fromPartial(object.latestHeight); + } else { + message.latestHeight = undefined; + } + if (object.proofSpecs !== undefined && object.proofSpecs !== null) { + for (const e of object.proofSpecs) { + message.proofSpecs.push(ProofSpec.fromPartial(e)); + } + } + if (object.upgradePath !== undefined && object.upgradePath !== null) { + for (const e of object.upgradePath) { + message.upgradePath.push(e); + } + } + if (object.allowUpdateAfterExpiry !== undefined && object.allowUpdateAfterExpiry !== null) { + message.allowUpdateAfterExpiry = object.allowUpdateAfterExpiry; + } else { + message.allowUpdateAfterExpiry = false; + } + if (object.allowUpdateAfterMisbehaviour !== undefined && object.allowUpdateAfterMisbehaviour !== null) { + message.allowUpdateAfterMisbehaviour = object.allowUpdateAfterMisbehaviour; + } else { + message.allowUpdateAfterMisbehaviour = false; + } + return message; + }, +}; + +const baseConsensusState: object = {}; + +export const ConsensusState = { + encode(message: ConsensusState, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.timestamp !== undefined) { + Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(10).fork()).ldelim(); + } + if (message.root !== undefined) { + MerkleRoot.encode(message.root, writer.uint32(18).fork()).ldelim(); + } + if (message.nextValidatorsHash.length !== 0) { + writer.uint32(26).bytes(message.nextValidatorsHash); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): ConsensusState { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseConsensusState } as ConsensusState; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.timestamp = fromTimestamp(Timestamp.decode(reader, reader.uint32())); + break; + case 2: + message.root = MerkleRoot.decode(reader, reader.uint32()); + break; + case 3: + message.nextValidatorsHash = reader.bytes(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): ConsensusState { + const message = { ...baseConsensusState } as ConsensusState; + if (object.timestamp !== undefined && object.timestamp !== null) { + message.timestamp = fromJsonTimestamp(object.timestamp); + } else { + message.timestamp = undefined; + } + if (object.root !== undefined && object.root !== null) { + message.root = MerkleRoot.fromJSON(object.root); + } else { + message.root = undefined; + } + if (object.nextValidatorsHash !== undefined && object.nextValidatorsHash !== null) { + message.nextValidatorsHash = bytesFromBase64(object.nextValidatorsHash); + } + return message; + }, + + toJSON(message: ConsensusState): unknown { + const obj: any = {}; + message.timestamp !== undefined && + (obj.timestamp = message.timestamp !== undefined ? message.timestamp.toISOString() : null); + message.root !== undefined && (obj.root = message.root ? MerkleRoot.toJSON(message.root) : undefined); + message.nextValidatorsHash !== undefined && + (obj.nextValidatorsHash = base64FromBytes( + message.nextValidatorsHash !== undefined ? message.nextValidatorsHash : new Uint8Array(), + )); + return obj; + }, + + fromPartial(object: DeepPartial): ConsensusState { + const message = { ...baseConsensusState } as ConsensusState; + if (object.timestamp !== undefined && object.timestamp !== null) { + message.timestamp = object.timestamp; + } else { + message.timestamp = undefined; + } + if (object.root !== undefined && object.root !== null) { + message.root = MerkleRoot.fromPartial(object.root); + } else { + message.root = undefined; + } + if (object.nextValidatorsHash !== undefined && object.nextValidatorsHash !== null) { + message.nextValidatorsHash = object.nextValidatorsHash; + } else { + message.nextValidatorsHash = new Uint8Array(); + } + return message; + }, +}; + +const baseMisbehaviour: object = { clientId: "" }; + +export const Misbehaviour = { + encode(message: Misbehaviour, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.clientId !== "") { + writer.uint32(10).string(message.clientId); + } + if (message.header1 !== undefined) { + Header.encode(message.header1, writer.uint32(18).fork()).ldelim(); + } + if (message.header2 !== undefined) { + Header.encode(message.header2, writer.uint32(26).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Misbehaviour { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMisbehaviour } as Misbehaviour; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.clientId = reader.string(); + break; + case 2: + message.header1 = Header.decode(reader, reader.uint32()); + break; + case 3: + message.header2 = Header.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Misbehaviour { + const message = { ...baseMisbehaviour } as Misbehaviour; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = String(object.clientId); + } else { + message.clientId = ""; + } + if (object.header1 !== undefined && object.header1 !== null) { + message.header1 = Header.fromJSON(object.header1); + } else { + message.header1 = undefined; + } + if (object.header2 !== undefined && object.header2 !== null) { + message.header2 = Header.fromJSON(object.header2); + } else { + message.header2 = undefined; + } + return message; + }, + + toJSON(message: Misbehaviour): unknown { + const obj: any = {}; + message.clientId !== undefined && (obj.clientId = message.clientId); + message.header1 !== undefined && + (obj.header1 = message.header1 ? Header.toJSON(message.header1) : undefined); + message.header2 !== undefined && + (obj.header2 = message.header2 ? Header.toJSON(message.header2) : undefined); + return obj; + }, + + fromPartial(object: DeepPartial): Misbehaviour { + const message = { ...baseMisbehaviour } as Misbehaviour; + if (object.clientId !== undefined && object.clientId !== null) { + message.clientId = object.clientId; + } else { + message.clientId = ""; + } + if (object.header1 !== undefined && object.header1 !== null) { + message.header1 = Header.fromPartial(object.header1); + } else { + message.header1 = undefined; + } + if (object.header2 !== undefined && object.header2 !== null) { + message.header2 = Header.fromPartial(object.header2); + } else { + message.header2 = undefined; + } + return message; + }, +}; + +const baseHeader: object = {}; + +export const Header = { + encode(message: Header, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.signedHeader !== undefined) { + SignedHeader.encode(message.signedHeader, writer.uint32(10).fork()).ldelim(); + } + if (message.validatorSet !== undefined) { + ValidatorSet.encode(message.validatorSet, writer.uint32(18).fork()).ldelim(); + } + if (message.trustedHeight !== undefined) { + Height.encode(message.trustedHeight, writer.uint32(26).fork()).ldelim(); + } + if (message.trustedValidators !== undefined) { + ValidatorSet.encode(message.trustedValidators, writer.uint32(34).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Header { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseHeader } as Header; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.signedHeader = SignedHeader.decode(reader, reader.uint32()); + break; + case 2: + message.validatorSet = ValidatorSet.decode(reader, reader.uint32()); + break; + case 3: + message.trustedHeight = Height.decode(reader, reader.uint32()); + break; + case 4: + message.trustedValidators = ValidatorSet.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Header { + const message = { ...baseHeader } as Header; + if (object.signedHeader !== undefined && object.signedHeader !== null) { + message.signedHeader = SignedHeader.fromJSON(object.signedHeader); + } else { + message.signedHeader = undefined; + } + if (object.validatorSet !== undefined && object.validatorSet !== null) { + message.validatorSet = ValidatorSet.fromJSON(object.validatorSet); + } else { + message.validatorSet = undefined; + } + if (object.trustedHeight !== undefined && object.trustedHeight !== null) { + message.trustedHeight = Height.fromJSON(object.trustedHeight); + } else { + message.trustedHeight = undefined; + } + if (object.trustedValidators !== undefined && object.trustedValidators !== null) { + message.trustedValidators = ValidatorSet.fromJSON(object.trustedValidators); + } else { + message.trustedValidators = undefined; + } + return message; + }, + + toJSON(message: Header): unknown { + const obj: any = {}; + message.signedHeader !== undefined && + (obj.signedHeader = message.signedHeader ? SignedHeader.toJSON(message.signedHeader) : undefined); + message.validatorSet !== undefined && + (obj.validatorSet = message.validatorSet ? ValidatorSet.toJSON(message.validatorSet) : undefined); + message.trustedHeight !== undefined && + (obj.trustedHeight = message.trustedHeight ? Height.toJSON(message.trustedHeight) : undefined); + message.trustedValidators !== undefined && + (obj.trustedValidators = message.trustedValidators + ? ValidatorSet.toJSON(message.trustedValidators) + : undefined); + return obj; + }, + + fromPartial(object: DeepPartial
): Header { + const message = { ...baseHeader } as Header; + if (object.signedHeader !== undefined && object.signedHeader !== null) { + message.signedHeader = SignedHeader.fromPartial(object.signedHeader); + } else { + message.signedHeader = undefined; + } + if (object.validatorSet !== undefined && object.validatorSet !== null) { + message.validatorSet = ValidatorSet.fromPartial(object.validatorSet); + } else { + message.validatorSet = undefined; + } + if (object.trustedHeight !== undefined && object.trustedHeight !== null) { + message.trustedHeight = Height.fromPartial(object.trustedHeight); + } else { + message.trustedHeight = undefined; + } + if (object.trustedValidators !== undefined && object.trustedValidators !== null) { + message.trustedValidators = ValidatorSet.fromPartial(object.trustedValidators); + } else { + message.trustedValidators = undefined; + } + return message; + }, +}; + +const baseFraction: object = { numerator: Long.UZERO, denominator: Long.UZERO }; + +export const Fraction = { + encode(message: Fraction, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (!message.numerator.isZero()) { + writer.uint32(8).uint64(message.numerator); + } + if (!message.denominator.isZero()) { + writer.uint32(16).uint64(message.denominator); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Fraction { + const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseFraction } as Fraction; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.numerator = reader.uint64() as Long; + break; + case 2: + message.denominator = reader.uint64() as Long; + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Fraction { + const message = { ...baseFraction } as Fraction; + if (object.numerator !== undefined && object.numerator !== null) { + message.numerator = Long.fromString(object.numerator); + } else { + message.numerator = Long.UZERO; + } + if (object.denominator !== undefined && object.denominator !== null) { + message.denominator = Long.fromString(object.denominator); + } else { + message.denominator = Long.UZERO; + } + return message; + }, + + toJSON(message: Fraction): unknown { + const obj: any = {}; + message.numerator !== undefined && (obj.numerator = (message.numerator || Long.UZERO).toString()); + message.denominator !== undefined && (obj.denominator = (message.denominator || Long.UZERO).toString()); + return obj; + }, + + fromPartial(object: DeepPartial): Fraction { + const message = { ...baseFraction } as Fraction; + if (object.numerator !== undefined && object.numerator !== null) { + message.numerator = object.numerator as Long; + } else { + message.numerator = Long.UZERO; + } + if (object.denominator !== undefined && object.denominator !== null) { + message.denominator = object.denominator as Long; + } else { + message.denominator = Long.UZERO; + } + return message; + }, +}; + +declare var self: any | undefined; +declare var window: any | undefined; +var globalThis: any = (() => { + if (typeof globalThis !== "undefined") return globalThis; + if (typeof self !== "undefined") return self; + if (typeof window !== "undefined") return window; + if (typeof global !== "undefined") return global; + throw "Unable to locate global object"; +})(); + +const atob: (b64: string) => string = + globalThis.atob || ((b64) => globalThis.Buffer.from(b64, "base64").toString("binary")); +function bytesFromBase64(b64: string): Uint8Array { + const bin = atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; +} + +const btoa: (bin: string) => string = + globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); +function base64FromBytes(arr: Uint8Array): string { + const bin: string[] = []; + for (let i = 0; i < arr.byteLength; ++i) { + bin.push(String.fromCharCode(arr[i])); + } + return btoa(bin.join("")); +} + +type Builtin = Date | Function | Uint8Array | string | number | undefined | Long; +export type DeepPartial = T extends Builtin + ? T + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; + +function toTimestamp(date: Date): Timestamp { + const seconds = numberToLong(date.getTime() / 1_000); + const nanos = (date.getTime() % 1_000) * 1_000_000; + return { seconds, nanos }; +} + +function fromTimestamp(t: Timestamp): Date { + let millis = t.seconds.toNumber() * 1_000; + millis += t.nanos / 1_000_000; + return new Date(millis); +} + +function fromJsonTimestamp(o: any): Date { + if (o instanceof Date) { + return o; + } else if (typeof o === "string") { + return new Date(o); + } else { + return fromTimestamp(Timestamp.fromJSON(o)); + } +} + +function numberToLong(number: number) { + return Long.fromNumber(number); +} + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any; + _m0.configure(); +} diff --git a/packages/stargate/src/queries/ibc.spec.ts b/packages/stargate/src/queries/ibc.spec.ts index d5f51b7a..8b6a5dab 100644 --- a/packages/stargate/src/queries/ibc.spec.ts +++ b/packages/stargate/src/queries/ibc.spec.ts @@ -14,220 +14,562 @@ async function makeClientWithIbc(rpcUrl: string): Promise<[QueryClient & IbcExte describe("IbcExtension", () => { describe("unverified", () => { describe("channel", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + describe("channel", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - const response = await client.ibc.unverified.channel(ibcTest.portId, ibcTest.channelId); - expect(response.channel).toEqual(ibcTest.channel); - expect(response.proofHeight).toBeDefined(); - expect(response.proofHeight).not.toBeNull(); + const response = await client.ibc.unverified.channel.channel(ibcTest.portId, ibcTest.channelId); + expect(response.channel).toEqual(ibcTest.channel); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); - tmClient.disconnect(); + tmClient.disconnect(); + }); + }); + + describe("channels", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.channels(); + expect(response.channels).toEqual([ibcTest.identifiedChannel]); + expect(response.pagination).toBeDefined(); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("allChannels", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.allChannels(); + expect(response.channels).toEqual([ibcTest.identifiedChannel]); + + tmClient.disconnect(); + }); + }); + + describe("connectionChannels", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.connectionChannels(ibcTest.connectionId); + expect(response.channels).toEqual([ibcTest.identifiedChannel]); + expect(response.pagination).toBeDefined(); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("allConnectionChannels", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.allConnectionChannels(ibcTest.connectionId); + expect(response.channels).toEqual([ibcTest.identifiedChannel]); + + tmClient.disconnect(); + }); + }); + + describe("clientState", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.clientState(ibcTest.portId, ibcTest.channelId); + expect(response.identifiedClientState).toEqual({ + clientId: ibcTest.clientId, + clientState: { + typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", + value: jasmine.any(Uint8Array), + }, + }); + + tmClient.disconnect(); + }); + }); + + describe("consensusState", () => { + xit("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.consensusState( + ibcTest.portId, + ibcTest.channelId, + // TODO: Find valid values + 0, + 0, + ); + expect(response.consensusState).toEqual({ + typeUrl: "/haha", + value: jasmine.any(Uint8Array), + }); + expect(response.clientId).toEqual(ibcTest.clientId); + + tmClient.disconnect(); + }); + }); + + describe("packetCommitment", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.packetCommitment( + ibcTest.portId, + ibcTest.channelId, + Long.fromInt(ibcTest.commitment.sequence, true), + ); + expect(response.commitment).toEqual(ibcTest.commitment.data); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); + + tmClient.disconnect(); + }); + }); + + describe("packetCommitments", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.packetCommitments( + ibcTest.portId, + ibcTest.channelId, + ); + expect(response.commitments).toEqual([ibcTest.packetState]); + expect(response.pagination).toBeDefined(); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("allPacketCommitments", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.allPacketCommitments( + ibcTest.portId, + ibcTest.channelId, + ); + expect(response.commitments).toEqual([ibcTest.packetState]); + + tmClient.disconnect(); + }); + }); + + describe("packetReceipt", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.packetReceipt( + ibcTest.portId, + ibcTest.channelId, + 1, + ); + expect(response.received).toEqual(false); + + tmClient.disconnect(); + }); + }); + + describe("packetAcknowledgement", () => { + it("works", async () => { + pending("We don't have an acknowledgement for testing at the moment"); + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.packetAcknowledgement( + ibcTest.portId, + ibcTest.channelId, + ibcTest.commitment.sequence, + ); + expect(response.acknowledgement).toEqual(ibcTest.packetAcknowledgements[0].data); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); + + tmClient.disconnect(); + }); + }); + + describe("packetAcknowledgements", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.packetAcknowledgements( + ibcTest.portId, + ibcTest.channelId, + ); + expect(response.acknowledgements).toEqual(ibcTest.packetAcknowledgements); + expect(response.pagination).toBeDefined(); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("allPacketAcknowledgements", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.allPacketAcknowledgements( + ibcTest.portId, + ibcTest.channelId, + ); + expect(response.acknowledgements).toEqual(ibcTest.packetAcknowledgements); + + tmClient.disconnect(); + }); + }); + + describe("unreceivedPackets", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.unreceivedPackets( + ibcTest.portId, + ibcTest.channelId, + [1, 2, 3], + ); + expect(response.sequences).toEqual([1, 2, 3].map((n) => Long.fromInt(n, true))); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("unreceivedAcks", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.unreceivedAcks( + ibcTest.portId, + ibcTest.channelId, + [1, 2, 3, 4, 5, 6, 7], + ); + expect(response.sequences).toEqual([Long.fromInt(ibcTest.commitment.sequence, true)]); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("nextSequenceReceive", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.channel.nextSequenceReceive( + ibcTest.portId, + ibcTest.channelId, + ); + expect(response.nextSequenceReceive).toEqual(Long.fromInt(1, true)); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); + + tmClient.disconnect(); + }); }); }); - describe("channels", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + describe("client", () => { + describe("state", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - const response = await client.ibc.unverified.channels(); - expect(response.channels).toEqual([ibcTest.identifiedChannel]); - expect(response.pagination).toBeDefined(); - expect(response.pagination).not.toBeNull(); - expect(response.height).toBeDefined(); - expect(response.height).not.toBeNull(); + const response = await client.ibc.unverified.client.state(ibcTest.clientId); + expect(response.clientState).toEqual({ + typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", + value: jasmine.any(Uint8Array), + }); - tmClient.disconnect(); + tmClient.disconnect(); + }); + }); + + describe("states", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.client.states(); + expect(response.clientStates).toEqual([ + { + clientId: ibcTest.clientId, + clientState: { + typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", + value: jasmine.any(Uint8Array), + }, + }, + ]); + expect(response.pagination).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("allStates", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.client.allStates(); + expect(response.clientStates).toEqual([ + { + clientId: ibcTest.clientId, + clientState: { + typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", + value: jasmine.any(Uint8Array), + }, + }, + ]); + + tmClient.disconnect(); + }); + }); + + describe("consensusState", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.client.consensusState(ibcTest.clientId); + expect(response.consensusState).toEqual({ + typeUrl: "/ibc.lightclients.tendermint.v1.ConsensusState", + value: jasmine.any(Uint8Array), + }); + + tmClient.disconnect(); + }); + }); + + describe("consensusStates", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.client.consensusStates(ibcTest.clientId); + expect(response.consensusStates).toEqual( + jasmine.arrayContaining([ + { + height: jasmine.anything(), + consensusState: { + typeUrl: "/ibc.lightclients.tendermint.v1.ConsensusState", + value: jasmine.any(Uint8Array), + }, + }, + ]), + ); + + tmClient.disconnect(); + }); + }); + + describe("allConsensusStates", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.client.allConsensusStates(ibcTest.clientId); + expect(response.consensusStates).toEqual( + jasmine.arrayContaining([ + { + height: jasmine.anything(), + consensusState: { + typeUrl: "/ibc.lightclients.tendermint.v1.ConsensusState", + value: jasmine.any(Uint8Array), + }, + }, + ]), + ); + + tmClient.disconnect(); + }); + }); + + describe("params", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.client.params(); + expect(response.params).toEqual({ + allowedClients: ["06-solomachine", "07-tendermint"], + }); + + tmClient.disconnect(); + }); + }); + + describe("stateTm", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.client.stateTm(ibcTest.clientId); + expect(response.chainId).toEqual("ibc-1"); + // TODO: Fill these expectations out + + tmClient.disconnect(); + }); + }); + + describe("statesTm", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.client.statesTm(); + expect(response).toEqual( + jasmine.arrayContaining([ + jasmine.objectContaining({ + chainId: "ibc-1", + }), + ]), + ); + + tmClient.disconnect(); + }); + }); + + describe("allStatesTm", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.client.allStatesTm(); + expect(response).toEqual( + jasmine.arrayContaining([ + jasmine.objectContaining({ + chainId: "ibc-1", + }), + ]), + ); + + tmClient.disconnect(); + }); + }); + + describe("consensusStateTm", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.client.consensusStateTm(ibcTest.clientId); + expect(response.nextValidatorsHash).toEqual(jasmine.any(Uint8Array)); + // TODO: Fill out these expectations + + tmClient.disconnect(); + }); }); }); - describe("connectionChannels", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.connectionChannels(ibcTest.connectionId); - expect(response.channels).toEqual([ibcTest.identifiedChannel]); - expect(response.pagination).toBeDefined(); - expect(response.pagination).not.toBeNull(); - expect(response.height).toBeDefined(); - expect(response.height).not.toBeNull(); - - tmClient.disconnect(); - }); - }); - - describe("packetCommitment", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.packetCommitment( - ibcTest.portId, - ibcTest.channelId, - ibcTest.commitment.sequence, - ); - expect(response.commitment).toEqual(ibcTest.commitment.data); - expect(response.proofHeight).toBeDefined(); - expect(response.proofHeight).not.toBeNull(); - - tmClient.disconnect(); - }); - }); - - describe("packetCommitments", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.packetCommitments(ibcTest.portId, ibcTest.channelId); - expect(response.commitments).toEqual([ibcTest.packetState]); - expect(response.pagination).toBeDefined(); - expect(response.pagination).not.toBeNull(); - expect(response.height).toBeDefined(); - expect(response.height).not.toBeNull(); - - tmClient.disconnect(); - }); - }); - - describe("packetAcknowledgement", () => { - it("works", async () => { - pending("We don't have an acknowledgement for testing at the moment"); - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.packetAcknowledgement( - ibcTest.portId, - ibcTest.channelId, - ibcTest.commitment.sequence, - ); - expect(response.acknowledgement).toEqual(ibcTest.packetAcknowledgements[0].data); - expect(response.proofHeight).toBeDefined(); - expect(response.proofHeight).not.toBeNull(); - - tmClient.disconnect(); - }); - }); - - describe("packetAcknowledgements", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.packetAcknowledgements( - ibcTest.portId, - ibcTest.channelId, - ); - expect(response.acknowledgements).toEqual(ibcTest.packetAcknowledgements); - expect(response.pagination).toBeDefined(); - expect(response.pagination).not.toBeNull(); - expect(response.height).toBeDefined(); - expect(response.height).not.toBeNull(); - - tmClient.disconnect(); - }); - }); - - describe("unreceivedPackets", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.unreceivedPackets(ibcTest.portId, ibcTest.channelId, [ - 1, - 2, - 3, - ]); - expect(response.sequences).toEqual([1, 2, 3].map((n) => Long.fromInt(n, true))); - expect(response.height).toBeDefined(); - expect(response.height).not.toBeNull(); - - tmClient.disconnect(); - }); - }); - - describe("unreceivedAcks", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.unreceivedAcks(ibcTest.portId, ibcTest.channelId, [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - ]); - expect(response.sequences).toEqual([Long.fromInt(ibcTest.commitment.sequence, true)]); - expect(response.height).toBeDefined(); - expect(response.height).not.toBeNull(); - - tmClient.disconnect(); - }); - }); - - describe("nextSequenceReceive", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.nextSequenceReceive(ibcTest.portId, ibcTest.channelId); - expect(response.nextSequenceReceive).toEqual(Long.fromInt(1, true)); - expect(response.proofHeight).toBeDefined(); - expect(response.proofHeight).not.toBeNull(); - - tmClient.disconnect(); - }); - }); - - // Queries for ibc.connection - describe("connection", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + describe("connection", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - const response = await client.ibc.unverified.connection(ibcTest.connectionId); - expect(response.connection).toEqual(ibcTest.connection); - expect(response.proofHeight).toBeDefined(); - expect(response.proofHeight).not.toBeNull(); + const response = await client.ibc.unverified.connection.connection(ibcTest.connectionId); + expect(response.connection).toEqual(ibcTest.connection); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); - tmClient.disconnect(); + tmClient.disconnect(); + }); }); - }); - describe("connections", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + describe("connections", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - const response = await client.ibc.unverified.connections(); - expect(response.connections).toEqual([ibcTest.identifiedConnection]); - expect(response.pagination).toBeDefined(); - expect(response.pagination).not.toBeNull(); - expect(response.height).toBeDefined(); - expect(response.height).not.toBeNull(); + const response = await client.ibc.unverified.connection.connections(); + expect(response.connections).toEqual([ibcTest.identifiedConnection]); + expect(response.pagination).toBeDefined(); + expect(response.height).toBeDefined(); - tmClient.disconnect(); + tmClient.disconnect(); + }); }); - }); - describe("clientConnections", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + describe("allConnections", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - const response = await client.ibc.unverified.clientConnections(ibcTest.clientId); - expect(response.connectionPaths).toEqual([ibcTest.connectionId]); - expect(response.proofHeight).toBeDefined(); - expect(response.proofHeight).not.toBeNull(); + const response = await client.ibc.unverified.connection.allConnections(); + expect(response.connections).toEqual([ibcTest.identifiedConnection]); - tmClient.disconnect(); + tmClient.disconnect(); + }); + }); + + describe("clientConnections", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.connection.clientConnections(ibcTest.clientId); + expect(response.connectionPaths).toEqual([ibcTest.connectionId]); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); + + tmClient.disconnect(); + }); + }); + + describe("clientState", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.connection.clientState(ibcTest.connectionId); + expect(response.identifiedClientState).toEqual({ + clientId: ibcTest.clientId, + clientState: { + typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", + value: jasmine.any(Uint8Array), + }, + }); + + tmClient.disconnect(); + }); + }); + + describe("consensusState", () => { + xit("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + // TODO: Find valid values + const response = await client.ibc.unverified.connection.consensusState(ibcTest.connectionId, 1, 1); + expect(response.clientId).toEqual(ibcTest.clientId); + expect(response.consensusState).toEqual({ + typeUrl: "/ibc.lightclients.tendermint.v1.ConsensusState", + value: jasmine.any(Uint8Array), + }); + + tmClient.disconnect(); + }); }); }); }); diff --git a/packages/stargate/src/queries/ibc.ts b/packages/stargate/src/queries/ibc.ts index c3a84de1..9ae7cb8f 100644 --- a/packages/stargate/src/queries/ibc.ts +++ b/packages/stargate/src/queries/ibc.ts @@ -3,8 +3,11 @@ import { toAscii } from "@cosmjs/encoding"; import { Uint64 } from "@cosmjs/math"; import Long from "long"; +import { Any } from "../codec/google/protobuf/any"; import { Channel } from "../codec/ibc/core/channel/v1/channel"; import { + QueryChannelClientStateResponse, + QueryChannelConsensusStateResponse, QueryChannelResponse, QueryChannelsResponse, QueryClientImpl as ChannelQuery, @@ -14,76 +17,155 @@ import { QueryPacketAcknowledgementsResponse, QueryPacketCommitmentResponse, QueryPacketCommitmentsResponse, + QueryPacketReceiptResponse, QueryUnreceivedAcksResponse, QueryUnreceivedPacketsResponse, } from "../codec/ibc/core/channel/v1/query"; +import { Height } from "../codec/ibc/core/client/v1/client"; +import { + QueryClientImpl as ClientQuery, + QueryClientParamsResponse, + QueryClientStateResponse, + QueryClientStatesResponse, + QueryConsensusStateRequest, + QueryConsensusStateResponse, + QueryConsensusStatesResponse, +} from "../codec/ibc/core/client/v1/query"; import { QueryClientConnectionsResponse, QueryClientImpl as ConnectionQuery, + QueryConnectionClientStateResponse, + QueryConnectionConsensusStateRequest, + QueryConnectionConsensusStateResponse, QueryConnectionResponse, QueryConnectionsResponse, } from "../codec/ibc/core/connection/v1/query"; +import { + ClientState as TendermintClientState, + ConsensusState as TendermintConsensusState, +} from "../codec/ibc/lightclients/tendermint/v1/tendermint"; import { QueryClient } from "./queryclient"; import { createPagination, createProtobufRpcClient } from "./utils"; +function decodeTendermintClientStateAny(clientState: Any | undefined): TendermintClientState { + if (clientState?.typeUrl !== "/ibc.lightclients.tendermint.v1.ClientState") { + throw new Error(`Unexpected client state type: ${clientState?.typeUrl}`); + } + return TendermintClientState.decode(clientState.value); +} + +function decodeTendermintConsensusStateAny(clientState: Any | undefined): TendermintConsensusState { + if (clientState?.typeUrl !== "/ibc.lightclients.tendermint.v1.ConsensusState") { + throw new Error(`Unexpected client state type: ${clientState?.typeUrl}`); + } + return TendermintConsensusState.decode(clientState.value); +} + export interface IbcExtension { readonly ibc: { - readonly channel: (portId: string, channelId: string) => Promise; - readonly packetCommitment: (portId: string, channelId: string, sequence: number) => Promise; - readonly packetAcknowledgement: ( - portId: string, - channelId: string, - sequence: number, - ) => Promise; - readonly nextSequenceReceive: (portId: string, channelId: string) => Promise; - readonly unverified: { - // Queries for ibc.core.channel.v1 - readonly channel: (portId: string, channelId: string) => Promise; - readonly channels: (paginationKey?: Uint8Array) => Promise; - readonly connectionChannels: ( - connection: string, - paginationKey?: Uint8Array, - ) => Promise; - readonly packetCommitment: ( - portId: string, - channelId: string, - sequence: number, - ) => Promise; - readonly packetCommitments: ( - portId: string, - channelId: string, - paginationKey?: Uint8Array, - ) => Promise; + readonly channel: { + readonly channel: (portId: string, channelId: string) => Promise; + readonly packetCommitment: (portId: string, channelId: string, sequence: number) => Promise; readonly packetAcknowledgement: ( portId: string, channelId: string, sequence: number, - ) => Promise; - readonly packetAcknowledgements: ( - portId: string, - channelId: string, - paginationKey?: Uint8Array, - ) => Promise; - readonly unreceivedPackets: ( - portId: string, - channelId: string, - packetCommitmentSequences: readonly number[], - ) => Promise; - readonly unreceivedAcks: ( - portId: string, - channelId: string, - packetCommitmentSequences: readonly number[], - ) => Promise; - readonly nextSequenceReceive: ( - portId: string, - channelId: string, - ) => Promise; - - // Queries for ibc.core.connection.v1 - - readonly connection: (connectionId: string) => Promise; - readonly connections: (paginationKey?: Uint8Array) => Promise; - readonly clientConnections: (clientId: string) => Promise; + ) => Promise; + readonly nextSequenceReceive: (portId: string, channelId: string) => Promise; + }; + readonly unverified: { + readonly channel: { + readonly channel: (portId: string, channelId: string) => Promise; + readonly channels: (paginationKey?: Uint8Array) => Promise; + readonly allChannels: () => Promise; + readonly connectionChannels: ( + connection: string, + paginationKey?: Uint8Array, + ) => Promise; + readonly allConnectionChannels: (connection: string) => Promise; + readonly clientState: (portId: string, channelId: string) => Promise; + readonly consensusState: ( + portId: string, + channelId: string, + revisionNumber: number, + revisionHeight: number, + ) => Promise; + readonly packetCommitment: ( + portId: string, + channelId: string, + sequence: Long, + ) => Promise; + readonly packetCommitments: ( + portId: string, + channelId: string, + paginationKey?: Uint8Array, + ) => Promise; + readonly allPacketCommitments: ( + portId: string, + channelId: string, + ) => Promise; + readonly packetReceipt: ( + portId: string, + channelId: string, + sequence: number, + ) => Promise; + readonly packetAcknowledgement: ( + portId: string, + channelId: string, + sequence: number, + ) => Promise; + readonly packetAcknowledgements: ( + portId: string, + channelId: string, + paginationKey?: Uint8Array, + ) => Promise; + readonly allPacketAcknowledgements: ( + portId: string, + channelId: string, + ) => Promise; + readonly unreceivedPackets: ( + portId: string, + channelId: string, + packetCommitmentSequences: readonly number[], + ) => Promise; + readonly unreceivedAcks: ( + portId: string, + channelId: string, + packetAckSequences: readonly number[], + ) => Promise; + readonly nextSequenceReceive: ( + portId: string, + channelId: string, + ) => Promise; + }; + readonly client: { + readonly state: (clientId: string) => Promise; + readonly states: (paginationKey?: Uint8Array) => Promise; + readonly allStates: () => Promise; + readonly consensusState: (clientId: string, height?: number) => Promise; + readonly consensusStates: ( + clientId: string, + paginationKey?: Uint8Array, + ) => Promise; + readonly allConsensusStates: (clientId: string) => Promise; + readonly params: () => Promise; + readonly stateTm: (clientId: string) => Promise; + readonly statesTm: (paginationKey?: Uint8Array) => Promise; + readonly allStatesTm: () => Promise; + readonly consensusStateTm: (clientId: string, height?: Height) => Promise; + }; + readonly connection: { + readonly connection: (connectionId: string) => Promise; + readonly connections: (paginationKey?: Uint8Array) => Promise; + readonly allConnections: () => Promise; + readonly clientConnections: (clientId: string) => Promise; + readonly clientState: (connectionId: string) => Promise; + readonly consensusState: ( + connectionId: string, + revisionNumber: number, + revisionHeight: number, + ) => Promise; + }; }; }; } @@ -93,139 +175,324 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { // Use these services to get easy typed access to query methods // These cannot be used for proof verification const channelQueryService = new ChannelQuery(rpc); + const clientQueryService = new ClientQuery(rpc); const connectionQueryService = new ConnectionQuery(rpc); return { ibc: { - channel: async (portId: string, channelId: string) => { - // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L55-L65 - // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L117-L120 - const key = toAscii(`channelEnds/ports/${portId}/channels/${channelId}`); - const responseData = await base.queryVerified("ibc", key); - return responseData.length ? Channel.decode(responseData) : null; - }, - packetCommitment: async (portId: string, channelId: string, sequence: number) => { - // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L128-L133 - // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L183-L185 - const key = toAscii(`commitments/ports/${portId}/channels/${channelId}/packets/${sequence}`); - const responseData = await base.queryVerified("ibc", key); - // keeper code doesn't parse, but returns raw - return responseData; - }, - packetAcknowledgement: async (portId: string, channelId: string, sequence: number) => { - // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L159-L166 - // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L153-L156 - const key = toAscii(`acks/ports/${portId}/channels/${channelId}/acknowledgements/${sequence}`); - const responseData = await base.queryVerified("ibc", key); - // keeper code doesn't parse, but returns raw - return responseData; - }, - nextSequenceReceive: async (portId: string, channelId: string) => { - // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L92-L101 - // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L133-L136 - const key = toAscii(`seqAcks/ports/${portId}/channels/${channelId}/nextSequenceAck`); - const responseData = await base.queryVerified("ibc", key); - return responseData.length ? Uint64.fromBytes(responseData).toNumber() : null; - }, - - unverified: { - // Queries for ibc.core.channel.v1 + channel: { channel: async (portId: string, channelId: string) => { - const response = await channelQueryService.Channel({ portId: portId, channelId: channelId }); - return response; - }, - channels: async (paginationKey?: Uint8Array) => { - const request = { - pagination: createPagination(paginationKey), - }; - const response = await channelQueryService.Channels(request); - return response; - }, - connectionChannels: async (connection: string, paginationKey?: Uint8Array) => { - const request = { - connection: connection, - pagination: createPagination(paginationKey), - }; - const response = await channelQueryService.ConnectionChannels(request); - return response; + // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L55-L65 + // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L117-L120 + const key = toAscii(`channelEnds/ports/${portId}/channels/${channelId}`); + const responseData = await base.queryVerified("ibc", key); + return responseData.length ? Channel.decode(responseData) : null; }, packetCommitment: async (portId: string, channelId: string, sequence: number) => { - const response = await channelQueryService.PacketCommitment({ - portId: portId, - channelId: channelId, - sequence: Long.fromNumber(sequence, true), - }); - return response; - }, - packetCommitments: async (portId: string, channelId: string, paginationKey?: Uint8Array) => { - const request = { - channelId: channelId, - portId: portId, - pagination: createPagination(paginationKey), - }; - const response = await channelQueryService.PacketCommitments(request); - return response; + // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L128-L133 + // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L183-L185 + const key = toAscii(`commitments/ports/${portId}/channels/${channelId}/packets/${sequence}`); + const responseData = await base.queryVerified("ibc", key); + // keeper code doesn't parse, but returns raw + return responseData; }, packetAcknowledgement: async (portId: string, channelId: string, sequence: number) => { - const response = await channelQueryService.PacketAcknowledgement({ - portId: portId, - channelId: channelId, - sequence: Long.fromNumber(sequence, true), - }); - return response; - }, - packetAcknowledgements: async (portId: string, channelId: string, paginationKey?: Uint8Array) => { - const response = await channelQueryService.PacketAcknowledgements({ - portId: portId, - channelId: channelId, - pagination: createPagination(paginationKey), - }); - return response; - }, - unreceivedPackets: async ( - portId: string, - channelId: string, - packetCommitmentSequences: readonly number[], - ) => { - const response = await channelQueryService.UnreceivedPackets({ - portId: portId, - channelId: channelId, - packetCommitmentSequences: packetCommitmentSequences.map((s) => Long.fromNumber(s, true)), - }); - return response; - }, - unreceivedAcks: async (portId: string, channelId: string, packetAckSequences: readonly number[]) => { - const response = await channelQueryService.UnreceivedAcks({ - portId: portId, - channelId: channelId, - packetAckSequences: packetAckSequences.map((s) => Long.fromNumber(s, true)), - }); - return response; + // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L159-L166 + // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L153-L156 + const key = toAscii(`acks/ports/${portId}/channels/${channelId}/acknowledgements/${sequence}`); + const responseData = await base.queryVerified("ibc", key); + // keeper code doesn't parse, but returns raw + return responseData; }, nextSequenceReceive: async (portId: string, channelId: string) => { - const response = await channelQueryService.NextSequenceReceive({ - portId: portId, - channelId: channelId, - }); - return response; + // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L92-L101 + // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L133-L136 + const key = toAscii(`seqAcks/ports/${portId}/channels/${channelId}/nextSequenceAck`); + const responseData = await base.queryVerified("ibc", key); + return responseData.length ? Uint64.fromBytes(responseData).toNumber() : null; }, - - // Queries for ibc.core.connection.v1 - - connection: async (connectionId: string) => { - const response = await connectionQueryService.Connection({ connectionId: connectionId }); - return response; + }, + unverified: { + channel: { + channel: async (portId: string, channelId: string) => + channelQueryService.Channel({ + portId: portId, + channelId: channelId, + }), + channels: async (paginationKey?: Uint8Array) => + channelQueryService.Channels({ + pagination: createPagination(paginationKey), + }), + allChannels: async () => { + const channels = []; + let response: QueryChannelsResponse; + let key: Uint8Array | undefined; + do { + response = await channelQueryService.Channels({ + pagination: createPagination(key), + }); + channels.push(...response.channels); + key = response.pagination?.nextKey; + } while (key); + return { + channels: channels, + height: response.height, + }; + }, + connectionChannels: async (connection: string, paginationKey?: Uint8Array) => + channelQueryService.ConnectionChannels({ + connection: connection, + pagination: createPagination(paginationKey), + }), + allConnectionChannels: async (connection: string) => { + const channels = []; + let response: QueryConnectionChannelsResponse; + let key: Uint8Array | undefined; + do { + response = await channelQueryService.ConnectionChannels({ + connection: connection, + pagination: createPagination(key), + }); + channels.push(...response.channels); + key = response.pagination?.nextKey; + } while (key); + return { + channels: channels, + height: response.height, + }; + }, + clientState: async (portId: string, channelId: string) => + channelQueryService.ChannelClientState({ + portId: portId, + channelId: channelId, + }), + consensusState: async ( + portId: string, + channelId: string, + revisionNumber: number, + revisionHeight: number, + ) => + channelQueryService.ChannelConsensusState({ + portId: portId, + channelId: channelId, + revisionNumber: Long.fromNumber(revisionNumber, true), + revisionHeight: Long.fromNumber(revisionHeight, true), + }), + packetCommitment: async (portId: string, channelId: string, sequence: Long) => + channelQueryService.PacketCommitment({ + portId: portId, + channelId: channelId, + sequence: sequence, + }), + packetCommitments: async (portId: string, channelId: string, paginationKey?: Uint8Array) => + channelQueryService.PacketCommitments({ + channelId: channelId, + portId: portId, + pagination: createPagination(paginationKey), + }), + allPacketCommitments: async (portId: string, channelId: string) => { + const commitments = []; + let response: QueryPacketCommitmentsResponse; + let key: Uint8Array | undefined; + do { + response = await channelQueryService.PacketCommitments({ + channelId: channelId, + portId: portId, + pagination: createPagination(key), + }); + commitments.push(...response.commitments); + key = response.pagination?.nextKey; + } while (key); + return { + commitments: commitments, + height: response.height, + }; + }, + packetReceipt: async (portId: string, channelId: string, sequence: number) => + channelQueryService.PacketReceipt({ + portId: portId, + channelId: channelId, + sequence: Long.fromNumber(sequence, true), + }), + packetAcknowledgement: async (portId: string, channelId: string, sequence: number) => + channelQueryService.PacketAcknowledgement({ + portId: portId, + channelId: channelId, + sequence: Long.fromNumber(sequence, true), + }), + packetAcknowledgements: async (portId: string, channelId: string, paginationKey?: Uint8Array) => + channelQueryService.PacketAcknowledgements({ + portId: portId, + channelId: channelId, + pagination: createPagination(paginationKey), + }), + allPacketAcknowledgements: async (portId: string, channelId: string) => { + const acknowledgements = []; + let response: QueryPacketAcknowledgementsResponse; + let key: Uint8Array | undefined; + do { + response = await channelQueryService.PacketAcknowledgements({ + channelId: channelId, + portId: portId, + pagination: createPagination(key), + }); + acknowledgements.push(...response.acknowledgements); + key = response.pagination?.nextKey; + } while (key); + return { + acknowledgements: acknowledgements, + height: response.height, + }; + }, + unreceivedPackets: async ( + portId: string, + channelId: string, + packetCommitmentSequences: readonly number[], + ) => + channelQueryService.UnreceivedPackets({ + portId: portId, + channelId: channelId, + packetCommitmentSequences: packetCommitmentSequences.map((s) => Long.fromNumber(s, true)), + }), + unreceivedAcks: async (portId: string, channelId: string, packetAckSequences: readonly number[]) => + channelQueryService.UnreceivedAcks({ + portId: portId, + channelId: channelId, + packetAckSequences: packetAckSequences.map((s) => Long.fromNumber(s, true)), + }), + nextSequenceReceive: async (portId: string, channelId: string) => + channelQueryService.NextSequenceReceive({ + portId: portId, + channelId: channelId, + }), }, - connections: async (paginationKey?: Uint8Array) => { - const request = { - pagination: createPagination(paginationKey), - }; - const response = await connectionQueryService.Connections(request); - return response; + client: { + state: (clientId: string) => clientQueryService.ClientState({ clientId }), + states: (paginationKey?: Uint8Array) => + clientQueryService.ClientStates({ + pagination: createPagination(paginationKey), + }), + allStates: async () => { + const clientStates = []; + let response: QueryClientStatesResponse; + let key: Uint8Array | undefined; + do { + response = await clientQueryService.ClientStates({ + pagination: createPagination(key), + }); + clientStates.push(...response.clientStates); + key = response.pagination?.nextKey; + } while (key); + return { + clientStates: clientStates, + }; + }, + consensusState: (clientId: string, consensusHeight?: number) => + clientQueryService.ConsensusState( + QueryConsensusStateRequest.fromPartial({ + clientId: clientId, + revisionHeight: + consensusHeight !== undefined ? Long.fromNumber(consensusHeight, true) : undefined, + latestHeight: consensusHeight === undefined, + }), + ), + consensusStates: (clientId: string, paginationKey?: Uint8Array) => + clientQueryService.ConsensusStates({ + clientId: clientId, + pagination: createPagination(paginationKey), + }), + allConsensusStates: async (clientId: string) => { + const consensusStates = []; + let response: QueryConsensusStatesResponse; + let key: Uint8Array | undefined; + do { + response = await clientQueryService.ConsensusStates({ + clientId: clientId, + pagination: createPagination(key), + }); + consensusStates.push(...response.consensusStates); + key = response.pagination?.nextKey; + } while (key); + return { + consensusStates: consensusStates, + }; + }, + params: () => clientQueryService.ClientParams({}), + stateTm: async (clientId: string) => { + const response = await clientQueryService.ClientState({ clientId }); + return decodeTendermintClientStateAny(response.clientState); + }, + statesTm: async (paginationKey?: Uint8Array) => { + const { clientStates } = await clientQueryService.ClientStates({ + pagination: createPagination(paginationKey), + }); + return clientStates.map(({ clientState }) => decodeTendermintClientStateAny(clientState)); + }, + allStatesTm: async () => { + const clientStates = []; + let response: QueryClientStatesResponse; + let key: Uint8Array | undefined; + do { + response = await clientQueryService.ClientStates({ + pagination: createPagination(key), + }); + clientStates.push(...response.clientStates); + key = response.pagination?.nextKey; + } while (key); + return clientStates.map(({ clientState }) => decodeTendermintClientStateAny(clientState)); + }, + consensusStateTm: async (clientId: string, consensusHeight?: Height) => { + const response = await clientQueryService.ConsensusState( + QueryConsensusStateRequest.fromPartial({ + clientId: clientId, + revisionHeight: consensusHeight?.revisionHeight, + revisionNumber: consensusHeight?.revisionNumber, + latestHeight: consensusHeight === undefined, + }), + ); + return decodeTendermintConsensusStateAny(response.consensusState); + }, }, - clientConnections: async (clientId: string) => { - const response = await connectionQueryService.ClientConnections({ clientId: clientId }); - return response; + connection: { + connection: async (connectionId: string) => + connectionQueryService.Connection({ + connectionId: connectionId, + }), + connections: async (paginationKey?: Uint8Array) => + connectionQueryService.Connections({ + pagination: createPagination(paginationKey), + }), + allConnections: async () => { + const connections = []; + let response: QueryConnectionsResponse; + let key: Uint8Array | undefined; + do { + response = await connectionQueryService.Connections({ + pagination: createPagination(key), + }); + connections.push(...response.connections); + key = response.pagination?.nextKey; + } while (key); + return { + connections: connections, + height: response.height, + }; + }, + clientConnections: async (clientId: string) => + connectionQueryService.ClientConnections({ + clientId: clientId, + }), + clientState: async (connectionId: string) => + connectionQueryService.ConnectionClientState({ + connectionId: connectionId, + }), + consensusState: async (connectionId: string, revisionHeight: number) => + connectionQueryService.ConnectionConsensusState( + QueryConnectionConsensusStateRequest.fromPartial({ + connectionId: connectionId, + revisionHeight: Long.fromNumber(revisionHeight, true), + }), + ), }, }, }, diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index 3b08d9f1..b7d5bc75 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -39,6 +39,30 @@ import { } from "./codec/cosmos/staking/v1beta1/tx"; import { SignMode } from "./codec/cosmos/tx/signing/v1beta1/signing"; import { TxRaw } from "./codec/cosmos/tx/v1beta1/tx"; +import { + MsgAcknowledgement, + MsgChannelCloseConfirm, + MsgChannelCloseInit, + MsgChannelOpenAck, + MsgChannelOpenConfirm, + MsgChannelOpenInit, + MsgChannelOpenTry, + MsgRecvPacket, + MsgTimeout, + MsgTimeoutOnClose, +} from "./codec/ibc/core/channel/v1/tx"; +import { + MsgCreateClient, + MsgSubmitMisbehaviour, + MsgUpdateClient, + MsgUpgradeClient, +} from "./codec/ibc/core/client/v1/tx"; +import { + MsgConnectionOpenAck, + MsgConnectionOpenConfirm, + MsgConnectionOpenInit, + MsgConnectionOpenTry, +} from "./codec/ibc/core/connection/v1/tx"; import { BroadcastTxResponse, StargateClient } from "./stargateclient"; const defaultGasPrice = GasPrice.fromString("0.025ucosm"); @@ -55,6 +79,24 @@ export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [ ["/cosmos.staking.v1beta1.MsgDelegate", MsgDelegate], ["/cosmos.staking.v1beta1.MsgEditValidator", MsgEditValidator], ["/cosmos.staking.v1beta1.MsgUndelegate", MsgUndelegate], + ["/ibc.core.channel.v1.MsgChannelOpenInit", MsgChannelOpenInit], + ["/ibc.core.channel.v1.MsgChannelOpenTry", MsgChannelOpenTry], + ["/ibc.core.channel.v1.MsgChannelOpenAck", MsgChannelOpenAck], + ["/ibc.core.channel.v1.MsgChannelOpenConfirm", MsgChannelOpenConfirm], + ["/ibc.core.channel.v1.MsgChannelCloseInit", MsgChannelCloseInit], + ["/ibc.core.channel.v1.MsgChannelCloseConfirm", MsgChannelCloseConfirm], + ["/ibc.core.channel.v1.MsgRecvPacket", MsgRecvPacket], + ["/ibc.core.channel.v1.MsgTimeout ", MsgTimeout], + ["/ibc.core.channel.v1.MsgTimeoutOnClose", MsgTimeoutOnClose], + ["/ibc.core.channel.v1.MsgAcknowledgement", MsgAcknowledgement], + ["/ibc.core.client.v1.MsgCreateClient", MsgCreateClient], + ["/ibc.core.client.v1.MsgUpdateClient", MsgUpdateClient], + ["/ibc.core.client.v1.MsgUpgradeClient", MsgUpgradeClient], + ["/ibc.core.client.v1.MsgSubmitMisbehaviour", MsgSubmitMisbehaviour], + ["/ibc.core.connection.v1.MsgConnectionOpenInit", MsgConnectionOpenInit], + ["/ibc.core.connection.v1.MsgConnectionOpenTry", MsgConnectionOpenTry], + ["/ibc.core.connection.v1.MsgConnectionOpenAck", MsgConnectionOpenAck], + ["/ibc.core.connection.v1.MsgConnectionOpenConfirm", MsgConnectionOpenConfirm], ]; function createDefaultRegistry(): Registry {