Skip to content

Commit

Permalink
Implement From for FilterId (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored May 1, 2024
1 parent 5a5f29e commit c058e32
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
18 changes: 15 additions & 3 deletions crates/rpc-types/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transaction>) -> Self {
Self { transactions: BlockTransactions::Full(txs), ..self }
Self { transactions: txs.into(), ..self }
}
}

Expand Down Expand Up @@ -249,6 +249,18 @@ impl BlockTransactions {
}
}

impl From<Vec<B256>> for BlockTransactions {
fn from(hashes: Vec<B256>) -> Self {
BlockTransactions::Hashes(hashes)
}
}

impl<T> From<Vec<T>> for BlockTransactions<T> {
fn from(transactions: Vec<T>) -> Self {
BlockTransactions::Full(transactions)
}
}

/// An iterator over the transaction hashes of a block.
///
/// See [`BlockTransactions::hashes`].
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
16 changes: 14 additions & 2 deletions crates/rpc-types/src/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,18 @@ pub enum FilterId {
Str(String),
}

impl From<u64> for FilterId {
fn from(num: u64) -> Self {
FilterId::Num(num)
}
}

impl From<String> for FilterId {
fn from(str: String) -> Self {
FilterId::Str(str)
}
}

#[cfg(feature = "jsonrpsee-types")]
impl From<FilterId> for jsonrpsee_types::SubscriptionId<'_> {
fn from(value: FilterId) -> Self {
Expand All @@ -957,8 +969,8 @@ impl From<FilterId> for jsonrpsee_types::SubscriptionId<'_> {
impl From<jsonrpsee_types::SubscriptionId<'_>> 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(),
}
}
}
Expand Down

0 comments on commit c058e32

Please sign in to comment.