mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 05:45:40 +00:00
Generate addresses as late as possible
This commit is contained in:
parent
3f43581da7
commit
9e30bd5151
@ -47,8 +47,6 @@ pub async fn swap(
|
|||||||
monero_wallet: Arc<monero::Wallet>,
|
monero_wallet: Arc<monero::Wallet>,
|
||||||
listen: Multiaddr,
|
listen: Multiaddr,
|
||||||
local_port: Option<u16>,
|
local_port: Option<u16>,
|
||||||
redeem_address: ::bitcoin::Address,
|
|
||||||
punish_address: ::bitcoin::Address,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
struct Network {
|
struct Network {
|
||||||
swarm: Arc<Mutex<Swarm>>,
|
swarm: Arc<Mutex<Swarm>>,
|
||||||
@ -131,6 +129,9 @@ pub async fn swap(
|
|||||||
None => unreachable!("should have amounts by here"),
|
None => unreachable!("should have amounts by here"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let redeem_address = bitcoin_wallet.as_ref().new_address().await?;
|
||||||
|
let punish_address = redeem_address.clone();
|
||||||
|
|
||||||
// TODO: Pass this in using <R: RngCore + CryptoRng>
|
// TODO: Pass this in using <R: RngCore + CryptoRng>
|
||||||
let rng = &mut OsRng;
|
let rng = &mut OsRng;
|
||||||
let state0 = State0::new(
|
let state0 = State0::new(
|
||||||
|
@ -46,7 +46,6 @@ pub async fn swap(
|
|||||||
addr: Multiaddr,
|
addr: Multiaddr,
|
||||||
mut cmd_tx: Sender<Cmd>,
|
mut cmd_tx: Sender<Cmd>,
|
||||||
mut rsp_rx: Receiver<Rsp>,
|
mut rsp_rx: Receiver<Rsp>,
|
||||||
refund_address: ::bitcoin::Address,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
struct Network(Swarm);
|
struct Network(Swarm);
|
||||||
|
|
||||||
@ -106,6 +105,8 @@ pub async fn swap(
|
|||||||
other => panic!("unexpected event: {:?}", other),
|
other => panic!("unexpected event: {:?}", other),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let refund_address = bitcoin_wallet.new_address().await?;
|
||||||
|
|
||||||
// TODO: Pass this in using <R: RngCore + CryptoRng>
|
// TODO: Pass this in using <R: RngCore + CryptoRng>
|
||||||
let rng = &mut OsRng;
|
let rng = &mut OsRng;
|
||||||
let state0 = State0::new(
|
let state0 = State0::new(
|
||||||
|
@ -74,20 +74,11 @@ async fn main() -> Result<()> {
|
|||||||
let bitcoin_wallet = bitcoin::Wallet::new("alice", &url)
|
let bitcoin_wallet = bitcoin::Wallet::new("alice", &url)
|
||||||
.await
|
.await
|
||||||
.expect("failed to create bitcoin wallet");
|
.expect("failed to create bitcoin wallet");
|
||||||
|
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
||||||
|
|
||||||
let monero_wallet = Arc::new(monero::Wallet::localhost(MONERO_WALLET_RPC_PORT));
|
let monero_wallet = Arc::new(monero::Wallet::localhost(MONERO_WALLET_RPC_PORT));
|
||||||
|
|
||||||
let redeem = bitcoin_wallet
|
swap_as_alice(bitcoin_wallet, monero_wallet, alice.clone()).await?;
|
||||||
.new_address()
|
|
||||||
.await
|
|
||||||
.expect("failed to get new redeem address");
|
|
||||||
let punish = bitcoin_wallet
|
|
||||||
.new_address()
|
|
||||||
.await
|
|
||||||
.expect("failed to get new punish address");
|
|
||||||
|
|
||||||
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
|
||||||
swap_as_alice(bitcoin_wallet, monero_wallet, alice.clone(), redeem, punish).await?;
|
|
||||||
} else {
|
} else {
|
||||||
info!("running swap node as Bob ...");
|
info!("running swap node as Bob ...");
|
||||||
|
|
||||||
@ -101,21 +92,16 @@ async fn main() -> Result<()> {
|
|||||||
let bitcoin_wallet = bitcoin::Wallet::new("bob", &url)
|
let bitcoin_wallet = bitcoin::Wallet::new("bob", &url)
|
||||||
.await
|
.await
|
||||||
.expect("failed to create bitcoin wallet");
|
.expect("failed to create bitcoin wallet");
|
||||||
|
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
||||||
|
|
||||||
let monero_wallet = Arc::new(monero::Wallet::localhost(MONERO_WALLET_RPC_PORT));
|
let monero_wallet = Arc::new(monero::Wallet::localhost(MONERO_WALLET_RPC_PORT));
|
||||||
|
|
||||||
let refund = bitcoin_wallet
|
|
||||||
.new_address()
|
|
||||||
.await
|
|
||||||
.expect("failed to get new address");
|
|
||||||
|
|
||||||
let bitcoin_wallet = Arc::new(bitcoin_wallet);
|
|
||||||
match (opt.piconeros, opt.satoshis) {
|
match (opt.piconeros, opt.satoshis) {
|
||||||
(Some(_), Some(_)) => bail!("Please supply only a single amount to swap"),
|
(Some(_), Some(_)) => bail!("Please supply only a single amount to swap"),
|
||||||
(None, None) => bail!("Please supply an amount to swap"),
|
(None, None) => bail!("Please supply an amount to swap"),
|
||||||
(Some(_picos), _) => todo!("support starting with picos"),
|
(Some(_picos), _) => todo!("support starting with picos"),
|
||||||
(None, Some(sats)) => {
|
(None, Some(sats)) => {
|
||||||
swap_as_bob(bitcoin_wallet, monero_wallet, sats, alice, refund).await?;
|
swap_as_bob(bitcoin_wallet, monero_wallet, sats, alice).await?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -145,24 +131,14 @@ async fn swap_as_alice(
|
|||||||
bitcoin_wallet: Arc<swap::bitcoin::Wallet>,
|
bitcoin_wallet: Arc<swap::bitcoin::Wallet>,
|
||||||
monero_wallet: Arc<swap::monero::Wallet>,
|
monero_wallet: Arc<swap::monero::Wallet>,
|
||||||
addr: Multiaddr,
|
addr: Multiaddr,
|
||||||
redeem: ::bitcoin::Address,
|
|
||||||
punish: ::bitcoin::Address,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
#[cfg(not(feature = "tor"))]
|
#[cfg(not(feature = "tor"))]
|
||||||
{
|
{
|
||||||
alice::swap(bitcoin_wallet, monero_wallet, addr, None, redeem, punish).await
|
alice::swap(bitcoin_wallet, monero_wallet, addr, None).await
|
||||||
}
|
}
|
||||||
#[cfg(feature = "tor")]
|
#[cfg(feature = "tor")]
|
||||||
{
|
{
|
||||||
alice::swap(
|
alice::swap(bitcoin_wallet, monero_wallet, addr, Some(PORT)).await
|
||||||
bitcoin_wallet,
|
|
||||||
monero_wallet,
|
|
||||||
addr,
|
|
||||||
Some(PORT),
|
|
||||||
redeem,
|
|
||||||
punish,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +147,6 @@ async fn swap_as_bob(
|
|||||||
monero_wallet: Arc<swap::monero::Wallet>,
|
monero_wallet: Arc<swap::monero::Wallet>,
|
||||||
sats: u64,
|
sats: u64,
|
||||||
alice: Multiaddr,
|
alice: Multiaddr,
|
||||||
refund: ::bitcoin::Address,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let (cmd_tx, mut cmd_rx) = mpsc::channel(1);
|
let (cmd_tx, mut cmd_rx) = mpsc::channel(1);
|
||||||
let (mut rsp_tx, rsp_rx) = mpsc::channel(1);
|
let (mut rsp_tx, rsp_rx) = mpsc::channel(1);
|
||||||
@ -182,7 +157,6 @@ async fn swap_as_bob(
|
|||||||
alice,
|
alice,
|
||||||
cmd_tx,
|
cmd_tx,
|
||||||
rsp_rx,
|
rsp_rx,
|
||||||
refund,
|
|
||||||
));
|
));
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
Loading…
Reference in New Issue
Block a user