Skip to content

Commit

Permalink
bless whole source with rustfmt
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Sep 25, 2023
1 parent 3e7c2f2 commit 6e15b36
Show file tree
Hide file tree
Showing 431 changed files with 2,759 additions and 2,084 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::{anyhow, bail, Result};
use serde_json::Value as Json;
use std::collections::HashMap;

use anyhow::{anyhow, bail, Result};
use common::log::{debug, error};
use serde_json::Value as Json;

use super::init_activation_scheme::get_activation_scheme_path;
use crate::helpers::read_json_file;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::fs::OpenOptions;
use std::io::Write;
use std::path::PathBuf;

use anyhow::{anyhow, Result};
use common::log::{error, info};
use http::StatusCode;
use itertools::Itertools;
use mm2_net::transport::slurp_url;
use std::fs::OpenOptions;
use std::io::Write;
use std::path::PathBuf;

use crate::adex_config::AdexConfigImpl;
use crate::error_anyhow;
Expand Down
7 changes: 4 additions & 3 deletions mm2src/adex_cli/src/adex_config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::fmt::{Display, Formatter};
use std::fs;
use std::path::{Path, PathBuf};

use anyhow::{anyhow, bail, Result};
use directories::ProjectDirs;
use inquire::Password;
use log::{error, info, warn};
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
use std::fs;
use std::path::{Path, PathBuf};

use crate::adex_proc::SmartFractPrecision;
use crate::helpers::rewrite_json_file;
Expand Down
10 changes: 5 additions & 5 deletions mm2src/adex_cli/src/adex_proc/response_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
#[path = "response_handler/smart_fraction_fmt.rs"]
mod smart_fraction_fmt;

pub(crate) use smart_fraction_fmt::SmartFractPrecision;
use std::cell::RefCell;
use std::fmt::Debug;
use std::io::Write;

use anyhow::{anyhow, Result};
use common::{write_safe::io::WriteSafeIO, write_safe_io, writeln_safe_io};
use itertools::Itertools;
use log::{error, info};
use mm2_rpc::data::legacy::{BalanceResponse, CoinInitResponse, GetEnabledResponse, Mm2RpcResult, MmVersionResponse,
OrderbookResponse, SellBuyResponse, Status};
use serde_json::Value as Json;
use std::cell::RefCell;
use std::fmt::Debug;
use std::io::Write;
pub(crate) use smart_fraction_fmt::SmartFractPrecision;

use super::OrderbookConfig;
use crate::adex_config::AdexConfig;
use crate::error_anyhow;
use common::{write_safe::io::WriteSafeIO, write_safe_io, writeln_safe_io};

pub(crate) trait ResponseHandler {
fn print_response(&self, response: Json) -> Result<()>;
Expand Down
5 changes: 3 additions & 2 deletions mm2src/adex_cli/src/adex_proc/response_handler/orderbook.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use mm2_number::bigdecimal::ToPrimitive;
use mm2_rpc::data::legacy::{AggregatedOrderbookEntry, OrderConfirmationsSettings};
use std::cmp::Ordering;
use std::fmt::{Display, Formatter};

use mm2_number::bigdecimal::ToPrimitive;
use mm2_rpc::data::legacy::{AggregatedOrderbookEntry, OrderConfirmationsSettings};

use super::{smart_fraction_fmt::{SmartFractPrecision, SmartFractionFmt},
OrderbookConfig};

Expand Down
7 changes: 4 additions & 3 deletions mm2src/adex_cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::collections::HashSet;
use std::mem::take;
use std::str::FromStr;

use anyhow::Result;
use clap::{ArgAction, Args, Parser, Subcommand, ValueEnum};
use common::serde_derive::Serialize;
use mm2_number::{bigdecimal::ParseBigDecimalError, BigDecimal, MmNumber};
use mm2_rpc::data::legacy::{MatchBy, OrderType, SellBuyRequest};
use rpc::v1::types::H256 as H256Json;
use std::collections::HashSet;
use std::mem::take;
use std::str::FromStr;
use uuid::Uuid;

use crate::adex_config::{get_config, set_config, AdexConfig};
Expand Down
7 changes: 4 additions & 3 deletions mm2src/adex_cli/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use anyhow::{anyhow, Result};
use common::log::error;
use serde::{Deserialize, Serialize};
use std::fs;
use std::io::Write;
use std::ops::Deref;
#[cfg(unix)] use std::os::unix::fs::PermissionsExt;
use std::path::Path;

use anyhow::{anyhow, Result};
use common::log::error;
use serde::{Deserialize, Serialize};

use crate::error_anyhow;

pub(crate) fn rewrite_data_file<T>(data: T, file: &str) -> Result<()>
Expand Down
5 changes: 3 additions & 2 deletions mm2src/adex_cli/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[cfg(not(any(test, target_arch = "wasm32")))]
use log::LevelFilter;
#[cfg(not(any(test, target_arch = "wasm32")))]
use std::io::Write;

#[cfg(not(any(test, target_arch = "wasm32")))]
use log::LevelFilter;

#[cfg(not(any(test, target_arch = "wasm32")))]
pub(super) fn init_logging() {
let mut builder = env_logger::builder();
Expand Down
7 changes: 4 additions & 3 deletions mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::net::Ipv4Addr;
use std::ops::Not;
use std::path::Path;

use anyhow::{anyhow, Result};
use bip39::{Language, Mnemonic, MnemonicType};
use common::log::{error, info};
use common::password_policy;
use inquire::{validator::Validation, Confirm, CustomType, CustomUserError, Text};
use passwords::PasswordGenerator;
use serde::Serialize;
use std::net::Ipv4Addr;
use std::ops::Not;
use std::path::Path;

use super::inquire_extentions::{InquireOption, DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER, DEFAULT_OPTION_BOOL_FORMATTER,
OPTION_BOOL_PARSER};
Expand Down
3 changes: 2 additions & 1 deletion mm2src/adex_cli/src/scenarios/inquire_extentions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use inquire::parser::DEFAULT_BOOL_PARSER;
use std::str::FromStr;

use inquire::parser::DEFAULT_BOOL_PARSER;

#[derive(Clone)]
pub(super) enum InquireOption<T> {
Some(T),
Expand Down
10 changes: 6 additions & 4 deletions mm2src/adex_cli/src/scenarios/mm2_proc_mng.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
use anyhow::{anyhow, Result};
use common::log::{error, info};
use std::env;
use std::path::PathBuf;

use crate::error_anyhow;

use anyhow::{anyhow, Result};
use common::log::{error, info};
#[cfg(not(target_os = "macos"))]
use sysinfo::{PidExt, ProcessExt, System, SystemExt};

use crate::error_anyhow;

#[cfg(windows)]
mod reexport {
pub(super) use std::ffi::CString;
pub(super) use std::mem;
pub(super) use std::mem::size_of;
pub(super) use std::ptr::null;
pub(super) use std::u32;

pub(super) use winapi::um::processthreadsapi::{CreateProcessA, OpenProcess, TerminateProcess, PROCESS_INFORMATION,
STARTUPINFOA};
pub(super) use winapi::um::winnt::{PROCESS_TERMINATE, SYNCHRONIZE};
Expand Down Expand Up @@ -48,6 +49,7 @@ mod macos_reexport {
pub(super) use std::process::Command;
pub(super) use std::thread::sleep;
pub(super) use std::time::Duration;

pub(super) use sysinfo::{ProcessExt, System, SystemExt};
pub(super) const LAUNCHCTL_MM2_ID: &str = "com.komodoproject.mm2";
}
Expand Down
3 changes: 1 addition & 2 deletions mm2src/adex_cli/src/scenarios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use anyhow::Result;
use init_coins::init_coins;
use init_mm2_cfg::init_mm2_cfg;
use log::info;
pub(super) use mm2_proc_mng::{get_status, start_process, stop_process};

use super::activation_scheme_db::init_activation_scheme;

pub(super) use mm2_proc_mng::{get_status, start_process, stop_process};

pub(super) async fn init(cfg_file: &str, coins_file: &str) { let _ = init_impl(cfg_file, coins_file).await; }

async fn init_impl(cfg_file: &str, coins_file: &str) -> Result<()> {
Expand Down
1 change: 1 addition & 0 deletions mm2src/adex_cli/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::io::Write;
use std::time::Duration;

use tokio::io::AsyncWriteExt;
use tokio::net::{TcpListener, TcpStream};

Expand Down
10 changes: 5 additions & 5 deletions mm2src/adex_cli/src/transport.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use anyhow::{anyhow, bail, Result};
use async_trait::async_trait;
use http::{HeaderMap, StatusCode};
use serde::{Deserialize, Serialize};

use common::log::{error, warn};
use http::{HeaderMap, StatusCode};
use hyper_dangerous::get_hyper_client_dangerous;
use mm2_net::native_http::SlurpHttpClient;
use serde::{Deserialize, Serialize};

use crate::{error_anyhow, error_bail, warn_bail};

Expand Down Expand Up @@ -85,12 +84,13 @@ impl Response for (StatusCode, HeaderMap, Vec<u8>) {

mod hyper_dangerous {

use std::sync::Arc;
use std::time::SystemTime;

use hyper::{client::HttpConnector, Body, Client};
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
use rustls::client::{ServerCertVerified, ServerCertVerifier};
use rustls::{RootCertStore, DEFAULT_CIPHER_SUITES, DEFAULT_VERSIONS};
use std::sync::Arc;
use std::time::SystemTime;

use super::*;

Expand Down
18 changes: 10 additions & 8 deletions mm2src/coins/coin_balance.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
use crate::hd_pubkey::HDXPubExtractor;
use crate::hd_wallet::{HDAccountOps, HDAddressId, HDWalletCoinOps, HDWalletOps, NewAccountCreatingError,
NewAddressDerivingError};
use crate::{BalanceError, BalanceResult, CoinBalance, CoinWithDerivationMethod, DerivationMethod, HDAddress,
MarketCoinOps};
use std::collections::HashMap;
use std::ops::Range;
use std::{fmt, iter};

use async_trait::async_trait;
use common::log::{debug, info};
use crypto::{Bip44Chain, RpcDerivationPath};
use futures::compat::Future01CompatExt;
use mm2_err_handle::prelude::*;
use mm2_number::BigDecimal;
#[cfg(test)] use mocktopus::macros::*;
use std::collections::HashMap;
use std::ops::Range;
use std::{fmt, iter};

use crate::hd_pubkey::HDXPubExtractor;
use crate::hd_wallet::{HDAccountOps, HDAddressId, HDWalletCoinOps, HDWalletOps, NewAccountCreatingError,
NewAddressDerivingError};
use crate::{BalanceError, BalanceResult, CoinBalance, CoinWithDerivationMethod, DerivationMethod, HDAddress,
MarketCoinOps};

pub type AddressIdRange = Range<u32>;

Expand Down
8 changes: 5 additions & 3 deletions mm2src/coins/coin_errors.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::{eth::Web3RpcError, my_tx_history_v2::MyTxHistoryErrorV2, utxo::rpc_clients::UtxoRpcError, DelegationError,
NumConversError, TxHistoryError, UnexpectedDerivationMethod, WithdrawError};
use std::num::TryFromIntError;

use futures01::Future;
use mm2_err_handle::prelude::MmError;
use spv_validation::helpers_validation::SPVError;
use std::num::TryFromIntError;

use crate::{eth::Web3RpcError, my_tx_history_v2::MyTxHistoryErrorV2, utxo::rpc_clients::UtxoRpcError, DelegationError,
NumConversError, TxHistoryError, UnexpectedDerivationMethod, WithdrawError};

/// Helper type used as result for swap payment validation function(s)
pub type ValidatePaymentFut<T> = Box<dyn Future<Item = T, Error = MmError<ValidatePaymentError>> + Send>;
Expand Down
31 changes: 18 additions & 13 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
//
// Copyright © 2022 AtomicDEX. All rights reserved.
//
use super::eth::Action::{Call, Create};
use crate::lp_price::get_base_price_in_rel;
use crate::nft::nft_structs::{ContractType, ConvertChain, TransactionNftDetails, WithdrawErc1155, WithdrawErc721};
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::ops::Deref;
#[cfg(not(target_arch = "wasm32"))] use std::path::PathBuf;
use std::str::FromStr;
use std::sync::atomic::{AtomicU64, Ordering as AtomicOrdering};
use std::sync::{Arc, Mutex};

use async_trait::async_trait;
use bitcrypto::{keccak256, ripemd160, sha256};
use common::custom_futures::repeatable::{Ready, Retry, RetryOnError};
Expand Down Expand Up @@ -60,25 +65,24 @@ use secp256k1::PublicKey;
use serde_json::{self as json, Value as Json};
use serialization::{CompactInteger, Serializable, Stream};
use sha3::{Digest, Keccak256};
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::ops::Deref;
#[cfg(not(target_arch = "wasm32"))] use std::path::PathBuf;
use std::str::FromStr;
use std::sync::atomic::{AtomicU64, Ordering as AtomicOrdering};
use std::sync::{Arc, Mutex};
use web3::types::{Action as TraceAction, BlockId, BlockNumber, Bytes, CallRequest, FilterBuilder, Log, Trace,
TraceFilterBuilder, Transaction as Web3Transaction, TransactionId, U64};
use web3::{self, Web3};
use web3_transport::{http_transport::HttpTransportNode, EthFeeHistoryNamespace, Web3Transport};

use super::eth::Action::{Call, Create};
use crate::lp_price::get_base_price_in_rel;
use crate::nft::nft_structs::{ContractType, ConvertChain, TransactionNftDetails, WithdrawErc1155, WithdrawErc721};

cfg_wasm32! {
use crypto::MetamaskArc;
use ethereum_types::{H264, H520};
use mm2_metamask::MetamaskError;
use web3::types::TransactionRequest;
}

pub use rlp;

use super::watcher_common::{validate_watcher_reward, REWARD_GAS_AMOUNT};
use super::{coin_conf, lp_coinfind_or_err, AsyncMutex, BalanceError, BalanceFut, CheckIfMyPaymentSentArgs,
CoinBalance, CoinFutSpawner, CoinProtocol, CoinTransportMetrics, CoinsContext, ConfirmPaymentInput,
Expand All @@ -99,20 +103,21 @@ use super::{coin_conf, lp_coinfind_or_err, AsyncMutex, BalanceError, BalanceFut,
WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest, WithdrawResult, EARLY_CONFIRMATION_ERR_LOG,
INVALID_CONTRACT_ADDRESS_ERR_LOG, INVALID_PAYMENT_STATE_ERR_LOG, INVALID_RECEIVER_ERR_LOG,
INVALID_SENDER_ERR_LOG, INVALID_SWAP_ID_ERR_LOG};
pub use rlp;

#[cfg(test)] mod eth_tests;
#[cfg(target_arch = "wasm32")] mod eth_wasm_tests;
mod web3_transport;

#[path = "eth/v2_activation.rs"] pub mod v2_activation;
use crate::nft::{find_wallet_nft_amount, WithdrawNftResult};
use v2_activation::{build_address_and_priv_key_policy, EthActivationV2Error};

use crate::nft::{find_wallet_nft_amount, WithdrawNftResult};

mod nonce;
use crate::{PrivKeyPolicy, TransactionResult, WithdrawFrom};
use nonce::ParityNonce;

use crate::{PrivKeyPolicy, TransactionResult, WithdrawFrom};

/// https://github.com/artemii235/etomic-swap/blob/master/contracts/EtomicSwap.sol
/// Dev chain (195.201.137.5:8565) contract address: 0x83965C539899cC0F918552e5A26915de40ee8852
/// Ropsten: https://ropsten.etherscan.io/address/0x7bc1bbdd6a0a722fc9bffc49c921b685ecb84b94
Expand Down
5 changes: 3 additions & 2 deletions mm2src/coins/eth/eth_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use super::*;
use crate::IguanaPrivKey;
use common::{block_on, now_sec, wait_until_sec};
use crypto::privkey::key_pair_from_seed;
use ethkey::{Generator, Random};
Expand All @@ -10,6 +8,9 @@ use mm2_test_helpers::{for_tests::{eth_jst_testnet_conf, eth_testnet_conf, ETH_D
get_passphrase};
use mocktopus::mocking::*;

use super::*;
use crate::IguanaPrivKey;

/// The gas price for the tests
const GAS_PRICE: u64 = 50_000_000_000;
// `GAS_PRICE` increased by 3%
Expand Down
5 changes: 3 additions & 2 deletions mm2src/coins/eth/eth_wasm_tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::*;
use crate::lp_coininit;
use crypto::CryptoCtx;
use mm2_core::mm_ctx::MmCtxBuilder;
use mm2_test_helpers::for_tests::{ETH_DEV_NODE, ETH_DEV_SWAP_CONTRACT};
use wasm_bindgen_test::*;
use web_sys::console;

use super::*;
use crate::lp_coininit;

wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen_test]
Expand Down
Loading

0 comments on commit 6e15b36

Please sign in to comment.