Skip to content
Snippets Groups Projects
Unverified Commit fb98291e authored by PG Herveou's avatar PG Herveou Committed by GitHub
Browse files

[pallet-revive] Add support for eip1898 block notation (#7848)


[pallet-revive] Add support for eip1898 block notation
https://eips.ethereum.org/EIPS/eip-1898

---------

Co-authored-by: default avatarcmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
parent 2a239206
No related merge requests found
Pipeline #518627 waiting for manual action with stages
in 10 minutes and 54 seconds
title: '[pallet-revive] Add support for eip1898 block notation'
doc:
- audience: Runtime Dev
description: |-
[pallet-revive] Add support for eip1898 block notation
https://eips.ethereum.org/EIPS/eip-1898
crates:
- name: pallet-revive
bump: patch
......@@ -167,9 +167,7 @@ impl Default for BlockNumberOrTag {
}
/// Block number, tag, or block hash
#[derive(
Debug, Clone, Encode, Decode, TypeInfo, Serialize, Deserialize, From, TryInto, Eq, PartialEq,
)]
#[derive(Debug, Clone, Encode, Decode, TypeInfo, Serialize, From, TryInto, Eq, PartialEq)]
#[serde(untagged)]
pub enum BlockNumberOrTagOrHash {
/// Block number
......@@ -185,6 +183,41 @@ impl Default for BlockNumberOrTagOrHash {
}
}
// Support nested object notation as defined in https://eips.ethereum.org/EIPS/eip-1898
impl<'a> serde::Deserialize<'a> for BlockNumberOrTagOrHash {
fn deserialize<D>(de: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'a>,
{
#[derive(Deserialize)]
#[serde(untagged)]
pub enum BlockNumberOrTagOrHashWithAlias {
BlockTag(BlockTag),
U256(U256),
BlockNumber {
#[serde(rename = "blockNumber")]
block_number: U256,
},
H256(H256),
BlockHash {
#[serde(rename = "blockHash")]
block_hash: H256,
},
}
let r = BlockNumberOrTagOrHashWithAlias::deserialize(de)?;
Ok(match r {
BlockNumberOrTagOrHashWithAlias::BlockTag(val) => BlockNumberOrTagOrHash::BlockTag(val),
BlockNumberOrTagOrHashWithAlias::U256(val) |
BlockNumberOrTagOrHashWithAlias::BlockNumber { block_number: val } =>
BlockNumberOrTagOrHash::U256(val),
BlockNumberOrTagOrHashWithAlias::H256(val) |
BlockNumberOrTagOrHashWithAlias::BlockHash { block_hash: val } =>
BlockNumberOrTagOrHash::H256(val),
})
}
}
/// filter
#[derive(
Debug, Default, Clone, Encode, Decode, TypeInfo, Serialize, Deserialize, Eq, PartialEq,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment