dione/consensus/msg_log.go

55 lines
1.1 KiB
Go
Raw Normal View History

package consensus
import (
"bytes"
types2 "github.com/Secured-Finance/dione/consensus/types"
mapset "github.com/Secured-Finance/golang-set"
)
type ConsensusMessageLog struct {
messages mapset.Set
maxLogSize int
}
func NewConsensusMessageLog() *ConsensusMessageLog {
msgLog := &ConsensusMessageLog{
messages: mapset.NewSet(),
maxLogSize: 0, // TODO
}
return msgLog
}
func (ml *ConsensusMessageLog) AddMessage(msg types2.ConsensusMessage) {
ml.messages.Add(msg)
}
func (ml *ConsensusMessageLog) Exists(msg types2.ConsensusMessage) bool {
return ml.messages.Contains(msg)
}
func (ml *ConsensusMessageLog) Get(typ types2.ConsensusMessageType, blockhash []byte) []*types2.ConsensusMessage {
2021-06-02 21:19:52 +00:00
var result []*types2.ConsensusMessage
for v := range ml.messages.Iter() {
2021-06-02 21:19:52 +00:00
msg := v.(types2.ConsensusMessage)
if msg.Block != nil {
}
if msg.Type == typ {
var msgBlockHash []byte
if msg.Block != nil {
msgBlockHash = msg.Block.Header.Hash
} else {
msgBlockHash = msg.Blockhash
}
if bytes.Compare(msgBlockHash, blockhash) == 0 {
result = append(result, &msg)
}
}
}
return result
}