pshenmic-dpp 1.0.4 → 1.0.5
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/.github/workflows/build.yml +8 -0
- package/.github/workflows/publish.yml +8 -0
- package/Cargo.lock +79 -31
- package/Cargo.toml +20 -17
- package/README.md +66 -23
- package/babel.config.json +19 -0
- package/dist/wasm/pshenmic_dpp.js +2487 -355
- package/dist/wasm/pshenmic_dpp_bg.js +1 -1
- package/package.json +13 -6
- package/packages/cbor_conversation/Cargo.toml +1 -1
- package/packages/data_contract/Cargo.toml +2 -2
- package/packages/data_contract/src/lib.rs +195 -23
- package/packages/data_contract_transitions/Cargo.toml +1 -1
- package/packages/data_contract_transitions/src/create/mod.rs +23 -16
- package/packages/data_contract_transitions/src/update/mod.rs +21 -12
- package/packages/document/Cargo.toml +1 -1
- package/packages/document/src/lib.rs +1 -1
- package/packages/document/src/methods/mod.rs +370 -2
- package/packages/{document_batch → documents_batch}/Cargo.toml +6 -4
- package/packages/documents_batch/src/document_base_transition/mod.rs +92 -0
- package/packages/documents_batch/src/document_transition/mod.rs +166 -0
- package/packages/documents_batch/src/generators.rs +122 -0
- package/packages/documents_batch/src/lib.rs +188 -0
- package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
- package/packages/documents_batch/src/transitions/create/mod.rs +123 -0
- package/packages/documents_batch/src/transitions/delete/mod.rs +67 -0
- package/packages/documents_batch/src/transitions/mod.rs +6 -0
- package/packages/documents_batch/src/transitions/purchase/mod.rs +91 -0
- package/packages/documents_batch/src/transitions/replace/mod.rs +93 -0
- package/packages/documents_batch/src/transitions/transfer/mod.rs +86 -0
- package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
- package/packages/enums/Cargo.toml +3 -3
- package/packages/enums/src/batch/batch_enum.rs +75 -10
- package/packages/enums/src/keys/key_type.rs +46 -0
- package/packages/enums/src/keys/purpose.rs +55 -0
- package/packages/enums/src/keys/security_level.rs +46 -0
- package/packages/enums/src/lib.rs +1 -0
- package/packages/enums/src/network/mod.rs +67 -0
- package/packages/enums/src/platform/mod.rs +66 -8
- package/packages/identity/Cargo.toml +3 -4
- package/packages/identity/src/lib.rs +25 -14
- package/packages/{public_key → identity_public_key}/Cargo.toml +1 -1
- package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
- package/packages/identity_transitions/Cargo.toml +2 -2
- package/packages/identity_transitions/src/create_transition/mod.rs +3 -1
- package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +25 -21
- package/packages/mock_bls/Cargo.toml +1 -1
- package/packages/private_key/Cargo.toml +3 -2
- package/packages/private_key/src/lib.rs +44 -6
- package/packages/state_transition/Cargo.toml +5 -4
- package/packages/state_transition/src/lib.rs +101 -36
- package/packages/utils/Cargo.toml +1 -2
- package/packages/utils/src/lib.rs +17 -15
- package/scripts/build-js.sh +6 -5
- package/scripts/build.sh +22 -1
- package/src/lib.rs +7 -1
- package/tests/DataContract.spec.js +175 -0
- package/tests/DataContractCreateStateTransition.spec.js +109 -0
- package/tests/DataContractUpdateStateTransition.spec.js +109 -0
- package/tests/Document.spec.js +232 -0
- package/tests/DocumentBatchTransition.spec.js +109 -0
- package/tests/DocumentTransition.spec.js +97 -0
- package/tests/DocumentsTransitions.spec.js +705 -0
- package/tests/Identity.spec.js +113 -0
- package/tests/IdentityPublicKey.spec.js +132 -0
- package/tests/PrivateKey.spec.js +73 -0
- package/tests/mocks/DataContract/DataContract.json +153 -0
- package/tests/mocks/DataContract/index.js +6 -0
- package/tests/mocks/Document/DataContract.json +23 -0
- package/tests/mocks/Document/document.json +3 -0
- package/tests/mocks/Document/document2.json +3 -0
- package/tests/mocks/Document/index.js +11 -0
- package/tests/mocks/Identity/index.js +7 -0
- package/tests/mocks/PrivateKey/index.js +5 -0
- package/tests/mocks/PublicKey/index.js +14 -0
- package/tests/utils/hex.js +15 -0
- package/tests/utils/wasm.js +14 -0
- package/packages/document/src/methods/js.rs +0 -260
- package/packages/document/src/methods/rust.rs +0 -92
- package/packages/document_batch/src/generators.rs +0 -63
- package/packages/document_batch/src/lib.rs +0 -228
package/package.json
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pshenmic-dpp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"main": "dist/wasm/pshenmic_dpp.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/owl352/pshenmic-dpp"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"tsc": "tsc",
|
|
11
10
|
"build:bin": "./scripts/build.sh",
|
|
12
11
|
"build:js": "./scripts/build-js.sh",
|
|
13
12
|
"build:full": "./scripts/build.sh && ./scripts/build-js.sh",
|
|
14
|
-
"build:raw": "./scripts/build.sh && RAW=true ./scripts/build-js.sh"
|
|
13
|
+
"build:raw": "./scripts/build.sh && RAW=true ./scripts/build-js.sh",
|
|
14
|
+
"babel": "babel dist/wasm --out-dir dist/cjs/wasm",
|
|
15
|
+
"tests": "mocha ./tests/*.spec.js"
|
|
15
16
|
},
|
|
16
17
|
"author": "owl352",
|
|
17
18
|
"license": "ISC",
|
|
18
19
|
"description": "",
|
|
19
20
|
"devDependencies": {
|
|
20
|
-
"babel": "^
|
|
21
|
-
"babel
|
|
22
|
-
"
|
|
21
|
+
"@babel/cli": "^7.27.0",
|
|
22
|
+
"@babel/core": "^7.26.10",
|
|
23
|
+
"@babel/plugin-transform-modules-commonjs": "^7.26.3",
|
|
24
|
+
"@babel/plugin-transform-runtime": "^7.26.10",
|
|
25
|
+
"@babel/preset-env": "^7.26.9",
|
|
26
|
+
"@scure/base": "^1.2.4",
|
|
27
|
+
"core-js": "^3.41.0",
|
|
28
|
+
"mocha": "^11.1.0",
|
|
29
|
+
"standard": "^17.1.2"
|
|
23
30
|
},
|
|
24
31
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
25
32
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pshenmic_dpp_data_contract"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
@@ -12,6 +12,6 @@ pshenmic_dpp_utils = {path = "../utils"}
|
|
|
12
12
|
pshenmic_dpp_enums = {path = "../enums"}
|
|
13
13
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
14
14
|
"data-contract-json-conversion",
|
|
15
|
-
"platform-value"
|
|
16
15
|
]}
|
|
16
|
+
js-sys = "0.3.53"
|
|
17
17
|
serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
use dpp::dashcore::hashes::serde::Serialize;
|
|
2
2
|
use dpp::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters};
|
|
3
|
+
use dpp::data_contract::config::DataContractConfig;
|
|
3
4
|
use dpp::data_contract::conversion::json::DataContractJsonConversionMethodsV0;
|
|
4
5
|
use dpp::data_contract::conversion::value::v0::DataContractValueConversionMethodsV0;
|
|
5
6
|
use dpp::data_contract::document_type::DocumentTypeRef;
|
|
6
7
|
use dpp::data_contract::errors::DataContractError;
|
|
7
8
|
use dpp::data_contract::schema::DataContractSchemaMethodsV0;
|
|
8
9
|
use dpp::data_contract::{DataContract, DataContractV0};
|
|
10
|
+
use dpp::platform_value::string_encoding::Encoding::Base58;
|
|
11
|
+
use dpp::platform_value::{Value, ValueMap};
|
|
9
12
|
use dpp::prelude::IdentityNonce;
|
|
10
13
|
use dpp::serialization::{
|
|
11
14
|
PlatformDeserializableWithPotentialValidationFromVersionedStructure,
|
|
12
15
|
PlatformSerializableWithPlatformVersion,
|
|
13
16
|
};
|
|
17
|
+
use dpp::version::PlatformVersion;
|
|
14
18
|
use pshenmic_dpp_enums::platform::PlatformVersionWASM;
|
|
15
19
|
use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError, identifier_from_js_value};
|
|
20
|
+
use std::collections::BTreeMap;
|
|
16
21
|
use wasm_bindgen::JsValue;
|
|
17
22
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
18
23
|
|
|
@@ -35,11 +40,100 @@ impl From<DataContractWASM> for DataContract {
|
|
|
35
40
|
#[wasm_bindgen]
|
|
36
41
|
impl DataContractWASM {
|
|
37
42
|
#[wasm_bindgen(constructor)]
|
|
38
|
-
pub fn
|
|
43
|
+
pub fn from_js_values(
|
|
44
|
+
js_owner_id: JsValue,
|
|
45
|
+
identity_nonce: IdentityNonce,
|
|
46
|
+
js_schema: JsValue,
|
|
47
|
+
js_definitions: Option<js_sys::Object>,
|
|
48
|
+
full_validation: bool,
|
|
49
|
+
js_platform_version: JsValue,
|
|
50
|
+
) -> Result<DataContractWASM, JsValue> {
|
|
51
|
+
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
52
|
+
|
|
53
|
+
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
54
|
+
|
|
55
|
+
let owner_id_value = Value::from(owner_id.to_string(Base58));
|
|
56
|
+
|
|
57
|
+
let schema: Value = serde_wasm_bindgen::from_value(js_schema)?;
|
|
58
|
+
|
|
59
|
+
let platform_version: PlatformVersion = match js_platform_version.is_undefined() {
|
|
60
|
+
true => PlatformVersionWASM::PLATFORM_V1.into(),
|
|
61
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?.into(),
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
let data_contract_structure_version_value = Value::from(
|
|
65
|
+
platform_version
|
|
66
|
+
.dpp
|
|
67
|
+
.contract_versions
|
|
68
|
+
.contract_structure_version
|
|
69
|
+
.to_string(),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
let definitions = js_definitions
|
|
73
|
+
.map(|definitions| serde_wasm_bindgen::from_value(definitions.into()))
|
|
74
|
+
.transpose()?;
|
|
75
|
+
|
|
76
|
+
let definitions_value = Value::from(definitions);
|
|
77
|
+
|
|
78
|
+
let data_contract_id = DataContract::generate_data_contract_id_v0(owner_id, identity_nonce);
|
|
79
|
+
|
|
80
|
+
let data_contract_id_value = Value::from(data_contract_id.to_string(Base58));
|
|
81
|
+
|
|
82
|
+
let config =
|
|
83
|
+
DataContractConfig::default_for_version(&platform_version.clone()).with_js_error()?;
|
|
84
|
+
|
|
85
|
+
let config_value = config
|
|
86
|
+
.serialize(&serializer)
|
|
87
|
+
.map_err(JsValue::from)?
|
|
88
|
+
.with_serde_to_platform_value_map()?;
|
|
89
|
+
|
|
90
|
+
let mut contract_value = Value::Map(ValueMap::new());
|
|
91
|
+
|
|
92
|
+
contract_value
|
|
93
|
+
.set_value("$format_version", data_contract_structure_version_value)
|
|
94
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
95
|
+
|
|
96
|
+
contract_value
|
|
97
|
+
.set_value("id", data_contract_id_value)
|
|
98
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
99
|
+
|
|
100
|
+
contract_value
|
|
101
|
+
.set_value("config", Value::from(config_value))
|
|
102
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
103
|
+
|
|
104
|
+
contract_value
|
|
105
|
+
.set_value("version", Value::from(1u16))
|
|
106
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
107
|
+
|
|
108
|
+
contract_value
|
|
109
|
+
.set_value("ownerId", owner_id_value)
|
|
110
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
111
|
+
|
|
112
|
+
contract_value
|
|
113
|
+
.set_value("schemaDefs", definitions_value)
|
|
114
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
115
|
+
|
|
116
|
+
contract_value
|
|
117
|
+
.set_value("documentSchemas", schema)
|
|
118
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
119
|
+
|
|
120
|
+
Ok(DataContractWASM(
|
|
121
|
+
DataContract::from_value(contract_value, full_validation, &platform_version)
|
|
122
|
+
.with_js_error()?,
|
|
123
|
+
))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
#[wasm_bindgen(js_name = "fromValue")]
|
|
127
|
+
pub fn from_value(
|
|
39
128
|
js_value: JsValue,
|
|
40
129
|
full_validation: bool,
|
|
41
|
-
|
|
130
|
+
js_platform_version: JsValue,
|
|
42
131
|
) -> Result<DataContractWASM, JsValue> {
|
|
132
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
133
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
134
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
135
|
+
};
|
|
136
|
+
|
|
43
137
|
let value = js_value.with_serde_to_platform_value()?;
|
|
44
138
|
|
|
45
139
|
let v0_contract =
|
|
@@ -53,8 +147,13 @@ impl DataContractWASM {
|
|
|
53
147
|
pub fn from_bytes(
|
|
54
148
|
bytes: Vec<u8>,
|
|
55
149
|
full_validation: bool,
|
|
56
|
-
|
|
150
|
+
js_platform_version: JsValue,
|
|
57
151
|
) -> Result<DataContractWASM, JsValue> {
|
|
152
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
153
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
154
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
155
|
+
};
|
|
156
|
+
|
|
58
157
|
let rs_data_contract = DataContract::versioned_deserialize(
|
|
59
158
|
&bytes.as_slice(),
|
|
60
159
|
full_validation,
|
|
@@ -66,7 +165,12 @@ impl DataContractWASM {
|
|
|
66
165
|
}
|
|
67
166
|
|
|
68
167
|
#[wasm_bindgen(js_name = "toBytes")]
|
|
69
|
-
pub fn to_bytes(&self,
|
|
168
|
+
pub fn to_bytes(&self, js_platform_version: JsValue) -> Result<Vec<u8>, JsValue> {
|
|
169
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
170
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
171
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
172
|
+
};
|
|
173
|
+
|
|
70
174
|
let rs_data_contract: DataContract = self.0.clone();
|
|
71
175
|
|
|
72
176
|
rs_data_contract
|
|
@@ -75,7 +179,12 @@ impl DataContractWASM {
|
|
|
75
179
|
}
|
|
76
180
|
|
|
77
181
|
#[wasm_bindgen(js_name = "toValue")]
|
|
78
|
-
pub fn to_value(&self,
|
|
182
|
+
pub fn to_value(&self, js_platform_version: JsValue) -> Result<JsValue, JsValue> {
|
|
183
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
184
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
185
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
186
|
+
};
|
|
187
|
+
|
|
79
188
|
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
80
189
|
|
|
81
190
|
self.0
|
|
@@ -86,7 +195,7 @@ impl DataContractWASM {
|
|
|
86
195
|
.map_err(JsValue::from)
|
|
87
196
|
}
|
|
88
197
|
|
|
89
|
-
#[wasm_bindgen(js_name = "
|
|
198
|
+
#[wasm_bindgen(js_name = "getSchema")]
|
|
90
199
|
pub fn get_schemas(&self) -> Result<JsValue, JsValue> {
|
|
91
200
|
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
92
201
|
|
|
@@ -96,8 +205,8 @@ impl DataContractWASM {
|
|
|
96
205
|
.map_err(JsValue::from)
|
|
97
206
|
}
|
|
98
207
|
|
|
99
|
-
#[wasm_bindgen(js_name = "
|
|
100
|
-
pub fn
|
|
208
|
+
#[wasm_bindgen(js_name = "getVersion")]
|
|
209
|
+
pub fn get_version(&self) -> u32 {
|
|
101
210
|
self.0.version()
|
|
102
211
|
}
|
|
103
212
|
|
|
@@ -119,8 +228,85 @@ impl DataContractWASM {
|
|
|
119
228
|
.map_err(JsValue::from)
|
|
120
229
|
}
|
|
121
230
|
|
|
231
|
+
#[wasm_bindgen(js_name = "setId")]
|
|
232
|
+
pub fn set_id(&mut self, js_data_contract_id: JsValue) -> Result<(), JsValue> {
|
|
233
|
+
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
234
|
+
|
|
235
|
+
Ok(self.0.set_id(data_contract_id))
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
#[wasm_bindgen(js_name = "setOwnerId")]
|
|
239
|
+
pub fn set_owner_id(&mut self, js_owner_id: JsValue) -> Result<(), JsValue> {
|
|
240
|
+
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
241
|
+
|
|
242
|
+
Ok(self.0.set_owner_id(owner_id))
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
#[wasm_bindgen(js_name = "setVersion")]
|
|
246
|
+
pub fn set_version(&mut self, version: u32) {
|
|
247
|
+
self.0.set_version(version)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
#[wasm_bindgen(js_name = "setConfig")]
|
|
251
|
+
pub fn set_config(
|
|
252
|
+
&mut self,
|
|
253
|
+
js_config: JsValue,
|
|
254
|
+
js_platform_version: JsValue,
|
|
255
|
+
) -> Result<(), JsValue> {
|
|
256
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
257
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
258
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
let config_value: Value = serde_wasm_bindgen::from_value(js_config)?;
|
|
262
|
+
|
|
263
|
+
let config = DataContractConfig::from_value(config_value, &platform_version.into())
|
|
264
|
+
.with_js_error()?;
|
|
265
|
+
|
|
266
|
+
self.0.set_config(config);
|
|
267
|
+
|
|
268
|
+
Ok(())
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
#[wasm_bindgen(js_name = "setSchema")]
|
|
272
|
+
pub fn set_schemas(
|
|
273
|
+
&mut self,
|
|
274
|
+
js_schema: JsValue,
|
|
275
|
+
js_definitions: Option<js_sys::Object>,
|
|
276
|
+
full_validation: bool,
|
|
277
|
+
js_platform_version: JsValue,
|
|
278
|
+
) -> Result<(), JsValue> {
|
|
279
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
280
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
281
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
let schema = js_schema.with_serde_to_platform_value_map()?;
|
|
285
|
+
|
|
286
|
+
let definitions: Option<BTreeMap<String, Value>> = js_definitions
|
|
287
|
+
.map(|definitions| serde_wasm_bindgen::from_value(definitions.into()))
|
|
288
|
+
.transpose()?;
|
|
289
|
+
|
|
290
|
+
self.0
|
|
291
|
+
.set_document_schemas(
|
|
292
|
+
schema,
|
|
293
|
+
definitions,
|
|
294
|
+
full_validation,
|
|
295
|
+
&mut Vec::new(),
|
|
296
|
+
&platform_version.into(),
|
|
297
|
+
)
|
|
298
|
+
.with_js_error()?;
|
|
299
|
+
|
|
300
|
+
Ok(())
|
|
301
|
+
}
|
|
302
|
+
|
|
122
303
|
#[wasm_bindgen(js_name = "toJson")]
|
|
123
|
-
pub fn to_json(&self,
|
|
304
|
+
pub fn to_json(&self, js_platform_version: JsValue) -> Result<JsValue, JsValue> {
|
|
305
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
306
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
307
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
308
|
+
};
|
|
309
|
+
|
|
124
310
|
let json = self.0.to_json(&platform_version.into()).with_js_error()?;
|
|
125
311
|
|
|
126
312
|
json.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
|
|
@@ -136,20 +322,6 @@ impl DataContractWASM {
|
|
|
136
322
|
|
|
137
323
|
Ok(DataContract::generate_data_contract_id_v0(owner_id, identity_nonce).to_vec())
|
|
138
324
|
}
|
|
139
|
-
|
|
140
|
-
#[wasm_bindgen(js_name = "setId")]
|
|
141
|
-
pub fn set_id(&mut self, js_data_contract_id: JsValue) -> Result<(), JsValue> {
|
|
142
|
-
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
143
|
-
|
|
144
|
-
Ok(self.0.set_id(data_contract_id))
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
#[wasm_bindgen(js_name = "setOwnerId")]
|
|
148
|
-
pub fn set_owner_id(&mut self, js_owner_id: JsValue) -> Result<(), JsValue> {
|
|
149
|
-
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
150
|
-
|
|
151
|
-
Ok(self.0.set_owner_id(owner_id))
|
|
152
|
-
}
|
|
153
325
|
}
|
|
154
326
|
|
|
155
327
|
impl DataContractWASM {
|
|
@@ -27,18 +27,19 @@ impl DataContractCreateTransitionWASM {
|
|
|
27
27
|
pub fn new(
|
|
28
28
|
data_contract: &DataContractWASM,
|
|
29
29
|
identity_nonce: IdentityNonce,
|
|
30
|
-
|
|
30
|
+
js_platform_version: JsValue,
|
|
31
31
|
) -> Result<DataContractCreateTransitionWASM, JsValue> {
|
|
32
32
|
let rs_data_contract: DataContract = data_contract.clone().into();
|
|
33
33
|
|
|
34
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
35
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
36
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
37
|
+
};
|
|
38
|
+
|
|
34
39
|
let rs_data_contract_in_serialized: Result<
|
|
35
40
|
DataContractInSerializationFormat,
|
|
36
41
|
ProtocolError,
|
|
37
|
-
> = rs_data_contract.try_into_platform_versioned(
|
|
38
|
-
&platform_version
|
|
39
|
-
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
40
|
-
.into(),
|
|
41
|
-
);
|
|
42
|
+
> = rs_data_contract.try_into_platform_versioned(&platform_version.into());
|
|
42
43
|
|
|
43
44
|
let rs_data_contract_create_transition_v0: DataContractCreateTransitionV0 =
|
|
44
45
|
DataContractCreateTransitionV0 {
|
|
@@ -91,15 +92,18 @@ impl DataContractCreateTransitionWASM {
|
|
|
91
92
|
#[wasm_bindgen(js_name = "setDataContract")]
|
|
92
93
|
pub fn set_data_contract(
|
|
93
94
|
&mut self,
|
|
94
|
-
data_contract: DataContractWASM,
|
|
95
|
-
|
|
95
|
+
data_contract: &DataContractWASM,
|
|
96
|
+
js_platform_version: JsValue,
|
|
96
97
|
) -> Result<(), JsValue> {
|
|
98
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
99
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
100
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
101
|
+
};
|
|
102
|
+
|
|
97
103
|
let data_contract_serialization_format =
|
|
98
104
|
DataContractInSerializationFormat::try_from_platform_versioned(
|
|
99
|
-
DataContract::from(data_contract),
|
|
100
|
-
&
|
|
101
|
-
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
102
|
-
.into(),
|
|
105
|
+
DataContract::from(data_contract.clone()),
|
|
106
|
+
&platform_version.into(),
|
|
103
107
|
)
|
|
104
108
|
.with_js_error()?;
|
|
105
109
|
|
|
@@ -111,9 +115,14 @@ impl DataContractCreateTransitionWASM {
|
|
|
111
115
|
#[wasm_bindgen(js_name = "getDataContract")]
|
|
112
116
|
pub fn get_data_contract(
|
|
113
117
|
&self,
|
|
114
|
-
|
|
118
|
+
js_platform_version: JsValue,
|
|
115
119
|
full_validation: Option<bool>,
|
|
116
120
|
) -> Result<DataContractWASM, JsValue> {
|
|
121
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
122
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
123
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
124
|
+
};
|
|
125
|
+
|
|
117
126
|
let rs_data_contract_serialization_format = self.0.data_contract();
|
|
118
127
|
|
|
119
128
|
let mut validation_operations: Vec<ProtocolValidationOperation> = Vec::new();
|
|
@@ -122,9 +131,7 @@ impl DataContractCreateTransitionWASM {
|
|
|
122
131
|
rs_data_contract_serialization_format.clone(),
|
|
123
132
|
full_validation.unwrap_or(false),
|
|
124
133
|
&mut validation_operations,
|
|
125
|
-
&
|
|
126
|
-
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
127
|
-
.into(),
|
|
134
|
+
&platform_version.into(),
|
|
128
135
|
)
|
|
129
136
|
.with_js_error()?;
|
|
130
137
|
|
|
@@ -22,14 +22,17 @@ impl DataContractUpdateTransitionWASM {
|
|
|
22
22
|
pub fn new(
|
|
23
23
|
data_contract: &DataContractWASM,
|
|
24
24
|
identity_nonce: IdentityNonce,
|
|
25
|
-
|
|
25
|
+
js_platform_version: JsValue,
|
|
26
26
|
) -> Result<DataContractUpdateTransitionWASM, JsValue> {
|
|
27
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
28
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
29
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
30
|
+
};
|
|
31
|
+
|
|
27
32
|
let rs_data_contract_update_transition =
|
|
28
33
|
DataContractUpdateTransition::try_from_platform_versioned(
|
|
29
34
|
(DataContract::from(data_contract.clone()), identity_nonce),
|
|
30
|
-
&platform_version
|
|
31
|
-
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
32
|
-
.into(),
|
|
35
|
+
&platform_version.into(),
|
|
33
36
|
)
|
|
34
37
|
.with_js_error()?;
|
|
35
38
|
|
|
@@ -73,14 +76,17 @@ impl DataContractUpdateTransitionWASM {
|
|
|
73
76
|
pub fn set_data_contract(
|
|
74
77
|
&mut self,
|
|
75
78
|
data_contract: &DataContractWASM,
|
|
76
|
-
|
|
79
|
+
js_platform_version: JsValue,
|
|
77
80
|
) -> Result<(), JsValue> {
|
|
81
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
82
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
83
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
84
|
+
};
|
|
85
|
+
|
|
78
86
|
let data_contract_serialization_format =
|
|
79
87
|
DataContractInSerializationFormat::try_from_platform_versioned(
|
|
80
88
|
DataContract::from(data_contract.clone()),
|
|
81
|
-
&
|
|
82
|
-
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
83
|
-
.into(),
|
|
89
|
+
&platform_version.into(),
|
|
84
90
|
)
|
|
85
91
|
.with_js_error()?;
|
|
86
92
|
|
|
@@ -93,8 +99,13 @@ impl DataContractUpdateTransitionWASM {
|
|
|
93
99
|
pub fn get_data_contract(
|
|
94
100
|
&self,
|
|
95
101
|
full_validation: Option<bool>,
|
|
96
|
-
|
|
102
|
+
js_platform_version: JsValue,
|
|
97
103
|
) -> Result<DataContractWASM, JsValue> {
|
|
104
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
105
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
106
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
107
|
+
};
|
|
108
|
+
|
|
98
109
|
let data_contract_serialization_format = self.0.data_contract();
|
|
99
110
|
|
|
100
111
|
let mut validation_operations: Vec<ProtocolValidationOperation> = Vec::new();
|
|
@@ -103,9 +114,7 @@ impl DataContractUpdateTransitionWASM {
|
|
|
103
114
|
data_contract_serialization_format.clone(),
|
|
104
115
|
full_validation.unwrap_or(false),
|
|
105
116
|
&mut validation_operations,
|
|
106
|
-
&
|
|
107
|
-
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
108
|
-
.into(),
|
|
117
|
+
&platform_version.into(),
|
|
109
118
|
)
|
|
110
119
|
.with_js_error()?;
|
|
111
120
|
|