-
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
"type": "object", | ||
"$defs": { | ||
"localization": { | ||
"type": "string", | ||
"pattern": "^[\\p{L}\\p{N}]*$", | ||
"minLength": 1, | ||
"maxLength": 64, | ||
"$comment": "Allow only alphanumeric characters" | ||
} | ||
}, | ||
"properties": { | ||
"shouldCapitalize": { | ||
"type": "boolean", | ||
"description": "TODO" | ||
}, | ||
"localizations": { | ||
"type": "object", | ||
"description": "TODO", | ||
"additionalProperties": { | ||
"type": "object", | ||
"properties": { | ||
"singular": { | ||
"$ref": "#/$defs/localization" | ||
}, | ||
"plural": { | ||
"$ref": "#/$defs/localization" | ||
} | ||
}, | ||
"required": ["singular", "plural"], | ||
"additionalProperties": false | ||
}, | ||
"maxProperties": 255, | ||
"minProperties": 1 | ||
}, | ||
"maintainer": { | ||
"type": "array", | ||
"contentMediaType": "application/x.dash.dpp.identifier", | ||
"byteArray": true, | ||
"minItems": 32, | ||
"maxItems": 32, | ||
"description": "TODO" | ||
}, | ||
"initialSupply": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"description": "TODO" | ||
}, | ||
"decimals": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"description": "TODO" | ||
}, | ||
"maxSupply": { | ||
"type": "integer", | ||
"minimum": 1, | ||
"description": "TODO" | ||
}, | ||
"permissions": { | ||
"type": "object", | ||
"properties": { | ||
"maintainer": { | ||
"type": "object", | ||
"properties": { | ||
"canMint": { | ||
"type": "boolean" | ||
}, | ||
"canBurn": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": ["canBurn", "canMint"] | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"minProperties": 1, | ||
"description": "TODO" | ||
}, | ||
"description": { | ||
"type": "string", | ||
"maxLength": 1024, | ||
"description": "Token description" | ||
}, | ||
"metadata": { | ||
"type": "object", | ||
"propertyNames": { | ||
"type": "string", | ||
"maxLength": 255, | ||
}, | ||
"additionalProperties": { | ||
"type": "string", | ||
"maxLength": 1024, | ||
}, | ||
"minProperties": 1, | ||
"maxProperties": 255, | ||
"description": "Token arbitrary metadata", | ||
} | ||
QuantumExplorer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"required": [ | ||
"initialSupply", | ||
"decimals" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,10 +36,14 @@ lazy_static! { | |
"../../../schema/meta_schemas/draft2020-12/meta/content.json" | ||
)) | ||
.expect("Valid schema!"); | ||
static ref DATA_CONTRACT_V0: Value = serde_json::from_str::<Value>(include_str!( | ||
static ref DOCUMENT_META_JSON_V0: Value = serde_json::from_str::<Value>(include_str!( | ||
"../../../schema/meta_schemas/document/v0/document-meta.json" | ||
)) | ||
.unwrap(); | ||
static ref TOKEN_META_JSON_V0: Value = serde_json::from_str::<Value>(include_str!( | ||
"../../../schema/meta_schemas/token/v0/token-meta.json" | ||
)) | ||
.unwrap(); | ||
|
||
pub static ref DRAFT_202012_META_SCHEMA: JSONSchema = JSONSchema::options() | ||
.with_draft(Draft::Draft202012) | ||
|
@@ -85,8 +89,7 @@ lazy_static! { | |
.compile(&DRAFT202012) | ||
.expect("Invalid data contract schema"); | ||
|
||
|
||
// Compiled version of data contract meta schema | ||
// Compiled version of document meta schema | ||
pub static ref DOCUMENT_META_SCHEMA_V0: JSONSchema = JSONSchema::options() | ||
.with_keyword( | ||
"byteArray", | ||
|
@@ -137,6 +140,60 @@ lazy_static! { | |
DRAFT202012.clone(), | ||
) | ||
.to_owned() | ||
.compile(&DATA_CONTRACT_V0) | ||
.compile(&DOCUMENT_META_JSON_V0) | ||
.expect("Invalid data contract schema"); | ||
|
||
// 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) | ||
Comment on lines
+146
to
+197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider reducing code duplication in schema configurations The configuration for 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"); |
||
.expect("Invalid data contract schema"); | ||
} |
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 pathThe schema's
$id
URL referencesdocument-meta.json
instead oftoken-meta.json
.Apply this fix:
📝 Committable suggestion