-
Notifications
You must be signed in to change notification settings - Fork 146
Implement eth_getTransactionByHash, eth_getTransactionReceipt JSON RPC function #122
Implement eth_getTransactionByHash, eth_getTransactionReceipt JSON RPC function #122
Conversation
Implementing the |
34f913c
to
96ce0ac
Compare
96ce0ac
to
9588f8b
Compare
I think CI failures are due to recent merge of #121 and you need to rename |
@Bhargavasomu the chain inside the RPC module moved from |
9588f8b
to
3d40010
Compare
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.
To make this work for light clients as well we need to implement coro_get_canoncal_transaction
on the BaseAsyncChain
and all the implementing chains and then use that instead.
trinity/rpc/modules/eth.py
Outdated
@@ -247,6 +247,11 @@ def name(self) -> str: | |||
nonce = account_db.get_nonce(address) | |||
return hex(nonce) | |||
|
|||
@format_params(decode_hex) | |||
async def getTransactionByHash(self, transaction_hash: Hash32) -> Dict[str, str]: | |||
transaction = self.chain.get_canonical_transaction(transaction_hash) |
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.
Actually, I just noticed that this may not be correct. The modules work on a BaseAsyncChain
which is primary because of the light client support where certain type of data (including this) needs to be fetched from peers. So if this API is intended to work for light clients as well (which I think it should) then, this needs to be fetched via a coro_get_canonical_transaction
API which also needs to be implemented first.
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.
@cburgdorf can this function coro_get_canonical_transaction
be also added to the AsyncChainMixin
as async_method(get_canonical_transaction)
, or does it need an explicit implementation as far as the API goes?
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, it would need an abstract method on BaseAsyncChainAPI
and then an implementation of AsyncChainMixin
(see my comment here https://github.com/ethereum/trinity/pull/122/files#r252588196)
3d40010
to
d507533
Compare
@pipermerriam @cburgdorf review please. Also based on the above arguments, I guess even |
@cburgdorf can I hand this over to you to finish review. @Bhargavasomu I believe you are correct that the other methods should also be using |
Sorry, I missed this. I'll take a look at it tomorrow. |
trinity/rpc/modules/eth.py
Outdated
async def getTransactionReceipt( | ||
self, | ||
transaction_hash: Hash32) -> Dict[str, Union[str, List[Log]]]: | ||
transaction_block_number, transaction_index = self.chain.chaindb.get_transaction_index( |
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.
Digging into self.chain.chaindb
is violating the expected encapsulation. All modules should only work on the public API of the BaseAsyncChain
.
I propose to add get_transaction_receipt
to the BaseChain
and then also add a coro_get_transaction_receipt
to the BaseAsyncChainAPI
and add an implementation in AsyncChainMixin
.
And then this code here would use self.chain.get_transaction_receipt
d507533
to
ba4ae5d
Compare
ba4ae5d
to
d752899
Compare
@cburgdorf I have now added the |
def get_transaction_receipt(self, transaction_hash: Hash32) -> Receipt: | ||
raise NotImplementedError("Chain classes must implement " + inspect.stack()[0][3]) | ||
|
||
async def coro_get_transaction_receipt(self, transaction_hash: Hash32) -> Receipt: |
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.
Shouldn't this provide an actual implementation?
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.
I think this is still missing implementations for the LightDispatchChain
. It would be really cool if we had actual tests backing this. But I know this might be a bit too much to ask for this PR.
@@ -203,6 +203,15 @@ def create_unsigned_transaction(cls, | |||
def get_canonical_transaction(self, transaction_hash: Hash32) -> BaseTransaction: | |||
raise NotImplementedError("Chain classes must implement " + inspect.stack()[0][3]) | |||
|
|||
async def coro_get_canonical_transaction(self, transaction_hash: Hash32) -> BaseTransaction: | |||
raise NotImplementedError("Chain classes must implement " + inspect.stack()[0][3]) |
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.
Shouldn't this also provide an implementation?
What was wrong?
As part of Issue #26 and also #20.
How was it fixed?
This spec was followed
Cute Animal Picture