| 3035 | } |
| 3036 | |
| 3037 | void wallet_channel_insert(struct wallet *w, struct channel *chan) |
| 3038 | { |
| 3039 | struct db_stmt *stmt; |
| 3040 | |
| 3041 | assert(chan->dbid != 0); |
| 3042 | assert(chan->unsaved_dbid == 0); |
| 3043 | |
| 3044 | if (chan->peer->dbid == 0) |
| 3045 | wallet_peer_save(w, chan->peer); |
| 3046 | |
| 3047 | /* Insert a stub, that we update, unifies INSERT and UPDATE paths */ |
| 3048 | stmt = db_prepare_v2( |
| 3049 | w->db, SQL("INSERT INTO channels (" |
| 3050 | " peer_id" |
| 3051 | ", first_blocknum" |
| 3052 | ", id" |
| 3053 | ", revocation_basepoint_local" |
| 3054 | ", payment_basepoint_local" |
| 3055 | ", htlc_basepoint_local" |
| 3056 | ", delayed_payment_basepoint_local" |
| 3057 | ", funding_pubkey_local" |
| 3058 | ", require_confirm_inputs_remote" |
| 3059 | ", require_confirm_inputs_local" |
| 3060 | ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); |
| 3061 | db_bind_u64(stmt, chan->peer->dbid); |
| 3062 | db_bind_int(stmt, chan->first_blocknum); |
| 3063 | db_bind_int(stmt, chan->dbid); |
| 3064 | |
| 3065 | db_bind_pubkey(stmt, &chan->local_basepoints.revocation); |
| 3066 | db_bind_pubkey(stmt, &chan->local_basepoints.payment); |
| 3067 | db_bind_pubkey(stmt, &chan->local_basepoints.htlc); |
| 3068 | db_bind_pubkey(stmt, &chan->local_basepoints.delayed_payment); |
| 3069 | db_bind_pubkey(stmt, &chan->local_funding_pubkey); |
| 3070 | db_bind_int(stmt, chan->req_confirmed_ins[REMOTE]); |
| 3071 | db_bind_int(stmt, chan->req_confirmed_ins[LOCAL]); |
| 3072 | |
| 3073 | db_exec_prepared_v2(take(stmt)); |
| 3074 | |
| 3075 | wallet_channel_config_insert(w, &chan->our_config); |
| 3076 | wallet_channel_config_insert(w, &chan->channel_info.their_config); |
| 3077 | if (chan->scid && is_stub_scid(*chan->scid)) { |
| 3078 | wallet_stub_shachain_init(w, &chan->their_shachain); |
| 3079 | } else { |
| 3080 | wallet_shachain_init(w, &chan->their_shachain); |
| 3081 | } |
| 3082 | |
| 3083 | /* Now save path as normal */ |
| 3084 | wallet_channel_save(w, chan); |
| 3085 | } |
| 3086 | |
| 3087 | void wallet_delete_old_htlcs(struct wallet *w) |
| 3088 | { |