void transfer(std::shared_ptr<WalletInfo> walletInfo) { std::cout << InformationMsg("Note: You can type cancel at any time to " "cancel the transaction") << std::endl << std::endl; uint64_t balance = walletInfo->wallet.getActualBalance(); auto maybeAddress = getDestinationAddress(); if (!maybeAddress.isJust) { std::cout << WarningMsg("Cancelling transaction.") << std::endl; return; } std::string address = maybeAddress.x; auto maybeAmount = getTransferAmount(); if (!maybeAmount.isJust) { std::cout << WarningMsg("Cancelling transaction.") << std::endl; return; } uint64_t amount = maybeAmount.x; if (balance < amount) { std::cout << WarningMsg("You don't have enough funds to cover this " "transaction!") << std::endl << InformationMsg("Funds needed: " + formatAmount(amount)) << std::endl << SuccessMsg("Funds available: " + formatAmount(balance)) << std::endl; return; } auto maybeFee = getFee(); if (!maybeFee.isJust) { std::cout << WarningMsg("Cancelling transaction.") << std::endl; return; } uint64_t fee = maybeFee.x; if (balance < amount + fee) { std::cout << WarningMsg("You don't have enough funds to cover this " "transaction!") << std::endl << InformationMsg("Funds needed: " + formatAmount(amount + fee)) << std::endl << SuccessMsg("Funds available: " + formatAmount(balance)) << std::endl; return; } auto maybeMixin = getMixin(); if (!maybeMixin.isJust) { std::cout << WarningMsg("Cancelling transaction.") << std::endl; return; } uint16_t mixin = maybeMixin.x; auto maybeExtra = getPaymentID(); if (!maybeExtra.isJust) { std::cout << WarningMsg("Cancelling transaction.") << std::endl; return; } std::string extra = maybeExtra.x; doTransfer(mixin, address, amount, fee, extra, walletInfo); }
string Packet::toString() const{ // Serialize this object for the network string delimiter = "\n"; stringstream serialization; serialization << getType(); serialization << delimiter; struct tm *nowtm; char tmbuf[64] ; nowtm = localtime(&timeSent); strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", nowtm); string timeString (tmbuf); serialization << timeString; serialization << delimiter; serialization << getLifeTime(); serialization << delimiter; serialization << getPacketNumber(); serialization << delimiter; serialization << getHopCount(); serialization << delimiter; serialization << getSourceAddress(); serialization << delimiter; serialization << getDestinationAddress(); serialization << delimiter; serialization << getPayload(); return serialization.str(); }