Lake Parent Transaction Cache is a ready-to-use context for the Lake Framework in Rust. It provides a cache for keeping the relation between transactions and receipts in cache.
```norun use lakeparenttransactioncache::{ParentTransactionCache, ParentTransactionCacheBuilder};
let parenttransactioncache_ctx = ParentTransactionCacheBuilder::default() .build() .expect("Failed to build the ParentTransactionCache context");
LakeBuilder::default() .mainnet() .startblockheight(80504433) .build() .expect("Failed to build the Lake Framework") .runwithcontext(handleblock, &parenttransactioncachectx) .expect("Failed to run the Lake Framework");
async fn handleblock( mut block: Block, ctx: &ParentTransactionCache, ) -> anyhow::Result<()> { for action in block.actions() { println!( "Action receipt ID: {:?} | Parent TX hash: {:?}", action.receiptid(), ctx.getparenttransactionhash(&action.receiptid()) ); } Ok(()) } ```
To use the Lake Parent Transaction Cache context in your Rust project, follow these steps:
Cargo.toml
file:toml
[dependencies]
lake_parent_transaction_cache = "<version>"
ignore
use lake_parent_transaction_cache::ParentTransactionCache;
use near_lake_primitives::actions::ActionMetaDataExt;
ParentTransactionCache
context:```no_run
let parenttransactioncache_ctx = ParentTransactionCacheBuilder::default(); ```
ignore
near_lake_framework::LakeBuilder::default()
.mainnet()
.start_block_height(<desired_block_height>)
.build()?
.run_with_context(<your_indexing_function>, &parent_transaction_cache_ctx)?;
Replace <desired_block_height>
with the starting block height you want to use. Replace <you_indexing_function>
with the function you want to use to index the blocks.
We use SizedCache under the hood. So we can configure the cache size by using the cache_size
method:
```no_run
let parenttransactioncachectx = ParentTransactionCacheBuilder::default() .cachesize(100_000); ```
By default the cache size is 100,000.
By default ParentTransactionCache
context will cache the relation between Transaction and Receipt for every Transaction in the block. But you can configure it to watch for specific accounts only:
```no_run
use nearlakeframework::near_primitives::types::AccountId;
let accountstowatch: Vec
for_account
method```no_run
use nearlakeframework::near_primitives::types::AccountId;
let parenttransactioncachectx = ParentTransactionCacheBuilder::default() .foraccount(String::from("alice.near).tryinto().unwrap()) .foraccount(String::from("bob.near).try_into().unwrap()); ```