MCPcopy Create free account
hub / github.com/ElementsProject/lightning / wallet_transaction_add

Function wallet_transaction_add

wallet/wallet.c:4037–4083  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4035}
4036
4037void wallet_transaction_add(struct wallet *w, const struct wally_tx *tx,
4038 const u32 blockheight, const u32 txindex)
4039{
4040 struct bitcoin_txid txid;
4041 struct db_stmt *stmt = db_prepare_v2(
4042 w->db, SQL("SELECT blockheight FROM transactions WHERE id=?"));
4043
4044 wally_txid(tx, &txid);
4045 db_bind_txid(stmt, 0, &txid);
4046 db_query_prepared(stmt);
4047
4048 if (!db_step(stmt)) {
4049 tal_free(stmt);
4050 /* This transaction is still unknown, insert */
4051 stmt = db_prepare_v2(w->db,
4052 SQL("INSERT INTO transactions ("
4053 " id"
4054 ", blockheight"
4055 ", txindex"
4056 ", rawtx) VALUES (?, ?, ?, ?);"));
4057 db_bind_txid(stmt, 0, &txid);
4058 if (blockheight) {
4059 db_bind_int(stmt, 1, blockheight);
4060 db_bind_int(stmt, 2, txindex);
4061 } else {
4062 db_bind_null(stmt, 1);
4063 db_bind_null(stmt, 2);
4064 }
4065 db_bind_tx(stmt, 3, tx);
4066 db_exec_prepared_v2(take(stmt));
4067 } else {
4068 db_col_ignore(stmt, "blockheight");
4069 tal_free(stmt);
4070
4071 if (blockheight) {
4072 /* We know about the transaction, update */
4073 stmt = db_prepare_v2(w->db,
4074 SQL("UPDATE transactions "
4075 "SET blockheight = ?, txindex = ? "
4076 "WHERE id = ?"));
4077 db_bind_int(stmt, 0, blockheight);
4078 db_bind_int(stmt, 1, txindex);
4079 db_bind_txid(stmt, 2, &txid);
4080 db_exec_prepared_v2(take(stmt));
4081 }
4082 }
4083}
4084
4085static void wallet_annotation_add(struct wallet *w, const struct bitcoin_txid *txid, int num,
4086 enum wallet_tx_annotation_type annotation_type, enum wallet_tx_type type, u64 channel)

Callers 1

sendpsbt_doneFunction · 0.70

Calls 10

wally_txidFunction · 0.85
db_bind_txidFunction · 0.85
db_query_preparedFunction · 0.85
db_stepFunction · 0.85
tal_freeFunction · 0.85
db_bind_intFunction · 0.85
db_bind_nullFunction · 0.85
db_bind_txFunction · 0.85
db_exec_prepared_v2Function · 0.85
db_col_ignoreFunction · 0.85

Tested by

no test coverage detected