| 1426 | } |
| 1427 | |
| 1428 | static void |
| 1429 | parse_and_log_chain_move(struct command *cmd, |
| 1430 | const char *buf, |
| 1431 | const jsmntok_t *chainmove, |
| 1432 | struct refresh_info *rinfo) |
| 1433 | { |
| 1434 | struct chain_event *e = tal(cmd, struct chain_event); |
| 1435 | struct sha256 *payment_hash = tal(cmd, struct sha256); |
| 1436 | struct bitcoin_txid *spending_txid = tal(cmd, struct bitcoin_txid); |
| 1437 | struct node_id *peer_id; |
| 1438 | struct account *acct; |
| 1439 | u32 closed_count; |
| 1440 | char *acct_name; |
| 1441 | const char *err; |
| 1442 | struct bkpr *bkpr = bkpr_of(cmd->plugin); |
| 1443 | enum mvt_tag tag, *tags; |
| 1444 | |
| 1445 | /* Fields we expect on *every* chain movement */ |
| 1446 | closed_count = 0; |
| 1447 | err = json_scan(tmpctx, buf, chainmove, |
| 1448 | "{account_id:%" |
| 1449 | ",created_index:%" |
| 1450 | ",credit_msat:%" |
| 1451 | ",debit_msat:%" |
| 1452 | ",timestamp:%" |
| 1453 | ",utxo:%" |
| 1454 | ",output_msat:%" |
| 1455 | ",blockheight:%" |
| 1456 | ",primary_tag:%" |
| 1457 | ",extra_tags:%" |
| 1458 | ",output_count?:%" |
| 1459 | "}", |
| 1460 | JSON_SCAN_TAL(tmpctx, json_strdup, &acct_name), |
| 1461 | JSON_SCAN(json_to_u64, &e->db_id), |
| 1462 | JSON_SCAN(json_to_msat, &e->credit), |
| 1463 | JSON_SCAN(json_to_msat, &e->debit), |
| 1464 | JSON_SCAN(json_to_u64, &e->timestamp), |
| 1465 | JSON_SCAN(json_to_outpoint, &e->outpoint), |
| 1466 | JSON_SCAN(json_to_msat, &e->output_value), |
| 1467 | JSON_SCAN(json_to_number, &e->blockheight), |
| 1468 | JSON_SCAN(json_to_coin_mvt_tag, &tag), |
| 1469 | JSON_SCAN_TAL(tmpctx, json_to_tags, &tags), |
| 1470 | JSON_SCAN(json_to_number, &closed_count)); |
| 1471 | if (err) |
| 1472 | plugin_err(cmd->plugin, |
| 1473 | "chainmove did" |
| 1474 | " not scan %s: %.*s", |
| 1475 | err, json_tok_full_len(chainmove), |
| 1476 | json_tok_full(buf, chainmove)); |
| 1477 | |
| 1478 | /* Now try to get out the optional parts */ |
| 1479 | err = json_scan(tmpctx, buf, chainmove, |
| 1480 | "{spending_txid:%" |
| 1481 | "}", |
| 1482 | JSON_SCAN(json_to_txid, spending_txid)); |
| 1483 | |
| 1484 | if (err) { |
| 1485 | spending_txid = tal_free(spending_txid); |
no test coverage detected