-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(starknet_committer_and_os_cli): moved block-hash logic into sep…
…arate folder
- Loading branch information
1 parent
34298e6
commit 113d8cb
Showing
5 changed files
with
70 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod run_block_hash_cli; |
58 changes: 58 additions & 0 deletions
58
crates/starknet_committer_and_os_cli/src/block_hash_cli/run_block_hash_cli.rs
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,58 @@ | ||
use clap::{Parser, Subcommand}; | ||
use starknet_api::block_hash::block_hash_calculator::{ | ||
calculate_block_commitments, | ||
calculate_block_hash, | ||
}; | ||
use tracing::info; | ||
|
||
use crate::committer_cli::block_hash::{BlockCommitmentsInput, BlockHashInput}; | ||
use crate::shared_utils::read::{load_input, write_to_file}; | ||
use crate::shared_utils::types::IoArgs; | ||
|
||
#[derive(Parser, Debug)] | ||
pub struct BlockHashCliCommand { | ||
#[clap(subcommand)] | ||
command: Command, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum Command { | ||
/// Calculates the block hash. | ||
BlockHash { | ||
#[clap(flatten)] | ||
io_args: IoArgs, | ||
}, | ||
/// Calculates commitments needed for the block hash. | ||
BlockHashCommitments { | ||
#[clap(flatten)] | ||
io_args: IoArgs, | ||
}, | ||
} | ||
|
||
pub async fn run_block_hash_cli(block_hash_cli_command: BlockHashCliCommand) { | ||
info!("Starting block-hash-cli with command: \n{:?}", block_hash_cli_command); | ||
match block_hash_cli_command.command { | ||
Command::BlockHash { io_args: IoArgs { input_path, output_path } } => { | ||
let block_hash_input: BlockHashInput = load_input(input_path); | ||
info!("Successfully loaded block hash input."); | ||
let block_hash = | ||
calculate_block_hash(block_hash_input.header, block_hash_input.block_commitments) | ||
.unwrap_or_else(|error| panic!("Failed to calculate block hash: {}", error)); | ||
write_to_file(&output_path, &block_hash); | ||
info!("Successfully computed block hash {:?}.", block_hash); | ||
} | ||
|
||
Command::BlockHashCommitments { io_args: IoArgs { input_path, output_path } } => { | ||
let commitments_input: BlockCommitmentsInput = load_input(input_path); | ||
info!("Successfully loaded block hash commitment input."); | ||
let commitments = calculate_block_commitments( | ||
&commitments_input.transactions_data, | ||
&commitments_input.state_diff, | ||
commitments_input.l1_da_mode, | ||
&commitments_input.starknet_version, | ||
); | ||
write_to_file(&output_path, &commitments); | ||
info!("Successfully computed block hash commitment: \n{:?}", commitments); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod block_hash_cli; | ||
pub mod committer_cli; | ||
pub mod os_cli; | ||
pub mod shared_utils; | ||
|
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