| 1379 | return notification_handled(cmd); |
| 1380 | } |
| 1381 | static struct command_result * |
| 1382 | parse_and_log_chain_move(struct command *cmd, |
| 1383 | const char *buf, |
| 1384 | const jsmntok_t *params, |
| 1385 | const char *acct_name STEALS, |
| 1386 | const struct amount_msat credit, |
| 1387 | const struct amount_msat debit, |
| 1388 | const char *coin_type STEALS, |
| 1389 | const u64 timestamp, |
| 1390 | const enum mvt_tag *tags, |
| 1391 | const char *desc) |
| 1392 | { |
| 1393 | struct chain_event *e = tal(cmd, struct chain_event); |
| 1394 | struct sha256 *payment_hash = tal(cmd, struct sha256); |
| 1395 | struct bitcoin_txid *spending_txid = tal(cmd, struct bitcoin_txid); |
| 1396 | struct node_id *peer_id; |
| 1397 | struct account *acct, *orig_acct; |
| 1398 | u32 closed_count; |
| 1399 | const char *err; |
| 1400 | |
| 1401 | /* Fields we expect on *every* chain movement */ |
| 1402 | err = json_scan(tmpctx, buf, params, |
| 1403 | "{coin_movement:" |
| 1404 | "{utxo_txid:%" |
| 1405 | ",vout:%" |
| 1406 | ",output_msat:%" |
| 1407 | ",blockheight:%" |
| 1408 | "}}", |
| 1409 | JSON_SCAN(json_to_txid, &e->outpoint.txid), |
| 1410 | JSON_SCAN(json_to_number, &e->outpoint.n), |
| 1411 | JSON_SCAN(json_to_msat, &e->output_value), |
| 1412 | JSON_SCAN(json_to_number, &e->blockheight)); |
| 1413 | |
| 1414 | if (err) |
| 1415 | plugin_err(cmd->plugin, |
| 1416 | "`coin_movement` payload did" |
| 1417 | " not scan %s: %.*s", |
| 1418 | err, json_tok_full_len(params), |
| 1419 | json_tok_full(buf, params)); |
| 1420 | |
| 1421 | /* Now try to get out the optional parts */ |
| 1422 | err = json_scan(tmpctx, buf, params, |
| 1423 | "{coin_movement:" |
| 1424 | "{txid:%" |
| 1425 | "}}", |
| 1426 | JSON_SCAN(json_to_txid, spending_txid)); |
| 1427 | |
| 1428 | if (err) { |
| 1429 | spending_txid = tal_free(spending_txid); |
| 1430 | err = tal_free(err); |
| 1431 | } |
| 1432 | |
| 1433 | e->spending_txid = tal_steal(e, spending_txid); |
| 1434 | |
| 1435 | /* Now try to get out the optional parts */ |
| 1436 | err = json_scan(tmpctx, buf, params, |
| 1437 | "{coin_movement:" |
| 1438 | "{payment_hash:%" |
no test coverage detected