本文整理汇总了Golang中github.com/wchh/gocoin/lib/btc.Uint256.Equal方法的典型用法代码示例。如果您正苦于以下问题:Golang Uint256.Equal方法的具体用法?Golang Uint256.Equal怎么用?Golang Uint256.Equal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/wchh/gocoin/lib/btc.Uint256
的用法示例。
在下文中一共展示了Uint256.Equal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetTxFromWeb
// Download raw transaction from a web server (try one after another)
func GetTxFromWeb(txid *btc.Uint256) (raw []byte) {
raw = GetTxFromWebBTC(txid)
if raw != nil && txid.Equal(btc.NewSha2Hash(raw)) {
println("GetTxFromWebBTC - OK")
return
}
raw = GetTxFromBlockrIo(txid)
if raw != nil && txid.Equal(btc.NewSha2Hash(raw)) {
println("GetTxFromBlockrIo - OK")
return
}
raw, _ = GetTxFromExplorer(txid)
if raw != nil && txid.Equal(btc.NewSha2Hash(raw)) {
println("GetTxFromExplorer - OK")
return
}
return
}
示例2: main
func main() {
if len(os.Args) < 2 {
fmt.Println("Specify a path to folder containig blockchain.dat and blockchain.new")
fmt.Println("Output bootstrap.dat file will be written in the current folder.")
return
}
blks := chain.NewBlockDB(os.Args[1])
if blks == nil {
return
}
fmt.Println("Loading block index...")
bidx = make(map[[32]byte]*chain.BlockTreeNode, 300e3)
blks.LoadBlockIndex(nil, walk)
var tail, nd *chain.BlockTreeNode
var genesis_block_hash *btc.Uint256
for _, v := range bidx {
if v == tail {
// skip root block (should be only one)
continue
}
par_hash := btc.NewUint256(v.BlockHeader[4:36])
par, ok := bidx[par_hash.Hash]
if !ok {
genesis_block_hash = par_hash
} else {
v.Parent = par
if tail == nil || v.Height > tail.Height {
tail = v
}
}
}
if genesis_block_hash == nil {
println("genesis_block_hash not found")
return
}
var magic []byte
gen_bin, _ := hex.DecodeString(GenesisBitcoin)
tmp := btc.NewSha2Hash(gen_bin[:80])
if genesis_block_hash.Equal(tmp) {
println("Bitcoin genesis block")
magic = []byte{0xF9, 0xBE, 0xB4, 0xD9}
}
if magic == nil {
gen_bin, _ := hex.DecodeString(GenesisTestnet)
tmp = btc.NewSha2Hash(gen_bin[:80])
if genesis_block_hash.Equal(tmp) {
println("Testnet3 genesis block")
magic = []byte{0x0B, 0x11, 0x09, 0x07}
}
}
if magic == nil {
println("Unknow genesis block", genesis_block_hash.String())
println("Aborting since cannot figure out the magic bytes")
return
}
var total_data, curr_data int64
for nd = tail; nd.Parent != nil; {
nd.Parent.Childs = []*chain.BlockTreeNode{nd}
total_data += int64(nd.BlockSize)
nd = nd.Parent
}
fmt.Println("Writting bootstrap.dat, height", tail.Height, " magic", hex.EncodeToString(magic))
f, _ := os.Create("bootstrap.dat")
f.Write(magic)
binary.Write(f, binary.LittleEndian, uint32(len(gen_bin)))
f.Write(gen_bin)
for {
bl, _, _ := blks.BlockGet(nd.BlockHash)
f.Write(magic)
binary.Write(f, binary.LittleEndian, uint32(len(bl)))
f.Write(bl)
curr_data += int64(nd.BlockSize)
if (nd.Height & 0xfff) == 0 {
fmt.Printf("\r%.1f%%...", 100*float64(curr_data)/float64(total_data))
}
if len(nd.Childs) == 0 {
break
}
nd = nd.Childs[0]
}
fmt.Println("\rDone ")
}