| 1352 | } |
| 1353 | |
| 1354 | void log_channel_event(struct db *db, |
| 1355 | const struct account *acct, |
| 1356 | struct channel_event *e) |
| 1357 | { |
| 1358 | struct db_stmt *stmt; |
| 1359 | |
| 1360 | stmt = db_prepare_v2(db, SQL("INSERT INTO channel_events" |
| 1361 | " (" |
| 1362 | " account_id" |
| 1363 | ", tag" |
| 1364 | ", credit" |
| 1365 | ", debit" |
| 1366 | ", fees" |
| 1367 | ", currency" |
| 1368 | ", payment_id" |
| 1369 | ", part_id" |
| 1370 | ", timestamp" |
| 1371 | ", ev_desc" |
| 1372 | ", rebalance_id" |
| 1373 | ")" |
| 1374 | " VALUES" |
| 1375 | " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); |
| 1376 | |
| 1377 | db_bind_u64(stmt, 0, acct->db_id); |
| 1378 | db_bind_text(stmt, 1, e->tag); |
| 1379 | db_bind_amount_msat(stmt, 2, &e->credit); |
| 1380 | db_bind_amount_msat(stmt, 3, &e->debit); |
| 1381 | db_bind_amount_msat(stmt, 4, &e->fees); |
| 1382 | db_bind_text(stmt, 5, e->currency); |
| 1383 | if (e->payment_id) |
| 1384 | db_bind_sha256(stmt, 6, e->payment_id); |
| 1385 | else |
| 1386 | db_bind_null(stmt, 6); |
| 1387 | db_bind_int(stmt, 7, e->part_id); |
| 1388 | db_bind_u64(stmt, 8, e->timestamp); |
| 1389 | if (e->desc) |
| 1390 | db_bind_text(stmt, 9, e->desc); |
| 1391 | else |
| 1392 | db_bind_null(stmt, 9); |
| 1393 | |
| 1394 | if (e->rebalance_id) |
| 1395 | db_bind_u64(stmt, 10, *e->rebalance_id); |
| 1396 | else |
| 1397 | db_bind_null(stmt, 10); |
| 1398 | |
| 1399 | db_exec_prepared_v2(stmt); |
| 1400 | e->db_id = db_last_insert_id_v2(stmt); |
| 1401 | e->acct_db_id = acct->db_id; |
| 1402 | e->acct_name = tal_strdup(e, acct->name); |
| 1403 | tal_free(stmt); |
| 1404 | } |
| 1405 | |
| 1406 | static struct chain_event **find_chain_events_bytxid(const tal_t *ctx, struct db *db, |
| 1407 | struct bitcoin_txid *txid) |