We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Geth version: v1.10.26 (but also in master branch)
v1.10.26
When {"result": null} is returned from a JSON RPC call in rpc.CallContext, it should unmarshal into a json.RawMessage as json.RawMessage("null").
{"result": null}
rpc.CallContext
json.RawMessage
json.RawMessage("null")
It actually gets unmarshalled as nil.
nil
--http
--ws
RPC_ENDPOINT
result
package main import ( "encoding/json" "fmt" "os" "github.com/ethereum/go-ethereum/rpc" ) func main() { client, err := rpc.Dial(os.Getenv("RPC_ENDPOINT")) if err != nil { panic(err) } defer client.Close() var result json.RawMessage invalidHash := "0x1234567890123456789012345678901234567890123456789012345678901234" err = client.Call(&result, "eth_getTransactionReceipt", invalidHash) if err != nil { panic(err) } if result == nil { panic("result should not be nil") } else { fmt.Printf("result: %s", result) } }
"result": null
The error seems to be caused by a redundant reference operator in rpc.Client.CallContext(), when the JSON unmarshaller is called.
rpc.Client.CallContext()
go-ethereum/rpc/client.go
Line 348 in dbd6c13
Line 321 already checks that result is a pointer, so there shouldn’t be any need to reference it again.
Lines 321 to 323 in dbd6c13
Upon further investigation, it seems that nested pointers will be set to nil specifically when decoding null values (https://go.dev/src/encoding/json/decode.go#L424).
null
The text was updated successfully, but these errors were encountered:
Closed in #26723
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
System information
Geth version:
v1.10.26
(but also in master branch)Expected behaviour
When
{"result": null}
is returned from a JSON RPC call inrpc.CallContext
, it should unmarshal into ajson.RawMessage
asjson.RawMessage("null")
.Actual behaviour
It actually gets unmarshalled as
nil
.Steps to reproduce the behaviour
--http
or--ws
RPC_ENDPOINT
environment variable to the URL of the networkresult
tojson.RawMessage("null")
result
isnil
"result": null
.Fix
The error seems to be caused by a redundant reference operator in
rpc.Client.CallContext()
, when the JSON unmarshaller is called.go-ethereum/rpc/client.go
Line 348 in dbd6c13
Line 321 already checks that
result
is a pointer, so there shouldn’t be any need to reference it again.go-ethereum/rpc/client.go
Lines 321 to 323 in dbd6c13
Upon further investigation, it seems that nested pointers will be set to
nil
specifically when decodingnull
values (https://go.dev/src/encoding/json/decode.go#L424).The text was updated successfully, but these errors were encountered: