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

Function fillin_missing_local_basepoints

wallet/db.c:284–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

282}
283
284void fillin_missing_local_basepoints(struct lightningd *ld,
285 struct db *db)
286{
287
288 struct db_stmt *stmt;
289 stmt = db_prepare_v2(
290 db,
291 SQL("SELECT"
292 " channels.id"
293 ", peers.node_id "
294 "FROM"
295 " channels JOIN"
296 " peers "
297 "ON (peers.id = channels.peer_id)"));
298
299 db_query_prepared(stmt);
300 while (db_step(stmt)) {
301 struct node_id peer_id;
302 u64 dbid;
303 u8 *msg;
304 struct db_stmt *upstmt;
305 struct basepoints base;
306 struct pubkey funding_pubkey;
307
308 dbid = db_col_u64(stmt, "channels.id");
309 db_col_node_id(stmt, "peers.node_id", &peer_id);
310
311 if (!wire_sync_write(ld->hsm_fd,
312 towire_hsmd_get_channel_basepoints(
313 tmpctx, &peer_id, dbid)))
314 fatal("could not retrieve basepoint from hsmd");
315
316 msg = wire_sync_read(tmpctx, ld->hsm_fd);
317 if (!fromwire_hsmd_get_channel_basepoints_reply(
318 msg, &base, &funding_pubkey))
319 fatal("malformed hsmd_get_channel_basepoints_reply "
320 "from hsmd");
321
322 upstmt = db_prepare_v2(
323 db,
324 SQL("UPDATE channels SET"
325 " revocation_basepoint_local = ?"
326 ", payment_basepoint_local = ?"
327 ", htlc_basepoint_local = ?"
328 ", delayed_payment_basepoint_local = ?"
329 ", funding_pubkey_local = ? "
330 "WHERE id = ?;"));
331 db_bind_pubkey(upstmt, &base.revocation);
332 db_bind_pubkey(upstmt, &base.payment);
333 db_bind_pubkey(upstmt, &base.htlc);
334 db_bind_pubkey(upstmt, &base.delayed_payment);
335 db_bind_pubkey(upstmt, &funding_pubkey);
336
337 db_bind_u64(upstmt, dbid);
338
339 db_exec_prepared_v2(take(upstmt));
340 }
341

Callers

nothing calls this directly

Calls 13

db_query_preparedFunction · 0.85
db_stepFunction · 0.85
db_col_u64Function · 0.85
db_col_node_idFunction · 0.85
db_bind_pubkeyFunction · 0.85
db_bind_u64Function · 0.85
db_exec_prepared_v2Function · 0.85
tal_freeFunction · 0.85
wire_sync_writeFunction · 0.50
fatalFunction · 0.50
wire_sync_readFunction · 0.50

Tested by

no test coverage detected