In the following post Calculating fee based on fee rate for bitcoin transaction the respondent describes how the fees can be calculated.
Since your transaction building starts with a known target feerate, and you know the size of the transaction header data and outputs, you can calculate their fees in advance.
However, AFAKT, the bitcoin core SRD algorithm only accounts for a single output, the change output (change_fee):
In the line about, the
target_value is incremented by the
CHANGE_LOWER (dust limit) and the cost of producing a change output (
change_fee). That way, the change amount is larger than the dust limit and can also pay for the fee of creating the change output. However, this does not account for paying for the remaining output nor the transaction header fields as described in the above link. Why is it not important to add the size of theses respective transaction parts when setting the target_value in SRD?