| 3380 | } |
| 3381 | |
| 3382 | void wallet_htlc_save_in(struct wallet *wallet, |
| 3383 | const struct channel *chan, struct htlc_in *in) |
| 3384 | { |
| 3385 | struct db_stmt *stmt; |
| 3386 | |
| 3387 | stmt = db_prepare_v2(wallet->db, |
| 3388 | SQL("INSERT INTO channel_htlcs (" |
| 3389 | " id," |
| 3390 | " channel_id," |
| 3391 | " channel_htlc_id, " |
| 3392 | " direction," |
| 3393 | " msatoshi," |
| 3394 | " cltv_expiry," |
| 3395 | " payment_hash, " |
| 3396 | " payment_key," |
| 3397 | " hstate," |
| 3398 | " shared_secret," |
| 3399 | " routing_onion," |
| 3400 | " received_time," |
| 3401 | " min_commit_num, " |
| 3402 | " fail_immediate) VALUES " |
| 3403 | "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); |
| 3404 | |
| 3405 | in->dbid = htlcs_index_created(wallet->ld, |
| 3406 | in->key.id, |
| 3407 | chan, |
| 3408 | &in->payment_hash, |
| 3409 | REMOTE, |
| 3410 | in->cltv_expiry, |
| 3411 | in->msat, |
| 3412 | in->hstate); |
| 3413 | db_bind_u64(stmt, in->dbid); |
| 3414 | db_bind_u64(stmt, chan->dbid); |
| 3415 | db_bind_u64(stmt, in->key.id); |
| 3416 | db_bind_int(stmt, DIRECTION_INCOMING); |
| 3417 | db_bind_amount_msat(stmt, in->msat); |
| 3418 | db_bind_int(stmt, in->cltv_expiry); |
| 3419 | db_bind_sha256(stmt, &in->payment_hash); |
| 3420 | |
| 3421 | if (in->preimage) |
| 3422 | db_bind_preimage(stmt, in->preimage); |
| 3423 | else |
| 3424 | db_bind_null(stmt); |
| 3425 | db_bind_int(stmt, in->hstate); |
| 3426 | |
| 3427 | if (!in->shared_secret) |
| 3428 | db_bind_null(stmt); |
| 3429 | else |
| 3430 | db_bind_secret(stmt, in->shared_secret); |
| 3431 | |
| 3432 | db_bind_blob(stmt, in->onion_routing_packet, |
| 3433 | sizeof(in->onion_routing_packet)); |
| 3434 | |
| 3435 | db_bind_timeabs(stmt, in->received_time); |
| 3436 | db_bind_u64(stmt, min_unsigned(chan->next_index[LOCAL]-1, |
| 3437 | chan->next_index[REMOTE]-1)); |
| 3438 | |
| 3439 | db_bind_int(stmt, in->fail_immediate); |