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

Function parse_and_log_chain_move

plugins/bkpr/bookkeeper.c:1404–1584  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1402}
1403
1404static void
1405parse_and_log_chain_move(struct command *cmd,
1406 const char *buf,
1407 const jsmntok_t *chainmove,
1408 struct refresh_info *rinfo)
1409{
1410 struct chain_event *e = tal(cmd, struct chain_event);
1411 struct sha256 *payment_hash = tal(cmd, struct sha256);
1412 struct bitcoin_txid *spending_txid = tal(cmd, struct bitcoin_txid);
1413 struct node_id *peer_id;
1414 struct account *acct;
1415 u32 closed_count;
1416 char *acct_name;
1417 const char *err;
1418 struct bkpr *bkpr = bkpr_of(cmd->plugin);
1419 enum mvt_tag tag, *tags;
1420
1421 /* Fields we expect on *every* chain movement */
1422 closed_count = 0;
1423 err = json_scan(tmpctx, buf, chainmove,
1424 "{account_id:%"
1425 ",created_index:%"
1426 ",credit_msat:%"
1427 ",debit_msat:%"
1428 ",timestamp:%"
1429 ",utxo:%"
1430 ",output_msat:%"
1431 ",blockheight:%"
1432 ",primary_tag:%"
1433 ",extra_tags:%"
1434 ",output_count?:%"
1435 "}",
1436 JSON_SCAN_TAL(tmpctx, json_strdup, &acct_name),
1437 JSON_SCAN(json_to_u64, &e->db_id),
1438 JSON_SCAN(json_to_msat, &e->credit),
1439 JSON_SCAN(json_to_msat, &e->debit),
1440 JSON_SCAN(json_to_u64, &e->timestamp),
1441 JSON_SCAN(json_to_outpoint, &e->outpoint),
1442 JSON_SCAN(json_to_msat, &e->output_value),
1443 JSON_SCAN(json_to_number, &e->blockheight),
1444 JSON_SCAN(json_to_coin_mvt_tag, &tag),
1445 JSON_SCAN_TAL(tmpctx, json_to_tags, &tags),
1446 JSON_SCAN(json_to_number, &closed_count));
1447 if (err)
1448 plugin_err(cmd->plugin,
1449 "chainmove did"
1450 " not scan %s: %.*s",
1451 err, json_tok_full_len(chainmove),
1452 json_tok_full(buf, chainmove));
1453
1454 /* Now try to get out the optional parts */
1455 err = json_scan(tmpctx, buf, chainmove,
1456 "{spending_txid:%"
1457 "}",
1458 JSON_SCAN(json_to_txid, spending_txid));
1459
1460 if (err) {
1461 spending_txid = tal_free(spending_txid);

Callers 1

listchainmoves_doneFunction · 0.85

Calls 15

tal_freeFunction · 0.85
mvt_tag_strFunction · 0.85
fmt_bitcoin_outpointFunction · 0.85
fmt_bitcoin_txidFunction · 0.85
do_account_close_checksFunction · 0.85
lookup_invoice_descFunction · 0.85
lookup_currencyFunction · 0.85
bkpr_ofFunction · 0.70
find_or_create_accountFunction · 0.70
maybe_update_accountFunction · 0.70

Tested by

no test coverage detected