Skip to content

Conversation

@jonasXchen
Copy link
Contributor

@jonasXchen jonasXchen commented Nov 21, 2025

Summary by CodeRabbit

New Features

  • Enhanced action arguments API with builder pattern support for improved configuration workflows. Added convenience methods for initialization and chainable property updates, streamlining the developer experience when working with action parameters.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions
Copy link

Manual Deploy Available

You can trigger a manual deploy of this PR branch to testnet:

Deploy to Testnet 🚀

Alternative: Comment /deploy on this PR to trigger deployment directly.

⚠️ Note: Manual deploy requires authorization. Only authorized users can trigger deployments.

Comment updated automatically when the PR is synchronized.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 21, 2025

Walkthrough

Added an inherent impl block for ActionArgs with constructor, getter methods, and builder-style method. Includes default(data: Vec<u8>) constructor initializing escrow_index to 255, getters for escrow_index() and data(), and with_escrow_index() builder method for fluent API usage.

Changes

Cohort / File(s) Change Summary
ActionArgs API Enhancement
magicblock-magic-program-api/src/args.rs
Added inherent impl block with: (1) default(data: Vec<u8>) -> Self constructor initializing escrow_index to 255; (2) escrow_index(&self) -> u8 getter; (3) data(&self) -> &Vec<u8> getter; (4) with_escrow_index(mut self, index: u8) -> Self builder method.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify getter implementations return correct field references
  • Confirm default() constructor properly initializes both escrow_index (255) and data fields
  • Check builder method signature and self-consumption pattern are idiomatic

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately reflects the main change: introducing a default() method for ActionArgs that abstracts the escrow_index initialization.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jonasXchen/magic-action-args

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5823d8 and 5f2a30b.

📒 Files selected for processing (1)
  • magicblock-magic-program-api/src/args.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: run_make_ci_lint
  • GitHub Check: Build Project
  • GitHub Check: run_make_ci_test
🔇 Additional comments (3)
magicblock-magic-program-api/src/args.rs (3)

22-24: Getter is redundant but acceptable for future-proofing.

Since escrow_index is a public field (line 11), this getter is technically redundant. However, it may be useful if you plan to make the field private in the future or add validation logic.


30-33: Builder pattern implementation is correct and approved.

Verification confirms this is the only builder-style method in the codebase. The implementation correctly consumes self, updates the field, and returns self for method chaining.


16-21: Rename default to new to avoid confusion with the Default trait.

The method name default misleadingly suggests the standard Default trait, which has a different signature (no parameters). Since this is a custom constructor taking data as a parameter, renaming to new aligns with Rust conventions.

Additionally, document the magic number 255 for escrow_index. Extract it to a named constant or add a doc comment explaining its semantic meaning (e.g., whether it represents "no escrow" or "unset").

+    /// Creates a new ActionArgs with the given data and a default escrow_index of 255 (no escrow selected).
-    pub fn default(data: Vec<u8>) -> Self {
+    pub fn new(data: Vec<u8>) -> Self {
         Self {
             escrow_index: 255,
             data,
         }
     }

Since no existing call sites were found, this rename poses no integration risk.

Comment on lines +26 to +28
pub fn data(&self) -> &Vec<u8> {
&self.data
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Return &[u8] instead of &Vec<u8> for idiomatic Rust.

Returning &Vec<u8> is considered an anti-pattern in Rust because it exposes the implementation detail and limits flexibility. Instead, return &[u8], which works with vectors, arrays, and slices. Callers can still obtain &Vec<u8> via deref coercion if needed.

Apply this diff:

-    pub fn data(&self) -> &Vec<u8> {
-        &self.data
+    pub fn data(&self) -> &[u8] {
+        &self.data
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn data(&self) -> &Vec<u8> {
&self.data
}
pub fn data(&self) -> &[u8] {
&self.data
}
🤖 Prompt for AI Agents
In magicblock-magic-program-api/src/args.rs around lines 26 to 28, the accessor
currently returns &Vec<u8> which leaks the implementation; change the method
signature to return a slice (&[u8]) instead and return a slice of the vector
(e.g., via as_slice() or a full-range slice) so callers get a &[u8] while the
internal field remains Vec<u8>.

@jonasXchen jonasXchen merged commit 91c606b into master Nov 21, 2025
18 checks passed
@jonasXchen jonasXchen deleted the jonasXchen/magic-action-args branch November 21, 2025 12:03
thlorenz added a commit that referenced this pull request Nov 21, 2025
* master:
  feat: detecting accounts stuck in undelegating state and fixing that (#664)
  feat: ActionArgs::default() to abstract escrow_index (#662)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants