Skip to content

Commit

Permalink
Some starting code
Browse files Browse the repository at this point in the history
  • Loading branch information
darunrs committed Jun 5, 2024
1 parent ffceeef commit 3c3fbb8
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 2 deletions.
1 change: 1 addition & 0 deletions block-streamer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions block-streamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ wildmatch = "2.1.1"

registry-types = { path = "../registry/types" }
base64 = "0.22.1"
async-stream = "0.3.5"

[build-dependencies]
tonic-build = "0.10"
Expand Down
25 changes: 25 additions & 0 deletions block-streamer/src/bitmap.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use anyhow::anyhow;
use base64::{engine::general_purpose, Engine as _};
use std::convert::TryFrom;

use crate::graphql::client::{get_bitmaps_exact, get_bitmaps_wildcard};

#[derive(Debug, Default, PartialEq)]
pub struct Base64Bitmap {
pub start_block_height: usize,
pub base64: String,
}

#[derive(Debug, Default, PartialEq)]
pub struct Bitmap {
pub start_block_height: usize,
pub bitmap: Vec<u8>,
Expand All @@ -19,6 +24,26 @@ struct EliasGammaDecoded {

pub struct BitmapOperator {}

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

pub fn from_wildcard_query(
query_item: get_bitmaps_wildcard::GetBitmapsWildcardDarunrsNearBitmapV5ActionsIndex,
) -> Self {
Self {
base64: query_item.bitmap,
start_block_height: usize::try_from(query_item.first_block_height).unwrap(),
}
}
}

#[cfg_attr(test, mockall::automock)]
impl BitmapOperator {
pub fn new() -> Self {
Expand Down
48 changes: 48 additions & 0 deletions block-streamer/src/block_height_stream.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use crate::bitmap::{Base64Bitmap, BitmapOperator};
use crate::graphql::client::GraphQLClient;
use async_stream::stream;
use futures::Stream;
use near_lake_framework::near_indexer_primitives;

pub struct BlockHeightStream {
graphql_client: GraphQLClient,
bitmap_operator: BitmapOperator,
}

#[cfg_attr(test, mockall::automock)]
impl BlockHeightStream {
pub fn new(graphql_endpoint: String) -> Self {
Self {
graphql_client: GraphQLClient::new(graphql_endpoint),
bitmap_operator: BitmapOperator::new(),
}
}

fn parse_contract_pattern(&self, contract_pattern: &str) -> Vec<

pub async fn list_matching_block_heights(
&self,
start_block_height: near_indexer_primitives::types::BlockHeight,
contract_pattern: &str,
) -> impl Stream<Item = usize> {
let start_date = self.get_nearest_block_date(start_block_height).await?;

stream! {
for i in 0..3 {
yield i;
}
}
}
}

#[cfg(test)]
mod tests {
use super::*;

const HASURA_ENDPOINT: &str =
"https://queryapi-hasura-graphql-mainnet-vcqilefdcq-ew.a.run.app/v1/graphql";

fn collect_three_block_heights_from_one_bitmap() {}

fn collect_three_block_heights_from_two_bitmaps() {}
}
4 changes: 2 additions & 2 deletions block-streamer/src/graphql/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Date = String;
response_derives = "Debug",
normalization = "rust"
)]
struct GetBitmapsExact;
pub struct GetBitmapsExact;

#[derive(GraphQLQuery)]
#[graphql(
Expand All @@ -23,7 +23,7 @@ struct GetBitmapsExact;
response_derives = "Debug",
normalization = "rust"
)]
struct GetBitmapsWildcard;
pub struct GetBitmapsWildcard;

pub struct GraphQLClient {
client: reqwest::Client,
Expand Down
1 change: 1 addition & 0 deletions block-streamer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use tracing_subscriber::prelude::*;

mod bitmap;
mod block_height_stream;
mod block_stream;
mod delta_lake_client;
mod graphql;
Expand Down
1 change: 1 addition & 0 deletions coordinator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3c3fbb8

Please sign in to comment.