本文整理汇总了C++中OT_ME类的典型用法代码示例。如果您正苦于以下问题:C++ OT_ME类的具体用法?C++ OT_ME怎么用?C++ OT_ME使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OT_ME类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LowLevelRetrieveMarketList
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;
}
示例2: qDebug
// ----------------------------------------------------------------------
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;
}
示例3: switch
// ---------------------------------------
// For outgoing, pending (not-yet-accepted) instruments.
//
bool MTRecord::CancelOutgoing(const std::string str_via_acct) // This can be blank if it's a cheque.
{
if (!this->CanCancelOutgoing())
return false;
switch (this->GetRecordType())
{
case MTRecord::Instrument:
{
if (m_str_nym_id.empty())
{
OTLog::vError("%s: Error: missing nym id (%s)\n",
__FUNCTION__, m_str_nym_id.c_str());
return false;
}
const OTIdentifier theNymID(m_str_nym_id);
// ------------------------------
std::string str_using_acct;
if (this->IsCheque())
{
str_using_acct = m_str_account_id;
}
else
{
str_using_acct = str_via_acct;
}
// ---------------------------------------
if (str_using_acct.empty())
{
OTLog::vError("%s: Error: Missing account ID (FAILURE)\n", __FUNCTION__);
return false;
}
// ------------------------------
if (0 == m_lTransactionNum)
{
if (IsCash())
{
// Maybe it's cash...
std::string strOutpayment(OTAPI_Wrap::GetNym_OutpaymentsContentsByIndex(m_str_nym_id, GetBoxIndex()));
if (strOutpayment.empty())
{
long lIndex = static_cast<long>(GetBoxIndex());
OTLog::vError("%s: Error: Blank outpayment at index %ld\n", __FUNCTION__, lIndex);
return false;
}
// ------------------------
OTString strPayment(strOutpayment);
OTPayment thePayment(strPayment);
if (!thePayment.IsValid() || !thePayment.SetTempValues())
{
long lIndex = static_cast<long>(GetBoxIndex());
OTLog::vError("%s: Error: Invalid outpayment at index %ld\n", __FUNCTION__, lIndex);
return false;
}
// ------------------------
long lTransNum = 0;
thePayment.GetOpeningNum(lTransNum, theNymID);
// ------------------------
if (0 == lTransNum) // Found it.
{
long lIndex = static_cast<long>(GetBoxIndex());
OTString strIndices;
strIndices.Format("%ld", lIndex);
const std::string str_indices(strIndices.Get());
// ---------------------------------
OT_ME madeEasy;
return madeEasy.cancel_outgoing_payments(m_str_nym_id, str_using_acct, str_indices);
}
else
{
OTLog::vError("%s: Error: Transaction number is non-zero (%ld), for cash outgoing payment for nym id (%s)\n",
__FUNCTION__, lTransNum, m_str_nym_id.c_str());
return false;
}
} // IsCash()
else
{
OTLog::vError("%s: Error: Transaction number is 0, for non-cash outgoing payment for nym id (%s)\n",
__FUNCTION__, m_str_nym_id.c_str());
return false;
}
}
// ---------------------------------------
// Find the payment in the Nym's outpayments box that correlates to this MTRecord.
//
int32_t nCount = OTAPI_Wrap::GetNym_OutpaymentsCount(m_str_nym_id);
for (int32_t nIndex = 0; nIndex < nCount; ++nIndex)
{
std::string strOutpayment(OTAPI_Wrap::GetNym_OutpaymentsContentsByIndex(m_str_nym_id, nIndex));
if (strOutpayment.empty())
//.........这里部分代码省略.........
示例4: QString
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;
}
示例5: qDebug
bool MTSendDlg::sendCash(int64_t amount, QString toNymId, QString fromAcctId, QString note)
{
if (toNymId.size() == 0) {
qDebug() << QString("Cannot send cash to an empty nym id, aborting.");
return false;
}
if (fromAcctId.size() == 0) {
qDebug() << QString("Cannot send cash from an unknown account id, aborting.");
return false;
}
if (amount <= 0) {
qDebug() << QString("Why send 0 (or less) units? Aborting send cash.");
return false;
}
// ------------------------------------------------------------
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));
std::string str_assetId (OTAPI_Wrap::GetAccountWallet_AssetTypeID(str_fromAcctId));
// ------------------------------------------------------------
// TODO: for security reasons, we might change the below 'if' so that
// it ONLY checks the cash balance, and not the account balance here.
// This would force the user to withdraw the cash by hand first, before
// sending it (which would make it possible to preserve untraceability.)
//
// Otherwise, if the send_instrument happens directly after the withdrawal,
// the server will be able to tell who the recipient is purely by timing
// analysis, without having to break the Chaumian blinding.
//
int64_t theCashBalance = MTHome::rawCashBalance(QString::fromStdString(str_serverId),
QString::fromStdString(str_assetId),
QString::fromStdString(str_fromNymId));
int64_t theAcctBalance = MTHome::rawAcctBalance(this->m_myAcctId);
if ((amount > theCashBalance) && (amount > (theAcctBalance + theCashBalance)))
{
qDebug() << QString("Aborting send cash: Amount is larger than cash balance, and is also "
"larger than combined cash + account balance.");
return false;
// Note: you may be asking why doesn't the amount only have to be equal
// to the SUM of the two balances? Why must it be available in FULL from
// one or the other? The answer is, because if there is not enough available
// in the purse, or if the tokens there have enough units, but not the right
// denominations to create the amount exactly, then we have to withdraw the
// amount from the account instead. In that case we will want to withdraw the
// full amount, so that we can guarantee that we have tokens of the right
// denominations for that amount.
// NOTE: apparently the high-level API only withdraws the difference, which
// means it could still end up with the right "amount" of cash, but the wrong
// denominations necessary to "make change" for the exact amount.
}
// ------------------------------------------------------------
int64_t SignedAmount = amount;
qDebug() << QString("Sending cash:\n Server:'%1'\n Nym:'%2'\n Acct:'%3'\n ToNym:'%4'\n Amount:'%5'\n Note:'%6'").
arg(str_serverId.c_str()).arg(str_fromNymId.c_str()).arg(str_fromAcctId.c_str()).arg(toNymId).arg(SignedAmount).arg(note);
// ------------------------------------------------------------
OT_ME madeEasy;
bool bReturnValue = false;
{
MTOverrideCursor theSpinner;
bReturnValue = madeEasy.withdraw_and_send_cash(str_fromAcctId, str_toNymId, note.toStdString(), SignedAmount);
}
// ------------------------------------------------------------
return bReturnValue;
// NOTE: We don't retrieve the account files in the case of success, because the
// above function already does all that internally.
}
示例6: theWizard
//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))
//.........这里部分代码省略.........
示例7: theWizard
//virtual
void MTNymDetails::AddButtonClicked()
{
MTWizardAddNym theWizard(this);
theWizard.setWindowTitle(tr("Create Nym (a.k.a. Create Identity)"));
if (QDialog::Accepted == theWizard.exec())
{
QString qstrName = theWizard.field("Name") .toString();
int nKeysizeIndex = theWizard.field("Keysize") .toInt();
int nAuthorityIndex = theWizard.field("Authority").toInt();
QString qstrSource = theWizard.field("Source") .toString();
QString qstrLocation = theWizard.field("Location") .toString();
// ---------------------------------------------------
// NOTE: theWizard won't allow each page to finish unless the data is provided.
// (Therefore we don't have to check here to see if any of the data is empty.)
int32_t nKeybits = 1024;
switch (nKeysizeIndex)
{
case 0: // 1024
nKeybits = 1024;
break;
case 1: // 2048
nKeybits = 2048;
break;
case 2: // 4096
nKeybits = 4096;
break;
default:
qDebug() << QString("%1: %2").arg(tr("Error in keysize selection. Using default")).arg(nKeybits);
break;
}
// -------------------------------------------
std::string NYM_ID_SOURCE("");
if (0 != nAuthorityIndex) // Zero would be Self-Signed, which needs no source.
NYM_ID_SOURCE = qstrSource.toStdString();
// -------------------------------------------
std::string ALT_LOCATION("");
if (!qstrLocation.isEmpty())
ALT_LOCATION = qstrLocation.toStdString();
// -------------------------------------------
// Create Nym here...
//
OT_ME madeEasy;
std::string str_id = madeEasy.create_pseudonym(nKeybits, NYM_ID_SOURCE, ALT_LOCATION);
if (str_id.empty())
{
QMessageBox::warning(this, tr("Failed Creating Nym"),
tr("Failed trying to create Nym."));
return;
}
// ------------------------------------------------------
// Get the ID of the new nym.
//
QString qstrID = QString::fromStdString(str_id);
// ------------------------------------------------------
// Register the Namecoin name.
if (nAuthorityIndex == 1)
{
const unsigned cnt = OTAPI_Wrap::GetNym_CredentialCount (str_id);
if (cnt != 1)
{
qDebug () << "Expected one master credential, got " << cnt
<< ". Skipping Namecoin registration.";
}
else
{
const std::string cred = OTAPI_Wrap::GetNym_CredentialID (str_id, 0);
const QString qCred = QString::fromStdString (cred);
NMC_NameManager& nmc = NMC_NameManager::getInstance ();
nmc.startRegistration (qstrID, qCred);
}
}
// ------------------------------------------------------
// Set the Name of the new Nym.
//
//bool bNameSet =
OTAPI_Wrap::SetNym_Name(qstrID.toStdString(), qstrID.toStdString(), qstrName.toStdString());
// -----------------------------------------------
// Commenting this out for now.
//
// QMessageBox::information(this, tr("Success!"), QString("%1: '%2' %3: %4").arg(tr("Success Creating Nym! Name")).
// arg(qstrName).arg(tr("ID")).arg(qstrID));
// ----------
m_pOwner->m_map.insert(qstrID, qstrName);
m_pOwner->SetPreSelected(qstrID);
//.........这里部分代码省略.........