wallet: Add primitive to register new utxoset outpoint to the wallet

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-03-04 01:37:56 +01:00
parent d8d11e5689
commit 27e0ec694c
2 changed files with 34 additions and 0 deletions

View file

@ -1816,3 +1816,33 @@ void wallet_outpoint_spend(struct wallet *w, const u32 blockheight,
db_exec_prepared(w->db, stmt); 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);
}

View file

@ -711,4 +711,8 @@ void wallet_blocks_rollback(struct wallet *w, u32 height);
void wallet_outpoint_spend(struct wallet *w, const u32 blockheight, void wallet_outpoint_spend(struct wallet *w, const u32 blockheight,
const struct bitcoin_txid *txid, const u32 outnum); 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 */ #endif /* WALLET_WALLET_H */