當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Database.Get方法代碼示例

本文整理匯總了Golang中github.com/ethereum/go-ethereum/common.Database.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang Database.Get方法的具體用法?Golang Database.Get怎麽用?Golang Database.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/ethereum/go-ethereum/common.Database的用法示例。


在下文中一共展示了Database.Get方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewStateObjectFromBytes

func NewStateObjectFromBytes(address common.Address, data []byte, db common.Database) *StateObject {
	// TODO clean me up
	var extobject struct {
		Nonce    uint64
		Balance  *big.Int
		Root     common.Hash
		CodeHash []byte
	}
	err := rlp.Decode(bytes.NewReader(data), &extobject)
	if err != nil {
		fmt.Println(err)
		return nil
	}

	object := &StateObject{address: address, db: db}
	object.nonce = extobject.Nonce
	object.balance = extobject.Balance
	object.codeHash = extobject.CodeHash
	object.trie = trie.NewSecure(extobject.Root[:], db)
	object.storage = make(map[string]common.Hash)
	object.gasPool = new(big.Int)
	object.prepaid = new(big.Int)
	object.code, _ = db.Get(extobject.CodeHash)

	return object
}
開發者ID:ssonneborn22,項目名稱:go-ethereum,代碼行數:26,代碼來源:state_object.go

示例2: saveProtocolVersion

func saveProtocolVersion(db common.Database, protov int) {
	d, _ := db.Get([]byte("ProtocolVersion"))
	protocolVersion := common.NewValue(d).Uint()

	if protocolVersion == 0 {
		db.Put([]byte("ProtocolVersion"), common.NewValue(protov).Bytes())
	}
}
開發者ID:hiroshi1tanaka,項目名稱:gethkey,代碼行數:8,代碼來源:backend.go

示例3: saveBlockchainVersion

func saveBlockchainVersion(db common.Database, bcVersion int) {
	d, _ := db.Get([]byte("BlockchainVersion"))
	blockchainVersion := common.NewValue(d).Uint()

	if blockchainVersion == 0 {
		db.Put([]byte("BlockchainVersion"), common.NewValue(bcVersion).Bytes())
	}
}
開發者ID:hiroshi1tanaka,項目名稱:gethkey,代碼行數:8,代碼來源:backend.go

示例4: GetBlockByNumber

// GetBlockByHash returns the canonical block by number or nil if not found
func GetBlockByNumber(db common.Database, number uint64) *types.Block {
	key, _ := db.Get(append(blockNumPre, big.NewInt(int64(number)).Bytes()...))
	if len(key) == 0 {
		return nil
	}

	return GetBlockByHash(db, common.BytesToHash(key))
}
開發者ID:RepublicMaster,項目名稱:go-ethereum,代碼行數:9,代碼來源:chain_util.go

示例5: getBlockReceipts

func getBlockReceipts(db common.Database, bhash common.Hash) (receipts types.Receipts, err error) {
	var rdata []byte
	rdata, err = db.Get(append(receiptsPre, bhash[:]...))

	if err == nil {
		err = rlp.DecodeBytes(rdata, &receipts)
	} else {
		glog.V(logger.Detail).Infof("getBlockReceipts error %v\n", err)
	}
	return
}
開發者ID:haegyung,項目名稱:go-ethereum,代碼行數:11,代碼來源:block_processor.go

示例6: GetBlockByHash

// GetBlockByHash returns the block corresponding to the hash or nil if not found
func GetBlockByHash(db common.Database, hash common.Hash) *types.Block {
	data, _ := db.Get(append(blockHashPre, hash[:]...))
	if len(data) == 0 {
		return nil
	}
	var block types.StorageBlock
	if err := rlp.Decode(bytes.NewReader(data), &block); err != nil {
		glog.V(logger.Error).Infof("invalid block RLP for hash %x: %v", hash, err)
		return nil
	}
	return (*types.Block)(&block)
}
開發者ID:RepublicMaster,項目名稱:go-ethereum,代碼行數:13,代碼來源:chain_util.go

示例7: GetBlockReceipts

// GetBlockReceipts returns the receipts generated by the transactions
// included in block's given hash.
func GetBlockReceipts(db common.Database, hash common.Hash) types.Receipts {
	data, _ := db.Get(append(blockReceiptsPre, hash[:]...))
	if len(data) == 0 {
		return nil
	}

	var receipts types.Receipts
	err := rlp.DecodeBytes(data, &receipts)
	if err != nil {
		glog.V(logger.Core).Infoln("GetReceiptse err", err)
	}
	return receipts
}
開發者ID:nellyk,項目名稱:go-ethereum,代碼行數:15,代碼來源:transaction_util.go

示例8: GetReceipt

// GetReceipt returns a receipt by hash
func GetReceipt(db common.Database, txHash common.Hash) *types.Receipt {
	data, _ := db.Get(append(receiptsPre, txHash[:]...))
	if len(data) == 0 {
		return nil
	}

	var receipt types.Receipt
	err := rlp.DecodeBytes(data, &receipt)
	if err != nil {
		glog.V(logger.Core).Infoln("GetReceipt err:", err)
	}
	return &receipt
}
開發者ID:nellyk,項目名稱:go-ethereum,代碼行數:14,代碼來源:transaction_util.go


注:本文中的github.com/ethereum/go-ethereum/common.Database.Get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。