Skip to content

Commit

Permalink
refactor: refactored code to take in cli params as well
Browse files Browse the repository at this point in the history
  • Loading branch information
mohiiit committed Nov 5, 2024
1 parent f717bf1 commit 24c62c0
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 121 deletions.
28 changes: 6 additions & 22 deletions src/contract_clients/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ethereum_instance::EthereumClient;
use starknet::providers::jsonrpc::{HttpTransport, JsonRpcClient};
use starknet::providers::Url;

use crate::ConfigFile;
use crate::Config;

pub struct Clients {
eth_client: EthereumClient,
Expand All @@ -18,32 +18,16 @@ impl Clients {
&self.eth_client
}

/// To deploy the instance of ethereum and starknet and returning the struct.
// pub async fn init(config: &CliArgs) -> Self {
// let client_instance = EthereumClient::attach(
// Option::from(config.eth_rpc.clone()),
// Option::from(config.eth_priv_key.clone()),
// Option::from(config.eth_chain_id),
// )
// .unwrap();
//
// let provider_l2 = JsonRpcClient::new(HttpTransport::new(
// Url::parse(&config.rollup_seq_url).expect("Failed to declare provider for app chain"),
// ));
//
// Self { eth_client: client_instance, provider_l2 }
// }

pub async fn init_from_config(config_file: &ConfigFile) -> Self {
pub async fn init_from_config(config: &Config) -> Self {
let client_instance = EthereumClient::attach(
Option::from(config_file.eth_rpc.clone()),
Option::from(config_file.eth_priv_key.clone()),
Option::from(config_file.eth_chain_id),
Option::from(config.eth_rpc.clone()),
Option::from(config.eth_priv_key.clone()),
Option::from(config.eth_chain_id),
)
.unwrap();

let provider_l2 = JsonRpcClient::new(HttpTransport::new(
Url::parse(&config_file.rollup_seq_url).expect("Failed to declare provider for app chain"),
Url::parse(&config.rollup_seq_url).expect("Failed to declare provider for app chain"),
));

Self { eth_client: client_instance, provider_l2 }
Expand Down
4 changes: 2 additions & 2 deletions src/contract_clients/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::contract_clients::legacy_class::CompressedLegacyContractClass;
use crate::contract_clients::utils::DeclarationInput::{DeclarationInputs, LegacyDeclarationInputs};
use crate::helpers::account_actions::{get_contract_address_from_deploy_tx, AccountActions};
use crate::utils::{invoke_contract, save_to_json, wait_for_transaction, JsonValueType};
use crate::ConfigFile;
use crate::Config;

pub type RpcAccount<'a> = SingleOwnerAccount<&'a JsonRpcClient<HttpTransport>, LocalWallet>;
pub async fn build_single_owner_account<'a>(
Expand Down Expand Up @@ -75,7 +75,7 @@ pub fn generate_config_hash(
Pedersen::hash_array(&[config_hash_version, chain_id, fee_token_address, native_fee_token_address])
}

pub fn get_bridge_init_configs(config: &ConfigFile) -> (Felt, Felt) {
pub fn get_bridge_init_configs(config: &Config) -> (Felt, Felt) {
let program_hash = Felt::from_hex(config.sn_os_program_hash.as_str()).unwrap();

let config_hash = generate_config_hash(
Expand Down
Loading

0 comments on commit 24c62c0

Please sign in to comment.