github.com/aergoio/aergo@v1.3.1/mempool/txverifier.go (about)

     1  package mempool
     2  
     3  import (
     4  	"github.com/aergoio/aergo-actor/actor"
     5  	"github.com/aergoio/aergo/message"
     6  	"github.com/aergoio/aergo/types"
     7  )
     8  
     9  type TxVerifier struct {
    10  	mp *MemPool
    11  }
    12  
    13  func NewTxVerifier(p *MemPool) *TxVerifier {
    14  	return &TxVerifier{mp: p}
    15  }
    16  
    17  //Receive actor message
    18  func (s *TxVerifier) Receive(context actor.Context) {
    19  	switch msg := context.Message().(type) {
    20  	case *types.Tx:
    21  		var err error
    22  		if s.mp.exist(msg.GetHash()) != nil {
    23  			err = types.ErrTxAlreadyInMempool
    24  		} else {
    25  			tx := types.NewTransaction(msg)
    26  			err = s.mp.verifyTx(tx)
    27  			if err == nil {
    28  				err = s.mp.put(tx)
    29  			}
    30  		}
    31  		context.Respond(&message.MemPoolPutRsp{Err: err})
    32  	}
    33  }