/
tx.go
103 lines (85 loc) · 2.34 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
package cli
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/ovrclk/akash/sdkutil"
"github.com/ovrclk/akash/x/provider/config"
types "github.com/ovrclk/akash/x/provider/types/v1beta2"
)
// GetTxCmd returns the transaction commands for provider module
func GetTxCmd(key string) *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: "Provider transaction subcommands",
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(
cmdCreate(key),
cmdUpdate(key),
)
return cmd
}
func cmdCreate(key string) *cobra.Command {
cmd := &cobra.Command{
Use: "create [config-file]",
Short: fmt.Sprintf("Create a %s", key),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
// TODO: enable reading files with non-local URIs
cfg, err := config.ReadConfigPath(args[0])
if err != nil {
err = errors.Wrapf(err, "ReadConfigPath err: %q", args[0])
return err
}
msg := &types.MsgCreateProvider{
Owner: clientCtx.GetFromAddress().String(),
HostURI: cfg.Host,
Info: cfg.Info,
Attributes: cfg.GetAttributes(),
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return sdkutil.BroadcastTX(cmd.Context(), clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
func cmdUpdate(key string) *cobra.Command {
cmd := &cobra.Command{
Use: "update [config-file]",
Short: fmt.Sprintf("Update %s", key),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
cfg, err := config.ReadConfigPath(args[0])
if err != nil {
return err
}
msg := &types.MsgUpdateProvider{
Owner: clientCtx.GetFromAddress().String(),
HostURI: cfg.Host,
Info: cfg.Info,
Attributes: cfg.GetAttributes(),
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return sdkutil.BroadcastTX(cmd.Context(), clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}