-
Notifications
You must be signed in to change notification settings - Fork 2.3k
On calls, pull defaultBlock from web3 #2964
Conversation
instead of always using 'latest.' See PR for detail.
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 the build is failing because of this
inside function() {}
, but that's easily corrected. I also suggested a bit of defensive coding with the || "latest"
, just to be on the safe side.
Apart from that, I think this change makes sense and shouldn't cause problems! Will approve once tests pass. Thanks for this!
@eggplantzzz if you have a second, could you get your eyes on this too? Would just like another opinion! |
in case defaultBlock is undefined, per suggestion by @gnidan, though seems likely unnecessary
Note that it's not 100% clear to me, having not yet fully tested this, whether changes to the global web3.eth.defaultBlock are reflected in the web3 referenced in the "this"/constructor object. If not, I think the edit would probably do no harm, but also not accomplish the intended goal. |
My guess is that almost certainly not, since @truffle/contract constructs its own web3 |
In that case, this should probably be considered an Issue report which had a specific suggested fix but where that suggestion was likely ultimately insufficient by itself. |
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.
This looks like it should be fine to add to me
Issue:
Function calls using @truffle/contract (
.call()
) act as ifweb3.eth.defaultBlock == 'latest'
, even when it isn't.The workaround is to add a parameter at the end of the parameter list for every
call()
which isweb3.eth.defaultBlock
.This is not intuitive, not consistent with a prior major version, and the change does not appear easy to find in documentation. It's also not clear that this is the best choice for behavior.
I think the behaviour is due to the line:
let defaultBlock = "latest";
That was added in this commit by @cgewecke back on Jun 10, 2018, but I can't really find why; I don't see any associated PR/discussion.
This PR proposes changing that line to
let defaultBlock = this.web3.eth.defaultBlock;
but hasn't been tested. The intended result includes: