MCPcopy Create free account
hub / github.com/ElementsProject/lightning / msat_find_diff

Function msat_find_diff

plugins/bkpr/bookkeeper.c:788–825  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

786}
787
788static 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
827static void log_journal_entry(struct account *acct,
828 const char *currency,

Callers 3

listpeers_multi_doneFunction · 0.85
json_balance_snapshotFunction · 0.85
listpeers_doneFunction · 0.85

Calls 5

msat_netFunction · 0.85
amount_msat_zeroFunction · 0.85
amount_msat_addFunction · 0.85
amount_msat_greaterFunction · 0.85
amount_msat_subFunction · 0.85

Tested by

no test coverage detected