-
Notifications
You must be signed in to change notification settings - Fork 105
/
msg_call_contract.go
64 lines (52 loc) · 1.75 KB
/
msg_call_contract.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/axelarnetwork/axelar-core/utils"
nexus "github.com/axelarnetwork/axelar-core/x/nexus/exported"
)
// NewCallContractRequest is the constructor for NewCallContractRequest
func NewCallContractRequest(sender sdk.AccAddress, chain string, contractAddress string, payload []byte, fee *Fee) *CallContractRequest {
return &CallContractRequest{
Sender: sender,
Chain: nexus.ChainName(utils.NormalizeString(chain)),
ContractAddress: contractAddress,
Payload: payload,
Fee: fee,
}
}
// Route returns the route for this message
func (m CallContractRequest) Route() string {
return RouterKey
}
// Type returns the type of the message
func (m CallContractRequest) Type() string {
return "CallContract"
}
// ValidateBasic executes a stateless message validation
func (m CallContractRequest) ValidateBasic() error {
if err := sdk.VerifyAddressFormat(m.Sender); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, sdkerrors.Wrap(err, "sender").Error())
}
if err := m.Chain.Validate(); err != nil {
return sdkerrors.Wrap(err, "invalid chain")
}
if err := utils.ValidateString(m.ContractAddress); err != nil {
return err
}
if m.Fee != nil {
if err := m.Fee.ValidateBasic(); err != nil {
return sdkerrors.Wrap(err, "fee")
}
}
return nil
}
// GetSignBytes returns the message bytes that need to be signed
func (m CallContractRequest) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&m)
return sdk.MustSortJSON(bz)
}
// GetSigners returns the set of signers for this message
func (m CallContractRequest) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{m.Sender}
}