mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Reduce Transactor virtual interface
This commit is contained in:
@@ -34,17 +34,29 @@ Change::preflight (PreflightContext const& ctx)
|
|||||||
auto account = ctx.tx.getAccountID(sfAccount);
|
auto account = ctx.tx.getAccountID(sfAccount);
|
||||||
if (account != zero)
|
if (account != zero)
|
||||||
{
|
{
|
||||||
JLOG(ctx.j.warning) << "Bad source id";
|
JLOG(ctx.j.warning) << "Change: Bad source id";
|
||||||
return temBAD_SRC_ACCOUNT;
|
return temBAD_SRC_ACCOUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const fee = ctx.tx.getTransactionFee ();
|
auto const fee = ctx.tx.getTransactionFee ();
|
||||||
if (!fee.native () || fee != beast::zero)
|
if (!fee.native () || fee != beast::zero)
|
||||||
{
|
{
|
||||||
JLOG(ctx.j.warning) << "Non-zero fee";
|
JLOG(ctx.j.warning) << "Change: Non-zero fee";
|
||||||
return temBAD_FEE;
|
return temBAD_FEE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ctx.tx.getSigningPubKey ().empty () || !ctx.tx.getSignature ().empty ())
|
||||||
|
{
|
||||||
|
JLOG(ctx.j.warning) << "Change: Bad signature";
|
||||||
|
return temBAD_SIGNATURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx.tx.getSequence () != 0 || ctx.tx.isFieldPresent (sfPreviousTxnID))
|
||||||
|
{
|
||||||
|
JLOG(ctx.j.warning) << "Change: Bad sequence";
|
||||||
|
return temBAD_SEQUENCE;
|
||||||
|
}
|
||||||
|
|
||||||
return tesSUCCESS;
|
return tesSUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,42 +80,6 @@ Change::doApply()
|
|||||||
return temUNKNOWN;
|
return temUNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
TER
|
|
||||||
Change::checkSign()
|
|
||||||
{
|
|
||||||
if (!tx().getSigningPubKey ().empty () || !tx().getSignature ().empty ())
|
|
||||||
{
|
|
||||||
j_.warning << "Bad signature";
|
|
||||||
return temBAD_SIGNATURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tesSUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
TER
|
|
||||||
Change::checkSeq()
|
|
||||||
{
|
|
||||||
if ((tx().getSequence () != 0) || tx().isFieldPresent (sfPreviousTxnID))
|
|
||||||
{
|
|
||||||
j_.warning << "Bad sequence";
|
|
||||||
return temBAD_SEQUENCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tesSUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
TER
|
|
||||||
Change::payFee()
|
|
||||||
{
|
|
||||||
if (tx().getTransactionFee () != beast::zero)
|
|
||||||
{
|
|
||||||
j_.warning << "Non-zero fee";
|
|
||||||
return temBAD_FEE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tesSUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Change::preCompute()
|
Change::preCompute()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,9 +43,6 @@ public:
|
|||||||
preflight (PreflightContext const& ctx);
|
preflight (PreflightContext const& ctx);
|
||||||
|
|
||||||
TER doApply () override;
|
TER doApply () override;
|
||||||
TER checkSign () override;
|
|
||||||
TER checkSeq () override;
|
|
||||||
TER payFee () override;
|
|
||||||
void preCompute() override;
|
void preCompute() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -53,10 +50,9 @@ private:
|
|||||||
|
|
||||||
TER applyFee ();
|
TER applyFee ();
|
||||||
|
|
||||||
// VFALCO TODO Can this be removed?
|
std::uint64_t calculateBaseFee () override
|
||||||
bool mustHaveValidAccount () override
|
|
||||||
{
|
{
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -96,13 +96,6 @@ Transactor::Transactor(
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transactor::calculateFee ()
|
|
||||||
{
|
|
||||||
mFeeDue = STAmount (getApp().getFeeTrack().scaleFeeLoad(
|
|
||||||
calculateBaseFee(), view().fees().base,
|
|
||||||
view().fees().units, view().flags() & tapADMIN));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::uint64_t Transactor::calculateBaseFee ()
|
std::uint64_t Transactor::calculateBaseFee ()
|
||||||
{
|
{
|
||||||
// Returns the fee in fee units
|
// Returns the fee in fee units
|
||||||
@@ -113,22 +106,18 @@ TER Transactor::payFee ()
|
|||||||
{
|
{
|
||||||
STAmount saPaid = tx().getTransactionFee ();
|
STAmount saPaid = tx().getTransactionFee ();
|
||||||
|
|
||||||
if (!isLegalNet (saPaid))
|
if (!isLegalNet (saPaid) || saPaid < zero)
|
||||||
return temBAD_AMOUNT;
|
return temBAD_FEE;
|
||||||
|
|
||||||
// Only check fee is sufficient when the ledger is open.
|
// Only check fee is sufficient when the ledger is open.
|
||||||
if (view().open() && saPaid < mFeeDue)
|
if (view().open() && saPaid < mFeeDue)
|
||||||
{
|
{
|
||||||
JLOG(j_.trace) << "Insufficient fee paid: " <<
|
JLOG(j_.trace) << "Insufficient fee paid: " <<
|
||||||
saPaid.getText () << "/" << mFeeDue.getText ();
|
saPaid.getText () << "/" << mFeeDue.getText ();
|
||||||
|
|
||||||
return telINSUF_FEE_P;
|
return telINSUF_FEE_P;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saPaid < zero || !saPaid.native ())
|
if (saPaid == zero)
|
||||||
return temBAD_FEE;
|
|
||||||
|
|
||||||
if (!saPaid)
|
|
||||||
return tesSUCCESS;
|
return tesSUCCESS;
|
||||||
|
|
||||||
auto const sle = view().peek(
|
auto const sle = view().peek(
|
||||||
@@ -216,29 +205,26 @@ TER Transactor::apply ()
|
|||||||
{
|
{
|
||||||
preCompute();
|
preCompute();
|
||||||
|
|
||||||
// Find source account
|
// If the transactor requires a valid account and the transaction doesn't
|
||||||
|
// list one, preflight will have already a flagged a failure.
|
||||||
auto const sle = view().peek (keylet::account(account_));
|
auto const sle = view().peek (keylet::account(account_));
|
||||||
|
|
||||||
calculateFee ();
|
if (sle == nullptr && account_ != zero)
|
||||||
|
|
||||||
// If are only forwarding, due to resource limitations, we might verifying
|
|
||||||
// only some transactions, this would be probabilistic.
|
|
||||||
if (!sle)
|
|
||||||
{
|
{
|
||||||
if (mustHaveValidAccount ())
|
JLOG (j_.trace) <<
|
||||||
{
|
"apply: source account " << toBase58(account_) << " not found.";
|
||||||
JLOG(j_.trace) <<
|
|
||||||
"applyTransaction: delay: source account does not exist " <<
|
|
||||||
toBase58(tx().getAccountID(sfAccount));
|
|
||||||
return terNO_ACCOUNT;
|
return terNO_ACCOUNT;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
mFeeDue = STAmount (getApp().getFeeTrack().scaleFeeLoad(
|
||||||
|
calculateBaseFee(), view().fees().base,
|
||||||
|
view().fees().units, view().flags() & tapADMIN));
|
||||||
|
|
||||||
|
if (sle)
|
||||||
{
|
{
|
||||||
mPriorBalance = sle->getFieldAmount (sfBalance);
|
mPriorBalance = sle->getFieldAmount (sfBalance);
|
||||||
mSourceBalance = mPriorBalance;
|
mSourceBalance = mPriorBalance;
|
||||||
mHasAuthKey = sle->isFieldPresent (sfRegularKey);
|
mHasAuthKey = sle->isFieldPresent (sfRegularKey);
|
||||||
}
|
|
||||||
|
|
||||||
auto terResult = checkSeq ();
|
auto terResult = checkSeq ();
|
||||||
|
|
||||||
@@ -252,8 +238,8 @@ TER Transactor::apply ()
|
|||||||
|
|
||||||
if (terResult != tesSUCCESS) return terResult;
|
if (terResult != tesSUCCESS) return terResult;
|
||||||
|
|
||||||
if (sle)
|
|
||||||
view().update (sle);
|
view().update (sle);
|
||||||
|
}
|
||||||
|
|
||||||
return doApply ();
|
return doApply ();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,28 +94,17 @@ protected:
|
|||||||
explicit
|
explicit
|
||||||
Transactor (ApplyContext& ctx);
|
Transactor (ApplyContext& ctx);
|
||||||
|
|
||||||
void calculateFee ();
|
|
||||||
|
|
||||||
// VFALCO This is the equivalent of dynamic_cast
|
|
||||||
// to discover the type of the derived class,
|
|
||||||
// and therefore bad.
|
|
||||||
virtual
|
|
||||||
bool
|
|
||||||
mustHaveValidAccount()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the fee, not scaled for load (Should be in fee units. FIXME)
|
// Returns the fee, not scaled for load (Should be in fee units. FIXME)
|
||||||
virtual std::uint64_t calculateBaseFee ();
|
virtual std::uint64_t calculateBaseFee ();
|
||||||
|
|
||||||
virtual void preCompute();
|
virtual void preCompute();
|
||||||
virtual TER checkSeq ();
|
|
||||||
virtual TER payFee ();
|
|
||||||
virtual TER checkSign ();
|
|
||||||
virtual TER doApply () = 0;
|
virtual TER doApply () = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
TER checkSeq ();
|
||||||
|
TER checkSign ();
|
||||||
|
TER payFee ();
|
||||||
TER checkSingleSign ();
|
TER checkSingleSign ();
|
||||||
TER checkMultiSign ();
|
TER checkMultiSign ();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user