Skip to content

[TA-4885]: Add MPTCurrency Amount#140

Merged
GuillemGarciaDev merged 13 commits intov0.1.xfrom
xrpl/feat/mpt_currency_amount
Jun 30, 2025
Merged

[TA-4885]: Add MPTCurrency Amount#140
GuillemGarciaDev merged 13 commits intov0.1.xfrom
xrpl/feat/mpt_currency_amount

Conversation

@banasa44
Copy link

@banasa44 banasa44 commented Jun 19, 2025

[TA-4885]: Add MPTCurrency Amount

Changes 🛠️

binary-codec/types

  • Add functions to serialize and deserialize MPTCurrencyAmount
  • Add unit tests

xrpl/transaction

  • Add MPTCurrencyAmount for currency kinds
  • Add unit tests

Changelog

Summary by CodeRabbit

  • New Features

    • Added support for Multi-Party Token (MPT) amounts, including serialization, deserialization, and JSON conversion.
    • Introduced a new currency type for MPT, enabling handling of MPT currency amounts in transactions.
  • Tests

    • Added comprehensive unit tests for MPT currency value validation, serialization, deserialization, and JSON handling.
  • Documentation

    • Updated changelog to reflect the addition of MPTToken and MPTCurrencyAmount features.

@coderabbitai
Copy link

coderabbitai bot commented Jun 19, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

"""

Walkthrough

Support for a new MPT (Multi-Party Token) currency amount type is introduced across the codebase. This includes serialization, deserialization, validation, and JSON handling in the binary codec, as well as new types and unmarshaling logic in the transaction layer. Comprehensive unit tests and changelog updates accompany these changes.

Changes

Files/Groups Change Summary
CHANGELOG.md Updated with entries for MPTToken and MPTCurrencyAmount features, clarifying ongoing and new feature documentation.
binary-codec/types/amount.go Added MPT amount support: constants, error types, serialization/deserialization/validation functions, JSON logic.
binary-codec/types/amount_test.go Added unit tests for MPT value/issuance ID/amount verification, serialization, deserialization, and JSON handling.
xrpl/transaction/types/currency_amount.go Added MPT currency kind, MPTCurrencyAmount struct, and extended unmarshaling logic for MPT JSON objects.
xrpl/transaction/types/currency_amount_test.go Added unit tests for MPTCurrencyAmount's methods and unmarshaling from JSON.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Codec as BinaryCodec
    participant XRPL as TransactionLayer

    Client->>Codec: FromJSON({value, mpt_issuance_id})
    Codec->>Codec: serializeMPTCurrencyAmount(value, mpt_issuance_id)
    Codec-->>Client: []byte (MPT amount)

    Client->>Codec: ToJSON([]byte MPT amount)
    Codec->>Codec: deserializeMPTAmount([]byte)
    Codec-->>Client: {value, mpt_issuance_id}

    Client->>XRPL: UnmarshalCurrencyAmount(JSON with mpt_issuance_id)
    XRPL->>XRPL: Unmarshal into MPTCurrencyAmount
    XRPL-->>Client: MPTCurrencyAmount instance
Loading

Suggested labels

feature, xrpl

Suggested reviewers

  • AdriaCarrera
  • florent-uzio

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@notion-workspace
Copy link

Copy link

@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

🧹 Nitpick comments (1)
CHANGELOG.md (1)

14-17: Minor style improvement: Consider varying sentence beginnings.

While the content accurately documents the MPT additions, consider varying the sentence structure to improve readability by replacing some instances of "Adds" with alternatives like "Introduces" or "Implements".

- Adds `MPToken` definitions.
+ Introduces `MPToken` definitions.
- Adds functions to serialize and deserialize `MPTCurrencyAmount`.
+ Implements functions to serialize and deserialize `MPTCurrencyAmount`.
- Adds unit tests for `MPTCurrencyAmount`.
+ Provides unit tests for `MPTCurrencyAmount`.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b8142e and 31c8607.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • binary-codec/types/amount.go (8 hunks)
  • binary-codec/types/amount_test.go (4 hunks)
  • xrpl/transaction/types/currency_amount.go (3 hunks)
  • xrpl/transaction/types/currency_amount_test.go (1 hunks)
🧰 Additional context used
🪛 LanguageTool
CHANGELOG.md

[style] ~16-~16: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...definitions. - AddsHash192` type. - Adds functions to serialize and deserialize ...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~17-~17: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... and deserialize MPTCurrencyAmount. - Adds unit tests for MPTCurrencyAmount. ##...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🪛 golangci-lint (1.64.8)
binary-codec/types/amount.go

[high] 558-558: G115: integer overflow conversion uint64 -> uint32

(gosec)


[high] 559-559: G115: integer overflow conversion uint64 -> uint32

(gosec)

🪛 GitHub Actions: XRPL-GO Lint and Test
binary-codec/types/amount.go

[error] 558-559: golangci-lint (gosec): G115 integer overflow conversion uint64 -> uint32 at lines 558 and 559.

🔇 Additional comments (16)
CHANGELOG.md (1)

22-23: Documentation accurately reflects the new MPT features.

The changelog entries correctly document the addition of MPTCurrencyAmount support and corresponding unit tests.

xrpl/transaction/types/currency_amount_test.go (3)

57-62: Well-implemented unit test for MPT currency kind.

The test correctly verifies that MPTCurrencyAmount.Kind() returns the MPT enum value.


64-128: Comprehensive test coverage for Flatten() method.

Excellent test coverage with proper edge cases:

  • Empty MPT amount
  • Partial data (ID only, value only)
  • Complete data (both ID and value)

The assertion logic properly validates both the structure and content of the flattened output.


130-143: Proper JSON unmarshaling test for MPT amounts.

The test correctly validates that JSON containing mpt_issuance_id is properly unmarshaled into an MPTCurrencyAmount instance with correct field values.

xrpl/transaction/types/currency_amount.go (3)

13-13: Correct addition of MPT currency kind.

The MPT enum value is properly added to the CurrencyKind type, maintaining the established pattern.


27-38: Well-implemented MPT detection in unmarshaling logic.

The logic correctly identifies MPT amounts by checking for the presence of mpt_issuance_id key in the JSON object and properly unmarshals into the MPTCurrencyAmount struct.


132-150: Properly implemented MPTCurrencyAmount type.

The struct definition and interface implementation follow established patterns:

  • Clear field names with appropriate JSON tags
  • Kind() method returns correct enum value
  • Flatten() method conditionally includes non-empty fields
binary-codec/types/amount_test.go (3)

108-156: Comprehensive MPT value validation testing.

Excellent test coverage including:

  • Valid integer values (including zero and large numbers)
  • Invalid cases (decimals, negative numbers, non-numeric, high bit set)
  • Proper error type validation

489-819: Thorough serialization and deserialization test coverage.

The test suite comprehensively covers:

  • Valid value serialization with expected byte outputs
  • Issuance ID encoding/decoding with proper length validation
  • Complete MPT amount round-trip testing
  • Error handling for malformed inputs

All test cases include proper assertions for both success and error scenarios.


895-929: Well-integrated MPT support in Amount JSON tests.

The existing Amount JSON marshalling/unmarshalling tests are properly extended to include MPT currency amounts, ensuring full integration with the Amount type's JSON handling.

Also applies to: 1012-1028

binary-codec/types/amount.go (6)

32-38: Well-defined MPT constants and error variables.

The constants properly define MPT-specific byte lengths, markers, and masks. The error variables provide clear, specific error messages for MPT validation failures.

Also applies to: 50-52


96-99: Correct MPT detection logic in FromJSON.

The logic properly distinguishes between issued currency amounts (with "issuer" key) and MPT amounts (with "mpt_issuance_id" key), delegating to the appropriate serialization function.


116-122: Proper MPT detection in ToJSON deserialization.

The bit masking logic correctly identifies MPT amounts using the 0x20 bit pattern and properly handles the 33-byte MPT amount structure.


215-270: Well-implemented MPT deserialization functions.

The deserialization logic properly:

  • Handles sign bits and extracts 64-bit mantissa using big.Int operations
  • Validates byte lengths and extracts issuance IDs
  • Combines components into proper map structure

329-353: Comprehensive MPT value validation.

The validation function properly checks:

  • No decimal points (integers only)
  • Non-negative values
  • High bit not set to avoid conflicts with other amount types

565-574: Solid MPT serialization helper functions.

The issuance ID and complete amount serialization functions properly:

  • Validate hex decoding and byte lengths
  • Combine components with correct marker byte placement
  • Handle error propagation appropriately

Also applies to: 578-598

Copy link
Collaborator

@GuillemGarciaDev GuillemGarciaDev left a comment

Choose a reason for hiding this comment

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

First review!

@GuillemGarciaDev GuillemGarciaDev changed the base branch from main to v0.1.x June 19, 2025 14:15
@GuillemGarciaDev
Copy link
Collaborator

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jun 20, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@GuillemGarciaDev GuillemGarciaDev merged commit 84e4c88 into v0.1.x Jun 30, 2025
5 checks passed
@GuillemGarciaDev GuillemGarciaDev deleted the xrpl/feat/mpt_currency_amount branch June 30, 2025 07:52
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.

2 participants