Maybe<uint64_t> getTransferAmount() { while (true) { std::string stringAmount; std::cout << std::endl << InformationMsg("How much WTIP do you want to send?: "); std::getline(std::cin, stringAmount); if (stringAmount == "cancel") { return Nothing<uint64_t>(); } uint64_t amount; if (parseAmount(stringAmount)) { parseAmount(stringAmount, amount); return Just<uint64_t>(amount); } } }
Maybe<uint64_t> getFee() { while (true) { std::string stringAmount; std::cout << std::endl << InformationMsg("What fee do you want to use?") << std::endl << "Hit enter for the default fee of 0.1 WTIP: "; std::getline(std::cin, stringAmount); if (stringAmount == "") { return Just<uint64_t>(CryptoNote::parameters::MINIMUM_FEE); } if (stringAmount == "cancel") { return Nothing<uint64_t>(); } uint64_t amount; if (parseFee(stringAmount)) { parseAmount(stringAmount, amount); return Just<uint64_t>(amount); } } }
///------------------------------------------------------------- bool CCommandLineParser::parseArgv( const char *const argv[ ] ) ///------------------------------------------------------------- { return parsePath( argv ) && parseAmount( argv ) && parseMp3FileName( argv ); }
PaymentRequest::PaymentRequest(const QUrl& url) { if (url.scheme().compare(VALID_URL_SCHEME, Qt::CaseInsensitive) != 0) { throw std::runtime_error(QObject::tr("Invalid payment request URL scheme").toStdString()); } QString path = url.path(); address_ = path.section(';', 0, 0); hasAddress_ = !address_.isEmpty(); if (!hasAddress_) { throw std::runtime_error(QObject::tr("Payment address is missing").toStdString()); } QStringList versionParts = path.section(';', 1).split('='); hasVersion_ = versionParts.count() != 1; if (hasVersion_) { if (versionParts.count() != 2 || versionParts[0] != "version") { throw std::runtime_error(QObject::tr("Payment version is invalid").toStdString()); } version_ = versionParts[1]; } bytes_t payload; unsigned int addressVersion; if (!fromBase58Check(address_.toStdString(), payload, addressVersion, BASE58_CHARS) || payload.size() != ADDRESS_DATA_SIZE || [&]() { for (int i = 0; i < VALID_VERSION_COUNT; i++) { if (addressVersion == VALID_ADDRESS_VERSIONS[i]) return false; } return true; }()) { throw std::runtime_error(QObject::tr("Invalid payment address").toStdString()); } QUrlQuery query(url); hasValue_ = query.hasQueryItem("amount"); if (hasValue_) value_ = parseAmount(query.queryItemValue("amount")); hasLabel_ = query.hasQueryItem("label"); if (hasLabel_) label_ = query.queryItemValue("label"); hasMessage_ = query.hasQueryItem("message"); if (hasMessage_) message_ = query.queryItemValue("message"); hasSend_ = query.hasQueryItem("send"); if (hasSend_) send_ = query.queryItemValue("send"); }
bool parseAmount(std::string amountString) { uint64_t amount; if (!parseAmount(amountString, amount)) { std::cout << WarningMsg("Failed to parse amount! Ensure you entered " "the value correctly.") << std::endl << "Please note, the minimum you can send is 0.00000001 WTIP," << std::endl << "and you can only use 8 decimal places." << std::endl; return false; } return true; }
bool parseFee(std::string feeString) { uint64_t fee; if (!parseAmount(feeString, fee)) { std::cout << WarningMsg("Failed to parse fee! Ensure you entered the " "value correctly.") << std::endl << "Please note, you can only use 2 decimal places." << std::endl; return false; } else if (fee < CryptoNote::parameters::MINIMUM_FEE) { std::cout << WarningMsg("Fee must be at least 0.1 WTIP!") << std::endl; return false; } return true; }
void reserveProof(std::shared_ptr<WalletInfo> walletInfo, bool viewWallet) { if (viewWallet) { std::cout << WarningMsg("This is tracking wallet. ") << WarningMsg("The reserve proof can be generated ") << WarningMsg("only by a full wallet.") << std::endl; return; } uint64_t amount; uint64_t actualBalance = walletInfo->wallet.getActualBalance(); while (true) { std::cout << InformationMsg("Enter amount to prove ") << InformationMsg("or type ") << "\"all\" " << InformationMsg("if you want to prove all balance: "); std::string amtStr; std::getline(std::cin, amtStr); if (amtStr == "all") { amount = actualBalance; break; } if (parseAmount(amtStr, amount)) { if (amount > actualBalance) { std::cout << WarningMsg("Amount is bigger than ") << WarningMsg("actual balance ") << WarningMsg(formatAmount(actualBalance)) << std::endl; } else { break; } } if (std::cin.fail() || std::cin.eof()) { std::cin.clear(); break; } } std::string message; while (true) { std::cout << InformationMsg("Enter optional challenge message: "); std::getline(std::cin, message); boost::algorithm::trim(message); if (message == "") { break; } if (std::cin.fail() || std::cin.eof()) { std::cin.clear(); break; } } try { const std::string sig = walletInfo->wallet.getReserveProof(amount, walletInfo->walletAddress, message.empty() ? "" : message); std::string fileName; while (true) { std::cout << InformationMsg("Enter file name ") << InformationMsg("where to save your proof: "); std::getline(std::cin, fileName); boost::algorithm::trim(fileName); if (boost::filesystem::portable_name(fileName)) { break; } else { std::cout << WarningMsg("Enter valid file name") << std::endl; } if (std::cin.fail() || std::cin.eof()) { std::cin.clear(); break; } } fileName += ".txt"; boost::system::error_code ec; if (boost::filesystem::exists(fileName, ec)) { boost::filesystem::remove(fileName, ec); } std::ofstream proofFile(fileName, std::ios::out | std::ios::trunc | std::ios::binary); if (!proofFile.good()) { std::cout << WarningMsg("Failed to save reserve proof to file") << std::endl; return; } proofFile << sig; std::cout << SuccessMsg("Proof signature saved to file: ") << SuccessMsg(fileName) << std::endl; } catch (const std::exception &e) { std::cout << WarningMsg("Failed to get reserve proof: ") << WarningMsg(e.what()) << std::endl; } }
void transfer(std::shared_ptr<WalletInfo> walletInfo, std::vector<std::string> args) { uint16_t mixin; std::string address; uint64_t amount; uint64_t fee = CryptoNote::parameters::MINIMUM_FEE; std::string extra; /* Check we have enough args for the default required parameters */ if (args.size() >= 3) { if (parseMixin(args[0]) && parseAddress(args[1]) && parseAmount(args[2])) { mixin = std::stoi(args[0]); address = args[1]; parseAmount(args[2], amount); } else { return; } } else { std::cout << WarningMsg("Not enough arguments given!") << std::endl << "Try running just " << SuggestionMsg("transfer") << " for a walk through guide to transferring." << std::endl; return; } for (size_t i = 0; i < args.size(); i++) { if (args[i] == "-f") { if (i+1 < args.size()) { if (parseFee(args[i+1])) { parseAmount(args[i+1], fee); } else { return; } } else { std::cout << WarningMsg("Fee flag given but no fee follows!") << std::endl; return; } } else if (args[i] == "-p") { if (i+1 < args.size()) { std::vector<uint8_t> extraVec; std::string extraString; /* Convert the payment ID into an "extra" */ if (!CryptoNote::createTxExtraWithPaymentId(args[i+1], extraVec)) { std::cout << WarningMsg("Failed to parse payment ID! " "Payment ID's are 64 character " "hexadecimal strings.") << std::endl; return; } else { /* Then convert the "extra" back into a string so we can pass the argument that walletgreen expects. Note this string is not the same as the original paymentID string! */ for (auto i : extraVec) { extraString += static_cast<char>(i); } } extra = extraString; } else { std::cout << WarningMsg("Payment ID flag given but no payment " "ID follows!") << std::endl; return; } } } doTransfer(mixin, address, amount, fee, extra, walletInfo); }