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

Function fillin_missing_scriptpubkeys

wallet/db.c:166–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164}
165
166void fillin_missing_scriptpubkeys(struct lightningd *ld, struct db *db)
167{
168 struct db_stmt *stmt;
169
170 stmt = db_prepare_v2(db, SQL("SELECT"
171 " type"
172 ", keyindex"
173 ", prev_out_tx"
174 ", prev_out_index"
175 ", channel_id"
176 ", peer_id"
177 ", commitment_point"
178 " FROM outputs"
179 " WHERE scriptpubkey IS NULL;"));
180
181 db_query_prepared(stmt);
182 while (db_step(stmt)) {
183 int type;
184 u8 *scriptPubkey;
185 struct bitcoin_txid txid;
186 u32 outnum, keyindex;
187 struct pubkey key;
188 struct db_stmt *update_stmt;
189
190 type = db_col_int(stmt, "type");
191 keyindex = db_col_int(stmt, "keyindex");
192 db_col_txid(stmt, "prev_out_tx", &txid);
193 outnum = db_col_int(stmt, "prev_out_index");
194
195 /* This indiciates whether or not we have 'close_info' */
196 if (!db_col_is_null(stmt, "channel_id")) {
197 struct pubkey *commitment_point;
198 struct node_id peer_id;
199 u64 channel_id;
200 u8 *msg;
201
202 channel_id = db_col_u64(stmt, "channel_id");
203 db_col_node_id(stmt, "peer_id", &peer_id);
204 commitment_point = db_col_optional(stmt, stmt, "commitment_point", pubkey);
205
206 /* Have to go ask the HSM to derive the pubkey for us */
207 msg = towire_hsmd_get_output_scriptpubkey(NULL,
208 channel_id,
209 &peer_id,
210 commitment_point);
211 if (!wire_sync_write(ld->hsm_fd, take(msg)))
212 fatal("Could not write to HSM: %s", strerror(errno));
213 msg = wire_sync_read(stmt, ld->hsm_fd);
214 if (!fromwire_hsmd_get_output_scriptpubkey_reply(stmt, msg,
215 &scriptPubkey))
216 fatal("HSM gave bad hsm_get_output_scriptpubkey_reply %s",
217 tal_hex(msg, msg));
218 } else {
219 db_col_ignore(stmt, "peer_id");
220 db_col_ignore(stmt, "commitment_point");
221 bip32_pubkey(ld, &key, keyindex);
222 if (type == WALLET_OUTPUT_P2SH_WPKH) {
223 u8 *redeemscript = bitcoin_redeem_p2sh_p2wpkh(stmt, &key);

Callers

nothing calls this directly

Calls 15

db_query_preparedFunction · 0.85
db_stepFunction · 0.85
db_col_intFunction · 0.85
db_col_txidFunction · 0.85
db_col_is_nullFunction · 0.85
db_col_u64Function · 0.85
db_col_node_idFunction · 0.85
tal_hexFunction · 0.85
db_col_ignoreFunction · 0.85
scriptpubkey_p2shFunction · 0.85
scriptpubkey_p2wpkhFunction · 0.85

Tested by

no test coverage detected