本文整理匯總了Golang中github.com/FactomProject/factomd/common/interfaces.IDirectoryBlock類的典型用法代碼示例。如果您正苦於以下問題:Golang IDirectoryBlock類的具體用法?Golang IDirectoryBlock怎麽用?Golang IDirectoryBlock使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了IDirectoryBlock類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewDBState
func (list *DBStateList) NewDBState(isNew bool,
directoryBlock interfaces.IDirectoryBlock,
adminBlock interfaces.IAdminBlock,
factoidBlock interfaces.IFBlock,
entryCreditBlock interfaces.IEntryCreditBlock,
eBlocks []interfaces.IEntryBlock,
entries []interfaces.IEBEntry) *DBState {
dbState := new(DBState)
dbState.DBHash = directoryBlock.DatabasePrimaryIndex()
dbState.ABHash = adminBlock.DatabasePrimaryIndex()
dbState.FBHash = factoidBlock.DatabasePrimaryIndex()
dbState.ECHash = entryCreditBlock.DatabasePrimaryIndex()
dbState.isNew = isNew
dbState.DirectoryBlock = directoryBlock
dbState.AdminBlock = adminBlock
dbState.FactoidBlock = factoidBlock
dbState.EntryCreditBlock = entryCreditBlock
dbState.EntryBlocks = eBlocks
dbState.Entries = entries
// If we actually add this to the list, return the dbstate.
if list.Put(dbState) {
return dbState
}
// Failed, so return nil
return nil
}
示例2: CreateAnchorRecordFromDBlock
func CreateAnchorRecordFromDBlock(dBlock interfaces.IDirectoryBlock) *AnchorRecord {
ar := new(AnchorRecord)
ar.AnchorRecordVer = 1
ar.DBHeight = dBlock.GetHeader().GetDBHeight()
ar.KeyMR = dBlock.DatabasePrimaryIndex().String()
ar.RecordHeight = ar.DBHeight
return ar
}
示例3: NewDirBlockInfoFromDirBlock
// NewDirBlockInfoFromDirBlock creates a DirDirBlockInfo from DirectoryBlock
func NewDirBlockInfoFromDirBlock(dirBlock interfaces.IDirectoryBlock) *DirBlockInfo {
dbic := new(DirBlockInfo)
dbic.DBHash = dirBlock.GetHash()
dbic.DBHeight = dirBlock.GetDatabaseHeight()
dbic.DBMerkleRoot = dirBlock.GetKeyMR()
dbic.Timestamp = int64(dirBlock.GetHeader().GetTimestamp()) // * 60 ???
dbic.BTCTxHash = primitives.NewZeroHash()
dbic.BTCBlockHash = primitives.NewZeroHash()
dbic.BTCConfirmed = false
return dbic
}
示例4: ValidNext
// Validate this directory block given the next Directory Block. Need to check the
// signatures as being from the authority set, and valid. Also check that this DBState holds
// a previous KeyMR that matches the previous DBState KeyMR.
//
// Return a -1 on failure.
//
func (d *DBState) ValidNext(state interfaces.IState, dirblk interfaces.IDirectoryBlock) int {
dbheight := dirblk.GetHeader().GetDBHeight()
if dbheight == 0 {
// The genesis block is valid by definition.
return 1
}
if d == nil || !d.Saved {
// Must be out of order. Can't make the call if valid or not yet.
return 0
}
// Get the keymr of the Previous DBState
pkeymr := d.DirectoryBlock.GetKeyMR()
// Get the Previous KeyMR pointer in the possible new Directory Block
prevkeymr := dirblk.GetHeader().GetPrevKeyMR()
if !pkeymr.IsSameAs(prevkeymr) {
// If not the same, this is a bad new Directory Block
return -1
}
return 1
}
示例5: NewDirectoryBlock
func NewDirectoryBlock(prev interfaces.IDirectoryBlock) interfaces.IDirectoryBlock {
newdb := new(DirectoryBlock)
newdb.Header = new(DBlockHeader)
newdb.Header.SetVersion(constants.VERSION_0)
if prev != nil {
newdb.GetHeader().SetPrevFullHash(prev.GetFullHash())
newdb.GetHeader().SetPrevKeyMR(prev.GetKeyMR())
newdb.GetHeader().SetDBHeight(prev.GetHeader().GetDBHeight() + 1)
} else {
newdb.Header.SetPrevFullHash(primitives.NewZeroHash())
newdb.Header.SetPrevKeyMR(primitives.NewZeroHash())
newdb.GetHeader().SetDBHeight(0)
}
newdb.SetDBEntries(make([]interfaces.IDBEntry, 0))
newdb.AddEntry(primitives.NewHash(constants.ADMIN_CHAINID), primitives.NewZeroHash())
newdb.AddEntry(primitives.NewHash(constants.EC_CHAINID), primitives.NewZeroHash())
newdb.AddEntry(primitives.NewHash(constants.FACTOID_CHAINID), primitives.NewZeroHash())
return newdb
}
示例6: CheckBlockPairIntegrity
func CheckBlockPairIntegrity(block interfaces.IDirectoryBlock, prev interfaces.IDirectoryBlock) error {
if block == nil {
return fmt.Errorf("No block specified")
}
if prev == nil {
if block.GetHeader().GetPrevKeyMR().IsZero() == false {
return fmt.Errorf("Invalid PrevKeyMR")
}
if block.GetHeader().GetPrevFullHash().IsZero() == false {
return fmt.Errorf("Invalid PrevFullHash")
}
if block.GetHeader().GetDBHeight() != 0 {
return fmt.Errorf("Invalid DBHeight")
}
} else {
if block.GetHeader().GetPrevKeyMR().IsSameAs(prev.GetKeyMR()) == false {
return fmt.Errorf("Invalid PrevKeyMR")
}
if block.GetHeader().GetPrevFullHash().IsSameAs(prev.GetFullHash()) == false {
return fmt.Errorf("Invalid PrevFullHash")
}
if block.GetHeader().GetDBHeight() != (prev.GetHeader().GetDBHeight() + 1) {
return fmt.Errorf("Invalid DBHeight")
}
}
return nil
}
示例7: getPastEntries
// Control Panel shows the last 100 entry and factoid transactions. This will look into the past if we do not
// currently have 100 of each transaction type. A checkpoint is set each time we check a new height, so we will
// not check a directory block in the past twice.
func getPastEntries(last interfaces.IDirectoryBlock, eNeeded int, fNeeded int) {
height := last.GetHeader().GetDBHeight()
next := last.GetHeader().GetPrevKeyMR()
zero := primitives.NewZeroHash()
newCheckpoint := height
for height > RecentTransactions.LastHeightChecked && (eNeeded > 0 || fNeeded > 0) {
if next.IsSameAs(zero) {
break
}
dbase := StatePointer.GetAndLockDB()
dblk, err := dbase.FetchDBlock(next)
StatePointer.UnlockDB()
if err != nil || dblk == nil {
break
}
height = dblk.GetHeader().GetDBHeight()
ents := dblk.GetDBEntries()
if len(ents) > 3 && eNeeded > 0 {
for _, eblock := range ents[3:] {
dbase := StatePointer.GetAndLockDB()
eblk, err := dbase.FetchEBlock(eblock.GetKeyMR())
StatePointer.UnlockDB()
if err != nil || eblk == nil {
break
}
for _, hash := range eblk.GetEntryHashes() {
if RecentTransactions.ContainsEntry(hash) {
continue
}
e := getEntry(hash.String())
if e != nil && eNeeded > 0 {
eNeeded--
RecentTransactions.Entries = append(RecentTransactions.Entries, *e)
//RecentTransactions.Entries = append([]EntryHolder{*e}, RecentTransactions.Entries...)
}
}
}
}
if fNeeded > 0 {
fChain := primitives.NewHash(constants.FACTOID_CHAINID)
for _, entry := range ents {
if entry.GetChainID().IsSameAs(fChain) {
dbase := StatePointer.GetAndLockDB()
fblk, err := dbase.FetchFBlock(entry.GetKeyMR())
StatePointer.UnlockDB()
if err != nil || fblk == nil {
break
}
transList := fblk.GetTransactions()
for _, trans := range transList {
if RecentTransactions.ContainsTrans(trans.GetSigHash()) {
continue
}
if trans != nil {
input, err := trans.TotalInputs()
if err != nil || input == 0 {
continue
}
totalInputs := len(trans.GetInputs())
totalOutputs := len(trans.GetECOutputs())
totalOutputs = totalOutputs + len(trans.GetOutputs())
inputStr := fmt.Sprintf("%f", float64(input)/1e8)
fNeeded--
RecentTransactions.FactoidTransactions = append(RecentTransactions.FactoidTransactions, struct {
TxID string
Hash string
TotalInput string
Status string
TotalInputs int
TotalOutputs int
}{trans.GetSigHash().String(), trans.GetHash().String(), inputStr, "Confirmed", totalInputs, totalOutputs})
}
}
}
}
}
next = dblk.GetHeader().GetPrevKeyMR()
}
DisplayStateMutex.Lock()
if newCheckpoint < DisplayState.CurrentEBDBHeight && newCheckpoint > RecentTransactions.LastHeightChecked {
RecentTransactions.LastHeightChecked = newCheckpoint
}
DisplayStateMutex.Unlock()
}
示例8: CheckDBlockEntries
func CheckDBlockEntries(dBlock interfaces.IDirectoryBlock, dbo interfaces.DBOverlay) {
entries := dBlock.GetDBEntries()
for {
missing := 0
for _, e := range entries {
HashMap[e.GetKeyMR().String()] = "OK"
switch e.GetChainID().String() {
case "000000000000000000000000000000000000000000000000000000000000000a":
aBlock, err := dbo.FetchABlock(e.GetKeyMR())
if err != nil {
panic(err)
}
if aBlock != nil {
break
}
fmt.Printf("Found missing aBlock in #%v\n", dBlock.GetDatabaseHeight())
missing++
aBlock, err = GetABlock(e.GetKeyMR().String())
if err != nil {
panic(err)
}
err = dbo.ProcessABlockBatchWithoutHead(aBlock)
if err != nil {
panic(err)
}
break
case "000000000000000000000000000000000000000000000000000000000000000f":
fBlock, err := dbo.FetchFBlock(e.GetKeyMR())
if err != nil {
panic(err)
}
if fBlock != nil {
break
}
fmt.Printf("Found missing fBlock in #%v\n", dBlock.GetDatabaseHeight())
missing++
fBlock, err = GetFBlock(e.GetKeyMR().String())
if err != nil {
panic(err)
}
err = dbo.ProcessFBlockBatchWithoutHead(fBlock)
if err != nil {
panic(err)
}
break
case "000000000000000000000000000000000000000000000000000000000000000c":
ecBlock, err := dbo.FetchECBlock(e.GetKeyMR())
if err != nil {
panic(err)
}
if ecBlock != nil {
break
}
fmt.Printf("Found missing ecBlock in #%v\n", dBlock.GetDatabaseHeight())
missing++
ecBlock, err = GetECBlock(e.GetKeyMR().String())
if err != nil {
panic(err)
}
err = dbo.ProcessECBlockBatchWithoutHead(ecBlock, true)
if err != nil {
panic(err)
}
break
default:
eBlock, err := dbo.FetchEBlock(e.GetKeyMR())
if err != nil {
if err.Error() != "EOF" {
panic(err)
}
}
if eBlock == nil {
fmt.Printf("Found missing eBlock in #%v\n", dBlock.GetDatabaseHeight())
missing++
eBlock, err = GetEBlock(e.GetKeyMR().String())
if err != nil {
panic(err)
}
err = dbo.ProcessEBlockBatchWithoutHead(eBlock, true)
if err != nil {
panic(err)
}
}
eBlockEntries := eBlock.GetEntryHashes()
for _, eHash := range eBlockEntries {
if eHash.IsMinuteMarker() == true {
continue
}
entry, err := dbo.FetchEntry(eHash)
if err != nil {
panic(err)
}
if entry == nil {
fmt.Printf("Found missing entry in #%v\n", dBlock.GetDatabaseHeight())
missing++
entry, err := GetEntry(eHash.String())
if err != nil {
fmt.Printf("Problem getting entry `%v` from block %v\n", eHash.String(), e.GetKeyMR().String())
panic(err)
//.........這裏部分代碼省略.........