Skip to content

Commit be2199c

Browse files
committed
ga_tx: add_input_signature: handle single sig inputs
1 parent dd5d632 commit be2199c

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/ga_tx.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,9 +988,22 @@ namespace sdk {
988988
= u.value("is_segwit", is_segwit_script_type(u.value("script_type", script_type::ga_pubkey_hash_out)));
989989
const auto script = h2b(u.at("prevout_script"));
990990
auto der = h2b(der_hex);
991+
const auto address_type = u.at("address_type");
991992

992-
if (is_segwit) {
993-
// See above re: spending using the users key only
993+
if (address_type == "p2pkh") {
994+
tx_set_input_script(tx, index, scriptsig_p2pkh_from_der(h2b(u.at("public_key")), der));
995+
} else if (address_type == "p2sh-p2wpkh" || address_type == "p2wpkh") {
996+
const auto public_key = h2b(u.at("public_key"));
997+
auto wit = tx_witness_stack_init(2);
998+
tx_witness_stack_add(wit, der);
999+
tx_witness_stack_add(wit, public_key);
1000+
tx_set_input_witness(tx, index, wit);
1001+
if (address_type == "p2sh-p2wpkh") {
1002+
// for native segwit do not set the scriptsig
1003+
tx_set_input_script(tx, index, scriptsig_p2sh_p2wpkh_from_bytes(public_key));
1004+
}
1005+
} else if (is_segwit) {
1006+
// Multisig cases
9941007
auto wit = tx_witness_stack_init(1);
9951008
tx_witness_stack_add(wit, der);
9961009
tx_set_input_witness(tx, index, wit);

src/ga_wally.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ namespace sdk {
177177
return out;
178178
}
179179

180+
std::vector<unsigned char> scriptsig_p2sh_p2wpkh_from_bytes(byte_span_t public_key)
181+
{
182+
const uint32_t witness_ver = 0;
183+
return witness_program_from_bytes(public_key, witness_ver, WALLY_SCRIPT_HASH160 | WALLY_SCRIPT_AS_PUSH);
184+
}
185+
180186
void scriptpubkey_csv_2of2_then_1_from_bytes(
181187
byte_span_t keys, uint32_t csv_blocks, bool optimize, std::vector<unsigned char>& out)
182188
{

src/ga_wally.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ namespace sdk {
130130

131131
std::vector<unsigned char> scriptsig_p2pkh_from_der(byte_span_t public_key, byte_span_t sig);
132132

133+
std::vector<unsigned char> scriptsig_p2sh_p2wpkh_from_bytes(byte_span_t public_key);
134+
133135
void scriptpubkey_csv_2of2_then_1_from_bytes(
134136
byte_span_t keys, uint32_t csv_blocks, bool optimize, std::vector<unsigned char>& out);
135137

0 commit comments

Comments
 (0)