wormchain: move governance consts to sdk (#2086)
This commit is contained in:
parent
d7198a74d7
commit
235fb59d05
|
@ -10,6 +10,22 @@ import (
|
|||
// CoreModule is the identifier of the Core module (which is used for governance messages)
|
||||
var CoreModule = []byte{00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0x43, 0x6f, 0x72, 0x65}
|
||||
|
||||
// WasmdModule is the identifier of the Wormchain Wasmd module (which is used for governance messages)
|
||||
var WasmdModule = [32]byte{00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0x57, 0x61, 0x73, 0x6D, 0x64, 0x4D, 0x6F, 0x64, 0x75, 0x6C, 0x65}
|
||||
var WasmdModuleStr = string(WasmdModule[:])
|
||||
|
||||
type GovernanceAction uint8
|
||||
|
||||
var (
|
||||
// Wormhole governance actions
|
||||
ActionContractUpgrade GovernanceAction = 1
|
||||
ActionGuardianSetUpdate GovernanceAction = 2
|
||||
|
||||
// Wormchain cosmwasm governance actions
|
||||
ActionStoreCode GovernanceAction = 1
|
||||
ActionInstantiateContract GovernanceAction = 2
|
||||
)
|
||||
|
||||
type (
|
||||
// BodyContractUpgrade is a governance message to perform a contract upgrade of the core module
|
||||
BodyContractUpgrade struct {
|
||||
|
@ -54,7 +70,7 @@ func (b BodyContractUpgrade) Serialize() []byte {
|
|||
// Module
|
||||
buf.Write(CoreModule)
|
||||
// Action
|
||||
MustWrite(buf, binary.BigEndian, uint8(1))
|
||||
MustWrite(buf, binary.BigEndian, ActionContractUpgrade)
|
||||
// ChainID
|
||||
MustWrite(buf, binary.BigEndian, uint16(b.ChainID))
|
||||
|
||||
|
@ -69,7 +85,7 @@ func (b BodyGuardianSetUpdate) Serialize() []byte {
|
|||
// Module
|
||||
buf.Write(CoreModule)
|
||||
// Action
|
||||
MustWrite(buf, binary.BigEndian, uint8(2))
|
||||
MustWrite(buf, binary.BigEndian, ActionGuardianSetUpdate)
|
||||
// ChainID - 0 for universal
|
||||
MustWrite(buf, binary.BigEndian, uint16(0))
|
||||
|
||||
|
@ -91,14 +107,14 @@ func (r BodyTokenBridgeUpgradeContract) Serialize() []byte {
|
|||
}
|
||||
|
||||
func (r BodyWormchainStoreCode) Serialize() []byte {
|
||||
return serializeBridgeGovernanceVaa("WasmdModule", 1, ChainIDWormchain, r.WasmHash)
|
||||
return serializeBridgeGovernanceVaa(WasmdModuleStr, ActionStoreCode, ChainIDWormchain, r.WasmHash)
|
||||
}
|
||||
|
||||
func (r BodyWormchainInstantiateContract) Serialize() []byte {
|
||||
return serializeBridgeGovernanceVaa("WasmdModule", 2, ChainIDWormchain, r.InstantiationParamsHash)
|
||||
return serializeBridgeGovernanceVaa(WasmdModuleStr, ActionInstantiateContract, ChainIDWormchain, r.InstantiationParamsHash)
|
||||
}
|
||||
|
||||
func serializeBridgeGovernanceVaa(module string, actionId uint8, chainId ChainID, payload [32]byte) []byte {
|
||||
func serializeBridgeGovernanceVaa(module string, actionId GovernanceAction, chainId ChainID, payload [32]byte) []byte {
|
||||
if len(module) > 32 {
|
||||
panic("module longer than 32 byte")
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
// "github.com/cosmos/cosmos-sdk/client/flags"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/wormhole-foundation/wormchain/x/wormhole/keeper"
|
||||
"github.com/wormhole-foundation/wormchain/x/wormhole/types"
|
||||
wormholesdk "github.com/wormhole-foundation/wormhole/sdk"
|
||||
"github.com/wormhole-foundation/wormhole/sdk/vaa"
|
||||
|
@ -378,7 +377,7 @@ func CmdGenerateGuardianSetUpdatea() *cobra.Command {
|
|||
set_update = append(set_update, pubkey...)
|
||||
}
|
||||
|
||||
action := keeper.ActionGuardianSetUpdate
|
||||
action := vaa.ActionGuardianSetUpdate
|
||||
chain := 3104
|
||||
module := [32]byte{}
|
||||
copy(module[:], vaa.CoreModule)
|
||||
|
|
|
@ -9,13 +9,6 @@ import (
|
|||
"github.com/wormhole-foundation/wormhole/sdk/vaa"
|
||||
)
|
||||
|
||||
type GovernanceAction uint8
|
||||
|
||||
var (
|
||||
ActionContractUpgrade GovernanceAction = 1
|
||||
ActionGuardianSetUpdate GovernanceAction = 2
|
||||
)
|
||||
|
||||
func (k msgServer) ExecuteGovernanceVAA(goCtx context.Context, msg *types.MsgExecuteGovernanceVAA) (*types.MsgExecuteGovernanceVAAResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
|
||||
|
@ -34,8 +27,8 @@ func (k msgServer) ExecuteGovernanceVAA(goCtx context.Context, msg *types.MsgExe
|
|||
}
|
||||
|
||||
// Execute action
|
||||
switch GovernanceAction(action) {
|
||||
case ActionGuardianSetUpdate:
|
||||
switch vaa.GovernanceAction(action) {
|
||||
case vaa.ActionGuardianSetUpdate:
|
||||
if len(payload) < 5 {
|
||||
return nil, types.ErrInvalidGovernancePayloadLength
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func createExecuteGovernanceVaaPayload(k *keeper.Keeper, ctx sdk.Context, num_gu
|
|||
// governance message with sha3 of wasmBytes as the payload
|
||||
module := [32]byte{}
|
||||
copy(module[:], vaa.CoreModule)
|
||||
gov_msg := types.NewGovernanceMessage(module, byte(keeper.ActionGuardianSetUpdate), uint16(vaa.ChainIDWormchain), set_update)
|
||||
gov_msg := types.NewGovernanceMessage(module, byte(vaa.ActionGuardianSetUpdate), uint16(vaa.ChainIDWormchain), set_update)
|
||||
|
||||
return gov_msg.MarshalBinary(), privateKeys
|
||||
}
|
||||
|
|
|
@ -12,14 +12,6 @@ import (
|
|||
"golang.org/x/crypto/sha3"
|
||||
)
|
||||
|
||||
// WasmdModule is the identifier of the Wasmd module (which is used for governance messages)
|
||||
var WasmdModule = [32]byte{00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0x57, 0x61, 0x73, 0x6D, 0x64, 0x4D, 0x6F, 0x64, 0x75, 0x6C, 0x65}
|
||||
|
||||
var (
|
||||
ActionStoreCode GovernanceAction = 1
|
||||
ActionInstantiateContract GovernanceAction = 2
|
||||
)
|
||||
|
||||
// Simple wrapper of x/wasmd StoreCode that requires a VAA
|
||||
func (k msgServer) StoreCode(goCtx context.Context, msg *types.MsgStoreCode) (*types.MsgStoreCodeResponse, error) {
|
||||
if !k.setWasmd {
|
||||
|
@ -33,12 +25,12 @@ func (k msgServer) StoreCode(goCtx context.Context, msg *types.MsgStoreCode) (*t
|
|||
return nil, err
|
||||
}
|
||||
// Verify VAA
|
||||
action, payload, err := k.VerifyGovernanceVAA(ctx, v, WasmdModule)
|
||||
action, payload, err := k.VerifyGovernanceVAA(ctx, v, vaa.WasmdModule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if GovernanceAction(action) != ActionStoreCode {
|
||||
if vaa.GovernanceAction(action) != vaa.ActionStoreCode {
|
||||
return nil, types.ErrUnknownGovernanceAction
|
||||
}
|
||||
|
||||
|
@ -83,12 +75,12 @@ func (k msgServer) InstantiateContract(goCtx context.Context, msg *types.MsgInst
|
|||
}
|
||||
|
||||
// Verify VAA
|
||||
action, payload, err := k.VerifyGovernanceVAA(ctx, v, WasmdModule)
|
||||
action, payload, err := k.VerifyGovernanceVAA(ctx, v, vaa.WasmdModule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if GovernanceAction(action) != ActionInstantiateContract {
|
||||
if vaa.GovernanceAction(action) != vaa.ActionInstantiateContract {
|
||||
return nil, types.ErrUnknownGovernanceAction
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ func createWasmStoreCodePayload(wasmBytes []byte) []byte {
|
|||
keccak.Write(wasmBytes)
|
||||
keccak.Sum(hashWasm[:0])
|
||||
|
||||
gov_msg := types.NewGovernanceMessage(keeper.WasmdModule, byte(keeper.ActionStoreCode), uint16(vaa.ChainIDWormchain), hashWasm[:])
|
||||
gov_msg := types.NewGovernanceMessage(vaa.WasmdModule, byte(vaa.ActionStoreCode), uint16(vaa.ChainIDWormchain), hashWasm[:])
|
||||
return gov_msg.MarshalBinary()
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,8 @@ func createWasmInstantiatePayload(code_id uint64, label string, json_msg string)
|
|||
expected_hash := vaa.CreateInstatiateCosmwasmContractHash(code_id, label, []byte(json_msg))
|
||||
|
||||
var payload bytes.Buffer
|
||||
payload.Write(keeper.WasmdModule[:])
|
||||
payload.Write([]byte{byte(keeper.ActionInstantiateContract)})
|
||||
payload.Write(vaa.WasmdModule[:])
|
||||
payload.Write([]byte{byte(vaa.ActionInstantiateContract)})
|
||||
binary.Write(&payload, binary.BigEndian, uint16(vaa.ChainIDWormchain))
|
||||
// custom payload
|
||||
payload.Write(expected_hash[:])
|
||||
|
|
Loading…
Reference in New Issue