mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-12-16 00:53:58 -05:00
Merge #290
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:
commit
4b99d68790
5 changed files with 73 additions and 46 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
|
@ -60,11 +60,11 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
cargo build -p swap --target ${{ matrix.target }}
|
cargo build -p swap --target ${{ matrix.target }}
|
||||||
|
|
||||||
- name: Upload swap_cli binary
|
- name: Upload swap binary
|
||||||
uses: actions/upload-artifact@v2-preview
|
uses: actions/upload-artifact@v2-preview
|
||||||
with:
|
with:
|
||||||
name: swap-${{ matrix.target }}
|
name: swap-${{ matrix.target }}
|
||||||
path: target/${{ matrix.target }}/debug/swap_cli
|
path: target/${{ matrix.target }}/debug/swap
|
||||||
|
|
||||||
- name: Upload asb binary
|
- name: Upload asb binary
|
||||||
uses: actions/upload-artifact@v2-preview
|
uses: actions/upload-artifact@v2-preview
|
||||||
|
|
|
||||||
18
.github/workflows/release-cli.yml
vendored
18
.github/workflows/release-cli.yml
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
name: "Release swap_cli"
|
name: "Release swap"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
|
|
@ -6,7 +6,7 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
name: Release swap_cli
|
name: Release swap
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
|
|
@ -30,10 +30,10 @@ jobs:
|
||||||
- uses: Swatinem/rust-cache@v1.2.0
|
- uses: Swatinem/rust-cache@v1.2.0
|
||||||
|
|
||||||
- name: Build ${{ matrix.target }} release binary
|
- 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
|
- 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
|
# Remove once python 3 is the default
|
||||||
- uses: actions/setup-python@v1
|
- uses: actions/setup-python@v1
|
||||||
|
|
@ -51,26 +51,26 @@ jobs:
|
||||||
triple = "${{ matrix.target }}".split("-")
|
triple = "${{ matrix.target }}".split("-")
|
||||||
arch = triple[0]
|
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}')
|
print(f'::set-output name=archive::{archive_name}')
|
||||||
|
|
||||||
- name: Pack macos archive
|
- name: Pack macos archive
|
||||||
if: matrix.os == 'macos-latest'
|
if: matrix.os == 'macos-latest'
|
||||||
shell: bash
|
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
|
- name: Pack linux archive
|
||||||
if: matrix.os == 'ubuntu-latest'
|
if: matrix.os == 'ubuntu-latest'
|
||||||
shell: bash
|
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
|
- name: Pack windows archive
|
||||||
if: matrix.os == 'windows-latest'
|
if: matrix.os == 'windows-latest'
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
cp target/${{ matrix.target }}/release/swap_cli.exe ./swap_cli.exe
|
cp target/${{ matrix.target }}/release/swap.exe ./swap.exe
|
||||||
7z a -tzip ${{ steps.create-archive-name.outputs.archive }} ./swap_cli.exe
|
7z a -tzip ${{ steps.create-archive-name.outputs.archive }} ./swap.exe
|
||||||
|
|
||||||
- name: Upload archive
|
- name: Upload archive
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,6 @@ authors = ["CoBloX developers <team@coblox.tech>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "XMR/BTC trustless atomic swaps."
|
description = "XMR/BTC trustless atomic swaps."
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "swap_cli"
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "swap"
|
name = "swap"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use swap::bitcoin::{Amount, TxLock};
|
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::cli::config::{read_config, Config};
|
||||||
use swap::database::Database;
|
use swap::database::Database;
|
||||||
use swap::execution_params::GetExecutionParams;
|
use swap::execution_params::GetExecutionParams;
|
||||||
|
|
@ -84,9 +84,16 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
match args.cmd {
|
match args.cmd {
|
||||||
Command::BuyXmr {
|
Command::BuyXmr {
|
||||||
receive_monero_address,
|
connect_params:
|
||||||
|
ConnectParams {
|
||||||
alice_peer_id,
|
alice_peer_id,
|
||||||
alice_addr,
|
alice_addr,
|
||||||
|
},
|
||||||
|
monero_params:
|
||||||
|
MoneroParams {
|
||||||
|
receive_monero_address,
|
||||||
|
monero_daemon_host,
|
||||||
|
},
|
||||||
} => {
|
} => {
|
||||||
if receive_monero_address.network != monero_network {
|
if receive_monero_address.network != monero_network {
|
||||||
bail!(
|
bail!(
|
||||||
|
|
@ -97,7 +104,8 @@ async fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let bitcoin_wallet = init_bitcoin_wallet(bitcoin_network, &config, seed).await?;
|
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 bitcoin_wallet = Arc::new(bitcoin_wallet);
|
||||||
let (event_loop, mut event_loop_handle) = EventLoop::new(
|
let (event_loop, mut event_loop_handle) = EventLoop::new(
|
||||||
&seed.derive_libp2p_identity(),
|
&seed.derive_libp2p_identity(),
|
||||||
|
|
@ -159,17 +167,25 @@ async fn main() -> Result<()> {
|
||||||
table.printstd();
|
table.printstd();
|
||||||
}
|
}
|
||||||
Command::Resume {
|
Command::Resume {
|
||||||
receive_monero_address,
|
|
||||||
swap_id,
|
swap_id,
|
||||||
|
connect_params:
|
||||||
|
ConnectParams {
|
||||||
alice_peer_id,
|
alice_peer_id,
|
||||||
alice_addr,
|
alice_addr,
|
||||||
|
},
|
||||||
|
monero_params:
|
||||||
|
MoneroParams {
|
||||||
|
receive_monero_address,
|
||||||
|
monero_daemon_host,
|
||||||
|
},
|
||||||
} => {
|
} => {
|
||||||
if receive_monero_address.network != monero_network {
|
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)
|
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 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 bitcoin_wallet = Arc::new(bitcoin_wallet);
|
||||||
|
|
||||||
let (event_loop, event_loop_handle) = EventLoop::new(
|
let (event_loop, event_loop_handle) = EventLoop::new(
|
||||||
|
|
@ -265,13 +281,14 @@ async fn init_bitcoin_wallet(
|
||||||
async fn init_monero_wallet(
|
async fn init_monero_wallet(
|
||||||
monero_network: monero::Network,
|
monero_network: monero::Network,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
|
monero_daemon_host: String,
|
||||||
) -> Result<(monero::Wallet, monero::WalletRpcProcess)> {
|
) -> Result<(monero::Wallet, monero::WalletRpcProcess)> {
|
||||||
const MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME: &str = "swap-tool-blockchain-monitoring-wallet";
|
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 = monero::WalletRpc::new(config.data.dir.join("monero")).await?;
|
||||||
|
|
||||||
let monero_wallet_rpc_process = monero_wallet_rpc
|
let monero_wallet_rpc_process = monero_wallet_rpc
|
||||||
.run(monero_network, "monero-stagenet.exan.tech")
|
.run(monero_network, monero_daemon_host.as_str())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let monero_wallet = monero::Wallet::new(
|
let monero_wallet = monero::Wallet::new(
|
||||||
|
|
@ -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_MULTIADDR: &str = "/dns4/xmr-btc-asb.coblox.tech/tcp/9876";
|
||||||
pub const DEFAULT_ALICE_PEER_ID: &str = "12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi";
|
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)]
|
#[derive(structopt::StructOpt, Debug)]
|
||||||
pub struct Arguments {
|
pub struct Arguments {
|
||||||
#[structopt(
|
#[structopt(
|
||||||
|
|
@ -28,36 +31,22 @@ pub struct Arguments {
|
||||||
#[structopt(name = "xmr_btc-swap", about = "XMR BTC atomic swap")]
|
#[structopt(name = "xmr_btc-swap", about = "XMR BTC atomic swap")]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
BuyXmr {
|
BuyXmr {
|
||||||
#[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))]
|
#[structopt(flatten)]
|
||||||
receive_monero_address: monero::Address,
|
connect_params: ConnectParams,
|
||||||
|
|
||||||
#[structopt(long = "connect-peer-id", default_value = DEFAULT_ALICE_PEER_ID)]
|
#[structopt(flatten)]
|
||||||
alice_peer_id: PeerId,
|
monero_params: MoneroParams,
|
||||||
|
|
||||||
#[structopt(
|
|
||||||
long = "connect-addr",
|
|
||||||
default_value = DEFAULT_ALICE_MULTIADDR
|
|
||||||
)]
|
|
||||||
alice_addr: Multiaddr,
|
|
||||||
},
|
},
|
||||||
History,
|
History,
|
||||||
Resume {
|
Resume {
|
||||||
#[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))]
|
|
||||||
receive_monero_address: monero::Address,
|
|
||||||
|
|
||||||
#[structopt(long = "swap-id")]
|
#[structopt(long = "swap-id")]
|
||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
|
|
||||||
// TODO: Remove Alice peer-id/address, it should be saved in the database when running swap
|
#[structopt(flatten)]
|
||||||
// and loaded from the database when running resume/cancel/refund
|
connect_params: ConnectParams,
|
||||||
#[structopt(long = "counterpart-peer-id", default_value = DEFAULT_ALICE_PEER_ID)]
|
|
||||||
alice_peer_id: PeerId,
|
|
||||||
|
|
||||||
#[structopt(
|
#[structopt(flatten)]
|
||||||
long = "counterpart-addr",
|
monero_params: MoneroParams,
|
||||||
default_value = DEFAULT_ALICE_MULTIADDR
|
|
||||||
)]
|
|
||||||
alice_addr: Multiaddr,
|
|
||||||
},
|
},
|
||||||
Cancel {
|
Cancel {
|
||||||
#[structopt(long = "swap-id")]
|
#[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> {
|
fn parse_monero_address(s: &str) -> Result<monero::Address> {
|
||||||
monero::Address::from_str(s).with_context(|| {
|
monero::Address::from_str(s).with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue