From 2a86bee66b5539b550d1b09dda8a75baade8b61f Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Wed, 1 May 2024 10:31:50 +0200 Subject: [PATCH] Implement From for FilterId --- crates/rpc-types/src/eth/block.rs | 18 +++++++++++++++--- crates/rpc-types/src/eth/filter.rs | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/crates/rpc-types/src/eth/block.rs b/crates/rpc-types/src/eth/block.rs index d9c8360119f..07832ccaa35 100644 --- a/crates/rpc-types/src/eth/block.rs +++ b/crates/rpc-types/src/eth/block.rs @@ -42,7 +42,7 @@ pub struct Block { impl Block { /// Converts a block with Tx hashes into a full block. pub fn into_full_block(self, txs: Vec) -> Self { - Self { transactions: BlockTransactions::Full(txs), ..self } + Self { transactions: txs.into(), ..self } } } @@ -249,6 +249,18 @@ impl BlockTransactions { } } +impl From> for BlockTransactions { + fn from(hashes: Vec) -> Self { + BlockTransactions::Hashes(hashes) + } +} + +impl From> for BlockTransactions { + fn from(transactions: Vec) -> Self { + BlockTransactions::Full(transactions) + } +} + /// An iterator over the transaction hashes of a block. /// /// See [`BlockTransactions::hashes`]. @@ -581,7 +593,7 @@ mod tests { parent_beacon_block_root: None, }, uncles: vec![B256::with_last_byte(17)], - transactions: BlockTransactions::Hashes(vec![B256::with_last_byte(18)]), + transactions: vec![B256::with_last_byte(18)].into(), size: Some(U256::from(19)), withdrawals: Some(vec![]), other: Default::default(), @@ -665,7 +677,7 @@ mod tests { parent_beacon_block_root: None, }, uncles: vec![B256::with_last_byte(17)], - transactions: BlockTransactions::Hashes(vec![B256::with_last_byte(18)]), + transactions: vec![B256::with_last_byte(18)].into(), size: Some(U256::from(19)), withdrawals: None, other: Default::default(), diff --git a/crates/rpc-types/src/eth/filter.rs b/crates/rpc-types/src/eth/filter.rs index 941032c7ee9..1a022c0a89d 100644 --- a/crates/rpc-types/src/eth/filter.rs +++ b/crates/rpc-types/src/eth/filter.rs @@ -943,6 +943,18 @@ pub enum FilterId { Str(String), } +impl From for FilterId { + fn from(num: u64) -> Self { + FilterId::Num(num) + } +} + +impl From for FilterId { + fn from(str: String) -> Self { + FilterId::Str(str) + } +} + #[cfg(feature = "jsonrpsee-types")] impl From for jsonrpsee_types::SubscriptionId<'_> { fn from(value: FilterId) -> Self { @@ -957,8 +969,8 @@ impl From for jsonrpsee_types::SubscriptionId<'_> { impl From> for FilterId { fn from(value: jsonrpsee_types::SubscriptionId<'_>) -> Self { match value { - jsonrpsee_types::SubscriptionId::Num(n) => FilterId::Num(n), - jsonrpsee_types::SubscriptionId::Str(s) => FilterId::Str(s.into_owned()), + jsonrpsee_types::SubscriptionId::Num(n) => n.into(), + jsonrpsee_types::SubscriptionId::Str(s) => s.into_owned().into(), } } }