Skip to content

Commit

Permalink
Add monero-recovery command to print address + view/spend keys
Browse files Browse the repository at this point in the history
This allows manual recovery of problems like #537
Since we could not figure out what causes this issue, and it is most likely an upstream problem this is the best we can do so far to allow the user to manually interact with `monero-wallet-cli` or `monero-wallet-rpc`.
  • Loading branch information
da-kami committed Dec 20, 2021
1 parent b95ad75 commit df89ed6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- `monero-recovery` command that can be used to print the monero address, private spend and view key so one can manually recover instances where the `monero-wallet-rpc` does not pick up the Monero funds locked up by the ASB.
Related issue: https://github.com/comit-network/xmr-btc-swap/issues/537
The command takes the swap-id as parameter.
The swap has to be in a `BtcRedeemed` state.
Use `--help` for more details.

## [0.10.0] - 2021-10-15

### Removed
Expand Down
39 changes: 38 additions & 1 deletion swap/src/bin/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#![forbid(unsafe_code)]
#![allow(non_snake_case)]

use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};
use comfy_table::Table;
use qrcode::render::unicode;
use qrcode::QrCode;
Expand Down Expand Up @@ -417,6 +417,43 @@ async fn main() -> Result<()> {
let wallet_export = bitcoin_wallet.wallet_export("cli").await?;
println!("{}", wallet_export.to_string())
}
Command::MoneroRecovery { swap_id } => {
let db = open_db(data_dir.join("sqlite")).await?;

let swap_state: BobState = db.get_state(swap_id).await?.try_into()?;

match swap_state {
BobState::Started { .. }
| BobState::SwapSetupCompleted(_)
| BobState::BtcLocked(_)
| BobState::XmrLockProofReceived { .. }
| BobState::XmrLocked(_)
| BobState::EncSigSent(_)
| BobState::CancelTimelockExpired(_)
| BobState::BtcCancelled(_)
| BobState::BtcRefunded(_)
| BobState::BtcPunished { .. }
| BobState::SafelyAborted
| BobState::XmrRedeemed { .. } => {
bail!("Cannot print monero recovery information in state {}, only possible for BtcRedeemed", swap_state)
}
BobState::BtcRedeemed(state5) => {
let (spend_key, view_key) = state5.xmr_keys();

let address = monero::Address::standard(
env_config.monero_network,
monero::PublicKey::from_private_key(&spend_key),
monero::PublicKey::from(view_key.public()),
);
tracing::info!("Wallet address: {}", address.to_string());

let view_key = serde_json::to_string(&view_key)?;
println!("View key: {}", view_key);

println!("Spend key: {}", spend_key);
}
}
}
};
Ok(())
}
Expand Down
19 changes: 19 additions & 0 deletions swap/src/cli/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ where
},
}
}
RawCommand::MoneroRecovery { swap_id } => Arguments {
env_config: env_config_from(is_testnet),
debug,
json,
data_dir: data::data_dir_from(data, is_testnet)?,
cmd: Command::MoneroRecovery {
swap_id: swap_id.swap_id,
},
},
};

Ok(ParseResult::Arguments(arguments))
Expand Down Expand Up @@ -303,6 +312,9 @@ pub enum Command {
bitcoin_electrum_rpc_url: Url,
bitcoin_target_block: usize,
},
MoneroRecovery {
swap_id: Uuid,
},
}

#[derive(structopt::StructOpt, Debug)]
Expand Down Expand Up @@ -439,6 +451,13 @@ enum RawCommand {
#[structopt(flatten)]
bitcoin: Bitcoin,
},
/// Prints Monero information related to the swap in case the generated
/// wallet fails to detect the funds. This can only be used for swaps
/// that are in a `btc is redeemed` state.
MoneroRecovery {
#[structopt(flatten)]
swap_id: SwapId,
},
}

#[derive(structopt::StructOpt, Debug)]
Expand Down

0 comments on commit df89ed6

Please sign in to comment.