From e1e896e62be8ea52517163f2c9bf86e84b2295cc Mon Sep 17 00:00:00 2001 From: chris-belcher Date: Thu, 3 Feb 2022 18:04:15 +0000 Subject: [PATCH] Add check if maker has enough money Previously if there wasnt enough money then the ProofOfFunding stage would fail, however at that point the taker has already wasted miner fees getting transactions confirmed, so it would be very nice to let them know before. --- src/maker_protocol.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/maker_protocol.rs b/src/maker_protocol.rs index d206dcfd..1b11ac18 100644 --- a/src/maker_protocol.rs +++ b/src/maker_protocol.rs @@ -468,14 +468,22 @@ fn handle_sign_senders_contract_tx( funding_txids.push(txinfo.senders_contract_tx.input[0].previous_output.txid); total_amount += txinfo.funding_input_value; } - log::info!( - "requested contracts amount={}, for funding txids = {:?}", - Amount::from_sat(total_amount), - funding_txids - ); - Ok(Some(MakerToTakerMessage::SendersContractSig( - SendersContractSig { sigs }, - ))) + if total_amount < wallet.read().unwrap().get_offer_maxsize_cache() { + log::info!( + "requested contracts amount={}, for funding txids = {:?}", + Amount::from_sat(total_amount), + funding_txids + ); + Ok(Some(MakerToTakerMessage::SendersContractSig( + SendersContractSig { sigs }, + ))) + } else { + log::info!( + "rejecting contracts for amount={} because not enough funds", + Amount::from_sat(total_amount) + ); + Err(Error::Protocol("not enough funds")) + } } fn handle_proof_of_funding(