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
|
@@ -1,2 +1,370 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
use crate::DocumentWASM;
|
|
2
|
+
use dpp::ProtocolError;
|
|
3
|
+
use dpp::dashcore::hashes::serde::Serialize;
|
|
4
|
+
use dpp::data_contract::JsonValue;
|
|
5
|
+
use dpp::document::Document;
|
|
6
|
+
use dpp::document::serialization_traits::DocumentPlatformConversionMethodsV0;
|
|
7
|
+
use dpp::identifier::Identifier;
|
|
8
|
+
use dpp::platform_value::Value;
|
|
9
|
+
use dpp::platform_value::converter::serde_json::BTreeValueJsonConverter;
|
|
10
|
+
use dpp::prelude::Revision;
|
|
11
|
+
use dpp::util::entropy_generator;
|
|
12
|
+
use dpp::util::entropy_generator::EntropyGenerator;
|
|
13
|
+
use pshenmic_dpp_data_contract::DataContractWASM;
|
|
14
|
+
use pshenmic_dpp_enums::platform::PlatformVersionWASM;
|
|
15
|
+
use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError, identifier_from_js_value};
|
|
16
|
+
use std::collections::BTreeMap;
|
|
17
|
+
use wasm_bindgen::JsValue;
|
|
18
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
19
|
+
|
|
20
|
+
#[wasm_bindgen]
|
|
21
|
+
impl DocumentWASM {
|
|
22
|
+
#[wasm_bindgen(constructor)]
|
|
23
|
+
pub fn new(
|
|
24
|
+
js_raw_document: JsValue,
|
|
25
|
+
js_document_type_name: &str,
|
|
26
|
+
js_revision: u64,
|
|
27
|
+
js_data_contract_id: JsValue,
|
|
28
|
+
js_owner_id: JsValue,
|
|
29
|
+
js_document_id: JsValue,
|
|
30
|
+
) -> Result<DocumentWASM, JsValue> {
|
|
31
|
+
let revision = Revision::from(js_revision);
|
|
32
|
+
|
|
33
|
+
let document = js_raw_document
|
|
34
|
+
.with_serde_to_platform_value_map()
|
|
35
|
+
.expect("cannot convert document to platform value map");
|
|
36
|
+
|
|
37
|
+
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
38
|
+
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
39
|
+
let revision = Revision::from(revision);
|
|
40
|
+
|
|
41
|
+
let entropy = entropy_generator::DefaultEntropyGenerator
|
|
42
|
+
.generate()
|
|
43
|
+
.unwrap();
|
|
44
|
+
|
|
45
|
+
let document_id: Identifier = {
|
|
46
|
+
if JsValue::UNDEFINED == js_document_id {
|
|
47
|
+
pshenmic_dpp_utils::generate_document_id_v0(
|
|
48
|
+
&data_contract_id,
|
|
49
|
+
&owner_id,
|
|
50
|
+
js_document_type_name,
|
|
51
|
+
&entropy,
|
|
52
|
+
)
|
|
53
|
+
} else {
|
|
54
|
+
identifier_from_js_value(&js_document_id)
|
|
55
|
+
}
|
|
56
|
+
}?;
|
|
57
|
+
|
|
58
|
+
Ok(DocumentWASM {
|
|
59
|
+
owner_id,
|
|
60
|
+
entropy: Some(entropy),
|
|
61
|
+
id: document_id,
|
|
62
|
+
document_type_name: js_document_type_name.to_string(),
|
|
63
|
+
data_contract_id,
|
|
64
|
+
properties: document,
|
|
65
|
+
revision: Some(revision),
|
|
66
|
+
created_at: None,
|
|
67
|
+
updated_at: None,
|
|
68
|
+
transferred_at: None,
|
|
69
|
+
created_at_block_height: None,
|
|
70
|
+
updated_at_block_height: None,
|
|
71
|
+
transferred_at_block_height: None,
|
|
72
|
+
created_at_core_block_height: None,
|
|
73
|
+
updated_at_core_block_height: None,
|
|
74
|
+
transferred_at_core_block_height: None,
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#[wasm_bindgen(js_name=getId)]
|
|
79
|
+
pub fn get_id(&self) -> Vec<u8> {
|
|
80
|
+
self.id.to_vec()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#[wasm_bindgen(js_name=getEntropy)]
|
|
84
|
+
pub fn get_entropy(&self) -> Option<Vec<u8>> {
|
|
85
|
+
match self.entropy {
|
|
86
|
+
Some(entropy) => Some(entropy.to_vec()),
|
|
87
|
+
None => None,
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
#[wasm_bindgen(js_name=getDataContractId)]
|
|
92
|
+
pub fn get_data_contract_id(&self) -> Vec<u8> {
|
|
93
|
+
self.data_contract_id.to_vec()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#[wasm_bindgen(js_name=getOwnerId)]
|
|
97
|
+
pub fn get_owner_id(&self) -> Vec<u8> {
|
|
98
|
+
self.owner_id.to_vec()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#[wasm_bindgen(js_name=getProperties)]
|
|
102
|
+
pub fn get_properties(&self) -> Result<JsValue, JsValue> {
|
|
103
|
+
let json_value: JsonValue = self
|
|
104
|
+
.properties
|
|
105
|
+
.clone()
|
|
106
|
+
.to_json_value()
|
|
107
|
+
.map_err(ProtocolError::ValueError)
|
|
108
|
+
.with_js_error()?;
|
|
109
|
+
|
|
110
|
+
let js_value = json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?;
|
|
111
|
+
Ok(js_value)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#[wasm_bindgen(js_name=getRevision)]
|
|
115
|
+
pub fn get_revision(&self) -> Option<u64> {
|
|
116
|
+
self.revision
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#[wasm_bindgen(js_name=getCreatedAt)]
|
|
120
|
+
pub fn get_created_at(&self) -> Option<u64> {
|
|
121
|
+
self.created_at
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#[wasm_bindgen(js_name=getUpdatedAt)]
|
|
125
|
+
pub fn get_updated_at(&self) -> Option<u64> {
|
|
126
|
+
self.updated_at
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#[wasm_bindgen(js_name=getTransferredAt)]
|
|
130
|
+
pub fn get_transferred_at(&self) -> Option<u64> {
|
|
131
|
+
self.transferred_at
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#[wasm_bindgen(js_name=getCreatedAtBlockHeight)]
|
|
135
|
+
pub fn get_created_at_block_height(&self) -> Option<u64> {
|
|
136
|
+
self.created_at_block_height
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#[wasm_bindgen(js_name=getUpdatedAtBlockHeight)]
|
|
140
|
+
pub fn get_updated_at_block_height(&self) -> Option<u64> {
|
|
141
|
+
self.updated_at_block_height
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
#[wasm_bindgen(js_name=getTransferredAtBlockHeight)]
|
|
145
|
+
pub fn get_transferred_at_block_height(&self) -> Option<u64> {
|
|
146
|
+
self.transferred_at_block_height
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
#[wasm_bindgen(js_name=getCreatedAtCoreBlockHeight)]
|
|
150
|
+
pub fn get_created_at_core_block_height(&self) -> Option<u32> {
|
|
151
|
+
self.created_at_core_block_height
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
#[wasm_bindgen(js_name=getUpdatedAtCoreBlockHeight)]
|
|
155
|
+
pub fn get_updated_at_core_block_height(&self) -> Option<u32> {
|
|
156
|
+
self.updated_at_core_block_height
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#[wasm_bindgen(js_name=getTransferredAtCoreBlockHeight)]
|
|
160
|
+
pub fn get_transferred_at_core_block_height(&self) -> Option<u32> {
|
|
161
|
+
self.transferred_at_core_block_height
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
#[wasm_bindgen(js_name=getDocumentTypeName)]
|
|
165
|
+
pub fn get_document_type_name(&self) -> String {
|
|
166
|
+
self.document_type_name.clone()
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
#[wasm_bindgen(js_name=setId)]
|
|
170
|
+
pub fn set_id(&mut self, id: JsValue) {
|
|
171
|
+
self.id = identifier_from_js_value(&id).unwrap()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
#[wasm_bindgen(js_name=setEntropy)]
|
|
175
|
+
pub fn set_entropy(&mut self, entropy: JsValue) {
|
|
176
|
+
match entropy.is_undefined() {
|
|
177
|
+
false => {
|
|
178
|
+
let value = entropy.with_serde_to_platform_value().unwrap();
|
|
179
|
+
|
|
180
|
+
let mut entropy = [0u8; 32];
|
|
181
|
+
let bytes = value.as_bytes().unwrap();
|
|
182
|
+
let len = bytes.len().min(32);
|
|
183
|
+
entropy[..len].copy_from_slice(&bytes[..len]);
|
|
184
|
+
self.entropy = Some(entropy);
|
|
185
|
+
}
|
|
186
|
+
true => self.entropy = None,
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
#[wasm_bindgen(js_name=setOwnerId)]
|
|
191
|
+
pub fn set_owner_id(&mut self, id: JsValue) {
|
|
192
|
+
self.owner_id = identifier_from_js_value(&id).unwrap()
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
#[wasm_bindgen(js_name=setProperties)]
|
|
196
|
+
pub fn set_properties(&mut self, properties: JsValue) {
|
|
197
|
+
self.properties = properties.with_serde_to_platform_value_map().unwrap()
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
#[wasm_bindgen(js_name=setRevision)]
|
|
201
|
+
pub fn set_revision(&mut self, revision: Option<u64>) {
|
|
202
|
+
self.revision = revision
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
#[wasm_bindgen(js_name=setCreatedAt)]
|
|
206
|
+
pub fn set_created_at(&mut self, created_at: Option<u64>) {
|
|
207
|
+
self.created_at = created_at
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
#[wasm_bindgen(js_name=setUpdatedAt)]
|
|
211
|
+
pub fn set_get_updated_at(&mut self, updated_at: Option<u64>) {
|
|
212
|
+
self.updated_at = updated_at
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#[wasm_bindgen(js_name=setTransferredAt)]
|
|
216
|
+
pub fn set_transferred_at(&mut self, transferred_at: Option<u64>) {
|
|
217
|
+
self.transferred_at = transferred_at
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
#[wasm_bindgen(js_name=setCreatedAtBlockHeight)]
|
|
221
|
+
pub fn set_created_at_block_height(&mut self, created_at_block_height: Option<u64>) {
|
|
222
|
+
self.created_at_block_height = created_at_block_height
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
#[wasm_bindgen(js_name=setUpdatedAtBlockHeight)]
|
|
226
|
+
pub fn set_updated_at_block_height(&mut self, updated_at_block_height: Option<u64>) {
|
|
227
|
+
self.updated_at_block_height = updated_at_block_height
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
#[wasm_bindgen(js_name=setTransferredAtBlockHeight)]
|
|
231
|
+
pub fn set_transferred_at_block_height(&mut self, transferred_at_block_height: Option<u64>) {
|
|
232
|
+
self.transferred_at_block_height = transferred_at_block_height
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
#[wasm_bindgen(js_name=setCreatedAtCoreBlockHeight)]
|
|
236
|
+
pub fn set_created_at_core_block_height(&mut self, created_at_core_block_height: Option<u32>) {
|
|
237
|
+
self.created_at_core_block_height = created_at_core_block_height
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
#[wasm_bindgen(js_name=setUpdatedAtCoreBlockHeight)]
|
|
241
|
+
pub fn set_updated_at_core_block_height(&mut self, updated_at_core_block_height: Option<u32>) {
|
|
242
|
+
self.updated_at_core_block_height = updated_at_core_block_height
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
#[wasm_bindgen(js_name=setTransferredAtCoreBlockHeight)]
|
|
246
|
+
pub fn set_transferred_at_core_block_height(
|
|
247
|
+
&mut self,
|
|
248
|
+
transferred_at_core_block_height: Option<u32>,
|
|
249
|
+
) {
|
|
250
|
+
self.transferred_at_core_block_height = transferred_at_core_block_height
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
#[wasm_bindgen(js_name=setDocumentTypeName)]
|
|
254
|
+
pub fn set_document_type_name(&mut self, document_type_name: &str) {
|
|
255
|
+
self.document_type_name = document_type_name.to_string();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
#[wasm_bindgen(js_name=toBytes)]
|
|
259
|
+
pub fn to_bytes(
|
|
260
|
+
&self,
|
|
261
|
+
data_contract: &DataContractWASM,
|
|
262
|
+
type_name: String,
|
|
263
|
+
js_platform_version: JsValue,
|
|
264
|
+
) -> Result<Vec<u8>, JsValue> {
|
|
265
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
266
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
267
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
let rs_document: Document = Document::from(self.clone());
|
|
271
|
+
|
|
272
|
+
let document_type_ref = data_contract
|
|
273
|
+
.get_document_type_ref_by_name(type_name)
|
|
274
|
+
.map_err(|err| JsValue::from_str(err.to_string().as_str()))?;
|
|
275
|
+
|
|
276
|
+
DocumentPlatformConversionMethodsV0::serialize(
|
|
277
|
+
&rs_document,
|
|
278
|
+
document_type_ref,
|
|
279
|
+
&platform_version.into(),
|
|
280
|
+
)
|
|
281
|
+
.with_js_error()
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
#[wasm_bindgen(js_name=fromBytes)]
|
|
285
|
+
pub fn from_bytes(
|
|
286
|
+
bytes: Vec<u8>,
|
|
287
|
+
data_contract: &DataContractWASM,
|
|
288
|
+
type_name: String,
|
|
289
|
+
js_platform_version: JsValue,
|
|
290
|
+
) -> Result<DocumentWASM, JsValue> {
|
|
291
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
292
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
293
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
let document_type_ref = match data_contract.get_document_type_ref_by_name(type_name) {
|
|
297
|
+
Ok(type_ref) => Ok(type_ref),
|
|
298
|
+
Err(err) => Err(JsValue::from_str(err.to_string().as_str())),
|
|
299
|
+
}?;
|
|
300
|
+
|
|
301
|
+
let rs_document = Document::from_bytes(
|
|
302
|
+
bytes.as_slice(),
|
|
303
|
+
document_type_ref,
|
|
304
|
+
&platform_version.into(),
|
|
305
|
+
)
|
|
306
|
+
.with_js_error();
|
|
307
|
+
|
|
308
|
+
match rs_document {
|
|
309
|
+
Ok(doc) => Ok(DocumentWASM::from(doc)),
|
|
310
|
+
Err(err) => Err(err),
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
#[wasm_bindgen(js_name=generateId)]
|
|
315
|
+
pub fn generate_id(
|
|
316
|
+
js_document_type_name: &str,
|
|
317
|
+
js_owner_id: JsValue,
|
|
318
|
+
js_data_contract_id: JsValue,
|
|
319
|
+
opt_entropy: Option<Vec<u8>>,
|
|
320
|
+
) -> Result<Vec<u8>, JsValue> {
|
|
321
|
+
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
322
|
+
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
323
|
+
let entropy: [u8; 32] = match opt_entropy {
|
|
324
|
+
Some(entropy_vec) => {
|
|
325
|
+
let mut entropy = [0u8; 32];
|
|
326
|
+
let bytes = entropy_vec.as_slice();
|
|
327
|
+
let len = bytes.len().min(32);
|
|
328
|
+
entropy[..len].copy_from_slice(&bytes[..len]);
|
|
329
|
+
entropy
|
|
330
|
+
}
|
|
331
|
+
None => entropy_generator::DefaultEntropyGenerator
|
|
332
|
+
.generate()
|
|
333
|
+
.with_js_error()?,
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
let identifier = pshenmic_dpp_utils::generate_document_id_v0(
|
|
337
|
+
&data_contract_id,
|
|
338
|
+
&owner_id,
|
|
339
|
+
js_document_type_name,
|
|
340
|
+
&entropy,
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
match identifier {
|
|
344
|
+
Ok(identifier) => Ok(identifier.to_vec()),
|
|
345
|
+
Err(err) => Err(err),
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
impl DocumentWASM {
|
|
351
|
+
pub fn rs_get_owner_id(&self) -> Identifier {
|
|
352
|
+
self.owner_id
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
pub fn rs_get_id(&self) -> Identifier {
|
|
356
|
+
self.id
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
pub fn rs_get_data_contract_id(&self) -> Identifier {
|
|
360
|
+
self.data_contract_id
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
pub fn rs_get_entropy(&self) -> Option<[u8; 32]> {
|
|
364
|
+
self.entropy
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
pub fn rs_get_properties(&self) -> BTreeMap<String, Value> {
|
|
368
|
+
self.clone().properties
|
|
369
|
+
}
|
|
370
|
+
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
name = "
|
|
3
|
-
version =
|
|
2
|
+
name = "pshenmic_dpp_documents_batch"
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
7
7
|
crate-type = ["cdylib", "lib"]
|
|
8
8
|
|
|
9
9
|
[dependencies]
|
|
10
|
-
wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
|
|
10
|
+
wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
|
|
11
11
|
pshenmic_dpp_document = {path = "../document"}
|
|
12
12
|
pshenmic_dpp_enums = {path = "../enums"}
|
|
13
13
|
pshenmic_dpp_utils = {path = "../utils"}
|
|
14
14
|
pshenmic_dpp_state_transition = {path = "../state_transition"}
|
|
15
15
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
16
16
|
"document-json-conversion",
|
|
17
|
-
]}
|
|
17
|
+
]}
|
|
18
|
+
js-sys = "0.3.77"
|
|
19
|
+
serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
use dpp::prelude::IdentityNonce;
|
|
2
|
+
use dpp::state_transition::documents_batch_transition::document_base_transition::DocumentBaseTransition;
|
|
3
|
+
use dpp::state_transition::documents_batch_transition::document_base_transition::v0::DocumentBaseTransitionV0;
|
|
4
|
+
use dpp::state_transition::documents_batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods;
|
|
5
|
+
use pshenmic_dpp_utils::identifier_from_js_value;
|
|
6
|
+
use wasm_bindgen::JsValue;
|
|
7
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
8
|
+
|
|
9
|
+
#[derive(Clone)]
|
|
10
|
+
#[wasm_bindgen(js_name = "DocumentBaseTransitionWASM")]
|
|
11
|
+
pub struct DocumentBaseTransitionWASM(DocumentBaseTransition);
|
|
12
|
+
|
|
13
|
+
impl From<DocumentBaseTransition> for DocumentBaseTransitionWASM {
|
|
14
|
+
fn from(v: DocumentBaseTransition) -> Self {
|
|
15
|
+
DocumentBaseTransitionWASM(v)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
impl From<DocumentBaseTransitionWASM> for DocumentBaseTransition {
|
|
20
|
+
fn from(v: DocumentBaseTransitionWASM) -> Self {
|
|
21
|
+
v.0
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#[wasm_bindgen]
|
|
26
|
+
impl DocumentBaseTransitionWASM {
|
|
27
|
+
#[wasm_bindgen(constructor)]
|
|
28
|
+
pub fn new(
|
|
29
|
+
js_document_id: JsValue,
|
|
30
|
+
identity_contract_nonce: IdentityNonce,
|
|
31
|
+
document_type_name: String,
|
|
32
|
+
js_data_contract_id: JsValue,
|
|
33
|
+
) -> Result<DocumentBaseTransitionWASM, JsValue> {
|
|
34
|
+
let document_id = identifier_from_js_value(&js_document_id)?;
|
|
35
|
+
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
36
|
+
|
|
37
|
+
let rs_base_v0 = DocumentBaseTransitionV0 {
|
|
38
|
+
id: document_id,
|
|
39
|
+
identity_contract_nonce,
|
|
40
|
+
document_type_name,
|
|
41
|
+
data_contract_id,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
Ok(DocumentBaseTransitionWASM(DocumentBaseTransition::from(
|
|
45
|
+
rs_base_v0,
|
|
46
|
+
)))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#[wasm_bindgen(getter = "id")]
|
|
50
|
+
pub fn get_id(&self) -> Vec<u8> {
|
|
51
|
+
self.0.id().to_vec()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
#[wasm_bindgen(getter = "identityContractNonce")]
|
|
55
|
+
pub fn get_identity_contract_nonce(&self) -> IdentityNonce {
|
|
56
|
+
self.0.identity_contract_nonce()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#[wasm_bindgen(getter = "dataContractId")]
|
|
60
|
+
pub fn get_data_contract_id(&self) -> Vec<u8> {
|
|
61
|
+
self.0.data_contract_id().to_vec()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#[wasm_bindgen(getter = "documentTypeName")]
|
|
65
|
+
pub fn get_document_type_name(&self) -> String {
|
|
66
|
+
self.0.document_type_name().to_string()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
#[wasm_bindgen(setter = "id")]
|
|
70
|
+
pub fn set_id(&mut self, js_id: JsValue) -> Result<(), JsValue> {
|
|
71
|
+
let id = identifier_from_js_value(&js_id)?;
|
|
72
|
+
|
|
73
|
+
Ok(self.0.set_id(id))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#[wasm_bindgen(setter = "identityContractNonce")]
|
|
77
|
+
pub fn set_identity_contract_nonce(&mut self, nonce: IdentityNonce) {
|
|
78
|
+
self.0.set_identity_contract_nonce(nonce)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#[wasm_bindgen(setter = "dataContractId")]
|
|
82
|
+
pub fn set_data_contract_id(&mut self, js_data_contract_id: JsValue) -> Result<(), JsValue> {
|
|
83
|
+
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
84
|
+
|
|
85
|
+
Ok(self.0.set_data_contract_id(data_contract_id))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#[wasm_bindgen(setter = "documentTypeName")]
|
|
89
|
+
pub fn set_document_type_name(&mut self, document_type_name: String) {
|
|
90
|
+
self.0.set_document_type_name(document_type_name)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
use crate::transitions::create::DocumentCreateTransitionWASM;
|
|
2
|
+
use crate::transitions::delete::DocumentDeleteTransitionWASM;
|
|
3
|
+
use crate::transitions::purchase::DocumentPurchaseTransitionWASM;
|
|
4
|
+
use crate::transitions::replace::DocumentReplaceTransitionWASM;
|
|
5
|
+
use crate::transitions::transfer::DocumentTransferTransitionWASM;
|
|
6
|
+
use crate::transitions::update_price::DocumentUpdatePriceTransitionWASM;
|
|
7
|
+
use dpp::prelude::{Identifier, IdentityNonce, Revision};
|
|
8
|
+
use dpp::state_transition::documents_batch_transition::document_transition::action_type::TransitionActionTypeGetter;
|
|
9
|
+
use dpp::state_transition::documents_batch_transition::document_transition::{
|
|
10
|
+
DocumentTransition, DocumentTransitionV0Methods,
|
|
11
|
+
};
|
|
12
|
+
use pshenmic_dpp_enums::batch::batch_enum::BatchTypeWASM;
|
|
13
|
+
use pshenmic_dpp_utils::identifier_from_js_value;
|
|
14
|
+
use wasm_bindgen::JsValue;
|
|
15
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
16
|
+
|
|
17
|
+
#[derive(Clone)]
|
|
18
|
+
#[wasm_bindgen(js_name = "DocumentTransitionWASM")]
|
|
19
|
+
pub struct DocumentTransitionWASM(DocumentTransition);
|
|
20
|
+
|
|
21
|
+
impl From<DocumentTransition> for DocumentTransitionWASM {
|
|
22
|
+
fn from(transition: DocumentTransition) -> Self {
|
|
23
|
+
DocumentTransitionWASM(transition)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
impl From<DocumentTransitionWASM> for DocumentTransition {
|
|
28
|
+
fn from(transition: DocumentTransitionWASM) -> Self {
|
|
29
|
+
transition.0
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#[wasm_bindgen]
|
|
34
|
+
impl DocumentTransitionWASM {
|
|
35
|
+
#[wasm_bindgen(getter = "actionType")]
|
|
36
|
+
pub fn get_action_type(&self) -> String {
|
|
37
|
+
BatchTypeWASM::from(self.0.action_type()).into()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#[wasm_bindgen(getter = "dataContractId")]
|
|
41
|
+
pub fn get_data_contract_id(&self) -> Vec<u8> {
|
|
42
|
+
self.0.data_contract_id().to_vec()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#[wasm_bindgen(getter = "id")]
|
|
46
|
+
pub fn get_id(&self) -> Vec<u8> {
|
|
47
|
+
self.0.get_id().to_vec()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#[wasm_bindgen(getter = "documentTypeName")]
|
|
51
|
+
pub fn get_document_type_name(&self) -> String {
|
|
52
|
+
self.0.document_type_name().clone()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#[wasm_bindgen(getter = "identityContractNonce")]
|
|
56
|
+
pub fn get_identity_contract_nonce(&self) -> IdentityNonce {
|
|
57
|
+
self.0.identity_contract_nonce()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#[wasm_bindgen(getter = "revision")]
|
|
61
|
+
pub fn get_revision(&self) -> Option<Revision> {
|
|
62
|
+
self.0.revision()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#[wasm_bindgen(getter = "entropy")]
|
|
66
|
+
pub fn get_entropy(&self) -> Option<Vec<u8>> {
|
|
67
|
+
self.0.entropy()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#[wasm_bindgen(getter = "createTransition")]
|
|
71
|
+
pub fn get_create_transition(&self) -> Result<DocumentCreateTransitionWASM, JsValue> {
|
|
72
|
+
match self.0.clone() {
|
|
73
|
+
DocumentTransition::Create(create) => Ok(DocumentCreateTransitionWASM::from(create)),
|
|
74
|
+
_ => Err(JsValue::undefined()),
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#[wasm_bindgen(getter = "replaceTransition")]
|
|
79
|
+
pub fn get_replace_transition(&self) -> Result<DocumentReplaceTransitionWASM, JsValue> {
|
|
80
|
+
match self.0.clone() {
|
|
81
|
+
DocumentTransition::Replace(replace) => {
|
|
82
|
+
Ok(DocumentReplaceTransitionWASM::from(replace))
|
|
83
|
+
}
|
|
84
|
+
_ => Err(JsValue::undefined()),
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#[wasm_bindgen(getter = "deleteTransition")]
|
|
89
|
+
pub fn get_delete_transition(&self) -> Result<DocumentDeleteTransitionWASM, JsValue> {
|
|
90
|
+
match self.0.clone() {
|
|
91
|
+
DocumentTransition::Delete(delete) => Ok(DocumentDeleteTransitionWASM::from(delete)),
|
|
92
|
+
_ => Err(JsValue::undefined()),
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#[wasm_bindgen(getter = "purchaseTransition")]
|
|
97
|
+
pub fn get_purchase_transition(&self) -> Result<DocumentPurchaseTransitionWASM, JsValue> {
|
|
98
|
+
match self.0.clone() {
|
|
99
|
+
DocumentTransition::Purchase(purchase) => {
|
|
100
|
+
Ok(DocumentPurchaseTransitionWASM::from(purchase))
|
|
101
|
+
}
|
|
102
|
+
_ => Err(JsValue::undefined()),
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
#[wasm_bindgen(getter = "transferTransition")]
|
|
107
|
+
pub fn get_transfer_transition(&self) -> Result<DocumentTransferTransitionWASM, JsValue> {
|
|
108
|
+
match self.0.clone() {
|
|
109
|
+
DocumentTransition::Transfer(transfer) => {
|
|
110
|
+
Ok(DocumentTransferTransitionWASM::from(transfer))
|
|
111
|
+
}
|
|
112
|
+
_ => Err(JsValue::undefined()),
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#[wasm_bindgen(getter = "updatePriceTransition")]
|
|
117
|
+
pub fn get_update_price_transition(
|
|
118
|
+
&self,
|
|
119
|
+
) -> Result<DocumentUpdatePriceTransitionWASM, JsValue> {
|
|
120
|
+
match self.0.clone() {
|
|
121
|
+
DocumentTransition::UpdatePrice(update_price) => {
|
|
122
|
+
Ok(DocumentUpdatePriceTransitionWASM::from(update_price))
|
|
123
|
+
}
|
|
124
|
+
_ => Err(JsValue::undefined()),
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
#[wasm_bindgen(setter = "dataContractId")]
|
|
129
|
+
pub fn set_data_contract_id(&mut self, js_data_contract_id: JsValue) -> Result<(), JsValue> {
|
|
130
|
+
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
131
|
+
|
|
132
|
+
Ok(self.0.set_data_contract_id(data_contract_id))
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#[wasm_bindgen(setter = "revision")]
|
|
136
|
+
pub fn set_revision(&mut self, revision: Revision) {
|
|
137
|
+
self.0.set_revision(revision)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
#[wasm_bindgen(setter = "identityContractNonce")]
|
|
141
|
+
pub fn set_identity_contract_nonce(&mut self, identity_contract_nonce: IdentityNonce) {
|
|
142
|
+
self.0.set_identity_contract_nonce(identity_contract_nonce)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
impl DocumentTransitionWASM {
|
|
147
|
+
pub fn rs_get_data_contract_id(&self) -> Identifier {
|
|
148
|
+
self.0.data_contract_id()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
pub fn rs_get_id(&self) -> Identifier {
|
|
152
|
+
self.0.get_id()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
pub fn rs_get_entropy(&self) -> Option<Vec<u8>> {
|
|
156
|
+
self.0.entropy()
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
pub fn rs_get_revision(&self) -> Option<Revision> {
|
|
160
|
+
self.0.revision()
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
pub fn rs_get_identity_contract_nonce(&self) -> IdentityNonce {
|
|
164
|
+
self.0.identity_contract_nonce()
|
|
165
|
+
}
|
|
166
|
+
}
|