MCPcopy Create free account
hub / github.com/ElementsProject/lightning / wallet_channel_insert

Function wallet_channel_insert

wallet/wallet.c:3019–3067  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3017}
3018
3019void wallet_channel_insert(struct wallet *w, struct channel *chan)
3020{
3021 struct db_stmt *stmt;
3022
3023 assert(chan->dbid != 0);
3024 assert(chan->unsaved_dbid == 0);
3025
3026 if (chan->peer->dbid == 0)
3027 wallet_peer_save(w, chan->peer);
3028
3029 /* Insert a stub, that we update, unifies INSERT and UPDATE paths */
3030 stmt = db_prepare_v2(
3031 w->db, SQL("INSERT INTO channels ("
3032 " peer_id"
3033 ", first_blocknum"
3034 ", id"
3035 ", revocation_basepoint_local"
3036 ", payment_basepoint_local"
3037 ", htlc_basepoint_local"
3038 ", delayed_payment_basepoint_local"
3039 ", funding_pubkey_local"
3040 ", require_confirm_inputs_remote"
3041 ", require_confirm_inputs_local"
3042 ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
3043 db_bind_u64(stmt, chan->peer->dbid);
3044 db_bind_int(stmt, chan->first_blocknum);
3045 db_bind_int(stmt, chan->dbid);
3046
3047 db_bind_pubkey(stmt, &chan->local_basepoints.revocation);
3048 db_bind_pubkey(stmt, &chan->local_basepoints.payment);
3049 db_bind_pubkey(stmt, &chan->local_basepoints.htlc);
3050 db_bind_pubkey(stmt, &chan->local_basepoints.delayed_payment);
3051 db_bind_pubkey(stmt, &chan->local_funding_pubkey);
3052 db_bind_int(stmt, chan->req_confirmed_ins[REMOTE]);
3053 db_bind_int(stmt, chan->req_confirmed_ins[LOCAL]);
3054
3055 db_exec_prepared_v2(take(stmt));
3056
3057 wallet_channel_config_insert(w, &chan->our_config);
3058 wallet_channel_config_insert(w, &chan->channel_info.their_config);
3059 if (chan->scid && is_stub_scid(*chan->scid)) {
3060 wallet_stub_shachain_init(w, &chan->their_shachain);
3061 } else {
3062 wallet_shachain_init(w, &chan->their_shachain);
3063 }
3064
3065 /* Now save path as normal */
3066 wallet_channel_save(w, chan);
3067}
3068
3069void wallet_delete_old_htlcs(struct wallet *w)
3070{

Callers 5

test_channel_crudFunction · 0.85
wallet_commit_channelFunction · 0.85
wallet_commit_channelFunction · 0.85
json_recoverchannelFunction · 0.85

Calls 10

wallet_peer_saveFunction · 0.85
db_bind_u64Function · 0.85
db_bind_intFunction · 0.85
db_bind_pubkeyFunction · 0.85
db_exec_prepared_v2Function · 0.85
is_stub_scidFunction · 0.85
wallet_shachain_initFunction · 0.85
wallet_channel_saveFunction · 0.70

Tested by 2

test_channel_crudFunction · 0.68