Skip to content

Commit

Permalink
Add AccountPermission
Browse files Browse the repository at this point in the history
  • Loading branch information
yinyiqian1 committed Nov 4, 2024
1 parent 50dbe3d commit abceb0a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/xrpl/protocol/detail/sfields.macro
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ TYPED_SFIELD(sfUnauthorize, ACCOUNT, 6)
TYPED_SFIELD(sfRegularKey, ACCOUNT, 8)
TYPED_SFIELD(sfNFTokenMinter, ACCOUNT, 9)
TYPED_SFIELD(sfEmitCallback, ACCOUNT, 10)
TYPED_SFIELD(sfOnBehalfOf, ACCOUNT, 11)

// account (uncommon)
TYPED_SFIELD(sfHookAccount, ACCOUNT, 16)
Expand Down
4 changes: 4 additions & 0 deletions src/libxrpl/protocol/InnerObjectFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ InnerObjectFormats::InnerObjectFormats()
{sfAssetPrice, soeOPTIONAL},
{sfScale, soeDEFAULT},
});

add(sfPermission.jsonName.c_str(),
sfPermission.getCode(),
{{sfPermissionValue, soeREQUIRED}});
}

InnerObjectFormats const&
Expand Down
1 change: 1 addition & 0 deletions src/libxrpl/protocol/TxFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ TxFormats::TxFormats()
{sfTxnSignature, soeOPTIONAL},
{sfSigners, soeOPTIONAL}, // submit_multisigned
{sfNetworkID, soeOPTIONAL},
{sfOnBehalfOf, soeOPTIONAL},
};

#pragma push_macro("UNWRAP")
Expand Down
43 changes: 43 additions & 0 deletions src/xrpld/app/tx/detail/AMMCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,49 @@ 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 amount = ctx.tx[sfAmount];
auto const amount2 = ctx.tx[sfAmount2];
Expand Down

0 comments on commit abceb0a

Please sign in to comment.