github.com/annchain/OG@v0.0.9/plugin/annsensus/handler.go (about)

     1  package annsensus
     2  
     3  import (
     4  	"github.com/annchain/OG/consensus/annsensus"
     5  	"github.com/annchain/OG/message"
     6  	"github.com/sirupsen/logrus"
     7  )
     8  
     9  type AnnsensusMessageMessageHandler struct {
    10  	AnnsensusPartner        *annsensus.AnnsensusPartner
    11  	AnnsensusMessageAdapter AnnsensusMessageAdapter
    12  }
    13  
    14  func (a AnnsensusMessageMessageHandler) Handle(msgEvent *message.GeneralMessageEvent) {
    15  	annsensusMessage, err := a.AnnsensusMessageAdapter.AdaptGeneralMessage(msgEvent.Message)
    16  	if err != nil {
    17  		logrus.WithError(err).Warn("failed to adapt og message to annsensus")
    18  		return
    19  	}
    20  	annsensusPeer, err := a.AnnsensusMessageAdapter.AdaptGeneralPeer(msgEvent.Sender)
    21  	if err != nil {
    22  		logrus.WithError(err).Warn("failed to adapt og peer to annsensus")
    23  		return
    24  	}
    25  
    26  	a.AnnsensusPartner.HandleAnnsensusMessage(&annsensus.AnnsensusMessageEvent{
    27  		Message: annsensusMessage,
    28  		Peer:    annsensusPeer,
    29  	})
    30  }