Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support bytes20 and bytes32 in Ethereum contract bindings #116

Merged
merged 2 commits into from
May 1, 2023

Conversation

pdyraga
Copy link
Member

@pdyraga pdyraga commented May 1, 2023

There are quite a few functions in our Solidity contracts that accept bytes20 or bytes32 as a parameter. One of many examples are requestHeartbeat(bytes20 walletPubKeyHash, bytes calldata message) from the WalletCoordinator contract and getWallet(bytes32 walletID) from the WalletRegistry contract. Given there was no parsing function defined in our Ethereum contract parsing logic, all functions accepting bytes32 and bytes20 were skipped during the code generation:

WARNING: Unsupported param type for method getWallet:
  ABI Type: bytes32
  Go Type:  [32]byte
  the method won't be callable with 'ethereum' command

This changeset adds two parsing functions: one for bytes20 and another for bytes32 Solidity type. In theory, we could have other variations of bytesN 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 all bytesN 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 execute make all. You will see a bunch of warnings like this:

WARNING: Unsupported param type for method getWallet:
  ABI Type: bytes32
  Go Type:  [32]byte
  the method won't be callable with 'ethereum' command
WARNING: Unsupported param type for method isWalletRegistered:
  ABI Type: bytes32
  Go Type:  [32]byte
  the method won't be callable with 'ethereum' command
WARNING: Unsupported param type for method isWalletMember:
  ABI Type: bytes32
  Go Type:  [32]byte
  the method won't be callable with 'ethereum' command

Check out this branch locally, go to keep-network/keep-core repository, and add replace directive in go.mod to point to the checked-out code. In my case, it is github.com/keep-network/keep-common => /Users/piotr/git/keep-network/keep-common. Then run make 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:

$ ./keep-client ethereum tbtc wallet-coordinator request-heartbeat \
0x3805eed0bb0792eff8815addedb36add2c7257e5 \
0xFFFFFFFFFFFFFFFF0000000000000000 \
--config configs/config.deployer.toml --submit

There are quite a few functions in our Solidity contracts that accept `bytes20`
or `bytes32` as a parameter. One of many examples are
`requestHeartbeat(bytes20 walletPubKeyHash, bytes calldata message)` from the
`WalletCoordinator` contract and `getWallet(bytes32 walletID)` from the
`WalletRegistry` contract. Given there was no parsing function defined in our
Ethereum contract parsing logic, all functions accepting `bytes32` and `bytes20`
were skipped during the code generation:

```
WARNING: Unsupported param type for method getWallet:
  ABI Type: bytes32
  Go Type:  [32]byte
  the method won't be callable with 'ethereum' command
```

This changeset adds two parsing functions: one for `bytes20` and another for
`bytes32` Solidity type. In theory, we could have other variations of `bytesN`
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 all `bytesN` types, it is enough
for now.
@pdyraga pdyraga self-assigned this May 1, 2023
@pdyraga pdyraga requested a review from lukasz-zimnoch May 1, 2023 11:56
pkg/utils/decode/bytes.go Show resolved Hide resolved
pkg/utils/decode/bytes.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants