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

Function migrate_setup_coinmoves

wallet/wallet.c:7726–7854  ·  view source on GitHub ↗

An existing node without accounting. Fill in what we have so far. */

Source from the content-addressed store, hash-verified

7724
7725/* An existing node without accounting. Fill in what we have so far. */
7726void migrate_setup_coinmoves(struct lightningd *ld, struct db *db)
7727{
7728 struct utxo **utxos = db_get_unspent_utxos(tmpctx, db);
7729 struct db_stmt *stmt;
7730 u64 base_timestamp = clock_time().ts.tv_sec - 2;
7731
7732 for (size_t i = 0; i < tal_count(utxos); i++) {
7733 struct chain_coin_mvt *mvt;
7734
7735 /* Only confirmed ones */
7736 if (!utxos[i]->blockheight)
7737 continue;
7738 mvt = new_coin_wallet_deposit(tmpctx,
7739 &utxos[i]->outpoint,
7740 *utxos[i]->blockheight,
7741 utxos[i]->amount,
7742 mk_mvt_tags(MVT_DEPOSIT));
7743 insert_chain_mvt(ld, db, mvt);
7744 }
7745
7746 /* Now channels. We create the open event, and then pushed/leased,
7747 * the finally fixup with a journal entry. */
7748 stmt = db_prepare_v2(db, SQL("SELECT"
7749 " p.node_id"
7750 ", scid"
7751 ", full_channel_id"
7752 ", funding_tx_id"
7753 ", funding_tx_outnum"
7754 ", funder"
7755 ", push_msatoshi"
7756 ", lease_commit_sig"
7757 ", funding_satoshi"
7758 ", our_funding_satoshi"
7759 ", msatoshi_local"
7760 " FROM channels c"
7761 " JOIN peers p ON c.peer_id = p.id"
7762 " WHERE c.scid IS NOT NULL"
7763 " AND c.state != ?;"));
7764 db_bind_int(stmt, CLOSED);
7765 db_query_prepared(stmt);
7766
7767 while (db_step(stmt)) {
7768 struct chain_coin_mvt *mvt;
7769 struct bitcoin_outpoint funding;
7770 struct channel_id cid;
7771 struct node_id peerid;
7772 struct amount_sat funding_sat, our_funding_sat;
7773 struct amount_msat start_balance, our_msat, push_msat;
7774 struct short_channel_id scid;
7775 enum side opener;
7776 bool is_leased;
7777
7778 db_col_node_id(stmt, "p.node_id", &peerid);
7779 scid = db_col_short_channel_id(stmt, "scid");
7780 db_col_txid(stmt, "funding_tx_id", &funding.txid);
7781 funding.n = db_col_int(stmt, "funding_tx_outnum");
7782 db_col_channel_id(stmt, "full_channel_id", &cid);
7783 opener = db_col_int(stmt, "funder");

Callers 1

migrate_from_account_dbFunction · 0.85

Calls 15

db_get_unspent_utxosFunction · 0.85
clock_timeFunction · 0.85
new_coin_wallet_depositFunction · 0.85
insert_chain_mvtFunction · 0.85
db_bind_intFunction · 0.85
db_query_preparedFunction · 0.85
db_stepFunction · 0.85
db_col_node_idFunction · 0.85
db_col_short_channel_idFunction · 0.85
db_col_txidFunction · 0.85
db_col_intFunction · 0.85
db_col_channel_idFunction · 0.85

Tested by

no test coverage detected