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

Function wallet_channel_insert

wallet/wallet.c:3042–3090  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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