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

Function main

devtools/checkchannels.c:110–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110int main(int argc, char *argv[])
111{
112 char *config_dir, *net_dir, *config_filename, *rpc_filename, *hsmfile, *dbfile;
113 sqlite3 *sql;
114 sqlite3_stmt *stmt;
115 int flags = SQLITE_OPEN_READONLY, dberr;
116 struct secret *hsm_secret;
117 bool verbose = false;
118 size_t num, num_ok;
119 const tal_t *top_ctx = tal(NULL, char);
120
121 setup_locale();
122 wally_init(0);
123 secp256k1_ctx = wally_get_secp_context();
124
125 setup_option_allocators();
126
127 initial_config_opts(top_ctx, argc, argv,
128 &config_filename, &config_dir, &net_dir,
129 &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 if (argc != 1)
136 errx(1, "no arguments accepted");
137
138 hsmfile = path_join(top_ctx, net_dir, "hsm_secret");
139 dbfile = path_join(top_ctx, net_dir, "lightningd.sqlite3");
140
141 dberr = sqlite3_open_v2(dbfile, &sql, flags, NULL);
142 if (dberr != SQLITE_OK)
143 errx(1, "failed to open database %s: %s", dbfile,
144 sqlite3_errstr(dberr));
145
146 hsm_secret = grab_file(hsmfile, hsmfile);
147 if (!hsm_secret)
148 err(1, "failed to read %s", hsmfile);
149
150 dberr = sqlite3_prepare_v2(sql,
151 "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! */
152 if (dberr != SQLITE_OK)
153 errx(1, "failed to prepare query for %s: %s", dbfile,
154 sqlite3_errstr(dberr));
155
156 num = num_ok = 0;
157 while ((dberr = sqlite3_step(stmt)) == SQLITE_ROW) {
158 u64 dbid;
159 struct node_id peer_id;
160 struct short_channel_id scid;
161 struct bitcoin_txid funding_txid;
162 u32 funding_outnum;
163 u64 funding_satoshis;
164 struct pubkey remote_fundingkey, local_fundingkey;
165 u8 *scriptpubkey;
166 u64 utxo_satoshis;
167 const tal_t *ctx = tal(dbfile, char);

Callers

nothing calls this directly

Calls 15

setup_localeFunction · 0.85
setup_option_allocatorsFunction · 0.85
initial_config_optsFunction · 0.85
opt_parseFunction · 0.85
errxFunction · 0.85
path_joinFunction · 0.85
grab_fileFunction · 0.85
errFunction · 0.85
copy_columnFunction · 0.85
bitcoin_txid_to_hexFunction · 0.85
abortFunction · 0.85

Tested by

no test coverage detected