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

Function listpeers_done

plugins/bkpr/bookkeeper.c:1320–1380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1318};
1319
1320static struct command_result *
1321listpeers_done(struct command *cmd, const char *buf,
1322 const jsmntok_t *result, struct event_info *info)
1323{
1324 struct acct_balance **balances, *bal;
1325 struct amount_msat credit_diff, debit_diff;
1326 const char *err;
1327
1328 if (new_missed_channel_account(cmd, buf, result,
1329 info->acct,
1330 info->ev->currency,
1331 info->ev->timestamp)) {
1332 db_begin_transaction(db);
1333 err = account_get_balance(tmpctx, db, info->acct->name,
1334 false, false, &balances, NULL);
1335 db_commit_transaction(db);
1336
1337 if (err)
1338 plugin_err(cmd->plugin, err);
1339
1340 /* FIXME: multiple currencies per account? */
1341 if (tal_count(balances) > 0)
1342 bal = balances[0];
1343 else {
1344 bal = tal(balances, struct acct_balance);
1345 bal->credit = AMOUNT_MSAT(0);
1346 bal->debit = AMOUNT_MSAT(0);
1347 }
1348 assert(tal_count(balances) == 1);
1349
1350 /* The expected current balance is zero, since
1351 * we just got the channel close event */
1352 err = msat_find_diff(AMOUNT_MSAT(0),
1353 bal->credit,
1354 bal->debit,
1355 &credit_diff, &debit_diff);
1356 if (err)
1357 plugin_err(cmd->plugin, err);
1358
1359 log_journal_entry(info->acct,
1360 info->ev->currency,
1361 info->ev->timestamp - 1,
1362 credit_diff, debit_diff);
1363 } else
1364 plugin_log(cmd->plugin, LOG_BROKEN,
1365 "Unable to find account %s in listpeers",
1366 info->acct->name);
1367
1368 /* Maybe mark acct as onchain resolved */
1369 err = do_account_close_checks(cmd, info->ev, info->acct);
1370 if (err)
1371 plugin_err(cmd->plugin, err);
1372
1373 if (info->ev->payment_id &&
1374 streq(info->ev->tag, mvt_tag_str(INVOICE))) {
1375 return lookup_invoice_desc(cmd, info->ev->credit,
1376 info->ev->payment_id);
1377 }

Callers

nothing calls this directly

Calls 11

account_get_balanceFunction · 0.85
msat_find_diffFunction · 0.85
log_journal_entryFunction · 0.85
do_account_close_checksFunction · 0.85
lookup_invoice_descFunction · 0.85
notification_handledFunction · 0.85
db_commit_transactionFunction · 0.50
plugin_errFunction · 0.50
plugin_logFunction · 0.50
mvt_tag_strFunction · 0.50

Tested by

no test coverage detected