-
Notifications
You must be signed in to change notification settings - Fork 203
/
tx_unstake_provider.go
66 lines (56 loc) · 1.81 KB
/
tx_unstake_provider.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 cli
import (
"strconv"
"strings"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
dualstakingclient "github.com/lavanet/lava/x/dualstaking/client/cli"
"github.com/lavanet/lava/x/pairing/types"
"github.com/spf13/cobra"
)
var _ = strconv.Itoa(0)
func CmdUnstakeProvider() *cobra.Command {
cmd := &cobra.Command{
Use: "unstake-provider [chain-id,chain-id,chain-id...] [optional: validator]",
Short: "unstake a provider staked on a specific specification on the lava blockchain initiating an un-stake period, funds are returned at the end of the period",
Long: `args:
[chain-id,chain-id] is the specs the provider wishes to stop supporting separated by a ','
[validator] optional arg. this is the validator that will get its delegation decreased due to the unstake. if
no validator is specified, the validator from the largest delegation is picked`,
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argChainIDs := args[0]
chainIDs := strings.Split(argChainIDs, ",")
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
var validator string
if len(args) > 1 {
validator = args[1]
} else {
validator = dualstakingclient.GetValidator(clientCtx)
}
msgs := []sdk.Msg{}
for _, chainID := range chainIDs {
if chainID == "" {
continue
}
msg := types.NewMsgUnstakeProvider(
clientCtx.GetFromAddress().String(),
chainID,
validator,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
msgs = append(msgs, msg)
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msgs...)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}