From 433704e48c5d46cb41266a03ab53660e4185ad4c Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Thu, 21 Jan 2021 17:09:53 +1100 Subject: [PATCH] Top to bottom `pub mod` then `mod` then `pub use` then `use` (incl. `use crate` and `use self`) --- monero-harness/src/lib.rs | 1 - swap/src/bitcoin.rs | 15 ++++++++------- swap/src/config.rs | 1 + swap/src/database.rs | 5 +++-- swap/src/lib.rs | 9 +++++---- swap/src/main.rs | 1 + swap/src/monero.rs | 7 ++++--- swap/src/network.rs | 8 ++++---- swap/tests/happy_path.rs | 4 ++-- swap/tests/happy_path_restart_alice.rs | 4 ++-- swap/tests/happy_path_restart_bob_after_comm.rs | 4 ++-- swap/tests/happy_path_restart_bob_before_comm.rs | 4 ++-- swap/tests/punish.rs | 4 ++-- swap/tests/refund_restart_alice.rs | 4 ++-- 14 files changed, 38 insertions(+), 33 deletions(-) diff --git a/monero-harness/src/lib.rs b/monero-harness/src/lib.rs index 353ebceb..f53f5c74 100644 --- a/monero-harness/src/lib.rs +++ b/monero-harness/src/lib.rs @@ -20,7 +20,6 @@ //! every BLOCK_TIME_SECS seconds. //! //! Also provides standalone JSON RPC clients for monerod and monero-wallet-rpc. - pub mod image; pub mod rpc; diff --git a/swap/src/bitcoin.rs b/swap/src/bitcoin.rs index a7ae1e0c..9948e5aa 100644 --- a/swap/src/bitcoin.rs +++ b/swap/src/bitcoin.rs @@ -1,7 +1,15 @@ +pub mod timelocks; +pub mod transactions; +pub mod wallet; + pub use crate::bitcoin::{ timelocks::Timelock, transactions::{TxCancel, TxLock, TxPunish, TxRedeem, TxRefund}, }; +pub use ::bitcoin::{util::amount::Amount, Address, Network, Transaction, Txid}; +pub use ecdsa_fun::{adaptor::EncryptedSignature, fun::Scalar, Signature}; +pub use wallet::Wallet; + use crate::{bitcoin::timelocks::BlockHeight, config::Config, ExpiredTimelocks}; use ::bitcoin::{ hashes::{hex::ToHex, Hash}, @@ -9,21 +17,14 @@ use ::bitcoin::{ util::psbt::PartiallySignedTransaction, SigHash, }; -pub use ::bitcoin::{util::amount::Amount, Address, Network, Transaction, Txid}; use anyhow::{anyhow, bail, Result}; use async_trait::async_trait; use ecdsa_fun::{adaptor::Adaptor, fun::Point, nonce::Deterministic, ECDSA}; -pub use ecdsa_fun::{adaptor::EncryptedSignature, fun::Scalar, Signature}; use miniscript::{Descriptor, Segwitv0}; use rand::{CryptoRng, RngCore}; use serde::{Deserialize, Serialize}; use sha2::Sha256; use std::str::FromStr; -pub use wallet::Wallet; - -pub mod timelocks; -pub mod transactions; -pub mod wallet; // TODO: Configurable tx-fee (note: parties have to agree prior to swapping) // Current reasoning: diff --git a/swap/src/config.rs b/swap/src/config.rs index b23cdc43..8ef318c2 100644 --- a/swap/src/config.rs +++ b/swap/src/config.rs @@ -1,4 +1,5 @@ pub mod seed; + use crate::bitcoin::Timelock; use conquer_once::Lazy; use std::time::Duration; diff --git a/swap/src/database.rs b/swap/src/database.rs index 6b314f14..33c02b0c 100644 --- a/swap/src/database.rs +++ b/swap/src/database.rs @@ -1,3 +1,6 @@ +pub use alice::Alice; +pub use bob::Bob; + use anyhow::{anyhow, bail, Context, Result}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::{fmt::Display, path::Path}; @@ -5,8 +8,6 @@ use uuid::Uuid; mod alice; mod bob; -pub use alice::Alice; -pub use bob::Bob; #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] pub enum Swap { diff --git a/swap/src/lib.rs b/swap/src/lib.rs index 569148ba..ab951533 100644 --- a/swap/src/lib.rs +++ b/swap/src/lib.rs @@ -16,19 +16,20 @@ missing_copy_implementations )] -use serde::{Deserialize, Serialize}; -use std::fmt::{self, Display}; - pub mod bitcoin; pub mod config; pub mod database; -mod fs; pub mod monero; pub mod network; pub mod protocol; pub mod seed; pub mod trace; +mod fs; + +use serde::{Deserialize, Serialize}; +use std::fmt::{self, Display}; + pub type Never = std::convert::Infallible; /// XMR/BTC swap amounts. diff --git a/swap/src/main.rs b/swap/src/main.rs index e02ab6f9..fdad3b55 100644 --- a/swap/src/main.rs +++ b/swap/src/main.rs @@ -12,6 +12,7 @@ )] #![forbid(unsafe_code)] #![allow(non_snake_case)] + use crate::cli::{Command, Options, Resume}; use anyhow::{Context, Result}; use prettytable::{row, Table}; diff --git a/swap/src/monero.rs b/swap/src/monero.rs index a4490466..1b65bc10 100644 --- a/swap/src/monero.rs +++ b/swap/src/monero.rs @@ -1,11 +1,13 @@ pub mod wallet; +pub use ::monero::{Network, PrivateKey, PublicKey}; +pub use curve25519_dalek::scalar::Scalar; +pub use wallet::Wallet; + use crate::bitcoin; use ::bitcoin::hashes::core::fmt::Formatter; -pub use ::monero::{Network, PrivateKey, PublicKey}; use anyhow::Result; use async_trait::async_trait; -pub use curve25519_dalek::scalar::Scalar; use rand::{CryptoRng, RngCore}; use rust_decimal::{ prelude::{FromPrimitive, ToPrimitive}, @@ -17,7 +19,6 @@ use std::{ ops::{Add, Mul, Sub}, str::FromStr, }; -pub use wallet::Wallet; pub const PICONERO_OFFSET: u64 = 1_000_000_000_000; diff --git a/swap/src/network.rs b/swap/src/network.rs index 0b0a70df..917b9977 100644 --- a/swap/src/network.rs +++ b/swap/src/network.rs @@ -1,3 +1,7 @@ +pub mod peer_tracker; +pub mod request_response; +pub mod transport; + use crate::seed::SEED_LENGTH; use bitcoin::hashes::{sha256, Hash, HashEngine}; use futures::prelude::*; @@ -5,10 +9,6 @@ use libp2p::{core::Executor, identity::ed25519}; use std::pin::Pin; use tokio::runtime::Handle; -pub mod peer_tracker; -pub mod request_response; -pub mod transport; - #[allow(missing_debug_implementations)] pub struct TokioExecutor { pub handle: Handle, diff --git a/swap/tests/happy_path.rs b/swap/tests/happy_path.rs index 57789eed..435edfa8 100644 --- a/swap/tests/happy_path.rs +++ b/swap/tests/happy_path.rs @@ -1,8 +1,8 @@ +pub mod testutils; + use swap::protocol::{alice, bob}; use tokio::join; -pub mod testutils; - /// Run the following tests with RUST_MIN_STACK=10000000 #[tokio::test] diff --git a/swap/tests/happy_path_restart_alice.rs b/swap/tests/happy_path_restart_alice.rs index 1f298818..f557db8b 100644 --- a/swap/tests/happy_path_restart_alice.rs +++ b/swap/tests/happy_path_restart_alice.rs @@ -1,7 +1,7 @@ -use swap::protocol::{alice, alice::AliceState, bob}; - pub mod testutils; +use swap::protocol::{alice, alice::AliceState, bob}; + #[tokio::test] async fn given_alice_restarts_after_encsig_is_learned_resume_swap() { testutils::setup_test(|mut ctx| async move { diff --git a/swap/tests/happy_path_restart_bob_after_comm.rs b/swap/tests/happy_path_restart_bob_after_comm.rs index 93382734..ca6c62cc 100644 --- a/swap/tests/happy_path_restart_bob_after_comm.rs +++ b/swap/tests/happy_path_restart_bob_after_comm.rs @@ -1,7 +1,7 @@ -use swap::protocol::{alice, bob, bob::BobState}; - pub mod testutils; +use swap::protocol::{alice, bob, bob::BobState}; + #[tokio::test] async fn given_bob_restarts_after_encsig_is_sent_resume_swap() { testutils::setup_test(|mut ctx| async move { diff --git a/swap/tests/happy_path_restart_bob_before_comm.rs b/swap/tests/happy_path_restart_bob_before_comm.rs index bd190b4c..ffbbe4af 100644 --- a/swap/tests/happy_path_restart_bob_before_comm.rs +++ b/swap/tests/happy_path_restart_bob_before_comm.rs @@ -1,10 +1,10 @@ +pub mod testutils; + use swap::protocol::{ alice, bob, bob::{swap::is_xmr_locked, BobState}, }; -pub mod testutils; - #[tokio::test] async fn given_bob_restarts_after_xmr_is_locked_resume_swap() { testutils::setup_test(|mut ctx| async move { diff --git a/swap/tests/punish.rs b/swap/tests/punish.rs index cc7289c4..4262b4bd 100644 --- a/swap/tests/punish.rs +++ b/swap/tests/punish.rs @@ -1,10 +1,10 @@ +pub mod testutils; + use swap::protocol::{ alice, bob, bob::{swap::is_btc_locked, BobState}, }; -pub mod testutils; - /// Bob locks Btc and Alice locks Xmr. Bob does not act; he fails to send Alice /// the encsig and fail to refund or redeem. Alice punishes. #[tokio::test] diff --git a/swap/tests/refund_restart_alice.rs b/swap/tests/refund_restart_alice.rs index a4908c95..031efe48 100644 --- a/swap/tests/refund_restart_alice.rs +++ b/swap/tests/refund_restart_alice.rs @@ -1,7 +1,7 @@ -use swap::protocol::{alice, alice::AliceState, bob}; - pub mod testutils; +use swap::protocol::{alice, alice::AliceState, bob}; + /// Bob locks btc and Alice locks xmr. Alice fails to act so Bob refunds. Alice /// then also refunds. #[tokio::test]