| 813 | } |
| 814 | |
| 815 | static struct peer *wallet_peer_load(struct wallet *w, const u64 dbid) |
| 816 | { |
| 817 | const char *addrstr; |
| 818 | struct peer *peer = NULL; |
| 819 | struct node_id id; |
| 820 | struct wireaddr_internal addr; |
| 821 | struct db_stmt *stmt; |
| 822 | |
| 823 | stmt = db_prepare_v2( |
| 824 | w->db, SQL("SELECT id, node_id, address FROM peers WHERE id=?;")); |
| 825 | db_bind_u64(stmt, 0, dbid); |
| 826 | db_query_prepared(stmt); |
| 827 | |
| 828 | if (!db_step(stmt)) |
| 829 | goto done; |
| 830 | |
| 831 | if (db_col_is_null(stmt, "node_id")) { |
| 832 | db_col_ignore(stmt, "address"); |
| 833 | db_col_ignore(stmt, "id"); |
| 834 | goto done; |
| 835 | } |
| 836 | |
| 837 | db_col_node_id(stmt, "node_id", &id); |
| 838 | |
| 839 | /* This can happen for peers last seen on Torv2! */ |
| 840 | addrstr = db_col_strdup(tmpctx, stmt, "address"); |
| 841 | if (!parse_wireaddr_internal(addrstr, &addr, chainparams_get_ln_port(chainparams), |
| 842 | false, false, true, NULL)) { |
| 843 | log_unusual(w->log, "Unparsable peer address %s: replacing", |
| 844 | addrstr); |
| 845 | parse_wireaddr_internal("127.0.0.1:1", &addr, chainparams_get_ln_port(chainparams), |
| 846 | false, false, true, NULL); |
| 847 | } |
| 848 | |
| 849 | /* FIXME: save incoming in db! */ |
| 850 | peer = new_peer(w->ld, db_col_u64(stmt, "id"), &id, &addr, false); |
| 851 | |
| 852 | done: |
| 853 | tal_free(stmt); |
| 854 | return peer; |
| 855 | } |
| 856 | |
| 857 | static struct bitcoin_signature * |
| 858 | wallet_htlc_sigs_load(const tal_t *ctx, struct wallet *w, u64 channelid, |
no test coverage detected