mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Move definitions out of lib.rs
This commit is contained in:
parent
b88a777bae
commit
f2a25ee49b
@ -10,7 +10,7 @@ pub use ::bitcoin::{util::amount::Amount, Address, Network, Transaction, Txid};
|
|||||||
pub use ecdsa_fun::{adaptor::EncryptedSignature, fun::Scalar, Signature};
|
pub use ecdsa_fun::{adaptor::EncryptedSignature, fun::Scalar, Signature};
|
||||||
pub use wallet::Wallet;
|
pub use wallet::Wallet;
|
||||||
|
|
||||||
use crate::{bitcoin::timelocks::BlockHeight, config::Config, ExpiredTimelocks};
|
use crate::{bitcoin::timelocks::BlockHeight, config::Config};
|
||||||
use ::bitcoin::{
|
use ::bitcoin::{
|
||||||
hashes::{hex::ToHex, Hash},
|
hashes::{hex::ToHex, Hash},
|
||||||
secp256k1,
|
secp256k1,
|
||||||
@ -25,6 +25,7 @@ use rand::{CryptoRng, RngCore};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use timelocks::ExpiredTimelocks;
|
||||||
|
|
||||||
// TODO: Configurable tx-fee (note: parties have to agree prior to swapping)
|
// TODO: Configurable tx-fee (note: parties have to agree prior to swapping)
|
||||||
// Current reasoning:
|
// Current reasoning:
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// Represent a timelock, expressed in relative block height as defined in
|
/// Represent a timelock, expressed in relative block height as defined in
|
||||||
/// [BIP68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki).
|
/// [BIP68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki).
|
||||||
/// E.g. The timelock expires 10 blocks after the reference transaction is
|
/// E.g. The timelock expires 10 blocks after the reference transaction is
|
||||||
@ -47,3 +48,10 @@ impl Add<Timelock> for BlockHeight {
|
|||||||
BlockHeight(self.0 + rhs.0)
|
BlockHeight(self.0 + rhs.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum ExpiredTimelocks {
|
||||||
|
None,
|
||||||
|
Cancel,
|
||||||
|
Punish,
|
||||||
|
}
|
||||||
|
@ -2,8 +2,7 @@ use crate::{
|
|||||||
bitcoin::{EncryptedSignature, TxCancel, TxRefund},
|
bitcoin::{EncryptedSignature, TxCancel, TxRefund},
|
||||||
monero,
|
monero,
|
||||||
monero::monero_private_key,
|
monero::monero_private_key,
|
||||||
protocol::{alice, alice::AliceState},
|
protocol::{alice, alice::AliceState, SwapAmounts},
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
use ::bitcoin::hashes::core::fmt::Display;
|
use ::bitcoin::hashes::core::fmt::Display;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
monero::TransferProof,
|
monero::TransferProof,
|
||||||
protocol::{bob, bob::BobState},
|
protocol::{bob, bob::BobState, SwapAmounts},
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
use ::bitcoin::hashes::core::fmt::Display;
|
use ::bitcoin::hashes::core::fmt::Display;
|
||||||
use monero_harness::rpc::wallet::BlockHeight;
|
use monero_harness::rpc::wallet::BlockHeight;
|
||||||
|
@ -26,37 +26,3 @@ pub mod seed;
|
|||||||
pub mod trace;
|
pub mod trace;
|
||||||
|
|
||||||
mod fs;
|
mod fs;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::fmt::{self, Display};
|
|
||||||
|
|
||||||
/// XMR/BTC swap amounts.
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
// TODO(Franck): review necessity of this struct
|
|
||||||
pub struct SwapAmounts {
|
|
||||||
/// Amount of BTC to swap.
|
|
||||||
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
|
|
||||||
pub btc: bitcoin::Amount,
|
|
||||||
/// Amount of XMR to swap.
|
|
||||||
#[serde(with = "monero::monero_amount")]
|
|
||||||
pub xmr: monero::Amount,
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Display in XMR and BTC (not picos and sats).
|
|
||||||
impl Display for SwapAmounts {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"{} sats for {} piconeros",
|
|
||||||
self.btc.as_sat(),
|
|
||||||
self.xmr.as_piconero()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub enum ExpiredTimelocks {
|
|
||||||
None,
|
|
||||||
Cancel,
|
|
||||||
Punish,
|
|
||||||
}
|
|
||||||
|
@ -13,22 +13,24 @@
|
|||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use crate::cli::{Command, Options, Resume};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use prettytable::{row, Table};
|
use prettytable::{row, Table};
|
||||||
use std::sync::Arc;
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
use tracing::{info, log::LevelFilter};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use swap::{
|
use swap::{
|
||||||
bitcoin,
|
bitcoin,
|
||||||
config::Config,
|
config::Config,
|
||||||
database::Database,
|
database::Database,
|
||||||
monero,
|
monero,
|
||||||
protocol::{alice, bob, bob::Builder},
|
protocol::{alice, bob, bob::Builder, SwapAmounts},
|
||||||
trace::init_tracing,
|
trace::init_tracing,
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
use tracing::{info, log::LevelFilter};
|
|
||||||
use uuid::Uuid;
|
use crate::cli::{Command, Options, Resume};
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use crate::protocol::{alice, bob};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use libp2p::{
|
use libp2p::{
|
||||||
@ -8,8 +9,6 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::{fmt::Debug, io, marker::PhantomData};
|
use std::{fmt::Debug, io, marker::PhantomData};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use crate::protocol::{alice, bob};
|
|
||||||
|
|
||||||
/// Time to wait for a response back once we send a request.
|
/// Time to wait for a response back once we send a request.
|
||||||
pub const TIMEOUT: u64 = 3600; // One hour.
|
pub const TIMEOUT: u64 = 3600; // One hour.
|
||||||
|
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
use crate::monero;
|
||||||
|
use bitcoin::hashes::core::{fmt, fmt::Display};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub mod alice;
|
pub mod alice;
|
||||||
pub mod bob;
|
pub mod bob;
|
||||||
|
|
||||||
@ -6,3 +10,26 @@ pub struct StartingBalances {
|
|||||||
pub xmr: crate::monero::Amount,
|
pub xmr: crate::monero::Amount,
|
||||||
pub btc: bitcoin::Amount,
|
pub btc: bitcoin::Amount,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// XMR/BTC swap amounts.
|
||||||
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||||
|
pub struct SwapAmounts {
|
||||||
|
/// Amount of BTC to swap.
|
||||||
|
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
|
||||||
|
pub btc: bitcoin::Amount,
|
||||||
|
/// Amount of XMR to swap.
|
||||||
|
#[serde(with = "monero::monero_amount")]
|
||||||
|
pub xmr: crate::monero::Amount,
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Display in XMR and BTC (not picos and sats).
|
||||||
|
impl Display for SwapAmounts {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"{} sats for {} piconeros",
|
||||||
|
self.btc.as_sat(),
|
||||||
|
self.xmr.as_piconero()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,9 +21,8 @@ use crate::{
|
|||||||
transport::build,
|
transport::build,
|
||||||
Seed as NetworkSeed,
|
Seed as NetworkSeed,
|
||||||
},
|
},
|
||||||
protocol::bob,
|
protocol::{bob, SwapAmounts},
|
||||||
seed::Seed,
|
seed::Seed,
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use libp2p::{
|
use libp2p::{
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
bitcoin,
|
bitcoin,
|
||||||
bitcoin::{
|
bitcoin::{
|
||||||
current_epoch, timelocks::Timelock, wait_for_cancel_timelock_to_expire, GetBlockHeight,
|
current_epoch,
|
||||||
TransactionBlockHeight, TxCancel, TxRefund, WatchForRawTransaction,
|
timelocks::{ExpiredTimelocks, Timelock},
|
||||||
|
wait_for_cancel_timelock_to_expire, GetBlockHeight, TransactionBlockHeight, TxCancel,
|
||||||
|
TxRefund, WatchForRawTransaction,
|
||||||
},
|
},
|
||||||
monero,
|
monero,
|
||||||
monero::CreateWalletForOutput,
|
monero::CreateWalletForOutput,
|
||||||
network::request_response::AliceToBob,
|
network::request_response::AliceToBob,
|
||||||
protocol::{alice, bob},
|
protocol::{alice, bob, SwapAmounts},
|
||||||
ExpiredTimelocks, SwapAmounts,
|
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use ecdsa_fun::{
|
use ecdsa_fun::{
|
||||||
|
@ -1,16 +1,3 @@
|
|||||||
use anyhow::{Context, Result};
|
|
||||||
use ecdsa_fun::{adaptor::Adaptor, nonce::Deterministic};
|
|
||||||
use futures::{
|
|
||||||
future::{select, Either},
|
|
||||||
pin_mut,
|
|
||||||
};
|
|
||||||
use libp2p::request_response::ResponseChannel;
|
|
||||||
use rand::rngs::OsRng;
|
|
||||||
use sha2::Sha256;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::time::timeout;
|
|
||||||
use tracing::{info, trace};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bitcoin,
|
bitcoin,
|
||||||
bitcoin::{
|
bitcoin::{
|
||||||
@ -27,9 +14,21 @@ use crate::{
|
|||||||
protocol::{
|
protocol::{
|
||||||
alice,
|
alice,
|
||||||
alice::{event_loop::EventLoopHandle, SwapResponse},
|
alice::{event_loop::EventLoopHandle, SwapResponse},
|
||||||
|
SwapAmounts,
|
||||||
},
|
},
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
|
use anyhow::{Context, Result};
|
||||||
|
use ecdsa_fun::{adaptor::Adaptor, nonce::Deterministic};
|
||||||
|
use futures::{
|
||||||
|
future::{select, Either},
|
||||||
|
pin_mut,
|
||||||
|
};
|
||||||
|
use libp2p::request_response::ResponseChannel;
|
||||||
|
use rand::rngs::OsRng;
|
||||||
|
use sha2::Sha256;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tokio::time::timeout;
|
||||||
|
use tracing::{info, trace};
|
||||||
|
|
||||||
pub async fn negotiate(
|
pub async fn negotiate(
|
||||||
state0: alice::State0,
|
state0: alice::State0,
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
//! Alice holds XMR and wishes receive BTC.
|
//! Alice holds XMR and wishes receive BTC.
|
||||||
use crate::{
|
use crate::{
|
||||||
bitcoin,
|
bitcoin,
|
||||||
bitcoin::{TransactionBlockHeight, WaitForTransactionFinality, WatchForRawTransaction},
|
bitcoin::{
|
||||||
|
timelocks::ExpiredTimelocks, TransactionBlockHeight, WaitForTransactionFinality,
|
||||||
|
WatchForRawTransaction,
|
||||||
|
},
|
||||||
config::Config,
|
config::Config,
|
||||||
database,
|
database,
|
||||||
database::Database,
|
database::Database,
|
||||||
@ -22,7 +25,6 @@ use crate::{
|
|||||||
AliceState,
|
AliceState,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ExpiredTimelocks,
|
|
||||||
};
|
};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use async_recursion::async_recursion;
|
use async_recursion::async_recursion;
|
||||||
|
@ -11,9 +11,8 @@ use crate::{
|
|||||||
peer_tracker::{self, PeerTracker},
|
peer_tracker::{self, PeerTracker},
|
||||||
transport::build,
|
transport::build,
|
||||||
},
|
},
|
||||||
protocol::{alice, bob},
|
protocol::{alice, bob, SwapAmounts},
|
||||||
seed::Seed,
|
seed::Seed,
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use libp2p::{core::Multiaddr, identity::Keypair, NetworkBehaviour, PeerId};
|
use libp2p::{core::Multiaddr, identity::Keypair, NetworkBehaviour, PeerId};
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
bitcoin::{
|
bitcoin::{
|
||||||
self, current_epoch, timelocks::Timelock, wait_for_cancel_timelock_to_expire,
|
self, current_epoch,
|
||||||
BroadcastSignedTransaction, BuildTxLockPsbt, GetBlockHeight, GetNetwork, GetRawTransaction,
|
timelocks::{ExpiredTimelocks, Timelock},
|
||||||
Transaction, TransactionBlockHeight, TxCancel, Txid, WatchForRawTransaction,
|
wait_for_cancel_timelock_to_expire, BroadcastSignedTransaction, BuildTxLockPsbt,
|
||||||
|
GetBlockHeight, GetNetwork, GetRawTransaction, Transaction, TransactionBlockHeight,
|
||||||
|
TxCancel, Txid, WatchForRawTransaction,
|
||||||
},
|
},
|
||||||
config::Config,
|
config::Config,
|
||||||
monero,
|
monero,
|
||||||
monero::{monero_private_key, TransferProof},
|
monero::{monero_private_key, TransferProof},
|
||||||
protocol::{alice, bob},
|
protocol::{alice, bob, SwapAmounts},
|
||||||
ExpiredTimelocks, SwapAmounts,
|
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use ecdsa_fun::{
|
use ecdsa_fun::{
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
bitcoin,
|
bitcoin,
|
||||||
|
bitcoin::timelocks::ExpiredTimelocks,
|
||||||
config::Config,
|
config::Config,
|
||||||
database::{Database, Swap},
|
database::{Database, Swap},
|
||||||
monero,
|
monero,
|
||||||
protocol::bob::{self, event_loop::EventLoopHandle, state::*, SwapRequest},
|
protocol::{
|
||||||
ExpiredTimelocks, SwapAmounts,
|
bob::{self, event_loop::EventLoopHandle, state::*, SwapRequest},
|
||||||
|
SwapAmounts,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use async_recursion::async_recursion;
|
use async_recursion::async_recursion;
|
||||||
|
@ -9,9 +9,8 @@ use swap::{
|
|||||||
bitcoin,
|
bitcoin,
|
||||||
config::Config,
|
config::Config,
|
||||||
monero,
|
monero,
|
||||||
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
protocol::{alice, alice::AliceState, bob, bob::BobState, SwapAmounts},
|
||||||
seed::Seed,
|
seed::Seed,
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use testcontainers::{clients::Cli, Container};
|
use testcontainers::{clients::Cli, Container};
|
||||||
|
Loading…
Reference in New Issue
Block a user