diff --git a/Cargo.toml b/Cargo.toml index fd0cfe7f..7a85c91c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,5 +84,6 @@ ws-tls-async-std = ["async-native-tls", "async-native-tls/runtime-async-std", "w ipc-tokio = ["tokio", "tokio-stream", "tokio-util"] arbitrary_precision = ["serde_json/arbitrary_precision", "jsonrpc-core/arbitrary_precision"] test = [] +allow-missing-fields = [] [workspace] diff --git a/README.md b/README.md index ee148897..41dab7b2 100644 --- a/README.md +++ b/README.md @@ -136,3 +136,6 @@ The library supports following features: - `eip-1193` - Enable EIP-1193 support. - `wasm` - Compile for WASM (make sure to disable default features). - `arbitrary_precision` - Enable `arbitrary_precision` in `serde_json`. +- `allow-missing-fields` - Some response fields are mandatory in Ethereum but not present in + EVM-compatible chains such as Celo and Fantom. This feature enables compatibility by setting a + default value on those fields. diff --git a/src/types/block.rs b/src/types/block.rs index fb790879..0c5ff9ea 100644 --- a/src/types/block.rs +++ b/src/types/block.rs @@ -11,6 +11,7 @@ pub struct BlockHeader { pub parent_hash: H256, /// Hash of the uncles #[serde(rename = "sha3Uncles")] + #[cfg_attr(feature = "allow-missing-fields", serde(default))] pub uncles_hash: H256, /// Miner/author's address. #[serde(rename = "miner", default, deserialize_with = "null_to_default")] @@ -31,6 +32,7 @@ pub struct BlockHeader { pub gas_used: U256, /// Gas Limit #[serde(rename = "gasLimit")] + #[cfg_attr(feature = "allow-missing-fields", serde(default))] pub gas_limit: U256, /// Base fee per unit of gas (if past London) #[serde(rename = "baseFeePerGas", skip_serializing_if = "Option::is_none")] @@ -44,6 +46,7 @@ pub struct BlockHeader { /// Timestamp pub timestamp: U256, /// Difficulty + #[cfg_attr(feature = "allow-missing-fields", serde(default))] pub difficulty: U256, /// Mix Hash #[serde(rename = "mixHash")] @@ -63,6 +66,7 @@ pub struct Block { pub parent_hash: H256, /// Hash of the uncles #[serde(rename = "sha3Uncles")] + #[cfg_attr(feature = "allow-missing-fields", serde(default))] pub uncles_hash: H256, /// Miner/author's address. #[serde(rename = "miner", default, deserialize_with = "null_to_default")] @@ -83,6 +87,7 @@ pub struct Block { pub gas_used: U256, /// Gas Limit #[serde(rename = "gasLimit")] + #[cfg_attr(feature = "allow-missing-fields", serde(default))] pub gas_limit: U256, /// Base fee per unit of gas (if past London) #[serde(rename = "baseFeePerGas", skip_serializing_if = "Option::is_none")] @@ -96,6 +101,7 @@ pub struct Block { /// Timestamp pub timestamp: U256, /// Difficulty + #[cfg_attr(feature = "allow-missing-fields", serde(default))] pub difficulty: U256, /// Total difficulty #[serde(rename = "totalDifficulty")] @@ -104,6 +110,7 @@ pub struct Block { #[serde(default, rename = "sealFields")] pub seal_fields: Vec, /// Uncles' hashes + #[cfg_attr(feature = "allow-missing-fields", serde(default))] pub uncles: Vec, /// Transactions pub transactions: Vec, diff --git a/src/types/trace_filtering.rs b/src/types/trace_filtering.rs index 250445db..5909fef2 100644 --- a/src/types/trace_filtering.rs +++ b/src/types/trace_filtering.rs @@ -160,6 +160,7 @@ pub struct CallResult { #[serde(rename = "gasUsed")] pub gas_used: U256, /// Output bytes + #[cfg_attr(feature = "allow-missing-fields", serde(default))] pub output: Bytes, } @@ -187,6 +188,7 @@ pub struct Call { /// Gas pub gas: U256, /// Input data + #[cfg_attr(feature = "allow-missing-fields", serde(default))] pub input: Bytes, /// The type of the call. #[serde(rename = "callType")]