| 108 | } |
| 109 | |
| 110 | int main(int argc, char *argv[]) |
| 111 | { |
| 112 | char *config_filename, *base_dir; |
| 113 | char *net_dir, *rpc_filename, *hsmfile, *dbfile; |
| 114 | sqlite3 *sql; |
| 115 | sqlite3_stmt *stmt; |
| 116 | int flags = SQLITE_OPEN_READONLY, dberr; |
| 117 | struct secret *hsm_secret; |
| 118 | bool verbose = false; |
| 119 | size_t num, num_ok; |
| 120 | const tal_t *top_ctx = tal(NULL, char); |
| 121 | |
| 122 | setup_locale(); |
| 123 | wally_init(0); |
| 124 | secp256k1_ctx = wally_get_secp_context(); |
| 125 | |
| 126 | setup_option_allocators(); |
| 127 | |
| 128 | minimal_config_opts(top_ctx, argc, argv, &config_filename, &base_dir, |
| 129 | &net_dir, &rpc_filename); |
| 130 | |
| 131 | opt_register_noarg("-v|--verbose", opt_set_bool, &verbose, |
| 132 | "Print everything"); |
| 133 | |
| 134 | opt_parse(&argc, argv, opt_log_stderr_exit); |
| 135 | |
| 136 | if (argc != 1) |
| 137 | errx(1, "no arguments accepted"); |
| 138 | |
| 139 | hsmfile = path_join(top_ctx, net_dir, "hsm_secret"); |
| 140 | dbfile = path_join(top_ctx, net_dir, "lightningd.sqlite3"); |
| 141 | |
| 142 | dberr = sqlite3_open_v2(dbfile, &sql, flags, NULL); |
| 143 | if (dberr != SQLITE_OK) |
| 144 | errx(1, "failed to open database %s: %s", dbfile, |
| 145 | sqlite3_errstr(dberr)); |
| 146 | |
| 147 | hsm_secret = grab_file_raw(hsmfile, hsmfile); |
| 148 | if (!hsm_secret) |
| 149 | err(1, "failed to read %s", hsmfile); |
| 150 | |
| 151 | dberr = sqlite3_prepare_v2(sql, |
| 152 | "SELECT channels.id, peers.node_id, channels.short_channel_id, channels.funding_tx_id, channels.funding_tx_outnum, channels.funding_satoshi, channels.fundingkey_remote, utxoset.scriptpubkey, utxoset.satoshis FROM channels INNER JOIN peers ON channels.peer_id = peers.id LEFT JOIN utxoset on channels.funding_tx_id = utxoset.txid AND channels.funding_tx_outnum = utxoset.outnum;", -1, &stmt, NULL); /* Raw: false positive! */ |
| 153 | if (dberr != SQLITE_OK) |
| 154 | errx(1, "failed to prepare query for %s: %s", dbfile, |
| 155 | sqlite3_errstr(dberr)); |
| 156 | |
| 157 | num = num_ok = 0; |
| 158 | while ((dberr = sqlite3_step(stmt)) == SQLITE_ROW) { |
| 159 | u64 dbid; |
| 160 | struct node_id peer_id; |
| 161 | struct short_channel_id scid; |
| 162 | struct bitcoin_txid funding_txid; |
| 163 | u32 funding_outnum; |
| 164 | u64 funding_satoshis; |
| 165 | struct pubkey remote_fundingkey, local_fundingkey; |
| 166 | u8 *scriptpubkey; |
| 167 | u64 utxo_satoshis; |
nothing calls this directly
no test coverage detected