-
Notifications
You must be signed in to change notification settings - Fork 276
/
msgs.go
39 lines (32 loc) · 1014 Bytes
/
msgs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
)
var _ sdk.Msg = &MsgRegisterEVMAddress{}
func NewMsgRegisterEVMAddress(valAddress sdk.ValAddress, evmAddress common.Address) *MsgRegisterEVMAddress {
msg := &MsgRegisterEVMAddress{
ValidatorAddress: valAddress.String(),
EvmAddress: evmAddress.Hex(),
}
return msg
}
// ValidateBasic verifies that the EVM address and val address are of a valid type
func (msg MsgRegisterEVMAddress) ValidateBasic() error {
_, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
if err != nil {
return err
}
if !common.IsHexAddress(msg.EvmAddress) {
return ErrEVMAddressNotHex
}
return nil
}
// GetSigner fulfills the sdk.Msg interface. The signer must be the validator address
func (msg MsgRegisterEVMAddress) GetSigners() []sdk.AccAddress {
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sdk.AccAddress(valAddr)}
}