| 2166 | } |
| 2167 | |
| 2168 | void wallet_channel_insert(struct wallet *w, struct channel *chan) |
| 2169 | { |
| 2170 | struct db_stmt *stmt; |
| 2171 | |
| 2172 | assert(chan->dbid != 0); |
| 2173 | assert(chan->unsaved_dbid == 0); |
| 2174 | |
| 2175 | if (chan->peer->dbid == 0) |
| 2176 | wallet_peer_save(w, chan->peer); |
| 2177 | |
| 2178 | /* Insert a stub, that we update, unifies INSERT and UPDATE paths */ |
| 2179 | stmt = db_prepare_v2( |
| 2180 | w->db, SQL("INSERT INTO channels (" |
| 2181 | " peer_id" |
| 2182 | ", first_blocknum" |
| 2183 | ", id" |
| 2184 | ", revocation_basepoint_local" |
| 2185 | ", payment_basepoint_local" |
| 2186 | ", htlc_basepoint_local" |
| 2187 | ", delayed_payment_basepoint_local" |
| 2188 | ", funding_pubkey_local" |
| 2189 | ") VALUES (?, ?, ?, ?, ?, ?, ?, ?);")); |
| 2190 | db_bind_u64(stmt, 0, chan->peer->dbid); |
| 2191 | db_bind_int(stmt, 1, chan->first_blocknum); |
| 2192 | db_bind_int(stmt, 2, chan->dbid); |
| 2193 | |
| 2194 | db_bind_pubkey(stmt, 3, &chan->local_basepoints.revocation); |
| 2195 | db_bind_pubkey(stmt, 4, &chan->local_basepoints.payment); |
| 2196 | db_bind_pubkey(stmt, 5, &chan->local_basepoints.htlc); |
| 2197 | db_bind_pubkey(stmt, 6, &chan->local_basepoints.delayed_payment); |
| 2198 | db_bind_pubkey(stmt, 7, &chan->local_funding_pubkey); |
| 2199 | |
| 2200 | db_exec_prepared_v2(take(stmt)); |
| 2201 | |
| 2202 | wallet_channel_config_insert(w, &chan->our_config); |
| 2203 | wallet_channel_config_insert(w, &chan->channel_info.their_config); |
| 2204 | wallet_shachain_init(w, &chan->their_shachain); |
| 2205 | |
| 2206 | /* Now save path as normal */ |
| 2207 | wallet_channel_save(w, chan); |
| 2208 | } |
| 2209 | |
| 2210 | void wallet_channel_close(struct wallet *w, u64 wallet_id) |
| 2211 | { |