| 3398 | } |
| 3399 | |
| 3400 | void wallet_htlc_save_in(struct wallet *wallet, |
| 3401 | const struct channel *chan, struct htlc_in *in) |
| 3402 | { |
| 3403 | struct db_stmt *stmt; |
| 3404 | |
| 3405 | stmt = db_prepare_v2(wallet->db, |
| 3406 | SQL("INSERT INTO channel_htlcs (" |
| 3407 | " id," |
| 3408 | " channel_id," |
| 3409 | " channel_htlc_id, " |
| 3410 | " direction," |
| 3411 | " msatoshi," |
| 3412 | " cltv_expiry," |
| 3413 | " payment_hash, " |
| 3414 | " payment_key," |
| 3415 | " hstate," |
| 3416 | " shared_secret," |
| 3417 | " routing_onion," |
| 3418 | " received_time," |
| 3419 | " min_commit_num, " |
| 3420 | " fail_immediate) VALUES " |
| 3421 | "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); |
| 3422 | |
| 3423 | in->dbid = htlcs_index_created(wallet->ld, |
| 3424 | in->key.id, |
| 3425 | chan, |
| 3426 | &in->payment_hash, |
| 3427 | REMOTE, |
| 3428 | in->cltv_expiry, |
| 3429 | in->msat, |
| 3430 | in->hstate); |
| 3431 | db_bind_u64(stmt, in->dbid); |
| 3432 | db_bind_u64(stmt, chan->dbid); |
| 3433 | db_bind_u64(stmt, in->key.id); |
| 3434 | db_bind_int(stmt, DIRECTION_INCOMING); |
| 3435 | db_bind_amount_msat(stmt, in->msat); |
| 3436 | db_bind_int(stmt, in->cltv_expiry); |
| 3437 | db_bind_sha256(stmt, &in->payment_hash); |
| 3438 | |
| 3439 | if (in->preimage) |
| 3440 | db_bind_preimage(stmt, in->preimage); |
| 3441 | else |
| 3442 | db_bind_null(stmt); |
| 3443 | db_bind_int(stmt, in->hstate); |
| 3444 | |
| 3445 | if (!in->shared_secret) |
| 3446 | db_bind_null(stmt); |
| 3447 | else |
| 3448 | db_bind_secret(stmt, in->shared_secret); |
| 3449 | |
| 3450 | db_bind_blob(stmt, in->onion_routing_packet, |
| 3451 | sizeof(in->onion_routing_packet)); |
| 3452 | |
| 3453 | db_bind_timeabs(stmt, in->received_time); |
| 3454 | db_bind_u64(stmt, min_unsigned(chan->next_index[LOCAL]-1, |
| 3455 | chan->next_index[REMOTE]-1)); |
| 3456 | |
| 3457 | db_bind_int(stmt, in->fail_immediate); |