| 1274 | } |
| 1275 | |
| 1276 | static struct peer *wallet_peer_load(struct wallet *w, const u64 dbid) |
| 1277 | { |
| 1278 | const char *addrstr, *err; |
| 1279 | struct peer *peer = NULL; |
| 1280 | struct node_id id; |
| 1281 | struct wireaddr_internal addr; |
| 1282 | struct wireaddr *last_known_addr; |
| 1283 | struct db_stmt *stmt; |
| 1284 | |
| 1285 | stmt = db_prepare_v2( |
| 1286 | w->db, SQL("SELECT id, node_id, address, feature_bits, last_known_address FROM peers WHERE id=?;")); |
| 1287 | db_bind_u64(stmt, dbid); |
| 1288 | db_query_prepared(stmt); |
| 1289 | |
| 1290 | if (!db_step(stmt)) |
| 1291 | goto done; |
| 1292 | |
| 1293 | if (db_col_is_null(stmt, "node_id")) { |
| 1294 | db_col_ignore(stmt, "address"); |
| 1295 | db_col_ignore(stmt, "id"); |
| 1296 | db_col_ignore(stmt, "feature_bits"); |
| 1297 | db_col_ignore(stmt, "last_known_address"); |
| 1298 | goto done; |
| 1299 | } |
| 1300 | |
| 1301 | db_col_node_id(stmt, "node_id", &id); |
| 1302 | |
| 1303 | /* This can happen for peers last seen on Torv2! */ |
| 1304 | addrstr = db_col_strdup(tmpctx, stmt, "address"); |
| 1305 | err = parse_wireaddr_internal(tmpctx, addrstr, chainparams_get_ln_port(chainparams), true, &addr); |
| 1306 | if (err) { |
| 1307 | log_unusual(w->log, "Unparsable peer address %s (%s): replacing", |
| 1308 | addrstr, err); |
| 1309 | err = parse_wireaddr_internal(tmpctx, "127.0.0.1:1", chainparams_get_ln_port(chainparams), |
| 1310 | false, &addr); |
| 1311 | assert(!err); |
| 1312 | } |
| 1313 | |
| 1314 | if (db_col_is_null(stmt, "last_known_address")) { |
| 1315 | last_known_addr = NULL; |
| 1316 | } else { |
| 1317 | last_known_addr = db_col_wireaddr(tmpctx, stmt, "last_known_address"); |
| 1318 | if (!last_known_addr) { |
| 1319 | log_broken(w->log, "Unparsable lastknown address %s: ignoring", |
| 1320 | tal_hex(tmpctx, db_col_arr(tmpctx, stmt, "last_known_address", u8))); |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | peer = new_peer(w->ld, db_col_u64(stmt, "id"), &id, &addr, last_known_addr, |
| 1325 | db_col_arr(stmt, stmt, "feature_bits", u8), false); |
| 1326 | |
| 1327 | done: |
| 1328 | tal_free(stmt); |
| 1329 | return peer; |
| 1330 | } |
| 1331 | |
| 1332 | static struct bitcoin_signature * |
| 1333 | wallet_htlc_sigs_load(const tal_t *ctx, struct wallet *w, u64 channelid, |
no test coverage detected