Skip to content

Commit

Permalink
add AccountPermission
Browse files Browse the repository at this point in the history
  • Loading branch information
yinyiqian1 committed Nov 13, 2024
1 parent fae15f2 commit f9764a5
Show file tree
Hide file tree
Showing 33 changed files with 218 additions and 173 deletions.
2 changes: 1 addition & 1 deletion include/xrpl/protocol/detail/features.macro
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ XRPL_FIX (1513, Supported::yes, VoteBehavior::DefaultYe
XRPL_FEATURE(FlowCross, Supported::yes, VoteBehavior::DefaultYes)
XRPL_FEATURE(Flow, Supported::yes, VoteBehavior::DefaultYes)
XRPL_FEATURE(OwnerPaysFee, Supported::no, VoteBehavior::DefaultNo)
XRPL_FEATURE(AccountPermission, Supported::yes, VoteBehavior::DefaultYes)
XRPL_FEATURE(AccountPermission, Supported::yes, VoteBehavior::DefaultNo)

// The following amendments are obsolete, but must remain supported
// because they could potentially get enabled.
Expand Down
3 changes: 3 additions & 0 deletions src/test/app/AMM_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3234,6 +3234,7 @@ struct AMM_test : public jtx::AMMTest
*jtx.stx,
env.current()->rules(),
tapNONE,
AccountID(0),
env.journal);
auto pf = AMMBid::preflight(pfctx);
BEAST_EXPECT(pf == temDISABLED);
Expand All @@ -3249,6 +3250,7 @@ struct AMM_test : public jtx::AMMTest
*jtx.stx,
env.current()->rules(),
tapNONE,
AccountID(0),
env.journal);
auto pf = AMMBid::preflight(pfctx);
BEAST_EXPECT(pf != tesSUCCESS);
Expand All @@ -3264,6 +3266,7 @@ struct AMM_test : public jtx::AMMTest
*jtx.stx,
env.current()->rules(),
tapNONE,
AccountID(0),
env.journal);
auto pf = AMMBid::preflight(pfctx);
BEAST_EXPECT(pf == temBAD_AMM_TOKENS);
Expand Down
4 changes: 4 additions & 0 deletions src/test/app/NFTokenBurn_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,8 @@ class NFTokenBurnBaseUtil_test : public beast::unit_test::suite
tesSUCCESS,
env.current()->fees().base,
tapNONE,
false,
AccountID(0),
jlog};

// Verify that the last page is present and contains one NFT.
Expand Down Expand Up @@ -865,6 +867,8 @@ class NFTokenBurnBaseUtil_test : public beast::unit_test::suite
tesSUCCESS,
env.current()->fees().base,
tapNONE,
false,
AccountID(0),
jlog};

// Verify that the middle page is present.
Expand Down
2 changes: 2 additions & 0 deletions src/test/ledger/Invariants_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class Invariants_test : public beast::unit_test::suite
tesSUCCESS,
env.current()->fees().base,
tapNONE,
false,
AccountID(0),
jlog};

BEAST_EXPECT(precheck(A1, A2, ac));
Expand Down
15 changes: 14 additions & 1 deletion src/xrpld/app/tx/applySteps.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,27 @@ struct PreflightResult
ApplyFlags const flags;
/// From the input - the journal
beast::Journal const j;

/// If the transaction is a delegated transaction
bool const isDelegated;
/// the account that the transaction is operated on
AccountID const account;
/// Intermediate transaction result
NotTEC const ter;

/// Constructor
template <class Context>
PreflightResult(
Context const& ctx_,
bool const isDelegated,
AccountID const account,
std::pair<NotTEC, TxConsequences> const& result)
: tx(ctx_.tx)
, rules(ctx_.rules)
, consequences(result.second)
, flags(ctx_.flags)
, j(ctx_.j)
, isDelegated(isDelegated)
, account(account)
, ter(result.first)
{
}
Expand Down Expand Up @@ -201,6 +208,10 @@ struct PreclaimResult
ApplyFlags const flags;
/// From the input - the journal
beast::Journal const j;
/// If the transaction is a delegated transaction
bool const isDelegated; // todo: may remove
/// the account that the transaction is operated on
AccountID const account;

/// Intermediate transaction result
TER const ter;
Expand All @@ -215,6 +226,8 @@ struct PreclaimResult
, tx(ctx_.tx)
, flags(ctx_.flags)
, j(ctx_.j)
, isDelegated(ctx_.isDelegated)
, account(ctx_.account)
, ter(ter_)
, likelyToClaimFee(ter == tesSUCCESS || isTecClaimHardFail(ter, flags))
{
Expand Down
3 changes: 1 addition & 2 deletions src/xrpld/app/tx/detail/AMMBid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ AMMBid::preclaim(PreclaimContext const& ctx)
}
}

auto const lpTokens =
ammLPHolds(ctx.view, *ammSle, ctx.tx[sfAccount], ctx.j);
auto const lpTokens = ammLPHolds(ctx.view, *ammSle, ctx.account, ctx.j);
// Not LP
if (lpTokens == beast::zero)
{
Expand Down
45 changes: 1 addition & 44 deletions src/xrpld/app/tx/detail/AMMCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,50 +88,7 @@ AMMCreate::calculateBaseFee(ReadView const& view, STTx const& tx)
TER
AMMCreate::preclaim(PreclaimContext const& ctx)
{
// if (ctx.rules.enabled(featureAccountPermission))
// {
auto const onBehalfOfAccount =
ctx.view.read(keylet::account(ctx.tx[sfOnBehalfOf]));
if (!onBehalfOfAccount)
return terNO_ACCOUNT;

auto const accountPermissionKey =
keylet::accountPermission(ctx.tx[sfAccount], ctx.tx[sfOnBehalfOf]);
auto const sle = ctx.view.read(accountPermissionKey);
if (!sle)
return temMALFORMED; // todo: change error code

auto const permissions = sle->getFieldArray(sfPermissions);
bool grantedPermission = false;
for (auto const& permissionObj : permissions)
{
// auto permissionObj = dynamic_cast<STObject const*>(&permission);
auto const permissionValue =
permissionObj.getFieldU32(sfPermissionValue);
std::cout << "perimssionValue = " << permissionValue << std::endl;
auto const transactionType = ctx.tx.getTxnType();
std::cout << "transactionType = " << transactionType << std::endl;
if (permissionValue == transactionType + 1)
grantedPermission = true;
// for (auto const& permissionElement : *permissionObj)
// {
// auto permissionStr = permissionElement.getText();
// auto const& name = permissionElement.getFName();

// auto const permissionValue =
// permissionElement.getFieldU32(sfPermissionValue); auto const
// transactionType = ctx.tx.getTxnType(); if (permissionValue ==
// transactionType + 1)
// grantedPermission = true;
// }
}

if (!grantedPermission)
return terNO_AUTH;

//}

auto const accountID = ctx.tx[sfAccount];
auto const accountID = ctx.account;
auto const amount = ctx.tx[sfAmount];
auto const amount2 = ctx.tx[sfAmount2];

Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/tx/detail/AMMDeposit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ AMMDeposit::preflight(PreflightContext const& ctx)
TER
AMMDeposit::preclaim(PreclaimContext const& ctx)
{
auto const accountID = ctx.tx[sfAccount];
auto const accountID = ctx.account;

auto const ammSle =
ctx.view.read(keylet::amm(ctx.tx[sfAsset], ctx.tx[sfAsset2]));
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/tx/detail/AMMVote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ AMMVote::preclaim(PreclaimContext const& ctx)
else if (ammSle->getFieldAmount(sfLPTokenBalance) == beast::zero)
return tecAMM_EMPTY;
else if (auto const lpTokensNew =
ammLPHolds(ctx.view, *ammSle, ctx.tx[sfAccount], ctx.j);
ammLPHolds(ctx.view, *ammSle, ctx.account, ctx.j);
lpTokensNew == beast::zero)
{
JLOG(ctx.j.debug()) << "AMM Vote: account is not LP.";
Expand Down
7 changes: 3 additions & 4 deletions src/xrpld/app/tx/detail/AMMWithdraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ tokensWithdraw(
TER
AMMWithdraw::preclaim(PreclaimContext const& ctx)
{
auto const accountID = ctx.tx[sfAccount];
auto const accountID = ctx.account;

auto const ammSle =
ctx.view.read(keylet::amm(ctx.tx[sfAsset], ctx.tx[sfAsset2]));
Expand Down Expand Up @@ -251,8 +251,7 @@ AMMWithdraw::preclaim(PreclaimContext const& ctx)
if (auto const ter = checkAmount(amount2, amount2Balance))
return ter;

auto const lpTokens =
ammLPHolds(ctx.view, *ammSle, ctx.tx[sfAccount], ctx.j);
auto const lpTokens = ammLPHolds(ctx.view, *ammSle, accountID, ctx.j);
auto const lpTokensWithdraw =
tokensWithdraw(lpTokens, ctx.tx[~sfLPTokenIn], ctx.tx.getFlags());

Expand Down Expand Up @@ -306,7 +305,7 @@ AMMWithdraw::applyGuts(Sandbox& sb)
if (!accountSle)
return {tecINTERNAL, false}; // LCOV_EXCL_LINE
auto const lpTokens =
ammLPHolds(ctx_.view(), *ammSle, ctx_.tx[sfAccount], ctx_.journal);
ammLPHolds(ctx_.view(), *ammSle, account_, ctx_.journal);
auto const lpTokensWithdraw =
tokensWithdraw(lpTokens, ctx_.tx[~sfLPTokenIn], ctx_.tx.getFlags());

Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/tx/detail/AccountPermissionSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ AccountPermissionSet::preflight(PreflightContext const& ctx)
TER
AccountPermissionSet::preclaim(PreclaimContext const& ctx)
{
auto const account = ctx.view.read(keylet::account(ctx.tx[sfAccount]));
auto const account = ctx.view.read(keylet::account(ctx.account));
if (!account)
return terNO_ACCOUNT; // LCOV_EXCL_LINE

Expand Down
4 changes: 4 additions & 0 deletions src/xrpld/app/tx/detail/ApplyContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ ApplyContext::ApplyContext(
TER preclaimResult_,
XRPAmount baseFee_,
ApplyFlags flags,
bool isDelegated, // todo: may remove
AccountID const account,
beast::Journal journal_)
: app(app_)
, tx(tx_)
, preclaimResult(preclaimResult_)
, baseFee(baseFee_)
, isDelegated(isDelegated)
, account(account)
, journal(journal_)
, base_(base)
, flags_(flags)
Expand Down
4 changes: 4 additions & 0 deletions src/xrpld/app/tx/detail/ApplyContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ class ApplyContext
TER preclaimResult,
XRPAmount baseFee,
ApplyFlags flags,
bool isDelegated,
AccountID const account,
beast::Journal = beast::Journal{beast::Journal::getNullSink()});

Application& app;
STTx const& tx;
TER const preclaimResult;
XRPAmount const baseFee;
bool isDelegated;
AccountID const account;
beast::Journal const journal;

ApplyView&
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/tx/detail/CancelCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ CancelCheck::preclaim(PreclaimContext const& ctx)
{
// If the check is not yet expired, then only the creator or the
// destination may cancel the check.
AccountID const acctId{ctx.tx[sfAccount]};
AccountID const acctId{ctx.account};
if (acctId != (*sleCheck)[sfAccount] &&
acctId != (*sleCheck)[sfDestination])
{
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/tx/detail/CashCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ CashCheck::preclaim(PreclaimContext const& ctx)

// Only cash a check with this account as the destination.
AccountID const dstId = sleCheck->at(sfDestination);
if (ctx.tx[sfAccount] != dstId)
if (ctx.account != dstId)
{
JLOG(ctx.j.warn()) << "Cashing a check with wrong Destination.";
return tecNO_PERMISSION;
Expand Down
4 changes: 2 additions & 2 deletions src/xrpld/app/tx/detail/Clawback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Clawback::preflight(PreflightContext const& ctx)
if (ctx.tx.getFlags() & tfClawbackMask)
return temINVALID_FLAG;

AccountID const issuer = ctx.tx[sfAccount];
AccountID const issuer = ctx.account;
STAmount const clawAmount = ctx.tx[sfAmount];

// The issuer field is used for the token holder instead
Expand All @@ -54,7 +54,7 @@ Clawback::preflight(PreflightContext const& ctx)
TER
Clawback::preclaim(PreclaimContext const& ctx)
{
AccountID const issuer = ctx.tx[sfAccount];
AccountID const issuer = ctx.account;
STAmount const clawAmount = ctx.tx[sfAmount];
AccountID const& holder = clawAmount.getIssuer();

Expand Down
4 changes: 2 additions & 2 deletions src/xrpld/app/tx/detail/CreateCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CreateCheck::preflight(PreflightContext const& ctx)
JLOG(ctx.j.warn()) << "Malformed transaction: Invalid flags set.";
return temINVALID_FLAG;
}
if (ctx.tx[sfAccount] == ctx.tx[sfDestination])
if (ctx.account == ctx.tx[sfDestination])
{
// They wrote a check to themselves.
JLOG(ctx.j.warn()) << "Malformed transaction: Check to self.";
Expand Down Expand Up @@ -125,7 +125,7 @@ CreateCheck::preclaim(PreclaimContext const& ctx)
//
// Note that we DO allow create check for a currency that the
// account does not yet have a trustline to.
AccountID const srcId{ctx.tx.getAccountID(sfAccount)};
AccountID const srcId{ctx.account};
if (issuerId != srcId)
{
// Check if the issuer froze the line
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/tx/detail/CreateOffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ CreateOffer::preflight(PreflightContext const& ctx)
TER
CreateOffer::preclaim(PreclaimContext const& ctx)
{
auto const id = ctx.tx[sfAccount];
auto const id = ctx.account;

auto saTakerPays = ctx.tx[sfTakerPays];
auto saTakerGets = ctx.tx[sfTakerGets];
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/tx/detail/CreateTicket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CreateTicket::preflight(PreflightContext const& ctx)
TER
CreateTicket::preclaim(PreclaimContext const& ctx)
{
auto const id = ctx.tx[sfAccount];
auto const id = ctx.account;
auto const sleAccountRoot = ctx.view.read(keylet::account(id));
if (!sleAccountRoot)
return terNO_ACCOUNT;
Expand Down
4 changes: 2 additions & 2 deletions src/xrpld/app/tx/detail/DeleteAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ DeleteAccount::preflight(PreflightContext const& ctx)
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;

if (ctx.tx[sfAccount] == ctx.tx[sfDestination])
if (ctx.account == ctx.tx[sfDestination])
// An account cannot be deleted and give itself the resulting XRP.
return temDST_IS_SRC;

Expand Down Expand Up @@ -207,7 +207,7 @@ nonObligationDeleter(LedgerEntryType t)
TER
DeleteAccount::preclaim(PreclaimContext const& ctx)
{
AccountID const account{ctx.tx[sfAccount]};
AccountID const account{ctx.account};
AccountID const dst{ctx.tx[sfDestination]};

auto sleDst = ctx.view.read(keylet::account(dst));
Expand Down
6 changes: 3 additions & 3 deletions src/xrpld/app/tx/detail/DepositPreauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ DepositPreauth::preflight(PreflightContext const& ctx)
}

// An account may not preauthorize itself.
if (optAuth && (target == ctx.tx[sfAccount]))
if (optAuth && (target == ctx.account))
{
JLOG(j.trace())
<< "Malformed transaction: Attempting to DepositPreauth self.";
Expand All @@ -90,14 +90,14 @@ DepositPreauth::preclaim(PreclaimContext const& ctx)

// Verify that the Preauth entry they asked to add is not already
// in the ledger.
if (ctx.view.exists(keylet::depositPreauth(ctx.tx[sfAccount], auth)))
if (ctx.view.exists(keylet::depositPreauth(ctx.account, auth)))
return tecDUPLICATE;
}
else
{
// Verify that the Preauth entry they asked to remove is in the ledger.
AccountID const unauth{ctx.tx[sfUnauthorize]};
if (!ctx.view.exists(keylet::depositPreauth(ctx.tx[sfAccount], unauth)))
if (!ctx.view.exists(keylet::depositPreauth(ctx.account, unauth)))
return tecNO_ENTRY;
}
return tesSUCCESS;
Expand Down
Loading

0 comments on commit f9764a5

Please sign in to comment.