-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_delegate.go
executable file
·53 lines (44 loc) · 1.3 KB
/
msg_delegate.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
package types
import (
"github.com/ci123chain/ci123chain/pkg/abci/types"
)
type MsgDelegate struct {
FromAddress types.AccAddress `json:"from_address"`
DelegatorAddress types.AccAddress `json:"delegator_address"`
ValidatorAddress types.AccAddress `json:"validator_address"`
Amount types.Coin `json:"amount"`
}
func NewMsgDelegate(from types.AccAddress, delegatorAddr types.AccAddress, validatorAddr types.AccAddress,
amount types.Coin) *MsgDelegate {
return &MsgDelegate{
FromAddress: from,
DelegatorAddress: delegatorAddr,
ValidatorAddress: validatorAddr,
Amount: amount,
}
}
func (msg *MsgDelegate) ValidateBasic() error {
if msg.DelegatorAddress.Empty() {
return ErrInvalidParam
}
if msg.ValidatorAddress.Empty() {
return ErrInvalidParam
}
if !msg.Amount.Amount.IsPositive() {
return ErrInvalidParam
}
if !msg.FromAddress.Equal(msg.DelegatorAddress) {
return ErrInvalidParam
}
return nil
}
func (msg *MsgDelegate) Bytes() []byte {
bytes, err := StakingCodec.MarshalBinaryLengthPrefixed(msg)
if err != nil {
panic(err)
}
return bytes
}
func (msg *MsgDelegate) Route() string {return RouteKey}
func (msg *MsgDelegate) MsgType() string {return "delegate"}
func (msg *MsgDelegate) GetFromAddress() types.AccAddress { return msg.FromAddress}