Skip to content

Commit

Permalink
Create the output folders if they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation committed Apr 30, 2024
1 parent c5a4544 commit ec60ae7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions examples/crawler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async fn tx_matches<'a>(_tx: &MultiEraTx<'a>) -> bool {
#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();

// Connect to the local node over the file socket
let mut client = NodeClient::connect(args.socket_path.clone(), args.network_magic)
.await
Expand Down Expand Up @@ -55,19 +55,23 @@ async fn main() -> Result<()> {
let height = block.number();
let hash = block.hash();

if height % 100000 == 0 {
if height % 10000 == 0 {
println!("Processed block height {}: {}/{}", height, slot, hash);
}
// And check each transaction for the predicate, and save if needed
for tx in block.txs() {
if tx_matches(&tx).await {
println!("Found matching tx in block {}/{}", slot, hash);
// Make sure we create the out diretory
std::fs::create_dir_all(format!("{}/txs", args.out.to_str().unwrap())).context("couldn't create output directory")?;
save_file(args.tx_path(&tx), tx.encode().as_slice())?;
}
}
// Then, we can check the block as a whole
if block_matches(&block).await {
println!("Found matching block {}/{}", slot, hash);
// Make sure we create the out diretory
std::fs::create_dir_all(format!("{}/blocks", args.out.to_str().unwrap())).context("couldn't create output directory")?;
let path = args.block_path(&block);
// We drop the block, because the block is
// holding a reference to bytes, which we need to save it
Expand Down

0 comments on commit ec60ae7

Please sign in to comment.