当前位置: 首页>>代码示例>>Golang>>正文


Golang Uint256.BIdx方法代码示例

本文整理汇总了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
}
开发者ID:wchh,项目名称:gocoin,代码行数:13,代码来源:txpool.go

示例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
}
开发者ID:wchh,项目名称:gocoin,代码行数:14,代码来源:txpool.go

示例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
}
开发者ID:wchh,项目名称:gocoin,代码行数:46,代码来源:blockdb.go

示例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}
}
开发者ID:wchh,项目名称:gocoin,代码行数:18,代码来源:blockdb.go

示例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
}
开发者ID:wchh,项目名称:gocoin,代码行数:21,代码来源:txpool.go


注:本文中的github.com/wchh/gocoin/lib/btc.Uint256.BIdx方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。