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


Golang Hash.Bytes方法代碼示例

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


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

示例1: 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
}
開發者ID:6londe,項目名稱:FactomCode,代碼行數:9,代碼來源:dblock.go

示例2: 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
}
開發者ID:FactomProject,項目名稱:FactomCode,代碼行數:17,代碼來源:entry.go

示例3: 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
}
開發者ID:6londe,項目名稱:FactomCode,代碼行數:18,代碼來源:ecblock.go

示例4: validateFBlockByMR

// Validate FBlock by merkle root
func validateFBlockByMR(mr *common.Hash) error {
	b, _ := db.FetchFBlockByHash(mr)

	if b == nil {
		return errors.New("Factoid block not found in db for merkle root: \n" + mr.String())
	}

	// check that we used the KeyMR to store the block...
	if !bytes.Equal(b.GetKeyMR().Bytes(), mr.Bytes()) {
		return fmt.Errorf("Factoid block match failure: block %d \n%s\n%s",
			b.GetDBHeight(),
			"Key in the database:   "+mr.String(),
			"Hash of the blk found: "+b.GetKeyMR().String())
	}

	return nil
}
開發者ID:FactomProject,項目名稱:FactomCode,代碼行數:18,代碼來源:init.go

示例5: 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
}
開發者ID:FactomProject,項目名稱:FactomCode,代碼行數:18,代碼來源:ablock.go

示例6: 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
}
開發者ID:brianharness,項目名稱:FactomCode,代碼行數:18,代碼來源:scblock.go

示例7: 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
}
開發者ID:6londe,項目名稱:FactomCode,代碼行數:19,代碼來源:dblock.go

示例8: 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
}
開發者ID:FactomProject,項目名稱:FactomCode,代碼行數:19,代碼來源:eblock.go

示例9: 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
}
開發者ID:6londe,項目名稱:FactomCode,代碼行數:20,代碼來源:dblock.go

示例10: 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
}
開發者ID:FactomProject,項目名稱:FactomCode,代碼行數:20,代碼來源:eblock.go

示例11: 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
}
開發者ID:FactomProject,項目名稱:FactomCode,代碼行數:20,代碼來源:dblock.go

示例12: FetchChainByHash

// FetchChainByHash gets a chain by chainID
func (db *LevelDb) FetchChainByHash(chainID *common.Hash) (*common.EChain, error) {
	var key []byte = []byte{byte(TBL_CHAIN_HASH)}
	key = append(key, chainID.Bytes()...)
	db.dbLock.RLock()
	data, err := db.lDb.Get(key, db.ro)
	db.dbLock.RUnlock()
	if err != nil {
		return nil, err
	}

	chain := common.NewEChain()
	if data != nil {
		_, err := chain.UnmarshalBinaryData(data)
		if err != nil {
			return nil, err
		}
	}
	return chain, nil
}
開發者ID:FactomProject,項目名稱:FactomCode,代碼行數:20,代碼來源:eblock.go

示例13: doTransaction

func doTransaction(hash *common.Hash, blockHeight uint64, dirBlockInfo *common.DirBlockInfo) (*wire.ShaHash, error) {
	b := balances[0]
	i := copy(balances, balances[1:])
	balances[i] = b

	msgtx, err := createRawTransaction(b, hash.Bytes(), blockHeight)
	if err != nil {
		return nil, fmt.Errorf("cannot create Raw Transaction: %s", err)
	}

	shaHash, err := sendRawTransaction(msgtx)
	if err != nil {
		return nil, fmt.Errorf("cannot send Raw Transaction: %s", err)
	}
	// for test purpose
	if dirBlockInfo != nil {
		dirBlockInfo.BTCTxHash = toHash(shaHash)
	}
	return shaHash, nil
}
開發者ID:jakeporter,項目名稱:FactomCode,代碼行數:20,代碼來源:anchor.go

示例14: doTransaction

func doTransaction(hash *common.Hash, blockHeight uint32, dirBlockInfo *common.DirBlockInfo) (*wire.ShaHash, error) {
	b := balances[0]
	balances = balances[1:]
	anchorLog.Info("new balances.len=", len(balances))

	msgtx, err := createRawTransaction(b, hash.Bytes(), blockHeight)
	if err != nil {
		return nil, fmt.Errorf("cannot create Raw Transaction: %s", err)
	}

	shaHash, err := sendRawTransaction(msgtx)
	if err != nil {
		return nil, fmt.Errorf("cannot send Raw Transaction: %s", err)
	}

	if dirBlockInfo != nil {
		dirBlockInfo.BTCTxHash = toHash(shaHash)
	}

	return shaHash, nil
}
開發者ID:FactomProject,項目名稱:FactomCode,代碼行數:21,代碼來源:anchor.go

示例15: FetchAllEBlocksByChain

// FetchAllEBlocksByChain gets all of the blocks by chain id
func (db *LevelDb) FetchAllEBlocksByChain(chainID *common.Hash) (eBlocks *[]common.EBlock, err error) {
	db.dbLock.RLock()
	defer db.dbLock.RUnlock()

	var fromkey []byte = []byte{byte(TBL_EB_CHAIN_NUM)} // Table Name (1 bytes)
	fromkey = append(fromkey, chainID.Bytes()...)       // Chain Type (32 bytes)
	var tokey []byte = addOneToByteArray(fromkey)

	eBlockSlice := make([]common.EBlock, 0, 10)

	iter := db.lDb.NewIterator(&util.Range{Start: fromkey, Limit: tokey}, db.ro)

	for iter.Next() {
		eBlockHash := common.NewHash()
		_, err := eBlockHash.UnmarshalBinaryData(iter.Value())
		if err != nil {
			return nil, err
		}

		var key []byte = []byte{byte(TBL_EB)}
		key = append(key, eBlockHash.Bytes()...)
		data, err := db.lDb.Get(key, db.ro)
		if err != nil {
			return nil, err
		}

		eBlock := common.NewEBlock()
		if data != nil {
			_, err := eBlock.UnmarshalBinaryData(data)
			if err != nil {
				return nil, err
			}
			eBlockSlice = append(eBlockSlice, *eBlock)
		}
	}
	iter.Release()
	err = iter.Error()

	return &eBlockSlice, nil
}
開發者ID:FactomProject,項目名稱:FactomCode,代碼行數:41,代碼來源:eblock.go


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