@dashevo/wasm-dpp 2.0.0-rc.13 → 2.0.0-rc.15

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.
Files changed (22) hide show
  1. package/Cargo.toml +1 -1
  2. package/dist/wasm/wasm_dpp.d.ts +1017 -935
  3. package/dist/wasm/wasm_dpp.js +133 -69
  4. package/dist/wasm/wasm_dpp_bg.js +1 -1
  5. package/lib/wasm/wasm_dpp.d.ts +1017 -935
  6. package/package.json +2 -2
  7. package/src/data_contract/data_contract.rs +2 -3
  8. package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +18 -3
  9. package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +18 -3
  10. package/src/document/state_transition/batch_transition/token_transition/burn.rs +14 -0
  11. package/src/document/state_transition/batch_transition/token_transition/claim.rs +18 -0
  12. package/src/document/state_transition/batch_transition/token_transition/config.rs +9 -0
  13. package/src/document/state_transition/batch_transition/token_transition/destroy.rs +5 -0
  14. package/src/document/state_transition/batch_transition/token_transition/direct_purchase.rs +16 -0
  15. package/src/document/state_transition/batch_transition/token_transition/emergency_action.rs +18 -0
  16. package/src/document/state_transition/batch_transition/token_transition/freeze.rs +5 -0
  17. package/src/document/state_transition/batch_transition/token_transition/mint.rs +15 -0
  18. package/src/document/state_transition/batch_transition/token_transition/set_price_for_direct_purchase.rs +22 -0
  19. package/src/document/state_transition/batch_transition/token_transition/transfer.rs +10 -0
  20. package/src/document/state_transition/batch_transition/token_transition/unfreeze.rs +5 -0
  21. package/src/errors/consensus/consensus_error.rs +15 -2
  22. package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +6 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/wasm-dpp",
3
- "version": "2.0.0-rc.13",
3
+ "version": "2.0.0-rc.15",
4
4
  "description": "The JavaScript implementation of the Dash Platform Protocol",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -44,7 +44,7 @@
44
44
  "@babel/core": "^7.26.10",
45
45
  "@babel/preset-env": "^7.26.9",
46
46
  "@dashevo/dashcore-lib": "~0.22.0",
47
- "@dashevo/dpns-contract": "2.0.0-rc.13",
47
+ "@dashevo/dpns-contract": "2.0.0-rc.15",
48
48
  "@types/bs58": "^4.0.1",
49
49
  "@types/node": "^14.6.0",
50
50
  "@yarnpkg/pnpify": "^4.0.0-rc.42",
@@ -415,12 +415,11 @@ impl DataContractWasm {
415
415
  self.clone()
416
416
  }
417
417
 
418
- pub(crate) fn try_from_serialization_format(
418
+ pub(crate) fn try_from_serialization_format_with_platform_version(
419
419
  value: DataContractInSerializationFormat,
420
420
  full_validation: bool,
421
+ platform_version: &PlatformVersion,
421
422
  ) -> Result<Self, JsValue> {
422
- let platform_version = PlatformVersion::first();
423
-
424
423
  DataContract::try_from_platform_versioned(
425
424
  value,
426
425
  full_validation,
@@ -55,9 +55,24 @@ impl DataContractCreateTransitionWasm {
55
55
  }
56
56
 
57
57
  #[wasm_bindgen(js_name=getDataContract)]
58
- pub fn get_data_contract(&self) -> DataContractWasm {
59
- DataContractWasm::try_from_serialization_format(self.0.data_contract().clone(), false)
60
- .expect("should convert from serialziation format")
58
+ pub fn get_data_contract(
59
+ &self,
60
+ protocol_version: Option<u32>,
61
+ ) -> Result<DataContractWasm, JsValue> {
62
+ // Use provided protocol version or latest if not specified
63
+ let platform_version = if let Some(version) = protocol_version {
64
+ PlatformVersion::get(version)
65
+ .map_err(ProtocolError::PlatformVersionError)
66
+ .with_js_error()?
67
+ } else {
68
+ PlatformVersion::latest()
69
+ };
70
+
71
+ DataContractWasm::try_from_serialization_format_with_platform_version(
72
+ self.0.data_contract().clone(),
73
+ false,
74
+ platform_version,
75
+ )
61
76
  }
62
77
 
63
78
  // #[wasm_bindgen(js_name=setDataContractConfig)]
@@ -56,9 +56,24 @@ impl DataContractUpdateTransitionWasm {
56
56
  }
57
57
 
58
58
  #[wasm_bindgen(js_name=getDataContract)]
59
- pub fn get_data_contract(&self) -> DataContractWasm {
60
- DataContractWasm::try_from_serialization_format(self.0.data_contract().clone(), false)
61
- .expect("should create data contract from serialized format")
59
+ pub fn get_data_contract(
60
+ &self,
61
+ protocol_version: Option<u32>,
62
+ ) -> Result<DataContractWasm, JsValue> {
63
+ // Use provided protocol version or latest if not specified
64
+ let platform_version = if let Some(version) = protocol_version {
65
+ PlatformVersion::get(version)
66
+ .map_err(ProtocolError::PlatformVersionError)
67
+ .with_js_error()?
68
+ } else {
69
+ PlatformVersion::latest()
70
+ };
71
+
72
+ DataContractWasm::try_from_serialization_format_with_platform_version(
73
+ self.0.data_contract().clone(),
74
+ false,
75
+ platform_version,
76
+ )
62
77
  }
63
78
 
64
79
  // #[wasm_bindgen(js_name=setDataContractConfig)]
@@ -1,3 +1,4 @@
1
+ use dpp::state_transition::batch_transition::token_burn_transition::v0::v0_methods::TokenBurnTransitionV0Methods;
1
2
  use dpp::state_transition::batch_transition::TokenBurnTransition;
2
3
  use wasm_bindgen::prelude::wasm_bindgen;
3
4
 
@@ -10,3 +11,16 @@ impl From<TokenBurnTransition> for TokenBurnTransitionWasm {
10
11
  Self(value)
11
12
  }
12
13
  }
14
+
15
+ #[wasm_bindgen(js_class = TokenBurnTransition)]
16
+ impl TokenBurnTransitionWasm {
17
+ #[wasm_bindgen(js_name=getPublicNote)]
18
+ pub fn public_note(&self) -> Option<String> {
19
+ self.0.public_note().cloned()
20
+ }
21
+
22
+ #[wasm_bindgen(js_name=getBurnAmount)]
23
+ pub fn amount(&self) -> u64 {
24
+ self.0.burn_amount()
25
+ }
26
+ }
@@ -1,3 +1,5 @@
1
+ use dpp::data_contract::associated_token::token_distribution_key::TokenDistributionType;
2
+ use dpp::state_transition::batch_transition::token_claim_transition::v0::v0_methods::TokenClaimTransitionV0Methods;
1
3
  use dpp::state_transition::batch_transition::TokenClaimTransition;
2
4
  use wasm_bindgen::prelude::wasm_bindgen;
3
5
 
@@ -10,3 +12,19 @@ impl From<TokenClaimTransition> for TokenClaimTransitionWasm {
10
12
  Self(value)
11
13
  }
12
14
  }
15
+
16
+ #[wasm_bindgen(js_class = TokenClaimTransition)]
17
+ impl TokenClaimTransitionWasm {
18
+ #[wasm_bindgen(js_name=getPublicNote)]
19
+ pub fn public_note(&self) -> Option<String> {
20
+ self.0.public_note().cloned()
21
+ }
22
+
23
+ #[wasm_bindgen(js_name=getDistributionType)]
24
+ pub fn distribution_type(&self) -> u8 {
25
+ match self.0.distribution_type() {
26
+ TokenDistributionType::PreProgrammed => 0,
27
+ TokenDistributionType::Perpetual => 1,
28
+ }
29
+ }
30
+ }
@@ -1,3 +1,4 @@
1
+ use dpp::state_transition::batch_transition::token_config_update_transition::v0::v0_methods::TokenConfigUpdateTransitionV0Methods;
1
2
  use dpp::state_transition::batch_transition::TokenConfigUpdateTransition;
2
3
  use wasm_bindgen::prelude::wasm_bindgen;
3
4
 
@@ -10,3 +11,11 @@ impl From<TokenConfigUpdateTransition> for TokenConfigUpdateTransitionWasm {
10
11
  Self(value)
11
12
  }
12
13
  }
14
+
15
+ #[wasm_bindgen(js_class = TokenConfigUpdateTransition)]
16
+ impl TokenConfigUpdateTransitionWasm {
17
+ #[wasm_bindgen(js_name=getPublicNote)]
18
+ pub fn public_note(&self) -> Option<String> {
19
+ self.0.public_note().cloned()
20
+ }
21
+ }
@@ -19,4 +19,9 @@ impl TokenDestroyFrozenFundsTransitionWasm {
19
19
  pub fn frozen_identity_id(&self) -> IdentifierWrapper {
20
20
  self.0.frozen_identity_id().into()
21
21
  }
22
+
23
+ #[wasm_bindgen(js_name=getPublicNote)]
24
+ pub fn public_note(&self) -> Option<String> {
25
+ self.0.public_note().cloned()
26
+ }
22
27
  }
@@ -1,3 +1,6 @@
1
+ use dpp::balances::credits::TokenAmount;
2
+ use dpp::fee::Credits;
3
+ use dpp::state_transition::batch_transition::token_direct_purchase_transition::v0::v0_methods::TokenDirectPurchaseTransitionV0Methods;
1
4
  use dpp::state_transition::batch_transition::TokenDirectPurchaseTransition;
2
5
  use wasm_bindgen::prelude::wasm_bindgen;
3
6
 
@@ -10,3 +13,16 @@ impl From<TokenDirectPurchaseTransition> for TokenDirectPurchaseTransitionWasm {
10
13
  Self(value)
11
14
  }
12
15
  }
16
+
17
+ #[wasm_bindgen(js_class = TokenDirectPurchaseTransition)]
18
+ impl TokenDirectPurchaseTransitionWasm {
19
+ #[wasm_bindgen(js_name=getTokenCount)]
20
+ pub fn count(&self) -> TokenAmount {
21
+ self.0.token_count()
22
+ }
23
+
24
+ #[wasm_bindgen(js_name=getTotalAgreedPrice)]
25
+ pub fn total_agreed_price(&self) -> Credits {
26
+ self.0.total_agreed_price()
27
+ }
28
+ }
@@ -1,4 +1,6 @@
1
+ use dpp::state_transition::batch_transition::token_emergency_action_transition::v0::v0_methods::TokenEmergencyActionTransitionV0Methods;
1
2
  use dpp::state_transition::batch_transition::TokenEmergencyActionTransition;
3
+ use dpp::tokens::emergency_action::TokenEmergencyAction;
2
4
  use wasm_bindgen::prelude::wasm_bindgen;
3
5
 
4
6
  #[wasm_bindgen(js_name=TokenEmergencyActionTransition)]
@@ -10,3 +12,19 @@ impl From<TokenEmergencyActionTransition> for TokenEmergencyActionTransitionWasm
10
12
  Self(value)
11
13
  }
12
14
  }
15
+
16
+ #[wasm_bindgen(js_class = TokenEmergencyActionTransition)]
17
+ impl TokenEmergencyActionTransitionWasm {
18
+ #[wasm_bindgen(js_name=getPublicNote)]
19
+ pub fn public_note(&self) -> Option<String> {
20
+ self.0.public_note().cloned()
21
+ }
22
+
23
+ #[wasm_bindgen(js_name=getEmergencyAction)]
24
+ pub fn emergency_action(&self) -> u8 {
25
+ match self.0.emergency_action() {
26
+ TokenEmergencyAction::Pause => 0,
27
+ TokenEmergencyAction::Resume => 1,
28
+ }
29
+ }
30
+ }
@@ -19,4 +19,9 @@ impl TokenFreezeTransitionWasm {
19
19
  pub fn frozen_identity_id(&self) -> IdentifierWrapper {
20
20
  self.0.frozen_identity_id().into()
21
21
  }
22
+
23
+ #[wasm_bindgen(js_name=getPublicNote)]
24
+ pub fn public_note(&self) -> Option<String> {
25
+ self.0.public_note().cloned()
26
+ }
22
27
  }
@@ -28,4 +28,19 @@ impl TokenMintTransitionWasm {
28
28
  .with_js_error()
29
29
  .map(Into::into)
30
30
  }
31
+
32
+ #[wasm_bindgen(js_name=getIssuedToIdentityId)]
33
+ pub fn issued_to_identity_id(&self) -> Option<IdentifierWrapper> {
34
+ self.0.issued_to_identity_id().map(|id| id.into())
35
+ }
36
+
37
+ #[wasm_bindgen(js_name=getPublicNote)]
38
+ pub fn public_note(&self) -> Option<String> {
39
+ self.0.public_note().cloned()
40
+ }
41
+
42
+ #[wasm_bindgen(js_name=getAmount)]
43
+ pub fn amount(&self) -> u64 {
44
+ self.0.amount()
45
+ }
31
46
  }
@@ -1,5 +1,8 @@
1
1
  use dpp::state_transition::batch_transition::TokenSetPriceForDirectPurchaseTransition;
2
2
  use wasm_bindgen::prelude::wasm_bindgen;
3
+ use dpp::fee::Credits;
4
+ use dpp::state_transition::batch_transition::token_set_price_for_direct_purchase_transition::v0::v0_methods::TokenSetPriceForDirectPurchaseTransitionV0Methods;
5
+ use dpp::tokens::token_pricing_schedule::TokenPricingSchedule;
3
6
 
4
7
  #[wasm_bindgen(js_name=TokenSetPriceForDirectPurchaseTransition)]
5
8
  #[derive(Debug, Clone)]
@@ -12,3 +15,22 @@ impl From<TokenSetPriceForDirectPurchaseTransition>
12
15
  Self(value)
13
16
  }
14
17
  }
18
+
19
+ #[wasm_bindgen(js_class=TokenSetPriceForDirectPurchaseTransition)]
20
+ impl TokenSetPriceForDirectPurchaseTransitionWasm {
21
+ #[wasm_bindgen(js_name=getPublicNote)]
22
+ pub fn public_note(&self) -> Option<String> {
23
+ self.0.public_note().cloned()
24
+ }
25
+
26
+ #[wasm_bindgen(js_name=getPrice)]
27
+ pub fn price(&self) -> Option<Credits> {
28
+ match self.0.price() {
29
+ Some(token_pricing_schedule) => match token_pricing_schedule {
30
+ TokenPricingSchedule::SinglePrice(credits) => Some(*credits),
31
+ TokenPricingSchedule::SetPrices(_) => None,
32
+ },
33
+ None => None,
34
+ }
35
+ }
36
+ }
@@ -19,4 +19,14 @@ impl TokenTransferTransitionWasm {
19
19
  pub fn recipient_id(&self) -> IdentifierWrapper {
20
20
  self.0.recipient_id().into()
21
21
  }
22
+
23
+ #[wasm_bindgen(js_name=getPublicNote)]
24
+ pub fn public_note(&self) -> Option<String> {
25
+ self.0.public_note().cloned()
26
+ }
27
+
28
+ #[wasm_bindgen(js_name=getAmount)]
29
+ pub fn amount(&self) -> u64 {
30
+ self.0.amount()
31
+ }
22
32
  }
@@ -19,4 +19,9 @@ impl TokenUnfreezeTransitionWasm {
19
19
  pub fn frozen_identity_id(&self) -> IdentifierWrapper {
20
20
  self.0.frozen_identity_id().into()
21
21
  }
22
+
23
+ #[wasm_bindgen(js_name=getPublicNote)]
24
+ pub fn public_note(&self) -> Option<String> {
25
+ self.0.public_note().cloned()
26
+ }
22
27
  }
@@ -61,12 +61,12 @@ use dpp::consensus::state::data_trigger::DataTriggerError::{
61
61
  DataTriggerConditionError, DataTriggerExecutionError, DataTriggerInvalidResultError,
62
62
  };
63
63
  use wasm_bindgen::{JsError, JsValue};
64
- use dpp::consensus::basic::data_contract::{ContestedUniqueIndexOnMutableDocumentTypeError, ContestedUniqueIndexWithUniqueIndexError, DataContractTokenConfigurationUpdateError, DecimalsOverLimitError, DuplicateKeywordsError, GroupExceedsMaxMembersError, GroupMemberHasPowerOfZeroError, GroupMemberHasPowerOverLimitError, GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError, GroupPositionDoesNotExistError, GroupRequiredPowerIsInvalidError, GroupTotalPowerLessThanRequiredError, InvalidDescriptionLengthError, InvalidDocumentTypeRequiredSecurityLevelError, InvalidKeywordCharacterError, InvalidKeywordLengthError, InvalidTokenBaseSupplyError, InvalidTokenDistributionFunctionDivideByZeroError, InvalidTokenDistributionFunctionIncoherenceError, InvalidTokenDistributionFunctionInvalidParameterError, InvalidTokenDistributionFunctionInvalidParameterTupleError, InvalidTokenLanguageCodeError, InvalidTokenNameCharacterError, InvalidTokenNameLengthError, MainGroupIsNotDefinedError, NewTokensDestinationIdentityOptionRequiredError, NonContiguousContractGroupPositionsError, NonContiguousContractTokenPositionsError, RedundantDocumentPaidForByTokenWithContractId, TokenPaymentByBurningOnlyAllowedOnInternalTokenError, TooManyKeywordsError, UnknownDocumentActionTokenEffectError, UnknownDocumentCreationRestrictionModeError, UnknownGasFeesPaidByError, UnknownSecurityLevelError, UnknownStorageKeyRequirementsError, UnknownTradeModeError, UnknownTransferableTypeError};
64
+ use dpp::consensus::basic::data_contract::{ContestedUniqueIndexOnMutableDocumentTypeError, ContestedUniqueIndexWithUniqueIndexError, DataContractTokenConfigurationUpdateError, DecimalsOverLimitError, DuplicateKeywordsError, GroupExceedsMaxMembersError, GroupHasTooFewMembersError, GroupMemberHasPowerOfZeroError, GroupMemberHasPowerOverLimitError, GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError, GroupPositionDoesNotExistError, GroupRequiredPowerIsInvalidError, GroupTotalPowerLessThanRequiredError, InvalidDescriptionLengthError, InvalidDocumentTypeRequiredSecurityLevelError, InvalidKeywordCharacterError, InvalidKeywordLengthError, InvalidTokenBaseSupplyError, InvalidTokenDistributionFunctionDivideByZeroError, InvalidTokenDistributionFunctionIncoherenceError, InvalidTokenDistributionFunctionInvalidParameterError, InvalidTokenDistributionFunctionInvalidParameterTupleError, InvalidTokenLanguageCodeError, InvalidTokenNameCharacterError, InvalidTokenNameLengthError, MainGroupIsNotDefinedError, NewTokensDestinationIdentityOptionRequiredError, NonContiguousContractGroupPositionsError, NonContiguousContractTokenPositionsError, RedundantDocumentPaidForByTokenWithContractId, TokenPaymentByBurningOnlyAllowedOnInternalTokenError, TooManyKeywordsError, UnknownDocumentActionTokenEffectError, UnknownDocumentCreationRestrictionModeError, UnknownGasFeesPaidByError, UnknownSecurityLevelError, UnknownStorageKeyRequirementsError, UnknownTradeModeError, UnknownTransferableTypeError};
65
65
  use dpp::consensus::basic::document::{ContestedDocumentsTemporarilyNotAllowedError, DocumentCreationNotAllowedError, DocumentFieldMaxSizeExceededError, MaxDocumentsTransitionsExceededError, MissingPositionsInDocumentTypePropertiesError};
66
66
  use dpp::consensus::basic::group::GroupActionNotAllowedOnTransitionError;
67
67
  use dpp::consensus::basic::identity::{DataContractBoundsNotPresentError, DisablingKeyIdAlsoBeingAddedInSameTransitionError, InvalidIdentityCreditWithdrawalTransitionAmountError, InvalidIdentityUpdateTransitionDisableKeysError, InvalidIdentityUpdateTransitionEmptyError, TooManyMasterPublicKeyError, WithdrawalOutputScriptNotAllowedWhenSigningWithOwnerKeyError};
68
68
  use dpp::consensus::basic::overflow_error::OverflowError;
69
- use dpp::consensus::basic::token::{ChoosingTokenMintRecipientNotAllowedError, ContractHasNoTokensError, DestinationIdentityForTokenMintingNotSetError, InvalidActionIdError, InvalidTokenAmountError, InvalidTokenConfigUpdateNoChangeError, InvalidTokenIdError, InvalidTokenNoteTooBigError, InvalidTokenPositionError, MissingDefaultLocalizationError, TokenNoteOnlyAllowedWhenProposerError, TokenTransferToOurselfError};
69
+ use dpp::consensus::basic::token::{ChoosingTokenMintRecipientNotAllowedError, ContractHasNoTokensError, DestinationIdentityForTokenMintingNotSetError, InvalidActionIdError, InvalidTokenAmountError, InvalidTokenConfigUpdateNoChangeError, InvalidTokenIdError, InvalidTokenNoteTooBigError, InvalidTokenPositionError, MissingDefaultLocalizationError, TokenNoteOnlyAllowedWhenProposerError, TokenTransferToOurselfError, InvalidTokenDistributionTimeIntervalNotMinuteAlignedError, InvalidTokenDistributionTimeIntervalTooShortError, InvalidTokenDistributionBlockIntervalTooShortError};
70
70
  use dpp::consensus::state::data_contract::data_contract_not_found_error::DataContractNotFoundError;
71
71
  use dpp::consensus::state::data_contract::data_contract_update_action_not_allowed_error::DataContractUpdateActionNotAllowedError;
72
72
  use dpp::consensus::state::data_contract::document_type_update_error::DocumentTypeUpdateError;
@@ -831,9 +831,22 @@ fn from_basic_error(basic_error: &BasicError) -> JsValue {
831
831
  BasicError::TokenNoteOnlyAllowedWhenProposerError(e) => {
832
832
  generic_consensus_error!(TokenNoteOnlyAllowedWhenProposerError, e).into()
833
833
  }
834
+ BasicError::InvalidTokenDistributionBlockIntervalTooShortError(e) => {
835
+ generic_consensus_error!(InvalidTokenDistributionBlockIntervalTooShortError, e).into()
836
+ }
837
+ BasicError::InvalidTokenDistributionTimeIntervalTooShortError(e) => {
838
+ generic_consensus_error!(InvalidTokenDistributionTimeIntervalTooShortError, e).into()
839
+ }
840
+ BasicError::InvalidTokenDistributionTimeIntervalNotMinuteAlignedError(e) => {
841
+ generic_consensus_error!(InvalidTokenDistributionTimeIntervalNotMinuteAlignedError, e)
842
+ .into()
843
+ }
834
844
  BasicError::RedundantDocumentPaidForByTokenWithContractId(e) => {
835
845
  generic_consensus_error!(RedundantDocumentPaidForByTokenWithContractId, e).into()
836
846
  }
847
+ BasicError::GroupHasTooFewMembersError(e) => {
848
+ generic_consensus_error!(GroupHasTooFewMembersError, e).into()
849
+ }
837
850
  }
838
851
  }
839
852
 
@@ -46,6 +46,12 @@ describe('DataContractCreateTransition', () => {
46
46
 
47
47
  expect(result.toObject()).to.deep.equal(dataContract.toObject());
48
48
  });
49
+
50
+ it('should return Data Contract with specific protocol version', () => {
51
+ const result = stateTransition.getDataContract(1);
52
+
53
+ expect(result.toObject()).to.deep.equal(dataContract.toObject());
54
+ });
49
55
  });
50
56
 
51
57
  describe.skip('#toJSON', () => {