Remove newlines from import statements to avoid problems

Rust fmt automatically groups the imports (from top to bottom) as `pub use` `use crate` and `use`.
There is no need to introduce sections which cause annoyance when auto importing using the IDE.
This commit is contained in:
Daniel Karzel 2021-01-21 11:20:57 +11:00
parent 4e858197c9
commit 44c4b5dcea
24 changed files with 120 additions and 146 deletions

View File

@ -24,11 +24,6 @@
pub mod image;
pub mod rpc;
use anyhow::{anyhow, bail, Result};
use std::time::Duration;
use testcontainers::{clients::Cli, core::Port, Container, Docker, RunArgs};
use tokio::time;
use crate::{
image::{
MONEROD_DAEMON_CONTAINER_NAME, MONEROD_DEFAULT_NETWORK, MONEROD_RPC_PORT, WALLET_RPC_PORT,
@ -38,6 +33,10 @@ use crate::{
wallet::{self, GetAddress, Refreshed, Transfer},
},
};
use anyhow::{anyhow, bail, Result};
use std::time::Duration;
use testcontainers::{clients::Cli, core::Port, Container, Docker, RunArgs};
use tokio::time;
/// How often we mine a block.
const BLOCK_TIME_SECS: u64 = 1;

View File

@ -1,26 +1,24 @@
pub use crate::bitcoin::{
timelocks::Timelock,
transactions::{TxCancel, TxLock, TxPunish, TxRedeem, TxRefund},
};
use crate::{bitcoin::timelocks::BlockHeight, config::Config, ExpiredTimelocks};
use ::bitcoin::{
hashes::{hex::ToHex, Hash},
secp256k1,
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;
use crate::{bitcoin::timelocks::BlockHeight, config::Config, ExpiredTimelocks};
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;
pub mod timelocks;

View File

@ -1,3 +1,7 @@
use crate::bitcoin::{
build_shared_output_descriptor, timelocks::Timelock, verify_sig, Address, Amount,
BuildTxLockPsbt, GetNetwork, PublicKey, Transaction, TX_FEE,
};
use ::bitcoin::{
util::{bip143::SigHashCache, psbt::PartiallySignedTransaction},
OutPoint, SigHash, SigHashType, TxIn, TxOut, Txid,
@ -8,11 +12,6 @@ use miniscript::{Descriptor, NullCtx};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::bitcoin::{
build_shared_output_descriptor, timelocks::Timelock, verify_sig, Address, Amount,
BuildTxLockPsbt, GetNetwork, PublicKey, Transaction, TX_FEE,
};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TxLock {
inner: Transaction,

View File

@ -1,12 +1,3 @@
use ::bitcoin::{util::psbt::PartiallySignedTransaction, Txid};
use anyhow::{Context, Result};
use async_trait::async_trait;
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
use bitcoin_harness::{bitcoind_rpc::PsbtBase64, BitcoindRpcApi};
use reqwest::Url;
use std::time::Duration;
use tokio::time::interval;
use crate::{
bitcoin::{
timelocks::BlockHeight, Address, Amount, BroadcastSignedTransaction, BuildTxLockPsbt,
@ -15,6 +6,14 @@ use crate::{
},
config::Config,
};
use ::bitcoin::{util::psbt::PartiallySignedTransaction, Txid};
use anyhow::{Context, Result};
use async_trait::async_trait;
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
use bitcoin_harness::{bitcoind_rpc::PsbtBase64, BitcoindRpcApi};
use reqwest::Url;
use std::time::Duration;
use tokio::time::interval;
#[derive(Debug)]
pub struct Wallet {

View File

@ -1,9 +1,8 @@
use crate::{bitcoin, monero};
use libp2p::{core::Multiaddr, PeerId};
use url::Url;
use uuid::Uuid;
use crate::{bitcoin, monero};
#[derive(structopt::StructOpt, Debug)]
pub struct Options {
// TODO: Default value should points to proper configuration folder in home folder

View File

@ -1,5 +1,4 @@
pub mod seed;
use crate::bitcoin::Timelock;
use conquer_once::Lazy;
use std::time::Duration;

View File

@ -5,7 +5,6 @@ use uuid::Uuid;
mod alice;
mod bob;
pub use alice::Alice;
pub use bob::Bob;

View File

@ -12,7 +12,6 @@
)]
#![forbid(unsafe_code)]
#![allow(non_snake_case)]
use crate::cli::{Command, Options, Resume};
use anyhow::{Context, Result};
use prettytable::{row, Table};

View File

@ -1,8 +1,11 @@
pub mod 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},
@ -14,11 +17,6 @@ use std::{
ops::{Add, Mul, Sub},
str::FromStr,
};
use crate::bitcoin;
pub use ::monero::{Network, PrivateKey, PublicKey};
pub use curve25519_dalek::scalar::Scalar;
pub use wallet::Wallet;
pub const PICONERO_OFFSET: u64 = 1_000_000_000_000;

View File

@ -1,3 +1,7 @@
use crate::monero::{
Amount, CreateWalletForOutput, InsufficientFunds, PrivateViewKey, PublicViewKey, Transfer,
TransferProof, TxHash, WatchForTransfer,
};
use ::monero::{Address, Network, PrivateKey, PublicKey};
use anyhow::Result;
use async_trait::async_trait;
@ -12,11 +16,6 @@ use std::{
use tracing::info;
use url::Url;
use crate::monero::{
Amount, CreateWalletForOutput, InsufficientFunds, PrivateViewKey, PublicViewKey, Transfer,
TransferProof, TxHash, WatchForTransfer,
};
#[derive(Debug)]
pub struct Wallet {
pub inner: wallet::Client,

View File

@ -1,5 +1,14 @@
//! Run an XMR/BTC swap in the role of Alice.
//! Alice holds XMR and wishes receive BTC.
pub use self::{
event_loop::{EventLoop, EventLoopHandle},
message0::Message0,
message1::Message1,
message2::Message2,
state::*,
swap::{run, run_until},
swap_response::*,
};
use crate::{
bitcoin,
config::Config,
@ -25,16 +34,6 @@ use std::{path::PathBuf, sync::Arc};
use tracing::{debug, info};
use uuid::Uuid;
pub use self::{
event_loop::{EventLoop, EventLoopHandle},
message0::Message0,
message1::Message1,
message2::Message2,
state::*,
swap::{run, run_until},
swap_response::*,
};
pub mod event_loop;
mod message0;
mod message1;

View File

@ -1,10 +1,3 @@
use anyhow::{anyhow, Context, Result};
use futures::FutureExt;
use libp2p::{
core::Multiaddr, futures::StreamExt, request_response::ResponseChannel, PeerId, Swarm,
};
use tokio::sync::mpsc::{Receiver, Sender};
use crate::{
network::{request_response::AliceToBob, transport::SwapTransport, TokioExecutor},
protocol::{
@ -13,6 +6,12 @@ use crate::{
bob,
},
};
use anyhow::{anyhow, Context, Result};
use futures::FutureExt;
use libp2p::{
core::Multiaddr, futures::StreamExt, request_response::ResponseChannel, PeerId, Swarm,
};
use tokio::sync::mpsc::{Receiver, Sender};
#[allow(missing_debug_implementations)]
pub struct Channels<T> {

View File

@ -1,3 +1,8 @@
use crate::{
bitcoin, monero,
network::request_response::{AliceToBob, BobToAlice, Codec, Message0Protocol, TIMEOUT},
protocol::bob,
};
use libp2p::{
request_response::{
handler::RequestProtocol, ProtocolSupport, RequestResponse, RequestResponseConfig,
@ -14,12 +19,6 @@ use std::{
};
use tracing::{debug, error};
use crate::{
bitcoin, monero,
network::request_response::{AliceToBob, BobToAlice, Codec, Message0Protocol, TIMEOUT},
protocol::bob,
};
#[derive(Debug)]
pub enum OutEvent {
Msg {

View File

@ -1,3 +1,7 @@
use crate::{
network::request_response::{AliceToBob, BobToAlice, Codec, Message1Protocol, TIMEOUT},
protocol::bob,
};
use ecdsa_fun::{adaptor::EncryptedSignature, Signature};
use libp2p::{
request_response::{
@ -15,11 +19,6 @@ use std::{
};
use tracing::{debug, error};
use crate::{
network::request_response::{AliceToBob, BobToAlice, Codec, Message1Protocol, TIMEOUT},
protocol::bob,
};
#[derive(Debug)]
pub enum OutEvent {
Msg {

View File

@ -1,3 +1,8 @@
use crate::{
monero,
network::request_response::{AliceToBob, BobToAlice, Codec, Message2Protocol, TIMEOUT},
protocol::bob,
};
use libp2p::{
request_response::{
handler::RequestProtocol, ProtocolSupport, RequestResponse, RequestResponseConfig,
@ -14,12 +19,6 @@ use std::{
};
use tracing::{debug, error};
use crate::{
monero,
network::request_response::{AliceToBob, BobToAlice, Codec, Message2Protocol, TIMEOUT},
protocol::bob,
};
#[derive(Debug)]
pub enum OutEvent {
Msg {

View File

@ -1,3 +1,7 @@
use crate::{
network::request_response::{AliceToBob, BobToAlice, Codec, Message3Protocol, TIMEOUT},
protocol::bob,
};
use libp2p::{
request_response::{
handler::RequestProtocol, ProtocolSupport, RequestResponse, RequestResponseConfig,
@ -13,11 +17,6 @@ use std::{
};
use tracing::{debug, error};
use crate::{
network::request_response::{AliceToBob, BobToAlice, Codec, Message3Protocol, TIMEOUT},
protocol::bob,
};
#[derive(Debug)]
pub enum OutEvent {
Msg(bob::Message3),

View File

@ -1,15 +1,3 @@
use anyhow::{anyhow, Context, Result};
use ecdsa_fun::{
adaptor::{Adaptor, EncryptedSignature},
nonce::Deterministic,
};
use libp2p::request_response::ResponseChannel;
use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
use sha2::Sha256;
use std::fmt;
use tracing::info;
use crate::{
bitcoin,
bitcoin::{
@ -22,6 +10,17 @@ use crate::{
protocol::{alice, bob},
ExpiredTimelocks, SwapAmounts,
};
use anyhow::{anyhow, Context, Result};
use ecdsa_fun::{
adaptor::{Adaptor, EncryptedSignature},
nonce::Deterministic,
};
use libp2p::request_response::ResponseChannel;
use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
use sha2::Sha256;
use std::fmt;
use tracing::info;
#[derive(Debug)]
pub enum AliceState {

View File

@ -1,16 +1,5 @@
//! Run an XMR/BTC swap in the role of Alice.
//! Alice holds XMR and wishes receive BTC.
use anyhow::{bail, Result};
use async_recursion::async_recursion;
use futures::{
future::{select, Either},
pin_mut,
};
use rand::{CryptoRng, RngCore};
use std::sync::Arc;
use tracing::{error, info};
use uuid::Uuid;
use crate::{
bitcoin,
bitcoin::{TransactionBlockHeight, WaitForTransactionFinality, WatchForRawTransaction},
@ -35,6 +24,16 @@ use crate::{
},
ExpiredTimelocks,
};
use anyhow::{bail, Result};
use async_recursion::async_recursion;
use futures::{
future::{select, Either},
pin_mut,
};
use rand::{CryptoRng, RngCore};
use std::sync::Arc;
use tracing::{error, info};
use uuid::Uuid;
trait Rng: RngCore + CryptoRng + Send {}

View File

@ -1,3 +1,8 @@
use crate::{
bitcoin, monero,
network::request_response::{AliceToBob, BobToAlice, Codec, Message0Protocol, TIMEOUT},
protocol::{alice, bob},
};
use libp2p::{
request_response::{
handler::RequestProtocol, ProtocolSupport, RequestResponse, RequestResponseConfig,
@ -14,12 +19,6 @@ use std::{
};
use tracing::{debug, error};
use crate::{
bitcoin, monero,
network::request_response::{AliceToBob, BobToAlice, Codec, Message0Protocol, TIMEOUT},
protocol::{alice, bob},
};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Message0 {
pub(crate) B: bitcoin::PublicKey,

View File

@ -1,3 +1,8 @@
use crate::{
bitcoin,
network::request_response::{AliceToBob, BobToAlice, Codec, Message1Protocol, TIMEOUT},
protocol::alice,
};
use libp2p::{
request_response::{
handler::RequestProtocol, ProtocolSupport, RequestResponse, RequestResponseConfig,
@ -14,12 +19,6 @@ use std::{
};
use tracing::{debug, error};
use crate::{
bitcoin,
network::request_response::{AliceToBob, BobToAlice, Codec, Message1Protocol, TIMEOUT},
protocol::alice,
};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Message1 {
pub(crate) tx_lock: bitcoin::TxLock,

View File

@ -1,3 +1,7 @@
use crate::{
network::request_response::{AliceToBob, BobToAlice, Codec, Message2Protocol, TIMEOUT},
protocol::alice,
};
use ecdsa_fun::Signature;
use libp2p::{
request_response::{
@ -15,11 +19,6 @@ use std::{
};
use tracing::{debug, error};
use crate::{
network::request_response::{AliceToBob, BobToAlice, Codec, Message2Protocol, TIMEOUT},
protocol::alice,
};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Message2 {
pub(crate) tx_punish_sig: Signature,

View File

@ -1,3 +1,7 @@
use crate::{
bitcoin::EncryptedSignature,
network::request_response::{AliceToBob, BobToAlice, Codec, Message3Protocol, TIMEOUT},
};
use libp2p::{
request_response::{
handler::RequestProtocol, ProtocolSupport, RequestResponse, RequestResponseConfig,
@ -14,11 +18,6 @@ use std::{
};
use tracing::error;
use crate::{
bitcoin::EncryptedSignature,
network::request_response::{AliceToBob, BobToAlice, Codec, Message3Protocol, TIMEOUT},
};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Message3 {
pub tx_redeem_encsig: EncryptedSignature,

View File

@ -1,14 +1,3 @@
use anyhow::{anyhow, Result};
use ecdsa_fun::{
adaptor::{Adaptor, EncryptedSignature},
nonce::Deterministic,
Signature,
};
use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
use sha2::Sha256;
use std::fmt;
use crate::{
bitcoin::{
self, current_epoch, timelocks::Timelock, wait_for_cancel_timelock_to_expire,
@ -21,6 +10,16 @@ use crate::{
protocol::{alice, bob},
ExpiredTimelocks, SwapAmounts,
};
use anyhow::{anyhow, Result};
use ecdsa_fun::{
adaptor::{Adaptor, EncryptedSignature},
nonce::Deterministic,
Signature,
};
use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
use sha2::Sha256;
use std::fmt;
#[derive(Debug, Clone)]
pub enum BobState {

View File

@ -1,11 +1,3 @@
use anyhow::{bail, Result};
use async_recursion::async_recursion;
use rand::{rngs::OsRng, CryptoRng, RngCore};
use std::sync::Arc;
use tokio::select;
use tracing::{debug, info};
use uuid::Uuid;
use crate::{
bitcoin,
config::Config,
@ -14,6 +6,13 @@ use crate::{
protocol::bob::{self, event_loop::EventLoopHandle, state::*, SwapRequest},
ExpiredTimelocks, SwapAmounts,
};
use anyhow::{bail, Result};
use async_recursion::async_recursion;
use rand::{rngs::OsRng, CryptoRng, RngCore};
use std::sync::Arc;
use tokio::select;
use tracing::{debug, info};
use uuid::Uuid;
pub fn is_complete(state: &BobState) -> bool {
matches!(