Core cleanup function. */
| 237 | |
| 238 | /* Core cleanup function. */ |
| 239 | static struct command_result * |
| 240 | mfc_cleanup_(struct multifundchannel_command *mfc, |
| 241 | struct command_result *(*cb)(void *arg), |
| 242 | void *arg) |
| 243 | { |
| 244 | struct multifundchannel_cleanup *cleanup; |
| 245 | unsigned int i; |
| 246 | |
| 247 | plugin_log(mfc->cmd->plugin, LOG_DBG, |
| 248 | "mfc %"PRIu64": cleanup!", mfc->id); |
| 249 | |
| 250 | cleanup = tal(mfc, struct multifundchannel_cleanup); |
| 251 | cleanup->pending = 0; |
| 252 | cleanup->cb = cb; |
| 253 | cleanup->arg = arg; |
| 254 | |
| 255 | /* If there's commitments, anywhere, we have to fail/restart. |
| 256 | * We also cleanup the PSBT if there's no v2's around */ |
| 257 | if (mfc->psbt) { |
| 258 | plugin_log(mfc->cmd->plugin, LOG_DBG, |
| 259 | "mfc %"PRIu64": unreserveinputs task.", mfc->id); |
| 260 | |
| 261 | ++cleanup->pending; |
| 262 | mfc_cleanup_psbt(mfc->cmd, cleanup, mfc->psbt); |
| 263 | } |
| 264 | for (i = 0; i < tal_count(mfc->destinations); ++i) { |
| 265 | struct multifundchannel_destination *dest; |
| 266 | dest = &mfc->destinations[i]; |
| 267 | |
| 268 | switch (dest->state) { |
| 269 | case MULTIFUNDCHANNEL_STARTED: |
| 270 | /* v1 handling */ |
| 271 | if (!is_v2(dest)) { |
| 272 | plugin_log(mfc->cmd->plugin, LOG_DBG, |
| 273 | "mfc %"PRIu64", dest %u: " |
| 274 | "fundchannel_cancel task.", |
| 275 | mfc->id, dest->index); |
| 276 | ++cleanup->pending; |
| 277 | mfc_cleanup_fc(mfc->cmd, cleanup, dest); |
| 278 | } else { /* v2 handling */ |
| 279 | plugin_log(mfc->cmd->plugin, LOG_DBG, |
| 280 | "mfc %"PRIu64", dest %u:" |
| 281 | " openchannel_abort task.", |
| 282 | mfc->id, dest->index); |
| 283 | ++cleanup->pending; |
| 284 | mfc_cleanup_oc(mfc->cmd, cleanup, dest); |
| 285 | } |
| 286 | continue; |
| 287 | case MULTIFUNDCHANNEL_COMPLETED: |
| 288 | /* Definitely a v1 */ |
| 289 | plugin_log(mfc->cmd->plugin, LOG_DBG, |
| 290 | "mfc %"PRIu64", dest %u: " |
| 291 | "fundchannel_cancel task.", |
| 292 | mfc->id, dest->index); |
| 293 | ++cleanup->pending; |
| 294 | mfc_cleanup_fc(mfc->cmd, cleanup, dest); |
| 295 | continue; |
| 296 | case MULTIFUNDCHANNEL_UPDATED: |
nothing calls this directly
no test coverage detected