Pull peers, channels and HTLCs from db, and wire them up. */
| 2122 | |
| 2123 | /* Pull peers, channels and HTLCs from db, and wire them up. */ |
| 2124 | struct htlc_in_map *load_channels_from_wallet(struct lightningd *ld) |
| 2125 | { |
| 2126 | struct peer *peer; |
| 2127 | struct htlc_in_map *unconnected_htlcs_in = tal(ld, struct htlc_in_map); |
| 2128 | |
| 2129 | /* Load channels from database */ |
| 2130 | if (!wallet_init_channels(ld->wallet)) |
| 2131 | fatal("Could not load channels from the database"); |
| 2132 | |
| 2133 | /* First we load the incoming htlcs */ |
| 2134 | list_for_each(&ld->peers, peer, list) { |
| 2135 | struct channel *channel; |
| 2136 | |
| 2137 | list_for_each(&peer->channels, channel, list) { |
| 2138 | if (!wallet_htlcs_load_in_for_channel(ld->wallet, |
| 2139 | channel, |
| 2140 | &ld->htlcs_in)) { |
| 2141 | fatal("could not load htlcs for channel"); |
| 2142 | } |
| 2143 | } |
| 2144 | } |
| 2145 | |
| 2146 | /* Make a copy of the htlc_map: entries removed as they're matched */ |
| 2147 | htlc_in_map_copy(unconnected_htlcs_in, &ld->htlcs_in); |
| 2148 | |
| 2149 | /* Now we load the outgoing HTLCs, so we can connect them. */ |
| 2150 | list_for_each(&ld->peers, peer, list) { |
| 2151 | struct channel *channel; |
| 2152 | |
| 2153 | list_for_each(&peer->channels, channel, list) { |
| 2154 | if (!wallet_htlcs_load_out_for_channel(ld->wallet, |
| 2155 | channel, |
| 2156 | &ld->htlcs_out, |
| 2157 | unconnected_htlcs_in)) { |
| 2158 | fatal("could not load outgoing htlcs for channel"); |
| 2159 | } |
| 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | #ifdef COMPAT_V061 |
| 2164 | fixup_htlcs_out(ld); |
| 2165 | #endif /* COMPAT_V061 */ |
| 2166 | |
| 2167 | return unconnected_htlcs_in; |
| 2168 | } |
| 2169 | |
| 2170 | static struct command_result *json_disconnect(struct command *cmd, |
| 2171 | const char *buffer, |
no test coverage detected