Skip to content

Commit

Permalink
wallet, rpc: implement ancestor aware funding for sendall
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaanam committed Dec 10, 2023
1 parent 6940812 commit 8d28da4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/wallet/rpc/spend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1472,10 +1472,22 @@ RPCHelpMan sendall()
}
}

std::vector<COutPoint> outpoints_spent;
outpoints_spent.reserve(rawTx.vin.size());

for (const CTxIn& tx_in : rawTx.vin) {
outpoints_spent.push_back(tx_in.prevout);
}

// estimate final size of tx
const TxSize tx_size{CalculateMaximumSignedTxSize(CTransaction(rawTx), pwallet.get())};
const CAmount fee_from_size{fee_rate.GetFee(tx_size.vsize)};
const CAmount effective_value{total_input_value - fee_from_size};
CAmount effective_value{total_input_value - fee_from_size};

const std::optional<CAmount> total_bump_fees{pwallet->chain().calculateCombinedBumpFee(outpoints_spent, fee_rate)};
if (total_bump_fees) {
effective_value -= *total_bump_fees;
}

if (fee_from_size > pwallet->m_default_max_tx_fee) {
throw JSONRPCError(RPC_WALLET_ERROR, TransactionErrorString(TransactionError::MAX_FEE_EXCEEDED).original);
Expand Down

0 comments on commit 8d28da4

Please sign in to comment.