Skip to content

Commit

Permalink
feat: ICA packet data
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Oct 25, 2023
1 parent 30098f1 commit 3be667c
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
5 changes: 4 additions & 1 deletion src/client/lcd/api/ICAv1API.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -53,7 +54,9 @@ export class ICAv1API extends BaseAPI {
connectionId: string,
params: Partial<APIParams> = {}
) {
return this.getReqFromAddress(ownerAddr).get<{ params: ControllerParams }>(
return this.getReqFromAddress(
ownerAddr
).get<QueryInterchainAccountResponse>(
`/ibc/apps/interchain_accounts/controller/v1/owners/${ownerAddr}/connections/${connectionId}`,
params
);
Expand Down
116 changes: 116 additions & 0 deletions src/core/ica/controller/v1/InterchainAccountPacketData.ts
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 5 additions & 3 deletions src/core/ica/controller/v1/msgs/MsgSendTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
{},
Expand Down Expand Up @@ -69,6 +69,8 @@ export class MsgSendTx extends JSONSerializable<
proto.connectionId,
proto.relativeTimeout,
proto.packetData
? InterchainAccountPacketData.fromProto(proto.packetData)
: undefined
);
}

Expand All @@ -79,7 +81,7 @@ export class MsgSendTx extends JSONSerializable<
owner,
connectionId,
relativeTimeout,
packetData,
packetData: packetData as any,
});
}

Expand Down

0 comments on commit 3be667c

Please sign in to comment.