refactor: Start making ledger helpers type-safe, beginning with AccountRoot#6620
refactor: Start making ledger helpers type-safe, beginning with AccountRoot#6620
AccountRoot#6620Conversation
|
/ai-review |
| * Inherits from AccountRoot to reuse read-only methods, | ||
| * and adds write capabilities. | ||
| */ | ||
| class WritableAccountRoot : public AccountRoot, public WritableSLE |
There was a problem hiding this comment.
I don't think this multi-inheritance is a good practice.
AccountRoot is a ReadOnlySLE, so we're effectively doing
class WritableAccouontRoot : public ReadOnlySLE, public WritableSLE
{};Because both WritableSLE and ReadOnlySLE hold a shared_ptr, each WritableAccountRoot will hold two shared_ptr instances.
There was a problem hiding this comment.
@a1q123456 how do you propose to address this? Note, having a single class responsible for both reading and writing is not an option, as it invites making mistakes.
There was a problem hiding this comment.
Please take a look at the latest version - I think I've resolved this issue while still separating read and write considerations.
| * Derived classes should provide domain-specific accessors that hide | ||
| * implementation details of the underlying ledger entry format. | ||
| */ | ||
| class WritableSLE |
There was a problem hiding this comment.
I think WritableSLE provides functionalities interacting with the ledger itself, like removing, inserting, updating, etc, which doesn't fully align with the name WritableSLE.
I suggest making it a template class and we use the CRTP pattern.
template <typename T>
class SLEEditor : T
{};This approach provides 2 benefits:
- The name
SLEEditoraligns better with what the class is doing - We don't have to use multiple inheritance at all. If you want to get the sle pointer, you get it from the base class
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 103 out of 103 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!ctx.view.rules().enabled(featureMPTokensV2)) | ||
| { | ||
| // If AllowTrustLineClawback is not set or NoFreeze is set, return no | ||
| // permission | ||
| if (((issuerFlagsIn & lsfAllowTrustLineClawback) == 0u) || | ||
| ((issuerFlagsIn & lsfNoFreeze) != 0u)) | ||
| if (!acctIssuer->isFlag(lsfAllowTrustLineClawback) || !acctIssuer->isFlag(lsfNoFreeze)) | ||
| return tesSUCCESS; |
There was a problem hiding this comment.
In preclaim, the lsfNoFreeze check appears inverted vs the prior logic and the comment directly above it. The old code early-returned when NoFreeze is set; the refactor now early-returns when NoFreeze is not set (!acctIssuer->isFlag(lsfNoFreeze)), which changes clawback permission behavior. Update the condition to preserve the original (NoFreeze != 0u) semantics (and align with the comment).
| * @details | ||
| * Populates the provided JSON value with the description of the specified | ||
| * ledger entry. If the entry is an account root and contains an email hash, | ||
| * adds a 'urlgravatar' field with the corresponding Gravatar URL. | ||
| * If the entry is not an account root, sets the 'Invalid' field to true. | ||
| */ |
There was a problem hiding this comment.
The docblock for injectSLE still says: "If the entry is not an account root, sets the 'Invalid' field to true." After changing the signature to RAccountRoot const&, the function can no longer be called with a non-account-root entry and it no longer sets jss::Invalid. Please update the comment (or reintroduce equivalent handling if you still need to represent invalid/non-account-root entries).
| **`SLEBase<ReadView>`** (aliased as `ReadOnlySLE`) holds a `std::shared_ptr<SLE const>` and a `ReadView const&`. Write-only members are excluded at compile time. | ||
|
|
||
| **`SLEBase<ApplyView>`** (aliased as `WritableSLE`) holds a mutable `std::shared_ptr<SLE>`, an `ApplyView&`, and a `Keylet`. It exposes `insert()`, `update()`, `erase()`, and `newSLE()` to keep the SLE and its view in sync automatically. | ||
|
|
There was a problem hiding this comment.
README states SLEBase<ReadView>/SLEBase<ApplyView> are aliased as ReadOnlySLE/WritableSLE, and the file table repeats this, but those aliases are not actually declared in SLEBase.h (only mentioned in comments). Either add the aliases (e.g., using ReadOnlySLE = SLEBase<ReadView>; using WritableSLE = SLEBase<ApplyView>;) or adjust the README to match the implementation.
|
@a1q123456 after this PR is merged I plan on tinkering with how we can add in the autogen classes. |
High Level Overview of Change
This PR marks the beginning of a process to make SLEs and SLE helpers more type-safe. The original proposal is here. The general idea is each ledger entry will have a read-only and a write-access version of the class. Getter functions will be on the read-only version, and modifier functions will be on the writable version.
This PR begins with implementing base read and write classes, and also implements and migrates
AccountRootto the type-safe architecture. To keep PRs small and easy to review, ~each ledger entry will have its own implementation/migration PR.There is no functionality change in this PR, only pure refactoring.
Note for reviewers: I recommend enabling "Hide whitespace" when looking at the diff for this PR in the Github UI.
Context of Change
There is a README added as a part of this PR
API Impact
N/A
Test Plan
Tests were not modified at all, and still pass.