cmd/pushtx: address code review feedback

Co-authored-by: drQedwards <213266729+drQedwards@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-12 15:58:03 +00:00
parent 17ef318c42
commit b91a437b09
2 changed files with 14 additions and 4 deletions

View file

@ -85,7 +85,7 @@ func run(args []string, stdin io.Reader) error {
txHex = strings.TrimSpace(string(data)) txHex = strings.TrimSpace(string(data))
} }
if txHex == "" { if txHex == "" {
return fmt.Errorf("no transaction data provided\nUsage: pushtx [--rpc URL] <tx-hex>") return fmt.Errorf("no transaction data provided (see --help for usage)")
} }
rawTx, err := hex.DecodeString(strings.TrimPrefix(txHex, "0x")) rawTx, err := hex.DecodeString(strings.TrimPrefix(txHex, "0x"))

View file

@ -98,10 +98,20 @@ func fakeRPC(t *testing.T, wantErr bool) *httptest.Server {
} }
// Decode the raw tx to return its hash as the result. // Decode the raw tx to return its hash as the result.
var hexData string var hexData string
json.Unmarshal(req.Params[0], &hexData) if err := json.Unmarshal(req.Params[0], &hexData); err != nil {
rawBytes, _ := hexutil.Decode(hexData) 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 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{}{ json.NewEncoder(w).Encode(map[string]interface{}{
"jsonrpc": "2.0", "jsonrpc": "2.0",
"id": req.ID, "id": req.ID,