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


Golang DBOverlay.FetchIncludedIn方法代碼示例

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


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

示例1: 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)
//.........這裏部分代碼省略.........
開發者ID:FactomProject,項目名稱:factomd,代碼行數:101,代碼來源:receipts.go


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