本文整理匯總了Golang中github.com/FactomProject/FactomCode/common.Hash類的典型用法代碼示例。如果您正苦於以下問題:Golang Hash類的具體用法?Golang Hash怎麽用?Golang Hash使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Hash類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sanityCheck
func sanityCheck(hash *common.Hash) (*common.DirBlockInfo, error) {
dirBlockInfo := dirBlockInfoMap[hash.String()]
if dirBlockInfo == nil {
s := fmt.Sprintf("Anchor Error: hash %s does not exist in dirBlockInfoMap.\n", hash.String())
anchorLog.Error(s)
return nil, errors.New(s)
}
if dirBlockInfo.BTCConfirmed {
s := fmt.Sprintf("Anchor Warning: hash %s has already been confirmed in btc block chain.\n", hash.String())
anchorLog.Error(s)
return nil, errors.New(s)
}
//The re-anchoring is allowed now.
//if !common.NewHash().IsSameAs(dirBlockInfo.BTCTxHash) {
//s := fmt.Sprintf("Anchor Warning: hash %s has already been anchored but not confirmed. btc tx hash is %s\n", hash.String(), dirBlockInfo.BTCTxHash.String())
//anchorLog.Error(s)
//return nil, errors.New(s)
//}
if dclient == nil || wclient == nil {
s := fmt.Sprintf("\n\n$$$ WARNING: rpc clients and/or wallet are not initiated successfully. No anchoring for now.\n")
anchorLog.Warning(s)
return nil, errors.New(s)
}
if len(balances) == 0 {
anchorLog.Warning("len(balances) == 0, start rescan UTXO *** ")
updateUTXO()
}
if len(balances) == 0 {
s := fmt.Sprintf("\n\n$$$ WARNING: No balance in your wallet. No anchoring for now.\n")
anchorLog.Warning(s)
return nil, errors.New(s)
}
return dirBlockInfo, nil
}
示例2: HaveBlockInDB
// HaveBlockInDB returns whether or not the chain instance has the block represented
// by the passed hash. This includes checking the various places a block can
// be like part of the main chain, on a side chain, or in the orphan pool.
//
// This function is NOT safe for concurrent access.
func HaveBlockInDB(hash *common.Hash) (bool, error) {
//util.Trace(spew.Sdump(hash))
blk, _ := db.FetchDBlockByHash(hash)
if blk != nil {
fmt.Println("HaveBlockInDB. true. ", hash.BTCString())
return true, nil
}
return false, nil
/*
if hash == nil || dchain.Blocks == nil || len(dchain.Blocks) == 0 {
return false, nil
}
// double check the block ids
for i := 0; i < len(dchain.Blocks); i = i + 1 {
if dchain.Blocks[i] == nil {
continue
}
if dchain.Blocks[i].DBHash == nil {
dchain.Blocks[i].DBHash, _ = common.CreateHash(dchain.Blocks[i])
}
if dchain.Blocks[i].DBHash.IsSameAs(hash) {
return true, nil
}
}
return false, nil */
}
示例3: SendRawTransactionToBTC
// SendRawTransactionToBTC is the main function used to anchor factom
// dir block hash to bitcoin blockchain
func SendRawTransactionToBTC(hash *common.Hash, blockHeight uint32) (*wire.ShaHash, error) {
anchorLog.Debug("SendRawTransactionToBTC: hash=", hash.String(), ", dir block height=", blockHeight) //strconv.FormatUint(blockHeight, 10))
dirBlockInfo, err := sanityCheck(hash)
if err != nil {
return nil, err
}
return doTransaction(hash, blockHeight, dirBlockInfo)
}
示例4: UpdateBlockHeightCache
// UpdateBlockHeightCache updates the dir block height cache in db
func (db *LevelDb) UpdateBlockHeightCache(dirBlkHeigh uint32, dirBlkHash *common.Hash) error {
// Update DirBlock Height cache
db.lastDirBlkHeight = int64(dirBlkHeigh)
db.lastDirBlkSha, _ = wire.NewShaHash(dirBlkHash.Bytes())
db.lastDirBlkShaCached = true
return nil
}
示例5: validateABlockByMR
// Validate Admin Block by merkle root
func validateABlockByMR(mr *common.Hash) error {
b, _ := db.FetchABlockByHash(mr)
if b == nil {
return errors.New("Admin block not found in db for merkle root: " + mr.String())
}
return nil
}
示例6: validateCBlockByMR
// Validate Entry Credit Block by merkle root
func validateCBlockByMR(mr *common.Hash) error {
cb, _ := db.FetchECBlockByHash(mr)
if cb == nil {
return errors.New("Entry Credit block not found in db for merkle root: " + mr.String())
}
return nil
}
示例7: FetchEntryByHash
// FetchEntry gets an entry by hash from the database.
func (db *LevelDb) FetchEntryByHash(entrySha *common.Hash) (entry *common.Entry, err error) {
var key []byte = []byte{byte(TBL_ENTRY)}
key = append(key, entrySha.Bytes()...)
db.dbLock.RLock()
data, err := db.lDb.Get(key, db.ro)
db.dbLock.RUnlock()
if data != nil {
entry = new(common.Entry)
_, err := entry.UnmarshalBinaryData(data)
if err != nil {
return nil, err
}
}
return entry, nil
}
示例8: FetchECBlockByHash
// FetchECBlockByHash gets an Entry Credit block by hash from the database.
func (db *LevelDb) FetchECBlockByHash(ecBlockHash *common.Hash) (ecBlock *common.ECBlock, err error) {
db.dbLock.Lock()
defer db.dbLock.Unlock()
var key []byte = []byte{byte(TBL_CB)}
key = append(key, ecBlockHash.Bytes()...)
data, err := db.lDb.Get(key, db.ro)
if data != nil {
ecBlock = common.NewECBlock()
_, err := ecBlock.UnmarshalBinaryData(data)
if err != nil {
return nil, err
}
}
return ecBlock, nil
}
示例9: FetchFBlockByHash
// FetchFBlockByHash gets an factoid block by hash from the database.
func (db *LevelDb) FetchFBlockByHash(hash *common.Hash) (FBlock block.IFBlock, err error) {
db.dbLock.Lock()
defer db.dbLock.Unlock()
var key []byte = []byte{byte(TBL_SC)}
key = append(key, hash.Bytes()...)
data, err := db.lDb.Get(key, db.ro)
if data != nil {
FBlock = new(block.FBlock)
_, err := FBlock.UnmarshalBinaryData(data)
if err != nil {
return nil, err
}
}
return FBlock, nil
}
示例10: FetchABlockByHash
// FetchABlockByHash gets an admin block by hash from the database.
func (db *LevelDb) FetchABlockByHash(aBlockHash *common.Hash) (aBlock *common.AdminBlock, err error) {
var key = []byte{byte(TBL_AB)}
key = append(key, aBlockHash.Bytes()...)
var data []byte
db.dbLock.RLock()
data, err = db.lDb.Get(key, db.ro)
db.dbLock.RUnlock()
if data != nil {
aBlock = new(common.AdminBlock)
_, err := aBlock.UnmarshalBinaryData(data)
if err != nil {
return nil, err
}
}
return aBlock, nil
}
示例11: FetchDirBlockInfoByHash
// FetchDirBlockInfoByHash gets an DirBlockInfo obj
func (db *LevelDb) FetchDirBlockInfoByHash(dbHash *common.Hash) (dirBlockInfo *common.DirBlockInfo, err error) {
db.dbLock.Lock()
defer db.dbLock.Unlock()
var key []byte = []byte{byte(TBL_DB_INFO)}
key = append(key, dbHash.Bytes()...)
data, err := db.lDb.Get(key, db.ro)
if data != nil {
dirBlockInfo = new(common.DirBlockInfo)
_, err := dirBlockInfo.UnmarshalBinaryData(data)
if err != nil {
return nil, err
}
}
return dirBlockInfo, nil
}
示例12: FetchEBHashByMR
// FetchEBHashByMR gets an entry by hash from the database.
func (db *LevelDb) FetchEBHashByMR(eBMR *common.Hash) (*common.Hash, error) {
var key []byte = []byte{byte(TBL_EB_MR)}
key = append(key, eBMR.Bytes()...)
db.dbLock.RLock()
data, err := db.lDb.Get(key, db.ro)
db.dbLock.RUnlock()
if err != nil {
return nil, err
}
eBlockHash := common.NewHash()
_, err = eBlockHash.UnmarshalBinaryData(data)
if err != nil {
return nil, err
}
return eBlockHash, nil
}
示例13: FetchDBHashByMR
// FetchDBHashByMR gets a DBHash by MR from the database.
func (db *LevelDb) FetchDBHashByMR(dBMR *common.Hash) (*common.Hash, error) {
db.dbLock.Lock()
defer db.dbLock.Unlock()
var key []byte = []byte{byte(TBL_DB_MR)}
key = append(key, dBMR.Bytes()...)
data, err := db.lDb.Get(key, db.ro)
if err != nil {
return nil, err
}
dBlockHash := common.NewHash()
_, err = dBlockHash.UnmarshalBinaryData(data)
if err != nil {
return nil, err
}
return dBlockHash, nil
}
示例14: FetchEBlockByHash
// FetchEntryBlock gets an entry by hash from the database.
func (db *LevelDb) FetchEBlockByHash(eBlockHash *common.Hash) (*common.EBlock, error) {
var key []byte = []byte{byte(TBL_EB)}
key = append(key, eBlockHash.Bytes()...)
db.dbLock.RLock()
data, err := db.lDb.Get(key, db.ro)
db.dbLock.RUnlock()
if err != nil {
return nil, err
}
eBlock := common.NewEBlock()
if data != nil {
_, err := eBlock.UnmarshalBinaryData(data)
if err != nil {
return nil, err
}
}
return eBlock, nil
}
示例15: FetchDBlockByHash
// FetchDBlockByHash gets an entry by hash from the database.
func (db *LevelDb) FetchDBlockByHash(dBlockHash *common.Hash) (*common.DirectoryBlock, error) {
var key = []byte{byte(TBL_DB)}
key = append(key, dBlockHash.Bytes()...)
db.dbLock.RLock()
data, _ := db.lDb.Get(key, db.ro)
db.dbLock.RUnlock()
dBlock := common.NewDBlock()
if data == nil {
return nil, errors.New("DBlock not found for Hash: " + dBlockHash.String())
}
_, err := dBlock.UnmarshalBinaryData(data)
if err != nil {
return nil, err
}
dBlock.DBHash = dBlockHash
return dBlock, nil
}