| 730 | } |
| 731 | |
| 732 | static void json_add_events(struct json_stream *res, |
| 733 | const struct bkpr *bkpr, |
| 734 | struct channel_event **channel_events, |
| 735 | struct chain_event **chain_events, |
| 736 | struct onchain_fee **onchain_fees) |
| 737 | { |
| 738 | for (size_t i = 0, j = 0, k = 0; |
| 739 | i < tal_count(chain_events) |
| 740 | || j < tal_count(channel_events) |
| 741 | || k < tal_count(onchain_fees); |
| 742 | /* Incrementing happens inside loop */) { |
| 743 | struct channel_event *chan; |
| 744 | struct chain_event *chain; |
| 745 | struct onchain_fee *fee; |
| 746 | u64 lowest = 0; |
| 747 | |
| 748 | if (i < tal_count(chain_events)) |
| 749 | chain = chain_events[i]; |
| 750 | else |
| 751 | chain = NULL; |
| 752 | if (j < tal_count(channel_events)) |
| 753 | chan = channel_events[j]; |
| 754 | else |
| 755 | chan = NULL; |
| 756 | if (k < tal_count(onchain_fees)) |
| 757 | fee = onchain_fees[k]; |
| 758 | else |
| 759 | fee = NULL; |
| 760 | |
| 761 | if (chain) |
| 762 | lowest = chain->timestamp; |
| 763 | |
| 764 | if (chan |
| 765 | && (lowest == 0 || lowest > chan->timestamp)) |
| 766 | lowest = chan->timestamp; |
| 767 | |
| 768 | if (fee |
| 769 | && (lowest == 0 || lowest > fee->timestamp)) |
| 770 | lowest = fee->timestamp; |
| 771 | |
| 772 | /* chain events first, then channel events, then fees. */ |
| 773 | if (chain && chain->timestamp == lowest) { |
| 774 | json_add_chain_event(res, bkpr, chain); |
| 775 | i++; |
| 776 | continue; |
| 777 | } |
| 778 | |
| 779 | if (chan && chan->timestamp == lowest) { |
| 780 | json_add_channel_event(res, bkpr, chan); |
| 781 | j++; |
| 782 | continue; |
| 783 | } |
| 784 | |
| 785 | /* Last thing left is the fee */ |
| 786 | json_add_onchain_fee(res, bkpr, fee); |
| 787 | k++; |
| 788 | } |
| 789 | } |
no test coverage detected