Skip to content

Commit 3a1156f

Browse files
committed
Refactor set_tx_output_value
1 parent 6796db4 commit 3a1156f

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/ga_tx.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,7 @@ namespace sdk {
716716
// so compute what we can send (everything minus the
717717
// fee) and exit the loop
718718
required_total = available_total - fee;
719-
if (is_liquid) {
720-
set_tx_output_commitment(tx, 0, asset_id, required_total.value());
721-
} else {
722-
tx->outputs[0].satoshi = required_total.value();
723-
}
719+
set_tx_output_value(net_params, tx, 0, asset_id, required_total.value());
724720
if (num_addressees == 1u) {
725721
addressees_p->at(0)["satoshi"] = required_total.value();
726722
}

src/transaction_utils.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ namespace sdk {
435435
asset_id_from_json(net_params, addressee));
436436
}
437437

438+
void set_tx_output_value(const network_parameters& net_params, wally_tx_ptr& tx, uint32_t index,
439+
const std::string& asset_id, amount::value_type satoshi)
440+
{
441+
if (net_params.is_liquid()) {
442+
set_tx_output_commitment(tx, index, asset_id, satoshi);
443+
} else {
444+
tx->outputs[index].satoshi = satoshi;
445+
}
446+
}
447+
438448
void update_tx_size_info(const network_parameters& net_params, const wally_tx_ptr& tx, nlohmann::json& result)
439449
{
440450
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_id, 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)