| 3460 | } |
| 3461 | |
| 3462 | void wallet_htlc_save_out(struct wallet *wallet, |
| 3463 | const struct channel *chan, |
| 3464 | struct htlc_out *out) |
| 3465 | { |
| 3466 | struct db_stmt *stmt; |
| 3467 | |
| 3468 | /* We absolutely need the incoming HTLC to be persisted before |
| 3469 | * we can persist it's dependent */ |
| 3470 | assert(out->in == NULL || out->in->dbid != 0); |
| 3471 | |
| 3472 | stmt = db_prepare_v2( |
| 3473 | wallet->db, |
| 3474 | SQL("INSERT INTO channel_htlcs (" |
| 3475 | " id," |
| 3476 | " channel_id," |
| 3477 | " channel_htlc_id," |
| 3478 | " direction," |
| 3479 | " origin_htlc," |
| 3480 | " msatoshi," |
| 3481 | " cltv_expiry," |
| 3482 | " payment_hash," |
| 3483 | " payment_key," |
| 3484 | " hstate," |
| 3485 | " routing_onion," |
| 3486 | " malformed_onion," |
| 3487 | " partid," |
| 3488 | " groupid," |
| 3489 | " fees_msat," |
| 3490 | " min_commit_num" |
| 3491 | ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?, ?);")); |
| 3492 | |
| 3493 | out->dbid = htlcs_index_created(wallet->ld, |
| 3494 | out->key.id, |
| 3495 | chan, |
| 3496 | &out->payment_hash, |
| 3497 | LOCAL, |
| 3498 | out->cltv_expiry, |
| 3499 | out->msat, |
| 3500 | out->hstate); |
| 3501 | db_bind_u64(stmt, out->dbid); |
| 3502 | db_bind_u64(stmt, chan->dbid); |
| 3503 | db_bind_u64(stmt, out->key.id); |
| 3504 | db_bind_int(stmt, DIRECTION_OUTGOING); |
| 3505 | if (out->in) |
| 3506 | db_bind_u64(stmt, out->in->dbid); |
| 3507 | else |
| 3508 | db_bind_null(stmt); |
| 3509 | db_bind_amount_msat(stmt, out->msat); |
| 3510 | db_bind_int(stmt, out->cltv_expiry); |
| 3511 | db_bind_sha256(stmt, &out->payment_hash); |
| 3512 | |
| 3513 | if (out->preimage) |
| 3514 | db_bind_preimage(stmt, out->preimage); |
| 3515 | else |
| 3516 | db_bind_null(stmt); |
| 3517 | db_bind_int(stmt, out->hstate); |
| 3518 | |
| 3519 | db_bind_blob(stmt, out->onion_routing_packet, |