nlordell / ethrpc-rs

Ethereum transport-agnositic JSON RPC implementation
Apache License 2.0
2 stars 2 forks source link

Parse Error Signed Transaction (Geth Clients) #10

Open bh2smith opened 1 year ago

bh2smith commented 1 year ago

The transaction Responses return both fields "yParity" and "v" (which are equivalent).

Observe the difference in data for this request:

curl -X POST $NODE_URL --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0xe4e364", true],"id":1}' | jq '.result.transactions[0]'

when NODE_URL is ankr node vs quicknode or infura. Ankr returns a parsable response while the other two have "conflicting fields".

This is likely due to this:

  /// Y parity of the signature.
  #[serde(alias = "v")]
  pub y_parity: YParity,

Is there some way to intercept serde to remove the conflicting fields in the response before parsing? It seems that this will need to be handled here since there are multiple nodes returning this data.

Brought up also in #9

bh2smith commented 1 year ago

So, after some digging, it turns out the Geth still returns both:

https://github.com/ethereum/go-ethereum/blob/c5b7cfa9c3a9643138d608e49be5e79fb18ee5f4/internal/ethapi/api.go#L1417-L1441

v and yParity.

bh2smith commented 1 year ago

Best solution I have for now is the following:

#[derive(Clone, Eq, PartialEq, Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct SampleStruct {
    pub v: YParity,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub y_parity: Option<YParity>,
}

which parses both when json has v and when it has both.

bh2smith commented 1 year ago

Here is an example demonstrating the error (essentially any request for Hydrated Blocks)

https://github.com/bh2smith/ethrpc-tinker/pull/2