mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Merge pull request #1284 from cosmos/fix-cosmwasm-msg-types-simon
Fix the cosmwasm msg types
This commit is contained in:
commit
e4aa7f89eb
11
CHANGELOG.md
11
CHANGELOG.md
@ -11,6 +11,17 @@ and this project adheres to
|
||||
- @cosmjs/utils: Add `isDefined` which checks for `undefined` in a
|
||||
TypeScript-friendly way.
|
||||
|
||||
### Fixed
|
||||
|
||||
- @cosmjs/cosmwasm-stargate: Use type `JsonObject = any` for smart query
|
||||
requests and messages (in `WasmExtension.wasm.queryContractSmart`,
|
||||
`CosmWasmClient.queryContractSmart`, `SigningCosmWasmClient.instantiate`,
|
||||
`SigningCosmWasmClient.migrate`, `SigningCosmWasmClient.execute`). This
|
||||
reverts the type change done in CosmJS 0.23.0. ([#1281], [#1284])
|
||||
|
||||
[#1281]: https://github.com/cosmos/cosmjs/pull/1281
|
||||
[#1284]: https://github.com/cosmos/cosmjs/pull/1284
|
||||
|
||||
## [0.29.1] - 2022-10-09
|
||||
|
||||
### Changed
|
||||
|
@ -418,6 +418,14 @@ describe("CosmWasmClient", () => {
|
||||
const client = await CosmWasmClient.connect(wasmd.endpoint);
|
||||
const result = await client.queryContractSmart(contract.address, { verifier: {} });
|
||||
expect(result).toEqual({ verifier: contract.instantiateMsg.verifier });
|
||||
|
||||
// Typed request (https://github.com/cosmos/cosmjs/pull/1281)
|
||||
interface VerifierQuery {
|
||||
verifier: Record<string, never>;
|
||||
}
|
||||
const request: VerifierQuery = { verifier: {} };
|
||||
const result2 = await client.queryContractSmart(contract.address, request);
|
||||
expect(result2).toEqual({ verifier: contract.instantiateMsg.verifier });
|
||||
});
|
||||
|
||||
it("errors for malformed query message", async () => {
|
||||
|
@ -71,7 +71,7 @@ export interface ContractCodeHistoryEntry {
|
||||
/** The source of this history entry */
|
||||
readonly operation: "Genesis" | "Init" | "Migrate";
|
||||
readonly codeId: number;
|
||||
readonly msg: Record<string, unknown>;
|
||||
readonly msg: JsonObject;
|
||||
}
|
||||
|
||||
/** Use for testing only */
|
||||
@ -439,7 +439,7 @@ export class CosmWasmClient {
|
||||
* Promise is rejected for invalid query format.
|
||||
* Promise is rejected for invalid response format.
|
||||
*/
|
||||
public async queryContractSmart(address: string, queryMsg: Record<string, unknown>): Promise<JsonObject> {
|
||||
public async queryContractSmart(address: string, queryMsg: JsonObject): Promise<JsonObject> {
|
||||
try {
|
||||
return await this.forceGetQueryClient().wasm.queryContractSmart(address, queryMsg);
|
||||
} catch (error) {
|
||||
|
@ -35,6 +35,7 @@ import {
|
||||
MsgStoreCodeEncodeObject,
|
||||
wasmTypes,
|
||||
} from "./messages";
|
||||
import { JsonObject } from "./queries";
|
||||
|
||||
const registry = new Registry(wasmTypes);
|
||||
|
||||
@ -100,7 +101,7 @@ async function instantiateContract(
|
||||
async function executeContract(
|
||||
signer: OfflineDirectSigner,
|
||||
contractAddress: string,
|
||||
msg: Record<string, unknown>,
|
||||
msg: JsonObject,
|
||||
): Promise<DeliverTxResponse> {
|
||||
const memo = "Time for action";
|
||||
const theMsg: MsgExecuteContractEncodeObject = {
|
||||
|
@ -61,7 +61,7 @@ export interface WasmExtension {
|
||||
* Makes a smart query on the contract and parses the response as JSON.
|
||||
* Throws error if no such contract exists, the query format is invalid or the response is invalid.
|
||||
*/
|
||||
readonly queryContractSmart: (address: string, query: Record<string, unknown>) => Promise<JsonObject>;
|
||||
readonly queryContractSmart: (address: string, query: JsonObject) => Promise<JsonObject>;
|
||||
};
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ export function setupWasmExtension(base: QueryClient): WasmExtension {
|
||||
return queryService.RawContractState(request);
|
||||
},
|
||||
|
||||
queryContractSmart: async (address: string, query: Record<string, unknown>) => {
|
||||
queryContractSmart: async (address: string, query: JsonObject) => {
|
||||
const request = { address: address, queryData: toUtf8(JSON.stringify(query)) };
|
||||
const { data } = await queryService.SmartContractState(request);
|
||||
// By convention, smart queries must return a valid JSON document (see https://github.com/CosmWasm/cosmwasm/issues/144)
|
||||
|
@ -50,6 +50,7 @@ import pako from "pako";
|
||||
import { CosmWasmClient } from "./cosmwasmclient";
|
||||
import {
|
||||
createWasmAminoConverters,
|
||||
JsonObject,
|
||||
MsgClearAdminEncodeObject,
|
||||
MsgExecuteContractEncodeObject,
|
||||
MsgInstantiateContractEncodeObject,
|
||||
@ -137,7 +138,7 @@ export interface MigrateResult {
|
||||
|
||||
export interface ExecuteInstruction {
|
||||
contractAddress: string;
|
||||
msg: Record<string, unknown>;
|
||||
msg: JsonObject;
|
||||
funds?: readonly Coin[];
|
||||
}
|
||||
|
||||
@ -278,7 +279,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
public async instantiate(
|
||||
senderAddress: string,
|
||||
codeId: number,
|
||||
msg: Record<string, unknown>,
|
||||
msg: JsonObject,
|
||||
label: string,
|
||||
fee: StdFee | "auto" | number,
|
||||
options: InstantiateOptions = {},
|
||||
@ -368,7 +369,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
senderAddress: string,
|
||||
contractAddress: string,
|
||||
codeId: number,
|
||||
migrateMsg: Record<string, unknown>,
|
||||
migrateMsg: JsonObject,
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
): Promise<MigrateResult> {
|
||||
@ -397,7 +398,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
public async execute(
|
||||
senderAddress: string,
|
||||
contractAddress: string,
|
||||
msg: Record<string, unknown>,
|
||||
msg: JsonObject,
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
funds?: readonly Coin[],
|
||||
|
Loading…
x
Reference in New Issue
Block a user