Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(high-level): Don't require &mut Block to improve the API for developers #93

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() -> anyhow::Result<()> {
}

async fn print_function_calls_to_my_account(
mut block: near_lake_primitives::block::Block,
block: near_lake_primitives::block::Block,
) -> anyhow::Result<()> {
let block_height = block.block_height();
let actions: Vec<&near_lake_primitives::actions::FunctionCall> = block
Expand Down
4 changes: 3 additions & 1 deletion examples/nft_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ fn main() -> anyhow::Result<()> {
Ok(())
}

async fn handle_block(mut block: near_lake_primitives::block::Block) -> anyhow::Result<()> {
async fn handle_block(block: near_lake_primitives::block::Block) -> anyhow::Result<()> {
// Indexing lines START
let nfts: Vec<NFTReceipt> = block
.events() // fetching all the events that occurred in the block
.values()
.flatten()
.filter(|event| event.standard() == "nep171")
.filter(|event| event.event() == "nft_mint") // filter them by "nft_mint" event only
.filter_map(|event| parse_event(event))
Expand Down
2 changes: 1 addition & 1 deletion examples/with_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() -> anyhow::Result<()> {
}

async fn print_function_calls_to_my_account(
mut block: near_lake_primitives::block::Block,
block: near_lake_primitives::block::Block,
ctx: &FileContext,
) -> anyhow::Result<()> {
let block_height = block.block_height();
Expand Down
2 changes: 1 addition & 1 deletion examples/with_context_parent_tx_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() -> anyhow::Result<()> {
}

async fn print_function_call_tx_hash(
mut block: near_lake_primitives::block::Block,
block: near_lake_primitives::block::Block,
ctx: &ParentTransactionCache,
) -> anyhow::Result<()> {
// Cache has been updated before this function is called.
Expand Down
2 changes: 1 addition & 1 deletion lake-context-derive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This will simplify your indexer function signature. It now needs only the contex

```ignore
async fn handle_block(
mut block: Block,
block: Block,
ctx: &MyContext,
) -> anyhow::Result<()> {
// body
Expand Down
2 changes: 1 addition & 1 deletion lake-context-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn lake_context_derive(input: TokenStream) -> TokenStream {
let expanded = quote! {
// The generated impl.
impl near_lake_framework::LakeContextExt for #name {
fn execute_before_run(&self, block: &mut near_lake_primitives::block::Block) {
fn execute_before_run(&self, block: &near_lake_primitives::block::Block) {
#( #calls_before_run )*
}

Expand Down
4 changes: 2 additions & 2 deletions lake-framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ tokio = { version = "1.1", features = ["sync", "time", "rt-multi-thread"] }
tokio-stream = { version = "0.1" }
tracing = "0.1.13"

near-lake-primitives = { path = "../lake-primitives", version = "0.8.0-beta.2" }
near-lake-context-derive = { path = "../lake-context-derive", version = "0.8.0-beta.2" }
near-lake-primitives = { path = "../lake-primitives", version = "0.8.0-beta.3" }
near-lake-context-derive = { path = "../lake-context-derive", version = "0.8.0-beta.3" }

[dev-dependencies]
aws-smithy-http = "0.60.0"
Expand Down
2 changes: 1 addition & 1 deletion lake-framework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn main() -> anyhow::Result<()> {
}

async fn print_function_call_tx_hash(
mut block: near_lake_primitives::block::Block,
block: near_lake_primitives::block::Block,
ctx: &ParentTransactionCache,
) -> anyhow::Result<()> {
// Cache has been updated before this function is called.
Expand Down
6 changes: 3 additions & 3 deletions lake-framework/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ impl types::Lake {
// concurrency 1
let mut handlers = tokio_stream::wrappers::ReceiverStream::new(stream)
.map(|streamer_message| async {
let mut block: near_lake_primitives::block::Block = streamer_message.into();
let block: near_lake_primitives::block::Block = streamer_message.into();

context.execute_before_run(&mut block);
context.execute_before_run(&block);

let user_indexer_function_execution_result = f(block, context).await;

Expand Down Expand Up @@ -116,7 +116,7 @@ impl types::Lake {
struct EmptyContext {}

impl LakeContextExt for EmptyContext {
fn execute_before_run(&self, _block: &mut near_lake_primitives::block::Block) {}
fn execute_before_run(&self, _block: &near_lake_primitives::block::Block) {}

fn execute_after_run(&self) {}
}
Expand Down
6 changes: 3 additions & 3 deletions lake-framework/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub enum LakeError {
/// struct PrinterContext;
///
/// impl LakeContextExt for PrinterContext {
/// fn execute_before_run(&self, block: &mut near_lake_primitives::block::Block) {
/// fn execute_before_run(&self, block: &near_lake_primitives::block::Block) {
/// println!("Processing block {}", block.header().height());
/// }
/// fn execute_after_run(&self) {}
Expand All @@ -201,7 +201,7 @@ pub enum LakeError {
/// // We need our context to do nothing before and after the indexing process.
/// // The only purpose is to provide the database connection pool to the indexing process.
/// impl LakeContextExt for ApplicationDataContext {
/// fn execute_before_run(&self, block: &mut near_lake_primitives::block::Block) {}
/// fn execute_before_run(&self, block: &near_lake_primitives::block::Block) {}
/// fn execute_after_run(&self) {}
/// }
///
Expand Down Expand Up @@ -319,7 +319,7 @@ pub enum LakeError {
/// And we didn't need to implement them in our `ApplicationDataContext` struct because `LakeContext` derive macro did it for us automatically.
pub trait LakeContextExt {
/// This method will be called before the indexing process is started.
fn execute_before_run(&self, block: &mut near_lake_primitives::block::Block);
fn execute_before_run(&self, block: &near_lake_primitives::block::Block);
/// This method will be called after the indexing process is finished.
fn execute_after_run(&self);
}
2 changes: 1 addition & 1 deletion lake-parent-transaction-cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ LakeBuilder::default()
# }

async fn handle_block(
mut block: Block,
block: Block,
ctx: &ParentTransactionCache,
) -> anyhow::Result<()> {
for action in block.actions() {
Expand Down
2 changes: 1 addition & 1 deletion lake-parent-transaction-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl LakeContextExt for ParentTransactionCache {
/// The process to scan the [near_lake_primitives::Block](near_lake_framework::near_lake_primitives::block::Block) and update the cache
/// with the new transactions and first expected receipts.
/// The cache is used to find the parent transaction hash for a given receipt id.
fn execute_before_run(&self, block: &mut Block) {
fn execute_before_run(&self, block: &Block) {
// Fill up the cache with new transactions and first expected receipts
// We will try to skip the transactions related to the accounts we're not watching for.
// Based on `accounts_id`
Expand Down
Loading
Loading