-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Conversation
…I added a chainId() function to the libethereum\Interface class which returns 0 by default (since chainId values start @ 0x1 with MainNet), along with the corresponding function to libethereum\ClientBase which retrieves the current chain ID from BlockChain::chainParams. I then surfaced the function in the JSON-RPC API by adding it to libweb3jsonrpc\eth.json and regenerating EthFace.h via jsonrpcstub, and removing unnecessary changes from the generated file.
Codecov Report
@@ Coverage Diff @@
## develop #4975 +/- ##
===========================================
- Coverage 61.08% 61.01% -0.08%
===========================================
Files 350 350
Lines 28338 28319 -19
Branches 2884 2884
===========================================
- Hits 17310 17278 -32
- Misses 10069 10073 +4
- Partials 959 968 +9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides single nit, it looks good to me. @gumb0 would you double check it?
libethereum/ClientBase.h
Outdated
@@ -174,7 +174,9 @@ class ClientBase: public Interface | |||
} | |||
|
|||
Block block(BlockNumber _h) const; | |||
|
|||
|
|||
virtual int chainId() const override; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not repeat virtual
keyword if override
is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback @chfast! I followed the approach used by other functions in the class e.g.:
After reading more about the virtual and override keywords, it looks like neither of them are required:
- Virtual: This keyword is redundant because ClientBase::chainId() is implicitly virtual because it overrides a virtual function (Interface::chainId())
- Override: This keyword isn't required, but it can be help one avoid runtime bugs since it tells the compiler to verify that there's a function in the parent class with the same signature and to raise an error if that's not the case
As such, I think it makes sense to remove the virtual keyword. However, I can also see the value in keeping both keywords in the interest of code consistency. What are your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, override
is helpful and having both virtual
and override
is redundant. I'm fine with making it less consistent and leaving only override
.
You could also remove all other virtual
from other overridden methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gumb0, I've removed virtual from all of the ClientBase functions which override other functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
It would be great if you could also document how you generate stub files with jsonrpcstub, because usually no one can't make it work. |
…er functions since the keyword is redundant - these functions are implicitly virtual because they override virtual functions.
Fixes #4810
Implements https://github.com/ethereum/EIPs/blob/master/EIPS/eip-695.md
I added a
chainId()
function to thelibethereum\Interface
class which returns 0 by default (since chainId values start @ 0x1 with MainNet), along with the corresponding function tolibethereum\ClientBase
which retrieves the current chain id fromBlockChain::chainParams
. I then surfaced the function in the JSON-RPC API by adding it tolibweb3jsonrpc\eth.json
and regeneratingEthFace.h
viajsonrpcstub
, and removing unnecessary changes from the generated file.I tested my changes on Ubuntu with eth connected to Ropsten and a JSON-RPC server setup via the
jsonrpcproxy.py
script: