-
Notifications
You must be signed in to change notification settings - Fork 86
/
main.go
65 lines (55 loc) · 1.52 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
package main
import (
"flag"
"fmt"
"os"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/rpcclient"
)
var host = flag.String("host", "127.0.0.1:8332", "node RPC host:port")
var user = flag.String("user", "", "node RPC username")
var pass = flag.String("pass", "", "node RPC password")
func main() {
os.Exit(mainCore())
}
func mainCore() int {
flag.Parse()
client, err := rpcclient.New(&rpcclient.ConnConfig{
HTTPPostMode: true,
DisableTLS: true,
Host: *host,
User: *user,
Pass: *pass,
}, nil)
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: Unable to connect to RPC server: %v\n", err)
return 1
}
defer client.Shutdown()
infoResult, err := client.GetNetworkInfo()
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: GetInfo failed: %v\n", err)
return 1
}
fmt.Printf("Node connection count: %d\n", infoResult.Connections)
hash, err := client.GetBestBlockHash()
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: GetBestBlockHash failed: %v\n", err)
return 2
}
hdr, err := client.GetBlockHeaderVerbose(hash)
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: GetBestBlockHash failed: %v\n", err)
return 2
}
fmt.Println(hdr.Height, hash)
// block with tx with big witness item that fails for old btcd/wire
bigBlockHash, _ := chainhash.NewHashFromStr("0000000000000000000400a35a007e223a7fb8a622dc7b5aa5eaace6824291fb")
msgBlock, err := client.GetBlock(bigBlockHash)
if err != nil {
fmt.Println(err)
return 1
}
fmt.Println(msgBlock.BlockHash())
return 0
}