-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes introduce a new JSON schema for token metadata in the Changes
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@coderabbitai review all |
@lklimek: I will review all the changes. ✅ Actions performedFull review triggered. |
There was a problem hiding this 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 descriptionsSeveral 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 constraintsThe 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 callsThe 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
📒 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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
"$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", |
// 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) |
There was a problem hiding this comment.
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>
Issue being fixed or feature implemented
What was done?
How Has This Been Tested?
Breaking Changes
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit
New Features
initialSupply
,decimals
, andpermissions
.Improvements