Skip to content

Commit

Permalink
Taker swap is not recoverable when MakerPaymentWaitConfirmFailed #647
Browse files Browse the repository at this point in the history
  • Loading branch information
artemii235 committed May 25, 2020
1 parent cc20999 commit e1dac77
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions mm2src/lp_swap/taker_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ impl TakerSavedSwap {
if !self.is_finished() { return false };
for event in self.events.iter() {
match event.event {
TakerSwapEvent::StartFailed(_) | TakerSwapEvent::NegotiateFailed(_) | TakerSwapEvent::TakerFeeSendFailed(_) |
TakerSwapEvent::MakerPaymentValidateFailed(_) | TakerSwapEvent::TakerPaymentRefunded(_) | TakerSwapEvent::MakerPaymentSpent(_) => {
TakerSwapEvent::StartFailed(_) | TakerSwapEvent::NegotiateFailed(_) |
TakerSwapEvent::TakerFeeSendFailed(_) | TakerSwapEvent::MakerPaymentValidateFailed(_) |
TakerSwapEvent::TakerPaymentRefunded(_) | TakerSwapEvent::MakerPaymentSpent(_) |
TakerSwapEvent::MakerPaymentWaitConfirmFailed(_) => {
return false;
}
_ => (),
Expand Down Expand Up @@ -1501,4 +1503,13 @@ mod taker_swap_tests {
let event = TakerSwapEvent::TakerPaymentWaitForSpendFailed("err".into());
assert!(event.should_ban_maker());
}

#[test]
// https://github.com/KomodoPlatform/atomicDEX-API/issues/647
fn test_recoverable() {
// Swap ended with MakerPaymentWaitConfirmFailed event.
// MM2 did not attempt to send the payment in this case so swap is not recoverable.
let swap: TakerSavedSwap = json::from_str(r#"{"error_events":["StartFailed","NegotiateFailed","TakerFeeSendFailed","MakerPaymentValidateFailed","MakerPaymentWaitConfirmFailed","TakerPaymentTransactionFailed","TakerPaymentWaitConfirmFailed","TakerPaymentDataSendFailed","TakerPaymentWaitForSpendFailed","MakerPaymentSpendFailed","TakerPaymentWaitRefundStarted","TakerPaymentRefunded","TakerPaymentRefundFailed"],"events":[{"event":{"data":{"lock_duration":7800,"maker":"1bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","maker_amount":"0.12596566232185483","maker_coin":"KMD","maker_coin_start_block":1458035,"maker_payment_confirmations":1,"maker_payment_wait":1564053079,"my_persistent_pub":"0326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0a","started_at":1564050479,"taker_amount":"50.000000000000001504212457800000","taker_coin":"DOGE","taker_coin_start_block":2823448,"taker_payment_confirmations":1,"taker_payment_lock":1564058279,"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"},"type":"Started"},"timestamp":1564050480269},{"event":{"data":{"maker_payment_locktime":1564066080,"maker_pubkey":"031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8","secret_hash":"3669eb83a007a3c507448d79f45a9f06ec2f36a8"},"type":"Negotiated"},"timestamp":1564050540991},{"event":{"data":{"block_height":0,"coin":"DOGE","fee_details":{"amount":5},"from":["DBNHC8sQS8SCwCrKzG57G7ZVCh1zaih2tx"],"internal_id":"bdde828b492d6d1cc25cd2322fd592dafd722fcc7d8b0fedce4d3bb4a1a8c8ff","my_balance_change":-5.05791505,"received_by_me":96.85084225,"spent_by_me":101.9087573,"timestamp":0,"to":["DBNHC8sQS8SCwCrKzG57G7ZVCh1zaih2tx","DPZnzesTGPD42AXY1qX8BQp78jLbmzpRT7"],"total_amount":101.9087573,"tx_hash":"bdde828b492d6d1cc25cd2322fd592dafd722fcc7d8b0fedce4d3bb4a1a8c8ff","tx_hex":"0100000002c7efa995c8b7be0a8b6c2d526c6c444c1634d65584e9ee89904e9d8675eac88c010000006a473044022051f34d5e3b7d0b9098d5e35333f3550f9cb9e57df83d5e4635b7a8d2986d6d5602200288c98da05de6950e01229a637110a1800ba643e75cfec59d4eb1021ad9b40801210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffffae6c233989efa7c7d2aa6534adc96078917ff395b7f09f734a147b2f44ade164000000006a4730440220393a784c2da74d0e2a28ec4f7df6c8f9d8b2af6ae6957f1e68346d744223a8fd02201b7a96954ac06815a43a6c7668d829ae9cbb5de76fa77189ddfd9e3038df662c01210326846707a52a233cfc49a61ef51b1698bbe6aa78fa8b8d411c02743c09688f0affffffff02115f5800000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac41a84641020000001976a914444f0e1099709ba4d742454a7d98a5c9c162ceab88ac6d84395d"},"type":"TakerFeeSent"},"timestamp":1564050545296},{"event":{"data":{"block_height":0,"coin":"KMD","fee_details":{"amount":0.00001},"from":["RT9MpMyucqXiX8bZLimXBnrrn2ofmdGNKd"],"internal_id":"0a0f11fa82802c2c30862c50ab2162185dae8de7f7235f32c506f814c142b382","my_balance_change":0,"received_by_me":0,"spent_by_me":0,"timestamp":0,"to":["RT9MpMyucqXiX8bZLimXBnrrn2ofmdGNKd","bQTa5QiudricscFpKeJpcvi3rqFW4YEBcs"],"total_amount":1.10033066,"tx_hash":"0a0f11fa82802c2c30862c50ab2162185dae8de7f7235f32c506f814c142b382","tx_hex":"0400008085202f8902ace337db2dd4c56b0697f58fb8cfb6bd1cd6f469d925fc0376d1dcfb7581bf82000000006b483045022100d1f95be235c5c8880f5d703ace287e2768548792c58c5dbd27f5578881b30ea70220030596106e21c7e0057ee0dab283f9a1fe273f15208cba80870c447bd559ef0d0121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff9f339752567c404427fd77f2b35cecdb4c21489edc64e25e729fdb281785e423000000006a47304402203179e95877dbc107123a417f1e648e3ff13d384890f1e4a67b6dd5087235152e0220102a8ab799fadb26b5d89ceb9c7bc721a7e0c2a0d0d7e46bbe0cf3d130010d430121031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ffffffff025635c0000000000017a91480a95d366d65e34a465ab17b0c9eb1d5a33bae08876cbfce05000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac8d7c395d000000000000000000000000000000"},"type":"MakerPaymentReceived"},"timestamp":1564050588176},{"event":{"type":"MakerPaymentWaitConfirmStarted"},"timestamp":1564050588178},{"event":{"data":{"error":"error"},"type":"MakerPaymentWaitConfirmFailed"},"timestamp":1564051092897},{"event":{"type":"Finished"},"timestamp":1564051092900}],"success_events":["Started","Negotiated","TakerFeeSent","MakerPaymentReceived","MakerPaymentWaitConfirmStarted","MakerPaymentValidatedAndConfirmed","TakerPaymentSent","TakerPaymentSpent","MakerPaymentSpent","Finished"],"uuid":"41383f43-46a5-478c-9386-3b2cce0aca20"}"#).unwrap();
assert!(!swap.is_recoverable());
}
}

0 comments on commit e1dac77

Please sign in to comment.