eqlabs / pathfinder

A Starknet full node written in Rust
https://eqlabs.github.io/pathfinder/
Other
632 stars 234 forks source link

Remove `Felt` serde #884

Open Mirko-von-Leipzig opened 1 year ago

Mirko-von-Leipzig commented 1 year ago

Follow-up issue from #881.

We should aim at removing serde capabilities from Felt and its newtype wrappers in pathfinder_common. Serde specifics should be handled by each component directly. This lets us decouple components more correctly.

Mirko-von-Leipzig commented 1 year ago

I think for json serde (rpc & gateway) we should consider a proc macro. Things we want to achieve:

  1. Hex (with and without 0x prefix) and bigint decimal string serde, often for the same base type, but differently for rpc and gateway serde.
  2. Use the original type - not crate specific types in the API
  3. Minimal manual typing

I'm thinking we should be able to do annotations like:

    #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
    #[serde(deny_unknown_fields)]
    pub struct L1ToL2Message {
        #[pf_serde("Hex")]
        pub from_address: EthereumAddress,
        #[pf_serde("Vec<Decimal>")]
        pub payload: Vec<L1ToL2MessagePayloadElem>,
        #[pf_serde("Hex")]
        pub selector: EntryPoint,
        #[pf_serde("Hex")]
        pub to_address: ContractAddress,
        #[serde(default)]
        #[pf_serde("Option<Hex>")]
        pub nonce: Option<L1ToL2MessageNonce>,
    }