-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
120 lines (98 loc) · 3.28 KB
/
main.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
package main
import (
"context"
"log"
"os"
"path/filepath"
"strings"
"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/pomifer/tx-gen/cmd/accounts"
"github.com/pomifer/tx-gen/cmd/fund"
"github.com/pomifer/tx-gen/cmd/history"
"github.com/pomifer/tx-gen/cmd/profile"
"github.com/tendermint/tendermint/libs/cli"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/spf13/cobra"
)
var defaultKeyHome string
func init() {
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
defaultKeyHome = filepath.Join(userHomeDir, ".tx-gen")
}
func main() {
encodingConfig := encoding.MakeConfig(app.ModuleEncodingRegisters...)
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithInput(os.Stdin).
WithAccountRetriever(types.AccountRetriever{}).
WithBroadcastMode(flags.BroadcastBlock).
WithHomeDir(defaultKeyHome).
WithViper("TX-GEN")
rootCmd := &cobra.Command{
Use: "tx-gen",
Short: "generate sdk transactions",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
if err != nil {
return err
}
initClientCtx, err = config.ReadFromClientConfig(initClientCtx)
if err != nil {
return err
}
node, err := cmd.Flags().GetString("node")
if err != nil {
return err
}
rpcClient, err := client.NewClientFromNode("tcp://localhost:26657")
if err != nil {
log.Fatal(err)
}
node = strings.Replace(node, "26657", "9090", 1)
node = strings.Replace(node, "tcp://", "", 1)
grpcClient, err := grpc.Dial(node, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return err
}
initClientCtx = initClientCtx.WithClient(rpcClient).
WithGRPCClient(grpcClient)
// WithKeyring(kr)
if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
return err
}
return nil
},
}
rootCmd.PersistentFlags().String(flags.FlagNode, "tcp://localhost:26657", "")
rootCmd.PersistentFlags().String(flags.FlagChainID, "mocha-3", "")
rootCmd.PersistentFlags().String(flags.FlagHome, defaultKeyHome, "The application home directory")
rootCmd.PersistentFlags().String(flags.FlagKeyringDir, defaultKeyHome, "The client Keyring directory; if omitted, the default 'home' directory will be used")
rootCmd.PersistentFlags().String(flags.FlagKeyringBackend, "file", "Select keyring's backend (os|file|test)")
rootCmd.PersistentFlags().String(cli.OutputFlag, "text", "Output format (text|json)")
rootCmd.AddCommand(
accounts.InitCmd(),
accounts.PrintAccountsCmd(),
fund.FundCmd(),
keys.Commands(defaultKeyHome),
history.HistoryCmd(),
profile.ProfileCmd(),
)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{})
if err := rootCmd.ExecuteContext(ctx); err != nil {
log.Fatal(err)
}
}