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

feat(dpp): token meta schema #2378

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

shumkov
Copy link
Member

@shumkov shumkov commented Dec 5, 2024

Issue being fixed or feature implemented

What was done?

How Has This Been Tested?

Breaking Changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Introduced a new JSON schema for token metadata, defining key attributes such as initialSupply, decimals, and permissions.
    • Added validation support for the new token metadata schema.
  • Improvements

    • Enhanced clarity in schema handling by renaming and reorganizing variables related to document and token schemas.

Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

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

The changes introduce a new JSON schema for token metadata in the token-meta.json file, which includes various properties defining token attributes such as shouldCapitalize, localizations, and permissions. Additionally, modifications in the mod.rs file rename an existing static variable and add a new one for the token schema, enhancing clarity in the schema handling. The updates ensure that both document and token schemas are distinctly managed within the validation module.

Changes

File Path Change Summary
packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json Added a new JSON schema for token metadata with various defined properties and constraints.
packages/rs-dpp/src/validation/meta_validators/mod.rs Renamed DATA_CONTRACT_V0 to DOCUMENT_META_JSON_V0, added TOKEN_META_JSON_V0, and updated related schema references.

Poem

In the garden of code, a new schema blooms,
With tokens and metadata, it brightly looms.
A hop and a skip, the changes take flight,
Document and token, now clearer and bright!
So let’s dance through the lines, with joy we shall sing,
For each little change, a new springtime they bring! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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

@lklimek
Copy link
Contributor

lklimek commented Dec 6, 2024

@coderabbitai review all

Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

@lklimek: I will review all the changes.

✅ Actions performed

Full review triggered.

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

🧹 Outside diff range and nitpick comments (3)
packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json (2)

17-17: Complete TODO descriptions

Several properties are missing proper descriptions, marked with TODO comments. This affects documentation quality and schema usability.

Please provide meaningful descriptions for:

  • shouldCapitalize
  • localizations
  • maintainer
  • initialSupply
  • decimals
  • maxSupply
  • permissions

Also applies to: 21-21, 44-44, 49-49, 54-54, 59-59, 80-80


46-60: Consider adding maximum value constraints

The numeric properties (initialSupply, decimals, maxSupply) only have minimum value constraints. Consider adding maximum values to prevent potential overflow issues.

Consider adding maximum constraints:

    "initialSupply": {
      "type": "integer",
      "minimum": 0,
+     "maximum": 9007199254740991,  // Number.MAX_SAFE_INTEGER
      "description": "TODO"
    },
    "decimals": {
      "type": "integer",
      "minimum": 0,
+     "maximum": 18,  // Common maximum for token decimals
      "description": "TODO"
    },
    "maxSupply": {
      "type": "integer",
      "minimum": 1,
+     "maximum": 9007199254740991,  // Number.MAX_SAFE_INTEGER
      "description": "TODO"
    },
packages/rs-dpp/src/validation/meta_validators/mod.rs (1)

144-144: Update error messages in expect calls

The error messages in the expect calls still reference "data contract schema" instead of the specific schema type.

Apply these changes:

-        .expect("Invalid data contract schema");
+        .expect("Invalid document meta schema");

-        .expect("Invalid data contract schema");
+        .expect("Invalid token meta schema");

Also applies to: 197-197

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c72013b and d98c15e.

📒 Files selected for processing (2)
  • packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json (1 hunks)
  • packages/rs-dpp/src/validation/meta_validators/mod.rs (3 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json

[error] 92-92: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 96-96: Expected a property but instead found '}'.

Expected a property here.

(parse)


[error] 100-100: Expected a property but instead found '}'.

Expected a property here.

(parse)

🔇 Additional comments (1)
packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json (1)

38-45: Verify maintainer identifier format

The maintainer property uses a custom media type application/x.dash.dpp.identifier.

Let's verify if this media type is consistently used across the codebase:

✅ Verification successful

Based on the search results, I can see that the custom media type application/x.dash.dpp.identifier is consistently used across multiple JSON schema files in the test vectors, specifically for the identity property within the records object of domain documents. The format appears to be standardized and follows the same pattern with identical constraints (32-byte array) in all instances.

Custom identifier format is consistently used

The application/x.dash.dpp.identifier media type is consistently used throughout the codebase for identity references, with standardized constraints:

  • Always used with 32-byte arrays
  • Applied to identity references in domain records
  • Maintains consistent validation rules across all schema definitions
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the custom media type usage
rg "application/x\.dash\.dpp\.identifier" --type json

Length of output: 69871

@@ -0,0 +1,106 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/dashpay/platform/blob/master/packages/rs-dpp/schema/meta_schemas/document/v0/document-meta.json",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect $id URL path

The schema's $id URL references document-meta.json instead of token-meta.json.

Apply this fix:

-  "$id": "https://github.com/dashpay/platform/blob/master/packages/rs-dpp/schema/meta_schemas/document/v0/document-meta.json",
+  "$id": "https://github.com/dashpay/platform/blob/master/packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json",
📝 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
"$id": "https://github.com/dashpay/platform/blob/master/packages/rs-dpp/schema/meta_schemas/document/v0/document-meta.json",
"$id": "https://github.com/dashpay/platform/blob/master/packages/rs-dpp/schema/meta_schemas/token/v0/token-meta.json",

Comment on lines +146 to +197
// Compiled version of token meta schema
pub static ref TOKEN_META_SCHEMA_V0: JSONSchema = JSONSchema::options()
.with_keyword(
"byteArray",
|_, _, _| Ok(Box::new(ByteArrayKeyword)),
)
.with_patterns_regex_engine(RegexEngine::Regex(RegexOptions {
size_limit: Some(5 * (1 << 20)),
..Default::default()
}))
.should_ignore_unknown_formats(false)
.should_validate_formats(true)
.with_patterns_regex_engine(RegexEngine::Regex(Default::default()))
.with_draft(Draft::Draft202012)
.with_document(
"https://json-schema.org/draft/2020-12/meta/applicator".to_string(),
DRAFT202012_APPLICATOR.clone(),
)
.with_document(
"https://json-schema.org/draft/2020-12/meta/core".to_string(),
DRAFT202012_CORE.clone(),
)
.with_document(
"https://json-schema.org/draft/2020-12/meta/applicator".to_string(),
DRAFT202012_APPLICATOR.clone(),
)
.with_document(
"https://json-schema.org/draft/2020-12/meta/unevaluated".to_string(),
DRAFT202012_UNEVALUATED.clone(),
)
.with_document(
"https://json-schema.org/draft/2020-12/meta/validation".to_string(),
DRAFT202012_VALIDATION.clone(),
)
.with_document(
"https://json-schema.org/draft/2020-12/meta/meta-data".to_string(),
DRAFT202012_META_DATA.clone(),
)
.with_document(
"https://json-schema.org/draft/2020-12/meta/format-annotation".to_string(),
DRAFT202012_FORMAT_ANNOTATION.clone(),
)
.with_document(
"https://json-schema.org/draft/2020-12/meta/content".to_string(),
DRAFT202012_CONTENT.clone(),
)
.with_document(
"https://json-schema.org/draft/2020-12/schema".to_string(),
DRAFT202012.clone(),
)
.to_owned()
.compile(&TOKEN_META_JSON_V0)
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

Consider reducing code duplication in schema configurations

The configuration for TOKEN_META_SCHEMA_V0 is identical to DOCUMENT_META_SCHEMA_V0. This duplication increases maintenance overhead.

Consider extracting the common configuration into a helper function:

fn create_base_schema_options() -> jsonschema::CompilationOptions {
    JSONSchema::options()
        .with_keyword(
            "byteArray",
            |_, _, _| Ok(Box::new(ByteArrayKeyword)),
        )
        .with_patterns_regex_engine(RegexEngine::Regex(RegexOptions {
            size_limit: Some(5 * (1 << 20)),
            ..Default::default()
        }))
        .should_ignore_unknown_formats(false)
        .should_validate_formats(true)
        .with_patterns_regex_engine(RegexEngine::Regex(Default::default()))
        .with_draft(Draft::Draft202012)
        // Add all the .with_document calls here
        .to_owned()
}

// Usage:
pub static ref TOKEN_META_SCHEMA_V0: JSONSchema = create_base_schema_options()
    .compile(&TOKEN_META_JSON_V0)
    .expect("Invalid token meta schema");

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@QuantumExplorer QuantumExplorer merged commit b9235d2 into feat/tokenSupport Dec 10, 2024
3 checks passed
@QuantumExplorer QuantumExplorer deleted the feat/shemaForTokenSupport branch December 10, 2024 07:05
@QuantumExplorer QuantumExplorer restored the feat/shemaForTokenSupport branch December 10, 2024 07:05
@QuantumExplorer QuantumExplorer deleted the feat/shemaForTokenSupport branch December 10, 2024 07:06
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