gitlab.com/aquachain/aquachain@v1.17.16-rc3.0.20221018032414-e3ddf1e1c055/testing/btcrpcclient.go (about)

     1  // +build ignore
     2  
     3  // Copyright 2018 The aquachain Authors
     4  // This file is part of the aquachain library.
     5  //
     6  // The aquachain library is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU Lesser General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // (at your option) any later version.
    10  //
    11  // The aquachain library is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    14  // GNU Lesser General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU Lesser General Public License
    17  // along with the aquachain library. If not, see <http://www.gnu.org/licenses/>.
    18  
    19  package main
    20  
    21  import (
    22  	"context"
    23  	"fmt"
    24  	"log"
    25  
    26  	"gitlab.com/aquachain/aquachain/opt/aquaclient"
    27  	rpc "gitlab.com/aquachain/aquachain/rpc/rpcclient"
    28  
    29  	"github.com/btcsuite/btcd/rpcclient"
    30  )
    31  
    32  func main() {
    33  	// Connect to local bitcoin core RPC server using HTTP POST mode.
    34  	connCfg := &rpcclient.ConnConfig{
    35  		Host: "localhost:8543",
    36  		//		User:         "yourrpcuser",
    37  		//		Pass:         "yourrpcpass",
    38  		HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
    39  		DisableTLS:   true, // Bitcoin core does not provide TLS by default
    40  	}
    41  	rpcc, err := rpc.DialHTTP("http://localhost:8543")
    42  	if err != nil {
    43  		log.Fatal(err)
    44  	}
    45  	aquaclient1 := aquaclient.NewClient(rpcc)
    46  	latest, err := aquaclient1.BlockByNumber(context.Background(), nil)
    47  	if err != nil {
    48  		log.Fatal(err)
    49  	}
    50  	fmt.Println("AQUA:", latest.Number())
    51  
    52  	// Notice the notification parameter is nil since notifications are
    53  	// not supported in HTTP POST mode.
    54  	client, err := rpcclient.New(connCfg, nil)
    55  	if err != nil {
    56  		log.Fatal(err)
    57  	}
    58  	defer client.Shutdown()
    59  
    60  	// Get the current block count.
    61  	blockCount, err := client.GetBlockCount()
    62  	if err != nil {
    63  		log.Fatal(err)
    64  	}
    65  	log.Printf("BTC: %d", blockCount)
    66  }