@@ -67,7 +67,8 @@ namespace sdk {
67
67
const std::string txhash = utxo.at (" txhash" );
68
68
const auto txid = h2b_rev (txhash);
69
69
const uint32_t index = utxo.at (" pt_idx" );
70
- const auto type = script_type (utxo.at (" script_type" ));
70
+ const auto is_segwit = utxo.value (
71
+ " is_segwit" , is_segwit_script_type (utxo.value (" script_type" , script_type::ga_pubkey_hash_out)));
71
72
const bool low_r = session.get_nonnull_signer ()->supports_low_r ();
72
73
const uint32_t dummy_sig_type = low_r ? WALLY_TX_DUMMY_SIG_LOW_R : WALLY_TX_DUMMY_SIG;
73
74
const bool external = !json_get_value (utxo, " private_key" ).empty ();
@@ -90,7 +91,7 @@ namespace sdk {
90
91
91
92
wally_tx_witness_stack_ptr wit;
92
93
93
- if (is_segwit_script_type (type) ) {
94
+ if (is_segwit ) {
94
95
// TODO: If the UTXO is CSV and expired, spend it using the users key only (smaller)
95
96
wit = tx_witness_stack_init (4 );
96
97
tx_witness_stack_add_dummy (wit, WALLY_TX_DUMMY_NULL);
@@ -128,7 +129,8 @@ namespace sdk {
128
129
// - 2of3 p2wsh, backup key signing
129
130
// - 2of2 csv, csv path
130
131
const auto type = script_type (utxo.at (" script_type" ));
131
- if (!is_segwit_script_type (type)) {
132
+ const auto is_segwit = utxo.value (" is_segwit" , is_segwit_script_type (type));
133
+ if (!is_segwit) {
132
134
// 2of2 p2sh: script sig: OP_0 <ga_sig> <user_sig>
133
135
// 2of3 p2sh: script sig: OP_0 <ga_sig> <user_sig>
134
136
const auto & input = tx->inputs [index];
@@ -887,8 +889,9 @@ namespace sdk {
887
889
const auto txhash = u.at (" txhash" );
888
890
const uint32_t subaccount = json_get_value (u, " subaccount" , 0u );
889
891
const uint32_t pointer = json_get_value (u, " pointer" , 0u );
890
- const auto type = script_type (u.at (" script_type" ));
891
892
const bool is_internal = json_get_value (u, " is_internal" , false );
893
+ const auto is_segwit
894
+ = u.value (" is_segwit" , is_segwit_script_type (u.value (" script_type" , script_type::ga_pubkey_hash_out)));
892
895
const auto script = h2b (u.at (" prevout_script" ));
893
896
const std::string private_key = json_get_value (u, " private_key" );
894
897
auto signer = session.get_nonnull_signer ();
@@ -909,7 +912,7 @@ namespace sdk {
909
912
const auto user_sig = signer->sign_hash (path, tx_hash);
910
913
const auto der = ec_sig_to_der (user_sig, true );
911
914
912
- if (is_segwit_script_type (type) ) {
915
+ if (is_segwit ) {
913
916
// TODO: If the UTXO is CSV and expired, spend it using the users key only (smaller)
914
917
// Note that this requires setting the inputs sequence number to the CSV time too
915
918
auto wit = tx_witness_stack_init (1 );
@@ -929,10 +932,11 @@ namespace sdk {
929
932
const network_parameters& net_params, const nlohmann::json& utxo, const wally_tx_ptr& tx, size_t index)
930
933
{
931
934
const amount::value_type v = utxo.at (" satoshi" );
932
- const auto type = script_type (utxo.at (" script_type" ));
935
+ const auto is_segwit = utxo.value (
936
+ " is_segwit" , is_segwit_script_type (utxo.value (" script_type" , script_type::ga_pubkey_hash_out)));
933
937
const auto script = h2b (utxo.at (" prevout_script" ));
934
938
935
- const uint32_t flags = is_segwit_script_type (type) ? WALLY_TX_FLAG_USE_WITNESS : 0 ;
939
+ const uint32_t flags = is_segwit ? WALLY_TX_FLAG_USE_WITNESS : 0 ;
936
940
937
941
if (!net_params.is_liquid ()) {
938
942
const amount satoshi{ v };
@@ -980,11 +984,12 @@ namespace sdk {
980
984
{
981
985
GDK_RUNTIME_ASSERT (json_get_value (u, " private_key" ).empty ());
982
986
983
- const auto type = script_type (u.at (" script_type" ));
987
+ const auto is_segwit
988
+ = u.value (" is_segwit" , is_segwit_script_type (u.value (" script_type" , script_type::ga_pubkey_hash_out)));
984
989
const auto script = h2b (u.at (" prevout_script" ));
985
990
auto der = h2b (der_hex);
986
991
987
- if (is_segwit_script_type (type) ) {
992
+ if (is_segwit ) {
988
993
// See above re: spending using the users key only
989
994
auto wit = tx_witness_stack_init (1 );
990
995
tx_witness_stack_add (wit, der);
0 commit comments