Use Option for CallContract member 'data' #1076
Conversation
What do you think @D4nte and @luckysori in terms of the API? |
Yes a serialisation test when |
@tcharding Go for that then :) |
7f87858
to
601aa41
Compare
The enum variant |
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.
Great insight. Well done.
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.
The enum variant ActionResponseBody::EthereumCallContract uses a struct that has fields that mirror the ethereum::CallContract struct.
Sorry but this is actually very much on purpose!
- IMO the
CallContract
andDeployContract
structs are part of the COMIT core (we should soon start extracting that into its own crate to make that one clear). Hence, they shouldn't implement Serialize/Deserialize in order to not leak their inner structure. (Even if you were to implement Serialize, you should probablyderive
it in order to not having to write the implementation manually) - For Bitcoin, the data is actually different because there is a signing step that happens between emitting the action from the state and serializing it to the user.
For consistency reasons, I'd therefore not re-use those structs there. IMO that causes more confusion than it adds value in terms of de-duplication. It will look like a job half done which cannot be finished because what was done for Ethereum cannot be done for Bitcoin.
I'd say this applies in general. Separate data structures for any external facing communication is key if you want to avoid accidental breaking API changes through actions like renamed fields.
In order to fully embrace that (it is not enforced currently), we probably should do something like this:
EthereumCallContract {
contract_address: Http<ethereum_support::Address>,
data: Http<ethereum_support::Bytes>,
gas_limit: Http<ethereum_support::U256>,
network: Http<ethereum_support::Network>,
min_block_timestamp: Option<Http<Timestamp>>,
},
(Note that all types are wrapped in Http
). This would allow us to actually pin down the API and would increase awareness about breaking API changes since you have to actively change the impl Serialize for Http<ethereum_support::U256>
for example.
Taking over, I will just remove commit 601aa41 |
601aa41
to
41c6f7b
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.
looks legit :)
be1387f
to
929e9db
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.
I'm just blocking this as we have two approvals and we should not accidentally get the flaky test merged into master
This comment has been minimized.
This comment has been minimized.
Currently we use bytes.default() to generate an empty value for bytes array `data` in the `CallContract` structure. This results in the value `0x` being used (I do not know the exact reason). Rust has options for such a case. This needs testing, I have no idea what will now be expressed by the `None` in place of the original `0x` (FTR I do not know where the `Ox` is either :) Fixes: #999
`CallContract` has some `Option<T>` fields. When `CallContract` is serialized we would like field members that have the value `None` to be _not_ in the JSON string. Add failing unit test for serialization of `CallContract` with `None` valued fields.
`CallContract` has some `Option<T>` fields. When `CallContract` is serialized we would like field members that have the value `None` to be _not_ in the JSON string. Make failing unit test for serialization of `CallContract` with `None` valued fields pass.
84e3a5f
to
708aa89
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.
Good work Franck! 🎉
@@ -147,7 +147,7 @@ export class EthereumWallet { | |||
|
|||
public async sendEthTransactionTo( | |||
to: string, | |||
data: string = "0x0", |
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 stupid EthereumWallet
has bitten us so many times now, on bobtimus
as well as here in the tests.
I think we should extract what we have here into an NPM package and publish it. Basically an idiot-proof EthereumWallet
that cannot be used wrongly :D
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.
hahahahaha, yes I think it's worth considering and to give back to the community.
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.
Created ticket here: coblox/bobtimus#78
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.
Good job. That definitely was an easy-first-ticket
:D
Currently we use
bytes.default()
to generate an empty value for byte arraydata
member of theCallContract
structure. This results in the value0x
being used (I do not know the exact reason why or where this0x
is found, please see note below on testing). Rust has options for such a case.This needs testing, I have no idea what will now be expressed by the
None
in place of the original0x
.Fixes: #999