@dashevo/wasm-dpp 0.25.0-dev.15 → 0.25.0-dev.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +5 -1
- package/dist/wasm/wasm_dpp.d.ts +1319 -1058
- package/dist/wasm/wasm_dpp.js +227 -116
- package/dist/wasm/wasm_dpp_bg.js +1 -1
- package/lib/test/fixtures/getDataContractFixture.js +9 -1
- package/lib/test/fixtures/getIdentityCreditTransferTransitionFixture.js +19 -0
- package/lib/wasm/wasm_dpp.d.ts +1319 -1058
- package/package.json +4 -4
- package/scripts/build-wasm.sh +6 -9
- package/src/data_contract/data_contract.rs +12 -0
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +18 -1
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +18 -1
- package/src/data_contract_factory/data_contract_factory.rs +11 -2
- package/src/errors/consensus/consensus_error.rs +10 -1
- package/src/errors/consensus/state/data_contract/data_contract_config_update_error.rs +53 -0
- package/src/errors/consensus/state/data_contract/data_contract_is_readonly_error.rs +53 -0
- package/src/errors/consensus/state/data_contract/mod.rs +4 -0
- package/src/errors/consensus/state/document/document_timestamps_are_equal_error.rs +1 -1
- package/src/identity/identity_facade.rs +20 -2
- package/src/identity/identity_factory.rs +20 -2
- package/src/identity/state_transition/identity_credit_transfer_transition/apply_identity_credit_transfer_transition.rs +31 -0
- package/src/identity/state_transition/identity_credit_transfer_transition/identity_credit_transfer_transition_basic_validator.rs +66 -0
- package/src/identity/state_transition/identity_credit_transfer_transition/identity_credit_transfer_transition_state_validator.rs +44 -0
- package/src/identity/state_transition/identity_credit_transfer_transition/mod.rs +8 -0
- package/src/identity/state_transition/identity_credit_transfer_transition/to_object.rs +52 -0
- package/src/identity/state_transition/identity_credit_transfer_transition/transition.rs +311 -0
- package/src/identity/state_transition/mod.rs +2 -0
- package/src/identity/state_transition/transition_types.rs +4 -0
- package/src/state_transition/conversion.rs +11 -1
- package/src/state_transition/state_transition_facade.rs +1 -1
- package/src/state_transition/state_transition_factory.rs +10 -1
- package/src/state_transition/validation/validate_state_transition_identity_signature.rs +5 -0
- package/test/unit/dataContract/DataContract.spec.js +18 -0
- package/test/unit/dataContract/DataContractFactory.spec.js +20 -0
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +10 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +10 -0
- package/test/unit/identity/stateTransition/identityCreditTransferTransition/identityCreditTransferTransition.spec.js +139 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/wasm-dpp",
|
|
3
|
-
"version": "0.25.0-dev.
|
|
3
|
+
"version": "0.25.0-dev.16",
|
|
4
4
|
"description": "The JavaScript implementation of the Dash Platform Protocol",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"@babel/cli": "^7.21.0",
|
|
44
44
|
"@babel/core": "^7.15.5",
|
|
45
45
|
"@babel/preset-env": "^7.15.4",
|
|
46
|
-
"@dashevo/dashcore-lib": "~0.20.
|
|
47
|
-
"@dashevo/dpns-contract": "0.25.0-dev.
|
|
48
|
-
"@dashevo/dpp": "0.25.0-dev.
|
|
46
|
+
"@dashevo/dashcore-lib": "~0.20.9",
|
|
47
|
+
"@dashevo/dpns-contract": "0.25.0-dev.16",
|
|
48
|
+
"@dashevo/dpp": "0.25.0-dev.16",
|
|
49
49
|
"@dashevo/wasm-re2": "~1.0.2",
|
|
50
50
|
"@types/bs58": "^4.0.1",
|
|
51
51
|
"@types/node": "^14.6.0",
|
package/scripts/build-wasm.sh
CHANGED
|
@@ -14,7 +14,6 @@ if [[ "${CARGO_BUILD_PROFILE}" == "dev" ]]; then
|
|
|
14
14
|
fi
|
|
15
15
|
|
|
16
16
|
OUTPUT_DIR="${PWD}/wasm"
|
|
17
|
-
WORKSPACE_ROOT="$(dirname "$0")/../../.."
|
|
18
17
|
# shellcheck disable=SC2034
|
|
19
18
|
OUTPUT_FILE="${OUTPUT_DIR}/wasm_dpp_bg.wasm"
|
|
20
19
|
BUILD_COMMAND="cargo build --config net.git-fetch-with-cli=true --target=${TARGET} ${PROFILE_ARG}"
|
|
@@ -24,15 +23,13 @@ if ! [[ -d ${OUTPUT_DIR} ]]; then
|
|
|
24
23
|
mkdir -p "${OUTPUT_DIR}"
|
|
25
24
|
fi
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
WASM_BINDGEN_VERSION=$(cargo-lock list --file "${WORKSPACE_ROOT}/Cargo.lock" --package wasm-bindgen | grep -Eo '[0-9.]+')
|
|
33
|
-
if ! [[ "$(wasm-bindgen --version)" =~ ${WASM_BINDGEN_VERSION} ]]; then
|
|
26
|
+
# TODO: Build wasm with build.rs
|
|
27
|
+
# Meantime if you want to update wasm-bindgen you also need to update version in:
|
|
28
|
+
# - packages/wasm-dpp/Cargo.toml
|
|
29
|
+
# - Dockerfile
|
|
30
|
+
if ! [[ -x "$(command -v wasm-bindgen)" ]]; then
|
|
34
31
|
echo "Wasm-bindgen CLI ${WASM_BINDGEN_VERSION} is not installed. Installing"
|
|
35
|
-
cargo install --config net.git-fetch-with-cli=true --profile "${CARGO_BUILD_PROFILE}" -f "wasm-bindgen-cli
|
|
32
|
+
cargo install --config net.git-fetch-with-cli=true --profile "${CARGO_BUILD_PROFILE}" -f "wasm-bindgen-cli@0.2.86"
|
|
36
33
|
fi
|
|
37
34
|
|
|
38
35
|
# On a mac, bundled clang won't work - you need to install LLVM manually through brew,
|
|
@@ -327,6 +327,18 @@ impl DataContractWasm {
|
|
|
327
327
|
Ok(object)
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
+
#[wasm_bindgen(js_name=getConfig)]
|
|
331
|
+
pub fn config(&self) -> Result<JsValue, JsValue> {
|
|
332
|
+
Ok(serde_wasm_bindgen::to_value(&self.inner.config)?)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
#[wasm_bindgen(js_name=setConfig)]
|
|
336
|
+
pub fn set_config(&mut self, config: JsValue) -> Result<(), JsValue> {
|
|
337
|
+
let res = serde_wasm_bindgen::from_value(config);
|
|
338
|
+
self.inner.config = res.unwrap();
|
|
339
|
+
Ok(())
|
|
340
|
+
}
|
|
341
|
+
|
|
330
342
|
#[wasm_bindgen(js_name=toJSON)]
|
|
331
343
|
pub fn to_json(&self) -> Result<JsValue, JsValue> {
|
|
332
344
|
let json = self.inner.to_json().with_js_error()?;
|
|
@@ -8,7 +8,7 @@ pub use validation::*;
|
|
|
8
8
|
|
|
9
9
|
use dpp::consensus::signature::SignatureError;
|
|
10
10
|
use dpp::consensus::ConsensusError;
|
|
11
|
-
use dpp::serialization_traits::PlatformSerializable;
|
|
11
|
+
use dpp::serialization_traits::{PlatformDeserializable, PlatformSerializable};
|
|
12
12
|
use dpp::state_transition::StateTransition;
|
|
13
13
|
use dpp::{
|
|
14
14
|
data_contract::state_transition::data_contract_create_transition::DataContractCreateTransition,
|
|
@@ -77,6 +77,13 @@ impl DataContractCreateTransitionWasm {
|
|
|
77
77
|
self.0.data_contract.clone().into()
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
#[wasm_bindgen(js_name=setDataContractConfig)]
|
|
81
|
+
pub fn set_data_contract_config(&mut self, config: JsValue) -> Result<(), JsValue> {
|
|
82
|
+
let res = serde_wasm_bindgen::from_value(config);
|
|
83
|
+
self.0.data_contract.config = res.unwrap();
|
|
84
|
+
Ok(())
|
|
85
|
+
}
|
|
86
|
+
|
|
80
87
|
#[wasm_bindgen(js_name=getProtocolVersion)]
|
|
81
88
|
pub fn get_protocol_version(&self) -> u32 {
|
|
82
89
|
self.0.protocol_version
|
|
@@ -116,6 +123,16 @@ impl DataContractCreateTransitionWasm {
|
|
|
116
123
|
Ok(Buffer::from_bytes(&bytes))
|
|
117
124
|
}
|
|
118
125
|
|
|
126
|
+
#[wasm_bindgen(js_name=fromBuffer)]
|
|
127
|
+
pub fn from_buffer(buffer: Vec<u8>) -> Result<DataContractCreateTransitionWasm, JsValue> {
|
|
128
|
+
let state_transition: StateTransition =
|
|
129
|
+
PlatformDeserializable::deserialize(&buffer).with_js_error()?;
|
|
130
|
+
match state_transition {
|
|
131
|
+
StateTransition::DataContractCreate(dct) => Ok(dct.into()),
|
|
132
|
+
_ => Err(JsValue::from_str("Invalid state transition type")),
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
119
136
|
#[wasm_bindgen(js_name=getModifiedDataIds)]
|
|
120
137
|
pub fn get_modified_data_ids(&self) -> Vec<JsValue> {
|
|
121
138
|
self.0
|
|
@@ -7,7 +7,7 @@ pub use apply::*;
|
|
|
7
7
|
pub use validation::*;
|
|
8
8
|
|
|
9
9
|
use dpp::consensus::ConsensusError;
|
|
10
|
-
use dpp::serialization_traits::PlatformSerializable;
|
|
10
|
+
use dpp::serialization_traits::{PlatformDeserializable, PlatformSerializable};
|
|
11
11
|
use dpp::state_transition::StateTransition;
|
|
12
12
|
use dpp::{
|
|
13
13
|
consensus::signature::SignatureError,
|
|
@@ -79,6 +79,13 @@ impl DataContractUpdateTransitionWasm {
|
|
|
79
79
|
self.0.data_contract.clone().into()
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
#[wasm_bindgen(js_name=setDataContractConfig)]
|
|
83
|
+
pub fn set_data_contract_config(&mut self, config: JsValue) -> Result<(), JsValue> {
|
|
84
|
+
let res = serde_wasm_bindgen::from_value(config);
|
|
85
|
+
self.0.data_contract.config = res.unwrap();
|
|
86
|
+
Ok(())
|
|
87
|
+
}
|
|
88
|
+
|
|
82
89
|
#[wasm_bindgen(js_name=getProtocolVersion)]
|
|
83
90
|
pub fn get_protocol_version(&self) -> u32 {
|
|
84
91
|
self.0.protocol_version
|
|
@@ -113,6 +120,16 @@ impl DataContractUpdateTransitionWasm {
|
|
|
113
120
|
Ok(Buffer::from_bytes(&bytes))
|
|
114
121
|
}
|
|
115
122
|
|
|
123
|
+
#[wasm_bindgen(js_name=fromBuffer)]
|
|
124
|
+
pub fn from_buffer(buffer: Vec<u8>) -> Result<DataContractUpdateTransitionWasm, JsValue> {
|
|
125
|
+
let state_transition: StateTransition =
|
|
126
|
+
PlatformDeserializable::deserialize(&buffer).with_js_error()?;
|
|
127
|
+
match state_transition {
|
|
128
|
+
StateTransition::DataContractUpdate(dct) => Ok(dct.into()),
|
|
129
|
+
_ => Err(JsValue::from_str("Invalid state transition type")),
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
116
133
|
#[wasm_bindgen(js_name=getModifiedDataIds)]
|
|
117
134
|
pub fn get_modified_data_ids(&self) -> Vec<JsValue> {
|
|
118
135
|
self.0
|
|
@@ -14,7 +14,7 @@ use dpp::{
|
|
|
14
14
|
use wasm_bindgen::prelude::*;
|
|
15
15
|
|
|
16
16
|
use crate::entropy_generator::ExternalEntropyGenerator;
|
|
17
|
-
use crate::utils::WithJsError;
|
|
17
|
+
use crate::utils::{ToSerdeJSONExt, WithJsError};
|
|
18
18
|
|
|
19
19
|
use crate::{
|
|
20
20
|
data_contract::errors::InvalidDataContractError,
|
|
@@ -106,15 +106,24 @@ impl DataContractFactoryWasm {
|
|
|
106
106
|
&self,
|
|
107
107
|
owner_id: Vec<u8>,
|
|
108
108
|
documents: JsValue,
|
|
109
|
+
config: JsValue,
|
|
109
110
|
) -> Result<DataContractWasm, JsValue> {
|
|
110
111
|
let documents_object: platform_value::Value =
|
|
111
112
|
with_js_error!(serde_wasm_bindgen::from_value(documents))?;
|
|
113
|
+
|
|
114
|
+
let contract_config = if config.is_object() && !config.is_falsy() {
|
|
115
|
+
let raw_config = config.with_serde_to_json_value()?;
|
|
116
|
+
Some(serde_json::from_value(raw_config).with_js_error()?)
|
|
117
|
+
} else {
|
|
118
|
+
None
|
|
119
|
+
};
|
|
120
|
+
|
|
112
121
|
let identifier = Identifier::from_bytes(&owner_id)
|
|
113
122
|
.map_err(ProtocolError::ValueError)
|
|
114
123
|
.with_js_error()?;
|
|
115
124
|
//todo: contract config
|
|
116
125
|
self.0
|
|
117
|
-
.create(identifier, documents_object,
|
|
126
|
+
.create(identifier, documents_object, contract_config, None)
|
|
118
127
|
.map(Into::into)
|
|
119
128
|
.with_js_error()
|
|
120
129
|
}
|
|
@@ -74,7 +74,10 @@ use crate::errors::consensus::signature::{
|
|
|
74
74
|
use crate::errors::consensus::state::data_contract::data_trigger::{
|
|
75
75
|
DataTriggerConditionErrorWasm, DataTriggerExecutionErrorWasm,
|
|
76
76
|
};
|
|
77
|
-
use crate::errors::consensus::state::data_contract::
|
|
77
|
+
use crate::errors::consensus::state::data_contract::{
|
|
78
|
+
DataContractAlreadyPresentErrorWasm, DataContractConfigUpdateErrorWasm,
|
|
79
|
+
DataContractIsReadonlyErrorWasm,
|
|
80
|
+
};
|
|
78
81
|
use crate::errors::consensus::state::document::{
|
|
79
82
|
DocumentAlreadyPresentErrorWasm, DocumentNotFoundErrorWasm, DocumentOwnerIdMismatchErrorWasm,
|
|
80
83
|
DocumentTimestampWindowViolationErrorWasm, DocumentTimestampsMismatchErrorWasm,
|
|
@@ -202,6 +205,12 @@ pub fn from_state_error(state_error: &StateError) -> JsValue {
|
|
|
202
205
|
StateError::DocumentTimestampsAreEqualError(e) => {
|
|
203
206
|
DocumentTimestampsAreEqualErrorWasm::from(e).into()
|
|
204
207
|
}
|
|
208
|
+
StateError::DataContractIsReadonlyError(e) => {
|
|
209
|
+
DataContractIsReadonlyErrorWasm::from(e).into()
|
|
210
|
+
}
|
|
211
|
+
StateError::DataContractConfigUpdateError(e) => {
|
|
212
|
+
DataContractConfigUpdateErrorWasm::from(e).into()
|
|
213
|
+
}
|
|
205
214
|
}
|
|
206
215
|
}
|
|
207
216
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
use crate::buffer::Buffer;
|
|
2
|
+
use crate::identifier::IdentifierWrapper;
|
|
3
|
+
use dpp::consensus::codes::ErrorWithCode;
|
|
4
|
+
use dpp::consensus::state::data_contract::data_contract_config_update_error::DataContractConfigUpdateError;
|
|
5
|
+
use dpp::consensus::ConsensusError;
|
|
6
|
+
|
|
7
|
+
use dpp::serialization_traits::PlatformSerializable;
|
|
8
|
+
use wasm_bindgen::prelude::*;
|
|
9
|
+
|
|
10
|
+
#[wasm_bindgen(js_name=DataContractConfigUpdateError)]
|
|
11
|
+
pub struct DataContractConfigUpdateErrorWasm {
|
|
12
|
+
inner: DataContractConfigUpdateError,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
impl From<&DataContractConfigUpdateError> for DataContractConfigUpdateErrorWasm {
|
|
16
|
+
fn from(e: &DataContractConfigUpdateError) -> Self {
|
|
17
|
+
Self { inner: e.clone() }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#[wasm_bindgen(js_class=DataContractConfigUpdateError)]
|
|
22
|
+
impl DataContractConfigUpdateErrorWasm {
|
|
23
|
+
#[wasm_bindgen(constructor)]
|
|
24
|
+
pub fn new(data_contract_id: IdentifierWrapper, message: String) -> Self {
|
|
25
|
+
Self {
|
|
26
|
+
inner: DataContractConfigUpdateError::new(data_contract_id.into(), message),
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#[wasm_bindgen(js_name=getDataContractId)]
|
|
31
|
+
pub fn data_contract_id(&self) -> IdentifierWrapper {
|
|
32
|
+
self.inner.data_contract_id().to_owned().into()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[wasm_bindgen(js_name=getCode)]
|
|
36
|
+
pub fn get_code(&self) -> u32 {
|
|
37
|
+
ConsensusError::from(self.inner.clone()).code()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#[wasm_bindgen(getter)]
|
|
41
|
+
pub fn message(&self) -> String {
|
|
42
|
+
self.inner.to_string()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#[wasm_bindgen(js_name=serialize)]
|
|
46
|
+
pub fn serialize(&self) -> Result<Buffer, JsError> {
|
|
47
|
+
let bytes = ConsensusError::from(self.inner.clone())
|
|
48
|
+
.serialize()
|
|
49
|
+
.map_err(JsError::from)?;
|
|
50
|
+
|
|
51
|
+
Ok(Buffer::from_bytes(bytes.as_slice()))
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
use crate::buffer::Buffer;
|
|
2
|
+
use crate::identifier::IdentifierWrapper;
|
|
3
|
+
use dpp::consensus::codes::ErrorWithCode;
|
|
4
|
+
use dpp::consensus::state::data_contract::data_contract_is_readonly_error::DataContractIsReadonlyError;
|
|
5
|
+
use dpp::consensus::ConsensusError;
|
|
6
|
+
|
|
7
|
+
use dpp::serialization_traits::PlatformSerializable;
|
|
8
|
+
use wasm_bindgen::prelude::*;
|
|
9
|
+
|
|
10
|
+
#[wasm_bindgen(js_name=DataContractIsReadonlyError)]
|
|
11
|
+
pub struct DataContractIsReadonlyErrorWasm {
|
|
12
|
+
inner: DataContractIsReadonlyError,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
impl From<&DataContractIsReadonlyError> for DataContractIsReadonlyErrorWasm {
|
|
16
|
+
fn from(e: &DataContractIsReadonlyError) -> Self {
|
|
17
|
+
Self { inner: e.clone() }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#[wasm_bindgen(js_class=DataContractIsReadonlyError)]
|
|
22
|
+
impl DataContractIsReadonlyErrorWasm {
|
|
23
|
+
#[wasm_bindgen(constructor)]
|
|
24
|
+
pub fn new(data_contract_id: IdentifierWrapper) -> Self {
|
|
25
|
+
Self {
|
|
26
|
+
inner: DataContractIsReadonlyError::new(data_contract_id.into()),
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#[wasm_bindgen(js_name=getDataContractId)]
|
|
31
|
+
pub fn data_contract_id(&self) -> IdentifierWrapper {
|
|
32
|
+
self.inner.data_contract_id().to_owned().into()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[wasm_bindgen(js_name=getCode)]
|
|
36
|
+
pub fn get_code(&self) -> u32 {
|
|
37
|
+
ConsensusError::from(self.inner.clone()).code()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#[wasm_bindgen(getter)]
|
|
41
|
+
pub fn message(&self) -> String {
|
|
42
|
+
self.inner.to_string()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#[wasm_bindgen(js_name=serialize)]
|
|
46
|
+
pub fn serialize(&self) -> Result<Buffer, JsError> {
|
|
47
|
+
let bytes = ConsensusError::from(self.inner.clone())
|
|
48
|
+
.serialize()
|
|
49
|
+
.map_err(JsError::from)?;
|
|
50
|
+
|
|
51
|
+
Ok(Buffer::from_bytes(bytes.as_slice()))
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
mod data_contract_already_present_error;
|
|
2
|
+
mod data_contract_config_update_error;
|
|
3
|
+
mod data_contract_is_readonly_error;
|
|
2
4
|
pub mod data_trigger;
|
|
3
5
|
|
|
4
6
|
pub use data_contract_already_present_error::*;
|
|
7
|
+
pub use data_contract_config_update_error::*;
|
|
8
|
+
pub use data_contract_is_readonly_error::*;
|
|
@@ -36,7 +36,7 @@ impl DocumentTimestampsAreEqualErrorWasm {
|
|
|
36
36
|
pub fn serialize(&self) -> Result<Buffer, JsError> {
|
|
37
37
|
let bytes = ConsensusError::from(self.inner.clone())
|
|
38
38
|
.serialize()
|
|
39
|
-
.map_err(
|
|
39
|
+
.map_err(JsError::from)?;
|
|
40
40
|
|
|
41
41
|
Ok(Buffer::from_bytes(bytes.as_slice()))
|
|
42
42
|
}
|
|
@@ -17,8 +17,9 @@ use crate::utils::{ToSerdeJSONExt, WithJsError};
|
|
|
17
17
|
use crate::validation::ValidationResultWasm;
|
|
18
18
|
use crate::{
|
|
19
19
|
create_asset_lock_proof_from_wasm_instance, with_js_error, ChainAssetLockProofWasm,
|
|
20
|
-
IdentityCreateTransitionWasm,
|
|
21
|
-
|
|
20
|
+
IdentityCreateTransitionWasm, IdentityCreditTransferTransitionWasm,
|
|
21
|
+
IdentityTopUpTransitionWasm, IdentityUpdateTransitionWasm, IdentityWasm,
|
|
22
|
+
InstantAssetLockProofWasm,
|
|
22
23
|
};
|
|
23
24
|
use dpp::dashcore::{consensus, InstantLock, Transaction};
|
|
24
25
|
|
|
@@ -191,6 +192,23 @@ impl IdentityFacadeWasm {
|
|
|
191
192
|
.with_js_error()
|
|
192
193
|
}
|
|
193
194
|
|
|
195
|
+
#[wasm_bindgen(js_name=createIdentityCreditTransferTransition)]
|
|
196
|
+
pub fn create_identity_credit_transfer_transition(
|
|
197
|
+
&self,
|
|
198
|
+
identity_id: &IdentifierWrapper,
|
|
199
|
+
recipient_id: &IdentifierWrapper,
|
|
200
|
+
amount: u64,
|
|
201
|
+
) -> Result<IdentityCreditTransferTransitionWasm, JsValue> {
|
|
202
|
+
self.0
|
|
203
|
+
.create_identity_credit_transfer_transition(
|
|
204
|
+
identity_id.to_owned().into(),
|
|
205
|
+
recipient_id.to_owned().into(),
|
|
206
|
+
amount,
|
|
207
|
+
)
|
|
208
|
+
.map(Into::into)
|
|
209
|
+
.with_js_error()
|
|
210
|
+
}
|
|
211
|
+
|
|
194
212
|
#[wasm_bindgen(js_name=createIdentityUpdateTransition)]
|
|
195
213
|
pub fn create_identity_update_transition(
|
|
196
214
|
&self,
|
|
@@ -7,8 +7,9 @@ use crate::identity::validation::IdentityValidatorWasm;
|
|
|
7
7
|
|
|
8
8
|
use crate::{
|
|
9
9
|
create_asset_lock_proof_from_wasm_instance, with_js_error, ChainAssetLockProofWasm,
|
|
10
|
-
IdentityCreateTransitionWasm,
|
|
11
|
-
|
|
10
|
+
IdentityCreateTransitionWasm, IdentityCreditTransferTransitionWasm,
|
|
11
|
+
IdentityTopUpTransitionWasm, IdentityUpdateTransitionWasm, IdentityWasm,
|
|
12
|
+
InstantAssetLockProofWasm,
|
|
12
13
|
};
|
|
13
14
|
use dpp::dashcore::{consensus, InstantLock, Transaction};
|
|
14
15
|
use dpp::identity::factory::IdentityFactory;
|
|
@@ -177,6 +178,23 @@ impl IdentityFactoryWasm {
|
|
|
177
178
|
.with_js_error()
|
|
178
179
|
}
|
|
179
180
|
|
|
181
|
+
#[wasm_bindgen(js_name=createIdentityCreditTransferTransition)]
|
|
182
|
+
pub fn create_identity_credit_transfer_transition(
|
|
183
|
+
&self,
|
|
184
|
+
identity_id: &IdentifierWrapper,
|
|
185
|
+
recipient_id: &IdentifierWrapper,
|
|
186
|
+
amount: u64,
|
|
187
|
+
) -> Result<IdentityCreditTransferTransitionWasm, JsValue> {
|
|
188
|
+
self.0
|
|
189
|
+
.create_identity_credit_transfer_transition(
|
|
190
|
+
identity_id.to_owned().into(),
|
|
191
|
+
recipient_id.to_owned().into(),
|
|
192
|
+
amount,
|
|
193
|
+
)
|
|
194
|
+
.map(Into::into)
|
|
195
|
+
.with_js_error()
|
|
196
|
+
}
|
|
197
|
+
|
|
180
198
|
#[wasm_bindgen(js_name=createIdentityUpdateTransition)]
|
|
181
199
|
pub fn create_identity_update_transition(
|
|
182
200
|
&self,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
use dpp::identity::state_transition::identity_credit_transfer_transition::apply_identity_credit_transfer::ApplyIdentityCreditTransferTransition;
|
|
2
|
+
use std::sync::Arc;
|
|
3
|
+
use wasm_bindgen::prelude::*;
|
|
4
|
+
|
|
5
|
+
use crate::identity::state_transition::identity_credit_transfer_transition::transition::IdentityCreditTransferTransitionWasm;
|
|
6
|
+
use crate::{
|
|
7
|
+
state_repository::{ExternalStateRepositoryLike, ExternalStateRepositoryLikeWrapper},
|
|
8
|
+
StateTransitionExecutionContextWasm,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
#[wasm_bindgen(js_name=applyIdentityCreditTransferTransition)]
|
|
12
|
+
pub async fn apply_identity_credit_transfer_transition_wasm(
|
|
13
|
+
state_repository: ExternalStateRepositoryLike,
|
|
14
|
+
state_transition: &IdentityCreditTransferTransitionWasm,
|
|
15
|
+
execution_context: &StateTransitionExecutionContextWasm,
|
|
16
|
+
) -> Result<(), JsValue> {
|
|
17
|
+
let wrapped_state_repository =
|
|
18
|
+
Arc::new(ExternalStateRepositoryLikeWrapper::new(state_repository));
|
|
19
|
+
|
|
20
|
+
let instance = ApplyIdentityCreditTransferTransition::new(wrapped_state_repository);
|
|
21
|
+
|
|
22
|
+
instance
|
|
23
|
+
.apply(
|
|
24
|
+
&state_transition.to_owned().into(),
|
|
25
|
+
&execution_context.to_owned().into(),
|
|
26
|
+
)
|
|
27
|
+
.await
|
|
28
|
+
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
29
|
+
|
|
30
|
+
Ok(())
|
|
31
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
use dpp::identity::state_transition::identity_credit_transfer_transition::validation::basic::identity_credit_transfer_basic::IdentityCreditTransferTransitionBasicValidator;
|
|
2
|
+
|
|
3
|
+
use dpp::version::{ProtocolVersionValidator, COMPATIBILITY_MAP, LATEST_VERSION};
|
|
4
|
+
use dpp::ProtocolError;
|
|
5
|
+
|
|
6
|
+
use wasm_bindgen::prelude::*;
|
|
7
|
+
|
|
8
|
+
use crate::errors::from_dpp_err;
|
|
9
|
+
use crate::utils::ToSerdeJSONExt;
|
|
10
|
+
use crate::validation::ValidationResultWasm;
|
|
11
|
+
|
|
12
|
+
#[wasm_bindgen(js_name=IdentityCreditTransferTransitionBasicValidator)]
|
|
13
|
+
pub struct IdentityCreditTransferTransitionBasicValidatorWasm(
|
|
14
|
+
IdentityCreditTransferTransitionBasicValidator,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
impl From<IdentityCreditTransferTransitionBasicValidator>
|
|
18
|
+
for IdentityCreditTransferTransitionBasicValidatorWasm
|
|
19
|
+
{
|
|
20
|
+
fn from(validator: IdentityCreditTransferTransitionBasicValidator) -> Self {
|
|
21
|
+
Self(validator)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#[wasm_bindgen(js_class=IdentityCreditTransferTransitionBasicValidator)]
|
|
26
|
+
impl IdentityCreditTransferTransitionBasicValidatorWasm {
|
|
27
|
+
#[wasm_bindgen(constructor)]
|
|
28
|
+
pub fn new() -> Result<IdentityCreditTransferTransitionBasicValidatorWasm, JsValue> {
|
|
29
|
+
let protocol_version_validator = ProtocolVersionValidator::new(
|
|
30
|
+
LATEST_VERSION,
|
|
31
|
+
LATEST_VERSION,
|
|
32
|
+
COMPATIBILITY_MAP.clone(),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
let validator =
|
|
36
|
+
IdentityCreditTransferTransitionBasicValidator::new(protocol_version_validator)
|
|
37
|
+
.map_err(|e| from_dpp_err(ProtocolError::Generic(e.to_string())))?;
|
|
38
|
+
|
|
39
|
+
Ok(validator.into())
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#[wasm_bindgen]
|
|
43
|
+
pub async fn validate(
|
|
44
|
+
mut self,
|
|
45
|
+
raw_state_transition: JsValue,
|
|
46
|
+
) -> Result<ValidationResultWasm, JsValue> {
|
|
47
|
+
let current_protocol_version =
|
|
48
|
+
js_sys::Reflect::get(&raw_state_transition, &"protocolVersion".into())
|
|
49
|
+
.map(|v| v.as_f64().unwrap_or(LATEST_VERSION as f64) as u32)
|
|
50
|
+
.unwrap_or(LATEST_VERSION);
|
|
51
|
+
|
|
52
|
+
self.0
|
|
53
|
+
.protocol_version_validator()
|
|
54
|
+
.set_current_protocol_version(current_protocol_version);
|
|
55
|
+
|
|
56
|
+
let state_transition_object = raw_state_transition.with_serde_to_platform_value()?;
|
|
57
|
+
|
|
58
|
+
let validation_result = self
|
|
59
|
+
.0
|
|
60
|
+
.validate(&state_transition_object)
|
|
61
|
+
.await
|
|
62
|
+
.map_err(|e| from_dpp_err(e.into()))?;
|
|
63
|
+
|
|
64
|
+
Ok(validation_result.map(|_| JsValue::undefined()).into())
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
use crate::errors::from_dpp_err;
|
|
2
|
+
use crate::state_repository::{ExternalStateRepositoryLike, ExternalStateRepositoryLikeWrapper};
|
|
3
|
+
use crate::validation::ValidationResultWasm;
|
|
4
|
+
use crate::{IdentityCreditTransferTransitionWasm, StateTransitionExecutionContextWasm};
|
|
5
|
+
use dpp::identity::state_transition::identity_credit_transfer_transition::validation::state::IdentityCreditTransferTransitionStateValidator;
|
|
6
|
+
use dpp::identity::state_transition::identity_credit_transfer_transition::IdentityCreditTransferTransition;
|
|
7
|
+
use wasm_bindgen::prelude::*;
|
|
8
|
+
use wasm_bindgen::JsValue;
|
|
9
|
+
|
|
10
|
+
#[wasm_bindgen(js_name=IdentityCreditTransferTransitionStateValidator)]
|
|
11
|
+
pub struct IdentityCreditTransferTransitionStateValidatorWasm(
|
|
12
|
+
IdentityCreditTransferTransitionStateValidator<ExternalStateRepositoryLikeWrapper>,
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
#[wasm_bindgen(js_class=IdentityCreditTransferTransitionStateValidator)]
|
|
16
|
+
impl IdentityCreditTransferTransitionStateValidatorWasm {
|
|
17
|
+
#[wasm_bindgen(constructor)]
|
|
18
|
+
pub fn new(
|
|
19
|
+
state_repository: ExternalStateRepositoryLike,
|
|
20
|
+
) -> Result<IdentityCreditTransferTransitionStateValidatorWasm, JsValue> {
|
|
21
|
+
let state_repository = ExternalStateRepositoryLikeWrapper::new(state_repository);
|
|
22
|
+
|
|
23
|
+
let validator = IdentityCreditTransferTransitionStateValidator::new(state_repository);
|
|
24
|
+
|
|
25
|
+
Ok(Self(validator))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
#[wasm_bindgen]
|
|
29
|
+
pub async fn validate(
|
|
30
|
+
&self,
|
|
31
|
+
state_transition: &IdentityCreditTransferTransitionWasm,
|
|
32
|
+
execution_context: &StateTransitionExecutionContextWasm,
|
|
33
|
+
) -> Result<ValidationResultWasm, JsValue> {
|
|
34
|
+
let state_transition: IdentityCreditTransferTransition = state_transition.to_owned().into();
|
|
35
|
+
|
|
36
|
+
let validation_result = self
|
|
37
|
+
.0
|
|
38
|
+
.validate(&state_transition, &execution_context.to_owned().into())
|
|
39
|
+
.await
|
|
40
|
+
.map_err(from_dpp_err)?;
|
|
41
|
+
|
|
42
|
+
Ok(validation_result.map(|_| JsValue::undefined()).into())
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
use dpp::identity::KeyID;
|
|
2
|
+
use dpp::state_transition::StateTransitionIdentitySigned;
|
|
3
|
+
use dpp::{
|
|
4
|
+
identifier::Identifier,
|
|
5
|
+
identity::state_transition::identity_credit_transfer_transition::IdentityCreditTransferTransition,
|
|
6
|
+
state_transition::StateTransitionLike,
|
|
7
|
+
};
|
|
8
|
+
use serde::Deserialize;
|
|
9
|
+
use std::default::Default;
|
|
10
|
+
|
|
11
|
+
#[derive(Deserialize, Default)]
|
|
12
|
+
#[serde(rename_all = "camelCase")]
|
|
13
|
+
pub struct ToObjectOptions {
|
|
14
|
+
pub skip_signature: Option<bool>,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#[derive(Default)]
|
|
18
|
+
pub struct ToObject {
|
|
19
|
+
pub transition_type: u8,
|
|
20
|
+
pub protocol_version: u32,
|
|
21
|
+
pub identity_id: Identifier,
|
|
22
|
+
pub recipient_id: Identifier,
|
|
23
|
+
pub amount: u64,
|
|
24
|
+
pub signature: Option<Vec<u8>>,
|
|
25
|
+
pub signature_public_key_id: Option<KeyID>,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
pub fn to_object_struct(
|
|
29
|
+
transition: &IdentityCreditTransferTransition,
|
|
30
|
+
options: ToObjectOptions,
|
|
31
|
+
) -> ToObject {
|
|
32
|
+
let mut to_object = ToObject {
|
|
33
|
+
transition_type: transition.get_type() as u8,
|
|
34
|
+
protocol_version: transition.get_protocol_version(),
|
|
35
|
+
identity_id: *transition.get_identity_id(),
|
|
36
|
+
recipient_id: *transition.get_recipient_id(),
|
|
37
|
+
amount: transition.get_amount(),
|
|
38
|
+
..ToObject::default()
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
if !options.skip_signature.unwrap_or(false) {
|
|
42
|
+
let signature = Some(transition.get_signature().to_vec());
|
|
43
|
+
if let Some(signature) = &signature {
|
|
44
|
+
if !signature.is_empty() {
|
|
45
|
+
to_object.signature_public_key_id = transition.get_signature_public_key_id()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
to_object.signature = signature;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
to_object
|
|
52
|
+
}
|