From 274f2c04087d5aaf585eaf05dfc17b0528b3ffcb Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Sat, 10 Apr 2021 00:31:42 +0300 Subject: [PATCH 1/2] rpc/server: be more specific in some sendrawtransaction error cases Refs. #1894. --- pkg/rpc/server/server.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 93356c421..2a64d1383 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -1419,15 +1419,15 @@ func (s *Server) submitOracleResponse(ps request.Params) (interface{}, *response func (s *Server) sendrawtransaction(reqParams request.Params) (interface{}, *response.Error) { if len(reqParams) < 1 { - return nil, response.ErrInvalidParams + return nil, response.NewInvalidParamsError("not enough parameters", nil) } byteTx, err := reqParams[0].GetBytesBase64() if err != nil { - return nil, response.ErrInvalidParams + return nil, response.NewInvalidParamsError("not base64", err) } tx, err := transaction.NewTransactionFromBytes(byteTx) if err != nil { - return nil, response.ErrInvalidParams + return nil, response.NewInvalidParamsError("can't decode transaction", err) } return getRelayResult(s.coreServer.RelayTxn(tx), tx.Hash()) } From 13619a0e77a3be5dcc3c341645d22aeed402b178 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Sat, 10 Apr 2021 22:47:24 +0300 Subject: [PATCH 2/2] rpc/server: improve submitblock and submitnotaryrequest also --- pkg/rpc/server/server.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 2a64d1383..72932a704 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -1325,13 +1325,13 @@ func (s *Server) runScriptInVM(t trigger.Type, script []byte, contractScriptHash func (s *Server) submitBlock(reqParams request.Params) (interface{}, *response.Error) { blockBytes, err := reqParams.ValueWithType(0, request.StringT).GetBytesBase64() if err != nil { - return nil, response.ErrInvalidParams + return nil, response.NewInvalidParamsError("missing parameter or not base64", err) } b := block.New(s.stateRootEnabled) r := io.NewBinReaderFromBuf(blockBytes) b.DecodeBinary(r) if r.Err != nil { - return nil, response.ErrInvalidParams + return nil, response.NewInvalidParamsError("can't decode block", r.Err) } err = s.chain.AddBlock(b) if err != nil { @@ -1354,15 +1354,15 @@ func (s *Server) submitNotaryRequest(ps request.Params) (interface{}, *response. } if len(ps) < 1 { - return nil, response.ErrInvalidParams + return nil, response.NewInvalidParamsError("not enough parameters", nil) } bytePayload, err := ps[0].GetBytesBase64() if err != nil { - return nil, response.ErrInvalidParams + return nil, response.NewInvalidParamsError("not base64", err) } r, err := payload.NewP2PNotaryRequestFromBytes(bytePayload) if err != nil { - return nil, response.ErrInvalidParams + return nil, response.NewInvalidParamsError("can't decode notary payload", err) } return getRelayResult(s.coreServer.RelayP2PNotaryRequest(r), r.FallbackTransaction.Hash()) }