@@ -547,7 +547,7 @@ namespace sdk {
547
547
std::vector<nlohmann::json> used_utxos;
548
548
used_utxos.reserve (utxos.size ());
549
549
550
- std::set<std::string> asset_tags ;
550
+ std::set<std::string> asset_ids ;
551
551
bool addressees_have_assets = json_get_value (result, " addressees_have_assets" , false );
552
552
if (num_addressees) {
553
553
for (auto & addressee : *addressees_p) {
@@ -571,15 +571,15 @@ namespace sdk {
571
571
addressees_have_assets = true ;
572
572
573
573
if (assetid_hex == net_params.policy_asset ()) {
574
- addressee[" asset_tag " ] = " btc" ;
574
+ addressee[" asset_id " ] = " btc" ;
575
575
} else {
576
- addressee[" asset_tag " ] = assetid_hex;
576
+ addressee[" asset_id " ] = assetid_hex;
577
577
}
578
578
}
579
579
}
580
580
581
- asset_tags .insert (session. asset_id_from_string (addressee. value ( " asset_tag " , " btc " ) ));
582
- if (asset_tags .size () > 1 && net_params.is_main_net ()) {
581
+ asset_ids .insert (asset_id_from_json (net_params, addressee ));
582
+ if (asset_ids .size () > 1 && net_params.is_main_net ()) {
583
583
// Multi-asset send disabled in (liquid) mainnet
584
584
GDK_LOG_SEV (log_level::error) << " Multi-asset send not supported" ;
585
585
GDK_RUNTIME_ASSERT (false );
@@ -590,8 +590,8 @@ namespace sdk {
590
590
591
591
std::vector<nlohmann::json> reordered_addressees;
592
592
593
- auto create_tx_outputs = [&](const std::string& asset_tag ) {
594
- const bool include_fee = asset_tag == " btc" ;
593
+ auto create_tx_outputs = [&](const std::string& asset_id ) {
594
+ const bool include_fee = asset_id == " btc" ;
595
595
596
596
std::vector<nlohmann::json> current_used_utxos;
597
597
amount available_total, total, fee, v;
@@ -612,9 +612,8 @@ namespace sdk {
612
612
613
613
if (num_addressees) {
614
614
for (auto & addressee : *addressees_p) {
615
- const auto addressee_asset_tag
616
- = session.asset_id_from_string (addressee.value (" asset_tag" , std::string{}));
617
- if (addressee_asset_tag == asset_tag) {
615
+ const auto addressee_asset_id = asset_id_from_json (net_params, addressee);
616
+ if (addressee_asset_id == asset_id) {
618
617
required_total += add_tx_addressee (session, net_params, result, tx, addressee);
619
618
reordered_addressees.push_back (addressee);
620
619
}
@@ -633,13 +632,13 @@ namespace sdk {
633
632
} else {
634
633
// Collect utxos in order until we have covered the amount to send
635
634
// FIXME: Better coin selection algorithms (esp. minimum size)
636
- const auto asset_utxos_p = utxos.find (asset_tag );
635
+ const auto asset_utxos_p = utxos.find (asset_id );
637
636
if (asset_utxos_p == utxos.end ()) {
638
637
if (!is_rbf) {
639
638
set_tx_error (result, res::id_insufficient_funds); // Insufficient funds
640
639
}
641
640
} else {
642
- for (auto & utxo : utxos.at (asset_tag )) {
641
+ for (auto & utxo : utxos.at (asset_id )) {
643
642
if (send_all || total < required_total) {
644
643
v = add_utxo (session, tx, utxo);
645
644
total += v;
@@ -685,7 +684,7 @@ namespace sdk {
685
684
bool change_address = result.find (" change_address" ) != result.end ();
686
685
if (change_address) {
687
686
const auto asset_change_address
688
- = result.at (" change_address" ).value (asset_tag , nlohmann::json::object ());
687
+ = result.at (" change_address" ).value (asset_id , nlohmann::json::object ());
689
688
change_address = !asset_change_address.empty ();
690
689
}
691
690
if (!change_address) {
@@ -708,7 +707,7 @@ namespace sdk {
708
707
}
709
708
710
709
add_paths (session, change_address);
711
- result[" change_address" ][asset_tag ] = change_address;
710
+ result[" change_address" ][asset_id ] = change_address;
712
711
}
713
712
714
713
const size_t max_loop_iterations
@@ -723,10 +722,10 @@ namespace sdk {
723
722
if (is_liquid) {
724
723
constexpr amount::value_type dummy_amount = 1 ;
725
724
if (!have_fee_output) {
726
- if (send_all && addressees_p->at (0 ).value (" asset_tag " , " btc" ) == asset_tag ) {
725
+ if (send_all && addressees_p->at (0 ).value (" asset_id " , " btc" ) == asset_id ) {
727
726
// the output commitment will be corrected below. this is a placeholder for the
728
727
// blinding.
729
- set_tx_output_commitment (net_params, tx, 0 , asset_tag , dummy_amount);
728
+ set_tx_output_commitment (net_params, tx, 0 , asset_id , dummy_amount);
730
729
}
731
730
fee_index = add_tx_fee_output (net_params, tx, dummy_amount);
732
731
have_fee_output = true ;
@@ -745,7 +744,7 @@ namespace sdk {
745
744
fee += network_fee;
746
745
}
747
746
748
- if (send_all && addressees_p->at (0 ).value (" asset_tag " , " btc" ) == asset_tag ) {
747
+ if (send_all && addressees_p->at (0 ).value (" asset_id " , " btc" ) == asset_id ) {
749
748
if (available_total < fee + dust_threshold) {
750
749
// After paying the fee, we only have dust left, so
751
750
// the requested amount isn't payable
@@ -756,7 +755,7 @@ namespace sdk {
756
755
// fee) and exit the loop
757
756
required_total = available_total - fee;
758
757
if (is_liquid) {
759
- set_tx_output_commitment (net_params, tx, 0 , asset_tag , required_total.value ());
758
+ set_tx_output_commitment (net_params, tx, 0 , asset_id , required_total.value ());
760
759
} else {
761
760
tx->outputs [0 ].satoshi = required_total.value ();
762
761
}
@@ -773,14 +772,14 @@ namespace sdk {
773
772
// need to add more to avoid a dusty change output
774
773
force_add_utxo = false ;
775
774
if (manual_selection || utxos.empty ()
776
- || current_used_utxos.size () == utxos.at (asset_tag ).size ()) {
775
+ || current_used_utxos.size () == utxos.at (asset_id ).size ()) {
777
776
// Used all inputs and do not have enough funds
778
777
set_tx_error (result, res::id_insufficient_funds); // Insufficient funds
779
778
goto leave_loop;
780
779
}
781
780
782
781
// FIXME: Use our strategy here when non-default implemented
783
- auto & utxo = utxos.at (asset_tag ).at (current_used_utxos.size ());
782
+ auto & utxo = utxos.at (asset_id ).at (current_used_utxos.size ());
784
783
total += add_utxo (session, tx, utxo);
785
784
current_used_utxos.emplace_back (utxo);
786
785
continue ;
@@ -818,16 +817,16 @@ namespace sdk {
818
817
// We have more than the dust amount of change. Add a change
819
818
// output to collect it, then loop again in case the amount
820
819
// this increases the fee by requires more UTXOs.
821
- add_tx_output (net_params, result, tx, result.at (" change_address" ).at (asset_tag ).at (" address" ),
822
- is_liquid ? 1 : 0 , asset_tag == " btc" ? std::string{} : asset_tag );
820
+ add_tx_output (net_params, result, tx, result.at (" change_address" ).at (asset_id ).at (" address" ),
821
+ is_liquid ? 1 : 0 , asset_id == " btc" ? std::string{} : asset_id );
823
822
have_change_output = true ;
824
823
change_index = tx->num_outputs - 1 ;
825
824
if (is_liquid && include_fee) {
826
825
std::swap (tx->outputs [fee_index], tx->outputs [change_index]);
827
826
std::swap (fee_index, change_index);
828
827
}
829
- result[" have_change" ][asset_tag ] = have_change_output;
830
- result[" change_index" ][asset_tag ] = change_index;
828
+ result[" have_change" ][asset_id ] = have_change_output;
829
+ result[" change_index" ][asset_id ] = change_index;
831
830
}
832
831
833
832
used_utxos.insert (used_utxos.end (), std::begin (current_used_utxos), std::end (current_used_utxos));
@@ -843,7 +842,7 @@ namespace sdk {
843
842
// Set the change amount
844
843
change_amount = (total - required_total - fee).value ();
845
844
if (is_liquid) {
846
- set_tx_output_commitment (net_params, tx, change_index, asset_tag , change_amount);
845
+ set_tx_output_commitment (net_params, tx, change_index, asset_id , change_amount);
847
846
} else {
848
847
auto & change_output = tx->outputs [change_index];
849
848
change_output.satoshi = change_amount;
@@ -856,14 +855,14 @@ namespace sdk {
856
855
}
857
856
}
858
857
// TODO: change amount should be liquid specific (blinded)
859
- result[" change_amount" ][asset_tag ] = change_amount;
860
- result[" change_index" ][asset_tag ] = change_index;
858
+ result[" change_amount" ][asset_id ] = change_amount;
859
+ result[" change_index" ][asset_id ] = change_index;
861
860
};
862
861
863
862
update_change_output (fee);
864
863
865
864
if (include_fee && is_liquid) {
866
- set_tx_output_commitment (net_params, tx, fee_index, asset_tag , fee.value ());
865
+ set_tx_output_commitment (net_params, tx, fee_index, asset_id , fee.value ());
867
866
}
868
867
869
868
if (required_total == 0 && (!include_fee || !is_liquid)) {
@@ -874,8 +873,8 @@ namespace sdk {
874
873
}
875
874
876
875
result[" used_utxos" ] = used_utxos;
877
- result[" have_change" ][asset_tag ] = have_change_output;
878
- result[" satoshi" ][asset_tag ] = required_total.value ();
876
+ result[" have_change" ][asset_id ] = have_change_output;
877
+ result[" satoshi" ][asset_id ] = required_total.value ();
879
878
880
879
update_tx_info (net_params, tx, result);
881
880
@@ -895,9 +894,9 @@ namespace sdk {
895
894
};
896
895
897
896
if (is_liquid) {
898
- std::for_each (std::begin (asset_tags ), std::end (asset_tags ), [&](const auto & asset_tag ) {
899
- if (asset_tag != " btc" ) {
900
- create_tx_outputs (asset_tag );
897
+ std::for_each (std::begin (asset_ids ), std::end (asset_ids ), [&](const auto & id ) {
898
+ if (id != " btc" ) {
899
+ create_tx_outputs (id );
901
900
}
902
901
});
903
902
}
0 commit comments