Skip to content
New issue

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

internal/ethapi: add comment explaining return of nil instead of error #25097

Merged
merged 4 commits into from
Jun 16, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,8 @@ func (s *PublicTransactionPoolAPI) GetRawTransactionByHash(ctx context.Context,
func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) {
tx, blockHash, blockNumber, index, err := s.b.GetTransaction(ctx, hash)
if err != nil {
// Returns nil on purpose instead of err
// When the transaction doesn't exist, the return value of this RPC call should be JSON null.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can also be invoked from the Geth console so I'm not sure mentioning the JSON encoding of a nil return from this function makes sense here.

Copy link
Contributor

@fjl fjl Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The console also calls this method via JSON-RPC, and the return value will be null in this case as well. The comment makes sense because returning null in the 'not-found' case is a general convention in the web3 JSON-RPC API, but it looks weird in Go.

return nil, nil
}
receipts, err := s.b.GetReceipts(ctx, blockHash)
Expand Down