Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into eth-maker-tpu-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
laruh committed Oct 24, 2024
2 parents f7eab3c + b35a818 commit 5f1e38c
Show file tree
Hide file tree
Showing 54 changed files with 153 additions and 7,968 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ members = [

exclude = [
"mm2src/adex_cli",
"mm2src/floodsub",
"mm2src/gossipsub",
"mm2src/mm2_libp2p",
"mm2src/mm2_test_helpers",
]

Expand Down
10 changes: 5 additions & 5 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,11 +1329,11 @@ impl SwapOps for EthCoin {
)
}

fn send_maker_payment(&self, maker_payment: SendPaymentArgs) -> TransactionFut {
Box::new(
self.send_hash_time_locked_payment(maker_payment)
.map(TransactionEnum::from),
)
async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult {
self.send_hash_time_locked_payment(maker_payment_args)
.compat()
.await
.map(TransactionEnum::from)
}

fn send_taker_payment(&self, taker_payment: SendPaymentArgs) -> TransactionFut {
Expand Down
14 changes: 5 additions & 9 deletions mm2src/coins/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,19 +615,15 @@ impl SwapOps for LightningCoin {
Box::new(fut.boxed().compat())
}

fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionFut {
async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult {
let invoice = match maker_payment_args.payment_instructions.clone() {
Some(PaymentInstructions::Lightning(invoice)) => invoice,
_ => try_tx_fus!(ERR!("Invalid instructions, ligntning invoice is expected")),
_ => try_tx_s!(ERR!("Invalid instructions, ligntning invoice is expected")),
};

let coin = self.clone();
let fut = async move {
// No need for max_total_cltv_expiry_delta for lightning maker payment since the maker is the side that reveals the secret/preimage
let payment = try_tx_s!(coin.pay_invoice(invoice, None).await);
Ok(payment.payment_hash.into())
};
Box::new(fut.boxed().compat())
// No need for max_total_cltv_expiry_delta for lightning maker payment since the maker is the side that reveals the secret/preimage
let payment = try_tx_s!(self.pay_invoice(invoice, None).await);
Ok(payment.payment_hash.into())
}

fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionFut {
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ pub enum WatcherRewardError {
pub trait SwapOps {
fn send_taker_fee(&self, fee_addr: &[u8], dex_fee: DexFee, uuid: &[u8], expire_at: u64) -> TransactionFut;

fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionFut;
async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult;

fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionFut;

Expand Down
19 changes: 7 additions & 12 deletions mm2src/coins/qrc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,21 +771,16 @@ impl SwapOps for Qrc20Coin {
Box::new(fut.boxed().compat())
}

fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs) -> TransactionFut {
let time_lock = try_tx_fus!(maker_payment_args.time_lock.try_into());
let taker_addr = try_tx_fus!(self.contract_address_from_raw_pubkey(maker_payment_args.other_pubkey));
async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult {
let time_lock = try_tx_s!(maker_payment_args.time_lock.try_into());
let taker_addr = try_tx_s!(self.contract_address_from_raw_pubkey(maker_payment_args.other_pubkey));
let id = qrc20_swap_id(time_lock, maker_payment_args.secret_hash);
let value = try_tx_fus!(wei_from_big_decimal(&maker_payment_args.amount, self.utxo.decimals));
let value = try_tx_s!(wei_from_big_decimal(&maker_payment_args.amount, self.utxo.decimals));
let secret_hash = Vec::from(maker_payment_args.secret_hash);
let swap_contract_address = try_tx_fus!(maker_payment_args.swap_contract_address.try_to_address());
let swap_contract_address = try_tx_s!(maker_payment_args.swap_contract_address.try_to_address());

let selfi = self.clone();
let fut = async move {
selfi
.send_hash_time_locked_payment(id, value, time_lock, secret_hash, taker_addr, swap_contract_address)
.await
};
Box::new(fut.boxed().compat())
self.send_hash_time_locked_payment(id, value, time_lock, secret_hash, taker_addr, swap_contract_address)
.await
}

#[inline]
Expand Down
4 changes: 3 additions & 1 deletion mm2src/coins/siacoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ impl SwapOps for SiaCoin {
unimplemented!()
}

fn send_maker_payment(&self, _maker_payment_args: SendPaymentArgs) -> TransactionFut { unimplemented!() }
async fn send_maker_payment(&self, _maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult {
unimplemented!()
}

fn send_taker_payment(&self, _taker_payment_args: SendPaymentArgs) -> TransactionFut { unimplemented!() }

Expand Down
4 changes: 3 additions & 1 deletion mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2702,7 +2702,7 @@ impl SwapOps for TendermintCoin {
)
}

fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs) -> TransactionFut {
async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult {
self.send_htlc_for_denom(
maker_payment_args.time_lock_duration,
maker_payment_args.other_pubkey,
Expand All @@ -2711,6 +2711,8 @@ impl SwapOps for TendermintCoin {
self.denom.clone(),
self.decimals,
)
.compat()
.await
}

fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs) -> TransactionFut {
Expand Down
21 changes: 12 additions & 9 deletions mm2src/coins/tendermint/tendermint_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ impl SwapOps for TendermintToken {
)
}

fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs) -> TransactionFut {
self.platform_coin.send_htlc_for_denom(
maker_payment_args.time_lock_duration,
maker_payment_args.other_pubkey,
maker_payment_args.secret_hash,
maker_payment_args.amount,
self.denom.clone(),
self.decimals,
)
async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult {
self.platform_coin
.send_htlc_for_denom(
maker_payment_args.time_lock_duration,
maker_payment_args.other_pubkey,
maker_payment_args.secret_hash,
maker_payment_args.amount,
self.denom.clone(),
self.decimals,
)
.compat()
.await
}

fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs) -> TransactionFut {
Expand Down
4 changes: 3 additions & 1 deletion mm2src/coins/test_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ impl SwapOps for TestCoin {
unimplemented!()
}

fn send_maker_payment(&self, _maker_payment_args: SendPaymentArgs) -> TransactionFut { unimplemented!() }
async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult {
unimplemented!()
}

fn send_taker_payment(&self, _taker_payment_args: SendPaymentArgs) -> TransactionFut { unimplemented!() }

Expand Down
4 changes: 3 additions & 1 deletion mm2src/coins/utxo/bch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,10 @@ impl SwapOps for BchCoin {
}

#[inline]
fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs) -> TransactionFut {
async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult {
utxo_common::send_maker_payment(self.clone(), maker_payment_args)
.compat()
.await
}

#[inline]
Expand Down
4 changes: 3 additions & 1 deletion mm2src/coins/utxo/qtum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,10 @@ impl SwapOps for QtumCoin {
}

#[inline]
fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs) -> TransactionFut {
async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult {
utxo_common::send_maker_payment(self.clone(), maker_payment_args)
.compat()
.await
}

#[inline]
Expand Down
22 changes: 9 additions & 13 deletions mm2src/coins/utxo/slp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,22 +1238,18 @@ impl SwapOps for SlpToken {
Box::new(fut.boxed().compat().map(|tx| tx.into()))
}

fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs) -> TransactionFut {
let taker_pub = try_tx_fus!(Public::from_slice(maker_payment_args.other_pubkey));
let amount = try_tx_fus!(sat_from_big_decimal(&maker_payment_args.amount, self.decimals()));
async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult {
let taker_pub = try_tx_s!(Public::from_slice(maker_payment_args.other_pubkey));
let amount = try_tx_s!(sat_from_big_decimal(&maker_payment_args.amount, self.decimals()));
let secret_hash = maker_payment_args.secret_hash.to_owned();
let maker_htlc_keypair = self.derive_htlc_key_pair(maker_payment_args.swap_unique_data);
let time_lock = try_tx_fus!(maker_payment_args.time_lock.try_into());
let time_lock = try_tx_s!(maker_payment_args.time_lock.try_into());

let coin = self.clone();
let fut = async move {
let tx = try_tx_s!(
coin.send_htlc(maker_htlc_keypair.public(), &taker_pub, time_lock, &secret_hash, amount)
.await
);
Ok(tx.into())
};
Box::new(fut.boxed().compat())
let tx = try_tx_s!(
self.send_htlc(maker_htlc_keypair.public(), &taker_pub, time_lock, &secret_hash, amount)
.await
);
Ok(tx.into())
}

fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs) -> TransactionFut {
Expand Down
4 changes: 3 additions & 1 deletion mm2src/coins/utxo/utxo_standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,10 @@ impl SwapOps for UtxoStandardCoin {
}

#[inline]
fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs) -> TransactionFut {
async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult {
utxo_common::send_maker_payment(self.clone(), maker_payment_args)
.compat()
.await
}

#[inline]
Expand Down
34 changes: 15 additions & 19 deletions mm2src/coins/z_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,28 +1210,24 @@ impl SwapOps for ZCoin {
Box::new(fut.boxed().compat())
}

fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionFut {
let selfi = self.clone();
async fn send_maker_payment(&self, maker_payment_args: SendPaymentArgs<'_>) -> TransactionResult {
let maker_key_pair = self.derive_htlc_key_pair(maker_payment_args.swap_unique_data);
let taker_pub = try_tx_fus!(Public::from_slice(maker_payment_args.other_pubkey));
let taker_pub = try_tx_s!(Public::from_slice(maker_payment_args.other_pubkey));
let secret_hash = maker_payment_args.secret_hash.to_vec();
let time_lock = try_tx_fus!(maker_payment_args.time_lock.try_into());
let time_lock = try_tx_s!(maker_payment_args.time_lock.try_into());
let amount = maker_payment_args.amount;
let fut = async move {
let utxo_tx = try_tx_s!(
z_send_htlc(
&selfi,
time_lock,
maker_key_pair.public(),
&taker_pub,
&secret_hash,
amount
)
.await
);
Ok(utxo_tx.into())
};
Box::new(fut.boxed().compat())
let utxo_tx = try_tx_s!(
z_send_htlc(
self,
time_lock,
maker_key_pair.public(),
&taker_pub,
&secret_hash,
amount
)
.await
);
Ok(utxo_tx.into())
}

fn send_taker_payment(&self, taker_payment_args: SendPaymentArgs<'_>) -> TransactionFut {
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/z_coin/z_coin_native_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn zombie_coin_send_and_refund_maker_payment() {
watcher_reward: None,
wait_for_confirmation_until: 0,
};
let tx = block_on_f01(coin.send_maker_payment(args)).unwrap();
let tx = block_on(coin.send_maker_payment(args)).unwrap();
log!("swap tx {}", hex::encode(tx.tx_hash_as_bytes().0));

let refund_args = RefundPaymentArgs {
Expand Down Expand Up @@ -115,7 +115,7 @@ fn zombie_coin_send_and_spend_maker_payment() {
wait_for_confirmation_until: 0,
};

let tx = block_on_f01(coin.send_maker_payment(maker_payment_args)).unwrap();
let tx = block_on(coin.send_maker_payment(maker_payment_args)).unwrap();
log!("swap tx {}", hex::encode(tx.tx_hash_as_bytes().0));

let maker_pub = taker_pub;
Expand Down
15 changes: 0 additions & 15 deletions mm2src/floodsub/CHANGELOG.md

This file was deleted.

25 changes: 0 additions & 25 deletions mm2src/floodsub/Cargo.toml

This file was deleted.

21 changes: 0 additions & 21 deletions mm2src/floodsub/build.rs

This file was deleted.

Loading

0 comments on commit 5f1e38c

Please sign in to comment.