本文整理汇总了C++中sle::pointer::setFieldAmount方法的典型用法代码示例。如果您正苦于以下问题:C++ pointer::setFieldAmount方法的具体用法?C++ pointer::setFieldAmount怎么用?C++ pointer::setFieldAmount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sle::pointer
的用法示例。
在下文中一共展示了pointer::setFieldAmount方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doApply
//.........这里部分代码省略.........
const uint64 uReserveCreate = (uOwnerCount < 2) ? 0 : mEngine->getLedger ()->getReserve (uOwnerCount + 1);
STAmount saLimitAllow = saLimitAmount;
saLimitAllow.setIssuer (mTxnAccountID);
SLE::pointer sleRippleState = mEngine->entryCache (ltRIPPLE_STATE, Ledger::getRippleStateIndex (mTxnAccountID, uDstAccountID, uCurrencyID));
if (sleRippleState)
{
STAmount saLowBalance;
STAmount saLowLimit;
STAmount saHighBalance;
STAmount saHighLimit;
uint32 uLowQualityIn;
uint32 uLowQualityOut;
uint32 uHighQualityIn;
uint32 uHighQualityOut;
const uint160& uLowAccountID = !bHigh ? mTxnAccountID : uDstAccountID;
const uint160& uHighAccountID = bHigh ? mTxnAccountID : uDstAccountID;
SLE::ref sleLowAccount = !bHigh ? mTxnAccount : sleDst;
SLE::ref sleHighAccount = bHigh ? mTxnAccount : sleDst;
//
// Balances
//
saLowBalance = sleRippleState->getFieldAmount (sfBalance);
saHighBalance = -saLowBalance;
//
// Limits
//
sleRippleState->setFieldAmount (!bHigh ? sfLowLimit : sfHighLimit, saLimitAllow);
saLowLimit = !bHigh ? saLimitAllow : sleRippleState->getFieldAmount (sfLowLimit);
saHighLimit = bHigh ? saLimitAllow : sleRippleState->getFieldAmount (sfHighLimit);
//
// Quality in
//
if (!bQualityIn)
{
// Not setting. Just get it.
uLowQualityIn = sleRippleState->getFieldU32 (sfLowQualityIn);
uHighQualityIn = sleRippleState->getFieldU32 (sfHighQualityIn);
}
else if (uQualityIn)
{
// Setting.
sleRippleState->setFieldU32 (!bHigh ? sfLowQualityIn : sfHighQualityIn, uQualityIn);
uLowQualityIn = !bHigh ? uQualityIn : sleRippleState->getFieldU32 (sfLowQualityIn);
uHighQualityIn = bHigh ? uQualityIn : sleRippleState->getFieldU32 (sfHighQualityIn);
}
else
{
// Clearing.
sleRippleState->makeFieldAbsent (!bHigh ? sfLowQualityIn : sfHighQualityIn);
uLowQualityIn = !bHigh ? 0 : sleRippleState->getFieldU32 (sfLowQualityIn);
uHighQualityIn = bHigh ? 0 : sleRippleState->getFieldU32 (sfHighQualityIn);
示例2: doApply
//.........这里部分代码省略.........
terResult = telBAD_PATH_COUNT; // Too many paths for proposed ledger.
}
else
{
path::DivvyCalc::Output rc;
{
ScopedDeferCredits g (mEngine->view ());
rc = path::DivvyCalc::divvyCalculate (
mEngine->view (),
maxSourceAmount,
saDstAmount,
uDstAccountID,
mTxnAccountID,
spsPaths,
&rcInput);
}
// TODO: is this right? If the amount is the correct amount, was
// the delivered amount previously set?
if (rc.result () == tesSUCCESS && rc.actualAmountOut != saDstAmount)
mEngine->view ().setDeliveredAmount (rc.actualAmountOut);
terResult = rc.result ();
}
// TODO(tom): what's going on here?
if (isTerRetry (terResult))
terResult = tecPATH_DRY;
}
catch (std::exception const& e)
{
m_journal.trace <<
"Caught throw: " << e.what ();
terResult = tefEXCEPTION;
}
}
else
{
// Direct XDV payment.
// uOwnerCount is the number of entries in this legder for this
// account that require a reserve.
auto const uOwnerCount = mTxnAccount->getFieldU32 (sfOwnerCount);
// This is the total reserve in drops.
std::uint64_t const uReserve =
mEngine->getLedger ()->getReserve (uOwnerCount);
// mPriorBalance is the balance on the sending account BEFORE the
// fees were charged. We want to make sure we have enough reserve
// to send. Allow final spend to use reserve for fee.
auto const mmm = std::max(mTxn.getTransactionFee (),
STAmount (uReserve));
if (mPriorBalance < saDstAmount + mmm)
{
// Vote no. However the transaction might succeed, if applied in
// a different order.
m_journal.trace << "Delay transaction: Insufficient funds: " <<
" " << mPriorBalance.getText () <<
" / " << (saDstAmount + mmm).getText () <<
" (" << uReserve << ")";
terResult = tecUNFUNDED_PAYMENT;
}
else
{
// The source account does have enough money, so do the
// arithmetic for the transfer and make the ledger change.
mTxnAccount->setFieldAmount (sfBalance,
mSourceBalance - saDstAmount);
sleDst->setFieldAmount (sfBalance,
sleDst->getFieldAmount (sfBalance) + saDstAmount);
// Re-arm the password change fee if we can and need to.
if ((sleDst->getFlags () & lsfPasswordSpent))
sleDst->clearFlag (lsfPasswordSpent);
terResult = tesSUCCESS;
}
}
std::string strToken;
std::string strHuman;
if (transResultInfo (terResult, strToken, strHuman))
{
m_journal.trace <<
strToken << ": " << strHuman;
}
else
{
assert (false);
}
return terResult;
}
示例3: takeOffers
//.........这里部分代码省略.........
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saTakerPaid: " << saTakerPaid.getFullText ();
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saTakerFunds: " << saTakerFunds.getFullText ();
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saOfferFunds: " << saOfferFunds.getFullText ();
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saOfferPays: " << saOfferPays.getFullText ();
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saOfferGets: " << saOfferGets.getFullText ();
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saOfferRate: " << saOfferRate.getFullText ();
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saSubTakerPays: " << saSubTakerPays.getFullText ();
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saSubTakerGets: " << saSubTakerGets.getFullText ();
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saTakerPays: " << saTakerPays.getFullText ();
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saTakerGets: " << saTakerGets.getFullText ();
bool bOfferDelete = STAmount::applyOffer (
bSell,
lesActive.rippleTransferRate (uTakerAccountID, uOfferOwnerID, uTakerPaysAccountID),
lesActive.rippleTransferRate (uOfferOwnerID, uTakerAccountID, uTakerGetsAccountID),
saOfferRate,
saOfferFunds,
saTakerFunds,
saOfferPays,
saOfferGets,
saSubTakerPays,
saSubTakerGets,
saSubTakerPaid,
saSubTakerGot,
saTakerIssuerFee,
saOfferIssuerFee);
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saSubTakerPaid: " << saSubTakerPaid.getFullText ();
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saSubTakerGot: " << saSubTakerGot.getFullText ();
// Adjust offer
// Offer owner will pay less. Subtract what taker just got.
sleOffer->setFieldAmount (sfTakerGets, saOfferPays -= saSubTakerGot);
// Offer owner will get less. Subtract what owner just paid.
sleOffer->setFieldAmount (sfTakerPays, saOfferGets -= saSubTakerPaid);
mEngine->entryModify (sleOffer);
if (bOfferDelete)
{
// Offer now fully claimed or now unfunded.
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: Offer claimed: Delete.";
usOfferUnfundedBecame.insert (uOfferIndex); // Delete unfunded offer on success.
// Offer owner's account is no longer pristine.
usAccountTouched.insert (uOfferOwnerID);
}
else if (saSubTakerGot)
{
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: Offer partial claim.";
if (!saOfferPays.isPositive () || !saOfferGets.isPositive ())
{
WriteLog (lsWARNING, OfferCreateTransactor) << "takeOffers: ILLEGAL OFFER RESULT.";
bUnfunded = true;
terResult = bOpenLedger ? telFAILED_PROCESSING : tecFAILED_PROCESSING;
}
}
else
{
// Taker got nothing, probably due to rounding. Consider taker unfunded.
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: No claim.";
示例4: bPassive
//.........这里部分代码省略.........
std::uint64_t uOwnerNode;
std::uint64_t uBookNode;
uint256 uDirectory;
// Add offer to owner's directory.
terResult = view.dirAdd (uOwnerNode,
Ledger::getOwnerDirIndex (mTxnAccountID), uLedgerIndex,
std::bind (
&Ledger::ownerDirDescriber, std::placeholders::_1,
std::placeholders::_2, mTxnAccountID));
if (tesSUCCESS == terResult)
{
// Update owner count.
view.ownerCountAdjust (mTxnAccountID, 1, sleCreator);
uint256 const uBookBase (Ledger::getBookBase (
{{uPaysCurrency, uPaysIssuerID},
{uGetsCurrency, uGetsIssuerID}}));
if (m_journal.debug) m_journal.debug <<
"adding to book: " << to_string (uBookBase) <<
" : " << saTakerPays.getHumanCurrency () <<
"/" << to_string (saTakerPays.getIssuer ()) <<
" -> " << saTakerGets.getHumanCurrency () <<
"/" << to_string (saTakerGets.getIssuer ());
// We use the original rate to place the offer.
uDirectory = Ledger::getQualityIndex (uBookBase, uRate);
// Add offer to order book.
terResult = view.dirAdd (uBookNode, uDirectory, uLedgerIndex,
std::bind (
&Ledger::qualityDirDescriber, std::placeholders::_1,
std::placeholders::_2, saTakerPays.getCurrency (),
uPaysIssuerID, saTakerGets.getCurrency (),
uGetsIssuerID, uRate));
}
if (tesSUCCESS == terResult)
{
if (m_journal.debug)
{
m_journal.debug <<
"sfAccount=" <<
to_string (mTxnAccountID);
m_journal.debug <<
"uPaysIssuerID=" <<
to_string (uPaysIssuerID);
m_journal.debug <<
"uGetsIssuerID=" <<
to_string (uGetsIssuerID);
m_journal.debug <<
"saTakerPays.isNative()=" <<
saTakerPays.isNative ();
m_journal.debug <<
"saTakerGets.isNative()=" <<
saTakerGets.isNative ();
m_journal.debug <<
"uPaysCurrency=" <<
saTakerPays.getHumanCurrency ();
m_journal.debug <<
"uGetsCurrency=" <<
saTakerGets.getHumanCurrency ();
}
SLE::pointer sleOffer (mEngine->entryCreate (ltOFFER, uLedgerIndex));
sleOffer->setFieldAccount (sfAccount, mTxnAccountID);
sleOffer->setFieldU32 (sfSequence, uSequence);
sleOffer->setFieldH256 (sfBookDirectory, uDirectory);
sleOffer->setFieldAmount (sfTakerPays, saTakerPays);
sleOffer->setFieldAmount (sfTakerGets, saTakerGets);
sleOffer->setFieldU64 (sfOwnerNode, uOwnerNode);
sleOffer->setFieldU64 (sfBookNode, uBookNode);
if (uExpiration)
sleOffer->setFieldU32 (sfExpiration, uExpiration);
if (bPassive)
sleOffer->setFlag (lsfPassive);
if (bSell)
sleOffer->setFlag (lsfSell);
if (m_journal.debug) m_journal.debug <<
"final terResult=" << transToken (terResult) <<
" sleOffer=" << sleOffer->getJson (0);
}
}
if (terResult != tesSUCCESS)
{
m_journal.debug <<
"final terResult=" << transToken (terResult);
}
return terResult;
}
示例5: applyTransaction
//.........这里部分代码省略.........
SLE::pointer txnAcct = entryCache (ltACCOUNT_ROOT,
getAccountRootIndex (txn.getSourceAccount ()));
if (!txnAcct)
terResult = terNO_ACCOUNT;
else
{
std::uint32_t t_seq = txn.getSequence ();
std::uint32_t a_seq = txnAcct->getFieldU32 (sfSequence);
if (a_seq < t_seq)
terResult = terPRE_SEQ;
else if (a_seq > t_seq)
terResult = tefPAST_SEQ;
else
{
STAmount fee = txn.getTransactionFee ();
STAmount balance = txnAcct->getFieldAmount (sfBalance);
STAmount balanceVBC = txnAcct->getFieldAmount(sfBalanceVBC);
// We retry/reject the transaction if the account
// balance is zero or we're applying against an open
// ledger and the balance is less than the fee
if ((balance == zero) || (balanceVBC.getNValue() == 0) ||
((params & tapOPEN_LEDGER) && (balance < fee)))
{
// Account has no funds or ledger is open
terResult = terINSUF_FEE_B;
}
else
{
if (fee > balance)
fee = balance;
txnAcct->setFieldAmount (sfBalance, balance - fee);
txnAcct->setFieldAmount(sfBalanceVBC, balanceVBC);
txnAcct->setFieldU32 (sfSequence, t_seq + 1);
entryModify (txnAcct);
didApply = true;
}
}
}
}
else
WriteLog (lsDEBUG, TransactionEngine) << "Not applying transaction " << txID;
if (didApply)
{
if (!checkInvariants (terResult, txn, params))
{
WriteLog (lsFATAL, TransactionEngine) <<
"Transaction violates invariants";
WriteLog (lsFATAL, TransactionEngine) <<
txn.getJson (0);
WriteLog (lsFATAL, TransactionEngine) <<
transToken (terResult) << ": " << transHuman (terResult);
WriteLog (lsFATAL, TransactionEngine) <<
mNodes.getJson (0);
didApply = false;
terResult = tefINTERNAL;
}
else
{
// Transaction succeeded fully or (retries are not allowed and the
// transaction could claim a fee)
Serializer m;
mNodes.calcRawMeta (m, terResult, mTxnSeq++);
示例6: takeOffers
//.........这里部分代码省略.........
WriteLog (lsTRACE, OfferCreateTransactor) << "takeOffers: applyOffer: saTakerPaid: " << saTakerPaid.getFullText ();
WriteLog (lsTRACE, OfferCreateTransactor) << "takeOffers: applyOffer: saTakerFunds: " << saTakerFunds.getFullText ();
WriteLog (lsTRACE, OfferCreateTransactor) << "takeOffers: applyOffer: saOfferFunds: " << saOfferFunds.getFullText ();
WriteLog (lsTRACE, OfferCreateTransactor) << "takeOffers: applyOffer: saOfferPays: " << saOfferPays.getFullText ();
WriteLog (lsTRACE, OfferCreateTransactor) << "takeOffers: applyOffer: saOfferGets: " << saOfferGets.getFullText ();
WriteLog (lsTRACE, OfferCreateTransactor) << "takeOffers: applyOffer: saOfferRate: " << saOfferRate.getFullText ();
WriteLog (lsTRACE, OfferCreateTransactor) << "takeOffers: applyOffer: saSubTakerPays: " << saSubTakerPays.getFullText ();
WriteLog (lsTRACE, OfferCreateTransactor) << "takeOffers: applyOffer: saSubTakerGets: " << saSubTakerGets.getFullText ();
WriteLog (lsTRACE, OfferCreateTransactor) << "takeOffers: applyOffer: saTakerPays: " << saTakerPays.getFullText ();
WriteLog (lsTRACE, OfferCreateTransactor) << "takeOffers: applyOffer: saTakerGets: " << saTakerGets.getFullText ();
bool bOfferDelete = STAmount::applyOffer (
bSell,
lesActive.rippleTransferRate (uTakerAccountID, uOfferOwnerID, uTakerPaysAccountID),
lesActive.rippleTransferRate (uOfferOwnerID, uTakerAccountID, uTakerGetsAccountID),
saOfferRate,
saOfferFunds,
saTakerFunds,
saOfferPays,
saOfferGets,
saSubTakerPays,
saSubTakerGets,
saSubTakerPaid,
saSubTakerGot,
saTakerIssuerFee,
saOfferIssuerFee);
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saSubTakerPaid: " << saSubTakerPaid.getFullText ();
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: applyOffer: saSubTakerGot: " << saSubTakerGot.getFullText ();
// Adjust offer
// Offer owner will pay less. Subtract what taker just got.
sleOffer->setFieldAmount (sfTakerGets, saOfferPays -= saSubTakerGot);
// Offer owner will get less. Subtract what owner just paid.
sleOffer->setFieldAmount (sfTakerPays, saOfferGets -= saSubTakerPaid);
mEngine->entryModify (sleOffer);
if (bOfferDelete)
{
// Offer now fully claimed or now unfunded.
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: Offer claimed: Delete.";
usOfferUnfundedBecame.insert (sleOffer->getIndex()); // Delete unfunded offer on success.
// Offer owner's account is no longer pristine.
usAccountTouched.insert (uOfferOwnerID);
}
else if (saSubTakerGot)
{
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: Offer partial claim.";
if (!saOfferPays.isPositive () || !saOfferGets.isPositive ())
{
WriteLog (lsWARNING, OfferCreateTransactor) << "takeOffers: ILLEGAL OFFER RESULT.";
bUnfunded = true;
terResult = bOpenLedger ? telFAILED_PROCESSING : tecFAILED_PROCESSING;
}
}
else
{
// Taker got nothing, probably due to rounding. Consider taker unfunded.
WriteLog (lsDEBUG, OfferCreateTransactor) << "takeOffers: No claim.";
示例7: doApply
//.........这里部分代码省略.........
for (auto const& path : spsPaths)
if (path.size () > MaxPathLength)
pathTooBig = true;
if (rcInput.isLedgerOpen && pathTooBig)
{
terResult = telBAD_PATH_COUNT; // Too many paths for proposed ledger.
}
else
{
auto rc = path::RippleCalc::rippleCalculate (
mEngine->view (),
maxSourceAmount,
saDstAmount,
uDstAccountID,
mTxnAccountID,
spsPaths,
&rcInput);
// TODO: is this right? If the amount is the correct amount, was
// the delivered amount previously set?
if (rc.result () == tesSUCCESS && rc.actualAmountOut != saDstAmount)
mEngine->view ().setDeliveredAmount (rc.actualAmountOut);
terResult = rc.result ();
}
// TODO(tom): what's going on here?
if (isTerRetry (terResult))
terResult = tecPATH_DRY;
}
catch (std::exception const& e)
{
m_journal.trace <<
"Caught throw: " << e.what ();
terResult = tefEXCEPTION;
}
}
else
{
// Direct XRP payment.
// uOwnerCount is the number of entries in this legder for this account
// that require a reserve.
std::uint32_t const uOwnerCount (mTxnAccount->getFieldU32 (sfOwnerCount));
// This is the total reserve in drops.
// TODO(tom): there should be a class for this.
std::uint64_t const uReserve (mEngine->getLedger ()->getReserve (uOwnerCount));
// mPriorBalance is the balance on the sending account BEFORE the fees were charged.
//
// Make sure have enough reserve to send. Allow final spend to use
// reserve for fee.
auto const mmm = std::max(uReserve, mTxn.getTransactionFee ().getNValue ());
if (mPriorBalance < saDstAmount + mmm)
{
// Vote no.
// However, transaction might succeed, if applied in a different order.
m_journal.trace << "Delay transaction: Insufficient funds: " <<
" " << mPriorBalance.getText () <<
" / " << (saDstAmount + uReserve).getText () <<
" (" << uReserve << ")";
terResult = tecUNFUNDED_PAYMENT;
}
else
{
// The source account does have enough money, so do the arithmetic
// for the transfer and make the ledger change.
mTxnAccount->setFieldAmount (sfBalance, mSourceBalance - saDstAmount);
sleDst->setFieldAmount (sfBalance, sleDst->getFieldAmount (sfBalance) + saDstAmount);
// Re-arm the password change fee if we can and need to.
if ((sleDst->getFlags () & lsfPasswordSpent))
sleDst->clearFlag (lsfPasswordSpent);
terResult = tesSUCCESS;
}
}
std::string strToken;
std::string strHuman;
if (transResultInfo (terResult, strToken, strHuman))
{
m_journal.trace <<
strToken << ": " << strHuman;
}
else
{
assert (false);
}
return terResult;
}
示例8: doApply
//.........这里部分代码省略.........
STAmount saLimitAllow = saLimitAmount;
saLimitAllow.setIssuer (mTxnAccountID);
SLE::pointer sleRippleState (mEngine->entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (mTxnAccountID, uDstAccountID, currency)));
if (sleRippleState)
{
STAmount saLowBalance;
STAmount saLowLimit;
STAmount saHighBalance;
STAmount saHighLimit;
std::uint32_t uLowQualityIn;
std::uint32_t uLowQualityOut;
std::uint32_t uHighQualityIn;
std::uint32_t uHighQualityOut;
auto const& uLowAccountID = !bHigh ? mTxnAccountID : uDstAccountID;
auto const& uHighAccountID = bHigh ? mTxnAccountID : uDstAccountID;
SLE::ref sleLowAccount = !bHigh ? mTxnAccount : sleDst;
SLE::ref sleHighAccount = bHigh ? mTxnAccount : sleDst;
//
// Balances
//
saLowBalance = sleRippleState->getFieldAmount (sfBalance);
saHighBalance = -saLowBalance;
//
// Limits
//
sleRippleState->setFieldAmount (!bHigh ? sfLowLimit : sfHighLimit, saLimitAllow);
saLowLimit = !bHigh ? saLimitAllow : sleRippleState->getFieldAmount (sfLowLimit);
saHighLimit = bHigh ? saLimitAllow : sleRippleState->getFieldAmount (sfHighLimit);
//
// Quality in
//
if (!bQualityIn)
{
// Not setting. Just get it.
uLowQualityIn = sleRippleState->getFieldU32 (sfLowQualityIn);
uHighQualityIn = sleRippleState->getFieldU32 (sfHighQualityIn);
}
else if (uQualityIn)
{
// Setting.
sleRippleState->setFieldU32 (!bHigh ? sfLowQualityIn : sfHighQualityIn, uQualityIn);
uLowQualityIn = !bHigh ? uQualityIn : sleRippleState->getFieldU32 (sfLowQualityIn);
uHighQualityIn = bHigh ? uQualityIn : sleRippleState->getFieldU32 (sfHighQualityIn);
}
else
{
// Clearing.
sleRippleState->makeFieldAbsent (!bHigh ? sfLowQualityIn : sfHighQualityIn);
uLowQualityIn = !bHigh ? 0 : sleRippleState->getFieldU32 (sfLowQualityIn);
uHighQualityIn = bHigh ? 0 : sleRippleState->getFieldU32 (sfHighQualityIn);
示例9: saLimitAmount
//.........这里部分代码省略.........
STAmount saLimitAllow = saLimitAmount;
saLimitAllow.setIssuer (account_);
SLE::pointer sleRippleState = view().peek (
keylet::line(account_, uDstAccountID, currency));
if (sleRippleState)
{
STAmount saLowBalance;
STAmount saLowLimit;
STAmount saHighBalance;
STAmount saHighLimit;
std::uint32_t uLowQualityIn;
std::uint32_t uLowQualityOut;
std::uint32_t uHighQualityIn;
std::uint32_t uHighQualityOut;
auto const& uLowAccountID = !bHigh ? account_ : uDstAccountID;
auto const& uHighAccountID = bHigh ? account_ : uDstAccountID;
SLE::ref sleLowAccount = !bHigh ? sle : sleDst;
SLE::ref sleHighAccount = bHigh ? sle : sleDst;
//
// Balances
//
saLowBalance = sleRippleState->getFieldAmount (sfBalance);
saHighBalance = -saLowBalance;
//
// Limits
//
sleRippleState->setFieldAmount (!bHigh ? sfLowLimit : sfHighLimit, saLimitAllow);
saLowLimit = !bHigh ? saLimitAllow : sleRippleState->getFieldAmount (sfLowLimit);
saHighLimit = bHigh ? saLimitAllow : sleRippleState->getFieldAmount (sfHighLimit);
//
// Quality in
//
if (!bQualityIn)
{
// Not setting. Just get it.
uLowQualityIn = sleRippleState->getFieldU32 (sfLowQualityIn);
uHighQualityIn = sleRippleState->getFieldU32 (sfHighQualityIn);
}
else if (uQualityIn)
{
// Setting.
sleRippleState->setFieldU32 (!bHigh ? sfLowQualityIn : sfHighQualityIn, uQualityIn);
uLowQualityIn = !bHigh ? uQualityIn : sleRippleState->getFieldU32 (sfLowQualityIn);
uHighQualityIn = bHigh ? uQualityIn : sleRippleState->getFieldU32 (sfHighQualityIn);
}
else
{
// Clearing.
sleRippleState->makeFieldAbsent (!bHigh ? sfLowQualityIn : sfHighQualityIn);
uLowQualityIn = !bHigh ? 0 : sleRippleState->getFieldU32 (sfLowQualityIn);
uHighQualityIn = bHigh ? 0 : sleRippleState->getFieldU32 (sfHighQualityIn);
示例10: doApply
//.........这里部分代码省略.........
STPathSet spsPaths = mTxn.getFieldPathSet (sfPaths);
std::vector<PathState::pointer> vpsExpanded;
STAmount saMaxAmountAct;
STAmount saDstAmountAct;
try
{
bool const openLedger = is_bit_set (mParams, tapOPEN_LEDGER);
bool tooManyPaths = false;
if (spsPaths.size() > MAX_NUM_PATHS) tooManyPaths = true;
else
{
for (auto const& path : spsPaths)
{
if (path.size() > MAX_PATH_SIZE)
{
tooManyPaths = true;
break;
}
}
}
terResult = openLedger && tooManyPaths
? telBAD_PATH_COUNT // Too many paths for proposed ledger.
: RippleCalc::rippleCalc(
mEngine->view(),
saMaxAmountAct,
saDstAmountAct,
vpsExpanded,
saMaxAmount,
saDstAmount,
uDstAccountID,
mTxnAccountID,
spsPaths,
false,
bLimitQuality,
bNoRippleDirect, // Always compute for finalizing ledger.
false, // Not standalone, delete unfundeds.
is_bit_set(mParams, tapOPEN_LEDGER));
if (isTerRetry(terResult))
terResult = tecPATH_DRY;
if ((tesSUCCESS == terResult) && (saDstAmountAct != saDstAmount))
mEngine->view().setDeliveredAmount(saDstAmountAct);
}
catch (std::exception const& e)
{
m_journal.trace <<
"Caught throw: " << e.what ();
terResult = tefEXCEPTION;
}
}
else
{
// Direct STR payment.
std::uint32_t const uOwnerCount (mTxnAccount->getFieldU32 (sfOwnerCount));
std::uint64_t const uReserve (mEngine->getLedger ()->getReserve (uOwnerCount));
// Make sure have enough reserve to send. Allow final spend to use reserve for fee.
if (mPriorBalance < saDstAmount + std::max(uReserve, mTxn.getTransactionFee ().getNValue ()))
{
// Vote no. However, transaction might succeed, if applied in a different order.
m_journal.trace << "Delay transaction: Insufficient funds: " <<
" " << mPriorBalance.getText () <<
" / " << (saDstAmount + uReserve).getText () <<
" (" << uReserve << ")";
terResult = tecUNFUNDED_PAYMENT;
}
else
{
mTxnAccount->setFieldAmount (sfBalance, mSourceBalance - saDstAmount);
sleDst->setFieldAmount (sfBalance, sleDst->getFieldAmount (sfBalance) + saDstAmount);
terResult = tesSUCCESS;
}
}
std::string strToken;
std::string strHuman;
if (transResultInfo (terResult, strToken, strHuman))
{
m_journal.trace <<
strToken << ": " << strHuman;
}
else
{
assert (false);
}
return terResult;
}
示例11: doApply
TER WalletAddTransactor::doApply ()
{
std::uint32_t const uTxFlags = mTxn.getFlags ();
if (uTxFlags & tfUniversalMask)
{
m_journal.trace <<
"Malformed transaction: Invalid flags set.";
return temINVALID_FLAG;
}
Blob const vucPubKey = mTxn.getFieldVL (sfPublicKey);
Blob const vucSignature = mTxn.getFieldVL (sfSignature);
uint160 const uAuthKeyID (mTxn.getFieldAccount160 (sfRegularKey));
RippleAddress const naMasterPubKey (
RippleAddress::createAccountPublic (vucPubKey));
uint160 const uDstAccountID (naMasterPubKey.getAccountID ());
// FIXME: This should be moved to the transaction's signature check logic and cached
if (!naMasterPubKey.verifySignature(
Serializer::getSHA512Half (uAuthKeyID.begin (), uAuthKeyID.size ()),
vucSignature))
{
m_journal.trace <<
"Unauthorized: bad signature ";
return tefBAD_ADD_AUTH;
}
SLE::pointer sleDst (mEngine->entryCache (
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uDstAccountID)));
if (sleDst)
{
m_journal.trace <<
"account already created";
return tefCREATED;
}
// Direct STR payment.
STAmount saDstAmount = mTxn.getFieldAmount (sfAmount);
STAmount saPaid = mTxn.getTransactionFee ();
STAmount const saSrcBalance = mTxnAccount->getFieldAmount (sfBalance);
std::uint32_t const uOwnerCount = mTxnAccount->getFieldU32 (sfOwnerCount);
std::uint64_t const uReserve = mEngine->getLedger ()->getReserve (uOwnerCount);
// Make sure have enough reserve to send. Allow final spend to use reserve
// for fee.
// Note: Reserve is not scaled by fee.
if (saSrcBalance + saPaid < saDstAmount + uReserve)
{
// Vote no. However, transaction might succeed, if applied in a
// different order.
m_journal.trace <<
"Delay transaction: Insufficient funds: %s / %s (%d)" <<
saSrcBalance.getText () << " / " <<
(saDstAmount + uReserve).getText () << " with reserve = " <<
uReserve;
return tecUNFUNDED_ADD;
}
// Deduct initial balance from source account.
mTxnAccount->setFieldAmount (sfBalance, saSrcBalance - saDstAmount);
// Create the account.
sleDst = mEngine->entryCreate (ltACCOUNT_ROOT,
Ledger::getAccountRootIndex (uDstAccountID));
sleDst->setFieldAccount (sfAccount, uDstAccountID);
sleDst->setFieldU32 (sfSequence, 1);
sleDst->setFieldAmount (sfBalance, saDstAmount);
sleDst->setFieldAccount (sfRegularKey, uAuthKeyID);
return tesSUCCESS;
}