github.com/aergoio/aergo@v1.3.1/account/signer.go (about)

     1  package account
     2  
     3  import (
     4  	"github.com/aergoio/aergo-actor/actor"
     5  	"github.com/aergoio/aergo/account/key"
     6  	"github.com/aergoio/aergo/message"
     7  )
     8  
     9  type Signer struct {
    10  	keystore *key.Store
    11  }
    12  
    13  func NewSigner(s *key.Store) *Signer {
    14  	return &Signer{keystore: s}
    15  }
    16  
    17  //Receive actor message
    18  func (s *Signer) Receive(context actor.Context) {
    19  	switch msg := context.Message().(type) {
    20  	case *message.SignTx:
    21  		err := s.keystore.SignTx(msg.Tx, msg.Requester)
    22  		defer context.Self().Stop()
    23  		if err != nil {
    24  			context.Respond(&message.SignTxRsp{Tx: nil, Err: err})
    25  		} else {
    26  			//context.Tell(context.Sender(), &message.SignTxRsp{Tx: msg, Err: nil})
    27  			context.Respond(&message.SignTxRsp{Tx: msg.Tx, Err: nil})
    28  		}
    29  	}
    30  }