You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

67 lines
1.9 KiB

package privval
import (
"fmt"
"github.com/tendermint/tendermint/crypto"
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
privvalproto "github.com/tendermint/tendermint/proto/privval"
"github.com/tendermint/tendermint/types"
)
func DefaultValidationRequestHandler(
privVal types.PrivValidator,
req privvalproto.Message,
chainID string,
) (privvalproto.Message, error) {
var (
res privvalproto.Message
err error
)
switch r := req.Sum.(type) {
case *privvalproto.Message_PubKeyRequest:
var pubKey crypto.PubKey
pubKey, err = privVal.GetPubKey()
pk, err := cryptoenc.PubKeyToProto(pubKey)
if err != nil {
return res, err
}
if err != nil {
res = mustWrapMsg(&privvalproto.PubKeyResponse{
PubKey: nil, Error: &privvalproto.RemoteSignerError{Code: 0, Description: err.Error()}})
} else {
res = mustWrapMsg(&privvalproto.PubKeyResponse{PubKey: &pk, Error: nil})
}
case *privvalproto.Message_SignVoteRequest:
vote := r.SignVoteRequest.Vote
err = privVal.SignVote(chainID, vote)
if err != nil {
res = mustWrapMsg(&privvalproto.SignedVoteResponse{
Vote: nil, Error: &privvalproto.RemoteSignerError{Code: 0, Description: err.Error()}})
} else {
res = mustWrapMsg(&privvalproto.SignedVoteResponse{Vote: vote, Error: nil})
}
case *privvalproto.Message_SignProposalRequest:
proposal := r.SignProposalRequest.Proposal
err = privVal.SignProposal(chainID, &proposal)
if err != nil {
res = mustWrapMsg(&privvalproto.SignedProposalResponse{
Proposal: nil, Error: &privvalproto.RemoteSignerError{Code: 0, Description: err.Error()}})
} else {
res = mustWrapMsg(&privvalproto.SignedProposalResponse{Proposal: &proposal, Error: nil})
}
case *privvalproto.Message_PingRequest:
err, res = nil, mustWrapMsg(&privvalproto.PingResponse{})
default:
err = fmt.Errorf("unknown msg: %v", r)
}
return res, err
}