diff --git a/src/core/Msg.ts b/src/core/Msg.ts index c059ac10..9113c243 100644 --- a/src/core/Msg.ts +++ b/src/core/Msg.ts @@ -68,6 +68,7 @@ import { MsgUpdateContractAdmin, MsgClearContractAdmin, WasmMsg, + MsgSudoContract, } from './wasm/msgs'; import { MsgBurn, @@ -432,6 +433,11 @@ export namespace Msg { data as MsgExecuteContract.Amino, isClassic ); + case 'wasm/MsgSudoContract': + return MsgSudoContract.fromAmino( + data as MsgSudoContract.Amino, + isClassic + ); case 'wasm/MsgMigrateContract': return MsgMigrateContract.fromAmino( data as MsgMigrateContract.Amino, @@ -609,6 +615,8 @@ export namespace Msg { case '/terra.wasm.v1beta1.MsgExecuteContract': case '/cosmwasm.wasm.v1.MsgExecuteContract': return MsgExecuteContract.fromData(data, isClassic); + case '/cosmwasm.wasm.v1.MsgSudoContract': + return MsgSudoContract.fromData(data, isClassic); case '/terra.wasm.v1beta1.MsgMigrateContract': case '/cosmwasm.wasm.v1.MsgMigrateContract': return MsgMigrateContract.fromData(data, isClassic); @@ -815,6 +823,9 @@ export namespace Msg { case '/terra.wasm.v1beta1.MsgExecuteContract': case '/cosmwasm.wasm.v1.MsgExecuteContract': return MsgExecuteContract.unpackAny(proto, isClassic); + case '/terra.wasm.v1beta1.MsgSudoContract': + case '/cosmwasm.wasm.v1.MsgSudoContract': + return MsgSudoContract.unpackAny(proto, isClassic); case '/terra.wasm.v1beta1.MsgMigrateContract': case '/cosmwasm.wasm.v1beta1.MsgMigrateContract': return MsgMigrateContract.unpackAny(proto, isClassic); diff --git a/src/core/gov/v1/Proposal.ts b/src/core/gov/v1/Proposal.ts index f371fd06..c973d261 100644 --- a/src/core/gov/v1/Proposal.ts +++ b/src/core/gov/v1/Proposal.ts @@ -11,12 +11,8 @@ import { } from '../../upgrade/proposals'; import { ClearAdminProposal, - ExecuteContractProposal, - InstantiateContractProposal, - MigrateContractProposal, PinCodesProposal, StoreCodeProposal, - SudoContractProposal, UnpinCodesProposal, UpdateAdminProposal, UpdateInstantiateConfigProposal, @@ -39,6 +35,12 @@ import { MsgDeleteAlliance, } from '../../../core/alliance/proposals'; import { AccAddress } from 'core/bech32'; +import { + MsgExecuteContract, + MsgInstantiateContract, + MsgMigrateContract, + MsgSudoContract, +} from '../../wasm/msgs'; /** * Stores information pertaining to a submitted proposal, such as its status and time of @@ -318,12 +320,12 @@ export namespace Proposal { | MsgDeleteAlliance | ClientUpdateProposal | ClearAdminProposal - | ExecuteContractProposal - | InstantiateContractProposal - | MigrateContractProposal + | MsgExecuteContract + | MsgInstantiateContract + | MsgMigrateContract | PinCodesProposal | StoreCodeProposal - | SudoContractProposal + | MsgSudoContract | UnpinCodesProposal | UpdateAdminProposal | UpdateInstantiateConfigProposal; @@ -343,12 +345,12 @@ export namespace Proposal { | MsgDeleteAlliance.Amino | ClientUpdateProposal.Amino | ClearAdminProposal.Amino - | ExecuteContractProposal.Amino - | InstantiateContractProposal.Amino - | MigrateContractProposal.Amino + | MsgExecuteContract.Amino + | MsgInstantiateContract.Amino + | MsgMigrateContract.Amino | PinCodesProposal.Amino | StoreCodeProposal.Amino - | SudoContractProposal.Amino + | MsgSudoContract.Amino | UnpinCodesProposal.Amino | UpdateAdminProposal.Amino | UpdateInstantiateConfigProposal.Amino @@ -368,12 +370,12 @@ export namespace Proposal { | MsgDeleteAlliance.Data | ClientUpdateProposal.Data | ClearAdminProposal.Data - | ExecuteContractProposal.Data - | InstantiateContractProposal.Data - | MigrateContractProposal.Data + | MsgExecuteContract.Data + | MsgInstantiateContract.Data + | MsgMigrateContract.Data | PinCodesProposal.Data | StoreCodeProposal.Data - | SudoContractProposal.Data + | MsgSudoContract.Data | UnpinCodesProposal.Data | UpdateAdminProposal.Data | UpdateInstantiateConfigProposal.Data @@ -393,12 +395,12 @@ export namespace Proposal { | MsgDeleteAlliance.Proto | ClientUpdateProposal.Proto | ClearAdminProposal.Proto - | ExecuteContractProposal.Proto - | InstantiateContractProposal.Proto - | MigrateContractProposal.Proto + | MsgExecuteContract.Proto + | MsgInstantiateContract.Proto + | MsgMigrateContract.Proto | PinCodesProposal.Proto | StoreCodeProposal.Proto - | SudoContractProposal.Proto + | MsgSudoContract.Proto | UnpinCodesProposal.Proto | UpdateAdminProposal.Proto | UpdateInstantiateConfigProposal.Proto @@ -428,18 +430,18 @@ export namespace Proposal { return ClientUpdateProposal.fromAmino(amino, isClassic); case 'wasm/ClearAdminProposal': return ClearAdminProposal.fromAmino(amino, isClassic); - case 'wasm/ExecuteContractProposal': - return ExecuteContractProposal.fromAmino(amino, isClassic); - case 'wasm/InstantiateContractProposal': - return InstantiateContractProposal.fromAmino(amino, isClassic); - case 'wasm/MigrateContractProposal': - return MigrateContractProposal.fromAmino(amino, isClassic); + case 'wasm/MsgExecuteContract': + return MsgExecuteContract.fromAmino(amino, isClassic); + case 'wasm/MsgInstantiateContract': + return MsgInstantiateContract.fromAmino(amino, isClassic); + case 'wasm/MsgMigrateContract': + return MsgMigrateContract.fromAmino(amino, isClassic); case 'wasm/PinCodesProposal': return PinCodesProposal.fromAmino(amino, isClassic); case 'wasm/StoreCodeProposal': return StoreCodeProposal.fromAmino(amino, isClassic); - case 'wasm/SudoContractProposal': - return SudoContractProposal.fromAmino(amino, isClassic); + case 'wasm/MsgSudoContract': + return MsgSudoContract.fromAmino(amino, isClassic); case 'wasm/UnpinCodesProposal': return UnpinCodesProposal.fromAmino(amino, isClassic); case 'wasm/UpdateAdminProposal': @@ -479,18 +481,18 @@ export namespace Proposal { return ClientUpdateProposal.fromData(data, isClassic); case '/cosmwasm.wasm.v1.ClearAdminProposal': return ClearAdminProposal.fromData(data, isClassic); - case '/cosmwasm.wasm.v1.ExecuteContractProposal': - return ExecuteContractProposal.fromData(data, isClassic); - case '/cosmwasm.wasm.v1.InstantiateContractProposal': - return InstantiateContractProposal.fromData(data, isClassic); - case '/cosmwasm.wasm.v1.MigrateContractProposal': - return MigrateContractProposal.fromData(data, isClassic); + case '/cosmwasm.wasm.v1.MsgExecuteContract': + return MsgExecuteContract.fromData(data, isClassic); + case '/cosmwasm.wasm.v1.MsgInstantiateContract': + return MsgInstantiateContract.fromData(data, isClassic); + case '/cosmwasm.wasm.v1.MsgMigrateContract': + return MsgMigrateContract.fromData(data, isClassic); case '/cosmwasm.wasm.v1.PinCodesProposal': return PinCodesProposal.fromData(data, isClassic); case '/cosmwasm.wasm.v1.StoreCodeProposal': return StoreCodeProposal.fromData(data, isClassic); - case '/cosmwasm.wasm.v1.SudoContractProposal': - return SudoContractProposal.fromData(data, isClassic); + case '/cosmwasm.wasm.v1.MsgSudoContract': + return MsgSudoContract.fromData(data, isClassic); case '/cosmwasm.wasm.v1.UnpinCodesProposal': return UnpinCodesProposal.fromData(data, isClassic); case '/cosmwasm.wasm.v1.UpdateAdminProposal': @@ -534,18 +536,18 @@ export namespace Proposal { return ClientUpdateProposal.unpackAny(anyProto, isClassic); case '/cosmwasm.wasm.v1.ClearAdminProposal': return ClearAdminProposal.unpackAny(anyProto, isClassic); - case '/cosmwasm.wasm.v1.ExecuteContractProposal': - return ExecuteContractProposal.unpackAny(anyProto, isClassic); - case '/cosmwasm.wasm.v1.InstantiateContractProposal': - return InstantiateContractProposal.unpackAny(anyProto, isClassic); - case '/cosmwasm.wasm.v1.MigrateContractProposal': - return MigrateContractProposal.unpackAny(anyProto, isClassic); + case '/cosmwasm.wasm.v1.MsgExecuteContract': + return MsgExecuteContract.unpackAny(anyProto, isClassic); + case '/cosmwasm.wasm.v1.MsgInstantiateContract': + return MsgInstantiateContract.unpackAny(anyProto, isClassic); + case '/cosmwasm.wasm.v1.MsgMigrateContract': + return MsgMigrateContract.unpackAny(anyProto, isClassic); case '/cosmwasm.wasm.v1.PinCodesProposal': return PinCodesProposal.unpackAny(anyProto, isClassic); case '/cosmwasm.wasm.v1.StoreCodeProposal': return StoreCodeProposal.unpackAny(anyProto, isClassic); - case '/cosmwasm.wasm.v1.SudoContractProposal': - return SudoContractProposal.unpackAny(anyProto, isClassic); + case '/cosmwasm.wasm.v1.MsgSudoContract': + return MsgSudoContract.unpackAny(anyProto, isClassic); case '/cosmwasm.wasm.v1.UnpinCodesProposal': return UnpinCodesProposal.unpackAny(anyProto, isClassic); case '/cosmwasm.wasm.v1.UpdateAdminProposal': diff --git a/src/core/wasm/msgs/MsgSudoContract.ts b/src/core/wasm/msgs/MsgSudoContract.ts new file mode 100644 index 00000000..10abca11 --- /dev/null +++ b/src/core/wasm/msgs/MsgSudoContract.ts @@ -0,0 +1,136 @@ +import { JSONSerializable, removeNull } from '../../../util/json'; +import { Any } from '@terra-money/terra.proto/google/protobuf/any'; +import { MsgSudoContract as MsgSudoContract_pb } from '@terra-money/terra.proto/cosmwasm/wasm/v1/tx'; + +export class MsgSudoContract extends JSONSerializable< + MsgSudoContract.Amino, + MsgSudoContract.Data, + MsgSudoContract.Proto +> { + /** + * @param title a short summary + * @param description a human readable text + * @param contract contract address to be migrated from + * @param msg JSON message to configure the migrate state of the contract + */ + constructor( + public authority: string, + public contract: string, + public msg: object + ) { + super(); + } + + public static fromAmino( + data: MsgSudoContract.Amino, + isClassic?: boolean + ): MsgSudoContract { + if (isClassic) { + throw new Error('Not supported for the network'); + } + const { + value: { authority, contract, msg }, + } = data as MsgSudoContract.Amino; + return new MsgSudoContract(authority, contract, msg); + } + + public toAmino(isClassic?: boolean): MsgSudoContract.Amino { + if (isClassic) { + throw new Error('Not supported for the network'); + } + const { authority, contract, msg } = this; + return { + type: 'wasm/MsgSudoContract', + value: { + authority, + contract, + msg, + }, + }; + } + + public static fromProto( + proto: MsgSudoContract.Proto, + isClassic?: boolean + ): MsgSudoContract { + if (isClassic) { + throw new Error('Not supported for the network'); + } + return new MsgSudoContract(proto.authority, proto.contract, proto.msg); + } + + public toProto(isClassic?: boolean): MsgSudoContract.Proto { + if (isClassic) { + throw new Error('Not supported for the network'); + } + const { authority, contract, msg } = this; + return MsgSudoContract_pb.fromPartial({ + authority, + contract, + msg: Buffer.from(JSON.stringify(removeNull(msg)), 'utf-8'), + }); + } + public packAny(isClassic?: boolean): Any { + if (isClassic) { + throw new Error('Not supported for the network'); + } + return Any.fromPartial({ + typeUrl: '/cosmwasm.wasm.v1.MsgSudoContract', + value: MsgSudoContract_pb.encode(this.toProto(isClassic)).finish(), + }); + } + + public static unpackAny(msgAny: Any, isClassic?: boolean): MsgSudoContract { + if (isClassic) { + throw new Error('Not supported for the network'); + } + return MsgSudoContract.fromProto( + MsgSudoContract_pb.decode(msgAny.value), + isClassic + ); + } + + public static fromData( + data: MsgSudoContract.Data, + isClassic?: boolean + ): MsgSudoContract { + if (isClassic) { + throw new Error('Not supported for the network'); + } + const { authority, contract, msg } = data as MsgSudoContract.Data; + return new MsgSudoContract(authority, contract, msg); + } + + public toData(isClassic?: boolean): MsgSudoContract.Data { + if (isClassic) { + throw new Error('Not supported for the network'); + } + const { authority, contract, msg } = this; + return { + '@type': '/cosmwasm.wasm.v1.MsgSudoContract', + authority, + contract, + msg, + }; + } +} + +export namespace MsgSudoContract { + export interface Amino { + type: 'wasm/MsgSudoContract'; + value: { + authority: string; + contract: string; + msg: any; + }; + } + + export interface Data { + '@type': '/cosmwasm.wasm.v1.MsgSudoContract'; + authority: string; + contract: string; + msg: any; + } + + export type Proto = MsgSudoContract_pb; +} diff --git a/src/core/wasm/msgs/index.ts b/src/core/wasm/msgs/index.ts index ff0bb33b..28986da9 100644 --- a/src/core/wasm/msgs/index.ts +++ b/src/core/wasm/msgs/index.ts @@ -5,7 +5,9 @@ import { MsgExecuteContract } from './MsgExecuteContract'; import { MsgMigrateContract } from './MsgMigrateContract'; import { MsgUpdateContractAdmin } from './MsgUpdateContractAdmin'; import { MsgClearContractAdmin } from './MsgClearContractAdmin'; +import { MsgSudoContract } from './MsgSudoContract'; +export * from './MsgSudoContract'; export * from './MsgStoreCode'; export * from './MsgMigrateCode'; export * from './MsgInstantiateContract'; @@ -19,6 +21,7 @@ export type WasmMsg = | MsgMigrateCode | MsgInstantiateContract | MsgExecuteContract + | MsgSudoContract | MsgMigrateContract | MsgUpdateContractAdmin | MsgClearContractAdmin; @@ -29,6 +32,7 @@ export namespace WasmMsg { | MsgMigrateCode.Amino | MsgInstantiateContract.Amino | MsgExecuteContract.Amino + | MsgSudoContract.Amino | MsgMigrateContract.Amino | MsgUpdateContractAdmin.Amino | MsgClearContractAdmin.Amino; @@ -37,6 +41,7 @@ export namespace WasmMsg { | MsgMigrateCode.Data | MsgInstantiateContract.Data | MsgExecuteContract.Data + | MsgSudoContract.Data | MsgMigrateContract.Data | MsgUpdateContractAdmin.Data | MsgClearContractAdmin.Data; @@ -45,6 +50,7 @@ export namespace WasmMsg { | MsgMigrateCode.Proto | MsgInstantiateContract.Proto | MsgExecuteContract.Proto + | MsgSudoContract.Proto | MsgMigrateContract.Proto | MsgUpdateContractAdmin.Proto | MsgClearContractAdmin.Proto;