本文整理匯總了Golang中github.com/niniwzw/gocoin/lib/btc.Uint256.Equal方法的典型用法代碼示例。如果您正苦於以下問題:Golang Uint256.Equal方法的具體用法?Golang Uint256.Equal怎麽用?Golang Uint256.Equal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/niniwzw/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 ")
}