-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
72 lines (58 loc) · 1.37 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
package main
import (
"fmt"
"log"
"net/http"
"time"
"github.com/go-ShardingBlockchain/httpjsonrpc"
)
func getInfo(req *http.Request, cmd map[string]interface{}) map[string]interface{} {
id := cmd["id"].(float64)
fmt.Println(id)
params := cmd["params"]
fmt.Println(params)
if cmd == nil {
cmd = make(map[string]interface{})
}
return cmd
}
func init() {
go start_server()
}
func sendToAddress(req *http.Request, cmd map[string]interface{}) map[string]interface{} {
return cmd
}
func start_server() {
print("hello start server\n")
httpjsonrpc.InitServeMux()
http.HandleFunc("/", httpjsonrpc.Handle)
httpjsonrpc.HandleFunc("getinfo", getInfo)
httpjsonrpc.HandleFunc("sendtoaddress", sendToAddress)
err := http.ListenAndServe("localhost:10332", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err.Error())
}
}
func start_client() {
var res map[string]interface{}
var err error
print("start client\n")
res, err = httpjsonrpc.Call("http://127.0.0.1:10332", "getinfo", 1, []interface{}{})
if err != nil {
log.Fatalf("Err:%v", err)
}
log.Println(res)
/*
// call send to address
params := []interface{}{"asset_id", "address", 56}
res, err = httpjsonrpc.Call("http://127.0.0.1:10332", "sendtoaddress", 2, params)
if err != nil {
log.Fatalf("Err: %v", err)
}
log.Println(res)
*/
}
func main() {
time.Sleep(2 * time.Second)
start_client()
}