mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
fix(cli): allow bitcoin-change-address to be omitted when making request to rpc server (#1728)
This commit is contained in:
parent
c80bdb2d8c
commit
75cfc6b0d4
@ -437,7 +437,7 @@ pub mod api_test {
|
|||||||
|
|
||||||
Request::new(Method::BuyXmr {
|
Request::new(Method::BuyXmr {
|
||||||
seller,
|
seller,
|
||||||
bitcoin_change_address,
|
bitcoin_change_address: Some(bitcoin_change_address),
|
||||||
monero_receive_address,
|
monero_receive_address,
|
||||||
swap_id: Uuid::new_v4(),
|
swap_id: Uuid::new_v4(),
|
||||||
})
|
})
|
||||||
|
@ -31,7 +31,7 @@ pub struct Request {
|
|||||||
pub enum Method {
|
pub enum Method {
|
||||||
BuyXmr {
|
BuyXmr {
|
||||||
seller: Multiaddr,
|
seller: Multiaddr,
|
||||||
bitcoin_change_address: bitcoin::Address,
|
bitcoin_change_address: Option<bitcoin::Address>,
|
||||||
monero_receive_address: monero::Address,
|
monero_receive_address: monero::Address,
|
||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
},
|
},
|
||||||
@ -335,6 +335,25 @@ impl Request {
|
|||||||
let env_config = context.config.env_config;
|
let env_config = context.config.env_config;
|
||||||
let seed = context.config.seed.clone().context("Could not get seed")?;
|
let seed = context.config.seed.clone().context("Could not get seed")?;
|
||||||
|
|
||||||
|
// When no change address was provided we default to the internal wallet
|
||||||
|
let bitcoin_change_address = match bitcoin_change_address {
|
||||||
|
Some(addr) => addr,
|
||||||
|
None => {
|
||||||
|
let internal_wallet_address = context
|
||||||
|
.bitcoin_wallet()
|
||||||
|
.expect("bitcoin wallet should exist")
|
||||||
|
.new_address()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
tracing::info!(
|
||||||
|
internal_wallet_address=%internal_wallet_address,
|
||||||
|
"No --change-address supplied. Any change will be received to the internal wallet."
|
||||||
|
);
|
||||||
|
|
||||||
|
internal_wallet_address
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let seller_peer_id = seller
|
let seller_peer_id = seller
|
||||||
.extract_peer_id()
|
.extract_peer_id()
|
||||||
.context("Seller address must contain peer ID")?;
|
.context("Seller address must contain peer ID")?;
|
||||||
|
@ -81,29 +81,11 @@ where
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// when no refund address was provided we default to the internal wallet
|
|
||||||
let bitcoin_change_address = match bitcoin_change_address {
|
|
||||||
Some(addr) => addr,
|
|
||||||
None => {
|
|
||||||
let internal_wallet_address = context
|
|
||||||
.bitcoin_wallet()
|
|
||||||
.expect("bitcoin wallet should exist")
|
|
||||||
.new_address()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
tracing::info!(
|
|
||||||
internal_wallet_address=%internal_wallet_address,
|
|
||||||
"No --change-address supplied. Any change will be received to the internal wallet."
|
|
||||||
);
|
|
||||||
|
|
||||||
internal_wallet_address
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let monero_receive_address =
|
let monero_receive_address =
|
||||||
monero_address::validate_is_testnet(monero_receive_address, is_testnet)?;
|
monero_address::validate_is_testnet(monero_receive_address, is_testnet)?;
|
||||||
let bitcoin_change_address =
|
let bitcoin_change_address = bitcoin_change_address
|
||||||
bitcoin_address::validate_is_testnet(bitcoin_change_address, is_testnet)?;
|
.map(|address| bitcoin_address::validate_is_testnet(address, is_testnet))
|
||||||
|
.transpose()?;
|
||||||
|
|
||||||
let request = Request::new(Method::BuyXmr {
|
let request = Request::new(Method::BuyXmr {
|
||||||
seller,
|
seller,
|
||||||
|
@ -135,16 +135,25 @@ pub fn register_modules(context: Arc<Context>) -> Result<RpcModule<Arc<Context>>
|
|||||||
module.register_async_method("buy_xmr", |params_raw, context| async move {
|
module.register_async_method("buy_xmr", |params_raw, context| async move {
|
||||||
let params: HashMap<String, String> = params_raw.parse()?;
|
let params: HashMap<String, String> = params_raw.parse()?;
|
||||||
|
|
||||||
let bitcoin_change_address =
|
let bitcoin_change_address = params
|
||||||
bitcoin::Address::from_str(params.get("bitcoin_change_address").ok_or_else(|| {
|
.get("bitcoin_change_address")
|
||||||
jsonrpsee_core::Error::Custom("Does not contain bitcoin_change_address".to_string())
|
.map(|addr_str| {
|
||||||
})?)
|
bitcoin::Address::from_str(addr_str)
|
||||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
.map_err(|err| {
|
||||||
|
jsonrpsee_core::Error::Custom(format!(
|
||||||
let bitcoin_change_address = bitcoin_address::validate(
|
"Could not parse bitcoin address: {}",
|
||||||
bitcoin_change_address,
|
err
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.and_then(|address| {
|
||||||
|
bitcoin_address::validate(
|
||||||
|
address,
|
||||||
context.config.env_config.bitcoin_network,
|
context.config.env_config.bitcoin_network,
|
||||||
)?;
|
)
|
||||||
|
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.transpose()?;
|
||||||
|
|
||||||
let monero_receive_address =
|
let monero_receive_address =
|
||||||
monero::Address::from_str(params.get("monero_receive_address").ok_or_else(|| {
|
monero::Address::from_str(params.get("monero_receive_address").ok_or_else(|| {
|
||||||
|
Loading…
Reference in New Issue
Block a user