Example #1
0
bool DlgMarkets::LowLevelRetrieveMarketList(QString qstrServerID, QString qstrNymID, mapIDName & the_map)
{
    if (qstrServerID.isEmpty() || qstrNymID.isEmpty())
        return false;
    // -----------------
    OT_ME madeEasy;

    bool bSuccess = false;
    {
        MTSpinner theSpinner;

        const std::string str_reply = madeEasy.get_market_list(qstrServerID.toStdString(),
                                                               qstrNymID   .toStdString());
        const int32_t     nResult   = madeEasy.VerifyMessageSuccess(str_reply);

        bSuccess = (1 == nResult);
    }
    // -----------------------------------
    if (bSuccess)
    {
        return LowLevelLoadMarketList(qstrServerID, m_nymId, the_map);
    }
    else
        Moneychanger::HasUsageCredits(this, qstrServerID, qstrNymID);
    // -----------------------------------
    return bSuccess;
}
Example #2
0
// ----------------------------------------------------------------------
bool MTCompose::sendMessage(QString body, QString fromNymId, QString toNymId, QString atServerID, QString subject)
{
    if (fromNymId.isEmpty())
    {
        qDebug() << "Cannot send a message from an empty nym id, aborting.";
        return false;
    }
    // ----------------------------------------------------
    if (toNymId.isEmpty())
    {
        qDebug() << "Cannot send a message to an empty nym id, aborting.";
        return false;
    }
    // ----------------------------------------------------
    if (subject.isEmpty())
        subject = tr("From the desktop client. (Empty subject.)");
    // ----------------------------------------------------
    if (body.isEmpty())
        body = tr("From the desktop client. (Empty message body.)");
    // ----------------------------------------------------
    std::string str_serverId  (atServerID.toStdString());
    std::string str_fromNymId (fromNymId.toStdString());
    std::string str_toNymId   (toNymId.toStdString());
    // ----------------------------------------------------
    qDebug() << QString("Initiating sendMessage:\n Server:'%1'\n FromNym:'%2'\n ToNym:'%3'\n Subject:'%4'\n Body:'%5'").
                arg(atServerID).arg(fromNymId).arg(toNymId).arg(subject).arg(body);
    // ----------------------------------------------------
    QString contents = tr("%1: %2\n\n%3").arg(tr("Subject")).arg(subject).arg(body);
    // ----------------------------------------------------
    OT_ME madeEasy;

    std::string strResponse;
    {
        MTSpinner theSpinner;

        strResponse = madeEasy.send_user_msg(str_serverId, str_fromNymId, str_toNymId, contents.toStdString());
    }

    int32_t nReturnVal = madeEasy.VerifyMessageSuccess(strResponse);

    if (1 != nReturnVal)
    {
        qDebug() << "send_message: Failed.";

        Moneychanger::HasUsageCredits(this, str_serverId, str_fromNymId);

        return false;
    }

    qDebug() << "Success in send_message!";
    m_bSent = true;
    // ---------------------------------------------------------
    return m_bSent;
}
Example #3
0
bool MTSendDlg::sendChequeLowLevel(int64_t amount, QString toNymId, QString fromAcctId, QString note, bool isInvoice)
{
    QString nsChequeType = isInvoice ? QString("invoice") : QString("cheque");
    // ------------------------------------------------------------
    if (toNymId.size() == 0)
    {
        qDebug() << QString("Cannot send %1 to an empty nym id, aborting.").arg(nsChequeType);
        return false;
    }
    if (fromAcctId.size() == 0)
    {
        qDebug() << QString("Cannot send %1 from a non-existent account id, aborting.").arg(nsChequeType);
        return false;
    }
    if (amount <= 0)
    {
        qDebug() << QString("Why send 0 (or less) units? Aborting send %1.").arg(nsChequeType);
        return false;
    }
    // Note: in the case of cheques we don't have to see if the amount exceeds the
    // account balance here, since the money doesn't come out of the account until
    // the cheque is deposited by the recipient. Technically you could write a bad
    // cheque. Also, your balance will not change right away either -- not until the
    // recipient deposits the cheque.
    // Also of course, in the case of invoices, your account balance is irrelevant
    // since an invoice can only increase your balance, not decrease it.
    if (note.isEmpty())
        note = tr("From the Qt systray app.");
    // ------------------------------------------------------------
    std::string str_toNymId   (toNymId   .toStdString());
    std::string str_fromAcctId(fromAcctId.toStdString());
    // ------------------------------------------------------------
    std::string str_fromNymId(OTAPI_Wrap::GetAccountWallet_NymID   (str_fromAcctId));
    std::string str_serverId (OTAPI_Wrap::GetAccountWallet_ServerID(str_fromAcctId));
    // ------------------------------------------------------------
    int64_t SignedAmount = amount;
    int64_t trueAmount   = isInvoice ? (SignedAmount*(-1)) : SignedAmount;
    // ------------------------------------------------------------
    qDebug() << QString("Sending %1:\n Server:'%2'\n Nym:'%3'\n Acct:'%4'\n ToNym:'%5'\n Amount:'%6'\n Note:'%7'").
                arg(nsChequeType).arg(QString::fromStdString(str_serverId)).arg(QString::fromStdString(str_fromNymId)).
                arg(fromAcctId).arg(toNymId).arg(SignedAmount).arg(note);
    // ------------------------------------------------------------
    time_t tFrom = OTAPI_Wrap::GetTime();
    time_t tTo   = tFrom + DEFAULT_CHEQUE_EXPIRATION;
    // ------------------------------------------------------------
    std::string strCheque = OTAPI_Wrap::WriteCheque(str_serverId, trueAmount, tFrom, tTo,
                                                    str_fromAcctId, str_fromNymId, note.toStdString(),
                                                    str_toNymId);
    if (strCheque.empty())
    {
        qDebug() << QString("Failed creating %1.").arg(nsChequeType);
        return false;
    }
    // ------------------------------------------------------------
    OT_ME madeEasy;

    std::string  strResponse;
    {
        MTOverrideCursor theSpinner;

        strResponse = madeEasy.send_user_payment(str_serverId, str_fromNymId, str_toNymId, strCheque);
    }

    int32_t nReturnVal  = madeEasy.VerifyMessageSuccess(strResponse);

    if (1 != nReturnVal)
        qDebug() << QString("send %1: failed.").arg(nsChequeType);
    else
    {
        qDebug() << QString("Success in send %1!").arg(nsChequeType);
        return true;
    }
    // NOTE: We do not retrieve the account files here, in the case of success.
    // That's because none of them have changed yet from this operation -- not
    // until the recipient deposits the cheque.

    return false;
}
Example #4
0
bool MTSendDlg::sendCashierCheque(int64_t amount, QString toNymId, QString fromAcctId, QString note)
{
    QString nsChequeType = QString("voucher");
    // ------------------------------------------------------------
    if (toNymId.size() == 0) {
        qDebug() << QString("Cannot send %1 to an empty nym id, aborting.").arg(nsChequeType);
        return false;
    }
    if (fromAcctId.size() == 0) {
        qDebug() << QString("Cannot send %1 from an unknown account id, aborting.").arg(nsChequeType);
        return false;
    }
    if (amount <= 0) {
        qDebug() << QString("Why send 0 (or less) units? Aborting send %1.").arg(nsChequeType);
        return false;
    }
    if (amount > MTHome::rawAcctBalance(m_myAcctId)) {
        qDebug() << QString("Aborting send %1: Amount is larger than account balance.").arg(nsChequeType);
        return false;
    }
    if (note.isEmpty())
        note = tr("From the desktop systray app.");
    // ------------------------------------------------------------
    std::string str_toNymId   (toNymId   .toStdString());
    std::string str_fromAcctId(fromAcctId.toStdString());
    // ------------------------------------------------------------
    std::string str_fromNymId(OTAPI_Wrap::GetAccountWallet_NymID   (str_fromAcctId));
    std::string str_serverId (OTAPI_Wrap::GetAccountWallet_ServerID(str_fromAcctId));
    // ------------------------------------------------------------
    int64_t SignedAmount = amount;
    qDebug() << QString("Sending %1:\n Server:'%2'\n Nym:'%3'\n Acct:'%4'\n ToNym:'%5'\n Amount:'%6'\n Note:'%7'").
                arg(nsChequeType).arg(str_serverId.c_str()).arg(str_fromNymId.c_str()).arg(str_fromAcctId.c_str()).
                arg(toNymId).arg(SignedAmount).arg(note);
    // ------------------------------------------------------------
    OT_ME madeEasy;

    std::string strAttempt  = "withdraw_voucher";
    std::string strResponse;
    {
        MTOverrideCursor theSpinner;

        strResponse = madeEasy.withdraw_voucher(str_serverId, str_fromNymId, str_fromAcctId,
                                                str_toNymId, note.toStdString(), SignedAmount);
    }

    int32_t nInterpretReply = madeEasy.InterpretTransactionMsgReply(str_serverId, str_fromNymId, str_fromAcctId,
                                                                    strAttempt, strResponse);

    if (1 != nInterpretReply) // Failure
    {
        qDebug() << QString("Failure withdrawing voucher.");
        return false;
    }
    // ---------------------------------------------------------
    //else Success!
    std::string strLedger = OTAPI_Wrap::Message_GetLedger(strResponse);

    if (strLedger.empty())
    {
        qDebug() << QString("Failed withdrawing voucher: strLedger is empty.");
        return false;
    }
    // ---------------------------------------------------------
    std::string strTransReply = OTAPI_Wrap::Ledger_GetTransactionByIndex(str_serverId, str_fromNymId, str_fromAcctId, strLedger, 0); // index 0.

    if (strTransReply.empty())
    {
        qDebug() << QString("Error in withdraw_voucher: strTransReply is unexpectedly null, "
                            "returned by Ledger_GetTransactionByIndex, argument passed, index 0 and ledger:\n\n%s1\n").
                    arg(strLedger.c_str());
        return false;
    }
    // ---------------------------------------------------------
    std::string strVoucher = OTAPI_Wrap::Transaction_GetVoucher(str_serverId, str_fromNymId, str_fromAcctId, strTransReply);

    if (strVoucher.empty())
    {
        qDebug() << QString("Error in withdraw_voucher: Voucher is unexpectedly empty, returned by Transaction_GetVoucher "
                            "with strTransReply set to:\n\n%1\n").arg(strTransReply.c_str());
        return false;
    }
    else
    {
        // Save a copy in my own outpayments box. I don't want to lose this voucher since it uses
        // one of my own transaction numbers. (If I later send the voucher to someone, OT is smart
        // enough to remove the first copy from outpayments, when adding the second copy.)
        //
        // Notice how I can send an instrument to myself. This doesn't actually send anything --
        // it just puts a copy into my outpayments box for safe-keeping.
        //
        OT_ME sendToSelf;
        sendToSelf.send_user_payment(str_serverId, str_fromNymId, str_fromNymId, strVoucher);
    }
    // ---------------------------------------------------------
    // Download all the intermediary files (account balance, inbox, outbox, etc)
    // since they have probably changed from this operation.
    //
    OT_ME retrieveAcct;
    bool bRetrieved = false;
    {
        MTOverrideCursor theSpinner;

        bRetrieved = retrieveAcct.retrieve_account(str_serverId, str_fromNymId, str_fromAcctId, true); //bForceDownload defaults to false.
    }
    qDebug() << QString("%1 retrieving intermediary files for account %2. (After withdraw voucher.)").
                arg(bRetrieved ? QString("Success") : QString("Failed")).arg(str_fromAcctId.c_str());
    // ---------------------------------------------------------
    // We try to send it, even if the retrieve_account failed.
    // That way we insure that a copy of the voucher is stored
    // in the outpayment box. (Even if it fails to send.)
    // That way the user can later cancel or re-send it.
    //

    //OTLog::vOutput(0, "Sending payment to NymID: %s\n", str_toNymId.c_str());

    OT_ME sendPayment;

    std::string  strSendResponse;
    {
        MTOverrideCursor theSpinner;

        strSendResponse = sendPayment.send_user_payment(str_serverId, str_fromNymId, str_toNymId, strVoucher);
    }

    int32_t nReturnVal = sendPayment.VerifyMessageSuccess(strSendResponse);

    if (1 != nReturnVal)
        qDebug() << QString("send %1: Failed.").arg(nsChequeType);
    else
    {
        qDebug() << QString("Success in send %1!").arg(nsChequeType);
        return true;
    }

    return false;
}
//virtual
void MTAccountDetails::AddButtonClicked()
{
    MTWizardAddAccount theWizard(this);

    theWizard.setWindowTitle(tr("Create Account"));

    if (QDialog::Accepted == theWizard.exec())
    {
        QString qstrName     = theWizard.field("Name") .toString();
        QString qstrAssetID  = theWizard.field("AssetID") .toString();
        QString qstrNymID    = theWizard.field("NymID")   .toString();
        QString qstrServerID = theWizard.field("ServerID").toString();
        // ---------------------------------------------------
        QString qstrAssetName  = QString::fromStdString(OTAPI_Wrap::It()->GetAssetType_Name(qstrAssetID .toStdString()));
        QString qstrNymName    = QString::fromStdString(OTAPI_Wrap::It()->GetNym_Name      (qstrNymID   .toStdString()));
        QString qstrServerName = QString::fromStdString(OTAPI_Wrap::It()->GetServer_Name   (qstrServerID.toStdString()));
        // ---------------------------------------------------
        QMessageBox::information(this, tr("Confirm Create Account"),
                                 QString("%1: '%2'<br/>%3: %4<br/>%5: %6<br/>%7: %8").arg(tr("Confirm Create Account:<br/>Name")).
                                 arg(qstrName).arg(tr("Asset")).arg(qstrAssetName).arg(tr("Nym")).arg(qstrNymName).arg(tr("Server")).arg(qstrServerName));
        // ---------------------------------------------------
        // NOTE: theWizard won't allow each page to finish unless the ID is provided.
        // (Therefore we don't have to check here to see if any of the IDs are empty.)

        // ------------------------------
        // First make sure the Nym is registered at the server, and if not, register him.
        //
        bool bIsRegiseredAtServer = OTAPI_Wrap::It()->IsNym_RegisteredAtServer(qstrNymID.toStdString(),
                                                                         qstrServerID.toStdString());
        if (!bIsRegiseredAtServer)
        {
            OT_ME madeEasy;

            // If the Nym's not registered at the server, then register him first.
            //
            int32_t nSuccess = 0;
            {
                MTSpinner theSpinner;

                std::string strResponse = madeEasy.register_nym(qstrServerID.toStdString(),
                                                                qstrNymID   .toStdString()); // This also does getRequest internally, if success.
                nSuccess                = madeEasy.VerifyMessageSuccess(strResponse);
            }
            // -1 is error,
            //  0 is reply received: failure
            //  1 is reply received: success
            //
            switch (nSuccess)
            {
            case (1):
                {
                    bIsRegiseredAtServer = true;
                    break; // SUCCESS
                }
            case (0):
                {
                    QMessageBox::warning(this, tr("Failed Registration"),
                        tr("Failed while trying to register Nym at Server."));
                    break;
                }
            default:
                {
                    QMessageBox::warning(this, tr("Error in Registration"),
                        tr("Error while trying to register Nym at Server."));
                    break;
                }
            } // switch
            // --------------------------
            if (1 != nSuccess)
            {
                Moneychanger::HasUsageCredits(this, qstrServerID, qstrNymID);
                return;
            }
        }
        // --------------------------
        // Send the request.
        // (Create Account here...)
        //
        OT_ME madeEasy;

        // Send the 'create_asset_acct' message to the server.
        //
        std::string strResponse;
        {
            MTSpinner theSpinner;

            strResponse = madeEasy.create_asset_acct(qstrServerID.toStdString(),
                                                     qstrNymID   .toStdString(),
                                                     qstrAssetID .toStdString());
        }
        // -1 error, 0 failure, 1 success.
        //
        if (1 != madeEasy.VerifyMessageSuccess(strResponse))
        {
            const int64_t lUsageCredits = Moneychanger::HasUsageCredits(this, qstrServerID, qstrNymID);

            // HasUsageCredits already pops up an error box in the cases of -2 and 0.
            //
            if (((-2) != lUsageCredits) && (0 != lUsageCredits))
                QMessageBox::warning(this, tr("Failed Creating Account"),
                    tr("Failed trying to create Account at Server."));
            return;
        }
        // ------------------------------------------------------
        // Get the ID of the new account.
        //
        QString qstrID = QString::fromStdString(OTAPI_Wrap::It()->Message_GetNewAcctID(strResponse));

        if (qstrID.isEmpty())
        {
            QMessageBox::warning(this, tr("Failed Getting new Account ID"),
                                 tr("Failed trying to get the new account's ID from the server response."));
            return;
        }
        // ------------------------------------------------------
        // Set the Name of the new account.
        //
        //bool bNameSet =
                OTAPI_Wrap::It()->SetAccountWallet_Name(qstrID   .toStdString(),
                                                  qstrNymID.toStdString(),
                                                  qstrName .toStdString());
        // -----------------------------------------------
        // Commenting out for now.
        //
//        QMessageBox::information(this, tr("Success!"), QString("%1: '%2'<br/>%3: %4").arg(tr("Success Creating Account!<br/>Name")).
//                                 arg(qstrName).arg(tr("ID")).arg(qstrID));
        // ----------
        m_pOwner->m_map.insert(qstrID, qstrName);
        m_pOwner->SetPreSelected(qstrID);
        // ------------------------------------------------
        emit RefreshRecordsAndUpdateMenu();
        // ------------------------------------------------
    }
}