Exemplo n.º 1
0
void printHeights(uint32_t localHeight, uint32_t remoteHeight,
	uint32_t walletHeight)
{
	/* This is the height that the wallet has been scanned to. The blockchain
	   can be fully updated, but we have to walk the chain to find our
	   transactions, and this number indicates that progress. */
	std::cout << "Wallet blockchain height: ";

	/* Small buffer because wallet height doesn't update instantly like node
	   height does */
	if (walletHeight + 1000 > remoteHeight)
	{
		std::cout << SuccessMsg(std::to_string(walletHeight));
	}
	else
	{
		std::cout << WarningMsg(std::to_string(walletHeight));
	}

	std::cout << std::endl << "Local blockchain height: ";

	if (localHeight == remoteHeight)
	{
		std::cout << SuccessMsg(std::to_string(localHeight));
	}
	else
	{
		std::cout << WarningMsg(std::to_string(localHeight));
	}

	std::cout << std::endl << "Network blockchain height: "
		<< SuccessMsg(std::to_string(remoteHeight)) << std::endl;
}
Exemplo n.º 2
0
void printSyncStatus(uint32_t localHeight, uint32_t remoteHeight,
	uint32_t walletHeight)
{
	std::string networkSyncPercentage
		= Common::get_sync_percentage(localHeight, remoteHeight) + "%";

	std::string walletSyncPercentage
		= Common::get_sync_percentage(walletHeight, remoteHeight) + "%";

	std::cout << "Network sync status: ";

	if (localHeight == remoteHeight)
	{
		std::cout << SuccessMsg(networkSyncPercentage) << std::endl;
	}
	else
	{
		std::cout << WarningMsg(networkSyncPercentage) << std::endl;
	}

	std::cout << "Wallet sync status: ";

	/* Small buffer because wallet height is not always completely accurate */
	if (walletHeight + 1000 > remoteHeight)
	{
		std::cout << SuccessMsg(walletSyncPercentage) << std::endl;
	}
	else
	{
		std::cout << WarningMsg(walletSyncPercentage) << std::endl;
	}
}
Exemplo n.º 3
0
void printOutgoingTransfer(CryptoNote::WalletTransaction t,
                           CryptoNote::INode &node)
{
    std::cout << WarningMsg("Outgoing transfer:")
              << std::endl
              << WarningMsg("Hash: " + Common::podToHex(t.hash))
              << std::endl;

    /* Block height will be garbage from memory if not confirmed yet */
    if (t.timestamp != 0)
    {
        std::cout << WarningMsg("Block height: ")
                  << WarningMsg(std::to_string(t.blockHeight))
                  << std::endl
                  << WarningMsg("Timestamp: ")
                  << WarningMsg(unixTimeToDate(t.timestamp))
                  << std::endl;
    }

    std::cout << WarningMsg("Spent: " + formatAmount(-t.totalAmount - t.fee))
              << std::endl
              << WarningMsg("Fee: " + formatAmount(t.fee))
              << std::endl
              << WarningMsg("Total Spent: " + formatAmount(-t.totalAmount))
              << std::endl;

    const std::string paymentID = getPaymentIDFromExtra(t.extra);

    if (paymentID != "")
    {
        std::cout << WarningMsg("Payment ID: " + paymentID) << std::endl;
    }

    std::cout << std::endl;
}
Exemplo n.º 4
0
std::string getNewWalletFileName()
{
    std::string walletName;

    while (true)
    {
        std::cout << InformationMsg("What would you like to call your ")
                  << InformationMsg("new wallet?: ");

        std::getline(std::cin, walletName);

        const std::string walletFileName = walletName + ".wallet";

        if (boost::filesystem::exists(walletFileName))
        {
            std::cout << std::endl
                      << WarningMsg("A wallet with the filename " )
                      << InformationMsg(walletFileName)
                      << WarningMsg(" already exists!")
                      << std::endl
                      << "Try another name." << std::endl << std::endl;
        }
        else if (walletName == "")
        {
            std::cout << std::endl
                      << WarningMsg("Wallet name can't be blank! Try again.")
                      << std::endl << std::endl;
        }
        else
        {
            return walletFileName;
        }
    }
}
Exemplo n.º 5
0
std::shared_ptr<WalletInfo> generateWallet(CryptoNote::WalletGreen &wallet)
{
    const std::string walletFileName = getNewWalletFileName();

    const std::string msg = "Give your new wallet a password: "******"If you lose these your wallet cannot be ")
              << WarningMsg("recreated!")
              << std::endl << std::endl;

    return std::make_shared<WalletInfo>(walletFileName, walletPass,
                                        walletAddress, false, wallet);
}
Exemplo n.º 6
0
void fullOptimize(CryptoNote::WalletGreen &wallet)
{
    std::cout << "Attempting to optimize your wallet to allow you to "
              << "send large amounts at once. " << std::endl
              << WarningMsg("This may take a very long time!") << std::endl;

    if (!confirm("Do you want to proceed?"))
    {
        std::cout << WarningMsg("Cancelling optimization.") << std::endl;
        return;
    }

    for (int i = 1;;i++)
    {
        std::cout << InformationMsg("Running optimization round "
                                  + std::to_string(i) + "...")
                  << std::endl;

        /* Optimize as many times as possible until optimization is no longer
           possible. */
        if (!optimize(wallet, wallet.getActualBalance()))
        {
            break;
        }
    }

    std::cout << SuccessMsg("Full optimization completed!") << std::endl;
}
Exemplo n.º 7
0
//
// Add a state update to the pending queue
//
void plNetClientMgr::AddPendingLoad(PendingLoad *pl) 
{ 
    // find corresponding key
    pl->fKey = hsgResMgr::ResMgr()->FindKey(pl->fUoid);

#ifdef HS_DEBUGGING
    // check for age SDL state
    if (!pl->fUoid.GetObjectName().IsNull() && !pl->fUoid.GetObjectName().Compare(plSDL::kAgeSDLObjectName))
    {
        DebugMsg("Recv SDL state for age hook object, uoid=%s", pl->fUoid.StringIze().c_str());
        if (!pl->fKey)
            WarningMsg("Can't find age hook object, nil key!");
        else
            DebugMsg("Found age hook object");
    }
#endif

    // check if object is ready
    if (pl->fKey)
    {
        if (!pl->fKey->ObjectIsLoaded())
        {
            WarningMsg("Object %s not loaded, withholding SDL state", 
                pl->fKey->GetUoid().StringIze().c_str());
        }
        else if (!pl->fKey->ObjectIsLoaded()->IsFinal())
        {
            WarningMsg("Object %s is not FINAL, withholding SDL state", 
                pl->fKey->GetUoid().StringIze().c_str());
        }
    }

    // add entry
    fPendingLoads.push_back(pl);
}
Exemplo n.º 8
0
void printSyncSummary(uint32_t localHeight, uint32_t remoteHeight,
	uint32_t walletHeight)
{
	if (localHeight == 0 && remoteHeight == 0)
	{
		std::cout << WarningMsg("Uh oh, it looks like you don't have ")
			<< WarningMsg(WalletConfig::daemonName)
			<< WarningMsg(" open!")
			<< std::endl;
	}
	else if (walletHeight + 1000 < remoteHeight && localHeight == remoteHeight)
	{
		std::cout << InformationMsg("You are synced with the network, but the "
			"blockchain is still being scanned for "
			"your transactions.")
			<< std::endl
			<< "Balances might be incorrect whilst this is ongoing."
			<< std::endl;
	}
	else if (localHeight == remoteHeight)
	{
		std::cout << SuccessMsg("Yay! You are synced!") << std::endl;
	}
	else
	{
		std::cout << WarningMsg("Be patient, you are still syncing with the "
			"network!") << std::endl;
	}
}
Exemplo n.º 9
0
bool parseAddress(std::string address)
{
    uint64_t expectedPrefix
        = CryptoNote::parameters::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX;

    uint64_t prefix;

    CryptoNote::AccountPublicAddress addr;

    bool valid = CryptoNote::parseAccountAddressString(prefix, addr, address);

    /* Generate a dummy address and grab its length to check that the inputted
       address is correct */
    CryptoNote::KeyPair spendKey;
    Crypto::generate_keys(spendKey.publicKey, spendKey.secretKey);
    
    CryptoNote::KeyPair viewKey;
    Crypto::generate_keys(viewKey.publicKey, viewKey.secretKey);

    CryptoNote::AccountPublicAddress expectedAddr
        {spendKey.publicKey, viewKey.publicKey};

    size_t expectedLen = CryptoNote::getAccountAddressAsStr(expectedPrefix, 
                         expectedAddr).length();

    if (address.length() != expectedLen)
    {
        std::cout << WarningMsg("Address is wrong length!") << std::endl
                  << "It should be " << expectedLen
                  << " characters long, but it is " << address.length()
                  << " characters long!" << std::endl << std::endl;

        return false;
    }
    /* We can't get the actual prefix if the address is invalid for other
       reasons. To work around this, we can just check that the address starts
       with TRTL, aslong as the prefix is the TRTL prefix. This keeps it
       working on testnets with different prefixes. */
    else if (expectedPrefix == 3914525 && address.substr(0, 4) != "TRTL")
    {
        std::cout << WarningMsg("Invalid address! It should start with TRTL!")
                  << std::endl << std::endl;
        return false;
    }
    /* We can return earlier by checking the value of valid, but then we don't
       get to give more detailed error messages about the address */
    else if (!valid)
    {
        std::cout << WarningMsg("Failed to parse address, address is not a "
                                "valid TRTL address!") << std::endl
                  << std::endl;
        return false;
    }

    return true;
}
Exemplo n.º 10
0
void saveCSV(CryptoNote::WalletGreen &wallet, CryptoNote::INode &node)
{
    const size_t numTransactions = wallet.getTransactionCount();

    std::ofstream csv;
    csv.open(WalletConfig::csvFilename);

    if (!csv)
    {
        std::cout << WarningMsg("Couldn't open transactions.csv file for "
                                "saving!")
                  << std::endl
                  << WarningMsg("Ensure it is not open in any other "
                                "application.")
                  << std::endl;
        return;
    }

    std::cout << InformationMsg("Saving CSV file...") << std::endl;

    /* Create CSV header */
    csv << "Timestamp,Block Height,Hash,Amount,In/Out"
        << std::endl;

    /* Loop through transactions */
    for (size_t i = 0; i < numTransactions; i++)
    {
        const CryptoNote::WalletTransaction t = wallet.getTransaction(i);

        /* Ignore fusion transactions */
        if (t.totalAmount == 0)
        {
            continue;
        }

        const std::string amount = formatAmountBasic(std::abs(t.totalAmount));

        const std::string direction = t.totalAmount > 0 ? "IN" : "OUT";

        csv << unixTimeToDate(t.timestamp) << ","       /* Timestamp */
            << t.blockHeight << ","                     /* Block Height */
            << Common::podToHex(t.hash) << ","          /* Hash */
            << amount << ","                            /* Amount */
            << direction                                /* In/Out */
            << std::endl;
    }

    csv.close();

    std::cout << SuccessMsg("CSV successfully written to ")
              << SuccessMsg(WalletConfig::csvFilename)
              << SuccessMsg("!")
              << std::endl;
}
Maybe<std::string> getPaymentID()
{
    while (true)
    {
        std::string paymentID;

        std::cout << std::endl
                  << InformationMsg("What payment ID do you want to use?")
                  << std::endl 
                  << "These are usually used for sending to exchanges."
                  << std::endl
                  << WarningMsg("Warning: if you were given a payment ID,")
                  << std::endl
                  << WarningMsg("you MUST use it, or your funds may be lost!")
                  << std::endl
                  << "Hit enter for the default of no payment ID: ";

        std::getline(std::cin, paymentID);

        if (paymentID == "")
        {
            return Just<std::string>(paymentID);
        }

        if (paymentID == "cancel")
        {
            return Nothing<std::string>();
        }

        std::vector<uint8_t> extra;

        /* Convert the payment ID into an "extra" */
        if (!CryptoNote::createTxExtraWithPaymentId(paymentID, extra))
        {
            std::cout << WarningMsg("Failed to parse! Payment ID's are 64 "
                                    "character hexadecimal strings.")
                      << std::endl;
        }
        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! */
            std::string extraString;

            for (auto i : extra)
            {
                extraString += static_cast<char>(i);
            }

            return Just<std::string>(extraString);
        }
    }
}
Exemplo n.º 12
0
std::string getExistingWalletFileName(Config &config)
{
    bool initial = true;

    std::string walletName;

    while (true)
    {
        /* Only use wallet file once in case it is incorrect */
        if (config.walletGiven && initial)
        {
            walletName = config.walletFile;
        }
        else
        {
            std::cout << InformationMsg("What is the name of the wallet ")
                      << InformationMsg("you want to open?: ");

            std::getline(std::cin, walletName);
        }

        initial = false;

        const std::string walletFileName = walletName + ".wallet";

        if (walletName == "")
        {
            std::cout << std::endl
                      << WarningMsg("Wallet name can't be blank! Try again.")
                      << std::endl << std::endl;
        }
        /* Allow people to enter wallet name with or without file extension */
        else if (boost::filesystem::exists(walletName))
        {
            return walletName;
        }
        else if (boost::filesystem::exists(walletFileName))
        {
            return walletFileName;
        }
        else
        {
            std::cout << std::endl
                      << WarningMsg("A wallet with the filename ")
                      << InformationMsg(walletName)
                      << WarningMsg(" or ")
                      << InformationMsg(walletFileName)
                      << WarningMsg(" doesn't exist!")
                      << std::endl
                      << "Ensure you entered your wallet name correctly."
                      << std::endl << std::endl;
        }
    }
}
bool parseAddress(std::string address)
{
    uint64_t expectedPrefix
        = CryptoNote::parameters::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX;

    uint64_t prefix;

    CryptoNote::AccountPublicAddress addr;

    bool valid = CryptoNote::parseAccountAddressString(prefix, addr, address);

    /* Generate a dummy address and grab its length to check that the inputted
       address is correct */
    CryptoNote::KeyPair spendKey;
    Crypto::generate_keys(spendKey.publicKey, spendKey.secretKey);
    
    CryptoNote::KeyPair viewKey;
    Crypto::generate_keys(viewKey.publicKey, viewKey.secretKey);

    CryptoNote::AccountPublicAddress expectedAddr
        {spendKey.publicKey, viewKey.publicKey};

    size_t expectedLen = CryptoNote::getAccountAddressAsStr(expectedPrefix, 
                         expectedAddr).length();

    if (address.length() != expectedLen)
    {
        std::cout << WarningMsg("Address is wrong length!") << std::endl
                  << "It should be " << expectedLen
                  << " characters long, but it is " << address.length()
                  << " characters long!" << std::endl << std::endl;

        return false;
    }

    else if (expectedPrefix == 0x1db32 && address.substr(0, 4) != "Wtip")
    {
        std::cout << WarningMsg("Invalid address! It should start with Wtip!")
                  << std::endl << std::endl;
        return false;
    }

    else if (!valid)
    {
        std::cout << WarningMsg("Failed to parse address, address is not a "
                                "valid WTIP address!") << std::endl
                  << std::endl;
        return false;
    }

    return true;
}
Exemplo n.º 14
0
std::shared_ptr<WalletInfo> createViewWallet(CryptoNote::WalletGreen &wallet)
{
    std::cout << WarningMsg("View wallets are only for viewing incoming ")
              << WarningMsg("transactions, and cannot make transfers.")
              << std::endl;

    bool create = confirm("Is this OK?");

    std::cout << std::endl;

    if (!create)
    {
        return nullptr;
    }
    
    Crypto::SecretKey privateViewKey = getPrivateKey("Private View Key: ");

    std::string address;

    while (true)
    {
        std::cout << InformationMsg("Enter your public ")
                  << InformationMsg(WalletConfig::ticker)
                  << InformationMsg(" address: ");

        std::getline(std::cin, address);
        boost::algorithm::trim(address);

        if (parseAddress(address))
        {
            break;
        }
    }

    const std::string walletFileName = getNewWalletFileName();

    const std::string msg = "Give your new wallet a password: "******"Your view wallet ")
              << InformationMsg(address)
              << InformationMsg(" has been successfully imported!")
              << std::endl << std::endl;

    viewWalletMsg();

    return std::make_shared<WalletInfo>(walletFileName, walletPass, 
                                        address, true, wallet);
}
Exemplo n.º 15
0
std::shared_ptr<WalletInfo> importGUIWallet(CryptoNote::WalletGreen &wallet)
{
    const int privateKeyLen = 184;

    std::string guiPrivateKey;

    uint64_t addressPrefix;
    std::string data;
    CryptoNote::AccountKeys keys;

    while (true)
    {
        std::cout << "GUI Private Key: ";
        std::getline(std::cin, guiPrivateKey);
        boost::algorithm::trim(guiPrivateKey);

        if (guiPrivateKey.length() != privateKeyLen)
        {
            std::cout << WarningMsg("Invalid GUI Private Key, should be ")
                      << WarningMsg(std::to_string(privateKeyLen))
                      << WarningMsg(" characters! Try again.")
                      << std::endl;

            continue;
        }

        if (!Tools::Base58::decode_addr(guiPrivateKey, addressPrefix, data)
          || data.size() != sizeof(keys))
        {
            std::cout << WarningMsg("Failed to decode GUI Private Key!")
                      << WarningMsg("Ensure you have entered it correctly.")
                      << std::endl;

            continue;
        }

        if (addressPrefix != 
            CryptoNote::parameters::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX)
        {
            std::cout << WarningMsg("Invalid GUI Private Key, it should begin ")
                      << WarningMsg("with ")
                      << WarningMsg(WalletConfig::addressPrefix)
                      << WarningMsg("! Try again.")
                      << std::endl;

            continue;
        }

        break;
    }

    /* Copy the keys into the struct */
    std::memcpy(&keys, data.data(), sizeof(keys));

    return importFromKeys(wallet, keys.spendSecretKey, keys.viewSecretKey);
}
Exemplo n.º 16
0
void MainWindow::connectmodulatordevice(SettingsDialog::Device device)
{
    if(device==SettingsDialog::JDDS)
    {

        //disconnect audio connections
        audiomskmodulator->DisconnectSourceDevice();
        disconnect(serialPPT,SIGNAL(Warning(QString)),this,SLOT(WarningTextSlot(QString)));
        disconnect(ui->actionTXRX,SIGNAL(triggered(bool)),audiomskmodulator,SLOT(startstop(bool)));
        disconnect(ui->actionTXRX,SIGNAL(triggered(bool)),serialPPT,SLOT(setPPT(bool)));
        disconnect(ui->inputwidget->textinputdevice,SIGNAL(eof()),audiomskmodulator,SLOT(stopgraceful()));
        disconnect(audiomskmodulator,SIGNAL(statechanged(bool)),ui->actionTXRX,SLOT(setChecked(bool)));
        disconnect(audiomskmodulator,SIGNAL(statechanged(bool)),serialPPT,SLOT(setPPT(bool)));
        disconnect(audiomskmodulator,SIGNAL(statechanged(bool)),ui->inputwidget,SLOT(reset()));
        disconnect(audiomskmodulator,SIGNAL(ReadyState(bool)),ui->inputwidget->textinputdevice,SLOT(SinkReadySlot(bool)));
        disconnect(audiomskmodulator,SIGNAL(statechanged(bool)),beaconhandler,SLOT(TransmissionStatus(bool)));
        disconnect(beaconhandler,SIGNAL(DoTransmissionNow()),audiomskmodulator,SLOT(start()));
        //

        //connections for JDDS
        ddsmskmodulator->ConnectSourceDevice(varicodepipeencoder);
        connect(ddsmskmodulator,SIGNAL(WarningMsg(QString)),this,SLOT(WarningTextSlot(QString)));
        connect(ui->actionTXRX,SIGNAL(triggered(bool)),ddsmskmodulator,SLOT(startstop(bool)));
        connect(ddsmskmodulator,SIGNAL(ReadyState(bool)),ui->inputwidget->textinputdevice,SLOT(SinkReadySlot(bool)));//connection to signal textinputdevice to go from preamble to normal operation
        connect(ddsmskmodulator,SIGNAL(statechanged(bool)),ui->inputwidget,SLOT(reset()));

        connect(ddsmskmodulator,SIGNAL(statechanged(bool)),ui->actionTXRX,SLOT(setChecked(bool)));
        connect(ui->inputwidget->textinputdevice,SIGNAL(eof()),ddsmskmodulator,SLOT(stopgraceful()));
        connect(ddsmskmodulator,SIGNAL(statechanged(bool)),beaconhandler,SLOT(TransmissionStatus(bool)));
        connect(beaconhandler,SIGNAL(DoTransmissionNow()),ddsmskmodulator,SLOT(start()));
    }
Exemplo n.º 17
0
Crypto::SecretKey getPrivateKey(std::string msg)
{
    const size_t privateKeyLen = 64;
    size_t size;

    std::string privateKeyString;
    Crypto::Hash privateKeyHash;
    Crypto::SecretKey privateKey;
    Crypto::PublicKey publicKey;

    while (true)
    {
        std::cout << InformationMsg(msg);

        std::getline(std::cin, privateKeyString);
        boost::algorithm::trim(privateKeyString);

        if (privateKeyString.length() != privateKeyLen)
        {
            std::cout << std::endl
                      << WarningMsg("Invalid private key, should be 64 ")
                      << WarningMsg("characters! Try again.") << std::endl
                      << std::endl;

            continue;
        }
        else if (!Common::fromHex(privateKeyString, &privateKeyHash, 
                  sizeof(privateKeyHash), size)
               || size != sizeof(privateKeyHash))
        {
            std::cout << WarningMsg("Invalid private key, it is not a valid ")
                      << WarningMsg("hex string! Try again.")
                      << std::endl << std::endl;

            continue;
        }

        privateKey = *(struct Crypto::SecretKey *) &privateKeyHash;

        /* Just used for verification purposes before we pass it to
           walletgreen */
        if (!Crypto::secret_key_to_public_key(privateKey, publicKey))
        {
            std::cout << std::endl
                      << WarningMsg("Invalid private key, is not on the ")
                      << WarningMsg("ed25519 curve!") << std::endl
                      << WarningMsg("Probably a typo - ensure you entered ")
                      << WarningMsg("it correctly.")
                      << std::endl << std::endl;

            continue;
        }

        return privateKey;
    }
}
Exemplo n.º 18
0
bool fusionTX(CryptoNote::WalletGreen &wallet, 
              CryptoNote::TransactionParameters p)
{
    std::cout << WarningMsg("Your transaction is too large to be accepted by "
                            "the network!")
              << std::endl << "We're attempting to optimize your "
              << "wallet, which hopefully will make the transaction small "
              << "enough to fit in a block." << std::endl 
              << "Please wait, this will take some time..." << std::endl 
              << std::endl;

    /* We could check if optimization succeeded, but it's not really needed
       because we then check if the transaction is too large... it could have
       potentially become valid because another payment came in. */
    optimize(wallet, p.destinations[0].amount + p.fee);

    const auto startTime = std::chrono::system_clock::now();

    while (wallet.getActualBalance() < p.destinations[0].amount + p.fee)
    {
        /* Break after a minute just in case something has gone wrong */
        if ((std::chrono::system_clock::now() - startTime) > 
             std::chrono::minutes(5))
        {
            std::cout << WarningMsg("Fusion transactions have "
                                    "completed, however available "
                                    "balance is less than transfer "
                                    "amount specified.") << std::endl
                      << WarningMsg("Transfer aborted, please review "
                                    "and start a new transfer.")
                      << std::endl;

            return false;
        }

        std::cout << WarningMsg("Optimization completed, but balance "
                                "is not fully unlocked yet!")
                  << std::endl
                  << SuccessMsg("Will try again in 5 seconds...")
                  << std::endl;

        std::this_thread::sleep_for(std::chrono::seconds(5));
    }

    return true;
}
bool parseMixin(std::string mixinString)
{
    try
    {
        /* We shouldn't need to check this is >0 because it should fail
           to parse as it's a uint16_t? */
        uint16_t mixin = std::stoi(mixinString);

        /* Force them to use a set mixin, if we detect dust later, then we
           will allow them to use 0 mixin. */
        uint16_t minMixin = std::max(CryptoNote::parameters
                                               ::MINIMUM_MIXIN_NO_DUST,
                                     CryptoNote::parameters::MINIMUM_MIXIN_V1);

        uint16_t maxMixin = CryptoNote::parameters::MAXIMUM_MIXIN_V1;

        if (mixin < minMixin)
        {
            std::cout << WarningMsg("Mixin count is too small! "
                                    "Minimum allowed is " + 
                                    std::to_string(minMixin) + ".")
                                    << std::endl;

            return false;
        }
        else if (mixin > maxMixin)
        {
            std::cout << WarningMsg("Mixin count is too large! "
                                    "Maximum allowed is " +
                                    std::to_string(maxMixin) + ".")
                                    << std::endl;

            return false;
        }

        return true;
    }
    catch (const std::invalid_argument)
    {
        std::cout << WarningMsg("Failed to parse mixin! Ensure you entered the "
                                "value correctly.") << std::endl;
        return false;
    }
}
Exemplo n.º 20
0
size_t makeFusionTransaction(CryptoNote::WalletGreen &wallet, 
                             uint64_t threshold)
{
    uint64_t bestThreshold = threshold;
    size_t optimizable = 0;

    /* Find the best threshold by starting at threshold and decreasing by
       half till we get to the minimum amount, storing the threshold that
       gave us the most amount of optimizable amounts */
    while (threshold > WalletConfig::minimumSend)
    {
        const auto fusionReadyCount
            = wallet.estimate(threshold).fusionReadyCount;

        if (fusionReadyCount > optimizable)
        {
            optimizable = fusionReadyCount;
            bestThreshold = threshold;
        }

        threshold /= 2;
    }

    /* Can't optimize */
    if (optimizable == 0)
    {
        return CryptoNote::WALLET_INVALID_TRANSACTION_ID;
    }

    try
    {
        return wallet.createFusionTransaction(bestThreshold, 
                                              WalletConfig::defaultMixin);
    }
    catch (const std::runtime_error &e)
    {
        std::cout << WarningMsg("Failed to send fusion transaction: ")
                  << WarningMsg(e.what()) << std::endl;

        return CryptoNote::WALLET_INVALID_TRANSACTION_ID;
    }
}
Exemplo n.º 21
0
void LIWarning (const Collection* LineInfos, unsigned Level, const char* Format, ...)
/* Print warning message using the given line infos */
{
    if (Level <= WarnLevel) {
        /* Output the message */
        va_list ap;
        va_start (ap, Format);
        WarningMsg (LineInfos, Format, ap);
        va_end (ap);
    }
}
Exemplo n.º 22
0
void txSecretKey(CryptoNote::WalletGreen &wallet)
{
    std::string hashStr;
	Crypto::Hash txid;

    while (true)
    {
        std::cout << InformationMsg("Enter transaction hash: ");

        std::getline(std::cin, hashStr);
        boost::algorithm::trim(hashStr);

        if (!parse_hash256(hashStr, txid)) {
            std::cout << WarningMsg("Failed to parse txid") << std::endl;
            return;
        }
        else {
            break;
        }

        if (std::cin.fail() || std::cin.eof()) {
            std::cin.clear();
            break;
        }        
    }

    Crypto::SecretKey txSecretKey = wallet.getTransactionSecretKey(txid);

    if (txSecretKey == CryptoNote::NULL_SECRET_KEY) {
        std::cout << WarningMsg("Transaction ") 
                  << WarningMsg(hashStr)
                  << WarningMsg(" secret key is not available")
                  << std::endl;
        return;
    }
		
    std::cout << SuccessMsg("Transaction secret key: ")
              << std::endl
              << SuccessMsg(Common::podToHex(txSecretKey))
              << std::endl;
}
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;
}
Exemplo n.º 24
0
bool checkNodeStatus(CryptoNote::INode &node)
{
    while (node.getLastKnownBlockHeight() == 0)
    {
        std::stringstream msg;

        msg << "It looks like " << WalletConfig::daemonName << " isn't open!"
            << std::endl << std::endl
            << "Ensure " << WalletConfig::daemonName
            << " is open and has finished initializing." << std::endl
            << "If it's still not working, try restarting "
            << WalletConfig::daemonName << "."
            << "The daemon sometimes gets stuck."
            << std::endl << "Alternatively, perhaps "
            << WalletConfig::daemonName << " can't communicate with any peers."
            << std::endl << std::endl
            << "The wallet can't function fully until it can communicate with "
            << "the network.";

        std::cout << WarningMsg(msg.str()) << std::endl;

        /* Print the commands */
        printCommands(nodeDownCommands());

        /* See what the user wants to do */
        std::string command = parseCommand(nodeDownCommands(),
                                           nodeDownCommands(),
                                           "What would you like to do?: ",
                                           false,
                                           nullptr);

        /* If they want to try again, check the node height again */
        if (command == "try_again")
        {
            continue;
        }
        /* If they want to exit, exit */
        else if (command == "exit")
        {
            return false;
        }
        /* If they want to continue, proceed to the menu screen */
        else if (command == "continue")
        {
            return true;
        }
    }

    return true;
}
Exemplo n.º 25
0
void balance(CryptoNote::INode &node, CryptoNote::WalletGreen &wallet,
             bool viewWallet)
{
    const uint64_t unconfirmedBalance = wallet.getPendingBalance();
    const uint64_t confirmedBalance = wallet.getActualBalance();
    const uint64_t totalBalance = unconfirmedBalance + confirmedBalance;

    const uint32_t localHeight = node.getLastLocalBlockHeight();
    const uint32_t remoteHeight = node.getLastKnownBlockHeight();
    const uint32_t walletHeight = wallet.getBlockCount();

    std::cout << "Available balance: "
              << SuccessMsg(formatAmount(confirmedBalance)) << std::endl
              << "Locked (unconfirmed) balance: "
              << WarningMsg(formatAmount(unconfirmedBalance))
              << std::endl << "Total balance: "
              << InformationMsg(formatAmount(totalBalance)) << std::endl;

    if (viewWallet)
    {
        std::cout << std::endl 
                  << InformationMsg("Please note that view only wallets "
                                    "can only track incoming transactions,")
                  << std::endl
                  << InformationMsg("and so your wallet balance may appear "
                                    "inflated.") << std::endl;
    }

    if (localHeight < remoteHeight)
    {
        std::cout << std::endl
                  << InformationMsg("Your daemon is not fully synced with "
                                    "the network!")
                  << std::endl
                  << "Your balance may be incorrect until you are fully "
                  << "synced!" << std::endl;
    }
    /* Small buffer because wallet height doesn't update instantly like node
       height does */
    else if (walletHeight + 1000 < remoteHeight)
    {
        std::cout << std::endl
                  << InformationMsg("The blockchain is still being scanned for "
                                    "your transactions.")
                  << std::endl
                  << "Balances might be incorrect whilst this is ongoing."
                  << std::endl;
    }
}
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;
}
Exemplo n.º 27
0
void Warning (unsigned Level, const char* Format, ...)
/* Print warning message. */
{
    if (Level <= WarnLevel) {

        va_list ap;
        Collection LineInfos = STATIC_COLLECTION_INITIALIZER;

        /* Get line infos for the current position */
        GetFullLineInfo (&LineInfos);

        /* Output the message */
        va_start (ap, Format);
        WarningMsg (&LineInfos, Format, ap);
        va_end (ap);

        /* Free the line info list */
        ReleaseFullLineInfo (&LineInfos);
        DoneCollection (&LineInfos);
    }
}
Exemplo n.º 28
0
int main( int argc, char *argv[])
{
    XtAppContext  app_ctx;
    char          text[80];
    char          title[80];
    Widget        toplevel;

    /* Look for user and password as arguments */
    if ( argc > 1) {
        if ( strcmp( argv[1], "-h") == 0) {
            usage();
            exit(0);
        }
        strcpy( text, argv[1]);
        if ( argc > 2)
            strcpy( title, argv[2]);
        else
            strcpy( title, "Warning");
    }
    else {
        usage();
        exit(0);
    }

    // MrmInitialize();

    toplevel = XtVaAppInitialize( &app_ctx, "yesnodia",
                                  NULL, 0, &argc, argv, NULL,
                                  XmNmappedWhenManaged, False,
                                  NULL);

    WarningMsg( toplevel, text, title);

    XtRealizeWidget(toplevel);

    XtAppMainLoop(app_ctx);
    return (0);
}
Exemplo n.º 29
0
void listTransfers(bool incoming, bool outgoing, 
                   CryptoNote::WalletGreen &wallet, CryptoNote::INode &node)
{
    const size_t numTransactions = wallet.getTransactionCount();

    int64_t totalSpent = 0;
    int64_t totalReceived = 0;

    for (size_t i = 0; i < numTransactions; i++)
    {
        const CryptoNote::WalletTransaction t = wallet.getTransaction(i);

        if (t.totalAmount < 0 && outgoing)
        {
            printOutgoingTransfer(t, node);
            totalSpent += -t.totalAmount;
        }
        else if (t.totalAmount > 0 && incoming)
        {
            printIncomingTransfer(t, node);
            totalReceived += t.totalAmount;
        }
    }

    if (incoming)
    {
        std::cout << SuccessMsg("Total received: " 
                              + formatAmount(totalReceived))
                  << std::endl;
    }

    if (outgoing)
    {
        std::cout << WarningMsg("Total spent: " + formatAmount(totalSpent))
                  << std::endl;
    }
}
Exemplo n.º 30
0
std::shared_ptr<WalletInfo> openWallet(CryptoNote::WalletGreen &wallet,
                                       Config &config)
{
    const std::string walletFileName = getExistingWalletFileName(config);

    bool initial = true;

    while (true)
    {
        std::string walletPass;

        /* Only use the command line pass once, otherwise we will infinite
           loop if it is incorrect */
        if (initial && config.passGiven)
        {
            walletPass = config.walletPass;
        }
        else
        {
            walletPass = getWalletPassword(false, "Enter password: "******"Your view only wallet ")
                          << InformationMsg(walletAddress)
                          << InformationMsg(" has been successfully opened!")
                          << std::endl << std::endl;

                viewWalletMsg();

                viewWallet = true;

            }
            else
            {
                std::cout << std::endl
                          << InformationMsg("Your wallet ")
                          << InformationMsg(walletAddress)
                          << InformationMsg(" has been successfully opened!")
                          << std::endl << std::endl;
            }

            return std::make_shared<WalletInfo>(
                walletFileName, walletPass, walletAddress, viewWallet, wallet
            );

        }
        catch (const std::system_error& e)
        {
            bool handled = false;

            switch (e.code().value())
            {
                case CryptoNote::error::WRONG_PASSWORD:
                {
                    std::cout << std::endl 
                              << WarningMsg("Incorrect password! Try again.")
                              << std::endl << std::endl;

                    handled = true;

                    break;
                }
                case CryptoNote::error::WRONG_VERSION:
                {
                    std::stringstream msg;

                    msg << "Could not open wallet file! It doesn't appear "
                        << "to be a valid wallet!" << std::endl
                        << "Ensure you are opening a wallet file, and the "
                        << "file has not gotten corrupted." << std::endl
                        << "Try reimporting via keys, and always close "
                        << WalletConfig::walletName << " with the exit "
                        << "command to prevent corruption." << std::endl;

                    std::cout << WarningMsg(msg.str()) << std::endl;

                    return nullptr;
                }
            }

            if (handled)
            {
                continue;
            }

            const std::string alreadyOpenMsg =
                "MemoryMappedFile::open: The process cannot access the file "
                "because it is being used by another process.";

            const std::string errorMsg = e.what();
                
            /* The message actually has a \r\n on the end but i'd prefer to
               keep just the raw string in the source so check the it starts
               with instead */
            if (boost::starts_with(errorMsg, alreadyOpenMsg))
            {
                std::cout << WarningMsg("Could not open wallet! It is already "
                                        "open in another process.")
                          << std::endl
                          << WarningMsg("Check with a task manager that you "
                                        "don't have ")
                          << WalletConfig::walletName
                          << WarningMsg(" open twice.")
                          << std::endl
                          << WarningMsg("Also check you don't have another "
                                        "wallet program open, such as a GUI "
                                        "wallet or ")
                          << WarningMsg(WalletConfig::walletdName)
                          << WarningMsg(".")
                          << std::endl << std::endl;

                return nullptr;
            }
            else
            {
                std::cout << "Unexpected error: " << errorMsg << std::endl;
                std::cout << "Please report this error message and what "
                          << "you did to cause it." << std::endl << std::endl;

                return nullptr;
            }
        }
    }
}