github.com/pokt-network/tendermint@v0.32.11-0.20230426215212-59310158d3e9/privval/signer_requestHandler.go (about)

     1  package privval
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/tendermint/tendermint/crypto"
     7  	"github.com/tendermint/tendermint/types"
     8  )
     9  
    10  func DefaultValidationRequestHandler(
    11  	privVal types.PrivValidator,
    12  	req SignerMessage,
    13  	chainID string,
    14  ) (SignerMessage, error) {
    15  	var res SignerMessage
    16  	var err error
    17  
    18  	switch r := req.(type) {
    19  	case *PubKeyRequest:
    20  		var pubKey crypto.PubKey
    21  		pubKey, err = privVal.GetPubKey()
    22  		if err != nil {
    23  			res = &PubKeyResponse{nil, &RemoteSignerError{0, err.Error()}}
    24  		} else {
    25  			res = &PubKeyResponse{pubKey, nil}
    26  		}
    27  
    28  	case *SignVoteRequest:
    29  		err = privVal.SignVote(chainID, r.Vote)
    30  		if err != nil {
    31  			res = &SignedVoteResponse{nil, &RemoteSignerError{0, err.Error()}}
    32  		} else {
    33  			res = &SignedVoteResponse{r.Vote, nil}
    34  		}
    35  
    36  	case *SignProposalRequest:
    37  		err = privVal.SignProposal(chainID, r.Proposal)
    38  		if err != nil {
    39  			res = &SignedProposalResponse{nil, &RemoteSignerError{0, err.Error()}}
    40  		} else {
    41  			res = &SignedProposalResponse{r.Proposal, nil}
    42  		}
    43  
    44  	case *PingRequest:
    45  		err, res = nil, &PingResponse{}
    46  
    47  	default:
    48  		err = fmt.Errorf("unknown msg: %v", r)
    49  	}
    50  
    51  	return res, err
    52  }