FIXME: Load direct from db. */
| 2450 | |
| 2451 | /* FIXME: Load direct from db. */ |
| 2452 | const struct existing_htlc **peer_htlcs(const tal_t *ctx, |
| 2453 | const struct channel *channel) |
| 2454 | { |
| 2455 | struct existing_htlc **htlcs; |
| 2456 | struct htlc_in_map_iter ini; |
| 2457 | struct htlc_out_map_iter outi; |
| 2458 | struct htlc_in *hin; |
| 2459 | struct htlc_out *hout; |
| 2460 | struct lightningd *ld = channel->peer->ld; |
| 2461 | |
| 2462 | htlcs = tal_arr(ctx, struct existing_htlc *, 0); |
| 2463 | |
| 2464 | for (hin = htlc_in_map_first(&ld->htlcs_in, &ini); |
| 2465 | hin; |
| 2466 | hin = htlc_in_map_next(&ld->htlcs_in, &ini)) { |
| 2467 | struct failed_htlc *f; |
| 2468 | struct existing_htlc *existing; |
| 2469 | |
| 2470 | if (hin->key.channel != channel) |
| 2471 | continue; |
| 2472 | |
| 2473 | if (hin->badonion) |
| 2474 | f = take(mk_failed_htlc_badonion(NULL, hin, hin->badonion)); |
| 2475 | else if (hin->failonion) |
| 2476 | f = take(mk_failed_htlc(NULL, hin, hin->failonion)); |
| 2477 | else |
| 2478 | f = NULL; |
| 2479 | |
| 2480 | existing = new_existing_htlc(htlcs, hin->key.id, hin->hstate, |
| 2481 | hin->msat, &hin->payment_hash, |
| 2482 | hin->cltv_expiry, |
| 2483 | hin->onion_routing_packet, |
| 2484 | hin->blinding, |
| 2485 | hin->preimage, |
| 2486 | f); |
| 2487 | tal_arr_expand(&htlcs, existing); |
| 2488 | } |
| 2489 | |
| 2490 | for (hout = htlc_out_map_first(&ld->htlcs_out, &outi); |
| 2491 | hout; |
| 2492 | hout = htlc_out_map_next(&ld->htlcs_out, &outi)) { |
| 2493 | struct failed_htlc *f; |
| 2494 | struct existing_htlc *existing; |
| 2495 | |
| 2496 | if (hout->key.channel != channel) |
| 2497 | continue; |
| 2498 | |
| 2499 | /* Note that channeld doesn't actually care *why* outgoing |
| 2500 | * HTLCs failed, so just use a dummy here. */ |
| 2501 | if (hout->failonion || hout->failmsg) { |
| 2502 | f = take(tal(NULL, struct failed_htlc)); |
| 2503 | f->id = hout->key.id; |
| 2504 | f->sha256_of_onion = tal(f, struct sha256); |
| 2505 | memset(f->sha256_of_onion, 0, |
| 2506 | sizeof(*f->sha256_of_onion)); |
| 2507 | f->badonion = BADONION; |
| 2508 | f->onion = NULL; |
| 2509 | } else |
no test coverage detected