Skip to content

Update/interchainjs migration #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions __fixtures__/issues/98/out/98.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/

import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { StdFee } from "@cosmjs/amino";
import { ICosmWasmClient, ISigningCosmWasmClient } from "./baseClient";
import { DeliverTxResponse, StdFee } from "@interchainjs/types";
import { Uint128, InstantiateMsg, Coin, ExecuteMsg, InstallableExecMsg, Binary, ExecMsg, QueryMsg, InstallableQueryMsg, QueryMsg1, ConfigResponse, NullablePlugin, CanonicalAddr, Plugin, PluginsResponse } from "./98.types";
export interface 98ReadOnlyInterface {
contractAddress: string;
Expand All @@ -24,9 +24,9 @@ export interface 98ReadOnlyInterface {
}) => Promise<NullablePlugin>;
}
export class 98QueryClient implements 98ReadOnlyInterface {
client: CosmWasmClient;
client: ICosmWasmClient;
contractAddress: string;
constructor(client: CosmWasmClient, contractAddress: string) {
constructor(client: ICosmWasmClient, contractAddress: string) {
this.client = client;
this.contractAddress = contractAddress;
this.getConfig = this.getConfig.bind(this);
Expand Down Expand Up @@ -73,7 +73,7 @@ export interface 98Interface extends 98ReadOnlyInterface {
}: {
id: number;
instantiateMsg: Binary;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
registerPlugin: ({
checksum,
codeId,
Expand All @@ -88,12 +88,12 @@ export interface 98Interface extends 98ReadOnlyInterface {
ipfsHash: string;
name: string;
version: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
unregisterPlugin: ({
id
}: {
id: number;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
updatePlugin: ({
checksum,
codeId,
Expand All @@ -110,23 +110,23 @@ export interface 98Interface extends 98ReadOnlyInterface {
ipfsHash?: string;
name?: string;
version?: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
updateRegistryFee: ({
newFee
}: {
newFee: Coin;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
updateDaoAddr: ({
newAddr
}: {
newAddr: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
}
export class 98Client extends 98QueryClient implements 98Interface {
client: SigningCosmWasmClient;
client: ISigningCosmWasmClient;
sender: string;
contractAddress: string;
constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
constructor(client: ISigningCosmWasmClient, sender: string, contractAddress: string) {
super(client, contractAddress);
this.client = client;
this.sender = sender;
Expand All @@ -144,7 +144,7 @@ export class 98Client extends 98QueryClient implements 98Interface {
}: {
id: number;
instantiateMsg: Binary;
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
return await this.client.execute(this.sender, this.contractAddress, {
proxy_install_plugin: {
id,
Expand All @@ -166,7 +166,7 @@ export class 98Client extends 98QueryClient implements 98Interface {
ipfsHash: string;
name: string;
version: string;
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
return await this.client.execute(this.sender, this.contractAddress, {
register_plugin: {
checksum,
Expand All @@ -182,7 +182,7 @@ export class 98Client extends 98QueryClient implements 98Interface {
id
}: {
id: number;
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
return await this.client.execute(this.sender, this.contractAddress, {
unregister_plugin: {
id
Expand All @@ -205,7 +205,7 @@ export class 98Client extends 98QueryClient implements 98Interface {
ipfsHash?: string;
name?: string;
version?: string;
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
return await this.client.execute(this.sender, this.contractAddress, {
update_plugin: {
checksum,
Expand All @@ -222,7 +222,7 @@ export class 98Client extends 98QueryClient implements 98Interface {
newFee
}: {
newFee: Coin;
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
return await this.client.execute(this.sender, this.contractAddress, {
update_registry_fee: {
new_fee: newFee
Expand All @@ -233,7 +233,7 @@ export class 98Client extends 98QueryClient implements 98Interface {
newAddr
}: {
newAddr: string;
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
return await this.client.execute(this.sender, this.contractAddress, {
update_dao_addr: {
new_addr: newAddr
Expand Down
98 changes: 98 additions & 0 deletions __fixtures__/issues/98/out/baseClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* This file was automatically generated by @cosmwasm/ts-codegen@latest.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/


import { StdFee, Coin, DeliverTxResponse } from '@interchainjs/types';
import { SigningClient } from '@interchainjs/cosmos/signing-client';
import { getSmartContractState } from 'interchainjs/cosmwasm/wasm/v1/query.rpc.func';
import { executeContract } from 'interchainjs/cosmwasm/wasm/v1/tx.rpc.func';
import { QuerySmartContractStateRequest, QuerySmartContractStateResponse } from 'interchainjs/cosmwasm/wasm/v1/query';
import { MsgExecuteContract } from 'interchainjs/cosmwasm/wasm/v1/tx';

// Encoding utility functions
const fromUint8Array = <T>(uint8Array: Uint8Array): T => {
const text = new TextDecoder().decode(uint8Array);
return JSON.parse(text);
};

const toUint8Array = (obj: any): Uint8Array => {
const text = JSON.stringify(obj);
return new TextEncoder().encode(text);
};

// InterchainJS interfaces for CosmWasm clients
export interface ICosmWasmClient {
queryContractSmart(contractAddr: string, query: any): Promise<any>;
}

export interface ISigningCosmWasmClient {
execute(sender: string, contractAddress: string, msg: any, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]): Promise<DeliverTxResponse>;
}

export interface ISigningClient {
signAndBroadcast(
signerAddress: string,
messages: any[],
fee: number | StdFee | "auto",
memo?: string
): Promise<DeliverTxResponse>;
}

// Helper functions to create InterchainJS clients
export function getCosmWasmClient(rpcEndpoint: string): ICosmWasmClient {
return {
queryContractSmart: async (contractAddr: string, query: any) => {
// Create the request object
const request: QuerySmartContractStateRequest = {
address: contractAddr,
queryData: toUint8Array(query)
};

// Execute the query using InterchainJS
const response: QuerySmartContractStateResponse = await getSmartContractState(rpcEndpoint, request);

// Parse and return the result
return fromUint8Array(response.data);
},
};
}

export function getSigningCosmWasmClient(signingClient: SigningClient): ISigningCosmWasmClient {
return {
execute: async (sender: string, contractAddress: string, msg: any, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => {
// Handle fee conversion
let finalFee: StdFee;
if (typeof fee === 'number') {
finalFee = { amount: [], gas: fee.toString() };
} else if (fee === 'auto') {
finalFee = { amount: [], gas: '200000' }; // default gas for auto
} else if (fee) {
finalFee = fee;
} else {
finalFee = { amount: [], gas: '200000' }; // default fee
}

// Create the message object
const message: MsgExecuteContract = {
sender,
contract: contractAddress,
msg: toUint8Array(msg),
funds: funds || []
};

// Execute the transaction using InterchainJS
const result = await executeContract(
signingClient,
sender,
message,
finalFee,
memo || ''
);

return result;
},
};
}
4 changes: 4 additions & 0 deletions __fixtures__/issues/98/out/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
import * as _0 from "./98.types";
import * as _1 from "./98.client";
import * as _2 from "./98.react-query";
import * as _3 from "./baseClient";
export namespace contracts {
export const 98 = {
..._0,
..._1,
..._2
};
export const baseClient = {
..._3
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/

import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { Coin, StdFee } from "@cosmjs/amino";
import { ICosmWasmClient, ISigningCosmWasmClient } from "./baseClient";
import { Coin, DeliverTxResponse, StdFee } from "@interchainjs/types";
import { ExecuteMsg, Binary, InstantiateMsg, QueryMsg } from "./CwAdminFactory.types";
export interface CwAdminFactoryReadOnlyInterface {
contractAddress: string;
}
export class CwAdminFactoryQueryClient implements CwAdminFactoryReadOnlyInterface {
client: CosmWasmClient;
client: ICosmWasmClient;
contractAddress: string;
constructor(client: CosmWasmClient, contractAddress: string) {
constructor(client: ICosmWasmClient, contractAddress: string) {
this.client = client;
this.contractAddress = contractAddress;
}
Expand All @@ -29,13 +29,13 @@ export interface CwAdminFactoryInterface {
codeId: number;
instantiateMsg: Binary;
label: string;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<DeliverTxResponse>;
}
export class CwAdminFactoryClient implements CwAdminFactoryInterface {
client: SigningCosmWasmClient;
client: ISigningCosmWasmClient;
sender: string;
contractAddress: string;
constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
constructor(client: ISigningCosmWasmClient, sender: string, contractAddress: string) {
this.client = client;
this.sender = sender;
this.contractAddress = contractAddress;
Expand All @@ -49,7 +49,7 @@ export class CwAdminFactoryClient implements CwAdminFactoryInterface {
codeId: number;
instantiateMsg: Binary;
label: string;
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
}, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<DeliverTxResponse> => {
return await this.client.execute(this.sender, this.contractAddress, {
instantiate_contract_with_self_admin: {
code_id: codeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/

import { Coin } from "@cosmjs/amino";
import { MsgExecuteContractEncodeObject } from "@cosmjs/cosmwasm-stargate";
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { toUtf8 } from "@cosmjs/encoding";
import { Coin } from "@interchainjs/types";
import { EncodeObject } from "@interchainjs/cosmos-types";
import { MsgExecuteContract } from "interchainjs/cosmwasm/wasm/v1/tx";
import { toUtf8 } from "@interchainjs/encoding";
import { ExecuteMsg, Binary, InstantiateMsg, QueryMsg } from "./CwAdminFactory.types";
export interface CwAdminFactoryMsg {
contractAddress: string;
Expand All @@ -20,7 +20,7 @@ export interface CwAdminFactoryMsg {
codeId: number;
instantiateMsg: Binary;
label: string;
}, funds_?: Coin[]) => MsgExecuteContractEncodeObject;
}, funds_?: Coin[]) => EncodeObject;
}
export class CwAdminFactoryMsgComposer implements CwAdminFactoryMsg {
sender: string;
Expand All @@ -38,7 +38,7 @@ export class CwAdminFactoryMsgComposer implements CwAdminFactoryMsg {
codeId: number;
instantiateMsg: Binary;
label: string;
}, funds_?: Coin[]): MsgExecuteContractEncodeObject => {
}, funds_?: Coin[]): EncodeObject => {
return {
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
value: MsgExecuteContract.fromPartial({
Expand Down
Loading