From 7a5d5b3508d4eee2b679ade017d3fa4c3ffae4a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Bizjak?= Date: Sun, 1 Oct 2023 13:38:37 +0200 Subject: [PATCH] Avoid circular modules. --- generator/src/generator.rs | 45 ++++++++++++++++++++- generator/src/main.rs | 80 +++++++++----------------------------- 2 files changed, 62 insertions(+), 63 deletions(-) diff --git a/generator/src/generator.rs b/generator/src/generator.rs index 42586a68..373b6ce9 100644 --- a/generator/src/generator.rs +++ b/generator/src/generator.rs @@ -1,4 +1,5 @@ use anyhow::Context; +use clap::Args; use concordium_rust_sdk::{ base::cis4_types::CredentialInfo, cis2::{ @@ -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, + #[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, +} + +#[derive(Debug, Args)] +pub struct TransferCis2Args { + #[arg(long = "receivers", help = "Path to file containing receivers.")] + receivers: Option, +} + +#[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 { + 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 diff --git a/generator/src/main.rs b/generator/src/main.rs index 166d3baf..fa494255 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -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 { - 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, - #[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, -} - -#[derive(Debug, Args)] -pub struct TransferCis2Args { - #[arg(long = "receivers", help = "Path to file containing receivers.")] - receivers: Option, -} - #[derive(clap::Parser, Debug)] #[clap(author, version, about)] /// A transaction generator used for testing performance of the chain. @@ -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();