github.com/lbryio/lbcd@v0.22.119/rpcclient/examples/bitcoincorehttpbulk/main.go (about) 1 // Copyright (c) 2014-2020 The btcsuite developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "log" 10 11 "github.com/lbryio/lbcd/rpcclient" 12 ) 13 14 func main() { 15 // Connect to local bitcoin core RPC server using HTTP POST mode. 16 connCfg := &rpcclient.ConnConfig{ 17 Host: "localhost:9245", 18 User: "yourrpcuser", 19 Pass: "yourrpcpass", 20 DisableConnectOnNew: true, 21 HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode 22 DisableTLS: true, // Bitcoin core does not provide TLS by default 23 } 24 batchClient, err := rpcclient.NewBatch(connCfg) 25 defer batchClient.Shutdown() 26 27 if err != nil { 28 log.Fatal(err) 29 } 30 31 // batch mode requires async requests 32 blockCount := batchClient.GetBlockCountAsync() 33 block1 := batchClient.GetBlockHashAsync(1) 34 batchClient.GetBlockHashAsync(2) 35 batchClient.GetBlockHashAsync(3) 36 block4 := batchClient.GetBlockHashAsync(4) 37 difficulty := batchClient.GetDifficultyAsync() 38 39 // sends all queued batch requests 40 batchClient.Send() 41 42 fmt.Println(blockCount.Receive()) 43 fmt.Println(block1.Receive()) 44 fmt.Println(block4.Receive()) 45 fmt.Println(difficulty.Receive()) 46 }