本文整理汇总了Golang中github.com/piotrnar/gocoin/btc.Block.Trusted方法的典型用法代码示例。如果您正苦于以下问题:Golang Block.Trusted方法的具体用法?Golang Block.Trusted怎么用?Golang Block.Trusted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/piotrnar/gocoin/btc.Block
的用法示例。
在下文中一共展示了Block.Trusted方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: get_blocks
func get_blocks() {
var bl *btc.Block
BlocksInProgress = make(map[[32]byte]*one_bip)
BlocksCached = make(map[uint32]*btc.Block)
//fmt.Println("opening connections")
DlStartTime = time.Now()
BlocksComplete = TheBlockChain.BlockTreeEnd.Height
BlocksIndex = BlocksComplete
SetDoBlocks(true)
ct := time.Now().Unix()
lastdrop := ct
laststat := ct
TheBlockChain.DoNotSync = true
var blks2do []*btc.Block
for GetDoBlocks() {
BlocksMutex.Lock()
if BlocksComplete >= LastBlockHeight {
BlocksMutex.Unlock()
break
}
for {
bl = BlocksCached[BlocksComplete+1]
if bl == nil {
break
}
BlocksComplete++
if BlocksComplete > BlocksIndex {
BlocksIndex = BlocksComplete
}
bl.Trusted = BlocksComplete <= TrustUpTo
if OnlyStoreBlocks {
TheBlockChain.Blocks.BlockAdd(BlocksComplete, bl)
} else {
blks2do = append(blks2do, bl)
}
atomic.AddUint64(&DlBytesProcesses, uint64(len(bl.Raw)))
delete(BlocksCached, BlocksComplete)
BlocksCachedSize -= uint(len(bl.Raw))
}
BlocksMutex.Unlock()
if len(blks2do) > 0 {
for idx := range blks2do {
er, _, _ := TheBlockChain.CheckBlock(blks2do[idx])
if er != nil {
fmt.Println(er.Error())
return
}
blks2do[idx].LastKnownHeight = BlocksComplete
TheBlockChain.AcceptBlock(blks2do[idx])
}
blks2do = nil
} else {
TheBlockChain.Unspent.Idle()
COUNTER("IDLE")
}
time.Sleep(1e8)
ct = time.Now().Unix()
if open_connection_count() > MaxNetworkConns {
drop_slowest_peers()
} else {
// drop slowest peers once for awhile
occ := MaxNetworkConns
if occ > 0 {
occ = 1200 / occ // For 20 open connections: drop one per minute
if occ < 3 {
occ = 3 // .. drop not more often then once sper 3 seconds
}
if ct-lastdrop > int64(occ) {
lastdrop = ct
drop_slowest_peers()
}
}
}
add_new_connections()
if ct-laststat >= 5 {
laststat = ct
print_stats()
usif_prompt()
}
}
}
示例2: import_blockchain
func import_blockchain(dir string) {
trust := !textui.AskYesNo("Do you want to verify scripts while importing (will be slow)?")
BlockDatabase := blockdb.NewBlockDB(dir, common.Magic)
chain := btc.NewChain(common.GocoinHomeDir, common.GenesisBlock, false)
var bl *btc.Block
var er error
var dat []byte
var totbytes, perbytes uint64
chain.DoNotSync = true
fmt.Println("Be patient while importing Satoshi's database... ")
start := time.Now().UnixNano()
prv := start
for {
now := time.Now().UnixNano()
if now-prv >= 10e9 {
stat(now-start, now-prv, totbytes, perbytes, chain.BlockTreeEnd.Height)
prv = now // show progress each 10 seconds
perbytes = 0
}
dat, er = BlockDatabase.FetchNextBlock()
if dat == nil || er != nil {
println("END of DB file")
break
}
bl, er = btc.NewBlock(dat[:])
if er != nil {
println("Block inconsistent:", er.Error())
break
}
bl.Trusted = trust
er, _, _ = chain.CheckBlock(bl)
if er != nil {
if er.Error() != "Genesis" {
println("CheckBlock failed:", er.Error())
//os.Exit(1) // Such a thing should not happen, so let's better abort here.
}
continue
}
er = chain.AcceptBlock(bl)
if er != nil {
println("AcceptBlock failed:", er.Error())
//os.Exit(1) // Such a thing should not happen, so let's better abort here.
}
totbytes += uint64(len(bl.Raw))
perbytes += uint64(len(bl.Raw))
}
stop := time.Now().UnixNano()
stat(stop-start, stop-prv, totbytes, perbytes, chain.BlockTreeEnd.Height)
fmt.Println("Satoshi's database import finished in", (stop-start)/1e9, "seconds")
fmt.Println("Now saving the new database...")
chain.Sync()
chain.Save()
chain.Close()
fmt.Println("Database saved. No more imports should be needed.")
fmt.Println("It is advised to close and restart the node now, to free some mem.")
}
示例3: import_blockchain
func import_blockchain(dir string) {
trust := !ask_yes_no("Go you want to verify scripts while importing (will be slow)?")
BlockDatabase := blockdb.NewBlockDB(dir, Magic)
chain := btc.NewChain(GocoinHomeDir, GenesisBlock, false)
var bl *btc.Block
var er error
var dat []byte
var totbytes uint64
chain.DoNotSync = true
fmt.Println("Be patient while importing Satoshi's database... ")
start := time.Now().UnixNano()
prv := start
for {
now := time.Now().UnixNano()
if now-prv >= 10e9 {
prv = now // show progress each 10 seconds
stat(now-start, totbytes, chain.BlockTreeEnd.Height)
}
dat, er = BlockDatabase.FetchNextBlock()
if dat == nil || er != nil {
println("END of DB file")
break
}
bl, er = btc.NewBlock(dat[:])
if er != nil {
println("Block inconsistent:", er.Error())
break
}
bl.Trusted = trust
er, _, _ = chain.CheckBlock(bl)
if er != nil {
println("CheckBlock failed:", er.Error())
continue
}
er = chain.AcceptBlock(bl)
if er != nil {
println("AcceptBlock failed:", er.Error())
continue
}
totbytes += uint64(len(bl.Raw))
}
stop := time.Now().UnixNano()
stat(stop-start, totbytes, chain.BlockTreeEnd.Height)
fmt.Println("Satoshi's database import finished in", (stop-start)/1e9, "seconds")
fmt.Println("Now saving the new database...")
chain.Sync()
chain.Close()
fmt.Println("Database saved. No more imports should be needed.")
}