@dashevo/dpns-contract 1.0.0-dev.2 → 1.0.0-dev.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Cargo.toml CHANGED
@@ -1,11 +1,13 @@
1
1
  [package]
2
2
  name = "dpns-contract"
3
3
  description = "DPNS data contract schema and tools"
4
- version = "1.0.0-dev.2"
4
+ version = "1.0.0-dev.4"
5
5
  edition = "2021"
6
6
  rust-version = "1.73"
7
7
  license = "MIT"
8
8
 
9
9
  [dependencies]
10
+ thiserror = "1.0.56"
11
+ platform-version = { path = "../rs-platform-version" }
10
12
  serde_json = { version = "1.0" }
11
13
  platform-value = { path = "../rs-platform-value" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dpns-contract",
3
- "version": "1.0.0-dev.2",
3
+ "version": "1.0.0-dev.4",
4
4
  "description": "A contract and helper scripts for DPNS DApp",
5
5
  "scripts": {
6
6
  "lint": "eslint .",
@@ -31,7 +31,7 @@
31
31
  ],
32
32
  "license": "MIT",
33
33
  "devDependencies": {
34
- "@dashevo/wasm-dpp": "1.0.0-dev.2",
34
+ "@dashevo/wasm-dpp": "1.0.0-dev.4",
35
35
  "chai": "^4.3.10",
36
36
  "dirty-chai": "^2.0.1",
37
37
  "eslint": "^8.53.0",
package/src/error.rs ADDED
@@ -0,0 +1,17 @@
1
+ use platform_version::version::FeatureVersion;
2
+
3
+ #[derive(thiserror::Error, Debug)]
4
+ pub enum Error {
5
+ /// Platform expected some specific versions
6
+ #[error("platform unknown version on {method}, received: {received}")]
7
+ UnknownVersionMismatch {
8
+ /// method
9
+ method: String,
10
+ /// the allowed versions for this method
11
+ known_versions: Vec<FeatureVersion>,
12
+ /// requested core height
13
+ received: FeatureVersion,
14
+ },
15
+ #[error("schema deserialize error: {0}")]
16
+ InvalidSchemaJson(#[from] serde_json::Error),
17
+ }
package/src/lib.rs CHANGED
@@ -1,5 +1,10 @@
1
+ mod error;
2
+ pub mod v1;
3
+
4
+ pub use crate::error::Error;
1
5
  use platform_value::{Identifier, IdentifierBytes32};
2
- use serde_json::{Error, Value};
6
+ use platform_version::version::PlatformVersion;
7
+ use serde_json::Value;
3
8
 
4
9
  pub const ID_BYTES: [u8; 32] = [
5
10
  230, 104, 198, 89, 175, 102, 174, 225, 231, 44, 24, 109, 222, 123, 91, 126, 10, 29, 113, 42, 9,
@@ -11,27 +16,25 @@ pub const OWNER_ID_BYTES: [u8; 32] = [
11
16
  67, 4, 181, 246, 153, 65, 68, 40, 110, 253, 172,
12
17
  ];
13
18
 
14
- pub mod document_types {
15
- pub mod domain {
16
- pub const NAME: &str = "domain";
17
-
18
- pub mod properties {
19
- pub const LABEL: &str = "label";
20
- pub const NORMALIZED_LABEL: &str = "normalizedLabel";
21
- pub const PARENT_DOMAIN_NAME: &str = "parentDomainName";
22
- pub const NORMALIZED_PARENT_DOMAIN_NAME: &str = "normalizedParentDomainName";
23
- pub const PREORDER_SALT: &str = "preorderSalt";
24
- pub const ALLOW_SUBDOMAINS: &str = "subdomainRules.allowSubdomains";
25
- pub const RECORDS: &str = "records";
26
- pub const DASH_UNIQUE_IDENTITY_ID: &str = "dashUniqueIdentityId";
27
- pub const DASH_ALIAS_IDENTITY_ID: &str = "dashAliasIdentityId";
28
- }
29
- }
30
- }
31
-
32
19
  pub const ID: Identifier = Identifier(IdentifierBytes32(ID_BYTES));
33
20
  pub const OWNER_ID: Identifier = Identifier(IdentifierBytes32(OWNER_ID_BYTES));
34
-
35
- pub fn load_documents_schemas() -> Result<Value, Error> {
36
- serde_json::from_str(include_str!("../schema/dpns-contract-documents.json"))
21
+ pub fn load_definitions(platform_version: &PlatformVersion) -> Result<Option<Value>, Error> {
22
+ match platform_version.system_data_contracts.withdrawals {
23
+ 1 => Ok(None),
24
+ version => Err(Error::UnknownVersionMismatch {
25
+ method: "dpns_contract::load_definitions".to_string(),
26
+ known_versions: vec![1],
27
+ received: version,
28
+ }),
29
+ }
30
+ }
31
+ pub fn load_documents_schemas(platform_version: &PlatformVersion) -> Result<Value, Error> {
32
+ match platform_version.system_data_contracts.withdrawals {
33
+ 1 => v1::load_documents_schemas(),
34
+ version => Err(Error::UnknownVersionMismatch {
35
+ method: "dpns_contract::load_documents_schemas".to_string(),
36
+ known_versions: vec![1],
37
+ received: version,
38
+ }),
39
+ }
37
40
  }
package/src/v1/mod.rs ADDED
@@ -0,0 +1,25 @@
1
+ use crate::Error;
2
+ use serde_json::Value;
3
+
4
+ pub mod document_types {
5
+ pub mod domain {
6
+ pub const NAME: &str = "domain";
7
+
8
+ pub mod properties {
9
+ pub const LABEL: &str = "label";
10
+ pub const NORMALIZED_LABEL: &str = "normalizedLabel";
11
+ pub const PARENT_DOMAIN_NAME: &str = "parentDomainName";
12
+ pub const NORMALIZED_PARENT_DOMAIN_NAME: &str = "normalizedParentDomainName";
13
+ pub const PREORDER_SALT: &str = "preorderSalt";
14
+ pub const ALLOW_SUBDOMAINS: &str = "subdomainRules.allowSubdomains";
15
+ pub const RECORDS: &str = "records";
16
+ pub const DASH_UNIQUE_IDENTITY_ID: &str = "dashUniqueIdentityId";
17
+ pub const DASH_ALIAS_IDENTITY_ID: &str = "dashAliasIdentityId";
18
+ }
19
+ }
20
+ }
21
+
22
+ pub fn load_documents_schemas() -> Result<Value, Error> {
23
+ serde_json::from_str(include_str!("../../schema/v1/dpns-contract-documents.json"))
24
+ .map_err(Error::InvalidSchemaJson)
25
+ }
@@ -6,7 +6,7 @@ const {
6
6
  const generateRandomIdentifier = require('@dashevo/wasm-dpp/lib/test/utils/generateRandomIdentifierAsync');
7
7
 
8
8
  const { expect } = require('chai');
9
- const dpnsContractDocumentsSchema = require('../../schema/dpns-contract-documents.json');
9
+ const dpnsContractDocumentsSchema = require('../../schema/v1/dpns-contract-documents.json');
10
10
 
11
11
  const expectJsonSchemaError = (validationResult, errorCount = 1) => {
12
12
  const errors = validationResult.getErrors();