Skip to content

Commit

Permalink
lightningd/json_withdraw:
Browse files Browse the repository at this point in the history
Add the change output to owned_txfilter so its entry in db will
get a confirmation_height when detected in a block by filter_block_txs

before this commit, after a 'withdraw' command, 'listfunds' would
not show our change outputs as confirmed

Modified the log message in wallet_extract_owned_outputs to
append 'CONFIRMED' when it is called with a blockheight arg.
To make distinction between (1st call) when adding owned output to the
db and (2th call) when confirmed in block.
  • Loading branch information
SimonVrouwe authored and cdecker committed Feb 4, 2019
1 parent 7eaf5b5 commit 35545f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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",
output, tx->output[output].amount,
is_p2sh ? "P2SH" : "SEGWIT",
type_to_string(tmpctx, struct bitcoin_txid,
&utxo->txid));
&utxo->txid), blockheight ? "CONFIRMED" : "");

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

0 comments on commit 35545f7

Please sign in to comment.