diff --git a/package-lock.json b/package-lock.json index fdd46186..233eaea2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@terra-money/feather.js", - "version": "2.0.0-beta.2", + "version": "2.0.0-beta.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@terra-money/feather.js", - "version": "2.0.0-beta.2", + "version": "2.0.0-beta.4", "license": "MIT", "dependencies": { "@ethersproject/bytes": "^5.7.0", diff --git a/package.json b/package.json index d4971a03..f6087f45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@terra-money/feather.js", - "version": "2.0.0-beta.2", + "version": "2.0.0-beta.4", "description": "The JavaScript SDK for Terra and Feather chains", "license": "MIT", "author": "Terraform Labs, PTE.", diff --git a/src/client/lcd/api/ICAv1API.ts b/src/client/lcd/api/ICAv1API.ts index 4fbbcc89..8c2a4186 100644 --- a/src/client/lcd/api/ICAv1API.ts +++ b/src/client/lcd/api/ICAv1API.ts @@ -1,5 +1,6 @@ import { Params as HostParams } from '@terra-money/terra.proto/ibc/applications/interchain_accounts/host/v1/host'; import { Params as ControllerParams } from '@terra-money/terra.proto/ibc/applications/interchain_accounts/controller/v1/controller'; +import { QueryInterchainAccountResponse } from '@terra-money/terra.proto/ibc/applications/interchain_accounts/controller/v1/query'; import { APIParams } from '../APIRequester'; import { LCDClient } from '../LCDClient'; import { BaseAPI } from './BaseAPI'; @@ -53,7 +54,9 @@ export class ICAv1API extends BaseAPI { connectionId: string, params: Partial = {} ) { - return this.getReqFromAddress(ownerAddr).get<{ params: ControllerParams }>( + return this.getReqFromAddress( + ownerAddr + ).get( `/ibc/apps/interchain_accounts/controller/v1/owners/${ownerAddr}/connections/${connectionId}`, params ); diff --git a/src/core/ica/controller/v1/InterchainAccountPacketData.ts b/src/core/ica/controller/v1/InterchainAccountPacketData.ts new file mode 100644 index 00000000..7e87232f --- /dev/null +++ b/src/core/ica/controller/v1/InterchainAccountPacketData.ts @@ -0,0 +1,116 @@ +import { Any } from '@terra-money/legacy.proto/google/protobuf/any'; +import { JSONSerializable } from '../../../../util/json'; +import { + InterchainAccountPacketData as InterchainAccountPacketData_pb, + Type, +} from '@terra-money/terra.proto/ibc/applications/interchain_accounts/v1/packet'; + +/** + * Message to execute actions on host chain of the interchain account. + */ +export class InterchainAccountPacketData extends JSONSerializable< + {}, + InterchainAccountPacketData.Data, + InterchainAccountPacketData.Proto +> { + /** + * @param data base64 encoded proto message of the data e.g.: MsgSend_pb.encode(msgSend.toProto()).string("base64").finish() + * @param connectionId memo field data that will be passed to the message + * @param version of the message TYPE_UNSPECIFIED, TYPE_EXECUTE_TX or UNRECOGNIZED + */ + constructor( + public data: Uint8Array, + public memo: string = '', + public type: Type = Type.TYPE_EXECUTE_TX + ) { + super(); + } + + public static fromAmino( + data: InterchainAccountPacketData.Amino, + _?: boolean + ): InterchainAccountPacketData { + _; + data; + throw new Error('Amino not supported on InterchainAccountPacketData'); + } + + public toAmino(_?: boolean): InterchainAccountPacketData.Amino { + _; + throw new Error('Amino not supported on InterchainAccountPacketData'); + } + + public static fromData( + inputData: InterchainAccountPacketData.Data, + _?: boolean + ): InterchainAccountPacketData { + _; + const { data, type, memo } = inputData; + + return new InterchainAccountPacketData(data, memo, type); + } + + public toData(_?: boolean): InterchainAccountPacketData.Data { + _; + const { data, type, memo } = this; + return { + data, + type, + memo, + }; + } + + public static fromProto( + proto: InterchainAccountPacketData.Proto, + _?: boolean + ): InterchainAccountPacketData { + _; + return new InterchainAccountPacketData( + proto.data as any, + proto.memo, + proto.type + ); + } + + public toProto(_?: boolean): InterchainAccountPacketData.Proto { + _; + const { data, type, memo } = this; + return InterchainAccountPacketData_pb.fromPartial({ + data: data as any, + type, + memo, + }); + } + + public packAny(isClassic?: boolean): Any { + return Any.fromPartial({ + value: InterchainAccountPacketData_pb.encode( + this.toProto(isClassic) + ).finish(), + }); + } + + public static unpackAny( + msgAny: Any, + isClassic?: boolean + ): InterchainAccountPacketData { + return InterchainAccountPacketData.fromProto( + InterchainAccountPacketData_pb.decode(msgAny.value), + isClassic + ); + } +} + +export namespace InterchainAccountPacketData { + export interface Amino { + value: {}; + } + + export interface Data { + data: Uint8Array; + type: Type; + memo: string; + } + + export type Proto = InterchainAccountPacketData_pb; +} diff --git a/src/core/ica/controller/v1/msgs/MsgSendTx.ts b/src/core/ica/controller/v1/msgs/MsgSendTx.ts index 01da5039..cc846e02 100644 --- a/src/core/ica/controller/v1/msgs/MsgSendTx.ts +++ b/src/core/ica/controller/v1/msgs/MsgSendTx.ts @@ -2,11 +2,11 @@ import { AccAddress } from '../../../../bech32'; import { Any } from '@terra-money/legacy.proto/google/protobuf/any'; import { JSONSerializable } from '../../../../../util/json'; import { MsgSendTx as MsgSendTx_pb } from '@terra-money/terra.proto/ibc/applications/interchain_accounts/controller/v1/tx'; -import { InterchainAccountPacketData } from '@terra-money/terra.proto/ibc/applications/interchain_accounts/v1/packet'; import Long from 'long'; +import { InterchainAccountPacketData } from '../InterchainAccountPacketData'; /** - * A basic message for sending [[Coins]] between Terra accounts. + * Transaction message to wrap the packet data and execute actions on host chain. */ export class MsgSendTx extends JSONSerializable< {}, @@ -69,6 +69,8 @@ export class MsgSendTx extends JSONSerializable< proto.connectionId, proto.relativeTimeout, proto.packetData + ? InterchainAccountPacketData.fromProto(proto.packetData) + : undefined ); } @@ -79,7 +81,7 @@ export class MsgSendTx extends JSONSerializable< owner, connectionId, relativeTimeout, - packetData, + packetData: packetData as any, }); }