diff --git a/packages/cosmwasm-stargate/src/aminotypes.ts b/packages/cosmwasm-stargate/src/aminotypes.ts deleted file mode 100644 index b9aa88da..00000000 --- a/packages/cosmwasm-stargate/src/aminotypes.ts +++ /dev/null @@ -1,232 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import { fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding"; -import { AminoConverter, Coin } from "@cosmjs/stargate"; -import { - MsgClearAdmin, - MsgExecuteContract, - MsgInstantiateContract, - MsgMigrateContract, - MsgStoreCode, - MsgUpdateAdmin, -} from "cosmjs-types/cosmwasm/wasm/v1/tx"; -import Long from "long"; - -// TODO: implement -/** - * @see https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/types.proto#L36-L41 - */ -type AccessConfig = never; - -/** - * The Amino JSON representation of [MsgStoreCode]. - * - * [MsgStoreCode]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L28-L39 - */ -export interface AminoMsgStoreCode { - type: "wasm/MsgStoreCode"; - value: { - /** Bech32 account address */ - readonly sender: string; - /** Base64 encoded Wasm */ - readonly wasm_byte_code: string; - readonly instantiate_permission?: AccessConfig; - }; -} - -/** - * The Amino JSON representation of [MsgExecuteContract]. - * - * [MsgExecuteContract]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L73-L86 - */ -export interface AminoMsgExecuteContract { - type: "wasm/MsgExecuteContract"; - value: { - /** Bech32 account address */ - readonly sender: string; - /** Bech32 account address */ - readonly contract: string; - /** Execute message as JavaScript object */ - readonly msg: any; - readonly funds: readonly Coin[]; - }; -} - -/** - * The Amino JSON representation of [MsgInstantiateContract]. - * - * [MsgInstantiateContract]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L46-L64 - */ -export interface AminoMsgInstantiateContract { - type: "wasm/MsgInstantiateContract"; - value: { - /** Bech32 account address */ - readonly sender: string; - /** ID of the Wasm code that was uploaded before */ - readonly code_id: string; - /** Human-readable label for this contract */ - readonly label: string; - /** Instantiate message as JavaScript object */ - readonly msg: any; - readonly funds: readonly Coin[]; - /** Bech32-encoded admin address */ - readonly admin?: string; - }; -} - -/** - * The Amino JSON representation of [MsgMigrateContract]. - * - * [MsgMigrateContract]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L94-L104 - */ -export interface AminoMsgMigrateContract { - type: "wasm/MsgMigrateContract"; - value: { - /** Bech32 account address */ - readonly sender: string; - /** Bech32 account address */ - readonly contract: string; - /** The new code */ - readonly code_id: string; - /** Migrate message as JavaScript object */ - readonly msg: any; - }; -} - -/** - * The Amino JSON representation of [MsgUpdateAdmin]. - * - * [MsgUpdateAdmin]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L113-L121 - */ -export interface AminoMsgUpdateAdmin { - type: "wasm/MsgUpdateAdmin"; - value: { - /** Bech32-encoded sender address. This must be the old admin. */ - readonly sender: string; - /** Bech32-encoded contract address to be updated */ - readonly contract: string; - /** Bech32-encoded address of the new admin */ - readonly new_admin: string; - }; -} - -/** - * The Amino JSON representation of [MsgClearAdmin]. - * - * [MsgClearAdmin]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L126-L132 - */ -export interface AminoMsgClearAdmin { - type: "wasm/MsgClearAdmin"; - value: { - /** Bech32-encoded sender address. This must be the old admin. */ - readonly sender: string; - /** Bech32-encoded contract address to be updated */ - readonly contract: string; - }; -} - -export const cosmWasmTypes: Record = { - "/cosmwasm.wasm.v1.MsgStoreCode": { - aminoType: "wasm/MsgStoreCode", - toAmino: ({ sender, wasmByteCode }: MsgStoreCode): AminoMsgStoreCode["value"] => ({ - sender: sender, - wasm_byte_code: toBase64(wasmByteCode), - }), - fromAmino: ({ sender, wasm_byte_code }: AminoMsgStoreCode["value"]): MsgStoreCode => ({ - sender: sender, - wasmByteCode: fromBase64(wasm_byte_code), - instantiatePermission: undefined, - }), - }, - "/cosmwasm.wasm.v1.MsgInstantiateContract": { - aminoType: "wasm/MsgInstantiateContract", - toAmino: ({ - sender, - codeId, - label, - msg, - funds, - admin, - }: MsgInstantiateContract): AminoMsgInstantiateContract["value"] => ({ - sender: sender, - code_id: codeId.toString(), - label: label, - msg: JSON.parse(fromUtf8(msg)), - funds: funds, - admin: admin || undefined, - }), - fromAmino: ({ - sender, - code_id, - label, - msg, - funds, - admin, - }: AminoMsgInstantiateContract["value"]): MsgInstantiateContract => ({ - sender: sender, - codeId: Long.fromString(code_id), - label: label, - msg: toUtf8(JSON.stringify(msg)), - funds: [...funds], - admin: admin ?? "", - }), - }, - "/cosmwasm.wasm.v1.MsgUpdateAdmin": { - aminoType: "wasm/MsgUpdateAdmin", - toAmino: ({ sender, newAdmin, contract }: MsgUpdateAdmin): AminoMsgUpdateAdmin["value"] => ({ - sender: sender, - new_admin: newAdmin, - contract: contract, - }), - fromAmino: ({ sender, new_admin, contract }: AminoMsgUpdateAdmin["value"]): MsgUpdateAdmin => ({ - sender: sender, - newAdmin: new_admin, - contract: contract, - }), - }, - "/cosmwasm.wasm.v1.MsgClearAdmin": { - aminoType: "wasm/MsgClearAdmin", - toAmino: ({ sender, contract }: MsgClearAdmin): AminoMsgClearAdmin["value"] => ({ - sender: sender, - contract: contract, - }), - fromAmino: ({ sender, contract }: AminoMsgClearAdmin["value"]): MsgClearAdmin => ({ - sender: sender, - contract: contract, - }), - }, - "/cosmwasm.wasm.v1.MsgExecuteContract": { - aminoType: "wasm/MsgExecuteContract", - toAmino: ({ sender, contract, msg, funds }: MsgExecuteContract): AminoMsgExecuteContract["value"] => ({ - sender: sender, - contract: contract, - msg: JSON.parse(fromUtf8(msg)), - funds: funds, - }), - fromAmino: ({ sender, contract, msg, funds }: AminoMsgExecuteContract["value"]): MsgExecuteContract => ({ - sender: sender, - contract: contract, - msg: toUtf8(JSON.stringify(msg)), - funds: [...funds], - }), - }, - "/cosmwasm.wasm.v1.MsgMigrateContract": { - aminoType: "wasm/MsgMigrateContract", - toAmino: ({ sender, contract, codeId, msg }: MsgMigrateContract): AminoMsgMigrateContract["value"] => ({ - sender: sender, - contract: contract, - code_id: codeId.toString(), - msg: JSON.parse(fromUtf8(msg)), - }), - fromAmino: ({ - sender, - contract, - code_id, - msg, - }: AminoMsgMigrateContract["value"]): MsgMigrateContract => ({ - sender: sender, - contract: contract, - codeId: Long.fromString(code_id), - msg: toUtf8(JSON.stringify(msg)), - }), - }, -}; diff --git a/packages/cosmwasm-stargate/src/index.ts b/packages/cosmwasm-stargate/src/index.ts index a560f6c3..91ab2f30 100644 --- a/packages/cosmwasm-stargate/src/index.ts +++ b/packages/cosmwasm-stargate/src/index.ts @@ -1,7 +1,8 @@ -export { cosmWasmTypes } from "./aminotypes"; export { Code, CodeDetails, Contract, ContractCodeHistoryEntry, CosmWasmClient } from "./cosmwasmclient"; export { fromBinary, toBinary } from "./encoding"; export { + cosmWasmTypes, + createWasmAminoConverters, isMsgClearAdminEncodeObject, isMsgExecuteEncodeObject, isMsgInstantiateContractEncodeObject, diff --git a/packages/cosmwasm-stargate/src/modules/index.ts b/packages/cosmwasm-stargate/src/modules/index.ts index c15432af..7ae68425 100644 --- a/packages/cosmwasm-stargate/src/modules/index.ts +++ b/packages/cosmwasm-stargate/src/modules/index.ts @@ -1,3 +1,13 @@ +export { + AminoMsgClearAdmin, + AminoMsgExecuteContract, + AminoMsgInstantiateContract, + AminoMsgMigrateContract, + AminoMsgStoreCode, + AminoMsgUpdateAdmin, + cosmWasmTypes, + createWasmAminoConverters, +} from "./wasm/aminomessages"; export { isMsgClearAdminEncodeObject, isMsgExecuteEncodeObject, diff --git a/packages/cosmwasm-stargate/src/aminotypes.spec.ts b/packages/cosmwasm-stargate/src/modules/wasm/aminomessages.spec.ts similarity index 91% rename from packages/cosmwasm-stargate/src/aminotypes.spec.ts rename to packages/cosmwasm-stargate/src/modules/wasm/aminomessages.spec.ts index 6e92eb72..476519b7 100644 --- a/packages/cosmwasm-stargate/src/aminotypes.spec.ts +++ b/packages/cosmwasm-stargate/src/modules/wasm/aminomessages.spec.ts @@ -18,8 +18,8 @@ import { AminoMsgMigrateContract, AminoMsgStoreCode, AminoMsgUpdateAdmin, - cosmWasmTypes, -} from "./aminotypes"; + createWasmAminoConverters, +} from "./aminomessages"; describe("AminoTypes", () => { describe("toAmino", () => { @@ -29,7 +29,7 @@ describe("AminoTypes", () => { wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="), instantiatePermission: undefined, }; - const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({ + const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({ typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode", value: msg, }); @@ -54,10 +54,12 @@ describe("AminoTypes", () => { funds: coins(1234, "ucosm"), admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", }; - const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({ - typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract", - value: msg, - }); + const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino( + { + typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract", + value: msg, + }, + ); const expected: AminoMsgInstantiateContract = { type: "wasm/MsgInstantiateContract", value: { @@ -82,10 +84,12 @@ describe("AminoTypes", () => { funds: coins(1234, "ucosm"), admin: "", }; - const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({ - typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract", - value: msg, - }); + const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino( + { + typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract", + value: msg, + }, + ); const expected: AminoMsgInstantiateContract = { type: "wasm/MsgInstantiateContract", value: { @@ -107,7 +111,7 @@ describe("AminoTypes", () => { newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", }; - const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({ + const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({ typeUrl: "/cosmwasm.wasm.v1.MsgUpdateAdmin", value: msg, }); @@ -127,7 +131,7 @@ describe("AminoTypes", () => { sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", }; - const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({ + const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({ typeUrl: "/cosmwasm.wasm.v1.MsgClearAdmin", value: msg, }); @@ -148,7 +152,7 @@ describe("AminoTypes", () => { msg: toUtf8(`{"foo":"bar"}`), funds: coins(1234, "ucosm"), }; - const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({ + const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({ typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", value: msg, }); @@ -171,7 +175,7 @@ describe("AminoTypes", () => { codeId: Long.fromString("98765"), msg: toUtf8(`{"foo":"bar"}`), }; - const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({ + const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({ typeUrl: "/cosmwasm.wasm.v1.MsgMigrateContract", value: msg, }); @@ -197,7 +201,9 @@ describe("AminoTypes", () => { wasm_byte_code: "WUVMTE9XIFNVQk1BUklORQ==", }, }; - const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg); + const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino( + aminoMsg, + ); const expectedValue: MsgStoreCode = { sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="), @@ -223,7 +229,9 @@ describe("AminoTypes", () => { admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", }, }; - const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg); + const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino( + aminoMsg, + ); const expectedValue: MsgInstantiateContract = { sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", codeId: Long.fromString("12345"), @@ -250,7 +258,9 @@ describe("AminoTypes", () => { funds: coins(1234, "ucosm"), }, }; - const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg); + const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino( + aminoMsg, + ); const expectedValue: MsgInstantiateContract = { sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", codeId: Long.fromString("12345"), @@ -275,7 +285,9 @@ describe("AminoTypes", () => { contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", }, }; - const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg); + const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino( + aminoMsg, + ); const expectedValue: MsgUpdateAdmin = { sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", @@ -295,7 +307,9 @@ describe("AminoTypes", () => { contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", }, }; - const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg); + const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino( + aminoMsg, + ); const expectedValue: MsgClearAdmin = { sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", @@ -316,7 +330,9 @@ describe("AminoTypes", () => { funds: coins(1234, "ucosm"), }, }; - const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg); + const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino( + aminoMsg, + ); const expectedValue: MsgExecuteContract = { sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", @@ -339,7 +355,9 @@ describe("AminoTypes", () => { msg: { foo: "bar" }, }, }; - const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg); + const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino( + aminoMsg, + ); const expectedValue: MsgMigrateContract = { sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", diff --git a/packages/cosmwasm-stargate/src/modules/wasm/aminomessages.ts b/packages/cosmwasm-stargate/src/modules/wasm/aminomessages.ts new file mode 100644 index 00000000..5ba5cac9 --- /dev/null +++ b/packages/cosmwasm-stargate/src/modules/wasm/aminomessages.ts @@ -0,0 +1,242 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding"; +import { AminoConverters, Coin } from "@cosmjs/stargate"; +import { + MsgClearAdmin, + MsgExecuteContract, + MsgInstantiateContract, + MsgMigrateContract, + MsgStoreCode, + MsgUpdateAdmin, +} from "cosmjs-types/cosmwasm/wasm/v1/tx"; +import Long from "long"; + +// TODO: implement +/** + * @see https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/types.proto#L36-L41 + */ +type AccessConfig = never; + +/** + * The Amino JSON representation of [MsgStoreCode]. + * + * [MsgStoreCode]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L28-L39 + */ +export interface AminoMsgStoreCode { + type: "wasm/MsgStoreCode"; + value: { + /** Bech32 account address */ + readonly sender: string; + /** Base64 encoded Wasm */ + readonly wasm_byte_code: string; + readonly instantiate_permission?: AccessConfig; + }; +} + +/** + * The Amino JSON representation of [MsgExecuteContract]. + * + * [MsgExecuteContract]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L73-L86 + */ +export interface AminoMsgExecuteContract { + type: "wasm/MsgExecuteContract"; + value: { + /** Bech32 account address */ + readonly sender: string; + /** Bech32 account address */ + readonly contract: string; + /** Execute message as JavaScript object */ + readonly msg: any; + readonly funds: readonly Coin[]; + }; +} + +/** + * The Amino JSON representation of [MsgInstantiateContract]. + * + * [MsgInstantiateContract]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L46-L64 + */ +export interface AminoMsgInstantiateContract { + type: "wasm/MsgInstantiateContract"; + value: { + /** Bech32 account address */ + readonly sender: string; + /** ID of the Wasm code that was uploaded before */ + readonly code_id: string; + /** Human-readable label for this contract */ + readonly label: string; + /** Instantiate message as JavaScript object */ + readonly msg: any; + readonly funds: readonly Coin[]; + /** Bech32-encoded admin address */ + readonly admin?: string; + }; +} + +/** + * The Amino JSON representation of [MsgMigrateContract]. + * + * [MsgMigrateContract]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L94-L104 + */ +export interface AminoMsgMigrateContract { + type: "wasm/MsgMigrateContract"; + value: { + /** Bech32 account address */ + readonly sender: string; + /** Bech32 account address */ + readonly contract: string; + /** The new code */ + readonly code_id: string; + /** Migrate message as JavaScript object */ + readonly msg: any; + }; +} + +/** + * The Amino JSON representation of [MsgUpdateAdmin]. + * + * [MsgUpdateAdmin]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L113-L121 + */ +export interface AminoMsgUpdateAdmin { + type: "wasm/MsgUpdateAdmin"; + value: { + /** Bech32-encoded sender address. This must be the old admin. */ + readonly sender: string; + /** Bech32-encoded contract address to be updated */ + readonly contract: string; + /** Bech32-encoded address of the new admin */ + readonly new_admin: string; + }; +} + +/** + * The Amino JSON representation of [MsgClearAdmin]. + * + * [MsgClearAdmin]: https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/tx.proto#L126-L132 + */ +export interface AminoMsgClearAdmin { + type: "wasm/MsgClearAdmin"; + value: { + /** Bech32-encoded sender address. This must be the old admin. */ + readonly sender: string; + /** Bech32-encoded contract address to be updated */ + readonly contract: string; + }; +} + +export function createWasmAminoConverters(): AminoConverters { + return { + "/cosmwasm.wasm.v1.MsgStoreCode": { + aminoType: "wasm/MsgStoreCode", + toAmino: ({ sender, wasmByteCode }: MsgStoreCode): AminoMsgStoreCode["value"] => ({ + sender: sender, + wasm_byte_code: toBase64(wasmByteCode), + }), + fromAmino: ({ sender, wasm_byte_code }: AminoMsgStoreCode["value"]): MsgStoreCode => ({ + sender: sender, + wasmByteCode: fromBase64(wasm_byte_code), + instantiatePermission: undefined, + }), + }, + "/cosmwasm.wasm.v1.MsgInstantiateContract": { + aminoType: "wasm/MsgInstantiateContract", + toAmino: ({ + sender, + codeId, + label, + msg, + funds, + admin, + }: MsgInstantiateContract): AminoMsgInstantiateContract["value"] => ({ + sender: sender, + code_id: codeId.toString(), + label: label, + msg: JSON.parse(fromUtf8(msg)), + funds: funds, + admin: admin || undefined, + }), + fromAmino: ({ + sender, + code_id, + label, + msg, + funds, + admin, + }: AminoMsgInstantiateContract["value"]): MsgInstantiateContract => ({ + sender: sender, + codeId: Long.fromString(code_id), + label: label, + msg: toUtf8(JSON.stringify(msg)), + funds: [...funds], + admin: admin ?? "", + }), + }, + "/cosmwasm.wasm.v1.MsgUpdateAdmin": { + aminoType: "wasm/MsgUpdateAdmin", + toAmino: ({ sender, newAdmin, contract }: MsgUpdateAdmin): AminoMsgUpdateAdmin["value"] => ({ + sender: sender, + new_admin: newAdmin, + contract: contract, + }), + fromAmino: ({ sender, new_admin, contract }: AminoMsgUpdateAdmin["value"]): MsgUpdateAdmin => ({ + sender: sender, + newAdmin: new_admin, + contract: contract, + }), + }, + "/cosmwasm.wasm.v1.MsgClearAdmin": { + aminoType: "wasm/MsgClearAdmin", + toAmino: ({ sender, contract }: MsgClearAdmin): AminoMsgClearAdmin["value"] => ({ + sender: sender, + contract: contract, + }), + fromAmino: ({ sender, contract }: AminoMsgClearAdmin["value"]): MsgClearAdmin => ({ + sender: sender, + contract: contract, + }), + }, + "/cosmwasm.wasm.v1.MsgExecuteContract": { + aminoType: "wasm/MsgExecuteContract", + toAmino: ({ sender, contract, msg, funds }: MsgExecuteContract): AminoMsgExecuteContract["value"] => ({ + sender: sender, + contract: contract, + msg: JSON.parse(fromUtf8(msg)), + funds: funds, + }), + fromAmino: ({ + sender, + contract, + msg, + funds, + }: AminoMsgExecuteContract["value"]): MsgExecuteContract => ({ + sender: sender, + contract: contract, + msg: toUtf8(JSON.stringify(msg)), + funds: [...funds], + }), + }, + "/cosmwasm.wasm.v1.MsgMigrateContract": { + aminoType: "wasm/MsgMigrateContract", + toAmino: ({ sender, contract, codeId, msg }: MsgMigrateContract): AminoMsgMigrateContract["value"] => ({ + sender: sender, + contract: contract, + code_id: codeId.toString(), + msg: JSON.parse(fromUtf8(msg)), + }), + fromAmino: ({ + sender, + contract, + code_id, + msg, + }: AminoMsgMigrateContract["value"]): MsgMigrateContract => ({ + sender: sender, + contract: contract, + codeId: Long.fromString(code_id), + msg: toUtf8(JSON.stringify(msg)), + }), + }, + }; +} + +/** @deprecated use `createWasmAminoConverters()` */ +export const cosmWasmTypes: AminoConverters = createWasmAminoConverters(); diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index c43d04c7..884e9f1a 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -46,9 +46,9 @@ import { import Long from "long"; import pako from "pako"; -import { cosmWasmTypes } from "./aminotypes"; import { CosmWasmClient } from "./cosmwasmclient"; import { + createWasmAminoConverters, MsgClearAdminEncodeObject, MsgExecuteContractEncodeObject, MsgInstantiateContractEncodeObject, @@ -205,7 +205,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { const prefix = options.prefix ?? "cosmos"; const { registry = createDefaultRegistry(), - aminoTypes = new AminoTypes({ prefix, additions: cosmWasmTypes }), + aminoTypes = new AminoTypes({ prefix, additions: createWasmAminoConverters() }), } = options; this.registry = registry; this.aminoTypes = aminoTypes; diff --git a/packages/stargate/src/index.ts b/packages/stargate/src/index.ts index 519263b7..5cf0c01d 100644 --- a/packages/stargate/src/index.ts +++ b/packages/stargate/src/index.ts @@ -1,5 +1,5 @@ export { Account, accountFromAny } from "./accounts"; -export { AminoConverter } from "./aminoconverters"; +export { AminoConverter, AminoConverters } from "./aminoconverters"; export { AminoTypes, AminoTypesOptions } from "./aminotypes"; export { calculateFee, GasPrice } from "./fee"; export * as logs from "./logs";