| 1402 | } |
| 1403 | |
| 1404 | static void |
| 1405 | parse_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); |
no test coverage detected