diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff4e82e0..b460f3e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,11 +60,11 @@ jobs: run: | cargo build -p swap --target ${{ matrix.target }} - - name: Upload swap_cli binary + - name: Upload swap binary uses: actions/upload-artifact@v2-preview with: name: swap-${{ matrix.target }} - path: target/${{ matrix.target }}/debug/swap_cli + path: target/${{ matrix.target }}/debug/swap - name: Upload asb binary uses: actions/upload-artifact@v2-preview diff --git a/.github/workflows/release-cli.yml b/.github/workflows/release-cli.yml index 69c7e578..ccccae45 100644 --- a/.github/workflows/release-cli.yml +++ b/.github/workflows/release-cli.yml @@ -1,4 +1,4 @@ -name: "Release swap_cli" +name: "Release swap" on: release: @@ -6,7 +6,7 @@ on: jobs: release: - name: Release swap_cli + name: Release swap strategy: matrix: include: @@ -30,10 +30,10 @@ jobs: - uses: Swatinem/rust-cache@v1.2.0 - name: Build ${{ matrix.target }} release binary - run: cargo build --target=${{ matrix.target }} --release --package swap --bin swap_cli + run: cargo build --target=${{ matrix.target }} --release --package swap --bin swap - name: Smoke test the binary - run: target/${{ matrix.target }}/release/swap_cli --help + run: target/${{ matrix.target }}/release/swap --help # Remove once python 3 is the default - uses: actions/setup-python@v1 @@ -51,26 +51,26 @@ jobs: triple = "${{ matrix.target }}".split("-") arch = triple[0] - archive_name=f'swap_cli_${{ github.event.release.tag_name }}_{os_info.system}_{arch}.${{ matrix.archive_ext }}' + archive_name=f'swap_${{ github.event.release.tag_name }}_{os_info.system}_{arch}.${{ matrix.archive_ext }}' print(f'::set-output name=archive::{archive_name}') - name: Pack macos archive if: matrix.os == 'macos-latest' shell: bash - run: gtar -C ./target/${{ matrix.target }}/release --create --file=${{ steps.create-archive-name.outputs.archive }} swap_cli + run: gtar -C ./target/${{ matrix.target }}/release --create --file=${{ steps.create-archive-name.outputs.archive }} swap - name: Pack linux archive if: matrix.os == 'ubuntu-latest' shell: bash - run: tar -C ./target/${{ matrix.target }}/release --create --file=${{ steps.create-archive-name.outputs.archive }} swap_cli + run: tar -C ./target/${{ matrix.target }}/release --create --file=${{ steps.create-archive-name.outputs.archive }} swap - name: Pack windows archive if: matrix.os == 'windows-latest' shell: bash run: | - cp target/${{ matrix.target }}/release/swap_cli.exe ./swap_cli.exe - 7z a -tzip ${{ steps.create-archive-name.outputs.archive }} ./swap_cli.exe + cp target/${{ matrix.target }}/release/swap.exe ./swap.exe + 7z a -tzip ${{ steps.create-archive-name.outputs.archive }} ./swap.exe - name: Upload archive uses: actions/upload-release-asset@v1 diff --git a/swap/Cargo.toml b/swap/Cargo.toml index 27958b71..2b3d8f3b 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -5,9 +5,6 @@ authors = ["CoBloX developers "] edition = "2018" description = "XMR/BTC trustless atomic swaps." -[[bin]] -name = "swap_cli" - [lib] name = "swap" diff --git a/swap/src/bin/swap_cli.rs b/swap/src/bin/swap.rs similarity index 92% rename from swap/src/bin/swap_cli.rs rename to swap/src/bin/swap.rs index fffcee53..e85f6cb4 100644 --- a/swap/src/bin/swap_cli.rs +++ b/swap/src/bin/swap.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use std::time::Duration; use structopt::StructOpt; use swap::bitcoin::{Amount, TxLock}; -use swap::cli::command::{Arguments, Command}; +use swap::cli::command::{Arguments, Command, ConnectParams, MoneroParams}; use swap::cli::config::{read_config, Config}; use swap::database::Database; use swap::execution_params::GetExecutionParams; @@ -84,9 +84,16 @@ async fn main() -> Result<()> { match args.cmd { Command::BuyXmr { - receive_monero_address, - alice_peer_id, - alice_addr, + connect_params: + ConnectParams { + alice_peer_id, + alice_addr, + }, + monero_params: + MoneroParams { + receive_monero_address, + monero_daemon_host, + }, } => { if receive_monero_address.network != monero_network { bail!( @@ -97,7 +104,8 @@ async fn main() -> Result<()> { } let bitcoin_wallet = init_bitcoin_wallet(bitcoin_network, &config, seed).await?; - let (monero_wallet, _process) = init_monero_wallet(monero_network, &config).await?; + let (monero_wallet, _process) = + init_monero_wallet(monero_network, &config, monero_daemon_host).await?; let bitcoin_wallet = Arc::new(bitcoin_wallet); let (event_loop, mut event_loop_handle) = EventLoop::new( &seed.derive_libp2p_identity(), @@ -159,17 +167,25 @@ async fn main() -> Result<()> { table.printstd(); } Command::Resume { - receive_monero_address, swap_id, - alice_peer_id, - alice_addr, + connect_params: + ConnectParams { + alice_peer_id, + alice_addr, + }, + monero_params: + MoneroParams { + receive_monero_address, + monero_daemon_host, + }, } => { if receive_monero_address.network != monero_network { bail!("The given monero address is on network {:?}, expected address of network {:?}.", receive_monero_address.network, monero_network) } let bitcoin_wallet = init_bitcoin_wallet(bitcoin_network, &config, seed).await?; - let (monero_wallet, _process) = init_monero_wallet(monero_network, &config).await?; + let (monero_wallet, _process) = + init_monero_wallet(monero_network, &config, monero_daemon_host).await?; let bitcoin_wallet = Arc::new(bitcoin_wallet); let (event_loop, event_loop_handle) = EventLoop::new( @@ -265,13 +281,14 @@ async fn init_bitcoin_wallet( async fn init_monero_wallet( monero_network: monero::Network, config: &Config, + monero_daemon_host: String, ) -> Result<(monero::Wallet, monero::WalletRpcProcess)> { const MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME: &str = "swap-tool-blockchain-monitoring-wallet"; let monero_wallet_rpc = monero::WalletRpc::new(config.data.dir.join("monero")).await?; let monero_wallet_rpc_process = monero_wallet_rpc - .run(monero_network, "monero-stagenet.exan.tech") + .run(monero_network, monero_daemon_host.as_str()) .await?; let monero_wallet = monero::Wallet::new( diff --git a/swap/src/cli/command.rs b/swap/src/cli/command.rs index e478680f..6f9e9f6e 100644 --- a/swap/src/cli/command.rs +++ b/swap/src/cli/command.rs @@ -8,6 +8,9 @@ use uuid::Uuid; pub const DEFAULT_ALICE_MULTIADDR: &str = "/dns4/xmr-btc-asb.coblox.tech/tcp/9876"; pub const DEFAULT_ALICE_PEER_ID: &str = "12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi"; +// Port is assumed to be stagenet standard port 38081 +pub const DEFAULT_STAGENET_MONERO_DAEMON_HOST: &str = "monero-stagenet.exan.tech"; + #[derive(structopt::StructOpt, Debug)] pub struct Arguments { #[structopt( @@ -28,36 +31,22 @@ pub struct Arguments { #[structopt(name = "xmr_btc-swap", about = "XMR BTC atomic swap")] pub enum Command { BuyXmr { - #[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))] - receive_monero_address: monero::Address, + #[structopt(flatten)] + connect_params: ConnectParams, - #[structopt(long = "connect-peer-id", default_value = DEFAULT_ALICE_PEER_ID)] - alice_peer_id: PeerId, - - #[structopt( - long = "connect-addr", - default_value = DEFAULT_ALICE_MULTIADDR - )] - alice_addr: Multiaddr, + #[structopt(flatten)] + monero_params: MoneroParams, }, History, Resume { - #[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))] - receive_monero_address: monero::Address, - #[structopt(long = "swap-id")] swap_id: Uuid, - // TODO: Remove Alice peer-id/address, it should be saved in the database when running swap - // and loaded from the database when running resume/cancel/refund - #[structopt(long = "counterpart-peer-id", default_value = DEFAULT_ALICE_PEER_ID)] - alice_peer_id: PeerId, + #[structopt(flatten)] + connect_params: ConnectParams, - #[structopt( - long = "counterpart-addr", - default_value = DEFAULT_ALICE_MULTIADDR - )] - alice_addr: Multiaddr, + #[structopt(flatten)] + monero_params: MoneroParams, }, Cancel { #[structopt(long = "swap-id")] @@ -75,6 +64,30 @@ pub enum Command { }, } +#[derive(structopt::StructOpt, Debug)] +pub struct ConnectParams { + #[structopt(long = "connect-peer-id", default_value = DEFAULT_ALICE_PEER_ID)] + pub alice_peer_id: PeerId, + + #[structopt( + long = "connect-addr", + default_value = DEFAULT_ALICE_MULTIADDR + )] + pub alice_addr: Multiaddr, +} + +#[derive(structopt::StructOpt, Debug)] +pub struct MoneroParams { + #[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))] + pub receive_monero_address: monero::Address, + + #[structopt( + long = "monero-daemon-host", + default_value = DEFAULT_STAGENET_MONERO_DAEMON_HOST + )] + pub monero_daemon_host: String, +} + fn parse_monero_address(s: &str) -> Result { monero::Address::from_str(s).with_context(|| { format!(