| 786 | } |
| 787 | |
| 788 | static char *msat_find_diff(struct amount_msat balance, |
| 789 | struct amount_msat credits, |
| 790 | struct amount_msat debits, |
| 791 | struct amount_msat *credit_diff, |
| 792 | struct amount_msat *debit_diff) |
| 793 | { |
| 794 | struct amount_msat net_credit, net_debit; |
| 795 | char *err; |
| 796 | |
| 797 | err = msat_net(tmpctx, credits, debits, |
| 798 | &net_credit, &net_debit); |
| 799 | if (err) |
| 800 | return err; |
| 801 | |
| 802 | /* If we're not missing events, debits == 0 */ |
| 803 | if (!amount_msat_zero(net_debit)) { |
| 804 | assert(amount_msat_zero(net_credit)); |
| 805 | if (!amount_msat_add(credit_diff, net_debit, balance)) |
| 806 | return "Overflow finding credit_diff"; |
| 807 | *debit_diff = AMOUNT_MSAT(0); |
| 808 | } else { |
| 809 | assert(amount_msat_zero(net_debit)); |
| 810 | if (amount_msat_greater(net_credit, balance)) { |
| 811 | if (!amount_msat_sub(debit_diff, net_credit, |
| 812 | balance)) |
| 813 | return "Err net_credit - amt"; |
| 814 | *credit_diff = AMOUNT_MSAT(0); |
| 815 | } else { |
| 816 | if (!amount_msat_sub(credit_diff, balance, |
| 817 | net_credit)) |
| 818 | return "Err amt - net_credit"; |
| 819 | |
| 820 | *debit_diff = AMOUNT_MSAT(0); |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | return NULL; |
| 825 | } |
| 826 | |
| 827 | static void log_journal_entry(struct account *acct, |
| 828 | const char *currency, |
no test coverage detected