wallet: Update existing owned outputs with their confirmation height

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-03-02 14:33:01 +01:00
parent 7fc06d9b3e
commit b3c94a5256
1 changed files with 25 additions and 0 deletions

View File

@ -996,6 +996,24 @@ void wallet_peer_delete(struct wallet *w, u64 peer_dbid)
db_exec_prepared(w->db, stmt);
}
static void wallet_output_confirm(struct wallet *w,
const struct bitcoin_txid *txid,
const u32 outnum,
const u32 confirmation_height)
{
sqlite3_stmt *stmt;
assert(confirmation_height > 0);
stmt = db_prepare(w->db,
"UPDATE outputs "
"SET confirmation_height = ? "
"WHERE prev_out_tx = ? AND prev_out_index = ?");
sqlite3_bind_int(stmt, 1, confirmation_height);
sqlite3_bind_sha256_double(stmt, 2, &txid->shad);
sqlite3_bind_int(stmt, 3, outnum);
db_exec_prepared(w->db, stmt);
}
int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
const struct block *block, u64 *total_satoshi)
{
@ -1028,6 +1046,13 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
&utxo->txid));
if (!wallet_add_utxo(w, utxo, is_p2sh ? p2sh_wpkh : our_change)) {
/* In case we already know the output, make
* sure we actually track its
* blockheight. This can happen when we grab
* the output from a transaction we created
* outselves. */
if (block)
wallet_output_confirm(w, &utxo->txid, utxo->outnum, block->height);
tal_free(utxo);
return -1;
}