@ -70,35 +70,46 @@ bool elements_tx_output_is_fee(const struct bitcoin_tx *tx, int outnum)
tx - > wtx - > outputs [ outnum ] . script_len = = 0 ;
tx - > wtx - > outputs [ outnum ] . script_len = = 0 ;
}
}
/**
struct amount_sat bitcoin_tx_compute_fee_w_inputs ( const struct bitcoin_tx * tx ,
* Compute how much fee we are actually sending with this transaction .
struct amount_sat input_val )
*/
static struct amount_sat bitcoin_tx_compute_fee ( const struct bitcoin_tx * tx )
{
{
struct amount_sat fee = AMOUNT_SAT ( 0 ) , value ;
struct amount_asset asset ;
struct amount_asset asset ;
bool ok ;
bool ok ;
for ( size_t i = 0 ; i < tal_count ( tx - > input_amounts ) ; i + + ) {
value . satoshis = tx - > input_amounts [ i ] - > satoshis ; /* Raw: fee computation */
ok = amount_sat_add ( & fee , fee , value ) ;
assert ( ok ) ;
}
for ( size_t i = 0 ; i < tx - > wtx - > num_outputs ; i + + ) {
for ( size_t i = 0 ; i < tx - > wtx - > num_outputs ; i + + ) {
asset = bitcoin_tx_output_get_amount ( tx , i ) ;
asset = bitcoin_tx_output_get_amount ( tx , i ) ;
if ( elements_tx_output_is_fee ( tx , i ) | |
if ( elements_tx_output_is_fee ( tx , i ) | |
! amount_asset_is_main ( & asset ) )
! amount_asset_is_main ( & asset ) )
continue ;
continue ;
value = amount_asset_to_sat ( & asset ) ;
ok = amount_sat_sub ( & input_val , input_val ,
ok = amount_sat_sub ( & fee , fee , value ) ;
amount_asset_to_sat ( & asset ) ) ;
assert ( ok ) ;
assert ( ok ) ;
}
}
return fee ;
return input_val ;
}
}
/**
/**
* Compute how much fee we are actually sending with this transaction .
* Note that using this with a transaction without the input_amounts
* initialized / populated is an error .
*/
struct amount_sat bitcoin_tx_compute_fee ( const struct bitcoin_tx * tx )
{
struct amount_sat input_total = AMOUNT_SAT ( 0 ) ;
bool ok ;
for ( size_t i = 0 ; i < tal_count ( tx - > input_amounts ) ; i + + ) {
assert ( tx - > input_amounts [ i ] ) ;
ok = amount_sat_add ( & input_total , input_total ,
* tx - > input_amounts [ i ] ) ;
assert ( ok ) ;
}
return bitcoin_tx_compute_fee_w_inputs ( tx , input_total ) ;
}
/*
* Add an explicit fee output if necessary .
* Add an explicit fee output if necessary .
*
*
* An explicit fee output is only necessary if we are using an elements
* An explicit fee output is only necessary if we are using an elements