Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add MPTAmount support in Issue model #2919

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

achowdhry-ripple
Copy link
Collaborator

@achowdhry-ripple achowdhry-ripple commented Mar 4, 2025

High Level Overview of Change

Add MPTAmount support in the Issue object. Parallel to XRPLF/xrpl-py#809

Context of Change

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

Did you update HISTORY.md?

  • Yes
  • No, this change does not impact library users

Test Plan

Copy link

coderabbitai bot commented Mar 4, 2025

Walkthrough

The changes introduce a new section titled "Fixed" in the HISTORY.md file to document the addition of support for MPTAmount in the Issue. Additionally, the IssueObject type has been redefined from an interface to a union type comprising three distinct interfaces: XRPIssue, IOUIssue, and MPTIssue. The Issue class methods have been updated to accommodate these changes, enhancing the handling and serialization of different issue types.

Changes

File(s) Change Summary
packages/ripple-binary-codec/HISTORY.md Added "Fixed" section documenting support for MPTAmount.
packages/ripple-binary-codec/src/types/issue.ts Redefined IssueObject as a union type; added interfaces XRPIssue, IOUIssue, and MPTIssue; updated isIssueObject type guard and Issue class methods for improved handling and serialization.
packages/ripple-binary-codec/test/issue.test.ts Introduced unit tests for Issue type conversion functions, validating Issue.from and Issue.fromParser methods.

Suggested reviewers

  • pdp2121
  • ckeshava

Poem

I'm a little rabbit with code in my heart,
Hopping through changes, playing my part.
MPT support sprouted like a carrot so sweet,
Nibbling on bytes with a happy beat.
With every fix, I hop with delight—
Our code now dances in the moonlight! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

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.

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

🔭 Outside diff range comments (1)
packages/ripple-binary-codec/src/types/issue.ts (1)

83-90: ⚠️ Potential issue

Update the fromParser method to handle MPT amounts.

The fromParser method doesn't appear to have been updated to handle MPT amounts. Since you've added support for MPT in other methods, this method should also be updated to ensure consistency when parsing from binary data.

Consider adding logic to detect and handle MPT amounts in the parser:

  static fromParser(parser: BinaryParser): Issue {
    const currency = parser.read(20)
    if (new Currency(currency).toJSON() === 'XRP') {
      return new Issue(currency)
    }
+   // If the currency value matches an MPT issuance format, treat as MPT
+   if (currency.length === Hash192.width / 2) {
+     return new Issue(currency)
+   }
    const currencyAndIssuer = [currency, parser.read(20)]
    return new Issue(concat(currencyAndIssuer))
  }

Please verify this implementation against the xrpl-py repository's approach as mentioned in the PR objectives.

🧹 Nitpick comments (1)
packages/ripple-binary-codec/src/types/issue.ts (1)

1-121: Add tests for MPT amount handling.

With the addition of MPT amount support, it would be beneficial to add tests that verify the serialization and deserialization of MPT amounts to ensure the implementation works correctly for all cases.

Would you like me to help draft some test cases for this implementation?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d55cb3 and 322bfec.

📒 Files selected for processing (2)
  • packages/ripple-binary-codec/HISTORY.md (1 hunks)
  • packages/ripple-binary-codec/src/types/issue.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: snippets (22.x)
  • GitHub Check: snippets (20.x)
  • GitHub Check: integration (22.x)
  • GitHub Check: snippets (18.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: integration (18.x)
  • GitHub Check: browser (18.x)
🔇 Additional comments (5)
packages/ripple-binary-codec/HISTORY.md (1)

5-6: Documentation looks good.

The added "Fixed" section properly documents the implementation of MPTAmount support in the Issue type, making it clear what change was made in this release.

packages/ripple-binary-codec/src/types/issue.ts (4)

7-7: Appropriate import for MPT support.

The Hash192 import is correctly added to handle the MPT issuance ID in the Issue type.


13-16: Interface modifications look good.

The changes to the IssueObject interface are appropriate:

  • Making currency optional allows for cases where only an MPT issuance ID is present
  • Adding the optional mpt_issuance_id property supports the new MPT functionality

These changes align with the PR's objective of adding MPTAmount support.


23-29: Type guard logic properly updated.

The isIssueObject function is correctly updated to handle all three cases:

  • XRP case: object has only a currency property
  • IOU case: object has both currency and issuer properties
  • MPT case: object has only an mpt_issuance_id property

This comprehensive type guard ensures proper validation for all supported Issue object types.


54-72: Implementation of MPT case in from method looks good.

The static from method has been properly updated to handle the three cases:

  1. IOU case (when both currency and issuer are present)
  2. XRP case (when only currency is present)
  3. MPT case (when mpt_issuance_id is present)

The code structure is clear and the implementation is correct.

Comment on lines 98 to 104
// If the buffer is exactly 24 bytes, treat it as an MPT amount.
if (this.toBytes.length === Hash192.width) {
return {
mpt_issuance_id: this.toHex().toUpperCase(),
}
}

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix method call in toJSON implementation.

There appears to be a syntax error when checking the byte length. The toBytes should be called as a method, not accessed as a property.

-    if (this.toBytes.length === Hash192.width) {
+    if (this.toBytes().length === Hash192.width) {
📝 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
// If the buffer is exactly 24 bytes, treat it as an MPT amount.
if (this.toBytes.length === Hash192.width) {
return {
mpt_issuance_id: this.toHex().toUpperCase(),
}
}
// If the buffer is exactly 24 bytes, treat it as an MPT amount.
- if (this.toBytes.length === Hash192.width) {
+ if (this.toBytes().length === Hash192.width) {
return {
mpt_issuance_id: this.toHex().toUpperCase(),
}
}

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: 0

🔭 Outside diff range comments (1)
packages/ripple-binary-codec/src/types/issue.ts (1)

92-99: 🛠️ Refactor suggestion

Update fromParser method to handle MPT Issue types.

The fromParser method hasn't been updated to handle MPT issue types, which could lead to issues when parsing serialized MPT Issues. Consider adding support for MPT Issue types in this method.

static fromParser(parser: BinaryParser): Issue {
  const currency = parser.read(20)
  if (new Currency(currency).toJSON() === 'XRP') {
    return new Issue(currency)
  }
+ 
+ // Check if this is an MPT issue (should be exactly Hash192.width bytes)
+ if (currency.length === Hash192.width) {
+   return new Issue(currency)
+ }
+ 
  const currencyAndIssuer = [currency, parser.read(20)]
  return new Issue(concat(currencyAndIssuer))
}
♻️ Duplicate comments (1)
packages/ripple-binary-codec/src/types/issue.ts (1)

107-113: ⚠️ Potential issue

Fix method call in toJSON implementation.

There appears to be a syntax error when checking the byte length. The toBytes should be called as a method, not accessed as a property.

-    if (this.toBytes.length === Hash192.width) {
+    if (this.toBytes().length === Hash192.width) {
🧹 Nitpick comments (3)
packages/ripple-binary-codec/src/types/issue.ts (3)

48-54: Update JSDoc to include MPT issue type.

The JSDoc comment for the from method should be updated to include the MPT issue type.

/**
 * Construct an amount from an IOU or string amount
 *
- * @param value An Amount, object representing an IOU, or a string
+ * @param value An Amount, object representing an XRP, IOU, or MPT issue, or a string
 *     representing an integer amount
 * @returns An Amount object
 */

55-55: Consider implementing stronger type checking in the from method.

The current implementation relies on checking properties in a specific order. Consider making the type guard more explicit to handle unexpected combinations of properties.

static from<T extends Issue | IssueObject>(value: T): Issue {
  if (value instanceof Issue) {
    return value
  }

  if (isIssueObject(value)) {
+   // Handle each type explicitly rather than relying on property checks
+   if ('mpt_issuance_id' in value) {
+     const mptIssuanceIdBytes = Hash192.from(
+       value.mpt_issuance_id.toString(),
+     ).toBytes()
+     return new Issue(mptIssuanceIdBytes)
+   } else if ('currency' in value) {
+     const currency = Currency.from(value.currency.toString()).toBytes()
+     
+     if ('issuer' in value) {
+       const issuer = AccountID.from(value.issuer.toString()).toBytes()
+       return new Issue(concat([currency, issuer]))
+     }
+     
+     return new Issue(currency)
+   }
-   if (value.currency) {
-     const currency = Currency.from(value.currency.toString()).toBytes()
-
-     //IOU case
-     if (value.issuer) {
-       const issuer = AccountID.from(value.issuer.toString()).toBytes()
-       return new Issue(concat([currency, issuer]))
-     }
-
-     //XRP case
-     return new Issue(currency)
-   }
-
-   // MPT case
-   if (value.mpt_issuance_id) {
-     const mptIssuanceIdBytes = Hash192.from(
-       value.mpt_issuance_id.toString(),
-     ).toBytes()
-     return new Issue(mptIssuanceIdBytes)
-   }
  }

  throw new Error('Invalid type to construct an Amount')
}

83-83: Improve error message specificity.

The current error message is generic. Consider providing more specific error messages for different failure scenarios.

- throw new Error('Invalid type to construct an Amount')
+ throw new Error('Invalid type to construct an Issue: expected Issue instance or IssueObject with valid properties')
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 322bfec and a877ba8.

📒 Files selected for processing (1)
  • packages/ripple-binary-codec/src/types/issue.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: snippets (22.x)
  • GitHub Check: unit (20.x)
  • GitHub Check: snippets (20.x)
  • GitHub Check: unit (18.x)
  • GitHub Check: integration (22.x)
  • GitHub Check: snippets (18.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: integration (18.x)
  • GitHub Check: browser (18.x)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (5)
packages/ripple-binary-codec/src/types/issue.ts (5)

7-7: LGTM: Adding Hash192 import for MPT support.

The import of Hash192 is correctly added to support the new MPTIssue type.


9-19: Well-structured type definitions for Issue types.

The interfaces are cleanly structured to represent the three distinct issue types:

  • XRPIssue: Contains only currency
  • IOUIssue: Contains currency and issuer
  • MPTIssue: Contains mpt_issuance_id

This approach provides good type safety and clarity.


23-23: Good union type approach for IssueObject.

Converting IssueObject from an interface to a union type is the correct approach to handle the different issue variants.


28-36: Correctly updated type guard for the new union type.

The isIssueObject type guard has been properly updated to handle all three issue types. The implementation is clean and follows a logical pattern.


61-81: Well-implemented Issue handling in the from method.

The from method has been correctly updated to handle all three issue types with appropriate branching logic.


it(`test from value mpt`, () => {
const mptJson = {
// value: '100', // MPT amounts must be an integer string (no decimal point)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@khancode saw value in the python tests, but wasn't sure whether to add it here based on our discussions. Seems like it should be here, but that would require me to change the isMPT logic in Issue to something different than what we discussed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you check if value is included when Issue.from is normally called? If yes, then we should add it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Issue.from accepts both types in the input parameter.

static from<T extends Issue | IssueObject>(value: T): Issue

It should work either ways

@achowdhry-ripple achowdhry-ripple changed the title Mptamount issue support fix: add MPTAmount support in Issue model Mar 5, 2025
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 (3)
packages/ripple-binary-codec/src/types/issue.ts (3)

28-36: Type guard implementation could be more robust

The current implementation of isIssueObject relies on checking the existence and order of keys, which might be brittle if object properties are reordered. Consider enhancing the type guard to also validate the types of the values:

function isIssueObject(arg): arg is IssueObject {
  const keys = Object.keys(arg).sort()
  const isXRP = keys.length === 1 && keys[0] === 'currency'
  const isIOU =
    keys.length === 2 && keys[0] === 'currency' && keys[1] === 'issuer'
  const isMPT = keys.length === 1 && keys[0] === 'mpt_issuance_id'

+  // Additional validation for value types
+  if (isXRP && typeof arg.currency !== 'string') return false
+  if (isIOU && (typeof arg.currency !== 'string' || typeof arg.issuer !== 'string')) return false
+  if (isMPT && typeof arg.mpt_issuance_id !== 'string') return false

  return isXRP || isIOU || isMPT
}

48-54: Update JSDoc comment for the from method

The JSDoc comment for the from method needs to be updated to reflect the addition of MPT issue support.

/**
 * Construct an amount from an IOU or string amount
 *
 * @param value An Amount, object representing an IOU, or a string
 *     representing an integer amount
- * @returns An Issue object
+ * @param value An Amount, object representing an XRP issue, IOU issue, MPT issue, or a string
+ *     representing an integer amount
+ * @returns An Issue object representing XRP, IOU, or MPT
 */

75-81: Add validation for MPT issuance ID format

Currently, the code doesn't validate the format of the mpt_issuance_id string beyond passing it to Hash192.from(). Consider adding explicit validation to ensure it meets the expected format.

// MPT case
if (value.mpt_issuance_id) {
+  // Validate mpt_issuance_id format (should be 48 characters of hex)
+  const mptId = value.mpt_issuance_id.toString()
+  if (!/^[0-9A-Fa-f]{48}$/.test(mptId)) {
+    throw new Error('Invalid MPT issuance ID format')
+  }
  const mptIssuanceIdBytes = Hash192.from(
    value.mpt_issuance_id.toString(),
  ).toBytes()
  return new Issue(mptIssuanceIdBytes)
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a877ba8 and 6680559.

📒 Files selected for processing (2)
  • packages/ripple-binary-codec/src/types/issue.ts (4 hunks)
  • packages/ripple-binary-codec/test/issue.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: snippets (22.x)
  • GitHub Check: snippets (20.x)
  • GitHub Check: snippets (18.x)
  • GitHub Check: integration (22.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: integration (18.x)
🔇 Additional comments (7)
packages/ripple-binary-codec/test/issue.test.ts (2)

29-36: Good implementation of MPT issue test case

The test case properly verifies that an MPT issue with a mpt_issuance_id can be created and correctly serialized back to JSON.

There's a commented-out line about value property with an explanation that "MPT amounts must be an integer string (no decimal point)". This comment provides helpful context about the constraints of MPT amounts.


79-86: Comprehensive error handling test

Good job including a test case for invalid input handling. The test properly verifies that the Issue.from method throws an appropriate error message when given invalid input.

packages/ripple-binary-codec/src/types/issue.ts (5)

7-7: Good addition of Hash192 import

The addition of the Hash192 import is necessary for handling MPT issuance IDs, which are 192-bit hashes.


9-23: Well-structured type definitions for different issue types

Breaking down the IssueObject into three distinct interfaces (XRPIssue, IOUIssue, and MPTIssue) improves type safety and makes the code more maintainable. The union type definition in line 23 properly combines these interfaces.


55-81: Structured handling of different issue types

The implementation of the from method properly handles all three types of issues (XRP, IOU, and MPT). The structure is clear with dedicated code paths for each case.


95-106: Proper implementation of MPT parsing with hint parameter

The fromParser method has been updated to handle MPT issues by checking if the hint parameter matches Hash192.width. This approach is efficient and clear.


113-119: Fix method call in toJSON implementation

The issue identified in the previous review regarding this.toBytes has been correctly fixed to this.toBytes().

The implementation properly handles MPT issues by checking if the byte length matches Hash192.width and returning an appropriate object with mpt_issuance_id.

Comment on lines +68 to +77
it(`test from parser mpt`, () => {
const mptJson = {
// value: '100', // MPT amounts must be an integer string (no decimal point)
mpt_issuance_id: 'BAADF00DBAADF00DBAADF00DBAADF00DBAADF00DBAADF00D',
}
const mptIssue = Issue.from(mptJson)
const parser = new BinaryParser(mptIssue.toHex())
const parserIssue = Issue.fromParser(parser, 24)
expect(parserIssue.toJSON()).toMatchObject(mptJson)
})
Copy link

@coderabbitai coderabbitai bot Mar 5, 2025

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Ensure hint parameter for MPT parsing is always provided

This test correctly verifies that an MPT issue can be parsed from binary data using the fromParser method. Note that line 75 passes 24 as the hint parameter, which is crucial for correctly identifying and parsing MPT issues.

For clarity and to prevent potential issues, consider adding a test case that verifies behavior when the hint is not provided for an MPT issue.


🏁 Script executed:

#!/bin/bash
# Check if there are any other places in the codebase where fromParser is called for MPT issues without a hint
grep -r "fromParser" --include="*.ts" --include="*.js" . | grep -v "hint" | grep -i "mpt"

Length of output: 194


Action Required: Ensure consistent use of the hint parameter for MPT parsing

The test in packages/ripple-binary-codec/test/issue.test.ts demonstrates that providing a hint (e.g., 24) to Issue.fromParser is essential for correct MPT parsing. However, our search revealed that in packages/ripple-binary-codec/src/types/amount.ts the call to Hash192.fromParser(parser) does not include a hint parameter. Please review this discrepancy and consider the following:

  • Verify whether omitting the hint for Hash192.fromParser is intentional or an oversight.
  • If a hint is required for consistency (or to prevent potential parsing issues), update the invocation accordingly.
  • Additionally, add a test case that verifies the behavior when the hint parameter is not provided for an MPT issue.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@achowdhry-ripple this is a good catch. Hash192 doesn't have a hint parameter.

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Collaborator

Choose a reason for hiding this comment

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

The hint parameter is not used in the Issue.from_parser method. Specifying a hint won't affect the output of the function. I suspect it has been retained for inheritance purposes.

@ckeshava ckeshava self-requested a review March 6, 2025 00:08
expect(iouIssue.toJSON()).toMatchObject(iouJson)
})

it(`test from value nonstandard currency`, () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit

Suggested change
it(`test from value nonstandard currency`, () => {
it(`test from value non-standard currency`, () => {


it(`test from value mpt`, () => {
const mptJson = {
// value: '100', // MPT amounts must be an integer string (no decimal point)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you check if value is included when Issue.from is normally called? If yes, then we should add it.

Comment on lines +68 to +77
it(`test from parser mpt`, () => {
const mptJson = {
// value: '100', // MPT amounts must be an integer string (no decimal point)
mpt_issuance_id: 'BAADF00DBAADF00DBAADF00DBAADF00DBAADF00DBAADF00D',
}
const mptIssue = Issue.from(mptJson)
const parser = new BinaryParser(mptIssue.toHex())
const parserIssue = Issue.fromParser(parser, 24)
expect(parserIssue.toJSON()).toMatchObject(mptJson)
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

@achowdhry-ripple this is a good catch. Hash192 doesn't have a hint parameter.

@@ -39,20 +50,34 @@ class Issue extends SerializedType {
*
* @param value An Amount, object representing an IOU, or a string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* @param value An Amount, object representing an IOU, or a string
* @param value An Amount, object representing an IOU (or) MPTAmount, or a string

currency: string
issuer?: string
}
type IssueObject = XRPIssue | IOUIssue | MPTIssue

/**
* Type guard for AmountObject
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Type guard for AmountObject
* Type guard for Issue Object


it(`test from value mpt`, () => {
const mptJson = {
// value: '100', // MPT amounts must be an integer string (no decimal point)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Issue.from accepts both types in the input parameter.

static from<T extends Issue | IssueObject>(value: T): Issue

It should work either ways

Comment on lines +68 to +77
it(`test from parser mpt`, () => {
const mptJson = {
// value: '100', // MPT amounts must be an integer string (no decimal point)
mpt_issuance_id: 'BAADF00DBAADF00DBAADF00DBAADF00DBAADF00DBAADF00D',
}
const mptIssue = Issue.from(mptJson)
const parser = new BinaryParser(mptIssue.toHex())
const parserIssue = Issue.fromParser(parser, 24)
expect(parserIssue.toJSON()).toMatchObject(mptJson)
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

The hint parameter is not used in the Issue.from_parser method. Specifying a hint won't affect the output of the function. I suspect it has been retained for inheritance purposes.

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