Conversation
|
Are you sure the changelog does not need updating? |
3 similar comments
|
Are you sure the changelog does not need updating? |
|
Are you sure the changelog does not need updating? |
|
Are you sure the changelog does not need updating? |
| } | ||
| } | ||
|
|
||
| impl From<Address> for Hash { |
There was a problem hiding this comment.
That looks weird, why do we need to convert between an Address and a Hash?
There was a problem hiding this comment.
If we currently do this in production code and removing that is non-trivial, can you please record a follow-up issue?
There was a problem hiding this comment.
Okay interesting, I would put this functionality on the specific topic then and not as a generall conversion between addresses and hashes.
| impl Address { | ||
| pub fn from_slice(src: &[u8]) -> Self { | ||
| let mut address = Address([0u8; 20]); | ||
| address.0.copy_from_slice(src); |
There was a problem hiding this comment.
I think this can panic if the slice is not long enough, i.e. < 20 bytes. Can you please create a follow-up ticket for auditing the usages of this function with the goal of removing it?
| impl Hash { | ||
| pub fn from_slice(src: &[u8]) -> Self { | ||
| let mut h256 = Hash([0u8; 32]); | ||
| h256.0.copy_from_slice(src); |
There was a problem hiding this comment.
Same as above, this can panic and we should avoid using this function.
| match decision { | ||
| Some(Decision::Accepted) => { | ||
| match serde_json::from_value::<rfc003::messages::AcceptResponseBody<AI, BI>>( | ||
| response.body().clone(), |
There was a problem hiding this comment.
Nice, we are avoiding to calls to clone :)
| } | ||
| } | ||
|
|
||
| impl Display for Hash { |
There was a problem hiding this comment.
Eventually, I would like this Display implementation to not print ... but do what the implementation of LowerHex does.
We can then remove the implementation of LowerHex.
This will likely require a few changes to log statements in our code where we currently use {:x} to print the full transaction hash.
Can be done as a follow-up ticket :)
cnd/src/ethereum.rs
Outdated
| } | ||
| } | ||
|
|
||
| impl fmt::LowerHex for Address { |
There was a problem hiding this comment.
Instead of LowerHex, I would like us to use Display for printing the full address. That is much more natural in log statements.
cnd/src/ethereum.rs
Outdated
| mod tests { | ||
| use super::Log; | ||
| use crate::ethereum::TransactionReceipt; | ||
| use crate::ethereum::{Address, Hash, TransactionReceipt}; |
There was a problem hiding this comment.
Nit: If you do use super::* in tests modules, you automatically get all types from the parent module which are very likely the ones you want to test :)
| pub struct Block { | ||
| /// Hash of the block | ||
| pub hash: Option<H256>, | ||
| pub hash: Option<Hash>, |
There was a problem hiding this comment.
Can you record a follow-up issue for making this not an Option? It is so annoying 😬
primitive_types for Ethereum types such as Address and TransactionHash
primitive_types for Ethereum types such as Address and TransactionHashprimitive_types for Ethereum types such as Address and TransactionHash
f9126c7 to
96b9b39
Compare
96b9b39 to
3177357
Compare
|
bors r+ |
1 similar comment
|
bors r+ |
|
Already running a review |
Build succeeded |
This introduces the ethereum::Address type into our config::File struct. Unfortunately, this opens a can of worms with a bug in the serde-hex library. See [0] for more details. We work around this by removing the dependency on serde-hex from our Ethereum deserialization code and instead hand-roll everything for our usecase. This also has the advantage that we can now again just use our structs directly in the route handlers of warp instead of serde_json::Value. See [1] for more on this. [0]: fspmarshall/serde-hex#8 [1]: #2405
This introduces the ethereum::Address type into our config::File struct. Unfortunately, this opens a can of worms with a bug in the serde-hex library. See [0] for more details. We work around this by removing the dependency on serde-hex from our Ethereum deserialization code and instead hand-roll everything for our usecase. This also has the advantage that we can now again just use our structs directly in the route handlers of warp instead of serde_json::Value. See [1] for more on this. [0]: fspmarshall/serde-hex#8 [1]: #2405
This introduces the ethereum::Address type into our config::File struct. Unfortunately, this opens a can of worms with a bug in the serde-hex library. See [0] for more details. We work around this by removing the dependency on serde-hex from our Ethereum deserialization code and instead hand-roll everything for our usecase. This also has the advantage that we can now again just use our structs directly in the route handlers of warp instead of serde_json::Value. See [1] for more on this. [0]: fspmarshall/serde-hex#8 [1]: #2405
This introduces the ethereum::Address type into our config::File struct. Unfortunately, this opens a can of worms with a bug in the serde-hex library. See [0] for more details. We work around this by removing the dependency on serde-hex from our Ethereum deserialization code and instead hand-roll everything for our usecase. This also has the advantage that we can now again just use our structs directly in the route handlers of warp instead of serde_json::Value. See [1] for more on this. [0]: fspmarshall/serde-hex#8 [1]: #2405
This introduces the ethereum::Address type into our config::File struct. Unfortunately, this opens a can of worms with a bug in the serde-hex library. See [0] for more details. We work around this by removing the dependency on serde-hex from our Ethereum deserialization code and instead hand-roll everything for our usecase. This also has the advantage that we can now again just use our structs directly in the route handlers of warp instead of serde_json::Value. See [1] for more on this. [0]: fspmarshall/serde-hex#8 [1]: #2405
This introduces the ethereum::Address type into our config::File struct. Unfortunately, this opens a can of worms with a bug in the serde-hex library. See [0] for more details. We work around this by removing the dependency on serde-hex from our Ethereum deserialization code and instead hand-roll everything for our usecase. This also has the advantage that we can now again just use our structs directly in the route handlers of warp instead of serde_json::Value. See [1] for more on this. [0]: fspmarshall/serde-hex#8 [1]: #2405
This introduces the ethereum::Address type into our config::File struct. Unfortunately, this opens a can of worms with a bug in the serde-hex library. See [0] for more details. We work around this by removing the dependency on serde-hex from our Ethereum deserialization code and instead hand-roll everything for our usecase. This also has the advantage that we can now again just use our structs directly in the route handlers of warp instead of serde_json::Value. See [1] for more on this. [0]: fspmarshall/serde-hex#8 [1]: #2405
This introduces the ethereum::Address type into our config::File struct. Unfortunately, this opens a can of worms with a bug in the serde-hex library. See [0] for more details. We work around this by removing the dependency on serde-hex from our Ethereum deserialization code and instead hand-roll everything for our usecase. This also has the advantage that we can now again just use our structs directly in the route handlers of warp instead of serde_json::Value. See [1] for more on this. [0]: fspmarshall/serde-hex#8 [1]: #2405
This introduces the ethereum::Address type into our config::File struct. Unfortunately, this opens a can of worms with a bug in the serde-hex library. See [0] for more details. We work around this by removing the dependency on serde-hex from our Ethereum deserialization code and instead hand-roll everything for our usecase. This also has the advantage that we can now again just use our structs directly in the route handlers of warp instead of serde_json::Value. See [1] for more on this. [0]: fspmarshall/serde-hex#8 [1]: #2405
3071: Infer DAI token from Ethereum chain ID r=mergify[bot] a=thomaseizinger We are going to use this to avoid including the token contract address in the orders that we are sending around. This introduces the ethereum::Address type into our config::File struct. Unfortunately, this opens a can of worms with a bug in the serde-hex library. See [0] for more details. We work around this by removing the dependency on serde-hex from our Ethereum deserialization code and instead hand-roll everything for our usecase. This also has the advantage that we can now again just use our structs directly in the route handlers of warp instead of serde_json::Value. See [1] for more on this. [0]: fspmarshall/serde-hex#8 [1]: #2405 Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
H256(Hash) andH160(Address) are converted to our own types.Note that for deserialization we always have to pass the Hash/Address by reference, otherwise we don't reach the right code-path in serde hex. @thomaseizinger already tackled that problem.
Unfortunately, the
U256value in Ethereum is not fixed hex (although it actually is of fixed size, namely[u8, 32]).This leads to the problem, that we would have to implement our own
SerializerandDeserializerbecause serde-hex does not implementCompactfor[u8, 32].Implementing a custom
SerializerandDeserializeris, however, not trivial, because our hex library does not support compacted hex neither.I started pulling in the serialization and deserialization code from the parity codebase, but it is quite a lot of code to be pulled in, that is rather complicated.
Given, that this ticket was under the premise that we (most likely...) can just use serde-hex or our hex library for encoding/decoding the value, this is getting a rabbit hole. Since I already wasted quite some time on this ticket due to a tricky serde-hex bug I would put the implementation of
U256aside now and keep the dependency onprimitive_typesfor it.We can decide how/if we want to deal with
U256later. I am not sure we want to own the custom serialization/deserialization code, or if it is not better to useprimitive_types::U256.