Skip to content

Commit

Permalink
Refactor deposit commands
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 authored Mar 12, 2024
1 parent 14fcf02 commit 041ee9b
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 80 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/deposit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ jobs:
- name: Create random deposit id
run: |
echo DEPOSIT_NONCE0=$(shuf -i 0-2000000000 -n 1) >> $GITHUB_ENV
echo DEPOSIT_NONCE1=$(shuf -i 0-2000000000 -n 1) >> $GITHUB_ENV
echo DEPOSIT_NONCE2=$(shuf -i 0-2000000000 -n 1) >> $GITHUB_ENV
echo DEPOSIT_NONCE0=$(shuf -i 0-2000000000000000000 -n 1) >> $GITHUB_ENV
echo DEPOSIT_NONCE1=$(shuf -i 0-2000000000000000000 -n 1) >> $GITHUB_ENV
echo DEPOSIT_NONCE2=$(shuf -i 0-2000000000000000000 -n 1) >> $GITHUB_ENV
- name: Show created addresses
run: |
Expand Down Expand Up @@ -69,14 +69,14 @@ jobs:
- name: Create deposit
run: |
set -x
erc20_processor create-deposit --account-no 1 --amount 1 --fee-amount 0.1 --block-for 0 --spender $ETH_ADDRESS_2 --deposit-nonce $DEPOSIT_NONCE0
erc20_processor create-deposit --account-no 1 --amount 1 --fee-amount 0.1 --block-for 1000 --spender $ETH_ADDRESS_2 --deposit-nonce $DEPOSIT_NONCE1
erc20_processor deposit create --account-no 1 --amount 1 --fee-amount 0.1 --block-for 0 --spender $ETH_ADDRESS_2 --deposit-nonce $DEPOSIT_NONCE0
erc20_processor deposit create --account-no 1 --amount 1 --fee-amount 0.1 --block-for 1000 --spender $ETH_ADDRESS_2 --deposit-nonce $DEPOSIT_NONCE1
erc20_processor run
- name: Get Deposit ID from funder and nonce id
run: |
echo DEPOSIT_ID0=$(erc20_processor check-deposit --deposit-nonce $DEPOSIT_NONCE0 --deposit-funder=$ETH_ADDRESS_1 | jq -r ".depositId") >> $GITHUB_ENV
echo DEPOSIT_ID1=$(erc20_processor check-deposit --deposit-nonce $DEPOSIT_NONCE1 --deposit-funder=$ETH_ADDRESS_1 | jq -r ".depositId") >> $GITHUB_ENV
echo DEPOSIT_ID0=$(erc20_processor deposit check --deposit-nonce $DEPOSIT_NONCE0 --deposit-funder=$ETH_ADDRESS_1 | jq -r ".depositId") >> $GITHUB_ENV
echo DEPOSIT_ID1=$(erc20_processor deposit check --deposit-nonce $DEPOSIT_NONCE1 --deposit-funder=$ETH_ADDRESS_1 | jq -r ".depositId") >> $GITHUB_ENV
- name: Make single transfer from deposit
run: |
Expand Down Expand Up @@ -111,8 +111,8 @@ jobs:
- name: Free deposit
run: |
set -x
erc20_processor close-deposit --deposit-id $DEPOSIT_ID0 --account-no 2
erc20_processor close-deposit --deposit-id $DEPOSIT_ID1 --account-no 2
erc20_processor deposit close --deposit-id $DEPOSIT_ID0 --account-no 2
erc20_processor deposit close --deposit-id $DEPOSIT_ID1 --account-no 2
erc20_processor run
- name: Transfer all left ETH tokens
Expand Down
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 deposit;
pub mod scan_chain;
pub mod terminate_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 create;
pub mod details;
pub mod terminate;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use structopt::StructOpt;
use web3::types::{Address, U256};

#[derive(StructOpt)]
#[structopt(about = "Allocate funds for use by payer")]
#[structopt(about = "Close deposit if you are spender")]
pub struct CloseDepositOptions {
#[structopt(short = "c", long = "chain-name", default_value = "holesky")]
pub chain_name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use structopt::StructOpt;
use web3::types::{Address, U256};

#[derive(StructOpt)]
#[structopt(about = "Allocate funds for use by payer")]
#[structopt(about = "Create deposit for use by spender")]
pub struct CreateDepositOptions {
#[structopt(short = "c", long = "chain-name", default_value = "holesky")]
pub chain_name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use structopt::StructOpt;
use web3::types::{Address, U256};

#[derive(StructOpt)]
#[structopt(about = "Allocate funds for use by payer")]
#[structopt(about = "Show details of given deposit")]
pub struct CheckDepositOptions {
#[structopt(short = "c", long = "chain-name", default_value = "holesky")]
pub chain_name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use structopt::StructOpt;
use web3::types::{Address, U256};

#[derive(StructOpt)]
#[structopt(about = "Allocate funds for use by payer")]
#[structopt(about = "Terminate deposit if you are funder")]
pub struct TerminateDepositOptions {
#[structopt(short = "c", long = "chain-name", default_value = "holesky")]
pub chain_name: String,
Expand Down
90 changes: 45 additions & 45 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,48 @@ async fn main_internal() -> Result<(), PaymentError> {
)
.await?;
}
PaymentCommands::CreateDeposit {
make_deposit_options,
} => {
make_deposit_local(
conn.clone().unwrap(),
PaymentCommands::Deposit { deposit } => match deposit {
DepositCommands::Create {
make_deposit_options,
config,
&public_addrs,
signer,
)
.await?;
}
PaymentCommands::CloseDeposit {
close_deposit_options,
} => {
close_deposit_local(
conn.clone().unwrap(),
} => {
make_deposit_local(
conn.clone().unwrap(),
make_deposit_options,
config,
&public_addrs,
signer,
)
.await?;
}
DepositCommands::Close {
close_deposit_options,
config,
&public_addrs,
)
.await?;
}
PaymentCommands::TerminateDeposit {
terminate_deposit_options,
} => {
terminate_deposit_local(
conn.clone().unwrap(),
} => {
close_deposit_local(
conn.clone().unwrap(),
close_deposit_options,
config,
&public_addrs,
)
.await?;
}
DepositCommands::Terminate {
terminate_deposit_options,
config,
&public_addrs,
)
.await?;
}
PaymentCommands::CheckDeposit {
check_deposit_options,
} => {
deposit_details_local(check_deposit_options, config).await?;
}
} => {
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)]
#[structopt(about = "Commands for deposit management")]
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 {
#[structopt(flatten)]
make_deposit_options: CreateDepositOptions,
},
CloseDeposit {
#[structopt(flatten)]
close_deposit_options: CloseDepositOptions,
},
TerminateDeposit {
#[structopt(flatten)]
terminate_deposit_options: TerminateDepositOptions,
},
CheckDeposit {
Deposit {
#[structopt(flatten)]
check_deposit_options: CheckDepositOptions,
deposit: DepositCommands,
},
Transfer {
#[structopt(flatten)]
Expand Down

0 comments on commit 041ee9b

Please sign in to comment.