Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[r2r] Lightning Refunds #1592

Merged
merged 30 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3e907ac
lightning refunds wip: add is_auto_refundable, wait_for_htlc_refund S…
shamardy Dec 12, 2022
3a6c61d
lightning refunds wip: move fail_htlc_backwards to the right place
shamardy Dec 14, 2022
daf5da2
lightning refunds wip: add update_payment_status_in_db to LightningDB…
shamardy Dec 15, 2022
66e6f80
add update_payment_to_received_in_db method to LightningDB
shamardy Dec 19, 2022
2a5aa63
add update_payment_to_sent_in_db method to LightningDB
shamardy Dec 19, 2022
420e763
change add_or_update_payment_in_db to add_payment_to_db, remove payme…
shamardy Dec 19, 2022
e384af3
edit docs/notes related to fail_htlc_backwards
shamardy Dec 20, 2022
6067f03
Merge remote-tracking branch 'origin/dev' into ln-refunds
shamardy Dec 20, 2022
0353a81
fix typo: rename if_my_payment_spent_args to if_my_payment_sent_args
shamardy Dec 20, 2022
84d19b1
impl check_if_my_payment_sent for LightningCoin
shamardy Dec 20, 2022
e61e76b
add TakerPaymentInstructionsReceived to TAKER_SUCCESS_EVENTS, MakerPa…
shamardy Dec 22, 2022
ab68e26
implemented recover_funds for lightning, revised lightning swap resta…
shamardy Dec 26, 2022
fbc2da1
Remove unneeded todos
shamardy Dec 28, 2022
8df164c
Merge remote-tracking branch 'origin/dev' into ln-refunds
shamardy Dec 28, 2022
f133368
review fixes wip: add MakerSwapOps and TakerSwapOps
shamardy Jan 9, 2023
445a6ee
review fixes wip: update deny.toml
shamardy Jan 9, 2023
1f370bb
review fixes wip: revert deny.toml changes
shamardy Jan 10, 2023
72b3467
Merge remote-tracking branch 'origin/dev' into ln-refunds
shamardy Jan 10, 2023
ae5daf7
review fixes wip: add on_start/success trait methods to MakerSwapOps/…
shamardy Jan 10, 2023
d555e09
review fixes wip: fix wait_for_htlc_refund to not return TransactionFut
shamardy Jan 10, 2023
98b5798
review fixes wip: add with_preimage, with_status methods to PaymentIn…
shamardy Jan 10, 2023
ee12d6b
review fixes wip: use owned_named_params for insert_payment_sql
shamardy Jan 10, 2023
a35db06
first review fixes complete: use owned_named_params for insert_channe…
shamardy Jan 10, 2023
733aca1
second review fixes wip: use repeatable in wait_for_htlc_refund imple…
shamardy Jan 11, 2023
3279aa6
second review fixes wip: remove white spaces in recover_funds, fix is…
shamardy Jan 11, 2023
87f5fce
Merge remote-tracking branch 'origin/dev' into ln-refunds
shamardy Jan 12, 2023
cbe3d48
second review fixes wip: rename MakerSwapOps/TakerSwapOps to TakerSwa…
shamardy Jan 12, 2023
b329de3
second review fixes wip: Add TakerSwapCommand::PrepareForTakerPayment…
shamardy Jan 12, 2023
76632df
second review fixes: Add MakerSwapCommand::PrepareForMakerPaymentRefu…
shamardy Jan 12, 2023
0d2b7da
more review fixes
shamardy Jan 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,20 @@ use web3_transport::{http_transport::HttpTransportNode, EthFeeHistoryNamespace,

use super::{coin_conf, AsyncMutex, BalanceError, BalanceFut, CheckIfMyPaymentSentArgs, CoinBalance, CoinFutSpawner,
CoinProtocol, CoinTransportMetrics, CoinsContext, FeeApproxStage, FoundSwapTxSpend, HistorySyncState,
IguanaPrivKey, MarketCoinOps, MmCoin, MyAddressError, NegotiateSwapContractAddrErr, NumConversError,
NumConversResult, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy,
IguanaPrivKey, MakerSwapTakerCoin, MarketCoinOps, MmCoin, MyAddressError, NegotiateSwapContractAddrErr,
NumConversError, NumConversResult, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy,
PrivKeyPolicyNotAllowed, RawTransactionError, RawTransactionFut, RawTransactionRequest, RawTransactionRes,
RawTransactionResult, RpcClientType, RpcTransportEventHandler, RpcTransportEventHandlerShared,
SearchForSwapTxSpendInput, SendMakerPaymentArgs, SendMakerRefundsPaymentArgs,
SendMakerSpendsTakerPaymentArgs, SendTakerPaymentArgs, SendTakerRefundsPaymentArgs,
SendTakerSpendsMakerPaymentArgs, SignatureError, SignatureResult, SwapOps, TradeFee, TradePreimageError,
TradePreimageFut, TradePreimageResult, TradePreimageValue, Transaction, TransactionDetails,
TransactionEnum, TransactionErr, TransactionFut, TxMarshalingErr, UnexpectedDerivationMethod,
ValidateAddressResult, ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr,
ValidatePaymentError, ValidatePaymentFut, ValidatePaymentInput, VerificationError, VerificationResult,
WatcherOps, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput, WatcherValidateTakerFeeInput,
WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest, WithdrawResult};
RawTransactionResult, RefundError, RefundResult, RpcClientType, RpcTransportEventHandler,
RpcTransportEventHandlerShared, SearchForSwapTxSpendInput, SendMakerPaymentArgs,
SendMakerRefundsPaymentArgs, SendMakerSpendsTakerPaymentArgs, SendTakerPaymentArgs,
SendTakerRefundsPaymentArgs, SendTakerSpendsMakerPaymentArgs, SignatureError, SignatureResult, SwapOps,
TakerSwapMakerCoin, TradeFee, TradePreimageError, TradePreimageFut, TradePreimageResult,
TradePreimageValue, Transaction, TransactionDetails, TransactionEnum, TransactionErr, TransactionFut,
TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs,
ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut,
ValidatePaymentInput, VerificationError, VerificationResult, WatcherOps, WatcherSearchForSwapTxSpendInput,
WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawError, WithdrawFee, WithdrawFut,
WithdrawRequest, WithdrawResult};
pub use rlp;

#[cfg(test)] mod eth_tests;
Expand Down Expand Up @@ -1037,12 +1038,12 @@ impl SwapOps for EthCoin {

fn check_if_my_payment_sent(
&self,
if_my_payment_spent_args: CheckIfMyPaymentSentArgs,
if_my_payment_sent_args: CheckIfMyPaymentSentArgs,
) -> Box<dyn Future<Item = Option<TransactionEnum>, Error = String> + Send> {
let id = self.etomic_swap_id(if_my_payment_spent_args.time_lock, if_my_payment_spent_args.secret_hash);
let swap_contract_address = try_fus!(if_my_payment_spent_args.swap_contract_address.try_to_address());
let id = self.etomic_swap_id(if_my_payment_sent_args.time_lock, if_my_payment_sent_args.secret_hash);
let swap_contract_address = try_fus!(if_my_payment_sent_args.swap_contract_address.try_to_address());
let selfi = self.clone();
let from_block = if_my_payment_spent_args.search_from_block;
let from_block = if_my_payment_sent_args.search_from_block;
let fut = async move {
let status = try_s!(
selfi
Expand Down Expand Up @@ -1162,6 +1163,14 @@ impl SwapOps for EthCoin {
}
}

fn is_auto_refundable(&self) -> bool { false }

async fn wait_for_htlc_refund(&self, _tx: &[u8], _locktime: u64) -> RefundResult<()> {
MmError::err(RefundError::Internal(
"wait_for_htlc_refund is not supported for this coin!".into(),
))
}

fn negotiate_swap_contract_addr(
&self,
other_side_address: Option<&[u8]>,
Expand Down Expand Up @@ -1247,6 +1256,20 @@ impl SwapOps for EthCoin {
fn is_supported_by_watchers(&self) -> bool { false }
}

#[async_trait]
impl TakerSwapMakerCoin for EthCoin {
async fn on_taker_payment_refund_start(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) }

async fn on_taker_payment_refund_success(&self, _maker_payment: &[u8]) -> RefundResult<()> { Ok(()) }
}

#[async_trait]
impl MakerSwapTakerCoin for EthCoin {
async fn on_maker_payment_refund_start(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) }

async fn on_maker_payment_refund_success(&self, _taker_payment: &[u8]) -> RefundResult<()> { Ok(()) }
}

#[async_trait]
impl WatcherOps for EthCoin {
fn send_maker_payment_spend_preimage(&self, _preimage: &[u8], _secret: &[u8]) -> TransactionFut {
Expand Down
1 change: 1 addition & 0 deletions mm2src/coins/eth/eth_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ fn polygon_check_if_my_payment_sent() {
swap_contract_address: &Some(swap_contract_address),
swap_unique_data: &[],
amount: &BigDecimal::default(),
payment_instructions: &None,
};
let my_payment = coin
.check_if_my_payment_sent(if_my_payment_sent_args)
Expand Down
Loading