本文整理汇总了Golang中github.com/wchh/gocoin/lib/btc.Uint256.BIdx方法的典型用法代码示例。如果您正苦于以下问题:Golang Uint256.BIdx方法的具体用法?Golang Uint256.BIdx怎么用?Golang Uint256.BIdx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/wchh/gocoin/lib/btc.Uint256
的用法示例。
在下文中一共展示了Uint256.BIdx方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RejectTx
// Adds a transaction to the rejected list or not, it it has been mined already
// Make sure to call it with locked TxMutex.
// Returns the OneTxRejected or nil if it has not been added.
func RejectTx(id *btc.Uint256, size int, why byte) *OneTxRejected {
rec := new(OneTxRejected)
rec.Id = id
rec.Time = time.Now()
rec.Size = uint32(size)
rec.Reason = why
TransactionsRejected[id.BIdx()] = rec
TransactionsRejectedSize += uint64(rec.Size)
return rec
}
示例2: txChecker
func txChecker(h *btc.Uint256) bool {
TxMutex.Lock()
rec, ok := TransactionsToSend[h.BIdx()]
TxMutex.Unlock()
if ok && rec.Own != 0 {
return false // Assume own txs as non-trusted
}
if ok {
common.CountSafe("TxScrBoosted")
} else {
common.CountSafe("TxScrMissed")
}
return ok
}
示例3: BlockGet
func (db *BlockDB) BlockGet(hash *btc.Uint256) (bl []byte, trusted bool, e error) {
db.mutex.Lock()
rec, ok := db.blockIndex[hash.BIdx()]
if !ok {
db.mutex.Unlock()
e = errors.New("btc.Block not in the index")
return
}
trusted = rec.trusted
if crec, hit := db.cache[hash.BIdx()]; hit {
bl = crec.data
crec.used = time.Now()
db.mutex.Unlock()
return
}
db.mutex.Unlock()
bl = make([]byte, rec.blen)
// we will re-open the data file, to not spoil the writting pointer
f, e := os.Open(db.dirname + "blockchain.dat")
if e != nil {
return
}
_, e = f.Seek(int64(rec.fpos), os.SEEK_SET)
if e == nil {
_, e = f.Read(bl[:])
}
f.Close()
if rec.compressed {
if rec.snappied {
bl, _ = snappy.Decode(nil, bl)
} else {
gz, _ := gzip.NewReader(bytes.NewReader(bl))
bl, _ = ioutil.ReadAll(gz)
gz.Close()
}
}
db.addToCache(hash, bl)
return
}
示例4: addToCache
func (db *BlockDB) addToCache(h *btc.Uint256, bl []byte) {
if rec, ok := db.cache[h.BIdx()]; ok {
rec.used = time.Now()
return
}
if uint(len(db.cache)) >= MaxCachedBlocks {
var oldest_t time.Time
var oldest_k [btc.Uint256IdxLen]byte
for k, v := range db.cache {
if oldest_t.IsZero() || v.used.Before(oldest_t) {
oldest_t = v.used
oldest_k = k
}
}
delete(db.cache, oldest_k)
}
db.cache[h.BIdx()] = &cacheRecord{used: time.Now(), data: bl}
}
示例5: NeedThisTx
// Return false if we do not want to receive a data for this tx
func NeedThisTx(id *btc.Uint256, cb func()) (res bool) {
TxMutex.Lock()
if _, present := TransactionsToSend[id.BIdx()]; present {
//res = false
} else if _, present := TransactionsRejected[id.BIdx()]; present {
//res = false
} else if _, present := TransactionsPending[id.BIdx()]; present {
//res = false
} else if txo, _ := common.BlockChain.Unspent.UnspentGet(&btc.TxPrevOut{Hash: id.Hash}); txo != nil {
// This assumes that tx's out #0 has not been spent yet, which may not always be the case, but well...
common.CountSafe("TxMinedRejected")
} else {
res = true
if cb != nil {
cb()
}
}
TxMutex.Unlock()
return
}