github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/tools/fetchblock/fetchblock.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/piotrnar/gocoin/lib/btc"
     6  	"io/ioutil"
     7  	"github.com/piotrnar/gocoin/lib/others/utils"
     8  	"github.com/piotrnar/gocoin"
     9  	"os"
    10  )
    11  
    12  
    13  func main() {
    14  	fmt.Println("Gocoin FetchBlock version", gocoin.Version)
    15  
    16  	if len(os.Args) < 2 {
    17  		fmt.Println("Specify block hash on the command line (MSB).")
    18  		return
    19  	}
    20  
    21  	hash := btc.NewUint256FromString(os.Args[1])
    22  	bl := utils.GetBlockFromWeb(hash)
    23  	if bl==nil {
    24  		fmt.Println("Error fetching the block")
    25  	} else {
    26  		ioutil.WriteFile(bl.Hash.String()+".bin", bl.Raw, 0666)
    27  	}
    28  }