-
Notifications
You must be signed in to change notification settings - Fork 532
/
node.go
80 lines (68 loc) · 2.1 KB
/
node.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
package ignitecmd
import (
"github.com/spf13/cobra"
"github.com/ignite/cli/v29/ignite/pkg/cosmosaccount"
"github.com/ignite/cli/v29/ignite/pkg/cosmosclient"
"github.com/ignite/cli/v29/ignite/pkg/xurl"
)
const (
flagNode = "node"
cosmosRPCAddress = "https://rpc.cosmos.directory:443/cosmoshub"
)
func NewNode() *cobra.Command {
c := &cobra.Command{
Use: "node [command]",
Short: "Make requests to a live blockchain node",
Args: cobra.ExactArgs(1),
}
c.PersistentFlags().String(flagNode, cosmosRPCAddress, "<host>:<port> to tendermint rpc interface for this chain")
c.AddCommand(
NewNodeQuery(),
NewNodeTx(),
)
return c
}
func newNodeCosmosClient(cmd *cobra.Command) (cosmosclient.Client, error) {
var (
home = getHome(cmd)
prefix = getAddressPrefix(cmd)
node = getNode(cmd)
keyringBackend = getKeyringBackend(cmd)
keyringDir = getKeyringDir(cmd)
gas = getGas(cmd)
gasPrices = getGasPrices(cmd)
gasAdjustment = getGasAdjustment(cmd)
fees = getFees(cmd)
generateOnly = getGenerateOnly(cmd)
)
if keyringBackend == "" {
// Makes cosmosclient usable for commands that doesn't expose the keyring
// backend flag (cosmosclient.New returns an error if it's empty).
keyringBackend = cosmosaccount.KeyringTest
}
options := []cosmosclient.Option{
cosmosclient.WithAddressPrefix(prefix),
cosmosclient.WithHome(home),
cosmosclient.WithKeyringBackend(keyringBackend),
cosmosclient.WithKeyringDir(keyringDir),
cosmosclient.WithNodeAddress(xurl.HTTPEnsurePort(node)),
cosmosclient.WithGenerateOnly(generateOnly),
}
if gas != "" {
options = append(options, cosmosclient.WithGas(gas))
}
if gasPrices != "" {
options = append(options, cosmosclient.WithGasPrices(gasPrices))
}
if gasAdjustment != 0 {
options = append(options, cosmosclient.WithGasAdjustment(gasAdjustment))
}
if fees != "" {
options = append(options, cosmosclient.WithFees(fees))
}
return cosmosclient.New(cmd.Context(), options...)
}
func getNode(cmd *cobra.Command) (node string) {
node, _ = cmd.Flags().GetString(flagNode)
return
}