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


Golang IState.NextCommit方法代碼示例

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


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

示例1: ValidateRTN

// 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
// Also return the matching commit, if 1 (Don't put it back into the Commit List)
func (m *RevealEntryMsg) ValidateRTN(state interfaces.IState) (interfaces.IMsg, int) {
	commit := state.NextCommit(m.Entry.GetHash())

	if commit == nil {
		return nil, 0
	}
	//
	// Make sure one of the two proper commits got us here.
	var okChain, okEntry bool
	m.commitChain, okChain = commit.(*CommitChainMsg)
	m.commitEntry, okEntry = commit.(*CommitEntryMsg)
	if !okChain && !okEntry { // Discard any invalid entries in the map.  Should never happen.
		fmt.Println("dddd Bad EB Commit", state.GetFactomNodeName())
		return m.ValidateRTN(state)
	}

	// Now make sure the proper amount of credits were paid to record the entry.
	// The chain must exist
	if okEntry {
		m.IsEntry = true
		ECs := int(m.commitEntry.CommitEntry.Credits)
		if m.Entry.KSize() > ECs {
			fmt.Println("dddd EB Commit is short", state.GetFactomNodeName())
			return m.ValidateRTN(state) // Discard commits that are not funded properly.
		}

		// Make sure we have a chain.  If we don't, then bad things happen.
		db := state.GetAndLockDB()
		dbheight := state.GetLeaderHeight()
		eb := state.GetNewEBlocks(dbheight, m.Entry.GetChainID())
		eb_db := state.GetNewEBlocks(dbheight-1, m.Entry.GetChainID())
		if eb_db == nil {
			eb_db, _ = db.FetchEBlockHead(m.Entry.GetChainID())
		}

		if eb_db == nil && eb == nil {
			// If we don't have a chain, put the commit back.  Don't want to lose it.
			state.PutCommit(m.Entry.GetHash(), commit)
			return nil, 0
		}
	} else {
		m.IsEntry = false
		ECs := int(m.commitChain.CommitChain.Credits)
		if m.Entry.KSize()+10 > ECs { // Discard commits that are not funded properly
			return m.ValidateRTN(state)
		}
	}

	return commit, 1
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:55,代碼來源:revealEntry.go


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