Skip to content

Commit

Permalink
refactor deposit options
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Mar 11, 2024
1 parent 14fcf02 commit 290276d
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 68 deletions.
5 changes: 1 addition & 4 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ use std::str::FromStr;
use web3::types::Address;

pub mod check_rpc;
pub mod close_deposit;
pub mod create_deposit;
pub mod deposit_details;
pub mod scan_chain;
pub mod terminate_deposit;
pub mod deposit;

pub fn check_address_name(n: &str) -> Result<Address, FromHexError> {
match n {
Expand Down
4 changes: 4 additions & 0 deletions src/actions/deposit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod close;
pub mod terminate;
pub mod details;
pub mod create;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
96 changes: 50 additions & 46 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod actions;
mod options;
mod stats;

use crate::options::{PaymentCommands, PaymentOptions};
use crate::options::{DepositCommands, PaymentCommands, PaymentOptions};
use actix_web::Scope;
use actix_web::{web, App, HttpServer};
use csv::ReaderBuilder;
Expand All @@ -26,10 +26,10 @@ use std::str::FromStr;

use crate::actions::check_address_name;
use crate::actions::check_rpc::check_rpc_local;
use crate::actions::close_deposit::close_deposit_local;
use crate::actions::create_deposit::make_deposit_local;
use crate::actions::deposit_details::deposit_details_local;
use crate::actions::terminate_deposit::terminate_deposit_local;
use crate::actions::deposit::close::close_deposit_local;
use crate::actions::deposit::create::make_deposit_local;
use crate::actions::deposit::details::deposit_details_local;
use crate::actions::deposit::terminate::terminate_deposit_local;
use crate::stats::{export_stats, run_stats};
use erc20_payment_lib::faucet_client::faucet_donate;
use erc20_payment_lib::misc::gen_private_keys;
Expand Down Expand Up @@ -72,10 +72,7 @@ async fn main_internal() -> Result<(), PaymentError> {
PaymentCommands::CheckRpc { .. } => {}
PaymentCommands::GetDevEth { .. } => {}
PaymentCommands::MintTestTokens { .. } => {}
PaymentCommands::CreateDeposit { .. } => {}
PaymentCommands::CloseDeposit { .. } => {}
PaymentCommands::TerminateDeposit { .. } => {}
PaymentCommands::CheckDeposit { .. } => {}
PaymentCommands::Deposit { .. } => {}
PaymentCommands::Transfer { .. } => {}
PaymentCommands::Balance { .. } => {}
PaymentCommands::ImportPayments { .. } => {}
Expand Down Expand Up @@ -352,45 +349,52 @@ async fn main_internal() -> Result<(), PaymentError> {
)
.await?;
}
PaymentCommands::CreateDeposit {
make_deposit_options,
PaymentCommands::Deposit {
deposit
} => {
make_deposit_local(
conn.clone().unwrap(),
make_deposit_options,
config,
&public_addrs,
signer,
)
.await?;
}
PaymentCommands::CloseDeposit {
close_deposit_options,
} => {
close_deposit_local(
conn.clone().unwrap(),
close_deposit_options,
config,
&public_addrs,
)
.await?;
}
PaymentCommands::TerminateDeposit {
terminate_deposit_options,
} => {
terminate_deposit_local(
conn.clone().unwrap(),
terminate_deposit_options,
config,
&public_addrs,
)
.await?;
}
PaymentCommands::CheckDeposit {
check_deposit_options,
} => {
deposit_details_local(check_deposit_options, config).await?;
match deposit {
DepositCommands::Create {
make_deposit_options,
} => {
make_deposit_local(
conn.clone().unwrap(),
make_deposit_options,
config,
&public_addrs,
signer,
)
.await?;
}
DepositCommands::Close {
close_deposit_options,
} => {
close_deposit_local(
conn.clone().unwrap(),
close_deposit_options,
config,
&public_addrs,
)
.await?;
}
DepositCommands::Terminate {
terminate_deposit_options,
} => {
terminate_deposit_local(
conn.clone().unwrap(),
terminate_deposit_options,
config,
&public_addrs,
)
.await?;
}
DepositCommands::Check {
check_deposit_options,
} => {
deposit_details_local(check_deposit_options, config).await?;
}
}
}

PaymentCommands::GenerateKey {
generate_key_options,
} => {
Expand Down
45 changes: 27 additions & 18 deletions src/options.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{fmt::Debug, path::PathBuf};

use crate::actions::close_deposit::CloseDepositOptions;
use crate::actions::create_deposit::CreateDepositOptions;
use crate::actions::deposit_details::CheckDepositOptions;
use crate::actions::terminate_deposit::TerminateDepositOptions;
use crate::actions::deposit::close::CloseDepositOptions;
use crate::actions::deposit::create::CreateDepositOptions;
use crate::actions::deposit::details::CheckDepositOptions;
use crate::actions::deposit::terminate::TerminateDepositOptions;
use erc20_payment_lib_extra::{BalanceOptions, GenerateOptions};
use structopt::StructOpt;
use web3::types::Address;
Expand Down Expand Up @@ -355,6 +355,27 @@ pub struct CleanupOptions {
pub remove_tx_unsafe: bool,
}

#[derive(StructOpt)]
pub enum DepositCommands {
Create {
#[structopt(flatten)]
make_deposit_options: CreateDepositOptions,
},
Close {
#[structopt(flatten)]
close_deposit_options: CloseDepositOptions,
},
Terminate {
#[structopt(flatten)]
terminate_deposit_options: TerminateDepositOptions,
},
Check {
#[structopt(flatten)]
check_deposit_options: CheckDepositOptions,
},
}


#[derive(StructOpt)]
#[structopt(about = "Payment admin tool")]
pub enum PaymentCommands {
Expand Down Expand Up @@ -383,21 +404,9 @@ pub enum PaymentCommands {
#[structopt(flatten)]
mint_test_tokens_options: MintTestTokensOptions,
},
CreateDeposit {
Deposit {
#[structopt(flatten)]
make_deposit_options: CreateDepositOptions,
},
CloseDeposit {
#[structopt(flatten)]
close_deposit_options: CloseDepositOptions,
},
TerminateDeposit {
#[structopt(flatten)]
terminate_deposit_options: TerminateDepositOptions,
},
CheckDeposit {
#[structopt(flatten)]
check_deposit_options: CheckDepositOptions,
deposit: DepositCommands,
},
Transfer {
#[structopt(flatten)]
Expand Down

0 comments on commit 290276d

Please sign in to comment.