@dashevo/wasm-dpp 1.8.0 → 2.0.0-rc.1
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/.eslintrc +3 -0
- package/Cargo.toml +10 -6
- package/README.md +1 -1
- package/dist/wasm/wasm_dpp.d.ts +2045 -1114
- package/dist/wasm/wasm_dpp.js +740 -222
- package/dist/wasm/wasm_dpp_bg.js +1 -1
- package/lib/test/fixtures/getIdentityCreditTransferTransitionFixture.js +1 -1
- package/lib/test/fixtures/getIdentityFixture.js +1 -1
- package/lib/wasm/wasm_dpp.d.ts +2045 -1114
- package/package.json +6 -6
- package/scripts/build-wasm.sh +1 -1
- package/src/data_contract/data_contract.rs +17 -24
- package/src/data_contract/mod.rs +1 -0
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +21 -0
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +25 -0
- package/src/data_contract/tokens.rs +60 -0
- package/src/data_contract_factory/mod.rs +1 -1
- package/src/document/document_facade.rs +3 -3
- package/src/document/errors/document_already_exists_error.rs +1 -1
- package/src/document/errors/document_not_provided_error.rs +1 -1
- package/src/document/errors/invalid_document_action_error.rs +2 -2
- package/src/document/extended_document.rs +3 -5
- package/src/document/factory.rs +25 -10
- package/src/document/mod.rs +6 -8
- package/src/document/state_transition/batch_transition/batched_transition/mod.rs +18 -0
- package/src/document/state_transition/{document_batch_transition → batch_transition}/document_transition/document_create_transition.rs +45 -3
- package/src/document/state_transition/{document_batch_transition → batch_transition}/document_transition/document_delete_transition.rs +23 -4
- package/src/document/state_transition/{document_batch_transition → batch_transition}/document_transition/document_replace_transition.rs +24 -5
- package/src/document/state_transition/{document_batch_transition → batch_transition}/document_transition/mod.rs +97 -14
- package/src/document/state_transition/{document_batch_transition → batch_transition}/mod.rs +44 -29
- package/src/document/state_transition/batch_transition/token_transition/burn.rs +12 -0
- package/src/document/state_transition/batch_transition/token_transition/claim.rs +12 -0
- package/src/document/state_transition/batch_transition/token_transition/config.rs +12 -0
- package/src/document/state_transition/batch_transition/token_transition/destroy.rs +22 -0
- package/src/document/state_transition/batch_transition/token_transition/direct_purchase.rs +12 -0
- package/src/document/state_transition/batch_transition/token_transition/emergency_action.rs +12 -0
- package/src/document/state_transition/batch_transition/token_transition/freeze.rs +22 -0
- package/src/document/state_transition/batch_transition/token_transition/mint.rs +31 -0
- package/src/document/state_transition/batch_transition/token_transition/mod.rs +154 -0
- package/src/document/state_transition/batch_transition/token_transition/set_price_for_direct_purchase.rs +14 -0
- package/src/document/state_transition/batch_transition/token_transition/transfer.rs +22 -0
- package/src/document/state_transition/batch_transition/token_transition/unfreeze.rs +22 -0
- package/src/document/state_transition/mod.rs +1 -1
- package/src/errors/consensus/basic/identity/identity_insufficient_balance_error.rs +2 -2
- package/src/errors/consensus/basic/state_transition/missing_state_transition_type_error.rs +6 -0
- package/src/errors/consensus/consensus_error.rs +212 -1
- package/src/errors/consensus/fee/balance_is_not_enough_error.rs +4 -4
- package/src/errors/consensus/state/identity/invalid_identity_contract_nonce_error.rs +1 -1
- package/src/errors/value_error.rs +1 -0
- package/src/identity/identity.rs +14 -14
- package/src/identity/mod.rs +1 -0
- package/src/identity/state_transition/identity_create_transition/mod.rs +2 -2
- package/src/identity/state_transition/identity_create_transition/{identity_create_transition.rs → transition.rs} +10 -0
- package/src/identity/state_transition/identity_credit_transfer_transition/transition.rs +31 -6
- package/src/identity/state_transition/identity_credit_withdrawal_transition/transition.rs +15 -0
- package/src/identity/state_transition/identity_public_key_transitions.rs +2 -2
- package/src/identity/state_transition/identity_topup_transition/mod.rs +2 -2
- package/src/identity/state_transition/identity_topup_transition/{identity_topup_transition.rs → transition.rs} +10 -0
- package/src/identity/state_transition/identity_update_transition/mod.rs +2 -2
- package/src/identity/state_transition/identity_update_transition/to_object.rs +2 -2
- package/src/identity/state_transition/identity_update_transition/{identity_update_transition.rs → transition.rs} +29 -4
- package/src/identity/state_transition/transition_types.rs +1 -1
- package/src/metadata.rs +16 -27
- package/src/state_transition/state_transition_factory.rs +2 -4
- package/src/utils.rs +4 -2
- package/src/voting/state_transition/masternode_vote_transition/mod.rs +75 -50
- package/src/voting/state_transition/masternode_vote_transition/to_object.rs +1 -0
- package/test/integration/document/Document.spec.js +2 -7
- package/test/integration/document/DocumentFacade.spec.js +4 -4
- package/test/integration/identity/IdentityFacade.spec.js +5 -10
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +4 -4
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +3 -3
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +1 -1
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +3 -3
- package/test/unit/Metadata.spec.js +8 -23
- package/test/unit/dataContract/DataContract.spec.js +1 -18
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +1 -1
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +1 -1
- package/test/unit/document/Document.spec.js +4 -7
- package/test/unit/document/DocumentFactory.spec.js +2 -2
- package/test/unit/identity/Identity.spec.js +15 -35
- package/test/unit/identity/IdentityFactory.spec.js +3 -3
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/IdentityUpdateTransition.spec.js +2 -2
- package/test/unit/identity/stateTransition/identityCreditTransferTransition/identityCreditTransferTransition.spec.js +1 -1
- /package/src/data_contract_factory/{data_contract_factory.rs → factory.rs} +0 -0
- /package/src/document/state_transition/{document_batch_transition → batch_transition}/validation/basic/find_duplicates_by_id.rs +0 -0
- /package/src/document/state_transition/{document_batch_transition → batch_transition}/validation/basic/find_duplicates_by_indices.rs +0 -0
- /package/src/document/state_transition/{document_batch_transition → batch_transition}/validation/basic/mod.rs +0 -0
- /package/src/document/state_transition/{document_batch_transition → batch_transition}/validation/basic/validate_documents_batch_transition_basic.rs +0 -0
- /package/src/document/state_transition/{document_batch_transition → batch_transition}/validation/basic/validate_partial_compound_indices.rs +0 -0
- /package/src/document/state_transition/{document_batch_transition → batch_transition}/validation/mod.rs +0 -0
- /package/src/document/state_transition/{document_batch_transition → batch_transition}/validation/state/fetch_extended_documents.rs +0 -0
- /package/src/document/state_transition/{document_batch_transition → batch_transition}/validation/state/mod.rs +0 -0
- /package/src/document/state_transition/{document_batch_transition → batch_transition}/validation/state/validate_documents_batch_transitions_state.rs +0 -0
- /package/src/document/state_transition/{document_batch_transition → batch_transition}/validation/state/validate_documents_uniqueness_by_indices.rs +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/wasm-dpp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-rc.1",
|
|
4
4
|
"description": "The JavaScript implementation of the Dash Platform Protocol",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@apidevtools/json-schema-ref-parser": "^8.0.0",
|
|
43
|
-
"@babel/cli": "^7.
|
|
44
|
-
"@babel/core": "^7.
|
|
45
|
-
"@babel/preset-env": "^7.
|
|
43
|
+
"@babel/cli": "^7.26.4",
|
|
44
|
+
"@babel/core": "^7.26.10",
|
|
45
|
+
"@babel/preset-env": "^7.26.9",
|
|
46
46
|
"@dashevo/dashcore-lib": "~0.22.0",
|
|
47
|
-
"@dashevo/dpns-contract": "
|
|
47
|
+
"@dashevo/dpns-contract": "2.0.0-rc.1",
|
|
48
48
|
"@types/bs58": "^4.0.1",
|
|
49
49
|
"@types/node": "^14.6.0",
|
|
50
50
|
"@yarnpkg/pnpify": "^4.0.0-rc.42",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"karma-webpack": "^5.0.0",
|
|
74
74
|
"lodash": "^4.17.21",
|
|
75
75
|
"long": "^5.2.0",
|
|
76
|
-
"mocha": "^
|
|
76
|
+
"mocha": "^11.1.0",
|
|
77
77
|
"path-browserify": "^1.0.1",
|
|
78
78
|
"process": "^0.11.10",
|
|
79
79
|
"sinon": "^17.0.1",
|
package/scripts/build-wasm.sh
CHANGED
|
@@ -49,7 +49,7 @@ fi
|
|
|
49
49
|
|
|
50
50
|
if command -v wasm-opt &> /dev/null; then
|
|
51
51
|
echo "Optimizing wasm using Binaryen"
|
|
52
|
-
wasm-opt -Oz "$OUTPUT_FILE" -o "$OUTPUT_FILE"
|
|
52
|
+
wasm-opt -tnh --flatten --rereloop -Oz --gufa -Oz --gufa -Oz "$OUTPUT_FILE" -o "$OUTPUT_FILE"
|
|
53
53
|
else
|
|
54
54
|
echo "wasm-opt command not found. Skipping wasm optimization."
|
|
55
55
|
fi
|
|
@@ -7,10 +7,11 @@ pub use serde::{Deserialize, Serialize};
|
|
|
7
7
|
use wasm_bindgen::prelude::*;
|
|
8
8
|
|
|
9
9
|
use dpp::data_contract::schema::DataContractSchemaMethodsV0;
|
|
10
|
-
use dpp::data_contract::DataContract;
|
|
10
|
+
use dpp::data_contract::{DataContract, TokenContractPosition};
|
|
11
11
|
use dpp::platform_value::{platform_value, Value};
|
|
12
12
|
|
|
13
13
|
use dpp::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters};
|
|
14
|
+
use dpp::data_contract::accessors::v1::DataContractV1Getters;
|
|
14
15
|
use dpp::data_contract::config::DataContractConfig;
|
|
15
16
|
use dpp::data_contract::conversion::json::DataContractJsonConversionMethodsV0;
|
|
16
17
|
use dpp::data_contract::conversion::value::v0::DataContractValueConversionMethodsV0;
|
|
@@ -22,11 +23,11 @@ use dpp::serialization::PlatformSerializableWithPlatformVersion;
|
|
|
22
23
|
use dpp::version::PlatformVersion;
|
|
23
24
|
use dpp::ProtocolError;
|
|
24
25
|
|
|
26
|
+
use crate::data_contract::tokens::TokenConfigurationWasm;
|
|
25
27
|
use crate::identifier::identifier_from_js_value;
|
|
26
|
-
use crate::metadata::MetadataWasm;
|
|
27
28
|
use crate::utils::get_bool_from_options;
|
|
28
29
|
use crate::utils::SKIP_VALIDATION_PROPERTY_NAME;
|
|
29
|
-
use crate::utils::{Inner,
|
|
30
|
+
use crate::utils::{Inner, ToSerdeJSONExt, WithJsError};
|
|
30
31
|
use crate::with_js_error;
|
|
31
32
|
use crate::{buffer::Buffer, identifier::IdentifierWrapper};
|
|
32
33
|
|
|
@@ -313,8 +314,8 @@ impl DataContractWasm {
|
|
|
313
314
|
}
|
|
314
315
|
|
|
315
316
|
#[wasm_bindgen(js_name=setIdentityNonce)]
|
|
316
|
-
pub fn set_identity_nonce(&mut self,
|
|
317
|
-
self.identity_nonce = Some(
|
|
317
|
+
pub fn set_identity_nonce(&mut self, nonce: u64) -> Result<(), JsValue> {
|
|
318
|
+
self.identity_nonce = Some(nonce);
|
|
318
319
|
Ok(())
|
|
319
320
|
}
|
|
320
321
|
|
|
@@ -323,25 +324,6 @@ impl DataContractWasm {
|
|
|
323
324
|
self.identity_nonce.unwrap_or_default()
|
|
324
325
|
}
|
|
325
326
|
|
|
326
|
-
#[wasm_bindgen(js_name=getMetadata)]
|
|
327
|
-
pub fn metadata(&self) -> Option<MetadataWasm> {
|
|
328
|
-
self.inner.metadata().cloned().map(Into::into)
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
#[wasm_bindgen(js_name=setMetadata)]
|
|
332
|
-
pub fn set_metadata(&mut self, metadata: JsValue) -> Result<(), JsValue> {
|
|
333
|
-
let metadata = if !metadata.is_falsy() {
|
|
334
|
-
let metadata = metadata.to_wasm::<MetadataWasm>("Metadata")?;
|
|
335
|
-
Some(metadata.to_owned().into())
|
|
336
|
-
} else {
|
|
337
|
-
None
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
self.inner.set_metadata(metadata);
|
|
341
|
-
|
|
342
|
-
Ok(())
|
|
343
|
-
}
|
|
344
|
-
|
|
345
327
|
#[wasm_bindgen(js_name=toObject)]
|
|
346
328
|
pub fn to_object(&self) -> Result<JsValue, JsValue> {
|
|
347
329
|
let platform_version = PlatformVersion::first();
|
|
@@ -448,6 +430,17 @@ impl DataContractWasm {
|
|
|
448
430
|
.with_js_error()
|
|
449
431
|
.map(Into::into)
|
|
450
432
|
}
|
|
433
|
+
|
|
434
|
+
#[wasm_bindgen(js_name=getTokenConfiguration)]
|
|
435
|
+
pub fn token_configuration(
|
|
436
|
+
&self,
|
|
437
|
+
token_contract_position: TokenContractPosition,
|
|
438
|
+
) -> Result<TokenConfigurationWasm, JsValue> {
|
|
439
|
+
self.inner
|
|
440
|
+
.expected_token_configuration(token_contract_position)
|
|
441
|
+
.with_js_error()
|
|
442
|
+
.map(|token_configuration| token_configuration.clone().into())
|
|
443
|
+
}
|
|
451
444
|
}
|
|
452
445
|
|
|
453
446
|
impl Inner for DataContractWasm {
|
package/src/data_contract/mod.rs
CHANGED
|
@@ -81,6 +81,27 @@ impl DataContractCreateTransitionWasm {
|
|
|
81
81
|
pub fn get_type(&self) -> u32 {
|
|
82
82
|
self.0.state_transition_type() as u32
|
|
83
83
|
}
|
|
84
|
+
|
|
85
|
+
#[wasm_bindgen(js_name=setUserFeeIncrease)]
|
|
86
|
+
pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) {
|
|
87
|
+
self.0.set_user_fee_increase(user_fee_increase);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#[wasm_bindgen(js_name=getUserFeeIncrease)]
|
|
91
|
+
pub fn get_user_fee_increase(&self) -> u16 {
|
|
92
|
+
self.0.user_fee_increase()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#[wasm_bindgen(js_name=getSignature)]
|
|
96
|
+
pub fn get_signature(&self) -> Buffer {
|
|
97
|
+
Buffer::from_bytes(self.0.signature().as_slice())
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#[wasm_bindgen(js_name=getSignaturePublicKeyId)]
|
|
101
|
+
pub fn get_signature_public_key_id(&self) -> u32 {
|
|
102
|
+
self.0.signature_public_key_id()
|
|
103
|
+
}
|
|
104
|
+
|
|
84
105
|
//
|
|
85
106
|
// #[wasm_bindgen(js_name=toJSON)]
|
|
86
107
|
// pub fn to_json(&self, skip_signature: Option<bool>) -> Result<JsValue, JsValue> {
|
|
@@ -73,11 +73,36 @@ impl DataContractUpdateTransitionWasm {
|
|
|
73
73
|
self.0.owner_id().into()
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
#[wasm_bindgen(js_name=getIdentityContractNonce)]
|
|
77
|
+
pub fn get_identity_contract_nonce(&self) -> u64 {
|
|
78
|
+
self.0.identity_contract_nonce()
|
|
79
|
+
}
|
|
80
|
+
|
|
76
81
|
#[wasm_bindgen(js_name=getType)]
|
|
77
82
|
pub fn get_type(&self) -> u32 {
|
|
78
83
|
self.0.state_transition_type() as u32
|
|
79
84
|
}
|
|
80
85
|
|
|
86
|
+
#[wasm_bindgen(js_name=getUserFeeIncrease)]
|
|
87
|
+
pub fn get_user_fee_increase(&self) -> u16 {
|
|
88
|
+
self.0.user_fee_increase()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
#[wasm_bindgen(js_name=setUserFeeIncrease)]
|
|
92
|
+
pub fn set_user_fee_increase(&mut self, user_fee_increase: u16) {
|
|
93
|
+
self.0.set_user_fee_increase(user_fee_increase);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#[wasm_bindgen(js_name=getSignature)]
|
|
97
|
+
pub fn get_signature(&self) -> Buffer {
|
|
98
|
+
Buffer::from_bytes(self.0.signature().as_slice())
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#[wasm_bindgen(js_name=getSignaturePublicKeyId)]
|
|
102
|
+
pub fn get_signature_public_key_id(&self) -> u32 {
|
|
103
|
+
self.0.signature_public_key_id()
|
|
104
|
+
}
|
|
105
|
+
|
|
81
106
|
// #[wasm_bindgen(js_name=toJSON)]
|
|
82
107
|
// pub fn to_json(&self, skip_signature: Option<bool>) -> Result<JsValue, JsValue> {
|
|
83
108
|
// let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
use dpp::data_contract::associated_token::token_configuration::accessors::v0::TokenConfigurationV0Getters;
|
|
2
|
+
use dpp::data_contract::associated_token::token_keeps_history_rules::accessors::v0::TokenKeepsHistoryRulesV0Getters;
|
|
3
|
+
use dpp::data_contract::associated_token::token_keeps_history_rules::TokenKeepsHistoryRules;
|
|
4
|
+
use dpp::data_contract::TokenConfiguration;
|
|
5
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
6
|
+
|
|
7
|
+
#[derive(Debug, Clone)]
|
|
8
|
+
#[wasm_bindgen(js_name = "TokenConfiguration")]
|
|
9
|
+
pub struct TokenConfigurationWasm(TokenConfiguration);
|
|
10
|
+
|
|
11
|
+
impl From<TokenConfiguration> for TokenConfigurationWasm {
|
|
12
|
+
fn from(value: TokenConfiguration) -> Self {
|
|
13
|
+
Self(value)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
impl From<TokenConfigurationWasm> for TokenConfiguration {
|
|
18
|
+
fn from(val: TokenConfigurationWasm) -> Self {
|
|
19
|
+
val.0
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
#[wasm_bindgen(js_class = "TokenConfiguration")]
|
|
24
|
+
impl TokenConfigurationWasm {
|
|
25
|
+
#[wasm_bindgen(js_name=keepsHistory)]
|
|
26
|
+
pub fn keeps_history(&self) -> TokenKeepsHistoryRulesWasm {
|
|
27
|
+
TokenKeepsHistoryRulesWasm(*self.0.keeps_history())
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
#[derive(Debug, Clone)]
|
|
32
|
+
#[wasm_bindgen(js_name = "TokenKeepsHistoryRules")]
|
|
33
|
+
pub struct TokenKeepsHistoryRulesWasm(TokenKeepsHistoryRules);
|
|
34
|
+
|
|
35
|
+
#[wasm_bindgen(js_class = "TokenKeepsHistoryRules")]
|
|
36
|
+
impl TokenKeepsHistoryRulesWasm {
|
|
37
|
+
/// Whether transfer history is recorded.
|
|
38
|
+
#[wasm_bindgen(js_name=keepsTransferHistory)]
|
|
39
|
+
pub fn keeps_transfer_history(&self) -> bool {
|
|
40
|
+
self.0.keeps_transfer_history()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Whether freezing history is recorded.
|
|
44
|
+
#[wasm_bindgen(js_name=keepsFreezingHistory)]
|
|
45
|
+
pub fn keeps_freezing_history(&self) -> bool {
|
|
46
|
+
self.0.keeps_freezing_history()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/// Whether minting history is recorded.
|
|
50
|
+
#[wasm_bindgen(js_name=keepsMintingHistory)]
|
|
51
|
+
pub fn keeps_minting_history(&self) -> bool {
|
|
52
|
+
self.0.keeps_minting_history()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// Whether burning history is recorded.
|
|
56
|
+
#[wasm_bindgen(js_name=keepsBurningHistory)]
|
|
57
|
+
pub fn keeps_burning_history(&self) -> bool {
|
|
58
|
+
self.0.keeps_burning_history()
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
mod
|
|
1
|
+
mod factory;
|
|
@@ -4,7 +4,7 @@ use wasm_bindgen::{prelude::*, JsValue};
|
|
|
4
4
|
use crate::document::factory::DocumentFactoryWASM;
|
|
5
5
|
use crate::{DataContractWasm, ExtendedDocumentWasm};
|
|
6
6
|
|
|
7
|
-
use crate::document::state_transition::
|
|
7
|
+
use crate::document::state_transition::batch_transition::BatchTransitionWasm;
|
|
8
8
|
|
|
9
9
|
#[derive(Clone)]
|
|
10
10
|
#[wasm_bindgen(js_name=DocumentFacade)]
|
|
@@ -95,8 +95,8 @@ impl DocumentFacadeWasm {
|
|
|
95
95
|
pub fn create_state_transition(
|
|
96
96
|
&self,
|
|
97
97
|
documents: &JsValue,
|
|
98
|
-
nonce_counter_value: &js_sys::Object, //IdentityID/ContractID -> nonce
|
|
99
|
-
) -> Result<
|
|
98
|
+
nonce_counter_value: &js_sys::Object, //IdentityID/ContractID -> nonce (BigInt)
|
|
99
|
+
) -> Result<BatchTransitionWasm, JsValue> {
|
|
100
100
|
self.factory
|
|
101
101
|
.create_state_transition(documents, nonce_counter_value)
|
|
102
102
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
2
|
-
use dpp::state_transition::
|
|
2
|
+
use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition;
|
|
3
3
|
use thiserror::Error;
|
|
4
4
|
|
|
5
5
|
use super::*;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
2
|
-
use dpp::state_transition::
|
|
2
|
+
use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition;
|
|
3
3
|
use thiserror::Error;
|
|
4
4
|
|
|
5
5
|
use super::*;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
2
|
-
use dpp::state_transition::
|
|
2
|
+
use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition;
|
|
3
3
|
use thiserror::Error;
|
|
4
4
|
|
|
5
5
|
use super::*;
|
|
6
|
-
use dpp::state_transition::
|
|
6
|
+
use dpp::state_transition::batch_transition::batched_transition::document_transition_action_type::DocumentTransitionActionTypeGetter;
|
|
7
7
|
|
|
8
8
|
#[wasm_bindgen]
|
|
9
9
|
#[derive(Error, Debug)]
|
|
@@ -133,17 +133,15 @@ impl ExtendedDocumentWasm {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
#[wasm_bindgen(js_name=setRevision)]
|
|
136
|
-
pub fn set_revision(&mut self, rev: Option<
|
|
137
|
-
// TODO: js feeds Number (u32). Is casting revision to u64 safe?
|
|
136
|
+
pub fn set_revision(&mut self, rev: Option<u64>) {
|
|
138
137
|
self.0
|
|
139
138
|
.document_mut()
|
|
140
139
|
.set_revision(rev.map(|r| r as Revision));
|
|
141
140
|
}
|
|
142
141
|
|
|
143
142
|
#[wasm_bindgen(js_name=getRevision)]
|
|
144
|
-
pub fn get_revision(&self) -> Option<
|
|
145
|
-
|
|
146
|
-
self.0.document().revision().map(|r| r as u32)
|
|
143
|
+
pub fn get_revision(&self) -> Option<u64> {
|
|
144
|
+
self.0.document().revision()
|
|
147
145
|
}
|
|
148
146
|
|
|
149
147
|
#[wasm_bindgen(js_name=setEntropy)]
|
package/src/document/factory.rs
CHANGED
|
@@ -13,18 +13,18 @@ use dpp::document::Document;
|
|
|
13
13
|
|
|
14
14
|
use dpp::prelude::ExtendedDocument;
|
|
15
15
|
|
|
16
|
-
use
|
|
17
|
-
use dpp::state_transition::documents_batch_transition::document_transition::action_type::DocumentTransitionActionType;
|
|
18
|
-
use dpp::version::PlatformVersion;
|
|
19
|
-
use std::convert::TryFrom;
|
|
20
|
-
|
|
21
|
-
use crate::document_batch_transition::DocumentsBatchTransitionWasm;
|
|
16
|
+
use crate::batch_transition::BatchTransitionWasm;
|
|
22
17
|
use crate::entropy_generator::ExternalEntropyGenerator;
|
|
23
18
|
use crate::{
|
|
24
19
|
identifier::identifier_from_js_value,
|
|
25
20
|
utils::{IntoWasm, ToSerdeJSONExt, WithJsError},
|
|
26
21
|
DataContractWasm, ExtendedDocumentWasm,
|
|
27
22
|
};
|
|
23
|
+
use dpp::identifier::Identifier;
|
|
24
|
+
use dpp::state_transition::batch_transition::batched_transition::document_transition_action_type::DocumentTransitionActionType;
|
|
25
|
+
use dpp::tokens::token_payment_info::TokenPaymentInfo;
|
|
26
|
+
use dpp::version::PlatformVersion;
|
|
27
|
+
use std::convert::TryFrom;
|
|
28
28
|
|
|
29
29
|
#[wasm_bindgen(js_name=DocumentTransitions)]
|
|
30
30
|
#[derive(Debug, Default)]
|
|
@@ -109,7 +109,7 @@ impl DocumentFactoryWASM {
|
|
|
109
109
|
&self,
|
|
110
110
|
documents: &JsValue,
|
|
111
111
|
nonce_counter_value: &js_sys::Object, //IdentityID/ContractID -> nonce
|
|
112
|
-
) -> Result<
|
|
112
|
+
) -> Result<BatchTransitionWasm, JsValue> {
|
|
113
113
|
let mut nonce_counter = BTreeMap::new();
|
|
114
114
|
let mut contract_ids_to_check = HashSet::<&Identifier>::new();
|
|
115
115
|
|
|
@@ -128,7 +128,12 @@ impl DocumentFactoryWASM {
|
|
|
128
128
|
.for_each(|entry| {
|
|
129
129
|
let key_value = js_sys::Array::from(&entry);
|
|
130
130
|
let contract_id = identifier_from_js_value(&key_value.get(0)).unwrap();
|
|
131
|
-
let nonce = key_value
|
|
131
|
+
let nonce = key_value
|
|
132
|
+
.get(1)
|
|
133
|
+
.as_string()
|
|
134
|
+
.unwrap()
|
|
135
|
+
.parse::<u64>()
|
|
136
|
+
.unwrap();
|
|
132
137
|
nonce_counter.insert((identity_id, contract_id), nonce);
|
|
133
138
|
});
|
|
134
139
|
});
|
|
@@ -150,13 +155,20 @@ impl DocumentFactoryWASM {
|
|
|
150
155
|
}
|
|
151
156
|
}
|
|
152
157
|
|
|
158
|
+
// TODO: use types or structs
|
|
159
|
+
#[allow(clippy::type_complexity)]
|
|
153
160
|
let documents: Vec<(
|
|
154
161
|
DocumentTransitionActionType,
|
|
155
|
-
Vec<(Document, DocumentTypeRef, Bytes32)>,
|
|
162
|
+
Vec<(Document, DocumentTypeRef, Bytes32, Option<TokenPaymentInfo>)>,
|
|
156
163
|
)> = documents_by_action
|
|
157
164
|
.iter()
|
|
158
165
|
.map(|(action_type, documents)| {
|
|
159
|
-
let documents_with_refs: Vec<(
|
|
166
|
+
let documents_with_refs: Vec<(
|
|
167
|
+
Document,
|
|
168
|
+
DocumentTypeRef,
|
|
169
|
+
Bytes32,
|
|
170
|
+
Option<TokenPaymentInfo>,
|
|
171
|
+
)> = documents
|
|
160
172
|
.iter()
|
|
161
173
|
.map(|extended_document| {
|
|
162
174
|
(
|
|
@@ -166,6 +178,7 @@ impl DocumentFactoryWASM {
|
|
|
166
178
|
.document_type_for_name(extended_document.document_type_name())
|
|
167
179
|
.expect("should be able to get document type"),
|
|
168
180
|
extended_document.entropy().to_owned(),
|
|
181
|
+
extended_document.token_payment_info(),
|
|
169
182
|
)
|
|
170
183
|
})
|
|
171
184
|
.collect();
|
|
@@ -245,6 +258,7 @@ impl DocumentFactoryWASM {
|
|
|
245
258
|
//
|
|
246
259
|
// Ok(document.into())
|
|
247
260
|
// }
|
|
261
|
+
//
|
|
248
262
|
|
|
249
263
|
#[wasm_bindgen(js_name=createExtendedDocumentFromDocumentBuffer)]
|
|
250
264
|
pub fn create_extended_from_document_buffer(
|
|
@@ -319,6 +333,7 @@ fn extract_documents_of_action(
|
|
|
319
333
|
return Ok(vec![]);
|
|
320
334
|
}
|
|
321
335
|
|
|
336
|
+
#[allow(clippy::unnecessary_fallible_conversions)]
|
|
322
337
|
let documents_array = js_sys::Array::try_from(documents_with_action)
|
|
323
338
|
.map_err(|e| anyhow!("property '{}' isn't an array: {}", action, e))?;
|
|
324
339
|
|
package/src/document/mod.rs
CHANGED
|
@@ -126,15 +126,13 @@ impl DocumentWasm {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
#[wasm_bindgen(js_name=setRevision)]
|
|
129
|
-
pub fn set_revision(&mut self, revision: Option<
|
|
130
|
-
|
|
131
|
-
self.0.set_revision(revision.map(|r| r as u64));
|
|
129
|
+
pub fn set_revision(&mut self, revision: Option<u64>) {
|
|
130
|
+
self.0.set_revision(revision);
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
#[wasm_bindgen(js_name=getRevision)]
|
|
135
|
-
pub fn get_revision(&self) -> Option<
|
|
136
|
-
|
|
137
|
-
self.0.revision().map(|r| r as u32)
|
|
134
|
+
pub fn get_revision(&self) -> Option<u64> {
|
|
135
|
+
self.0.revision()
|
|
138
136
|
}
|
|
139
137
|
|
|
140
138
|
#[wasm_bindgen(js_name=setData)]
|
|
@@ -344,8 +342,8 @@ impl DocumentWasm {
|
|
|
344
342
|
}
|
|
345
343
|
}
|
|
346
344
|
|
|
347
|
-
/// document's dynamic data, regardless they are identifiers or binary, they should
|
|
348
|
-
/// be stored as arrays of int
|
|
345
|
+
// /// document's dynamic data, regardless they are identifiers or binary, they should
|
|
346
|
+
// /// be stored as arrays of int
|
|
349
347
|
// pub(crate) fn document_data_to_bytes(
|
|
350
348
|
// document: &mut Document,
|
|
351
349
|
// contract: &DataContract,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
use dpp::state_transition::batch_transition::batched_transition::BatchedTransition;
|
|
2
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
3
|
+
|
|
4
|
+
#[wasm_bindgen(js_name=BatchedTransition)]
|
|
5
|
+
#[derive(Debug, Clone)]
|
|
6
|
+
pub struct BatchedTransitionWasm(BatchedTransition);
|
|
7
|
+
|
|
8
|
+
impl From<BatchedTransition> for BatchedTransitionWasm {
|
|
9
|
+
fn from(t: BatchedTransition) -> Self {
|
|
10
|
+
BatchedTransitionWasm(t)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
impl From<BatchedTransitionWasm> for BatchedTransition {
|
|
15
|
+
fn from(t: BatchedTransitionWasm) -> Self {
|
|
16
|
+
t.0
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
use dpp::prelude::Revision;
|
|
2
2
|
|
|
3
|
-
use dpp::state_transition::
|
|
3
|
+
use dpp::state_transition::batch_transition::document_create_transition::DocumentCreateTransition;
|
|
4
4
|
|
|
5
5
|
use dpp::document::INITIAL_REVISION;
|
|
6
6
|
|
|
7
7
|
use wasm_bindgen::prelude::*;
|
|
8
|
+
use dpp::state_transition::batch_transition::document_create_transition::v0::v0_methods::DocumentCreateTransitionV0Methods;
|
|
9
|
+
use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors;
|
|
10
|
+
use dpp::state_transition::batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods;
|
|
8
11
|
|
|
9
12
|
#[wasm_bindgen(js_name=DocumentCreateTransition)]
|
|
10
13
|
#[derive(Debug, Clone)]
|
|
@@ -77,8 +80,47 @@ impl DocumentCreateTransitionWasm {
|
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
#[wasm_bindgen(getter, js_name=INITIAL_REVISION)]
|
|
80
|
-
pub fn initial_revision() ->
|
|
81
|
-
INITIAL_REVISION
|
|
83
|
+
pub fn initial_revision() -> u64 {
|
|
84
|
+
INITIAL_REVISION
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
#[wasm_bindgen(js_name = getEntropy)]
|
|
88
|
+
pub fn get_entropy(&self) -> Vec<u8> {
|
|
89
|
+
Vec::from(self.inner.entropy())
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#[wasm_bindgen(js_name=getIdentityContractNonce)]
|
|
93
|
+
pub fn get_identity_contract_nonce(&self) -> u64 {
|
|
94
|
+
self.inner.base().identity_contract_nonce()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#[wasm_bindgen(js_name=setIdentityContractNonce)]
|
|
98
|
+
pub fn set_identity_contract_nonce(&mut self, identity_contract_nonce: u64) {
|
|
99
|
+
let mut base = self.inner.base().clone();
|
|
100
|
+
|
|
101
|
+
base.set_identity_contract_nonce(identity_contract_nonce);
|
|
102
|
+
|
|
103
|
+
self.inner.set_base(base)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
#[wasm_bindgen(js_name = getPrefundedVotingBalance)]
|
|
107
|
+
pub fn get_prefunded_voting_balance(&self) -> Result<JsValue, JsValue> {
|
|
108
|
+
let prefunded_voting_balance = self.inner.prefunded_voting_balance().clone();
|
|
109
|
+
|
|
110
|
+
match prefunded_voting_balance {
|
|
111
|
+
None => Ok(JsValue::null()),
|
|
112
|
+
Some((index_name, credits)) => {
|
|
113
|
+
let js_object = js_sys::Object::new();
|
|
114
|
+
|
|
115
|
+
js_sys::Reflect::set(
|
|
116
|
+
&js_object,
|
|
117
|
+
&JsValue::from_str(&index_name),
|
|
118
|
+
&JsValue::from(credits),
|
|
119
|
+
)?;
|
|
120
|
+
|
|
121
|
+
Ok(JsValue::from(js_object))
|
|
122
|
+
}
|
|
123
|
+
}
|
|
82
124
|
}
|
|
83
125
|
|
|
84
126
|
// // AbstractDocumentTransitionMethods
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use dpp::state_transition::
|
|
1
|
+
use dpp::state_transition::batch_transition::{
|
|
2
2
|
document_delete_transition, DocumentDeleteTransition,
|
|
3
3
|
};
|
|
4
4
|
|
|
@@ -10,9 +10,9 @@ use crate::{
|
|
|
10
10
|
document::document_batch_transition::document_transition::to_object,
|
|
11
11
|
identifier::IdentifierWrapper, utils::WithJsError,
|
|
12
12
|
};
|
|
13
|
-
use dpp::state_transition::
|
|
14
|
-
use dpp::state_transition::
|
|
15
|
-
use dpp::state_transition::
|
|
13
|
+
use dpp::state_transition::batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods;
|
|
14
|
+
use dpp::state_transition::batch_transition::document_delete_transition::v0::v0_methods::DocumentDeleteTransitionV0Methods;
|
|
15
|
+
use dpp::state_transition::batch_transition::document_transition::action_type::DocumentTransitionActionType;
|
|
16
16
|
|
|
17
17
|
#[wasm_bindgen(js_name=DocumentDeleteTransition)]
|
|
18
18
|
#[derive(Debug, Clone)]
|
|
@@ -68,11 +68,30 @@ impl DocumentDeleteTransitionWasm {
|
|
|
68
68
|
self.inner.base().document_type_name().clone()
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
#[wasm_bindgen(js_name = getEntropy)]
|
|
72
|
+
pub fn get_entropy(&self) -> Vec<u8> {
|
|
73
|
+
Vec::from(self.inner.entropy())
|
|
74
|
+
}
|
|
75
|
+
|
|
71
76
|
#[wasm_bindgen(js_name=getDataContractId)]
|
|
72
77
|
pub fn data_contract_id(&self) -> IdentifierWrapper {
|
|
73
78
|
self.inner.base().data_contract_id().into()
|
|
74
79
|
}
|
|
75
80
|
|
|
81
|
+
#[wasm_bindgen(js_name=getIdentityContractNonce)]
|
|
82
|
+
pub fn get_identity_contract_nonce(&self) -> u64 {
|
|
83
|
+
self.inner.base().identity_contract_nonce() as u64
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#[wasm_bindgen(js_name=setIdentityContractNonce)]
|
|
87
|
+
pub fn set_identity_contract_nonce(&mut self, identity_contract_nonce: u64) {
|
|
88
|
+
let mut base = self.inner.base().clone();
|
|
89
|
+
|
|
90
|
+
base.set_identity_contract_nonce(identity_contract_nonce);
|
|
91
|
+
|
|
92
|
+
self.inner.set_base(base)
|
|
93
|
+
}
|
|
94
|
+
|
|
76
95
|
#[wasm_bindgen(js_name=get)]
|
|
77
96
|
pub fn get(&self, path: String) -> Result<JsValue, JsValue> {
|
|
78
97
|
let _ = path;
|
|
@@ -3,11 +3,15 @@ use std::convert::TryInto;
|
|
|
3
3
|
|
|
4
4
|
use serde_json::Value as JsonValue;
|
|
5
5
|
|
|
6
|
+
use dpp::data_contract::accessors::v0::DataContractV0Getters;
|
|
7
|
+
use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
|
|
6
8
|
use dpp::platform_value::btreemap_extensions::{
|
|
7
9
|
BTreeValueMapHelper, BTreeValueMapPathHelper, BTreeValueMapReplacementPathHelper,
|
|
8
10
|
};
|
|
9
11
|
use dpp::platform_value::ReplacementType;
|
|
10
12
|
use dpp::prelude::Revision;
|
|
13
|
+
use dpp::state_transition::batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods;
|
|
14
|
+
use dpp::state_transition::batch_transition::document_replace_transition::v0::v0_methods::DocumentReplaceTransitionV0Methods;
|
|
11
15
|
use dpp::{
|
|
12
16
|
prelude::{DataContract, Identifier},
|
|
13
17
|
state_transition::documents_batch_transition::{
|
|
@@ -18,10 +22,6 @@ use dpp::{
|
|
|
18
22
|
};
|
|
19
23
|
use serde::Serialize;
|
|
20
24
|
use wasm_bindgen::prelude::*;
|
|
21
|
-
use dpp::data_contract::accessors::v0::DataContractV0Getters;
|
|
22
|
-
use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
|
|
23
|
-
use dpp::state_transition::documents_batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods;
|
|
24
|
-
use dpp::state_transition::documents_batch_transition::document_replace_transition::v0::v0_methods::DocumentReplaceTransitionV0Methods;
|
|
25
25
|
|
|
26
26
|
use crate::{
|
|
27
27
|
buffer::Buffer,
|
|
@@ -31,7 +31,7 @@ use crate::{
|
|
|
31
31
|
utils::{ToSerdeJSONExt, WithJsError},
|
|
32
32
|
BinaryType, DataContractWasm,
|
|
33
33
|
};
|
|
34
|
-
use dpp::state_transition::
|
|
34
|
+
use dpp::state_transition::batch_transition::document_transition::action_type::DocumentTransitionActionType;
|
|
35
35
|
|
|
36
36
|
#[wasm_bindgen(js_name=DocumentReplaceTransition)]
|
|
37
37
|
#[derive(Debug, Clone)]
|
|
@@ -96,6 +96,11 @@ impl DocumentReplaceTransitionWasm {
|
|
|
96
96
|
self.inner.revision()
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
#[wasm_bindgen(js_name = getEntropy)]
|
|
100
|
+
pub fn get_entropy(&self) -> Vec<u8> {
|
|
101
|
+
Vec::from(self.inner.entropy())
|
|
102
|
+
}
|
|
103
|
+
|
|
99
104
|
#[wasm_bindgen(js_name=getUpdatedAt)]
|
|
100
105
|
pub fn updated_at(&self) -> Option<js_sys::Date> {
|
|
101
106
|
self.inner
|
|
@@ -189,6 +194,20 @@ impl DocumentReplaceTransitionWasm {
|
|
|
189
194
|
self.inner.base().data_contract_id().into()
|
|
190
195
|
}
|
|
191
196
|
|
|
197
|
+
#[wasm_bindgen(js_name=getIdentityContractNonce)]
|
|
198
|
+
pub fn get_identity_contract_nonce(&self) -> u64 {
|
|
199
|
+
self.inner.base().identity_contract_nonce() as u64
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
#[wasm_bindgen(js_name=setIdentityContractNonce)]
|
|
203
|
+
pub fn set_identity_contract_nonce(&mut self, identity_contract_nonce: u64) -> () {
|
|
204
|
+
let mut base = self.inner.base().clone();
|
|
205
|
+
|
|
206
|
+
base.set_identity_contract_nonce(identity_contract_nonce);
|
|
207
|
+
|
|
208
|
+
self.inner.set_base(base)
|
|
209
|
+
}
|
|
210
|
+
|
|
192
211
|
#[wasm_bindgen(js_name=get)]
|
|
193
212
|
pub fn get(&self, path: String) -> Result<JsValue, JsValue> {
|
|
194
213
|
let document_data = if let Some(ref data) = self.inner.data() {
|