-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx.go
142 lines (119 loc) · 3.65 KB
/
tx.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package cli
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/celinium-network/restaking_protocol/x/restaking/coordinator/types"
)
func NewTxCommand() *cobra.Command {
stakingTxCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Restaking Coordinator transaction subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
stakingTxCmd.AddCommand(
NewRegisterOperatorCmd(),
NewDelegateCmd(),
NewUndelegateCmd(),
NewWithdrawRewardCmd(),
)
return stakingTxCmd
}
func NewRegisterOperatorCmd() *cobra.Command {
cmd := &cobra.Command{
Use: `register-operator [consumer-chain-ids] [consumer-validator-addresses]
[restaking-denom]`,
Short: `register a new operator for restaking. eg register-operator "chain0,chain1" "chain0x123,chain10x234"
token`,
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
sender := clientCtx.GetFromAddress().String()
chainIDs := strings.Split(args[0], ",")
addressed := strings.Split(args[1], ",")
msg := types.MsgRegisterOperatorRequest{
ConsumerChainIDs: chainIDs,
ConsumerValidatorAddresses: addressed,
RestakingDenom: args[2],
Sender: sender,
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}
return cmd
}
func NewDelegateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: `delegate [delegator-address] [operator-address] [amount]`,
Short: `delegate to the operator. eg: delegate [celi0x123] [celi0x23] 100000`,
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
amount, ok := sdk.NewIntFromString(args[2])
if !ok {
return fmt.Errorf("can't new int from %s", args[2])
}
msg := types.MsgDelegateRequest{
DelegatorAddress: args[0],
OperatorAddress: args[1],
Amount: amount,
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}
return cmd
}
func NewUndelegateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: `undelegate [delegator-address] [operator-address] [amount]`,
Short: `undelegate from the operator. eg: delegate [celi0x123] [celi0x23] 100000`,
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
amount, ok := sdk.NewIntFromString(args[2])
if !ok {
return fmt.Errorf("can't new int from %s", args[2])
}
msg := types.MsgUndelegateRequest{
DelegatorAddress: args[0],
OperatorAddress: args[1],
Amount: amount,
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}
return cmd
}
func NewWithdrawRewardCmd() *cobra.Command {
cmd := &cobra.Command{
Use: `withdraw-reward [delegator-address] [operator-address]`,
Short: `withdraw reward from the operator. eg: withdraw-reward [celi0x123] [celi0x23]`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.MsgWithdrawRewardRequest{
DelegatorAddress: args[0],
OperatorAddress: args[1],
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}
return cmd
}