forked from btcsuite/btcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (38 loc) · 1.22 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
// Copyright (c) 2014-2020 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"log"
"github.com/DlricezZ/doged/rpcclient"
)
func main() {
// Connect to local bitcoin core RPC server using HTTP POST mode.
connCfg := &rpcclient.ConnConfig{
Host: "localhost:8332",
User: "yourrpcuser",
Pass: "yourrpcpass",
DisableConnectOnNew: true,
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
DisableTLS: true, // Bitcoin core does not provide TLS by default
}
batchClient, err := rpcclient.NewBatch(connCfg)
defer batchClient.Shutdown()
if err != nil {
log.Fatal(err)
}
// batch mode requires async requests
blockCount := batchClient.GetBlockCountAsync()
block1 := batchClient.GetBlockHashAsync(1)
batchClient.GetBlockHashAsync(2)
batchClient.GetBlockHashAsync(3)
block4 := batchClient.GetBlockHashAsync(4)
difficulty := batchClient.GetDifficultyAsync()
// sends all queued batch requests
batchClient.Send()
fmt.Println(blockCount.Receive())
fmt.Println(block1.Receive())
fmt.Println(block4.Receive())
fmt.Println(difficulty.Receive())
}