An existing node without accounting. Fill in what we have so far. */
| 7687 | |
| 7688 | /* An existing node without accounting. Fill in what we have so far. */ |
| 7689 | void migrate_setup_coinmoves(struct lightningd *ld, struct db *db) |
| 7690 | { |
| 7691 | struct utxo **utxos = db_get_unspent_utxos(tmpctx, db); |
| 7692 | struct db_stmt *stmt; |
| 7693 | u64 base_timestamp = clock_time().ts.tv_sec - 2; |
| 7694 | |
| 7695 | for (size_t i = 0; i < tal_count(utxos); i++) { |
| 7696 | struct chain_coin_mvt *mvt; |
| 7697 | |
| 7698 | /* Only confirmed ones */ |
| 7699 | if (!utxos[i]->blockheight) |
| 7700 | continue; |
| 7701 | mvt = new_coin_wallet_deposit(tmpctx, |
| 7702 | &utxos[i]->outpoint, |
| 7703 | *utxos[i]->blockheight, |
| 7704 | utxos[i]->amount, |
| 7705 | mk_mvt_tags(MVT_DEPOSIT)); |
| 7706 | insert_chain_mvt(ld, db, mvt); |
| 7707 | } |
| 7708 | |
| 7709 | /* Now channels. We create the open event, and then pushed/leased, |
| 7710 | * the finally fixup with a journal entry. */ |
| 7711 | stmt = db_prepare_v2(db, SQL("SELECT" |
| 7712 | " p.node_id" |
| 7713 | ", scid" |
| 7714 | ", full_channel_id" |
| 7715 | ", funding_tx_id" |
| 7716 | ", funding_tx_outnum" |
| 7717 | ", funder" |
| 7718 | ", push_msatoshi" |
| 7719 | ", lease_commit_sig" |
| 7720 | ", funding_satoshi" |
| 7721 | ", our_funding_satoshi" |
| 7722 | ", msatoshi_local" |
| 7723 | " FROM channels c" |
| 7724 | " JOIN peers p ON c.peer_id = p.id" |
| 7725 | " WHERE c.scid IS NOT NULL" |
| 7726 | " AND c.state != ?;")); |
| 7727 | db_bind_int(stmt, CLOSED); |
| 7728 | db_query_prepared(stmt); |
| 7729 | |
| 7730 | while (db_step(stmt)) { |
| 7731 | struct chain_coin_mvt *mvt; |
| 7732 | struct bitcoin_outpoint funding; |
| 7733 | struct channel_id cid; |
| 7734 | struct node_id peerid; |
| 7735 | struct amount_sat funding_sat, our_funding_sat; |
| 7736 | struct amount_msat start_balance, our_msat, push_msat; |
| 7737 | struct short_channel_id scid; |
| 7738 | enum side opener; |
| 7739 | bool is_leased; |
| 7740 | |
| 7741 | db_col_node_id(stmt, "p.node_id", &peerid); |
| 7742 | scid = db_col_short_channel_id(stmt, "scid"); |
| 7743 | db_col_txid(stmt, "funding_tx_id", &funding.txid); |
| 7744 | funding.n = db_col_int(stmt, "funding_tx_outnum"); |
| 7745 | db_col_channel_id(stmt, "full_channel_id", &cid); |
| 7746 | opener = db_col_int(stmt, "funder"); |
no test coverage detected