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

Function wallet_transaction_add

wallet/wallet.c:5140–5186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5138}
5139
5140void wallet_transaction_add(struct wallet *w, const struct wally_tx *tx,
5141 const u32 blockheight, const u32 txindex)
5142{
5143 struct bitcoin_txid txid;
5144 struct db_stmt *stmt = db_prepare_v2(
5145 w->db, SQL("SELECT blockheight FROM transactions WHERE id=?"));
5146
5147 wally_txid(tx, &txid);
5148 db_bind_txid(stmt, &txid);
5149 db_query_prepared(stmt);
5150
5151 if (!db_step(stmt)) {
5152 tal_free(stmt);
5153 /* This transaction is still unknown, insert */
5154 stmt = db_prepare_v2(w->db,
5155 SQL("INSERT INTO transactions ("
5156 " id"
5157 ", blockheight"
5158 ", txindex"
5159 ", rawtx) VALUES (?, ?, ?, ?);"));
5160 db_bind_txid(stmt, &txid);
5161 if (blockheight) {
5162 db_bind_int(stmt, blockheight);
5163 db_bind_int(stmt, txindex);
5164 } else {
5165 db_bind_null(stmt);
5166 db_bind_null(stmt);
5167 }
5168 db_bind_tx(stmt, tx);
5169 db_exec_prepared_v2(take(stmt));
5170 } else {
5171 db_col_ignore(stmt, "blockheight");
5172 tal_free(stmt);
5173
5174 if (blockheight) {
5175 /* We know about the transaction, update */
5176 stmt = db_prepare_v2(w->db,
5177 SQL("UPDATE transactions "
5178 "SET blockheight = ?, txindex = ? "
5179 "WHERE id = ?"));
5180 db_bind_int(stmt, blockheight);
5181 db_bind_int(stmt, txindex);
5182 db_bind_txid(stmt, &txid);
5183 db_exec_prepared_v2(take(stmt));
5184 }
5185 }
5186}
5187
5188static void wallet_annotation_add(struct wallet *w, const struct bitcoin_txid *txid, int num,
5189 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