Skip to content

Commit

Permalink
Add allow-missing-fields feature
Browse files Browse the repository at this point in the history
  • Loading branch information
leoyvens committed Aug 2, 2022
1 parent 46b9baa commit 6505d41
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -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]
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -131,3 +131,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.
14 changes: 7 additions & 7 deletions src/types/block.rs
Expand Up @@ -11,7 +11,7 @@ pub struct BlockHeader {
pub parent_hash: H256,
/// Hash of the uncles
#[serde(rename = "sha3Uncles")]
#[serde(default)]
#[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")]
Expand All @@ -32,7 +32,7 @@ pub struct BlockHeader {
pub gas_used: U256,
/// Gas Limit
#[serde(rename = "gasLimit")]
#[serde(default)]
#[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")]
Expand All @@ -46,7 +46,7 @@ pub struct BlockHeader {
/// Timestamp
pub timestamp: U256,
/// Difficulty
#[serde(default)]
#[cfg_attr(feature = "allow-missing-fields", serde(default))]
pub difficulty: U256,
/// Mix Hash
#[serde(rename = "mixHash")]
Expand All @@ -66,7 +66,7 @@ pub struct Block<TX> {
pub parent_hash: H256,
/// Hash of the uncles
#[serde(rename = "sha3Uncles")]
#[serde(default)]
#[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")]
Expand All @@ -87,7 +87,7 @@ pub struct Block<TX> {
pub gas_used: U256,
/// Gas Limit
#[serde(rename = "gasLimit")]
#[serde(default)]
#[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")]
Expand All @@ -101,7 +101,7 @@ pub struct Block<TX> {
/// Timestamp
pub timestamp: U256,
/// Difficulty
#[serde(default)]
#[cfg_attr(feature = "allow-missing-fields", serde(default))]
pub difficulty: U256,
/// Total difficulty
#[serde(rename = "totalDifficulty")]
Expand All @@ -110,7 +110,7 @@ pub struct Block<TX> {
#[serde(default, rename = "sealFields")]
pub seal_fields: Vec<Bytes>,
/// Uncles' hashes
#[serde(default)]
#[cfg_attr(feature = "allow-missing-fields", serde(default))]
pub uncles: Vec<H256>,
/// Transactions
pub transactions: Vec<TX>,
Expand Down
4 changes: 2 additions & 2 deletions src/types/trace_filtering.rs
Expand Up @@ -160,7 +160,7 @@ pub struct CallResult {
#[serde(rename = "gasUsed")]
pub gas_used: U256,
/// Output bytes
#[serde(default)]
#[cfg_attr(feature = "allow-missing-fields", serde(default))]
pub output: Bytes,
}

Expand Down Expand Up @@ -188,7 +188,7 @@ pub struct Call {
/// Gas
pub gas: U256,
/// Input data
#[serde(default)]
#[cfg_attr(feature = "allow-missing-fields", serde(default))]
pub input: Bytes,
/// The type of the call.
#[serde(rename = "callType")]
Expand Down

0 comments on commit 6505d41

Please sign in to comment.