290: Monero daemon host configurable r=rishflab a=da-kami

Note: `monero-daemon-host` in accordance with the wallet RPC params, from wallet RPC help:

```
Usage:
  monero-wallet-rpc [--wallet-file=<file>|--generate-from-json=<file>|--wallet-dir=<directory>] [--rpc-bind-port=<port>]

General options:
  --help                                Produce help message
  --version                             Output version information

Wallet options:
  --daemon-address arg                  Use daemon instance at <host>:<port>
  --daemon-host arg                     Use daemon instance at host <arg>
                                        instead of localhost
```

Co-authored-by: Daniel Karzel <daniel@comit.network>
This commit is contained in:
bors[bot] 2021-03-05 05:29:16 +00:00 committed by GitHub
commit 4b99d68790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 46 deletions

View File

@ -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

View File

@ -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

View File

@ -5,9 +5,6 @@ authors = ["CoBloX developers <team@coblox.tech>"]
edition = "2018"
description = "XMR/BTC trustless atomic swaps."
[[bin]]
name = "swap_cli"
[lib]
name = "swap"

View File

@ -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(

View File

@ -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> {
monero::Address::from_str(s).with_context(|| {
format!(