Skip to content

Commit

Permalink
feat: wallet escrow config and cli commands
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Jan 26, 2024
1 parent b8d5cc6 commit e780a34
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
64 changes: 62 additions & 2 deletions file-exchange/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use clap::{arg, ValueEnum};
use clap::{command, Args, Parser, Subcommand};
use ethers_core::types::U256;
use ethers_core::types::{H160, U256};
use serde::{Deserialize, Serialize};
use std::fmt;
use std::{fmt, str::FromStr};

use tracing::subscriber::SetGlobalDefaultError;
use tracing_subscriber::EnvFilter;
Expand Down Expand Up @@ -73,6 +73,9 @@ pub enum Role {
pub enum OnchainAction {
Allocate(AllocateArgs),
Unallocate(UnallocateArgs),
Deposit(DepositArgs),
DepositMany(DepositManyArgs),
Withdraw(WithdrawArgs),
}

#[derive(Clone, Debug, Args, Serialize, Deserialize, Default)]
Expand Down Expand Up @@ -337,6 +340,63 @@ pub struct UnallocateArgs {
pub allocation_id: String,
}

#[derive(Clone, Debug, Args, Serialize, Deserialize, Default)]
#[group(required = false, multiple = true)]
pub struct DepositArgs {
#[clap(
long,
value_name = "receiver",
env = "RECEIVER",
help = "The receivier address for the Escrow deposit",
value_parser = H160::from_str,
)]
pub receiver: H160,
#[clap(
long,
value_name = "tokens",
env = "TOKENS",
help = "Token amount to allocate (in units of GRT)",
value_parser = U256::from_dec_str,
)]
pub tokens: U256,
}

#[derive(Clone, Debug, Args, Serialize, Deserialize, Default)]
#[group(required = false, multiple = true)]
pub struct DepositManyArgs {
#[clap(
long,
value_name = "receivers",
env = "RECEIVERS",
value_delimiter = ',',
value_parser = H160::from_str,
help = "The receivier addresses to make the deposit"
)]
pub receivers: Vec<H160>,
#[clap(
long,
value_name = "tokens",
env = "TOKENS",
help = "Token amount mapped to each receiver (in units of GRT)",
value_parser = U256::from_dec_str,
value_delimiter = ',',
)]
pub tokens: Vec<U256>,
}

#[derive(Clone, Debug, Args, Serialize, Deserialize, Default)]
#[group(required = false, multiple = true)]
pub struct WithdrawArgs {
#[clap(
long,
value_name = "receiver",
env = "RECEIVER",
help = "Withdraw deposit from the receiver",
value_parser = H160::from_str,
)]
pub receiver: H160,
}

#[allow(unused)]
#[derive(ValueEnum, Clone, Debug, Serialize, Deserialize, Default)]
pub enum FileType {
Expand Down
13 changes: 13 additions & 0 deletions file-exchange/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ async fn main() {
.unallocate(&unallocate_args.allocation_id)
.await
}
Some(OnchainAction::Deposit(deposit_args)) => {
transaction_manager
.deposit(&deposit_args.receiver, &deposit_args.tokens)
.await
}
Some(OnchainAction::DepositMany(deposit_many_args)) => {
transaction_manager
.deposit_many(deposit_many_args.receivers, deposit_many_args.tokens)
.await
}
Some(OnchainAction::Withdraw(withdraw_args)) => {
transaction_manager.withdraw(&withdraw_args.receiver).await
}
None => {
panic!("No onchain command provided (later add general status return)")
}
Expand Down

0 comments on commit e780a34

Please sign in to comment.