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: use RPCBlock,RPCHeader instead of interface #27305

Closed
wants to merge 20 commits into from

Conversation

jsvisa
Copy link
Contributor

@jsvisa jsvisa commented May 19, 2023

This is a follow-up PR by #27265, If it's OK I'll add more test cases for getXXX's response to ensure no alter the spec of RPC's response.

jsvisa and others added 8 commits June 20, 2023 12:33
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
@jsvisa jsvisa changed the title internal/ethapi: use RPCBlock,RPCReceipt instead of interface internal/ethapi: use RPCBlock,RPCHeader instead of interface Jun 20, 2023
@jsvisa jsvisa marked this pull request as ready for review June 20, 2023 08:26
internal/ethapi/api_test.go Outdated Show resolved Hide resolved
internal/ethapi/api.go Outdated Show resolved Hide resolved
internal/ethapi/api.go Show resolved Hide resolved
internal/ethapi/api.go Outdated Show resolved Hide resolved
internal/ethapi/api.go Outdated Show resolved Hide resolved
internal/ethapi/api.go Outdated Show resolved Hide resolved
internal/ethapi/api.go Outdated Show resolved Hide resolved
jsvisa added 10 commits June 23, 2023 22:50
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
…le block

Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
…null

Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
@jsvisa jsvisa requested a review from lightclient June 29, 2023 01:23
ReceiptHash common.Hash `json:"receiptsRoot"`
BaseFee *hexutil.Big `json:"baseFeePerGas,omitempty"`
WithdrawalsHash *common.Hash `json:"withdrawalsRoot,omitempty"`
TotalDifficulty *hexutil.Big `json:"totalDifficulty"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
TotalDifficulty *hexutil.Big `json:"totalDifficulty"`
TotalDifficulty *hexutil.Big `json:"totalDifficulty,omitEmpty"`

Why not omit empty and get rid of the null values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the totalDifficulty of get{Header,Block}ByNumber's response is null

Uploading image.png…

Comment on lines +767 to +768
want, have := tc.want, string(out)
require.JSONEqf(t, want, have, "test %d: json not match, want: %s, have: %s", i, want, have)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why changing the raw string comparison into a json-equality check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems the JSON serialization order is differ

@holiman
Copy link
Contributor

holiman commented Aug 1, 2023

We've discussed this PR in triage, and decided not to include it: the addition of these new types does not seem to bring sufficient advantages.
These types are also in an internal package, and thus does not help external users either.
Thanks for the effort you put in!

@jsvisa
Copy link
Contributor Author

jsvisa commented Aug 1, 2023

@holiman anyway, thanks for your reply.

These types are also in an internal package, and thus does not help external users either.

I want to declare them first in the internal package, if this PR was merged, I'm considering moving them out into some package like rpc/jsonrpc or other names. do you think this is feasible?

@lightclient
Copy link
Member

rpc is a generic rpc package so I don't think it would be good to move the eth-specific definitions into that package. What use would exporting these values serve though? We generally use ethclient as the go interface for rpc values?

@jsvisa
Copy link
Contributor Author

jsvisa commented Aug 1, 2023

Here is a transaction example, in ethclient we did can retrieve the transaction body via TransactionByHash, but the response is tx *types.Transaction, which missing some import fields(blockNumber, blockHash, From) while the raw eth_getTransactionByHash RPC can retrieve those fields.

For this case seems we can make this struct into a public one:

type rpcTransaction struct {
,

or this txJSON into a public one:

BTW, does anyone know why we return this function as tx, isPending, error without blockNumber, blockHash, From fields?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

> content://media/external/downloads/1000000694
3 participants