本文整理匯總了Golang中github.com/FactomProject/btcd/wire.ShaHash.ToFactomHash方法的典型用法代碼示例。如果您正苦於以下問題:Golang ShaHash.ToFactomHash方法的具體用法?Golang ShaHash.ToFactomHash怎麽用?Golang ShaHash.ToFactomHash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/FactomProject/btcd/wire.ShaHash
的用法示例。
在下文中一共展示了ShaHash.ToFactomHash方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FetchBlockHeightBySha
// FetchBlockHeightBySha returns the block height for the given hash. This is
// part of the database.Db interface implementation.
func (db *LevelDb) FetchBlockHeightBySha(sha *wire.ShaHash) (int64, error) {
dblk, _ := db.FetchDBlockByHash(sha.ToFactomHash())
var height int64 = -1
if dblk != nil {
height = int64(dblk.Header.DBHeight)
}
return height, nil
}
示例2: DirBlockLocatorFromHash
// DirBlockLocatorFromHash returns a block locator for the passed block hash.
// See BlockLocator for details on the algotirhm used to create a block locator.
//
// In addition to the general algorithm referenced above, there are a couple of
// special cases which are handled:
//
// - If the genesis hash is passed, there are no previous hashes to add and
// therefore the block locator will only consist of the genesis hash
// - If the passed hash is not currently known, the block locator will only
// consist of the passed hash
func DirBlockLocatorFromHash(hash *wire.ShaHash) blockchain.BlockLocator {
// The locator contains the requested hash at the very least.
locator := make(blockchain.BlockLocator, 0, wire.MaxBlockLocatorsPerMsg)
locator = append(locator, hash)
h, _ := common.HexToHash(common.GENESIS_DIR_BLOCK_HASH)
genesisHash := wire.FactomHashToShaHash(h)
// Nothing more to do if a locator for the genesis hash was requested.
if genesisHash.IsEqual(hash) {
return locator
}
// Attempt to find the height of the block that corresponds to the
// passed hash, and if it's on a side chain, also find the height at
// which it forks from the main chain.
blockHeight := int64(-1)
// Generate the block locators according to the algorithm described in
// in the BlockLocator comment and make sure to leave room for the
// final genesis hash.
dblock, _ := db.FetchDBlockByHash(hash.ToFactomHash())
if dblock != nil {
blockHeight = int64(dblock.Header.DBHeight)
}
increment := int64(1)
for len(locator) < wire.MaxBlockLocatorsPerMsg-1 {
// Once there are 10 locators, exponentially increase the
// distance between each block locator.
if len(locator) > 10 {
increment *= 2
}
blockHeight -= increment
if blockHeight < 1 {
break
}
blk, _ := db.FetchDBlockByHeight(uint32(blockHeight))
if blk == nil {
continue
} else if blk.DBHash == nil {
blk.DBHash, _ = common.CreateHash(blk)
}
locator = append(locator, wire.FactomHashToShaHash(blk.DBHash))
}
// Append the appropriate genesis block.
locator = append(locator, genesisHash)
return locator
}