| 333 | } |
| 334 | |
| 335 | bool CLI::handleTransfer(const std::vector<std::string> &args) { |
| 336 | if (args.size() != 4) { |
| 337 | std::cerr << "Usage: transfer <quantum_secret_hex> <quip_wallet_address> " |
| 338 | "<to_address> <amount>" |
| 339 | << std::endl; |
| 340 | return false; |
| 341 | } |
| 342 | |
| 343 | try { |
| 344 | // 1. Parse Arguments |
| 345 | std::string quantum_secret_hex = args[0]; |
| 346 | if (quantum_secret_hex.front() == '"' && quantum_secret_hex.back() == '"') { |
| 347 | quantum_secret_hex = |
| 348 | quantum_secret_hex.substr(1, quantum_secret_hex.size() - 2); |
| 349 | } |
| 350 | std::array<uint8_t, 32> quantum_secret = fromHex32(quantum_secret_hex); |
| 351 | |
| 352 | std::string quip_wallet_address_str = args[1]; |
| 353 | if (quip_wallet_address_str.front() == '"' && |
| 354 | quip_wallet_address_str.back() == '"') { |
| 355 | quip_wallet_address_str = |
| 356 | quip_wallet_address_str.substr(1, quip_wallet_address_str.size() - 2); |
| 357 | } |
| 358 | quip_wallet_address_str = toChecksumAddress(quip_wallet_address_str); |
| 359 | Address quip_wallet_address = parseAddress(quip_wallet_address_str); |
| 360 | |
| 361 | std::string to_address_str = args[2]; |
| 362 | if (to_address_str.front() == '"' && to_address_str.back() == '"') { |
| 363 | to_address_str = to_address_str.substr(1, to_address_str.size() - 2); |
| 364 | } |
| 365 | to_address_str = toChecksumAddress(to_address_str); |
| 366 | Address to_address = parseAddress(to_address_str); |
| 367 | |
| 368 | std::string amount_str = args[3]; |
| 369 | if (amount_str.front() == '"' && amount_str.back() == '"') { |
| 370 | amount_str = amount_str.substr(1, amount_str.size() - 2); |
| 371 | } |
| 372 | Amount amount = std::stoull(amount_str); |
| 373 | |
| 374 | // 2. Find the correct Vault |
| 375 | std::string private_key_env = |
| 376 | getenv("PRIVATE_KEY") ? getenv("PRIVATE_KEY") : ""; |
| 377 | if (private_key_env.empty()) { |
| 378 | throw std::runtime_error("PRIVATE_KEY environment variable not set"); |
| 379 | } |
| 380 | Address classical_pubkey = deriveClassicalPublicKey(private_key_env); |
| 381 | classical_pubkey = toChecksumAddress(classical_pubkey); |
| 382 | |
| 383 | auto vaults = factory_->getVaults(classical_pubkey); |
| 384 | |
| 385 | auto it = |
| 386 | std::find_if(vaults.begin(), vaults.end(), [&](const auto &vault) { |
| 387 | return toChecksumAddress(vault.classical_address) == toChecksumAddress(quip_wallet_address); |
| 388 | }); |
| 389 | |
| 390 | if (it == vaults.end()) { |
| 391 | throw std::runtime_error( |
| 392 | "Could not find a vault for the given wallet address."); |
nothing calls this directly
no test coverage detected