/
main.go
95 lines (80 loc) · 2.72 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
// Copyright 2020 The the-blockchain-bar Authors
// This file is part of the the-blockchain-bar library.
//
// The the-blockchain-bar library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The the-blockchain-bar library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"fmt"
"os"
"github.com/IacopoMelani/the-blockchain-pub/fs"
"github.com/spf13/cobra"
)
const flagKeystoreFile = "keystore"
const flagDataDir = "datadir"
const flagMiner = "miner"
const flagSSLEmail = "ssl-email"
const flagDisableSSL = "disable-ssl"
const flagIP = "ip"
const flagPort = "port"
const flagBootstrapAcc = "bootstrap-account"
const flagBootstrapIp = "bootstrap-ip"
const flagBootstrapPort = "bootstrap-port"
const flagAmount = "amount"
const flagToAddress = "to"
const flagPassword = "pwd"
const flagConfirm = "confirm"
func main() {
var tbbCmd = &cobra.Command{
Use: "tbb",
Short: "The Blockchain Bar CLI",
Run: func(cmd *cobra.Command, args []string) {
},
}
tbbCmd.AddCommand(versionCmd)
tbbCmd.AddCommand(balancesCmd())
tbbCmd.AddCommand(walletCmd())
tbbCmd.AddCommand(runCmd())
err := tbbCmd.Execute()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func addDefaultRequiredFlags(cmd *cobra.Command) {
cmd.Flags().String(flagDataDir, "", "Absolute path to your node's data dir where the DB will be/is stored")
cmd.MarkFlagRequired(flagDataDir)
}
func addKeystoreFlag(cmd *cobra.Command) {
cmd.Flags().String(flagKeystoreFile, "", "Absolute path to the encrypted keystore file")
cmd.MarkFlagRequired(flagKeystoreFile)
}
func addAmountFlag(cmd *cobra.Command) {
cmd.Flags().Uint(flagAmount, 0, "Amount to send")
}
func addToAddressFlag(cmd *cobra.Command) {
cmd.Flags().String(flagToAddress, "", "Address to send the funds to")
}
func addPwdFlag(cmd *cobra.Command) {
cmd.Flags().String(flagPassword, "", "Password to unlock the keystore, use with caution")
}
func addConfirmFlag(cmd *cobra.Command) {
cmd.Flags().Bool(flagConfirm, false, "Confirm the action")
}
func getDataDirFromCmd(cmd *cobra.Command) string {
dataDir, _ := cmd.Flags().GetString(flagDataDir)
return fs.ExpandPath(dataDir)
}
func incorrectUsageErr() error {
return fmt.Errorf("incorrect usage")
}