MCPcopy Create free account
hub / github.com/QuipNetwork/cpp-sdk / main

Function main

src/main.cpp:156–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156int main(int argc, char *argv[]) {
157 // If PRIVATE_KEY is not set, try to load from ./ethereum-sdk/.env
158 if (std::getenv("PRIVATE_KEY") == nullptr) {
159 loadEnvFromFile("./ethereum-sdk/.env");
160 }
161 if (std::getenv("PRIVATE_KEY") == nullptr) {
162 std::cerr << "Error: PRIVATE_KEY environment variable not set.\n"
163 "Please create ./ethereum-sdk/.env with a PRIVATE_KEY entry, "
164 "or export PRIVATE_KEY manually."
165 << std::endl;
166 return 1;
167 }
168
169 if (argc < 2) {
170 std::cerr << "Usage: " << argv[0]
171 << " [--rpc-url <url>] [--contract-address <address>] <command> "
172 "[args...]"
173 << std::endl;
174 std::cerr << "Default RPC URL: http://localhost:8545" << std::endl;
175 std::cerr << "Use --help for more information" << std::endl;
176 return 1;
177 }
178
179 // Check for help flag first
180 if (std::string(argv[1]) == "--help") {
181 printHelp(argv[0]);
182 return 0;
183 }
184
185 // Default values
186 std::string rpc_url = "http://localhost:8545";
187 std::string contract_address = "";
188 std::vector<std::string> command_args;
189
190 // Parse command line arguments
191 for (int i = 1; i < argc; ++i) {
192 std::string arg = argv[i];
193
194 if (arg == "--rpc-url" && i + 1 < argc) {
195 rpc_url = argv[++i];
196 } else if (arg == "--contract-address" && i + 1 < argc) {
197 contract_address = argv[++i];
198 } else if (arg == "--help") {
199 printHelp(argv[0]);
200 return 0;
201 } else if (arg.substr(0, 2) == "--") {
202 std::cerr << "Unknown option: " << arg << std::endl;
203 std::cerr << "Use --help for usage information" << std::endl;
204 return 1;
205 } else {
206 // Everything else is part of the command
207 for (int j = i; j < argc; ++j) {
208 command_args.push_back(argv[j]);
209 }
210 break;
211 }
212 }
213

Callers

nothing calls this directly

Calls 3

loadEnvFromFileFunction · 0.85
printHelpFunction · 0.85
executeMethod · 0.80

Tested by

no test coverage detected