FIXME: Load direct from db. */
| 2838 | |
| 2839 | /* FIXME: Load direct from db. */ |
| 2840 | const struct existing_htlc **peer_htlcs(const tal_t *ctx, |
| 2841 | const struct channel *channel) |
| 2842 | { |
| 2843 | struct existing_htlc **htlcs; |
| 2844 | struct htlc_in_map_iter ini; |
| 2845 | struct htlc_out_map_iter outi; |
| 2846 | struct htlc_in *hin; |
| 2847 | struct htlc_out *hout; |
| 2848 | struct lightningd *ld = channel->peer->ld; |
| 2849 | |
| 2850 | htlcs = tal_arr(ctx, struct existing_htlc *, 0); |
| 2851 | |
| 2852 | for (hin = htlc_in_map_first(ld->htlcs_in, &ini); |
| 2853 | hin; |
| 2854 | hin = htlc_in_map_next(ld->htlcs_in, &ini)) { |
| 2855 | struct failed_htlc *f; |
| 2856 | struct existing_htlc *existing; |
| 2857 | |
| 2858 | if (hin->key.channel != channel) |
| 2859 | continue; |
| 2860 | |
| 2861 | if (hin->badonion) |
| 2862 | f = take(mk_failed_htlc_badonion(NULL, hin, hin->badonion)); |
| 2863 | else if (hin->failonion) |
| 2864 | f = take(mk_failed_htlc(NULL, hin, hin->failonion)); |
| 2865 | else |
| 2866 | f = NULL; |
| 2867 | |
| 2868 | |
| 2869 | existing = new_existing_htlc(htlcs, hin->key.id, hin->hstate, |
| 2870 | hin->msat, &hin->payment_hash, |
| 2871 | hin->cltv_expiry, |
| 2872 | hin->onion_routing_packet, |
| 2873 | hin->path_key, |
| 2874 | hin->preimage, |
| 2875 | f, |
| 2876 | hin->extra_tlvs); |
| 2877 | tal_arr_expand(&htlcs, existing); |
| 2878 | } |
| 2879 | |
| 2880 | for (hout = htlc_out_map_first(ld->htlcs_out, &outi); |
| 2881 | hout; |
| 2882 | hout = htlc_out_map_next(ld->htlcs_out, &outi)) { |
| 2883 | struct failed_htlc *f; |
| 2884 | struct existing_htlc *existing; |
| 2885 | |
| 2886 | if (hout->key.channel != channel) |
| 2887 | continue; |
| 2888 | |
| 2889 | /* Note that channeld doesn't actually care *why* outgoing |
| 2890 | * HTLCs failed, so just use a dummy here. */ |
| 2891 | if (hout->failonion || hout->failmsg) { |
| 2892 | f = take(tal(NULL, struct failed_htlc)); |
| 2893 | f->id = hout->key.id; |
| 2894 | f->sha256_of_onion = tal(f, struct sha256); |
| 2895 | memset(f->sha256_of_onion, 0, |
| 2896 | sizeof(*f->sha256_of_onion)); |
| 2897 | f->badonion = BADONION; |
no test coverage detected