Skip to content

Commit

Permalink
Save taker swapcoins to disk earlier
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chris-belcher committed Jul 14, 2021
1 parent ef4565c commit 5741b6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
18 changes: 16 additions & 2 deletions src/taker_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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<Vec<SwapCoinPrivateKey>> = None;
println!(
Expand Down Expand Up @@ -375,10 +384,15 @@ async fn send_coinswap(
.collect::<Vec<_>>()
);

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(())
}
Expand Down

0 comments on commit 5741b6d

Please sign in to comment.