Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1132,11 +1132,11 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
utxo->blockheight = blockheight?blockheight:NULL;
utxo->spendheight = NULL;

log_debug(w->log, "Owning output %zu %"PRIu64" (%s) txid %s",
log_debug(w->log, "Owning output %zu %"PRIu64" (%s) txid %s %s",
Comment thread
This conversation was marked as resolved.
output, tx->output[output].amount,
is_p2sh ? "P2SH" : "SEGWIT",
type_to_string(tmpctx, struct bitcoin_txid,
&utxo->txid));
&utxo->txid), blockheight ? "CONFIRMED" : "");
Comment thread
This conversation was marked as resolved.

if (!wallet_add_utxo(w, utxo, is_p2sh ? p2sh_wpkh : our_change)) {
/* In case we already know the output, make
Expand Down
16 changes: 16 additions & 0 deletions wallet/walletrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ static void wallet_withdrawal_broadcast(struct bitcoind *bitcoind UNUSED,
* generated the hex tx, so this should always work */
struct bitcoin_tx *tx = bitcoin_tx_from_hex(withdraw, withdraw->hextx, strlen(withdraw->hextx));
assert(tx != NULL);

/* Extract the change output and add it to the DB */
wallet_extract_owned_outputs(ld->wallet, tx, NULL, &change_satoshi);

/* Note normally, change_satoshi == withdraw->wtx.change, but
Expand Down Expand Up @@ -95,6 +97,8 @@ static struct command_result *json_withdraw(struct command *cmd,
struct withdrawal *withdraw = tal(cmd, struct withdrawal);
u32 *feerate_per_kw;
struct bitcoin_tx *tx;
struct ext_key ext;
struct pubkey pubkey;
enum address_parse_result addr_parse;
struct command_result *res;

Expand Down Expand Up @@ -143,6 +147,18 @@ static struct command_result *json_withdraw(struct command *cmd,
if (res)
return res;

if (bip32_key_from_parent(cmd->ld->wallet->bip32_base, withdraw->wtx.change_key_index,
BIP32_FLAG_KEY_PUBLIC, &ext) != WALLY_OK) {
return command_fail(cmd, LIGHTNINGD, "Keys generation failure");
}

if (!secp256k1_ec_pubkey_parse(secp256k1_ctx, &pubkey.pubkey,
ext.pub_key, sizeof(ext.pub_key))) {
return command_fail(cmd, LIGHTNINGD, "Key parsing failure");
}

txfilter_add_derkey(cmd->ld->owned_txfilter, ext.pub_key);

u8 *msg = towire_hsm_sign_withdrawal(cmd,
withdraw->wtx.amount,
withdraw->wtx.change,
Expand Down