本文整理汇总了C++中Currency::isZero方法的典型用法代码示例。如果您正苦于以下问题:C++ Currency::isZero方法的具体用法?C++ Currency::isZero怎么用?C++ Currency::isZero使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Currency
的用法示例。
在下文中一共展示了Currency::isZero方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processItem
void BudgetBalancer::processItem(LedgerBudget const& budget)
{
// if there is a budget period, process recorded items until we are within
// range of this budget command
advancePeriodToDate(budget.date());
// if the current period started before today, or if it already has recorded
// commands, then end the period today and process what we have
if (m_period.startDate() != budget.date() || m_numRecords != 0)
{
m_period = DateRange(m_period.startDate(), budget.date());
allocateCategories();
processRecords();
}
// remove categories that are not in this budget command, or that have
// changed, and allocate their funds to the available category
auto categories = budget.categories();
for (auto it = m_categories.cbegin(); it != m_categories.cend(); ++it)
{
if (!categories.contains(it.key()) ||
categories[it.key()].type != it->type)
{
switch (it->type)
{
case LedgerBudget::Category::Type::GOAL:
// nothing to do for goals
break;
case LedgerBudget::Category::Type::INCOME:
// nothing to do for income type
break;
case LedgerBudget::Category::Type::RESERVE_AMOUNT:
{
Currency amount = m_reserveAmountAllocator.deallocate(it.key());
if (!amount.isZero())
{
emit message(budget,
QString("Reserve category '%1' was closed with "
"a balance of %2. Those funds are "
"available again.")
.arg(it.key())
.arg(amount.toString()));
}
m_available += amount;
break;
}
case LedgerBudget::Category::Type::RESERVE_PERCENT:
{
Currency amount = m_reservePercentAllocator.deallocate(it.key());
if (!amount.isZero())
{
emit message(budget,
QString("Reserve category '%1' was closed with "
"a balance of %2. Those funds are "
"available again.")
.arg(it.key())
.arg(amount.toString()));
}
m_available += amount;
break;
}
case LedgerBudget::Category::Type::ROUTINE:
m_routineAllocator.deallocate(it.key());
break;
}
}
}
// configure new and changed budget categories
for (auto it = categories.cbegin(); it != categories.cend(); ++it)
{
switch (it->type)
{
case LedgerBudget::Category::Type::GOAL:
m_goalAllocator.budget(budget.date());
break;
case LedgerBudget::Category::Type::INCOME:
// nothing to do for income
break;
case LedgerBudget::Category::Type::RESERVE_AMOUNT:
m_reserveAmountAllocator.budget(budget.date(), it.key(), it->amount,
it->interval);
break;
case LedgerBudget::Category::Type::RESERVE_PERCENT:
m_reservePercentAllocator.budget(it.key(), it->percentage);
break;
case LedgerBudget::Category::Type::ROUTINE:
// nothing to do for routine expenses
break;
}
}
m_categories = categories;
// reset the dates for the new period
m_period = DateRange(budget.date(), budget.interval());
}
示例2: doRipplePathFind
//.........这里部分代码省略.........
raSrc.getAccountID(),
raDst.getAccountID(),
saDstAmount,
level,
4); // max paths
for (unsigned int i = 0; i != jvSrcCurrencies.size (); ++i)
{
Json::Value jvSource = jvSrcCurrencies[i];
Currency uSrcCurrencyID;
Account uSrcIssuerID;
if (!jvSource.isObject ())
return rpcError (rpcINVALID_PARAMS);
// Parse mandatory currency.
if (!jvSource.isMember ("currency")
|| !to_currency (
uSrcCurrencyID, jvSource["currency"].asString ()))
{
WriteLog (lsINFO, RPCHandler) << "Bad currency.";
return rpcError (rpcSRC_CUR_MALFORMED);
}
if (uSrcCurrencyID.isNonZero ())
uSrcIssuerID = raSrc.getAccountID ();
// Parse optional issuer.
if (jvSource.isMember ("issuer") &&
((!jvSource["issuer"].isString () ||
!to_issuer (uSrcIssuerID, jvSource["issuer"].asString ())) ||
(uSrcIssuerID.isZero () != uSrcCurrencyID.isZero ()) ||
(noAccount() == uSrcIssuerID)))
{
WriteLog (lsINFO, RPCHandler) << "Bad issuer.";
return rpcError (rpcSRC_ISR_MALFORMED);
}
STPathSet spsComputed;
if (context.params.isMember("paths"))
{
Json::Value pathSet = Json::objectValue;
pathSet["Paths"] = context.params["paths"];
STParsedJSONObject paths ("pathSet", pathSet);
if (paths.object.get() == nullptr)
return paths.error;
else
{
spsComputed = paths.object.get()->getFieldPathSet (sfPaths);
WriteLog (lsTRACE, RPCHandler) << "ripple_path_find: Paths: " << spsComputed.getJson (0);
}
}
STPath fullLiquidityPath;
auto valid = fp.findPathsForIssue (
{uSrcCurrencyID, uSrcIssuerID},
spsComputed,
fullLiquidityPath);
if (!valid)
{
WriteLog (lsWARNING, RPCHandler)
<< "ripple_path_find: No paths found.";
}
else
示例3: parseJson
int PathRequest::parseJson (const Json::Value& jvParams, bool complete)
{
int ret = PFR_PJ_NOCHANGE;
if (jvParams.isMember ("source_account"))
{
if (!raSrcAccount.setAccountID (jvParams["source_account"].asString ()))
{
jvStatus = rpcError (rpcSRC_ACT_MALFORMED);
return PFR_PJ_INVALID;
}
}
else if (complete)
{
jvStatus = rpcError (rpcSRC_ACT_MISSING);
return PFR_PJ_INVALID;
}
if (jvParams.isMember ("destination_account"))
{
if (!raDstAccount.setAccountID (jvParams["destination_account"].asString ()))
{
jvStatus = rpcError (rpcDST_ACT_MALFORMED);
return PFR_PJ_INVALID;
}
}
else if (complete)
{
jvStatus = rpcError (rpcDST_ACT_MISSING);
return PFR_PJ_INVALID;
}
if (jvParams.isMember ("destination_amount"))
{
if (!saDstAmount.bSetJson (jvParams["destination_amount"]) ||
(saDstAmount.getCurrency ().isZero () && saDstAmount.getIssuer ().isNonZero ()) ||
(saDstAmount.getCurrency () == badCurrency()) ||
saDstAmount <= zero)
{
jvStatus = rpcError (rpcDST_AMT_MALFORMED);
return PFR_PJ_INVALID;
}
}
else if (complete)
{
jvStatus = rpcError (rpcDST_ACT_MISSING);
return PFR_PJ_INVALID;
}
if (jvParams.isMember ("source_currencies"))
{
const Json::Value& jvSrcCur = jvParams["source_currencies"];
if (!jvSrcCur.isArray ())
{
jvStatus = rpcError (rpcSRC_CUR_MALFORMED);
return PFR_PJ_INVALID;
}
sciSourceCurrencies.clear ();
for (unsigned i = 0; i < jvSrcCur.size (); ++i)
{
const Json::Value& jvCur = jvSrcCur[i];
Currency uCur;
Account uIss;
if (!jvCur.isObject() || !jvCur.isMember ("currency") ||
!to_currency (uCur, jvCur["currency"].asString ()))
{
jvStatus = rpcError (rpcSRC_CUR_MALFORMED);
return PFR_PJ_INVALID;
}
if (jvCur.isMember ("issuer") &&
!to_issuer (uIss, jvCur["issuer"].asString ()))
{
jvStatus = rpcError (rpcSRC_ISR_MALFORMED);
}
if (uCur.isZero () && uIss.isNonZero ())
{
jvStatus = rpcError (rpcSRC_CUR_MALFORMED);
return PFR_PJ_INVALID;
}
sciSourceCurrencies.insert ({uCur, uIss});
}
}
if (jvParams.isMember ("id"))
jvId = jvParams["id"];
return ret;
}
示例4: parseJson
int PathRequest::parseJson (Json::Value const& jvParams)
{
if (! jvParams.isMember(jss::source_account))
{
jvStatus = rpcError(rpcSRC_ACT_MISSING);
return PFR_PJ_INVALID;
}
if (! jvParams.isMember(jss::destination_account))
{
jvStatus = rpcError(rpcDST_ACT_MISSING);
return PFR_PJ_INVALID;
}
if (! jvParams.isMember(jss::destination_amount))
{
jvStatus = rpcError(rpcDST_AMT_MISSING);
return PFR_PJ_INVALID;
}
raSrcAccount = parseBase58<AccountID>(
jvParams[jss::source_account].asString());
if (! raSrcAccount)
{
jvStatus = rpcError (rpcSRC_ACT_MALFORMED);
return PFR_PJ_INVALID;
}
raDstAccount = parseBase58<AccountID>(
jvParams[jss::destination_account].asString());
if (! raDstAccount)
{
jvStatus = rpcError (rpcDST_ACT_MALFORMED);
return PFR_PJ_INVALID;
}
if (! amountFromJsonNoThrow (
saDstAmount, jvParams[jss::destination_amount]))
{
jvStatus = rpcError (rpcDST_AMT_MALFORMED);
return PFR_PJ_INVALID;
}
convert_all_ = saDstAmount == STAmount(saDstAmount.issue(), 1u, 0, true);
if ((saDstAmount.getCurrency ().isZero () &&
saDstAmount.getIssuer ().isNonZero ()) ||
(saDstAmount.getCurrency () == badCurrency ()) ||
(! convert_all_ && saDstAmount <= zero))
{
jvStatus = rpcError (rpcDST_AMT_MALFORMED);
return PFR_PJ_INVALID;
}
if (jvParams.isMember(jss::send_max))
{
// Send_max requires destination amount to be -1.
if (! convert_all_)
{
jvStatus = rpcError(rpcDST_AMT_MALFORMED);
return PFR_PJ_INVALID;
}
saSendMax.emplace();
if (! amountFromJsonNoThrow(
*saSendMax, jvParams[jss::send_max]) ||
(saSendMax->getCurrency().isZero() &&
saSendMax->getIssuer().isNonZero()) ||
(saSendMax->getCurrency() == badCurrency()) ||
(*saSendMax <= zero &&
*saSendMax != STAmount(saSendMax->issue(), 1u, 0, true)))
{
jvStatus = rpcError(rpcSENDMAX_MALFORMED);
return PFR_PJ_INVALID;
}
}
if (jvParams.isMember (jss::source_currencies))
{
Json::Value const& jvSrcCurrencies = jvParams[jss::source_currencies];
if (! jvSrcCurrencies.isArray() || jvSrcCurrencies.size() == 0 ||
jvSrcCurrencies.size() > RPC::Tuning::max_src_cur)
{
jvStatus = rpcError (rpcSRC_CUR_MALFORMED);
return PFR_PJ_INVALID;
}
sciSourceCurrencies.clear ();
for (auto const& c : jvSrcCurrencies)
{
// Mandatory currency
Currency srcCurrencyID;
if (! c.isObject() ||
! c.isMember(jss::currency) ||
! to_currency(srcCurrencyID, c[jss::currency].asString()))
{
jvStatus = rpcError (rpcSRC_CUR_MALFORMED);
return PFR_PJ_INVALID;
}
//.........这里部分代码省略.........
示例5: fp
std::pair<bool, Json::Value>
ripplePathFind(RippleLineCache::pointer const& cache,
RippleAddress const& raSrc, RippleAddress const& raDst,
STAmount const& saDstAmount, Ledger::pointer const& lpLedger,
Json::Value const& jvSrcCurrencies,
boost::optional<Json::Value> const& contextPaths, int const& level)
{
FindPaths fp(
cache,
raSrc.getAccountID(),
raDst.getAccountID(),
saDstAmount,
level,
4); // max paths
Json::Value jvArray(Json::arrayValue);
for (unsigned int i = 0; i != jvSrcCurrencies.size(); ++i)
{
Json::Value jvSource = jvSrcCurrencies[i];
Currency uSrcCurrencyID;
Account uSrcIssuerID;
if (!jvSource.isObject())
return std::make_pair(false, rpcError(rpcINVALID_PARAMS));
// Parse mandatory currency.
if (!jvSource.isMember(jss::currency)
|| !to_currency(
uSrcCurrencyID, jvSource[jss::currency].asString()))
{
WriteLog(lsINFO, RPCHandler) << "Bad currency.";
return std::make_pair(false, rpcError(rpcSRC_CUR_MALFORMED));
}
if (uSrcCurrencyID.isNonZero())
uSrcIssuerID = raSrc.getAccountID();
// Parse optional issuer.
if (jvSource.isMember(jss::issuer) &&
((!jvSource[jss::issuer].isString() ||
!to_issuer(uSrcIssuerID, jvSource[jss::issuer].asString())) ||
(uSrcIssuerID.isZero() != uSrcCurrencyID.isZero()) ||
(noAccount() == uSrcIssuerID)))
{
WriteLog(lsINFO, RPCHandler) << "Bad issuer.";
return std::make_pair(false, rpcError(rpcSRC_ISR_MALFORMED));
}
STPathSet spsComputed;
if (contextPaths)
{
Json::Value pathSet = Json::objectValue;
pathSet[jss::Paths] = contextPaths.get();
STParsedJSONObject paths("pathSet", pathSet);
if (paths.object.get() == nullptr)
return std::make_pair(false, paths.error);
else
{
spsComputed = paths.object.get()->getFieldPathSet(sfPaths);
WriteLog(lsTRACE, RPCHandler) << "ripple_path_find: Paths: " <<
spsComputed.getJson(0);
}
}
STPath fullLiquidityPath;
auto valid = fp.findPathsForIssue(
{ uSrcCurrencyID, uSrcIssuerID },
spsComputed,
fullLiquidityPath);
if (!valid)
{
WriteLog(lsWARNING, RPCHandler)
<< "ripple_path_find: No paths found.";
}
else
{
auto& issuer =
isXRP(uSrcIssuerID) ?
isXRP(uSrcCurrencyID) ? // Default to source account.
xrpAccount() :
Account(raSrc.getAccountID())
: uSrcIssuerID; // Use specifed issuer.
STAmount saMaxAmount({ uSrcCurrencyID, issuer }, 1);
saMaxAmount.negate();
LedgerEntrySet lesSandbox(lpLedger, tapNONE);
auto rc = path::RippleCalc::rippleCalculate(
lesSandbox,
saMaxAmount, // --> Amount to send is unlimited
// to get an estimate.
saDstAmount, // --> Amount to deliver.
raDst.getAccountID(), // --> Account to deliver to.
raSrc.getAccountID(), // --> Account sending from.
spsComputed); // --> Path set.
//.........这里部分代码省略.........
示例6: parseJson
int PathRequest::parseJson (Json::Value const& jvParams, bool complete)
{
int ret = PFR_PJ_NOCHANGE;
if (jvParams.isMember (jss::source_account))
{
raSrcAccount = parseBase58<AccountID>(
jvParams[jss::source_account].asString());
if (! raSrcAccount)
{
jvStatus = rpcError (rpcSRC_ACT_MALFORMED);
return PFR_PJ_INVALID;
}
}
else if (complete)
{
jvStatus = rpcError (rpcSRC_ACT_MISSING);
return PFR_PJ_INVALID;
}
if (jvParams.isMember (jss::destination_account))
{
raDstAccount = parseBase58<AccountID>(
jvParams[jss::destination_account].asString());
if (! raDstAccount)
{
jvStatus = rpcError (rpcDST_ACT_MALFORMED);
return PFR_PJ_INVALID;
}
}
else if (complete)
{
jvStatus = rpcError (rpcDST_ACT_MISSING);
return PFR_PJ_INVALID;
}
if (jvParams.isMember (jss::destination_amount))
{
if (! amountFromJsonNoThrow (
saDstAmount, jvParams[jss::destination_amount]) ||
(saDstAmount.getCurrency ().isZero () &&
saDstAmount.getIssuer ().isNonZero ()) ||
(saDstAmount.getCurrency () == badCurrency ()) ||
saDstAmount <= zero)
{
jvStatus = rpcError (rpcDST_AMT_MALFORMED);
return PFR_PJ_INVALID;
}
}
else if (complete)
{
jvStatus = rpcError (rpcDST_ACT_MISSING);
return PFR_PJ_INVALID;
}
if (jvParams.isMember (jss::source_currencies))
{
Json::Value const& jvSrcCur = jvParams[jss::source_currencies];
if (!jvSrcCur.isArray ())
{
jvStatus = rpcError (rpcSRC_CUR_MALFORMED);
return PFR_PJ_INVALID;
}
sciSourceCurrencies.clear ();
for (unsigned i = 0; i < jvSrcCur.size (); ++i)
{
Json::Value const& jvCur = jvSrcCur[i];
Currency uCur;
AccountID uIss;
if (!jvCur.isObject() || !jvCur.isMember (jss::currency) ||
!to_currency (uCur, jvCur[jss::currency].asString ()))
{
jvStatus = rpcError (rpcSRC_CUR_MALFORMED);
return PFR_PJ_INVALID;
}
if (jvCur.isMember (jss::issuer) &&
!to_issuer (uIss, jvCur[jss::issuer].asString ()))
{
jvStatus = rpcError (rpcSRC_ISR_MALFORMED);
}
if (uCur.isZero () && uIss.isNonZero ())
{
jvStatus = rpcError (rpcSRC_CUR_MALFORMED);
return PFR_PJ_INVALID;
}
if (uCur.isNonZero() && uIss.isZero())
{
uIss = *raSrcAccount;
}
sciSourceCurrencies.insert ({uCur, uIss});
}
}
//.........这里部分代码省略.........