This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
61 lines (52 loc) · 1.47 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
package main
import (
"flag"
"fmt"
"github.com/spacemeshos/smrepl/client"
"github.com/spacemeshos/smrepl/log"
"github.com/spacemeshos/smrepl/repl"
"os"
)
func main() {
var (
dataDir string
walletName string
be *client.WalletBackend
)
grpcServer := client.DefaultGRPCServer
secureConnection := client.DefaultSecureConnection
flag.StringVar(&grpcServer, "server", grpcServer, fmt.Sprintf("The Spacemesh api grpc server host and port. Defaults to %s", client.DefaultGRPCServer))
flag.BoolVar(&secureConnection, "secure", secureConnection, "Connect securely to the server. Default is false")
flag.StringVar(&dataDir, "wallet_directory", getwd(), "set default wallet files directory")
flag.StringVar(&walletName, "wallet", "", "set the name of wallet file to open")
flag.Parse()
be, err := client.OpenConnection(grpcServer, secureConnection, dataDir)
if err != nil {
flag.Usage()
os.Exit(1)
}
if walletName != "" {
walletPath := dataDir + "/" + walletName
fmt.Println("Loading wallet from ", walletPath)
be, err = client.OpenWalletBackend(walletPath, grpcServer, secureConnection)
if err != nil {
fmt.Println("Failed to open wallet file : ", err)
os.Exit(1)
}
}
_, err = be.GetMeshInfo()
if err != nil {
log.Error("Failed to connect to mesh service at %v: %v", be.ServerInfo(), err)
fmt.Println()
flag.Usage()
os.Exit(1)
}
repl.Start(be)
}
func getwd() string {
pwd, err := os.Getwd()
if err != nil {
panic(err)
}
return pwd
}