alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
763 stars 137 forks source link

Derive Serialize/Deserialize if possible #611

Closed wtdcode closed 4 months ago

wtdcode commented 4 months ago

Motivation

Derive Serialize/Deserialize if possible (with serde dep).

Solution

See diff.

PR Checklist

prestwich commented 4 months ago

We do not intend these values to be (de)serialized, as they do not correspond to any standard data forma. We aren't really interested in pushing a new standard. For now, all of these types should be in-memory only

Closing as not planned

wtdcode commented 4 months ago

We do not intend these values to be (de)serialized, as they do not correspond to any standard data forma. We aren't really interested in pushing a new standard. For now, all of these types should be in-memory only

Closing as not planned

I can't understand. It's mostly harmless.

wtdcode commented 4 months ago

https://github.com/rust-ethereum/ethabi/blob/b1710adc18f5b771d2d2519c87248b1ba9430778/ethabi/src/token/token.rs#L21

Note ethabi also has these. If alloy is intended as an alternative to ethers-rs, it should also enable these derives, no? See https://github.com/gakonst/ethers-rs/issues/2667. Not having these derives prevents migration from ethers-rs to alloy/core.

Even just "in memory`, this enables it to represent in other format.

wtdcode commented 4 months ago

For tracking pupose, https://serde.rs/remote-derive.html also doesn't work:

error[E0277]: the trait bound `DynSolValue: Deserialize<'_>` is not satisfied
    --> -:21:15
     |
21   |         Tuple(Vec<DynSolValue>),
     |               ^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `DynSolValue`, which is required by `Vec<DynSolValue>: Deserialize<'_>`
     |
     = help: the following other types implement trait `Deserialize<'de>`:
               <bool as Deserialize<'de>>
               <char as Deserialize<'de>>
               <isize as Deserialize<'de>>
               <i8 as Deserialize<'de>>
               <i16 as Deserialize<'de>>
               <i32 as Deserialize<'de>>
               <i64 as Deserialize<'de>>
               <i128 as Deserialize<'de>>
             and 493 others
     = note: required for `Vec<DynSolValue>` to implement `Deserialize<'_>`