本文整理匯總了Golang中github.com/FactomProject/factomd/common/interfaces.IHash.Bytes方法的典型用法代碼示例。如果您正苦於以下問題:Golang IHash.Bytes方法的具體用法?Golang IHash.Bytes怎麽用?Golang IHash.Bytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/FactomProject/factomd/common/interfaces.IHash
的用法示例。
在下文中一共展示了IHash.Bytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FetchAllEntriesByChainID
func (db *Overlay) FetchAllEntriesByChainID(chainID interfaces.IHash) ([]interfaces.IEBEntry, error) {
list, err := db.FetchAllBlocksFromBucket(chainID.Bytes(), entryBlock.NewEntry())
if err != nil {
return nil, err
}
return toEntryList(list), nil
}
示例2: ProcessEndOfBlock
// End of Block means packing the current block away, and setting
// up the next
func (fs *FactoidState) ProcessEndOfBlock(state interfaces.IState) {
var hash, hash2 interfaces.IHash
if fs.GetCurrentBlock() == nil {
panic("Invalid state on initialization")
}
hash = fs.CurrentBlock.GetHash()
hash2 = fs.CurrentBlock.GetLedgerKeyMR()
state.GetCurrentDirectoryBlock().GetDBEntries()[2].SetKeyMR(hash)
if err := state.GetDB().SaveFactoidBlockHead(fs.CurrentBlock); err != nil {
panic(err)
}
state.SetPrevFactoidKeyMR(hash)
fs.CurrentBlock = block.NewFBlock(fs.GetFactoshisPerEC(), state.GetDBHeight()+1)
t := coinbase.GetCoinbase(primitives.GetTimeMilli())
err := fs.CurrentBlock.AddCoinbase(t)
if err != nil {
panic(err.Error())
}
fs.UpdateTransaction(t)
if hash != nil {
fs.CurrentBlock.SetPrevKeyMR(hash.Bytes())
fs.CurrentBlock.SetPrevLedgerKeyMR(hash2.Bytes())
}
}
示例3: addServerSigningKey
func addServerSigningKey(chainID interfaces.IHash, key interfaces.IHash, height uint32, st *State) {
AuthorityIndex := st.AddAuthorityFromChainID(chainID)
if st.IdentityChainID.IsSameAs(chainID) && len(st.serverPendingPrivKeys) > 0 {
for i, pubKey := range st.serverPendingPubKeys {
pubData, err := pubKey.MarshalBinary()
if err != nil {
break
}
if bytes.Compare(pubData, key.Bytes()) == 0 {
st.serverPrivKey = st.serverPendingPrivKeys[i]
st.serverPubKey = st.serverPendingPubKeys[i]
if len(st.serverPendingPrivKeys) > i+1 {
st.serverPendingPrivKeys = append(st.serverPendingPrivKeys[:i], st.serverPendingPrivKeys[i+1:]...)
st.serverPendingPubKeys = append(st.serverPendingPubKeys[:i], st.serverPendingPubKeys[i+1:]...)
} else {
st.serverPendingPrivKeys = st.serverPendingPrivKeys[:i]
st.serverPendingPubKeys = st.serverPendingPubKeys[:i]
}
break
}
}
}
// Add Key History
st.Authorities[AuthorityIndex].KeyHistory = append(st.Authorities[AuthorityIndex].KeyHistory, struct {
ActiveDBHeight uint32
SigningKey primitives.PublicKey
}{height, st.Authorities[AuthorityIndex].SigningKey})
// Replace Active Key
st.Authorities[AuthorityIndex].SigningKey = primitives.PubKeyFromString(key.String())
}
示例4: HashMerkleBranches
// HashMerkleBranches takes two hashes, treated as the left and right tree
// nodes, and returns the hash of their concatenation. This is a helper
// function used to aid in the generation of a merkle tree.
func HashMerkleBranches(left interfaces.IHash, right interfaces.IHash) interfaces.IHash {
// Concatenate the left and right nodes.
var barray []byte = make([]byte, constants.ADDRESS_LENGTH*2)
copy(barray[:constants.ADDRESS_LENGTH], left.Bytes())
copy(barray[constants.ADDRESS_LENGTH:], right.Bytes())
newSha := Sha(barray)
return newSha
}
示例5: FetchPrimaryIndexBySecondaryIndex
func (db *Overlay) FetchPrimaryIndexBySecondaryIndex(secondaryIndexBucket []byte, key interfaces.IHash) (interfaces.IHash, error) {
block, err := db.DB.Get(secondaryIndexBucket, key.Bytes(), new(primitives.Hash))
if err != nil {
return nil, err
}
if block == nil {
return nil, nil
}
return block.(interfaces.IHash), nil
}
示例6: FetchBlock
func (db *Overlay) FetchBlock(bucket []byte, key interfaces.IHash, dst interfaces.DatabaseBatchable) (interfaces.DatabaseBatchable, error) {
block, err := db.DB.Get(bucket, key.Bytes(), dst)
if err != nil {
return nil, err
}
if block == nil {
return nil, nil
}
return block.(interfaces.DatabaseBatchable), nil
}
示例7: FetchPaidFor
func (db *Overlay) FetchPaidFor(hash interfaces.IHash) (interfaces.IHash, error) {
block, err := db.DB.Get(PAID_FOR, hash.Bytes(), new(primitives.Hash))
if err != nil {
return nil, err
}
if block == nil {
return nil, nil
}
return block.(interfaces.IHash), nil
}
示例8: FetchIncludedIn
func (db *Overlay) FetchIncludedIn(hash interfaces.IHash) (interfaces.IHash, error) {
block, err := db.DB.Get(INCLUDED_IN, hash.Bytes(), new(primitives.Hash))
if err != nil {
return nil, err
}
if block == nil {
return nil, nil
}
return block.(interfaces.IHash), nil
}
示例9: IsSameAs
// Compare two Hashes
func (a Hash) IsSameAs(b interfaces.IHash) bool {
if b == nil {
return false
}
if bytes.Compare(a[:], b.Bytes()) == 0 {
return true
}
return false
}
示例10: SavePaidFor
func (db *Overlay) SavePaidFor(entry, ecEntry interfaces.IHash) error {
if entry == nil || ecEntry == nil {
return nil
}
batch := []interfaces.Record{}
batch = append(batch, interfaces.Record{PAID_FOR, entry.Bytes(), ecEntry})
err := db.DB.PutInBatch(batch)
if err != nil {
return err
}
return nil
}
示例11: SaveIncludedIn
func (db *Overlay) SaveIncludedIn(entry, block interfaces.IHash) error {
if entry == nil || block == nil {
return nil
}
batch := []interfaces.Record{}
batch = append(batch, interfaces.Record{INCLUDED_IN, entry.Bytes(), block})
err := db.DB.PutInBatch(batch)
if err != nil {
return err
}
return nil
}
示例12: GetAuditServerIndexHash
// Returns true and the index of this server, or false and the insertion point for this server
func (p *ProcessList) GetAuditServerIndexHash(identityChainID interfaces.IHash) (bool, int) {
if p == nil {
return false, 0
}
p.SortAuditServers()
scid := identityChainID.Bytes()
for i, fs := range p.AuditServers {
// Find and remove
if bytes.Compare(scid, fs.GetChainID().Bytes()) == 0 {
return true, i
}
}
return false, len(p.AuditServers)
}
示例13: FetchHeadIndexByChainID
// FetchHeadMRByChainID gets an index of the highest block from the database.
func (db *Overlay) FetchHeadIndexByChainID(chainID interfaces.IHash) (interfaces.IHash, error) {
if chainID == nil {
return nil, nil
}
bucket := []byte{byte(CHAIN_HEAD)}
key := chainID.Bytes()
block, err := db.DB.Get(bucket, key, new(primitives.Hash))
if err != nil {
return nil, err
}
if block == nil {
return nil, nil
}
return block.(interfaces.IHash), nil
}
示例14: FetchAllEBlocksByChain
// FetchAllEBlocksByChain gets all of the blocks by chain id
func (db *Overlay) FetchAllEBlocksByChain(chainID interfaces.IHash) ([]interfaces.IEntryBlock, error) {
bucket := append([]byte{byte(ENTRYBLOCK_CHAIN_NUMBER)}, chainID.Bytes()...)
keyList, err := db.FetchAllBlocksFromBucket(bucket, new(primitives.Hash))
if err != nil {
return nil, err
}
list := make([]interfaces.IEntryBlock, len(keyList))
for i, v := range keyList {
block, err := db.FetchEBlockByKeyMR(v.(interfaces.IHash))
if err != nil {
return nil, err
}
list[i] = block
}
return list, nil
}
示例15: 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
}