Skip to content

Commit cec8139

Browse files
committed
Refactor set_tx_output_value
1 parent de0c001 commit cec8139

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/ga_tx.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,7 @@ namespace sdk {
701701
// so compute what we can send (everything minus the
702702
// fee) and exit the loop
703703
required_total = available_total - fee;
704-
if (is_liquid) {
705-
set_tx_output_commitment(tx, 0, asset_id, required_total.value());
706-
} else {
707-
tx->outputs[0].satoshi = required_total.value();
708-
}
704+
set_tx_output_value(net_params, tx, 0, asset_id, required_total.value());
709705
if (num_addressees == 1u) {
710706
addressees_p->at(0)["satoshi"] = required_total.value();
711707
}

src/transaction_utils.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,17 @@ namespace sdk {
432432
asset_id_from_json(net_params, addressee));
433433
}
434434

435+
void set_tx_output_value(const network_parameters& net_params, wally_tx_ptr& tx, uint32_t index,
436+
const std::string& asset_tag, amount::value_type satoshi)
437+
{
438+
const bool is_liquid = net_params.is_liquid();
439+
if (is_liquid) {
440+
set_tx_output_commitment(tx, index, asset_tag, satoshi);
441+
} else {
442+
tx->outputs[index].satoshi = satoshi;
443+
}
444+
}
445+
435446
void update_tx_size_info(const network_parameters& net_params, const wally_tx_ptr& tx, nlohmann::json& result)
436447
{
437448
const bool valid = tx->num_inputs != 0u && tx->num_outputs != 0u;

src/transaction_utils.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ namespace sdk {
9292
amount add_tx_addressee(ga_session& session, const network_parameters& net_params, nlohmann::json& result,
9393
wally_tx_ptr& tx, nlohmann::json& addressee);
9494

95+
void set_tx_output_value(const network_parameters& net_params, wally_tx_ptr& tx, uint32_t index,
96+
const std::string& asset_tag, amount::value_type satoshi);
97+
9598
vbf_t generate_final_vbf(byte_span_t input_abfs, byte_span_t input_vbfs, uint64_span_t input_values,
9699
const std::vector<abf_t>& output_abfs, const std::vector<vbf_t>& output_vbfs, uint32_t num_inputs);
97100

0 commit comments

Comments
 (0)