Skip to content

Commit

Permalink
Avoid circular modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
abizjak committed Oct 1, 2023
1 parent 913b89b commit 7a5d5b3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 63 deletions.
45 changes: 43 additions & 2 deletions generator/src/generator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Context;
use clap::Args;
use concordium_rust_sdk::{
base::cis4_types::CredentialInfo,
cis2::{
Expand Down Expand Up @@ -26,9 +27,49 @@ use concordium_rust_sdk::{
};
use futures::TryStreamExt;
use rand::{rngs::StdRng, Rng, SeedableRng};
use std::{collections, collections::BTreeMap, io::Cursor};
use std::{collections, collections::BTreeMap, io::Cursor, path::PathBuf, str::FromStr};

#[derive(Debug, Args)]
pub struct CcdArgs {
#[arg(long = "receivers", help = "Path to file containing receivers.")]
receivers: Option<PathBuf>,
#[clap(
long = "amount",
help = "CCD amount to send in each transaction",
default_value = "0"
)]
amount: Amount,
#[clap(
long = "mode",
help = "If set this provides the mode when selecting accounts. It can either be `random` \
or a non-negative integer. If it is an integer then the set of receivers is \
partitioned based on baker id into the given amount of chunks."
)]
mode: Option<Mode>,
}

#[derive(Debug, Args)]
pub struct TransferCis2Args {
#[arg(long = "receivers", help = "Path to file containing receivers.")]
receivers: Option<PathBuf>,
}

#[derive(Debug, Clone, Copy)]
enum Mode {
Random,
Every(usize),
}

use crate::{CcdArgs, Mode, TransferCis2Args};
impl FromStr for Mode {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"random" => Ok(Self::Random),
s => Ok(Self::Every(s.parse()?)),
}
}
}

// All contracts were taken from
// https://github.com/Concordium/concordium-rust-smart-contracts/tree/fcc668d87207aaf07b43f5a3b02b6d0a634368d0/examples
Expand Down
80 changes: 19 additions & 61 deletions generator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,72 +1,14 @@
use anyhow::Context;
use clap::{Args, Parser, Subcommand};
use concordium_rust_sdk::{common::types::Amount, endpoints::Endpoint, types::WalletAccount, v2};
use clap::{Parser, Subcommand};
use concordium_rust_sdk::{endpoints::Endpoint, types::WalletAccount, v2};
use generator::{
generate_transactions, CcdGenerator, CommonArgs, MintCis2Generator,
RegisterCredentialsGenerator, TransferCis2Generator, WccdGenerator,
};
use std::{path::PathBuf, str::FromStr};
use std::path::PathBuf;

mod generator;

#[derive(Debug, Clone, Copy)]
enum Mode {
Random,
Every(usize),
}

impl FromStr for Mode {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"random" => Ok(Self::Random),
s => Ok(Self::Every(s.parse()?)),
}
}
}

#[derive(Debug, Subcommand)]
enum Command {
/// Send CCD to a list of receivers.
Ccd(CcdArgs),
/// Mint CIS-2 NFT tokens.
MintNfts,
/// Transfer CIS-2 tokens to a list of receivers.
TransferCis2(TransferCis2Args),
/// Wrap, unwrap, and transfer WCCD tokens. First, wCCD are minted for every
/// account on the chain and then 1 wCCD is alternately wrapped,
/// transferred, and unwrapped.
Wccd,
/// Register Web3 ID credentials.
RegisterCredentials,
}

#[derive(Debug, Args)]
pub struct CcdArgs {
#[arg(long = "receivers", help = "Path to file containing receivers.")]
receivers: Option<PathBuf>,
#[clap(
long = "amount",
help = "CCD amount to send in each transaction",
default_value = "0"
)]
amount: Amount,
#[clap(
long = "mode",
help = "If set this provides the mode when selecting accounts. It can either be `random` \
or a non-negative integer. If it is an integer then the set of receivers is \
partitioned based on baker id into the given amount of chunks."
)]
mode: Option<Mode>,
}

#[derive(Debug, Args)]
pub struct TransferCis2Args {
#[arg(long = "receivers", help = "Path to file containing receivers.")]
receivers: Option<PathBuf>,
}

#[derive(clap::Parser, Debug)]
#[clap(author, version, about)]
/// A transaction generator used for testing performance of the chain.
Expand Down Expand Up @@ -96,6 +38,22 @@ struct App {
command: Command,
}

#[derive(Debug, Subcommand)]
enum Command {
/// Send CCD to a list of receivers.
Ccd(generator::CcdArgs),
/// Mint CIS-2 NFT tokens.
MintNfts,
/// Transfer CIS-2 tokens to a list of receivers.
TransferCis2(generator::TransferCis2Args),
/// Wrap, unwrap, and transfer WCCD tokens. First, wCCD are minted for every
/// account on the chain and then 1 wCCD is alternately wrapped,
/// transferred, and unwrapped.
Wccd,
/// Register Web3 ID credentials.
RegisterCredentials,
}

#[tokio::main(flavor = "multi_thread")]
async fn main() -> anyhow::Result<()> {
let app = App::parse();
Expand Down

0 comments on commit 7a5d5b3

Please sign in to comment.