Skip to content

Commit

Permalink
Merge pull request #78 from terra-money/feat/sudo/contract
Browse files Browse the repository at this point in the history
feat: sudo contract
  • Loading branch information
emidev98 authored Feb 6, 2024
2 parents a9eba16 + 59dd0c7 commit d3cfd6a
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 44 deletions.
11 changes: 11 additions & 0 deletions src/core/Msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
MsgUpdateContractAdmin,
MsgClearContractAdmin,
WasmMsg,
MsgSudoContract,
} from './wasm/msgs';
import {
MsgBurn,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
90 changes: 46 additions & 44 deletions src/core/gov/v1/Proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ import {
} from '../../upgrade/proposals';
import {
ClearAdminProposal,
ExecuteContractProposal,
InstantiateContractProposal,
MigrateContractProposal,
PinCodesProposal,
StoreCodeProposal,
SudoContractProposal,
UnpinCodesProposal,
UpdateAdminProposal,
UpdateInstantiateConfigProposal,
Expand All @@ -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
Expand Down Expand Up @@ -318,12 +320,12 @@ export namespace Proposal {
| MsgDeleteAlliance
| ClientUpdateProposal
| ClearAdminProposal
| ExecuteContractProposal
| InstantiateContractProposal
| MigrateContractProposal
| MsgExecuteContract
| MsgInstantiateContract
| MsgMigrateContract
| PinCodesProposal
| StoreCodeProposal
| SudoContractProposal
| MsgSudoContract
| UnpinCodesProposal
| UpdateAdminProposal
| UpdateInstantiateConfigProposal;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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':
Expand Down
136 changes: 136 additions & 0 deletions src/core/wasm/msgs/MsgSudoContract.ts
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 6 additions & 0 deletions src/core/wasm/msgs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -19,6 +21,7 @@ export type WasmMsg =
| MsgMigrateCode
| MsgInstantiateContract
| MsgExecuteContract
| MsgSudoContract
| MsgMigrateContract
| MsgUpdateContractAdmin
| MsgClearContractAdmin;
Expand All @@ -29,6 +32,7 @@ export namespace WasmMsg {
| MsgMigrateCode.Amino
| MsgInstantiateContract.Amino
| MsgExecuteContract.Amino
| MsgSudoContract.Amino
| MsgMigrateContract.Amino
| MsgUpdateContractAdmin.Amino
| MsgClearContractAdmin.Amino;
Expand All @@ -37,6 +41,7 @@ export namespace WasmMsg {
| MsgMigrateCode.Data
| MsgInstantiateContract.Data
| MsgExecuteContract.Data
| MsgSudoContract.Data
| MsgMigrateContract.Data
| MsgUpdateContractAdmin.Data
| MsgClearContractAdmin.Data;
Expand All @@ -45,6 +50,7 @@ export namespace WasmMsg {
| MsgMigrateCode.Proto
| MsgInstantiateContract.Proto
| MsgExecuteContract.Proto
| MsgSudoContract.Proto
| MsgMigrateContract.Proto
| MsgUpdateContractAdmin.Proto
| MsgClearContractAdmin.Proto;
Expand Down

0 comments on commit d3cfd6a

Please sign in to comment.