mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Move wasm aminotypes to modules/wasm/aminomessages
This commit is contained in:
parent
248e7f3df3
commit
97b8761f71
@ -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<string, AminoConverter> = {
|
|
||||||
"/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)),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
};
|
|
@ -1,7 +1,8 @@
|
|||||||
export { cosmWasmTypes } from "./aminotypes";
|
|
||||||
export { Code, CodeDetails, Contract, ContractCodeHistoryEntry, CosmWasmClient } from "./cosmwasmclient";
|
export { Code, CodeDetails, Contract, ContractCodeHistoryEntry, CosmWasmClient } from "./cosmwasmclient";
|
||||||
export { fromBinary, toBinary } from "./encoding";
|
export { fromBinary, toBinary } from "./encoding";
|
||||||
export {
|
export {
|
||||||
|
cosmWasmTypes,
|
||||||
|
createWasmAminoConverters,
|
||||||
isMsgClearAdminEncodeObject,
|
isMsgClearAdminEncodeObject,
|
||||||
isMsgExecuteEncodeObject,
|
isMsgExecuteEncodeObject,
|
||||||
isMsgInstantiateContractEncodeObject,
|
isMsgInstantiateContractEncodeObject,
|
||||||
|
@ -1,3 +1,13 @@
|
|||||||
|
export {
|
||||||
|
AminoMsgClearAdmin,
|
||||||
|
AminoMsgExecuteContract,
|
||||||
|
AminoMsgInstantiateContract,
|
||||||
|
AminoMsgMigrateContract,
|
||||||
|
AminoMsgStoreCode,
|
||||||
|
AminoMsgUpdateAdmin,
|
||||||
|
cosmWasmTypes,
|
||||||
|
createWasmAminoConverters,
|
||||||
|
} from "./wasm/aminomessages";
|
||||||
export {
|
export {
|
||||||
isMsgClearAdminEncodeObject,
|
isMsgClearAdminEncodeObject,
|
||||||
isMsgExecuteEncodeObject,
|
isMsgExecuteEncodeObject,
|
||||||
|
@ -18,8 +18,8 @@ import {
|
|||||||
AminoMsgMigrateContract,
|
AminoMsgMigrateContract,
|
||||||
AminoMsgStoreCode,
|
AminoMsgStoreCode,
|
||||||
AminoMsgUpdateAdmin,
|
AminoMsgUpdateAdmin,
|
||||||
cosmWasmTypes,
|
createWasmAminoConverters,
|
||||||
} from "./aminotypes";
|
} from "./aminomessages";
|
||||||
|
|
||||||
describe("AminoTypes", () => {
|
describe("AminoTypes", () => {
|
||||||
describe("toAmino", () => {
|
describe("toAmino", () => {
|
||||||
@ -29,7 +29,7 @@ describe("AminoTypes", () => {
|
|||||||
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
|
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
|
||||||
instantiatePermission: undefined,
|
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",
|
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
|
||||||
value: msg,
|
value: msg,
|
||||||
});
|
});
|
||||||
@ -54,10 +54,12 @@ describe("AminoTypes", () => {
|
|||||||
funds: coins(1234, "ucosm"),
|
funds: coins(1234, "ucosm"),
|
||||||
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||||
};
|
};
|
||||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
|
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino(
|
||||||
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
{
|
||||||
value: msg,
|
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
||||||
});
|
value: msg,
|
||||||
|
},
|
||||||
|
);
|
||||||
const expected: AminoMsgInstantiateContract = {
|
const expected: AminoMsgInstantiateContract = {
|
||||||
type: "wasm/MsgInstantiateContract",
|
type: "wasm/MsgInstantiateContract",
|
||||||
value: {
|
value: {
|
||||||
@ -82,10 +84,12 @@ describe("AminoTypes", () => {
|
|||||||
funds: coins(1234, "ucosm"),
|
funds: coins(1234, "ucosm"),
|
||||||
admin: "",
|
admin: "",
|
||||||
};
|
};
|
||||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
|
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino(
|
||||||
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
{
|
||||||
value: msg,
|
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
||||||
});
|
value: msg,
|
||||||
|
},
|
||||||
|
);
|
||||||
const expected: AminoMsgInstantiateContract = {
|
const expected: AminoMsgInstantiateContract = {
|
||||||
type: "wasm/MsgInstantiateContract",
|
type: "wasm/MsgInstantiateContract",
|
||||||
value: {
|
value: {
|
||||||
@ -107,7 +111,7 @@ describe("AminoTypes", () => {
|
|||||||
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
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",
|
typeUrl: "/cosmwasm.wasm.v1.MsgUpdateAdmin",
|
||||||
value: msg,
|
value: msg,
|
||||||
});
|
});
|
||||||
@ -127,7 +131,7 @@ describe("AminoTypes", () => {
|
|||||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
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",
|
typeUrl: "/cosmwasm.wasm.v1.MsgClearAdmin",
|
||||||
value: msg,
|
value: msg,
|
||||||
});
|
});
|
||||||
@ -148,7 +152,7 @@ describe("AminoTypes", () => {
|
|||||||
msg: toUtf8(`{"foo":"bar"}`),
|
msg: toUtf8(`{"foo":"bar"}`),
|
||||||
funds: coins(1234, "ucosm"),
|
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",
|
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
||||||
value: msg,
|
value: msg,
|
||||||
});
|
});
|
||||||
@ -171,7 +175,7 @@ describe("AminoTypes", () => {
|
|||||||
codeId: Long.fromString("98765"),
|
codeId: Long.fromString("98765"),
|
||||||
msg: toUtf8(`{"foo":"bar"}`),
|
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",
|
typeUrl: "/cosmwasm.wasm.v1.MsgMigrateContract",
|
||||||
value: msg,
|
value: msg,
|
||||||
});
|
});
|
||||||
@ -197,7 +201,9 @@ describe("AminoTypes", () => {
|
|||||||
wasm_byte_code: "WUVMTE9XIFNVQk1BUklORQ==",
|
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 = {
|
const expectedValue: MsgStoreCode = {
|
||||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||||
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
|
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
|
||||||
@ -223,7 +229,9 @@ describe("AminoTypes", () => {
|
|||||||
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
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 = {
|
const expectedValue: MsgInstantiateContract = {
|
||||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||||
codeId: Long.fromString("12345"),
|
codeId: Long.fromString("12345"),
|
||||||
@ -250,7 +258,9 @@ describe("AminoTypes", () => {
|
|||||||
funds: coins(1234, "ucosm"),
|
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 = {
|
const expectedValue: MsgInstantiateContract = {
|
||||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||||
codeId: Long.fromString("12345"),
|
codeId: Long.fromString("12345"),
|
||||||
@ -275,7 +285,9 @@ describe("AminoTypes", () => {
|
|||||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
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 = {
|
const expectedValue: MsgUpdateAdmin = {
|
||||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||||
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||||
@ -295,7 +307,9 @@ describe("AminoTypes", () => {
|
|||||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
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 = {
|
const expectedValue: MsgClearAdmin = {
|
||||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||||
@ -316,7 +330,9 @@ describe("AminoTypes", () => {
|
|||||||
funds: coins(1234, "ucosm"),
|
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 = {
|
const expectedValue: MsgExecuteContract = {
|
||||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||||
@ -339,7 +355,9 @@ describe("AminoTypes", () => {
|
|||||||
msg: { foo: "bar" },
|
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 = {
|
const expectedValue: MsgMigrateContract = {
|
||||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
242
packages/cosmwasm-stargate/src/modules/wasm/aminomessages.ts
Normal file
242
packages/cosmwasm-stargate/src/modules/wasm/aminomessages.ts
Normal file
@ -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();
|
@ -46,9 +46,9 @@ import {
|
|||||||
import Long from "long";
|
import Long from "long";
|
||||||
import pako from "pako";
|
import pako from "pako";
|
||||||
|
|
||||||
import { cosmWasmTypes } from "./aminotypes";
|
|
||||||
import { CosmWasmClient } from "./cosmwasmclient";
|
import { CosmWasmClient } from "./cosmwasmclient";
|
||||||
import {
|
import {
|
||||||
|
createWasmAminoConverters,
|
||||||
MsgClearAdminEncodeObject,
|
MsgClearAdminEncodeObject,
|
||||||
MsgExecuteContractEncodeObject,
|
MsgExecuteContractEncodeObject,
|
||||||
MsgInstantiateContractEncodeObject,
|
MsgInstantiateContractEncodeObject,
|
||||||
@ -205,7 +205,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
|||||||
const prefix = options.prefix ?? "cosmos";
|
const prefix = options.prefix ?? "cosmos";
|
||||||
const {
|
const {
|
||||||
registry = createDefaultRegistry(),
|
registry = createDefaultRegistry(),
|
||||||
aminoTypes = new AminoTypes({ prefix, additions: cosmWasmTypes }),
|
aminoTypes = new AminoTypes({ prefix, additions: createWasmAminoConverters() }),
|
||||||
} = options;
|
} = options;
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
this.aminoTypes = aminoTypes;
|
this.aminoTypes = aminoTypes;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export { Account, accountFromAny } from "./accounts";
|
export { Account, accountFromAny } from "./accounts";
|
||||||
export { AminoConverter } from "./aminoconverters";
|
export { AminoConverter, AminoConverters } from "./aminoconverters";
|
||||||
export { AminoTypes, AminoTypesOptions } from "./aminotypes";
|
export { AminoTypes, AminoTypesOptions } from "./aminotypes";
|
||||||
export { calculateFee, GasPrice } from "./fee";
|
export { calculateFee, GasPrice } from "./fee";
|
||||||
export * as logs from "./logs";
|
export * as logs from "./logs";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user