本文整理匯總了Golang中github.com/FactomProject/FactomCode/common.DirectoryBlock.UnmarshalBinary方法的典型用法代碼示例。如果您正苦於以下問題:Golang DirectoryBlock.UnmarshalBinary方法的具體用法?Golang DirectoryBlock.UnmarshalBinary怎麽用?Golang DirectoryBlock.UnmarshalBinary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/FactomProject/FactomCode/common.DirectoryBlock
的用法示例。
在下文中一共展示了DirectoryBlock.UnmarshalBinary方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getAll
func getAll() error {
dbs := make([]*common.DirectoryBlock, 0, 100)
next := DBHeadStr
for {
blk, err := factom.GetRaw(next)
if err != nil {
panic(err.Error())
}
db := new(common.DirectoryBlock)
err = db.UnmarshalBinary(blk)
if err != nil {
panic(err.Error())
}
dbs = append(dbs, db)
if bytes.Equal(db.Header.PrevKeyMR.Bytes(), DBHeadLast) {
break
}
next = hex.EncodeToString(db.Header.PrevKeyMR.Bytes())
}
DBHeadLast = DBHead
for i := len(dbs) - 1; i >= 0; i-- {
DirectoryBlocks = append(DirectoryBlocks, dbs[i])
fb := new(block.FBlock)
var fcnt int
for _, dbe := range dbs[i].DBEntries {
if bytes.Equal(dbe.ChainID.Bytes(), common.FACTOID_CHAINID) {
fcnt++
hashstr := hex.EncodeToString(dbe.KeyMR.Bytes())
fdata, err := factom.GetRaw(hashstr)
if err != nil {
panic(err.Error())
}
err = fb.UnmarshalBinary(fdata)
if err != nil {
panic(err.Error())
}
FactoidBlocks = append(FactoidBlocks, fb)
break
}
}
if fb == nil {
panic("Missing Factoid Block from a directory block")
}
if fcnt > 1 {
panic("More than one Factom Block found in a directory block.")
}
if err := ProcessFB(fb); err != nil {
return err
}
}
return nil
}
示例2: getAll
func getAll() error {
dbs := make([]*common.DirectoryBlock, 0, 100)
next := DBHeadStr
for {
blk, err := factom.GetRaw(next)
if err != nil {
panic(err.Error())
}
db := new(common.DirectoryBlock)
err = db.UnmarshalBinary(blk)
if err != nil {
panic(err.Error())
}
dbs = append(dbs, db)
if bytes.Equal(db.Header.PrevKeyMR.Bytes(), common.ZERO_HASH[:]) {
break
}
next = hex.EncodeToString(db.Header.PrevKeyMR.Bytes())
}
for i := len(dbs) - 1; i >= 0; i-- {
DirectoryBlocks = append(DirectoryBlocks, dbs[i])
fb := new(block.FBlock)
for _, dbe := range dbs[i].DBEntries {
if bytes.Equal(dbe.ChainID.Bytes(), common.FACTOID_CHAINID) {
hashstr := hex.EncodeToString(dbe.KeyMR.Bytes())
fdata, err := factom.GetRaw(hashstr)
if err != nil {
panic(err.Error())
}
err = fb.UnmarshalBinary(fdata)
if err != nil {
panic(err.Error())
}
FactoidBlocks = append(FactoidBlocks, fb)
break
}
}
if fb == nil {
fmt.Println("Missing Factoid Block")
}
}
return nil
}