本文整理匯總了Golang中github.com/FactomProject/factomd/common/interfaces.IState類的典型用法代碼示例。如果您正苦於以下問題:Golang IState類的具體用法?Golang IState怎麽用?Golang IState使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了IState類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SigTally
func (m *FullServerFault) SigTally(state interfaces.IState) int {
validSigCount := 0
// Check main signature
bytes, err := m.MarshalForSignature()
if err != nil {
return 0
}
sig := m.Signature.GetSignature()
sfSigned, err := state.VerifyAuthoritySignature(bytes, sig, m.DBHeight)
if err != nil {
return 0
}
if sfSigned < 1 {
return 0
}
cb, err := m.MarshalCore()
if err != nil {
return 0
}
for _, fedSig := range m.SignatureList.List {
check, err := state.VerifyAuthoritySignature(cb, fedSig.GetSignature(), m.DBHeight)
if err == nil && check == 1 {
validSigCount++
}
}
return validSigCount
}
示例2: HandleV2FactoidSubmit
func HandleV2FactoidSubmit(state interfaces.IState, params interface{}) (interface{}, *primitives.JSONError) {
t := new(TransactionRequest)
err := MapToObject(params, t)
if err != nil {
return nil, NewInvalidParamsError()
}
msg := new(messages.FactoidTransaction)
p, err := hex.DecodeString(t.Transaction)
if err != nil {
return nil, NewUnableToDecodeTransactionError()
}
_, err = msg.UnmarshalTransData(p)
if err != nil {
return nil, NewUnableToDecodeTransactionError()
}
state.IncFCTSubmits()
state.APIQueue() <- msg
resp := new(FactoidSubmitResponse)
resp.Message = "Successfully submitted the transaction"
resp.TxID = msg.Transaction.GetSigHash().String()
return resp, nil
}
示例3: PrtMsgs
func (m *MsgLog) PrtMsgs(state interfaces.IState) {
m.sem.Lock()
defer m.sem.Unlock()
if len(m.MsgList) == 0 {
return
}
fmt.Println(state.String())
fmt.Println("\n-----------------------------------------------------")
for _, e := range m.MsgList {
if e.valid {
dirstr := "->"
if !e.out {
dirstr = "<-"
}
fmt.Print(fmt.Sprintf("**** %8s %2s %8s %10s %5v **** %s\n", e.name, dirstr, e.peer, e.where, e.valid, e.msg.String()))
}
}
now := state.GetTimestamp()
m.last = now
m.msgCnt += len(m.MsgList) // Keep my counts
m.msgCntp += len(m.MsgList)
m.MsgList = m.MsgList[0:0] // Once printed, clear the list
fmt.Println(fmt.Sprintf("*** %42s **** ", fmt.Sprintf("Length: %d Msgs/sec: T %d P %d", len(m.MsgList), m.msgPerSec, m.msgPerSecp)))
fmt.Println("\n-----------------------------------------------------")
}
示例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 *Ack) Validate(state interfaces.IState) int {
if m.authvalid {
return 1
}
// Only new acks are valid. Of course, the VMIndex has to be valid too.
msg, err := state.GetMsg(m.VMIndex, int(m.DBHeight), int(m.Height))
if err != nil || msg != nil {
return -1
}
// Check signature
bytes, err := m.MarshalForSignature()
if err != nil {
//fmt.Println("Err is not nil on Ack sig check: ", err)
return -1
}
sig := m.Signature.GetSignature()
ackSigned, err := state.VerifyAuthoritySignature(bytes, sig, m.DBHeight)
//ackSigned, err := m.VerifySignature()
if err != nil {
//fmt.Println("Err is not nil on Ack sig check: ", err)
return -1
}
if ackSigned < 1 {
return -1
}
m.authvalid = true
return 1
}
示例5: FollowerExecute
func (m *MissingData) FollowerExecute(state interfaces.IState) {
var dataObject interfaces.BinaryMarshallable
//var dataHash interfaces.IHash
rawObject, dataType, err := state.LoadDataByHash(m.RequestHash)
if rawObject != nil && err == nil { // If I don't have this message, ignore.
switch dataType {
case 0: // DataType = entry
dataObject = rawObject.(interfaces.IEBEntry)
//dataHash = dataObject.(interfaces.IEBEntry).GetHash()
case 1: // DataType = eblock
dataObject = rawObject.(interfaces.IEntryBlock)
//dataHash, _ = dataObject.(interfaces.IEntryBlock).Hash()
default:
return
}
msg := NewDataResponse(state, dataObject, dataType, m.RequestHash)
msg.SetOrigin(m.GetOrigin())
msg.SetNetworkOrigin(m.GetNetworkOrigin())
msg.SendOut(state, msg)
}
return
}
示例6: HandleV2CommitEntry
func HandleV2CommitEntry(state interfaces.IState, params interface{}) (interface{}, *primitives.JSONError) {
commitEntryMsg := new(EntryRequest)
err := MapToObject(params, commitEntryMsg)
if err != nil {
return nil, NewInvalidParamsError()
}
commit := entryCreditBlock.NewCommitEntry()
if p, err := hex.DecodeString(commitEntryMsg.Entry); err != nil {
return nil, NewInvalidCommitEntryError()
} else {
_, err := commit.UnmarshalBinaryData(p)
if err != nil {
return nil, NewInvalidCommitEntryError()
}
}
msg := new(messages.CommitEntryMsg)
msg.CommitEntry = commit
state.APIQueue() <- msg
state.IncECommits()
resp := new(CommitEntryResponse)
resp.Message = "Entry Commit Success"
resp.TxID = commit.GetSigHash().String()
return resp, nil
}
示例7: HandleV2FactoidBalance
func HandleV2FactoidBalance(state interfaces.IState, params interface{}) (interface{}, *primitives.JSONError) {
fadr := new(AddressRequest)
err := MapToObject(params, fadr)
if err != nil {
return nil, NewInvalidParamsError()
}
var adr []byte
if primitives.ValidateFUserStr(fadr.Address) {
adr = primitives.ConvertUserStrToAddress(fadr.Address)
} else {
adr, err = hex.DecodeString(fadr.Address)
if err == nil && len(adr) != constants.HASH_LENGTH {
return nil, NewInvalidAddressError()
}
if err != nil {
return nil, NewInvalidAddressError()
}
}
if len(adr) != constants.HASH_LENGTH {
return nil, NewInvalidAddressError()
}
resp := new(FactoidBalanceResponse)
resp.Balance = state.GetFactoidState().GetFactoidBalance(factoid.NewAddress(adr).Fixed())
return resp, nil
}
示例8: 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 *DBStateMsg) Validate(state interfaces.IState) int {
if m.DirectoryBlock == nil || m.AdminBlock == nil || m.FactoidBlock == nil || m.EntryCreditBlock == nil {
//We need the basic block types
return -1
}
if state.GetNetworkID() != m.DirectoryBlock.GetHeader().GetNetworkID() {
//Wrong network ID
return -1
}
dbheight := m.DirectoryBlock.GetHeader().GetDBHeight()
if dbheight != state.GetHighestCompletedBlock()+1 && dbheight != 0 {
//We only expect the next height
return -1
}
if m.DirectoryBlock.GetHeader().GetNetworkID() == constants.MAIN_NETWORK_ID {
key := constants.CheckPoints[dbheight]
if key != "" {
if key != m.DirectoryBlock.DatabasePrimaryIndex().String() {
//Key does not match checkpoint
return -1
}
}
}
return 1
}
示例9: FollowerExecute
func (m *CommitChainMsg) FollowerExecute(state interfaces.IState) error {
err := state.MatchAckFollowerExecute(m)
if err != nil {
return err
}
return nil
}
示例10: HandleV2RevealEntry
func HandleV2RevealEntry(state interfaces.IState, params interface{}) (interface{}, *primitives.JSONError) {
e := new(EntryRequest)
err := MapToObject(params, e)
if err != nil {
return nil, NewInvalidParamsError()
}
entry := entryBlock.NewEntry()
if p, err := hex.DecodeString(e.Entry); err != nil {
return nil, NewInvalidEntryError()
} else {
_, err := entry.UnmarshalBinaryData(p)
if err != nil {
return nil, NewInvalidEntryError()
}
}
msg := new(messages.RevealEntryMsg)
msg.Entry = entry
msg.Timestamp = state.GetTimestamp()
state.APIQueue() <- msg
resp := new(RevealEntryResponse)
resp.Message = "Entry Reveal Success"
resp.EntryHash = entry.GetHash().String()
return resp, nil
}
示例11: NewEntryBlockResponse
func NewEntryBlockResponse(state interfaces.IState) interfaces.IMsg {
msg := new(EntryBlockResponse)
msg.Peer2Peer = true // Always a peer2peer request.
msg.Timestamp = state.GetTimestamp()
return msg
}
示例12: NewAddServerByHashMsg
func NewAddServerByHashMsg(state interfaces.IState, serverType int, newServerHash interfaces.IHash) interfaces.IMsg {
msg := new(AddServerMsg)
msg.ServerChainID = newServerHash
msg.ServerType = serverType
msg.Timestamp = state.GetTimestamp()
return msg
}
示例13: 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 *FactoidTransaction) Validate(state interfaces.IState) int {
err := state.GetFactoidState().Validate(1, m.Transaction)
if err != nil {
fmt.Println(err.Error())
return -1
}
return 1
}
示例14: Validate
func (m *RevealEntryMsg) Validate(state interfaces.IState) int {
commit, rtn := m.ValidateRTN(state)
if rtn == 1 {
// Don't lose the commit that validates the entry
state.PutCommit(m.Entry.GetHash(), commit)
}
return rtn
}
示例15: NewAddServerMsg
func NewAddServerMsg(state interfaces.IState, serverType int) interfaces.IMsg {
msg := new(AddServerMsg)
msg.ServerChainID = state.GetIdentityChainID()
msg.ServerType = serverType
msg.Timestamp = state.GetTimestamp()
return msg
}