/
cli.go
99 lines (89 loc) · 2.45 KB
/
cli.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
package main
import (
"fmt"
"net/http"
"os"
"strings"
"github.com/33cn/plugin/plugin/dapp/dex/boss/buildFlags"
"github.com/33cn/plugin/plugin/dapp/dex/boss/deploy/chain33"
"github.com/33cn/plugin/plugin/dapp/dex/boss/deploy/chain33/offline"
"github.com/33cn/plugin/plugin/dapp/dex/boss/deploy/ethereum"
ethoffline "github.com/33cn/plugin/plugin/dapp/dex/boss/deploy/ethereum/offline"
"github.com/spf13/cobra"
)
func main() {
if buildFlags.RPCAddr4Chain33 == "" {
buildFlags.RPCAddr4Chain33 = "http://localhost:8801"
}
buildFlags.RPCAddr4Chain33 = testTLS(buildFlags.RPCAddr4Chain33)
if buildFlags.RPCAddr4Ethereum == "" {
buildFlags.RPCAddr4Ethereum = "https://data-seed-prebsc-1-s1.binance.org:8545"
//buildFlags.RPCAddr4Ethereum = "wss://ws-testnet.huobichain.com"
}
rootCmd := RootCmd()
rootCmd.PersistentFlags().String("rpc_laddr", buildFlags.RPCAddr4Chain33, "http url")
rootCmd.PersistentFlags().String("rpc_laddr_ethereum", buildFlags.RPCAddr4Ethereum, "http url")
rootCmd.PersistentFlags().String("paraName", "", "para chain name,Eg:user.p.fzm.")
rootCmd.PersistentFlags().String("expire", "120m", "transaction expire time (optional)")
rootCmd.PersistentFlags().Int32("chainID", 0, "chain id, default to 0")
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
// Cmd x2ethereum client command
func RootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "boss",
Short: "manage create offline tx or deploy contracts(dex) for test",
}
cmd.AddCommand(
DeployCmd(),
OfflineCmd(),
)
return cmd
}
func OfflineCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "offline",
Short: "create and sign offline tx to deploy and set dex contracts to ethereum or chain33",
}
cmd.AddCommand(
offline.Chain33OfflineCmd(),
ethoffline.EthOfflineCmd(),
)
return cmd
}
// Cmd x2ethereum client command
func DeployCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "deploy",
Short: "deploy dex to ethereum or chain33",
}
cmd.AddCommand(
ethereum.EthCmd(),
chain33.Chain33Cmd(),
)
return cmd
}
func testTLS(RPCAddr string) string {
rpcaddr := RPCAddr
if !strings.HasPrefix(rpcaddr, "http://") {
return RPCAddr
}
// if http://
if rpcaddr[len(rpcaddr)-1] != '/' {
rpcaddr += "/"
}
rpcaddr += "test"
/* #nosec */
resp, err := http.Get(rpcaddr)
if err != nil {
return "https://" + RPCAddr[7:]
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
return RPCAddr
}
return "https://" + RPCAddr[7:]
}