本文整理汇总了C++中Asset::type方法的典型用法代码示例。如果您正苦于以下问题:C++ Asset::type方法的具体用法?C++ Asset::type怎么用?C++ Asset::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Asset
的用法示例。
在下文中一共展示了Asset::type方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
AccountID
getIssuer(Asset const& asset)
{
return (asset.type() == ASSET_TYPE_CREDIT_ALPHANUM4
? asset.alphaNum4().issuer
: asset.alphaNum12().issuer);
}
示例2: runtime_error
void
processAsset(Asset& asset, AssetType assetType, std::string const& issuerStr,
soci::indicator const& issuerIndicator,
std::string const& assetCode,
soci::indicator const& assetCodeIndicator)
{
asset.type(assetType);
if (assetType != ASSET_TYPE_NATIVE)
{
if ((assetCodeIndicator != soci::i_ok) ||
(issuerIndicator != soci::i_ok))
{
throw std::runtime_error("bad database state");
}
if (assetType == ASSET_TYPE_CREDIT_ALPHANUM12)
{
asset.alphaNum12().issuer =
KeyUtils::fromStrKey<PublicKey>(issuerStr);
strToAssetCode(asset.alphaNum12().assetCode, assetCode);
}
else if (assetType == ASSET_TYPE_CREDIT_ALPHANUM4)
{
asset.alphaNum4().issuer =
KeyUtils::fromStrKey<PublicKey>(issuerStr);
strToAssetCode(asset.alphaNum4().assetCode, assetCode);
}
else
{
throw std::runtime_error("bad database state");
}
}
}
示例3:
QDebug operator<<(QDebug debug, const Asset& asset)
{
debug.nospace() << "Asset{mnem=" << asset.mnem() //
<< ",display=" << asset.display() //
<< ",type=" << asset.type() //
<< '}';
return debug;
}
示例4: if
// Note: This function is currently only used in AllowTrustOpFrame, which means
// the asset parameter will never satisfy asset.type() == ASSET_TYPE_NATIVE. As
// a consequence, I have not implemented that possibility so this function
// throws in that case.
std::vector<LedgerEntry>
LedgerStateRoot::Impl::loadOffersByAccountAndAsset(AccountID const& accountID,
Asset const& asset) const
{
std::string sql = "SELECT sellerid, offerid, "
"sellingassettype, sellingassetcode, sellingissuer, "
"buyingassettype, buyingassetcode, buyingissuer, "
"amount, pricen, priced, flags, lastmodified "
"FROM offers ";
sql += " WHERE sellerid = :acc"
" AND ((sellingassetcode = :code AND sellingissuer = :iss)"
" OR (buyingassetcode = :code AND buyingissuer = :iss))";
std::string accountStr = KeyUtils::toStrKey(accountID);
std::string assetCode;
std::string assetIssuer;
if (asset.type() == ASSET_TYPE_CREDIT_ALPHANUM4)
{
assetCodeToStr(asset.alphaNum4().assetCode, assetCode);
assetIssuer = KeyUtils::toStrKey(asset.alphaNum4().issuer);
}
else if (asset.type() == ASSET_TYPE_CREDIT_ALPHANUM12)
{
assetCodeToStr(asset.alphaNum12().assetCode, assetCode);
assetIssuer = KeyUtils::toStrKey(asset.alphaNum12().issuer);
}
else
{
throw std::runtime_error("Invalid asset type");
}
auto prep = mDatabase.getPreparedStatement(sql);
auto& st = prep.statement();
st.exchange(soci::use(accountStr, "acc"));
st.exchange(soci::use(assetCode, "code"));
st.exchange(soci::use(assetIssuer, "iss"));
std::vector<LedgerEntry> offers;
{
auto timer = mDatabase.getSelectTimer("offer");
offers = loadOffers(prep);
}
return offers;
}
示例5: if
TrustFrame::pointer
TrustFrame::createIssuerFrame(Asset const& issuer)
{
pointer res = make_shared<TrustFrame>();
res->mIsIssuer = true;
TrustLineEntry& tl = res->mEntry.data.trustLine();
if (issuer.type() == ASSET_TYPE_CREDIT_ALPHANUM4)
{
tl.accountID = issuer.alphaNum4().issuer;
}
else if (issuer.type() == ASSET_TYPE_CREDIT_ALPHANUM12)
{
tl.accountID = issuer.alphaNum12().issuer;
}
tl.flags |= AUTHORIZED_FLAG;
tl.balance = INT64_MAX;
tl.asset = issuer;
tl.limit = INT64_MAX;
return res;
}
示例6:
bool
compareAsset(Asset const& first, Asset const& second)
{
if (first.type() != second.type())
return false;
if (first.type() == ASSET_TYPE_NATIVE)
return true;
if (second.type() == ASSET_TYPE_CREDIT_ALPHANUM4)
{
if ((first.alphaNum4().issuer == second.alphaNum4().issuer) &&
(first.alphaNum4().assetCode == second.alphaNum4().assetCode))
return true;
}
if (second.type() == ASSET_TYPE_CREDIT_ALPHANUM12)
{
if ((first.alphaNum12().issuer == second.alphaNum12().issuer) &&
(first.alphaNum12().assetCode == second.alphaNum12().assetCode))
return true;
}
return false;
}
示例7: if
bool
AllowTrustOpFrame::doCheckValid(Application& app)
{
if (mAllowTrust.asset.type() == ASSET_TYPE_NATIVE)
{
app.getMetrics()
.NewMeter({"op-allow-trust", "invalid", "malformed-non-alphanum"},
"operation")
.Mark();
innerResult().code(ALLOW_TRUST_MALFORMED);
return false;
}
Asset ci;
ci.type(mAllowTrust.asset.type());
if (mAllowTrust.asset.type() == ASSET_TYPE_CREDIT_ALPHANUM4)
{
ci.alphaNum4().assetCode = mAllowTrust.asset.assetCode4();
ci.alphaNum4().issuer = getSourceID();
}
else if (mAllowTrust.asset.type() == ASSET_TYPE_CREDIT_ALPHANUM12)
{
ci.alphaNum12().assetCode = mAllowTrust.asset.assetCode12();
ci.alphaNum12().issuer = getSourceID();
}
if (!isAssetValid(ci))
{
app.getMetrics()
.NewMeter({"op-allow-trust", "invalid", "malformed-invalid-asset"},
"operation")
.Mark();
innerResult().code(ALLOW_TRUST_MALFORMED);
return false;
}
return true;
}
示例8: if
void
OfferFrame::loadBestOffers(size_t numOffers, size_t offset,
Asset const& selling, Asset const& buying,
vector<OfferFrame::pointer>& retOffers, Database& db)
{
std::string sql = offerColumnSelector;
std::string sellingAssetCode, sellingIssuerStrKey;
std::string buyingAssetCode, buyingIssuerStrKey;
bool useSellingAsset = false;
bool useBuyingAsset = false;
if (selling.type() == ASSET_TYPE_NATIVE)
{
sql += " WHERE sellingassettype = 0";
}
else
{
if (selling.type() == ASSET_TYPE_CREDIT_ALPHANUM4)
{
assetCodeToStr(selling.alphaNum4().assetCode, sellingAssetCode);
sellingIssuerStrKey =
PubKeyUtils::toStrKey(selling.alphaNum4().issuer);
}
else if (selling.type() == ASSET_TYPE_CREDIT_ALPHANUM12)
{
assetCodeToStr(selling.alphaNum12().assetCode, sellingAssetCode);
sellingIssuerStrKey =
PubKeyUtils::toStrKey(selling.alphaNum12().issuer);
}
else
{
throw std::runtime_error("unknown asset type");
}
useSellingAsset = true;
sql += " WHERE sellingassetcode = :pcur AND sellingissuer = :pi";
}
if (buying.type() == ASSET_TYPE_NATIVE)
{
sql += " AND buyingassettype = 0";
}
else
{
if (buying.type() == ASSET_TYPE_CREDIT_ALPHANUM4)
{
assetCodeToStr(buying.alphaNum4().assetCode, buyingAssetCode);
buyingIssuerStrKey =
PubKeyUtils::toStrKey(buying.alphaNum4().issuer);
}
else if (buying.type() == ASSET_TYPE_CREDIT_ALPHANUM12)
{
assetCodeToStr(buying.alphaNum12().assetCode, buyingAssetCode);
buyingIssuerStrKey =
PubKeyUtils::toStrKey(buying.alphaNum12().issuer);
}
else
{
throw std::runtime_error("unknown asset type");
}
useBuyingAsset = true;
sql += " AND buyingassetcode = :gcur AND buyingissuer = :gi";
}
// price is an approximation of the actual n/d (truncated math, 15 digits)
// ordering by offerid gives precendence to older offers for fairness
sql += " ORDER BY price, offerid LIMIT :n OFFSET :o";
auto prep = db.getPreparedStatement(sql);
auto& st = prep.statement();
if (useSellingAsset)
{
st.exchange(use(sellingAssetCode));
st.exchange(use(sellingIssuerStrKey));
}
if (useBuyingAsset)
{
st.exchange(use(buyingAssetCode));
st.exchange(use(buyingIssuerStrKey));
}
st.exchange(use(numOffers));
st.exchange(use(offset));
auto timer = db.getSelectTimer("offer");
loadOffers(prep, [&retOffers](LedgerEntry const& of)
{
retOffers.emplace_back(make_shared<OfferFrame>(of));
});
}
示例9: oe
bool
PathPaymentOpFrame::doApply(medida::MetricsRegistry& metrics,
LedgerDelta& delta, LedgerManager& ledgerManager)
{
Database& db = ledgerManager.getDatabase();
innerResult().code(PATH_PAYMENT_SUCCESS);
// tracks the last amount that was traded
int64_t curBReceived = mPathPayment.destAmount;
Asset curB = mPathPayment.destAsset;
// update balances, walks backwards
// build the full path to the destination, starting with sendAsset
std::vector<Asset> fullPath;
fullPath.emplace_back(mPathPayment.sendAsset);
fullPath.insert(fullPath.end(), mPathPayment.path.begin(),
mPathPayment.path.end());
bool bypassIssuerCheck = false;
// if the payment doesn't involve intermediate accounts
// and the destination is the issuer we don't bother
// checking if the destination account even exist
// so that it's always possible to send credits back to its issuer
bypassIssuerCheck = (curB.type() != ASSET_TYPE_NATIVE) &&
(fullPath.size() == 1) &&
(mPathPayment.sendAsset == mPathPayment.destAsset) &&
(getIssuer(curB) == mPathPayment.destination);
AccountFrame::pointer destination;
if (!bypassIssuerCheck)
{
destination = AccountFrame::loadAccount(mPathPayment.destination, db);
if (!destination)
{
metrics.NewMeter({"op-path-payment", "failure", "no-destination"},
"operation").Mark();
innerResult().code(PATH_PAYMENT_NO_DESTINATION);
return false;
}
}
// update last balance in the chain
if (curB.type() == ASSET_TYPE_NATIVE)
{
destination->getAccount().balance += curBReceived;
destination->storeChange(delta, db);
}
else
{
TrustFrame::pointer destLine;
if (bypassIssuerCheck)
{
destLine =
TrustFrame::loadTrustLine(mPathPayment.destination, curB, db);
}
else
{
auto tlI = TrustFrame::loadTrustLineIssuer(mPathPayment.destination,
curB, db);
if (!tlI.second)
{
metrics.NewMeter({"op-path-payment", "failure", "no-issuer"},
"operation").Mark();
innerResult().code(PATH_PAYMENT_NO_ISSUER);
innerResult().noIssuer() = curB;
return false;
}
destLine = tlI.first;
}
if (!destLine)
{
metrics.NewMeter({"op-path-payment", "failure", "no-trust"},
"operation").Mark();
innerResult().code(PATH_PAYMENT_NO_TRUST);
return false;
}
if (!destLine->isAuthorized())
{
metrics.NewMeter({"op-path-payment", "failure", "not-authorized"},
"operation").Mark();
innerResult().code(PATH_PAYMENT_NOT_AUTHORIZED);
return false;
}
if (!destLine->addBalance(curBReceived))
{
metrics.NewMeter({"op-path-payment", "failure", "line-full"},
"operation").Mark();
innerResult().code(PATH_PAYMENT_LINE_FULL);
return false;
}
//.........这里部分代码省略.........
示例10: if
bool
isAssetValid(Asset const& cur)
{
if (cur.type() == ASSET_TYPE_NATIVE)
return true;
auto& loc = std::locale::classic();
if (cur.type() == ASSET_TYPE_CREDIT_ALPHANUM4)
{
auto const& code = cur.alphaNum4().assetCode;
bool zeros = false;
bool onechar = false; // at least one non zero character
for (uint8_t b : code)
{
if (b == 0)
{
zeros = true;
}
else if (zeros)
{
// zeros can only be trailing
return false;
}
else
{
if (b > 0x7F || !std::isalnum((char)b, loc))
{
return false;
}
onechar = true;
}
}
return onechar;
}
if (cur.type() == ASSET_TYPE_CREDIT_ALPHANUM12)
{
auto const& code = cur.alphaNum12().assetCode;
bool zeros = false;
int charcount = 0; // at least 5 non zero characters
for (uint8_t b : code)
{
if (b == 0)
{
zeros = true;
}
else if (zeros)
{
// zeros can only be trailing
return false;
}
else
{
if (b > 0x7F || !std::isalnum((char)b, loc))
{
return false;
}
charcount++;
}
}
return charcount > 4;
}
return false;
}
示例11: runtime_error
bool
PathPaymentOpFrame::doApply(Application& app, AbstractLedgerState& ls)
{
innerResult().code(PATH_PAYMENT_SUCCESS);
// tracks the last amount that was traded
int64_t curBReceived = mPathPayment.destAmount;
Asset curB = mPathPayment.destAsset;
// update balances, walks backwards
// build the full path to the destination, starting with sendAsset
std::vector<Asset> fullPath;
fullPath.emplace_back(mPathPayment.sendAsset);
fullPath.insert(fullPath.end(), mPathPayment.path.begin(),
mPathPayment.path.end());
bool bypassIssuerCheck = false;
// if the payment doesn't involve intermediate accounts
// and the destination is the issuer we don't bother
// checking if the destination account even exist
// so that it's always possible to send credits back to its issuer
bypassIssuerCheck = (curB.type() != ASSET_TYPE_NATIVE) &&
(fullPath.size() == 1) &&
(mPathPayment.sendAsset == mPathPayment.destAsset) &&
(getIssuer(curB) == mPathPayment.destination);
bool doesSourceAccountExist = true;
if (ls.loadHeader().current().ledgerVersion < 8)
{
doesSourceAccountExist =
(bool)stellar::loadAccountWithoutRecord(ls, getSourceID());
}
if (!bypassIssuerCheck)
{
if (!stellar::loadAccountWithoutRecord(ls, mPathPayment.destination))
{
app.getMetrics()
.NewMeter({"op-path-payment", "failure", "no-destination"},
"operation")
.Mark();
innerResult().code(PATH_PAYMENT_NO_DESTINATION);
return false;
}
}
// update last balance in the chain
if (curB.type() == ASSET_TYPE_NATIVE)
{
auto destination = stellar::loadAccount(ls, mPathPayment.destination);
if (!addBalance(ls.loadHeader(), destination, curBReceived))
{
app.getMetrics()
.NewMeter({"op-path-payment", "invalid", "balance-overflow"},
"operation")
.Mark();
innerResult().code(PATH_PAYMENT_MALFORMED);
return false;
}
}
else
{
if (!bypassIssuerCheck)
{
auto issuer =
stellar::loadAccountWithoutRecord(ls, getIssuer(curB));
if (!issuer)
{
app.getMetrics()
.NewMeter({"op-path-payment", "failure", "no-issuer"},
"operation")
.Mark();
innerResult().code(PATH_PAYMENT_NO_ISSUER);
innerResult().noIssuer() = curB;
return false;
}
}
auto destLine =
stellar::loadTrustLine(ls, mPathPayment.destination, curB);
if (!destLine)
{
app.getMetrics()
.NewMeter({"op-path-payment", "failure", "no-trust"},
"operation")
.Mark();
innerResult().code(PATH_PAYMENT_NO_TRUST);
return false;
}
if (!destLine.isAuthorized())
{
app.getMetrics()
.NewMeter({"op-path-payment", "failure", "not-authorized"},
"operation")
.Mark();
innerResult().code(PATH_PAYMENT_NOT_AUTHORIZED);
return false;
//.........这里部分代码省略.........
示例12: runtime_error
TrustFrame::pointer
TrustFrame::loadTrustLine(AccountID const& accountID, Asset const& asset,
Database& db)
{
if (asset.type() == ASSET_TYPE_NATIVE)
{
throw std::runtime_error("XLM TrustLine?");
}
else
{
if (accountID == getIssuer(asset))
{
return createIssuerFrame(asset);
}
}
LedgerKey key;
key.type(TRUSTLINE);
key.trustLine().accountID = accountID;
key.trustLine().asset = asset;
if (cachedEntryExists(key, db))
{
auto p = getCachedEntry(key, db);
return p ? std::make_shared<TrustFrame>(*p) : nullptr;
}
std::string accStr, issuerStr, assetStr;
accStr = PubKeyUtils::toStrKey(accountID);
if (asset.type() == ASSET_TYPE_CREDIT_ALPHANUM4)
{
assetCodeToStr(asset.alphaNum4().assetCode, assetStr);
issuerStr = PubKeyUtils::toStrKey(asset.alphaNum4().issuer);
}
else if (asset.type() == ASSET_TYPE_CREDIT_ALPHANUM12)
{
assetCodeToStr(asset.alphaNum12().assetCode, assetStr);
issuerStr = PubKeyUtils::toStrKey(asset.alphaNum12().issuer);
}
auto query = std::string(trustLineColumnSelector);
query += (" WHERE accountid = :id "
" AND issuer = :issuer "
" AND assetcode = :asset");
auto prep = db.getPreparedStatement(query);
auto& st = prep.statement();
st.exchange(use(accStr));
st.exchange(use(issuerStr));
st.exchange(use(assetStr));
pointer retLine;
auto timer = db.getSelectTimer("trust");
loadLines(prep, [&retLine](LedgerEntry const& trust)
{
retLine = make_shared<TrustFrame>(trust);
});
if (retLine)
{
retLine->putCachedEntry(db);
}
else
{
putCachedEntry(key, nullptr, db);
}
return retLine;
}
示例13: assetCodeToStr
void
OfferFrame::loadBestOffers(size_t numOffers, size_t offset,
Asset const& selling, Asset const& buying,
vector<OfferFrame::pointer>& retOffers, Database& db)
{
soci::session& session = db.getSession();
soci::details::prepare_temp_type sql =
(session.prepare << offerColumnSelector);
std::string sellingAssetCode, sellingIssuerStrKey;
std::string buyingAssetCode, buyingIssuerStrKey;
if (selling.type() == ASSET_TYPE_NATIVE)
{
sql << " WHERE sellingassettype=0";
}
else
{
if(selling.type() == ASSET_TYPE_CREDIT_ALPHANUM4)
{
assetCodeToStr(selling.alphaNum4().assetCode, sellingAssetCode);
sellingIssuerStrKey = PubKeyUtils::toStrKey(selling.alphaNum4().issuer);
} else if(selling.type() == ASSET_TYPE_CREDIT_ALPHANUM12)
{
assetCodeToStr(selling.alphaNum12().assetCode, sellingAssetCode);
sellingIssuerStrKey = PubKeyUtils::toStrKey(selling.alphaNum12().issuer);
}else throw std::runtime_error("unknown asset type");
sql << " WHERE sellingassetcode=:pcur AND sellingissuer = :pi",
use(sellingAssetCode), use(sellingIssuerStrKey);
}
if (buying.type() == ASSET_TYPE_NATIVE)
{
sql << " AND buyingassettype=0";
}
else
{
if(buying.type() == ASSET_TYPE_CREDIT_ALPHANUM4)
{
assetCodeToStr(buying.alphaNum4().assetCode, buyingAssetCode);
buyingIssuerStrKey = PubKeyUtils::toStrKey(buying.alphaNum4().issuer);
} else if(buying.type() == ASSET_TYPE_CREDIT_ALPHANUM12)
{
assetCodeToStr(buying.alphaNum12().assetCode, buyingAssetCode);
buyingIssuerStrKey = PubKeyUtils::toStrKey(buying.alphaNum12().issuer);
}else throw std::runtime_error("unknown asset type");
sql << " AND buyingassetcode=:gcur AND buyingissuer = :gi",
use(buyingAssetCode), use(buyingIssuerStrKey);
}
sql << " ORDER BY price,offerid LIMIT :n OFFSET :o", use(numOffers),
use(offset);
auto timer = db.getSelectTimer("offer");
loadOffers(sql, [&retOffers](LedgerEntry const& of)
{
retOffers.emplace_back(make_shared<OfferFrame>(of));
});
}
示例14: oe
bool
PathPaymentOpFrame::doApply(medida::MetricsRegistry& metrics,
LedgerDelta& delta, LedgerManager& ledgerManager)
{
AccountFrame::pointer destination;
Database& db = ledgerManager.getDatabase();
destination = AccountFrame::loadAccount(mPathPayment.destination, db);
if (!destination)
{
metrics.NewMeter({"op-path-payment", "failure", "no-destination"},
"operation").Mark();
innerResult().code(PATH_PAYMENT_NO_DESTINATION);
return false;
}
innerResult().code(PATH_PAYMENT_SUCCESS);
// tracks the last amount that was traded
int64_t curBReceived = mPathPayment.destAmount;
Asset curB = mPathPayment.destAsset;
// update balances, walks backwards
// build the full path to the destination, starting with sendAsset
std::vector<Asset> fullPath;
fullPath.emplace_back(mPathPayment.sendAsset);
fullPath.insert(fullPath.end(), mPathPayment.path.begin(),
mPathPayment.path.end());
// update last balance in the chain
{
if (curB.type() == ASSET_TYPE_NATIVE)
{
destination->getAccount().balance += curBReceived;
destination->storeChange(delta, db);
}
else
{
TrustFrame::pointer destLine;
destLine =
TrustFrame::loadTrustLine(destination->getID(), curB, db);
if (!destLine)
{
metrics.NewMeter({"op-path-payment", "failure", "no-trust"},
"operation").Mark();
innerResult().code(PATH_PAYMENT_NO_TRUST);
return false;
}
if (!destLine->isAuthorized())
{
metrics.NewMeter(
{"op-path-payment", "failure", "not-authorized"},
"operation").Mark();
innerResult().code(PATH_PAYMENT_NOT_AUTHORIZED);
return false;
}
if (!destLine->addBalance(curBReceived))
{
metrics.NewMeter({"op-path-payment", "failure", "line-full"},
"operation").Mark();
innerResult().code(PATH_PAYMENT_LINE_FULL);
return false;
}
destLine->storeChange(delta, db);
}
innerResult().success().last =
SimplePaymentResult(destination->getID(), curB, curBReceived);
}
// now, walk the path backwards
for (int i = (int)fullPath.size() - 1; i >= 0; i--)
{
int64_t curASent, actualCurBReceived;
Asset const& curA = fullPath[i];
if (curA == curB)
{
continue;
}
OfferExchange oe(delta, ledgerManager);
// curA -> curB
OfferExchange::ConvertResult r =
oe.convertWithOffers(curA, INT64_MAX, curASent, curB, curBReceived,
actualCurBReceived, nullptr);
switch (r)
{
case OfferExchange::eFilterStop:
assert(false); // no filter -> should not happen
break;
case OfferExchange::eOK:
//.........这里部分代码省略.........