Skip to content

Commit

Permalink
fix: add allowClawback flag for account_info (XRPLF#4590)
Browse files Browse the repository at this point in the history
* Update the `account_info` API so that the `allowClawback` flag is
  included in the response.
  * The proposed `Clawback` amendement added an `allowClawback` flag in
    the `AccountRoot` object.
  * In the API response, under `account_flags`, there is now an
    `allowClawback` field with a boolean (`true` or `false`) value.
  * For reference, the XLS-39 Clawback implementation can be found in
    XRPLF#4553

Fix XRPLF#4588
  • Loading branch information
shawnxie999 authored and ckeshava committed Sep 25, 2023
1 parent e4f3c9c commit 102f291
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/ripple/rpc/handlers/AccountInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ doAccountInfo(RPC::JsonContext& context)
{"disallowIncomingPayChan", lsfDisallowIncomingPayChan},
{"disallowIncomingTrustline", lsfDisallowIncomingTrustline}}};

static constexpr std::pair<std::string_view, LedgerSpecificFlags>
allowClawbackFlag{"allowClawback", lsfAllowClawback};

auto const sleAccepted = ledger->read(keylet::account(accountID));
if (sleAccepted)
{
Expand Down Expand Up @@ -123,6 +126,11 @@ doAccountInfo(RPC::JsonContext& context)
for (auto const& lsf : disallowIncomingFlags)
acctFlags[lsf.first.data()] = sleAccepted->isFlag(lsf.second);
}

if (ledger->rules().enabled(featureClawback))
acctFlags[allowClawbackFlag.first.data()] =
sleAccepted->isFlag(allowClawbackFlag.second);

result[jss::account_flags] = std::move(acctFlags);

// The document states that signer_lists is a bool, however
Expand Down
43 changes: 35 additions & 8 deletions src/test/rpc/AccountInfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,16 @@ class AccountInfo_test : public beast::unit_test::suite

Env env(*this, features);
Account const alice{"alice"};
env.fund(XRP(1000), alice);
Account const bob{"bob"};
env.fund(XRP(1000), alice, bob);

auto getAccountFlag = [&env, &alice](std::string_view fName) {
auto getAccountFlag = [&env](
std::string_view fName,
Account const& account) {
auto const info = env.rpc(
"json",
"account_info",
R"({"account" : ")" + alice.human() + R"("})");
R"({"account" : ")" + account.human() + R"("})");

std::optional<bool> res;
if (info[jss::result][jss::status] == "success" &&
Expand Down Expand Up @@ -553,15 +556,15 @@ class AccountInfo_test : public beast::unit_test::suite
// as expected
env(fclear(alice, asf.second));
env.close();
auto const f1 = getAccountFlag(asf.first);
auto const f1 = getAccountFlag(asf.first, alice);
BEAST_EXPECT(f1.has_value());
BEAST_EXPECT(!f1.value());

// Set a flag and check that account_info returns results
// as expected
env(fset(alice, asf.second));
env.close();
auto const f2 = getAccountFlag(asf.first);
auto const f2 = getAccountFlag(asf.first, alice);
BEAST_EXPECT(f2.has_value());
BEAST_EXPECT(f2.value());
}
Expand All @@ -584,15 +587,15 @@ class AccountInfo_test : public beast::unit_test::suite
// as expected
env(fclear(alice, asf.second));
env.close();
auto const f1 = getAccountFlag(asf.first);
auto const f1 = getAccountFlag(asf.first, alice);
BEAST_EXPECT(f1.has_value());
BEAST_EXPECT(!f1.value());

// Set a flag and check that account_info returns results
// as expected
env(fset(alice, asf.second));
env.close();
auto const f2 = getAccountFlag(asf.first);
auto const f2 = getAccountFlag(asf.first, alice);
BEAST_EXPECT(f2.has_value());
BEAST_EXPECT(f2.value());
}
Expand All @@ -601,9 +604,31 @@ class AccountInfo_test : public beast::unit_test::suite
{
for (auto& asf : disallowIncomingFlags)
{
BEAST_EXPECT(!getAccountFlag(asf.first));
BEAST_EXPECT(!getAccountFlag(asf.first, alice));
}
}

static constexpr std::pair<std::string_view, std::uint32_t>
allowClawbackFlag{"allowClawback", asfAllowClawback};

if (features[featureClawback])
{
// must use bob's account because alice has noFreeze set
auto const f1 = getAccountFlag(allowClawbackFlag.first, bob);
BEAST_EXPECT(f1.has_value());
BEAST_EXPECT(!f1.value());

// Set allowClawback
env(fset(bob, allowClawbackFlag.second));
env.close();
auto const f2 = getAccountFlag(allowClawbackFlag.first, bob);
BEAST_EXPECT(f2.has_value());
BEAST_EXPECT(f2.value());
}
else
{
BEAST_EXPECT(!getAccountFlag(allowClawbackFlag.first, bob));
}
}

void
Expand All @@ -618,6 +643,8 @@ class AccountInfo_test : public beast::unit_test::suite
ripple::test::jtx::supported_amendments()};
testAccountFlags(allFeatures);
testAccountFlags(allFeatures - featureDisallowIncoming);
testAccountFlags(
allFeatures - featureDisallowIncoming - featureClawback);
}
};

Expand Down

0 comments on commit 102f291

Please sign in to comment.