/
message_worldcoin_identity_transfer.go
66 lines (54 loc) · 1.98 KB
/
message_worldcoin_identity_transfer.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package types
import (
"math/big"
"cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common/hexutil"
)
const TypeMsgCreateWorldCoinIdentityTransferOp = "create_worldcoin_identity_transfer_operation"
var _ types.Msg = &MsgCreateWorldCoinIdentityTransferOp{}
func (m *MsgCreateWorldCoinIdentityTransferOp) Route() string {
return RouterKey
}
func (m *MsgCreateWorldCoinIdentityTransferOp) Type() string {
return TypeMsgCreateWorldCoinIdentityTransferOp
}
func (m *MsgCreateWorldCoinIdentityTransferOp) GetSigners() []types.AccAddress {
creator, err := types.AccAddressFromBech32(m.Creator)
if err != nil {
panic(err)
}
return []types.AccAddress{creator}
}
func (m *MsgCreateWorldCoinIdentityTransferOp) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(m)
return types.MustSortJSON(bz)
}
func (m *MsgCreateWorldCoinIdentityTransferOp) ValidateBasic() error {
if _, err := types.AccAddressFromBech32(m.Creator); err != nil {
return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
return m.ValidateBody()
}
func (m *MsgCreateWorldCoinIdentityTransferOp) ValidateBody() error {
if _, err := hexutil.Decode(m.Contract); err != nil {
return errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid contract address (%s)", err)
}
if m.Chain == "" {
return errors.Wrap(sdkerrors.ErrInvalidRequest, "chain required")
}
if _, err := hexutil.Decode(m.PrevState); err != nil {
return errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid previous state (%s)", err)
}
if _, err := hexutil.Decode(m.State); err != nil {
return errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid state (%s)", err)
}
if _, ok := new(big.Int).SetString(m.Timestamp, 10); !ok {
return errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid timestamp %s", m.Timestamp)
}
if m.BlockNumber == 0 {
return errors.Wrap(sdkerrors.ErrInvalidRequest, "block number required")
}
return nil
}