Skip to content

Commit 401c169

Browse files
Gefei HouGefei Hou
authored andcommitted
Interchainjs migration
1 parent bbc6af3 commit 401c169

File tree

122 files changed

+2617
-1881
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+2617
-1881
lines changed

__fixtures__/issues/98/out/98.client.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
55
*/
66

7-
import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
8-
import { StdFee } from "@cosmjs/amino";
7+
import { ICosmWasmClient, ISigningCosmWasmClient } from "./baseClient";
8+
import { DeliverTxResponse, StdFee } from "@interchainjs/types";
99
import { Uint128, InstantiateMsg, Coin, ExecuteMsg, InstallableExecMsg, Binary, ExecMsg, QueryMsg, InstallableQueryMsg, QueryMsg1, ConfigResponse, NullablePlugin, CanonicalAddr, Plugin, PluginsResponse } from "./98.types";
1010
export interface 98ReadOnlyInterface {
1111
contractAddress: string;
@@ -24,9 +24,9 @@ export interface 98ReadOnlyInterface {
2424
}) => Promise<NullablePlugin>;
2525
}
2626
export class 98QueryClient implements 98ReadOnlyInterface {
27-
client: CosmWasmClient;
27+
client: ICosmWasmClient;
2828
contractAddress: string;
29-
constructor(client: CosmWasmClient, contractAddress: string) {
29+
constructor(client: ICosmWasmClient, contractAddress: string) {
3030
this.client = client;
3131
this.contractAddress = contractAddress;
3232
this.getConfig = this.getConfig.bind(this);
@@ -73,7 +73,7 @@ export interface 98Interface extends 98ReadOnlyInterface {
7373
}: {
7474
id: number;
7575
instantiateMsg: Binary;
76-
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
76+
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
7777
registerPlugin: ({
7878
checksum,
7979
codeId,
@@ -88,12 +88,12 @@ export interface 98Interface extends 98ReadOnlyInterface {
8888
ipfsHash: string;
8989
name: string;
9090
version: string;
91-
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
91+
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
9292
unregisterPlugin: ({
9393
id
9494
}: {
9595
id: number;
96-
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
96+
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
9797
updatePlugin: ({
9898
checksum,
9999
codeId,
@@ -110,23 +110,23 @@ export interface 98Interface extends 98ReadOnlyInterface {
110110
ipfsHash?: string;
111111
name?: string;
112112
version?: string;
113-
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
113+
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
114114
updateRegistryFee: ({
115115
newFee
116116
}: {
117117
newFee: Coin;
118-
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
118+
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
119119
updateDaoAddr: ({
120120
newAddr
121121
}: {
122122
newAddr: string;
123-
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
123+
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
124124
}
125125
export class 98Client extends 98QueryClient implements 98Interface {
126-
client: SigningCosmWasmClient;
126+
client: ISigningCosmWasmClient;
127127
sender: string;
128128
contractAddress: string;
129-
constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
129+
constructor(client: ISigningCosmWasmClient, sender: string, contractAddress: string) {
130130
super(client, contractAddress);
131131
this.client = client;
132132
this.sender = sender;
@@ -144,7 +144,7 @@ export class 98Client extends 98QueryClient implements 98Interface {
144144
}: {
145145
id: number;
146146
instantiateMsg: Binary;
147-
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
147+
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
148148
return await this.client.execute(this.sender, this.contractAddress, {
149149
proxy_install_plugin: {
150150
id,
@@ -166,7 +166,7 @@ export class 98Client extends 98QueryClient implements 98Interface {
166166
ipfsHash: string;
167167
name: string;
168168
version: string;
169-
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
169+
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
170170
return await this.client.execute(this.sender, this.contractAddress, {
171171
register_plugin: {
172172
checksum,
@@ -182,7 +182,7 @@ export class 98Client extends 98QueryClient implements 98Interface {
182182
id
183183
}: {
184184
id: number;
185-
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
185+
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
186186
return await this.client.execute(this.sender, this.contractAddress, {
187187
unregister_plugin: {
188188
id
@@ -205,7 +205,7 @@ export class 98Client extends 98QueryClient implements 98Interface {
205205
ipfsHash?: string;
206206
name?: string;
207207
version?: string;
208-
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
208+
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
209209
return await this.client.execute(this.sender, this.contractAddress, {
210210
update_plugin: {
211211
checksum,
@@ -222,7 +222,7 @@ export class 98Client extends 98QueryClient implements 98Interface {
222222
newFee
223223
}: {
224224
newFee: Coin;
225-
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
225+
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
226226
return await this.client.execute(this.sender, this.contractAddress, {
227227
update_registry_fee: {
228228
new_fee: newFee
@@ -233,7 +233,7 @@ export class 98Client extends 98QueryClient implements 98Interface {
233233
newAddr
234234
}: {
235235
newAddr: string;
236-
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
236+
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
237237
return await this.client.execute(this.sender, this.contractAddress, {
238238
update_dao_addr: {
239239
new_addr: newAddr
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* This file was automatically generated by @cosmwasm/ts-codegen@latest.
3+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4+
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
5+
*/
6+
7+
8+
import { StdFee, Coin, DeliverTxResponse } from '@interchainjs/types';
9+
import { SigningClient } from '@interchainjs/cosmos/signing-client';
10+
import { getSmartContractState } from 'interchainjs/cosmwasm/wasm/v1/query.rpc.func';
11+
import { executeContract } from 'interchainjs/cosmwasm/wasm/v1/tx.rpc.func';
12+
import { QuerySmartContractStateRequest, QuerySmartContractStateResponse } from 'interchainjs/cosmwasm/wasm/v1/query';
13+
import { MsgExecuteContract } from 'interchainjs/cosmwasm/wasm/v1/tx';
14+
15+
// Encoding utility functions
16+
const fromUint8Array = <T>(uint8Array: Uint8Array): T => {
17+
const text = new TextDecoder().decode(uint8Array);
18+
return JSON.parse(text);
19+
};
20+
21+
const toUint8Array = (obj: any): Uint8Array => {
22+
const text = JSON.stringify(obj);
23+
return new TextEncoder().encode(text);
24+
};
25+
26+
// InterchainJS interfaces for CosmWasm clients
27+
export interface ICosmWasmClient {
28+
queryContractSmart(contractAddr: string, query: any): Promise<any>;
29+
}
30+
31+
export interface ISigningCosmWasmClient {
32+
execute(sender: string, contractAddress: string, msg: any, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise<DeliverTxResponse>;
33+
}
34+
35+
export interface ISigningClient {
36+
signAndBroadcast(
37+
signerAddress: string,
38+
messages: any[],
39+
fee: number | StdFee | "auto",
40+
memo?: string
41+
): Promise<DeliverTxResponse>;
42+
}
43+
44+
// Helper functions to create InterchainJS clients
45+
export function getCosmWasmClient(rpcEndpoint: string): ICosmWasmClient {
46+
return {
47+
queryContractSmart: async (contractAddr: string, query: any) => {
48+
// Create the request object
49+
const request: QuerySmartContractStateRequest = {
50+
address: contractAddr,
51+
queryData: toUint8Array(query)
52+
};
53+
54+
// Execute the query using InterchainJS
55+
const response: QuerySmartContractStateResponse = await getSmartContractState(rpcEndpoint, request);
56+
57+
// Parse and return the result
58+
return fromUint8Array(response.data);
59+
},
60+
};
61+
}
62+
63+
export function getSigningCosmWasmClient(signingClient: SigningClient): ISigningCosmWasmClient {
64+
return {
65+
execute: async (sender: string, contractAddress: string, msg: any, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => {
66+
// Handle fee conversion
67+
let finalFee: StdFee;
68+
if (typeof fee === 'number') {
69+
finalFee = { amount: [], gas: fee.toString() };
70+
} else if (fee === 'auto') {
71+
finalFee = { amount: [], gas: '200000' }; // default gas for auto
72+
} else if (fee) {
73+
finalFee = fee;
74+
} else {
75+
finalFee = { amount: [], gas: '200000' }; // default fee
76+
}
77+
78+
// Create the message object
79+
const message: MsgExecuteContract = {
80+
sender,
81+
contract: contractAddress,
82+
msg: toUint8Array(msg),
83+
funds: funds || []
84+
};
85+
86+
// Execute the transaction using InterchainJS
87+
const result = await executeContract(
88+
signingClient,
89+
sender,
90+
message,
91+
finalFee,
92+
memo || ''
93+
);
94+
95+
return result;
96+
},
97+
};
98+
}

__fixtures__/issues/98/out/bundle.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
import * as _0 from "./98.types";
88
import * as _1 from "./98.client";
99
import * as _2 from "./98.react-query";
10+
import * as _3 from "./baseClient";
1011
export namespace contracts {
1112
export const 98 = {
1213
..._0,
1314
..._1,
1415
..._2
1516
};
17+
export const baseClient = {
18+
..._3
19+
};
1620
}

__output__/builder/bundler_test/contracts/CwAdminFactory.client.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
55
*/
66

7-
import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
8-
import { Coin, StdFee } from "@cosmjs/amino";
7+
import { ICosmWasmClient, ISigningCosmWasmClient } from "./baseClient";
8+
import { Coin, DeliverTxResponse, StdFee } from "@interchainjs/types";
99
import { ExecuteMsg, Binary, InstantiateMsg, QueryMsg } from "./CwAdminFactory.types";
1010
export interface CwAdminFactoryReadOnlyInterface {
1111
contractAddress: string;
1212
}
1313
export class CwAdminFactoryQueryClient implements CwAdminFactoryReadOnlyInterface {
14-
client: CosmWasmClient;
14+
client: ICosmWasmClient;
1515
contractAddress: string;
16-
constructor(client: CosmWasmClient, contractAddress: string) {
16+
constructor(client: ICosmWasmClient, contractAddress: string) {
1717
this.client = client;
1818
this.contractAddress = contractAddress;
1919
}
@@ -29,13 +29,13 @@ export interface CwAdminFactoryInterface {
2929
codeId: number;
3030
instantiateMsg: Binary;
3131
label: string;
32-
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
32+
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
3333
}
3434
export class CwAdminFactoryClient implements CwAdminFactoryInterface {
35-
client: SigningCosmWasmClient;
35+
client: ISigningCosmWasmClient;
3636
sender: string;
3737
contractAddress: string;
38-
constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
38+
constructor(client: ISigningCosmWasmClient, sender: string, contractAddress: string) {
3939
this.client = client;
4040
this.sender = sender;
4141
this.contractAddress = contractAddress;
@@ -49,7 +49,7 @@ export class CwAdminFactoryClient implements CwAdminFactoryInterface {
4949
codeId: number;
5050
instantiateMsg: Binary;
5151
label: string;
52-
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
52+
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
5353
return await this.client.execute(this.sender, this.contractAddress, {
5454
instantiate_contract_with_self_admin: {
5555
code_id: codeId,

__output__/builder/bundler_test/contracts/CwAdminFactory.message-composer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
55
*/
66

7-
import { Coin } from "@cosmjs/amino";
8-
import { MsgExecuteContractEncodeObject } from "@cosmjs/cosmwasm-stargate";
9-
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
10-
import { toUtf8 } from "@cosmjs/encoding";
7+
import { Coin } from "@interchainjs/types";
8+
import { EncodeObject } from "@interchainjs/cosmos-types";
9+
import { MsgExecuteContract } from "interchainjs/cosmwasm/wasm/v1/tx";
10+
import { toUtf8 } from "@interchainjs/encoding";
1111
import { ExecuteMsg, Binary, InstantiateMsg, QueryMsg } from "./CwAdminFactory.types";
1212
export interface CwAdminFactoryMsg {
1313
contractAddress: string;
@@ -20,7 +20,7 @@ export interface CwAdminFactoryMsg {
2020
codeId: number;
2121
instantiateMsg: Binary;
2222
label: string;
23-
}, funds_?: Coin[]) => MsgExecuteContractEncodeObject;
23+
}, funds_?: Coin[]) => EncodeObject;
2424
}
2525
export class CwAdminFactoryMsgComposer implements CwAdminFactoryMsg {
2626
sender: string;
@@ -38,7 +38,7 @@ export class CwAdminFactoryMsgComposer implements CwAdminFactoryMsg {
3838
codeId: number;
3939
instantiateMsg: Binary;
4040
label: string;
41-
}, funds_?: Coin[]): MsgExecuteContractEncodeObject => {
41+
}, funds_?: Coin[]): EncodeObject => {
4242
return {
4343
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
4444
value: MsgExecuteContract.fromPartial({

0 commit comments

Comments
 (0)