From 27e0ec694c4abd3a33c06e0f5f0c6816695a6040 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sun, 4 Mar 2018 01:37:56 +0100 Subject: [PATCH] wallet: Add primitive to register new utxoset outpoint to the wallet Signed-off-by: Christian Decker --- wallet/wallet.c | 30 ++++++++++++++++++++++++++++++ wallet/wallet.h | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/wallet/wallet.c b/wallet/wallet.c index 587636455..11e011f22 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1816,3 +1816,33 @@ void wallet_outpoint_spend(struct wallet *w, const u32 blockheight, db_exec_prepared(w->db, stmt); } } + +void wallet_utxoset_add(struct wallet *w, const struct bitcoin_tx *tx, + const u32 outnum, const u32 blockheight, + const u32 txindex, const u8 *scriptpubkey, + const u64 satoshis) +{ + sqlite3_stmt *stmt; + struct bitcoin_txid txid; + bitcoin_txid(tx, &txid); + + stmt = db_prepare(w->db, "INSERT INTO utxoset (" + " txid," + " outnum," + " blockheight," + " spendheight," + " txindex," + " scriptpubkey," + " satoshis" + ") VALUES(?, ?, ?, ?, ?, ?, ?);"); + sqlite3_bind_sha256_double(stmt, 1, &txid.shad); + sqlite3_bind_int(stmt, 2, outnum); + sqlite3_bind_int(stmt, 3, blockheight); + sqlite3_bind_null(stmt, 4); + sqlite3_bind_int(stmt, 5, txindex); + sqlite3_bind_blob(stmt, 6, scriptpubkey, tal_len(scriptpubkey), SQLITE_TRANSIENT); + sqlite3_bind_int64(stmt, 7, satoshis); + db_exec_prepared(w->db, stmt); + + outpointfilter_add(w->utxoset_outpoints, &txid, outnum); +} diff --git a/wallet/wallet.h b/wallet/wallet.h index 5bcbfc3a9..68a48571c 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -711,4 +711,8 @@ void wallet_blocks_rollback(struct wallet *w, u32 height); void wallet_outpoint_spend(struct wallet *w, const u32 blockheight, const struct bitcoin_txid *txid, const u32 outnum); +void wallet_utxoset_add(struct wallet *w, const struct bitcoin_tx *tx, + const u32 outnum, const u32 blockheight, + const u32 txindex, const u8 *scriptpubkey, + const u64 satoshis); #endif /* WALLET_WALLET_H */