本文整理匯總了Golang中github.com/FactomProject/factomd/common/interfaces.IEntryCreditBlock類的典型用法代碼示例。如果您正苦於以下問題:Golang IEntryCreditBlock類的具體用法?Golang IEntryCreditBlock怎麽用?Golang IEntryCreditBlock使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了IEntryCreditBlock類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: AddECBlock
func (fs *FactoidState) AddECBlock(blk interfaces.IEntryCreditBlock) error {
transactions := blk.GetBody().GetEntries()
for _, trans := range transactions {
err := fs.UpdateECTransaction(trans)
if err != nil {
return err
}
}
return nil
}
示例3: SavePaidForMultiFromBlock
func (db *Overlay) SavePaidForMultiFromBlock(block interfaces.IEntryCreditBlock, checkForDuplicateEntries bool) error {
if block == nil {
return nil
}
batch := []interfaces.Record{}
for _, entry := range block.GetBody().GetEntries() {
if entry.ECID() != entryCreditBlock.ECIDChainCommit && entry.ECID() != entryCreditBlock.ECIDEntryCommit {
continue
}
var entryHash interfaces.IHash
if entry.ECID() == entryCreditBlock.ECIDChainCommit {
entryHash = entry.(*entryCreditBlock.CommitChain).EntryHash
}
if entry.ECID() == entryCreditBlock.ECIDEntryCommit {
entryHash = entry.(*entryCreditBlock.CommitEntry).EntryHash
}
if checkForDuplicateEntries == true {
loaded, err := db.Get(PAID_FOR, entryHash.Bytes(), primitives.NewZeroHash())
if err != nil {
return err
}
if loaded != nil {
continue
}
}
batch = append(batch, interfaces.Record{PAID_FOR, entryHash.Bytes(), entry.Hash()})
}
if len(batch) == 0 {
return nil
}
err := db.DB.PutInBatch(batch)
if err != nil {
return err
}
return nil
}
示例4: NextECBlock
func NextECBlock(prev interfaces.IEntryCreditBlock) (interfaces.IEntryCreditBlock, error) {
e := NewECBlock()
// Handle the really unusual case of the first block.
if prev == nil {
e.GetHeader().SetPrevHeaderHash(primitives.NewHash(constants.ZERO_HASH))
e.GetHeader().SetPrevFullHash(primitives.NewHash(constants.ZERO_HASH))
e.GetHeader().SetDBHeight(0)
} else {
v, err := prev.HeaderHash()
if err != nil {
return nil, err
}
e.GetHeader().SetPrevHeaderHash(v)
v, err = prev.GetFullHash()
if err != nil {
return nil, err
}
e.GetHeader().SetPrevFullHash(v)
e.GetHeader().SetDBHeight(prev.GetHeader().GetDBHeight() + 1)
}
if err := e.(*ECBlock).BuildHeader(); err != nil {
return nil, err
}
return e, nil
}
示例5: UpdateECs
func (s *State) UpdateECs(ec interfaces.IEntryCreditBlock) {
now := s.GetTimestamp()
for _, entry := range ec.GetEntries() {
cc, ok := entry.(*entryCreditBlock.CommitChain)
if ok && s.Replay.IsTSValid_(constants.INTERNAL_REPLAY, cc.GetSigHash().Fixed(), cc.GetTimestamp(), now) {
if s.NoEntryYet(cc.EntryHash, cc.GetTimestamp()) {
cmsg := new(messages.CommitChainMsg)
cmsg.CommitChain = cc
s.PutCommit(cc.EntryHash, cmsg)
}
continue
}
ce, ok := entry.(*entryCreditBlock.CommitEntry)
if ok && s.Replay.IsTSValid_(constants.INTERNAL_REPLAY, ce.GetSigHash().Fixed(), ce.GetTimestamp(), now) {
if s.NoEntryYet(ce.EntryHash, ce.GetTimestamp()) {
emsg := new(messages.CommitEntryMsg)
emsg.CommitEntry = ce
s.PutCommit(ce.EntryHash, emsg)
}
continue
}
}
}
示例6: SetECBlockHash
func (c *DirectoryBlock) SetECBlockHash(ecBlock interfaces.IEntryCreditBlock) error {
hash := ecBlock.DatabasePrimaryIndex()
c.SetEntryHash(hash, ecBlock.GetChainID(), 1)
return nil
}
示例7: CheckBlockPairIntegrity
func CheckBlockPairIntegrity(block interfaces.IEntryCreditBlock, prev interfaces.IEntryCreditBlock) error {
if block == nil {
return fmt.Errorf("No block specified")
}
if prev == nil {
if block.GetHeader().GetPrevHeaderHash().IsZero() == false {
return fmt.Errorf("Invalid PrevHeaderHash")
}
if block.GetHeader().GetPrevFullHash().IsZero() == false {
return fmt.Errorf("Invalid PrevFullHash")
}
if block.GetHeader().GetDBHeight() != 0 {
return fmt.Errorf("Invalid DBHeight")
}
} else {
h, err := prev.HeaderHash()
if err != nil {
return err
}
if block.GetHeader().GetPrevHeaderHash().IsSameAs(h) == false {
return fmt.Errorf("Invalid PrevHeaderHash")
}
h, err = prev.GetFullHash()
if err != nil {
return err
}
if block.GetHeader().GetPrevFullHash().IsSameAs(h) == false {
return fmt.Errorf("Invalid PrevFullHash")
}
if block.GetHeader().GetDBHeight() != (prev.GetHeader().GetDBHeight() + 1) {
return fmt.Errorf("Invalid DBHeight")
}
}
return nil
}