Support bytes20 and bytes32 in Ethereum contract bindings #116
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.
There are quite a few functions in our Solidity contracts that accept
bytes20
orbytes32
as a parameter. One of many examples arerequestHeartbeat(bytes20 walletPubKeyHash, bytes calldata message)
from theWalletCoordinator
contract andgetWallet(bytes32 walletID)
from theWalletRegistry
contract. Given there was no parsing function defined in our Ethereum contract parsing logic, all functions acceptingbytes32
andbytes20
were skipped during the code generation:This changeset adds two parsing functions: one for
bytes20
and another forbytes32
Solidity type. In theory, we could have other variations ofbytesN
but this is not the case for our codebase, and defining a generic function is more complicated given we do not deal with slices but fixed-size arrays. Even though the proposed solution does not work for allbytesN
types, it is enough for now.Testing
Testing this change is easy.
First, see how it works without this change. Go to your
keep-network/keep-core
repository copy and executemake all
. You will see a bunch of warnings like this:Check out this branch locally, go to
keep-network/keep-core
repository, and add replace directive ingo.mod
to point to the checked-out code. In my case, it isjackfan.us.kg/keep-network/keep-common => /Users/piotr/git/keep-network/keep-common
. Then runmake all
again.All warnings should be gone and you should see the code generated for the previously skipped functions.
I did this testing locally and I was able to call some functions with the generated code. Example: