From 5741b6d2baa51b0d24e71f1361b53bd3c9f9b6de Mon Sep 17 00:00:00 2001 From: chris-belcher Date: Wed, 30 Jun 2021 13:24:54 +0100 Subject: [PATCH] Save taker swapcoins to disk earlier Previously taker would only save to the disk at the end of the function, meaning if anything went wrong there would be no data with which to recover. --- src/main.rs | 2 +- src/taker_protocol.rs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index bdad719f..76520ee7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -478,7 +478,7 @@ mod test { let maker2 = Wallet::load_wallet_from_file(&MAKER2).unwrap(); // Check assertions - assert_eq!(taker.get_swap_coins_count(), 3); + assert_eq!(taker.get_swap_coins_count(), 6); assert_eq!(maker1.get_swap_coins_count(), 6); assert_eq!(maker2.get_swap_coins_count(), 6); diff --git a/src/taker_protocol.rs b/src/taker_protocol.rs index fc00e14a..c76254ef 100644 --- a/src/taker_protocol.rs +++ b/src/taker_protocol.rs @@ -111,6 +111,11 @@ async fn send_coinswap( .zip(outgoing_swapcoins.iter_mut()) .for_each(|(sig, outgoing_swapcoin)| outgoing_swapcoin.others_contract_sig = Some(*sig)); + for outgoing_swapcoin in &outgoing_swapcoins { + wallet.add_swapcoin(outgoing_swapcoin.clone()); + } + wallet.update_swap_coins_list().unwrap(); + for my_funding_tx in my_funding_txes.iter() { let txid = rpc.send_raw_transaction(my_funding_tx)?; assert_eq!(txid, my_funding_tx.txid()); @@ -283,6 +288,10 @@ async fn send_coinswap( { incoming_swapcoin.others_contract_sig = Some(receiver_contract_sig); } + for incoming_swapcoin in &incoming_swapcoins { + wallet.add_swapcoin(incoming_swapcoin.clone()); + } + wallet.update_swap_coins_list().unwrap(); let mut outgoing_privkeys: Option> = None; println!( @@ -375,10 +384,15 @@ async fn send_coinswap( .collect::>() ); - for incoming_swapcoin in incoming_swapcoins { - wallet.add_swapcoin(incoming_swapcoin); + //update incoming_swapcoins with privkey on disk here + for incoming_swapcoin in &incoming_swapcoins { + wallet + .find_swapcoin_mut(&incoming_swapcoin.get_multisig_redeemscript()) + .unwrap() + .other_privkey = incoming_swapcoin.other_privkey; } wallet.update_swap_coins_list().unwrap(); + println!("successfully completed coinswap"); Ok(()) }