Skip to content

Commit b41a4cb

Browse files
committed
Merge branch 'permissions' into account_permissions
2 parents 7a7fa0c + cfdcef1 commit b41a4cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+525
-369
lines changed

include/xrpl/protocol/Permissions.h

+16-12
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,29 @@ namespace ripple {
3434
*/
3535

3636
enum GranularPermissionType : std::uint32_t {
37-
gpTrustlineAuthorize = 65537,
37+
TrustlineAuthorize = 65537,
3838

39-
gpTrustlineFreeze = 65538,
39+
TrustlineFreeze = 65538,
4040

41-
gpTrustlineUnfreeze = 65539,
41+
TrustlineUnfreeze = 65539,
4242

43-
gpAccountDomainSet = 65540,
43+
AccountDomainSet = 65540,
4444

45-
gpAccountEmailHashSet = 65541,
45+
AccountEmailHashSet = 65541,
4646

47-
gpAccountMessageKeySet = 65542,
47+
AccountMessageKeySet = 65542,
4848

49-
gpAccountTransferRateSet = 65543,
49+
AccountTransferRateSet = 65543,
5050

51-
gpAccountTickSizeSet = 65544,
51+
AccountTickSizeSet = 65544,
5252

53-
gpPaymentMint = 65545,
53+
PaymentMint = 65545,
5454

55-
gpPaymentBurn = 65546,
55+
PaymentBurn = 65546,
5656

57-
gpMPTokenIssuanceLock = 65547,
57+
MPTokenIssuanceLock = 65547,
5858

59-
gpMPTokenIssuanceUnlock = 65548,
59+
MPTokenIssuanceUnlock = 65548,
6060
};
6161

6262
class Permission
@@ -73,6 +73,10 @@ class Permission
7373
static Permission const&
7474
getInstance();
7575

76+
Permission(const Permission&) = delete;
77+
Permission&
78+
operator=(const Permission&) = delete;
79+
7680
std::optional<std::uint32_t>
7781
getGranularValue(std::string const& name) const;
7882

include/xrpl/protocol/STTxWr.h

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
//------------------------------------------------------------------------------
2+
/*
3+
This file is part of rippled: https://github.com/ripple/rippled
4+
Copyright (c) 2024 Ripple Labs Inc.
5+
6+
Permission to use, copy, modify, and/or distribute this software for any
7+
purpose with or without fee is hereby granted, provided that the above
8+
copyright notice and this permission notice appear in all copies.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
//==============================================================================
19+
20+
#ifndef RIPPLE_PROTOCOL_STTX_WRAPPER_H_INCLUDED
21+
#define RIPPLE_PROTOCOL_STTX_WRAPPER_H_INCLUDED
22+
23+
#include <xrpl/protocol/STAccount.h>
24+
#include <xrpl/protocol/STTx.h>
25+
#include <functional>
26+
27+
namespace ripple {
28+
29+
class STTxWr
30+
{
31+
private:
32+
STTx tx_; // Wrap an instance of STTx
33+
bool isDelegated_; // if the transaction is delegated by another account
34+
35+
public:
36+
explicit STTxWr(STTx tx, bool isDelegated)
37+
: tx_(tx), isDelegated_(isDelegated)
38+
{
39+
}
40+
41+
STTx
42+
getTx() const
43+
{
44+
return tx_;
45+
}
46+
47+
bool
48+
isDelegated() const
49+
{
50+
return isDelegated_;
51+
}
52+
53+
AccountID
54+
getAccountID(SField const& field) const
55+
{
56+
if (field == sfAccount)
57+
return tx_.isFieldPresent(sfOnBehalfOf) ? *tx_[~sfOnBehalfOf]
58+
: tx_[sfAccount];
59+
return tx_.getAccountID(field);
60+
}
61+
62+
template <class T>
63+
typename std::enable_if<std::is_same<T, SF_ACCOUNT>::value, AccountID>::type
64+
operator[](TypedField<T> const& f) const
65+
{
66+
return tx_.isFieldPresent(sfOnBehalfOf) ? *tx_[~sfOnBehalfOf]
67+
: tx_[sfAccount];
68+
}
69+
70+
template <class T>
71+
typename T::value_type
72+
operator[](TypedField<T> const& f) const
73+
{
74+
return tx_[f];
75+
}
76+
77+
template <class T>
78+
std::optional<std::decay_t<typename T::value_type>>
79+
operator[](OptionaledField<T> const& of) const
80+
{
81+
return tx_[of];
82+
}
83+
84+
uint256
85+
getTransactionID() const
86+
{
87+
return tx_.getTransactionID();
88+
}
89+
90+
TxType
91+
getTxnType() const
92+
{
93+
return tx_.getTxnType();
94+
}
95+
96+
std::uint32_t
97+
getFlags() const
98+
{
99+
return tx_.getFlags();
100+
}
101+
102+
bool
103+
isFieldPresent(SField const& field) const
104+
{
105+
return tx_.isFieldPresent(field);
106+
}
107+
108+
Json::Value
109+
getJson(JsonOptions options) const
110+
{
111+
return tx_.getJson(options);
112+
}
113+
114+
void
115+
add(Serializer& s) const
116+
{
117+
tx_.add(s);
118+
}
119+
120+
unsigned char
121+
getFieldU8(SField const& field) const
122+
{
123+
return tx_.getFieldU8(field);
124+
}
125+
126+
std::uint32_t
127+
getFieldU32(SField const& field) const
128+
{
129+
return tx_.getFieldU32(field);
130+
}
131+
132+
uint256
133+
getFieldH256(SField const& field) const
134+
{
135+
return tx_.getFieldH256(field);
136+
}
137+
138+
Blob
139+
getFieldVL(SField const& field) const
140+
{
141+
return tx_.getFieldVL(field);
142+
}
143+
144+
STAmount const&
145+
getFieldAmount(SField const& field) const
146+
{
147+
return tx_.getFieldAmount(field);
148+
}
149+
150+
STPathSet const&
151+
getFieldPathSet(SField const& field) const
152+
{
153+
return tx_.getFieldPathSet(field);
154+
}
155+
156+
const STVector256&
157+
getFieldV256(SField const& field) const
158+
{
159+
return tx_.getFieldV256(field);
160+
}
161+
162+
const STArray&
163+
getFieldArray(SField const& field) const
164+
{
165+
return tx_.getFieldArray(field);
166+
}
167+
168+
Blob
169+
getSigningPubKey() const
170+
{
171+
return tx_.getSigningPubKey();
172+
}
173+
174+
Blob
175+
getSignature() const
176+
{
177+
return tx_.getSignature();
178+
}
179+
180+
bool
181+
isFlag(std::uint32_t f) const
182+
{
183+
return tx_.isFlag(f);
184+
}
185+
186+
SeqProxy
187+
getSeqProxy() const
188+
{
189+
return tx_.getSeqProxy();
190+
}
191+
};
192+
193+
} // namespace ripple
194+
195+
#endif

src/libxrpl/protocol/Permissions.cpp

+24-24
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,32 @@ namespace ripple {
2727
Permission::Permission()
2828
{
2929
granularPermissionMap = {
30-
{"TrustlineAuthorize", gpTrustlineAuthorize},
31-
{"TrustlineFreeze", gpTrustlineFreeze},
32-
{"TrustlineUnfreeze", gpTrustlineUnfreeze},
33-
{"AccountDomainSet", gpAccountDomainSet},
34-
{"AccountEmailHashSet", gpAccountEmailHashSet},
35-
{"AccountMessageKeySet", gpAccountMessageKeySet},
36-
{"AccountTransferRateSet", gpAccountTransferRateSet},
37-
{"AccountTickSizeSet", gpAccountTickSizeSet},
38-
{"PaymentMint", gpPaymentMint},
39-
{"PaymentBurn", gpPaymentBurn},
40-
{"MPTokenIssuanceLock", gpMPTokenIssuanceLock},
41-
{"MPTokenIssuanceUnlock", gpMPTokenIssuanceUnlock}};
30+
{"TrustlineAuthorize", TrustlineAuthorize},
31+
{"TrustlineFreeze", TrustlineFreeze},
32+
{"TrustlineUnfreeze", TrustlineUnfreeze},
33+
{"AccountDomainSet", AccountDomainSet},
34+
{"AccountEmailHashSet", AccountEmailHashSet},
35+
{"AccountMessageKeySet", AccountMessageKeySet},
36+
{"AccountTransferRateSet", AccountTransferRateSet},
37+
{"AccountTickSizeSet", AccountTickSizeSet},
38+
{"PaymentMint", PaymentMint},
39+
{"PaymentBurn", PaymentBurn},
40+
{"MPTokenIssuanceLock", MPTokenIssuanceLock},
41+
{"MPTokenIssuanceUnlock", MPTokenIssuanceUnlock}};
4242

4343
granularTxTypeMap = {
44-
{gpTrustlineAuthorize, ttTRUST_SET},
45-
{gpTrustlineFreeze, ttTRUST_SET},
46-
{gpTrustlineUnfreeze, ttTRUST_SET},
47-
{gpAccountDomainSet, ttACCOUNT_SET},
48-
{gpAccountEmailHashSet, ttACCOUNT_SET},
49-
{gpAccountMessageKeySet, ttACCOUNT_SET},
50-
{gpAccountTransferRateSet, ttACCOUNT_SET},
51-
{gpAccountTickSizeSet, ttACCOUNT_SET},
52-
{gpPaymentMint, ttPAYMENT},
53-
{gpPaymentBurn, ttPAYMENT},
54-
{gpMPTokenIssuanceLock, ttMPTOKEN_ISSUANCE_SET},
55-
{gpMPTokenIssuanceUnlock, ttMPTOKEN_ISSUANCE_SET}};
44+
{TrustlineAuthorize, ttTRUST_SET},
45+
{TrustlineFreeze, ttTRUST_SET},
46+
{TrustlineUnfreeze, ttTRUST_SET},
47+
{AccountDomainSet, ttACCOUNT_SET},
48+
{AccountEmailHashSet, ttACCOUNT_SET},
49+
{AccountMessageKeySet, ttACCOUNT_SET},
50+
{AccountTransferRateSet, ttACCOUNT_SET},
51+
{AccountTickSizeSet, ttACCOUNT_SET},
52+
{PaymentMint, ttPAYMENT},
53+
{PaymentBurn, ttPAYMENT},
54+
{MPTokenIssuanceLock, ttMPTOKEN_ISSUANCE_SET},
55+
{MPTokenIssuanceUnlock, ttMPTOKEN_ISSUANCE_SET}};
5656
}
5757

5858
Permission const&

src/test/app/AMM_test.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -3304,10 +3304,9 @@ struct AMM_test : public jtx::AMMTest
33043304
env.app().config().features.erase(featureAMM);
33053305
PreflightContext pfctx(
33063306
env.app(),
3307-
*jtx.stx,
3307+
STTxWr(*jtx.stx, false),
33083308
env.current()->rules(),
33093309
tapNONE,
3310-
AccountID(0),
33113310
env.journal);
33123311
auto pf = AMMBid::preflight(pfctx);
33133312
BEAST_EXPECT(pf == temDISABLED);
@@ -3320,10 +3319,9 @@ struct AMM_test : public jtx::AMMTest
33203319
jtx.stx = env.ust(jtx);
33213320
PreflightContext pfctx(
33223321
env.app(),
3323-
*jtx.stx,
3322+
STTxWr(*jtx.stx, false),
33243323
env.current()->rules(),
33253324
tapNONE,
3326-
AccountID(0),
33273325
env.journal);
33283326
auto pf = AMMBid::preflight(pfctx);
33293327
BEAST_EXPECT(pf != tesSUCCESS);
@@ -3336,10 +3334,9 @@ struct AMM_test : public jtx::AMMTest
33363334
jtx.stx = env.ust(jtx);
33373335
PreflightContext pfctx(
33383336
env.app(),
3339-
*jtx.stx,
3337+
STTxWr(*jtx.stx, false),
33403338
env.current()->rules(),
33413339
tapNONE,
3342-
AccountID(0),
33433340
env.journal);
33443341
auto pf = AMMBid::preflight(pfctx);
33453342
BEAST_EXPECT(pf == temBAD_AMM_TOKENS);

src/test/app/Escrow_test.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ struct Escrow_test : public beast::unit_test::suite
13311331
auto const pf = preflight(
13321332
env.app(),
13331333
env.current()->rules(),
1334-
*jtx.stx,
1334+
STTxWr(*jtx.stx, false),
13351335
tapNONE,
13361336
env.journal);
13371337
BEAST_EXPECT(pf.ter == tesSUCCESS);
@@ -1345,7 +1345,7 @@ struct Escrow_test : public beast::unit_test::suite
13451345
auto const pf = preflight(
13461346
env.app(),
13471347
env.current()->rules(),
1348-
*jtx.stx,
1348+
STTxWr(*jtx.stx, false),
13491349
tapNONE,
13501350
env.journal);
13511351
BEAST_EXPECT(pf.ter == tesSUCCESS);
@@ -1359,7 +1359,7 @@ struct Escrow_test : public beast::unit_test::suite
13591359
auto const pf = preflight(
13601360
env.app(),
13611361
env.current()->rules(),
1362-
*jtx.stx,
1362+
STTxWr(*jtx.stx, false),
13631363
tapNONE,
13641364
env.journal);
13651365
BEAST_EXPECT(pf.ter == tesSUCCESS);

src/test/app/NFTokenBurn_test.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -807,12 +807,10 @@ class NFTokenBurnBaseUtil_test : public beast::unit_test::suite
807807
ApplyContext ac{
808808
env.app(),
809809
ov,
810-
tx,
810+
STTxWr(tx, false),
811811
tesSUCCESS,
812812
env.current()->fees().base,
813813
tapNONE,
814-
false,
815-
AccountID(0),
816814
std::unordered_set<GranularPermissionType>{},
817815
jlog};
818816

@@ -854,12 +852,10 @@ class NFTokenBurnBaseUtil_test : public beast::unit_test::suite
854852
ApplyContext ac{
855853
env.app(),
856854
ov,
857-
tx,
855+
STTxWr(tx, false),
858856
tesSUCCESS,
859857
env.current()->fees().base,
860858
tapNONE,
861-
false,
862-
AccountID(0),
863859
std::unordered_set<GranularPermissionType>{},
864860
jlog};
865861

0 commit comments

Comments
 (0)