Skip to content

Commit

Permalink
Write New, ValidateBasic for Msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Oct 28, 2022
1 parent a7e935a commit 5d2dec9
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions x/ccv/provider/types/msg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"strings"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -18,9 +20,20 @@ var (

// NewMsgDesignateConsensusKeyForConsumerChain creates a new MsgDesignateConsensusKeyForConsumerChain instance.
// Delegator address and validator address are the same.
func NewMsgDesignateConsensusKeyForConsumerChain() (*MsgDesignateConsensusKeyForConsumerChain, error) {

return &MsgDesignateConsensusKeyForConsumerChain{}, nil
func NewMsgDesignateConsensusKeyForConsumerChain(chainID string, providerValidatorAddress sdk.ValAddress,
consumerValidatorPubKey cryptotypes.PubKey) (*MsgDesignateConsensusKeyForConsumerChain, error) {
var pubKeyAny *codectypes.Any
if consumerValidatorPubKey != nil {
var err error
if pubKeyAny, err = codectypes.NewAnyWithValue(consumerValidatorPubKey); err != nil {
return nil, err
}
}
return &MsgDesignateConsensusKeyForConsumerChain{
ChainId: chainID,
ProviderValidatorAddress: providerValidatorAddress.String(),
ConsumerValidatorPubkey: pubKeyAny,
}, nil
}

// Route implements the sdk.Msg interface.
Expand All @@ -36,8 +49,11 @@ func (msg MsgDesignateConsensusKeyForConsumerChain) Type() string {
// If the validator address is not same as delegator's, then the validator must
// sign the msg as well.
func (msg MsgDesignateConsensusKeyForConsumerChain) GetSigners() []sdk.AccAddress {
addrs := []sdk.AccAddress{}
return addrs
valAddr, err := sdk.ValAddressFromBech32(msg.ProviderValidatorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{valAddr.Bytes()}
}

// GetSignBytes returns the message bytes to sign over.
Expand All @@ -48,7 +64,15 @@ func (msg MsgDesignateConsensusKeyForConsumerChain) GetSignBytes() []byte {

// ValidateBasic implements the sdk.Msg interface.
func (msg MsgDesignateConsensusKeyForConsumerChain) ValidateBasic() error {

if strings.TrimSpace(msg.ChainId) == "" {
return ErrBlankConsumerChainID
}
if msg.ProviderValidatorAddress == "" {
return ErrEmptyValidatorAddr
}
if msg.ConsumerValidatorPubkey == nil {
return ErrEmptyValidatorPubKey
}
return nil
}

Expand Down

0 comments on commit 5d2dec9

Please sign in to comment.