-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_redelegate.go
executable file
·58 lines (52 loc) · 1.95 KB
/
msg_redelegate.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
package types
import (
"fmt"
"github.com/ci123chain/ci123chain/pkg/abci/types"
sdkerrors "github.com/ci123chain/ci123chain/pkg/abci/types/errors"
)
type MsgRedelegate struct {
FromAddress types.AccAddress `json:"from_address"`
DelegatorAddress types.AccAddress `json:"delegator_address"`
ValidatorSrcAddress types.AccAddress `json:"validator_src_address"`
ValidatorDstAddress types.AccAddress `json:"validator_dst_address"`
Amount types.Coin `json:"amount"`
}
func NewMsgRedelegate(fromAddr types.AccAddress, delegateAddr types.AccAddress, validatorSrcAddr,
validatorDstAddr types.AccAddress, amount types.Coin) *MsgRedelegate {
//
return &MsgRedelegate{
FromAddress: fromAddr,
DelegatorAddress: delegateAddr,
ValidatorSrcAddress: validatorSrcAddr,
ValidatorDstAddress: validatorDstAddr,
Amount: amount,
}
}
func (msg *MsgRedelegate) ValidateBasic() error {
if msg.DelegatorAddress.Empty() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "empty delegator address")
}
if msg.ValidatorSrcAddress.Empty() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "empty validatorSrc address")
}
if msg.ValidatorDstAddress.Empty() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "empty validatorDst address")
}
if !msg.Amount.Amount.IsPositive() {
return sdkerrors.Wrap(sdkerrors.ErrParams, "amount can not be negative")
}
if !msg.FromAddress.Equal(msg.DelegatorAddress) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, fmt.Sprintf("expected %s, got %s", msg.FromAddress.String(), msg.DelegatorAddress.String()))
}
return nil
}
func (msg *MsgRedelegate) Bytes() []byte {
bytes, err := StakingCodec.MarshalBinaryLengthPrefixed(msg)
if err != nil {
panic(err)
}
return bytes
}
func (msg *MsgRedelegate) Route() string {return RouteKey}
func (msg *MsgRedelegate) MsgType() string {return "redelegate"}
func (msg *MsgRedelegate) GetFromAddress() types.AccAddress { return msg.FromAddress}