Skip to content

Commit

Permalink
Use From impl instead of custom name
Browse files Browse the repository at this point in the history
  • Loading branch information
darunrs committed Jun 11, 2024
1 parent b778236 commit 71d6c59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 7 additions & 3 deletions block-streamer/src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ pub struct Base64Bitmap {
pub base64: String,
}

impl Base64Bitmap {
pub fn from_exact_query(
impl From<&get_bitmaps_exact::GetBitmapsExactDarunrsNearBitmapV5ActionsIndex> for Base64Bitmap {
fn from(
query_item: &get_bitmaps_exact::GetBitmapsExactDarunrsNearBitmapV5ActionsIndex,
) -> Self {
Self {
base64: query_item.bitmap.clone(),
start_block_height: usize::try_from(query_item.first_block_height).unwrap(),
}
}
}

pub fn from_wildcard_query(
impl From<&get_bitmaps_wildcard::GetBitmapsWildcardDarunrsNearBitmapV5ActionsIndex>
for Base64Bitmap
{
fn from(
query_item: &get_bitmaps_wildcard::GetBitmapsWildcardDarunrsNearBitmapV5ActionsIndex,
) -> Self {
Self {
Expand Down
6 changes: 2 additions & 4 deletions block-streamer/src/block_height_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,13 @@ impl BlockHeightStreamImpl {
let bitmaps_from_query: Vec<Base64Bitmap> = match contract_pattern_type {
ContractPatternType::Exact(ref pattern) => {
let query_result: Vec<_> = self.graphql_client.get_bitmaps_exact(pattern.clone(), current_date_string.clone()).await.unwrap();
query_result.iter().map(|result_item| Base64Bitmap::from_exact_query(result_item)).collect()
query_result.iter().map(|result_item| Base64Bitmap::from(result_item)).collect()
},
ContractPatternType::Wildcard(ref pattern) => {
let query_result: Vec<_> = self.graphql_client.get_bitmaps_wildcard(pattern.clone(), current_date_string.clone()).await.unwrap();
query_result.iter().map(|result_item| Base64Bitmap::from_wildcard_query(result_item)).collect()

query_result.iter().map(|result_item| Base64Bitmap::from(result_item)).collect()
},
};
println!("date: {}, num of matched receivers: {}", &current_date_string, bitmaps_from_query.len());
if !bitmaps_from_query.is_empty() {
let starting_block_height = bitmaps_from_query.iter().map(|item| item.start_block_height).min().unwrap();
let bitmap_for_day = self.bitmap_operator.merge_bitmaps(&bitmaps_from_query, starting_block_height).unwrap();
Expand Down

0 comments on commit 71d6c59

Please sign in to comment.