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

Function msat_net

plugins/bkpr/bookkeeper.c:753–786  ·  view source on GitHub ↗

Net out credit/debit --> basically find the diff */

Source from the content-addressed store, hash-verified

751
752/* Net out credit/debit --> basically find the diff */
753static char *msat_net(const tal_t *ctx,
754 struct amount_msat credit,
755 struct amount_msat debit,
756 struct amount_msat *credit_net,
757 struct amount_msat *debit_net)
758{
759 if (amount_msat_eq(credit, debit)) {
760 *credit_net = AMOUNT_MSAT(0);
761 *debit_net = AMOUNT_MSAT(0);
762 } else if (amount_msat_greater(credit, debit)) {
763 if (!amount_msat_sub(credit_net, credit, debit))
764 return tal_fmt(ctx, "unexpected fail, can't sub."
765 " %s - %s",
766 type_to_string(ctx, struct amount_msat,
767 &credit),
768 type_to_string(ctx, struct amount_msat,
769 &debit));
770 *debit_net = AMOUNT_MSAT(0);
771 } else {
772 if (!amount_msat_sub(debit_net, debit, credit)) {
773 return tal_fmt(ctx, "unexpected fail, can't sub."
774 " %s - %s",
775 type_to_string(ctx,
776 struct amount_msat,
777 &debit),
778 type_to_string(ctx,
779 struct amount_msat,
780 &credit));
781 }
782 *credit_net = AMOUNT_MSAT(0);
783 }
784
785 return NULL;
786}
787
788static char *msat_find_diff(struct amount_msat balance,
789 struct amount_msat credits,

Callers 1

msat_find_diffFunction · 0.85

Calls 4

amount_msat_greaterFunction · 0.85
amount_msat_subFunction · 0.85
amount_msat_eqFunction · 0.50
type_to_stringClass · 0.50

Tested by

no test coverage detected