package main import ( "github.com/decred/dcrutil" "log" ) func main() { hashStr := "00000000000001d5e32d4b128b32ea40b189befe1a108cd32a3cfa542f7e03cf" blockHash, err := dcrutil.NewHashFromStr(hashStr) if err != nil { log.Fatalf("Failed to create hash from %s: %v", hashStr, err) } blockHeight := dcrutil.GetBlockHeight(blockHash) log.Printf("Block height of block %s is %d", hashStr, blockHeight) }
package main import ( "github.com/decred/dcrutil" "log" ) func main() { blockHeight := int64(500000) blockHash, err := dcrutil.BlockHeightToHash(blockHeight) if err != nil { log.Fatalf("Failed to convert block height %d to hash: %v", blockHeight, err) } log.Printf("Block hash of block height %d is %s", blockHeight, blockHash.String()) }This example demonstrates how to convert a block height to its corresponding hash. The `BlockHeightToHash` function takes an integer as input and returns a `Hash` type from the same library as output. The `blockHeight` variable is set to 500,000 for demonstration purposes.