diff --git a/cmd/pushtx/main.go b/cmd/pushtx/main.go index 674176a996..eb936c7850 100644 --- a/cmd/pushtx/main.go +++ b/cmd/pushtx/main.go @@ -85,7 +85,7 @@ func run(args []string, stdin io.Reader) error { txHex = strings.TrimSpace(string(data)) } if txHex == "" { - return fmt.Errorf("no transaction data provided\nUsage: pushtx [--rpc URL] ") + return fmt.Errorf("no transaction data provided (see --help for usage)") } rawTx, err := hex.DecodeString(strings.TrimPrefix(txHex, "0x")) diff --git a/cmd/pushtx/main_test.go b/cmd/pushtx/main_test.go index 101c3e8a22..972edf100b 100644 --- a/cmd/pushtx/main_test.go +++ b/cmd/pushtx/main_test.go @@ -98,10 +98,20 @@ func fakeRPC(t *testing.T, wantErr bool) *httptest.Server { } // Decode the raw tx to return its hash as the result. var hexData string - json.Unmarshal(req.Params[0], &hexData) - rawBytes, _ := hexutil.Decode(hexData) + if err := json.Unmarshal(req.Params[0], &hexData); err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + rawBytes, err := hexutil.Decode(hexData) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } var tx types.Transaction - tx.UnmarshalBinary(rawBytes) + if err := tx.UnmarshalBinary(rawBytes); err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } json.NewEncoder(w).Encode(map[string]interface{}{ "jsonrpc": "2.0", "id": req.ID,