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

     1  package main
     2  
     3  import (
     4  	"encoding/binary"
     5  	"fmt"
     6  	"github.com/piotrnar/gocoin/lib/btc"
     7  	"io"
     8  	"os"
     9  )
    10  
    11  func main() {
    12  	var buf [48]byte
    13  	if len(os.Args) != 2 {
    14  		fmt.Println("Specify the filename containing UTXO database")
    15  		return
    16  	}
    17  	f, er := os.Open(os.Args[1])
    18  	if er != nil {
    19  		fmt.Println(er.Error())
    20  		return
    21  	}
    22  	_, er = io.ReadFull(f, buf[:])
    23  	f.Close()
    24  	if er != nil {
    25  		fmt.Println(er.Error())
    26  		return
    27  	}
    28  	u64 := binary.LittleEndian.Uint64(buf[:8])
    29  	if (u64 & 0x8000000000000000) != 0 {
    30  		fmt.Println("Records: Compressed")
    31  	} else {
    32  		fmt.Println("Records: Not compressed")
    33  	}
    34  	fmt.Println("Last Block Height:", uint32(u64))
    35  	fmt.Println("Last Block Hash:", btc.NewUint256(buf[8:40]).String())
    36  	fmt.Println("Number of UTXO records:", binary.LittleEndian.Uint64(buf[40:48]))
    37  }