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

Function wallet_peer_save

wallet/wallet.c:2133–2166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2131}
2132
2133static void wallet_peer_save(struct wallet *w, struct peer *peer)
2134{
2135 const char *addr =
2136 type_to_string(tmpctx, struct wireaddr_internal, &peer->addr);
2137 struct db_stmt *stmt =
2138 db_prepare_v2(w->db, SQL("SELECT id FROM peers WHERE node_id = ?"));
2139
2140 db_bind_node_id(stmt, 0, &peer->id);
2141 db_query_prepared(stmt);
2142
2143 if (db_step(stmt)) {
2144 /* So we already knew this peer, just return its dbid */
2145 peer->dbid = db_col_u64(stmt, "id");
2146 tal_free(stmt);
2147
2148 /* Since we're at it update the wireaddr */
2149 stmt = db_prepare_v2(
2150 w->db, SQL("UPDATE peers SET address = ? WHERE id = ?"));
2151 db_bind_text(stmt, 0, addr);
2152 db_bind_u64(stmt, 1, peer->dbid);
2153 db_exec_prepared_v2(take(stmt));
2154
2155 } else {
2156 /* Unknown peer, create it from scratch */
2157 tal_free(stmt);
2158 stmt = db_prepare_v2(w->db,
2159 SQL("INSERT INTO peers (node_id, address) VALUES (?, ?);")
2160 );
2161 db_bind_node_id(stmt, 0, &peer->id);
2162 db_bind_text(stmt, 1,addr);
2163 db_exec_prepared_v2(stmt);
2164 peer->dbid = db_last_insert_id_v2(take(stmt));
2165 }
2166}
2167
2168void wallet_channel_insert(struct wallet *w, struct channel *chan)
2169{

Callers 1

wallet_channel_insertFunction · 0.85

Calls 10

db_bind_node_idFunction · 0.85
db_query_preparedFunction · 0.85
db_stepFunction · 0.85
db_col_u64Function · 0.85
tal_freeFunction · 0.85
db_bind_textFunction · 0.85
db_bind_u64Function · 0.85
db_exec_prepared_v2Function · 0.85
db_last_insert_id_v2Function · 0.85
type_to_stringClass · 0.50

Tested by

no test coverage detected