本文整理汇总了C++中STAmount::getNValue方法的典型用法代码示例。如果您正苦于以下问题:C++ STAmount::getNValue方法的具体用法?C++ STAmount::getNValue怎么用?C++ STAmount::getNValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类STAmount
的用法示例。
在下文中一共展示了STAmount::getNValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: applyTransaction
TER TransactionEngine::applyTransaction (
STTx const& txn,
TransactionEngineParams params,
bool& didApply)
{
WriteLog (lsTRACE, TransactionEngine) << "applyTransaction>";
didApply = false;
assert (mLedger);
uint256 const& txID = txn.getTransactionID ();
mNodes.init (mLedger, txID, mLedger->getLedgerSeq (), params);
#ifdef BEAST_DEBUG
if (1)
{
Serializer ser;
txn.add (ser);
SerializerIterator sit (ser);
STTx s2 (sit);
if (!s2.isEquivalent (txn))
{
WriteLog (lsFATAL, TransactionEngine) <<
"Transaction serdes mismatch";
WriteLog (lsINFO, TransactionEngine) << txn.getJson (0);
WriteLog (lsFATAL, TransactionEngine) << s2.getJson (0);
assert (false);
}
}
#endif
if (!txID)
{
WriteLog (lsWARNING, TransactionEngine) <<
"applyTransaction: invalid transaction id";
return temINVALID;
}
TER terResult = Transactor::transact (txn, params, this);
if (terResult == temUNKNOWN)
{
WriteLog (lsWARNING, TransactionEngine) <<
"applyTransaction: Invalid transaction: unknown transaction type";
return temUNKNOWN;
}
if (ShouldLog (lsDEBUG, TransactionEngine))
{
std::string strToken;
std::string strHuman;
transResultInfo (terResult, strToken, strHuman);
WriteLog (lsDEBUG, TransactionEngine) <<
"applyTransaction: terResult=" << strToken <<
" : " << terResult <<
" : " << strHuman;
}
if (isTesSuccess (terResult))
didApply = true;
else if (isTecClaim (terResult) && !(params & tapRETRY))
{
// only claim the transaction fee
WriteLog (lsDEBUG, TransactionEngine) << "Reprocessing to only claim fee";
mNodes.clear ();
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;
//.........这里部分代码省略.........
示例2: doApply
//.........这里部分代码省略.........
}
else if (bSTRDirect && bLimitQuality)
{
m_journal.trace <<
"Malformed transaction: Limit quality specified for STR to STR.";
return temBAD_SEND_STR_LIMIT;
}
else if (bSTRDirect && bNoRippleDirect)
{
m_journal.trace <<
"Malformed transaction: No ripple direct specified for STR to STR.";
return temBAD_SEND_STR_NO_DIRECT;
}
SLE::pointer sleDst (mEngine->entryCache (
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uDstAccountID)));
if (!sleDst)
{
// Destination account does not exist.
if (!saDstAmount.isNative ())
{
m_journal.trace <<
"Delay transaction: Destination account does not exist.";
// Another transaction could create the account and then this transaction would succeed.
return tecNO_DST;
}
// Note: Reserve is not scaled by load.
else if (saDstAmount.getNValue () < mEngine->getLedger ()->getReserve (0))
{
m_journal.trace <<
"Delay transaction: Destination account does not exist. " <<
"Insufficient payment to create account.";
// Another transaction could create the account and then this
// transaction would succeed.
return tecNO_DST_INSUF_STR;
}
// Create the account.
sleDst = mEngine->entryCreate (
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uDstAccountID));
sleDst->setFieldAccount (sfAccount, uDstAccountID);
sleDst->setFieldU32 (sfSequence, 1);
}
else if ((sleDst->getFlags () & lsfRequireDestTag) && !mTxn.isFieldPresent (sfDestinationTag))
{
m_journal.trace <<
"Malformed transaction: DestinationTag required.";
return tefDST_TAG_NEEDED;
}
else
{
mEngine->entryModify (sleDst);
}
TER terResult;
// XXX Should bMax be sufficient to imply ripple?
bool const bRipple = bPaths || bMax || !saDstAmount.isNative ();
示例3: doApply
//.........这里部分代码省略.........
return temBAD_SEND_XRP_NO_DIRECT;
}
//
// Open a ledger for editing.
auto const index = getAccountRootIndex (uDstAccountID);
SLE::pointer sleDst (mEngine->entryCache (ltACCOUNT_ROOT, index));
if (!sleDst)
{
// Destination account does not exist.
if (!saDstAmount.isNative ())
{
m_journal.trace <<
"Delay transaction: Destination account does not exist.";
// Another transaction could create the account and then this
// transaction would succeed.
return tecNO_DST;
}
else if (mParams & tapOPEN_LEDGER && partialPaymentAllowed)
{
// You cannot fund an account with a partial payment.
// Make retry work smaller, by rejecting this.
m_journal.trace <<
"Delay transaction: Partial payment not allowed to create account.";
// Another transaction could create the account and then this
// transaction would succeed.
return telNO_DST_PARTIAL;
}
else if (saDstAmount.getNValue () < mEngine->getLedger ()->getReserve (0))
{
// getReserve() is the minimum amount that an account can have.
// Reserve is not scaled by load.
m_journal.trace <<
"Delay transaction: Destination account does not exist. " <<
"Insufficent payment to create account.";
// TODO: dedupe
// Another transaction could create the account and then this
// transaction would succeed.
return tecNO_DST_INSUF_XRP;
}
// Create the account.
auto const newIndex = getAccountRootIndex (uDstAccountID);
sleDst = mEngine->entryCreate (ltACCOUNT_ROOT, newIndex);
sleDst->setFieldAccount (sfAccount, uDstAccountID);
sleDst->setFieldU32 (sfSequence, 1);
}
else if ((sleDst->getFlags () & lsfRequireDestTag) &&
!mTxn.isFieldPresent (sfDestinationTag))
{
// The tag is basically account-specific information we don't
// understand, but we can require someone to fill it in.
// We didn't make this test for a newly-formed account because there's
// no way for this field to be set.
m_journal.trace << "Malformed transaction: DestinationTag required.";
return tefDST_TAG_NEEDED;
}
else
示例4: autofill_fee
/** Fill in the fee on behalf of the client.
This is called when the client does not explicitly specify the fee.
The client may also put a ceiling on the amount of the fee. This ceiling
is expressed as a multiplier based on the current ledger's fee schedule.
JSON fields
"Fee" The fee paid by the transaction. Omitted when the client
wants the fee filled in.
"fee_mult_max" A multiplier applied to the current ledger's transaction
fee that caps the maximum the fee server should auto fill.
If this optional field is not specified, then a default
multiplier is used.
@param tx The JSON corresponding to the transaction to fill in
@param ledger A ledger for retrieving the current fee schedule
@param result A JSON object for injecting error results, if any
@param admin `true` if this is called by an administrative endpoint.
*/
static void autofill_fee (
Json::Value& request,
RPCDetail::LedgerFacade& ledgerFacade,
Json::Value& result,
bool admin)
{
Json::Value& tx (request["tx_json"]);
if (tx.isMember ("Fee"))
return;
std::uint64_t feeByTrans = 0;
if (tx.isMember("TransactionType") && tx["TransactionType"].asString() == "Payment")
{
if (!tx.isMember("Destination"))
{
RPC::inject_error (rpcINVALID_PARAMS, "no destination account", result);
return;
}
Config d;
std::string dstAccountID = tx["Destination"].asString();
RippleAddress dstAddress;
if (!dstAddress.setAccountID(dstAccountID))
{
RPC::inject_error (rpcINVALID_PARAMS, "invalid account id", result);
return;
}
//dst account not exist yet, charge a fix amount of fee(0.01) for creating
if (!ledgerFacade.isAccountExist(dstAddress.getAccountID()))
{
feeByTrans = d.FEE_DEFAULT_CREATE;
}
//if currency is native(VRP/VBC), charge 1/1000 of transfer amount,
//otherwise charge a fix amount of fee(0.001)
if (tx.isMember("Amount"))
{
STAmount amount;
if (!amountFromJsonNoThrow(amount, tx["Amount"]))
{
RPC::inject_error (rpcINVALID_PARAMS, "wrong amount format", result);
return;
}
feeByTrans += amount.isNative() ? amount.getNValue() * d.FEE_DEFAULT_RATE_NATIVE : d.FEE_DEFAULT_NONE_NATIVE;
}
}
int mult = Tuning::defaultAutoFillFeeMultiplier;
if (request.isMember ("fee_mult_max"))
{
if (request["fee_mult_max"].isNumeric ())
{
mult = request["fee_mult_max"].asInt();
}
else
{
RPC::inject_error (rpcHIGH_FEE, RPC::expected_field_message (
"fee_mult_max", "a number"), result);
return;
}
}
// Default fee in fee units.
std::uint64_t const feeDefault = getConfig().TRANSACTION_FEE_BASE;
// Administrative endpoints are exempt from local fees.
std::uint64_t const fee = ledgerFacade.scaleFeeLoad (feeDefault, admin);
std::uint64_t const limit = mult * ledgerFacade.scaleFeeBase (feeDefault);
if (fee > limit)
{
std::stringstream ss;
ss <<
"Fee of " << fee <<
" exceeds the requested tx limit of " << limit;
RPC::inject_error (rpcHIGH_FEE, ss.str(), result);
return;
}
std::stringstream ss;
//.........这里部分代码省略.........