2020-12-06 04:39:40 +01:00
|
|
|
// 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"
|
|
|
|
|
2021-10-15 07:45:32 +02:00
|
|
|
"github.com/lbryio/lbcd/rpcclient"
|
2020-12-06 04:39:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Connect to local bitcoin core RPC server using HTTP POST mode.
|
|
|
|
connCfg := &rpcclient.ConnConfig{
|
2018-08-15 02:59:48 +02:00
|
|
|
Host: "localhost:9245",
|
2020-12-06 04:39:40 +01:00
|
|
|
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())
|
|
|
|
}
|