-
Notifications
You must be signed in to change notification settings - Fork 8
/
client.go
81 lines (69 loc) · 1.81 KB
/
client.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
package main
import (
"encoding/hex"
"fmt"
"io"
"os"
cclient "github.com/eris-ltd/toadserver/Godeps/_workspace/src/github.com/tendermint/tendermint/rpc/core_client"
)
var (
DefaultNodeRPCHost = "0.0.0.0"
DefaultNodeRPCPort = "46657"
DefaultNodeRPCAddr = "http://" + DefaultNodeRPCHost + ":" + DefaultNodeRPCPort
DefaultChainID string
REQUEST_TYPE = "JSONRPC"
client cclient.Client
)
// override the hardcoded defaults with env variables if they're set
func init() {
nodeAddr := os.Getenv("MINTX_NODE_ADDR")
if nodeAddr != "" {
DefaultNodeRPCAddr = nodeAddr
}
chainID := os.Getenv("MINTX_CHAINID")
if chainID != "" {
DefaultChainID = chainID
}
}
func getInfos(fileName string) string {
if fileName == "" {
//to eventually support an endpoint that lists available files
_, err := client.ListNames()
ifExit(err)
//formatOutput(r)
return "" //result of format output
} else {
_, err := client.GetName(fileName)
ifExit(err)
//formatOutput(r)
return "" //result of format output
}
}
//this func is just a check
func checkAddr(addr string, w io.Writer) error {
if addr == "" {
_, err := client.ListAccounts()
ifExit(err)
//formatOutput(r)
return nil //result of format output
} else {
addrBytes, err := hex.DecodeString(addr)
if err != nil {
exit(fmt.Errorf("Addr %s is improper hex: %v", addr, err))
}
r, err := client.GetAccount(addrBytes)
ifExit(err)
if r == nil {
exit(fmt.Errorf("Account %X does not exist", addrBytes))
}
r2 := r.Account
if r2 == nil {
exit(fmt.Errorf("Account %X does not exist", addrBytes))
}
//formatOutput(c, 1, r2)
}
//TODO deal with this gracefully
// w.Write([]byte("Permission denied, invalid address\n"))
return nil //errors.New("Permission denied, invalid address")
//get more infos (like check if they have perms!)
}