本文整理匯總了Golang中github.com/FactomProject/factomd/common/interfaces.DBOverlay.FetchDBlock方法的典型用法代碼示例。如果您正苦於以下問題:Golang DBOverlay.FetchDBlock方法的具體用法?Golang DBOverlay.FetchDBlock怎麽用?Golang DBOverlay.FetchDBlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/FactomProject/factomd/common/interfaces.DBOverlay
的用法示例。
在下文中一共展示了DBOverlay.FetchDBlock方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FetchBlockSet
func FetchBlockSet(dbo interfaces.DBOverlay, dBlockHash interfaces.IHash) *BlockSet {
bs := new(BlockSet)
dBlock, err := dbo.FetchDBlock(dBlockHash)
if err != nil {
panic(err)
}
bs.DBlock = dBlock
if dBlock == nil {
return bs
}
entries := dBlock.GetDBEntries()
for _, entry := range entries {
switch entry.GetChainID().String() {
case "000000000000000000000000000000000000000000000000000000000000000a":
aBlock, err := dbo.FetchABlock(entry.GetKeyMR())
if err != nil {
panic(err)
}
bs.ABlock = aBlock
break
case "000000000000000000000000000000000000000000000000000000000000000c":
ecBlock, err := dbo.FetchECBlock(entry.GetKeyMR())
if err != nil {
panic(err)
}
bs.ECBlock = ecBlock
break
case "000000000000000000000000000000000000000000000000000000000000000f":
fBlock, err := dbo.FetchFBlock(entry.GetKeyMR())
if err != nil {
panic(err)
}
bs.FBlock = fBlock
break
default:
break
}
}
return bs
}
示例2: CreateReceipt
func CreateReceipt(dbo interfaces.DBOverlay, entryID interfaces.IHash) (*Receipt, error) {
receipt := new(Receipt)
receipt.Entry = new(JSON)
receipt.Entry.Key = entryID.String()
//EBlock
hash, err := dbo.FetchIncludedIn(entryID)
if err != nil {
return nil, err
}
if hash == nil {
return nil, fmt.Errorf("Block containing entry not found")
}
eBlock, err := dbo.FetchEBlock(hash)
if err != nil {
return nil, err
}
if eBlock == nil {
return nil, fmt.Errorf("EBlock not found")
}
hash = eBlock.DatabasePrimaryIndex()
receipt.EntryBlockKeyMR = hash.(*primitives.Hash)
entries := eBlock.GetEntryHashes()
//fmt.Printf("eBlock entries - %v\n\n", entries)
branch := primitives.BuildMerkleBranchForEntryHash(entries, entryID, true)
blockNode := new(primitives.MerkleNode)
left, err := eBlock.HeaderHash()
if err != nil {
return nil, err
}
blockNode.Left = left.(*primitives.Hash)
blockNode.Right = eBlock.BodyKeyMR().(*primitives.Hash)
blockNode.Top = hash.(*primitives.Hash)
//fmt.Printf("eBlock blockNode - %v\n\n", blockNode)
branch = append(branch, blockNode)
receipt.MerkleBranch = append(receipt.MerkleBranch, branch...)
//str, _ := eBlock.JSONString()
//fmt.Printf("eBlock - %v\n\n", str)
//DBlock
hash, err = dbo.FetchIncludedIn(hash)
if err != nil {
return nil, err
}
if hash == nil {
return nil, fmt.Errorf("Block containing EBlock not found")
}
dBlock, err := dbo.FetchDBlock(hash)
if err != nil {
return nil, err
}
if dBlock == nil {
return nil, fmt.Errorf("DBlock not found")
}
//str, _ = dBlock.JSONString()
//fmt.Printf("dBlock - %v\n\n", str)
entries = dBlock.GetEntryHashesForBranch()
//fmt.Printf("dBlock entries - %v\n\n", entries)
//merkleTree := primitives.BuildMerkleTreeStore(entries)
//fmt.Printf("dBlock merkleTree - %v\n\n", merkleTree)
branch = primitives.BuildMerkleBranchForEntryHash(entries, receipt.EntryBlockKeyMR, true)
blockNode = new(primitives.MerkleNode)
left, err = dBlock.HeaderHash()
if err != nil {
return nil, err
}
blockNode.Left = left.(*primitives.Hash)
blockNode.Right = dBlock.BodyKeyMR().(*primitives.Hash)
blockNode.Top = hash.(*primitives.Hash)
//fmt.Printf("dBlock blockNode - %v\n\n", blockNode)
branch = append(branch, blockNode)
receipt.MerkleBranch = append(receipt.MerkleBranch, branch...)
//DirBlockInfo
hash = dBlock.DatabasePrimaryIndex()
receipt.DirectoryBlockKeyMR = hash.(*primitives.Hash)
dirBlockInfo, err := dbo.FetchDirBlockInfoByKeyMR(hash)
if err != nil {
return nil, err
}
if dirBlockInfo != nil {
dbi := dirBlockInfo.(*dbInfo.DirBlockInfo)
//.........這裏部分代碼省略.........
示例3: CheckDatabaseForMissingEntries
func CheckDatabaseForMissingEntries(dbo interfaces.DBOverlay) {
fmt.Printf("\t\tIterating over DBlocks\n")
prevD, err := dbo.FetchDBlockHead()
if err != nil {
panic(err)
}
HashMap = map[string]string{}
for {
CheckDBlockEntries(prevD, dbo)
HashMap[prevD.DatabasePrimaryIndex().String()] = "OK"
if prevD.GetHeader().GetPrevKeyMR().String() == "0000000000000000000000000000000000000000000000000000000000000000" {
break
}
dBlock, err := dbo.FetchDBlock(prevD.GetHeader().GetPrevKeyMR())
if err != nil {
panic(err)
}
if dBlock == nil {
fmt.Printf("Found a missing dblock - %v\n", prevD.GetHeader().GetPrevKeyMR().String())
dblock, err := GetDBlock(prevD.GetHeader().GetPrevKeyMR().String())
if err != nil {
panic(err)
}
err = dbo.ProcessDBlockBatchWithoutHead(dblock)
if err != nil {
panic(err)
}
} else {
//only iterate to the next block if it was properly fetched from the database
prevD = dBlock
}
}
fmt.Printf("\t\tIterating over ECBlocks\n")
prevEC, err := dbo.FetchECBlockHead()
if err != nil {
panic(err)
}
for {
HashMap[prevEC.DatabasePrimaryIndex().String()] = "OK"
if prevEC.GetHeader().GetPrevHeaderHash().String() == "0000000000000000000000000000000000000000000000000000000000000000" {
break
}
ecBlock, err := dbo.FetchECBlock(prevEC.GetHeader().GetPrevHeaderHash())
if err != nil {
panic(err)
}
if ecBlock == nil {
fmt.Printf("Found a missing ecblock - %v\n", prevEC.GetHeader().GetPrevHeaderHash().String())
ecblock, err := GetECBlock(prevEC.GetHeader().GetPrevHeaderHash().String())
if err != nil {
panic(err)
}
err = dbo.ProcessECBlockBatchWithoutHead(ecblock, true)
if err != nil {
panic(err)
}
} else {
//only iterate to the next block if it was properly fetched from the database
prevEC = ecBlock
}
}
fmt.Printf("\t\tIterating over FBlocks\n")
prevF, err := dbo.FetchFBlockHead()
if err != nil {
panic(err)
}
for {
HashMap[prevF.DatabasePrimaryIndex().String()] = "OK"
if prevF.GetPrevKeyMR().String() == "0000000000000000000000000000000000000000000000000000000000000000" {
break
}
fBlock, err := dbo.FetchFBlock(prevF.GetPrevKeyMR())
if err != nil {
panic(err)
}
if fBlock == nil {
fmt.Printf("Found a missing fblock - %v\n", prevF.GetPrevKeyMR().String())
fBlock, err := GetFBlock(prevF.GetPrevKeyMR().String())
if err != nil {
panic(err)
}
err = dbo.ProcessFBlockBatchWithoutHead(fBlock)
if err != nil {
panic(err)
}
} else {
//only iterate to the next block if it was properly fetched from the database
prevF = fBlock
}
}
fmt.Printf("\t\tIterating over ABlocks\n")
prevA, err := dbo.FetchABlockHead()
if err != nil {
//.........這裏部分代碼省略.........