Skip to content

Commit

Permalink
docs: Update example API
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-herasme committed Jul 25, 2024
1 parent 40f1834 commit f8ec7af
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Block handlers are used to process blocks. They are defined as closures that imp
Here's an example of a block handler that processes blocks:

```rust
use alloy::{rpc::types::eth::BlockNumberOrTag, sol};
use alloy::{eips::BlockId, sol};
use ghost_crab::prelude::*;

sol!(
Expand All @@ -121,31 +121,25 @@ sol!(
"abis/stader/StaderStakePoolsManager.json"
);

const STADER: Address = address!("cf5EA1b38380f6aF39068375516Daf40Ed70D299");

#[block_handler(Stader)]
async fn StaderBlockHandler(ctx: BlockContext) {
let block_number = ctx.block.header.number.unwrap();

let stader_staking_manager = StaderStakePoolsManager::new(
"0xcf5EA1b38380f6aF39068375516Daf40Ed70D299"
.parse()
.unwrap(),
&ctx.provider,
);
let stader_staking_manager = StaderStakePoolsManager::new(STADER, &ctx.provider);

let total_assets = stader_staking_manager
.totalAssets()
.block(alloy::rpc::types::eth::BlockId::Number(
BlockNumberOrTag::Number(block_number),
))
.block(BlockId::from(ctx.block_number))
.call()
.await
.unwrap();

let db = db::get().await;

let eth = total_assets._0.to_string();
let block_number = block_number as i64;
let block_timestamp = ctx.block.header.timestamp as i64;
let block_number = ctx.block_number as i64;
let block = ctx.block().await.unwrap().unwrap();
let block_timestamp = block.header.timestamp as i64;

// Save the data to your database
}
Expand Down Expand Up @@ -187,8 +181,6 @@ async fn ETHVaultDeposited(ctx: Context) {

#[event_handler(VaultsRegistry.VaultAdded)]
async fn VaultsRegistry(ctx: Context) {
let vault = event.vault.to_string();

ctx.templates
.start(Template {
address: vault.clone(),
Expand Down

0 comments on commit f8ec7af

Please sign in to comment.