Fix raw transaction signing middleware with byte addresses #1067
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What was wrong?
Using
web3.middleware.construct_sign_and_send_raw_middleware
withbytes
typed addresses caused improper behaviour in at least the following cases:bytes
typed address as thefrom
address, in which case the middleware got never executed because the checktransaction.get('from') not in accounts
always evaluated asTrue
bytes
typed address as theto
address (for an instance, when doingweb3.eth.contract(address=bytes(...), ...)
), which resulted in an exception.How was it fixed?
The transaction is now formatted according to the transaction abi types in
sign_and_send_raw_middleware
(similar to what's done withabi_middleware
).I'm not totally sure about the fix, since I don't know web3.py internals that well. I discussed this issue with @voith and he encouraged me to submit a fix though. Any feedback is appreciated :) .
Cute Animal Picture