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


Golang interfaces.IHash類代碼示例

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


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

示例1: 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())
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:30,代碼來源:authority.go

示例2: registerFactomIdentity

func registerFactomIdentity(entry interfaces.IEBEntry, chainID interfaces.IHash, height uint32, st *State) error {
	extIDs := entry.ExternalIDs()
	if len(extIDs) == 0 {
		return errors.New("Identity Error Register Identity: Invalid external ID length")
	}
	if bytes.Compare([]byte{0x00}, extIDs[0]) != 0 || // Version
		!CheckExternalIDsLength(extIDs, []int{1, 24, 32, 33, 64}) { // Signiture
		return errors.New("Identity Error Register Identity: Invalid external ID length")
	}

	// find the Identity index from the chain id in the external id.  add this chainID as the management id
	idChain := primitives.NewHash(extIDs[2])
	IdentityIndex := st.isIdentityChain(idChain)
	if IdentityIndex == -1 {
		IdentityIndex = st.CreateBlankFactomIdentity(idChain)
	}

	sigmsg, err := AppendExtIDs(extIDs, 0, 2)
	if err != nil {
		return err
	} else {
		// Verify Signature
		idKey := st.Identities[IdentityIndex].Key1
		if CheckSig(idKey, extIDs[3][1:33], sigmsg, extIDs[4]) {
			st.Identities[IdentityIndex].ManagementRegistered = height
		} else {
			return errors.New("New Management Chain Register for identity [" + chainID.String()[:10] + "] is invalid. Bad signiture")
		}

	}
	st.Identities[IdentityIndex].IdentityRegistered = height

	return nil
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:34,代碼來源:identity.go

示例3: FetchPaidFor

func (s *State) FetchPaidFor(hash interfaces.IHash) (interfaces.IHash, error) {
	//TODO: expand to search data from outside database
	if hash == nil {
		return nil, nil
	}

	ecBlock := s.ProcessLists.LastList().EntryCreditBlock
	for _, tx := range ecBlock.GetEntries() {
		switch tx.ECID() {
		case entryCreditBlock.ECIDEntryCommit:
			if hash.IsSameAs(tx.(*entryCreditBlock.CommitEntry).EntryHash) {
				return tx.GetSigHash(), nil
			}
			break
		case entryCreditBlock.ECIDChainCommit:
			if hash.IsSameAs(tx.(*entryCreditBlock.CommitChain).EntryHash) {
				return tx.GetSigHash(), nil
			}
			break
		}
	}

	dbase := s.GetAndLockDB()
	defer s.UnlockDB()

	return dbase.FetchPaidFor(hash)
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:27,代碼來源:ack.go

示例4: Validate

// Validate the message, given the state.  Three possible results:
//  < 0 -- Message is invalid.  Discard
//  0   -- Cannot tell if message is Valid
//  1   -- Message is valid
func (m *DataResponse) Validate(state interfaces.IState) int {
	var dataHash interfaces.IHash
	var err error
	switch m.DataType {
	case 0: // DataType = entry
		dataObject, ok := m.DataObject.(interfaces.IEBEntry)
		if !ok {
			return -1
		}
		dataHash = dataObject.GetHash()
	case 1: // DataType = eblock
		dataObject, ok := m.DataObject.(interfaces.IEntryBlock)
		if !ok {
			return -1
		}
		dataHash, err = dataObject.KeyMR()
		if err != nil {
			return -1
		}
	default:
		// DataType currently not supported, treat as invalid
		return -1
	}

	if dataHash.IsSameAs(m.DataHash) {
		return 1
	}

	return -1
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:34,代碼來源:dataResponse.go

示例5: PutCommit

func (s *State) PutCommit(hash interfaces.IHash, msg interfaces.IMsg) {
	cs := s.Commits[hash.Fixed()]
	if cs == nil {
		cs = make([]interfaces.IMsg, 0)
	}
	s.Commits[hash.Fixed()] = append(cs, msg)
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:7,代碼來源:stateConsensus.go

示例6: 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
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:7,代碼來源:entry.go

示例7: GetAuthority

// Gets the authority matching the identity ChainID.
// Returns the authority and the int of its type:
//		1  ->  Federated
//		0  ->  Audit
// 		-1 ->  Not fed or audit
//		-2 -> Not found
func (st *State) GetAuthority(serverID interfaces.IHash) (*Authority, int) {
	for _, auth := range st.Authorities {
		if serverID.IsSameAs(auth.AuthorityChainID) {
			return auth, auth.Type()
		}
	}
	return nil, -2
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:14,代碼來源:authority.go

示例8: SendRawTransactionToBTC

// SendRawTransactionToBTC is the main function used to anchor factom
// dir block hash to bitcoin blockchain
func (a *Anchor) SendRawTransactionToBTC(hash interfaces.IHash, blockHeight uint32) (*wire.ShaHash, error) {
	anchorLog.Debug("SendRawTransactionToBTC: hash=", hash.String(), ", dir block height=", blockHeight) //strconv.FormatUint(blockHeight, 10))
	dirBlockInfo, err := a.sanityCheck(hash)
	if err != nil {
		return nil, err
	}
	return a.doTransaction(hash, blockHeight, dirBlockInfo)
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:10,代碼來源:anchor.go

示例9: ContainsEntry

func (d *LastDirectoryBlockTransactions) ContainsEntry(hash interfaces.IHash) bool {
	for _, entry := range d.Entries {
		if entry.Hash == hash.String() {
			return true
		}
	}
	return false
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:8,代碼來源:controlPanel.go

示例10: ContainsTrans

func (d *LastDirectoryBlockTransactions) ContainsTrans(txid interfaces.IHash) bool {
	for _, trans := range d.FactoidTransactions {
		if trans.TxID == txid.String() {
			return true
		}
	}
	return false
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:8,代碼來源:controlPanel.go

示例11: 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
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:12,代碼來源:merkle.go

示例12: Sha

// Create a sha hash from the message binary (output of BtcEncode)
func (msg *MsgRevealChain) Sha() (interfaces.IHash, error) {

	buf := bytes.NewBuffer(nil)
	msg.BtcEncode(buf, ProtocolVersion)
	var sha interfaces.IHash
	_ = sha.SetBytes(Sha256(buf.Bytes()))

	return sha, nil
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:10,代碼來源:msgrevealchain.go

示例13: 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
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:10,代碼來源:overlay.go

示例14: 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
}
開發者ID:jjdevbiz,項目名稱:factomd,代碼行數:10,代碼來源:overlay.go

示例15: 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
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:10,代碼來源:paidFor.go


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