| 92 | } |
| 93 | |
| 94 | int main(int argc, char *argv[]) |
| 95 | { |
| 96 | u8 version; |
| 97 | beint16_t be_inlen; |
| 98 | struct amount_sat sat; |
| 99 | bool verbose = false; |
| 100 | char *infile = NULL, *outfile = NULL, *csvfile = NULL, *csat = NULL; |
| 101 | int infd, outfd, scidi = 0, channels = 0, nodes = 0, updates = 0; |
| 102 | struct scidsat *scidsats = NULL; |
| 103 | const u8 *last_announce = NULL; |
| 104 | unsigned max = -1U; |
| 105 | |
| 106 | setup_locale(); |
| 107 | |
| 108 | opt_register_noarg("--verbose|-v", opt_set_bool, &verbose, |
| 109 | "Print progress to stderr"); |
| 110 | opt_register_arg("--output|-o", opt_set_charp, NULL, &outfile, |
| 111 | "Send output to this file instead of stdout"); |
| 112 | opt_register_arg("--input|-i", opt_set_charp, NULL, &infile, |
| 113 | "Read input from this file instead of stdin"); |
| 114 | opt_register_arg("--csv", opt_set_charp, NULL, &csvfile, |
| 115 | "Input for 'scid, satshis' csv"); |
| 116 | opt_register_arg("--sat", opt_set_charp, NULL, &csat, |
| 117 | "default satoshi value if --csv flag not present"); |
| 118 | opt_register_arg("--max", opt_set_uintval, opt_show_uintval, &max, |
| 119 | "maximum number of messages to read"); |
| 120 | opt_register_noarg("--help|-h", opt_usage_and_exit, |
| 121 | "Create gossip store, from be16 / input messages", |
| 122 | "Print this message."); |
| 123 | |
| 124 | opt_parse(&argc, argv, opt_log_stderr_exit); |
| 125 | |
| 126 | |
| 127 | if (csvfile && !csat) { |
| 128 | FILE *scidf; |
| 129 | scidf = fopen(csvfile, "r"); |
| 130 | if (!scidf) |
| 131 | err(1, "opening %s", csvfile); |
| 132 | scidsats = load_csv_file(scidf); |
| 133 | fclose(scidf); |
| 134 | } else if (csat && !csvfile) { |
| 135 | if (!parse_amount_sat(&sat, csat, strlen(csat))) { |
| 136 | errx(1, "Invalid satoshi amount %s", csat); |
| 137 | } |
| 138 | } |
| 139 | else { |
| 140 | err(1, "must contain either --sat xor --csv"); |
| 141 | } |
| 142 | |
| 143 | if (infile) { |
| 144 | infd = open(infile, O_RDONLY); |
| 145 | if (infd < 0) |
| 146 | err(1, "opening %s", infile); |
| 147 | } |
| 148 | else |
| 149 | infd = STDIN_FILENO; |
| 150 | |
| 151 | if (outfile) { |
nothing calls this directly
no test coverage detected