From a71b2775fe7779780bdc06267a0ebcb170fd3fb9 Mon Sep 17 00:00:00 2001 From: parazyd Date: Wed, 29 Sep 2021 17:10:20 +0200 Subject: [PATCH] bin: Remove unused files. --- src/bin/cashierd_old | 134 ------------------------------------ src/bin/darkfid_old | 115 ------------------------------- src/bin/test | 158 ------------------------------------------- 3 files changed, 407 deletions(-) delete mode 100644 src/bin/cashierd_old delete mode 100644 src/bin/darkfid_old delete mode 100644 src/bin/test diff --git a/src/bin/cashierd_old b/src/bin/cashierd_old deleted file mode 100644 index 64bd93a94..000000000 --- a/src/bin/cashierd_old +++ /dev/null @@ -1,134 +0,0 @@ -use async_std::sync::Arc; -use std::net::SocketAddr; - -use std::path::PathBuf; - -use blake2b_simd::Params; -use drk::cli::{CashierdCli, CashierdConfig, Config}; -use drk::serial::{deserialize, serialize}; -use drk::service::CashierService; -use drk::util::join_config_path; -use drk::wallet::{CashierDb, WalletDb}; -use drk::{Error, Result}; -use serde::{Deserialize, Serialize}; - -use async_executor::Executor; -use easy_parallel::Parallel; - -// TODO: this will be replaced by a vector of assets that can be updated at runtime -#[derive(Deserialize, Serialize, Debug)] -pub struct Asset { - pub name: String, - pub id: Vec, -} - -impl Asset { - pub fn new(name: String) -> Self { - let id = Self::id_hash(&name); - Self { name, id } - } - pub fn id_hash(name: &String) -> Vec { - let mut hasher = Params::new().hash_length(64).to_state(); - hasher.update(name.as_bytes()); - let result = hasher.finalize(); - let hash = jubjub::Fr::from_bytes_wide(result.as_array()); - let id = serialize(&hash); - id - } -} - -async fn start(executor: Arc>, config: Arc) -> Result<()> { - let ex = executor.clone(); - let accept_addr: SocketAddr = config.accept_url.parse()?; - - let gateway_addr: SocketAddr = config.gateway_url.parse()?; - - let database_path = join_config_path(&PathBuf::from("cashier_client_database.db"))?; - - let cashierdb = join_config_path(&PathBuf::from("cashier.db"))?; - let client_wallet = join_config_path(&PathBuf::from("cashier_client_walletdb.db"))?; - - let wallet = CashierDb::new( - &cashierdb.clone(), - config.password.clone(), - )?; - - let client_wallet = WalletDb::new( - &client_wallet.clone(), - config.client_password.clone(), - )?; - - let mint_params_path = join_config_path(&PathBuf::from("cashier_mint.params"))?; - let spend_params_path = join_config_path(&PathBuf::from("cashier_spend.params"))?; - - let mut cashier = CashierService::new( - accept_addr, - wallet.clone(), - client_wallet.clone(), - database_path, - (gateway_addr, "127.0.0.1:4444".parse()?), - (mint_params_path, spend_params_path), - ) - .await?; - - // TODO: make this a vector of accepted assets - let asset = Asset::new("btc".to_string()); - // TODO: this should be done by the user - let asset_id = deserialize(&asset.id)?; - - // TODO: pass vector of assets into cashier.start() - cashier.start(ex.clone(), asset_id).await?; - - Ok(()) -} - -fn main() -> Result<()> { - let ex = Arc::new(Executor::new()); - let (signal, shutdown) = async_channel::unbounded::<()>(); - - let path = join_config_path(&PathBuf::from("cashierd.toml")).unwrap(); - - let config: CashierdConfig = Config::::load(path)?; - - let config = Arc::new(config); - - let options = CashierdCli::load()?; - - { - use simplelog::*; - let logger_config = ConfigBuilder::new().set_time_format_str("%T%.6f").build(); - - let debug_level = if options.verbose { - LevelFilter::Debug - } else { - LevelFilter::Off - }; - - let log_path = config.log_path.clone(); - CombinedLogger::init(vec![ - TermLogger::new(debug_level, logger_config, TerminalMode::Mixed).unwrap(), - WriteLogger::new( - LevelFilter::Debug, - Config::default(), - std::fs::File::create(log_path).unwrap(), - ), - ]) - .unwrap(); - } - - let ex2 = ex.clone(); - - let (_, result) = Parallel::new() - // Run four executor threads. - .each(0..3, |_| smol::future::block_on(ex.run(shutdown.recv()))) - // Run the main future on the current thread. - .finish(|| { - smol::future::block_on(async move { - start(ex2, config).await?; - drop(signal); - Ok::<(), Error>(()) - }) - }); - - result -} diff --git a/src/bin/darkfid_old b/src/bin/darkfid_old deleted file mode 100644 index f1a7dd797..000000000 --- a/src/bin/darkfid_old +++ /dev/null @@ -1,115 +0,0 @@ -use drk::blockchain::Rocks; -use drk::cli::{Config, DarkfidCli, DarkfidConfig}; -use drk::util::join_config_path; -use drk::wallet::WalletDb; -use drk::Result; - -use drk::client::Client; - -use async_executor::Executor; -use easy_parallel::Parallel; - -use async_std::sync::Arc; -use std::net::SocketAddr; -use std::path::PathBuf; - -async fn start(executor: Arc>, config: Arc) -> Result<()> { - let connect_addr: SocketAddr = config.connect_url.parse()?; - let sub_addr: SocketAddr = config.subscriber_url.parse()?; - let cashier_addr: SocketAddr = config.cashier_url.parse()?; - let rpc_url: std::net::SocketAddr = config.rpc_url.parse()?; - - let database_path = join_config_path(&PathBuf::from("database_client.db"))?; - let walletdb_path = join_config_path(&PathBuf::from("walletdb.db"))?; - - let rocks = Rocks::new(&database_path)?; - - let wallet = WalletDb::new(&walletdb_path, config.password.clone())?; - - let mint_params_path = join_config_path(&PathBuf::from("mint.params"))?; - let spend_params_path = join_config_path(&PathBuf::from("spend.params"))?; - - if let Err(_) = wallet.get_keypairs() { - wallet.init_db()?; - wallet.key_gen()?; - } - - let mut client = Client::new( - rocks, - (connect_addr, sub_addr), - (mint_params_path, spend_params_path), - wallet.clone(), - )?; - - client.start().await?; - - Client::connect_to_cashier( - client, - executor.clone(), - cashier_addr.clone(), - rpc_url.clone(), - ) - .await?; - - Ok(()) -} - -fn main() -> Result<()> { - let options = Arc::new(DarkfidCli::load()?); - - let config_path: PathBuf; - - match options.config.as_ref() { - Some(path) => { - config_path = path.to_owned(); - } - None => { - config_path = join_config_path(&PathBuf::from("darkfid.toml"))?; - } - } - - let config: DarkfidConfig = Config::::load(config_path)?; - - let config = Arc::new(config); - - let ex = Arc::new(Executor::new()); - let (signal, shutdown) = async_channel::unbounded::<()>(); - - { - use simplelog::*; - let logger_config = ConfigBuilder::new().set_time_format_str("%T%.6f").build(); - - let debug_level = if options.verbose { - LevelFilter::Debug - } else { - LevelFilter::Off - }; - - let log_path = config.log_path.clone(); - CombinedLogger::init(vec![ - TermLogger::new(debug_level, logger_config, TerminalMode::Mixed).unwrap(), - WriteLogger::new( - LevelFilter::Debug, - Config::default(), - std::fs::File::create(log_path).unwrap(), - ), - ]) - .unwrap(); - } - - let ex2 = ex.clone(); - - let (_, result) = Parallel::new() - // Run four executor threads. - .each(0..3, |_| smol::future::block_on(ex.run(shutdown.recv()))) - // Run the main future on the current thread. - .finish(|| { - smol::future::block_on(async move { - start(ex2, config).await?; - drop(signal); - Ok::<(), drk::Error>(()) - }) - }); - - result -} diff --git a/src/bin/test b/src/bin/test deleted file mode 100644 index cf96e98dd..000000000 --- a/src/bin/test +++ /dev/null @@ -1,158 +0,0 @@ -#[macro_use] -extern crate clap; -use clap::ArgMatches; -use drk::cli::{Config, DrkConfig}; -use drk::util::join_config_path; -use drk::{rpc::jsonrpc, rpc::jsonrpc::JsonResult, Error, Result}; -use log::debug; -use serde::{Deserialize, Serialize}; -use serde_json::{json, Value}; -use simplelog::{ - CombinedLogger, Config as SimplelogConfig, ConfigBuilder, LevelFilter, TermLogger, - TerminalMode, WriteLogger, -}; -use std::path::PathBuf; - -struct Drk { - url: String, -} - -impl Drk { - pub fn new(url: String) -> Self { - Self { url } - } - - async fn request(&self, r: jsonrpc::JsonRequest) -> Result { - let r = json!(r); - // create http body from json - let data = surf::Body::from_json(&r)?; - debug!(target: "DRK", "--> {:?}", r); - println!("--> {:?}", r); - let d2 = surf::Body::from_json(&r)?; - println!("{:?}", d2.into_string().await); - // send the data to the server - let mut req = surf::post(&self.url).body(data).await?; - - // get the response - let resp = req.take_body(); - // read the response body as a string - let json = resp.into_string().await?; - - // parse the response into a JsonResult - println!("{}", json); - let v: JsonResult = serde_json::from_str(&json)?; - match v { - JsonResult::Resp(r) => { - debug!(target: "DRK", "<-- {:?}", r); - return Ok(r.result); - } - - JsonResult::Err(e) => { - debug!(target: "DRK", "<-- {:?}", e); - println!("here!"); - return Err(Error::JsonRpcError(e.error.message.to_string())); - } - - JsonResult::Notif(n) => { - debug!(target: "DRK", "<-- {:?}", n); - return Err(Error::JsonRpcError( - "Unexpected reply from server".to_string(), - )); - } - }; - } - - async fn deposit(&self, network: String, asset: String) -> Result { - // create json request - // method = deposit - // params = network, asset - // type = Value - let req = jsonrpc::request(json!("deposit"), json!([network, asset])); - // call request function - Ok(self.request(req).await?) - } -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct XX { - pub foo: Value, -} - -async fn start(config: &DrkConfig, options: ArgMatches<'_>) -> Result<()> { - //let req = json!(jsonrpc::request( - // json!("deposit"), - // json!(["solana", "USDC"]) - //)); - - ////let x = json!(XX { foo: json!(2) }); - //let ss = req.to_string(); - //println!("{}", ss); - //let v: jsonrpc::JsonRequest = serde_json::from_str(&ss)?; - //return Ok(()); - // - let client = Drk::new(config.rpc_url.clone()); - - if let Some(matches) = options.subcommand_matches("deposit") { - let network = matches.value_of("network").unwrap().to_lowercase(); - let token = matches.value_of("TOKEN").unwrap(); - - let reply = client - .deposit(network.to_string(), token.to_string()) - .await?; - - println!( - "Deposit your coins to the following address: {}", - &reply.to_string() - ); - - return Ok(()); - } - - println!("Please run 'drk help' to see usage."); - Err(Error::MissingParams) -} - -fn main() -> Result<()> { - let args = clap_app!(drk => - (@subcommand deposit => - (about: "Deposit clear assets for Dark assets") - (@arg network: +required +takes_value --network - "Which network to use (bitcoin/solana/...)") - (@arg TOKEN: +required - "Which token to deposit (BTC/SOL/USDC/...)") - ) - ) - .get_matches(); - - let config_path: PathBuf; - if args.is_present("CONFIG") { - config_path = PathBuf::from(args.value_of("CONFIG").unwrap()); - } else { - config_path = join_config_path(&PathBuf::from("drk.toml"))?; - } - - let config = Config::::load(config_path)?; - - let logger_config = ConfigBuilder::new().set_time_format_str("%T%.6f").build(); - - // TODO: --verbose - let debug_level = if args.is_present("verbose") { - LevelFilter::Debug - } else { - LevelFilter::Off - }; - - let log_path = config.log_path.clone(); - - CombinedLogger::init(vec![ - TermLogger::new(debug_level, logger_config, TerminalMode::Mixed).unwrap(), - WriteLogger::new( - LevelFilter::Debug, - SimplelogConfig::default(), - std::fs::File::create(log_path).unwrap(), - ), - ]) - .unwrap(); - - futures::executor::block_on(start(&config, args)) -}