-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
118 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## `Starknet` Raw Blockchain Data | ||
|
||
> Starknet | ||
> [`sf.starknet.type.v1.Block`](https://buf.build/streamingfast/firehose-starknet/docs/main:sf.starknet.type.v1) | ||
- [x] **Blocks** | ||
- [] **Transactions** | ||
- [] **Events** | ||
- [] **Calls** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use common::{structs::BlockTimestamp, utils::bytes_to_hex}; | ||
use serde_json::json; | ||
use substreams::Hex; | ||
|
||
use crate::pb::{ | ||
pinax::starknet::v1::Block as BlockOutput, | ||
sf::starknet::r#type::v1::{Block, StateDiff}, | ||
}; | ||
|
||
pub fn collect_block(block: &Block, timestamp: &BlockTimestamp) -> BlockOutput { | ||
let l1_data_gas_price = block.l1_data_gas_price.as_ref().expect("L1 data gas price missing"); | ||
let l1_gas_price = block.l1_gas_price.as_ref().expect("L1 gas price missing"); | ||
let state_diff = block.state_update.as_ref().expect("State diff missing").state_diff.as_ref().expect("State diff missing"); | ||
|
||
BlockOutput { | ||
time: Some(timestamp.time.clone()), | ||
number: timestamp.number, | ||
date: timestamp.date.clone(), | ||
hash: timestamp.hash.clone(), | ||
l1_da_mode: l1_da_mode_to_string(block.l1_da_mode), | ||
l1_data_gas_price_in_fri: l1_data_gas_price.price_in_fri.clone(), | ||
l1_data_gas_price_in_wei: l1_data_gas_price.price_in_wei.clone(), | ||
l1_gas_price_in_fri: l1_gas_price.price_in_fri.clone(), | ||
l1_gas_price_in_wei: l1_gas_price.price_in_wei.clone(), | ||
starknet_version: block.starknet_version.clone(), | ||
tx_count: block.transactions.len() as u32, | ||
new_root: bytes_to_hex(&block.new_root), | ||
parent_hash: bytes_to_hex(&block.parent_hash), | ||
sequencer_address: bytes_to_hex(&block.sequencer_address), | ||
state_diff: state_diff_to_string(state_diff), | ||
} | ||
} | ||
|
||
fn l1_da_mode_to_string(l1_da_mode: i32) -> String { | ||
match l1_da_mode { | ||
0 => "Unknown".to_string(), | ||
1 => "Calldata".to_string(), | ||
2 => "Blob".to_string(), | ||
_ => "Unknown".to_string(), | ||
} | ||
} | ||
|
||
fn state_diff_to_string(state_diff: &StateDiff) -> String { | ||
let json_str = json!({ | ||
"deployed_contracts": state_diff.deployed_contracts.iter().map(|contract| { | ||
json!({ | ||
"address": bytes_to_hex(&contract.address), | ||
"class_hash": bytes_to_hex(&contract.class_hash), | ||
}) | ||
}).collect::<Vec<_>>(), | ||
"storage_diffs": state_diff.storage_diffs.iter().map(|diff| { | ||
json!({ | ||
"address": bytes_to_hex(&diff.address), | ||
"storage_entries": diff.storage_entries.iter().map(|entry| { | ||
json!({ | ||
"key": bytes_to_hex(&entry.key), | ||
"value": bytes_to_hex(&entry.value), | ||
}) | ||
}).collect::<Vec<_>>(), | ||
}) | ||
}).collect::<Vec<_>>(), | ||
"nonces": state_diff.nonces.iter().map(|nonce| { | ||
json!({ | ||
"contract_address": bytes_to_hex(&nonce.contract_address), | ||
"nonce": Hex::encode(&nonce.nonce), | ||
}) | ||
}).collect::<Vec<_>>(), | ||
"deprecated_declared_classes": state_diff.deprecated_declared_classes.iter().map(|class_hash| { | ||
bytes_to_hex(class_hash) | ||
}).collect::<Vec<_>>(), | ||
"declared_classes": state_diff.declared_classes.iter().map(|class| { | ||
json!({ | ||
"class_hash": bytes_to_hex(&class.class_hash), | ||
"compiled_class_hash": bytes_to_hex(&class.compiled_class_hash), | ||
|
||
}) | ||
}).collect::<Vec<_>>(), | ||
"replaced_classes": state_diff.replaced_classes.iter().map(|class| { | ||
json!({ | ||
"contract_address": bytes_to_hex(&class.contract_address), | ||
"class_hash": bytes_to_hex(&class.class_hash), | ||
}) | ||
}).collect::<Vec<_>>(), | ||
}); | ||
|
||
json_str.to_string() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod blocks; | ||
mod map_events; | ||
mod pb; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
use common::utils::build_timestamp_with_prefix; | ||
use substreams::{errors::Error, pb::substreams::Clock}; | ||
|
||
use crate::pb::pinax::starknet::v1::{Block, EventsOutput}; | ||
use crate::{ | ||
blocks::collect_block, | ||
pb::{pinax::starknet::v1::EventsOutput, sf::starknet::r#type::v1::Block}, | ||
}; | ||
|
||
#[substreams::handlers::map] | ||
pub fn map_events(_clock: Clock, _block: Block) -> Result<EventsOutput, Error> { | ||
Ok(EventsOutput::default()) | ||
pub fn map_events(clock: Clock, block: Block) -> Result<EventsOutput, Error> { | ||
let timestamp = build_timestamp_with_prefix(&clock); | ||
|
||
let mut events = EventsOutput { | ||
blocks: vec![collect_block(&block, ×tamp)], | ||
transactions: vec![], | ||
access_lists: vec![], | ||
events: vec![], | ||
calls: vec![], | ||
}; | ||
|
||
Ok(events) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters