From 76983928e7b61961283ae2ad3a74b9d4936d260b Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Sat, 4 Oct 2025 19:10:07 +0700 Subject: [PATCH 01/44] feat: add wasm-dpp2 --- .pnp.cjs | 210 ++++++ Cargo.lock | 340 +++++++-- Cargo.toml | 1 + package.json | 1 + packages/scripts/build-wasm.sh | 13 +- packages/wasm-dpp2/.gitignore | 2 + packages/wasm-dpp2/.mocharc.yml | 4 + packages/wasm-dpp2/Cargo.toml | 32 + packages/wasm-dpp2/README.md | 13 + packages/wasm-dpp2/package.json | 69 ++ packages/wasm-dpp2/scripts/build-optimized.sh | 28 + packages/wasm-dpp2/scripts/build.sh | 18 + packages/wasm-dpp2/scripts/bundle.cjs | 129 ++++ .../src/asset_lock_proof/chain/mod.rs | 98 +++ .../asset_lock_proof/instant/instant_lock.rs | 121 +++ .../src/asset_lock_proof/instant/mod.rs | 146 ++++ .../wasm-dpp2/src/asset_lock_proof/mod.rs | 175 +++++ .../src/asset_lock_proof/outpoint/mod.rs | 119 +++ .../src/asset_lock_proof/tx_out/mod.rs | 90 +++ .../src/batch/batched_transition/mod.rs | 110 +++ .../src/batch/document_base_transition/mod.rs | 129 ++++ .../src/batch/document_transition/mod.rs | 189 +++++ .../batch/document_transitions/create/mod.rs | 162 ++++ .../batch/document_transitions/delete/mod.rs | 90 +++ .../src/batch/document_transitions/mod.rs | 6 + .../document_transitions/purchase/mod.rs | 116 +++ .../batch/document_transitions/replace/mod.rs | 116 +++ .../document_transitions/transfer/mod.rs | 109 +++ .../document_transitions/update_price/mod.rs | 100 +++ packages/wasm-dpp2/src/batch/generators.rs | 137 ++++ packages/wasm-dpp2/src/batch/mod.rs | 259 +++++++ .../src/batch/prefunded_voting_balance/mod.rs | 55 ++ .../src/batch/token_base_transition/mod.rs | 140 ++++ .../src/batch/token_payment_info/mod.rs | 149 ++++ .../src/batch/token_pricing_schedule/mod.rs | 83 +++ .../src/batch/token_transition/mod.rs | 276 +++++++ .../batch/token_transitions/config_update.rs | 83 +++ .../token_transitions/direct_purchase.rs | 82 ++ .../src/batch/token_transitions/mod.rs | 11 + .../set_price_for_direct_purchase.rs | 113 +++ .../src/batch/token_transitions/token_burn.rs | 81 ++ .../batch/token_transitions/token_claim.rs | 92 +++ .../token_destroy_frozen_funds.rs | 91 +++ .../token_emergency_action.rs | 81 ++ .../batch/token_transitions/token_freeze.rs | 91 +++ .../src/batch/token_transitions/token_mint.rs | 126 ++++ .../batch/token_transitions/token_transfer.rs | 185 +++++ .../batch/token_transitions/token_unfreeze.rs | 91 +++ packages/wasm-dpp2/src/consensus_error/mod.rs | 23 + packages/wasm-dpp2/src/contract_bounds/mod.rs | 130 ++++ packages/wasm-dpp2/src/core_script/mod.rs | 105 +++ packages/wasm-dpp2/src/data_contract/mod.rs | 502 +++++++++++++ .../data_contract_transitions/create/mod.rs | 208 ++++++ .../src/data_contract_transitions/mod.rs | 2 + .../data_contract_transitions/update/mod.rs | 191 +++++ .../wasm-dpp2/src/document/methods/mod.rs | 455 +++++++++++ packages/wasm-dpp2/src/document/mod.rs | 102 +++ packages/wasm-dpp2/src/encrypted_note/mod.rs | 2 + .../private_encrypted_note/mod.rs | 75 ++ .../shared_encrypted_note/mod.rs | 71 ++ .../wasm-dpp2/src/enums/batch/batch_enum.rs | 84 +++ .../src/enums/batch/gas_fees_paid_by.rs | 74 ++ packages/wasm-dpp2/src/enums/batch/mod.rs | 2 + packages/wasm-dpp2/src/enums/contested/mod.rs | 1 + .../enums/contested/vote_state_result_type.rs | 49 ++ packages/wasm-dpp2/src/enums/keys/key_type.rs | 94 +++ packages/wasm-dpp2/src/enums/keys/mod.rs | 3 + packages/wasm-dpp2/src/enums/keys/purpose.rs | 96 +++ .../src/enums/keys/security_level.rs | 78 ++ .../wasm-dpp2/src/enums/lock_types/mod.rs | 65 ++ packages/wasm-dpp2/src/enums/mod.rs | 8 + packages/wasm-dpp2/src/enums/network/mod.rs | 67 ++ packages/wasm-dpp2/src/enums/platform/mod.rs | 104 +++ .../wasm-dpp2/src/enums/token/action_goal.rs | 64 ++ .../src/enums/token/distribution_type.rs | 64 ++ .../src/enums/token/emergency_action.rs | 64 ++ packages/wasm-dpp2/src/enums/token/mod.rs | 3 + .../wasm-dpp2/src/enums/withdrawal/mod.rs | 72 ++ .../src/group_state_transition_info/mod.rs | 77 ++ packages/wasm-dpp2/src/identifier/mod.rs | 167 +++++ packages/wasm-dpp2/src/identity/mod.rs | 152 ++++ .../wasm-dpp2/src/identity_public_key/mod.rs | 293 ++++++++ .../create_transition/mod.rs | 188 +++++ .../credit_withdrawal_transition/mod.rs | 275 +++++++ .../mod.rs | 198 +++++ .../wasm-dpp2/src/identity_transitions/mod.rs | 6 + .../public_key_in_creation/mod.rs | 253 +++++++ .../top_up_transition/mod.rs | 181 +++++ .../update_transition/mod.rs | 255 +++++++ packages/wasm-dpp2/src/lib.rs | 35 + packages/wasm-dpp2/src/masternode_vote/mod.rs | 227 ++++++ .../resource_vote_choice/mod.rs | 70 ++ .../wasm-dpp2/src/masternode_vote/vote/mod.rs | 78 ++ .../src/masternode_vote/vote_poll/mod.rs | 172 +++++ packages/wasm-dpp2/src/mock_bls/mod.rs | 26 + .../wasm-dpp2/src/partial_identity/mod.rs | 184 +++++ packages/wasm-dpp2/src/private_key/mod.rs | 90 +++ packages/wasm-dpp2/src/public_key/mod.rs | 123 +++ .../wasm-dpp2/src/state_transition/mod.rs | 605 +++++++++++++++ .../src/token_configuration/action_taker.rs | 91 +++ .../authorized_action_takers.rs | 90 +++ .../change_control_rules.rs | 200 +++++ .../configuration_convention.rs | 127 ++++ .../distribution_function.rs | 374 ++++++++++ .../distribution_recipient.rs | 77 ++ .../token_configuration/distribution_rules.rs | 238 ++++++ .../distribution_structs.rs | 111 +++ .../src/token_configuration/group.rs | 130 ++++ .../keeps_history_rules.rs | 116 +++ .../src/token_configuration/localization.rs | 105 +++ .../token_configuration/marketplace_rules.rs | 74 ++ .../wasm-dpp2/src/token_configuration/mod.rs | 332 +++++++++ .../perpetual_distribution.rs | 70 ++ .../pre_programmed_distribution.rs | 122 +++ .../reward_distribution_type.rs | 182 +++++ .../src/token_configuration/trade_mode.rs | 43 ++ .../items/conventions.rs | 29 + .../items/destroy_frozen_funds.rs | 23 + .../items/emergency_action.rs | 25 + .../items/freeze.rs | 25 + .../items/main_control_group.rs | 14 + .../items/manual_burning.rs | 21 + .../items/manual_minting.rs | 21 + .../items/marketplace_trade_mode.rs | 33 + .../items/max_supply.rs | 27 + .../minting_allow_choosing_destination.rs | 36 + .../items/mod.rs | 14 + .../items/new_tokens_destination_identity.rs | 46 ++ .../items/no_change.rs | 11 + .../items/perpetual_distribution.rs | 52 ++ .../items/unfreeze.rs | 21 + .../token_configuration_change_item/mod.rs | 231 ++++++ packages/wasm-dpp2/src/utils/mod.rs | 248 ++++++ packages/wasm-dpp2/tests/.eslintrc.yml | 40 + packages/wasm-dpp2/tests/bootstrap.cjs | 10 + packages/wasm-dpp2/tests/karma/karma.conf.cjs | 15 + packages/wasm-dpp2/tests/karma/options.cjs | 66 ++ .../tests/unit/AssetLockProof.spec.mjs | 101 +++ .../unit/AuthorizedActionTakers.spec.mjs | 79 ++ .../tests/unit/BatchTransition.spec.mjs | 147 ++++ .../tests/unit/ChainLockProof.spec.mjs | 67 ++ .../tests/unit/ChangeControlRules.spec.mjs | 188 +++++ .../wasm-dpp2/tests/unit/CoreScript.spec.mjs | 41 + .../tests/unit/DataContract.spec.mjs | 175 +++++ ...DataContractCreateStateTransition.spec.mjs | 108 +++ ...DataContractUpdateStateTransition.spec.mjs | 108 +++ .../tests/unit/DistributionFunction.spec.mjs | 420 +++++++++++ .../wasm-dpp2/tests/unit/Document.spec.mjs | 233 ++++++ .../tests/unit/DocumentTransition.spec.mjs | 100 +++ .../tests/unit/DocumentsTransitions.spec.mjs | 705 ++++++++++++++++++ .../wasm-dpp2/tests/unit/Identifier.spec.mjs | 86 +++ .../wasm-dpp2/tests/unit/Identity.spec.mjs | 118 +++ .../unit/IdentityCreateTransition.spec.mjs | 90 +++ .../IdentityCreditTransferTransition.spec.mjs | 144 ++++ ...dentityCreditWithdrawalTransition.spec.mjs | 190 +++++ .../tests/unit/IdentityPublicKey.spec.mjs | 135 ++++ .../unit/IdentityTopUpTransition.spec.mjs | 129 ++++ .../unit/IdentityUpdateTransition.spec.mjs | 139 ++++ .../tests/unit/InstantLockProof.spec.mjs | 95 +++ .../wasm-dpp2/tests/unit/OutPoint.spec.mjs | 53 ++ .../wasm-dpp2/tests/unit/PrivateKey.spec.mjs | 71 ++ .../tests/unit/PublicKeyInCreation.spec.mjs | 256 +++++++ .../unit/RewardDistributionType.spec.mjs | 94 +++ .../tests/unit/TokenBaseTransition.spec.mjs | 100 +++ .../tests/unit/TokenConfiguration.spec.mjs | 194 +++++ .../TokenConfigurationConvention.spec.mjs | 103 +++ .../TokenConfigurationLocalization.spec.mjs | 63 ++ .../unit/TokenDistributionRecipient.spec.mjs | 53 ++ .../unit/TokenDistributionRules.spec.mjs | 317 ++++++++ .../unit/TokenKeepsHistoryRules.spec.mjs | 71 ++ .../unit/TokenPerpetualDistribution.spec.mjs | 134 ++++ .../TokenPreProgrammedDistribution.spec.mjs | 65 ++ .../tests/unit/TokensTransitions.spec.mjs | 513 +++++++++++++ packages/wasm-dpp2/tests/unit/TxOut.spec.mjs | 74 ++ packages/wasm-dpp2/tests/unit/helpers/wasm.js | 30 + .../unit/mocks/DataContract/DataContract.json | 153 ++++ .../tests/unit/mocks/DataContract/index.js | 6 + .../tests/unit/mocks/DataContract/value.js | 155 ++++ .../unit/mocks/Document/DataContract.json | 23 + .../tests/unit/mocks/Document/dataContract.js | 25 + .../tests/unit/mocks/Document/document.js | 5 + .../tests/unit/mocks/Document/document.json | 3 + .../tests/unit/mocks/Document/document2.js | 5 + .../tests/unit/mocks/Document/document2.json | 3 + .../tests/unit/mocks/Document/index.js | 12 + .../tests/unit/mocks/Identity/index.js | 13 + .../wasm-dpp2/tests/unit/mocks/Locks/index.js | 2 + .../tests/unit/mocks/PrivateKey/index.js | 5 + .../tests/unit/mocks/PublicKey/index.js | 11 + .../unit/mocks/TokenConfiguration/index.js | 5 + .../wasm-dpp2/tests/unit/module-load.spec.mjs | 19 + packages/wasm-dpp2/tests/unit/utils/hex.js | 10 + yarn.lock | 32 + 193 files changed, 21170 insertions(+), 71 deletions(-) create mode 100644 packages/wasm-dpp2/.gitignore create mode 100644 packages/wasm-dpp2/.mocharc.yml create mode 100644 packages/wasm-dpp2/Cargo.toml create mode 100644 packages/wasm-dpp2/README.md create mode 100644 packages/wasm-dpp2/package.json create mode 100755 packages/wasm-dpp2/scripts/build-optimized.sh create mode 100755 packages/wasm-dpp2/scripts/build.sh create mode 100755 packages/wasm-dpp2/scripts/bundle.cjs create mode 100644 packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs create mode 100644 packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs create mode 100644 packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs create mode 100644 packages/wasm-dpp2/src/asset_lock_proof/mod.rs create mode 100644 packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs create mode 100644 packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/batched_transition/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/document_base_transition/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/document_transition/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/document_transitions/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/generators.rs create mode 100644 packages/wasm-dpp2/src/batch/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/token_base_transition/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/token_payment_info/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transition/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transitions/config_update.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transitions/mod.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs create mode 100644 packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs create mode 100644 packages/wasm-dpp2/src/consensus_error/mod.rs create mode 100644 packages/wasm-dpp2/src/contract_bounds/mod.rs create mode 100644 packages/wasm-dpp2/src/core_script/mod.rs create mode 100644 packages/wasm-dpp2/src/data_contract/mod.rs create mode 100644 packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs create mode 100644 packages/wasm-dpp2/src/data_contract_transitions/mod.rs create mode 100644 packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs create mode 100644 packages/wasm-dpp2/src/document/methods/mod.rs create mode 100644 packages/wasm-dpp2/src/document/mod.rs create mode 100644 packages/wasm-dpp2/src/encrypted_note/mod.rs create mode 100644 packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs create mode 100644 packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs create mode 100644 packages/wasm-dpp2/src/enums/batch/batch_enum.rs create mode 100644 packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs create mode 100644 packages/wasm-dpp2/src/enums/batch/mod.rs create mode 100644 packages/wasm-dpp2/src/enums/contested/mod.rs create mode 100644 packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs create mode 100644 packages/wasm-dpp2/src/enums/keys/key_type.rs create mode 100644 packages/wasm-dpp2/src/enums/keys/mod.rs create mode 100644 packages/wasm-dpp2/src/enums/keys/purpose.rs create mode 100644 packages/wasm-dpp2/src/enums/keys/security_level.rs create mode 100644 packages/wasm-dpp2/src/enums/lock_types/mod.rs create mode 100644 packages/wasm-dpp2/src/enums/mod.rs create mode 100644 packages/wasm-dpp2/src/enums/network/mod.rs create mode 100644 packages/wasm-dpp2/src/enums/platform/mod.rs create mode 100644 packages/wasm-dpp2/src/enums/token/action_goal.rs create mode 100644 packages/wasm-dpp2/src/enums/token/distribution_type.rs create mode 100644 packages/wasm-dpp2/src/enums/token/emergency_action.rs create mode 100644 packages/wasm-dpp2/src/enums/token/mod.rs create mode 100644 packages/wasm-dpp2/src/enums/withdrawal/mod.rs create mode 100644 packages/wasm-dpp2/src/group_state_transition_info/mod.rs create mode 100644 packages/wasm-dpp2/src/identifier/mod.rs create mode 100644 packages/wasm-dpp2/src/identity/mod.rs create mode 100644 packages/wasm-dpp2/src/identity_public_key/mod.rs create mode 100644 packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs create mode 100644 packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs create mode 100644 packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs create mode 100644 packages/wasm-dpp2/src/identity_transitions/mod.rs create mode 100644 packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs create mode 100644 packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs create mode 100644 packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs create mode 100644 packages/wasm-dpp2/src/lib.rs create mode 100644 packages/wasm-dpp2/src/masternode_vote/mod.rs create mode 100644 packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs create mode 100644 packages/wasm-dpp2/src/masternode_vote/vote/mod.rs create mode 100644 packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs create mode 100644 packages/wasm-dpp2/src/mock_bls/mod.rs create mode 100644 packages/wasm-dpp2/src/partial_identity/mod.rs create mode 100644 packages/wasm-dpp2/src/private_key/mod.rs create mode 100644 packages/wasm-dpp2/src/public_key/mod.rs create mode 100644 packages/wasm-dpp2/src/state_transition/mod.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/action_taker.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/change_control_rules.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/configuration_convention.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/distribution_function.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/distribution_rules.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/distribution_structs.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/group.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/localization.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/mod.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs create mode 100644 packages/wasm-dpp2/src/token_configuration/trade_mode.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/mod.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs create mode 100644 packages/wasm-dpp2/src/token_configuration_change_item/mod.rs create mode 100644 packages/wasm-dpp2/src/utils/mod.rs create mode 100644 packages/wasm-dpp2/tests/.eslintrc.yml create mode 100644 packages/wasm-dpp2/tests/bootstrap.cjs create mode 100644 packages/wasm-dpp2/tests/karma/karma.conf.cjs create mode 100644 packages/wasm-dpp2/tests/karma/options.cjs create mode 100644 packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/ChainLockProof.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/ChangeControlRules.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/DataContract.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/DistributionFunction.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/Document.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/Identifier.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/Identity.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/IdentityPublicKey.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/InstantLockProof.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/PublicKeyInCreation.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/RewardDistributionType.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/TokenConfiguration.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/TokenConfigurationConvention.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/TokenKeepsHistoryRules.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/TokenPerpetualDistribution.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/TokenPreProgrammedDistribution.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/TxOut.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/helpers/wasm.js create mode 100644 packages/wasm-dpp2/tests/unit/mocks/DataContract/DataContract.json create mode 100644 packages/wasm-dpp2/tests/unit/mocks/DataContract/index.js create mode 100644 packages/wasm-dpp2/tests/unit/mocks/DataContract/value.js create mode 100644 packages/wasm-dpp2/tests/unit/mocks/Document/DataContract.json create mode 100644 packages/wasm-dpp2/tests/unit/mocks/Document/dataContract.js create mode 100644 packages/wasm-dpp2/tests/unit/mocks/Document/document.js create mode 100644 packages/wasm-dpp2/tests/unit/mocks/Document/document.json create mode 100644 packages/wasm-dpp2/tests/unit/mocks/Document/document2.js create mode 100644 packages/wasm-dpp2/tests/unit/mocks/Document/document2.json create mode 100644 packages/wasm-dpp2/tests/unit/mocks/Document/index.js create mode 100644 packages/wasm-dpp2/tests/unit/mocks/Identity/index.js create mode 100644 packages/wasm-dpp2/tests/unit/mocks/Locks/index.js create mode 100644 packages/wasm-dpp2/tests/unit/mocks/PrivateKey/index.js create mode 100644 packages/wasm-dpp2/tests/unit/mocks/PublicKey/index.js create mode 100644 packages/wasm-dpp2/tests/unit/mocks/TokenConfiguration/index.js create mode 100644 packages/wasm-dpp2/tests/unit/module-load.spec.mjs create mode 100644 packages/wasm-dpp2/tests/unit/utils/hex.js diff --git a/.pnp.cjs b/.pnp.cjs index e2e7b0d579b..90b9c4f147a 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -89,6 +89,10 @@ const RAW_RUNTIME_STATE = "name": "@dashevo/wasm-dpp",\ "reference": "workspace:packages/wasm-dpp"\ },\ + {\ + "name": "@dashevo/wasm-dpp2",\ + "reference": "workspace:packages/wasm-dpp2"\ + },\ {\ "name": "wasm-drive-verify",\ "reference": "workspace:packages/wasm-drive-verify"\ @@ -123,6 +127,7 @@ const RAW_RUNTIME_STATE = ["@dashevo/wallet-lib", ["workspace:packages/wallet-lib"]],\ ["@dashevo/wallet-utils-contract", ["workspace:packages/wallet-utils-contract"]],\ ["@dashevo/wasm-dpp", ["workspace:packages/wasm-dpp"]],\ + ["@dashevo/wasm-dpp2", ["workspace:packages/wasm-dpp2"]],\ ["@dashevo/wasm-sdk", ["workspace:packages/wasm-sdk"]],\ ["@dashevo/withdrawals-contract", ["workspace:packages/withdrawals-contract"]],\ ["dash", ["workspace:packages/js-dash-sdk"]],\ @@ -3117,6 +3122,40 @@ const RAW_RUNTIME_STATE = "linkType": "SOFT"\ }]\ ]],\ + ["@dashevo/wasm-dpp2", [\ + ["workspace:packages/wasm-dpp2", {\ + "packageLocation": "./packages/wasm-dpp2/",\ + "packageDependencies": [\ + ["@dashevo/wasm-dpp2", "workspace:packages/wasm-dpp2"],\ + ["assert", "npm:2.0.0"],\ + ["buffer", "npm:6.0.3"],\ + ["chai", "npm:4.3.10"],\ + ["chai-as-promised", "virtual:e2d057e7cc143d3cb9bec864f4a2d862441b5a09f81f8e6c46e7a098cbc89e4d07017cc6e2e2142d5704bb55da853cbec2d025ebc0b30e8696c31380c00f2c7d#npm:7.1.1"],\ + ["dirty-chai", "virtual:e2d057e7cc143d3cb9bec864f4a2d862441b5a09f81f8e6c46e7a098cbc89e4d07017cc6e2e2142d5704bb55da853cbec2d025ebc0b30e8696c31380c00f2c7d#npm:2.0.1"],\ + ["eslint", "npm:8.53.0"],\ + ["eslint-config-airbnb-base", "virtual:e2d057e7cc143d3cb9bec864f4a2d862441b5a09f81f8e6c46e7a098cbc89e4d07017cc6e2e2142d5704bb55da853cbec2d025ebc0b30e8696c31380c00f2c7d#npm:15.0.0"],\ + ["eslint-plugin-import", "virtual:e2d057e7cc143d3cb9bec864f4a2d862441b5a09f81f8e6c46e7a098cbc89e4d07017cc6e2e2142d5704bb55da853cbec2d025ebc0b30e8696c31380c00f2c7d#npm:2.29.0"],\ + ["eslint-plugin-jsdoc", "virtual:8f25fc90e0fb5fd89843707863857591fa8c52f9f33eadced4bf404b1871d91959f7bb86948ae0e1b53ee94d491ef8fde9c0b58b39c9490c0d0fa6c931945f97#npm:46.9.0"],\ + ["events", "npm:3.3.0"],\ + ["karma", "npm:6.4.3"],\ + ["karma-chai", "virtual:e2d057e7cc143d3cb9bec864f4a2d862441b5a09f81f8e6c46e7a098cbc89e4d07017cc6e2e2142d5704bb55da853cbec2d025ebc0b30e8696c31380c00f2c7d#npm:0.1.0"],\ + ["karma-chrome-launcher", "npm:3.1.0"],\ + ["karma-firefox-launcher", "npm:2.1.2"],\ + ["karma-mocha", "npm:2.0.1"],\ + ["karma-mocha-reporter", "virtual:e2d057e7cc143d3cb9bec864f4a2d862441b5a09f81f8e6c46e7a098cbc89e4d07017cc6e2e2142d5704bb55da853cbec2d025ebc0b30e8696c31380c00f2c7d#npm:2.2.5"],\ + ["karma-webpack", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:5.0.0"],\ + ["mocha", "npm:11.1.0"],\ + ["path-browserify", "npm:1.0.1"],\ + ["process", "npm:0.11.10"],\ + ["string_decoder", "npm:1.3.0"],\ + ["url", "npm:0.11.3"],\ + ["util", "npm:0.12.4"],\ + ["webpack", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:5.94.0"],\ + ["webpack-cli", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:4.9.1"]\ + ],\ + "linkType": "SOFT"\ + }]\ + ]],\ ["@dashevo/wasm-sdk", [\ ["workspace:packages/wasm-sdk", {\ "packageLocation": "./packages/wasm-sdk/",\ @@ -5463,6 +5502,23 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }],\ + ["virtual:a5a6463a0bb826fa62fe988272ac511c2dd2d7b75a693754f12e5e1d5d09a8882a0c7fc9cc88d37e0f1a3647214b9bc4031426b2ba0ee449276ccbb9901a0ba8#npm:1.1.0", {\ + "packageLocation": "./.yarn/__virtual__/@webpack-cli-configtest-virtual-962a737a82/0/cache/@webpack-cli-configtest-npm-1.1.0-2b6b2ef3d7-69e7816b5b.zip/node_modules/@webpack-cli/configtest/",\ + "packageDependencies": [\ + ["@webpack-cli/configtest", "virtual:a5a6463a0bb826fa62fe988272ac511c2dd2d7b75a693754f12e5e1d5d09a8882a0c7fc9cc88d37e0f1a3647214b9bc4031426b2ba0ee449276ccbb9901a0ba8#npm:1.1.0"],\ + ["@types/webpack", null],\ + ["@types/webpack-cli", null],\ + ["webpack", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:5.94.0"],\ + ["webpack-cli", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:4.9.1"]\ + ],\ + "packagePeers": [\ + "@types/webpack-cli",\ + "@types/webpack",\ + "webpack-cli",\ + "webpack"\ + ],\ + "linkType": "HARD"\ + }],\ ["virtual:b37ef7cf98ceabe8c7b789a7db3f0a5f3444d083afa5f0e3ab570292e74eff241f890fadbf245a134b2ebfcba326b1782124a4dd4f16ca7cdb6091dd9a987c04#npm:1.1.0", {\ "packageLocation": "./.yarn/__virtual__/@webpack-cli-configtest-virtual-34b876bdf7/0/cache/@webpack-cli-configtest-npm-1.1.0-2b6b2ef3d7-69e7816b5b.zip/node_modules/@webpack-cli/configtest/",\ "packageDependencies": [\ @@ -5565,6 +5621,20 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }],\ + ["virtual:a5a6463a0bb826fa62fe988272ac511c2dd2d7b75a693754f12e5e1d5d09a8882a0c7fc9cc88d37e0f1a3647214b9bc4031426b2ba0ee449276ccbb9901a0ba8#npm:1.4.0", {\ + "packageLocation": "./.yarn/__virtual__/@webpack-cli-info-virtual-8096a86511/0/cache/@webpack-cli-info-npm-1.4.0-4a26ccee64-6385b1e2c5.zip/node_modules/@webpack-cli/info/",\ + "packageDependencies": [\ + ["@webpack-cli/info", "virtual:a5a6463a0bb826fa62fe988272ac511c2dd2d7b75a693754f12e5e1d5d09a8882a0c7fc9cc88d37e0f1a3647214b9bc4031426b2ba0ee449276ccbb9901a0ba8#npm:1.4.0"],\ + ["@types/webpack-cli", null],\ + ["envinfo", "npm:7.8.1"],\ + ["webpack-cli", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:4.9.1"]\ + ],\ + "packagePeers": [\ + "@types/webpack-cli",\ + "webpack-cli"\ + ],\ + "linkType": "HARD"\ + }],\ ["virtual:b37ef7cf98ceabe8c7b789a7db3f0a5f3444d083afa5f0e3ab570292e74eff241f890fadbf245a134b2ebfcba326b1782124a4dd4f16ca7cdb6091dd9a987c04#npm:1.4.0", {\ "packageLocation": "./.yarn/__virtual__/@webpack-cli-info-virtual-5b3c564e68/0/cache/@webpack-cli-info-npm-1.4.0-4a26ccee64-6385b1e2c5.zip/node_modules/@webpack-cli/info/",\ "packageDependencies": [\ @@ -5667,6 +5737,23 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }],\ + ["virtual:a5a6463a0bb826fa62fe988272ac511c2dd2d7b75a693754f12e5e1d5d09a8882a0c7fc9cc88d37e0f1a3647214b9bc4031426b2ba0ee449276ccbb9901a0ba8#npm:1.6.0", {\ + "packageLocation": "./.yarn/__virtual__/@webpack-cli-serve-virtual-29c8ff0174/0/cache/@webpack-cli-serve-npm-1.6.0-c7b35aa4ef-3fd2e5f365.zip/node_modules/@webpack-cli/serve/",\ + "packageDependencies": [\ + ["@webpack-cli/serve", "virtual:a5a6463a0bb826fa62fe988272ac511c2dd2d7b75a693754f12e5e1d5d09a8882a0c7fc9cc88d37e0f1a3647214b9bc4031426b2ba0ee449276ccbb9901a0ba8#npm:1.6.0"],\ + ["@types/webpack-cli", null],\ + ["@types/webpack-dev-server", null],\ + ["webpack-cli", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:4.9.1"],\ + ["webpack-dev-server", null]\ + ],\ + "packagePeers": [\ + "@types/webpack-cli",\ + "@types/webpack-dev-server",\ + "webpack-cli",\ + "webpack-dev-server"\ + ],\ + "linkType": "HARD"\ + }],\ ["virtual:b37ef7cf98ceabe8c7b789a7db3f0a5f3444d083afa5f0e3ab570292e74eff241f890fadbf245a134b2ebfcba326b1782124a4dd4f16ca7cdb6091dd9a987c04#npm:1.6.0", {\ "packageLocation": "./.yarn/__virtual__/@webpack-cli-serve-virtual-bcf913d932/0/cache/@webpack-cli-serve-npm-1.6.0-c7b35aa4ef-3fd2e5f365.zip/node_modules/@webpack-cli/serve/",\ "packageDependencies": [\ @@ -13463,6 +13550,22 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }],\ + ["virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:5.0.0", {\ + "packageLocation": "./.yarn/__virtual__/karma-webpack-virtual-91170ce8e7/0/cache/karma-webpack-npm-5.0.0-d7c66b2a8a-9bd565adbc.zip/node_modules/karma-webpack/",\ + "packageDependencies": [\ + ["karma-webpack", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:5.0.0"],\ + ["@types/webpack", null],\ + ["glob", "npm:7.2.3"],\ + ["minimatch", "npm:3.1.2"],\ + ["webpack", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:5.94.0"],\ + ["webpack-merge", "npm:4.2.2"]\ + ],\ + "packagePeers": [\ + "@types/webpack",\ + "webpack"\ + ],\ + "linkType": "HARD"\ + }],\ ["virtual:8f25fc90e0fb5fd89843707863857591fa8c52f9f33eadced4bf404b1871d91959f7bb86948ae0e1b53ee94d491ef8fde9c0b58b39c9490c0d0fa6c931945f97#npm:5.0.0", {\ "packageLocation": "./.yarn/__virtual__/karma-webpack-virtual-bbb0fdb943/0/cache/karma-webpack-npm-5.0.0-d7c66b2a8a-9bd565adbc.zip/node_modules/karma-webpack/",\ "packageDependencies": [\ @@ -18830,6 +18933,36 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }],\ + ["virtual:6cee1e02ee58a73c62cad1f4570ca1ea4024e4b1a63e046914cb0da8168616f048581c24ee878b60d1b5ae4e5eea79e3cce2d7b7f05ffce69b1838a49b21e0b1#npm:5.3.10", {\ + "packageLocation": "./.yarn/__virtual__/terser-webpack-plugin-virtual-d7911a34cb/0/cache/terser-webpack-plugin-npm-5.3.10-3bde1920fb-fb1c2436ae.zip/node_modules/terser-webpack-plugin/",\ + "packageDependencies": [\ + ["terser-webpack-plugin", "virtual:6cee1e02ee58a73c62cad1f4570ca1ea4024e4b1a63e046914cb0da8168616f048581c24ee878b60d1b5ae4e5eea79e3cce2d7b7f05ffce69b1838a49b21e0b1#npm:5.3.10"],\ + ["@jridgewell/trace-mapping", "npm:0.3.25"],\ + ["@swc/core", null],\ + ["@types/esbuild", null],\ + ["@types/swc__core", null],\ + ["@types/uglify-js", null],\ + ["@types/webpack", null],\ + ["esbuild", null],\ + ["jest-worker", "npm:27.5.1"],\ + ["schema-utils", "npm:3.1.1"],\ + ["serialize-javascript", "npm:6.0.2"],\ + ["terser", "npm:5.31.6"],\ + ["uglify-js", null],\ + ["webpack", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:5.94.0"]\ + ],\ + "packagePeers": [\ + "@swc/core",\ + "@types/esbuild",\ + "@types/swc__core",\ + "@types/uglify-js",\ + "@types/webpack",\ + "esbuild",\ + "uglify-js",\ + "webpack"\ + ],\ + "linkType": "HARD"\ + }],\ ["virtual:78d5ff6fde5ea52c420e709e60c10ff99b2616c779333c323baa448d23fb3675eeb1eb1a1f40b6a9a0120ae591e10ee81fb9bed979e75f077ef3680845d7e170#npm:5.3.10", {\ "packageLocation": "./.yarn/__virtual__/terser-webpack-plugin-virtual-bd54e97fee/0/cache/terser-webpack-plugin-npm-5.3.10-3bde1920fb-fb1c2436ae.zip/node_modules/terser-webpack-plugin/",\ "packageDependencies": [\ @@ -20433,6 +20566,42 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }],\ + ["virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:5.94.0", {\ + "packageLocation": "./.yarn/__virtual__/webpack-virtual-6cee1e02ee/0/cache/webpack-npm-5.94.0-d1e43de389-648449c5fb.zip/node_modules/webpack/",\ + "packageDependencies": [\ + ["webpack", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:5.94.0"],\ + ["@types/estree", "npm:1.0.5"],\ + ["@types/webpack-cli", null],\ + ["@webassemblyjs/ast", "npm:1.12.1"],\ + ["@webassemblyjs/wasm-edit", "npm:1.12.1"],\ + ["@webassemblyjs/wasm-parser", "npm:1.12.1"],\ + ["acorn", "npm:8.11.2"],\ + ["acorn-import-attributes", "virtual:9644477017df2e32be56d4a1c7fe5ac5a3e402b2dbf0f12e92d05353a79eef964913f8eba76831dcc035bd99e7745cec85de81787c8c846ec7e2635108519296#npm:1.9.5"],\ + ["browserslist", "npm:4.23.3"],\ + ["chrome-trace-event", "npm:1.0.3"],\ + ["enhanced-resolve", "npm:5.17.1"],\ + ["es-module-lexer", "npm:1.5.4"],\ + ["eslint-scope", "npm:5.1.1"],\ + ["events", "npm:3.3.0"],\ + ["glob-to-regexp", "npm:0.4.1"],\ + ["graceful-fs", "npm:4.2.11"],\ + ["json-parse-even-better-errors", "npm:2.3.1"],\ + ["loader-runner", "npm:4.2.0"],\ + ["mime-types", "npm:2.1.34"],\ + ["neo-async", "npm:2.6.2"],\ + ["schema-utils", "npm:3.3.0"],\ + ["tapable", "npm:2.2.1"],\ + ["terser-webpack-plugin", "virtual:6cee1e02ee58a73c62cad1f4570ca1ea4024e4b1a63e046914cb0da8168616f048581c24ee878b60d1b5ae4e5eea79e3cce2d7b7f05ffce69b1838a49b21e0b1#npm:5.3.10"],\ + ["watchpack", "npm:2.4.2"],\ + ["webpack-cli", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:4.9.1"],\ + ["webpack-sources", "npm:3.2.3"]\ + ],\ + "packagePeers": [\ + "@types/webpack-cli",\ + "webpack-cli"\ + ],\ + "linkType": "HARD"\ + }],\ ["virtual:8f25fc90e0fb5fd89843707863857591fa8c52f9f33eadced4bf404b1871d91959f7bb86948ae0e1b53ee94d491ef8fde9c0b58b39c9490c0d0fa6c931945f97#npm:5.94.0", {\ "packageLocation": "./.yarn/__virtual__/webpack-virtual-905383bbe6/0/cache/webpack-npm-5.94.0-d1e43de389-648449c5fb.zip/node_modules/webpack/",\ "packageDependencies": [\ @@ -20663,6 +20832,47 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "HARD"\ }],\ + ["virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:4.9.1", {\ + "packageLocation": "./.yarn/__virtual__/webpack-cli-virtual-a5a6463a0b/0/cache/webpack-cli-npm-4.9.1-1b8a5f360f-14eb69cec6.zip/node_modules/webpack-cli/",\ + "packageDependencies": [\ + ["webpack-cli", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:4.9.1"],\ + ["@discoveryjs/json-ext", "npm:0.5.5"],\ + ["@types/webpack", null],\ + ["@types/webpack-bundle-analyzer", null],\ + ["@types/webpack-cli__generators", null],\ + ["@types/webpack-cli__migrate", null],\ + ["@types/webpack-dev-server", null],\ + ["@webpack-cli/configtest", "virtual:a5a6463a0bb826fa62fe988272ac511c2dd2d7b75a693754f12e5e1d5d09a8882a0c7fc9cc88d37e0f1a3647214b9bc4031426b2ba0ee449276ccbb9901a0ba8#npm:1.1.0"],\ + ["@webpack-cli/generators", null],\ + ["@webpack-cli/info", "virtual:a5a6463a0bb826fa62fe988272ac511c2dd2d7b75a693754f12e5e1d5d09a8882a0c7fc9cc88d37e0f1a3647214b9bc4031426b2ba0ee449276ccbb9901a0ba8#npm:1.4.0"],\ + ["@webpack-cli/migrate", null],\ + ["@webpack-cli/serve", "virtual:a5a6463a0bb826fa62fe988272ac511c2dd2d7b75a693754f12e5e1d5d09a8882a0c7fc9cc88d37e0f1a3647214b9bc4031426b2ba0ee449276ccbb9901a0ba8#npm:1.6.0"],\ + ["colorette", "npm:2.0.20"],\ + ["commander", "npm:7.2.0"],\ + ["execa", "npm:5.1.1"],\ + ["fastest-levenshtein", "npm:1.0.12"],\ + ["import-local", "npm:3.0.3"],\ + ["interpret", "npm:2.2.0"],\ + ["rechoir", "npm:0.7.1"],\ + ["webpack", "virtual:897449be52adaf897095babe74bfcc926f5d083ac9aac6fbc5e260f1f71b7e3ada3f268ac9457d3009b9c6fca51fe685ec21fbed21ec5087df84ab489b719456#npm:5.94.0"],\ + ["webpack-bundle-analyzer", null],\ + ["webpack-dev-server", null],\ + ["webpack-merge", "npm:5.8.0"]\ + ],\ + "packagePeers": [\ + "@types/webpack-bundle-analyzer",\ + "@types/webpack-cli__generators",\ + "@types/webpack-cli__migrate",\ + "@types/webpack-dev-server",\ + "@types/webpack",\ + "@webpack-cli/generators",\ + "@webpack-cli/migrate",\ + "webpack-bundle-analyzer",\ + "webpack-dev-server",\ + "webpack"\ + ],\ + "linkType": "HARD"\ + }],\ ["virtual:8f25fc90e0fb5fd89843707863857591fa8c52f9f33eadced4bf404b1871d91959f7bb86948ae0e1b53ee94d491ef8fde9c0b58b39c9490c0d0fa6c931945f97#npm:4.9.1", {\ "packageLocation": "./.yarn/__virtual__/webpack-cli-virtual-b37ef7cf98/0/cache/webpack-cli-npm-4.9.1-1b8a5f360f-14eb69cec6.zip/node_modules/webpack-cli/",\ "packageDependencies": [\ diff --git a/Cargo.lock b/Cargo.lock index b55b5c7500c..6d0033e4cf3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -665,6 +665,32 @@ dependencies = [ "zeroize", ] +[[package]] +name = "blsful" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d267776bf4742935d219fcdbdf590bed0f7e5fccdf5bd168fb30b2543a0b2b24" +dependencies = [ + "anyhow", + "blstrs_plus", + "hex", + "hkdf", + "merlin", + "pairing", + "rand 0.8.5", + "rand_chacha 0.3.1", + "rand_core 0.6.4", + "serde", + "serde_bare", + "sha2", + "sha3", + "subtle", + "thiserror 2.0.16", + "uint-zigzag", + "vsss-rs", + "zeroize", +] + [[package]] name = "blst" version = "0.3.12" @@ -1319,7 +1345,7 @@ dependencies = [ "dapi-grpc-macros", "futures-core", "getrandom 0.2.16", - "platform-version", + "platform-version 2.1.0-dev.8", "prost 0.14.1", "serde", "serde_bytes", @@ -1379,7 +1405,7 @@ dependencies = [ name = "dash-context-provider" version = "2.1.0-dev.8" dependencies = [ - "dpp", + "dpp 2.1.0-dev.8", "drive", "hex", "serde", @@ -1406,7 +1432,7 @@ dependencies = [ "clap", "dapi-grpc", "dash-sdk", - "dpp", + "dpp 2.1.0-dev.8", "drive-proof-verifier", "rpassword", "rs-dapi-client", @@ -1432,7 +1458,7 @@ dependencies = [ "dash-context-provider", "derive_more 1.0.0", "dotenvy", - "dpp", + "dpp 2.1.0-dev.8", "drive", "drive-proof-verifier", "envy", @@ -1466,11 +1492,11 @@ dependencies = [ "anyhow", "async-trait", "bincode 1.3.3", - "blsful", + "blsful 3.0.0-pre8", "clap", "crossterm", - "dashcore", - "dashcore_hashes", + "dashcore 0.40.0", + "dashcore_hashes 0.40.0", "hex", "hickory-resolver", "indexmap 2.11.3", @@ -1493,7 +1519,7 @@ source = "git+https://github.com/dashpay/rust-dashcore?rev=befd0356bebfcd0d06d10 dependencies = [ "cbindgen 0.29.0", "dash-spv", - "dashcore", + "dashcore 0.40.0", "env_logger 0.10.2", "hex", "key-wallet", @@ -1509,6 +1535,27 @@ dependencies = [ "tracing", ] +[[package]] +name = "dashcore" +version = "0.39.6" +source = "git+https://github.com/dashpay/rust-dashcore?tag=v0.39.6#51df58f5d5d499f5ee80ab17076ff70b5347c7db" +dependencies = [ + "anyhow", + "base64-compat", + "bech32", + "bitflags 2.9.4", + "blake3", + "blsful 3.0.0", + "dashcore-private 0.39.6", + "dashcore_hashes 0.39.6", + "hex", + "hex_lit", + "rustversion", + "secp256k1", + "serde", + "thiserror 2.0.16", +] + [[package]] name = "dashcore" version = "0.40.0" @@ -1521,10 +1568,10 @@ dependencies = [ "bincode_derive", "bitvec", "blake3", - "blsful", + "blsful 3.0.0-pre8", "dash-network", - "dashcore-private", - "dashcore_hashes", + "dashcore-private 0.40.0", + "dashcore_hashes 0.40.0", "ed25519-dalek", "hex", "hex_lit", @@ -1535,6 +1582,11 @@ dependencies = [ "thiserror 2.0.16", ] +[[package]] +name = "dashcore-private" +version = "0.39.6" +source = "git+https://github.com/dashpay/rust-dashcore?tag=v0.39.6#51df58f5d5d499f5ee80ab17076ff70b5347c7db" + [[package]] name = "dashcore-private" version = "0.40.0" @@ -1559,7 +1611,7 @@ version = "0.40.0" source = "git+https://github.com/dashpay/rust-dashcore?rev=befd0356bebfcd0d06d1028d8a03bfa4c78bd219#befd0356bebfcd0d06d1028d8a03bfa4c78bd219" dependencies = [ "bincode 2.0.0-rc.3", - "dashcore", + "dashcore 0.40.0", "hex", "key-wallet", "serde", @@ -1568,13 +1620,23 @@ dependencies = [ "serde_with 2.3.3", ] +[[package]] +name = "dashcore_hashes" +version = "0.39.6" +source = "git+https://github.com/dashpay/rust-dashcore?tag=v0.39.6#51df58f5d5d499f5ee80ab17076ff70b5347c7db" +dependencies = [ + "dashcore-private 0.39.6", + "secp256k1", + "serde", +] + [[package]] name = "dashcore_hashes" version = "0.40.0" source = "git+https://github.com/dashpay/rust-dashcore?rev=befd0356bebfcd0d06d1028d8a03bfa4c78bd219#befd0356bebfcd0d06d1028d8a03bfa4c78bd219" dependencies = [ "bincode 2.0.0-rc.3", - "dashcore-private", + "dashcore-private 0.40.0", "rs-x11-hash", "secp256k1", "serde", @@ -1584,8 +1646,8 @@ dependencies = [ name = "dashpay-contract" version = "2.1.0-dev.8" dependencies = [ - "platform-value", - "platform-version", + "platform-value 2.1.0-dev.8", + "platform-version 2.1.0-dev.8", "serde_json", "thiserror 2.0.16", ] @@ -1599,8 +1661,8 @@ dependencies = [ "feature-flags-contract", "keyword-search-contract", "masternode-reward-shares-contract", - "platform-value", - "platform-version", + "platform-value 2.1.0-dev.8", + "platform-version 2.1.0-dev.8", "serde_json", "thiserror 2.0.16", "token-history-contract", @@ -1741,9 +1803,49 @@ checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" name = "dpns-contract" version = "2.1.0-dev.8" dependencies = [ - "platform-value", - "platform-version", + "platform-value 2.1.0-dev.8", + "platform-version 2.1.0-dev.8", + "serde_json", + "thiserror 2.0.16", +] + +[[package]] +name = "dpp" +version = "2.0.1" +source = "git+https://github.com/owl352/platform?branch=v2.0.1#f6d7390361861f5a62b7cb413310b5ec42c26387" +dependencies = [ + "anyhow", + "async-trait", + "base64 0.22.1", + "bincode 2.0.0-rc.3", + "bincode_derive", + "bs58", + "byteorder", + "chrono", + "dashcore 0.39.6", + "derive_more 1.0.0", + "env_logger 0.11.8", + "getrandom 0.2.16", + "hex", + "indexmap 2.11.3", + "integer-encoding", + "itertools 0.13.0", + "lazy_static", + "nohash-hasher", + "num_enum 0.7.4", + "once_cell", + "platform-serialization 2.0.1", + "platform-serialization-derive 2.0.1", + "platform-value 2.0.1", + "platform-version 2.0.1", + "platform-versioning 2.0.1", + "rand 0.8.5", + "regex", + "serde", "serde_json", + "serde_repr", + "sha2", + "strum 0.26.3", "thiserror 2.0.16", ] @@ -1763,11 +1865,11 @@ dependencies = [ "chrono-tz", "ciborium", "dash-spv", - "dashcore", + "dashcore 0.40.0", "dashcore-rpc", "data-contracts", "derive_more 1.0.0", - "dpp", + "dpp 2.1.0-dev.8", "env_logger 0.11.8", "getrandom 0.2.16", "hex", @@ -1783,11 +1885,11 @@ dependencies = [ "nohash-hasher", "num_enum 0.7.4", "once_cell", - "platform-serialization", - "platform-serialization-derive", - "platform-value", - "platform-version", - "platform-versioning", + "platform-serialization 2.1.0-dev.8", + "platform-serialization-derive 2.1.0-dev.8", + "platform-value 2.1.0-dev.8", + "platform-version 2.1.0-dev.8", + "platform-versioning 2.1.0-dev.8", "pretty_assertions", "rand 0.8.5", "regex", @@ -1817,14 +1919,14 @@ dependencies = [ "ciborium", "criterion", "derive_more 1.0.0", - "dpp", + "dpp 2.1.0-dev.8", "enum-map", "grovedb", "grovedb-costs", "grovedb-epoch-based-storage-flags", "grovedb-path", "grovedb-storage", - "grovedb-version", + "grovedb-version 3.0.0 (git+https://github.com/dashpay/grovedb?rev=1ecedf530fbc5b5e12edf1bc607bd288c187ddde)", "hex", "indexmap 2.11.3", "integer-encoding", @@ -1834,7 +1936,7 @@ dependencies = [ "nohash-hasher", "once_cell", "parking_lot", - "platform-version", + "platform-version 2.1.0-dev.8", "rand 0.8.5", "serde", "serde_json", @@ -1863,7 +1965,7 @@ dependencies = [ "delegate", "derive_more 1.0.0", "dotenvy", - "dpp", + "dpp 2.1.0-dev.8", "drive", "drive-abci", "envy", @@ -1876,7 +1978,7 @@ dependencies = [ "metrics", "metrics-exporter-prometheus", "mockall", - "platform-version", + "platform-version 2.1.0-dev.8", "prost 0.14.1", "rand 0.8.5", "regex", @@ -1906,12 +2008,12 @@ dependencies = [ "dapi-grpc", "dash-context-provider", "derive_more 1.0.0", - "dpp", + "dpp 2.1.0-dev.8", "drive", "hex", "indexmap 2.11.3", - "platform-serialization", - "platform-serialization-derive", + "platform-serialization 2.1.0-dev.8", + "platform-serialization-derive 2.1.0-dev.8", "serde", "serde_json", "tenderdash-abci", @@ -2156,8 +2258,8 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" name = "feature-flags-contract" version = "2.1.0-dev.8" dependencies = [ - "platform-value", - "platform-version", + "platform-value 2.1.0-dev.8", + "platform-version 2.1.0-dev.8", "serde_json", "thiserror 2.0.16", ] @@ -2483,7 +2585,7 @@ dependencies = [ "grovedb-merk", "grovedb-path", "grovedb-storage", - "grovedb-version", + "grovedb-version 3.0.0 (git+https://github.com/dashpay/grovedb?rev=1ecedf530fbc5b5e12edf1bc607bd288c187ddde)", "grovedb-visualize", "grovedbg-types", "hex", @@ -2538,7 +2640,7 @@ dependencies = [ "grovedb-costs", "grovedb-path", "grovedb-storage", - "grovedb-version", + "grovedb-version 3.0.0 (git+https://github.com/dashpay/grovedb?rev=1ecedf530fbc5b5e12edf1bc607bd288c187ddde)", "grovedb-visualize", "hex", "indexmap 2.11.3", @@ -2575,6 +2677,16 @@ dependencies = [ "thiserror 2.0.16", ] +[[package]] +name = "grovedb-version" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d61d27c76d49758b365a9e4a9da7f995f976b9525626bf645aef258024defd2" +dependencies = [ + "thiserror 2.0.16", + "versioned-feature-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "grovedb-version" version = "3.0.0" @@ -3392,9 +3504,9 @@ dependencies = [ "bitflags 2.9.4", "bs58", "dash-network", - "dashcore", - "dashcore-private", - "dashcore_hashes", + "dashcore 0.40.0", + "dashcore-private 0.40.0", + "dashcore_hashes 0.40.0", "getrandom 0.2.16", "hex", "hkdf", @@ -3414,7 +3526,7 @@ source = "git+https://github.com/dashpay/rust-dashcore?rev=befd0356bebfcd0d06d10 dependencies = [ "cbindgen 0.29.0", "dash-network", - "dashcore", + "dashcore 0.40.0", "hex", "key-wallet", "key-wallet-manager", @@ -3430,8 +3542,8 @@ source = "git+https://github.com/dashpay/rust-dashcore?rev=befd0356bebfcd0d06d10 dependencies = [ "async-trait", "bincode 2.0.0-rc.3", - "dashcore", - "dashcore_hashes", + "dashcore 0.40.0", + "dashcore_hashes 0.40.0", "key-wallet", "secp256k1", "zeroize", @@ -3442,8 +3554,8 @@ name = "keyword-search-contract" version = "2.1.0-dev.8" dependencies = [ "base58", - "platform-value", - "platform-version", + "platform-value 2.1.0-dev.8", + "platform-version 2.1.0-dev.8", "serde_json", "thiserror 2.0.16", ] @@ -3593,8 +3705,8 @@ dependencies = [ name = "masternode-reward-shares-contract" version = "2.1.0-dev.8" dependencies = [ - "platform-value", - "platform-version", + "platform-value 2.1.0-dev.8", + "platform-version 2.1.0-dev.8", "serde_json", "thiserror 2.0.16", ] @@ -4301,12 +4413,32 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "platform-serialization" +version = "2.0.1" +source = "git+https://github.com/owl352/platform?branch=v2.0.1#f6d7390361861f5a62b7cb413310b5ec42c26387" +dependencies = [ + "bincode 2.0.0-rc.3", + "platform-version 2.0.1", +] + [[package]] name = "platform-serialization" version = "2.1.0-dev.8" dependencies = [ "bincode 2.0.0-rc.3", - "platform-version", + "platform-version 2.1.0-dev.8", +] + +[[package]] +name = "platform-serialization-derive" +version = "2.0.1" +source = "git+https://github.com/owl352/platform?branch=v2.0.1#f6d7390361861f5a62b7cb413310b5ec42c26387" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", + "virtue 0.0.17", ] [[package]] @@ -4319,6 +4451,25 @@ dependencies = [ "virtue 0.0.17", ] +[[package]] +name = "platform-value" +version = "2.0.1" +source = "git+https://github.com/owl352/platform?branch=v2.0.1#f6d7390361861f5a62b7cb413310b5ec42c26387" +dependencies = [ + "base64 0.22.1", + "bincode 2.0.0-rc.3", + "bs58", + "hex", + "indexmap 2.11.3", + "platform-serialization 2.0.1", + "platform-version 2.0.1", + "rand 0.8.5", + "serde", + "serde_json", + "thiserror 2.0.16", + "treediff", +] + [[package]] name = "platform-value" version = "2.1.0-dev.8" @@ -4329,8 +4480,8 @@ dependencies = [ "ciborium", "hex", "indexmap 2.11.3", - "platform-serialization", - "platform-version", + "platform-serialization 2.1.0-dev.8", + "platform-version 2.1.0-dev.8", "rand 0.8.5", "serde", "serde_json", @@ -4346,17 +4497,39 @@ dependencies = [ "syn 2.0.106", ] +[[package]] +name = "platform-version" +version = "2.0.1" +source = "git+https://github.com/owl352/platform?branch=v2.0.1#f6d7390361861f5a62b7cb413310b5ec42c26387" +dependencies = [ + "bincode 2.0.0-rc.3", + "grovedb-version 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "once_cell", + "thiserror 2.0.16", + "versioned-feature-core 1.0.0 (git+https://github.com/dashpay/versioned-feature-core)", +] + [[package]] name = "platform-version" version = "2.1.0-dev.8" dependencies = [ "bincode 2.0.0-rc.3", - "grovedb-version", + "grovedb-version 3.0.0 (git+https://github.com/dashpay/grovedb?rev=1ecedf530fbc5b5e12edf1bc607bd288c187ddde)", "once_cell", "thiserror 2.0.16", "versioned-feature-core 1.0.0 (git+https://github.com/dashpay/versioned-feature-core)", ] +[[package]] +name = "platform-versioning" +version = "2.0.1" +source = "git+https://github.com/owl352/platform?branch=v2.0.1#f6d7390361861f5a62b7cb413310b5ec42c26387" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + [[package]] name = "platform-versioning" version = "2.1.0-dev.8" @@ -4370,8 +4543,8 @@ dependencies = [ name = "platform-wallet" version = "2.1.0-dev.8" dependencies = [ - "dashcore", - "dpp", + "dashcore 0.40.0", + "dpp 2.1.0-dev.8", "indexmap 2.11.3", "key-wallet", "key-wallet-manager", @@ -5109,7 +5282,7 @@ dependencies = [ "arc-swap", "async-trait", "dash-context-provider", - "dpp", + "dpp 2.1.0-dev.8", "futures", "hex", "lru", @@ -5759,7 +5932,7 @@ version = "2.1.0-dev.8" dependencies = [ "base64 0.22.1", "bincode 2.0.0-rc.3", - "dpp", + "dpp 2.1.0-dev.8", "hex", "tracing", ] @@ -5855,13 +6028,13 @@ name = "strategy-tests" version = "2.1.0-dev.8" dependencies = [ "bincode 2.0.0-rc.3", - "dpp", + "dpp 2.1.0-dev.8", "drive", "futures", "hex", - "platform-serialization", - "platform-serialization-derive", - "platform-version", + "platform-serialization 2.1.0-dev.8", + "platform-serialization-derive 2.1.0-dev.8", + "platform-version 2.1.0-dev.8", "rand 0.8.5", "rocksdb 0.23.0", "serde_json", @@ -6002,6 +6175,15 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" +[[package]] +name = "talc" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fcad3be1cfe36eb7d716a04791eba36a197da9d9b6ea1e28e64ac569da3701d" +dependencies = [ + "lock_api", +] + [[package]] name = "tap" version = "1.0.1" @@ -6251,8 +6433,8 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" name = "token-history-contract" version = "2.1.0-dev.8" dependencies = [ - "platform-value", - "platform-version", + "platform-value 2.1.0-dev.8", + "platform-version 2.1.0-dev.8", "serde_json", "thiserror 2.0.16", ] @@ -6925,8 +7107,8 @@ dependencies = [ name = "wallet-utils-contract" version = "2.1.0-dev.8" dependencies = [ - "platform-value", - "platform-version", + "platform-value 2.1.0-dev.8", + "platform-version 2.1.0-dev.8", "serde_json", "thiserror 2.0.16", ] @@ -6973,6 +7155,8 @@ dependencies = [ "cfg-if 1.0.3", "once_cell", "rustversion", + "serde", + "serde_json", "wasm-bindgen-macro", ] @@ -7066,7 +7250,7 @@ dependencies = [ "anyhow", "async-trait", "bincode 2.0.0-rc.3", - "dpp", + "dpp 2.1.0-dev.8", "hex", "itertools 0.13.0", "js-sys", @@ -7083,6 +7267,24 @@ dependencies = [ "web-sys", ] +[[package]] +name = "wasm-dpp2" +version = "1.0.5" +dependencies = [ + "anyhow", + "bincode 2.0.0-rc.3", + "bincode_derive", + "dpp 2.0.1", + "hex", + "js-sys", + "serde", + "serde-wasm-bindgen 0.5.0", + "serde_json", + "sha2", + "talc", + "wasm-bindgen", +] + [[package]] name = "wasm-drive-verify" version = "2.1.0-dev.8" @@ -7093,7 +7295,7 @@ dependencies = [ "ciborium", "console_error_panic_hook", "criterion", - "dpp", + "dpp 2.1.0-dev.8", "drive", "hex", "indexmap 2.11.3", @@ -7135,7 +7337,7 @@ dependencies = [ "hmac", "js-sys", "once_cell", - "platform-value", + "platform-value 2.1.0-dev.8", "rand 0.8.5", "rs-dapi-client", "rs-sdk-trusted-context-provider", @@ -7687,8 +7889,8 @@ name = "withdrawals-contract" version = "2.1.0-dev.8" dependencies = [ "num_enum 0.5.11", - "platform-value", - "platform-version", + "platform-value 2.1.0-dev.8", + "platform-version 2.1.0-dev.8", "serde", "serde_json", "serde_repr", diff --git a/Cargo.toml b/Cargo.toml index 0041d4db196..1b1d9c47f3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ members = [ "packages/rs-context-provider", "packages/rs-sdk-trusted-context-provider", "packages/wasm-dpp", + "packages/wasm-dpp2", "packages/rs-dapi-client", "packages/rs-sdk", "packages/strategy-tests", diff --git a/package.json b/package.json index 9037de80278..d81e770aef6 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "packages/masternode-reward-shares-contract", "packages/dash-spv", "packages/wasm-dpp", + "packages/wasm-dpp2", "packages/withdrawals-contract", "packages/token-history-contract", "packages/keyword-search-contract", diff --git a/packages/scripts/build-wasm.sh b/packages/scripts/build-wasm.sh index 26cc313e131..5c8e29bf46f 100755 --- a/packages/scripts/build-wasm.sh +++ b/packages/scripts/build-wasm.sh @@ -21,6 +21,7 @@ PACKAGE_NAME="" TARGET_TYPE="web" OPT_LEVEL="full" USE_WASM_PACK=false +DEFAULT_FEATURES_FALLBACK=true # Parse command line arguments while [[ $# -gt 0 ]]; do @@ -76,6 +77,12 @@ case "$PACKAGE_NAME" in "wasm-sdk") USE_WASM_PACK=true WASM_FILE="wasm_sdk_bg.wasm" + DEFAULT_FEATURES_FALLBACK=true + ;; + "wasm-dpp2") + USE_WASM_PACK=true + WASM_FILE="wasm_dpp2_bg.wasm" + DEFAULT_FEATURES_FALLBACK=false ;; "wasm-drive-verify") USE_WASM_PACK=false @@ -113,10 +120,12 @@ if [ "$USE_WASM_PACK" = true ]; then if [ -n "${CARGO_BUILD_FEATURES:-}" ]; then echo "CARGO_BUILD_FEATURES is set to: '$CARGO_BUILD_FEATURES'" FEATURES_ARG="--features $CARGO_BUILD_FEATURES" - else + elif [ "$DEFAULT_FEATURES_FALLBACK" = true ]; then echo "CARGO_BUILD_FEATURES is not set, using default features" - # Explicitly pass default features to ensure they're used FEATURES_ARG="--features default" + else + echo "CARGO_BUILD_FEATURES is not set, building with crate defaults" + FEATURES_ARG="" fi echo "Running: wasm-pack build --target $TARGET_TYPE --release --no-opt $FEATURES_ARG" diff --git a/packages/wasm-dpp2/.gitignore b/packages/wasm-dpp2/.gitignore new file mode 100644 index 00000000000..0073538b9dc --- /dev/null +++ b/packages/wasm-dpp2/.gitignore @@ -0,0 +1,2 @@ +dist +pkg diff --git a/packages/wasm-dpp2/.mocharc.yml b/packages/wasm-dpp2/.mocharc.yml new file mode 100644 index 00000000000..e82067f393b --- /dev/null +++ b/packages/wasm-dpp2/.mocharc.yml @@ -0,0 +1,4 @@ +require: tests/bootstrap.cjs +recursive: true +timeout: 8000 + diff --git a/packages/wasm-dpp2/Cargo.toml b/packages/wasm-dpp2/Cargo.toml new file mode 100644 index 00000000000..40539121b64 --- /dev/null +++ b/packages/wasm-dpp2/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "wasm-dpp2" +version = "1.0.5" +edition = "2024" + +[lib] +crate-type = ["cdylib", "lib"] + +[dependencies] +talc = { version = "=4.4.2", default-features = false, features = ["lock_api"] } +bincode = "=2.0.0-rc.3" +bincode_derive = "=2.0.0-rc.3" +wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] } +dpp = { git = "https://github.com/owl352/platform", branch = "v2.0.1", default-features = false, features = [ + "state-transition-signing", + "document-json-conversion", + "identity-serialization", + "identity-value-conversion", + "data-contract-json-conversion", + "document-value-conversion", + "bls-signatures", + "platform-value", + "state-transitions", + "state-transition-serde-conversion" +] } +serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" } +serde = { version = "1.0.197", features = ["derive"] } +serde_json = { version = "1.0", features = ["preserve_order"] } +js-sys = "0.3.77" +hex = "0.4.3" +anyhow = "1.0.75" +sha2 = "0.10.8" diff --git a/packages/wasm-dpp2/README.md b/packages/wasm-dpp2/README.md new file mode 100644 index 00000000000..4f821701242 --- /dev/null +++ b/packages/wasm-dpp2/README.md @@ -0,0 +1,13 @@ +# @dashevo/wasm-dpp2 + +Internal build of the Dash Platform Protocol v2 WebAssembly bindings. + +## Scripts + +- `yarn build` – run the unified WASM build and bundle artifacts into `dist/` +- `yarn build:release` – same as `build` but forces full release optimisations +- `yarn test` – execute unit + browser (Karma) tests +- `yarn lint` – lint test sources + +The build scripts defer to `packages/scripts/build-wasm.sh` to keep behaviour +consistent with other WASM packages such as `@dashevo/wasm-sdk`. diff --git a/packages/wasm-dpp2/package.json b/packages/wasm-dpp2/package.json new file mode 100644 index 00000000000..882d9cc1224 --- /dev/null +++ b/packages/wasm-dpp2/package.json @@ -0,0 +1,69 @@ +{ + "name": "@dashevo/wasm-dpp2", + "version": "2.1.0-dev.8", + "type": "module", + "main": "./dist/dpp.js", + "types": "./dist/dpp.d.ts", + "exports": { + ".": { + "types": "./dist/dpp.d.ts", + "import": "./dist/dpp.js" + }, + "./compressed": { + "types": "./dist/dpp.d.ts", + "import": "./dist/dpp.compressed.js" + }, + "./raw": { + "types": "./dist/raw/wasm_dpp2.d.ts", + "import": "./dist/raw/wasm_dpp2.js" + }, + "./raw/*": "./dist/raw/*" + }, + "files": [ + "dist/**", + "README.md" + ], + "sideEffects": false, + "engines": { + "node": ">=18.18" + }, + "scripts": { + "build": "./scripts/build.sh && node ./scripts/bundle.cjs", + "build:release": "./scripts/build-optimized.sh && node ./scripts/bundle.cjs", + "test": "yarn run test:unit", + "test:unit": "mocha tests/unit/**/*.spec.mjs && karma start ./tests/karma/karma.conf.cjs --single-run", + "lint": "eslint tests/**/*.*js" + }, + "ultra": { + "concurrent": [ + "test" + ] + }, + "devDependencies": { + "assert": "^2.0.0", + "buffer": "^6.0.3", + "chai": "^4.3.10", + "chai-as-promised": "^7.1.1", + "dirty-chai": "^2.0.1", + "eslint": "^8.53.0", + "eslint-config-airbnb-base": "^15.0.0", + "eslint-plugin-import": "^2.29.0", + "eslint-plugin-jsdoc": "^46.9.0", + "events": "^3.3.0", + "karma": "^6.4.3", + "karma-chai": "^0.1.0", + "karma-chrome-launcher": "^3.1.0", + "karma-firefox-launcher": "^2.1.2", + "karma-mocha": "^2.0.1", + "karma-mocha-reporter": "^2.2.5", + "karma-webpack": "^5.0.0", + "mocha": "^11.1.0", + "path-browserify": "^1.0.1", + "process": "^0.11.10", + "string_decoder": "^1.3.0", + "url": "^0.11.3", + "util": "^0.12.4", + "webpack": "^5.94.0", + "webpack-cli": "^4.9.1" + } +} diff --git a/packages/wasm-dpp2/scripts/build-optimized.sh b/packages/wasm-dpp2/scripts/build-optimized.sh new file mode 100755 index 00000000000..4afe54f3366 --- /dev/null +++ b/packages/wasm-dpp2/scripts/build-optimized.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# +# Optimized build script for wasm-dpp2 npm release +# +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +echo "Building wasm-dpp2 with full optimization for npm release..." + +"$SCRIPT_DIR/../../scripts/build-wasm.sh" --package wasm-dpp2 --opt-level full + +cd "$SCRIPT_DIR/../pkg" + +REQUIRED_FILES=("wasm_dpp2.js" "wasm_dpp2.d.ts" "wasm_dpp2_bg.wasm") +for file in "${REQUIRED_FILES[@]}"; do + if [ ! -f "$file" ]; then + echo "Error: Required file $file not found" + exit 1 + fi +done + +echo "Package contents:" +ls -lah + +WASM_SIZE=$(wc -c < wasm_dpp2_bg.wasm) +WASM_SIZE_KB=$((WASM_SIZE / 1024)) +echo "WASM file size: ${WASM_SIZE_KB}KB" diff --git a/packages/wasm-dpp2/scripts/build.sh b/packages/wasm-dpp2/scripts/build.sh new file mode 100755 index 00000000000..f8ccba2fc35 --- /dev/null +++ b/packages/wasm-dpp2/scripts/build.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# +# Build wasm-dpp2 using unified build script +# +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +if [ "${CARGO_BUILD_PROFILE:-}" = "release" ]; then + exec "$SCRIPT_DIR/build-optimized.sh" +fi + +OPT_LEVEL="full" +if [ "${CARGO_BUILD_PROFILE:-}" = "dev" ] || [ "${CI:-}" != "true" ]; then + OPT_LEVEL="minimal" +fi + +exec "$SCRIPT_DIR/../../scripts/build-wasm.sh" --package wasm-dpp2 --opt-level "$OPT_LEVEL" diff --git a/packages/wasm-dpp2/scripts/bundle.cjs b/packages/wasm-dpp2/scripts/bundle.cjs new file mode 100755 index 00000000000..42c8313f134 --- /dev/null +++ b/packages/wasm-dpp2/scripts/bundle.cjs @@ -0,0 +1,129 @@ +#!/usr/bin/env node +/* + Prepare publishable artifacts for wasm-dpp2 with single-file wrappers and raw outputs. + - Input: pkg/wasm_dpp2.js, pkg/wasm_dpp2_bg.wasm, pkg/wasm_dpp2.d.ts + - Output: dist/raw/* (unaltered wasm-bindgen outputs), dist/dpp.js (single-file wrapper with inlined WASM), dist/dpp.compressed.js, dist/dpp.d.ts +*/ + +const fs = require('fs'); +const path = require('path'); +const zlib = require('zlib'); + +const root = process.cwd(); +const pkgDir = path.join(root, 'pkg'); +const distDir = path.join(root, 'dist'); +const rawDir = path.join(distDir, 'raw'); + +const jsPath = path.join(pkgDir, 'wasm_dpp2.js'); +const wasmPath = path.join(pkgDir, 'wasm_dpp2_bg.wasm'); +const dtsPath = path.join(pkgDir, 'wasm_dpp2.d.ts'); +const wasmDtsPath = path.join(pkgDir, 'wasm_dpp2_bg.wasm.d.ts'); + +if (!fs.existsSync(jsPath) || !fs.existsSync(wasmPath) || !fs.existsSync(dtsPath)) { + console.error('Missing build artifacts in pkg/. Run build first.'); + process.exit(1); +} + +fs.mkdirSync(distDir, { recursive: true }); +fs.mkdirSync(rawDir, { recursive: true }); + +const rawJs = fs.readFileSync(jsPath, 'utf8'); +fs.writeFileSync(path.join(rawDir, 'wasm_dpp2.js'), rawJs); +fs.copyFileSync(wasmPath, path.join(rawDir, 'wasm_dpp2_bg.wasm')); +fs.copyFileSync(dtsPath, path.join(rawDir, 'wasm_dpp2.d.ts')); +if (fs.existsSync(wasmDtsPath)) { + fs.copyFileSync(wasmDtsPath, path.join(rawDir, 'wasm_dpp2_bg.wasm.d.ts')); +} + +const defaultUrlRegex = /if\s*\(\s*typeof\s+module_or_path\s*===\s*'undefined'\s*\)\s*\{\s*module_or_path\s*=\s*new\s+URL\('wasm_dpp2_bg\\.wasm',\s*import\\.meta\\.url\);\s*\}/; +const sanitizedJs = rawJs.replace(defaultUrlRegex, "if (typeof module_or_path === 'undefined') { }"); +fs.writeFileSync(path.join(rawDir, 'wasm_dpp2.no_url.js'), sanitizedJs); + +const wasmBytes = fs.readFileSync(wasmPath); +const wasmBase64 = wasmBytes.toString('base64'); +const wasmGzip = zlib.gzipSync(wasmBytes, { level: zlib.constants.Z_BEST_COMPRESSION }); +const wasmGzipBase64 = wasmGzip.toString('base64'); + +const wrapper = `// Single-file ESM wrapper around wasm-bindgen output.\n// - Inlines WASM bytes as base64.\n// - Exposes async default init() for both Node and browser.\n\nimport rawInit, { initSync as rawInitSync } from './raw/wasm_dpp2.no_url.js';\n\nexport * from './raw/wasm_dpp2.no_url.js';\nexport { initSync } from './raw/wasm_dpp2.no_url.js';\n\nconst __WASM_BASE64 = '${wasmBase64}';\nfunction __wasmBytes() {\n if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') {\n return Buffer.from(__WASM_BASE64, 'base64');\n }\n const atobFn = (typeof atob === 'function') ? atob : (s) => globalThis.atob(s);\n const bin = atobFn(__WASM_BASE64);\n const len = bin.length;\n const bytes = new Uint8Array(len);\n for (let i = 0; i < len; i++) bytes[i] = bin.charCodeAt(i);\n return bytes;\n}\n\nfunction __supportsWorker() {\n return typeof Worker !== 'undefined' && typeof Blob !== 'undefined' && typeof URL !== 'undefined';\n}\n\nasync function __compileInWorker(bytes) {\n if (!__supportsWorker()) {\n return WebAssembly.compile(bytes);\n }\n const src = 'self.onmessage=async(e)=>{try{const m=await WebAssembly.compile(e.data);self.postMessage({ok:1,mod:m});}catch(err){self.postMessage({ok:0,err:String(err)});}}';\n const blob = new Blob([src], { type: 'application/javascript' });\n const url = URL.createObjectURL(blob);\n return new Promise((resolve, reject) => {\n const w = new Worker(url);\n const cleanup = () => {\n URL.revokeObjectURL(url);\n w.terminate();\n };\n w.onmessage = (ev) => {\n const d = ev.data || {};\n if (d.ok && d.mod) {\n cleanup();\n resolve(d.mod);\n } else {\n cleanup();\n reject(new Error(d.err || 'Worker failed to compile WASM.')); + }\n };\n w.onerror = (err) => {\n cleanup();\n reject(err instanceof Error ? err : new Error(String(err && err.message ? err.message : err)));\n };\n try {\n w.postMessage(bytes.buffer, [bytes.buffer]);\n } catch (_) {\n w.postMessage(new Uint8Array(bytes));\n }\n });\n}\n\nconst isNode = typeof window === 'undefined' && typeof process !== 'undefined' && !!(process.versions && process.versions.node);\n\nexport default async function init(moduleOrPath) {\n if (isNode) {\n if (typeof moduleOrPath === 'undefined') {\n const bytes = __wasmBytes();\n return rawInitSync({ module: bytes });\n }\n return rawInit(moduleOrPath);\n }\n if (typeof moduleOrPath === 'undefined') {\n const bytes = __wasmBytes();\n let mod;\n try {\n mod = await __compileInWorker(bytes);\n } catch (_) {\n mod = await WebAssembly.compile(bytes);\n }\n return rawInit({ module_or_path: mod });\n }\n return rawInit(moduleOrPath);\n}\n`; +fs.writeFileSync(path.join(distDir, 'dpp.js'), wrapper); + +const compressedWrapper = `// Gzip-compressed single-file ESM wrapper around wasm-bindgen output.\n// - Inlines WASM as base64 gzip payload to reduce bundle size.\n\nimport rawInit, { initSync as rawInitSync } from './raw/wasm_dpp2.no_url.js';\n\nexport * from './raw/wasm_dpp2.no_url.js';\nexport { initSync } from './raw/wasm_dpp2.no_url.js';\n\nconst __WASM_COMPRESSED_BASE64 = '${wasmGzipBase64}';\nconst __WASM_COMPRESSION = 'gzip';\nconst isNode = typeof window === 'undefined' && typeof process !== 'undefined' && !!(process.versions && process.versions.node);\n\nfunction __decodeBase64(source) {\n if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') {\n return Buffer.from(source, 'base64');\n }\n const atobFn = (typeof atob === 'function') ? atob : (s) => globalThis.atob(s);\n const bin = atobFn(source);\n const len = bin.length;\n const bytes = new Uint8Array(len);\n for (let i = 0; i < len; i++) bytes[i] = bin.charCodeAt(i);\n return bytes;\n}\n\nlet __nodeZlibPromise;\nfunction __loadNodeZlib() {\n if (!__nodeZlibPromise) {\n const importer = new Function('return import(\\"node:zlib\\")');\n __nodeZlibPromise = importer();\n }\n return __nodeZlibPromise;\n}\n\nasync function __decompress(bytes) {\n if (!__WASM_COMPRESSION) {\n return bytes;\n }\n if (isNode) {\n const { gunzipSync } = await __loadNodeZlib();\n const out = gunzipSync(bytes); + return out instanceof Uint8Array ? out : new Uint8Array(out.buffer, out.byteOffset, out.byteLength);\n }\n if (typeof Blob === 'function' && typeof Response === 'function' && typeof DecompressionStream === 'function') {\n const res = new Response(\n new Blob([bytes]).stream().pipeThrough(new DecompressionStream(__WASM_COMPRESSION))\n );\n const buf = await res.arrayBuffer();\n return new Uint8Array(buf);\n }\n throw new Error('Gzip decompression not supported in this environment.');\n}\n\nasync function __wasmBytes(options = {}) {\n const { decompress = true } = options;\n if (!__WASM_COMPRESSION) {\n throw new Error('Compression metadata missing.');\n }\n const compressed = __decodeBase64(__WASM_COMPRESSED_BASE64);\n if (!decompress) {\n return compressed;\n }\n return __decompress(compressed);\n}\n\nfunction __supportsWorker() {\n return typeof Worker !== 'undefined' && typeof Blob !== 'undefined' && typeof URL !== 'undefined';\n}\n\nasync function __compileInWorker(compressedBytes) {\n const bytes = compressedBytes instanceof Uint8Array ? compressedBytes : new Uint8Array(compressedBytes);\n if (!__supportsWorker()) {\n const decompressed = await __decompress(bytes);\n return WebAssembly.compile(decompressed);\n }\n const src = "self.onmessage=async(event)=>{try{const data=event.data||{};let bytes=data.compressed;const compression=data.compression||null;if(!(bytes instanceof Uint8Array)){bytes=bytes?new Uint8Array(bytes):new Uint8Array();}if(compression){if(typeof Blob==='function'&&typeof Response==='function'&&typeof DecompressionStream==='function'){const res=new Response(new Blob([bytes]).stream().pipeThrough(new DecompressionStream(compression)));const buf=await res.arrayBuffer();bytes=new Uint8Array(buf);}else{throw new Error('DecompressionStream not available');}}const mod=await WebAssembly.compile(bytes);self.postMessage({ok:1,mod});}catch(err){self.postMessage({ok:0,err:String(err)})}}"; + const blob = new Blob([src], { type: 'application/javascript' }); + const url = URL.createObjectURL(blob); + return new Promise((resolve, reject) => { + const worker = new Worker(url); + const cleanup = () => { + URL.revokeObjectURL(url); + worker.terminate(); + }; + worker.onmessage = (ev) => { + const d = ev.data || {}; + if (d.ok && d.mod) { + cleanup(); + resolve(d.mod); + } else { + cleanup(); + reject(new Error(d.err || 'Worker failed to compile WASM.')); + } + }; + worker.onerror = (err) => { + cleanup(); + reject(err instanceof Error ? err : new Error(String(err && err.message ? err.message : err))); + }; + try { + worker.postMessage({ compressed: bytes, compression: __WASM_COMPRESSION }); + } catch (postErr) { + cleanup(); + reject(postErr); + } + }); +} + +export default async function init(moduleOrPath) { + if (isNode) { + if (typeof moduleOrPath === 'undefined') { + const bytes = await __wasmBytes(); + return rawInitSync({ module: bytes }); + } + return rawInit(moduleOrPath); + } + if (typeof moduleOrPath === 'undefined') { + const compressedBytes = await __wasmBytes({ decompress: false }); + let mod; + try { + mod = await __compileInWorker(compressedBytes); + } catch (_) { + const decompressed = await __decompress(compressedBytes); + mod = await WebAssembly.compile(decompressed); + } + return rawInit({ module_or_path: mod }); + } + return rawInit(moduleOrPath); +} +`; +fs.writeFileSync(path.join(distDir, 'dpp.compressed.js'), compressedWrapper); + +const dppJsPath = path.join(distDir, 'dpp.js'); +const dppCompressedPath = path.join(distDir, 'dpp.compressed.js'); + +const baseStat = fs.statSync(dppJsPath); +const compressedStat = fs.statSync(dppCompressedPath); +const baseGzipSize = zlib.gzipSync(fs.readFileSync(dppJsPath)).length; +const compressedGzipSize = zlib.gzipSync(fs.readFileSync(dppCompressedPath)).length; + +fs.copyFileSync(dtsPath, path.join(distDir, 'dpp.d.ts')); + +console.log(`Wrote dist/dpp.js (${baseStat.size} bytes) single-file wrapper (inline WASM)`); +console.log(`Wrote dist/dpp.compressed.js (${compressedStat.size} bytes) gzip inline wrapper`); +console.log(`gzip(dpp.js): ${baseGzipSize} bytes | gzip(dpp.compressed.js): ${compressedGzipSize} bytes`); +console.log('Wrote dist/dpp.d.ts'); +console.log('Wrote dist/raw/* (separate JS + WASM)'); + +try { + fs.rmSync(pkgDir, { recursive: true, force: true }); + console.log('Removed pkg/ directory after bundling'); +} catch (e) { + console.warn('Warning: failed to remove pkg/ directory:', e?.message || e); +} diff --git a/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs new file mode 100644 index 00000000000..9e8c60233bf --- /dev/null +++ b/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs @@ -0,0 +1,98 @@ +use crate::asset_lock_proof::outpoint::OutPointWASM; +use crate::identifier::IdentifierWASM; +use dpp::identity::state_transition::asset_lock_proof::chain::ChainAssetLockProof; +use serde::Deserialize; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +struct ChainAssetLockProofParams { + core_chain_locked_height: u32, + out_point: Vec, +} + +#[wasm_bindgen(js_name = "ChainAssetLockProofWASM")] +#[derive(Clone)] +pub struct ChainAssetLockProofWASM(ChainAssetLockProof); + +impl From for ChainAssetLockProof { + fn from(chain_lock: ChainAssetLockProofWASM) -> Self { + chain_lock.0 + } +} + +impl From for ChainAssetLockProofWASM { + fn from(chain_lock: ChainAssetLockProof) -> Self { + ChainAssetLockProofWASM(chain_lock) + } +} + +#[wasm_bindgen] +impl ChainAssetLockProofWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "ChainAssetLockProofWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "ChainAssetLockProofWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + core_chain_locked_height: u32, + out_point: &OutPointWASM, + ) -> Result { + Ok(ChainAssetLockProofWASM(ChainAssetLockProof { + core_chain_locked_height, + out_point: out_point.clone().into(), + })) + } + + #[wasm_bindgen(js_name = "fromRawObject")] + pub fn from_raw_value( + raw_asset_lock_proof: JsValue, + ) -> Result { + let parameters: ChainAssetLockProofParams = + serde_wasm_bindgen::from_value(raw_asset_lock_proof) + .map_err(|err| JsError::from(err))?; + + let out_point: [u8; 36] = parameters + .out_point + .try_into() + .map_err(|_| JsError::new("outPoint must be a 36 byte array"))?; + + let rs_proof = ChainAssetLockProof::new(parameters.core_chain_locked_height, out_point); + + Ok(ChainAssetLockProofWASM(rs_proof)) + } + + #[wasm_bindgen(setter = "coreChainLockedHeight")] + pub fn set_core_chain_locked_height(&mut self, core_chain_locked_height: u32) { + self.0.core_chain_locked_height = core_chain_locked_height; + } + + #[wasm_bindgen(setter = "outPoint")] + pub fn set_out_point(&mut self, outpoint: &OutPointWASM) { + self.0.out_point = outpoint.clone().into(); + } + + #[wasm_bindgen(getter = "coreChainLockedHeight")] + pub fn get_core_chain_locked_height(self) -> u32 { + self.0.core_chain_locked_height + } + + #[wasm_bindgen(getter = "outPoint")] + pub fn get_out_point(self) -> OutPointWASM { + self.0.out_point.into() + } + + #[wasm_bindgen(js_name = "createIdentityId")] + pub fn create_identifier(&self) -> IdentifierWASM { + let identifier = self.0.create_identifier(); + + identifier.into() + } +} diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs new file mode 100644 index 00000000000..3cf5608749e --- /dev/null +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs @@ -0,0 +1,121 @@ +use crate::asset_lock_proof::outpoint::OutPointWASM; +use dpp::dashcore::bls_sig_utils::BLSSignature; +use dpp::dashcore::hash_types::CycleHash; +use dpp::dashcore::hashes::hex::FromHex; +use dpp::dashcore::secp256k1::hashes::hex::Case::Lower; +use dpp::dashcore::secp256k1::hashes::hex::DisplayHex; +use dpp::dashcore::{InstantLock, Txid}; +use std::str::FromStr; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "InstantLockWASM")] +#[derive(Clone)] +pub struct InstantLockWASM(InstantLock); + +impl From for InstantLock { + fn from(value: InstantLockWASM) -> Self { + value.0 + } +} + +impl From for InstantLockWASM { + fn from(value: InstantLock) -> Self { + InstantLockWASM(value) + } +} + +#[wasm_bindgen] +impl InstantLockWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "InstantLockWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "InstantLockWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + version: u8, + js_inputs: &js_sys::Array, + txid: String, + cycle_hash: String, + bls_signature: String, + ) -> Result { + let inputs = OutPointWASM::vec_from_js_value(js_inputs)?; + + Ok(InstantLockWASM(InstantLock { + version, + inputs: inputs.iter().map(|input| input.clone().into()).collect(), + txid: Txid::from_hex(&txid).map_err(|err| JsValue::from(err.to_string()))?, + cyclehash: CycleHash::from_str(&cycle_hash) + .map_err(|err| JsValue::from(err.to_string()))?, + signature: BLSSignature::from_hex(&bls_signature) + .map_err(|err| JsValue::from(err.to_string()))?, + })) + } + + #[wasm_bindgen(getter = "version")] + pub fn get_version(&self) -> u8 { + self.0.version + } + + #[wasm_bindgen(getter = "inputs")] + pub fn get_inputs(&self) -> Vec { + self.0 + .inputs + .iter() + .map(|input| input.clone().into()) + .collect() + } + + #[wasm_bindgen(getter = "txid")] + pub fn get_txid(&self) -> String { + self.0.txid.to_hex() + } + + #[wasm_bindgen(getter = "cyclehash")] + pub fn get_cycle_hash(&self) -> String { + self.0.cyclehash.to_string() + } + + #[wasm_bindgen(getter = "blsSignature")] + pub fn get_bls_signature(&self) -> String { + self.0.signature.to_bytes().to_hex_string(Lower) + } + + #[wasm_bindgen(setter = "version")] + pub fn set_version(&mut self, v: u8) { + self.0.version = v; + } + + #[wasm_bindgen(setter = "inputs")] + pub fn set_inputs(&mut self, inputs: &js_sys::Array) -> Result<(), JsValue> { + let inputs = OutPointWASM::vec_from_js_value(inputs)?; + self.0.inputs = inputs.iter().map(|input| input.clone().into()).collect(); + Ok(()) + } + + #[wasm_bindgen(setter = "txid")] + pub fn set_txid(&mut self, txid: String) -> Result<(), JsValue> { + self.0.txid = Txid::from_hex(&txid).map_err(|err| JsValue::from(err.to_string()))?; + Ok(()) + } + + #[wasm_bindgen(setter = "cyclehash")] + pub fn set_cycle_hash(&mut self, cycle_hash: String) -> Result<(), JsValue> { + self.0.cyclehash = + CycleHash::from_str(&cycle_hash).map_err(|err| JsValue::from(err.to_string()))?; + Ok(()) + } + + #[wasm_bindgen(setter = "blsSignature")] + pub fn set_bls_signature(&mut self, bls_signature: String) -> Result<(), JsValue> { + self.0.signature = + BLSSignature::from_hex(&bls_signature).map_err(|err| JsValue::from(err.to_string()))?; + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs new file mode 100644 index 00000000000..2b12175cfd6 --- /dev/null +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs @@ -0,0 +1,146 @@ +mod instant_lock; + +use crate::asset_lock_proof::instant::instant_lock::InstantLockWASM; +use crate::asset_lock_proof::outpoint::OutPointWASM; +use crate::asset_lock_proof::tx_out::TxOutWASM; +use crate::identifier::IdentifierWASM; +use crate::utils::WithJsError; +use dpp::dashcore::consensus::{deserialize, serialize}; +use dpp::dashcore::{InstantLock, Transaction}; +use dpp::identity::state_transition::asset_lock_proof::InstantAssetLockProof; +use serde::{Deserialize, Serialize}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +struct InstantAssetLockProofRAW { + instant_lock: Vec, + transaction: Vec, + output_index: u32, +} + +#[derive(Clone)] +#[wasm_bindgen(js_name = "InstantAssetLockProofWASM")] +pub struct InstantAssetLockProofWASM(InstantAssetLockProof); + +impl From for InstantAssetLockProof { + fn from(proof: InstantAssetLockProofWASM) -> Self { + proof.0 + } +} + +impl From for InstantAssetLockProofWASM { + fn from(proof: InstantAssetLockProof) -> Self { + InstantAssetLockProofWASM(proof) + } +} + +#[wasm_bindgen] +impl InstantAssetLockProofWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "InstantAssetLockProofWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "InstantAssetLockProofWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + instant_lock: Vec, + transaction: Vec, + output_index: u32, + ) -> Result { + let instant_lock: InstantLock = + deserialize(instant_lock.as_slice()).map_err(|err| JsValue::from(err.to_string()))?; + let transaction: Transaction = + deserialize(transaction.as_slice()).map_err(|err| JsValue::from(err.to_string()))?; + + Ok(InstantAssetLockProofWASM(InstantAssetLockProof { + instant_lock, + transaction, + output_index, + })) + } + + #[wasm_bindgen(js_name = "fromObject")] + pub fn from_object(value: JsValue) -> Result { + let parameters: InstantAssetLockProofRAW = + serde_wasm_bindgen::from_value(value).map_err(|err| JsValue::from(err.to_string()))?; + + InstantAssetLockProofWASM::new( + parameters.instant_lock, + parameters.transaction, + parameters.output_index, + ) + } + + #[wasm_bindgen(js_name = "toObject")] + pub fn to_object(&self) -> Result { + let serializer = serde_wasm_bindgen::Serializer::json_compatible(); + + self.0 + .to_object() + .with_js_error()? + .serialize(&serializer) + .map_err(JsValue::from) + } + + #[wasm_bindgen(js_name = "getOutput")] + pub fn get_output(&self) -> Option { + match self.0.output() { + Some(output) => Some(output.clone().into()), + None => None, + } + } + + #[wasm_bindgen(js_name = "getOutPoint")] + pub fn get_out_point(&self) -> Option { + match self.0.out_point() { + Some(output) => Some(output.clone().into()), + None => None, + } + } + + #[wasm_bindgen(getter = "outputIndex")] + pub fn get_output_index(&self) -> u32 { + self.0.output_index() + } + + #[wasm_bindgen(getter = "instantLock")] + pub fn get_instant_lock(&self) -> InstantLockWASM { + self.0.instant_lock.clone().into() + } + + #[wasm_bindgen(setter = "outputIndex")] + pub fn set_output_index(&mut self, output_index: u32) { + self.0.output_index = output_index; + } + + #[wasm_bindgen(setter = "instantLock")] + pub fn set_instant_lock(&mut self, instant_lock: &InstantLockWASM) { + self.0.instant_lock = instant_lock.clone().into(); + } + + #[wasm_bindgen(js_name=getTransaction)] + pub fn get_transaction(&self) -> Vec { + let transaction = self.0.transaction(); + serialize(transaction) + } + + #[wasm_bindgen(js_name=getInstantLockBytes)] + pub fn get_instant_lock_bytes(&self) -> Vec { + let instant_lock = self.0.instant_lock(); + serialize(instant_lock) + } + + #[wasm_bindgen(js_name = "createIdentityId")] + pub fn create_identifier(&self) -> Result { + let identifier = self.0.create_identifier().with_js_error()?; + + Ok(identifier.into()) + } +} diff --git a/packages/wasm-dpp2/src/asset_lock_proof/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/mod.rs new file mode 100644 index 00000000000..4837d556745 --- /dev/null +++ b/packages/wasm-dpp2/src/asset_lock_proof/mod.rs @@ -0,0 +1,175 @@ +pub mod chain; +pub mod instant; +pub mod outpoint; +mod tx_out; + +use crate::asset_lock_proof::chain::ChainAssetLockProofWASM; +use crate::asset_lock_proof::instant::InstantAssetLockProofWASM; + +use crate::asset_lock_proof::outpoint::OutPointWASM; +use crate::enums::lock_types::AssetLockProofTypeWASM; +use crate::identifier::IdentifierWASM; +use crate::utils::{IntoWasm, WithJsError, get_class_type}; +use dpp::prelude::AssetLockProof; +use serde::Serialize; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "AssetLockProofWASM")] +#[derive(Clone)] +pub struct AssetLockProofWASM(AssetLockProof); + +impl From for AssetLockProof { + fn from(proof: AssetLockProofWASM) -> Self { + proof.0 + } +} + +impl From for AssetLockProofWASM { + fn from(proof: AssetLockProof) -> Self { + AssetLockProofWASM(proof) + } +} + +impl From for AssetLockProofWASM { + fn from(proof: ChainAssetLockProofWASM) -> Self { + AssetLockProofWASM(AssetLockProof::Chain(proof.into())) + } +} + +impl From for AssetLockProofWASM { + fn from(proof: InstantAssetLockProofWASM) -> Self { + AssetLockProofWASM(AssetLockProof::Instant(proof.into())) + } +} + +impl From for ChainAssetLockProofWASM { + fn from(proof: AssetLockProof) -> ChainAssetLockProofWASM { + match proof { + AssetLockProof::Chain(chain) => ChainAssetLockProofWASM::from(chain), + _ => panic!("invalid asset lock proof. must contains chain lock"), + } + } +} + +impl From for InstantAssetLockProofWASM { + fn from(proof: AssetLockProof) -> InstantAssetLockProofWASM { + match proof { + AssetLockProof::Instant(instant) => InstantAssetLockProofWASM::from(instant), + _ => panic!("invalid asset lock proof. must contains chain lock"), + } + } +} + +#[wasm_bindgen] +impl AssetLockProofWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "AssetLockProofWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "AssetLockProofWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(js_asset_lock_proof: &JsValue) -> Result { + match get_class_type(js_asset_lock_proof)?.as_str() { + "ChainAssetLockProofWASM" => { + let chain_lock = js_asset_lock_proof + .to_wasm::("ChainAssetLockProofWASM")? + .clone(); + + Ok(AssetLockProofWASM::from(chain_lock)) + } + "InstantAssetLockProofWASM" => { + let instant_lock = js_asset_lock_proof + .to_wasm::("InstantAssetLockProofWASM")? + .clone(); + + Ok(AssetLockProofWASM::from(instant_lock)) + } + &_ => Err(JsValue::from("Invalid asset lock proof type.")), + } + } + + #[wasm_bindgen(js_name = "createInstantAssetLockProof")] + pub fn new_instant_asset_lock_proof( + instant_lock: Vec, + transaction: Vec, + output_index: u32, + ) -> Result { + Ok(InstantAssetLockProofWASM::new(instant_lock, transaction, output_index)?.into()) + } + + #[wasm_bindgen(js_name = "createChainAssetLockProof")] + pub fn new_chain_asset_lock_proof( + core_chain_locked_height: u32, + out_point: &OutPointWASM, + ) -> Result { + Ok(ChainAssetLockProofWASM::new(core_chain_locked_height, out_point)?.into()) + } + + #[wasm_bindgen(js_name = "getLockType")] + pub fn get_lock_type(&self) -> String { + match self.0 { + AssetLockProof::Chain(_) => AssetLockProofTypeWASM::Chain.into(), + AssetLockProof::Instant(_) => AssetLockProofTypeWASM::Instant.into(), + } + } + + #[wasm_bindgen(js_name = "getInstantLockProof")] + pub fn get_instant_lock(&self) -> InstantAssetLockProofWASM { + self.clone().0.into() + } + + #[wasm_bindgen(js_name = "getChainLockProof")] + pub fn get_chain_lock(&self) -> ChainAssetLockProofWASM { + self.clone().0.into() + } + + #[wasm_bindgen(js_name = "getOutPoint")] + pub fn get_out_point(&self) -> Option { + match self.0.out_point() { + Some(out_point) => Some(OutPointWASM::from(out_point)), + None => None, + } + } + + #[wasm_bindgen(js_name = "createIdentityId")] + pub fn create_identifier(&self) -> Result { + let identifier = self.0.create_identifier().with_js_error()?; + + Ok(identifier.into()) + } + + #[wasm_bindgen(js_name = "toObject")] + pub fn to_object(&self) -> Result { + let json_value = self.0.to_raw_object().with_js_error()?; + + Ok(json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?) + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_string(&self) -> Result { + Ok(hex::encode( + serde_json::to_string(&self.0).map_err(|err| JsValue::from(err.to_string()))?, + )) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(asset_lock_proof: String) -> Result { + let asset_lock_proof_bytes = hex::decode(&asset_lock_proof) + .map_err(|e| JsValue::from_str(&format!("Invalid asset lock proof hex: {}", e)))?; + + let json_str = String::from_utf8(asset_lock_proof_bytes) + .map_err(|e| JsValue::from_str(&format!("Invalid UTF-8 in asset lock proof: {}", e)))?; + + let asset_lock_proof = serde_json::from_str(&json_str).map_err(|e| { + JsValue::from_str(&format!("Failed to parse asset lock proof JSON: {}", e)) + })?; + + Ok(AssetLockProofWASM(asset_lock_proof)) + } +} diff --git a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs new file mode 100644 index 00000000000..6e6c4b66c7e --- /dev/null +++ b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs @@ -0,0 +1,119 @@ +use crate::utils::IntoWasm; +use dpp::dashcore::{OutPoint, Txid}; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[wasm_bindgen(js_name = "OutPointWASM")] +#[derive(Clone)] +pub struct OutPointWASM(OutPoint); + +impl From for OutPointWASM { + fn from(outpoint: OutPoint) -> Self { + OutPointWASM(outpoint) + } +} + +impl From for OutPoint { + fn from(outpoint: OutPointWASM) -> Self { + outpoint.0 + } +} + +impl TryFrom for OutPointWASM { + type Error = JsValue; + fn try_from(value: JsValue) -> Result { + let value = value.to_wasm::("OutPointWASM")?; + + Ok(value.clone()) + } +} + +#[wasm_bindgen] +impl OutPointWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "OutPointWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "OutPointWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(txid_hex: String, vout: u32) -> Result { + let out_point = Txid::from_hex(&txid_hex).map_err(|err| JsValue::from(err.to_string()))?; + + Ok(OutPointWASM(OutPoint { + txid: out_point, + vout, + })) + } + + #[wasm_bindgen(js_name = "getVOUT")] + pub fn get_vout(&self) -> u32 { + self.0.vout + } + + #[wasm_bindgen(js_name = "getTXID")] + pub fn get_tx_id(&self) -> String { + self.0.txid.to_hex() + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Vec { + let slice: [u8; 36] = self.0.into(); + slice.to_vec() + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_hex(&self) -> String { + let slice: [u8; 36] = self.0.into(); + + encode(slice.as_slice(), Hex) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> String { + let slice: [u8; 36] = self.0.into(); + + encode(slice.as_slice(), Base64) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(js_buffer: Vec) -> OutPointWASM { + let mut buffer = [0u8; 36]; + let bytes = js_buffer.as_slice(); + let len = bytes.len(); + buffer[..len].copy_from_slice(bytes); + + OutPointWASM(OutPoint::from(buffer)) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + Ok(OutPointWASM::from_bytes( + decode(hex.as_str(), Hex).map_err(JsError::from)?, + )) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> Result { + Ok(OutPointWASM::from_bytes( + decode(base64.as_str(), Base64).map_err(JsError::from)?, + )) + } +} + +impl OutPointWASM { + pub fn vec_from_js_value(js_outpoints: &js_sys::Array) -> Result, JsValue> { + let outpoints: Vec = js_outpoints + .iter() + .map(|key| OutPointWASM::try_from(key)) + .collect::, JsValue>>()?; + + Ok(outpoints) + } +} diff --git a/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs new file mode 100644 index 00000000000..e6050a427ff --- /dev/null +++ b/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs @@ -0,0 +1,90 @@ +use dpp::dashcore::{ScriptBuf, TxOut}; +use js_sys::Uint8Array; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "TxOutWASM")] +#[derive(Clone)] +pub struct TxOutWASM(TxOut); + +impl From for TxOutWASM { + fn from(value: TxOut) -> Self { + TxOutWASM(value) + } +} + +impl From for TxOut { + fn from(value: TxOutWASM) -> Self { + value.0 + } +} + +#[wasm_bindgen] +impl TxOutWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TxOutWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TxOutWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(value: u64, script_pubkey: JsValue) -> Result { + let tx_out: Result = match script_pubkey.is_array() { + true => Ok(TxOut { + value, + script_pubkey: ScriptBuf::from_bytes(Uint8Array::from(script_pubkey).to_vec()), + }), + false => match script_pubkey.is_string() { + true => Ok(TxOut { + value, + script_pubkey: ScriptBuf::from_hex(&script_pubkey.as_string().unwrap()) + .map_err(|err| JsValue::from(err.to_string()))?, + }), + false => Err(JsValue::from("Invalid script pubkey")), + }, + }; + + Ok(TxOutWASM(tx_out?)) + } + + #[wasm_bindgen(getter = "value")] + pub fn get_value(&self) -> u64 { + self.0.value + } + + #[wasm_bindgen(getter = "scriptPubKeyHex")] + pub fn get_script_pubkey_hex(&self) -> String { + self.0.script_pubkey.to_hex_string() + } + + #[wasm_bindgen(getter = "scriptPubKeyBytes")] + pub fn get_script_pubkey_bytes(&self) -> Vec { + self.0.script_pubkey.to_bytes() + } + + #[wasm_bindgen(setter = "value")] + pub fn set_value(&mut self, value: u64) { + self.0.value = value; + } + + #[wasm_bindgen(setter = "scriptPubKeyHex")] + pub fn set_script_pubkey_hex(&mut self, script_pubkey_hex: String) -> Result<(), JsValue> { + self.0.script_pubkey = ScriptBuf::from_hex(&script_pubkey_hex) + .map_err(|err| JsValue::from(err.to_string()))?; + Ok(()) + } + + #[wasm_bindgen(setter = "scriptPubKeyBytes")] + pub fn set_script_pubkey_bytes(&mut self, script_pubkey_bytes: Vec) { + self.0.script_pubkey = ScriptBuf::from_bytes(script_pubkey_bytes); + } + + #[wasm_bindgen(js_name = "getScriptPubKeyASM")] + pub fn get_script_pubkey_asm(&self) -> String { + self.0.script_pubkey.to_asm_string() + } +} diff --git a/packages/wasm-dpp2/src/batch/batched_transition/mod.rs b/packages/wasm-dpp2/src/batch/batched_transition/mod.rs new file mode 100644 index 00000000000..697ef08bbfe --- /dev/null +++ b/packages/wasm-dpp2/src/batch/batched_transition/mod.rs @@ -0,0 +1,110 @@ +use crate::batch::document_transition::DocumentTransitionWASM; +use crate::batch::token_transition::TokenTransitionWASM; +use crate::identifier::IdentifierWASM; +use crate::utils::{IntoWasm, get_class_type}; +use dpp::state_transition::batch_transition::batched_transition::BatchedTransition; +use dpp::state_transition::batch_transition::batched_transition::document_transition::{ + DocumentTransition, DocumentTransitionV0Methods, +}; +use dpp::state_transition::batch_transition::batched_transition::token_transition::{ + TokenTransition, TokenTransitionV0Methods, +}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=BatchedTransitionWASM)] +pub struct BatchedTransitionWASM(BatchedTransition); + +impl From for BatchedTransitionWASM { + fn from(v: BatchedTransition) -> Self { + BatchedTransitionWASM(v) + } +} + +impl From for BatchedTransition { + fn from(v: BatchedTransitionWASM) -> Self { + v.0 + } +} + +#[wasm_bindgen] +impl BatchedTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "BatchedTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "BatchedTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(js_transition: &JsValue) -> Result { + match js_transition.is_undefined() && js_transition.is_object() { + true => Err(JsValue::from_str("transition is undefined")), + false => match get_class_type(js_transition)?.as_str() { + "TokenTransitionWASM" => Ok(BatchedTransitionWASM::from(BatchedTransition::from( + TokenTransition::from( + js_transition + .to_wasm::("TokenTransitionWASM")? + .clone(), + ), + ))), + "DocumentTransitionWASM" => Ok(BatchedTransitionWASM(BatchedTransition::Document( + DocumentTransition::from( + js_transition + .to_wasm::("DocumentTransitionWASM")? + .clone(), + ), + ))), + _ => Err(JsValue::from_str("Invalid transition type")), + }, + } + } + + #[wasm_bindgen(js_name = "toTransition")] + pub fn to_transition(&self) -> JsValue { + match &self.0 { + BatchedTransition::Document(document_transition) => { + DocumentTransitionWASM::from(document_transition.clone()).into() + } + BatchedTransition::Token(token_transition) => { + TokenTransitionWASM::from(token_transition.clone()).into() + } + } + } + + #[wasm_bindgen(getter = "dataContractId")] + pub fn data_contract_id(&self) -> IdentifierWASM { + match self.0.clone() { + BatchedTransition::Document(document_transition) => { + document_transition.data_contract_id().into() + } + BatchedTransition::Token(token_transition) => { + token_transition.data_contract_id().into() + } + } + } + + #[wasm_bindgen(setter = "dataContractId")] + pub fn set_data_contract_id(&mut self, js_contract_id: &JsValue) -> Result<(), JsValue> { + let contract_id = IdentifierWASM::try_from(js_contract_id)?; + + self.0 = match self.0.clone() { + BatchedTransition::Document(mut document_transition) => { + document_transition.set_data_contract_id(contract_id.into()); + + BatchedTransition::Document(document_transition) + } + BatchedTransition::Token(mut token_transition) => { + token_transition.set_data_contract_id(contract_id.into()); + + BatchedTransition::Token(token_transition) + } + }; + + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs b/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs new file mode 100644 index 00000000000..dfc91e50c7a --- /dev/null +++ b/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs @@ -0,0 +1,129 @@ +use crate::batch::token_payment_info::TokenPaymentInfoWASM; +use crate::identifier::IdentifierWASM; +use crate::utils::IntoWasm; +use dpp::prelude::IdentityNonce; +use dpp::state_transition::batch_transition::document_base_transition::DocumentBaseTransition; +use dpp::state_transition::batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods; +use dpp::state_transition::batch_transition::document_base_transition::v1::DocumentBaseTransitionV1; +use dpp::state_transition::batch_transition::document_base_transition::v1::v1_methods::DocumentBaseTransitionV1Methods; +use dpp::tokens::token_payment_info::TokenPaymentInfo; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name = "DocumentBaseTransitionWASM")] +pub struct DocumentBaseTransitionWASM(DocumentBaseTransition); + +impl From for DocumentBaseTransitionWASM { + fn from(v: DocumentBaseTransition) -> Self { + DocumentBaseTransitionWASM(v) + } +} + +impl From for DocumentBaseTransition { + fn from(v: DocumentBaseTransitionWASM) -> Self { + v.0 + } +} + +#[wasm_bindgen] +impl DocumentBaseTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DocumentBaseTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DocumentBaseTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_document_id: &JsValue, + identity_contract_nonce: IdentityNonce, + document_type_name: String, + js_data_contract_id: &JsValue, + js_token_payment_info: &JsValue, + ) -> Result { + let token_payment_info: Option = + match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { + true => None, + false => Some( + js_token_payment_info + .to_wasm::("TokenPaymentInfoWASM")? + .clone() + .into(), + ), + }; + + let rs_base_v1 = DocumentBaseTransitionV1 { + id: IdentifierWASM::try_from(js_document_id)?.into(), + identity_contract_nonce, + document_type_name, + data_contract_id: IdentifierWASM::try_from(js_data_contract_id)?.into(), + token_payment_info, + }; + + Ok(DocumentBaseTransitionWASM(DocumentBaseTransition::from( + rs_base_v1, + ))) + } + + #[wasm_bindgen(getter = "id")] + pub fn get_id(&self) -> IdentifierWASM { + self.0.id().into() + } + + #[wasm_bindgen(getter = "identityContractNonce")] + pub fn get_identity_contract_nonce(&self) -> IdentityNonce { + self.0.identity_contract_nonce() + } + + #[wasm_bindgen(getter = "dataContractId")] + pub fn get_data_contract_id(&self) -> IdentifierWASM { + self.0.data_contract_id().into() + } + + #[wasm_bindgen(getter = "documentTypeName")] + pub fn get_document_type_name(&self) -> String { + self.0.document_type_name().to_string() + } + + #[wasm_bindgen(getter = "tokenPaymentInfo")] + pub fn get_token_payment_info(&self) -> Option { + match self.0.token_payment_info() { + None => None, + Some(info) => Some(info.into()), + } + } + + #[wasm_bindgen(setter = "id")] + pub fn set_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { + self.0.set_id(IdentifierWASM::try_from(js_id)?.into()); + Ok(()) + } + + #[wasm_bindgen(setter = "identityContractNonce")] + pub fn set_identity_contract_nonce(&mut self, nonce: IdentityNonce) { + self.0.set_identity_contract_nonce(nonce) + } + + #[wasm_bindgen(setter = "dataContractId")] + pub fn set_data_contract_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> { + self.0 + .set_data_contract_id(IdentifierWASM::try_from(js_data_contract_id)?.into()); + Ok(()) + } + + #[wasm_bindgen(setter = "documentTypeName")] + pub fn set_document_type_name(&mut self, document_type_name: String) { + self.0.set_document_type_name(document_type_name) + } + + #[wasm_bindgen(setter = "tokenPaymentInfo")] + pub fn set_token_payment_info(&mut self, token_payment_info: &TokenPaymentInfoWASM) { + self.0 + .set_token_payment_info(token_payment_info.clone().into()) + } +} diff --git a/packages/wasm-dpp2/src/batch/document_transition/mod.rs b/packages/wasm-dpp2/src/batch/document_transition/mod.rs new file mode 100644 index 00000000000..cdfcebb9160 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/document_transition/mod.rs @@ -0,0 +1,189 @@ +use crate::batch::document_transitions::create::DocumentCreateTransitionWASM; +use crate::batch::document_transitions::delete::DocumentDeleteTransitionWASM; +use crate::batch::document_transitions::purchase::DocumentPurchaseTransitionWASM; +use crate::batch::document_transitions::replace::DocumentReplaceTransitionWASM; +use crate::batch::document_transitions::transfer::DocumentTransferTransitionWASM; +use crate::batch::document_transitions::update_price::DocumentUpdatePriceTransitionWASM; +use dpp::prelude::{Identifier, IdentityNonce, Revision}; +use dpp::state_transition::batch_transition::batched_transition::document_transition::{ + DocumentTransition, DocumentTransitionV0Methods, +}; +use dpp::state_transition::batch_transition::batched_transition::document_transition_action_type::{DocumentTransitionActionType, DocumentTransitionActionTypeGetter}; +use crate::enums::batch::batch_enum::BatchTypeWASM; +use crate::identifier::IdentifierWASM; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name = "DocumentTransitionWASM")] +pub struct DocumentTransitionWASM(DocumentTransition); + +impl From for DocumentTransitionWASM { + fn from(transition: DocumentTransition) -> Self { + DocumentTransitionWASM(transition) + } +} + +impl From for DocumentTransition { + fn from(transition: DocumentTransitionWASM) -> Self { + transition.0 + } +} + +#[wasm_bindgen] +impl DocumentTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DocumentTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DocumentTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = "actionType")] + pub fn get_action_type(&self) -> String { + BatchTypeWASM::from(self.0.action_type()).into() + } + + #[wasm_bindgen(getter = "actionTypeNumber")] + pub fn get_action_type_number(&self) -> u8 { + match self.0.action_type() { + DocumentTransitionActionType::Create => 0, + DocumentTransitionActionType::Replace => 1, + DocumentTransitionActionType::Delete => 2, + DocumentTransitionActionType::Transfer => 3, + DocumentTransitionActionType::Purchase => 4, + DocumentTransitionActionType::UpdatePrice => 5, + DocumentTransitionActionType::IgnoreWhileBumpingRevision => 6, + } + } + + #[wasm_bindgen(getter = "dataContractId")] + pub fn get_data_contract_id(&self) -> IdentifierWASM { + self.0.data_contract_id().into() + } + + #[wasm_bindgen(getter = "id")] + pub fn get_id(&self) -> IdentifierWASM { + self.0.get_id().into() + } + + #[wasm_bindgen(getter = "documentTypeName")] + pub fn get_document_type_name(&self) -> String { + self.0.document_type_name().clone() + } + + #[wasm_bindgen(getter = "identityContractNonce")] + pub fn get_identity_contract_nonce(&self) -> IdentityNonce { + self.0.identity_contract_nonce() + } + + #[wasm_bindgen(getter = "revision")] + pub fn get_revision(&self) -> Option { + self.0.revision() + } + + #[wasm_bindgen(getter = "entropy")] + pub fn get_entropy(&self) -> Option> { + self.0.entropy() + } + + #[wasm_bindgen(getter = "createTransition")] + pub fn get_create_transition(&self) -> Result { + match self.0.clone() { + DocumentTransition::Create(create) => Ok(DocumentCreateTransitionWASM::from(create)), + _ => Err(JsValue::undefined()), + } + } + + #[wasm_bindgen(getter = "replaceTransition")] + pub fn get_replace_transition(&self) -> Result { + match self.0.clone() { + DocumentTransition::Replace(replace) => { + Ok(DocumentReplaceTransitionWASM::from(replace)) + } + _ => Err(JsValue::undefined()), + } + } + + #[wasm_bindgen(getter = "deleteTransition")] + pub fn get_delete_transition(&self) -> Result { + match self.0.clone() { + DocumentTransition::Delete(delete) => Ok(DocumentDeleteTransitionWASM::from(delete)), + _ => Err(JsValue::undefined()), + } + } + + #[wasm_bindgen(getter = "purchaseTransition")] + pub fn get_purchase_transition(&self) -> Result { + match self.0.clone() { + DocumentTransition::Purchase(purchase) => { + Ok(DocumentPurchaseTransitionWASM::from(purchase)) + } + _ => Err(JsValue::undefined()), + } + } + + #[wasm_bindgen(getter = "transferTransition")] + pub fn get_transfer_transition(&self) -> Result { + match self.0.clone() { + DocumentTransition::Transfer(transfer) => { + Ok(DocumentTransferTransitionWASM::from(transfer)) + } + _ => Err(JsValue::undefined()), + } + } + + #[wasm_bindgen(getter = "updatePriceTransition")] + pub fn get_update_price_transition( + &self, + ) -> Result { + match self.0.clone() { + DocumentTransition::UpdatePrice(update_price) => { + Ok(DocumentUpdatePriceTransitionWASM::from(update_price)) + } + _ => Err(JsValue::undefined()), + } + } + + #[wasm_bindgen(setter = "dataContractId")] + pub fn set_data_contract_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> { + Ok(self + .0 + .set_data_contract_id(IdentifierWASM::try_from(js_data_contract_id)?.into())) + } + + #[wasm_bindgen(setter = "revision")] + pub fn set_revision(&mut self, revision: Revision) { + self.0.set_revision(revision) + } + + #[wasm_bindgen(setter = "identityContractNonce")] + pub fn set_identity_contract_nonce(&mut self, identity_contract_nonce: IdentityNonce) { + self.0.set_identity_contract_nonce(identity_contract_nonce) + } +} + +impl DocumentTransitionWASM { + pub fn rs_get_data_contract_id(&self) -> Identifier { + self.0.data_contract_id() + } + + pub fn rs_get_id(&self) -> Identifier { + self.0.get_id() + } + + pub fn rs_get_entropy(&self) -> Option> { + self.0.entropy() + } + + pub fn rs_get_revision(&self) -> Option { + self.0.revision() + } + + pub fn rs_get_identity_contract_nonce(&self) -> IdentityNonce { + self.0.identity_contract_nonce() + } +} diff --git a/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs new file mode 100644 index 00000000000..76eb10a02e1 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs @@ -0,0 +1,162 @@ +use crate::batch::document_base_transition::DocumentBaseTransitionWASM; +use crate::batch::document_transition::DocumentTransitionWASM; +use crate::batch::generators::generate_create_transition; +use dpp::dashcore::hashes::serde::Serialize; +use dpp::prelude::IdentityNonce; +use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; +use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; +use dpp::state_transition::batch_transition::document_create_transition::v0::v0_methods::DocumentCreateTransitionV0Methods; +use dpp::state_transition::batch_transition::DocumentCreateTransition; +use crate::document::DocumentWASM; +use crate::utils::{IntoWasm, ToSerdeJSONExt}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::batch::prefunded_voting_balance::PrefundedVotingBalanceWASM; +use crate::batch::token_payment_info::TokenPaymentInfoWASM; + +#[wasm_bindgen(js_name = "DocumentCreateTransitionWASM")] +#[derive(Clone)] +pub struct DocumentCreateTransitionWASM(DocumentCreateTransition); + +impl From for DocumentCreateTransition { + fn from(transition: DocumentCreateTransitionWASM) -> Self { + transition.0 + } +} + +impl From for DocumentCreateTransitionWASM { + fn from(transition: DocumentCreateTransition) -> Self { + DocumentCreateTransitionWASM(transition) + } +} + +#[wasm_bindgen] +impl DocumentCreateTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DocumentCreateTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DocumentCreateTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + document: &DocumentWASM, + identity_contract_nonce: IdentityNonce, + js_prefunded_voting_balance: &JsValue, + js_token_payment_info: &JsValue, + ) -> Result { + let prefunded_voting_balance = match js_prefunded_voting_balance.is_undefined() + | js_prefunded_voting_balance.is_null() + { + true => None, + false => Some( + js_prefunded_voting_balance + .to_wasm::("PrefundedVotingBalanceWASM")? + .clone(), + ), + }; + + let token_payment_info = + match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { + true => None, + false => Some( + js_token_payment_info + .to_wasm::("TokenPaymentInfoWASM")? + .clone(), + ), + }; + + let rs_create_transition = generate_create_transition( + document.clone(), + identity_contract_nonce, + document.get_document_type_name().to_string(), + prefunded_voting_balance, + token_payment_info, + ); + + Ok(DocumentCreateTransitionWASM(rs_create_transition)) + } + + #[wasm_bindgen(getter = "data")] + pub fn get_data(&self) -> Result { + let serializer = serde_wasm_bindgen::Serializer::json_compatible(); + + self.0.data().serialize(&serializer).map_err(JsValue::from) + } + + #[wasm_bindgen(getter = "base")] + pub fn get_base(&self) -> DocumentBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = "entropy")] + pub fn get_entropy(&self) -> Vec { + self.0.entropy().to_vec() + } + + #[wasm_bindgen(setter = "data")] + pub fn set_data(&mut self, js_data: JsValue) -> Result<(), JsValue> { + let data = js_data.with_serde_to_platform_value_map()?; + + Ok(self.0.set_data(data)) + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) { + self.0.set_base(base.clone().into()) + } + + #[wasm_bindgen(setter = "entropy")] + pub fn set_entropy(&mut self, js_entropy: Vec) -> Result<(), JsValue> { + let mut entropy = [0u8; 32]; + let bytes = js_entropy.as_slice(); + let len = bytes.len().min(32); + entropy[..len].copy_from_slice(&bytes[..len]); + + Ok(self.0.set_entropy(entropy)) + } + + #[wasm_bindgen(getter = "prefundedVotingBalance")] + pub fn get_prefunded_voting_balance(&self) -> Option { + let rs_balance = self.0.prefunded_voting_balance(); + + match rs_balance { + Some(balance) => Some(balance.clone().into()), + None => None, + } + } + + #[wasm_bindgen(setter = "prefundedVotingBalance")] + pub fn set_prefunded_voting_balance( + &mut self, + prefunded_voting_balance: &PrefundedVotingBalanceWASM, + ) { + self.0.set_prefunded_voting_balance( + prefunded_voting_balance.index_name(), + prefunded_voting_balance.credits(), + ) + } + + #[wasm_bindgen(js_name = "clearPrefundedVotingBalance")] + pub fn clear_prefunded_voting_balance(&mut self) { + self.0.clear_prefunded_voting_balance() + } + + #[wasm_bindgen(js_name = "toDocumentTransition")] + pub fn to_document_transition(&self) -> DocumentTransitionWASM { + let rs_transition = DocumentTransition::from(self.0.clone()); + + DocumentTransitionWASM::from(rs_transition) + } + + #[wasm_bindgen(js_name = "fromDocumentTransition")] + pub fn from_document_transition( + js_transition: DocumentTransitionWASM, + ) -> Result { + js_transition.get_create_transition() + } +} diff --git a/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs new file mode 100644 index 00000000000..31c5ad26d66 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs @@ -0,0 +1,90 @@ +use crate::batch::document_base_transition::DocumentBaseTransitionWASM; +use crate::batch::document_transition::DocumentTransitionWASM; +use crate::batch::generators::generate_delete_transition; +use dpp::prelude::IdentityNonce; +use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; +use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; +use dpp::state_transition::batch_transition::DocumentDeleteTransition; +use crate::document::DocumentWASM; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::utils::IntoWasm; +use crate::batch::token_payment_info::TokenPaymentInfoWASM; + +#[wasm_bindgen(js_name = "DocumentDeleteTransitionWASM")] +pub struct DocumentDeleteTransitionWASM(DocumentDeleteTransition); + +impl From for DocumentDeleteTransitionWASM { + fn from(document_delete_transition: DocumentDeleteTransition) -> Self { + DocumentDeleteTransitionWASM(document_delete_transition) + } +} + +#[wasm_bindgen] +impl DocumentDeleteTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DocumentDeleteTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DocumentDeleteTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + document: &DocumentWASM, + identity_contract_nonce: IdentityNonce, + js_token_payment_info: &JsValue, + ) -> Result { + let token_payment_info = + match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { + true => None, + false => Some( + js_token_payment_info + .to_wasm::("TokenPaymentInfoWASM")? + .clone(), + ), + }; + + let rs_delete_transition = generate_delete_transition( + document.clone(), + identity_contract_nonce, + document.get_document_type_name().to_string(), + token_payment_info, + ); + + Ok(DocumentDeleteTransitionWASM(rs_delete_transition)) + } + + #[wasm_bindgen(getter = "base")] + pub fn get_base(&self) -> DocumentBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) { + self.0.set_base(base.clone().into()) + } + + #[wasm_bindgen(js_name = "toDocumentTransition")] + pub fn to_document_transition(&self) -> DocumentTransitionWASM { + let rs_transition = DocumentTransition::from(self.0.clone()); + + DocumentTransitionWASM::from(rs_transition) + } + + #[wasm_bindgen(js_name = "fromDocumentTransition")] + pub fn from_document_transition( + js_transition: DocumentTransitionWASM, + ) -> Result { + js_transition.get_delete_transition() + } +} + +impl From for DocumentDeleteTransition { + fn from(document_delete_transition: DocumentDeleteTransitionWASM) -> Self { + document_delete_transition.0 + } +} diff --git a/packages/wasm-dpp2/src/batch/document_transitions/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/mod.rs new file mode 100644 index 00000000000..f6ac52b077e --- /dev/null +++ b/packages/wasm-dpp2/src/batch/document_transitions/mod.rs @@ -0,0 +1,6 @@ +pub mod create; +pub mod delete; +pub mod purchase; +pub mod replace; +pub mod transfer; +pub mod update_price; diff --git a/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs new file mode 100644 index 00000000000..4b9dd62ac85 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs @@ -0,0 +1,116 @@ +use dpp::fee::Credits; +use dpp::prelude::{IdentityNonce, Revision}; +use dpp::state_transition::batch_transition::batched_transition::document_purchase_transition::v0::v0_methods::DocumentPurchaseTransitionV0Methods; +use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; +use dpp::state_transition::batch_transition::batched_transition::DocumentPurchaseTransition; +use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::document::DocumentWASM; +use crate::utils::IntoWasm; +use crate::batch::document_base_transition::DocumentBaseTransitionWASM; +use crate::batch::document_transition::DocumentTransitionWASM; +use crate::batch::generators::generate_purchase_transition; +use crate::batch::token_payment_info::TokenPaymentInfoWASM; + +#[wasm_bindgen(js_name = "DocumentPurchaseTransitionWASM")] +pub struct DocumentPurchaseTransitionWASM(DocumentPurchaseTransition); + +impl From for DocumentPurchaseTransition { + fn from(transition: DocumentPurchaseTransitionWASM) -> Self { + transition.0 + } +} + +impl From for DocumentPurchaseTransitionWASM { + fn from(transition: DocumentPurchaseTransition) -> Self { + DocumentPurchaseTransitionWASM(transition) + } +} + +#[wasm_bindgen] +impl DocumentPurchaseTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DocumentPurchaseTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DocumentPurchaseTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + document: &DocumentWASM, + identity_contract_nonce: IdentityNonce, + amount: Credits, + js_token_payment_info: &JsValue, + ) -> Result { + let token_payment_info = + match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { + true => None, + false => Some( + js_token_payment_info + .to_wasm::("TokenPaymentInfoWASM")? + .clone(), + ), + }; + + let rs_purchase_transition = generate_purchase_transition( + document.clone(), + identity_contract_nonce, + document.get_document_type_name().to_string(), + amount, + token_payment_info, + ); + + Ok(DocumentPurchaseTransitionWASM(rs_purchase_transition)) + } + + #[wasm_bindgen(getter = "base")] + pub fn get_base(&self) -> DocumentBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = "price")] + pub fn get_price(&self) -> Credits { + self.0.price() + } + + #[wasm_bindgen(getter = "revision")] + pub fn get_revision(&self) -> Revision { + self.0.revision() + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) { + self.0.set_base(base.clone().into()) + } + + #[wasm_bindgen(setter = "price")] + pub fn set_price(&mut self, price: Credits) { + match self.0 { + DocumentPurchaseTransition::V0(ref mut v0) => v0.price = price, + } + } + + #[wasm_bindgen(setter = "revision")] + pub fn set_revision(&mut self, revision: Revision) { + self.0.set_revision(revision); + } + + #[wasm_bindgen(js_name = "toDocumentTransition")] + pub fn to_document_transition(&self) -> DocumentTransitionWASM { + let rs_transition = DocumentTransition::from(self.0.clone()); + + DocumentTransitionWASM::from(rs_transition) + } + + #[wasm_bindgen(js_name = "fromDocumentTransition")] + pub fn from_document_transition( + js_transition: DocumentTransitionWASM, + ) -> Result { + js_transition.get_purchase_transition() + } +} diff --git a/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs new file mode 100644 index 00000000000..ed0f5969734 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs @@ -0,0 +1,116 @@ +use dpp::dashcore::hashes::serde::Serialize; +use dpp::prelude::{IdentityNonce, Revision}; +use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; +use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; +use dpp::state_transition::batch_transition::document_replace_transition::v0::v0_methods::DocumentReplaceTransitionV0Methods; +use dpp::state_transition::batch_transition::DocumentReplaceTransition; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::document::DocumentWASM; +use crate::utils::{IntoWasm, ToSerdeJSONExt}; +use crate::batch::document_base_transition::DocumentBaseTransitionWASM; +use crate::batch::generators::generate_replace_transition; +use crate::batch::document_transition::DocumentTransitionWASM; +use crate::batch::token_payment_info::TokenPaymentInfoWASM; + +#[wasm_bindgen(js_name = "DocumentReplaceTransitionWASM")] +pub struct DocumentReplaceTransitionWASM(DocumentReplaceTransition); + +impl From for DocumentReplaceTransitionWASM { + fn from(document_replace: DocumentReplaceTransition) -> Self { + DocumentReplaceTransitionWASM(document_replace) + } +} + +impl From for DocumentReplaceTransition { + fn from(document_replace: DocumentReplaceTransitionWASM) -> Self { + document_replace.0 + } +} + +#[wasm_bindgen] +impl DocumentReplaceTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DocumentReplaceTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DocumentReplaceTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + document: &DocumentWASM, + identity_contract_nonce: IdentityNonce, + js_token_payment_info: &JsValue, + ) -> Result { + let token_payment_info = + match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { + true => None, + false => Some( + js_token_payment_info + .to_wasm::("TokenPaymentInfoWASM")? + .clone(), + ), + }; + + let rs_update_transition = generate_replace_transition( + document.clone(), + identity_contract_nonce, + document.get_document_type_name().to_string(), + token_payment_info, + ); + + Ok(DocumentReplaceTransitionWASM(rs_update_transition)) + } + + #[wasm_bindgen(getter = "data")] + pub fn get_data(&self) -> Result { + let serializer = serde_wasm_bindgen::Serializer::json_compatible(); + + self.0.data().serialize(&serializer).map_err(JsValue::from) + } + + #[wasm_bindgen(getter = "base")] + pub fn get_base(&self) -> DocumentBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = "revision")] + pub fn get_revision(&self) -> Revision { + self.0.revision() + } + + #[wasm_bindgen(setter = "data")] + pub fn set_data(&mut self, js_data: JsValue) -> Result<(), JsValue> { + let data = js_data.with_serde_to_platform_value_map()?; + + Ok(self.0.set_data(data)) + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) { + self.0.set_base(base.clone().into()) + } + + #[wasm_bindgen(setter = "revision")] + pub fn set_revision(&mut self, revision: Revision) { + self.0.set_revision(revision); + } + + #[wasm_bindgen(js_name = "toDocumentTransition")] + pub fn to_document_transition(&self) -> DocumentTransitionWASM { + let rs_transition = DocumentTransition::from(self.0.clone()); + + DocumentTransitionWASM::from(rs_transition) + } + + #[wasm_bindgen(js_name = "fromDocumentTransition")] + pub fn from_document_transition( + js_transition: DocumentTransitionWASM, + ) -> Result { + js_transition.get_replace_transition() + } +} diff --git a/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs new file mode 100644 index 00000000000..047d24eb88f --- /dev/null +++ b/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs @@ -0,0 +1,109 @@ +use dpp::prelude::IdentityNonce; +use dpp::state_transition::batch_transition::batched_transition::document_transfer_transition::v0::v0_methods::DocumentTransferTransitionV0Methods; +use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; +use dpp::state_transition::batch_transition::batched_transition::DocumentTransferTransition; +use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::document::DocumentWASM; +use crate::identifier::IdentifierWASM; +use crate::utils::IntoWasm; +use crate::batch::document_base_transition::DocumentBaseTransitionWASM; +use crate::batch::document_transition::DocumentTransitionWASM; +use crate::batch::generators::generate_transfer_transition; +use crate::batch::token_payment_info::TokenPaymentInfoWASM; + +#[wasm_bindgen(js_name = "DocumentTransferTransitionWASM")] +pub struct DocumentTransferTransitionWASM(DocumentTransferTransition); + +impl From for DocumentTransferTransitionWASM { + fn from(transition: DocumentTransferTransition) -> Self { + DocumentTransferTransitionWASM(transition) + } +} + +impl From for DocumentTransferTransition { + fn from(transition: DocumentTransferTransitionWASM) -> Self { + transition.0 + } +} + +#[wasm_bindgen] +impl DocumentTransferTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DocumentTransferTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DocumentTransferTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + document: &DocumentWASM, + identity_contract_nonce: IdentityNonce, + js_recipient_owner_id: &JsValue, + js_token_payment_info: &JsValue, + ) -> Result { + let token_payment_info = + match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { + true => None, + false => Some( + js_token_payment_info + .to_wasm::("TokenPaymentInfoWASM")? + .clone(), + ), + }; + + let rs_transfer_transition = generate_transfer_transition( + document.clone(), + identity_contract_nonce, + document.get_document_type_name().to_string(), + IdentifierWASM::try_from(js_recipient_owner_id)?.into(), + token_payment_info, + ); + + Ok(DocumentTransferTransitionWASM(rs_transfer_transition)) + } + + #[wasm_bindgen(getter = "base")] + pub fn get_base(&self) -> DocumentBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = "recipientId")] + pub fn get_recipient_owner_id(&self) -> IdentifierWASM { + self.0.recipient_owner_id().into() + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) { + self.0.set_base(base.clone().into()) + } + + #[wasm_bindgen(setter = "recipientId")] + pub fn set_recipient_owner_id( + &mut self, + js_recipient_owner_id: &JsValue, + ) -> Result<(), JsValue> { + self.0 + .set_recipient_owner_id(IdentifierWASM::try_from(js_recipient_owner_id)?.into()); + Ok(()) + } + + #[wasm_bindgen(js_name = "toDocumentTransition")] + pub fn to_document_transition(&self) -> DocumentTransitionWASM { + let rs_transition = DocumentTransition::from(self.0.clone()); + + DocumentTransitionWASM::from(rs_transition) + } + + #[wasm_bindgen(js_name = "fromDocumentTransition")] + pub fn from_document_transition( + js_transition: DocumentTransitionWASM, + ) -> Result { + js_transition.get_transfer_transition() + } +} diff --git a/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs new file mode 100644 index 00000000000..0511d8c8dd0 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs @@ -0,0 +1,100 @@ +use dpp::fee::Credits; +use dpp::prelude::IdentityNonce; +use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; +use dpp::state_transition::batch_transition::batched_transition::document_update_price_transition::v0::v0_methods::DocumentUpdatePriceTransitionV0Methods; +use dpp::state_transition::batch_transition::batched_transition::DocumentUpdatePriceTransition; +use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::document::DocumentWASM; +use crate::utils::IntoWasm; +use crate::batch::document_base_transition::DocumentBaseTransitionWASM; +use crate::batch::document_transition::DocumentTransitionWASM; +use crate::batch::generators::generate_update_price_transition; +use crate::batch::token_payment_info::TokenPaymentInfoWASM; + +#[wasm_bindgen(js_name = "DocumentUpdatePriceTransitionWASM")] +pub struct DocumentUpdatePriceTransitionWASM(DocumentUpdatePriceTransition); + +impl From for DocumentUpdatePriceTransitionWASM { + fn from(document_update_price_transition: DocumentUpdatePriceTransition) -> Self { + DocumentUpdatePriceTransitionWASM(document_update_price_transition) + } +} + +#[wasm_bindgen] +impl DocumentUpdatePriceTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DocumentUpdatePriceTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DocumentUpdatePriceTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + document: &DocumentWASM, + identity_contract_nonce: IdentityNonce, + price: Credits, + js_token_payment_info: &JsValue, + ) -> Result { + let token_payment_info = + match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { + true => None, + false => Some( + js_token_payment_info + .to_wasm::("TokenPaymentInfoWASM")? + .clone(), + ), + }; + + let rs_document_update_price_transition = generate_update_price_transition( + document.clone(), + identity_contract_nonce, + document.get_document_type_name().to_string(), + price, + token_payment_info, + ); + + Ok(DocumentUpdatePriceTransitionWASM( + rs_document_update_price_transition, + )) + } + + #[wasm_bindgen(getter = "base")] + pub fn get_base(&self) -> DocumentBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = "price")] + pub fn get_price(&self) -> Credits { + self.0.price() + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) { + self.0.set_base(base.clone().into()) + } + + #[wasm_bindgen(setter = "price")] + pub fn set_price(&mut self, price: Credits) { + self.0.set_price(price) + } + + #[wasm_bindgen(js_name = "toDocumentTransition")] + pub fn to_document_transition(&self) -> DocumentTransitionWASM { + let rs_transition = DocumentTransition::from(self.0.clone()); + + DocumentTransitionWASM::from(rs_transition) + } + + #[wasm_bindgen(js_name = "fromDocumentTransition")] + pub fn from_document_transition( + js_transition: DocumentTransitionWASM, + ) -> Result { + js_transition.get_update_price_transition() + } +} diff --git a/packages/wasm-dpp2/src/batch/generators.rs b/packages/wasm-dpp2/src/batch/generators.rs new file mode 100644 index 00000000000..99d282f74ff --- /dev/null +++ b/packages/wasm-dpp2/src/batch/generators.rs @@ -0,0 +1,137 @@ +use crate::batch::prefunded_voting_balance::PrefundedVotingBalanceWASM; +use crate::batch::token_payment_info::TokenPaymentInfoWASM; +use crate::document::DocumentWASM; +use dpp::fee::Credits; +use dpp::prelude::{Identifier, IdentityNonce}; +use dpp::state_transition::batch_transition::batched_transition::document_purchase_transition::DocumentPurchaseTransitionV0; +use dpp::state_transition::batch_transition::batched_transition::document_transfer_transition::DocumentTransferTransitionV0; +use dpp::state_transition::batch_transition::batched_transition::document_update_price_transition::DocumentUpdatePriceTransitionV0; +use dpp::state_transition::batch_transition::batched_transition::{ + DocumentPurchaseTransition, DocumentTransferTransition, DocumentUpdatePriceTransition, +}; +use dpp::state_transition::batch_transition::document_base_transition::DocumentBaseTransition; +use dpp::state_transition::batch_transition::document_base_transition::v1::DocumentBaseTransitionV1; +use dpp::state_transition::batch_transition::document_create_transition::DocumentCreateTransitionV0; +use dpp::state_transition::batch_transition::document_delete_transition::DocumentDeleteTransitionV0; +use dpp::state_transition::batch_transition::document_replace_transition::DocumentReplaceTransitionV0; +use dpp::state_transition::batch_transition::{ + DocumentCreateTransition, DocumentDeleteTransition, DocumentReplaceTransition, +}; +use dpp::tokens::token_payment_info::TokenPaymentInfo; + +pub fn generate_create_transition( + document: DocumentWASM, + identity_contract_nonce: IdentityNonce, + document_type_name: String, + prefunded_voting_balance: Option, + token_payment_info: Option, +) -> DocumentCreateTransition { + DocumentCreateTransition::V0(DocumentCreateTransitionV0 { + base: DocumentBaseTransition::V1(DocumentBaseTransitionV1 { + id: document.rs_get_id(), + identity_contract_nonce, + document_type_name, + data_contract_id: document.rs_get_data_contract_id(), + token_payment_info: token_payment_info.map(TokenPaymentInfo::from), + }), + entropy: document.rs_get_entropy().unwrap(), + data: document.rs_get_properties(), + prefunded_voting_balance: prefunded_voting_balance.map(|pb| pb.into()), + }) +} + +pub fn generate_delete_transition( + document: DocumentWASM, + identity_contract_nonce: IdentityNonce, + document_type_name: String, + token_payment_info: Option, +) -> DocumentDeleteTransition { + DocumentDeleteTransition::V0(DocumentDeleteTransitionV0 { + base: DocumentBaseTransition::V1(DocumentBaseTransitionV1 { + id: document.rs_get_id(), + identity_contract_nonce, + document_type_name, + data_contract_id: document.rs_get_data_contract_id(), + token_payment_info: token_payment_info.map(TokenPaymentInfo::from), + }), + }) +} + +pub fn generate_replace_transition( + document: DocumentWASM, + identity_contract_nonce: IdentityNonce, + document_type_name: String, + token_payment_info: Option, +) -> DocumentReplaceTransition { + DocumentReplaceTransition::V0(DocumentReplaceTransitionV0 { + base: DocumentBaseTransition::V1(DocumentBaseTransitionV1 { + id: document.rs_get_id(), + identity_contract_nonce, + document_type_name, + data_contract_id: document.rs_get_data_contract_id(), + token_payment_info: token_payment_info.map(TokenPaymentInfo::from), + }), + revision: document.get_revision().unwrap() + 1, + data: document.rs_get_properties(), + }) +} + +pub fn generate_transfer_transition( + document: DocumentWASM, + identity_contract_nonce: IdentityNonce, + document_type_name: String, + recipient_owner_id: Identifier, + token_payment_info: Option, +) -> DocumentTransferTransition { + DocumentTransferTransition::V0(DocumentTransferTransitionV0 { + base: DocumentBaseTransition::V1(DocumentBaseTransitionV1 { + id: document.rs_get_id(), + identity_contract_nonce, + document_type_name, + data_contract_id: document.rs_get_data_contract_id(), + token_payment_info: token_payment_info.map(TokenPaymentInfo::from), + }), + revision: document.get_revision().unwrap() + 1, + recipient_owner_id, + }) +} + +pub fn generate_update_price_transition( + document: DocumentWASM, + identity_contract_nonce: IdentityNonce, + document_type_name: String, + price: Credits, + token_payment_info: Option, +) -> DocumentUpdatePriceTransition { + DocumentUpdatePriceTransition::V0(DocumentUpdatePriceTransitionV0 { + base: DocumentBaseTransition::V1(DocumentBaseTransitionV1 { + id: document.rs_get_id(), + identity_contract_nonce, + document_type_name, + data_contract_id: document.rs_get_data_contract_id(), + token_payment_info: token_payment_info.map(TokenPaymentInfo::from), + }), + revision: document.get_revision().unwrap() + 1, + price, + }) +} + +pub fn generate_purchase_transition( + document: DocumentWASM, + identity_contract_nonce: IdentityNonce, + document_type_name: String, + price: Credits, + token_payment_info: Option, +) -> DocumentPurchaseTransition { + DocumentPurchaseTransition::V0(DocumentPurchaseTransitionV0 { + base: DocumentBaseTransition::V1(DocumentBaseTransitionV1 { + id: document.rs_get_id(), + identity_contract_nonce, + document_type_name, + data_contract_id: document.rs_get_data_contract_id(), + token_payment_info: token_payment_info.map(TokenPaymentInfo::from), + }), + revision: document.get_revision().unwrap() + 1, + price, + }) +} diff --git a/packages/wasm-dpp2/src/batch/mod.rs b/packages/wasm-dpp2/src/batch/mod.rs new file mode 100644 index 00000000000..696fb1c8517 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/mod.rs @@ -0,0 +1,259 @@ +use crate::batch::batched_transition::BatchedTransitionWASM; +use crate::batch::document_transition::DocumentTransitionWASM; +use crate::identifier::IdentifierWASM; +use crate::state_transition::StateTransitionWASM; +use crate::utils::{IntoWasm, WithJsError}; +use dpp::fee::Credits; +use dpp::identity::KeyID; +use dpp::platform_value::BinaryData; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::prelude::{IdentityNonce, UserFeeIncrease}; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable}; +use dpp::state_transition::batch_transition::accessors::DocumentsBatchTransitionAccessorsV0; +use dpp::state_transition::batch_transition::batched_transition::BatchedTransition; +use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; +use dpp::state_transition::batch_transition::methods::v0::DocumentsBatchTransitionMethodsV0; +use dpp::state_transition::batch_transition::{ + BatchTransition, BatchTransitionV0, BatchTransitionV1, +}; +use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +pub mod batched_transition; +pub mod document_base_transition; +pub mod document_transition; +pub mod document_transitions; +pub mod generators; +pub mod prefunded_voting_balance; +pub mod token_base_transition; +pub mod token_payment_info; +pub mod token_pricing_schedule; +pub mod token_transition; +pub mod token_transitions; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=BatchTransitionWASM)] +pub struct BatchTransitionWASM(BatchTransition); + +impl From for BatchTransitionWASM { + fn from(batch: BatchTransition) -> Self { + BatchTransitionWASM(batch) + } +} + +impl From for BatchTransition { + fn from(batch: BatchTransitionWASM) -> Self { + batch.0 + } +} + +fn convert_array_to_vec_batched(js_batched_transitions: &js_sys::Array) -> Vec { + js_batched_transitions + .clone() + .iter() + .map(|js_batched_transition| { + let batched_transition: BatchedTransitionWASM = js_batched_transition + .to_wasm::("BatchedTransitionWASM") + .unwrap() + .clone(); + BatchedTransition::from(batched_transition) + }) + .collect() +} + +#[wasm_bindgen] +impl BatchTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "BatchTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "BatchTransitionWASM".to_string() + } + + #[wasm_bindgen(js_name = "fromV1BatchedTransitions")] + pub fn from_v1_batched_transitions( + js_batched_transitions: &js_sys::Array, + owner_id: &JsValue, + user_fee_increase: UserFeeIncrease, + signature_public_key_id: Option, + signature: Option>, + ) -> Result { + let transitions = convert_array_to_vec_batched(&js_batched_transitions); + + Ok(BatchTransitionWASM(BatchTransition::V1( + BatchTransitionV1 { + owner_id: IdentifierWASM::try_from(owner_id)?.into(), + transitions, + user_fee_increase, + signature_public_key_id: signature_public_key_id.unwrap_or(0u32), + signature: BinaryData::from(signature.unwrap_or(Vec::new())), + }, + ))) + } + + #[wasm_bindgen(js_name = "fromV0Transitions")] + pub fn from_v0_transitions( + document_transitions: &js_sys::Array, + js_owner_id: &JsValue, + user_fee_increase: Option, + signature_public_key_id: Option, + signature: Option>, + ) -> Result { + let owner_id = IdentifierWASM::try_from(js_owner_id)?; + + let transitions: Vec = document_transitions + .clone() + .iter() + .map(|js_document_transition| { + let document_transition: DocumentTransitionWASM = js_document_transition + .to_wasm::("DocumentTransitionWASM") + .unwrap() + .clone(); + + DocumentTransition::from(document_transition.clone().clone()) + }) + .collect(); + + Ok(BatchTransitionWASM(BatchTransition::V0( + BatchTransitionV0 { + owner_id: owner_id.into(), + transitions, + user_fee_increase: user_fee_increase.unwrap_or(0), + signature_public_key_id: signature_public_key_id.unwrap_or(0), + signature: BinaryData::from(signature.unwrap_or(Vec::new())), + }, + ))) + } + + #[wasm_bindgen(getter = "transitions")] + pub fn get_transitions(&self) -> Vec { + self.0 + .transitions_iter() + .map(|transition| BatchedTransitionWASM::from(transition.to_owned_transition())) + .collect() + } + + #[wasm_bindgen(setter = "transitions")] + pub fn set_transitions(&mut self, js_batched_transitions: &js_sys::Array) { + let transitions = convert_array_to_vec_batched(&js_batched_transitions); + + self.0.set_transitions(transitions) + } + + #[wasm_bindgen(getter = "signature")] + pub fn get_signature(&self) -> Vec { + self.0.signature().to_vec() + } + + #[wasm_bindgen(getter = "signaturePublicKeyId")] + pub fn get_signature_public_key_id(&self) -> KeyID { + self.0.signature_public_key_id() + } + + #[wasm_bindgen(getter = "allPurchasesAmount")] + pub fn get_all_purchases_amount(&self) -> Result, JsValue> { + self.0.all_document_purchases_amount().with_js_error() + } + + #[wasm_bindgen(getter = "ownerId")] + pub fn get_owner_id(&self) -> IdentifierWASM { + self.0.owner_id().into() + } + + #[wasm_bindgen(getter = "modifiedDataIds")] + pub fn get_modified_data_ids(&self) -> Vec { + self.0 + .modified_data_ids() + .iter() + .map(|id| id.clone().into()) + .collect() + } + + #[wasm_bindgen(getter = "allConflictingIndexCollateralVotingFunds")] + pub fn get_all_conflicting_index_collateral_voting_funds( + &self, + ) -> Result, JsValue> { + self.0 + .all_conflicting_index_collateral_voting_funds() + .with_js_error() + } + + #[wasm_bindgen(setter = "signature")] + pub fn set_signature(&mut self, js_signature: Vec) { + self.0.set_signature(BinaryData::from(js_signature)) + } + + #[wasm_bindgen(setter = "signaturePublicKeyId")] + pub fn set_signature_public_key_id(&mut self, key_id: KeyID) { + self.0.set_signature_public_key_id(key_id) + } + + #[wasm_bindgen(js_name = "setIdentityContractNonce")] + pub fn set_identity_contract_nonce(&mut self, nonce: IdentityNonce) { + self.0.set_identity_contract_nonce(nonce) + } + + #[wasm_bindgen(js_name = "toStateTransition")] + pub fn to_state_transition(&self) -> StateTransitionWASM { + let st = StateTransition::from(self.0.clone()); + + StateTransitionWASM::from(st) + } + + #[wasm_bindgen(js_name = "fromStateTransition")] + pub fn from_state_transition( + state_transition: &StateTransitionWASM, + ) -> Result { + let rs_transition: StateTransition = StateTransition::from(state_transition.clone()); + + match rs_transition { + StateTransition::Batch(batch) => Ok(BatchTransitionWASM(batch)), + _ => Err(JsValue::from("invalid state document_transition content")), + } + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Result, JsValue> { + let bytes = self.0.serialize_to_bytes().with_js_error()?; + + Ok(bytes) + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_hex(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Hex, + )) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Base64, + )) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + let rs_batch = BatchTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + + Ok(BatchTransitionWASM::from(rs_batch)) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> Result { + BatchTransitionWASM::from_bytes(decode(base64.as_str(), Base64).map_err(JsError::from)?) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + BatchTransitionWASM::from_bytes(decode(hex.as_str(), Hex).map_err(JsError::from)?) + } +} diff --git a/packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs b/packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs new file mode 100644 index 00000000000..32e2b624b48 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs @@ -0,0 +1,55 @@ +use dpp::fee::Credits; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "PrefundedVotingBalanceWASM")] +#[derive(Clone)] +pub struct PrefundedVotingBalanceWASM { + index_name: String, + credits: Credits, +} + +impl From<(String, Credits)> for PrefundedVotingBalanceWASM { + fn from((index_name, credits): (String, Credits)) -> Self { + PrefundedVotingBalanceWASM { + index_name, + credits, + } + } +} + +impl From for (String, Credits) { + fn from(value: PrefundedVotingBalanceWASM) -> Self { + (value.index_name, value.credits) + } +} + +#[wasm_bindgen] +impl PrefundedVotingBalanceWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "PrefundedVotingBalanceWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "PrefundedVotingBalanceWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(index_name: String, credits: Credits) -> PrefundedVotingBalanceWASM { + PrefundedVotingBalanceWASM { + index_name, + credits, + } + } + + #[wasm_bindgen(getter, js_name = "indexName")] + pub fn index_name(&self) -> String { + self.index_name.clone() + } + + #[wasm_bindgen(getter)] + pub fn credits(&self) -> Credits { + self.credits.clone() + } +} diff --git a/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs b/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs new file mode 100644 index 00000000000..75680f48e75 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs @@ -0,0 +1,140 @@ +use crate::group_state_transition_info::GroupStateTransitionInfoWASM; +use crate::identifier::IdentifierWASM; +use crate::utils::IntoWasm; +use dpp::group::GroupStateTransitionInfo; +use dpp::prelude::IdentityNonce; +use dpp::state_transition::batch_transition::token_base_transition::TokenBaseTransition; +use dpp::state_transition::batch_transition::token_base_transition::v0::TokenBaseTransitionV0; +use dpp::state_transition::batch_transition::token_base_transition::v0::v0_methods::TokenBaseTransitionV0Methods; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=TokenBaseTransitionWASM)] +pub struct TokenBaseTransitionWASM(TokenBaseTransition); + +impl From for TokenBaseTransitionWASM { + fn from(t: TokenBaseTransition) -> Self { + TokenBaseTransitionWASM(t) + } +} + +impl From for TokenBaseTransition { + fn from(t: TokenBaseTransitionWASM) -> Self { + t.0 + } +} + +#[wasm_bindgen] +impl TokenBaseTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenBaseTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenBaseTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + identity_contract_nonce: IdentityNonce, + token_contract_position: u16, + js_data_contract_id: &JsValue, + js_token_id: &JsValue, + js_using_group_info: &JsValue, + ) -> Result { + let using_group_info: Option = + match js_using_group_info.is_undefined() { + false => Some( + js_using_group_info + .to_wasm::("GroupStateTransitionInfoWASM")? + .clone() + .into(), + ), + true => None, + }; + + Ok(TokenBaseTransitionWASM(TokenBaseTransition::V0( + TokenBaseTransitionV0 { + identity_contract_nonce, + token_contract_position, + data_contract_id: IdentifierWASM::try_from(js_data_contract_id)?.into(), + token_id: IdentifierWASM::try_from(js_token_id)?.into(), + using_group_info, + }, + ))) + } + + #[wasm_bindgen(getter = identityContractNonce)] + pub fn get_identity_contract_nonce(&self) -> IdentityNonce { + self.0.identity_contract_nonce() + } + + #[wasm_bindgen(getter = tokenContractPosition)] + pub fn get_token_contract_position(&self) -> u16 { + self.0.token_contract_position() + } + + #[wasm_bindgen(getter = dataContractId)] + pub fn get_data_contract_id(&self) -> IdentifierWASM { + self.0.data_contract_id().into() + } + + #[wasm_bindgen(getter = tokenId)] + pub fn get_token_id(&self) -> IdentifierWASM { + self.0.token_id().into() + } + + #[wasm_bindgen(getter = usingGroupInfo)] + pub fn get_using_group_info(&self) -> Option { + match self.0.using_group_info() { + Some(using_group_info) => Some(using_group_info.clone().into()), + None => None, + } + } + + #[wasm_bindgen(setter = identityContractNonce)] + pub fn set_identity_contract_nonce(&mut self, identity_contract_nonce: IdentityNonce) { + self.0.set_identity_contract_nonce(identity_contract_nonce) + } + + #[wasm_bindgen(setter = tokenContractPosition)] + pub fn set_token_contract_position(&mut self, pos: u16) { + self.0.set_token_contract_position(pos) + } + + #[wasm_bindgen(setter = dataContractId)] + pub fn set_data_contract_id(&mut self, js_identifier: &JsValue) -> Result<(), JsValue> { + self.0 + .set_data_contract_id(IdentifierWASM::try_from(js_identifier)?.into()); + Ok(()) + } + + #[wasm_bindgen(setter = tokenId)] + pub fn set_token_id(&mut self, js_identifier: &JsValue) -> Result<(), JsValue> { + self.0 + .set_token_id(IdentifierWASM::try_from(js_identifier)?.into()); + + Ok(()) + } + + #[wasm_bindgen(setter = usingGroupInfo)] + pub fn set_using_group_info(&mut self, js_using_group_info: &JsValue) -> Result<(), JsValue> { + let using_group_info: Option = + match js_using_group_info.is_undefined() { + false => Some( + js_using_group_info + .to_wasm::("GroupStateTransitionInfoWASM")? + .clone() + .into(), + ), + true => None, + }; + + self.0.set_using_group_info(using_group_info); + + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs b/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs new file mode 100644 index 00000000000..1be9a1ee32d --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs @@ -0,0 +1,149 @@ +use crate::enums::batch::gas_fees_paid_by::GasFeesPaidByWASM; +use crate::identifier::IdentifierWASM; +use dpp::balances::credits::TokenAmount; +use dpp::data_contract::TokenContractPosition; +use dpp::prelude::Identifier; +use dpp::tokens::gas_fees_paid_by::GasFeesPaidBy; +use dpp::tokens::token_payment_info::TokenPaymentInfo; +use dpp::tokens::token_payment_info::v0::TokenPaymentInfoV0; +use dpp::tokens::token_payment_info::v0::v0_accessors::TokenPaymentInfoAccessorsV0; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name = "TokenPaymentInfoWASM")] +pub struct TokenPaymentInfoWASM(TokenPaymentInfo); + +impl From for TokenPaymentInfoWASM { + fn from(info: TokenPaymentInfo) -> Self { + TokenPaymentInfoWASM(info) + } +} + +impl From for TokenPaymentInfo { + fn from(info: TokenPaymentInfoWASM) -> Self { + info.0 + } +} + +#[wasm_bindgen] +impl TokenPaymentInfoWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenPaymentInfoWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenPaymentInfoWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_payment_token_contract_id: &JsValue, + token_contract_position: TokenContractPosition, + minimum_token_cost: Option, + maximum_token_cost: Option, + js_gas_fees_paid_by: &JsValue, + ) -> Result { + let payment_token_contract_id: Option = match js_payment_token_contract_id + .is_null() + | js_payment_token_contract_id.is_undefined() + { + true => None, + false => Some(IdentifierWASM::try_from(js_payment_token_contract_id.clone())?.into()), + }; + + let gas_fees_paid_by = + match js_gas_fees_paid_by.is_undefined() | js_gas_fees_paid_by.is_null() { + true => GasFeesPaidBy::default(), + false => GasFeesPaidByWASM::try_from(js_gas_fees_paid_by.clone())? + .clone() + .into(), + }; + + Ok(TokenPaymentInfoWASM(TokenPaymentInfo::V0( + TokenPaymentInfoV0 { + payment_token_contract_id, + token_contract_position, + minimum_token_cost, + maximum_token_cost, + gas_fees_paid_by, + }, + ))) + } + + #[wasm_bindgen(getter = "paymentTokenContractId")] + pub fn payment_token_contract_id(&self) -> Option { + self.0.payment_token_contract_id().map(|id| id.into()) + } + + #[wasm_bindgen(getter = "tokenContractPosition")] + pub fn token_contract_position(&self) -> TokenContractPosition { + self.0.token_contract_position() + } + + #[wasm_bindgen(getter = "minimumTokenCost")] + pub fn minimum_token_cost(&self) -> Option { + self.0.minimum_token_cost() + } + + #[wasm_bindgen(getter = "maximumTokenCost")] + pub fn maximum_token_cost(&self) -> Option { + self.0.maximum_token_cost() + } + + #[wasm_bindgen(getter = "gasFeesPaidBy")] + pub fn gas_fees_paid_by(&self) -> String { + GasFeesPaidByWASM::from(self.0.gas_fees_paid_by()).into() + } + + #[wasm_bindgen(setter = "paymentTokenContractId")] + pub fn set_payment_token_contract_id( + &mut self, + js_payment_token_contract_id: &JsValue, + ) -> Result<(), JsValue> { + let payment_token_contract_id: Option = match js_payment_token_contract_id + .is_null() + | js_payment_token_contract_id.is_undefined() + { + true => None, + false => Some(IdentifierWASM::try_from(js_payment_token_contract_id.clone())?.into()), + }; + + self.0 + .set_payment_token_contract_id(payment_token_contract_id); + + Ok(()) + } + + #[wasm_bindgen(setter = "tokenContractPosition")] + pub fn set_token_contract_position(&mut self, token_contract_position: TokenContractPosition) { + self.0.set_token_contract_position(token_contract_position) + } + + #[wasm_bindgen(setter = "minimumTokenCost")] + pub fn set_minimum_token_cost(&mut self, minimum_cost: Option) { + self.0.set_maximum_token_cost(minimum_cost); + } + + #[wasm_bindgen(setter = "maximumTokenCost")] + pub fn set_maximum_token_cost(&mut self, maximum_cost: Option) { + self.0.set_maximum_token_cost(maximum_cost) + } + + #[wasm_bindgen(setter = "gasFeesPaidBy")] + pub fn set_gas_fees_paid_by(&mut self, js_gas_fees_paid_by: &JsValue) -> Result<(), JsValue> { + let gas_fees_paid_by = + match js_gas_fees_paid_by.is_undefined() | js_gas_fees_paid_by.is_null() { + true => GasFeesPaidBy::default(), + false => GasFeesPaidByWASM::try_from(js_gas_fees_paid_by.clone())? + .clone() + .into(), + }; + + self.0.set_gas_fees_paid_by(gas_fees_paid_by); + + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs b/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs new file mode 100644 index 00000000000..c818f96bca4 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs @@ -0,0 +1,83 @@ +use crate::utils::ToSerdeJSONExt; +use dpp::balances::credits::TokenAmount; +use dpp::fee::Credits; +use dpp::tokens::token_pricing_schedule::TokenPricingSchedule; +use js_sys::{Object, Reflect}; +use std::collections::BTreeMap; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "TokenPricingScheduleWASM")] +pub struct TokenPricingScheduleWASM(TokenPricingSchedule); + +impl From for TokenPricingSchedule { + fn from(schedule: TokenPricingScheduleWASM) -> Self { + schedule.0 + } +} + +impl From for TokenPricingScheduleWASM { + fn from(schedule: TokenPricingSchedule) -> Self { + TokenPricingScheduleWASM(schedule) + } +} + +#[wasm_bindgen] +impl TokenPricingScheduleWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenPricingScheduleWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenPricingScheduleWASM".to_string() + } + + #[wasm_bindgen(js_name = "SinglePrice")] + pub fn single_price(credits: Credits) -> Self { + Self(TokenPricingSchedule::SinglePrice(credits)) + } + + #[wasm_bindgen(js_name = "SetPrices")] + pub fn set_prices(js_prices: &JsValue) -> Result { + let prices: BTreeMap = js_prices + .with_serde_to_platform_value_map()? + .iter() + .map(|(k, v)| (k.clone().parse().unwrap(), v.clone().as_integer().unwrap())) + .collect(); + + Ok(Self(TokenPricingSchedule::SetPrices(prices))) + } + + #[wasm_bindgen(js_name = "getScheduleType")] + pub fn get_scheduled_type(&self) -> String { + match &self.0 { + TokenPricingSchedule::SinglePrice(_) => String::from("SinglePrice"), + TokenPricingSchedule::SetPrices(_) => String::from("SetPrices"), + } + } + + #[wasm_bindgen(js_name = "getValue")] + pub fn get_value(&self) -> Result { + match &self.0 { + TokenPricingSchedule::SinglePrice(credits) => { + Ok(JsValue::bigint_from_str(&credits.to_string())) + } + TokenPricingSchedule::SetPrices(prices) => { + let price_object = Object::new(); + + for (key, value) in prices.iter() { + Reflect::set( + &price_object, + &JsValue::from(key.to_string()), + &value.clone().into(), + )?; + } + + Ok(price_object.into()) + } + } + } +} diff --git a/packages/wasm-dpp2/src/batch/token_transition/mod.rs b/packages/wasm-dpp2/src/batch/token_transition/mod.rs new file mode 100644 index 00000000000..82d95391084 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transition/mod.rs @@ -0,0 +1,276 @@ +use crate::batch::token_transitions::config_update::TokenConfigUpdateTransitionWASM; +use crate::batch::token_transitions::direct_purchase::TokenDirectPurchaseTransitionWASM; +use crate::batch::token_transitions::set_price_for_direct_purchase::TokenSetPriceForDirectPurchaseTransitionWASM; +use crate::batch::token_transitions::token_burn::TokenBurnTransitionWASM; +use crate::batch::token_transitions::token_claim::TokenClaimTransitionWASM; +use crate::batch::token_transitions::token_destroy_frozen_funds::TokenDestroyFrozenFundsTransitionWASM; +use crate::batch::token_transitions::token_emergency_action::TokenEmergencyActionTransitionWASM; +use crate::batch::token_transitions::token_freeze::TokenFreezeTransitionWASM; +use crate::batch::token_transitions::token_mint::TokenMintTransitionWASM; +use crate::batch::token_transitions::token_transfer::TokenTransferTransitionWASM; +use crate::batch::token_transitions::token_unfreeze::TokenUnFreezeTransitionWASM; +use crate::identifier::IdentifierWASM; +use crate::utils::{IntoWasm, get_class_type}; +use dpp::prelude::IdentityNonce; +use dpp::state_transition::batch_transition::batched_transition::token_transition::{ + TokenTransition, TokenTransitionV0Methods, +}; +use dpp::state_transition::batch_transition::{ + TokenBurnTransition, TokenClaimTransition, TokenConfigUpdateTransition, + TokenDestroyFrozenFundsTransition, TokenDirectPurchaseTransition, + TokenEmergencyActionTransition, TokenFreezeTransition, TokenMintTransition, + TokenSetPriceForDirectPurchaseTransition, TokenTransferTransition, TokenUnfreezeTransition, +}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=TokenTransitionWASM)] +pub struct TokenTransitionWASM(TokenTransition); + +impl From for TokenTransitionWASM { + fn from(transition: TokenTransition) -> Self { + Self(transition) + } +} + +impl From for TokenTransition { + fn from(transition: TokenTransitionWASM) -> Self { + transition.0 + } +} + +#[wasm_bindgen] +impl TokenTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(js_transition: &JsValue) -> Result { + let transition = match js_transition.is_object() { + true => match get_class_type(js_transition)?.as_str() { + "TokenMintTransitionWASM" => Ok(TokenTransition::from(TokenMintTransition::from( + js_transition + .to_wasm::("TokenMintTransitionWASM")? + .clone(), + ))), + "TokenUnFreezeTransitionWASM" => { + Ok(TokenTransition::from(TokenUnfreezeTransition::from( + js_transition + .to_wasm::("TokenUnFreezeTransitionWASM")? + .clone(), + ))) + } + "TokenTransferTransitionWASM" => { + Ok(TokenTransition::from(TokenTransferTransition::from( + js_transition + .to_wasm::("TokenTransferTransitionWASM")? + .clone(), + ))) + } + "TokenFreezeTransitionWASM" => { + Ok(TokenTransition::from(TokenFreezeTransition::from( + js_transition + .to_wasm::("TokenFreezeTransitionWASM")? + .clone(), + ))) + } + "TokenDestroyFrozenFundsTransitionWASM" => Ok(TokenTransition::from( + TokenDestroyFrozenFundsTransition::from( + js_transition + .to_wasm::( + "TokenDestroyFrozenFundsTransitionWASM", + )? + .clone(), + ), + )), + "TokenClaimTransitionWASM" => { + Ok(TokenTransition::from(TokenClaimTransition::from( + js_transition + .to_wasm::("TokenClaimTransitionWASM")? + .clone(), + ))) + } + "TokenBurnTransitionWASM" => Ok(TokenTransition::from(TokenBurnTransition::from( + js_transition + .to_wasm::("TokenBurnTransitionWASM")? + .clone(), + ))), + "TokenSetPriceForDirectPurchaseTransitionWASM" => Ok(TokenTransition::from( + TokenSetPriceForDirectPurchaseTransition::from( + js_transition + .to_wasm::( + "TokenSetPriceForDirectPurchaseTransitionWASM", + )? + .clone(), + ), + )), + "TokenDirectPurchaseTransitionWASM" => { + Ok(TokenTransition::from(TokenDirectPurchaseTransition::from( + js_transition + .to_wasm::( + "TokenDirectPurchaseTransitionWASM", + )? + .clone(), + ))) + } + "TokenConfigUpdateTransitionWASM" => { + Ok(TokenTransition::from(TokenConfigUpdateTransition::from( + js_transition + .to_wasm::( + "TokenConfigUpdateTransitionWASM", + )? + .clone(), + ))) + } + "TokenEmergencyActionTransitionWASM" => { + Ok(TokenTransition::from(TokenEmergencyActionTransition::from( + js_transition + .to_wasm::( + "TokenEmergencyActionTransitionWASM", + )? + .clone(), + ))) + } + _ => Err(JsValue::from("Bad token transition input")), + }, + false => Err(JsValue::from("Bad token transition input")), + }?; + + Ok(TokenTransitionWASM(TokenTransition::from(transition))) + } + + #[wasm_bindgen(js_name = "getTransition")] + pub fn to_transition(&self) -> JsValue { + match self.clone().0 { + TokenTransition::Burn(token_transition) => { + TokenBurnTransitionWASM::from(token_transition).into() + } + TokenTransition::Mint(token_transition) => { + TokenMintTransitionWASM::from(token_transition).into() + } + TokenTransition::Transfer(token_transition) => { + TokenTransferTransitionWASM::from(token_transition).into() + } + TokenTransition::Freeze(token_transition) => { + TokenFreezeTransitionWASM::from(token_transition).into() + } + TokenTransition::Unfreeze(token_transition) => { + TokenUnFreezeTransitionWASM::from(token_transition).into() + } + TokenTransition::DestroyFrozenFunds(token_transition) => { + TokenDestroyFrozenFundsTransitionWASM::from(token_transition).into() + } + TokenTransition::Claim(token_transition) => { + TokenClaimTransitionWASM::from(token_transition).into() + } + TokenTransition::EmergencyAction(token_transition) => { + TokenEmergencyActionTransitionWASM::from(token_transition).into() + } + TokenTransition::ConfigUpdate(token_transition) => { + TokenConfigUpdateTransitionWASM::from(token_transition).into() + } + TokenTransition::DirectPurchase(token_transition) => { + TokenDirectPurchaseTransitionWASM::from(token_transition).into() + } + TokenTransition::SetPriceForDirectPurchase(token_transition) => { + TokenSetPriceForDirectPurchaseTransitionWASM::from(token_transition).into() + } + } + } + + #[wasm_bindgen(js_name = "getTransitionTypeNumber")] + pub fn get_transition_type_number(&self) -> u8 { + match self.clone().0 { + TokenTransition::Burn(_) => 0, + TokenTransition::Mint(_) => 1, + TokenTransition::Transfer(_) => 2, + TokenTransition::Freeze(_) => 3, + TokenTransition::Unfreeze(_) => 4, + TokenTransition::DestroyFrozenFunds(_) => 5, + TokenTransition::Claim(_) => 6, + TokenTransition::EmergencyAction(_) => 7, + TokenTransition::ConfigUpdate(_) => 8, + TokenTransition::DirectPurchase(_) => 9, + TokenTransition::SetPriceForDirectPurchase(_) => 10, + } + } + + #[wasm_bindgen(js_name = "getTransitionType")] + pub fn get_transition_type(&self) -> String { + match self.clone().0 { + TokenTransition::Burn(_) => "Burn".to_string(), + TokenTransition::Mint(_) => "Mint".to_string(), + TokenTransition::Transfer(_) => "Transfer".to_string(), + TokenTransition::Freeze(_) => "Freeze".to_string(), + TokenTransition::Unfreeze(_) => "Unfreeze".to_string(), + TokenTransition::DestroyFrozenFunds(_) => "DestroyFrozenFunds".to_string(), + TokenTransition::Claim(_) => "Claim".to_string(), + TokenTransition::EmergencyAction(_) => "EmergencyAction".to_string(), + TokenTransition::ConfigUpdate(_) => "ConfigUpdate".to_string(), + TokenTransition::DirectPurchase(_) => "DirectPurchase".to_string(), + TokenTransition::SetPriceForDirectPurchase(_) => { + "SetPriceForDirectPurchase".to_string() + } + } + } + + #[wasm_bindgen(js_name = "getHistoricalDocumentTypeName")] + pub fn get_historical_document_type_name(&self) -> String { + self.0.historical_document_type_name().to_string() + } + + #[wasm_bindgen(js_name = "getHistoricalDocumentId")] + pub fn get_historical_document_id( + &self, + js_owner: &JsValue, + ) -> Result { + let owner = IdentifierWASM::try_from(js_owner)?; + Ok(self.0.historical_document_id(owner.into()).into()) + } + + #[wasm_bindgen(getter = "identityContractNonce")] + pub fn get_identity_contract_nonce(&self) -> IdentityNonce { + self.0.identity_contract_nonce() + } + + #[wasm_bindgen(getter = "tokenId")] + pub fn get_token_id(&self) -> IdentifierWASM { + self.0.token_id().into() + } + + #[wasm_bindgen(getter = "contractId")] + pub fn get_contract_id(&self) -> IdentifierWASM { + self.0.data_contract_id().into() + } + + #[wasm_bindgen(setter = "identityContractNonce")] + pub fn set_identity_contract_nonce(&mut self, nonce: IdentityNonce) { + self.0.set_identity_contract_nonce(nonce) + } + + #[wasm_bindgen(setter = "tokenId")] + pub fn set_token_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { + let id = IdentifierWASM::try_from(js_id)?; + + self.0.set_token_id(id.into()); + + Ok(()) + } + + #[wasm_bindgen(setter = "contractId")] + pub fn set_contract_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { + let id = IdentifierWASM::try_from(js_id)?; + + self.0.set_data_contract_id(id.into()); + + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs b/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs new file mode 100644 index 00000000000..340358d0001 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs @@ -0,0 +1,83 @@ +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; +use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use dpp::state_transition::batch_transition::TokenConfigUpdateTransition; +use dpp::state_transition::batch_transition::token_config_update_transition::TokenConfigUpdateTransitionV0; +use dpp::state_transition::batch_transition::token_config_update_transition::v0::v0_methods::TokenConfigUpdateTransitionV0Methods; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name = "TokenConfigUpdateTransitionWASM")] +pub struct TokenConfigUpdateTransitionWASM(TokenConfigUpdateTransition); + +impl From for TokenConfigUpdateTransition { + fn from(transition: TokenConfigUpdateTransitionWASM) -> Self { + transition.0 + } +} + +impl From for TokenConfigUpdateTransitionWASM { + fn from(transition: TokenConfigUpdateTransition) -> Self { + TokenConfigUpdateTransitionWASM(transition) + } +} + +#[wasm_bindgen] +impl TokenConfigUpdateTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenConfigUpdateTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenConfigUpdateTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + base: &TokenBaseTransitionWASM, + update_token_configuration_item: &TokenConfigurationChangeItemWASM, + public_note: Option, + ) -> Result { + Ok(TokenConfigUpdateTransitionWASM( + TokenConfigUpdateTransition::V0(TokenConfigUpdateTransitionV0 { + base: base.clone().into(), + update_token_configuration_item: update_token_configuration_item.clone().into(), + public_note, + }), + )) + } + + #[wasm_bindgen(getter = base)] + pub fn get_base(&self) -> TokenBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = publicNote)] + pub fn get_public_note(&self) -> Option { + self.clone().0.public_note_owned() + } + + #[wasm_bindgen(getter = updateTokenConfigurationItem)] + pub fn get_update_token_configuration_item(&self) -> TokenConfigurationChangeItemWASM { + self.0.update_token_configuration_item().clone().into() + } + + #[wasm_bindgen(setter = base)] + pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + self.0.set_base(base.into()) + } + + #[wasm_bindgen(setter = publicNote)] + pub fn set_public_note(&mut self, note: Option) { + self.0.set_public_note(note) + } + + #[wasm_bindgen(setter = updateTokenConfigurationItem)] + pub fn set_update_token_configuration_item(&mut self, item: &TokenConfigurationChangeItemWASM) { + self.0 + .set_update_token_configuration_item(item.clone().into()) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs b/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs new file mode 100644 index 00000000000..8ebc262ef45 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs @@ -0,0 +1,82 @@ +use dpp::balances::credits::TokenAmount; +use dpp::fee::Credits; +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; +use dpp::state_transition::batch_transition::token_direct_purchase_transition::TokenDirectPurchaseTransitionV0; +use dpp::state_transition::batch_transition::token_direct_purchase_transition::v0::v0_methods::TokenDirectPurchaseTransitionV0Methods; +use dpp::state_transition::batch_transition::TokenDirectPurchaseTransition; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::batch::token_base_transition::TokenBaseTransitionWASM; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=TokenDirectPurchaseTransitionWASM)] +pub struct TokenDirectPurchaseTransitionWASM(TokenDirectPurchaseTransition); + +impl From for TokenDirectPurchaseTransition { + fn from(transition: TokenDirectPurchaseTransitionWASM) -> Self { + transition.0 + } +} + +impl From for TokenDirectPurchaseTransitionWASM { + fn from(transition: TokenDirectPurchaseTransition) -> Self { + TokenDirectPurchaseTransitionWASM(transition) + } +} + +#[wasm_bindgen] +impl TokenDirectPurchaseTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenDirectPurchaseTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenDirectPurchaseTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + base: &TokenBaseTransitionWASM, + token_count: TokenAmount, + total_agreed_price: Credits, + ) -> Self { + TokenDirectPurchaseTransitionWASM(TokenDirectPurchaseTransition::V0( + TokenDirectPurchaseTransitionV0 { + base: base.clone().into(), + token_count, + total_agreed_price, + }, + )) + } + + #[wasm_bindgen(getter = base)] + pub fn get_base(&self) -> TokenBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = tokenCount)] + pub fn get_token_count(&self) -> TokenAmount { + self.0.token_count() + } + + #[wasm_bindgen(getter = totalAgreedPrice)] + pub fn get_total_agreed_price(&self) -> Credits { + self.0.total_agreed_price() + } + + #[wasm_bindgen(setter = base)] + pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + self.0.set_base(base.into()) + } + + #[wasm_bindgen(setter = tokenCount)] + pub fn set_token_count(&mut self, token_count: TokenAmount) { + self.0.set_token_count(token_count) + } + + #[wasm_bindgen(setter = totalAgreedPrice)] + pub fn set_total_agreed_price(&mut self, total_agreed_price: Credits) { + self.0.set_total_agreed_price(total_agreed_price) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_transitions/mod.rs b/packages/wasm-dpp2/src/batch/token_transitions/mod.rs new file mode 100644 index 00000000000..97fe1ee522b --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transitions/mod.rs @@ -0,0 +1,11 @@ +pub mod config_update; +pub mod direct_purchase; +pub mod set_price_for_direct_purchase; +pub mod token_burn; +pub mod token_claim; +pub mod token_destroy_frozen_funds; +pub mod token_emergency_action; +pub mod token_freeze; +pub mod token_mint; +pub mod token_transfer; +pub mod token_unfreeze; diff --git a/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs b/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs new file mode 100644 index 00000000000..1058e0a8499 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs @@ -0,0 +1,113 @@ +use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use crate::batch::token_pricing_schedule::TokenPricingScheduleWASM; +use dpp::state_transition::batch_transition::token_set_price_for_direct_purchase_transition::TokenSetPriceForDirectPurchaseTransitionV0; +use dpp::state_transition::batch_transition::TokenSetPriceForDirectPurchaseTransition; +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; +use dpp::state_transition::batch_transition::token_set_price_for_direct_purchase_transition::v0::v0_methods::TokenSetPriceForDirectPurchaseTransitionV0Methods; +use dpp::tokens::token_pricing_schedule::TokenPricingSchedule; +use crate::utils::IntoWasm; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=TokenSetPriceForDirectPurchaseTransitionWASM)] +pub struct TokenSetPriceForDirectPurchaseTransitionWASM(TokenSetPriceForDirectPurchaseTransition); + +impl From + for TokenSetPriceForDirectPurchaseTransitionWASM +{ + fn from(transition: TokenSetPriceForDirectPurchaseTransition) -> Self { + TokenSetPriceForDirectPurchaseTransitionWASM(transition) + } +} + +impl From + for TokenSetPriceForDirectPurchaseTransition +{ + fn from(transition: TokenSetPriceForDirectPurchaseTransitionWASM) -> Self { + transition.0 + } +} + +#[wasm_bindgen] +impl TokenSetPriceForDirectPurchaseTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenSetPriceForDirectPurchaseTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenSetPriceForDirectPurchaseTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + base: &TokenBaseTransitionWASM, + js_price: &JsValue, + public_note: Option, + ) -> Result { + let price: Option = match js_price.is_undefined() { + true => None, + false => Some( + js_price + .to_wasm::("TokenPricingScheduleWASM")? + .clone() + .into(), + ), + }; + + Ok(TokenSetPriceForDirectPurchaseTransitionWASM( + TokenSetPriceForDirectPurchaseTransition::V0( + TokenSetPriceForDirectPurchaseTransitionV0 { + base: base.clone().into(), + price, + public_note, + }, + ), + )) + } + + #[wasm_bindgen(getter = base)] + pub fn get_base(&self) -> TokenBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = "publicNote")] + pub fn get_public_note(&self) -> Option { + self.clone().0.public_note_owned() + } + + #[wasm_bindgen(getter = "price")] + pub fn get_price(&self) -> JsValue { + match self.0.price() { + None => JsValue::null(), + Some(price) => JsValue::from(TokenPricingScheduleWASM::from(price.clone())), + } + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + self.0.set_base(base.into()) + } + + #[wasm_bindgen(setter = "publicNote")] + pub fn set_public_note(&mut self, note: Option) { + self.0.set_public_note(note) + } + + #[wasm_bindgen(setter = "price")] + pub fn set_price(&mut self, js_price: &JsValue) -> Result<(), JsValue> { + let price: Option = match js_price.is_undefined() { + true => None, + false => Some( + js_price + .to_wasm::("TokenPricingScheduleWASM")? + .clone() + .into(), + ), + }; + + Ok(self.0.set_price(price)) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs new file mode 100644 index 00000000000..6b06b69df04 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs @@ -0,0 +1,81 @@ +use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; +use dpp::state_transition::batch_transition::TokenBurnTransition; +use dpp::state_transition::batch_transition::token_burn_transition::TokenBurnTransitionV0; +use dpp::state_transition::batch_transition::token_burn_transition::v0::v0_methods::TokenBurnTransitionV0Methods; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=TokenBurnTransitionWASM)] +pub struct TokenBurnTransitionWASM(TokenBurnTransition); + +impl From for TokenBurnTransitionWASM { + fn from(transition: TokenBurnTransition) -> Self { + Self(transition) + } +} + +impl From for TokenBurnTransition { + fn from(transition: TokenBurnTransitionWASM) -> Self { + transition.0 + } +} + +#[wasm_bindgen] +impl TokenBurnTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenBurnTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenBurnTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + base: &TokenBaseTransitionWASM, + burn_amount: u64, + public_note: Option, + ) -> Result { + Ok(TokenBurnTransitionWASM(TokenBurnTransition::V0( + TokenBurnTransitionV0 { + base: base.clone().into(), + burn_amount, + public_note, + }, + ))) + } + + #[wasm_bindgen(getter = burnAmount)] + pub fn get_burn_amount(&self) -> u64 { + self.0.burn_amount() + } + + #[wasm_bindgen(getter = base)] + pub fn get_base(&self) -> TokenBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = publicNote)] + pub fn get_public_note(&self) -> Option { + self.clone().0.public_note_owned() + } + + #[wasm_bindgen(setter = burnAmount)] + pub fn set_burn_amount(&mut self, amount: u64) { + self.0.set_burn_amount(amount) + } + + #[wasm_bindgen(setter = base)] + pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + self.0.set_base(base.into()) + } + + #[wasm_bindgen(setter = publicNote)] + pub fn set_public_note(&mut self, note: Option) { + self.0.set_public_note(note) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs new file mode 100644 index 00000000000..778168349ba --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs @@ -0,0 +1,92 @@ +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; +use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use dpp::state_transition::batch_transition::TokenClaimTransition; +use dpp::state_transition::batch_transition::token_claim_transition::TokenClaimTransitionV0; +use dpp::state_transition::batch_transition::token_claim_transition::v0::v0_methods::TokenClaimTransitionV0Methods; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::enums::token::distribution_type::TokenDistributionTypeWASM; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name = "TokenClaimTransitionWASM")] +pub struct TokenClaimTransitionWASM(TokenClaimTransition); + +impl From for TokenClaimTransitionWASM { + fn from(transition: TokenClaimTransition) -> Self { + Self(transition) + } +} + +impl From for TokenClaimTransition { + fn from(transition: TokenClaimTransitionWASM) -> Self { + transition.0 + } +} + +#[wasm_bindgen] +impl TokenClaimTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenClaimTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenClaimTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + base: &TokenBaseTransitionWASM, + js_distribution_type: &JsValue, + public_note: Option, + ) -> Result { + let distribution_type = match js_distribution_type.is_undefined() { + true => TokenDistributionTypeWASM::default(), + false => TokenDistributionTypeWASM::try_from(js_distribution_type.clone())?, + }; + + Ok(TokenClaimTransitionWASM(TokenClaimTransition::V0( + TokenClaimTransitionV0 { + base: base.clone().into(), + distribution_type: distribution_type.into(), + public_note, + }, + ))) + } + + #[wasm_bindgen(getter = "base")] + pub fn get_base(&self) -> TokenBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = "publicNote")] + pub fn get_public_note(&self) -> Option { + self.clone().0.public_note_owned() + } + + #[wasm_bindgen(getter = "distributionType")] + pub fn get_distribution_type(&self) -> String { + TokenDistributionTypeWASM::from(self.0.distribution_type()).into() + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + self.0.set_base(base.into()) + } + + #[wasm_bindgen(setter = "publicNote")] + pub fn set_public_note(&mut self, note: Option) { + self.0.set_public_note(note) + } + + #[wasm_bindgen(setter = "distributionType")] + pub fn set_distribution_type(&mut self, js_distribution_type: &JsValue) -> Result<(), JsValue> { + let distribution_type = match js_distribution_type.is_undefined() { + true => TokenDistributionTypeWASM::default(), + false => TokenDistributionTypeWASM::try_from(js_distribution_type.clone())?, + }; + + Ok(self.0.set_distribution_type(distribution_type.into())) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs new file mode 100644 index 00000000000..a45d1f92acf --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs @@ -0,0 +1,91 @@ +use dpp::identifier::Identifier; +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; +use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use dpp::state_transition::batch_transition::TokenDestroyFrozenFundsTransition; +use dpp::state_transition::batch_transition::token_destroy_frozen_funds_transition::TokenDestroyFrozenFundsTransitionV0; +use dpp::state_transition::batch_transition::token_destroy_frozen_funds_transition::v0::v0_methods::TokenDestroyFrozenFundsTransitionV0Methods; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::identifier::IdentifierWASM; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=TokenDestroyFrozenFundsTransitionWASM)] +pub struct TokenDestroyFrozenFundsTransitionWASM(TokenDestroyFrozenFundsTransition); + +impl From for TokenDestroyFrozenFundsTransitionWASM { + fn from(transition: TokenDestroyFrozenFundsTransition) -> Self { + TokenDestroyFrozenFundsTransitionWASM(transition) + } +} + +impl From for TokenDestroyFrozenFundsTransition { + fn from(transition: TokenDestroyFrozenFundsTransitionWASM) -> Self { + transition.0 + } +} + +#[wasm_bindgen] +impl TokenDestroyFrozenFundsTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenDestroyFrozenFundsTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenDestroyFrozenFundsTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + base: &TokenBaseTransitionWASM, + js_frozen_identity_id: &JsValue, + public_note: Option, + ) -> Result { + let frozen_identity_id: Identifier = + IdentifierWASM::try_from(js_frozen_identity_id)?.into(); + + Ok(TokenDestroyFrozenFundsTransitionWASM( + TokenDestroyFrozenFundsTransition::V0(TokenDestroyFrozenFundsTransitionV0 { + base: base.clone().into(), + frozen_identity_id, + public_note, + }), + )) + } + + #[wasm_bindgen(getter = "base")] + pub fn get_base(&self) -> TokenBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = "publicNote")] + pub fn get_public_note(&self) -> Option { + self.clone().0.public_note_owned() + } + + #[wasm_bindgen(getter = "frozenIdentityId")] + pub fn get_frozen_identity_id(&self) -> IdentifierWASM { + self.0.frozen_identity_id().into() + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + self.0.set_base(base.into()) + } + + #[wasm_bindgen(setter = "publicNote")] + pub fn set_public_note(&mut self, note: Option) { + self.0.set_public_note(note) + } + + #[wasm_bindgen(setter = "frozenIdentityId")] + pub fn set_frozen_identity_id( + &mut self, + js_frozen_identity_id: &JsValue, + ) -> Result<(), JsValue> { + self.0 + .set_frozen_identity_id(IdentifierWASM::try_from(js_frozen_identity_id)?.into()); + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs new file mode 100644 index 00000000000..197273fe51d --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs @@ -0,0 +1,81 @@ +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; +use dpp::state_transition::batch_transition::token_emergency_action_transition::TokenEmergencyActionTransitionV0; +use dpp::state_transition::batch_transition::token_emergency_action_transition::v0::v0_methods::TokenEmergencyActionTransitionV0Methods; +use dpp::state_transition::batch_transition::TokenEmergencyActionTransition; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::enums::token::emergency_action::TokenEmergencyActionWASM; +use crate::batch::token_base_transition::TokenBaseTransitionWASM; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name = "TokenEmergencyActionTransitionWASM")] +pub struct TokenEmergencyActionTransitionWASM(TokenEmergencyActionTransition); + +impl From for TokenEmergencyActionTransition { + fn from(transition: TokenEmergencyActionTransitionWASM) -> Self { + transition.0 + } +} + +impl From for TokenEmergencyActionTransitionWASM { + fn from(transition: TokenEmergencyActionTransition) -> Self { + TokenEmergencyActionTransitionWASM(transition) + } +} + +#[wasm_bindgen] +impl TokenEmergencyActionTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenEmergencyActionTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenEmergencyActionTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + base: &TokenBaseTransitionWASM, + emergency_action: TokenEmergencyActionWASM, + public_note: Option, + ) -> TokenEmergencyActionTransitionWASM { + TokenEmergencyActionTransitionWASM(TokenEmergencyActionTransition::V0( + TokenEmergencyActionTransitionV0 { + base: base.clone().into(), + emergency_action: emergency_action.into(), + public_note, + }, + )) + } + + #[wasm_bindgen(getter = "base")] + pub fn get_base(&self) -> TokenBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = "publicNote")] + pub fn get_public_note(&self) -> Option { + self.clone().0.public_note_owned() + } + + #[wasm_bindgen(getter = "emergencyAction")] + pub fn get_emergency_action(&self) -> String { + TokenEmergencyActionWASM::from(self.0.emergency_action()).into() + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + self.0.set_base(base.into()) + } + + #[wasm_bindgen(setter = "publicNote")] + pub fn set_public_note(&mut self, note: Option) { + self.0.set_public_note(note) + } + + #[wasm_bindgen(setter = "emergencyAction")] + pub fn set_emergency_action(&mut self, action: TokenEmergencyActionWASM) { + self.0.set_emergency_action(action.into()) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs new file mode 100644 index 00000000000..f97937864e9 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs @@ -0,0 +1,91 @@ +use dpp::identifier::Identifier; +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; +use dpp::state_transition::batch_transition::token_freeze_transition::TokenFreezeTransitionV0; +use dpp::state_transition::batch_transition::token_freeze_transition::v0::v0_methods::TokenFreezeTransitionV0Methods; +use dpp::state_transition::batch_transition::TokenFreezeTransition; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::identifier::IdentifierWASM; +use crate::batch::token_base_transition::TokenBaseTransitionWASM; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=TokenFreezeTransitionWASM)] +pub struct TokenFreezeTransitionWASM(TokenFreezeTransition); + +impl From for TokenFreezeTransition { + fn from(transition: TokenFreezeTransitionWASM) -> Self { + transition.0 + } +} + +impl From for TokenFreezeTransitionWASM { + fn from(transition: TokenFreezeTransition) -> Self { + Self(transition) + } +} + +#[wasm_bindgen] +impl TokenFreezeTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenFreezeTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenFreezeTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + base: &TokenBaseTransitionWASM, + js_identity_to_freeze_id: &JsValue, + public_note: Option, + ) -> Result { + let identity_to_freeze_id: Identifier = + IdentifierWASM::try_from(js_identity_to_freeze_id)?.into(); + + Ok(TokenFreezeTransitionWASM(TokenFreezeTransition::V0( + TokenFreezeTransitionV0 { + base: base.clone().into(), + identity_to_freeze_id, + public_note, + }, + ))) + } + + #[wasm_bindgen(getter = "base")] + pub fn get_base(&self) -> TokenBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = "publicNote")] + pub fn get_public_note(&self) -> Option { + self.clone().0.public_note_owned() + } + + #[wasm_bindgen(getter = "frozenIdentityId")] + pub fn get_frozen_identity_id(&self) -> IdentifierWASM { + self.0.frozen_identity_id().into() + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + self.0.set_base(base.into()) + } + + #[wasm_bindgen(setter = "publicNote")] + pub fn set_public_note(&mut self, note: Option) { + self.0.set_public_note(note) + } + + #[wasm_bindgen(setter = "frozenIdentityId")] + pub fn set_frozen_identity_id( + &mut self, + js_frozen_identity_id: &JsValue, + ) -> Result<(), JsValue> { + self.0 + .set_frozen_identity_id(IdentifierWASM::try_from(js_frozen_identity_id)?.into()); + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs new file mode 100644 index 00000000000..f0573858e39 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs @@ -0,0 +1,126 @@ +use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use dpp::prelude::Identifier; +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; +use dpp::state_transition::batch_transition::TokenMintTransition; +use dpp::state_transition::batch_transition::token_mint_transition::TokenMintTransitionV0; +use dpp::state_transition::batch_transition::token_mint_transition::v0::v0_methods::TokenMintTransitionV0Methods; +use crate::identifier::IdentifierWASM; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::token_configuration::TokenConfigurationWASM; +use crate::utils::WithJsError; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=TokenMintTransitionWASM)] +pub struct TokenMintTransitionWASM(TokenMintTransition); + +impl From for TokenMintTransitionWASM { + fn from(transition: TokenMintTransition) -> Self { + Self(transition) + } +} + +impl From for TokenMintTransition { + fn from(transition: TokenMintTransitionWASM) -> Self { + transition.0 + } +} + +#[wasm_bindgen] +impl TokenMintTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenMintTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenMintTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + base: &TokenBaseTransitionWASM, + js_issued_to_identity_id: &JsValue, + amount: u64, + public_note: Option, + ) -> Result { + let issued_to_identity_id: Option = + match js_issued_to_identity_id.is_undefined() { + false => Some(IdentifierWASM::try_from(js_issued_to_identity_id)?.into()), + true => None, + }; + + Ok(TokenMintTransitionWASM(TokenMintTransition::V0( + TokenMintTransitionV0 { + base: base.clone().into(), + issued_to_identity_id, + amount, + public_note, + }, + ))) + } + + #[wasm_bindgen(getter = issuedToIdentityId)] + pub fn issued_to_identity_id(&self) -> Option { + match self.0.issued_to_identity_id() { + None => None, + Some(id) => Some(id.into()), + } + } + + #[wasm_bindgen(getter = amount)] + pub fn get_amount(&self) -> u64 { + self.0.amount() + } + + #[wasm_bindgen(getter = base)] + pub fn get_base(&self) -> TokenBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = publicNote)] + pub fn get_public_note(&self) -> Option { + self.clone().0.public_note_owned() + } + + #[wasm_bindgen(js_name = getRecipitnId)] + pub fn recipient_id(&self, config: &TokenConfigurationWASM) -> Result { + Ok(self + .0 + .recipient_id(&config.clone().into()) + .with_js_error()? + .into()) + } + + #[wasm_bindgen(setter = issuedToIdentityId)] + pub fn set_issued_to_identity_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { + match js_id.is_undefined() { + true => { + self.0.set_issued_to_identity_id(None); + } + false => { + let id = IdentifierWASM::try_from(js_id)?; + + self.0.set_issued_to_identity_id(Some(id.into())); + } + } + + Ok(()) + } + + #[wasm_bindgen(setter = amount)] + pub fn set_amount(&mut self, amount: u64) { + self.0.set_amount(amount) + } + + #[wasm_bindgen(setter = base)] + pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + self.0.set_base(base.into()) + } + + #[wasm_bindgen(setter = publicNote)] + pub fn set_public_note(&mut self, note: Option) { + self.0.set_public_note(note) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs new file mode 100644 index 00000000000..589e36f4675 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs @@ -0,0 +1,185 @@ +use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use dpp::prelude::Identifier; +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; +use dpp::state_transition::batch_transition::TokenTransferTransition; +use dpp::state_transition::batch_transition::token_transfer_transition::TokenTransferTransitionV0; +use dpp::state_transition::batch_transition::token_transfer_transition::v0::v0_methods::TokenTransferTransitionV0Methods; +use dpp::tokens::{PrivateEncryptedNote, SharedEncryptedNote}; +use crate::identifier::IdentifierWASM; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::encrypted_note::private_encrypted_note::PrivateEncryptedNoteWASM; +use crate::encrypted_note::shared_encrypted_note::SharedEncryptedNoteWASM; +use crate::utils::IntoWasm; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=TokenTransferTransitionWASM)] +pub struct TokenTransferTransitionWASM(TokenTransferTransition); + +impl From for TokenTransferTransitionWASM { + fn from(transition: TokenTransferTransition) -> Self { + Self(transition) + } +} + +impl From for TokenTransferTransition { + fn from(transition: TokenTransferTransitionWASM) -> Self { + transition.0 + } +} + +#[wasm_bindgen] +impl TokenTransferTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenTransferTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenTransferTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + base: &TokenBaseTransitionWASM, + js_recipient_id: &JsValue, + amount: u64, + public_note: Option, + js_shared_encrypted_note: &JsValue, + js_private_encrypted_note: &JsValue, + ) -> Result { + let recipient_id: Identifier = IdentifierWASM::try_from(js_recipient_id)?.into(); + + let shared_encrypted_note: Option = + match js_shared_encrypted_note.is_undefined() { + true => None, + false => Some( + js_shared_encrypted_note + .to_wasm::("SharedEncryptedNoteWASM")? + .clone() + .into(), + ), + }; + + let private_encrypted_note: Option = + match js_private_encrypted_note.is_undefined() { + true => None, + false => Some( + js_private_encrypted_note + .to_wasm::("PrivateEncryptedNoteWASM")? + .clone() + .into(), + ), + }; + + Ok(TokenTransferTransitionWASM(TokenTransferTransition::V0( + TokenTransferTransitionV0 { + base: base.clone().into(), + recipient_id, + amount, + public_note, + shared_encrypted_note, + private_encrypted_note, + }, + ))) + } + + #[wasm_bindgen(getter = "amount")] + pub fn get_amount(&self) -> u64 { + self.0.amount() + } + + #[wasm_bindgen(getter = "base")] + pub fn get_base(&self) -> TokenBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = "publicNote")] + pub fn get_public_note(&self) -> Option { + self.clone().0.public_note_owned() + } + + #[wasm_bindgen(getter = "sharedEncryptedNote")] + pub fn get_shared_encrypted_note(&self) -> Option { + match self.clone().0.shared_encrypted_note_owned() { + Some(shared_encrypted_note) => Some(shared_encrypted_note.into()), + None => None, + } + } + + #[wasm_bindgen(getter = "privateEncryptedNote")] + pub fn get_private_encrypted_note(&self) -> Option { + match self.clone().0.private_encrypted_note_owned() { + Some(private_encrypted_note) => Some(private_encrypted_note.into()), + None => None, + } + } + + #[wasm_bindgen(getter = recipientId)] + pub fn recipient_id(&self) -> IdentifierWASM { + self.0.recipient_id().into() + } + + #[wasm_bindgen(setter = recipientId)] + pub fn set_recipient_id(&mut self, js_recipient: &JsValue) -> Result<(), JsValue> { + let recipient = IdentifierWASM::try_from(js_recipient)?; + + self.0.set_recipient_id(recipient.into()); + + Ok(()) + } + + #[wasm_bindgen(setter = "amount")] + pub fn set_amount(&mut self, amount: u64) { + self.0.set_amount(amount) + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + self.0.set_base(base.into()) + } + + #[wasm_bindgen(setter = "publicNote")] + pub fn set_public_note(&mut self, note: Option) { + self.0.set_public_note(note) + } + + #[wasm_bindgen(setter = "sharedEncryptedNote")] + pub fn set_shared_encrypted_note( + &mut self, + js_shared_encrypted_note: &JsValue, + ) -> Result<(), JsValue> { + let shared_encrypted_note: Option = + match js_shared_encrypted_note.is_undefined() { + true => None, + false => Some( + js_shared_encrypted_note + .to_wasm::("SharedEncryptedNoteWASM")? + .clone() + .into(), + ), + }; + + Ok(self.0.set_shared_encrypted_note(shared_encrypted_note)) + } + + #[wasm_bindgen(setter = "privateEncryptedNote")] + pub fn set_private_encrypted_note( + &mut self, + js_private_encrypted_note: &JsValue, + ) -> Result<(), JsValue> { + let private_encrypted_note: Option = + match js_private_encrypted_note.is_undefined() { + true => None, + false => Some( + js_private_encrypted_note + .to_wasm::("PrivateEncryptedNoteWASM")? + .clone() + .into(), + ), + }; + + Ok(self.0.set_private_encrypted_note(private_encrypted_note)) + } +} diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs new file mode 100644 index 00000000000..e6c0055edb6 --- /dev/null +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs @@ -0,0 +1,91 @@ +use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use dpp::identifier::Identifier; +use dpp::state_transition::batch_transition::token_unfreeze_transition::TokenUnfreezeTransitionV0; +use dpp::state_transition::batch_transition::TokenUnfreezeTransition; +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; +use dpp::state_transition::batch_transition::token_unfreeze_transition::v0::v0_methods::TokenUnfreezeTransitionV0Methods; +use crate::identifier::IdentifierWASM; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=TokenUnFreezeTransitionWASM)] +pub struct TokenUnFreezeTransitionWASM(TokenUnfreezeTransition); + +impl From for TokenUnFreezeTransitionWASM { + fn from(transition: TokenUnfreezeTransition) -> Self { + Self(transition) + } +} + +impl From for TokenUnfreezeTransition { + fn from(transition: TokenUnFreezeTransitionWASM) -> Self { + transition.0 + } +} + +#[wasm_bindgen] +impl TokenUnFreezeTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenUnFreezeTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenUnFreezeTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + base: &TokenBaseTransitionWASM, + js_frozen_identity_id: &JsValue, + public_note: Option, + ) -> Result { + let frozen_identity_id: Identifier = + IdentifierWASM::try_from(js_frozen_identity_id)?.into(); + + Ok(TokenUnFreezeTransitionWASM(TokenUnfreezeTransition::V0( + TokenUnfreezeTransitionV0 { + base: base.clone().into(), + frozen_identity_id, + public_note, + }, + ))) + } + + #[wasm_bindgen(getter = "base")] + pub fn get_base(&self) -> TokenBaseTransitionWASM { + self.0.base().clone().into() + } + + #[wasm_bindgen(getter = "publicNote")] + pub fn get_public_note(&self) -> Option { + self.clone().0.public_note_owned() + } + + #[wasm_bindgen(getter = "frozenIdentityId")] + pub fn get_frozen_identity_id(&self) -> IdentifierWASM { + self.0.frozen_identity_id().into() + } + + #[wasm_bindgen(setter = "base")] + pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + self.0.set_base(base.into()) + } + + #[wasm_bindgen(setter = "publicNote")] + pub fn set_public_note(&mut self, note: Option) { + self.0.set_public_note(note) + } + + #[wasm_bindgen(setter = "frozenIdentityId")] + pub fn set_frozen_identity_id( + &mut self, + js_frozen_identity_id: &JsValue, + ) -> Result<(), JsValue> { + self.0 + .set_frozen_identity_id(IdentifierWASM::try_from(js_frozen_identity_id)?.into()); + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/consensus_error/mod.rs b/packages/wasm-dpp2/src/consensus_error/mod.rs new file mode 100644 index 00000000000..3cad23d9c2b --- /dev/null +++ b/packages/wasm-dpp2/src/consensus_error/mod.rs @@ -0,0 +1,23 @@ +use crate::utils::WithJsError; +use dpp::consensus::ConsensusError; +use dpp::serialization::PlatformDeserializable; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "ConsensusErrorWASM")] +pub struct ConsensusErrorWASM(ConsensusError); + +#[wasm_bindgen] +impl ConsensusErrorWASM { + #[wasm_bindgen(js_name = "deserialize")] + pub fn deserialize(error: Vec) -> Result { + Ok(ConsensusErrorWASM( + ConsensusError::deserialize_from_bytes(error.as_slice()).with_js_error()?, + )) + } + + #[wasm_bindgen(getter = "message")] + pub fn message(&self) -> String { + self.0.to_string() + } +} diff --git a/packages/wasm-dpp2/src/contract_bounds/mod.rs b/packages/wasm-dpp2/src/contract_bounds/mod.rs new file mode 100644 index 00000000000..c248e638703 --- /dev/null +++ b/packages/wasm-dpp2/src/contract_bounds/mod.rs @@ -0,0 +1,130 @@ +use crate::identifier::IdentifierWASM; +use dpp::identity::contract_bounds::ContractBounds; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "ContractBoundsWASM")] +#[derive(Clone)] +pub struct ContractBoundsWASM(ContractBounds); + +impl From for ContractBoundsWASM { + fn from(bounds: ContractBounds) -> Self { + ContractBoundsWASM(bounds) + } +} + +impl From for ContractBounds { + fn from(bounds: ContractBoundsWASM) -> Self { + bounds.0 + } +} + +#[wasm_bindgen] +impl ContractBoundsWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "ContractBoundsWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "ContractBoundsWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_contract_id: &JsValue, + document_type_name: Option, + ) -> Result { + let contract_id = IdentifierWASM::try_from(js_contract_id)?; + + Ok(ContractBoundsWASM(match document_type_name { + Some(document_type_name) => ContractBounds::SingleContractDocumentType { + id: contract_id.into(), + document_type_name, + }, + None => ContractBounds::SingleContract { + id: contract_id.into(), + }, + })) + } + + #[wasm_bindgen(js_name = "SingleContract")] + pub fn single_contract(js_contract_id: &JsValue) -> Result { + let contract_id = IdentifierWASM::try_from(js_contract_id)?; + + Ok(ContractBoundsWASM(ContractBounds::SingleContract { + id: contract_id.into(), + })) + } + + #[wasm_bindgen(js_name = "SingleContractDocumentType")] + pub fn single_contract_document_type_name( + js_contract_id: &JsValue, + document_type_name: String, + ) -> Result { + let contract_id = IdentifierWASM::try_from(js_contract_id)?; + + Ok(ContractBoundsWASM( + ContractBounds::SingleContractDocumentType { + id: contract_id.into(), + document_type_name, + }, + )) + } + + #[wasm_bindgen(getter = "identifier")] + pub fn id(&self) -> IdentifierWASM { + self.0.identifier().clone().into() + } + + #[wasm_bindgen(getter = "documentTypeName")] + pub fn document_type_name(&self) -> Option { + match self.0.document_type() { + Some(name) => Some(name.clone()), + None => None, + } + } + + #[wasm_bindgen(getter = "contractBoundsType")] + pub fn contract_bounds_type(&self) -> String { + self.0.contract_bounds_type_string().into() + } + + #[wasm_bindgen(getter = "contractBoundsTypeNumber")] + pub fn contract_bounds_type_number(&self) -> u8 { + self.0.contract_bounds_type() + } + + #[wasm_bindgen(setter = "identifier")] + pub fn set_id(&mut self, js_contract_id: &JsValue) -> Result<(), JsValue> { + let contract_id = IdentifierWASM::try_from(js_contract_id)?; + + self.0 = match self.clone().0 { + ContractBounds::SingleContract { .. } => ContractBounds::SingleContract { + id: contract_id.into(), + }, + ContractBounds::SingleContractDocumentType { + document_type_name, .. + } => ContractBounds::SingleContractDocumentType { + id: contract_id.into(), + document_type_name, + }, + }; + + Ok(()) + } + + #[wasm_bindgen(setter = "documentTypeName")] + pub fn set_document_type_name(&mut self, document_type_name: String) { + self.0 = match self.clone().0 { + ContractBounds::SingleContract { .. } => self.clone().0, + ContractBounds::SingleContractDocumentType { id, .. } => { + ContractBounds::SingleContractDocumentType { + id, + document_type_name, + } + } + } + } +} diff --git a/packages/wasm-dpp2/src/core_script/mod.rs b/packages/wasm-dpp2/src/core_script/mod.rs new file mode 100644 index 00000000000..1dd5fdced7b --- /dev/null +++ b/packages/wasm-dpp2/src/core_script/mod.rs @@ -0,0 +1,105 @@ +use crate::enums::network::NetworkWASM; +use dpp::dashcore::address::Payload; +use dpp::dashcore::{Address, opcodes}; +use dpp::identity::core_script::CoreScript; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::encode; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "CoreScriptWASM")] +#[derive(Clone)] +pub struct CoreScriptWASM(CoreScript); + +impl From for CoreScript { + fn from(value: CoreScriptWASM) -> Self { + value.0 + } +} + +impl From for CoreScriptWASM { + fn from(value: CoreScript) -> Self { + CoreScriptWASM(value) + } +} + +#[wasm_bindgen] +impl CoreScriptWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "CoreScriptWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "CoreScriptWASM".to_string() + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Self { + CoreScriptWASM(CoreScript::from_bytes(bytes)) + } + + #[wasm_bindgen(js_name = "newP2PKH")] + pub fn new_p2pkh(js_key_hash: Vec) -> Self { + let mut key_hash = [0u8; 20]; + let bytes = js_key_hash.as_slice(); + let len = bytes.len().min(32); + key_hash[..len].copy_from_slice(&bytes[..len]); + + CoreScriptWASM(CoreScript::new_p2pkh(key_hash)) + } + + #[wasm_bindgen(js_name = "newP2SH")] + pub fn new_p2sh(js_script_hash: Vec) -> Self { + let mut script_hash = [0u8; 20]; + let bytes = js_script_hash.as_slice(); + let len = bytes.len().min(32); + script_hash[..len].copy_from_slice(&bytes[..len]); + + let mut bytes = vec![ + opcodes::all::OP_HASH160.to_u8(), + opcodes::all::OP_PUSHBYTES_20.to_u8(), + ]; + bytes.extend_from_slice(&script_hash); + bytes.push(opcodes::all::OP_EQUAL.to_u8()); + Self::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "toAddress")] + pub fn to_address(&self, js_network: &JsValue) -> Result { + let network = NetworkWASM::try_from(js_network.clone())?; + + let payload = + Payload::from_script(self.0.as_script()).map_err(|e| JsValue::from(e.to_string()))?; + + let address = Address::new(network.into(), payload); + + Ok(address.to_string()) + } + + #[wasm_bindgen(js_name = "toString")] + pub fn to_string(&self) -> String { + self.0.to_string(Base64) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Vec { + self.0.to_bytes() + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_hex(&self) -> String { + encode(self.0.to_bytes().as_slice(), Hex) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> String { + encode(self.0.to_bytes().as_slice(), Base64) + } + + #[wasm_bindgen(js_name = "ASMString")] + pub fn to_asm_string(&self) -> String { + self.0.to_asm_string() + } +} diff --git a/packages/wasm-dpp2/src/data_contract/mod.rs b/packages/wasm-dpp2/src/data_contract/mod.rs new file mode 100644 index 00000000000..39cc4835f09 --- /dev/null +++ b/packages/wasm-dpp2/src/data_contract/mod.rs @@ -0,0 +1,502 @@ +use crate::enums::platform::PlatformVersionWASM; +use crate::identifier::IdentifierWASM; +use crate::token_configuration::TokenConfigurationWASM; +use crate::token_configuration::group::GroupWASM; +use crate::utils::{IntoWasm, ToSerdeJSONExt, WithJsError}; +use dpp::dashcore::hashes::serde::Serialize; +use dpp::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters}; +use dpp::data_contract::accessors::v1::{DataContractV1Getters, DataContractV1Setters}; +use dpp::data_contract::config::DataContractConfig; +use dpp::data_contract::conversion::json::DataContractJsonConversionMethodsV0; +use dpp::data_contract::conversion::value::v0::DataContractValueConversionMethodsV0; +use dpp::data_contract::document_type::DocumentTypeRef; +use dpp::data_contract::errors::DataContractError; +use dpp::data_contract::group::Group; +use dpp::data_contract::schema::DataContractSchemaMethodsV0; +use dpp::data_contract::{ + DataContract, GroupContractPosition, TokenConfiguration, TokenContractPosition, +}; +use dpp::platform_value::string_encoding::Encoding::{Base58, Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::platform_value::{Value, ValueMap}; +use dpp::prelude::IdentityNonce; +use dpp::serialization::{ + PlatformDeserializableWithPotentialValidationFromVersionedStructure, + PlatformSerializableWithPlatformVersion, +}; +use dpp::version::PlatformVersion; +use js_sys::{Object, Reflect}; +use std::collections::BTreeMap; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[wasm_bindgen(js_name = "DataContractWASM")] +#[derive(Clone)] +pub struct DataContractWASM(DataContract); + +impl From for DataContractWASM { + fn from(v: DataContract) -> Self { + DataContractWASM(v) + } +} + +impl From for DataContract { + fn from(v: DataContractWASM) -> Self { + v.0 + } +} + +pub fn tokens_configuration_from_js_value( + js_configuration: &JsValue, +) -> Result, JsValue> { + let configuration_object = Object::from(js_configuration.clone()); + let configuration_keys = Object::keys(&configuration_object); + + let mut configuration: BTreeMap = BTreeMap::new(); + + for key in configuration_keys.iter() { + let contract_position = match key.as_string() { + None => Err(JsValue::from("Cannot read timestamp in distribution rules")), + Some(contract_position) => Ok(contract_position + .parse::() + .map_err(JsError::from)?), + }?; + + let js_config = Reflect::get(&js_configuration, &key)? + .to_wasm::("TokenConfigurationWASM")? + .clone(); + + configuration.insert(contract_position, js_config.into()); + } + + Ok(configuration) +} + +#[wasm_bindgen] +impl DataContractWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DataContractWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DataContractWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn from_js_values( + js_owner_id: &JsValue, + identity_nonce: IdentityNonce, + js_schema: JsValue, + js_definitions: Option, + js_tokens: &JsValue, + full_validation: bool, + js_platform_version: JsValue, + ) -> Result { + let serializer = serde_wasm_bindgen::Serializer::json_compatible(); + + let owner_id: IdentifierWASM = js_owner_id.clone().try_into()?; + + let owner_id_value = Value::from(owner_id.get_base58()); + + let schema: Value = serde_wasm_bindgen::from_value(js_schema)?; + + let tokens: BTreeMap = + match js_tokens.is_undefined() { + true => BTreeMap::new(), + false => tokens_configuration_from_js_value(js_tokens)?, + }; + + let platform_version: PlatformVersion = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default().into(), + false => PlatformVersionWASM::try_from(js_platform_version)?.into(), + }; + + let data_contract_structure_version_value = Value::from( + platform_version + .dpp + .contract_versions + .contract_structure_version + .to_string(), + ); + + let definitions = js_definitions + .map(|definitions| serde_wasm_bindgen::from_value(definitions.into())) + .transpose()?; + + let definitions_value = Value::from(definitions); + + let data_contract_id = + DataContract::generate_data_contract_id_v0(owner_id.get_bytes(), identity_nonce); + + let data_contract_id_value = Value::from(data_contract_id.to_string(Base58)); + + let config = + DataContractConfig::default_for_version(&platform_version.clone()).with_js_error()?; + + let config_value = config + .serialize(&serializer) + .map_err(JsValue::from)? + .with_serde_to_platform_value_map()?; + + let mut contract_value = Value::Map(ValueMap::new()); + + contract_value + .set_value("$format_version", data_contract_structure_version_value) + .map_err(|err| JsValue::from(err.to_string()))?; + + contract_value + .set_value("id", data_contract_id_value) + .map_err(|err| JsValue::from(err.to_string()))?; + + contract_value + .set_value("config", Value::from(config_value)) + .map_err(|err| JsValue::from(err.to_string()))?; + + contract_value + .set_value("version", Value::from(1u16)) + .map_err(|err| JsValue::from(err.to_string()))?; + + contract_value + .set_value("ownerId", owner_id_value) + .map_err(|err| JsValue::from(err.to_string()))?; + + contract_value + .set_value("schemaDefs", definitions_value) + .map_err(|err| JsValue::from(err.to_string()))?; + + contract_value + .set_value("documentSchemas", schema) + .map_err(|err| JsValue::from(err.to_string()))?; + + let data_contract = + DataContract::from_value(contract_value, full_validation, &platform_version) + .with_js_error()?; + + let data_contract_with_tokens = match data_contract { + DataContract::V0(v0) => DataContract::from(v0), + DataContract::V1(mut v1) => { + v1.set_tokens(tokens); + + DataContract::from(v1) + } + }; + + Ok(DataContractWASM(data_contract_with_tokens)) + } + + #[wasm_bindgen(js_name = "fromValue")] + pub fn from_value( + js_value: JsValue, + full_validation: bool, + js_platform_version: JsValue, + ) -> Result { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let value = js_value.with_serde_to_platform_value()?; + + let contract = DataContract::from_value(value, full_validation, &platform_version.into()) + .with_js_error()?; + + Ok(DataContractWASM(contract)) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes( + bytes: Vec, + full_validation: bool, + js_platform_version: JsValue, + ) -> Result { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let rs_data_contract = DataContract::versioned_deserialize( + &bytes.as_slice(), + full_validation, + &platform_version.into(), + ) + .with_js_error()?; + + Ok(DataContractWASM(rs_data_contract)) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex( + hex: String, + full_validation: bool, + js_platform_version: JsValue, + ) -> Result { + DataContractWASM::from_bytes( + decode(hex.as_str(), Hex).map_err(JsError::from)?, + full_validation, + js_platform_version, + ) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64( + base64: String, + full_validation: bool, + js_platform_version: JsValue, + ) -> Result { + DataContractWASM::from_bytes( + decode(base64.as_str(), Base64).map_err(JsError::from)?, + full_validation, + js_platform_version, + ) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self, js_platform_version: JsValue) -> Result, JsValue> { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let rs_data_contract: DataContract = self.0.clone(); + + rs_data_contract + .serialize_to_bytes_with_platform_version(&platform_version.into()) + .with_js_error() + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_hex(&self, js_platform_version: JsValue) -> Result { + Ok(encode(self.to_bytes(js_platform_version)?.as_slice(), Hex)) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self, js_platform_version: JsValue) -> Result { + Ok(encode( + self.to_bytes(js_platform_version)?.as_slice(), + Base64, + )) + } + + #[wasm_bindgen(js_name = "toValue")] + pub fn to_value(&self, js_platform_version: JsValue) -> Result { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let serializer = serde_wasm_bindgen::Serializer::json_compatible(); + + self.0 + .clone() + .to_value(&platform_version.into()) + .with_js_error()? + .serialize(&serializer) + .map_err(JsValue::from) + } + + #[wasm_bindgen(js_name = "getSchemas")] + pub fn get_schemas(&self) -> Result { + let serializer = serde_wasm_bindgen::Serializer::json_compatible(); + + self.0 + .document_schemas() + .serialize(&serializer) + .map_err(JsValue::from) + } + + #[wasm_bindgen(getter = "version")] + pub fn get_version(&self) -> u32 { + self.0.version() + } + + #[wasm_bindgen(getter = "id")] + pub fn get_id(&self) -> IdentifierWASM { + self.0.id().into() + } + + #[wasm_bindgen(getter = "ownerId")] + pub fn get_owner_id(&self) -> IdentifierWASM { + self.0.owner_id().into() + } + + #[wasm_bindgen(js_name = "getConfig")] + pub fn get_config(&self) -> Result { + self.0 + .config() + .serialize(&serde_wasm_bindgen::Serializer::json_compatible()) + .map_err(JsValue::from) + } + + #[wasm_bindgen(getter = "tokens")] + pub fn get_tokens(&self) -> Result { + let tokens_object = Object::new(); + + for (key, value) in self.0.tokens().iter() { + Reflect::set( + &tokens_object, + &JsValue::from(key.clone()), + &JsValue::from(TokenConfigurationWASM::from(value.clone())), + )?; + } + + Ok(tokens_object) + } + + #[wasm_bindgen(getter = "groups")] + pub fn get_groups(&self) -> Result { + let groups_object = Object::new(); + + for (key, value) in self.0.groups().iter() { + Reflect::set( + &groups_object, + &JsValue::from(key.clone()), + &JsValue::from(GroupWASM::from(value.clone())), + )?; + } + + Ok(groups_object.into()) + } + + #[wasm_bindgen(setter = "id")] + pub fn set_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> { + self.0 + .set_id(IdentifierWASM::try_from(js_data_contract_id)?.into()); + Ok(()) + } + + #[wasm_bindgen(setter = "ownerId")] + pub fn set_owner_id(&mut self, js_owner_id: &JsValue) -> Result<(), JsValue> { + self.0 + .set_owner_id(IdentifierWASM::try_from(js_owner_id)?.into()); + Ok(()) + } + + #[wasm_bindgen(setter = "version")] + pub fn set_version(&mut self, version: u32) { + self.0.set_version(version) + } + + #[wasm_bindgen(js_name = "setConfig")] + pub fn set_config( + &mut self, + js_config: JsValue, + js_platform_version: JsValue, + ) -> Result<(), JsValue> { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let config_value: Value = serde_wasm_bindgen::from_value(js_config)?; + + let config = DataContractConfig::from_value(config_value, &platform_version.into()) + .with_js_error()?; + + self.0.set_config(config); + + Ok(()) + } + + #[wasm_bindgen(js_name = "setSchemas")] + pub fn set_schemas( + &mut self, + js_schema: JsValue, + js_definitions: Option, + full_validation: bool, + js_platform_version: JsValue, + ) -> Result<(), JsValue> { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let schema = js_schema.with_serde_to_platform_value_map()?; + + let definitions: Option> = js_definitions + .map(|definitions| serde_wasm_bindgen::from_value(definitions.into())) + .transpose()?; + + self.0 + .set_document_schemas( + schema, + definitions, + full_validation, + &mut Vec::new(), + &platform_version.into(), + ) + .with_js_error()?; + + Ok(()) + } + + #[wasm_bindgen(setter = "tokens")] + pub fn set_tokens(&mut self, js_tokens: &JsValue) -> Result<(), JsValue> { + Ok(self + .0 + .set_tokens(tokens_configuration_from_js_value(js_tokens)?)) + } + + #[wasm_bindgen(setter = "groups")] + pub fn set_groups(&mut self, js_groups: &JsValue) -> Result<(), JsValue> { + let groups_object = Object::from(js_groups.clone()); + + let mut groups: BTreeMap = BTreeMap::new(); + + for js_position in Object::keys(&groups_object) { + if js_position.as_f64().unwrap() > u16::MAX as f64 { + return Err(JsValue::from_str(&format!( + "Position value '{:?}' exceeds the maximum limit for u16.", + js_position.as_string() + ))); + } + + let position = js_position.as_f64().unwrap() as u16; + + let js_group = Reflect::get(&groups_object, &js_position)?; + + let group = js_group.to_wasm::("GroupWASM")?.clone(); + + groups.insert(position, group.into()); + } + + self.0.set_groups(groups); + + Ok(()) + } + + #[wasm_bindgen(js_name = "toJson")] + pub fn to_json(&self, js_platform_version: JsValue) -> Result { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let json = self.0.to_json(&platform_version.into()).with_js_error()?; + + json.serialize(&serde_wasm_bindgen::Serializer::json_compatible()) + .map_err(JsValue::from) + } + + #[wasm_bindgen(js_name = "generateId")] + pub fn generate_id( + js_owner_id: &JsValue, + identity_nonce: IdentityNonce, + ) -> Result { + Ok(DataContract::generate_data_contract_id_v0( + IdentifierWASM::try_from(js_owner_id)?.get_bytes(), + identity_nonce, + ) + .into()) + } +} + +impl DataContractWASM { + pub fn get_document_type_ref_by_name( + &self, + name: String, + ) -> Result { + self.0.document_type_for_name(name.as_str()).clone() + } +} diff --git a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs new file mode 100644 index 00000000000..63103699f87 --- /dev/null +++ b/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs @@ -0,0 +1,208 @@ +use crate::data_contract::DataContractWASM; +use crate::enums::platform::PlatformVersionWASM; +use crate::state_transition::StateTransitionWASM; +use crate::utils::WithJsError; +use dpp::ProtocolError; +use dpp::data_contract::serialized_version::DataContractInSerializationFormat; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::prelude::{DataContract, IdentityNonce}; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable}; +use dpp::state_transition::StateTransition; +use dpp::state_transition::data_contract_create_transition::accessors::DataContractCreateTransitionAccessorsV0; +use dpp::state_transition::data_contract_create_transition::{ + DataContractCreateTransition, DataContractCreateTransitionV0, +}; +use dpp::validation::operations::ProtocolValidationOperation; +use dpp::version::{ + FeatureVersion, ProtocolVersion, TryFromPlatformVersioned, TryIntoPlatformVersioned, +}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[wasm_bindgen(js_name = "DataContractCreateTransitionWASM")] +pub struct DataContractCreateTransitionWASM(DataContractCreateTransition); + +#[wasm_bindgen] +impl DataContractCreateTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DataContractCreateTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DataContractCreateTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + data_contract: &DataContractWASM, + identity_nonce: IdentityNonce, + js_platform_version: JsValue, + ) -> Result { + let rs_data_contract: DataContract = data_contract.clone().into(); + + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let rs_data_contract_in_serialized: Result< + DataContractInSerializationFormat, + ProtocolError, + > = rs_data_contract.try_into_platform_versioned(&platform_version.into()); + + let rs_data_contract_create_transition_v0: DataContractCreateTransitionV0 = + DataContractCreateTransitionV0 { + data_contract: rs_data_contract_in_serialized.with_js_error()?, + identity_nonce, + user_fee_increase: 0, + signature_public_key_id: 0, + signature: Default::default(), + }; + + let rs_data_contract_transition = + DataContractCreateTransition::V0(rs_data_contract_create_transition_v0); + + Ok(DataContractCreateTransitionWASM( + rs_data_contract_transition, + )) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + let rs_data_contract_create_transition: DataContractCreateTransition = + DataContractCreateTransition::deserialize_from_bytes(bytes.as_slice()) + .with_js_error()?; + + Ok(DataContractCreateTransitionWASM( + rs_data_contract_create_transition, + )) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + + DataContractCreateTransitionWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> Result { + let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + + DataContractCreateTransitionWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Result, JsValue> { + self.0.serialize_to_bytes().with_js_error() + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_hex(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Hex, + )) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Base64, + )) + } + + #[wasm_bindgen(getter = "featureVersion")] + pub fn get_feature_version(&self) -> FeatureVersion { + self.0.feature_version() + } + + #[wasm_bindgen(js_name = "verifyProtocolVersion")] + pub fn verify_protocol_version( + &self, + protocol_version: ProtocolVersion, + ) -> Result { + self.0 + .verify_protocol_version(protocol_version) + .with_js_error() + } + + #[wasm_bindgen(js_name = "setDataContract")] + pub fn set_data_contract( + &mut self, + data_contract: &DataContractWASM, + js_platform_version: JsValue, + ) -> Result<(), JsValue> { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let data_contract_serialization_format = + DataContractInSerializationFormat::try_from_platform_versioned( + DataContract::from(data_contract.clone()), + &platform_version.into(), + ) + .with_js_error()?; + + self.0.set_data_contract(data_contract_serialization_format); + + Ok(()) + } + + #[wasm_bindgen(getter = "identityNonce")] + pub fn get_identity_nonce(&self) -> IdentityNonce { + self.0.identity_nonce() + } + + #[wasm_bindgen(js_name = "getDataContract")] + pub fn get_data_contract( + &self, + js_platform_version: JsValue, + full_validation: Option, + ) -> Result { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let rs_data_contract_serialization_format = self.0.data_contract(); + + let mut validation_operations: Vec = Vec::new(); + + let rs_data_contract = DataContract::try_from_platform_versioned( + rs_data_contract_serialization_format.clone(), + full_validation.unwrap_or(false), + &mut validation_operations, + &platform_version.into(), + ) + .with_js_error()?; + + Ok(DataContractWASM::from(rs_data_contract)) + } + + #[wasm_bindgen(js_name = "toStateTransition")] + pub fn to_state_transition(&self) -> StateTransitionWASM { + let rs_state_transition = StateTransition::from(self.0.clone()); + + StateTransitionWASM::from(rs_state_transition) + } + + #[wasm_bindgen(js_name = "fromStateTransition")] + pub fn from_state_transition( + state_transition: &StateTransitionWASM, + ) -> Result { + let rs_transition = StateTransition::from(state_transition.clone()); + + match rs_transition { + StateTransition::DataContractCreate(state_transition) => { + Ok(DataContractCreateTransitionWASM(state_transition)) + } + _ => Err(JsValue::from("Incorrect transition type")), + } + } +} diff --git a/packages/wasm-dpp2/src/data_contract_transitions/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/mod.rs new file mode 100644 index 00000000000..82a5ce72ba7 --- /dev/null +++ b/packages/wasm-dpp2/src/data_contract_transitions/mod.rs @@ -0,0 +1,2 @@ +pub mod create; +pub mod update; diff --git a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs new file mode 100644 index 00000000000..09b60db04e5 --- /dev/null +++ b/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs @@ -0,0 +1,191 @@ +use crate::data_contract::DataContractWASM; +use crate::enums::platform::PlatformVersionWASM; +use crate::state_transition::StateTransitionWASM; +use crate::utils::WithJsError; +use dpp::data_contract::serialized_version::DataContractInSerializationFormat; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::prelude::{DataContract, IdentityNonce}; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable}; +use dpp::state_transition::StateTransition; +use dpp::state_transition::data_contract_update_transition::DataContractUpdateTransition; +use dpp::state_transition::data_contract_update_transition::accessors::DataContractUpdateTransitionAccessorsV0; +use dpp::validation::operations::ProtocolValidationOperation; +use dpp::version::{FeatureVersion, ProtocolVersion, TryFromPlatformVersioned}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[wasm_bindgen(js_name = "DataContractUpdateTransitionWASM")] +pub struct DataContractUpdateTransitionWASM(DataContractUpdateTransition); + +#[wasm_bindgen] +impl DataContractUpdateTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DataContractUpdateTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DataContractUpdateTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + data_contract: &DataContractWASM, + identity_nonce: IdentityNonce, + js_platform_version: JsValue, + ) -> Result { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let rs_data_contract_update_transition = + DataContractUpdateTransition::try_from_platform_versioned( + (DataContract::from(data_contract.clone()), identity_nonce), + &platform_version.into(), + ) + .with_js_error()?; + + Ok(DataContractUpdateTransitionWASM( + rs_data_contract_update_transition, + )) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + let rs_data_contract_update_transition: DataContractUpdateTransition = + DataContractUpdateTransition::deserialize_from_bytes(bytes.as_slice()) + .with_js_error()?; + + Ok(DataContractUpdateTransitionWASM( + rs_data_contract_update_transition, + )) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + + DataContractUpdateTransitionWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> Result { + let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + + DataContractUpdateTransitionWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Result, JsValue> { + self.0.serialize_to_bytes().with_js_error() + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_hex(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Hex, + )) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Base64, + )) + } + + #[wasm_bindgen(getter = "featureVersion")] + pub fn get_feature_version(&self) -> FeatureVersion { + self.0.feature_version() + } + + #[wasm_bindgen(js_name = "verifyProtocolVersion")] + pub fn verify_protocol_version( + &self, + protocol_version: ProtocolVersion, + ) -> Result { + self.0 + .verify_protocol_version(protocol_version) + .with_js_error() + } + + #[wasm_bindgen(js_name = "setDataContract")] + pub fn set_data_contract( + &mut self, + data_contract: &DataContractWASM, + js_platform_version: JsValue, + ) -> Result<(), JsValue> { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let data_contract_serialization_format = + DataContractInSerializationFormat::try_from_platform_versioned( + DataContract::from(data_contract.clone()), + &platform_version.into(), + ) + .with_js_error()?; + + self.0.set_data_contract(data_contract_serialization_format); + + Ok(()) + } + + #[wasm_bindgen(getter = "identityContractNonce")] + pub fn get_identity_nonce(&self) -> IdentityNonce { + self.0.identity_contract_nonce() + } + + #[wasm_bindgen(js_name = "getDataContract")] + pub fn get_data_contract( + &self, + full_validation: Option, + js_platform_version: JsValue, + ) -> Result { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let data_contract_serialization_format = self.0.data_contract(); + + let mut validation_operations: Vec = Vec::new(); + + let rs_data_contract = DataContract::try_from_platform_versioned( + data_contract_serialization_format.clone(), + full_validation.unwrap_or(false), + &mut validation_operations, + &platform_version.into(), + ) + .with_js_error()?; + + Ok(DataContractWASM::from(rs_data_contract)) + } + + #[wasm_bindgen(js_name = "toStateTransition")] + pub fn to_state_transition(&self) -> StateTransitionWASM { + let rs_state_transition = StateTransition::from(self.0.clone()); + + StateTransitionWASM::from(rs_state_transition) + } + + #[wasm_bindgen(js_name = "fromStateTransition")] + pub fn from_state_transition( + state_transition: &StateTransitionWASM, + ) -> Result { + let rs_transition = StateTransition::from(state_transition.clone()); + + match rs_transition { + StateTransition::DataContractUpdate(state_transition) => { + Ok(DataContractUpdateTransitionWASM(state_transition)) + } + _ => Err(JsValue::from("Incorrect transition type")), + } + } +} diff --git a/packages/wasm-dpp2/src/document/methods/mod.rs b/packages/wasm-dpp2/src/document/methods/mod.rs new file mode 100644 index 00000000000..0cc38e7b852 --- /dev/null +++ b/packages/wasm-dpp2/src/document/methods/mod.rs @@ -0,0 +1,455 @@ +use crate::data_contract::DataContractWASM; +use crate::document::DocumentWASM; +use crate::enums::platform::PlatformVersionWASM; +use crate::identifier::IdentifierWASM; +use crate::utils::{ToSerdeJSONExt, WithJsError}; +use dpp::ProtocolError; +use dpp::dashcore::hashes::serde::Serialize; +use dpp::data_contract::JsonValue; +use dpp::document::Document; +use dpp::document::serialization_traits::DocumentPlatformConversionMethodsV0; +use dpp::identifier::Identifier; +use dpp::platform_value::Value; +use dpp::platform_value::converter::serde_json::BTreeValueJsonConverter; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::prelude::Revision; +use dpp::util::entropy_generator; +use dpp::util::entropy_generator::EntropyGenerator; +use std::collections::BTreeMap; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[wasm_bindgen] +impl DocumentWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DocumentWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DocumentWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_raw_document: JsValue, + js_document_type_name: &str, + js_revision: u64, + js_data_contract_id: &JsValue, + js_owner_id: &JsValue, + js_document_id: &JsValue, + ) -> Result { + let data_contract_id = IdentifierWASM::try_from(js_data_contract_id)?; + let owner_id = IdentifierWASM::try_from(js_owner_id)?; + + let revision = Revision::from(js_revision); + + let document = js_raw_document + .with_serde_to_platform_value_map() + .expect("cannot convert document to platform value map"); + + let revision = Revision::from(revision); + + let entropy = entropy_generator::DefaultEntropyGenerator + .generate() + .map_err(|err| JsValue::from(err.to_string()))?; + + let document_id: IdentifierWASM = match js_document_id.is_undefined() { + true => crate::utils::generate_document_id_v0( + &data_contract_id.into(), + &owner_id.into(), + js_document_type_name, + &entropy, + )? + .into(), + false => js_document_id.try_into()?, + }; + + Ok(DocumentWASM { + owner_id, + entropy: Some(entropy), + id: document_id, + document_type_name: js_document_type_name.to_string(), + data_contract_id, + properties: document, + revision: Some(revision), + created_at: None, + updated_at: None, + transferred_at: None, + created_at_block_height: None, + updated_at_block_height: None, + transferred_at_block_height: None, + created_at_core_block_height: None, + updated_at_core_block_height: None, + transferred_at_core_block_height: None, + }) + } + + #[wasm_bindgen(getter=id)] + pub fn get_id(&self) -> IdentifierWASM { + self.id + } + + #[wasm_bindgen(getter=entropy)] + pub fn get_entropy(&self) -> Option> { + match self.entropy { + Some(entropy) => Some(entropy.to_vec()), + None => None, + } + } + + #[wasm_bindgen(getter=dataContractId)] + pub fn get_data_contract_id(&self) -> IdentifierWASM { + self.data_contract_id + } + + #[wasm_bindgen(getter=ownerId)] + pub fn get_owner_id(&self) -> IdentifierWASM { + self.owner_id + } + + #[wasm_bindgen(getter=properties)] + pub fn get_properties(&self) -> Result { + let json_value: JsonValue = self + .properties + .clone() + .to_json_value() + .map_err(ProtocolError::ValueError) + .with_js_error()?; + + let js_value = json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?; + Ok(js_value) + } + + #[wasm_bindgen(getter=revision)] + pub fn get_revision(&self) -> Option { + self.revision + } + + #[wasm_bindgen(getter=createdAt)] + pub fn get_created_at(&self) -> Option { + self.created_at + } + + #[wasm_bindgen(getter=updatedAt)] + pub fn get_updated_at(&self) -> Option { + self.updated_at + } + + #[wasm_bindgen(getter=transferredAt)] + pub fn get_transferred_at(&self) -> Option { + self.transferred_at + } + + #[wasm_bindgen(getter=createdAtBlockHeight)] + pub fn get_created_at_block_height(&self) -> Option { + self.created_at_block_height + } + + #[wasm_bindgen(getter=updatedAtBlockHeight)] + pub fn get_updated_at_block_height(&self) -> Option { + self.updated_at_block_height + } + + #[wasm_bindgen(getter=transferredAtBlockHeight)] + pub fn get_transferred_at_block_height(&self) -> Option { + self.transferred_at_block_height + } + + #[wasm_bindgen(getter=createdAtCoreBlockHeight)] + pub fn get_created_at_core_block_height(&self) -> Option { + self.created_at_core_block_height + } + + #[wasm_bindgen(getter=updatedAtCoreBlockHeight)] + pub fn get_updated_at_core_block_height(&self) -> Option { + self.updated_at_core_block_height + } + + #[wasm_bindgen(getter=transferredAtCoreBlockHeight)] + pub fn get_transferred_at_core_block_height(&self) -> Option { + self.transferred_at_core_block_height + } + + #[wasm_bindgen(getter=documentTypeName)] + pub fn get_document_type_name(&self) -> String { + self.document_type_name.clone() + } + + #[wasm_bindgen(setter=id)] + pub fn set_id(&mut self, id: &JsValue) -> Result<(), JsValue> { + self.id = IdentifierWASM::try_from(id)?.clone(); + Ok(()) + } + + #[wasm_bindgen(setter=entropy)] + pub fn set_entropy(&mut self, entropy: JsValue) { + match entropy.is_undefined() { + false => { + let value = entropy.with_serde_to_platform_value().unwrap(); + + let mut entropy = [0u8; 32]; + let bytes = value.as_bytes().unwrap(); + let len = bytes.len().min(32); + entropy[..len].copy_from_slice(&bytes[..len]); + self.entropy = Some(entropy); + } + true => self.entropy = None, + } + } + + #[wasm_bindgen(setter=dataContractId)] + pub fn set_js_data_contract_id(&mut self, js_contract_id: &JsValue) -> Result<(), JsValue> { + self.data_contract_id = IdentifierWASM::try_from(js_contract_id.clone())?; + + Ok(()) + } + + #[wasm_bindgen(setter=ownerId)] + pub fn set_owner_id(&mut self, id: &JsValue) -> Result<(), JsValue> { + self.owner_id = IdentifierWASM::try_from(id)?.clone(); + Ok(()) + } + + #[wasm_bindgen(setter=properties)] + pub fn set_properties(&mut self, properties: JsValue) { + self.properties = properties.with_serde_to_platform_value_map().unwrap() + } + + #[wasm_bindgen(setter=revision)] + pub fn set_revision(&mut self, revision: Option) { + self.revision = revision + } + + #[wasm_bindgen(setter=createdAt)] + pub fn set_created_at(&mut self, created_at: Option) { + self.created_at = created_at + } + + #[wasm_bindgen(setter=updatedAt)] + pub fn set_get_updated_at(&mut self, updated_at: Option) { + self.updated_at = updated_at + } + + #[wasm_bindgen(setter=transferredAt)] + pub fn set_transferred_at(&mut self, transferred_at: Option) { + self.transferred_at = transferred_at + } + + #[wasm_bindgen(setter=createdAtBlockHeight)] + pub fn set_created_at_block_height(&mut self, created_at_block_height: Option) { + self.created_at_block_height = created_at_block_height + } + + #[wasm_bindgen(setter=updatedAtBlockHeight)] + pub fn set_updated_at_block_height(&mut self, updated_at_block_height: Option) { + self.updated_at_block_height = updated_at_block_height + } + + #[wasm_bindgen(setter=transferredAtBlockHeight)] + pub fn set_transferred_at_block_height(&mut self, transferred_at_block_height: Option) { + self.transferred_at_block_height = transferred_at_block_height + } + + #[wasm_bindgen(setter=createdAtCoreBlockHeight)] + pub fn set_created_at_core_block_height(&mut self, created_at_core_block_height: Option) { + self.created_at_core_block_height = created_at_core_block_height + } + + #[wasm_bindgen(setter=updatedAtCoreBlockHeight)] + pub fn set_updated_at_core_block_height(&mut self, updated_at_core_block_height: Option) { + self.updated_at_core_block_height = updated_at_core_block_height + } + + #[wasm_bindgen(setter=transferredAtCoreBlockHeight)] + pub fn set_transferred_at_core_block_height( + &mut self, + transferred_at_core_block_height: Option, + ) { + self.transferred_at_core_block_height = transferred_at_core_block_height + } + + #[wasm_bindgen(setter=documentTypeName)] + pub fn set_document_type_name(&mut self, document_type_name: &str) { + self.document_type_name = document_type_name.to_string(); + } + + #[wasm_bindgen(js_name=bytes)] + pub fn to_bytes( + &self, + data_contract: &DataContractWASM, + js_platform_version: JsValue, + ) -> Result, JsValue> { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let rs_document: Document = Document::from(self.clone()); + + let document_type_ref = data_contract + .get_document_type_ref_by_name(self.get_document_type_name()) + .map_err(|err| JsValue::from_str(err.to_string().as_str()))?; + + DocumentPlatformConversionMethodsV0::serialize( + &rs_document, + document_type_ref, + &data_contract.clone().into(), + &platform_version.into(), + ) + .with_js_error() + } + + #[wasm_bindgen(js_name=hex)] + pub fn to_hex( + &self, + data_contract: &DataContractWASM, + js_platform_version: JsValue, + ) -> Result { + Ok(encode( + self.to_bytes(data_contract, js_platform_version)? + .as_slice(), + Hex, + )) + } + + #[wasm_bindgen(js_name=base64)] + pub fn to_base64( + &self, + data_contract: &DataContractWASM, + js_platform_version: JsValue, + ) -> Result { + Ok(encode( + self.to_bytes(data_contract, js_platform_version)? + .as_slice(), + Base64, + )) + } + + #[wasm_bindgen(js_name=fromBytes)] + pub fn from_bytes( + bytes: Vec, + data_contract: &DataContractWASM, + type_name: String, + js_platform_version: JsValue, + ) -> Result { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWASM::default(), + false => PlatformVersionWASM::try_from(js_platform_version)?, + }; + + let document_type_ref = match data_contract.get_document_type_ref_by_name(type_name.clone()) + { + Ok(type_ref) => Ok(type_ref), + Err(err) => Err(JsValue::from_str(err.to_string().as_str())), + }?; + + let rs_document = Document::from_bytes( + bytes.as_slice(), + document_type_ref, + &platform_version.into(), + ) + .with_js_error()?; + + let mut js_document = DocumentWASM::from(rs_document); + + js_document.set_document_type_name(type_name.clone().as_str()); + js_document.set_data_contract_id(&data_contract.get_id()); + + Ok(js_document) + } + + #[wasm_bindgen(js_name=fromHex)] + pub fn from_hex( + hex: String, + data_contract: &DataContractWASM, + type_name: String, + js_platform_version: JsValue, + ) -> Result { + DocumentWASM::from_bytes( + decode(hex.as_str(), Hex).map_err(JsError::from)?, + data_contract, + type_name, + js_platform_version, + ) + } + + #[wasm_bindgen(js_name=fromBase64)] + pub fn from_base64( + base64: String, + data_contract: &DataContractWASM, + type_name: String, + js_platform_version: JsValue, + ) -> Result { + DocumentWASM::from_bytes( + decode(base64.as_str(), Base64).map_err(JsError::from)?, + data_contract, + type_name, + js_platform_version, + ) + } + + #[wasm_bindgen(js_name=generateId)] + pub fn generate_id( + js_document_type_name: &str, + js_owner_id: &JsValue, + js_data_contract_id: &JsValue, + opt_entropy: Option>, + ) -> Result, JsValue> { + let owner_id = IdentifierWASM::try_from(js_owner_id)?; + let data_contract_id = IdentifierWASM::try_from(js_data_contract_id)?; + + let entropy: [u8; 32] = match opt_entropy { + Some(entropy_vec) => { + let mut entropy = [0u8; 32]; + let bytes = entropy_vec.as_slice(); + let len = bytes.len().min(32); + entropy[..len].copy_from_slice(&bytes[..len]); + entropy + } + None => entropy_generator::DefaultEntropyGenerator + .generate() + .with_js_error()?, + }; + + let identifier = crate::utils::generate_document_id_v0( + &data_contract_id.into(), + &owner_id.into(), + js_document_type_name, + &entropy, + ); + + match identifier { + Ok(identifier) => Ok(identifier.to_vec()), + Err(err) => Err(err), + } + } +} + +impl DocumentWASM { + pub fn rs_get_owner_id(&self) -> Identifier { + self.owner_id.into() + } + + pub fn rs_get_id(&self) -> Identifier { + self.id.into() + } + + pub fn rs_get_data_contract_id(&self) -> Identifier { + self.data_contract_id.into() + } + + pub fn rs_get_entropy(&self) -> Option<[u8; 32]> { + self.entropy + } + + pub fn rs_get_properties(&self) -> BTreeMap { + self.clone().properties + } + + fn set_data_contract_id(&mut self, data_contract_id: &IdentifierWASM) { + self.data_contract_id = data_contract_id.clone(); + } +} diff --git a/packages/wasm-dpp2/src/document/mod.rs b/packages/wasm-dpp2/src/document/mod.rs new file mode 100644 index 00000000000..59ece5a8c2f --- /dev/null +++ b/packages/wasm-dpp2/src/document/mod.rs @@ -0,0 +1,102 @@ +pub mod methods; + +use crate::identifier::IdentifierWASM; +use dpp::document::{Document, DocumentV0, DocumentV0Getters}; +use dpp::identifier::Identifier; +use dpp::identity::TimestampMillis; +use dpp::platform_value::Value; +use dpp::prelude::{BlockHeight, CoreBlockHeight, Revision}; +use std::collections::BTreeMap; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name = DocumentWASM)] +pub struct DocumentWASM { + id: IdentifierWASM, + owner_id: IdentifierWASM, + revision: Option, + data_contract_id: IdentifierWASM, + document_type_name: String, + properties: BTreeMap, + created_at: Option, + updated_at: Option, + transferred_at: Option, + created_at_block_height: Option, + updated_at_block_height: Option, + transferred_at_block_height: Option, + created_at_core_block_height: Option, + updated_at_core_block_height: Option, + transferred_at_core_block_height: Option, + entropy: Option<[u8; 32]>, +} + +impl From for Document { + fn from(wasm_doc: DocumentWASM) -> Self { + Document::V0(DocumentV0 { + id: wasm_doc.id.into(), + owner_id: wasm_doc.owner_id.into(), + properties: wasm_doc.properties, + revision: wasm_doc.revision, + created_at: wasm_doc.created_at, + updated_at: wasm_doc.updated_at, + transferred_at: wasm_doc.transferred_at, + created_at_block_height: wasm_doc.created_at_block_height, + updated_at_block_height: wasm_doc.updated_at_block_height, + transferred_at_block_height: wasm_doc.transferred_at_block_height, + created_at_core_block_height: wasm_doc.created_at_core_block_height, + updated_at_core_block_height: wasm_doc.updated_at_core_block_height, + transferred_at_core_block_height: wasm_doc.transferred_at_core_block_height, + }) + } +} + +impl From for DocumentWASM { + fn from(doc: Document) -> Self { + DocumentWASM { + id: doc.id().into(), + owner_id: doc.owner_id().into(), + revision: doc.revision(), + data_contract_id: Identifier::default().into(), + document_type_name: "".to_string(), + properties: doc.properties().clone(), + created_at: doc.created_at(), + updated_at: doc.updated_at(), + transferred_at: doc.transferred_at(), + created_at_block_height: doc.created_at_block_height(), + updated_at_block_height: doc.updated_at_block_height(), + transferred_at_block_height: doc.transferred_at_block_height(), + created_at_core_block_height: doc.created_at_core_block_height(), + updated_at_core_block_height: doc.updated_at_core_block_height(), + transferred_at_core_block_height: doc.transferred_at_core_block_height(), + entropy: None, + } + } +} + +impl DocumentWASM { + pub fn from_batch( + document: Document, + data_contract_id: Identifier, + document_type_name: String, + entropy: Option<[u8; 32]>, + ) -> Self { + DocumentWASM { + id: document.id().into(), + owner_id: document.owner_id().into(), + revision: document.revision(), + data_contract_id: data_contract_id.into(), + document_type_name, + properties: document.properties().clone(), + created_at: document.created_at(), + updated_at: document.updated_at(), + transferred_at: document.transferred_at(), + created_at_block_height: document.created_at_block_height(), + updated_at_block_height: document.updated_at_block_height(), + transferred_at_block_height: document.transferred_at_block_height(), + created_at_core_block_height: document.created_at_core_block_height(), + updated_at_core_block_height: document.updated_at_core_block_height(), + transferred_at_core_block_height: document.transferred_at_core_block_height(), + entropy, + } + } +} diff --git a/packages/wasm-dpp2/src/encrypted_note/mod.rs b/packages/wasm-dpp2/src/encrypted_note/mod.rs new file mode 100644 index 00000000000..083b5fc28b9 --- /dev/null +++ b/packages/wasm-dpp2/src/encrypted_note/mod.rs @@ -0,0 +1,2 @@ +pub mod private_encrypted_note; +pub mod shared_encrypted_note; diff --git a/packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs b/packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs new file mode 100644 index 00000000000..0ca84cb18d9 --- /dev/null +++ b/packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs @@ -0,0 +1,75 @@ +use dpp::prelude::{DerivationEncryptionKeyIndex, RootEncryptionKeyIndex}; +use dpp::tokens::PrivateEncryptedNote; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name = "PrivateEncryptedNoteWASM")] +pub struct PrivateEncryptedNoteWASM(PrivateEncryptedNote); + +impl From for PrivateEncryptedNoteWASM { + fn from(value: PrivateEncryptedNote) -> Self { + PrivateEncryptedNoteWASM(value) + } +} + +impl From for PrivateEncryptedNote { + fn from(value: PrivateEncryptedNoteWASM) -> Self { + value.0 + } +} + +#[wasm_bindgen] +impl PrivateEncryptedNoteWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "PrivateEncryptedNoteWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "PrivateEncryptedNoteWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + root_encryption_key_index: RootEncryptionKeyIndex, + derivation_encryption_key_index: DerivationEncryptionKeyIndex, + value: Vec, + ) -> PrivateEncryptedNoteWASM { + PrivateEncryptedNoteWASM(( + root_encryption_key_index, + derivation_encryption_key_index, + value, + )) + } + + #[wasm_bindgen(getter = "rootEncryptionKeyIndex")] + pub fn root_encryption_key_index(&self) -> RootEncryptionKeyIndex { + self.0.0 + } + + #[wasm_bindgen(getter = "derivationEncryptionKeyIndex")] + pub fn derivation_encryption_key_index(&self) -> DerivationEncryptionKeyIndex { + self.0.1 + } + + #[wasm_bindgen(getter = "value")] + pub fn value(&self) -> Vec { + self.0.2.clone() + } + + #[wasm_bindgen(setter = "rootEncryptionKeyIndex")] + pub fn set_root_encryption_key_index(&mut self, index: RootEncryptionKeyIndex) { + self.0.0 = index; + } + + #[wasm_bindgen(setter = "derivationEncryptionKeyIndex")] + pub fn set_derivation_encryption_key_index(&mut self, index: DerivationEncryptionKeyIndex) { + self.0.1 = index; + } + + #[wasm_bindgen(setter = "value")] + pub fn set_value(&mut self, value: Vec) { + self.0.2 = value; + } +} diff --git a/packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs b/packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs new file mode 100644 index 00000000000..6ee572adced --- /dev/null +++ b/packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs @@ -0,0 +1,71 @@ +use dpp::prelude::{RecipientKeyIndex, SenderKeyIndex}; +use dpp::tokens::SharedEncryptedNote; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name = "SharedEncryptedNoteWASM")] +pub struct SharedEncryptedNoteWASM(SharedEncryptedNote); + +impl From for SharedEncryptedNoteWASM { + fn from(note: SharedEncryptedNote) -> Self { + Self(note) + } +} + +impl From for SharedEncryptedNote { + fn from(note: SharedEncryptedNoteWASM) -> Self { + note.0 + } +} + +#[wasm_bindgen] +impl SharedEncryptedNoteWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "SharedEncryptedNoteWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "SharedEncryptedNoteWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + sender_key_index: SenderKeyIndex, + recipient_key_index: RecipientKeyIndex, + value: Vec, + ) -> Self { + SharedEncryptedNoteWASM((sender_key_index, recipient_key_index, value)) + } + + #[wasm_bindgen(getter = "senderKeyIndex")] + pub fn sender_key_index(&self) -> SenderKeyIndex { + self.0.0 + } + + #[wasm_bindgen(getter = "recipientKeyIndex")] + pub fn recipient_key_index(&self) -> RecipientKeyIndex { + self.0.1 + } + + #[wasm_bindgen(getter = "value")] + pub fn value(&self) -> Vec { + self.0.2.clone() + } + + #[wasm_bindgen(setter = "senderKeyIndex")] + pub fn set_sender_key_index(&mut self, index: SenderKeyIndex) { + self.0.0 = index; + } + + #[wasm_bindgen(setter = "recipientKeyIndex")] + pub fn set_recipient_key_index(&mut self, index: RecipientKeyIndex) { + self.0.1 = index; + } + + #[wasm_bindgen(setter = "value")] + pub fn set_value(&mut self, value: Vec) { + self.0.2 = value; + } +} diff --git a/packages/wasm-dpp2/src/enums/batch/batch_enum.rs b/packages/wasm-dpp2/src/enums/batch/batch_enum.rs new file mode 100644 index 00000000000..28b19a2cc4e --- /dev/null +++ b/packages/wasm-dpp2/src/enums/batch/batch_enum.rs @@ -0,0 +1,84 @@ +use dpp::state_transition::batch_transition::batched_transition::document_transition_action_type::DocumentTransitionActionType; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "BatchType")] +pub enum BatchTypeWASM { + Create, + Replace, + Delete, + Transfer, + Purchase, + UpdatePrice, + IgnoreWhileBumpingRevision, +} + +impl TryFrom for BatchTypeWASM { + type Error = JsValue; + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "create" => Ok(BatchTypeWASM::Create), + "replace" => Ok(BatchTypeWASM::Replace), + "delete" => Ok(BatchTypeWASM::Delete), + "transfer" => Ok(BatchTypeWASM::Transfer), + "purchase" => Ok(BatchTypeWASM::Purchase), + "updateprice" => Ok(BatchTypeWASM::UpdatePrice), + "ignorewhilebumpingrevision" => Ok(BatchTypeWASM::IgnoreWhileBumpingRevision), + _ => Err(JsValue::from(format!( + "unknown batch type value: {}", + enum_val + ))), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 0 => Ok(BatchTypeWASM::Create), + 1 => Ok(BatchTypeWASM::Replace), + 2 => Ok(BatchTypeWASM::Delete), + 3 => Ok(BatchTypeWASM::Transfer), + 4 => Ok(BatchTypeWASM::Purchase), + 5 => Ok(BatchTypeWASM::UpdatePrice), + 6 => Ok(BatchTypeWASM::IgnoreWhileBumpingRevision), + _ => Err(JsValue::from(format!( + "unknown batch type value: {}", + enum_val + ))), + }, + }, + } + } +} + +impl From for String { + fn from(value: BatchTypeWASM) -> Self { + match value { + BatchTypeWASM::Create => String::from("create"), + BatchTypeWASM::Replace => String::from("replace"), + BatchTypeWASM::Delete => String::from("delete"), + BatchTypeWASM::Transfer => String::from("transfer"), + BatchTypeWASM::Purchase => String::from("purchase"), + BatchTypeWASM::UpdatePrice => String::from("updatePrice"), + BatchTypeWASM::IgnoreWhileBumpingRevision => String::from("ignoreWhileBumpingRevision"), + } + } +} + +impl From for BatchTypeWASM { + fn from(action_type: DocumentTransitionActionType) -> Self { + match action_type { + DocumentTransitionActionType::Create => BatchTypeWASM::Create, + DocumentTransitionActionType::Replace => BatchTypeWASM::Replace, + DocumentTransitionActionType::Delete => BatchTypeWASM::Delete, + DocumentTransitionActionType::Transfer => BatchTypeWASM::Transfer, + DocumentTransitionActionType::Purchase => BatchTypeWASM::Purchase, + DocumentTransitionActionType::UpdatePrice => BatchTypeWASM::UpdatePrice, + DocumentTransitionActionType::IgnoreWhileBumpingRevision => { + BatchTypeWASM::IgnoreWhileBumpingRevision + } + } + } +} diff --git a/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs b/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs new file mode 100644 index 00000000000..39c2fe1338c --- /dev/null +++ b/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs @@ -0,0 +1,74 @@ +use dpp::tokens::gas_fees_paid_by::GasFeesPaidBy; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Default)] +#[wasm_bindgen(js_name = "GasFeesPaidByWASM")] +pub enum GasFeesPaidByWASM { + #[default] + DocumentOwner = 0, + ContractOwner = 1, + PreferContractOwner = 2, +} + +impl TryFrom for GasFeesPaidByWASM { + type Error = JsValue; + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "documentowner" => Ok(GasFeesPaidByWASM::DocumentOwner), + "contractowner" => Ok(GasFeesPaidByWASM::ContractOwner), + "prefercontractowner" => Ok(GasFeesPaidByWASM::PreferContractOwner), + _ => Err(JsValue::from(format!( + "unknown batch type value: {}", + enum_val + ))), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 0 => Ok(GasFeesPaidByWASM::DocumentOwner), + 1 => Ok(GasFeesPaidByWASM::ContractOwner), + 2 => Ok(GasFeesPaidByWASM::PreferContractOwner), + _ => Err(JsValue::from(format!( + "unknown batch type value: {}", + enum_val + ))), + }, + }, + } + } +} + +impl From for String { + fn from(value: GasFeesPaidByWASM) -> Self { + match value { + GasFeesPaidByWASM::DocumentOwner => String::from("DocumentOwner"), + GasFeesPaidByWASM::ContractOwner => String::from("ContractOwner"), + GasFeesPaidByWASM::PreferContractOwner => String::from("PreferContractOwner"), + } + } +} + +impl From for GasFeesPaidByWASM { + fn from(value: GasFeesPaidBy) -> Self { + match value { + GasFeesPaidBy::DocumentOwner => GasFeesPaidByWASM::DocumentOwner, + GasFeesPaidBy::ContractOwner => GasFeesPaidByWASM::ContractOwner, + GasFeesPaidBy::PreferContractOwner => GasFeesPaidByWASM::PreferContractOwner, + } + } +} + +impl From for GasFeesPaidBy { + fn from(value: GasFeesPaidByWASM) -> Self { + match value { + GasFeesPaidByWASM::DocumentOwner => GasFeesPaidBy::DocumentOwner, + GasFeesPaidByWASM::ContractOwner => GasFeesPaidBy::ContractOwner, + GasFeesPaidByWASM::PreferContractOwner => GasFeesPaidBy::PreferContractOwner, + } + } +} diff --git a/packages/wasm-dpp2/src/enums/batch/mod.rs b/packages/wasm-dpp2/src/enums/batch/mod.rs new file mode 100644 index 00000000000..7c460827da4 --- /dev/null +++ b/packages/wasm-dpp2/src/enums/batch/mod.rs @@ -0,0 +1,2 @@ +pub mod batch_enum; +pub mod gas_fees_paid_by; diff --git a/packages/wasm-dpp2/src/enums/contested/mod.rs b/packages/wasm-dpp2/src/enums/contested/mod.rs new file mode 100644 index 00000000000..2633453a017 --- /dev/null +++ b/packages/wasm-dpp2/src/enums/contested/mod.rs @@ -0,0 +1 @@ +pub mod vote_state_result_type; diff --git a/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs b/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs new file mode 100644 index 00000000000..6772bb7609a --- /dev/null +++ b/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs @@ -0,0 +1,49 @@ +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "VoteStateResultTypeWASM")] +#[allow(non_camel_case_types)] +#[derive(Default, Clone)] +pub enum VoteStateResultTypeWASM { + #[default] + Documents = 0, + VoteTally = 1, + DocumentsAndVoteTally = 2, +} + +impl TryFrom for VoteStateResultTypeWASM { + type Error = JsValue; + + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "documents" => Ok(VoteStateResultTypeWASM::Documents), + "votetally" => Ok(VoteStateResultTypeWASM::VoteTally), + "documentsandvotetally" => Ok(VoteStateResultTypeWASM::DocumentsAndVoteTally), + _ => Err(JsValue::from("unknown result type")), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 0 => Ok(VoteStateResultTypeWASM::Documents), + 1 => Ok(VoteStateResultTypeWASM::VoteTally), + 2 => Ok(VoteStateResultTypeWASM::DocumentsAndVoteTally), + _ => Err(JsValue::from("unknown action type")), + }, + }, + } + } +} + +impl From for String { + fn from(result_type: VoteStateResultTypeWASM) -> Self { + match result_type { + VoteStateResultTypeWASM::Documents => String::from("Documents"), + VoteStateResultTypeWASM::VoteTally => String::from("VoteTally"), + VoteStateResultTypeWASM::DocumentsAndVoteTally => String::from("DocumentsAndVoteTally"), + } + } +} diff --git a/packages/wasm-dpp2/src/enums/keys/key_type.rs b/packages/wasm-dpp2/src/enums/keys/key_type.rs new file mode 100644 index 00000000000..64872bdc9c7 --- /dev/null +++ b/packages/wasm-dpp2/src/enums/keys/key_type.rs @@ -0,0 +1,94 @@ +use dpp::identity::KeyType; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[allow(non_camel_case_types)] +#[wasm_bindgen(js_name = "KeyType")] +pub enum KeyTypeWASM { + ECDSA_SECP256K1 = 0, + BLS12_381 = 1, + ECDSA_HASH160 = 2, + BIP13_SCRIPT_HASH = 3, + EDDSA_25519_HASH160 = 4, +} + +impl TryFrom for KeyTypeWASM { + type Error = JsValue; + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "ecdsa_secp256k1" => Ok(KeyTypeWASM::ECDSA_SECP256K1), + "bls12_381" => Ok(KeyTypeWASM::BLS12_381), + "ecdsa_hash160" => Ok(KeyTypeWASM::ECDSA_HASH160), + "bip13_script_hash" => Ok(KeyTypeWASM::BIP13_SCRIPT_HASH), + "eddsa_25519_hash160" => Ok(KeyTypeWASM::EDDSA_25519_HASH160), + _ => Err(JsValue::from(format!("unsupported key type {}", enum_val))), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 0 => Ok(KeyTypeWASM::ECDSA_SECP256K1), + 1 => Ok(KeyTypeWASM::BLS12_381), + 2 => Ok(KeyTypeWASM::ECDSA_HASH160), + 3 => Ok(KeyTypeWASM::BIP13_SCRIPT_HASH), + 4 => Ok(KeyTypeWASM::EDDSA_25519_HASH160), + _ => Err(JsValue::from(format!( + "unsupported key type ({})", + enum_val + ))), + }, + }, + } + } +} + +impl From for String { + fn from(value: KeyTypeWASM) -> Self { + match value { + KeyTypeWASM::ECDSA_SECP256K1 => String::from("ECDSA_SECP256K1"), + KeyTypeWASM::BLS12_381 => String::from("BLS12_381"), + KeyTypeWASM::ECDSA_HASH160 => String::from("ECDSA_HASH160"), + KeyTypeWASM::BIP13_SCRIPT_HASH => String::from("BIP13_SCRIPT_HASH"), + KeyTypeWASM::EDDSA_25519_HASH160 => String::from("EDDSA_25519_HASH160"), + } + } +} + +impl From for KeyType { + fn from(key_type: KeyTypeWASM) -> Self { + match key_type { + KeyTypeWASM::ECDSA_SECP256K1 => KeyType::ECDSA_SECP256K1, + KeyTypeWASM::BLS12_381 => KeyType::BLS12_381, + KeyTypeWASM::ECDSA_HASH160 => KeyType::ECDSA_HASH160, + KeyTypeWASM::BIP13_SCRIPT_HASH => KeyType::BIP13_SCRIPT_HASH, + KeyTypeWASM::EDDSA_25519_HASH160 => KeyType::EDDSA_25519_HASH160, + } + } +} + +impl From for KeyTypeWASM { + fn from(key_type: KeyType) -> Self { + match key_type { + KeyType::ECDSA_SECP256K1 => KeyTypeWASM::ECDSA_SECP256K1, + KeyType::BLS12_381 => KeyTypeWASM::BLS12_381, + KeyType::ECDSA_HASH160 => KeyTypeWASM::ECDSA_HASH160, + KeyType::BIP13_SCRIPT_HASH => KeyTypeWASM::BIP13_SCRIPT_HASH, + KeyType::EDDSA_25519_HASH160 => KeyTypeWASM::EDDSA_25519_HASH160, + } + } +} + +impl From for u8 { + fn from(key_type: KeyTypeWASM) -> Self { + match key_type { + KeyTypeWASM::ECDSA_SECP256K1 => 0, + KeyTypeWASM::BLS12_381 => 1, + KeyTypeWASM::ECDSA_HASH160 => 2, + KeyTypeWASM::BIP13_SCRIPT_HASH => 3, + KeyTypeWASM::EDDSA_25519_HASH160 => 4, + } + } +} diff --git a/packages/wasm-dpp2/src/enums/keys/mod.rs b/packages/wasm-dpp2/src/enums/keys/mod.rs new file mode 100644 index 00000000000..ffc9430d211 --- /dev/null +++ b/packages/wasm-dpp2/src/enums/keys/mod.rs @@ -0,0 +1,3 @@ +pub mod key_type; +pub mod purpose; +pub mod security_level; diff --git a/packages/wasm-dpp2/src/enums/keys/purpose.rs b/packages/wasm-dpp2/src/enums/keys/purpose.rs new file mode 100644 index 00000000000..35c237ade6e --- /dev/null +++ b/packages/wasm-dpp2/src/enums/keys/purpose.rs @@ -0,0 +1,96 @@ +use dpp::identity::Purpose; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "Purpose")] +pub enum PurposeWASM { + AUTHENTICATION = 0, + ENCRYPTION = 1, + DECRYPTION = 2, + TRANSFER = 3, + SYSTEM = 4, + VOTING = 5, + OWNER = 6, +} + +impl TryFrom for PurposeWASM { + type Error = JsValue; + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "authentication" => Ok(PurposeWASM::AUTHENTICATION), + "encryption" => Ok(PurposeWASM::ENCRYPTION), + "decryption" => Ok(PurposeWASM::DECRYPTION), + "transfer" => Ok(PurposeWASM::TRANSFER), + "system" => Ok(PurposeWASM::SYSTEM), + "voting" => Ok(PurposeWASM::VOTING), + "owner" => Ok(PurposeWASM::OWNER), + _ => Err(JsValue::from(format!( + "unsupported purpose value ({})", + enum_val + ))), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 0 => Ok(PurposeWASM::AUTHENTICATION), + 1 => Ok(PurposeWASM::ENCRYPTION), + 2 => Ok(PurposeWASM::DECRYPTION), + 3 => Ok(PurposeWASM::TRANSFER), + 4 => Ok(PurposeWASM::SYSTEM), + 5 => Ok(PurposeWASM::VOTING), + 6 => Ok(PurposeWASM::OWNER), + _ => Err(JsValue::from(format!( + "unsupported purpose value ({})", + enum_val + ))), + }, + }, + } + } +} + +impl From for String { + fn from(value: PurposeWASM) -> Self { + match value { + PurposeWASM::AUTHENTICATION => String::from("AUTHENTICATION"), + PurposeWASM::ENCRYPTION => String::from("ENCRYPTION"), + PurposeWASM::DECRYPTION => String::from("DECRYPTION"), + PurposeWASM::TRANSFER => String::from("TRANSFER"), + PurposeWASM::SYSTEM => String::from("SYSTEM"), + PurposeWASM::VOTING => String::from("VOTING"), + PurposeWASM::OWNER => String::from("OWNER"), + } + } +} + +impl From for Purpose { + fn from(purpose: PurposeWASM) -> Self { + match purpose { + PurposeWASM::AUTHENTICATION => Purpose::AUTHENTICATION, + PurposeWASM::ENCRYPTION => Purpose::ENCRYPTION, + PurposeWASM::DECRYPTION => Purpose::DECRYPTION, + PurposeWASM::TRANSFER => Purpose::TRANSFER, + PurposeWASM::SYSTEM => Purpose::SYSTEM, + PurposeWASM::VOTING => Purpose::VOTING, + PurposeWASM::OWNER => Purpose::OWNER, + } + } +} + +impl From for PurposeWASM { + fn from(purpose: Purpose) -> Self { + match purpose { + Purpose::AUTHENTICATION => PurposeWASM::AUTHENTICATION, + Purpose::ENCRYPTION => PurposeWASM::ENCRYPTION, + Purpose::DECRYPTION => PurposeWASM::DECRYPTION, + Purpose::TRANSFER => PurposeWASM::TRANSFER, + Purpose::SYSTEM => PurposeWASM::SYSTEM, + Purpose::VOTING => PurposeWASM::VOTING, + Purpose::OWNER => PurposeWASM::OWNER, + } + } +} diff --git a/packages/wasm-dpp2/src/enums/keys/security_level.rs b/packages/wasm-dpp2/src/enums/keys/security_level.rs new file mode 100644 index 00000000000..33db627b0e6 --- /dev/null +++ b/packages/wasm-dpp2/src/enums/keys/security_level.rs @@ -0,0 +1,78 @@ +use dpp::identity::SecurityLevel; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = SecurityLevel)] +pub enum SecurityLevelWASM { + MASTER = 0, + CRITICAL = 1, + HIGH = 2, + MEDIUM = 3, +} + +impl TryFrom for SecurityLevelWASM { + type Error = JsValue; + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "master" => Ok(SecurityLevelWASM::MASTER), + "critical" => Ok(SecurityLevelWASM::CRITICAL), + "high" => Ok(SecurityLevelWASM::HIGH), + "medium" => Ok(SecurityLevelWASM::MEDIUM), + _ => Err(JsValue::from(format!( + "unsupported security level value ({})", + enum_val + ))), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 0 => Ok(SecurityLevelWASM::MASTER), + 1 => Ok(SecurityLevelWASM::CRITICAL), + 2 => Ok(SecurityLevelWASM::HIGH), + 3 => Ok(SecurityLevelWASM::MEDIUM), + _ => Err(JsValue::from(format!( + "unsupported security level value ({})", + enum_val + ))), + }, + }, + } + } +} + +impl From for String { + fn from(level: SecurityLevelWASM) -> String { + match level { + SecurityLevelWASM::MASTER => String::from("MASTER"), + SecurityLevelWASM::CRITICAL => String::from("CRITICAL"), + SecurityLevelWASM::HIGH => String::from("HIGH"), + SecurityLevelWASM::MEDIUM => String::from("MEDIUM"), + } + } +} + +impl From for SecurityLevel { + fn from(security_level: SecurityLevelWASM) -> Self { + match security_level { + SecurityLevelWASM::MASTER => SecurityLevel::MASTER, + SecurityLevelWASM::CRITICAL => SecurityLevel::CRITICAL, + SecurityLevelWASM::HIGH => SecurityLevel::HIGH, + SecurityLevelWASM::MEDIUM => SecurityLevel::MEDIUM, + } + } +} + +impl From for SecurityLevelWASM { + fn from(security_level: SecurityLevel) -> Self { + match security_level { + SecurityLevel::MASTER => SecurityLevelWASM::MASTER, + SecurityLevel::CRITICAL => SecurityLevelWASM::CRITICAL, + SecurityLevel::HIGH => SecurityLevelWASM::HIGH, + SecurityLevel::MEDIUM => SecurityLevelWASM::MEDIUM, + } + } +} diff --git a/packages/wasm-dpp2/src/enums/lock_types/mod.rs b/packages/wasm-dpp2/src/enums/lock_types/mod.rs new file mode 100644 index 00000000000..d7d8c52d555 --- /dev/null +++ b/packages/wasm-dpp2/src/enums/lock_types/mod.rs @@ -0,0 +1,65 @@ +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[wasm_bindgen(js_name = "AssetLockProofTypeWASM")] +pub enum AssetLockProofTypeWASM { + Instant = 0, + Chain = 1, +} + +impl From for String { + fn from(value: AssetLockProofTypeWASM) -> Self { + match value { + AssetLockProofTypeWASM::Instant => String::from("Instant"), + AssetLockProofTypeWASM::Chain => String::from("Chain"), + } + } +} + +impl TryFrom for AssetLockProofTypeWASM { + type Error = JsValue; + + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "instant" => Ok(AssetLockProofTypeWASM::Instant), + "chain" => Ok(AssetLockProofTypeWASM::Chain), + _ => Err(JsValue::from(format!("unsupported lock type {}", enum_val))), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 0 => Ok(AssetLockProofTypeWASM::Instant), + 1 => Ok(AssetLockProofTypeWASM::Chain), + _ => Err(JsValue::from(format!("unsupported lock type {}", enum_val))), + }, + }, + } + } +} + +impl TryFrom for AssetLockProofTypeWASM { + type Error = JsError; + fn try_from(value: u8) -> Result { + match value { + 0 => Ok(Self::Instant), + 1 => Ok(Self::Chain), + _ => Err(JsError::new("Unexpected asset lock proof type")), + } + } +} + +impl TryFrom for AssetLockProofTypeWASM { + type Error = JsError; + + fn try_from(value: u64) -> Result { + match value { + 0 => Ok(Self::Instant), + 1 => Ok(Self::Chain), + _ => Err(JsError::new("Unexpected asset lock proof type")), + } + } +} diff --git a/packages/wasm-dpp2/src/enums/mod.rs b/packages/wasm-dpp2/src/enums/mod.rs new file mode 100644 index 00000000000..b8303a599d5 --- /dev/null +++ b/packages/wasm-dpp2/src/enums/mod.rs @@ -0,0 +1,8 @@ +pub mod batch; +pub mod contested; +pub mod keys; +pub mod lock_types; +pub mod network; +pub mod platform; +pub mod token; +pub mod withdrawal; diff --git a/packages/wasm-dpp2/src/enums/network/mod.rs b/packages/wasm-dpp2/src/enums/network/mod.rs new file mode 100644 index 00000000000..0ab4825d865 --- /dev/null +++ b/packages/wasm-dpp2/src/enums/network/mod.rs @@ -0,0 +1,67 @@ +use dpp::dashcore::network::constants::Network; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +#[wasm_bindgen(js_name = "NetworkWASM")] +#[allow(non_camel_case_types)] +pub enum NetworkWASM { + Mainnet = 0, + Testnet = 1, + Devnet = 2, + Regtest = 3, +} + +impl TryFrom for NetworkWASM { + type Error = JsValue; + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "mainnet" => Ok(NetworkWASM::Mainnet), + "testnet" => Ok(NetworkWASM::Testnet), + "devnet" => Ok(NetworkWASM::Devnet), + "regtest" => Ok(NetworkWASM::Regtest), + _ => Err(JsValue::from(format!( + "unsupported network name ({})", + enum_val + ))), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 0 => Ok(NetworkWASM::Mainnet), + 1 => Ok(NetworkWASM::Testnet), + 2 => Ok(NetworkWASM::Devnet), + 3 => Ok(NetworkWASM::Regtest), + _ => Err(JsValue::from(format!( + "unsupported network name ({})", + enum_val + ))), + }, + }, + } + } +} + +impl From for String { + fn from(value: NetworkWASM) -> Self { + match value { + NetworkWASM::Mainnet => "Mainnet".to_string(), + NetworkWASM::Testnet => "Testnet".to_string(), + NetworkWASM::Devnet => "Devnet".to_string(), + NetworkWASM::Regtest => "Regtest".to_string(), + } + } +} + +impl From for Network { + fn from(network: NetworkWASM) -> Self { + match network { + NetworkWASM::Mainnet => Network::Dash, + NetworkWASM::Testnet => Network::Testnet, + NetworkWASM::Devnet => Network::Devnet, + NetworkWASM::Regtest => Network::Regtest, + } + } +} diff --git a/packages/wasm-dpp2/src/enums/platform/mod.rs b/packages/wasm-dpp2/src/enums/platform/mod.rs new file mode 100644 index 00000000000..845f9abef07 --- /dev/null +++ b/packages/wasm-dpp2/src/enums/platform/mod.rs @@ -0,0 +1,104 @@ +use dpp::version::PlatformVersion; +use dpp::version::v1::PLATFORM_V1; +use dpp::version::v2::PLATFORM_V2; +use dpp::version::v3::PLATFORM_V3; +use dpp::version::v4::PLATFORM_V4; +use dpp::version::v5::PLATFORM_V5; +use dpp::version::v6::PLATFORM_V6; +use dpp::version::v7::PLATFORM_V7; +use dpp::version::v8::PLATFORM_V8; +use dpp::version::v9::PLATFORM_V9; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "PlatformVersionWASM")] +#[derive(Default)] +#[allow(non_camel_case_types)] +pub enum PlatformVersionWASM { + #[default] + PLATFORM_V1 = 1, + PLATFORM_V2 = 2, + PLATFORM_V3 = 3, + PLATFORM_V4 = 4, + PLATFORM_V5 = 5, + PLATFORM_V6 = 6, + PLATFORM_V7 = 7, + PLATFORM_V8 = 8, + PLATFORM_V9 = 9, +} + +impl TryFrom for PlatformVersionWASM { + type Error = JsValue; + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "platform_v1" => Ok(PlatformVersionWASM::PLATFORM_V1), + "platform_v2" => Ok(PlatformVersionWASM::PLATFORM_V2), + "platform_v3" => Ok(PlatformVersionWASM::PLATFORM_V3), + "platform_v4" => Ok(PlatformVersionWASM::PLATFORM_V4), + "platform_v5" => Ok(PlatformVersionWASM::PLATFORM_V5), + "platform_v6" => Ok(PlatformVersionWASM::PLATFORM_V6), + "platform_v7" => Ok(PlatformVersionWASM::PLATFORM_V7), + "platform_v8" => Ok(PlatformVersionWASM::PLATFORM_V8), + "platform_v9" => Ok(PlatformVersionWASM::PLATFORM_V9), + _ => Err(JsValue::from(format!( + "unknown platform version value: {}", + enum_val + ))), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 1 => Ok(PlatformVersionWASM::PLATFORM_V1), + 2 => Ok(PlatformVersionWASM::PLATFORM_V2), + 3 => Ok(PlatformVersionWASM::PLATFORM_V3), + 4 => Ok(PlatformVersionWASM::PLATFORM_V4), + 5 => Ok(PlatformVersionWASM::PLATFORM_V5), + 6 => Ok(PlatformVersionWASM::PLATFORM_V6), + 7 => Ok(PlatformVersionWASM::PLATFORM_V7), + 8 => Ok(PlatformVersionWASM::PLATFORM_V8), + 9 => Ok(PlatformVersionWASM::PLATFORM_V9), + _ => Err(JsValue::from(format!( + "unknown platform version value: {}", + enum_val + ))), + }, + }, + } + } +} + +impl From for String { + fn from(version: PlatformVersionWASM) -> String { + match version { + PlatformVersionWASM::PLATFORM_V1 => String::from("PLATFORM_V1"), + PlatformVersionWASM::PLATFORM_V2 => String::from("PLATFORM_V2"), + PlatformVersionWASM::PLATFORM_V3 => String::from("PLATFORM_V3"), + PlatformVersionWASM::PLATFORM_V4 => String::from("PLATFORM_V4"), + PlatformVersionWASM::PLATFORM_V5 => String::from("PLATFORM_V5"), + PlatformVersionWASM::PLATFORM_V6 => String::from("PLATFORM_V6"), + PlatformVersionWASM::PLATFORM_V7 => String::from("PLATFORM_V7"), + PlatformVersionWASM::PLATFORM_V8 => String::from("PLATFORM_V8"), + PlatformVersionWASM::PLATFORM_V9 => String::from("PLATFORM_V9"), + } + } +} + +impl From for PlatformVersion { + fn from(value: PlatformVersionWASM) -> Self { + match value { + PlatformVersionWASM::PLATFORM_V1 => PLATFORM_V1, + PlatformVersionWASM::PLATFORM_V2 => PLATFORM_V2, + PlatformVersionWASM::PLATFORM_V3 => PLATFORM_V3, + PlatformVersionWASM::PLATFORM_V4 => PLATFORM_V4, + PlatformVersionWASM::PLATFORM_V5 => PLATFORM_V5, + PlatformVersionWASM::PLATFORM_V6 => PLATFORM_V6, + PlatformVersionWASM::PLATFORM_V7 => PLATFORM_V7, + PlatformVersionWASM::PLATFORM_V8 => PLATFORM_V8, + PlatformVersionWASM::PLATFORM_V9 => PLATFORM_V9, + } + } +} diff --git a/packages/wasm-dpp2/src/enums/token/action_goal.rs b/packages/wasm-dpp2/src/enums/token/action_goal.rs new file mode 100644 index 00000000000..7cdfcedbd75 --- /dev/null +++ b/packages/wasm-dpp2/src/enums/token/action_goal.rs @@ -0,0 +1,64 @@ +use dpp::group::action_taker::ActionGoal; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "ActionGoalWASM")] +#[allow(non_camel_case_types)] +#[derive(Default, Clone)] +pub enum ActionGoalWASM { + #[default] + ActionCompletion = 0, + ActionParticipation = 1, +} + +impl From for ActionGoal { + fn from(action_goal: ActionGoalWASM) -> Self { + match action_goal { + ActionGoalWASM::ActionCompletion => ActionGoal::ActionCompletion, + ActionGoalWASM::ActionParticipation => ActionGoal::ActionParticipation, + } + } +} + +impl From for ActionGoalWASM { + fn from(action_goal: ActionGoal) -> Self { + match action_goal { + ActionGoal::ActionCompletion => ActionGoalWASM::ActionCompletion, + ActionGoal::ActionParticipation => ActionGoalWASM::ActionParticipation, + } + } +} + +impl TryFrom for ActionGoalWASM { + type Error = JsValue; + + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "actioncompletion" => Ok(ActionGoalWASM::ActionCompletion), + "actionparticipation" => Ok(ActionGoalWASM::ActionParticipation), + _ => Err(JsValue::from("unknown action type")), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 0 => Ok(ActionGoalWASM::ActionCompletion), + 1 => Ok(ActionGoalWASM::ActionParticipation), + _ => Err(JsValue::from("unknown action type")), + }, + }, + } + } +} + +impl From for String { + fn from(action_goal: ActionGoalWASM) -> Self { + match action_goal { + ActionGoalWASM::ActionCompletion => String::from("ActionCompletion"), + ActionGoalWASM::ActionParticipation => String::from("ActionParticipation"), + } + } +} diff --git a/packages/wasm-dpp2/src/enums/token/distribution_type.rs b/packages/wasm-dpp2/src/enums/token/distribution_type.rs new file mode 100644 index 00000000000..c375e8b2344 --- /dev/null +++ b/packages/wasm-dpp2/src/enums/token/distribution_type.rs @@ -0,0 +1,64 @@ +use dpp::data_contract::associated_token::token_distribution_key::TokenDistributionType; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "TokenDistributionTypeWASM")] +#[allow(non_camel_case_types)] +#[derive(Default)] +pub enum TokenDistributionTypeWASM { + #[default] + PreProgrammed = 0, + Perpetual = 1, +} + +impl From for TokenDistributionType { + fn from(distribution_type: TokenDistributionTypeWASM) -> Self { + match distribution_type { + TokenDistributionTypeWASM::PreProgrammed => TokenDistributionType::PreProgrammed, + TokenDistributionTypeWASM::Perpetual => TokenDistributionType::Perpetual, + } + } +} + +impl From for TokenDistributionTypeWASM { + fn from(distribution_type: TokenDistributionType) -> Self { + match distribution_type { + TokenDistributionType::Perpetual => TokenDistributionTypeWASM::Perpetual, + TokenDistributionType::PreProgrammed => TokenDistributionTypeWASM::PreProgrammed, + } + } +} + +impl TryFrom for TokenDistributionTypeWASM { + type Error = JsValue; + + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "preprogrammed" => Ok(TokenDistributionTypeWASM::PreProgrammed), + "perpetual" => Ok(TokenDistributionTypeWASM::Perpetual), + _ => Err(JsValue::from("unknown distribution type")), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 0 => Ok(TokenDistributionTypeWASM::PreProgrammed), + 1 => Ok(TokenDistributionTypeWASM::Perpetual), + _ => Err(JsValue::from("unknown distribution type")), + }, + }, + } + } +} + +impl From for String { + fn from(distribution_type: TokenDistributionTypeWASM) -> Self { + match distribution_type { + TokenDistributionTypeWASM::PreProgrammed => String::from("PreProgrammed"), + TokenDistributionTypeWASM::Perpetual => String::from("Perpetual"), + } + } +} diff --git a/packages/wasm-dpp2/src/enums/token/emergency_action.rs b/packages/wasm-dpp2/src/enums/token/emergency_action.rs new file mode 100644 index 00000000000..2999e95b8f8 --- /dev/null +++ b/packages/wasm-dpp2/src/enums/token/emergency_action.rs @@ -0,0 +1,64 @@ +use dpp::tokens::emergency_action::TokenEmergencyAction; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "TokenEmergencyActionWASM")] +#[allow(non_camel_case_types)] +#[derive(Default)] +pub enum TokenEmergencyActionWASM { + #[default] + Pause = 0, + Resume = 1, +} + +impl From for TokenEmergencyAction { + fn from(distribution_type: TokenEmergencyActionWASM) -> Self { + match distribution_type { + TokenEmergencyActionWASM::Pause => TokenEmergencyAction::Pause, + TokenEmergencyActionWASM::Resume => TokenEmergencyAction::Resume, + } + } +} + +impl From for TokenEmergencyActionWASM { + fn from(distribution_type: TokenEmergencyAction) -> Self { + match distribution_type { + TokenEmergencyAction::Pause => TokenEmergencyActionWASM::Pause, + TokenEmergencyAction::Resume => TokenEmergencyActionWASM::Resume, + } + } +} + +impl TryFrom for TokenEmergencyActionWASM { + type Error = JsValue; + + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "pause" => Ok(TokenEmergencyActionWASM::Pause), + "resume" => Ok(TokenEmergencyActionWASM::Resume), + _ => Err(JsValue::from("unknown distribution type")), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 0 => Ok(TokenEmergencyActionWASM::Pause), + 1 => Ok(TokenEmergencyActionWASM::Resume), + _ => Err(JsValue::from("unknown distribution type")), + }, + }, + } + } +} + +impl From for String { + fn from(distribution_type: TokenEmergencyActionWASM) -> Self { + match distribution_type { + TokenEmergencyActionWASM::Pause => String::from("Pause"), + TokenEmergencyActionWASM::Resume => String::from("Resume"), + } + } +} diff --git a/packages/wasm-dpp2/src/enums/token/mod.rs b/packages/wasm-dpp2/src/enums/token/mod.rs new file mode 100644 index 00000000000..323cf4199cf --- /dev/null +++ b/packages/wasm-dpp2/src/enums/token/mod.rs @@ -0,0 +1,3 @@ +pub mod action_goal; +pub mod distribution_type; +pub mod emergency_action; diff --git a/packages/wasm-dpp2/src/enums/withdrawal/mod.rs b/packages/wasm-dpp2/src/enums/withdrawal/mod.rs new file mode 100644 index 00000000000..226ba34716b --- /dev/null +++ b/packages/wasm-dpp2/src/enums/withdrawal/mod.rs @@ -0,0 +1,72 @@ +use dpp::withdrawal::Pooling; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub enum PoolingWASM { + Never = 0, + IfAvailable = 1, + Standard = 2, +} + +impl From for Pooling { + fn from(pooling: PoolingWASM) -> Self { + match pooling { + PoolingWASM::Never => Pooling::Never, + PoolingWASM::IfAvailable => Pooling::IfAvailable, + PoolingWASM::Standard => Pooling::Standard, + } + } +} + +impl From for PoolingWASM { + fn from(pooling: Pooling) -> Self { + match pooling { + Pooling::Never => PoolingWASM::Never, + Pooling::IfAvailable => PoolingWASM::IfAvailable, + Pooling::Standard => PoolingWASM::Standard, + } + } +} + +impl TryFrom for PoolingWASM { + type Error = JsValue; + fn try_from(value: JsValue) -> Result { + match value.is_string() { + true => match value.as_string() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val.to_lowercase().as_str() { + "never" => Ok(PoolingWASM::Never), + "ifavailable" => Ok(PoolingWASM::IfAvailable), + "standard" => Ok(PoolingWASM::Standard), + _ => Err(JsValue::from(format!( + "unsupported pooling value ({})", + enum_val + ))), + }, + }, + false => match value.as_f64() { + None => Err(JsValue::from("cannot read value from enum")), + Some(enum_val) => match enum_val as u8 { + 0 => Ok(PoolingWASM::Never), + 1 => Ok(PoolingWASM::IfAvailable), + 2 => Ok(PoolingWASM::Standard), + _ => Err(JsValue::from(format!( + "unsupported pooling value ({})", + enum_val + ))), + }, + }, + } + } +} + +impl From for String { + fn from(pooling_wasm: PoolingWASM) -> String { + match pooling_wasm { + PoolingWASM::Never => String::from("Never"), + PoolingWASM::IfAvailable => String::from("IfAvailable"), + PoolingWASM::Standard => String::from("Standard"), + } + } +} diff --git a/packages/wasm-dpp2/src/group_state_transition_info/mod.rs b/packages/wasm-dpp2/src/group_state_transition_info/mod.rs new file mode 100644 index 00000000000..8d589258502 --- /dev/null +++ b/packages/wasm-dpp2/src/group_state_transition_info/mod.rs @@ -0,0 +1,77 @@ +use crate::identifier::IdentifierWASM; +use dpp::group::GroupStateTransitionInfo; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=GroupStateTransitionInfoWASM)] +pub struct GroupStateTransitionInfoWASM(GroupStateTransitionInfo); + +impl From for GroupStateTransitionInfo { + fn from(info: GroupStateTransitionInfoWASM) -> Self { + info.0 + } +} + +impl From for GroupStateTransitionInfoWASM { + fn from(info: GroupStateTransitionInfo) -> Self { + GroupStateTransitionInfoWASM(info) + } +} + +#[wasm_bindgen] +impl GroupStateTransitionInfoWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "GroupStateTransitionInfoWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "GroupStateTransitionInfoWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + group_contract_position: u16, + action_id: &JsValue, + action_is_proposer: bool, + ) -> Result { + Ok(GroupStateTransitionInfoWASM(GroupStateTransitionInfo { + group_contract_position, + action_id: IdentifierWASM::try_from(action_id)?.into(), + action_is_proposer, + })) + } + + #[wasm_bindgen(setter = "groupContractPosition")] + pub fn set_group_contract_position(&mut self, group_contract_position: u16) { + self.0.group_contract_position = group_contract_position; + } + + #[wasm_bindgen(setter = "actionId")] + pub fn set_action_id(&mut self, action_id: &JsValue) -> Result<(), JsValue> { + self.0.action_id = IdentifierWASM::try_from(action_id)?.into(); + Ok(()) + } + + #[wasm_bindgen(setter = "actionIsProposer")] + pub fn set_action_is_proposer(&mut self, action_is_proposer: bool) { + self.0.action_is_proposer = action_is_proposer; + } + + #[wasm_bindgen(getter = "groupContractPosition")] + pub fn get_group_contract_position(&mut self) -> u16 { + self.0.group_contract_position + } + + #[wasm_bindgen(getter = "actionId")] + pub fn get_action_id(&self) -> IdentifierWASM { + self.0.action_id.into() + } + + #[wasm_bindgen(getter = "actionIsProposer")] + pub fn get_action_is_proposer(&self) -> bool { + self.0.action_is_proposer + } +} diff --git a/packages/wasm-dpp2/src/identifier/mod.rs b/packages/wasm-dpp2/src/identifier/mod.rs new file mode 100644 index 00000000000..156e81ab5a1 --- /dev/null +++ b/packages/wasm-dpp2/src/identifier/mod.rs @@ -0,0 +1,167 @@ +use crate::utils::{IntoWasm, get_class_type, identifier_from_js_value}; +use dpp::platform_value::string_encoding::Encoding::{Base58, Base64, Hex}; +use dpp::platform_value::string_encoding::decode; +use dpp::prelude::Identifier; +use wasm_bindgen::prelude::*; + +#[derive(Copy, Clone)] +#[wasm_bindgen(js_name = "IdentifierWASM")] +pub struct IdentifierWASM(Identifier); + +impl From for Identifier { + fn from(identifier: IdentifierWASM) -> Self { + identifier.0 + } +} + +impl From for IdentifierWASM { + fn from(identifier: Identifier) -> Self { + IdentifierWASM(identifier) + } +} + +impl From<[u8; 32]> for IdentifierWASM { + fn from(identifier: [u8; 32]) -> Self { + IdentifierWASM(Identifier::new(identifier)) + } +} + +impl From<&IdentifierWASM> for Identifier { + fn from(identifier: &IdentifierWASM) -> Self { + identifier.clone().into() + } +} + +impl TryFrom<&[u8]> for IdentifierWASM { + type Error = JsValue; + fn try_from(value: &[u8]) -> Result { + if value.len() != 32 { + return Err(JsValue::from("Identifier must be 32 bytes length")); + } + + let norm_slice: [u8; 32] = value + .try_into() + .map_err(|_| JsValue::from("Cannot parse identifier"))?; + + Ok(IdentifierWASM(Identifier::new(norm_slice))) + } +} + +impl TryFrom for IdentifierWASM { + type Error = JsValue; + fn try_from(value: JsValue) -> Result { + match value.is_object() { + true => match get_class_type(&value) { + Ok(class_type) => match class_type.as_str() { + "IdentifierWASM" => { + Ok(value.to_wasm::("IdentifierWASM")?.clone()) + } + "" => Ok(identifier_from_js_value(&value)?.into()), + _ => Err(Self::Error::from_str(&format!( + "Invalid type of data for identifier (passed {})", + class_type + ))), + }, + Err(_) => Ok(identifier_from_js_value(&value)?.into()), + }, + false => match value.is_string() { + false => Ok(identifier_from_js_value(&value)?.into()), + true => { + let id_str = value.as_string().unwrap(); + match id_str.len() == 64 { + true => { + let bytes = decode(value.as_string().unwrap().as_str(), Hex) + .map_err(|err| JsValue::from(err.to_string()))?; + + Ok(IdentifierWASM::try_from(bytes.as_slice())?) + } + false => Ok(identifier_from_js_value(&value)?.into()), + } + } + }, + } + } +} + +impl TryFrom<&JsValue> for IdentifierWASM { + type Error = JsValue; + fn try_from(value: &JsValue) -> Result { + IdentifierWASM::try_from(value.clone()) + } +} + +#[wasm_bindgen] +impl IdentifierWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "IdentifierWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "IdentifierWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(js_identifier: &JsValue) -> Result { + IdentifierWASM::try_from(js_identifier) + } + + #[wasm_bindgen(js_name = "base58")] + pub fn get_base58(&self) -> String { + self.0.to_string(Base58) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn get_base64(&self) -> String { + self.0.to_string(Base64) + } + + #[wasm_bindgen(js_name = "hex")] + pub fn get_hex(&self) -> String { + self.0.to_string(Hex) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn get_bytes(&self) -> Vec { + self.0.to_vec() + } + + #[wasm_bindgen(js_name = "fromBase58")] + pub fn from_base58(base58: String) -> Result { + let identitfier = Identifier::from_string(base58.as_str(), Base58) + .map_err(|err| JsValue::from(err.to_string()))?; + + Ok(IdentifierWASM(identitfier)) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> Result { + let identitfier = Identifier::from_string(base64.as_str(), Base64) + .map_err(|err| JsValue::from(err.to_string()))?; + + Ok(IdentifierWASM(identitfier)) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + let identitfier = Identifier::from_string(hex.as_str(), Hex) + .map_err(|err| JsValue::from(err.to_string()))?; + + Ok(IdentifierWASM(identitfier)) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + let identifier = + Identifier::from_vec(bytes).map_err(|err| JsValue::from(err.to_string()))?; + + Ok(IdentifierWASM(identifier)) + } +} + +impl IdentifierWASM { + pub fn to_slice(&self) -> [u8; 32] { + self.0.as_bytes().clone() + } +} diff --git a/packages/wasm-dpp2/src/identity/mod.rs b/packages/wasm-dpp2/src/identity/mod.rs new file mode 100644 index 00000000000..7a48417b216 --- /dev/null +++ b/packages/wasm-dpp2/src/identity/mod.rs @@ -0,0 +1,152 @@ +use crate::identifier::IdentifierWASM; +use crate::identity_public_key::IdentityPublicKeyWASM; +use crate::utils::WithJsError; +use dpp::identity::accessors::{IdentityGettersV0, IdentitySettersV0}; +use dpp::identity::{Identity, KeyID}; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::prelude::IdentityPublicKey; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable}; +use dpp::version::PlatformVersion; +use std::collections::BTreeMap; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[derive(Clone)] +#[wasm_bindgen(js_name = "IdentityWASM")] +pub struct IdentityWASM(Identity); + +impl From for IdentityWASM { + fn from(identity: Identity) -> Self { + Self(identity) + } +} + +#[wasm_bindgen] +impl IdentityWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "IdentityWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "IdentityWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(js_identifier: &JsValue) -> Result { + let identifier: IdentifierWASM = js_identifier.try_into()?; + + let identity = Identity::create_basic_identity(identifier.into(), PlatformVersion::first()) + .with_js_error()?; + + Ok(IdentityWASM(identity)) + } + + #[wasm_bindgen(setter = "id")] + pub fn set_id(&mut self, js_identifier: &JsValue) -> Result<(), JsValue> { + Ok(self + .0 + .set_id(IdentifierWASM::try_from(js_identifier)?.into())) + } + + #[wasm_bindgen(setter = "balance")] + pub fn set_balance(&mut self, balance: u64) { + self.0.set_balance(balance); + } + + #[wasm_bindgen(setter = "revision")] + pub fn set_revision(&mut self, revision: u64) { + self.0.set_revision(revision); + } + + #[wasm_bindgen(js_name = "addPublicKey")] + pub fn add_public_key(&mut self, public_key: &IdentityPublicKeyWASM) { + self.0.add_public_key(public_key.clone().into()); + } + + // GETTERS + + #[wasm_bindgen(getter = "id")] + pub fn get_id(&self) -> IdentifierWASM { + self.0.id().into() + } + + #[wasm_bindgen(getter = "balance")] + pub fn get_balance(&self) -> u64 { + self.0.balance() + } + + #[wasm_bindgen(getter = "revision")] + pub fn get_revision(&self) -> u64 { + self.0.revision() + } + + #[wasm_bindgen(js_name = "getPublicKeyById")] + pub fn get_public_key_by_id(&self, key_id: KeyID) -> IdentityPublicKeyWASM { + let identity_public_key = self.0.get_public_key_by_id(key_id); + IdentityPublicKeyWASM::from(identity_public_key.unwrap().clone()) + } + + #[wasm_bindgen(js_name = "getPublicKeys")] + pub fn get_public_keys(&self) -> Vec { + let keys = self + .0 + .public_keys() + .iter() + .map(|(_index, key)| IdentityPublicKeyWASM::from(key.clone())) + .collect(); + + keys + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + + IdentityWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> Result { + let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + + IdentityWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Result, JsValue> { + self.0.serialize_to_bytes().with_js_error() + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_hex(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Hex, + )) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Base64, + )) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + match Identity::deserialize_from_bytes(bytes.as_slice()).with_js_error() { + Ok(identity) => Ok(IdentityWASM(identity)), + Err(err) => Err(err), + } + } +} + +impl IdentityWASM { + pub fn get_rs_public_keys(&self) -> BTreeMap { + self.0.public_keys().clone() + } +} diff --git a/packages/wasm-dpp2/src/identity_public_key/mod.rs b/packages/wasm-dpp2/src/identity_public_key/mod.rs new file mode 100644 index 00000000000..6fe019fba8f --- /dev/null +++ b/packages/wasm-dpp2/src/identity_public_key/mod.rs @@ -0,0 +1,293 @@ +use crate::contract_bounds::ContractBoundsWASM; +use crate::enums::keys::key_type::KeyTypeWASM; +use crate::enums::keys::purpose::PurposeWASM; +use crate::enums::keys::security_level::SecurityLevelWASM; +use crate::enums::network::NetworkWASM; +use crate::utils::{IntoWasm, WithJsError}; +use dpp::dashcore::Network; +use dpp::dashcore::secp256k1::hashes::hex::{Case, DisplayHex}; +use dpp::identity::contract_bounds::ContractBounds; +use dpp::identity::hash::IdentityPublicKeyHashMethodsV0; +use dpp::identity::identity_public_key::accessors::v0::{ + IdentityPublicKeyGettersV0, IdentityPublicKeySettersV0, +}; +use dpp::identity::identity_public_key::v0::IdentityPublicKeyV0; +use dpp::identity::{IdentityPublicKey, KeyType, Purpose, SecurityLevel, TimestampMillis}; +use dpp::platform_value::BinaryData; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[derive(Clone)] +#[wasm_bindgen(js_name = IdentityPublicKeyWASM)] +pub struct IdentityPublicKeyWASM(IdentityPublicKey); + +impl From for IdentityPublicKeyWASM { + fn from(value: IdentityPublicKey) -> Self { + IdentityPublicKeyWASM(value) + } +} + +impl From for IdentityPublicKey { + fn from(value: IdentityPublicKeyWASM) -> Self { + value.0 + } +} + +#[wasm_bindgen] +impl IdentityPublicKeyWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "IdentityPublicKeyWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "IdentityPublicKeyWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + id: u32, + js_purpose: JsValue, + js_security_level: JsValue, + js_key_type: JsValue, + read_only: bool, + binary_data: &str, + disabled_at: Option, + js_contract_bounds: &JsValue, + ) -> Result { + let purpose = PurposeWASM::try_from(js_purpose)?; + let security_level = SecurityLevelWASM::try_from(js_security_level)?; + let key_type = KeyTypeWASM::try_from(js_key_type)?; + let contract_bounds: Option = + match js_contract_bounds.is_undefined() | js_contract_bounds.is_null() { + true => None, + false => Some( + js_contract_bounds + .to_wasm::("ContractBoundsWASM")? + .clone() + .into(), + ), + }; + + Ok(IdentityPublicKeyWASM(IdentityPublicKey::from( + IdentityPublicKeyV0 { + id, + purpose: Purpose::from(purpose), + security_level: SecurityLevel::from(security_level), + contract_bounds, + key_type: KeyType::from(key_type), + read_only, + data: BinaryData::from_string(binary_data, Hex).unwrap(), + disabled_at, + }, + ))) + } +} + +#[wasm_bindgen] +impl IdentityPublicKeyWASM { + #[wasm_bindgen(js_name = "validatePrivateKey")] + pub fn validate_private_key( + &self, + js_private_key_bytes: Vec, + js_network: JsValue, + ) -> Result { + let mut private_key_bytes = [0u8; 32]; + let len = js_private_key_bytes.len().min(32); + private_key_bytes[..len].copy_from_slice(&js_private_key_bytes[..len]); + + let network = Network::from(NetworkWASM::try_from(js_network)?); + + self.0 + .validate_private_key_bytes(&private_key_bytes, network) + .with_js_error() + } + + #[wasm_bindgen(js_name = "getContractBounds")] + pub fn contract_bounds(&self) -> JsValue { + match self.0.contract_bounds() { + None => JsValue::undefined(), + Some(bounds) => JsValue::from(ContractBoundsWASM::from(bounds.clone())), + } + } + + #[wasm_bindgen(getter = keyId)] + pub fn get_key_id(&self) -> u32 { + self.0.id() + } + + #[wasm_bindgen(getter = purpose)] + pub fn get_purpose(&self) -> String { + PurposeWASM::from(self.0.purpose()).into() + } + + #[wasm_bindgen(getter = purposeNumber)] + pub fn get_purpose_number(&self) -> PurposeWASM { + PurposeWASM::from(self.0.purpose()) + } + + #[wasm_bindgen(getter = securityLevel)] + pub fn get_security_level(&self) -> String { + SecurityLevelWASM::from(self.0.security_level()).into() + } + + #[wasm_bindgen(getter = securityLevelNumber)] + pub fn get_security_level_number(&self) -> SecurityLevelWASM { + SecurityLevelWASM::from(self.0.security_level()) + } + + #[wasm_bindgen(getter = keyType)] + pub fn get_key_type(&self) -> String { + KeyTypeWASM::from(self.0.key_type()).into() + } + + #[wasm_bindgen(getter = keyTypeNumber)] + pub fn get_key_type_number(&self) -> KeyTypeWASM { + KeyTypeWASM::from(self.0.key_type()) + } + + #[wasm_bindgen(getter = readOnly)] + pub fn get_read_only(&self) -> bool { + self.0.read_only() + } + + #[wasm_bindgen(getter = data)] + pub fn get_data(&self) -> String { + self.0.data().to_string(Hex) + } + + #[wasm_bindgen(getter = disabledAt)] + pub fn get_disabled_at(&self) -> Option { + self.0.disabled_at() + } + + #[wasm_bindgen(setter = keyId)] + pub fn set_key_id(&mut self, key_id: u32) { + self.0.set_id(key_id) + } + + #[wasm_bindgen(setter = purpose)] + pub fn set_purpose(&mut self, purpose: JsValue) -> Result<(), JsValue> { + Ok(self + .0 + .set_purpose(Purpose::from(PurposeWASM::try_from(purpose)?))) + } + + #[wasm_bindgen(setter = purposeNumber)] + pub fn set_purpose_number(&mut self, purpose: JsValue) -> Result<(), JsValue> { + self.set_purpose(purpose) + } + + #[wasm_bindgen(setter = securityLevel)] + pub fn set_security_level(&mut self, security_level: JsValue) -> Result<(), JsValue> { + Ok(self + .0 + .set_security_level(SecurityLevel::from(SecurityLevelWASM::try_from( + security_level, + )?))) + } + + #[wasm_bindgen(setter = securityLevelNumber)] + pub fn set_security_level_number(&mut self, security_level: JsValue) -> Result<(), JsValue> { + self.set_security_level(security_level) + } + + #[wasm_bindgen(setter = keyType)] + pub fn set_key_type(&mut self, key_type: JsValue) -> Result<(), JsValue> { + Ok(self + .0 + .set_key_type(KeyType::from(KeyTypeWASM::try_from(key_type)?))) + } + + #[wasm_bindgen(setter = keyTypeNumber)] + pub fn set_key_type_number(&mut self, key_type: JsValue) -> Result<(), JsValue> { + self.set_key_type(key_type) + } + + #[wasm_bindgen(setter = readOnly)] + pub fn set_read_only(&mut self, read_only: bool) { + self.0.set_read_only(read_only) + } + + #[wasm_bindgen(setter = data)] + pub fn set_data(&mut self, binary_data: &str) { + let data = BinaryData::from_string(binary_data, Hex).unwrap(); + + self.0.set_data(data) + } + + #[wasm_bindgen(setter = disabledAt)] + pub fn set_disabled_at(&mut self, disabled_at: u64) { + self.0.set_disabled_at(disabled_at) + } + + #[wasm_bindgen(js_name = "getPublicKeyHash")] + pub fn public_key_hash(&self) -> Result { + let hash = self + .0 + .public_key_hash() + .with_js_error() + .map(|slice| slice.to_vec())? + .to_hex_string(Case::Lower); + + Ok(hash) + } + + #[wasm_bindgen(js_name = "isMaster")] + pub fn is_master(&self) -> bool { + self.0.is_master() + } + + #[wasm_bindgen(js_name = bytes)] + pub fn to_byes(&self) -> Result, JsValue> { + self.0.serialize_to_bytes().with_js_error() + } + + #[wasm_bindgen(js_name = hex)] + pub fn to_hex(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Hex, + )) + } + + #[wasm_bindgen(js_name = base64)] + pub fn to_base64(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Base64, + )) + } + + #[wasm_bindgen(js_name = fromBytes)] + pub fn from_bytes(bytes: Vec) -> Result { + let public_key = + IdentityPublicKey::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + + Ok(IdentityPublicKeyWASM(public_key)) + } + + #[wasm_bindgen(js_name = fromHex)] + pub fn from_hex(hex: String) -> Result { + let bytes = decode(&hex, Hex).map_err(|err| JsValue::from(JsError::from(err)))?; + + let public_key = + IdentityPublicKey::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + + Ok(IdentityPublicKeyWASM(public_key)) + } + + #[wasm_bindgen(js_name = fromBase64)] + pub fn from_base64(hex: String) -> Result { + let bytes = decode(&hex, Base64).map_err(|err| JsValue::from(JsError::from(err)))?; + + let public_key = + IdentityPublicKey::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + + Ok(IdentityPublicKeyWASM(public_key)) + } +} diff --git a/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs new file mode 100644 index 00000000000..1a7171312ed --- /dev/null +++ b/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs @@ -0,0 +1,188 @@ +use crate::asset_lock_proof::AssetLockProofWASM; +use crate::enums::platform::PlatformVersionWASM; +use crate::identifier::IdentifierWASM; +use crate::identity_transitions::public_key_in_creation::IdentityPublicKeyInCreationWASM; +use crate::state_transition::StateTransitionWASM; +use crate::utils::WithJsError; +use dpp::identity::state_transition::AssetLockProved; +use dpp::platform_value::BinaryData; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::decode; +use dpp::prelude::UserFeeIncrease; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable}; +use dpp::state_transition::identity_create_transition::IdentityCreateTransition; +use dpp::state_transition::identity_create_transition::accessors::IdentityCreateTransitionAccessorsV0; +use dpp::state_transition::identity_create_transition::v0::IdentityCreateTransitionV0; +use dpp::state_transition::public_key_in_creation::IdentityPublicKeyInCreation; +use dpp::state_transition::{StateTransition, StateTransitionLike}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[wasm_bindgen(js_name = "IdentityCreateTransitionWASM")] +#[derive(Clone)] +pub struct IdentityCreateTransitionWASM(IdentityCreateTransition); + +impl From for IdentityCreateTransitionWASM { + fn from(val: IdentityCreateTransition) -> Self { + IdentityCreateTransitionWASM(val) + } +} + +impl From for IdentityCreateTransition { + fn from(val: IdentityCreateTransitionWASM) -> Self { + val.0 + } +} + +#[wasm_bindgen] +impl IdentityCreateTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "IdentityCreateTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "IdentityCreateTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_public_keys: &js_sys::Array, + asset_lock: &AssetLockProofWASM, + signature: Option>, + user_fee_increase: Option, + ) -> Result { + let public_keys: Vec = + IdentityPublicKeyInCreationWASM::vec_from_js_value(js_public_keys)?; + + Ok(IdentityCreateTransitionWASM(IdentityCreateTransition::V0( + IdentityCreateTransitionV0 { + public_keys: public_keys.iter().map(|key| key.clone().into()).collect(), + asset_lock_proof: asset_lock.clone().into(), + user_fee_increase: user_fee_increase.unwrap_or(0), + signature: BinaryData::from(signature.unwrap_or(vec![])), + identity_id: asset_lock.create_identifier()?.into(), + }, + ))) + } + + #[wasm_bindgen(js_name = "default")] + pub fn default(js_platform_version: JsValue) -> Result { + let platform_version = PlatformVersionWASM::try_from(js_platform_version)?; + + IdentityCreateTransition::default_versioned(&platform_version.into()) + .map_err(|err| JsValue::from_str(&*err.to_string())) + .map(Into::into) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + + IdentityCreateTransitionWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> Result { + let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + + IdentityCreateTransitionWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Result, JsValue> { + self.0.serialize_to_bytes().with_js_error() + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + let rs_transition = + IdentityCreateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + + Ok(IdentityCreateTransitionWASM(rs_transition)) + } + + #[wasm_bindgen(getter = "publicKeys")] + pub fn get_public_keys(&self) -> Vec { + self.0 + .public_keys() + .iter() + .map(|key| IdentityPublicKeyInCreationWASM::from(key.clone())) + .collect() + } + + #[wasm_bindgen(js_name = "getIdentifier")] + pub fn get_identity_id(&self) -> IdentifierWASM { + self.0.identity_id().into() + } + + #[wasm_bindgen(getter = "userFeeIncrease")] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() + } + + #[wasm_bindgen(getter = "signature")] + pub fn get_signature(&self) -> Vec { + self.0.signature().to_vec() + } + + #[wasm_bindgen(js_name = "getSignableBytes")] + pub fn get_signable_bytes(&self) -> Result, JsValue> { + self.0.signable_bytes().with_js_error() + } + + #[wasm_bindgen(getter = "assetLock")] + pub fn get_asset_lock_proof(&self) -> AssetLockProofWASM { + AssetLockProofWASM::from(self.0.asset_lock_proof().clone()) + } + + #[wasm_bindgen(setter = "publicKeys")] + pub fn set_public_keys(&mut self, js_public_keys: &js_sys::Array) -> Result<(), JsValue> { + let public_keys: Vec = + IdentityPublicKeyInCreationWASM::vec_from_js_value(js_public_keys)?; + + self.0.set_public_keys( + public_keys + .iter() + .map(|key| IdentityPublicKeyInCreation::from(key.clone())) + .collect(), + ); + + Ok(()) + } + + #[wasm_bindgen(setter = "userFeeIncrease")] + pub fn set_user_fee_increase(&mut self, amount: u16) { + self.0.set_user_fee_increase(amount) + } + + #[wasm_bindgen(setter = "signature")] + pub fn set_signature(&mut self, signature: Vec) { + self.0.set_signature_bytes(signature) + } + + #[wasm_bindgen(setter = "assetLock")] + pub fn set_asset_lock_proof(&mut self, proof: AssetLockProofWASM) -> Result<(), JsValue> { + self.0.set_asset_lock_proof(proof.into()).with_js_error() + } + + #[wasm_bindgen(js_name = "toStateTransition")] + pub fn to_state_transition(&self) -> StateTransitionWASM { + StateTransitionWASM::from(StateTransition::IdentityCreate(self.clone().0)) + } + + #[wasm_bindgen(js_name = "fromStateTransition")] + pub fn from_state_transition( + st: &StateTransitionWASM, + ) -> Result { + let rs_st: StateTransition = st.clone().into(); + + match rs_st { + StateTransition::IdentityCreate(st) => Ok(IdentityCreateTransitionWASM(st)), + _ => Err(JsValue::from_str( + &"Invalid state document_transition type)", + )), + } + } +} diff --git a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs new file mode 100644 index 00000000000..09e6289a445 --- /dev/null +++ b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs @@ -0,0 +1,275 @@ +use crate::asset_lock_proof::AssetLockProofWASM; +use crate::core_script::CoreScriptWASM; +use crate::enums::keys::purpose::PurposeWASM; +use crate::enums::withdrawal::PoolingWASM; +use crate::identifier::IdentifierWASM; +use crate::state_transition::StateTransitionWASM; +use crate::utils::{IntoWasm, WithJsError}; +use dpp::identity::KeyID; +use dpp::identity::core_script::CoreScript; +use dpp::identity::state_transition::OptionallyAssetLockProved; +use dpp::platform_value::Identifier; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::prelude::{IdentityNonce, UserFeeIncrease}; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable}; +use dpp::state_transition::identity_credit_withdrawal_transition::IdentityCreditWithdrawalTransition; +use dpp::state_transition::identity_credit_withdrawal_transition::accessors::IdentityCreditWithdrawalTransitionAccessorsV0; +use dpp::state_transition::identity_credit_withdrawal_transition::v1::IdentityCreditWithdrawalTransitionV1; +use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[wasm_bindgen(js_name = "IdentityCreditWithdrawalTransitionWASM")] +pub struct IdentityCreditWithdrawalTransitionWASM(IdentityCreditWithdrawalTransition); + +#[wasm_bindgen] +impl IdentityCreditWithdrawalTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "IdentityCreditWithdrawalTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "IdentityCreditWithdrawalTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_identity_id: JsValue, + amount: u64, + core_fee_per_byte: u32, + js_pooling: JsValue, + js_output_script: &JsValue, + nonce: Option, + user_fee_increase: Option, + ) -> Result { + let pooling = PoolingWASM::try_from(js_pooling)?; + let identity_id: Identifier = IdentifierWASM::try_from(js_identity_id)?.into(); + + let output_script: Option = match js_output_script.is_undefined() { + true => None, + false => Some( + js_output_script + .to_wasm::("CoreScriptWASM")? + .clone() + .into(), + ), + }; + + Ok(IdentityCreditWithdrawalTransitionWASM( + IdentityCreditWithdrawalTransition::V1(IdentityCreditWithdrawalTransitionV1 { + amount, + identity_id, + output_script, + core_fee_per_byte, + pooling: pooling.into(), + nonce: nonce.unwrap_or(0), + user_fee_increase: user_fee_increase.unwrap_or(0), + signature_public_key_id: 0, + signature: Default::default(), + }), + )) + } + + #[wasm_bindgen(getter = "outputScript")] + pub fn get_output_script(&self) -> Option { + match self.0.output_script() { + None => None, + Some(script) => Some(script.into()), + } + } + + #[wasm_bindgen(getter = "pooling")] + pub fn get_pooling(&self) -> String { + PoolingWASM::from(self.0.pooling()).into() + } + + #[wasm_bindgen(getter = "identityId")] + pub fn get_identity_id(&self) -> IdentifierWASM { + IdentifierWASM::from(self.0.identity_id()) + } + + #[wasm_bindgen(getter = "userFeeIncrease")] + pub fn get_user_fee_increase(&self) -> UserFeeIncrease { + self.0.user_fee_increase() + } + + #[wasm_bindgen(getter = "nonce")] + pub fn get_nonce(&self) -> IdentityNonce { + self.0.nonce() + } + + #[wasm_bindgen(getter = "amount")] + pub fn get_amount(&self) -> u64 { + self.0.amount() + } + + #[wasm_bindgen(js_name = "getPurposeRequirement")] + pub fn get_purpose_requirement(&self) -> Vec { + self.0 + .purpose_requirement() + .iter() + .map(|purpose| PurposeWASM::from(purpose.clone()).into()) + .collect() + } + + #[wasm_bindgen(js_name = "getModifiedDataIds")] + pub fn get_modified_data_ids(&self) -> Vec { + self.0 + .modified_data_ids() + .iter() + .map(|id| id.clone().into()) + .collect() + } + + #[wasm_bindgen(js_name = "getOptionalAssetLockProof")] + pub fn get_optional_asset_lock_proof(&self) -> JsValue { + match self.0.optional_asset_lock_proof() { + Some(asset_lock) => JsValue::from(AssetLockProofWASM::from(asset_lock.clone())), + None => JsValue::null(), + } + } + + #[wasm_bindgen(setter = "outputScript")] + pub fn set_output_script(&mut self, js_script: &JsValue) -> Result<(), JsValue> { + match js_script.is_undefined() { + true => self.0.set_output_script(None), + false => { + let script: CoreScriptWASM = js_script + .to_wasm::("CoreScriptWASM")? + .clone(); + self.0.set_output_script(Some(script.clone().into())) + } + }; + + Ok(()) + } + + #[wasm_bindgen(setter = "pooling")] + pub fn set_pooling(&mut self, js_pooling: JsValue) -> Result<(), JsValue> { + let pooling: PoolingWASM = PoolingWASM::try_from(js_pooling)?; + Ok(self.0.set_pooling(pooling.into())) + } + + #[wasm_bindgen(setter = "identityId")] + pub fn set_identity_id(&mut self, js_identity_id: JsValue) -> Result<(), JsValue> { + let identity_id = IdentifierWASM::try_from(js_identity_id)?; + + Ok(self.0.set_identity_id(identity_id.into())) + } + + #[wasm_bindgen(setter = "userFeeIncrease")] + pub fn set_user_fee_increase(&mut self, user_fee_increase: UserFeeIncrease) { + self.0.set_user_fee_increase(user_fee_increase); + } + + #[wasm_bindgen(setter = "nonce")] + pub fn set_nonce(&mut self, nonce: IdentityNonce) { + self.0.set_nonce(nonce) + } + + #[wasm_bindgen(setter = "amount")] + pub fn set_amount(&mut self, amount: u64) { + self.0.set_amount(amount) + } + + #[wasm_bindgen(setter = "coreFeePerByte")] + pub fn set_core_fee_per_byte(&mut self, fee_per_byte: u32) { + self.0.set_core_fee_per_byte(fee_per_byte) + } + + #[wasm_bindgen(getter = "signature")] + pub fn get_signature(&self) -> Vec { + self.0.signature().to_vec() + } + + #[wasm_bindgen(getter = "coreFeePerByte")] + pub fn get_core_fee_per_byte(&self) -> u32 { + self.0.core_fee_per_byte() + } + + #[wasm_bindgen(js_name = "getSignableBytes")] + pub fn get_signable_bytes(&self) -> Result, JsValue> { + self.0.signable_bytes().with_js_error() + } + + #[wasm_bindgen(getter = "signaturePublicKeyId")] + pub fn get_signature_public_key_id(&self) -> KeyID { + self.0.signature_public_key_id() + } + + #[wasm_bindgen(setter = "signature")] + pub fn set_signature(&mut self, signature: Vec) { + self.0.set_signature_bytes(signature) + } + + #[wasm_bindgen(setter = "signaturePublicKeyId")] + pub fn set_signature_public_key_id(&mut self, signature_public_key_id: KeyID) { + self.0.set_signature_public_key_id(signature_public_key_id) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + + IdentityCreditWithdrawalTransitionWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> Result { + let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + + IdentityCreditWithdrawalTransitionWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Result, JsValue> { + self.0.serialize_to_bytes().with_js_error() + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_hex(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Hex, + )) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Base64, + )) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + let rs_transition = + IdentityCreditWithdrawalTransition::deserialize_from_bytes(bytes.as_slice()) + .with_js_error()?; + + Ok(IdentityCreditWithdrawalTransitionWASM(rs_transition)) + } + + #[wasm_bindgen(js_name = "toStateTransition")] + pub fn to_state_transition(&self) -> StateTransitionWASM { + StateTransitionWASM::from(StateTransition::from(self.0.clone())) + } + + #[wasm_bindgen(js_name = "fromStateTransition")] + pub fn from_state_transition( + st: &StateTransitionWASM, + ) -> Result { + let rs_st: StateTransition = st.clone().into(); + + match rs_st { + StateTransition::IdentityCreditWithdrawal(st) => { + Ok(IdentityCreditWithdrawalTransitionWASM(st)) + } + _ => Err(JsValue::from_str(&"Invalid state transition type)")), + } + } +} diff --git a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs new file mode 100644 index 00000000000..18bd5730eea --- /dev/null +++ b/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs @@ -0,0 +1,198 @@ +use crate::identifier::IdentifierWASM; +use crate::state_transition::StateTransitionWASM; +use crate::utils::WithJsError; +use dpp::platform_value::BinaryData; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::prelude::{Identifier, UserFeeIncrease}; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable}; +use dpp::state_transition::identity_credit_transfer_transition::IdentityCreditTransferTransition; +use dpp::state_transition::identity_credit_transfer_transition::accessors::IdentityCreditTransferTransitionAccessorsV0; +use dpp::state_transition::identity_credit_transfer_transition::v0::IdentityCreditTransferTransitionV0; +use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[wasm_bindgen(js_name = IdentityCreditTransferWASM)] +#[derive(Clone)] +pub struct IdentityCreditTransferWASM(IdentityCreditTransferTransition); + +#[wasm_bindgen] +impl IdentityCreditTransferWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "IdentityCreditTransferWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "IdentityCreditTransferWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + amount: u64, + js_sender: &JsValue, + js_recipient: &JsValue, + nonce: u64, + user_fee_increase: Option, + ) -> Result { + let sender: Identifier = IdentifierWASM::try_from(js_sender)?.into(); + + let recipient: Identifier = IdentifierWASM::try_from(js_recipient)?.into(); + + Ok(IdentityCreditTransferWASM( + IdentityCreditTransferTransition::V0(IdentityCreditTransferTransitionV0 { + identity_id: sender, + recipient_id: recipient, + amount, + nonce, + user_fee_increase: user_fee_increase.unwrap_or(0), + signature_public_key_id: 0, + signature: Default::default(), + }), + )) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Result, JsValue> { + self.0.serialize_to_bytes().with_js_error() + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_hex(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Hex, + )) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Base64, + )) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + let rs_transition = + IdentityCreditTransferTransition::deserialize_from_bytes(bytes.as_slice()) + .with_js_error()?; + + Ok(IdentityCreditTransferWASM(rs_transition)) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + IdentityCreditTransferWASM::from_bytes(decode(hex.as_str(), Hex).map_err(JsError::from)?) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(hex: String) -> Result { + IdentityCreditTransferWASM::from_bytes(decode(hex.as_str(), Base64).map_err(JsError::from)?) + } + + #[wasm_bindgen(setter = "recipientId")] + pub fn set_recipient_id(&mut self, js_recipient: &JsValue) -> Result<(), JsValue> { + let recipient: Identifier = IdentifierWASM::try_from(js_recipient)?.into(); + + Ok(self.0.set_recipient_id(recipient)) + } + + #[wasm_bindgen(setter = "senderId")] + pub fn set_sender_id(&mut self, js_sender: &JsValue) -> Result<(), JsValue> { + let sender: Identifier = IdentifierWASM::try_from(js_sender)?.into(); + + Ok(self.0.set_identity_id(sender)) + } + + #[wasm_bindgen(setter = "amount")] + pub fn set_amount(&mut self, amount: u64) { + self.0.set_amount(amount) + } + + #[wasm_bindgen(setter = "nonce")] + pub fn set_nonce(&mut self, nonce: u64) { + self.0.set_nonce(nonce) + } + + #[wasm_bindgen(setter = "signature")] + pub fn set_signature(&mut self, signature: Vec) { + self.0.set_signature_bytes(signature) + } + + #[wasm_bindgen(setter = "signaturePublicKeyId")] + pub fn set_signature_public_key_id(&mut self, public_key_id: u32) { + self.0.set_signature_public_key_id(public_key_id) + } + + #[wasm_bindgen(setter = "userFeeIncrease")] + pub fn set_user_fee_increase(&mut self, amount: u16) { + self.0.set_user_fee_increase(amount) + } + + #[wasm_bindgen(getter = "signature")] + pub fn get_signature(&self) -> Vec { + self.0.signature().to_vec() + } + + #[wasm_bindgen(js_name = "getSignableBytes")] + pub fn get_signable_bytes(&self) -> Result, JsValue> { + self.0.signable_bytes().with_js_error() + } + + #[wasm_bindgen(getter = "signaturePublicKeyId")] + pub fn get_signature_public_key_id(&self) -> u32 { + self.0.signature_public_key_id() + } + + #[wasm_bindgen(getter = "userFeeIncrease")] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() + } + + #[wasm_bindgen(getter = "recipientId")] + pub fn get_recipient_id(&self) -> IdentifierWASM { + self.0.recipient_id().into() + } + + #[wasm_bindgen(getter = "senderId")] + pub fn get_identity_id(&self) -> IdentifierWASM { + self.0.identity_id().into() + } + + #[wasm_bindgen(getter = "amount")] + pub fn get_amount(&self) -> u64 { + self.0.amount() + } + + #[wasm_bindgen(getter = "nonce")] + pub fn get_nonce(&self) -> u64 { + self.0.nonce() + } + + #[wasm_bindgen(js_name = "toStateTransition")] + pub fn to_state_transition(&self) -> StateTransitionWASM { + StateTransitionWASM::from(StateTransition::from(self.0.clone())) + } + + #[wasm_bindgen(js_name = "fromStateTransition")] + pub fn from_state_transition( + st: &StateTransitionWASM, + ) -> Result { + let rs_st: StateTransition = st.clone().into(); + + match rs_st { + StateTransition::IdentityCreditTransfer(st) => Ok(IdentityCreditTransferWASM(st)), + _ => Err(JsValue::from_str(&"Invalid state transition type)")), + } + } +} + +impl IdentityCreditTransferWASM { + pub fn set_signature_binary_data(&mut self, data: BinaryData) { + self.0.set_signature(data) + } +} diff --git a/packages/wasm-dpp2/src/identity_transitions/mod.rs b/packages/wasm-dpp2/src/identity_transitions/mod.rs new file mode 100644 index 00000000000..5e1c857d817 --- /dev/null +++ b/packages/wasm-dpp2/src/identity_transitions/mod.rs @@ -0,0 +1,6 @@ +pub mod create_transition; +pub mod credit_withdrawal_transition; +pub mod identity_credit_transfer_transition; +pub mod public_key_in_creation; +pub mod top_up_transition; +pub mod update_transition; diff --git a/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs b/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs new file mode 100644 index 00000000000..9c6673b4e92 --- /dev/null +++ b/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs @@ -0,0 +1,253 @@ +use crate::contract_bounds::ContractBoundsWASM; +use crate::enums::keys::key_type::KeyTypeWASM; +use crate::enums::keys::purpose::PurposeWASM; +use crate::enums::keys::security_level::SecurityLevelWASM; +use crate::identity_public_key::IdentityPublicKeyWASM; +use crate::utils::{IntoWasm, WithJsError}; +use dpp::identity::contract_bounds::ContractBounds; +use dpp::identity::identity_public_key::v0::IdentityPublicKeyV0; +use dpp::identity::{IdentityPublicKey, KeyType, Purpose, SecurityLevel}; +use dpp::platform_value::BinaryData; +use dpp::platform_value::string_encoding::Encoding::Hex; +use dpp::state_transition::public_key_in_creation::IdentityPublicKeyInCreation; +use dpp::state_transition::public_key_in_creation::accessors::{ + IdentityPublicKeyInCreationV0Getters, IdentityPublicKeyInCreationV0Setters, +}; +use dpp::state_transition::public_key_in_creation::v0::IdentityPublicKeyInCreationV0; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name = "IdentityPublicKeyInCreationWASM")] +pub struct IdentityPublicKeyInCreationWASM(IdentityPublicKeyInCreation); + +impl From for IdentityPublicKeyInCreationWASM { + fn from(value: IdentityPublicKeyInCreation) -> Self { + IdentityPublicKeyInCreationWASM(value) + } +} + +impl From for IdentityPublicKeyInCreation { + fn from(value: IdentityPublicKeyInCreationWASM) -> Self { + value.0 + } +} + +impl TryFrom for IdentityPublicKeyInCreationWASM { + type Error = JsValue; + fn try_from(value: JsValue) -> Result { + let value = + value.to_wasm::("IdentityPublicKeyInCreationWASM")?; + + Ok(value.clone()) + } +} + +impl From for IdentityPublicKey { + fn from(value: IdentityPublicKeyInCreationWASM) -> Self { + let contract_bounds = match value.0.contract_bounds() { + None => None, + Some(bounds) => Some(bounds.clone()), + }; + + IdentityPublicKey::V0(IdentityPublicKeyV0 { + id: value.0.id(), + purpose: value.0.purpose(), + security_level: value.0.security_level(), + contract_bounds, + key_type: value.0.key_type(), + read_only: value.0.read_only(), + data: value.0.data().clone(), + disabled_at: None, + }) + } +} + +#[wasm_bindgen] +impl IdentityPublicKeyInCreationWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "IdentityPublicKeyInCreationWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "IdentityPublicKeyInCreationWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + id: u32, + js_purpose: JsValue, + js_security_level: JsValue, + js_key_type: JsValue, + read_only: bool, + binary_data: Vec, + signature: Option>, + js_contract_bounds: &JsValue, + ) -> Result { + let purpose = PurposeWASM::try_from(js_purpose)?; + let security_level = SecurityLevelWASM::try_from(js_security_level)?; + let key_type = KeyTypeWASM::try_from(js_key_type)?; + let contract_bounds: Option = + match js_contract_bounds.is_undefined() | js_contract_bounds.is_null() { + true => None, + false => Some( + js_contract_bounds + .to_wasm::("ContractBoundsWASM")? + .clone() + .into(), + ), + }; + + Ok(IdentityPublicKeyInCreationWASM( + IdentityPublicKeyInCreation::V0(IdentityPublicKeyInCreationV0 { + id, + key_type: KeyType::from(key_type), + purpose: Purpose::from(purpose), + security_level: SecurityLevel::from(security_level), + contract_bounds, + read_only, + data: BinaryData::from(binary_data), + signature: BinaryData::from(signature.unwrap_or(Vec::new())), + }), + )) + } + + #[wasm_bindgen(js_name = toIdentityPublicKey)] + pub fn to_identity_public_key(&self) -> Result { + IdentityPublicKeyWASM::new( + self.0.id(), + JsValue::from(PurposeWASM::from(self.0.purpose())), + JsValue::from(SecurityLevelWASM::from(self.0.security_level())), + JsValue::from(KeyTypeWASM::from(self.0.key_type())), + self.0.read_only(), + self.0.data().to_string(Hex).as_str(), + None, + &JsValue::from(self.get_contract_bounds().clone()), + ) + } + + #[wasm_bindgen(js_name = "getHash")] + pub fn get_hash(&self) -> Result, JsValue> { + match self.0.hash().with_js_error() { + Ok(hash) => Ok(hash.to_vec()), + Err(err) => Err(err), + } + } + + #[wasm_bindgen(getter = "contractBounds")] + pub fn get_contract_bounds(&self) -> Option { + match self.0.contract_bounds() { + Some(bounds) => Some(ContractBoundsWASM::from(bounds.clone())), + None => None, + } + } + + #[wasm_bindgen(getter = keyId)] + pub fn get_key_id(&self) -> u32 { + self.0.id() + } + + #[wasm_bindgen(getter = purpose)] + pub fn get_purpose(&self) -> String { + PurposeWASM::from(self.0.purpose()).into() + } + + #[wasm_bindgen(getter = securityLevel)] + pub fn get_security_level(&self) -> String { + SecurityLevelWASM::from(self.0.security_level()).into() + } + + #[wasm_bindgen(getter = keyType)] + pub fn get_key_type(&self) -> String { + KeyTypeWASM::from(self.0.key_type()).into() + } + + #[wasm_bindgen(getter = readOnly)] + pub fn get_read_only(&self) -> bool { + self.0.read_only() + } + + #[wasm_bindgen(getter = data)] + pub fn get_data(&self) -> Vec { + self.0.data().to_vec() + } + + #[wasm_bindgen(getter = signature)] + pub fn get_signature(&self) -> Vec { + self.0.signature().to_vec() + } + + #[wasm_bindgen(setter = keyId)] + pub fn set_key_id(&mut self, key_id: u32) { + self.0.set_id(key_id) + } + + #[wasm_bindgen(setter = purpose)] + pub fn set_purpose(&mut self, js_purpose: JsValue) -> Result<(), JsValue> { + let purpose = PurposeWASM::try_from(js_purpose)?; + Ok(self.0.set_purpose(Purpose::from(purpose))) + } + + #[wasm_bindgen(setter = securityLevel)] + pub fn set_security_level(&mut self, js_security_level: JsValue) -> Result<(), JsValue> { + let security_level = SecurityLevelWASM::try_from(js_security_level)?; + Ok(self + .0 + .set_security_level(SecurityLevel::from(security_level))) + } + + #[wasm_bindgen(setter = keyType)] + pub fn set_key_type(&mut self, key_type: JsValue) -> Result<(), JsValue> { + let key_type = KeyTypeWASM::try_from(key_type)?; + self.0.set_type(key_type.into()); + Ok(()) + } + + #[wasm_bindgen(setter = readOnly)] + pub fn set_read_only(&mut self, read_only: bool) { + self.0.set_read_only(read_only) + } + + #[wasm_bindgen(setter = data)] + pub fn set_data(&mut self, binary_data: Vec) { + let data = BinaryData::from(binary_data); + self.0.set_data(data) + } + + #[wasm_bindgen(setter = signature)] + pub fn set_signature(&mut self, binary_data: Vec) { + let signature = BinaryData::from(binary_data); + self.0.set_signature(signature) + } + + #[wasm_bindgen(setter = "contractBounds")] + pub fn set_contract_bounds(&mut self, js_bounds: &JsValue) -> Result<(), JsValue> { + match js_bounds.is_undefined() { + true => self.0.set_contract_bounds(None), + false => { + let bounds = js_bounds + .to_wasm::("ContractBoundsWASM")? + .clone(); + + self.0.set_contract_bounds(Some(bounds.into())) + } + }; + + Ok(()) + } +} + +impl IdentityPublicKeyInCreationWASM { + pub fn vec_from_js_value( + js_add_public_keys: &js_sys::Array, + ) -> Result, JsValue> { + let add_public_keys: Vec = js_add_public_keys + .iter() + .map(|key| IdentityPublicKeyInCreationWASM::try_from(key)) + .collect::, JsValue>>()?; + + Ok(add_public_keys) + } +} diff --git a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs new file mode 100644 index 00000000000..2d2d1d95e7c --- /dev/null +++ b/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs @@ -0,0 +1,181 @@ +use crate::asset_lock_proof::AssetLockProofWASM; +use crate::identifier::IdentifierWASM; +use crate::state_transition::StateTransitionWASM; +use crate::utils::WithJsError; +use dpp::identifier::Identifier; +use dpp::identity::state_transition::{AssetLockProved, OptionallyAssetLockProved}; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::prelude::UserFeeIncrease; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable}; +use dpp::state_transition::identity_topup_transition::IdentityTopUpTransition; +use dpp::state_transition::identity_topup_transition::accessors::IdentityTopUpTransitionAccessorsV0; +use dpp::state_transition::identity_topup_transition::v0::IdentityTopUpTransitionV0; +use dpp::state_transition::{StateTransition, StateTransitionLike}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[wasm_bindgen(js_name = "IdentityTopUpTransitionWASM")] +#[derive(Clone)] +pub struct IdentityTopUpTransitionWASM(IdentityTopUpTransition); + +#[wasm_bindgen] +impl IdentityTopUpTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "IdentityTopUpTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "IdentityTopUpTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + asset_lock_proof: &AssetLockProofWASM, + js_identity_id: JsValue, + user_fee_increase: Option, + ) -> Result { + let identity_id: Identifier = IdentifierWASM::try_from(js_identity_id)?.into(); + + Ok(IdentityTopUpTransitionWASM(IdentityTopUpTransition::V0( + IdentityTopUpTransitionV0 { + asset_lock_proof: asset_lock_proof.clone().into(), + identity_id, + user_fee_increase: user_fee_increase.unwrap_or(0), + signature: Default::default(), + }, + ))) + } + + #[wasm_bindgen(js_name = "getModifiedDataIds")] + pub fn get_modified_data_ids(&self) -> Vec { + self.0 + .modified_data_ids() + .iter() + .map(|id| id.clone().into()) + .collect() + } + + #[wasm_bindgen(js_name = "getOptionalAssetLockProof")] + pub fn get_optional_asset_lock_proof(&self) -> JsValue { + match self.0.optional_asset_lock_proof() { + Some(asset_lock) => JsValue::from(AssetLockProofWASM::from(asset_lock.clone())), + None => JsValue::null(), + } + } + + #[wasm_bindgen(getter = "userFeeIncrease")] + pub fn get_user_fee_increase(&self) -> UserFeeIncrease { + self.0.user_fee_increase() + } + + #[wasm_bindgen(getter = "identityIdentifier")] + pub fn get_identity_identifier(&self) -> IdentifierWASM { + self.0.identity_id().clone().into() + } + + #[wasm_bindgen(getter = "assetLockProof")] + pub fn get_asset_lock_proof(&self) -> AssetLockProofWASM { + self.0.asset_lock_proof().clone().into() + } + + #[wasm_bindgen(setter = "userFeeIncrease")] + pub fn set_user_fee_increase(&mut self, user_fee_increase: UserFeeIncrease) { + self.0.set_user_fee_increase(user_fee_increase); + } + + #[wasm_bindgen(setter = "identityIdentifier")] + pub fn set_identity_identifier( + &mut self, + js_identity_identifier: &JsValue, + ) -> Result<(), JsValue> { + let identity_identifier: Identifier = + IdentifierWASM::try_from(js_identity_identifier)?.into(); + Ok(self.0.set_identity_id(identity_identifier.clone().into())) + } + + #[wasm_bindgen(setter = "assetLockProof")] + pub fn set_asset_lock_proof( + &mut self, + asset_lock_proof: &AssetLockProofWASM, + ) -> Result<(), JsValue> { + self.0 + .set_asset_lock_proof(asset_lock_proof.clone().into()) + .with_js_error() + } + + #[wasm_bindgen(getter = "signature")] + pub fn get_signature(&self) -> Vec { + self.0.signature().to_vec() + } + + #[wasm_bindgen(js_name = "getSignableBytes")] + pub fn get_signable_bytes(&self) -> Result, JsValue> { + self.0.signable_bytes().with_js_error() + } + + #[wasm_bindgen(setter = "signature")] + pub fn set_signature(&mut self, signature: Vec) { + self.0.set_signature_bytes(signature) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Result, JsValue> { + self.0.serialize_to_bytes().with_js_error() + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_hex(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Hex, + )) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Base64, + )) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + let rs_transition = + IdentityTopUpTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + + Ok(IdentityTopUpTransitionWASM(rs_transition)) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + IdentityTopUpTransitionWASM::from_bytes(decode(hex.as_str(), Hex).map_err(JsError::from)?) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> Result { + IdentityTopUpTransitionWASM::from_bytes( + decode(base64.as_str(), Base64).map_err(JsError::from)?, + ) + } + + #[wasm_bindgen(js_name = "toStateTransition")] + pub fn to_state_transition(&self) -> StateTransitionWASM { + StateTransitionWASM::from(StateTransition::from(self.0.clone())) + } + + #[wasm_bindgen(js_name = "fromStateTransition")] + pub fn from_state_transition( + st: &StateTransitionWASM, + ) -> Result { + let rs_st: StateTransition = st.clone().into(); + + match rs_st { + StateTransition::IdentityTopUp(st) => Ok(IdentityTopUpTransitionWASM(st)), + _ => Err(JsValue::from_str(&"Invalid state transition type)")), + } + } +} diff --git a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs new file mode 100644 index 00000000000..06f7545fed4 --- /dev/null +++ b/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs @@ -0,0 +1,255 @@ +use crate::asset_lock_proof::AssetLockProofWASM; +use crate::enums::keys::purpose::PurposeWASM; +use crate::identifier::IdentifierWASM; +use crate::identity_transitions::public_key_in_creation::IdentityPublicKeyInCreationWASM; +use crate::state_transition::StateTransitionWASM; +use crate::utils::WithJsError; +use dpp::identity::KeyID; +use dpp::identity::state_transition::OptionallyAssetLockProved; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::prelude::{IdentityNonce, Revision, UserFeeIncrease}; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable}; +use dpp::state_transition::identity_update_transition::IdentityUpdateTransition; +use dpp::state_transition::identity_update_transition::accessors::IdentityUpdateTransitionAccessorsV0; +use dpp::state_transition::identity_update_transition::v0::IdentityUpdateTransitionV0; +use dpp::state_transition::public_key_in_creation::IdentityPublicKeyInCreation; +use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[wasm_bindgen(js_name = "IdentityUpdateTransitionWASM")] +#[derive(Clone)] +pub struct IdentityUpdateTransitionWASM(IdentityUpdateTransition); + +#[wasm_bindgen] +impl IdentityUpdateTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "IdentityUpdateTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "IdentityUpdateTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_identity_id: &JsValue, + revision: Revision, + nonce: IdentityNonce, + js_add_public_keys: &js_sys::Array, + disable_public_keys: Vec, + user_fee_increase: Option, + ) -> Result { + let identity_id = IdentifierWASM::try_from(js_identity_id)?; + + let add_public_keys: Vec = + IdentityPublicKeyInCreationWASM::vec_from_js_value(js_add_public_keys)?; + + Ok(IdentityUpdateTransitionWASM(IdentityUpdateTransition::V0( + IdentityUpdateTransitionV0 { + identity_id: identity_id.into(), + revision, + nonce, + add_public_keys: add_public_keys + .clone() + .iter() + .map(|key| key.clone().into()) + .collect(), + disable_public_keys, + user_fee_increase: user_fee_increase.unwrap_or(0), + signature_public_key_id: 0, + signature: Default::default(), + }, + ))) + } + + #[wasm_bindgen(getter = "revision")] + pub fn get_revision(&self) -> Revision { + self.0.revision() + } + + #[wasm_bindgen(getter = "nonce")] + pub fn get_nonce(&self) -> IdentityNonce { + self.0.nonce() + } + + #[wasm_bindgen(getter = "identityIdentifier")] + pub fn get_identity_identifier(&self) -> IdentifierWASM { + self.0.identity_id().into() + } + + #[wasm_bindgen(js_name = "getPurposeRequirement")] + pub fn get_purpose_requirement(&self) -> Vec { + self.0 + .purpose_requirement() + .iter() + .map(|purpose| PurposeWASM::from(purpose.clone()).into()) + .collect() + } + + #[wasm_bindgen(js_name = "getModifiedDataIds")] + pub fn get_modified_data_ids(&self) -> Vec { + self.0 + .modified_data_ids() + .iter() + .map(|id| id.clone().into()) + .collect() + } + + #[wasm_bindgen(js_name = "getOptionalAssetLockProof")] + pub fn get_optional_asset_lock_proof(&self) -> JsValue { + match self.0.optional_asset_lock_proof() { + Some(asset_lock) => JsValue::from(AssetLockProofWASM::from(asset_lock.clone())), + None => JsValue::null(), + } + } + + #[wasm_bindgen(getter = "publicKeyIdsToDisable")] + pub fn get_public_key_ids_to_disable(&self) -> Vec { + self.0.public_key_ids_to_disable().to_vec() + } + + #[wasm_bindgen(getter = "publicKeyIdsToAdd")] + pub fn get_public_key_ids_to_add(&self) -> Vec { + self.0 + .public_keys_to_add() + .to_vec() + .iter() + .map(|id| id.clone().into()) + .collect() + } + + #[wasm_bindgen(getter = "userFeeIncrease")] + pub fn get_user_fee_increase(&self) -> UserFeeIncrease { + self.0.user_fee_increase() + } + + #[wasm_bindgen(setter = "revision")] + pub fn set_revision(&mut self, revision: Revision) { + self.0.set_revision(revision); + } + + #[wasm_bindgen(setter = "nonce")] + pub fn set_nonce(&mut self, nonce: IdentityNonce) { + self.0.set_nonce(nonce); + } + + #[wasm_bindgen(setter = "identityIdentifier")] + pub fn set_identity_identifier(&mut self, js_identity_id: &JsValue) -> Result<(), JsValue> { + let identity_id = IdentifierWASM::try_from(js_identity_id)?; + self.0.set_identity_id(identity_id.clone().into()); + Ok(()) + } + + #[wasm_bindgen(setter = "publicKeyIdsToAdd")] + pub fn set_public_key_ids_to_add( + &mut self, + js_add_public_keys: &js_sys::Array, + ) -> Result<(), JsValue> { + let add_public_keys: Vec = + IdentityPublicKeyInCreationWASM::vec_from_js_value(js_add_public_keys)?; + + let keys: Vec = + add_public_keys.iter().map(|id| id.clone().into()).collect(); + + Ok(self.0.set_public_keys_to_add(keys)) + } + + #[wasm_bindgen(setter = "publicKeyIdsToDisable")] + pub fn set_public_key_ids_to_disable(&mut self, public_keys: Vec) { + self.0.set_public_key_ids_to_disable(public_keys) + } + + #[wasm_bindgen(setter = "userFeeIncrease")] + pub fn set_user_fee_increase(&mut self, user_fee_increase: UserFeeIncrease) { + self.0.set_user_fee_increase(user_fee_increase) + } + + #[wasm_bindgen(getter = "signature")] + pub fn get_signature(&self) -> Vec { + self.0.signature().to_vec() + } + + #[wasm_bindgen(js_name = "getSignableBytes")] + pub fn get_signable_bytes(&self) -> Result, JsValue> { + self.0.signable_bytes().with_js_error() + } + + #[wasm_bindgen(getter = "signaturePublicKeyId")] + pub fn get_signature_public_key_id(&self) -> KeyID { + self.0.signature_public_key_id() + } + + #[wasm_bindgen(setter = "signature")] + pub fn set_signature(&mut self, signature: Vec) { + self.0.set_signature_bytes(signature) + } + + #[wasm_bindgen(setter = "signaturePublicKeyId")] + pub fn set_signature_public_key_id(&mut self, signature_public_key_id: KeyID) { + self.0.set_signature_public_key_id(signature_public_key_id) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + + IdentityUpdateTransitionWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> Result { + let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + + IdentityUpdateTransitionWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Result, JsValue> { + self.0.serialize_to_bytes().with_js_error() + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_hex(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Hex, + )) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> Result { + Ok(encode( + self.0.serialize_to_bytes().with_js_error()?.as_slice(), + Base64, + )) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + let rs_transition = + IdentityUpdateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + + Ok(IdentityUpdateTransitionWASM(rs_transition)) + } + + #[wasm_bindgen(js_name = "toStateTransition")] + pub fn to_state_transition(&self) -> StateTransitionWASM { + StateTransitionWASM::from(StateTransition::from(self.0.clone())) + } + + #[wasm_bindgen(js_name = "fromStateTransition")] + pub fn from_state_transition( + st: &StateTransitionWASM, + ) -> Result { + let rs_st: StateTransition = st.clone().into(); + + match rs_st { + StateTransition::IdentityUpdate(st) => Ok(IdentityUpdateTransitionWASM(st)), + _ => Err(JsValue::from_str(&"Invalid state transition type)")), + } + } +} diff --git a/packages/wasm-dpp2/src/lib.rs b/packages/wasm-dpp2/src/lib.rs new file mode 100644 index 00000000000..c0d9a6e4cb5 --- /dev/null +++ b/packages/wasm-dpp2/src/lib.rs @@ -0,0 +1,35 @@ +// #[global_allocator] +// static ALLOCATOR: talc::Talck = unsafe { +// use core::{mem::MaybeUninit, ptr::addr_of_mut}; +// +// const MEMORY_SIZE: usize = 128 * 1024 * 1024; +// static mut MEMORY: [MaybeUninit; MEMORY_SIZE] = [MaybeUninit::uninit(); MEMORY_SIZE]; +// let span = talc::Span::from_array(addr_of_mut!(MEMORY)); +// let oom_handler = { talc::ClaimOnOom::new(span) }; +// talc::Talc::new(oom_handler).lock() +// }; + +pub mod asset_lock_proof; +pub mod batch; +pub mod consensus_error; +pub mod contract_bounds; +pub mod core_script; +pub mod data_contract; +pub mod data_contract_transitions; +pub mod document; +pub mod encrypted_note; +pub mod enums; +pub mod group_state_transition_info; +pub mod identifier; +pub mod identity; +pub mod identity_public_key; +pub mod identity_transitions; +pub mod masternode_vote; +pub mod mock_bls; +pub mod partial_identity; +pub mod private_key; +pub mod public_key; +pub mod state_transition; +pub mod token_configuration; +pub mod token_configuration_change_item; +pub mod utils; diff --git a/packages/wasm-dpp2/src/masternode_vote/mod.rs b/packages/wasm-dpp2/src/masternode_vote/mod.rs new file mode 100644 index 00000000000..3161985de1a --- /dev/null +++ b/packages/wasm-dpp2/src/masternode_vote/mod.rs @@ -0,0 +1,227 @@ +pub mod resource_vote_choice; +pub mod vote; +pub mod vote_poll; + +use crate::asset_lock_proof::AssetLockProofWASM; +use crate::identifier::IdentifierWASM; +use crate::masternode_vote::vote::VoteWASM; +use crate::state_transition::StateTransitionWASM; +use crate::utils::WithJsError; +use dpp::identity::KeyID; +use dpp::identity::state_transition::OptionallyAssetLockProved; +use dpp::platform_value::BinaryData; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::decode; +use dpp::prelude::IdentityNonce; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable}; +use dpp::state_transition::masternode_vote_transition::MasternodeVoteTransition; +use dpp::state_transition::masternode_vote_transition::accessors::MasternodeVoteTransitionAccessorsV0; +use dpp::state_transition::masternode_vote_transition::v0::MasternodeVoteTransitionV0; +use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[wasm_bindgen(js_name = "MasternodeVoteTransitionWASM")] +#[derive(Clone)] +pub struct MasternodeVoteTransitionWASM(MasternodeVoteTransition); + +impl From for MasternodeVoteTransitionWASM { + fn from(val: MasternodeVoteTransition) -> Self { + MasternodeVoteTransitionWASM(val) + } +} + +impl From for MasternodeVoteTransition { + fn from(val: MasternodeVoteTransitionWASM) -> Self { + val.0 + } +} + +#[wasm_bindgen] +impl MasternodeVoteTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "MasternodeVoteTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "MasternodeVoteTransitionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_pro_tx_hash: &JsValue, + js_voter_identity_id: &JsValue, + vote: &VoteWASM, + nonce: IdentityNonce, + signature_public_key: Option, + signature: Option>, + ) -> Result { + let pro_tx_hash = IdentifierWASM::try_from(js_pro_tx_hash)?; + let voter_identity_id = IdentifierWASM::try_from(js_voter_identity_id)?; + + Ok(MasternodeVoteTransitionWASM(MasternodeVoteTransition::V0( + MasternodeVoteTransitionV0 { + pro_tx_hash: pro_tx_hash.into(), + voter_identity_id: voter_identity_id.into(), + vote: vote.clone().into(), + nonce, + signature_public_key_id: signature_public_key.unwrap_or(0), + signature: BinaryData::from(signature.unwrap_or(vec![])), + }, + ))) + } + + #[wasm_bindgen(getter = proTxHash)] + pub fn pro_tx_hash(&self) -> IdentifierWASM { + self.0.pro_tx_hash().into() + } + + #[wasm_bindgen(getter = voterIdentityId)] + pub fn voter_identity_id(&self) -> IdentifierWASM { + self.0.voter_identity_id().into() + } + + #[wasm_bindgen(getter = vote)] + pub fn vote(&self) -> VoteWASM { + self.0.vote().clone().into() + } + + #[wasm_bindgen(getter = nonce)] + pub fn nonce(&self) -> IdentityNonce { + self.0.nonce() + } + + #[wasm_bindgen(getter=signaturePublicKeyId)] + pub fn signature_public_key_id(&self) -> KeyID { + self.0.signature_public_key_id() + } + + #[wasm_bindgen(getter=signature)] + pub fn signature(&self) -> Vec { + self.0.signature().clone().to_vec() + } + + #[wasm_bindgen(setter = proTxHash)] + pub fn set_pro_tx_hash(&mut self, js_pro_tx_hash: &JsValue) -> Result<(), JsValue> { + let pro_tx_hash = IdentifierWASM::try_from(js_pro_tx_hash)?; + + self.0.set_pro_tx_hash(pro_tx_hash.into()); + + Ok(()) + } + + #[wasm_bindgen(setter = voterIdentityId)] + pub fn set_voter_identity_id(&mut self, js_voter_identity_id: &JsValue) -> Result<(), JsValue> { + let voter_identity_id = IdentifierWASM::try_from(js_voter_identity_id)?; + + self.0.set_voter_identity_id(voter_identity_id.into()); + + Ok(()) + } + + #[wasm_bindgen(setter = vote)] + pub fn set_vote(&mut self, vote: &VoteWASM) { + self.0.set_vote(vote.clone().into()) + } + + #[wasm_bindgen(setter = nonce)] + pub fn set_nonce(&mut self, nonce: IdentityNonce) { + self.0 = match self.0.clone() { + MasternodeVoteTransition::V0(mut vote) => { + vote.nonce = nonce; + + MasternodeVoteTransition::V0(vote) + } + } + } + + #[wasm_bindgen(setter=signaturePublicKeyId)] + pub fn set_signature_public_key_id(&mut self, signature_public_key_id: KeyID) { + self.0.set_signature_public_key_id(signature_public_key_id) + } + + #[wasm_bindgen(setter=signature)] + pub fn set_signature(&mut self, signature: Vec) { + self.0.set_signature_bytes(signature); + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + + MasternodeVoteTransitionWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> Result { + let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + + MasternodeVoteTransitionWASM::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Result, JsValue> { + self.0.serialize_to_bytes().with_js_error() + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + let rs_transition = + MasternodeVoteTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + + Ok(MasternodeVoteTransitionWASM(rs_transition)) + } + + #[wasm_bindgen(getter = "userFeeIncrease")] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() + } + + #[wasm_bindgen(js_name = "getSignableBytes")] + pub fn get_signable_bytes(&self) -> Result, JsValue> { + self.0.signable_bytes().with_js_error() + } + + #[wasm_bindgen(getter = "assetLock")] + pub fn get_asset_lock_proof(&self) -> Option { + match self.0.optional_asset_lock_proof().clone() { + None => None, + Some(asset_lock_proof) => Some(AssetLockProofWASM::from(asset_lock_proof.clone())), + } + } + + #[wasm_bindgen(setter = "userFeeIncrease")] + pub fn set_user_fee_increase(&mut self, amount: u16) { + self.0.set_user_fee_increase(amount) + } + + #[wasm_bindgen(getter = "modifiedDataIds")] + pub fn get_modified_data_ids(&self) -> Vec { + self.0 + .modified_data_ids() + .iter() + .map(|id| id.clone().into()) + .collect() + } + + #[wasm_bindgen(js_name = "toStateTransition")] + pub fn to_state_transition(&self) -> StateTransitionWASM { + StateTransitionWASM::from(StateTransition::MasternodeVote(self.clone().0)) + } + + #[wasm_bindgen(js_name = "fromStateTransition")] + pub fn from_state_transition( + st: &StateTransitionWASM, + ) -> Result { + let rs_st: StateTransition = st.clone().into(); + + match rs_st { + StateTransition::MasternodeVote(st) => Ok(MasternodeVoteTransitionWASM(st)), + _ => Err(JsValue::from_str( + &"Invalid state document_transition type)", + )), + } + } +} diff --git a/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs b/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs new file mode 100644 index 00000000000..8796b69bc1f --- /dev/null +++ b/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs @@ -0,0 +1,70 @@ +use crate::identifier::IdentifierWASM; +use dpp::voting::vote_choices::resource_vote_choice::ResourceVoteChoice; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name = ResourceVoteChoiceWASM)] +pub struct ResourceVoteChoiceWASM(ResourceVoteChoice); + +impl From for ResourceVoteChoiceWASM { + fn from(choice: ResourceVoteChoice) -> Self { + Self(choice) + } +} + +impl From for ResourceVoteChoice { + fn from(choice: ResourceVoteChoiceWASM) -> Self { + choice.0 + } +} + +#[wasm_bindgen] +impl ResourceVoteChoiceWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "ResourceVoteChoiceWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "ResourceVoteChoiceWASM".to_string() + } + + #[wasm_bindgen(js_name = "TowardsIdentity")] + pub fn towards_identity(js_id: &JsValue) -> Result { + let id = IdentifierWASM::try_from(js_id)?; + + Ok(ResourceVoteChoiceWASM(ResourceVoteChoice::TowardsIdentity( + id.into(), + ))) + } + + #[wasm_bindgen(js_name = "Abstain")] + pub fn abstain() -> Self { + ResourceVoteChoiceWASM(ResourceVoteChoice::Abstain) + } + + #[wasm_bindgen(js_name = "Lock")] + pub fn lock() -> Self { + ResourceVoteChoiceWASM(ResourceVoteChoice::Lock) + } + + #[wasm_bindgen(js_name = "getValue")] + pub fn get_value(&self) -> JsValue { + match self.0.clone() { + ResourceVoteChoice::TowardsIdentity(id) => JsValue::from(IdentifierWASM::from(id)), + ResourceVoteChoice::Abstain => JsValue::undefined(), + ResourceVoteChoice::Lock => JsValue::undefined(), + } + } + + #[wasm_bindgen(js_name = "getType")] + pub fn get_type(&self) -> String { + match self.0.clone() { + ResourceVoteChoice::TowardsIdentity(_) => "TowardsIdentity".to_string(), + ResourceVoteChoice::Abstain => "Abstain".to_string(), + ResourceVoteChoice::Lock => "Lock".to_string(), + } + } +} diff --git a/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs b/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs new file mode 100644 index 00000000000..dec275105b1 --- /dev/null +++ b/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs @@ -0,0 +1,78 @@ +use crate::masternode_vote::resource_vote_choice::ResourceVoteChoiceWASM; +use crate::masternode_vote::vote_poll::VotePollWASM; +use dpp::voting::votes::Vote; +use dpp::voting::votes::resource_vote::ResourceVote; +use dpp::voting::votes::resource_vote::accessors::v0::ResourceVoteGettersV0; +use dpp::voting::votes::resource_vote::v0::ResourceVoteV0; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name=VoteWASM)] +pub struct VoteWASM(Vote); + +impl From for VoteWASM { + fn from(vote: Vote) -> Self { + Self(vote) + } +} + +impl From for Vote { + fn from(vote: VoteWASM) -> Self { + vote.0 + } +} + +#[wasm_bindgen] +impl VoteWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "VoteWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "VoteWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(vote_poll: &VotePollWASM, resource_vote_choice: &ResourceVoteChoiceWASM) -> Self { + VoteWASM(Vote::ResourceVote(ResourceVote::V0(ResourceVoteV0 { + vote_poll: vote_poll.clone().into(), + resource_vote_choice: resource_vote_choice.clone().into(), + }))) + } + + #[wasm_bindgen(getter = votePoll)] + pub fn vote_poll(&self) -> VotePollWASM { + match self.0.clone() { + Vote::ResourceVote(vote) => vote.vote_poll().clone().into(), + } + } + + #[wasm_bindgen(getter = resourceVoteChoice)] + pub fn resource_vote_choice(&self) -> ResourceVoteChoiceWASM { + match self.0.clone() { + Vote::ResourceVote(vote) => vote.resource_vote_choice().clone().into(), + } + } + + #[wasm_bindgen(setter = votePoll)] + pub fn set_vote_poll(&mut self, vote_poll: &VotePollWASM) { + self.0 = match self.0.clone() { + Vote::ResourceVote(vote) => Vote::ResourceVote(ResourceVote::V0(ResourceVoteV0 { + vote_poll: vote_poll.clone().into(), + resource_vote_choice: vote.resource_vote_choice(), + })), + } + } + + #[wasm_bindgen(setter = resourceVoteChoice)] + pub fn set_resource_vote_choice(&mut self, resource_vote_choice: &ResourceVoteChoiceWASM) { + self.0 = match self.0.clone() { + Vote::ResourceVote(vote) => Vote::ResourceVote(ResourceVote::V0(ResourceVoteV0 { + vote_poll: vote.vote_poll().clone(), + resource_vote_choice: resource_vote_choice.clone().into(), + })), + } + } +} diff --git a/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs b/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs new file mode 100644 index 00000000000..db83dc63272 --- /dev/null +++ b/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs @@ -0,0 +1,172 @@ +use crate::identifier::IdentifierWASM; +use crate::utils::ToSerdeJSONExt; +use dpp::bincode; +use dpp::voting::vote_polls::VotePoll; +use dpp::voting::vote_polls::contested_document_resource_vote_poll::ContestedDocumentResourceVotePoll; +use js_sys::Array; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name = VotePollWASM)] +pub struct VotePollWASM(VotePoll); + +impl From for VotePollWASM { + fn from(poll: VotePoll) -> Self { + VotePollWASM(poll) + } +} + +impl From for VotePoll { + fn from(poll: VotePollWASM) -> Self { + poll.0 + } +} + +#[wasm_bindgen] +impl VotePollWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "VotePollWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "VotePollWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_contract_id: &JsValue, + document_type_name: String, + index_name: String, + js_index_values: JsValue, + ) -> Result { + let contract_id = IdentifierWASM::try_from(js_contract_id)?; + + let index_values = js_index_values + .with_serde_to_platform_value()? + .as_array() + .unwrap() + .clone(); + + Ok(VotePollWASM(VotePoll::ContestedDocumentResourceVotePoll( + ContestedDocumentResourceVotePoll { + contract_id: contract_id.into(), + document_type_name, + index_name, + index_values, + }, + ))) + } + + #[wasm_bindgen(js_name = "toString")] + pub fn to_string(&self) -> String { + self.0.to_string() + } + + #[wasm_bindgen(getter = "contractId")] + pub fn contract_id(&self) -> IdentifierWASM { + match self.0.clone() { + VotePoll::ContestedDocumentResourceVotePoll(poll) => poll.contract_id.into(), + } + } + + #[wasm_bindgen(getter = "documentTypeName")] + pub fn document_type_name(&self) -> String { + match self.0.clone() { + VotePoll::ContestedDocumentResourceVotePoll(poll) => poll.document_type_name.into(), + } + } + + #[wasm_bindgen(getter = "indexName")] + pub fn index_name(&self) -> String { + match self.0.clone() { + VotePoll::ContestedDocumentResourceVotePoll(poll) => poll.index_name.into(), + } + } + + #[wasm_bindgen(getter = "indexValues")] + pub fn index_values(&self) -> Result { + let config = bincode::config::standard() + .with_big_endian() + .with_no_limit(); + + match self.0.clone() { + VotePoll::ContestedDocumentResourceVotePoll(poll) => { + let encoded: Result>, JsValue> = poll + .index_values + .iter() + .map(|value| { + bincode::encode_to_vec(value, config) + .map_err(|err| JsValue::from(err.to_string())) + }) + .collect(); + + let js_array = Array::new(); + + for bytes in encoded? { + js_array.push(&JsValue::from(bytes)); + } + + Ok(js_array) + } + } + } + + #[wasm_bindgen(setter = "contractId")] + pub fn set_contract_id(&mut self, js_contract_id: &JsValue) -> Result<(), JsValue> { + let contract_id = IdentifierWASM::try_from(js_contract_id)?; + + self.0 = match self.0.clone() { + VotePoll::ContestedDocumentResourceVotePoll(mut poll) => { + poll.contract_id = contract_id.into(); + + VotePoll::ContestedDocumentResourceVotePoll(poll) + } + }; + + Ok(()) + } + + #[wasm_bindgen(setter = "documentTypeName")] + pub fn set_document_type_name(&mut self, document_type_name: String) { + self.0 = match self.0.clone() { + VotePoll::ContestedDocumentResourceVotePoll(mut poll) => { + poll.document_type_name = document_type_name; + + VotePoll::ContestedDocumentResourceVotePoll(poll) + } + } + } + + #[wasm_bindgen(setter = "indexName")] + pub fn set_index_name(&mut self, index_name: String) { + self.0 = match self.0.clone() { + VotePoll::ContestedDocumentResourceVotePoll(mut poll) => { + poll.index_name = index_name; + + VotePoll::ContestedDocumentResourceVotePoll(poll) + } + }; + } + + #[wasm_bindgen(setter = "indexValues")] + pub fn set_index_values(&mut self, js_index_values: JsValue) -> Result<(), JsValue> { + let index_values = js_index_values + .with_serde_to_platform_value()? + .as_array() + .unwrap() + .clone(); + + self.0 = match self.0.clone() { + VotePoll::ContestedDocumentResourceVotePoll(mut poll) => { + poll.index_values = index_values; + + VotePoll::ContestedDocumentResourceVotePoll(poll) + } + }; + + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/mock_bls/mod.rs b/packages/wasm-dpp2/src/mock_bls/mod.rs new file mode 100644 index 00000000000..3954a1dbf4e --- /dev/null +++ b/packages/wasm-dpp2/src/mock_bls/mod.rs @@ -0,0 +1,26 @@ +use dpp::{BlsModule, ProtocolError, PublicKeyValidationError}; + +pub struct MockBLS {} + +impl BlsModule for MockBLS { + fn validate_public_key(&self, _pk: &[u8]) -> Result<(), PublicKeyValidationError> { + panic!("BLS signatures are not implemented"); + } + + fn verify_signature( + &self, + _signature: &[u8], + _data: &[u8], + _public_key: &[u8], + ) -> Result { + panic!("BLS signatures are not implemented"); + } + + fn private_key_to_public_key(&self, _private_key: &[u8]) -> Result, ProtocolError> { + panic!("BLS signatures are not implemented"); + } + + fn sign(&self, _data: &[u8], _private_key: &[u8]) -> Result, ProtocolError> { + panic!("BLS signatures are not implemented"); + } +} diff --git a/packages/wasm-dpp2/src/partial_identity/mod.rs b/packages/wasm-dpp2/src/partial_identity/mod.rs new file mode 100644 index 00000000000..216fd49e774 --- /dev/null +++ b/packages/wasm-dpp2/src/partial_identity/mod.rs @@ -0,0 +1,184 @@ +use crate::identifier::IdentifierWASM; +use crate::identity_public_key::IdentityPublicKeyWASM; +use crate::utils::IntoWasm; +use dpp::fee::Credits; +use dpp::identity::{IdentityPublicKey, KeyID, PartialIdentity}; +use dpp::prelude::Revision; +use js_sys::{Array, Object, Reflect}; +use std::collections::{BTreeMap, BTreeSet}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name = "PartialIdentityWASM")] +pub struct PartialIdentityWASM(PartialIdentity); + +impl From for PartialIdentityWASM { + fn from(value: PartialIdentity) -> Self { + Self(value) + } +} + +#[wasm_bindgen] +impl PartialIdentityWASM { + #[wasm_bindgen(constructor)] + pub fn new( + js_id: &JsValue, + js_loaded_public_keys: &JsValue, + balance: Option, + revision: Option, + js_not_found_public_keys: Option, + ) -> Result { + let id = IdentifierWASM::try_from(js_id)?; + let loaded_public_keys = js_value_to_loaded_public_keys(js_loaded_public_keys)?; + + let not_found_public_keys: BTreeSet = + option_array_to_not_found(js_not_found_public_keys)?; + + Ok(PartialIdentityWASM(PartialIdentity { + id: id.into(), + loaded_public_keys, + balance, + revision, + not_found_public_keys, + })) + } + + #[wasm_bindgen(getter = "id")] + pub fn id(&self) -> IdentifierWASM { + self.0.id.into() + } + + #[wasm_bindgen(getter = "loadedPublicKeys")] + pub fn loaded_public_keys(&self) -> Result { + let obj = Object::new(); + + for (k, v) in self.0.loaded_public_keys.clone() { + Reflect::set( + &obj, + &k.to_string().into(), + &IdentityPublicKeyWASM::from(v).into(), + )?; + } + + Ok(obj) + } + + #[wasm_bindgen(getter = "balance")] + pub fn balance(&self) -> Option { + self.0.balance + } + + #[wasm_bindgen(getter = "revision")] + pub fn revision(&self) -> Option { + self.0.revision + } + + #[wasm_bindgen(getter = "notFoundPublicKeys")] + pub fn not_found_public_keys(&self) -> Array { + let arr = Array::new(); + + for v in self.0.not_found_public_keys.clone() { + arr.push(&v.into()); + } + + arr.into() + } + + #[wasm_bindgen(setter = "id")] + pub fn set_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { + let identifier: IdentifierWASM = IdentifierWASM::try_from(js_id)?; + + self.0.id = identifier.into(); + + Ok(()) + } + + #[wasm_bindgen(setter = "loadedPublicKeys")] + pub fn set_loaded_public_keys(&mut self, loaded_public_keys: &JsValue) -> Result<(), JsValue> { + self.0.loaded_public_keys = js_value_to_loaded_public_keys(loaded_public_keys)?; + + Ok(()) + } + + #[wasm_bindgen(setter = "balance")] + pub fn set_balance(&mut self, balance: Option) { + self.0.balance = balance; + } + + #[wasm_bindgen(setter = "revision")] + pub fn set_revision(&mut self, revision: Option) { + self.0.revision = revision; + } + + #[wasm_bindgen(setter = "notFoundPublicKeys")] + pub fn set_not_found_public_keys(&mut self, keys: Option) -> Result<(), JsValue> { + self.0.not_found_public_keys = option_array_to_not_found(keys)?; + + Ok(()) + } +} + +pub fn js_value_to_loaded_public_keys( + js_loaded_public_keys: &JsValue, +) -> Result, JsValue> { + match js_loaded_public_keys.is_object() { + false => Err(JsValue::from("loaded_public_keys must be an object")), + true => { + let mut map = BTreeMap::new(); + + let pub_keys_object = Object::from(js_loaded_public_keys.clone()); + let keys = Object::keys(&pub_keys_object); + + for key in keys.iter() { + if key.as_f64().unwrap() > u32::MAX as f64 { + return Err(JsValue::from_str(&format!( + "Key id '{:?}' exceeds the maximum limit for u32.", + key.as_string() + ))); + } + + let key_id = KeyID::from(key.as_f64().unwrap() as u32); + + let js_key = Reflect::get(&pub_keys_object, &key)?; + + let key = js_key + .to_wasm::("IdentityPublicKeyWASM")? + .clone(); + + map.insert(key_id, IdentityPublicKey::from(key)); + } + + Ok(map) + } + } +} + +pub fn option_array_to_not_found( + js_not_found_public_keys: Option, +) -> Result, JsValue> { + match js_not_found_public_keys { + None => Ok::, JsValue>(BTreeSet::new()), + Some(keys) => { + let keys_iter: Vec = keys + .to_vec() + .iter() + .map(|key| { + if key.as_f64().unwrap() > u32::MAX as f64 { + return Err(JsValue::from_str(&format!( + "Key id '{:?}' exceeds the maximum limit for u32.", + key.as_string() + )))?; + } + + Ok(key.as_f64().unwrap() as KeyID) + }) + .collect::, JsValue>>()?; + + Ok(BTreeSet::from_iter(keys_iter.iter().map(|id| id.clone())) + .iter() + .map(|key| key.clone()) + .collect()) + } + } +} diff --git a/packages/wasm-dpp2/src/private_key/mod.rs b/packages/wasm-dpp2/src/private_key/mod.rs new file mode 100644 index 00000000000..b2eadddf754 --- /dev/null +++ b/packages/wasm-dpp2/src/private_key/mod.rs @@ -0,0 +1,90 @@ +use crate::enums::network::NetworkWASM; +use crate::public_key::PublicKeyWASM; +use dpp::dashcore::PrivateKey; +use dpp::dashcore::hashes::hex::FromHex; +use dpp::dashcore::key::Secp256k1; +use dpp::dashcore::secp256k1::hashes::hex::{Case, DisplayHex}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "PrivateKeyWASM")] +pub struct PrivateKeyWASM(PrivateKey); + +#[wasm_bindgen] +impl PrivateKeyWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "PrivateKeyWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "PrivateKeyWASM".to_string() + } + + #[wasm_bindgen(js_name = "fromWIF")] + pub fn from_wif(wif: &str) -> Result { + let pk = PrivateKey::from_wif(wif).map_err(|err| JsValue::from_str(&*err.to_string())); + + match pk { + Ok(pk) => Ok(PrivateKeyWASM(pk)), + Err(err) => Err(err), + } + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec, js_network: JsValue) -> Result { + let network = NetworkWASM::try_from(js_network)?; + + let pk = PrivateKey::from_slice(bytes.as_slice(), network.into()) + .map_err(|err| JsValue::from_str(&*err.to_string()))?; + + Ok(PrivateKeyWASM(pk)) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex_key: &str, js_network: JsValue) -> Result { + let network = NetworkWASM::try_from(js_network)?; + + let bytes = Vec::from_hex(hex_key).map_err(|err| JsValue::from(err.to_string()))?; + + let pk = PrivateKey::from_slice(bytes.as_slice(), network.into()) + .map_err(|err| JsValue::from_str(&*err.to_string()))?; + + Ok(PrivateKeyWASM(pk)) + } + + #[wasm_bindgen(js_name = "getPublicKey")] + pub fn get_public_key(&self) -> PublicKeyWASM { + let secp = Secp256k1::new(); + + let public_key = self.0.public_key(&secp); + + public_key.into() + } +} + +#[wasm_bindgen] +impl PrivateKeyWASM { + #[wasm_bindgen(js_name = "WIF")] + pub fn get_wif(&self) -> String { + self.0.to_wif() + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn get_bytes(&self) -> Vec { + self.0.to_bytes() + } + + #[wasm_bindgen(js_name = "hex")] + pub fn get_hex(&self) -> String { + self.0.to_bytes().to_hex_string(Case::Upper) + } + + #[wasm_bindgen(js_name = "getPublicKeyHash")] + pub fn get_public_key_hash(&self) -> String { + let secp = Secp256k1::new(); + + self.0.public_key(&secp).pubkey_hash().to_hex() + } +} diff --git a/packages/wasm-dpp2/src/public_key/mod.rs b/packages/wasm-dpp2/src/public_key/mod.rs new file mode 100644 index 00000000000..bb5bdd3ca14 --- /dev/null +++ b/packages/wasm-dpp2/src/public_key/mod.rs @@ -0,0 +1,123 @@ +use dpp::dashcore::key::constants; +use dpp::dashcore::{PublicKey, secp256k1}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "PublicKeyWASM")] +pub struct PublicKeyWASM(PublicKey); + +impl From for PublicKeyWASM { + fn from(pk: PublicKey) -> Self { + Self(pk) + } +} + +impl From for PublicKey { + fn from(pk: PublicKeyWASM) -> Self { + pk.0 + } +} + +#[wasm_bindgen] +impl PublicKeyWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "PublicKeyWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "PublicKeyWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(compressed: bool, public_key_bytes: Vec) -> Result { + let inner = match compressed { + true => { + if public_key_bytes.len() != constants::PUBLIC_KEY_SIZE { + return Err(JsValue::from(String::from(format!( + "compressed public key size must be equal to {}", + constants::PUBLIC_KEY_SIZE + )))); + } + + secp256k1::PublicKey::from_byte_array_compressed(&public_key_bytes.try_into()?) + } + false => { + if public_key_bytes.len() != constants::UNCOMPRESSED_PUBLIC_KEY_SIZE { + return Err(JsValue::from(String::from(format!( + "uncompressed public key size must be equal to {}", + constants::UNCOMPRESSED_PUBLIC_KEY_SIZE + )))); + } + + secp256k1::PublicKey::from_byte_array_uncompressed(&public_key_bytes.try_into()?) + } + } + .map_err(|err| JsValue::from(err.to_string()))?; + + Ok(PublicKeyWASM(PublicKey { compressed, inner })) + } + + #[wasm_bindgen(getter = "compressed")] + pub fn compressed(&self) -> bool { + self.0.compressed + } + + #[wasm_bindgen(getter = "inner")] + pub fn inner(&self) -> Vec { + match self.0.compressed { + true => self.0.inner.serialize().into(), + false => self.0.inner.serialize_uncompressed().into(), + } + } + + #[wasm_bindgen(setter = "compressed")] + pub fn set_compressed(&mut self, compressed: bool) { + self.0.compressed = compressed; + } + + #[wasm_bindgen(setter = "inner")] + pub fn set_inner(&mut self, inner: Vec) -> Result<(), JsValue> { + match inner.len() == constants::PUBLIC_KEY_SIZE { + true => { + self.0.compressed = true; + self.0.inner = secp256k1::PublicKey::from_byte_array_compressed(&inner.try_into()?) + .map_err(|err| JsValue::from(err.to_string()))? + } + false => { + if inner.len() != constants::UNCOMPRESSED_PUBLIC_KEY_SIZE { + return Err(JsValue::from(String::from(format!( + "uncompressed public key size must be equal to {}", + constants::UNCOMPRESSED_PUBLIC_KEY_SIZE + )))); + } + + self.0.compressed = false; + self.0.inner = + secp256k1::PublicKey::from_byte_array_uncompressed(&inner.try_into()?) + .map_err(|err| JsValue::from(err.to_string()))? + } + }; + + Ok(()) + } + + #[wasm_bindgen(js_name = getPublicKeyHash)] + pub fn get_public_key_hash(&self) -> String { + self.0.pubkey_hash().to_hex() + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Vec { + self.0.to_bytes() + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + Ok(PublicKeyWASM( + PublicKey::from_slice(bytes.as_slice()) + .map_err(|err| JsValue::from(err.to_string()))?, + )) + } +} diff --git a/packages/wasm-dpp2/src/state_transition/mod.rs b/packages/wasm-dpp2/src/state_transition/mod.rs new file mode 100644 index 00000000000..ce98734d732 --- /dev/null +++ b/packages/wasm-dpp2/src/state_transition/mod.rs @@ -0,0 +1,605 @@ +use crate::enums::keys::key_type::KeyTypeWASM; +use crate::enums::keys::purpose::PurposeWASM; +use crate::enums::keys::security_level::SecurityLevelWASM; +use crate::identifier::IdentifierWASM; +use crate::identity_public_key::IdentityPublicKeyWASM; +use crate::mock_bls::MockBLS; +use crate::private_key::PrivateKeyWASM; +use crate::utils::WithJsError; +use dpp::dashcore::secp256k1::hashes::hex::Case::Lower; +use dpp::dashcore::secp256k1::hashes::hex::DisplayHex; +use dpp::data_contract::serialized_version::DataContractInSerializationFormat; +use dpp::identity::{KeyID, KeyType}; +use dpp::platform_value::BinaryData; +use dpp::platform_value::string_encoding::{Encoding, decode, encode}; +use dpp::prelude::{IdentityNonce, UserFeeIncrease}; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable}; +use dpp::state_transition::StateTransition::{ + Batch, DataContractCreate, DataContractUpdate, IdentityCreditTransfer, + IdentityCreditWithdrawal, IdentityTopUp, IdentityUpdate, MasternodeVote, +}; +use dpp::state_transition::batch_transition::BatchTransition; +use dpp::state_transition::batch_transition::batched_transition::BatchedTransition; +use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransitionV0Methods; +use dpp::state_transition::batch_transition::batched_transition::token_transition::TokenTransitionV0Methods; +use dpp::state_transition::batch_transition::methods::v0::DocumentsBatchTransitionMethodsV0; +use dpp::state_transition::data_contract_create_transition::DataContractCreateTransition; +use dpp::state_transition::data_contract_create_transition::accessors::DataContractCreateTransitionAccessorsV0; +use dpp::state_transition::data_contract_update_transition::DataContractUpdateTransition; +use dpp::state_transition::data_contract_update_transition::accessors::DataContractUpdateTransitionAccessorsV0; +use dpp::state_transition::identity_credit_transfer_transition::accessors::IdentityCreditTransferTransitionAccessorsV0; +use dpp::state_transition::identity_credit_withdrawal_transition::accessors::IdentityCreditWithdrawalTransitionAccessorsV0; +use dpp::state_transition::identity_topup_transition::accessors::IdentityTopUpTransitionAccessorsV0; +use dpp::state_transition::identity_update_transition::accessors::IdentityUpdateTransitionAccessorsV0; +use dpp::state_transition::masternode_vote_transition::MasternodeVoteTransition; +use dpp::state_transition::masternode_vote_transition::accessors::MasternodeVoteTransitionAccessorsV0; +use dpp::state_transition::{ + StateTransition, StateTransitionIdentitySigned, StateTransitionSigningOptions, +}; +use sha2::{Digest, Sha256}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[derive(Clone)] +#[wasm_bindgen(js_name = "StateTransitionWASM")] +pub struct StateTransitionWASM(StateTransition); + +impl From for StateTransitionWASM { + fn from(transition: StateTransition) -> Self { + StateTransitionWASM(transition) + } +} + +impl From for StateTransition { + fn from(transition: StateTransitionWASM) -> Self { + transition.0 + } +} + +#[wasm_bindgen] +impl StateTransitionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "StateTransitionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "StateTransitionWASM".to_string() + } + + #[wasm_bindgen(js_name = "sign")] + pub fn sign( + &mut self, + private_key: &PrivateKeyWASM, + public_key: &IdentityPublicKeyWASM, + ) -> Result, JsValue> { + self.0 + .sign( + &public_key.clone().into(), + private_key.get_bytes().as_slice(), + &MockBLS {}, + ) + .with_js_error()?; + + self.0.set_signature(self.0.signature().clone()); + self.0 + .set_signature_public_key_id(self.0.signature_public_key_id().unwrap()); + + self.0.serialize_to_bytes().with_js_error() + } + + #[wasm_bindgen(js_name = "signByPrivateKey")] + pub fn sign_by_private_key( + &mut self, + private_key: &PrivateKeyWASM, + key_id: Option, + js_key_type: JsValue, + ) -> Result, JsValue> { + let key_type = match js_key_type.is_undefined() { + true => KeyTypeWASM::ECDSA_SECP256K1, + false => KeyTypeWASM::try_from(js_key_type)?, + }; + + let _sig = self + .0 + .sign_by_private_key( + &private_key.get_bytes().as_slice(), + KeyType::from(key_type), + &MockBLS {}, + ) + .with_js_error(); + + if key_id.is_some() { + self.0.set_signature_public_key_id(key_id.unwrap()); + } + + self.0.serialize_to_bytes().with_js_error() + } + + #[wasm_bindgen(js_name = "verifyPublicKey")] + pub fn verify_public_key( + &self, + public_key: &IdentityPublicKeyWASM, + js_allow_signing_with_any_security_level: Option, + js_allow_signing_with_any_purpose: Option, + ) -> Result<(), JsValue> { + let allow_signing_with_any_security_level = + js_allow_signing_with_any_security_level.unwrap_or(false); + let allow_signing_with_any_purpose = js_allow_signing_with_any_purpose.unwrap_or(false); + + match &self.0 { + DataContractCreate(st) => { + st.verify_public_key_level_and_purpose( + &public_key.clone().into(), + StateTransitionSigningOptions { + allow_signing_with_any_security_level, + allow_signing_with_any_purpose, + }, + ) + .with_js_error()?; + + st.verify_public_key_is_enabled(&public_key.clone().into()) + .with_js_error()?; + } + DataContractUpdate(st) => { + st.verify_public_key_level_and_purpose( + &public_key.clone().into(), + StateTransitionSigningOptions { + allow_signing_with_any_security_level, + allow_signing_with_any_purpose, + }, + ) + .with_js_error()?; + + st.verify_public_key_is_enabled(&public_key.clone().into()) + .with_js_error()?; + } + Batch(st) => { + st.verify_public_key_level_and_purpose( + &public_key.clone().into(), + StateTransitionSigningOptions { + allow_signing_with_any_security_level, + allow_signing_with_any_purpose, + }, + ) + .with_js_error()?; + + st.verify_public_key_is_enabled(&public_key.clone().into()) + .with_js_error()?; + } + IdentityCreditWithdrawal(st) => { + st.verify_public_key_level_and_purpose( + &public_key.clone().into(), + StateTransitionSigningOptions { + allow_signing_with_any_security_level, + allow_signing_with_any_purpose, + }, + ) + .with_js_error()?; + + st.verify_public_key_is_enabled(&public_key.clone().into()) + .with_js_error()?; + } + IdentityUpdate(st) => { + st.verify_public_key_level_and_purpose( + &public_key.clone().into(), + StateTransitionSigningOptions { + allow_signing_with_any_security_level, + allow_signing_with_any_purpose, + }, + ) + .with_js_error()?; + + st.verify_public_key_is_enabled(&public_key.clone().into()) + .with_js_error()?; + } + IdentityCreditTransfer(st) => { + st.verify_public_key_level_and_purpose( + &public_key.clone().into(), + StateTransitionSigningOptions { + allow_signing_with_any_security_level, + allow_signing_with_any_purpose, + }, + ) + .with_js_error()?; + + st.verify_public_key_is_enabled(&public_key.clone().into()) + .with_js_error()?; + } + MasternodeVote(st) => { + st.verify_public_key_level_and_purpose( + &public_key.clone().into(), + StateTransitionSigningOptions { + allow_signing_with_any_security_level, + allow_signing_with_any_purpose, + }, + ) + .with_js_error()?; + + st.verify_public_key_is_enabled(&public_key.clone().into()) + .with_js_error()?; + } + _ => {} + } + + Ok(()) + } + + #[wasm_bindgen(js_name = "bytes")] + pub fn to_bytes(&self) -> Result { + let bytes = self.0.serialize_to_bytes().with_js_error()?; + + Ok(JsValue::from(bytes.clone())) + } + + #[wasm_bindgen(js_name = "hex")] + pub fn to_hex(&self) -> Result { + let bytes = self.0.serialize_to_bytes().with_js_error()?; + + Ok(JsValue::from(encode(bytes.as_slice(), Encoding::Hex))) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> Result { + let bytes = self.0.serialize_to_bytes().with_js_error()?; + + Ok(JsValue::from(encode(bytes.as_slice(), Encoding::Base64))) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> Result { + let st = StateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + + Ok(st.into()) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> Result { + let bytes = decode(&hex, Encoding::Hex).map_err(JsError::from)?; + + let st = StateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + + Ok(st.into()) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> Result { + let bytes = decode(&base64, Encoding::Base64).map_err(JsError::from)?; + + let st = StateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + + Ok(st.into()) + } + + #[wasm_bindgen(js_name = "hash")] + pub fn get_hash(&self, skip_signature: bool) -> Result { + let payload: Vec; + + if skip_signature { + payload = self.0.signable_bytes().with_js_error()?; + } else { + payload = dpp::serialization::PlatformSerializable::serialize_to_bytes(&self.0) + .with_js_error()?; + } + + Ok(Sha256::digest(payload).to_hex_string(Lower)) + } + + #[wasm_bindgen(js_name = "getActionType")] + pub fn get_action_type(&self) -> String { + self.0.name() + } + + #[wasm_bindgen(js_name = "getActionTypeNumber")] + pub fn get_action_type_number(&self) -> u8 { + match self.0 { + DataContractCreate(_) => 0, + Batch(_) => 1, + StateTransition::IdentityCreate(_) => 2, + IdentityTopUp(_) => 3, + DataContractUpdate(_) => 4, + IdentityUpdate(_) => 5, + IdentityCreditWithdrawal(_) => 6, + IdentityCreditTransfer(_) => 7, + MasternodeVote(_) => 8, + } + } + + #[wasm_bindgen(js_name = "getOwnerId")] + pub fn get_owner_id(&self) -> IdentifierWASM { + self.0.owner_id().into() + } + + #[wasm_bindgen(getter = "signature")] + pub fn get_signature(&self) -> Vec { + self.0.signature().to_vec() + } + + #[wasm_bindgen(getter = "signaturePublicKeyId")] + pub fn get_signature_public_key_id(&self) -> Option { + self.0.signature_public_key_id() + } + + #[wasm_bindgen(getter = "userFeeIncrease")] + pub fn get_user_fee_increase(&self) -> UserFeeIncrease { + self.0.user_fee_increase() + } + + #[wasm_bindgen(js_name = "getPurposeRequirement")] + pub fn get_purpose_requirement(&self) -> Option> { + let requirements = self.0.purpose_requirement(); + + match requirements { + None => None, + Some(req) => Some( + req.iter() + .map(|purpose| PurposeWASM::from(purpose.clone())) + .map(String::from) + .collect(), + ), + } + } + + #[wasm_bindgen(js_name = "getKeyLevelRequirement")] + pub fn get_key_level_requirement( + &self, + js_purpose: &JsValue, + ) -> Result>, JsValue> { + let purpose = PurposeWASM::try_from(js_purpose.clone())?; + + let requirements = self.0.security_level_requirement(purpose.into()); + + match requirements { + None => Ok(None), + Some(req) => Ok(Some( + req.iter() + .map(|security_level| SecurityLevelWASM::from(security_level.clone())) + .map(String::from) + .collect(), + )), + } + } + + #[wasm_bindgen(js_name = "getIdentityContractNonce")] + pub fn get_identity_contract_nonce(&self) -> Option { + match self.0.clone() { + DataContractCreate(_) => None, + DataContractUpdate(contract_update) => Some(contract_update.identity_contract_nonce()), + Batch(batch) => match batch { + BatchTransition::V0(v0) => Some(v0.transitions.first()?.identity_contract_nonce()), + BatchTransition::V1(v1) => match v1.transitions.first()? { + BatchedTransition::Document(doc_batch) => { + Some(doc_batch.identity_contract_nonce()) + } + BatchedTransition::Token(token_batch) => { + Some(token_batch.identity_contract_nonce()) + } + }, + }, + StateTransition::IdentityCreate(_) => None, + IdentityTopUp(_) => None, + IdentityCreditWithdrawal(_) => None, + IdentityUpdate(_) => None, + IdentityCreditTransfer(_) => None, + MasternodeVote(_) => None, + } + } + + #[wasm_bindgen(js_name = "getIdentityNonce")] + pub fn get_identity_nonce(&self) -> Option { + match self.0.clone() { + DataContractCreate(contract_create) => Some(contract_create.identity_nonce()), + DataContractUpdate(_) => None, + Batch(_) => None, + StateTransition::IdentityCreate(_) => None, + IdentityTopUp(_) => None, + IdentityCreditWithdrawal(withdrawal) => Some(withdrawal.nonce()), + IdentityUpdate(identity_update) => Some(identity_update.nonce()), + IdentityCreditTransfer(credit_transfer) => Some(credit_transfer.nonce()), + MasternodeVote(mn_vote) => Some(mn_vote.nonce()), + } + } + + #[wasm_bindgen(setter = "signature")] + pub fn set_signature(&mut self, signature: Vec) { + self.0.set_signature(BinaryData::from(signature)) + } + + #[wasm_bindgen(setter = "signaturePublicKeyId")] + pub fn set_signature_public_key_id(&mut self, key_id: KeyID) { + self.0.set_signature_public_key_id(key_id) + } + + #[wasm_bindgen(setter = "userFeeIncrease")] + pub fn set_user_fee_increase(&mut self, user_fee_increase: UserFeeIncrease) { + self.0.set_user_fee_increase(user_fee_increase) + } + + #[wasm_bindgen(js_name = "setOwnerId")] + pub fn set_owner_id(&mut self, js_owner_id: &JsValue) -> Result<(), JsValue> { + let owner_id = IdentifierWASM::try_from(js_owner_id.clone())?; + + match self.0.clone() { + DataContractCreate(mut contract_create) => { + let new_contract = match contract_create.data_contract().clone() { + DataContractInSerializationFormat::V0(mut v0) => { + v0.owner_id = owner_id.into(); + + DataContractInSerializationFormat::V0(v0) + } + DataContractInSerializationFormat::V1(mut v1) => { + v1.owner_id = owner_id.into(); + + DataContractInSerializationFormat::V1(v1) + } + }; + + contract_create.set_data_contract(new_contract); + + self.0 = DataContractCreate(contract_create); + } + DataContractUpdate(mut contract_update) => { + let new_contract = match contract_update.data_contract().clone() { + DataContractInSerializationFormat::V0(mut v0) => { + v0.owner_id = owner_id.into(); + + DataContractInSerializationFormat::V0(v0) + } + DataContractInSerializationFormat::V1(mut v1) => { + v1.owner_id = owner_id.into(); + + DataContractInSerializationFormat::V1(v1) + } + }; + + contract_update.set_data_contract(new_contract); + + self.0 = DataContractUpdate(contract_update); + } + Batch(mut batch) => { + batch = match batch { + BatchTransition::V0(mut v0) => { + v0.owner_id = owner_id.into(); + + BatchTransition::V0(v0) + } + BatchTransition::V1(mut v1) => { + v1.owner_id = owner_id.into(); + + BatchTransition::V1(v1) + } + }; + + self.0 = Batch(batch); + } + StateTransition::IdentityCreate(_) => { + Err(JsValue::from_str( + "Cannot set owner for identity create transition", + ))?; + } + IdentityTopUp(mut top_up) => { + top_up.set_identity_id(owner_id.into()); + + self.0 = IdentityTopUp(top_up); + } + IdentityCreditWithdrawal(mut withdrawal) => { + withdrawal.set_identity_id(owner_id.into()); + + self.0 = IdentityCreditWithdrawal(withdrawal); + } + IdentityUpdate(mut identity_update) => { + identity_update.set_identity_id(owner_id.into()); + + self.0 = IdentityUpdate(identity_update); + } + IdentityCreditTransfer(mut credit_transfer) => { + credit_transfer.set_identity_id(owner_id.into()); + + self.0 = IdentityCreditTransfer(credit_transfer); + } + MasternodeVote(mut mn_vote) => { + mn_vote.set_voter_identity_id(owner_id.into()); + + self.0 = MasternodeVote(mn_vote); + } + }; + + Ok(()) + } + + #[wasm_bindgen(js_name = "setIdentityContractNonce")] + pub fn set_identity_contract_nonce(&mut self, nonce: IdentityNonce) -> Result<(), JsValue> { + self.0 = match self.0.clone() { + DataContractCreate(_) => Err(JsValue::from_str( + "Cannot set identity contract nonce for Data Contract Create", + ))?, + DataContractUpdate(contract_update) => match contract_update { + DataContractUpdateTransition::V0(mut v0) => { + v0.identity_contract_nonce = nonce; + + DataContractUpdateTransition::V0(v0).into() + } + }, + Batch(mut batch) => { + batch.set_identity_contract_nonce(nonce); + + batch.into() + } + StateTransition::IdentityCreate(_) => Err(JsValue::from_str( + "Cannot set identity contract nonce for Identity Create", + ))?, + IdentityTopUp(_) => Err(JsValue::from_str( + "Cannot set identity contract nonce for Identity Top Up", + ))?, + IdentityCreditWithdrawal(_) => Err(JsValue::from_str( + "Cannot set identity contract nonce for Identity Credit Withdrawal", + ))?, + IdentityUpdate(_) => Err(JsValue::from_str( + "Cannot set identity contract nonce for Identity Update", + ))?, + IdentityCreditTransfer(_) => Err(JsValue::from_str( + "Cannot set identity contract nonce for Identity Credit Transfer", + ))?, + MasternodeVote(_) => Err(JsValue::from_str( + "Cannot set identity contract nonce for Masternode Vote", + ))?, + }; + + Ok(()) + } + + #[wasm_bindgen(js_name = "setIdentityNonce")] + pub fn set_identity_nonce(&mut self, nonce: IdentityNonce) -> Result<(), JsValue> { + self.0 = match self.0.clone() { + DataContractCreate(mut contract_create) => { + contract_create = match contract_create { + DataContractCreateTransition::V0(mut v0) => { + v0.identity_nonce = nonce; + v0.into() + } + }; + + contract_create.into() + } + DataContractUpdate(_) => Err(JsValue::from_str( + "Cannot set identity nonce for Data Contract Update", + ))?, + Batch(_) => Err(JsValue::from_str("Cannot set identity nonce for Batch"))?, + StateTransition::IdentityCreate(_) => Err(JsValue::from_str( + "Cannot set identity nonce for Identity Create", + ))?, + IdentityTopUp(_) => Err(JsValue::from_str( + "Cannot set identity nonce for Identity Top Up", + ))?, + IdentityCreditWithdrawal(mut withdrawal) => { + withdrawal.set_nonce(nonce); + + withdrawal.into() + } + IdentityUpdate(mut identity_update) => { + identity_update.set_nonce(nonce); + + identity_update.into() + } + IdentityCreditTransfer(mut credit_transfer) => { + credit_transfer.set_nonce(nonce); + + credit_transfer.into() + } + MasternodeVote(mut mn_vote) => { + mn_vote = match mn_vote { + MasternodeVoteTransition::V0(mut v0) => { + v0.nonce = nonce; + + v0.into() + } + }; + + mn_vote.into() + } + }; + + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/action_taker.rs b/packages/wasm-dpp2/src/token_configuration/action_taker.rs new file mode 100644 index 00000000000..eb29fa27ee5 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/action_taker.rs @@ -0,0 +1,91 @@ +use crate::identifier::IdentifierWASM; +use dpp::group::action_taker::ActionTaker; +use dpp::prelude::Identifier; +use js_sys::Array; +use std::collections::BTreeSet; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "ActionTakerWASM")] +pub struct ActionTakerWASM(ActionTaker); + +impl From for ActionTakerWASM { + fn from(action_taker: ActionTaker) -> Self { + ActionTakerWASM(action_taker) + } +} + +impl From for ActionTaker { + fn from(action_taker: ActionTakerWASM) -> Self { + action_taker.0 + } +} + +#[wasm_bindgen] +impl ActionTakerWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "ActionTakerWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "ActionTakerWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(value: &JsValue) -> Result { + let identifier = IdentifierWASM::try_from(value); + + if identifier.is_err() { + let set_of_identifiers: Vec = Array::from(value) + .to_vec() + .iter() + .map(|js_value: &JsValue| { + Identifier::from(IdentifierWASM::try_from(js_value).expect("err")) + }) + .collect(); + + Ok(ActionTakerWASM(ActionTaker::SpecifiedIdentities( + BTreeSet::from_iter(set_of_identifiers), + ))) + } else { + Ok(ActionTakerWASM(ActionTaker::SingleIdentity( + identifier?.into(), + ))) + } + } + + #[wasm_bindgen(js_name = "getType")] + pub fn get_type(&self) -> String { + match &self.0 { + ActionTaker::SpecifiedIdentities(_) => "SpecifiedIdentities".to_string(), + ActionTaker::SingleIdentity(_) => "SingleIdentity".to_string(), + } + } + + #[wasm_bindgen(getter = "value")] + pub fn get_value(&self) -> JsValue { + match &self.0 { + ActionTaker::SingleIdentity(value) => { + JsValue::from(IdentifierWASM::from(value.clone())) + } + ActionTaker::SpecifiedIdentities(value) => { + let identifiers: Vec = value + .iter() + .map(|identifier: &Identifier| IdentifierWASM::from(identifier.clone())) + .collect(); + + JsValue::from(identifiers) + } + } + } + + #[wasm_bindgen(setter = "value")] + pub fn set_value(&mut self, value: &JsValue) -> Result<(), JsValue> { + self.0 = Self::new(value)?.0; + + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs b/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs new file mode 100644 index 00000000000..91cd97bcf5a --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs @@ -0,0 +1,90 @@ +use crate::identifier::IdentifierWASM; +use dpp::data_contract::change_control_rules::authorized_action_takers::AuthorizedActionTakers; +use dpp::platform_value::string_encoding::Encoding::Base58; +use dpp::platform_value::string_encoding::encode; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "AuthorizedActionTakersWASM")] +pub struct AuthorizedActionTakersWASM(AuthorizedActionTakers); + +impl From for AuthorizedActionTakersWASM { + fn from(action: AuthorizedActionTakers) -> Self { + AuthorizedActionTakersWASM(action) + } +} + +impl From for AuthorizedActionTakers { + fn from(action: AuthorizedActionTakersWASM) -> Self { + action.0 + } +} + +#[wasm_bindgen] +impl AuthorizedActionTakersWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "AuthorizedActionTakersWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "AuthorizedActionTakersWASM".to_string() + } + + #[wasm_bindgen(js_name = "NoOne")] + pub fn no_one() -> Self { + AuthorizedActionTakersWASM(AuthorizedActionTakers::NoOne) + } + + #[wasm_bindgen(js_name = "ContractOwner")] + pub fn contract_owner() -> Self { + AuthorizedActionTakersWASM(AuthorizedActionTakers::ContractOwner) + } + + #[wasm_bindgen(js_name = "Identity")] + pub fn identity(js_identity_id: &JsValue) -> Result { + let identity_id = IdentifierWASM::try_from(js_identity_id)?; + + Ok(AuthorizedActionTakersWASM( + AuthorizedActionTakers::Identity(identity_id.into()), + )) + } + + #[wasm_bindgen(js_name = "MainGroup")] + pub fn main_group() -> Self { + AuthorizedActionTakersWASM(AuthorizedActionTakers::MainGroup) + } + + #[wasm_bindgen(js_name = "Group")] + pub fn group(group_contract_position: u16) -> Self { + AuthorizedActionTakersWASM(AuthorizedActionTakers::Group(group_contract_position)) + } + + #[wasm_bindgen(js_name = "getTakerType")] + pub fn taker_type(&self) -> String { + match self.0 { + AuthorizedActionTakers::NoOne => "NoOne".to_string(), + AuthorizedActionTakers::ContractOwner => "ContractOwner".to_string(), + AuthorizedActionTakers::Identity(identifier) => { + format!("Identity({})", encode(identifier.as_slice(), Base58)) + } + AuthorizedActionTakers::MainGroup => "MainGroup".to_string(), + AuthorizedActionTakers::Group(group) => format!("Group({})", group), + } + } + + #[wasm_bindgen(js_name = "getValue")] + pub fn get_value(&self) -> JsValue { + match self.0 { + AuthorizedActionTakers::NoOne => JsValue::undefined(), + AuthorizedActionTakers::ContractOwner => JsValue::undefined(), + AuthorizedActionTakers::Identity(identifier) => { + JsValue::from(IdentifierWASM::from(identifier)) + } + AuthorizedActionTakers::MainGroup => JsValue::undefined(), + AuthorizedActionTakers::Group(position) => JsValue::from(position), + } + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs b/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs new file mode 100644 index 00000000000..38c6bb09e2f --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs @@ -0,0 +1,200 @@ +use crate::enums::token::action_goal::ActionGoalWASM; +use crate::identifier::IdentifierWASM; +use crate::token_configuration::action_taker::ActionTakerWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration::group::GroupWASM; +use crate::utils::IntoWasm; +use dpp::data_contract::GroupContractPosition; +use dpp::data_contract::change_control_rules::ChangeControlRules; +use dpp::data_contract::change_control_rules::v0::ChangeControlRulesV0; +use dpp::data_contract::group::Group; +use js_sys::{Object, Reflect}; +use std::collections::BTreeMap; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "ChangeControlRulesWASM")] +pub struct ChangeControlRulesWASM(ChangeControlRules); + +impl From for ChangeControlRulesWASM { + fn from(value: ChangeControlRules) -> Self { + Self(value) + } +} + +impl From for ChangeControlRules { + fn from(value: ChangeControlRulesWASM) -> Self { + value.0 + } +} + +#[wasm_bindgen] +impl ChangeControlRulesWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "ChangeControlRulesWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "ChangeControlRulesWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + authorized_to_make_change: &AuthorizedActionTakersWASM, + admin_action_takers: &AuthorizedActionTakersWASM, + changing_authorized_action_takers_to_no_one_allowed: bool, + changing_admin_action_takers_to_no_one_allowed: bool, + self_changing_admin_action_takers_allowed: bool, + ) -> Self { + ChangeControlRulesWASM(ChangeControlRules::V0(ChangeControlRulesV0 { + authorized_to_make_change: authorized_to_make_change.clone().into(), + admin_action_takers: admin_action_takers.clone().into(), + changing_authorized_action_takers_to_no_one_allowed, + changing_admin_action_takers_to_no_one_allowed, + self_changing_admin_action_takers_allowed, + })) + } + + #[wasm_bindgen(getter = "authorizedToMakeChange")] + pub fn get_authorized_to_make_change(&self) -> AuthorizedActionTakersWASM { + self.0 + .authorized_to_make_change_action_takers() + .clone() + .into() + } + + #[wasm_bindgen(getter = "adminActionTakers")] + pub fn get_admin_action_takers(&self) -> AuthorizedActionTakersWASM { + self.0.admin_action_takers().clone().into() + } + + #[wasm_bindgen(getter = "changingAuthorizedActionTakersToNoOneAllowed")] + pub fn get_changing_authorized_action_takers_to_no_one_allowed(&self) -> bool { + match self.0.clone() { + ChangeControlRules::V0(v0) => v0.changing_authorized_action_takers_to_no_one_allowed, + } + } + + #[wasm_bindgen(getter = "changingAdminActionTakersToNoOneAllowed")] + pub fn get_changing_admin_action_takers_to_no_one_allowed(&self) -> bool { + match self.0.clone() { + ChangeControlRules::V0(v0) => v0.changing_admin_action_takers_to_no_one_allowed, + } + } + + #[wasm_bindgen(getter = "selfChangingAdminActionTakersAllowed")] + pub fn get_self_changing_admin_action_takers_allowed(&self) -> bool { + match self.0.clone() { + ChangeControlRules::V0(v0) => v0.self_changing_admin_action_takers_allowed, + } + } + + #[wasm_bindgen(setter = "authorizedToMakeChange")] + pub fn set_authorized_to_make_change( + &mut self, + authorized_to_make_change: &AuthorizedActionTakersWASM, + ) { + self.0 + .set_authorized_to_make_change_action_takers(authorized_to_make_change.clone().into()); + } + + #[wasm_bindgen(setter = "adminActionTakers")] + pub fn set_admin_action_takers(&mut self, admin_action_takers: &AuthorizedActionTakersWASM) { + self.0 + .set_admin_action_takers(admin_action_takers.clone().into()); + } + + #[wasm_bindgen(setter = "changingAuthorizedActionTakersToNoOneAllowed")] + pub fn set_changing_authorized_action_takers_to_no_one_allowed( + &mut self, + changing_authorized_action_takers_to_no_one_allowed: bool, + ) { + let v0 = match self.0.clone() { + ChangeControlRules::V0(mut v0) => { + v0.changing_authorized_action_takers_to_no_one_allowed = + changing_authorized_action_takers_to_no_one_allowed; + v0 + } + }; + + self.0 = ChangeControlRules::V0(v0); + } + + #[wasm_bindgen(setter = "changingAdminActionTakersToNoOneAllowed")] + pub fn set_changing_admin_action_takers_to_no_one_allowed( + &mut self, + changing_admin_action_takers_to_no_one_allowed: bool, + ) { + let v0 = match self.0.clone() { + ChangeControlRules::V0(mut v0) => { + v0.changing_admin_action_takers_to_no_one_allowed = + changing_admin_action_takers_to_no_one_allowed; + v0 + } + }; + + self.0 = ChangeControlRules::V0(v0) + } + + #[wasm_bindgen(setter = "selfChangingAdminActionTakersAllowed")] + pub fn set_self_changing_admin_action_takers_allowed( + &mut self, + self_changing_admin_action_takers_allowed: bool, + ) { + let v0 = match self.0.clone() { + ChangeControlRules::V0(mut v0) => { + v0.self_changing_admin_action_takers_allowed = + self_changing_admin_action_takers_allowed; + v0 + } + }; + + self.0 = ChangeControlRules::V0(v0); + } + + #[wasm_bindgen(js_name = "canChangeAdminActionTakers")] + pub fn can_change_admin_action_takers( + &self, + admin_action_takers: &AuthorizedActionTakersWASM, + js_contract_owner_id: &JsValue, + main_group: Option, + js_groups: &JsValue, + action_taker: &ActionTakerWASM, + js_goal: &JsValue, + ) -> Result { + let contract_owner_id = IdentifierWASM::try_from(js_contract_owner_id)?; + let goal = ActionGoalWASM::try_from(js_goal.clone())?; + + let groups_object = Object::from(js_groups.clone()); + let groups_keys = Object::keys(&groups_object); + + let mut groups: BTreeMap = BTreeMap::new(); + + for key in groups_keys.iter() { + let contract_position = match key.as_string() { + None => Err(JsValue::from("Cannot read timestamp in distribution rules")), + Some(contract_position) => Ok(contract_position + .parse::() + .map_err(JsError::from)?), + }?; + + let group_value = Reflect::get(js_groups, &key)?; + + let group = group_value.to_wasm::("GroupWASM")?.clone(); + + groups.insert(contract_position, group.into()); + } + + Ok(self.0.can_change_admin_action_takers( + &admin_action_takers.clone().into(), + &contract_owner_id.clone().into(), + main_group, + &groups, + &action_taker.clone().into(), + goal.clone().into(), + )) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs b/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs new file mode 100644 index 00000000000..89581679f08 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs @@ -0,0 +1,127 @@ +use crate::token_configuration::localization::TokenConfigurationLocalizationWASM; +use crate::utils::ToSerdeJSONExt; +use dpp::data_contract::associated_token::token_configuration_convention::TokenConfigurationConvention; +use dpp::data_contract::associated_token::token_configuration_convention::accessors::v0::{ + TokenConfigurationConventionV0Getters, TokenConfigurationConventionV0Setters, +}; +use dpp::data_contract::associated_token::token_configuration_convention::v0::TokenConfigurationConventionV0; +use dpp::data_contract::associated_token::token_configuration_localization::TokenConfigurationLocalization; +use dpp::data_contract::associated_token::token_configuration_localization::v0::TokenConfigurationLocalizationV0; +use js_sys::{Object, Reflect}; +use std::collections::BTreeMap; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name = "TokenConfigurationConventionWASM")] +pub struct TokenConfigurationConventionWASM(TokenConfigurationConvention); + +impl From for TokenConfigurationConventionWASM { + fn from(convention: TokenConfigurationConvention) -> Self { + TokenConfigurationConventionWASM(convention) + } +} + +impl From for TokenConfigurationConvention { + fn from(convention: TokenConfigurationConventionWASM) -> Self { + convention.0 + } +} + +#[wasm_bindgen] +impl TokenConfigurationConventionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenConfigurationConventionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenConfigurationConventionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_localizations: &JsValue, + decimals: u8, + ) -> Result { + let localizations: BTreeMap = + js_value_to_localizations(js_localizations)?; + + Ok(TokenConfigurationConventionWASM( + TokenConfigurationConvention::V0(TokenConfigurationConventionV0 { + localizations, + decimals, + }), + )) + } + + #[wasm_bindgen(getter = "decimals")] + pub fn decimals(&self) -> u8 { + self.0.decimals() + } + + #[wasm_bindgen(getter = "localizations")] + pub fn localizations(&self) -> Result { + let object = Object::new(); + + for (key, value) in &self.0.localizations().clone() { + Reflect::set( + &object, + &JsValue::from(key.clone()), + &TokenConfigurationLocalizationWASM::from(value.clone()).into(), + )?; + } + + Ok(object.into()) + } + + #[wasm_bindgen(setter = "decimals")] + pub fn set_decimals(&mut self, decimals: u8) { + self.0.set_decimals(decimals) + } + + #[wasm_bindgen(setter = "localizations")] + pub fn set_localizations(&mut self, js_localizations: &JsValue) -> Result<(), JsValue> { + let localizations: BTreeMap = + js_value_to_localizations(js_localizations)?; + + Ok(self.0.set_localizations(localizations)) + } +} + +fn js_value_to_localizations( + js_localizations: &JsValue, +) -> Result, JsValue> { + let localizations: BTreeMap = js_localizations + .clone() + .with_serde_to_platform_value_map()? + .iter() + .map(|(key, value)| { + ( + key.clone(), + TokenConfigurationLocalization::V0(TokenConfigurationLocalizationV0 { + should_capitalize: value + .get_value("shouldCapitalize") + .unwrap() + .as_bool() + .unwrap(), + singular_form: value + .get_value("singularForm") + .unwrap() + .as_str() + .unwrap() + .to_string(), + plural_form: value + .get_value("pluralForm") + .unwrap() + .as_str() + .unwrap() + .to_string(), + }), + ) + }) + .collect(); + + Ok(localizations) +} diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_function.rs b/packages/wasm-dpp2/src/token_configuration/distribution_function.rs new file mode 100644 index 00000000000..b400fbd9f7f --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/distribution_function.rs @@ -0,0 +1,374 @@ +use crate::token_configuration::distribution_structs::{ + DistributionExponentialWASM, DistributionFixedAmountWASM, DistributionInvertedLogarithmicWASM, + DistributionLinearWASM, DistributionLogarithmicWASM, DistributionPolynomialWASM, + DistributionRandomWASM, DistributionStepDecreasingAmountWASM, +}; +use crate::utils::try_to_u64; +use dpp::balances::credits::TokenAmount; +use dpp::data_contract::associated_token::token_perpetual_distribution::distribution_function::DistributionFunction; +use js_sys::{BigInt, Object, Reflect}; +use std::collections::BTreeMap; +use std::str::FromStr; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "DistributionFunctionWASM")] +pub struct DistributionFunctionWASM(DistributionFunction); + +impl From for DistributionFunction { + fn from(function: DistributionFunctionWASM) -> Self { + function.0 + } +} + +impl From for DistributionFunctionWASM { + fn from(function: DistributionFunction) -> Self { + Self(function) + } +} + +#[wasm_bindgen] +impl DistributionFunctionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DistributionFunctionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DistributionFunctionWASM".to_string() + } + + #[wasm_bindgen(js_name = "FixedAmountDistribution")] + pub fn fixed_amount_distribution(amount: TokenAmount) -> DistributionFunctionWASM { + DistributionFunctionWASM(DistributionFunction::FixedAmount { amount }) + } + + #[wasm_bindgen(js_name = "Random")] + pub fn random(min: TokenAmount, max: TokenAmount) -> Self { + DistributionFunctionWASM(DistributionFunction::Random { min, max }) + } + + #[wasm_bindgen(js_name = "StepDecreasingAmount")] + pub fn step_decreasing_amount( + step_count: u32, + decrease_per_interval_numerator: u16, + decrease_per_interval_denominator: u16, + start_decreasing_offset: Option, + max_interval_count: Option, + distribution_start_amount: TokenAmount, + trailing_distribution_interval_amount: TokenAmount, + min_value: Option, + ) -> Self { + DistributionFunctionWASM(DistributionFunction::StepDecreasingAmount { + step_count, + decrease_per_interval_numerator, + decrease_per_interval_denominator, + start_decreasing_offset, + max_interval_count, + distribution_start_amount, + trailing_distribution_interval_amount, + min_value, + }) + } + + #[wasm_bindgen(js_name = "Stepwise")] + pub fn stepwise(js_steps_with_amount: JsValue) -> Result { + let obj = Object::from(js_steps_with_amount); + + let mut steps_with_amount: BTreeMap = BTreeMap::new(); + + for key in Object::keys(&obj) { + steps_with_amount.insert( + try_to_u64(BigInt::from_str(key.as_string().unwrap().as_str())?.into()) + .map_err(|err| JsValue::from(err.to_string()))?, + try_to_u64(Reflect::get(&obj, &key)?) + .map_err(|err| JsValue::from(err.to_string()))?, + ); + } + + Ok(DistributionFunctionWASM(DistributionFunction::Stepwise( + steps_with_amount, + ))) + } + + #[wasm_bindgen(js_name = "Linear")] + pub fn linear( + a: i64, + d: u64, + start_step: Option, + starting_amount: TokenAmount, + min_value: Option, + max_value: Option, + ) -> DistributionFunctionWASM { + DistributionFunctionWASM(DistributionFunction::Linear { + a, + d, + start_step, + starting_amount, + min_value, + max_value, + }) + } + + #[wasm_bindgen(js_name = "Polynomial")] + pub fn polynomial( + a: i64, + d: u64, + m: i64, + n: u64, + o: i64, + start_moment: Option, + b: TokenAmount, + min_value: Option, + max_value: Option, + ) -> DistributionFunctionWASM { + DistributionFunctionWASM(DistributionFunction::Polynomial { + a, + d, + m, + n, + o, + start_moment, + b, + min_value, + max_value, + }) + } + + #[wasm_bindgen(js_name = "Exponential")] + pub fn exponential( + a: u64, + d: u64, + m: i64, + n: u64, + o: i64, + start_moment: Option, + b: TokenAmount, + min_value: Option, + max_value: Option, + ) -> DistributionFunctionWASM { + DistributionFunctionWASM(DistributionFunction::Exponential { + a, + d, + m, + n, + o, + start_moment, + b, + min_value, + max_value, + }) + } + + #[wasm_bindgen(js_name = "Logarithmic")] + pub fn logarithmic( + a: i64, + d: u64, + m: u64, + n: u64, + o: i64, + start_moment: Option, + b: TokenAmount, + min_value: Option, + max_value: Option, + ) -> DistributionFunctionWASM { + DistributionFunctionWASM(DistributionFunction::Logarithmic { + a, + d, + m, + n, + o, + start_moment, + b, + min_value, + max_value, + }) + } + + #[wasm_bindgen(js_name = "InvertedLogarithmic")] + pub fn inverted_logarithmic( + a: i64, + d: u64, + m: u64, + n: u64, + o: i64, + start_moment: Option, + b: TokenAmount, + min_value: Option, + max_value: Option, + ) -> DistributionFunctionWASM { + DistributionFunctionWASM(DistributionFunction::InvertedLogarithmic { + a, + d, + m, + n, + o, + start_moment, + b, + min_value, + max_value, + }) + } + + #[wasm_bindgen(js_name = "getFunctionName")] + pub fn get_function_name(&self) -> String { + match self.0 { + DistributionFunction::FixedAmount { .. } => String::from("FixedAmount"), + DistributionFunction::Random { .. } => String::from("Random"), + DistributionFunction::StepDecreasingAmount { .. } => { + String::from("StepDecreasingAmount") + } + DistributionFunction::Stepwise(_) => String::from("Stepwise"), + DistributionFunction::Linear { .. } => String::from("Linear"), + DistributionFunction::Polynomial { .. } => String::from("Polynomial"), + DistributionFunction::Exponential { .. } => String::from("Exponential"), + DistributionFunction::Logarithmic { .. } => String::from("Logarithmic"), + DistributionFunction::InvertedLogarithmic { .. } => String::from("InvertedLogarithmic"), + } + } + + #[wasm_bindgen(js_name = "getFunctionValue")] + pub fn get_function_values(&self) -> Result { + match self.0.clone() { + DistributionFunction::FixedAmount { amount } => { + Ok(JsValue::from(DistributionFixedAmountWASM { amount })) + } + DistributionFunction::Random { min, max } => { + Ok(JsValue::from(DistributionRandomWASM { min, max })) + } + DistributionFunction::StepDecreasingAmount { + step_count, + decrease_per_interval_numerator, + decrease_per_interval_denominator, + start_decreasing_offset, + max_interval_count, + distribution_start_amount, + trailing_distribution_interval_amount, + min_value, + } => Ok(JsValue::from(DistributionStepDecreasingAmountWASM { + step_count, + decrease_per_interval_numerator, + decrease_per_interval_denominator, + start_decreasing_offset, + max_interval_count, + distribution_start_amount, + trailing_distribution_interval_amount, + min_value, + })), + DistributionFunction::Stepwise(map) => { + let object = Object::new(); + + for (key, value) in map { + Reflect::set( + &object, + &key.to_string().into(), + &BigInt::from(value).into(), + )?; + } + + Ok(object.into()) + } + DistributionFunction::Linear { + a, + d, + start_step, + starting_amount, + min_value, + max_value, + } => Ok(JsValue::from(DistributionLinearWASM { + a, + d, + start_step, + starting_amount, + min_value, + max_value, + })), + DistributionFunction::Polynomial { + a, + d, + m, + n, + o, + start_moment, + b, + min_value, + max_value, + } => Ok(JsValue::from(DistributionPolynomialWASM { + a, + d, + m, + n, + o, + start_moment, + b, + min_value, + max_value, + })), + DistributionFunction::Exponential { + a, + d, + m, + n, + o, + start_moment, + b, + min_value, + max_value, + } => Ok(JsValue::from(DistributionExponentialWASM { + a, + d, + m, + n, + o, + start_moment, + b, + min_value, + max_value, + })), + DistributionFunction::Logarithmic { + a, + d, + m, + n, + o, + start_moment, + b, + min_value, + max_value, + } => Ok(JsValue::from(DistributionLogarithmicWASM { + a, + d, + m, + n, + o, + start_moment, + b, + min_value, + max_value, + })), + DistributionFunction::InvertedLogarithmic { + a, + d, + m, + n, + o, + start_moment, + b, + min_value, + max_value, + } => Ok(JsValue::from(DistributionInvertedLogarithmicWASM { + a, + d, + m, + n, + o, + start_moment, + b, + min_value, + max_value, + })), + } + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs b/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs new file mode 100644 index 00000000000..c561a9e1729 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs @@ -0,0 +1,77 @@ +use crate::identifier::IdentifierWASM; +use dpp::data_contract::associated_token::token_perpetual_distribution::distribution_recipient::TokenDistributionRecipient; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "TokenDistributionRecipientWASM")] +pub struct TokenDistributionRecipientWASM(TokenDistributionRecipient); + +impl From for TokenDistributionRecipientWASM { + fn from(distribution_recipient: TokenDistributionRecipient) -> Self { + TokenDistributionRecipientWASM(distribution_recipient) + } +} + +impl From for TokenDistributionRecipient { + fn from(distribution_recipient: TokenDistributionRecipientWASM) -> Self { + distribution_recipient.0 + } +} + +#[wasm_bindgen] +impl TokenDistributionRecipientWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenDistributionRecipientWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenDistributionRecipientWASM".to_string() + } + + #[wasm_bindgen(js_name = "ContractOwner")] + pub fn contract_owner() -> TokenDistributionRecipientWASM { + TokenDistributionRecipientWASM(TokenDistributionRecipient::ContractOwner) + } + + #[wasm_bindgen(js_name = "Identity")] + pub fn identity(js_identity_id: &JsValue) -> Result { + let identity_id = IdentifierWASM::try_from(js_identity_id)?; + + Ok(TokenDistributionRecipientWASM( + TokenDistributionRecipient::Identity(identity_id.into()), + )) + } + + #[wasm_bindgen(js_name = "EvonodesByParticipation")] + pub fn evonodes_by_participation() -> TokenDistributionRecipientWASM { + TokenDistributionRecipientWASM(TokenDistributionRecipient::EvonodesByParticipation) + } + + #[wasm_bindgen(js_name = "getType")] + pub fn get_type(&self) -> String { + match self.0 { + TokenDistributionRecipient::EvonodesByParticipation => { + String::from("EvonodesByParticipation") + } + TokenDistributionRecipient::ContractOwner => String::from("ContractOwner"), + TokenDistributionRecipient::Identity(identity) => String::from(format!( + "Identity({})", + IdentifierWASM::from(identity).get_base58() + )), + } + } + + #[wasm_bindgen(js_name = "getValue")] + pub fn get_value(&self) -> JsValue { + match self.0 { + TokenDistributionRecipient::EvonodesByParticipation => JsValue::undefined(), + TokenDistributionRecipient::ContractOwner => JsValue::undefined(), + TokenDistributionRecipient::Identity(identifier) => { + IdentifierWASM::from(identifier).into() + } + } + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs b/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs new file mode 100644 index 00000000000..123400dbbe6 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs @@ -0,0 +1,238 @@ +use crate::identifier::IdentifierWASM; +use crate::token_configuration::change_control_rules::ChangeControlRulesWASM; +use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWASM; +use crate::token_configuration::pre_programmed_distribution::TokenPreProgrammedDistributionWASM; +use crate::utils::IntoWasm; +use dpp::data_contract::associated_token::token_distribution_rules::TokenDistributionRules; +use dpp::data_contract::associated_token::token_distribution_rules::accessors::v0::{ + TokenDistributionRulesV0Getters, TokenDistributionRulesV0Setters, +}; +use dpp::data_contract::associated_token::token_distribution_rules::v0::TokenDistributionRulesV0; +use dpp::data_contract::associated_token::token_perpetual_distribution::TokenPerpetualDistribution; +use dpp::data_contract::associated_token::token_pre_programmed_distribution::TokenPreProgrammedDistribution; +use dpp::prelude::Identifier; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "TokenDistributionRulesWASM")] +pub struct TokenDistributionRulesWASM(TokenDistributionRules); + +impl From for TokenDistributionRules { + fn from(rules: TokenDistributionRulesWASM) -> Self { + rules.0 + } +} + +impl From for TokenDistributionRulesWASM { + fn from(rules: TokenDistributionRules) -> Self { + Self(rules) + } +} + +#[wasm_bindgen] +impl TokenDistributionRulesWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenDistributionRulesWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenDistributionRulesWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_perpetual_distribution: &JsValue, + perpetual_distribution_rules: &ChangeControlRulesWASM, + js_pre_programmed_distribution: &JsValue, + js_new_tokens_destination_identity: &JsValue, + new_tokens_destination_identity_rules: &ChangeControlRulesWASM, + minting_allow_choosing_destination: bool, + minting_allow_choosing_destination_rules: &ChangeControlRulesWASM, + change_direct_purchase_pricing_rules: &ChangeControlRulesWASM, + ) -> Result { + let perpetual_distribution = match js_perpetual_distribution.is_undefined() { + true => None, + false => Some(TokenPerpetualDistribution::from( + js_perpetual_distribution + .to_wasm::("TokenPerpetualDistributionWASM")? + .clone(), + )), + }; + + let pre_programmed_distribution = match js_pre_programmed_distribution.is_undefined() { + true => None, + false => Some(TokenPreProgrammedDistribution::from( + js_pre_programmed_distribution + .to_wasm::( + "TokenPreProgrammedDistributionWASM", + )? + .clone(), + )), + }; + + let new_tokens_destination_identity = + match js_new_tokens_destination_identity.is_undefined() { + true => None, + false => Some(Identifier::from(IdentifierWASM::try_from( + js_new_tokens_destination_identity, + )?)), + }; + + Ok(TokenDistributionRulesWASM(TokenDistributionRules::V0( + TokenDistributionRulesV0 { + perpetual_distribution, + perpetual_distribution_rules: perpetual_distribution_rules.clone().into(), + pre_programmed_distribution, + new_tokens_destination_identity, + new_tokens_destination_identity_rules: new_tokens_destination_identity_rules + .clone() + .into(), + minting_allow_choosing_destination, + minting_allow_choosing_destination_rules: minting_allow_choosing_destination_rules + .clone() + .into(), + change_direct_purchase_pricing_rules: change_direct_purchase_pricing_rules + .clone() + .into(), + }, + ))) + } + + #[wasm_bindgen(getter = "perpetualDistribution")] + pub fn get_perpetual_distribution(&self) -> Option { + match self.0.perpetual_distribution() { + Some(perp) => Some(perp.clone().into()), + None => None, + } + } + + #[wasm_bindgen(getter = "perpetualDistributionRules")] + pub fn get_perpetual_distribution_rules(&self) -> ChangeControlRulesWASM { + self.0.perpetual_distribution_rules().clone().into() + } + + #[wasm_bindgen(getter = "preProgrammedDistribution")] + pub fn get_pre_programmed_distribution(&self) -> Option { + match self.0.pre_programmed_distribution() { + Some(pre) => Some(pre.clone().into()), + None => None, + } + } + + #[wasm_bindgen(getter = "newTokenDestinationIdentity")] + pub fn get_new_tokens_destination_identity(&self) -> Option { + match self.0.new_tokens_destination_identity().clone() { + Some(id) => Some(id.clone().into()), + None => None, + } + } + + #[wasm_bindgen(getter = "newTokenDestinationIdentityRules")] + pub fn get_new_tokens_destination_identity_rules(&self) -> ChangeControlRulesWASM { + self.0 + .new_tokens_destination_identity_rules() + .clone() + .into() + } + + #[wasm_bindgen(getter = "mintingAllowChoosingDestination")] + pub fn get_minting_allow_choosing_destination(&self) -> bool { + self.0.minting_allow_choosing_destination() + } + + #[wasm_bindgen(getter = "mintingAllowChoosingDestinationRules")] + pub fn get_minting_allow_choosing_destination_rules(&self) -> ChangeControlRulesWASM { + self.0 + .minting_allow_choosing_destination_rules() + .clone() + .into() + } + + #[wasm_bindgen(getter = "changeDirectPurchasePricingRules")] + pub fn get_change_direct_purchase_pricing_rules(&self) -> ChangeControlRulesWASM { + self.0.change_direct_purchase_pricing_rules().clone().into() + } + + #[wasm_bindgen(setter = "perpetualDistribution")] + pub fn set_perpetual_distribution( + &mut self, + js_perpetual_distribution: &JsValue, + ) -> Result<(), JsValue> { + let perpetual_distribution = match js_perpetual_distribution.is_undefined() { + true => None, + false => Some(TokenPerpetualDistribution::from( + js_perpetual_distribution + .to_wasm::("TokenPerpetualDistributionWASM")? + .clone(), + )), + }; + + Ok(self.0.set_perpetual_distribution(perpetual_distribution)) + } + + #[wasm_bindgen(setter = "perpetualDistributionRules")] + pub fn set_perpetual_distribution_rules(&mut self, rules: &ChangeControlRulesWASM) { + self.0 + .set_perpetual_distribution_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "preProgrammedDistribution")] + pub fn set_pre_programmed_distribution( + &mut self, + js_distribution: &JsValue, + ) -> Result<(), JsValue> { + let distribution = match js_distribution.is_undefined() { + true => None, + false => Some(TokenPreProgrammedDistribution::from( + js_distribution + .to_wasm::( + "TokenPreProgrammedDistributionWASM", + )? + .clone(), + )), + }; + + Ok(self.0.set_pre_programmed_distribution(distribution)) + } + + #[wasm_bindgen(setter = "newTokenDestinationIdentity")] + pub fn set_new_tokens_destination_identity( + &mut self, + js_identifier: &JsValue, + ) -> Result<(), JsValue> { + let identifier = match js_identifier.is_undefined() { + true => None, + false => Some(Identifier::from( + IdentifierWASM::try_from(js_identifier)?.clone(), + )), + }; + + Ok(self.0.set_new_tokens_destination_identity(identifier)) + } + + #[wasm_bindgen(setter = "newTokenDestinationIdentityRules")] + pub fn set_new_tokens_destination_identity_rules(&mut self, rules: &ChangeControlRulesWASM) { + self.0 + .set_new_tokens_destination_identity_rules(rules.clone().into()); + } + + #[wasm_bindgen(setter = "mintingAllowChoosingDestination")] + pub fn set_minting_allow_choosing_destination(&mut self, flag: bool) { + self.0.set_minting_allow_choosing_destination(flag); + } + + #[wasm_bindgen(setter = "mintingAllowChoosingDestinationRules")] + pub fn set_minting_allow_choosing_destination_rules(&mut self, rules: &ChangeControlRulesWASM) { + self.0 + .set_minting_allow_choosing_destination_rules(rules.clone().into()); + } + + #[wasm_bindgen(setter = "changeDirectPurchasePricingRules")] + pub fn set_change_direct_purchase_pricing_rules(&mut self, rules: &ChangeControlRulesWASM) { + self.0 + .set_change_direct_purchase_pricing_rules(rules.clone().into()); + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_structs.rs b/packages/wasm-dpp2/src/token_configuration/distribution_structs.rs new file mode 100644 index 00000000000..0e9d9f28c2b --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/distribution_structs.rs @@ -0,0 +1,111 @@ +use dpp::balances::credits::TokenAmount; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "DistributionFixedAmountWASM")] +pub struct DistributionFixedAmountWASM { + pub amount: TokenAmount, +} + +#[wasm_bindgen(js_name = "DistributionRandomWASM")] +pub struct DistributionRandomWASM { + pub min: TokenAmount, + pub max: TokenAmount, +} + +#[wasm_bindgen(js_name = "DistributionStepDecreasingAmountWASM")] +pub struct DistributionStepDecreasingAmountWASM { + #[wasm_bindgen(js_name = "stepCount")] + pub step_count: u32, + #[wasm_bindgen(js_name = "decreasePerIntervalNumerator")] + pub decrease_per_interval_numerator: u16, + #[wasm_bindgen(js_name = "decreasePerIntervalDenominator")] + pub decrease_per_interval_denominator: u16, + #[wasm_bindgen(js_name = "startDecreasingOffset")] + pub start_decreasing_offset: Option, + #[wasm_bindgen(js_name = "maxIntervalCount")] + pub max_interval_count: Option, + #[wasm_bindgen(js_name = "distributionStartAmount")] + pub distribution_start_amount: TokenAmount, + #[wasm_bindgen(js_name = "trailingDistributionIntervalAmount")] + pub trailing_distribution_interval_amount: TokenAmount, + #[wasm_bindgen(js_name = "minValue")] + pub min_value: Option, +} + +#[wasm_bindgen(js_name = "DistributionLinearWASM")] +pub struct DistributionLinearWASM { + pub a: i64, + pub d: u64, + #[wasm_bindgen(js_name = "startStep")] + pub start_step: Option, + #[wasm_bindgen(js_name = "startingAmount")] + pub starting_amount: TokenAmount, + #[wasm_bindgen(js_name = "minValue")] + pub min_value: Option, + #[wasm_bindgen(js_name = "maxValue")] + pub max_value: Option, +} + +#[wasm_bindgen(js_name = "DistributionPolynomialWASM")] +pub struct DistributionPolynomialWASM { + pub a: i64, + pub d: u64, + pub m: i64, + pub n: u64, + pub o: i64, + #[wasm_bindgen(js_name = "startMoment")] + pub start_moment: Option, + pub b: TokenAmount, + #[wasm_bindgen(js_name = "minValue")] + pub min_value: Option, + #[wasm_bindgen(js_name = "maxValue")] + pub max_value: Option, +} + +#[wasm_bindgen(js_name = "DistributionExponentialWASM")] +pub struct DistributionExponentialWASM { + pub a: u64, + pub d: u64, + pub m: i64, + pub n: u64, + pub o: i64, + #[wasm_bindgen(js_name = "startMoment")] + pub start_moment: Option, + pub b: TokenAmount, + #[wasm_bindgen(js_name = "minValue")] + pub min_value: Option, + #[wasm_bindgen(js_name = "maxValue")] + pub max_value: Option, +} + +#[wasm_bindgen(js_name = "DistributionLogarithmicWASM")] +pub struct DistributionLogarithmicWASM { + pub a: i64, + pub d: u64, + pub m: u64, + pub n: u64, + pub o: i64, + #[wasm_bindgen(js_name = "startMoment")] + pub start_moment: Option, + pub b: TokenAmount, + #[wasm_bindgen(js_name = "minValue")] + pub min_value: Option, + #[wasm_bindgen(js_name = "maxValue")] + pub max_value: Option, +} + +#[wasm_bindgen(js_name = "DistributionInvertedLogarithmicWASM")] +pub struct DistributionInvertedLogarithmicWASM { + pub a: i64, + pub d: u64, + pub m: u64, + pub n: u64, + pub o: i64, + #[wasm_bindgen(js_name = "startMoment")] + pub start_moment: Option, + pub b: TokenAmount, + #[wasm_bindgen(js_name = "minValue")] + pub min_value: Option, + #[wasm_bindgen(js_name = "maxValue")] + pub max_value: Option, +} diff --git a/packages/wasm-dpp2/src/token_configuration/group.rs b/packages/wasm-dpp2/src/token_configuration/group.rs new file mode 100644 index 00000000000..7f1b4854dac --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/group.rs @@ -0,0 +1,130 @@ +use crate::identifier::IdentifierWASM; +use dpp::data_contract::group::accessors::v0::{GroupV0Getters, GroupV0Setters}; +use dpp::data_contract::group::v0::GroupV0; +use dpp::data_contract::group::{Group, GroupMemberPower, GroupRequiredPower}; +use dpp::platform_value::string_encoding::Encoding; +use dpp::prelude::Identifier; +use js_sys::Object; +use js_sys::Reflect; +use std::collections::BTreeMap; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, PartialEq, Debug)] +#[wasm_bindgen(js_name = "GroupWASM")] +pub struct GroupWASM(Group); + +impl From for GroupWASM { + fn from(group: Group) -> Self { + GroupWASM(group) + } +} + +impl From for Group { + fn from(group: GroupWASM) -> Self { + group.0 + } +} + +pub fn js_members_to_map( + js_members: &JsValue, +) -> Result, JsValue> { + let members_object = Object::from(js_members.clone()); + let members_keys = Object::keys(&members_object); + + let mut members = BTreeMap::new(); + + for key in members_keys.iter() { + let key_str = key + .as_string() + .ok_or_else(|| JsValue::from_str("cannot convert key to string"))?; + + let id_wasm = IdentifierWASM::try_from(key.clone()) + .map_err(|_| JsValue::from_str(&format!("Invalid identifier: {}", key_str)))?; + + let val = Reflect::get(js_members, &key) + .map_err(|_| JsValue::from_str(&format!("Invalid value at key '{}'", key_str)))?; + + let power: GroupMemberPower = serde_wasm_bindgen::from_value(val)?; + + members.insert(Identifier::from(id_wasm), power); + } + + Ok(members) +} + +#[wasm_bindgen] +impl GroupWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "GroupWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "GroupWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_members: &JsValue, + required_power: GroupRequiredPower, + ) -> Result { + let members = js_members_to_map(js_members)?; + + Ok(GroupWASM(Group::V0(GroupV0 { + members, + required_power, + }))) + } + + #[wasm_bindgen(getter = "members")] + pub fn get_members(&self) -> Result { + let members = self.0.members(); + + let js_members = Object::new(); + + for (k, v) in members { + Reflect::set( + &js_members, + &JsValue::from(k.to_string(Encoding::Base58)), + &JsValue::from(v.clone()), + )?; + } + + Ok(js_members.into()) + } + + #[wasm_bindgen(getter = "requiredPower")] + pub fn get_required_power(&self) -> GroupRequiredPower { + self.0.required_power() + } + + #[wasm_bindgen(setter = "members")] + pub fn set_members(&mut self, js_members: &JsValue) -> Result<(), JsValue> { + let members = js_members_to_map(js_members)?; + + self.0.set_members(members); + + Ok(()) + } + + #[wasm_bindgen(setter = "requiredPower")] + pub fn set_required_power(&mut self, required_power: GroupRequiredPower) { + self.0.set_required_power(required_power); + } + + #[wasm_bindgen(js_name = "setMemberRequiredPower")] + pub fn set_member_required_power( + &mut self, + js_member: &JsValue, + member_required_power: GroupRequiredPower, + ) -> Result<(), JsValue> { + let member = IdentifierWASM::try_from(js_member.clone())?; + + self.0 + .set_member_power(member.into(), member_required_power); + + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs b/packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs new file mode 100644 index 00000000000..671785a9522 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs @@ -0,0 +1,116 @@ +use dpp::data_contract::associated_token::token_keeps_history_rules::TokenKeepsHistoryRules; +use dpp::data_contract::associated_token::token_keeps_history_rules::accessors::v0::{ + TokenKeepsHistoryRulesV0Getters, TokenKeepsHistoryRulesV0Setters, +}; +use dpp::data_contract::associated_token::token_keeps_history_rules::v0::TokenKeepsHistoryRulesV0; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name = "TokenKeepsHistoryRulesWASM")] +pub struct TokenKeepsHistoryRulesWASM(TokenKeepsHistoryRules); + +impl From for TokenKeepsHistoryRules { + fn from(rules: TokenKeepsHistoryRulesWASM) -> Self { + rules.0 + } +} + +impl From for TokenKeepsHistoryRulesWASM { + fn from(rules: TokenKeepsHistoryRules) -> Self { + Self(rules) + } +} + +#[wasm_bindgen] +impl TokenKeepsHistoryRulesWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenKeepsHistoryRulesWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenKeepsHistoryRulesWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + keeps_transfer_history: bool, + keeps_freezing_history: bool, + keeps_minting_history: bool, + keeps_burning_history: bool, + keeps_direct_pricing_history: bool, + keeps_direct_purchase_history: bool, + ) -> TokenKeepsHistoryRulesWASM { + TokenKeepsHistoryRulesWASM(TokenKeepsHistoryRules::V0(TokenKeepsHistoryRulesV0 { + keeps_transfer_history, + keeps_freezing_history, + keeps_minting_history, + keeps_burning_history, + keeps_direct_pricing_history, + keeps_direct_purchase_history, + })) + } + + #[wasm_bindgen(getter = "keepsTransferHistory")] + pub fn get_keeps_transfer_history(&self) -> bool { + self.0.keeps_transfer_history() + } + + #[wasm_bindgen(getter = "keepsFreezingHistory")] + pub fn get_keeps_freezing_history(&self) -> bool { + self.0.keeps_freezing_history() + } + + #[wasm_bindgen(getter = "keepsMintingHistory")] + pub fn get_keeps_minting_history(&self) -> bool { + self.0.keeps_minting_history() + } + + #[wasm_bindgen(getter = "keepsBurningHistory")] + pub fn get_keeps_burning_history(&self) -> bool { + self.0.keeps_burning_history() + } + + #[wasm_bindgen(getter = "keepsDirectPricingHistory")] + pub fn get_keeps_direct_pricing_history(&self) -> bool { + self.0.keeps_direct_pricing_history() + } + + #[wasm_bindgen(getter = "keepsDirectPurchaseHistory")] + pub fn get_keeps_direct_purchase_history(&self) -> bool { + self.0.keeps_direct_purchase_history() + } + + #[wasm_bindgen(setter = "keepsTransferHistory")] + pub fn set_keeps_transfer_history(&mut self, keeps_transfer_history: bool) { + self.0.set_keeps_transfer_history(keeps_transfer_history); + } + + #[wasm_bindgen(setter = "keepsFreezingHistory")] + pub fn set_keeps_freezing_history(&mut self, keeps_freezing_history: bool) { + self.0.set_keeps_freezing_history(keeps_freezing_history); + } + + #[wasm_bindgen(setter = "keepsMintingHistory")] + pub fn set_keeps_minting_history(&mut self, keeps_minting_history: bool) { + self.0.set_keeps_minting_history(keeps_minting_history); + } + + #[wasm_bindgen(setter = "keepsBurningHistory")] + pub fn set_keeps_burning_history(&mut self, keeps_burning_history: bool) { + self.0.set_keeps_burning_history(keeps_burning_history); + } + + #[wasm_bindgen(setter = "keepsDirectPricingHistory")] + pub fn set_keeps_direct_pricing_history(&mut self, keeps_direct_pricing_history: bool) { + self.0 + .set_keeps_direct_pricing_history(keeps_direct_pricing_history); + } + + #[wasm_bindgen(setter = "keepsDirectPurchaseHistory")] + pub fn set_keeps_direct_purchase_history(&mut self, keeps_direct_purchase_history: bool) { + self.0 + .set_keeps_direct_purchase_history(keeps_direct_purchase_history); + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/localization.rs b/packages/wasm-dpp2/src/token_configuration/localization.rs new file mode 100644 index 00000000000..d45fb9bfee4 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/localization.rs @@ -0,0 +1,105 @@ +use dpp::data_contract::associated_token::token_configuration_localization::TokenConfigurationLocalization; +use dpp::data_contract::associated_token::token_configuration_localization::accessors::v0::{ + TokenConfigurationLocalizationV0Getters, TokenConfigurationLocalizationV0Setters, +}; +use dpp::data_contract::associated_token::token_configuration_localization::v0::TokenConfigurationLocalizationV0; +use js_sys::{Object, Reflect}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = TokenConfigurationLocalizationWASM)] +pub struct TokenConfigurationLocalizationWASM(TokenConfigurationLocalization); + +impl From for TokenConfigurationLocalizationWASM { + fn from(configuration: TokenConfigurationLocalization) -> TokenConfigurationLocalizationWASM { + TokenConfigurationLocalizationWASM(configuration) + } +} + +impl From for TokenConfigurationLocalization { + fn from(configuration: TokenConfigurationLocalizationWASM) -> TokenConfigurationLocalization { + configuration.0 + } +} + +#[wasm_bindgen] +impl TokenConfigurationLocalizationWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenConfigurationLocalizationWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenConfigurationLocalizationWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + should_capitalize: bool, + singular_form: String, + plural_form: String, + ) -> TokenConfigurationLocalizationWASM { + TokenConfigurationLocalizationWASM(TokenConfigurationLocalization::V0( + TokenConfigurationLocalizationV0 { + should_capitalize, + singular_form, + plural_form, + }, + )) + } + + #[wasm_bindgen(getter = "shouldCapitalize")] + pub fn get_should_capitalize(&self) -> bool { + self.0.should_capitalize() + } + + #[wasm_bindgen(getter = "pluralForm")] + pub fn get_plural_form(&self) -> String { + self.0.plural_form().to_string() + } + + #[wasm_bindgen(getter = "singularForm")] + pub fn get_singular_form(&self) -> String { + self.0.singular_form().to_string() + } + + #[wasm_bindgen(setter = "shouldCapitalize")] + pub fn set_should_capitalize(&mut self, capitalize: bool) { + self.0.set_should_capitalize(capitalize); + } + + #[wasm_bindgen(setter = "pluralForm")] + pub fn set_plural_form(&mut self, plural_form: String) { + self.0.set_plural_form(plural_form); + } + + #[wasm_bindgen(setter = "singularForm")] + pub fn set_singular_form(&mut self, singular_form: String) { + self.0.set_singular_form(singular_form); + } + + #[wasm_bindgen(js_name = "toJSON")] + pub fn to_json(&self) -> Result { + let object = Object::new(); + + Reflect::set( + &object, + &JsValue::from("shouldCapitalize"), + &JsValue::from(self.0.should_capitalize()), + )?; + Reflect::set( + &object, + &JsValue::from("pluralForm"), + &JsValue::from(self.0.plural_form()), + )?; + Reflect::set( + &object, + &JsValue::from("singularForm"), + &JsValue::from(self.0.singular_form()), + )?; + + Ok(object.into()) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs b/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs new file mode 100644 index 00000000000..bbbe69337b7 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs @@ -0,0 +1,74 @@ +use crate::token_configuration::change_control_rules::ChangeControlRulesWASM; +use crate::token_configuration::trade_mode::TokenTradeModeWASM; +use dpp::data_contract::associated_token::token_marketplace_rules::TokenMarketplaceRules; +use dpp::data_contract::associated_token::token_marketplace_rules::accessors::v0::{ + TokenMarketplaceRulesV0Getters, TokenMarketplaceRulesV0Setters, +}; +use dpp::data_contract::associated_token::token_marketplace_rules::v0::TokenMarketplaceRulesV0; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, PartialEq, Debug)] +#[wasm_bindgen(js_name = "TokenMarketplaceRulesWASM")] +pub struct TokenMarketplaceRulesWASM(TokenMarketplaceRules); + +impl From for TokenMarketplaceRulesWASM { + fn from(rules: TokenMarketplaceRules) -> Self { + TokenMarketplaceRulesWASM(rules) + } +} + +impl From for TokenMarketplaceRules { + fn from(rules: TokenMarketplaceRulesWASM) -> Self { + rules.0 + } +} + +#[wasm_bindgen] +impl TokenMarketplaceRulesWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenMarketplaceRulesWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenMarketplaceRulesWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + trade_mode: &TokenTradeModeWASM, + trade_mode_change_rules: &ChangeControlRulesWASM, + ) -> TokenMarketplaceRulesWASM { + TokenMarketplaceRulesWASM(TokenMarketplaceRules::V0({ + TokenMarketplaceRulesV0 { + trade_mode: trade_mode.clone().into(), + trade_mode_change_rules: trade_mode_change_rules.clone().into(), + } + })) + } + + #[wasm_bindgen(getter = "tradeMode")] + pub fn trade_mode(&self) -> TokenTradeModeWASM { + self.0.trade_mode().clone().into() + } + + #[wasm_bindgen(getter = "tradeModeChangeRules")] + pub fn trade_mode_change_rules(&self) -> ChangeControlRulesWASM { + self.0.trade_mode_change_rules().clone().into() + } + + #[wasm_bindgen(setter = "tradeMode")] + pub fn set_trade_mode(&mut self, trade_mode: &TokenTradeModeWASM) { + self.0.set_trade_mode(trade_mode.clone().into()); + } + + #[wasm_bindgen(setter = "tradeModeChangeRules")] + pub fn set_trade_mode_change_rules( + &mut self, + trade_mode_change_rules: &ChangeControlRulesWASM, + ) { + self.0 + .set_trade_mode_change_rules(trade_mode_change_rules.clone().into()); + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/mod.rs b/packages/wasm-dpp2/src/token_configuration/mod.rs new file mode 100644 index 00000000000..07950edca1c --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/mod.rs @@ -0,0 +1,332 @@ +use crate::identifier::IdentifierWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration::change_control_rules::ChangeControlRulesWASM; +use crate::token_configuration::configuration_convention::TokenConfigurationConventionWASM; +use crate::token_configuration::distribution_rules::TokenDistributionRulesWASM; +use crate::token_configuration::keeps_history_rules::TokenKeepsHistoryRulesWASM; +use crate::token_configuration::marketplace_rules::TokenMarketplaceRulesWASM; +use dpp::balances::credits::TokenAmount; +use dpp::data_contract::associated_token::token_configuration::accessors::v0::{ + TokenConfigurationV0Getters, TokenConfigurationV0Setters, +}; +use dpp::data_contract::associated_token::token_configuration::v0::TokenConfigurationV0; +use dpp::data_contract::{GroupContractPosition, TokenConfiguration, TokenContractPosition}; +use dpp::tokens::calculate_token_id; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +pub mod action_taker; +pub mod authorized_action_takers; +pub mod change_control_rules; +pub mod configuration_convention; +pub mod distribution_function; +pub mod distribution_recipient; +pub mod distribution_rules; +pub mod distribution_structs; +pub mod group; +pub mod keeps_history_rules; +pub mod localization; +pub mod marketplace_rules; +pub mod perpetual_distribution; +pub mod pre_programmed_distribution; +pub mod reward_distribution_type; +pub mod trade_mode; + +#[derive(Clone, PartialEq, Debug)] +#[wasm_bindgen(js_name = "TokenConfigurationWASM")] +pub struct TokenConfigurationWASM(TokenConfiguration); + +impl From for TokenConfigurationWASM { + fn from(configuration: TokenConfiguration) -> Self { + Self(configuration) + } +} + +impl From for TokenConfiguration { + fn from(configuration: TokenConfigurationWASM) -> Self { + configuration.0 + } +} + +#[wasm_bindgen] +impl TokenConfigurationWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenConfigurationWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenConfigurationWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + conventions: &TokenConfigurationConventionWASM, + conventions_change_rules: &ChangeControlRulesWASM, + base_supply: TokenAmount, + max_supply: Option, + keeps_history: &TokenKeepsHistoryRulesWASM, + start_as_paused: bool, + allow_transfer_to_frozen_balance: bool, + max_supply_change_rules: &ChangeControlRulesWASM, + distribution_rules: &TokenDistributionRulesWASM, + marketplace_rules: &TokenMarketplaceRulesWASM, + manual_minting_rules: &ChangeControlRulesWASM, + manual_burning_rules: &ChangeControlRulesWASM, + freeze_rules: &ChangeControlRulesWASM, + unfreeze_rules: &ChangeControlRulesWASM, + destroy_frozen_funds_rules: &ChangeControlRulesWASM, + emergency_action_rules: &ChangeControlRulesWASM, + main_control_group: Option, + main_control_group_can_be_modified: &AuthorizedActionTakersWASM, + description: Option, + ) -> TokenConfigurationWASM { + TokenConfigurationWASM(TokenConfiguration::V0(TokenConfigurationV0 { + conventions: conventions.clone().into(), + conventions_change_rules: conventions_change_rules.clone().into(), + base_supply, + max_supply, + keeps_history: keeps_history.clone().into(), + start_as_paused, + allow_transfer_to_frozen_balance, + max_supply_change_rules: max_supply_change_rules.clone().into(), + distribution_rules: distribution_rules.clone().into(), + marketplace_rules: marketplace_rules.clone().into(), + manual_minting_rules: manual_minting_rules.clone().into(), + manual_burning_rules: manual_burning_rules.clone().into(), + freeze_rules: freeze_rules.clone().into(), + unfreeze_rules: unfreeze_rules.clone().into(), + destroy_frozen_funds_rules: destroy_frozen_funds_rules.clone().into(), + emergency_action_rules: emergency_action_rules.clone().into(), + main_control_group, + main_control_group_can_be_modified: main_control_group_can_be_modified.clone().into(), + description, + })) + } + + #[wasm_bindgen(getter = "conventions")] + pub fn get_conventions(&self) -> TokenConfigurationConventionWASM { + self.0.conventions().clone().into() + } + + #[wasm_bindgen(getter = "conventionsChangeRules")] + pub fn get_conventions_change_rules(&self) -> ChangeControlRulesWASM { + self.0.conventions_change_rules().clone().into() + } + + #[wasm_bindgen(getter = "baseSupply")] + pub fn get_base_supply(&self) -> TokenAmount { + self.0.base_supply() + } + + #[wasm_bindgen(getter = "keepsHistory")] + pub fn get_keeps_history(&self) -> TokenKeepsHistoryRulesWASM { + self.0.keeps_history().clone().into() + } + + #[wasm_bindgen(getter = "startAsPaused")] + pub fn get_start_as_paused(&self) -> bool { + self.0.start_as_paused() + } + + #[wasm_bindgen(getter = "isAllowedTransferToFrozenBalance")] + pub fn get_is_allowed_transfer_to_frozen_balance(&self) -> bool { + self.0.is_allowed_transfer_to_frozen_balance() + } + + #[wasm_bindgen(getter = "maxSupply")] + pub fn get_max_supply(&self) -> Option { + self.0.max_supply() + } + + #[wasm_bindgen(getter = "maxSupplyChangeRules")] + pub fn get_max_supply_change_rules(&self) -> ChangeControlRulesWASM { + self.0.max_supply_change_rules().clone().into() + } + + #[wasm_bindgen(getter = "distributionRules")] + pub fn get_distribution_rules(&self) -> TokenDistributionRulesWASM { + self.0.distribution_rules().clone().into() + } + + #[wasm_bindgen(getter = "marketplaceRules")] + pub fn get_marketplace_rules(&self) -> TokenMarketplaceRulesWASM { + match self.0.clone() { + TokenConfiguration::V0(v0) => v0.marketplace_rules.clone().into(), + } + } + + #[wasm_bindgen(getter = "manualMintingRules")] + pub fn get_manual_minting_rules(&self) -> ChangeControlRulesWASM { + self.0.manual_minting_rules().clone().into() + } + + #[wasm_bindgen(getter = "manualBurningRules")] + pub fn get_manual_burning_rules(&self) -> ChangeControlRulesWASM { + self.0.manual_burning_rules().clone().into() + } + + #[wasm_bindgen(getter = "freezeRules")] + pub fn get_freeze_rules(&self) -> ChangeControlRulesWASM { + self.0.freeze_rules().clone().into() + } + + #[wasm_bindgen(getter = "unfreezeRules")] + pub fn get_unfreeze_rules(&self) -> ChangeControlRulesWASM { + self.0.unfreeze_rules().clone().into() + } + + #[wasm_bindgen(getter = "destroyFrozenFundsRules")] + pub fn get_destroy_frozen_funds_rules(&self) -> ChangeControlRulesWASM { + self.0.destroy_frozen_funds_rules().clone().into() + } + + #[wasm_bindgen(getter = "emergencyActionRules")] + pub fn get_emergency_action_rules(&self) -> ChangeControlRulesWASM { + self.0.emergency_action_rules().clone().into() + } + + #[wasm_bindgen(getter = "mainControlGroup")] + pub fn get_main_control_group(&self) -> Option { + self.0.main_control_group() + } + + #[wasm_bindgen(getter = "mainControlGroupCanBeModified")] + pub fn get_main_control_group_can_be_modified(&self) -> AuthorizedActionTakersWASM { + self.0.main_control_group_can_be_modified().clone().into() + } + + #[wasm_bindgen(getter = "description")] + pub fn get_description(&self) -> Option { + self.0.description().clone() + } + + #[wasm_bindgen(setter = "conventions")] + pub fn set_conventions(&mut self, conventions: &TokenConfigurationConventionWASM) { + self.0.set_conventions(conventions.clone().into()) + } + + #[wasm_bindgen(setter = "conventionsChangeRules")] + pub fn set_conventions_change_rules(&mut self, rules: &ChangeControlRulesWASM) { + self.0.set_conventions_change_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "baseSupply")] + pub fn set_base_supply(&mut self, base_supply: TokenAmount) { + self.0.set_base_supply(base_supply) + } + + #[wasm_bindgen(setter = "keepsHistory")] + pub fn set_keeps_history(&mut self, keeps_history: &TokenKeepsHistoryRulesWASM) { + self.0 = match self.0.clone() { + TokenConfiguration::V0(mut v0) => { + v0.keeps_history = keeps_history.clone().into(); + + TokenConfiguration::V0(v0) + } + }; + } + + #[wasm_bindgen(setter = "startAsPaused")] + pub fn set_start_as_paused(&mut self, start_as_paused: bool) { + self.0.set_start_as_paused(start_as_paused) + } + + #[wasm_bindgen(setter = "isAllowedTransferToFrozenBalance")] + pub fn set_is_allowed_transfer_to_frozen_balance( + &mut self, + is_allowed_transfer_to_frozen_balance: bool, + ) { + self.0 + .allow_transfer_to_frozen_balance(is_allowed_transfer_to_frozen_balance); + } + + #[wasm_bindgen(setter = "maxSupply")] + pub fn set_max_supply(&mut self, max_supply: Option) { + self.0.set_max_supply(max_supply) + } + + #[wasm_bindgen(setter = "maxSupplyChangeRules")] + pub fn set_max_supply_change_rules(&mut self, rules: &ChangeControlRulesWASM) { + self.0.set_max_supply_change_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "distributionRules")] + pub fn set_distribution_rules(&mut self, rules: &TokenDistributionRulesWASM) { + self.0.set_distribution_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "marketplaceRules")] + pub fn set_marketplace_rules(&mut self, marketplace_rules: &TokenMarketplaceRulesWASM) { + self.0 = match self.0.clone() { + TokenConfiguration::V0(mut v0) => { + v0.marketplace_rules = marketplace_rules.clone().into(); + + TokenConfiguration::V0(v0) + } + } + } + + #[wasm_bindgen(setter = "manualMintingRules")] + pub fn set_manual_minting_rules(&mut self, rules: &ChangeControlRulesWASM) { + self.0.set_manual_minting_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "manualBurningRules")] + pub fn set_manual_burning_rules(&mut self, rules: &ChangeControlRulesWASM) { + self.0.set_manual_burning_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "freezeRules")] + pub fn set_freeze_rules(&mut self, rules: &ChangeControlRulesWASM) { + self.0.set_freeze_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "unfreezeRules")] + pub fn set_unfreeze_rules(&mut self, rules: &ChangeControlRulesWASM) { + self.0.set_unfreeze_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "destroyFrozenFundsRules")] + pub fn set_destroy_frozen_funds_rules(&mut self, rules: &ChangeControlRulesWASM) { + self.0.set_destroy_frozen_funds_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "emergencyActionRules")] + pub fn set_emergency_action_rules(&mut self, rules: &ChangeControlRulesWASM) { + self.0.set_emergency_action_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "mainControlGroup")] + pub fn set_main_control_group(&mut self, group: Option) { + self.0.set_main_control_group(group) + } + + #[wasm_bindgen(setter = "mainControlGroupCanBeModified")] + pub fn set_main_control_group_can_be_modified( + &mut self, + authorized_action_taker: &AuthorizedActionTakersWASM, + ) { + self.0 + .set_main_control_group_can_be_modified(authorized_action_taker.clone().into()) + } + + #[wasm_bindgen(setter = "description")] + pub fn set_description(&mut self, description: Option) { + self.0.set_description(description) + } + + #[wasm_bindgen(js_name = "calculateTokenId")] + pub fn calculate_token_id( + js_contract_id: &JsValue, + token_pos: TokenContractPosition, + ) -> Result { + let contract_id = IdentifierWASM::try_from(js_contract_id)?; + + Ok(IdentifierWASM::from(calculate_token_id( + &contract_id.to_slice(), + token_pos, + ))) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs b/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs new file mode 100644 index 00000000000..63f4f646987 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs @@ -0,0 +1,70 @@ +use crate::token_configuration::distribution_recipient::TokenDistributionRecipientWASM; +use crate::token_configuration::reward_distribution_type::RewardDistributionTypeWASM; +use dpp::data_contract::associated_token::token_perpetual_distribution::TokenPerpetualDistribution; +use dpp::data_contract::associated_token::token_perpetual_distribution::methods::v0::TokenPerpetualDistributionV0Accessors; +use dpp::data_contract::associated_token::token_perpetual_distribution::v0::TokenPerpetualDistributionV0; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, PartialEq, Debug)] +#[wasm_bindgen(js_name = "TokenPerpetualDistributionWASM")] +pub struct TokenPerpetualDistributionWASM(TokenPerpetualDistribution); + +impl From for TokenPerpetualDistribution { + fn from(value: TokenPerpetualDistributionWASM) -> Self { + value.0 + } +} + +impl From for TokenPerpetualDistributionWASM { + fn from(value: TokenPerpetualDistribution) -> Self { + TokenPerpetualDistributionWASM(value) + } +} + +#[wasm_bindgen] +impl TokenPerpetualDistributionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenPerpetualDistributionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenPerpetualDistributionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + distribution_type: &RewardDistributionTypeWASM, + recipient: &TokenDistributionRecipientWASM, + ) -> Self { + TokenPerpetualDistributionWASM(TokenPerpetualDistribution::V0( + TokenPerpetualDistributionV0 { + distribution_type: distribution_type.clone().into(), + distribution_recipient: recipient.clone().into(), + }, + )) + } + + #[wasm_bindgen(getter = distributionType)] + pub fn distribution_type(&self) -> RewardDistributionTypeWASM { + self.0.distribution_type().clone().into() + } + + #[wasm_bindgen(getter = distributionRecipient)] + pub fn recipient(&self) -> TokenDistributionRecipientWASM { + self.0.distribution_recipient().clone().into() + } + + #[wasm_bindgen(setter = distributionType)] + pub fn set_distribution_type(&mut self, distribution_type: &RewardDistributionTypeWASM) { + self.0 + .set_distribution_type(distribution_type.clone().into()); + } + + #[wasm_bindgen(setter = distributionRecipient)] + pub fn set_recipient(&mut self, distribution_recipient: &TokenDistributionRecipientWASM) { + self.0 + .set_distribution_recipient(distribution_recipient.clone().into()); + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs b/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs new file mode 100644 index 00000000000..6eb3024065a --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs @@ -0,0 +1,122 @@ +use crate::identifier::IdentifierWASM; +use dpp::balances::credits::TokenAmount; +use dpp::data_contract::associated_token::token_pre_programmed_distribution::TokenPreProgrammedDistribution; +use dpp::data_contract::associated_token::token_pre_programmed_distribution::accessors::v0::TokenPreProgrammedDistributionV0Methods; +use dpp::data_contract::associated_token::token_pre_programmed_distribution::v0::TokenPreProgrammedDistributionV0; +use dpp::prelude::{Identifier, TimestampMillis}; +use js_sys::{BigInt, Object, Reflect}; +use std::collections::BTreeMap; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsError, JsValue}; + +#[derive(Clone, PartialEq, Debug)] +#[wasm_bindgen(js_name = "TokenPreProgrammedDistributionWASM")] +pub struct TokenPreProgrammedDistributionWASM(TokenPreProgrammedDistribution); + +impl From for TokenPreProgrammedDistribution { + fn from(value: TokenPreProgrammedDistributionWASM) -> Self { + value.0 + } +} + +impl From for TokenPreProgrammedDistributionWASM { + fn from(value: TokenPreProgrammedDistribution) -> Self { + TokenPreProgrammedDistributionWASM(value) + } +} + +pub fn js_distributions_to_distributions( + js_distributions: &JsValue, +) -> Result>, JsValue> { + let distributions_object = Object::from(js_distributions.clone()); + let distributions_keys = Object::keys(&distributions_object); + + let mut distributions = BTreeMap::new(); + + for key in distributions_keys.iter() { + let timestamp = match key.as_string() { + None => Err(JsValue::from("Cannot read timestamp in distribution rules")), + Some(timestamp) => Ok(timestamp + .parse::() + .map_err(JsError::from)?), + }?; + + let identifiers_object = Object::from(Reflect::get(&distributions_object, &key)?.clone()); + let identifiers_keys = Object::keys(&identifiers_object); + + let mut ids = BTreeMap::new(); + + for id_key in identifiers_keys.iter() { + let identifier = Identifier::from(IdentifierWASM::try_from(id_key.clone())?); + + let token_amount = BigInt::new(&Reflect::get(&identifiers_object, &id_key.clone())?)? + .to_string(10) + .map_err(|err| JsValue::from(format!("bigint to string: {}", err.to_string())))? + .as_string() + .ok_or_else(|| JsValue::from_str("Failed to convert BigInt to string"))? + .parse::() + .map_err(JsError::from)?; + + ids.insert(identifier, token_amount); + } + + distributions.insert(timestamp, ids); + } + + Ok(distributions) +} + +#[wasm_bindgen] +impl TokenPreProgrammedDistributionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenPreProgrammedDistributionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenPreProgrammedDistributionWASM".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(js_distributions: &JsValue) -> Result { + let distributions = js_distributions_to_distributions(js_distributions)?; + + Ok(TokenPreProgrammedDistributionWASM( + TokenPreProgrammedDistribution::V0(TokenPreProgrammedDistributionV0 { distributions }), + )) + } + + #[wasm_bindgen(getter = "distributions")] + pub fn get_distributions(&self) -> Result { + let obj = Object::new(); + + for (key, value) in self.0.distributions() { + let identifiers_obj = Object::new(); + // &BigInt::from(key.clone()).into() + + for (identifiers_key, identifiers_value) in value { + Reflect::set( + &identifiers_obj, + &IdentifierWASM::from(identifiers_key.clone()) + .get_base58() + .into(), + &BigInt::from(identifiers_value.clone()).into(), + )?; + } + + Reflect::set(&obj, &key.to_string().into(), &identifiers_obj.into())?; + } + + Ok(obj.into()) + } + + #[wasm_bindgen(setter = "distributions")] + pub fn set_distributions(&mut self, js_distributions: &JsValue) -> Result<(), JsValue> { + let distributions = js_distributions_to_distributions(js_distributions)?; + + self.0.set_distributions(distributions); + + Ok(()) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs b/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs new file mode 100644 index 00000000000..41f0c64838e --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs @@ -0,0 +1,182 @@ +use dpp::data_contract::associated_token::token_perpetual_distribution::reward_distribution_type::RewardDistributionType; +use dpp::data_contract::associated_token::token_perpetual_distribution::reward_distribution_type::RewardDistributionType::{BlockBasedDistribution, EpochBasedDistribution, TimeBasedDistribution}; +use dpp::prelude::{BlockHeightInterval, EpochInterval, TimestampMillisInterval}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::token_configuration::distribution_function::DistributionFunctionWASM; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "RewardDistributionTypeWASM")] +pub struct RewardDistributionTypeWASM(RewardDistributionType); + +impl From for RewardDistributionTypeWASM { + fn from(reward_distribution_type: RewardDistributionType) -> Self { + Self(reward_distribution_type) + } +} + +impl From for RewardDistributionType { + fn from(reward_distribution_type: RewardDistributionTypeWASM) -> Self { + reward_distribution_type.0 + } +} + +#[wasm_bindgen] +impl RewardDistributionTypeWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "RewardDistributionTypeWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "RewardDistributionTypeWASM".to_string() + } + + #[wasm_bindgen(js_name = "BlockBasedDistribution")] + pub fn block_based_distribution( + interval: BlockHeightInterval, + function: &DistributionFunctionWASM, + ) -> Self { + RewardDistributionTypeWASM(BlockBasedDistribution { + interval, + function: function.clone().into(), + }) + } + + #[wasm_bindgen(js_name = "TimeBasedDistribution")] + pub fn time_based_distribution( + interval: TimestampMillisInterval, + function: &DistributionFunctionWASM, + ) -> Self { + RewardDistributionTypeWASM(TimeBasedDistribution { + interval, + function: function.clone().into(), + }) + } + + #[wasm_bindgen(js_name = "EpochBasedDistribution")] + pub fn epoch_based_distribution( + interval: EpochInterval, + function: &DistributionFunctionWASM, + ) -> Self { + RewardDistributionTypeWASM(EpochBasedDistribution { + interval, + function: function.clone().into(), + }) + } + + #[wasm_bindgen(js_name = "getDistribution")] + pub fn get_distribution(&self) -> JsValue { + match self.0.clone() { + RewardDistributionType::BlockBasedDistribution { interval, function } => { + JsValue::from(BlockBasedDistributionWASM { + interval, + function: function.clone().into(), + }) + } + RewardDistributionType::TimeBasedDistribution { interval, function } => { + JsValue::from(TimeBasedDistributionWASM { + interval, + function: function.clone().into(), + }) + } + RewardDistributionType::EpochBasedDistribution { interval, function } => { + JsValue::from(EpochBasedDistributionWASM { + interval, + function: function.clone().into(), + }) + } + } + } +} + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "BlockBasedDistributionWASM")] +pub struct BlockBasedDistributionWASM { + pub interval: BlockHeightInterval, + function: DistributionFunctionWASM, +} + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "TimeBasedDistributionWASM")] +pub struct TimeBasedDistributionWASM { + pub interval: TimestampMillisInterval, + function: DistributionFunctionWASM, +} + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "EpochBasedDistributionWASM")] +pub struct EpochBasedDistributionWASM { + pub interval: EpochInterval, + function: DistributionFunctionWASM, +} + +#[wasm_bindgen] +impl BlockBasedDistributionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "BlockBasedDistributionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "BlockBasedDistributionWASM".to_string() + } + + #[wasm_bindgen(getter = "function")] + pub fn get_function(&self) -> DistributionFunctionWASM { + self.function.clone() + } + + #[wasm_bindgen(setter = "function")] + pub fn set_function(&mut self, function: &DistributionFunctionWASM) { + self.function = function.clone() + } +} + +#[wasm_bindgen] +impl TimeBasedDistributionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TimeBasedDistributionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TimeBasedDistributionWASM".to_string() + } + + #[wasm_bindgen(getter = "function")] + pub fn get_function(&self) -> DistributionFunctionWASM { + self.function.clone() + } + + #[wasm_bindgen(setter = "function")] + pub fn set_function(&mut self, function: &DistributionFunctionWASM) { + self.function = function.clone() + } +} + +#[wasm_bindgen] +impl EpochBasedDistributionWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "EpochBasedDistributionWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "EpochBasedDistributionWASM".to_string() + } + + #[wasm_bindgen(getter = "function")] + pub fn get_function(&self) -> DistributionFunctionWASM { + self.function.clone() + } + + #[wasm_bindgen(setter = "function")] + pub fn set_function(&mut self, function: &DistributionFunctionWASM) { + self.function = function.clone() + } +} diff --git a/packages/wasm-dpp2/src/token_configuration/trade_mode.rs b/packages/wasm-dpp2/src/token_configuration/trade_mode.rs new file mode 100644 index 00000000000..43eb7008cc8 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration/trade_mode.rs @@ -0,0 +1,43 @@ +use dpp::data_contract::associated_token::token_marketplace_rules::v0::TokenTradeMode; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "TokenTradeModeWASM")] +pub struct TokenTradeModeWASM(TokenTradeMode); + +impl From for TokenTradeModeWASM { + fn from(trade_mode: TokenTradeMode) -> Self { + TokenTradeModeWASM(trade_mode) + } +} + +impl From for TokenTradeMode { + fn from(trade_mode: TokenTradeModeWASM) -> Self { + trade_mode.0 + } +} + +#[wasm_bindgen] +impl TokenTradeModeWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenTradeModeWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenTradeModeWASM".to_string() + } + + #[wasm_bindgen(js_name = "NotTradeable")] + pub fn not_tradeable() -> TokenTradeModeWASM { + TokenTradeModeWASM(TokenTradeMode::NotTradeable) + } + + #[wasm_bindgen(js_name = "getValue")] + pub fn get_value(&self) -> String { + match self.0 { + TokenTradeMode::NotTradeable => String::from("NotTradeable"), + } + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs new file mode 100644 index 00000000000..da25fc093ff --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs @@ -0,0 +1,29 @@ +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration::configuration_convention::TokenConfigurationConventionWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "conventionsItem")] + pub fn conventions_item(convention: &TokenConfigurationConventionWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::Conventions( + convention.clone().into(), + )) + } + + #[wasm_bindgen(js_name = "ConventionsAdminGroupItem")] + pub fn conventions_admin_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::ConventionsAdminGroup( + action_taker.clone().into(), + )) + } + + #[wasm_bindgen(js_name = "ConventionsControlGroupItem")] + pub fn conventions_control_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::ConventionsControlGroup( + action_taker.clone().into(), + )) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs new file mode 100644 index 00000000000..1963aff53fa --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs @@ -0,0 +1,23 @@ +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "DestroyFrozenFundsItem")] + pub fn destroy_frozen_funds_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::DestroyFrozenFunds( + action_taker.clone().into(), + )) + } + + #[wasm_bindgen(js_name = "DestroyFrozenFundsAdminGroupItem")] + pub fn destroy_frozen_funds_admin_group_item( + action_taker: &AuthorizedActionTakersWASM, + ) -> Self { + TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItem::DestroyFrozenFundsAdminGroup(action_taker.clone().into()), + ) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs new file mode 100644 index 00000000000..7b9196991ca --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs @@ -0,0 +1,25 @@ +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "EmergencyActionItem")] + pub fn emergency_action_item( + action_taker: &AuthorizedActionTakersWASM, + ) -> TokenConfigurationChangeItemWASM { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::EmergencyAction( + action_taker.clone().into(), + )) + } + + #[wasm_bindgen(js_name = "EmergencyActionAdminGroupItem")] + pub fn emergency_action_admin_group_item( + action_taker: &AuthorizedActionTakersWASM, + ) -> TokenConfigurationChangeItemWASM { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::EmergencyActionAdminGroup( + action_taker.clone().into(), + )) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs new file mode 100644 index 00000000000..1dc566b774e --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs @@ -0,0 +1,25 @@ +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "FreezeItem")] + pub fn freeze_item( + action_taker: &AuthorizedActionTakersWASM, + ) -> TokenConfigurationChangeItemWASM { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::Freeze( + action_taker.clone().into(), + )) + } + + #[wasm_bindgen(js_name = "FreezeAdminGroupItem")] + pub fn freeze_admin_group_item( + action_taker: &AuthorizedActionTakersWASM, + ) -> TokenConfigurationChangeItemWASM { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::FreezeAdminGroup( + action_taker.clone().into(), + )) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs new file mode 100644 index 00000000000..270ef068395 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs @@ -0,0 +1,14 @@ +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::data_contract::GroupContractPosition; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "MainControlGroupItem")] + pub fn main_control_group_item(group_contract_position: Option) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::MainControlGroup( + group_contract_position, + )) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs new file mode 100644 index 00000000000..29d53e15080 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs @@ -0,0 +1,21 @@ +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "ManualBurningItem")] + pub fn manual_burning_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::ManualBurning( + action_taker.clone().into(), + )) + } + + #[wasm_bindgen(js_name = "ManualBurningAdminGroupItem")] + pub fn manual_burning_admin_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::ManualBurningAdminGroup( + action_taker.clone().into(), + )) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs new file mode 100644 index 00000000000..fdf53be24f6 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs @@ -0,0 +1,21 @@ +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "ManualMintingItem")] + pub fn manual_minting_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::ManualMinting( + action_taker.clone().into(), + )) + } + + #[wasm_bindgen(js_name = "ManualMintingAdminGroupItem")] + pub fn manual_minting_admin_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::ManualMintingAdminGroup( + action_taker.clone().into(), + )) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs new file mode 100644 index 00000000000..73dfbf90e00 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs @@ -0,0 +1,33 @@ +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration::trade_mode::TokenTradeModeWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "MarketplaceTradeModeItem")] + pub fn market_trade_mode_item(trade_mode: &TokenTradeModeWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::MarketplaceTradeMode( + trade_mode.clone().into(), + )) + } + + #[wasm_bindgen(js_name = "MarketplaceTradeModeControlGroupItem")] + pub fn market_trade_mode_control_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItem::MarketplaceTradeModeControlGroup( + action_taker.clone().into(), + ), + ) + } + + #[wasm_bindgen(js_name = "MarketplaceTradeModeAdminGroupItem")] + pub fn market_trade_mode_admin_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItem::MarketplaceTradeModeAdminGroup( + action_taker.clone().into(), + ), + ) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs new file mode 100644 index 00000000000..56ca2dff867 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs @@ -0,0 +1,27 @@ +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::balances::credits::TokenAmount; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "MaxSupplyItem")] + pub fn max_supply_item(supply: Option) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::MaxSupply(supply)) + } + + #[wasm_bindgen(js_name = "MaxSupplyControlGroupItem")] + pub fn max_supply_control_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::MaxSupplyControlGroup( + action_taker.clone().into(), + )) + } + + #[wasm_bindgen(js_name = "MaxSupplyAdminGroupItem")] + pub fn max_supply_admin_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::MaxSupplyAdminGroup( + action_taker.clone().into(), + )) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs new file mode 100644 index 00000000000..82889f337d8 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs @@ -0,0 +1,36 @@ +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "MintingAllowChoosingDestinationItem")] + pub fn minting_allow_choosing_destination_item(flag: bool) -> Self { + TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItem::MintingAllowChoosingDestination(flag), + ) + } + + #[wasm_bindgen(js_name = "MintingAllowChoosingDestinationControlGroupItem")] + pub fn minting_allow_choosing_destination_control_group_item( + action_taker: &AuthorizedActionTakersWASM, + ) -> Self { + TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItem::MintingAllowChoosingDestinationControlGroup( + action_taker.clone().into(), + ), + ) + } + + #[wasm_bindgen(js_name = "MintingAllowChoosingDestinationAdminGroupItem")] + pub fn minting_allow_choosing_destination_admin_group_item( + action_taker: &AuthorizedActionTakersWASM, + ) -> Self { + TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItem::MintingAllowChoosingDestinationAdminGroup( + action_taker.clone().into(), + ), + ) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/mod.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/mod.rs new file mode 100644 index 00000000000..08abe33bcad --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/mod.rs @@ -0,0 +1,14 @@ +pub mod conventions; +pub mod destroy_frozen_funds; +pub mod emergency_action; +pub mod freeze; +pub mod main_control_group; +pub mod manual_burning; +pub mod manual_minting; +pub mod marketplace_trade_mode; +pub mod max_supply; +pub mod minting_allow_choosing_destination; +pub mod new_tokens_destination_identity; +pub mod no_change; +pub mod perpetual_distribution; +pub mod unfreeze; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs new file mode 100644 index 00000000000..e99d4a1f113 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs @@ -0,0 +1,46 @@ +use crate::identifier::IdentifierWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use dpp::prelude::Identifier; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "NewTokensDestinationIdentityItem")] + pub fn new_tokens_destination_identity_item( + js_identity_id: &JsValue, + ) -> Result { + let identity_id: Option = match js_identity_id.is_undefined() { + true => None, + false => Some(IdentifierWASM::try_from(js_identity_id)?.into()), + }; + + Ok(TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItem::NewTokensDestinationIdentity(identity_id), + )) + } + + #[wasm_bindgen(js_name = "NewTokensDestinationIdentityControlGroupItem")] + pub fn new_tokens_destination_identity_control_group_item( + action_taker: &AuthorizedActionTakersWASM, + ) -> Self { + TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItem::NewTokensDestinationIdentityControlGroup( + action_taker.clone().into(), + ), + ) + } + + #[wasm_bindgen(js_name = "NewTokensDestinationIdentityAdminGroupItem")] + pub fn new_tokens_destination_identity_admin_group_item( + action_taker: &AuthorizedActionTakersWASM, + ) -> Self { + TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItem::NewTokensDestinationIdentityAdminGroup( + action_taker.clone().into(), + ), + ) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs new file mode 100644 index 00000000000..5d78200a540 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs @@ -0,0 +1,11 @@ +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "noChangeItem")] + pub fn no_changes_item() -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::TokenConfigurationNoChange) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs new file mode 100644 index 00000000000..6055871bc2c --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs @@ -0,0 +1,52 @@ +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::utils::IntoWasm; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use dpp::data_contract::associated_token::token_perpetual_distribution::TokenPerpetualDistribution; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "PerpetualDistributionConfigurationItem")] + pub fn perpetual_distribution_item(js_perpetual_distribution_value: JsValue) -> Self { + let perpetual_distribution_value: Option = + match js_perpetual_distribution_value.is_undefined() { + true => None, + false => Some( + js_perpetual_distribution_value + .to_wasm::("TokenPerpetualDistributionWASM") + .unwrap() + .clone() + .into(), + ), + }; + + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::PerpetualDistribution( + perpetual_distribution_value, + )) + } + + #[wasm_bindgen(js_name = "PerpetualDistributionControlGroupItem")] + pub fn perpetual_distribution_control_group_item( + action_taker: &AuthorizedActionTakersWASM, + ) -> Self { + TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItem::PerpetualDistributionControlGroup( + action_taker.clone().into(), + ), + ) + } + + #[wasm_bindgen(js_name = "PerpetualDistributionAdminGroupItem")] + pub fn perpetual_distribution_admin_group_item( + action_taker: &AuthorizedActionTakersWASM, + ) -> Self { + TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItem::PerpetualDistributionAdminGroup( + action_taker.clone().into(), + ), + ) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs new file mode 100644 index 00000000000..180494c629f --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs @@ -0,0 +1,21 @@ +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(js_name = "UnfreezeItem")] + pub fn unfreeze_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::Unfreeze( + action_taker.clone().into(), + )) + } + + #[wasm_bindgen(js_name = "UnfreezeAdminGroupItem")] + pub fn unfreeze_admin_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { + TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::UnfreezeAdminGroup( + action_taker.clone().into(), + )) + } +} diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs b/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs new file mode 100644 index 00000000000..62c41d73925 --- /dev/null +++ b/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs @@ -0,0 +1,231 @@ +pub mod items; + +use crate::identifier::IdentifierWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; +use crate::token_configuration::configuration_convention::TokenConfigurationConventionWASM; +use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWASM; +use crate::token_configuration::trade_mode::TokenTradeModeWASM; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name = "TokenConfigurationChangeItemWASM")] +pub struct TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem); + +impl From for TokenConfigurationChangeItem { + fn from(item: TokenConfigurationChangeItemWASM) -> Self { + item.0 + } +} + +impl From for TokenConfigurationChangeItemWASM { + fn from(item: TokenConfigurationChangeItem) -> Self { + TokenConfigurationChangeItemWASM(item) + } +} + +#[wasm_bindgen] +impl TokenConfigurationChangeItemWASM { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenConfigurationChangeItemWASM".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenConfigurationChangeItemWASM".to_string() + } + + #[wasm_bindgen(js_name = "getItemName")] + pub fn get_item_name(&self) -> String { + match self.0.clone() { + TokenConfigurationChangeItem::TokenConfigurationNoChange => { + String::from("TokenConfigurationNoChange") + } + TokenConfigurationChangeItem::Conventions(_) => String::from("Conventions"), + TokenConfigurationChangeItem::ConventionsControlGroup(_) => { + String::from("ConventionsControlGroup") + } + TokenConfigurationChangeItem::ConventionsAdminGroup(_) => { + String::from("ConventionsAdminGroup") + } + TokenConfigurationChangeItem::MaxSupply(_) => String::from("MaxSupply"), + TokenConfigurationChangeItem::MaxSupplyControlGroup(_) => { + String::from("MaxSupplyControlGroup") + } + TokenConfigurationChangeItem::MaxSupplyAdminGroup(_) => { + String::from("MaxSupplyAdminGroup") + } + TokenConfigurationChangeItem::PerpetualDistribution(_) => { + String::from("PerpetualDistribution") + } + TokenConfigurationChangeItem::PerpetualDistributionControlGroup(_) => { + String::from("PerpetualDistributionControlGroup") + } + TokenConfigurationChangeItem::PerpetualDistributionAdminGroup(_) => { + String::from("PerpetualDistributionAdminGroup") + } + TokenConfigurationChangeItem::NewTokensDestinationIdentity(_) => { + String::from("NewTokensDestinationIdentity") + } + TokenConfigurationChangeItem::NewTokensDestinationIdentityControlGroup(_) => { + String::from("NewTokensDestinationIdentityControlGroup") + } + TokenConfigurationChangeItem::NewTokensDestinationIdentityAdminGroup(_) => { + String::from("NewTokensDestinationIdentityAdminGroup") + } + TokenConfigurationChangeItem::MintingAllowChoosingDestination(_) => { + String::from("MintingAllowChoosingDestination") + } + TokenConfigurationChangeItem::MintingAllowChoosingDestinationControlGroup(_) => { + String::from("MintingAllowChoosingDestinationControlGroup") + } + TokenConfigurationChangeItem::MintingAllowChoosingDestinationAdminGroup(_) => { + String::from("MintingAllowChoosingDestinationAdminGroup") + } + TokenConfigurationChangeItem::ManualMinting(_) => String::from("ManualMinting"), + TokenConfigurationChangeItem::ManualMintingAdminGroup(_) => { + String::from("ManualMintingAdminGroup") + } + TokenConfigurationChangeItem::ManualBurning(_) => String::from("ManualBurning"), + TokenConfigurationChangeItem::ManualBurningAdminGroup(_) => { + String::from("ManualBurningAdminGroup") + } + TokenConfigurationChangeItem::Freeze(_) => String::from("Freeze"), + TokenConfigurationChangeItem::FreezeAdminGroup(_) => String::from("FreezeAdminGroup"), + TokenConfigurationChangeItem::Unfreeze(_) => String::from("Unfreeze"), + TokenConfigurationChangeItem::UnfreezeAdminGroup(_) => { + String::from("UnfreezeAdminGroup") + } + TokenConfigurationChangeItem::DestroyFrozenFunds(_) => { + String::from("DestroyFrozenFunds") + } + TokenConfigurationChangeItem::DestroyFrozenFundsAdminGroup(_) => { + String::from("DestroyFrozenFundsAdminGroup") + } + TokenConfigurationChangeItem::EmergencyAction(_) => String::from("EmergencyAction"), + TokenConfigurationChangeItem::EmergencyActionAdminGroup(_) => { + String::from("EmergencyActionAdminGroup") + } + TokenConfigurationChangeItem::MarketplaceTradeMode(_) => { + String::from("MarketplaceTradeMode") + } + TokenConfigurationChangeItem::MarketplaceTradeModeControlGroup(_) => { + String::from("MarketplaceTradeModeControlGroup") + } + TokenConfigurationChangeItem::MarketplaceTradeModeAdminGroup(_) => { + String::from("MarketplaceTradeModeAdminGroup") + } + TokenConfigurationChangeItem::MainControlGroup(_) => String::from("MainControlGroup"), + } + } + + #[wasm_bindgen(js_name = "getItem")] + pub fn get_item(&self) -> JsValue { + match self.0.clone() { + TokenConfigurationChangeItem::TokenConfigurationNoChange => { + JsValue::from_str("TokenConfigurationNoChange") + } + TokenConfigurationChangeItem::Conventions(convention) => { + JsValue::from(TokenConfigurationConventionWASM::from(convention)) + } + TokenConfigurationChangeItem::ConventionsControlGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::ConventionsAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::MaxSupply(amount) => JsValue::from(amount), + TokenConfigurationChangeItem::MaxSupplyControlGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::MaxSupplyAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::PerpetualDistribution(perpetual_distribution) => { + match perpetual_distribution { + Some(token_perpetual_distribution) => JsValue::from( + TokenPerpetualDistributionWASM::from(token_perpetual_distribution), + ), + None => JsValue::null(), + } + } + TokenConfigurationChangeItem::PerpetualDistributionControlGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::PerpetualDistributionAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::NewTokensDestinationIdentity(identifier) => { + match identifier { + Some(id) => JsValue::from(IdentifierWASM::from(id)), + None => JsValue::null(), + } + } + TokenConfigurationChangeItem::NewTokensDestinationIdentityControlGroup( + action_takers, + ) => JsValue::from(AuthorizedActionTakersWASM::from(action_takers)), + TokenConfigurationChangeItem::NewTokensDestinationIdentityAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::MintingAllowChoosingDestination(flag) => { + JsValue::from_bool(flag) + } + TokenConfigurationChangeItem::MintingAllowChoosingDestinationControlGroup( + action_takers, + ) => JsValue::from(AuthorizedActionTakersWASM::from(action_takers)), + TokenConfigurationChangeItem::MintingAllowChoosingDestinationAdminGroup( + action_takers, + ) => JsValue::from(AuthorizedActionTakersWASM::from(action_takers)), + TokenConfigurationChangeItem::ManualMinting(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::ManualMintingAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::ManualBurning(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::ManualBurningAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::Freeze(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::FreezeAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::Unfreeze(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::UnfreezeAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::DestroyFrozenFunds(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::DestroyFrozenFundsAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::EmergencyAction(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::EmergencyActionAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::MarketplaceTradeMode(trade_mode) => { + JsValue::from(TokenTradeModeWASM::from(trade_mode)) + } + TokenConfigurationChangeItem::MarketplaceTradeModeControlGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::MarketplaceTradeModeAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + } + TokenConfigurationChangeItem::MainControlGroup(group_contract_position) => { + JsValue::from(group_contract_position) + } + } + } +} diff --git a/packages/wasm-dpp2/src/utils/mod.rs b/packages/wasm-dpp2/src/utils/mod.rs new file mode 100644 index 00000000000..ccf5cd2a8cf --- /dev/null +++ b/packages/wasm-dpp2/src/utils/mod.rs @@ -0,0 +1,248 @@ +use anyhow::{Context, anyhow, bail}; +use dpp::ProtocolError; +use dpp::identifier::Identifier; +use dpp::platform_value::Value; +use dpp::platform_value::string_encoding::Encoding::Base58; +use dpp::util::hash::hash_double_to_vec; +use js_sys::{Function, Uint8Array}; +use serde_json::Value as JsonValue; +use std::collections::BTreeMap; +use std::convert::TryInto; +use wasm_bindgen::JsValue; +use wasm_bindgen::{convert::RefFromWasmAbi, prelude::*}; + +pub trait ToSerdeJSONExt { + fn with_serde_to_json_value(&self) -> Result; + fn with_serde_to_platform_value(&self) -> Result; + /// Converts the `JsValue` into `platform::Value`. It's an expensive conversion, + /// as `JsValue` must be stringified first + fn with_serde_to_platform_value_map(&self) -> Result, JsValue>; +} + +impl ToSerdeJSONExt for JsValue { + /// Converts the `JsValue` into `serde_json::Value`. It's an expensive conversion, + /// as `JsValue` must be stringified first + fn with_serde_to_json_value(&self) -> Result { + with_serde_to_json_value(self.clone()) + } + + /// Converts the `JsValue` into `platform::Value`. It's an expensive conversion, + /// as `JsValue` must be stringified first + fn with_serde_to_platform_value(&self) -> Result { + with_serde_to_platform_value(self) + } + + /// Converts the `JsValue` into `platform::Value`. It's an expensive conversion, + /// as `JsValue` must be stringified first + fn with_serde_to_platform_value_map(&self) -> Result, JsValue> { + self.with_serde_to_platform_value()? + .into_btree_string_map() + .map_err(ProtocolError::ValueError) + .with_js_error() + } +} + +pub fn to_vec_js(iter: impl IntoIterator) -> Vec +where + T: Into, +{ + iter.into_iter().map(|v| v.into()).collect() +} + +#[allow(dead_code)] +#[deprecated(note = "This function is marked as unused.")] +#[allow(deprecated)] +pub fn to_vec_of_serde_values( + values: impl IntoIterator>, +) -> Result, JsValue> { + values + .into_iter() + .map(|v| v.as_ref().with_serde_to_json_value()) + .collect() +} + +pub fn to_vec_of_platform_values( + values: impl IntoIterator>, +) -> Result, JsValue> { + values + .into_iter() + .map(|v| v.as_ref().with_serde_to_platform_value()) + .collect() +} + +pub fn with_serde_to_json_value(data: JsValue) -> Result { + let data = stringify(&data)?; + let value: JsonValue = serde_json::from_str(&data) + .with_context(|| format!("cant convert {data:#?} to serde json value")) + .map_err(|e| format!("{e:#}"))?; + Ok(value) +} + +pub fn with_serde_to_platform_value(data: &JsValue) -> Result { + Ok(with_serde_to_json_value(data.clone())?.into()) +} + +pub fn stringify(data: &JsValue) -> Result { + let replacer_func = Function::new_with_args( + "key, value", + "return (value != undefined && value.type=='Buffer') ? value.data : value ", + ); + + let data_string: String = + js_sys::JSON::stringify_with_replacer(data, &JsValue::from(replacer_func))?.into(); + + Ok(data_string) +} + +pub trait WithJsError { + /// Converts the error into JsValue + fn with_js_error(self) -> Result; +} + +impl WithJsError for Result { + fn with_js_error(self) -> Result { + match self { + Ok(ok) => Ok(ok), + Err(error) => Err(format!("{error:#}").into()), + } + } +} + +impl WithJsError for Result { + fn with_js_error(self) -> Result { + match self { + Ok(ok) => Ok(ok), + Err(error) => Err(JsValue::from_str(&error.to_string())), + } + } +} + +pub trait IntoWasm { + fn to_wasm>(&self, class_name: &str) + -> Result; +} + +impl IntoWasm for JsValue { + fn to_wasm>( + &self, + class_name: &str, + ) -> Result { + generic_of_js_val::(self, class_name) + } +} + +pub fn generic_of_js_val>( + js_value: &JsValue, + class_name: &str, +) -> Result { + if !js_value.is_object() { + return Err(JsError::new( + format!("Value supplied as {} is not an object", class_name).as_str(), + ) + .into()); + } + + let ctor_name = get_class_type(js_value)?; + + if ctor_name == class_name { + let ptr = js_sys::Reflect::get(js_value, &JsValue::from_str("__wbg_ptr"))?; + let ptr_u32: u32 = ptr + .as_f64() + .ok_or_else(|| JsValue::from(JsError::new("Invalid JS object pointer")))? + as u32; + let reference = unsafe { T::ref_from_abi(ptr_u32) }; + Ok(reference) + } else { + let error_string = format!( + "JS object constructor name mismatch. Expected {}, provided {}.", + class_name, ctor_name + ); + Err(JsError::new(&error_string).into()) + } +} + +pub fn get_class_type(value: &JsValue) -> Result { + let class_type = js_sys::Reflect::get(&value, &JsValue::from_str("__type")); + + match class_type { + Ok(class_type) => Ok(class_type.as_string().unwrap_or("".to_string())), + Err(_) => Err(JsValue::from_str(&"")), + } +} + +pub fn try_to_u64(value: JsValue) -> Result { + if value.is_bigint() { + js_sys::BigInt::new(&value) + .map_err(|e| anyhow!("unable to create bigInt: {}", e.to_string()))? + .try_into() + .map_err(|e| anyhow!("conversion of BigInt to u64 failed: {:#}", e)) + } else if value.as_f64().is_some() { + let number = js_sys::Number::from(value); + convert_number_to_u64(number) + } else { + bail!("supported types are Number or BigInt") + } +} + +pub fn convert_number_to_u64(js_number: js_sys::Number) -> Result { + if let Some(float_number) = js_number.as_f64() { + if float_number.is_nan() || float_number.is_infinite() { + bail!("received an invalid timestamp: the number is either NaN or Inf") + } + if float_number < 0. { + bail!("received an invalid timestamp: the number is negative"); + } + if float_number.fract() != 0. { + bail!("received an invalid timestamp: the number is fractional") + } + if float_number > u64::MAX as f64 { + bail!("received an invalid timestamp: the number is > u64::max") + } + + return Ok(float_number as u64); + } + bail!("the value is not a number") +} + +pub fn generate_document_id_v0( + contract_id: &Identifier, + owner_id: &Identifier, + document_type_name: &str, + entropy: &[u8], +) -> Result { + let mut buf: Vec = vec![]; + + buf.extend_from_slice(&contract_id.to_buffer()); + buf.extend_from_slice(&owner_id.to_buffer()); + buf.extend_from_slice(document_type_name.as_bytes()); + buf.extend_from_slice(entropy); + + Identifier::from_bytes(&hash_double_to_vec(&buf)).map_err(|e| JsValue::from(e.to_string())) +} + +// Try to extract Identifier from **stringified** identifier_utils. +// The `js_value` can be a stringified instance of: `Identifier`, `Buffer` or `Array` +pub fn identifier_from_js_value(js_value: &JsValue) -> Result { + if js_value.is_undefined() || js_value.is_null() { + wasm_bindgen::throw_val(JsValue::from_str( + "the identifier cannot be null or undefined", + )); + } + + match js_value.is_string() { + true => Identifier::from_string(js_value.as_string().unwrap_or("".into()).as_str(), Base58) + .map_err(ProtocolError::ValueError) + .with_js_error(), + false => match js_value.is_object() || js_value.is_array() { + true => { + let uint8_array = Uint8Array::from(js_value.clone()); + let bytes = uint8_array.to_vec(); + + Identifier::from_bytes(&bytes) + .map_err(ProtocolError::ValueError) + .with_js_error() + } + false => Err(JsValue::from_str("Invalid ID. Expected array or string")), + }, + } +} diff --git a/packages/wasm-dpp2/tests/.eslintrc.yml b/packages/wasm-dpp2/tests/.eslintrc.yml new file mode 100644 index 00000000000..2a3dfdadb80 --- /dev/null +++ b/packages/wasm-dpp2/tests/.eslintrc.yml @@ -0,0 +1,40 @@ +extends: + - airbnb-base + - plugin:jsdoc/recommended +env: + es2020: true + node: true + mocha: true +parserOptions: + ecmaVersion: 2024 +rules: + eol-last: + - error + - always + import/extensions: off + class-methods-use-this: off + import/no-extraneous-dependencies: off + import/no-named-as-default: off + import/named: off + import/prefer-default-export: off + max-len: off + no-bitwise: off + no-underscore-dangle: off + no-unused-expressions: off + jsdoc/require-returns: off + comma-dangle: off + func-names: off + import/newline-after-import: off + prefer-arrow-callback: off + semi: off + curly: + - error + - all + no-restricted-syntax: + - error + - selector: "LabeledStatement" + message: Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand. + - selector: "WithStatement" + message: "`with` is disallowed in strict mode because it makes code impossible to predict and optimize." +globals: + expect: true diff --git a/packages/wasm-dpp2/tests/bootstrap.cjs b/packages/wasm-dpp2/tests/bootstrap.cjs new file mode 100644 index 00000000000..4a2a30e0785 --- /dev/null +++ b/packages/wasm-dpp2/tests/bootstrap.cjs @@ -0,0 +1,10 @@ +const chai = require('chai'); +const dirtyChai = require('dirty-chai'); +const chaiAsPromised = require('chai-as-promised'); + +chai.use(chaiAsPromised); +chai.use(dirtyChai); + +const { expect } = chai; +const g = typeof globalThis !== 'undefined' ? globalThis : global; +g.expect = expect; diff --git a/packages/wasm-dpp2/tests/karma/karma.conf.cjs b/packages/wasm-dpp2/tests/karma/karma.conf.cjs new file mode 100644 index 00000000000..60f9d58a839 --- /dev/null +++ b/packages/wasm-dpp2/tests/karma/karma.conf.cjs @@ -0,0 +1,15 @@ +const options = require('./options.cjs'); + +module.exports = (config) => { + config.set({ + ...options, + files: [ + '../bootstrap.cjs', + '../unit/**/*.spec.mjs', + ], + preprocessors: { + '../bootstrap.cjs': ['webpack'], + '../unit/**/*.spec.mjs': ['webpack'], + }, + }); +}; diff --git a/packages/wasm-dpp2/tests/karma/options.cjs b/packages/wasm-dpp2/tests/karma/options.cjs new file mode 100644 index 00000000000..1e80694a7fa --- /dev/null +++ b/packages/wasm-dpp2/tests/karma/options.cjs @@ -0,0 +1,66 @@ +/* eslint-disable import/no-extraneous-dependencies */ +const webpack = require('webpack'); +const karmaMocha = require('karma-mocha'); +const karmaMochaReporter = require('karma-mocha-reporter'); +const karmaChai = require('karma-chai'); +const karmaChromeLauncher = require('karma-chrome-launcher'); +const karmaFirefoxLauncher = require('karma-firefox-launcher'); +const karmaWebpack = require('karma-webpack'); + +module.exports = { + frameworks: ['mocha', 'chai', 'webpack'], + webpack: { + mode: 'development', + devtool: 'eval', + plugins: [ + new webpack.ProvidePlugin({ + Buffer: [require.resolve('buffer/'), 'Buffer'], + process: require.resolve('process/browser'), + }), + ], + resolve: { + extensions: ['.mjs', '.js'], + fallback: { + fs: false, + path: require.resolve('path-browserify'), + url: require.resolve('url/'), + util: require.resolve('util/'), + buffer: require.resolve('buffer/'), + events: require.resolve('events/'), + assert: require.resolve('assert/'), + string_decoder: require.resolve('string_decoder/'), + process: require.resolve('process/browser'), + }, + }, + }, + reporters: ['mocha'], + port: 9876, + colors: true, + autoWatch: false, + browsers: ['ChromeHeadlessInsecure'], + singleRun: false, + concurrency: Infinity, + browserNoActivityTimeout: 7 * 60 * 1000, + browserDisconnectTimeout: 3 * 2000, + pingTimeout: 3 * 5000, + plugins: [ + karmaMocha, + karmaMochaReporter, + karmaChai, + karmaChromeLauncher, + karmaFirefoxLauncher, + karmaWebpack, + ], + webpackMiddleware: { + stats: 'errors-warnings', + }, + customLaunchers: { + ChromeHeadlessInsecure: { + base: 'ChromeHeadless', + flags: [ + '--allow-insecure-localhost', + ], + displayName: 'Chrome w/o security', + }, + }, +}; diff --git a/packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs b/packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs new file mode 100644 index 00000000000..db60e72080a --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs @@ -0,0 +1,101 @@ +import getWasm from './helpers/wasm.js'; +import { instantLockBytes, transactionBytes } from './mocks/Locks/index.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('AssetLockProof', () => { + describe('serialization / deserialization', () => { + it('should allow to get instant lock proof via constructor', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint); + const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + + const instantAssetLock = new wasm.AssetLockProofWASM(instantLockProof); + const chainAssetLock = new wasm.AssetLockProofWASM(chainlock); + + expect(instantAssetLock.constructor.name).to.equal('AssetLockProofWASM'); + expect(instantAssetLock.__wbg_ptr).to.not.equal(0); + expect(chainAssetLock.constructor.name).to.equal('AssetLockProofWASM'); + expect(chainAssetLock.__wbg_ptr).to.not.equal(0); + }); + + it('shouldn\'t allow to get chain lock proof via constructor', () => { + try { + // eslint-disable-next-line + new wasm.AssetLockProofWASM('chain') + } catch (e) { + expect(true).to.be.ok; + return; + } + expect.fail('Expected an error to be thrown'); + }); + + it('should allow to create instant lock proof from values', () => { + const instantLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof(instantLockBytes, transactionBytes, 0); + + expect(instantLockProof.constructor.name).to.equal('AssetLockProofWASM'); + }); + + it('should allow to create chain lock proof from values', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + + const chainLockProof = wasm.AssetLockProofWASM.createChainAssetLockProof(1, outpoint); + + expect(chainLockProof.constructor.name).to.equal('AssetLockProofWASM'); + }); + + it('should allow to serialize and deserialize asset lock in hex', () => { + const instantLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof(instantLockBytes, transactionBytes, 0); + + const newInstantLockProof = wasm.AssetLockProofWASM.fromHex(instantLockProof.hex()); + + expect(instantLockProof.constructor.name).to.equal('AssetLockProofWASM'); + expect(newInstantLockProof.constructor.name).to.equal('AssetLockProofWASM'); + + expect(newInstantLockProof.toObject()).to.deep.equal(instantLockProof.toObject()); + }); + }); + + describe('getters', () => { + it('should allow to get lock type', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + + const instantAssetLockProof = new wasm.AssetLockProofWASM(instantLockProof); + const chainLockProof = wasm.AssetLockProofWASM.createChainAssetLockProof(1, outpoint); + + expect(instantAssetLockProof.getLockType()).to.equal('Instant'); + expect(chainLockProof.getLockType()).to.equal('Chain'); + }); + + it('should allow to get lock instances', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + + const chainLockProof = wasm.AssetLockProofWASM.createChainAssetLockProof(1, outpoint); + const instantAssetLockProof = new wasm.AssetLockProofWASM(instantLockProof); + + expect(chainLockProof.getChainLockProof().constructor.name).to.equal('ChainAssetLockProofWASM'); + expect(instantAssetLockProof.getInstantLockProof().constructor.name).to.equal('InstantAssetLockProofWASM'); + }); + + it('should allow to return object of lock', () => { + const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + + const instantAssetLockProof = new wasm.AssetLockProofWASM(instantLockProof); + + const expected = { + instantLock: instantLockBytes, + transaction: transactionBytes, + outputIndex: 0, + }; + + expect(instantLockProof.toObject()).to.deep.equal(expected); + expect(instantAssetLockProof.toObject()).to.deep.equal(expected); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs b/packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs new file mode 100644 index 00000000000..53f2f5fd0b0 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs @@ -0,0 +1,79 @@ +import getWasm from './helpers/wasm.js'; +import { identifier } from './mocks/Identity/index.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('AuthorizedActionTakers', () => { + describe('serialization / deserialization', () => { + it('should allows to create AuthorizedActionTakers with NoOne', () => { + const actionTaker = wasm.AuthorizedActionTakersWASM.NoOne(); + + expect(actionTaker.__wbg_ptr).to.not.equal(0); + expect(actionTaker.getTakerType()).to.deep.equal('NoOne'); + }); + + it('should allows to create AuthorizedActionTakers with ContractOwner', () => { + const actionTaker = wasm.AuthorizedActionTakersWASM.ContractOwner(); + + expect(actionTaker.__wbg_ptr).to.not.equal(0); + expect(actionTaker.getTakerType()).to.deep.equal('ContractOwner'); + }); + + it('should allows to create AuthorizedActionTakers with Identity', () => { + const actionTaker = wasm.AuthorizedActionTakersWASM.Identity(identifier); + + expect(actionTaker.__wbg_ptr).to.not.equal(0); + expect(actionTaker.getTakerType()).to.deep.equal(`Identity(${identifier})`); + }); + + it('should allows to create AuthorizedActionTakers with MainGroup', () => { + const actionTaker = wasm.AuthorizedActionTakersWASM.MainGroup(); + + expect(actionTaker.__wbg_ptr).to.not.equal(0); + expect(actionTaker.getTakerType()).to.deep.equal('MainGroup'); + }); + + it('should allows to create AuthorizedActionTakers with Group', () => { + const actionTaker = wasm.AuthorizedActionTakersWASM.Group(12); + + expect(actionTaker.__wbg_ptr).to.not.equal(0); + expect(actionTaker.getTakerType()).to.deep.equal('Group(12)'); + }); + }); + + describe('getters', () => { + it('should allows to get value with NoOne', () => { + const actionTaker = wasm.AuthorizedActionTakersWASM.NoOne(); + + expect(actionTaker.getValue()).to.deep.equal(undefined); + }); + + it('should allows to get value with ContractOwner', () => { + const actionTaker = wasm.AuthorizedActionTakersWASM.ContractOwner(); + + expect(actionTaker.getValue()).to.deep.equal(undefined); + }); + + it('should allows to get value with Identity', () => { + const actionTaker = wasm.AuthorizedActionTakersWASM.Identity(identifier); + + expect(actionTaker.getValue().base58()).to.deep.equal(identifier); + }); + + it('should allows to get value with MainGroup', () => { + const actionTaker = wasm.AuthorizedActionTakersWASM.MainGroup(); + + expect(actionTaker.getValue()).to.deep.equal(undefined); + }); + + it('should allows to get value with Group', () => { + const actionTaker = wasm.AuthorizedActionTakersWASM.Group(12); + + expect(actionTaker.getValue()).to.deep.equal(12); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs new file mode 100644 index 00000000000..80a77517a43 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs @@ -0,0 +1,147 @@ +import getWasm from './helpers/wasm.js'; +import { + document, documentTypeName, revision, dataContractId, ownerId, id, +} from './mocks/Document/index.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('BatchTransition', () => { + describe('serialization / deserialization', () => { + describe('documents', () => { + it('should allow to create from v0 transition', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = createTransition.toDocumentTransition(); + + const batch = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(createTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batch.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create from v1 transition', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = createTransition.toDocumentTransition(); + + const batchedTransition = new wasm.BatchedTransitionWASM(documentTransition); + + const batch = wasm.BatchTransitionWASM.fromV1BatchedTransitions([batchedTransition, batchedTransition], documentInstance.ownerId, 1); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(createTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchedTransition.__wbg_ptr).to.not.equal(0); + expect(batch.__wbg_ptr).to.not.equal(0); + }); + }); + describe('tokens', () => { + it('should allow to create from v1 transition', () => { + const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId); + + const mintTransition = new wasm.TokenMintTransitionWASM(baseTransition, ownerId, BigInt(9999), 'bbbbbb'); + + const transition = new wasm.TokenTransitionWASM(mintTransition); + + const batchedTransition = new wasm.BatchedTransitionWASM(transition); + + const batch = wasm.BatchTransitionWASM.fromV1BatchedTransitions([batchedTransition, batchedTransition], ownerId, 1); + + expect(baseTransition.__wbg_ptr).to.not.equal(0); + expect(mintTransition.__wbg_ptr).to.not.equal(0); + expect(transition.__wbg_ptr).to.not.equal(0); + expect(batchedTransition.__wbg_ptr).to.not.equal(0); + expect(batch.__wbg_ptr).to.not.equal(0); + }); + }); + }); + + describe('getters', () => { + it('should allow to get transitions', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = createTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + expect(batchTransition.transitions.length).to.equal(2); + }); + + it('should allow to get signature', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = createTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + expect(batchTransition.signature).to.deep.equal(new Uint8Array(0)); + }); + + it('should allow to get signature public key id', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = createTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + expect(batchTransition.signaturePublicKeyId).to.equal(1); + }); + + it('should allow to get all purchases amount', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + const documentTransition = createTransition.toDocumentTransition(); + const documentTransition2 = purchaseTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition2], documentInstance.ownerId, 1, 1); + + expect(batchTransition.allPurchasesAmount).to.deep.equal(BigInt(100)); + }); + + it('should allow to get owner id', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = createTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + expect(batchTransition.ownerId.base58()).to.deep.equal(documentInstance.ownerId.base58()); + }); + + it('should allow to get modified data ids', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = createTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + expect(batchTransition.modifiedDataIds.map((identifier) => identifier.base58())).to.deep.equal([documentTransition.id.base58(), documentTransition.id.base58()]); + }); + + it('should allow to get allConflictingIndexCollateralVotingFunds', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = createTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + expect(batchTransition.allConflictingIndexCollateralVotingFunds).to.deep.equal(undefined); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/ChainLockProof.spec.mjs b/packages/wasm-dpp2/tests/unit/ChainLockProof.spec.mjs new file mode 100644 index 00000000000..3e5b78a3d18 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/ChainLockProof.spec.mjs @@ -0,0 +1,67 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('InstantLock', () => { + describe('serialization / deserialization', () => { + it('should allow to create chain lock proof from values', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint); + + expect(chainlock.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create chain lock proof from object', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = wasm.ChainAssetLockProofWASM.fromRawObject({ + coreChainLockedHeight: 11, + outPoint: Array.from(outpoint.bytes()), + }); + + expect(chainlock.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get coreChainLockedHeight', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint); + + expect(chainlock.coreChainLockedHeight).to.equal(11); + }); + + it('should allow to get outPoint', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint); + + expect(chainlock.outPoint.constructor.name).to.equal('OutPointWASM'); + }); + }); + + describe('setters', () => { + it('should allow to set coreChainLockedHeight', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint); + + chainlock.coreChainLockedHeight = 33; + + expect(chainlock.coreChainLockedHeight).to.equal(33); + }); + + it('should allow to get outPoint', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint); + + const newOutpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 222); + + chainlock.outPoint = newOutpoint; + + expect(chainlock.outPoint.getVOUT()).to.equal(222); + expect(newOutpoint.__wbg_ptr).to.not.equal(0); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/ChangeControlRules.spec.mjs b/packages/wasm-dpp2/tests/unit/ChangeControlRules.spec.mjs new file mode 100644 index 00000000000..8d4da9334f4 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/ChangeControlRules.spec.mjs @@ -0,0 +1,188 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('ChangeControlRules', () => { + describe('serialization / deserialization', () => { + it('should allow to create rules from values', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + expect(noOne.__wbg_ptr).to.not.equal(0); + expect(changeRules.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get authorizedToMakeChange', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + expect(changeRules.authorizedToMakeChange.constructor.name).to.deep.equal('AuthorizedActionTakersWASM'); + }); + + it('should allow to get adminActionTakers', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + expect(changeRules.adminActionTakers.constructor.name).to.deep.equal('AuthorizedActionTakersWASM'); + }); + + it('should allow to get changingAuthorizedActionTakersToNoOneAllowed', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + expect(changeRules.changingAuthorizedActionTakersToNoOneAllowed).to.deep.equal(true); + }); + + it('should allow to get changingAdminActionTakersToNoOneAllowed', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + expect(changeRules.changingAdminActionTakersToNoOneAllowed).to.deep.equal(true); + }); + + it('should allow to get selfChangingAdminActionTakersAllowed', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + expect(changeRules.selfChangingAdminActionTakersAllowed).to.deep.equal(true); + }); + }); + + describe('setters', () => { + it('should allow to set authorizedToMakeChange', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + const newActionTaker = wasm.AuthorizedActionTakersWASM.ContractOwner(); + + changeRules.authorizedToMakeChange = newActionTaker; + + expect(changeRules.authorizedToMakeChange.constructor.name).to.deep.equal('AuthorizedActionTakersWASM'); + expect(changeRules.authorizedToMakeChange.getTakerType()).to.deep.equal('ContractOwner'); + expect(newActionTaker.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to set adminActionTakers', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + const newActionTaker = wasm.AuthorizedActionTakersWASM.ContractOwner(); + + changeRules.adminActionTakers = newActionTaker; + + expect(changeRules.adminActionTakers.constructor.name).to.deep.equal('AuthorizedActionTakersWASM'); + expect(changeRules.adminActionTakers.getTakerType()).to.deep.equal('ContractOwner'); + expect(newActionTaker.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to set changingAuthorizedActionTakersToNoOneAllowed', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + changeRules.changingAuthorizedActionTakersToNoOneAllowed = false; + + expect(changeRules.changingAuthorizedActionTakersToNoOneAllowed).to.deep.equal(false); + }); + + it('should allow to set changingAdminActionTakersToNoOneAllowed', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + changeRules.changingAdminActionTakersToNoOneAllowed = false; + + expect(changeRules.changingAdminActionTakersToNoOneAllowed).to.deep.equal(false); + }); + + it('should allow to set selfChangingAdminActionTakersAllowed', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + changeRules.selfChangingAdminActionTakersAllowed = false; + + expect(changeRules.selfChangingAdminActionTakersAllowed).to.deep.equal(false); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs b/packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs new file mode 100644 index 00000000000..79fd513a6bd --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs @@ -0,0 +1,41 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('CoreScript', () => { + describe('serialization / deserialization', () => { + it('should allow to create from bytes', () => { + const script = wasm.CoreScriptWASM.fromBytes(Buffer.from('76a914c3dbfd40e7f8a4845c2f8e868a167c984049764988ac', 'hex')); + + expect(script._wbg_ptr).to.not.equal(0); + }); + + it('should allow to create P2PKH', () => { + const script = wasm.CoreScriptWASM.newP2PKH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73]); + + expect(script._wbg_ptr).to.not.equal(0); + }); + + it('should allow to create P2SH', () => { + const script = wasm.CoreScriptWASM.newP2SH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73]); + + expect(script._wbg_ptr).to.not.equal(0); + }); + + it('should allow to convert to asm P2PKH', () => { + const script = wasm.CoreScriptWASM.newP2PKH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73]); + + expect(script.ASMString()).to.equal('OP_DUP OP_HASH160 OP_PUSHBYTES_20 c3dbfd40e7f8a4845c2f8e868a167c9840497649 OP_EQUALVERIFY OP_CHECKSIG'); + }); + + it('should allow to convert to adddress', () => { + const script = wasm.CoreScriptWASM.fromBytes(Buffer.from('76a9142de40f87177f6e167fb9fcda9a3b3c64fc42468f88ac', 'hex')); + + expect(script.toAddress(wasm.NetworkWASM.Testnet)).to.equal('yQW6TmUFef5CDyhEYwjoN8aUTMmKLYYNDm'); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs b/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs new file mode 100644 index 00000000000..899d7c398e9 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs @@ -0,0 +1,175 @@ +import getWasm from './helpers/wasm.js'; +import { value, id, ownerId } from './mocks/DataContract/index.js'; +import { fromHexString } from './utils/hex.js'; + +let wasm; +let PlatformVersionWASM; + +before(async () => { + wasm = await getWasm(); + ({ PlatformVersionWASM } = wasm); +}); + +let dataContractsBytes; + +describe('DataContract', () => { + before(async () => { + dataContractsBytes = ['003662bb61e17fae3ea294cf603197fb0aab6d51180bd8b6104c4944a62fe2d97f00000000000101000001000000000000000000000000000000000000000000000000000000000000000000010a7769746864726177616c1607120b6465736372697074696f6e12805769746864726177616c20646f63756d656e7420746f20747261636b20756e6465726c79696e67207769746864726177616c207472616e73616374696f6e732e205769746864726177616c732073686f756c6420626520637265617465642077697468204964656e746974795769746864726177616c5472616e736974696f6e12176372656174696f6e5265737472696374696f6e4d6f6465020212047479706512066f626a6563741207696e64696365731504160312046e616d65120e6964656e74697479537461747573120a70726f70657274696573150316011208246f776e6572496412036173631601120673746174757312036173631601120a2463726561746564417412036173631206756e697175651300160312046e616d65120e6964656e74697479526563656e74120a70726f70657274696573150316011208246f776e6572496412036173631601120a2475706461746564417412036173631601120673746174757312036173631206756e697175651300160312046e616d651207706f6f6c696e67120a70726f70657274696573150416011206737461747573120361736316011207706f6f6c696e6712036173631601120e636f72654665655065724279746512036173631601120a2475706461746564417412036173631206756e697175651300160312046e616d65120b7472616e73616374696f6e120a70726f706572746965731502160112067374617475731203617363160112107472616e73616374696f6e496e64657812036173631206756e697175651300120a70726f70657274696573160712107472616e73616374696f6e496e64657816041204747970651207696e7465676572120b6465736372697074696f6e127953657175656e7469616c20696e646578206f6620617373657420756e6c6f636b20287769746864726177616c29207472616e73616374696f6e2e20506f70756c61746564207768656e2061207769746864726177616c20706f6f6c656420696e746f207769746864726177616c207472616e73616374696f6e12076d696e696d756d02011208706f736974696f6e020012157472616e73616374696f6e5369676e48656967687416041204747970651207696e7465676572120b6465736372697074696f6e122f54686520436f726520686569676874206f6e207768696368207472616e73616374696f6e20776173207369676e656412076d696e696d756d02011208706f736974696f6e02011206616d6f756e7416041204747970651207696e7465676572120b6465736372697074696f6e121a54686520616d6f756e7420746f2062652077697468647261776e12076d696e696d756d02fb03e81208706f736974696f6e0202120e636f72654665655065724279746516051204747970651207696e7465676572120b6465736372697074696f6e1250546869732069732074686520666565207468617420796f75206172652077696c6c696e6720746f207370656e6420666f722074686973207472616e73616374696f6e20696e2044756666732f4279746512076d696e696d756d020112076d6178696d756d02fcffffffff1208706f736974696f6e02031207706f6f6c696e6716041204747970651207696e7465676572120b6465736372697074696f6e124e5468697320696e6469636174656420746865206c6576656c20617420776869636820506c6174666f726d2073686f756c642074727920746f20706f6f6c2074686973207472616e73616374696f6e1204656e756d15030200020102021208706f736974696f6e0204120c6f75747075745363726970741605120474797065120561727261791209627974654172726179130112086d696e4974656d73021712086d61784974656d7302191208706f736974696f6e0205120673746174757316041204747970651207696e74656765721204656e756d150502000201020202030204120b6465736372697074696f6e124330202d2050656e64696e672c2031202d205369676e65642c2032202d2042726f61646361737465642c2033202d20436f6d706c6574652c2034202d20457870697265641208706f736974696f6e020612146164646974696f6e616c50726f706572746965731300120872657175697265641507120a24637265617465644174120a247570646174656441741206616d6f756e74120e636f7265466565506572427974651207706f6f6c696e67120c6f75747075745363726970741206737461747573']; + }); + + describe('serialization / deserialization', () => { + it('should allows to create DataContract from schema without full validation', () => { + const identifier = new wasm.IdentifierWASM(value.ownerId); + + const dataContract = new wasm.DataContractWASM(identifier, BigInt(2), value.documentSchemas, null, false); + + expect(dataContract.__wbg_ptr).to.not.equal(0); + }); + + it('should allows to create DataContract from schema with full validation', () => { + const identifier = new wasm.IdentifierWASM(value.ownerId); + + const dataContract = new wasm.DataContractWASM(identifier, BigInt(2), value.documentSchemas, null, true); + + expect(dataContract.__wbg_ptr).to.not.equal(0); + }); + + it('should allows to create DataContract from value with full validation and without platform version', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + expect(dataContract.__wbg_ptr).to.not.equal(0); + }); + + it('should allows to convert DataContract to bytes and from bytes', () => { + const [dataContractBytes] = dataContractsBytes; + + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + expect(dataContract.bytes()).to.deep.equal(fromHexString(dataContractBytes)); + + const dataContractFromBytes = wasm.DataContractWASM.fromBytes(dataContract.bytes(), false, PlatformVersionWASM.PLATFORM_V1); + + expect(dataContract.__wbg_ptr).to.not.equal(0); + + expect(dataContractFromBytes.bytes()).to.deep.equal(fromHexString(dataContractBytes)); + }); + + it('should allows to create DataContract from bytes without full validation', () => { + const [dataContractBytes] = dataContractsBytes; + + const dataContractFromBytes = wasm.DataContractWASM.fromBytes(fromHexString(dataContractBytes), false, PlatformVersionWASM.PLATFORM_V1); + const dataContractFromValue = wasm.DataContractWASM.fromValue(value, true); + + expect(dataContractFromBytes.toValue()).to.deep.equal(dataContractFromValue.toValue()); + }); + + it('should allows to create DataContract from bytes with full validation and without version', () => { + const [dataContractBytes] = dataContractsBytes; + + const dataContractFromBytes = wasm.DataContractWASM.fromBytes(fromHexString(dataContractBytes), true); + const dataContractFromValue = wasm.DataContractWASM.fromValue(value, true); + + expect(dataContractFromBytes.toValue()).to.deep.equal(dataContractFromValue.toValue()); + }); + + it('should allow to get json', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + expect(dataContract.toJson()).to.deep.equal(value); + }); + }); + + describe('getters', () => { + it('should allow to get schemas', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + expect(dataContract.getSchemas()).to.deep.equal(value.documentSchemas); + }); + + it('should allow to get version', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + expect(dataContract.version).to.deep.equal(value.version); + }); + + it('should allow to get id', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + expect(dataContract.id.base58()).to.deep.equal(id); + }); + + it('should allow to get owner id', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + expect(dataContract.ownerId.base58()).to.deep.equal(ownerId); + }); + + it('should allow to get config', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + expect(dataContract.getConfig()).to.deep.equal(value.config); + }); + }); + + describe('setters', () => { + it('should allow to set id', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + dataContract.id = new wasm.IdentifierWASM('7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH'); + + expect(dataContract.id.base58()).to.deep.equal('7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH'); + }); + + it('should allow to set owner id', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + dataContract.ownerId = new wasm.IdentifierWASM('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL'); + + expect(dataContract.ownerId.base58()).to.deep.equal('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL'); + }); + + it('should allow to set version', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + dataContract.version = 20; + + expect(dataContract.version).to.equal(20); + }); + + it('should allow to set config', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + const oldConfig = dataContract.getConfig(); + + const newConfig = { ...oldConfig, canBeDeleted: !oldConfig.canBeDeleted }; + + dataContract.setConfig(newConfig); + + expect(dataContract.getConfig()).to.deep.equal(newConfig); + }); + + it('should allow to set schema', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, true); + + const oldSchema = dataContract.getSchemas(); + + const newSchema = { + pupup: oldSchema.withdrawal, + }; + + dataContract.setSchemas(newSchema); + + expect(dataContract.getSchemas()).to.deep.equal(newSchema); + }); + }); + + describe('static', () => { + it('should allow to generate id', () => { + const identifier = new wasm.IdentifierWASM('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL'); + + const generatedId = wasm.DataContractWASM.generateId(identifier, BigInt(4)); + + expect(generatedId.base58()).to.deep.equal('7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH'); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs new file mode 100644 index 00000000000..3b4b4ed29ba --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs @@ -0,0 +1,108 @@ +import getWasm from './helpers/wasm.js'; +import { value, dataContractsBytes } from './mocks/DataContract/index.js'; +import { fromHexString } from './utils/hex.js'; + +let wasm; +let PlatformVersionWASM; + +before(async () => { + wasm = await getWasm(); + ({ PlatformVersionWASM } = wasm); +}); + +describe('DataContract Create Transition', () => { + describe('serialization / deserialization', () => { + it('should allow to create document_transitions from data contract', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + + expect(dataContractTransition.__wbg_ptr).to.not.equal(0); + expect(dataContract.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to convert document_transitions to bytes and create from bytes', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + + const bytes = dataContractTransition.bytes(); + + const newDataContractTransition = wasm.DataContractCreateTransitionWASM.fromBytes(bytes); + + expect(newDataContractTransition.bytes()).to.deep.equal(bytes); + expect(newDataContractTransition.__wbg_ptr).to.not.equal(0); + expect(dataContractTransition.__wbg_ptr).to.not.equal(0); + expect(dataContract.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to convert data contract transition to state document_transitions and create data contract transition from state transition', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + + const stateTransition = dataContractTransition.toStateTransition(); + + const newDataContractTransition = wasm.DataContractCreateTransitionWASM.fromStateTransition(stateTransition); + + expect(dataContractTransition.bytes()).to.deep.equal(newDataContractTransition.bytes()); + }); + }); + + describe('getters', () => { + it('should allow to get feature version', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + + expect(dataContractTransition.featureVersion).to.equal(0); + }); + + it('should allow to verify protocol version', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + + expect(dataContractTransition.verifyProtocolVersion(1)).to.equal(true); + }); + + it('should allow to verify incorrect protocol version', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + + try { + dataContractTransition.verifyProtocolVersion(20); + expect(true).to.equal(false); + } catch (error) { + expect(false).to.equal(false); + } + }); + + it('should allow to get data contract', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + + const newDataContract = dataContractTransition.getDataContract(); + + expect(dataContract.bytes()).to.deep.equal(newDataContract.bytes()); + }); + }); + + describe('setters', () => { + it('should allow to set the data contract', () => { + const [dataContractBytes] = dataContractsBytes; + + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + + const newDataContract = wasm.DataContractWASM.fromBytes(fromHexString(dataContractBytes), false, PlatformVersionWASM.PLATFORM_V1); + + dataContractTransition.setDataContract(newDataContract); + + expect(fromHexString(dataContractBytes)).to.deep.equal(dataContractTransition.getDataContract().bytes()); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs new file mode 100644 index 00000000000..24759eeb81f --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs @@ -0,0 +1,108 @@ +import getWasm from './helpers/wasm.js'; +import { value, dataContractsBytes } from './mocks/DataContract/index.js'; +import { fromHexString } from './utils/hex.js'; + +let wasm; +let PlatformVersionWASM; + +before(async () => { + wasm = await getWasm(); + ({ PlatformVersionWASM } = wasm); +}); + +describe('DataContract Updatet Transition', () => { + describe('serialization / deserialization', () => { + it('should allow to create document_transitions from data contract', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + + expect(dataContractTransition.__wbg_ptr).to.not.equal(0); + expect(dataContract.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to convert document_transitions to bytes and create from bytes', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + + const bytes = dataContractTransition.bytes(); + + const newDataContractTransition = wasm.DataContractUpdateTransitionWASM.fromBytes(bytes); + + expect(newDataContractTransition.bytes()).to.deep.equal(bytes); + expect(newDataContractTransition.__wbg_ptr).to.not.equal(0); + expect(dataContractTransition.__wbg_ptr).to.not.equal(0); + expect(dataContract.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to convert data contract transition to state document_transitions and create data contract transition from state transition', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + + const stateTransition = dataContractTransition.toStateTransition(); + + const newDataContractTransition = wasm.DataContractUpdateTransitionWASM.fromStateTransition(stateTransition); + + expect(dataContractTransition.bytes()).to.deep.equal(newDataContractTransition.bytes()); + }); + }); + + describe('getters', () => { + it('should allow to get feature version', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + + expect(dataContractTransition.featureVersion).to.equal(0); + }); + + it('should allow to verify protocol version', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + + expect(dataContractTransition.verifyProtocolVersion(1)).to.equal(true); + }); + + it('should allow to verify incorrect protocol version', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + + try { + dataContractTransition.verifyProtocolVersion(20); + expect(true).to.equal(false); + } catch (error) { + expect(false).to.equal(false); + } + }); + + it('should allow to get data contract', () => { + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + + const newDataContract = dataContractTransition.getDataContract(); + + expect(dataContract.bytes()).to.deep.equal(newDataContract.bytes()); + }); + }); + + describe('setters', () => { + it('should allow to set the data contract', () => { + const [dataContractBytes] = dataContractsBytes; + + const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + + const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + + const newDataContract = wasm.DataContractWASM.fromBytes(fromHexString(dataContractBytes), false, PlatformVersionWASM.PLATFORM_V1); + + dataContractTransition.setDataContract(newDataContract); + + expect(fromHexString(dataContractBytes)).to.deep.equal(newDataContract.bytes()); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/DistributionFunction.spec.mjs b/packages/wasm-dpp2/tests/unit/DistributionFunction.spec.mjs new file mode 100644 index 00000000000..70c26692fea --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/DistributionFunction.spec.mjs @@ -0,0 +1,420 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('DistributionFunction', function () { + describe('serialization / deserialization', function () { + it('shoulda allow to create FixedAmountDistribution', () => { + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111) + ) + + expect(distributionFunction.__wbg_ptr).to.not.equal(0) + }) + + it('shoulda allow to create Random', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Random( + BigInt(111), + BigInt(113) + ) + + expect(distributionFunction.__wbg_ptr).to.not.equal(0) + }) + + it('shoulda allow to create StepDecreasingAmount', () => { + const distributionFunction = wasm.DistributionFunctionWASM.StepDecreasingAmount( + 11, + 11, + 11, + undefined, + undefined, + BigInt(111), + BigInt(113), + BigInt(1) + ) + + expect(distributionFunction.__wbg_ptr).to.not.equal(0) + }) + + it('shoulda allow to create Stepwise', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Stepwise( + { + 11111111121: BigInt(111) + } + ) + + expect(distributionFunction.__wbg_ptr).to.not.equal(0) + }) + + it('shoulda allow to create Linear', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Linear( + BigInt(111), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.__wbg_ptr).to.not.equal(0) + }) + + it('shoulda allow to create Polynomial', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Polynomial( + BigInt(111), + BigInt(113), + BigInt(113), + BigInt(113), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.__wbg_ptr).to.not.equal(0) + }) + + it('shoulda allow to create Exponential', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Exponential( + BigInt(111), + BigInt(113), + BigInt(113), + BigInt(113), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.__wbg_ptr).to.not.equal(0) + }) + + it('shoulda allow to create Logarithmic', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Logarithmic( + BigInt(111), + BigInt(113), + BigInt(113), + BigInt(113), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.__wbg_ptr).to.not.equal(0) + }) + + it('shoulda allow to create InvertedLogarithmic', () => { + const distributionFunction = wasm.DistributionFunctionWASM.InvertedLogarithmic( + BigInt(111), + BigInt(113), + BigInt(113), + BigInt(113), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.__wbg_ptr).to.not.equal(0) + }) + }) + + describe('getters', function () { + describe('function name', function () { + it('FixedAmountDistribution', () => { + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111) + ) + + expect(distributionFunction.getFunctionName()).to.deep.equal('FixedAmount') + }) + + it('Random', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Random( + BigInt(111), + BigInt(113) + ) + + expect(distributionFunction.getFunctionName()).to.deep.equal('Random') + }) + + it('StepDecreasingAmount', () => { + const distributionFunction = wasm.DistributionFunctionWASM.StepDecreasingAmount( + 11, + 11, + 11, + undefined, + undefined, + BigInt(111), + BigInt(113), + BigInt(1) + ) + + expect(distributionFunction.getFunctionName()).to.deep.equal('StepDecreasingAmount') + }) + + it('Stepwise', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Stepwise( + { + 11111111121: BigInt(111) + } + ) + + expect(distributionFunction.getFunctionName()).to.deep.equal('Stepwise') + }) + + it('Linear', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Linear( + BigInt(111), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.getFunctionName()).to.deep.equal('Linear') + }) + + it('Polynomial', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Polynomial( + BigInt(111), + BigInt(113), + BigInt(113), + BigInt(113), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.getFunctionName()).to.deep.equal('Polynomial') + }) + + it('Exponential', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Exponential( + BigInt(111), + BigInt(113), + BigInt(113), + BigInt(113), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.getFunctionName()).to.deep.equal('Exponential') + }) + + it('Logarithmic', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Logarithmic( + BigInt(111), + BigInt(113), + BigInt(113), + BigInt(113), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.getFunctionName()).to.deep.equal('Logarithmic') + }) + + it('InvertedLogarithmic', () => { + const distributionFunction = wasm.DistributionFunctionWASM.InvertedLogarithmic( + BigInt(111), + BigInt(113), + BigInt(113), + BigInt(113), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.getFunctionName()).to.deep.equal('InvertedLogarithmic') + }) + }) + describe('function value', function () { + it('FixedAmountDistribution', () => { + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111) + ) + + expect(distributionFunction.getFunctionValue().amount).to.deep.equal(111n) + }) + + it('Random', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Random( + BigInt(111), + BigInt(113) + ) + + expect(distributionFunction.getFunctionValue().min).to.deep.equal(111n) + expect(distributionFunction.getFunctionValue().max).to.deep.equal(113n) + }) + + it('StepDecreasingAmount', () => { + const distributionFunction = wasm.DistributionFunctionWASM.StepDecreasingAmount( + 11, + 11, + 11, + undefined, + undefined, + BigInt(111), + BigInt(113), + BigInt(1) + ) + + expect(distributionFunction.getFunctionValue().stepCount).to.deep.equal(11) + expect(distributionFunction.getFunctionValue().decreasePerIntervalNumerator).to.deep.equal(11) + expect(distributionFunction.getFunctionValue().decreasePerIntervalDenominator).to.deep.equal(11) + expect(distributionFunction.getFunctionValue().startDecreasingOffset).to.deep.equal(undefined) + expect(distributionFunction.getFunctionValue().maxIntervalCount).to.deep.equal(undefined) + expect(distributionFunction.getFunctionValue().distributionStartAmount).to.deep.equal(111n) + expect(distributionFunction.getFunctionValue().trailingDistributionIntervalAmount).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().minValue).to.deep.equal(1n) + }) + + it('Stepwise', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Stepwise( + { + 11111111121: BigInt(111) + } + ) + + expect(distributionFunction.getFunctionValue()).to.deep.equal({ + 11111111121: BigInt(111) + }) + }) + + it('Linear', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Linear( + BigInt(111), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.getFunctionValue().a).to.deep.equal(111n) + expect(distributionFunction.getFunctionValue().d).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().startStep).to.deep.equal(undefined) + expect(distributionFunction.getFunctionValue().startingAmount).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().minValue).to.deep.equal(undefined) + expect(distributionFunction.getFunctionValue().maxValue).to.deep.equal(undefined) + }) + + it('Polynomial', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Polynomial( + BigInt(111), + BigInt(113), + BigInt(113), + BigInt(113), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.getFunctionValue().a).to.deep.equal(111n) + expect(distributionFunction.getFunctionValue().d).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().m).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().n).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().o).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().startMoment).to.deep.equal(undefined) + expect(distributionFunction.getFunctionValue().b).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().minValue).to.deep.equal(undefined) + expect(distributionFunction.getFunctionValue().maxValue).to.deep.equal(undefined) + }) + + it('Exponential', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Exponential( + BigInt(111), + BigInt(113), + BigInt(113), + BigInt(113), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.getFunctionValue().a).to.deep.equal(111n) + expect(distributionFunction.getFunctionValue().d).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().m).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().n).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().o).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().startMoment).to.deep.equal(undefined) + expect(distributionFunction.getFunctionValue().b).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().minValue).to.deep.equal(undefined) + expect(distributionFunction.getFunctionValue().maxValue).to.deep.equal(undefined) + }) + + it('Logarithmic', () => { + const distributionFunction = wasm.DistributionFunctionWASM.Logarithmic( + BigInt(111), + BigInt(113), + BigInt(113), + BigInt(113), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.getFunctionValue().a).to.deep.equal(111n) + expect(distributionFunction.getFunctionValue().d).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().m).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().n).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().o).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().startMoment).to.deep.equal(undefined) + expect(distributionFunction.getFunctionValue().b).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().minValue).to.deep.equal(undefined) + expect(distributionFunction.getFunctionValue().maxValue).to.deep.equal(undefined) + }) + + it('InvertedLogarithmic', () => { + const distributionFunction = wasm.DistributionFunctionWASM.InvertedLogarithmic( + BigInt(111), + BigInt(113), + BigInt(113), + BigInt(113), + BigInt(113), + undefined, + BigInt(113), + undefined, + undefined + ) + + expect(distributionFunction.getFunctionValue().a).to.deep.equal(111n) + expect(distributionFunction.getFunctionValue().d).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().m).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().n).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().o).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().startMoment).to.deep.equal(undefined) + expect(distributionFunction.getFunctionValue().b).to.deep.equal(113n) + expect(distributionFunction.getFunctionValue().minValue).to.deep.equal(undefined) + expect(distributionFunction.getFunctionValue().maxValue).to.deep.equal(undefined) + }) + }) + }) +}) diff --git a/packages/wasm-dpp2/tests/unit/Document.spec.mjs b/packages/wasm-dpp2/tests/unit/Document.spec.mjs new file mode 100644 index 00000000000..773205f8352 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/Document.spec.mjs @@ -0,0 +1,233 @@ +import getWasm from './helpers/wasm.js'; +import { + document, dataContractId, ownerId, documentTypeName, revision, dataContractValue, id, document2, documentBytes, +} from './mocks/Document/index.js'; +import { fromHexString } from './utils/hex.js'; + +let wasm; +let PlatformVersionWASM; + +before(async () => { + wasm = await getWasm(); + ({ PlatformVersionWASM } = wasm); +}); + +describe('Document', () => { + describe('serialization / deserialization', () => { + it('should allows to create Document from values', () => { + const dataContractIdentifier = new wasm.IdentifierWASM(dataContractId); + const ownerIdentifier = new wasm.IdentifierWASM(ownerId); + + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractIdentifier, ownerIdentifier); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + }); + + it('should allows to create Document from values with custom id', () => { + const dataContractIdentifier = new wasm.IdentifierWASM(dataContractId); + const ownerIdentifier = new wasm.IdentifierWASM(ownerId); + const identifier = new wasm.IdentifierWASM(id); + + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractIdentifier, ownerIdentifier, identifier); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + }); + + it('should allows to create Document from bytes and convert to bytes', () => { + const dataContract = wasm.DataContractWASM.fromValue(dataContractValue, false); + const documentInstance = wasm.DocumentWASM.fromBytes(fromHexString(documentBytes), dataContract, 'note'); + + const bytes = documentInstance.bytes(dataContract, PlatformVersionWASM.PLATFORM_V1); + + expect(documentInstance.dataContractId.base58()).to.equal(dataContract.id.base58()); + expect(bytes).to.deep.equal(fromHexString(documentBytes)); + expect(dataContract.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should return document id', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + expect(documentInstance.id.base58()).to.deep.equal(id); + }); + + it('should return owner id', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + expect(documentInstance.ownerId.base58()).to.deep.equal(ownerId); + }); + + it('should return data contract id', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + expect(documentInstance.dataContractId.base58()).to.deep.equal(dataContractId); + }); + + it('should return properties', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + expect(documentInstance.properties).to.deep.equal(document); + }); + + it('should return revision', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + expect(documentInstance.revision).to.deep.equal(revision); + }); + }); + + describe('setters', () => { + it('should allow to set document id', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + documentInstance.id = ownerId; + + expect(documentInstance.id.base58()).to.deep.equal(ownerId); + }); + + it('should allow to set document owner id', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + documentInstance.ownerId = id; + + expect(documentInstance.ownerId.base58()).to.deep.equal(id); + }); + + it('should allow to set entropy', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + const newEntropy = new Array(documentInstance.entropy.length).fill(0); + + documentInstance.entropy = newEntropy; + + expect(Array.from(documentInstance.entropy)).to.deep.equal(newEntropy); + }); + + it('should allow to set properties', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + documentInstance.properties = document2; + + expect(documentInstance.properties).to.deep.equal(document2); + }); + + it('should allow to set revision', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + const newRevision = BigInt(1000); + + documentInstance.revision = newRevision; + + expect(documentInstance.revision).to.deep.equal(newRevision); + }); + + it('should allow to set created at', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + const createdAt = BigInt(new Date(1123).getTime()); + + documentInstance.createdAt = createdAt; + + expect(documentInstance.createdAt).to.deep.equal(createdAt); + }); + + it('should allow to set updated at', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + const updatedAt = BigInt(new Date(1123).getTime()); + + documentInstance.updatedAt = updatedAt; + + expect(documentInstance.updatedAt).to.deep.equal(updatedAt); + }); + + it('should allow to set transferred at', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + const transferredAt = BigInt(new Date(11231).getTime()); + + documentInstance.transferredAt = transferredAt; + + expect(documentInstance.transferredAt).to.deep.equal(transferredAt); + }); + + it('should allow to set create at Block Height', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + const createdAtHeight = BigInt(9172); + + documentInstance.createdAtBlockHeight = createdAtHeight; + + expect(documentInstance.createdAtBlockHeight).to.deep.equal(createdAtHeight); + }); + + it('should allow to set updated at Block Height', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + const updatedAtHeight = BigInt(9172); + + documentInstance.updatedAtBlockHeight = updatedAtHeight; + + expect(documentInstance.updatedAtBlockHeight).to.deep.equal(updatedAtHeight); + }); + + it('should allow to set transferred at Block Height', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + const transferredAtHeight = BigInt(9172); + + documentInstance.transferredAtBlockHeight = transferredAtHeight; + + expect(documentInstance.transferredAtBlockHeight).to.deep.equal(transferredAtHeight); + }); + + it('should allow to set create at core Block Height', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + const createdAtHeight = 91721; + + documentInstance.createdAtCoreBlockHeight = createdAtHeight; + + expect(documentInstance.createdAtCoreBlockHeight).to.deep.equal(createdAtHeight); + }); + + it('should allow to set updated at Block Height', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + const updatedAtHeight = 91722; + + documentInstance.updatedAtCoreBlockHeight = updatedAtHeight; + + expect(documentInstance.updatedAtCoreBlockHeight).to.deep.equal(updatedAtHeight); + }); + + it('should allow to set transferred at Block Height', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + const transferredAtHeight = 91723; + + documentInstance.transferredAtCoreBlockHeight = transferredAtHeight; + + expect(documentInstance.transferredAtCoreBlockHeight).to.deep.equal(transferredAtHeight); + }); + + it('should allow to set document type name', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + + const newDocumentTypeName = 'bbbb'; + + documentInstance.documentTypeName = newDocumentTypeName; + + expect(documentInstance.documentTypeName).to.deep.equal(newDocumentTypeName); + }); + }); + + describe('static', () => { + it('should allow to generate id', () => { + const generatedId = wasm.DocumentWASM.generateId('note', ownerId, dataContractId); + + expect(Array.from(generatedId).length).to.equal(32); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs new file mode 100644 index 00000000000..3f4c16f2f41 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs @@ -0,0 +1,100 @@ +import getWasm from './helpers/wasm.js'; +import { + document, documentTypeName, revision, dataContractId, ownerId, id, +} from './mocks/Document/index.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +let documentInstance; +let createTransition; +let replaceTransition; + +describe('DocumentTransition', () => { + before(async () => { + documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + }); + + describe('serialization / deserialization', () => { + it('should allow to create from documents document_transitions', () => { + const documentTransition = createTransition.toDocumentTransition(); + + expect(documentTransition.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get action type', () => { + const documentTransition = createTransition.toDocumentTransition(); + + expect(documentTransition.actionType).to.equal('create'); + }); + + it('should allow to get dataContractId', () => { + const documentTransition = createTransition.toDocumentTransition(); + + expect(documentTransition.dataContractId.base58()).to.deep.equal(documentInstance.dataContractId.base58()); + }); + + it('should allow to get id', () => { + const documentTransition = createTransition.toDocumentTransition(); + + expect(documentTransition.id.base58()).to.deep.equal(documentInstance.id.base58()); + }); + + it('should allow to get documentTypeName', () => { + const documentTransition = createTransition.toDocumentTransition(); + + expect(documentTransition.documentTypeName).to.equal(documentTypeName); + }); + + it('should allow to get identityContractNonce', () => { + const documentTransition = createTransition.toDocumentTransition(); + + expect(documentTransition.identityContractNonce).to.equal(BigInt(1)); + }); + + it('should allow to get revision', () => { + const documentTransition = createTransition.toDocumentTransition(); + + expect(documentTransition.revision).to.equal(BigInt(1)); + }); + + it('should allow to get entropy', () => { + const documentTransition = createTransition.toDocumentTransition(); + + expect(documentTransition.entropy).to.deep.equal(documentInstance.entropy); + }); + }); + + describe('setters', () => { + it('should allow to set dataContractId', () => { + const documentTransition = createTransition.toDocumentTransition(); + + documentTransition.dataContractId = new Uint8Array(32); + + expect(documentTransition.dataContractId.bytes()).to.deep.equal(new Uint8Array(32)); + }); + + it('should allow to set identityContractNonce', () => { + const documentTransition = createTransition.toDocumentTransition(); + + documentTransition.identityContractNonce = BigInt(3333); + + expect(documentTransition.identityContractNonce).to.equal(BigInt(3333)); + }); + + it('should allow to set revision', () => { + const documentTransition = replaceTransition.toDocumentTransition(); + + documentTransition.revision = BigInt(123); + + expect(documentTransition.revision).to.equal(BigInt(123)); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs b/packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs new file mode 100644 index 00000000000..34d8bcd361e --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs @@ -0,0 +1,705 @@ +import getWasm from './helpers/wasm.js'; +import { + document, documentTypeName, revision, dataContractId, ownerId, id, +} from './mocks/Document/index.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('DocumentsTransitions', () => { + describe('serialization / deserialization', () => { + describe('document Create transition', () => { + it('should allow to create CreateTransition from document', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(createTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create Document Transition from Create transition', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = createTransition.toDocumentTransition(); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(createTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create Document Batch Transition from Document Transitions', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = createTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(createTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create state document_transitions from document and convert state transition to document batch', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = createTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + const st = batchTransition.toStateTransition(); + + const deserializedBatch = wasm.BatchTransitionWASM.fromStateTransition(st); + + const deserializedTransitions = deserializedBatch.transitions; + + expect(deserializedTransitions.length).to.equal(2); + + const deserializedPurchaseTransition = deserializedTransitions[0].toTransition().createTransition; + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(createTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchTransition.__wbg_ptr).to.not.equal(0); + expect(st.__wbg_ptr).to.not.equal(0); + expect(deserializedBatch.__wbg_ptr).to.not.equal(0); + expect(deserializedPurchaseTransition.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('document Delete transition', () => { + it('should allow to create DeleteTransition from document', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1)); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(deleteTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create Document Transition from Delete transition', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = deleteTransition.toDocumentTransition(); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(deleteTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create Document Batch Transition from Document Transitions', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = deleteTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(deleteTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create state document_transitions from document and convert state transition to document batch', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = deleteTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + const st = batchTransition.toStateTransition(); + + const deserializedBatch = wasm.BatchTransitionWASM.fromStateTransition(st); + + const deserializedTransitions = deserializedBatch.transitions; + + expect(deserializedTransitions.length).to.equal(2); + + const deserializedPurchaseTransition = deserializedTransitions[0].toTransition().deleteTransition; + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(deleteTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchTransition.__wbg_ptr).to.not.equal(0); + expect(st.__wbg_ptr).to.not.equal(0); + expect(deserializedBatch.__wbg_ptr).to.not.equal(0); + expect(deserializedPurchaseTransition.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('document Replace transition', () => { + it('should allow to create ReplaceTransition from document', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(replaceTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create Document Transition from Replace transition', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = replaceTransition.toDocumentTransition(); + + expect(replaceTransition.__wbg_ptr).to.not.equal(0); + expect(replaceTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create Document Batch Transition from Document Transitions', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = replaceTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(replaceTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create state document_transitions from document and convert state transition to document batch', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + + const documentTransition = replaceTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + const st = batchTransition.toStateTransition(); + + const deserializedBatch = wasm.BatchTransitionWASM.fromStateTransition(st); + + const deserializedTransitions = deserializedBatch.transitions; + + expect(deserializedTransitions.length).to.equal(2); + + const deserializedPurchaseTransition = deserializedTransitions[0].toTransition().replaceTransition; + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(replaceTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchTransition.__wbg_ptr).to.not.equal(0); + expect(st.__wbg_ptr).to.not.equal(0); + expect(deserializedBatch.__wbg_ptr).to.not.equal(0); + expect(deserializedPurchaseTransition.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('document Transfer transition', () => { + it('should allow to create ReplaceTransition from document', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(transferTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create Document Transition from Replace transition', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + + const documentTransition = transferTransition.toDocumentTransition(); + + expect(transferTransition.__wbg_ptr).to.not.equal(0); + expect(transferTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create Document Batch Transition from Document Transitions', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + + const documentTransition = transferTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(transferTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create state document_transitions from document and convert state transition to document batch', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + + const documentTransition = transferTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + const st = batchTransition.toStateTransition(); + + const deserializedBatch = wasm.BatchTransitionWASM.fromStateTransition(st); + + const deserializedTransitions = deserializedBatch.transitions; + + expect(deserializedTransitions.length).to.equal(2); + + const deserializedPurchaseTransition = deserializedTransitions[0].toTransition().transferTransition; + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(transferTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchTransition.__wbg_ptr).to.not.equal(0); + expect(st.__wbg_ptr).to.not.equal(0); + expect(deserializedBatch.__wbg_ptr).to.not.equal(0); + expect(deserializedPurchaseTransition.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('document UpdatePrice transition', () => { + it('should allow to create UpdatePriceTransition from document', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(updatePriceTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create Document Transition from UpdatePrice transition', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + const documentTransition = updatePriceTransition.toDocumentTransition(); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(updatePriceTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create Document Batch Transition from Document Transitions', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + const documentTransition = updatePriceTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(updatePriceTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create state document_transitions from document and convert state transition to document batch', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + const documentTransition = updatePriceTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + const st = batchTransition.toStateTransition(); + + const deserializedBatch = wasm.BatchTransitionWASM.fromStateTransition(st); + + const deserializedTransitions = deserializedBatch.transitions; + + expect(deserializedTransitions.length).to.equal(2); + + const deserializedPurchaseTransition = deserializedTransitions[0].toTransition().updatePriceTransition; + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(updatePriceTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchTransition.__wbg_ptr).to.not.equal(0); + expect(st.__wbg_ptr).to.not.equal(0); + expect(deserializedBatch.__wbg_ptr).to.not.equal(0); + expect(deserializedPurchaseTransition.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('document Purchase transition', () => { + it('should allow to create PurchaseTransition from document', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(purchaseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create Document Transition from PurchaseTransition transition', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + const documentTransition = purchaseTransition.toDocumentTransition(); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(purchaseTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create Document Batch Transition from Document Transitions', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + const documentTransition = purchaseTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(purchaseTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create state document_transitions from document and convert state transition to document batch', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + const documentTransition = purchaseTransition.toDocumentTransition(); + + const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + + const st = batchTransition.toStateTransition(); + + const deserializedBatch = wasm.BatchTransitionWASM.fromStateTransition(st); + + const deserializedTransitions = deserializedBatch.transitions; + + expect(deserializedTransitions.length).to.equal(2); + + const deserializedPurchaseTransition = deserializedTransitions[0].toTransition().purchaseTransition; + + expect(documentInstance.__wbg_ptr).to.not.equal(0); + expect(purchaseTransition.__wbg_ptr).to.not.equal(0); + expect(documentTransition.__wbg_ptr).to.not.equal(0); + expect(batchTransition.__wbg_ptr).to.not.equal(0); + expect(st.__wbg_ptr).to.not.equal(0); + expect(deserializedBatch.__wbg_ptr).to.not.equal(0); + expect(deserializedPurchaseTransition.__wbg_ptr).to.not.equal(0); + }); + }); + }); + describe('getters', () => { + describe('document Create transition', () => { + it('get data', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + expect(createTransition.data).to.deep.equal(document); + }); + + it('get base', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + expect(createTransition.base.constructor.name).to.equal('DocumentBaseTransitionWASM'); + }); + + it('get entropy', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + expect(createTransition.entropy).to.deep.equal(documentInstance.entropy); + }); + + it('get prefunded voting balance', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + expect(createTransition.prefundedVotingBalance).to.equal(undefined); + }); + }); + + describe('document Delete transition', () => { + it('get base', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1)); + + expect(deleteTransition.base.constructor.name).to.equal('DocumentBaseTransitionWASM'); + }); + }); + + describe('document Replace transition', () => { + it('get data', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + + expect(replaceTransition.data).to.deep.equal(document); + }); + + it('get base', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + + expect(replaceTransition.base.constructor.name).to.equal('DocumentBaseTransitionWASM'); + }); + + it('get revision', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + + expect(replaceTransition.revision).to.equal(BigInt(2)); + }); + }); + + describe('document Transfer transition', () => { + it('get base', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + + expect(transferTransition.base.constructor.name).to.equal('DocumentBaseTransitionWASM'); + }); + + it('get recipient', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + + expect(transferTransition.recipientId.base58()).to.deep.equal(documentInstance.ownerId.base58()); + }); + }); + + describe('document Update Price transition', () => { + it('get base', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + expect(updatePriceTransition.base.constructor.name).to.equal('DocumentBaseTransitionWASM'); + }); + + it('get price', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + expect(updatePriceTransition.price).to.deep.equal(BigInt(100)); + }); + }); + + describe('document Purchase transition', () => { + it('get base', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + expect(purchaseTransition.base.constructor.name).to.equal('DocumentBaseTransitionWASM'); + }); + + it('get price', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + expect(purchaseTransition.price).to.deep.equal(BigInt(100)); + }); + }); + }); + + describe('setters', () => { + describe('document Create transition', () => { + it('set data', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const newData = { message: 'bebra' }; + + createTransition.data = newData; + + expect(createTransition.data).to.deep.equal(newData); + }); + + it('set base', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const newBase = new wasm.DocumentBaseTransitionWASM( + documentInstance.id, + BigInt(12350), + 'bbbbb', + dataContractId, + ); + + createTransition.base = newBase; + + expect(createTransition.base.identityContractNonce).to.equal(newBase.identityContractNonce); + expect(newBase.__wbg_ptr).to.not.equal(0); + }); + + it('set entropy', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const newEntropy = new Uint8Array(32); + + createTransition.entropy = newEntropy; + + expect(createTransition.entropy).to.deep.equal(newEntropy); + }); + + it('set prefunded voting balance', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + + const newPrefundedVotingBalance = new wasm.PrefundedVotingBalanceWASM('note', BigInt(9999)); + + createTransition.prefundedVotingBalance = newPrefundedVotingBalance; + + expect(createTransition.prefundedVotingBalance.indexName).to.equal(newPrefundedVotingBalance.indexName); + expect(createTransition.prefundedVotingBalance.credits).to.equal(newPrefundedVotingBalance.credits); + }); + }); + + describe('document Delete transition', () => { + it('set base', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1)); + + const newBase = new wasm.DocumentBaseTransitionWASM( + documentInstance.id, + BigInt(12350), + 'bbbbb', + dataContractId, + ); + + deleteTransition.base = newBase; + + expect(deleteTransition.base.identityContractNonce).to.equal(newBase.identityContractNonce); + expect(newBase.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('document Replace transition', () => { + it('set data', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + + const newData = { message: 'bebra' }; + + replaceTransition.data = newData; + + expect(replaceTransition.data).to.deep.equal(newData); + }); + + it('set base', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + + const newBase = new wasm.DocumentBaseTransitionWASM( + documentInstance.id, + BigInt(12350), + 'bbbbb', + dataContractId, + ); + + replaceTransition.base = newBase; + + expect(replaceTransition.base.identityContractNonce).to.equal(newBase.identityContractNonce); + expect(newBase.__wbg_ptr).to.not.equal(0); + }); + + it('set revision', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + + replaceTransition.revision = BigInt(11); + + expect(replaceTransition.revision).to.equal(BigInt(11)); + }); + }); + + describe('document Transfer transition', () => { + it('set base', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + + const newBase = new wasm.DocumentBaseTransitionWASM( + documentInstance.id, + BigInt(12350), + 'bbbbb', + dataContractId, + ); + + transferTransition.base = newBase; + + expect(transferTransition.base.identityContractNonce).to.equal(newBase.identityContractNonce); + expect(newBase.__wbg_ptr).to.not.equal(0); + }); + + it('set recipient', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + + const newRecipient = new Uint8Array(32); + + transferTransition.recipientId = newRecipient; + + expect(transferTransition.recipientId.bytes()).to.deep.equal(newRecipient); + }); + }); + + describe('document Update Price transition', () => { + it('set base', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + const newBase = new wasm.DocumentBaseTransitionWASM( + documentInstance.id, + BigInt(12350), + 'bbbbb', + dataContractId, + ); + + updatePriceTransition.base = newBase; + + expect(updatePriceTransition.base.identityContractNonce).to.equal(newBase.identityContractNonce); + expect(newBase.__wbg_ptr).to.not.equal(0); + }); + + it('set price', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + updatePriceTransition.price = BigInt(1111); + + expect(updatePriceTransition.price).to.deep.equal(BigInt(1111)); + }); + }); + + describe('document Purchase transition', () => { + it('set base', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + const newBase = new wasm.DocumentBaseTransitionWASM( + documentInstance.id, + BigInt(12350), + 'bbbbb', + dataContractId, + ); + + purchaseTransition.base = newBase; + + expect(purchaseTransition.base.identityContractNonce).to.equal(newBase.identityContractNonce); + expect(newBase.__wbg_ptr).to.not.equal(0); + }); + + it('set price', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + purchaseTransition.price = BigInt(1111); + + expect(purchaseTransition.price).to.deep.equal(BigInt(1111)); + }); + + it('set revision', () => { + const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + + purchaseTransition.revision = BigInt(1111); + + expect(purchaseTransition.revision).to.deep.equal(BigInt(1111)); + }); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs b/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs new file mode 100644 index 00000000000..ad708f26003 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs @@ -0,0 +1,86 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +let identifierBytes; + +describe('Identifier', () => { + before(async () => { + identifierBytes = Uint8Array.from([9, 40, 40, 237, 192, 129, 211, 186, 26, 84, 240, 67, 37, 155, 148, 19, 104, 242, 199, 24, 136, 27, 6, 169, 211, 71, 136, 59, 33, 191, 227, 19]); + }); + + describe('serialization / deserialization', () => { + it('should allows to create Identifier from base58', () => { + const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + + expect(identifier.bytes()).to.deep.equal(identifierBytes); + }); + + it('should allows to create Identifier from base64', () => { + const identifier = wasm.IdentifierWASM.fromBase64('CSgo7cCB07oaVPBDJZuUE2jyxxiIGwap00eIOyG/4xM='); + + expect(identifier.bytes()).to.deep.equal(identifierBytes); + }); + + it('should allows to create Identifier from hex', () => { + const identifier = wasm.IdentifierWASM.fromHex('092828edc081d3ba1a54f043259b941368f2c718881b06a9d347883b21bfe313'); + + expect(identifier.bytes()).to.deep.equal(identifierBytes); + }); + + it('should allows to create Identifier from bytes', () => { + const identifier = wasm.IdentifierWASM.fromBytes(identifierBytes); + + expect(identifier.bytes()).to.deep.equal(identifierBytes); + }); + + it('should allows to create Identifier from Identifier', () => { + const identifier = wasm.IdentifierWASM.fromBytes(identifierBytes); + const identifier2 = new wasm.IdentifierWASM(identifier); + + expect(identifier2.bytes()).to.deep.equal(identifierBytes); + }); + + it('should allows to create Identifier from bytes in constructor', () => { + const identifier = new wasm.IdentifierWASM(identifierBytes); + + expect(identifier.bytes()).to.deep.equal(identifierBytes); + }); + + it('should allows to create Identifier from base58 in constructor', () => { + const identifier = new wasm.IdentifierWASM('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + + expect(identifier.bytes()).to.deep.equal(identifierBytes); + }); + }); + + describe('getters', () => { + it('should allow to get identifier base58', () => { + const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + + expect(identifier.base58()).to.equal('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + }); + + it('should allow to get identifier base64', () => { + const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + + expect(identifier.base64()).to.equal('CSgo7cCB07oaVPBDJZuUE2jyxxiIGwap00eIOyG/4xM='); + }); + + it('should allow to get identifier hex', () => { + const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + + expect(identifier.hex()).to.equal('092828edc081d3ba1a54f043259b941368f2c718881b06a9d347883b21bfe313'); + }); + + it('should allow to get identifier bytes', () => { + const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + + expect(identifier.bytes()).to.deep.equal(identifierBytes); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/Identity.spec.mjs b/packages/wasm-dpp2/tests/unit/Identity.spec.mjs new file mode 100644 index 00000000000..cd92b371cb9 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/Identity.spec.mjs @@ -0,0 +1,118 @@ +import getWasm from './helpers/wasm.js'; +import { + identifier, identityBytesWithoutKeys, identifierBytes, balance, revision, +} from './mocks/Identity/index.js'; +import { + keyId, purpose, securityLevel, keyType, binaryData, +} from './mocks/PublicKey/index.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('Identity', () => { + describe('serialization / deserialization', () => { + it('should generate identity from identifier', async () => { + const identity = new wasm.IdentityWASM(identifier); + + expect(identity.__wbg_ptr).to.not.equal(0); + }); + + it('should generate identity from identifier and return bytes', async () => { + const identity = new wasm.IdentityWASM(identifier); + + expect(Array.from(identity.bytes())).to.deep.equal(identityBytesWithoutKeys); + + const newIdentity = wasm.IdentityWASM.fromBytes(identity.bytes()); + + expect(identity.__wbg_ptr).to.not.equal(0); + expect(newIdentity.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should get id buffer', () => { + const identity = new wasm.IdentityWASM(identifier); + + expect(identity.id.bytes()).to.deep.equal(Uint8Array.from(identifierBytes)); + }); + + it('should get balance', () => { + const identity = new wasm.IdentityWASM(identifier); + + expect(identity.balance).to.deep.equal(BigInt(0)); + }); + + it('should get revision', () => { + const identity = new wasm.IdentityWASM(identifier); + + expect(identity.revision).to.deep.equal(BigInt(0)); + }); + + it('should get public keys', () => { + const identity = new wasm.IdentityWASM(identifier); + + const pubKey = new wasm.IdentityPublicKeyWASM( + keyId, + purpose, + securityLevel, + keyType, + false, + binaryData, + ); + + const pubKey2 = new wasm.IdentityPublicKeyWASM( + keyId + 1, + purpose, + securityLevel, + keyType, + false, + binaryData, + ); + + identity.addPublicKey(pubKey); + identity.addPublicKey(pubKey2); + + expect(identity.getPublicKeys().length).to.equal(2); + }); + }); + + describe('setters', () => { + it('should allows to set public key', () => { + const pubKey = new wasm.IdentityPublicKeyWASM( + keyId, + purpose, + securityLevel, + keyType, + false, + binaryData, + ); + + const identity = new wasm.IdentityWASM(identifier); + + identity.addPublicKey(pubKey); + + expect(identity.__wbg_ptr).to.not.equal(0); + + expect(identity.getPublicKeyById(keyId).bytes()).to.deep.equal(pubKey.bytes()); + }); + + it('should allows to set balance', () => { + const identity = new wasm.IdentityWASM(identifier); + + identity.balance = balance; + + expect(identity.balance).to.equal(balance); + }); + + it('should allows to set revision', () => { + const identity = new wasm.IdentityWASM(identifier); + + identity.revision = revision; + + expect(identity.revision).to.equal(revision); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs new file mode 100644 index 00000000000..a0051ef9865 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs @@ -0,0 +1,90 @@ +import getWasm from './helpers/wasm.js'; +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('IdentityCreateTransition', () => { + describe('serialization / deserialization', () => { + it('should allow to create transition', () => { + const transition = wasm.IdentityCreateTransitionWASM.default(1); + + expect(transition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to serialize to bytes', () => { + const transition = wasm.IdentityCreateTransitionWASM.default(1); + + const bytes = transition.bytes(); + + expect(bytes.length > 0).to.equal(true); + }); + + it('should allow to deserialize to bytes', () => { + const bytes = [0, 0, 0, 162, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 255, 1, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + + const transition = wasm.IdentityCreateTransitionWASM.fromBytes(bytes); + + expect(transition.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get userFeeIncrease', () => { + const transition = wasm.IdentityCreateTransitionWASM.default(1); + + expect(transition.userFeeIncrease).to.equal(0); + }); + + it('should allow to get AssetLock', () => { + const transition = wasm.IdentityCreateTransitionWASM.default(1); + + expect(transition.assetLock.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to get Identifier', () => { + const transition = wasm.IdentityCreateTransitionWASM.default(1); + + expect(transition.getIdentifier().base58()).to.equal('11111111111111111111111111111111'); + }); + + it('should allow to get PublicKeys', () => { + const transition = wasm.IdentityCreateTransitionWASM.default(1); + + expect(transition.publicKeys.length).to.equal(0); + }); + + it('should allow to get signature', () => { + const transition = wasm.IdentityCreateTransitionWASM.default(1); + + expect(transition.signature).to.deep.equal(Uint8Array.from([])); + }); + + it('should allow to get signable bytes', () => { + const transition = wasm.IdentityCreateTransitionWASM.default(1); + + expect(transition.getSignableBytes().length).to.equal(229); + }); + }); + + describe('setters', () => { + it('should allow to set the userFeeIncrease', () => { + const transition = wasm.IdentityCreateTransitionWASM.default(1); + + transition.userFeeIncrease = 100; + + expect(transition.userFeeIncrease).to.equal(100); + }); + + // TODO: Implement publickeys in creation setter + // it('should allow to set the publicKeys', function () { + // + // }) + + // TODO: Implement asset lock setter + // it('should allow to set the asset lock', function () { + // + // }) + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs new file mode 100644 index 00000000000..62a928aa2e2 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs @@ -0,0 +1,144 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('IdentityCreditTransferTransition', () => { + describe('serialization / deserialization', () => { + it('Should create IdentityCreditTransferTransition with empty platform version', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + expect(transition.__wbg_ptr).to.not.equal(0); + }); + + it('Should create IdentityCreditTransferTransition with non empty platform version', async () => { + const sender = new wasm.IdentifierWASM('11111111111111111111111111111111'); + const recipient = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), sender, recipient, BigInt(199), 'platform_v1'); + + expect(transition.__wbg_ptr).to.not.equal(0); + expect(sender.__wbg_ptr).to.not.equal(0); + expect(recipient.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('Should return recipientId', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + expect(transition.recipientId.base58()).to.deep.equal('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + }); + + it('Should return senderId', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + expect(transition.senderId.base58()).to.deep.equal('11111111111111111111111111111111'); + }); + + it('Should return amount', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + expect(transition.amount).to.deep.equal(BigInt(100)); + }); + + it('Should return nonce', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + expect(transition.nonce).to.deep.equal(BigInt(199)); + }); + + it('Should return signature', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + expect(transition.signature).to.deep.equal(Uint8Array.from([])); + }); + + it('Should return signaturePublicKeyId', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + expect(transition.signaturePublicKeyId).to.deep.equal(0); + }); + + it('Should return userFeeIncrease', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + expect(transition.userFeeIncrease).to.deep.equal(0); + }); + }); + + describe('setters', () => { + it('Should allow to set recipientId', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + const recipient = new wasm.IdentifierWASM('11111111111111111111111111111111'); + + transition.recipientId = recipient; + + expect(transition.recipientId.base58()).to.deep.equal('11111111111111111111111111111111'); + + transition.recipientId = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'; + + expect(transition.recipientId.base58()).to.deep.equal('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + expect(recipient.__wbg_ptr).to.not.equal(0); + }); + + it('Should return senderId', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + const sender = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + + transition.senderId = sender; + + expect(transition.senderId.base58()).to.deep.equal('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + + transition.senderId = '11111111111111111111111111111111'; + + expect(sender.__wbg_ptr).to.not.equal(0); + expect(transition.senderId.base58()).to.deep.equal('11111111111111111111111111111111'); + }); + + it('Should return amount', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + transition.amount = BigInt(199); + + expect(transition.amount).to.deep.equal(BigInt(199)); + }); + + it('Should return nonce', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + transition.nonce = BigInt(1); + + expect(transition.nonce).to.deep.equal(BigInt(1)); + }); + + it('Should return signature', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + transition.signature = [1, 1]; + + expect(transition.signature).to.deep.equal(Uint8Array.from([1, 1])); + }); + + it('Should return signaturePublicKeyId', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + transition.signaturePublicKeyId = 11; + + expect(transition.signaturePublicKeyId).to.deep.equal(11); + }); + + it('Should return userFeeIncrease', async () => { + const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + + transition.userFeeIncrease = 11; + + expect(transition.userFeeIncrease).to.deep.equal(11); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs new file mode 100644 index 00000000000..6ccaf16721e --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs @@ -0,0 +1,190 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('IdentityCreditWithdrawalTransition', () => { + describe('serialization / deserialization', () => { + it('Should allow to create IdentityCreditWithdrawalTransition', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + expect(identifier.__wbg_ptr).to.not.equal(0); + expect(script.__wbg_ptr).to.not.equal(0); + expect(transition.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('Should allow to get outputScript', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + expect(transition.outputScript.toString()).to.deep.equal('dqkUAQEBAQEBAQEBAQEBAQEBAQEBAQGIrA=='); + }); + + it('Should allow to get pooling', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + expect(transition.pooling).to.deep.equal('Never'); + }); + + it('Should allow to get identityId', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + expect(transition.identityId.base58()).to.deep.equal(identifier.base58()); + }); + + it('Should allow to get userFeeIncrease', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + expect(transition.userFeeIncrease).to.deep.equal(1); + }); + + it('Should allow to get nonce', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + expect(transition.nonce).to.deep.equal(BigInt(1)); + }); + + it('Should allow to get amount', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + expect(transition.amount).to.deep.equal(BigInt(111)); + }); + + it('Should allow to get signature', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + expect(transition.signature).to.deep.equal(Uint8Array.from([])); + }); + + it('Should allow to get signaturePublicKeyId', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + expect(transition.signaturePublicKeyId).to.deep.equal(0); + }); + }); + + describe('setters', () => { + it('Should allow to set outputScript', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + const script2 = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + transition.outputScript = script2; + + expect(transition.outputScript.toString()).to.deep.equal(script2.toString()); + }); + + it('Should allow to set pooling', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + transition.pooling = 'Standard'; + + expect(transition.pooling).to.deep.equal('Standard'); + }); + + it('Should allow to set identityId', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + const identifier2 = new wasm.IdentifierWASM('11SAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + + transition.identityId = identifier2; + + expect(transition.identityId.base58()).to.deep.equal(identifier2.base58()); + }); + + it('Should allow to set userFeeIncrease', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + transition.userFeeIncrease = 999; + + expect(transition.userFeeIncrease).to.deep.equal(999); + }); + + it('Should allow to set nonce', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + transition.nonce = BigInt(1111); + + expect(transition.nonce).to.deep.equal(BigInt(1111)); + }); + + it('Should allow to get amount', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + transition.amount = BigInt(2222); + + expect(transition.amount).to.deep.equal(BigInt(2222)); + }); + + it('Should allow to get signature', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + transition.signature = Uint8Array.from([1, 2, 3]); + + expect(transition.signature).to.deep.equal(Uint8Array.from([1, 2, 3])); + }); + + it('Should allow to get signaturePublicKeyId', () => { + const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + + const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + + transition.signaturePublicKeyId = 11; + + expect(transition.signaturePublicKeyId).to.deep.equal(11); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/IdentityPublicKey.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityPublicKey.spec.mjs new file mode 100644 index 00000000000..5301ceea854 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/IdentityPublicKey.spec.mjs @@ -0,0 +1,135 @@ +import getWasm from './helpers/wasm.js'; +import { wif } from './mocks/PrivateKey/index.js'; +import { + keyId, purpose, securityLevel, keyType, binaryData, securityLevelSet, keyIdSet, purposeSet, keyTypeSet, binaryDataSet, +} from './mocks/PublicKey/index.js'; +import { toHexString } from './utils/hex.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('PublicKey', () => { + describe('serialization / deserialization', () => { + it('should generate public key from values with type ECDSA_SECP256K1', () => { + const pubKey = new wasm.IdentityPublicKeyWASM( + keyId, + purpose, + securityLevel, + keyType, + false, + binaryData, + ); + + expect(pubKey.__wbg_ptr).to.not.equal(0); + }); + + it('should generate public key from values with type ECDSA_SECP256K1 and generate new from self bytes', () => { + const pubKey = new wasm.IdentityPublicKeyWASM( + keyId, + purpose, + securityLevel, + keyType, + false, + binaryData, + ); + + const bytes = pubKey.bytes(); + + const newPubKey = wasm.IdentityPublicKeyWASM.fromBytes(Array.from(bytes)); + + expect(pubKey.__wbg_ptr).to.not.equal(0); + expect(newPubKey.__wbg_ptr).to.not.equal(0); + + expect(pubKey.keyId).to.equal(newPubKey.keyId); + expect(pubKey.purpose).to.equal(newPubKey.purpose); + expect(pubKey.securityLevel).to.equal(newPubKey.securityLevel); + expect(pubKey.keyType).to.equal(newPubKey.keyType); + expect(pubKey.readOnly).to.equal(newPubKey.readOnly); + expect(pubKey.data).to.equal(newPubKey.data); + + expect(pubKey.bytes()).to.deep.equal(newPubKey.bytes()); + + expect(pubKey.__wbg_ptr).to.not.equal(0); + expect(newPubKey.__wbg_ptr).to.not.equal(0); + }); + + it('should return hash of key', () => { + const pubKey = new wasm.IdentityPublicKeyWASM( + keyId, + purpose, + securityLevel, + keyType, + false, + binaryData, + ); + + const hash = pubKey.getPublicKeyHash(); + + expect(hash).to.deep.equal(toHexString([211, 114, 240, 150, 37, 159, 114, 104, 110, 24, 102, 61, 125, 181, 248, 98, 52, 221, 111, 85])); + }); + }); + describe('getters', () => { + it('should generate public key from values with type ECDSA_SECP256K1 and return all fields', () => { + const pubKey = new wasm.IdentityPublicKeyWASM( + keyId, + purpose, + securityLevel, + keyType, + false, + binaryData, + ); + + expect(pubKey.keyId).to.equal(keyId); + expect(pubKey.purpose).to.equal('AUTHENTICATION'); + expect(pubKey.securityLevel).to.equal('CRITICAL'); + expect(pubKey.keyType).to.equal('ECDSA_SECP256K1'); + expect(pubKey.readOnly).to.equal(false); + expect(pubKey.data).to.equal(binaryData); + }); + + it('should allow to validate private key', () => { + const pubKey = new wasm.IdentityPublicKeyWASM( + keyId, + purpose, + securityLevel, + keyType, + false, + binaryData, + ); + + const privateKey = wasm.PrivateKeyWASM.fromWIF(wif); + + expect(pubKey.validatePrivateKey(privateKey.bytes(), wasm.NetworkWASM.Mainnet)).to.equal(false); + }); + }); + + describe('setters', () => { + it('should generate public key from values with type ECDSA_SECP256K1 and return all fields and set another fields', () => { + const pubKey = new wasm.IdentityPublicKeyWASM( + keyId, + purpose, + securityLevel, + keyType, + false, + binaryData, + ); + + pubKey.keyId = keyIdSet; + pubKey.purpose = purposeSet; + pubKey.securityLevel = securityLevelSet; + pubKey.keyType = keyTypeSet; + pubKey.readOnly = true; + pubKey.data = binaryDataSet; + + expect(pubKey.keyId).to.equal(keyIdSet); + expect(pubKey.purpose).to.equal('ENCRYPTION'); + expect(pubKey.securityLevel).to.equal('HIGH'); + expect(pubKey.keyType).to.equal('ECDSA_HASH160'); + expect(pubKey.readOnly).to.equal(true); + expect(pubKey.data).to.equal(binaryDataSet); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs new file mode 100644 index 00000000000..55b9cd46e84 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs @@ -0,0 +1,129 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('IdentityTopUpTransition', () => { + describe('serialization / deserialization', () => { + it('should allow to create IdentityTopUpTransition', () => { + const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + // instant lock + [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], + // transaction + [3, 0, 8, 0, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 106, 71, 48, 68, 2, 32, 2, 146, 73, 163, 223, 124, 140, 225, 109, 126, 239, 87, 105, 184, 118, 87, 182, 100, 182, 6, 15, 200, 26, 44, 33, 215, 165, 110, 211, 232, 245, 233, 2, 32, 69, 161, 168, 128, 101, 26, 171, 20, 63, 30, 219, 87, 23, 4, 142, 115, 73, 73, 170, 203, 46, 187, 149, 32, 210, 171, 46, 136, 253, 188, 36, 12, 1, 33, 2, 144, 231, 28, 153, 30, 92, 52, 10, 111, 47, 107, 74, 225, 237, 151, 33, 188, 184, 247, 121, 70, 135, 174, 31, 160, 16, 216, 239, 225, 103, 88, 112, 255, 255, 255, 255, 2, 64, 66, 15, 0, 0, 0, 0, 0, 2, 106, 0, 216, 154, 230, 5, 0, 0, 0, 0, 25, 118, 169, 20, 229, 154, 45, 140, 145, 114, 18, 52, 205, 13, 179, 84, 94, 174, 149, 207, 101, 115, 51, 240, 136, 172, 0, 0, 0, 0, 36, 1, 1, 64, 66, 15, 0, 0, 0, 0, 0, 25, 118, 169, 20, 176, 213, 107, 82, 203, 147, 209, 128, 255, 63, 69, 219, 41, 250, 232, 254, 185, 168, 85, 184, 136, 172], + // output index + 0, + ); + + const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + + expect(transition.__wbg_ptr).to.not.equal(0); + expect(assetLockProof.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to return userFeeIncrease', () => { + const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + // instant lock + [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], + // transaction + [3, 0, 8, 0, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 106, 71, 48, 68, 2, 32, 2, 146, 73, 163, 223, 124, 140, 225, 109, 126, 239, 87, 105, 184, 118, 87, 182, 100, 182, 6, 15, 200, 26, 44, 33, 215, 165, 110, 211, 232, 245, 233, 2, 32, 69, 161, 168, 128, 101, 26, 171, 20, 63, 30, 219, 87, 23, 4, 142, 115, 73, 73, 170, 203, 46, 187, 149, 32, 210, 171, 46, 136, 253, 188, 36, 12, 1, 33, 2, 144, 231, 28, 153, 30, 92, 52, 10, 111, 47, 107, 74, 225, 237, 151, 33, 188, 184, 247, 121, 70, 135, 174, 31, 160, 16, 216, 239, 225, 103, 88, 112, 255, 255, 255, 255, 2, 64, 66, 15, 0, 0, 0, 0, 0, 2, 106, 0, 216, 154, 230, 5, 0, 0, 0, 0, 25, 118, 169, 20, 229, 154, 45, 140, 145, 114, 18, 52, 205, 13, 179, 84, 94, 174, 149, 207, 101, 115, 51, 240, 136, 172, 0, 0, 0, 0, 36, 1, 1, 64, 66, 15, 0, 0, 0, 0, 0, 25, 118, 169, 20, 176, 213, 107, 82, 203, 147, 209, 128, 255, 63, 69, 219, 41, 250, 232, 254, 185, 168, 85, 184, 136, 172], + // output index + 0, + ); + + const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + + expect(transition.userFeeIncrease).to.deep.equal(11); + }); + + it('should allow to return identityIdentifier', () => { + const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + // instant lock + [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], + // transaction + [3, 0, 8, 0, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 106, 71, 48, 68, 2, 32, 2, 146, 73, 163, 223, 124, 140, 225, 109, 126, 239, 87, 105, 184, 118, 87, 182, 100, 182, 6, 15, 200, 26, 44, 33, 215, 165, 110, 211, 232, 245, 233, 2, 32, 69, 161, 168, 128, 101, 26, 171, 20, 63, 30, 219, 87, 23, 4, 142, 115, 73, 73, 170, 203, 46, 187, 149, 32, 210, 171, 46, 136, 253, 188, 36, 12, 1, 33, 2, 144, 231, 28, 153, 30, 92, 52, 10, 111, 47, 107, 74, 225, 237, 151, 33, 188, 184, 247, 121, 70, 135, 174, 31, 160, 16, 216, 239, 225, 103, 88, 112, 255, 255, 255, 255, 2, 64, 66, 15, 0, 0, 0, 0, 0, 2, 106, 0, 216, 154, 230, 5, 0, 0, 0, 0, 25, 118, 169, 20, 229, 154, 45, 140, 145, 114, 18, 52, 205, 13, 179, 84, 94, 174, 149, 207, 101, 115, 51, 240, 136, 172, 0, 0, 0, 0, 36, 1, 1, 64, 66, 15, 0, 0, 0, 0, 0, 25, 118, 169, 20, 176, 213, 107, 82, 203, 147, 209, 128, 255, 63, 69, 219, 41, 250, 232, 254, 185, 168, 85, 184, 136, 172], + // output index + 0, + ); + + const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + + expect(transition.identityIdentifier.base58()).to.deep.equal('B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'); + }); + + it('should allow to return signature', () => { + const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + // instant lock + [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], + // transaction + [3, 0, 8, 0, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 106, 71, 48, 68, 2, 32, 2, 146, 73, 163, 223, 124, 140, 225, 109, 126, 239, 87, 105, 184, 118, 87, 182, 100, 182, 6, 15, 200, 26, 44, 33, 215, 165, 110, 211, 232, 245, 233, 2, 32, 69, 161, 168, 128, 101, 26, 171, 20, 63, 30, 219, 87, 23, 4, 142, 115, 73, 73, 170, 203, 46, 187, 149, 32, 210, 171, 46, 136, 253, 188, 36, 12, 1, 33, 2, 144, 231, 28, 153, 30, 92, 52, 10, 111, 47, 107, 74, 225, 237, 151, 33, 188, 184, 247, 121, 70, 135, 174, 31, 160, 16, 216, 239, 225, 103, 88, 112, 255, 255, 255, 255, 2, 64, 66, 15, 0, 0, 0, 0, 0, 2, 106, 0, 216, 154, 230, 5, 0, 0, 0, 0, 25, 118, 169, 20, 229, 154, 45, 140, 145, 114, 18, 52, 205, 13, 179, 84, 94, 174, 149, 207, 101, 115, 51, 240, 136, 172, 0, 0, 0, 0, 36, 1, 1, 64, 66, 15, 0, 0, 0, 0, 0, 25, 118, 169, 20, 176, 213, 107, 82, 203, 147, 209, 128, 255, 63, 69, 219, 41, 250, 232, 254, 185, 168, 85, 184, 136, 172], + // output index + 0, + ); + + const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + + expect(transition.signature).to.deep.equal(Uint8Array.from([])); + }); + }); + + describe('setters', () => { + it('should allow to set userFeeIncrease', () => { + const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + // instant lock + [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], + // transaction + [3, 0, 8, 0, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 106, 71, 48, 68, 2, 32, 2, 146, 73, 163, 223, 124, 140, 225, 109, 126, 239, 87, 105, 184, 118, 87, 182, 100, 182, 6, 15, 200, 26, 44, 33, 215, 165, 110, 211, 232, 245, 233, 2, 32, 69, 161, 168, 128, 101, 26, 171, 20, 63, 30, 219, 87, 23, 4, 142, 115, 73, 73, 170, 203, 46, 187, 149, 32, 210, 171, 46, 136, 253, 188, 36, 12, 1, 33, 2, 144, 231, 28, 153, 30, 92, 52, 10, 111, 47, 107, 74, 225, 237, 151, 33, 188, 184, 247, 121, 70, 135, 174, 31, 160, 16, 216, 239, 225, 103, 88, 112, 255, 255, 255, 255, 2, 64, 66, 15, 0, 0, 0, 0, 0, 2, 106, 0, 216, 154, 230, 5, 0, 0, 0, 0, 25, 118, 169, 20, 229, 154, 45, 140, 145, 114, 18, 52, 205, 13, 179, 84, 94, 174, 149, 207, 101, 115, 51, 240, 136, 172, 0, 0, 0, 0, 36, 1, 1, 64, 66, 15, 0, 0, 0, 0, 0, 25, 118, 169, 20, 176, 213, 107, 82, 203, 147, 209, 128, 255, 63, 69, 219, 41, 250, 232, 254, 185, 168, 85, 184, 136, 172], + // output index + 0, + ); + + const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + + transition.userFeeIncrease = 21; + + expect(transition.userFeeIncrease).to.deep.equal(21); + }); + + it('should allow to set identityIdentifier', () => { + const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + // instant lock + [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], + // transaction + [3, 0, 8, 0, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 106, 71, 48, 68, 2, 32, 2, 146, 73, 163, 223, 124, 140, 225, 109, 126, 239, 87, 105, 184, 118, 87, 182, 100, 182, 6, 15, 200, 26, 44, 33, 215, 165, 110, 211, 232, 245, 233, 2, 32, 69, 161, 168, 128, 101, 26, 171, 20, 63, 30, 219, 87, 23, 4, 142, 115, 73, 73, 170, 203, 46, 187, 149, 32, 210, 171, 46, 136, 253, 188, 36, 12, 1, 33, 2, 144, 231, 28, 153, 30, 92, 52, 10, 111, 47, 107, 74, 225, 237, 151, 33, 188, 184, 247, 121, 70, 135, 174, 31, 160, 16, 216, 239, 225, 103, 88, 112, 255, 255, 255, 255, 2, 64, 66, 15, 0, 0, 0, 0, 0, 2, 106, 0, 216, 154, 230, 5, 0, 0, 0, 0, 25, 118, 169, 20, 229, 154, 45, 140, 145, 114, 18, 52, 205, 13, 179, 84, 94, 174, 149, 207, 101, 115, 51, 240, 136, 172, 0, 0, 0, 0, 36, 1, 1, 64, 66, 15, 0, 0, 0, 0, 0, 25, 118, 169, 20, 176, 213, 107, 82, 203, 147, 209, 128, 255, 63, 69, 219, 41, 250, 232, 254, 185, 168, 85, 184, 136, 172], + // output index + 0, + ); + + const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + + const identifier = new wasm.IdentifierWASM('777cE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'); + + transition.identityIdentifier = identifier; + + expect(transition.identityIdentifier.base58()).to.deep.equal('777cE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'); + }); + + it('should allow to set signature', () => { + const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + // instant lock + [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], + // transaction + [3, 0, 8, 0, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 106, 71, 48, 68, 2, 32, 2, 146, 73, 163, 223, 124, 140, 225, 109, 126, 239, 87, 105, 184, 118, 87, 182, 100, 182, 6, 15, 200, 26, 44, 33, 215, 165, 110, 211, 232, 245, 233, 2, 32, 69, 161, 168, 128, 101, 26, 171, 20, 63, 30, 219, 87, 23, 4, 142, 115, 73, 73, 170, 203, 46, 187, 149, 32, 210, 171, 46, 136, 253, 188, 36, 12, 1, 33, 2, 144, 231, 28, 153, 30, 92, 52, 10, 111, 47, 107, 74, 225, 237, 151, 33, 188, 184, 247, 121, 70, 135, 174, 31, 160, 16, 216, 239, 225, 103, 88, 112, 255, 255, 255, 255, 2, 64, 66, 15, 0, 0, 0, 0, 0, 2, 106, 0, 216, 154, 230, 5, 0, 0, 0, 0, 25, 118, 169, 20, 229, 154, 45, 140, 145, 114, 18, 52, 205, 13, 179, 84, 94, 174, 149, 207, 101, 115, 51, 240, 136, 172, 0, 0, 0, 0, 36, 1, 1, 64, 66, 15, 0, 0, 0, 0, 0, 25, 118, 169, 20, 176, 213, 107, 82, 203, 147, 209, 128, 255, 63, 69, 219, 41, 250, 232, 254, 185, 168, 85, 184, 136, 172], + // output index + 0, + ); + + const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + + transition.signature = Uint8Array.from([1, 1, 1]); + + expect(transition.signature).to.deep.equal(Uint8Array.from([1, 1, 1])); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs new file mode 100644 index 00000000000..14d68c7320a --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs @@ -0,0 +1,139 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('IdentityUpdateTransition', () => { + describe('serialization / deserialization', () => { + it('Should create IdentityUpdateTransition', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], []); + + expect(transition.__wbg_ptr).to.not.equal(0); + }); + + it('Should create IdentityUpdateTransition with key', () => { + const key = new wasm.IdentityPublicKeyInCreationWASM(1, 'system', 'master', 'ECDSA_SECP256K1', false, [], []); + + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [key], []); + + expect(transition.__wbg_ptr).to.not.equal(0); + expect(key.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('Should return revision', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], []); + + expect(transition.revision).to.deep.equal(BigInt(1)); + }); + + it('Should return nonce', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], []); + + expect(transition.nonce).to.deep.equal(BigInt(1)); + }); + + it('Should return identityIdentifier', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], []); + + expect(transition.identityIdentifier.base58()).to.deep.equal('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3'); + }); + + it('Should return publicKeyIdsToDisable', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + + expect(Array.from(transition.publicKeyIdsToDisable)).to.deep.equal([11]); + }); + + it('Should return publicKeyIdsToAdd', () => { + const key = new wasm.IdentityPublicKeyInCreationWASM(1, 'system', 'master', 'ECDSA_SECP256K1', false, [], []); + + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [key], [11]); + + expect(transition.publicKeyIdsToAdd.length).to.deep.equal(1); + }); + + it('Should return userFeeIncrease', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11], 1); + + expect(transition.userFeeIncrease).to.deep.equal(1); + }); + + it('Should return signature', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11], 1); + + expect(transition.signature).to.deep.equal(Uint8Array.from([])); + }); + + it('Should return signature public key id', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + + expect(transition.signaturePublicKeyId).to.deep.equal(0); + }); + }); + + describe('setters', () => { + it('Should allow to set identityIdentifier', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + + transition.identityIdentifier = '11Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3'; + + expect(transition.identityIdentifier.base58()).to.deep.equal('11Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3'); + }); + + it('Should allow to set revision', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + + transition.revision = BigInt(11111); + + expect(transition.revision).to.deep.equal(BigInt(11111)); + }); + + it('Should allow to set nonce', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + + transition.nonce = BigInt(11111); + + expect(transition.nonce).to.deep.equal(BigInt(11111)); + }); + + it('Should allow to set publicKeyIdsToDisable', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + + transition.publicKeyIdsToDisable = [1, 2, 3, 4]; + + expect(transition.publicKeyIdsToDisable).to.deep.equal(Uint32Array.from([1, 2, 3, 4])); + }); + + it('Should allow to set publicKeyIdsToAdd', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + + const key = new wasm.IdentityPublicKeyInCreationWASM(1, 'system', 'master', 'ECDSA_SECP256K1', false, [], []); + + transition.publicKeyIdsToAdd = [key, key]; + + expect(transition.publicKeyIdsToAdd.length).to.deep.equal(2); + expect(key.__wbg_ptr).to.not.equal(0); + }); + + it('Should allow to set signature', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + + transition.signature = [0, 1, 2, 3, 5]; + + expect(transition.signature).to.deep.equal(Uint8Array.from([0, 1, 2, 3, 5])); + }); + + it('Should allow to set signature public key id', () => { + const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + + transition.signaturePublicKeyId = 11; + + expect(transition.signaturePublicKeyId).to.deep.equal(11); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/InstantLockProof.spec.mjs b/packages/wasm-dpp2/tests/unit/InstantLockProof.spec.mjs new file mode 100644 index 00000000000..7486a2d758c --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/InstantLockProof.spec.mjs @@ -0,0 +1,95 @@ +import getWasm from './helpers/wasm.js'; +import { instantLockBytes, transactionBytes } from './mocks/Locks/index.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('InstantLock', () => { + describe('serialization / deserialization', () => { + it('should allow to create InstantLock from values', () => { + const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + + expect(instantLockProof.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to convert to object', () => { + const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + + const expected = { + instantLock: instantLockBytes, + transaction: transactionBytes, + outputIndex: 0, + }; + + expect(instantLockProof.toObject()).to.deep.equal(expected); + }); + + it('should allow to create from object', () => { + const lockObject = { + instantLock: instantLockBytes, + transaction: transactionBytes, + outputIndex: 0, + }; + + const instantLockProof = wasm.InstantAssetLockProofWASM.fromObject(lockObject); + + expect(instantLockProof.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get output', () => { + const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + + expect(instantLockProof.getOutput().constructor.name).to.deep.equal('TxOutWASM'); + }); + + it('should allow to convert to get OutPoint', () => { + const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + + expect(instantLockProof.getOutPoint().constructor.name).to.deep.equal('OutPointWASM'); + }); + + it('should allow to get output index', () => { + const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + + expect(instantLockProof.outputIndex).to.deep.equal(0); + }); + + it('should allow to get instant lock', () => { + const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + + expect(instantLockProof.instantLock.constructor.name).to.deep.equal('InstantLockWASM'); + }); + }); + + describe('setters', () => { + it('should allow to set output index', () => { + const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + + instantLockProof.outputIndex = 12; + + expect(instantLockProof.outputIndex).to.deep.equal(12); + }); + + it('should allow to set instant lock', () => { + const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + + const newInstantLockProof = new wasm.InstantLockWASM( + 0, + [], + 'dbdb604952d08184b55d48c915ed78aadc81dbc5cc98e8b4821abe5b4bbcbecb', + '00000000000000151e0fe3ab9a12c57402153c9f476236148364ec4337213101', + 'a9f131626c49a2f183b7a2f563ad1dc50ac8220190dbedb805209b608eb864e01d62f18bc9faa60a8b8a27f5a0c7c8b914fa3a14360a2f25558ee0e0a693b18faccbb59ec39b9b3cae430e0b76eb080752ce103df76537a1a583680a5914529d', + ); + + instantLockProof.instantLock = newInstantLockProof; + + expect(instantLockProof.instantLock.version).to.deep.equal(0); + expect(newInstantLockProof.__wbg_ptr).to.not.equal(0); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs b/packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs new file mode 100644 index 00000000000..76732373160 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs @@ -0,0 +1,53 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('OutPoint', () => { + describe('serialization / deserialization', () => { + it('should allow to create from values', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + + expect(outpoint.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create from bytes', () => { + const txIdBytes = Buffer.from('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 'hex'); + + // 32 bytes for txId and 4 bytes for vout + const bytes = [...txIdBytes.reverse(), ...[0, 0, 0, 1].reverse()]; + + const outpoint = wasm.OutPointWASM.fromBytes(bytes); + + expect(outpoint.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get txid', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + + expect(outpoint.getTXID()).to.equal('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d'); + }); + + it('should allow to get VOUT', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + + expect(outpoint.getVOUT()).to.equal(1); + }); + + it('should allow to get bytes', () => { + const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + + const txIdBytes = Buffer.from('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 'hex'); + + // 32 bytes for txId and 4 bytes for vout + const bytes = [...txIdBytes.reverse(), ...[0, 0, 0, 1].reverse()]; + + expect(outpoint.bytes()).to.deep.equal(Uint8Array.from(bytes)); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs b/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs new file mode 100644 index 00000000000..590d1e5a27a --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs @@ -0,0 +1,71 @@ +import getWasm from './helpers/wasm.js'; +import { wif, bytes, publicKeyHash } from './mocks/PrivateKey/index.js'; +import { fromHexString, toHexString } from './utils/hex.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('PrivateKey', () => { + describe('serialization / deserialization', () => { + it('should allows to create PrivateKey from wif', () => { + const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + + expect(pkey.__wbg_ptr).to.not.equal(0); + }); + + it('should allows to create PrivateKey from bytes', () => { + const pkey = wasm.PrivateKeyWASM.fromBytes(fromHexString(bytes), 'Mainnet'); + + expect(pkey.__wbg_ptr).to.not.equal(0); + }); + + it('should allows to create PrivateKey from hex', () => { + const pkey = wasm.PrivateKeyWASM.fromBytes(fromHexString(bytes), 'Mainnet'); + + const pkeyFromHex = wasm.PrivateKeyWASM.fromHex(bytes, 'Mainnet'); + + expect(pkey.bytes()).to.deep.equal(pkeyFromHex.bytes()); + }); + + it('should allow to create PrivateKey from wif and read value in wif', () => { + const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + + expect(pkey.WIF()).to.equal(wif); + }); + + it('should allow to create PrivateKey from wif and write value in bytes', () => { + const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + + expect(pkey.bytes()).to.deep.equal(fromHexString(bytes)); + }); + }); + + describe('getters', () => { + it('should allow to get key wif', () => { + const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + + expect(pkey.WIF()).to.equal(wif); + }); + + it('should allow to get key bytes', () => { + const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + + expect(toHexString(pkey.bytes())).to.equal(bytes); + }); + + it('should allow to get key hex', () => { + const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + + expect(pkey.hex().toLowerCase()).to.equal(bytes); + }); + + it('should allow to get public key hash', () => { + const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + + expect(pkey.getPublicKeyHash()).to.deep.equal(publicKeyHash); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/PublicKeyInCreation.spec.mjs b/packages/wasm-dpp2/tests/unit/PublicKeyInCreation.spec.mjs new file mode 100644 index 00000000000..b2de85073fd --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/PublicKeyInCreation.spec.mjs @@ -0,0 +1,256 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('InstantLock', () => { + describe('serialization / deserialization', () => { + it('should allow to create from values', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + expect(publicKeyInCreation.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create from values and convert to identity public key', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + const publicKey = publicKeyInCreation.toIdentityPublicKey(); + + expect(publicKeyInCreation.__wbg_ptr).to.not.equal(0); + expect(publicKey.constructor.name).to.equal('IdentityPublicKeyWASM'); + }); + }); + + describe('getters', () => { + it('should allow to get key id', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + expect(publicKeyInCreation.keyId).to.equal(0); + }); + + it('should allow to get purpose', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + expect(publicKeyInCreation.purpose).to.equal('AUTHENTICATION'); + }); + + it('should allow to get security level', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + expect(publicKeyInCreation.securityLevel).to.equal('MASTER'); + }); + + it('should allow to get key type', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + expect(publicKeyInCreation.keyType).to.equal('ECDSA_SECP256K1'); + }); + + it('should allow to get read only', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + expect(publicKeyInCreation.readOnly).to.equal(false); + }); + + it('should allow to get data', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + expect(Buffer.from(publicKeyInCreation.data)).to.deep.equal(Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex')); + }); + + it('should allow to get signature', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + expect([...publicKeyInCreation.signature]).to.deep.equal([]); + }); + }); + + describe('setters', () => { + it('should allow to set key id', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + publicKeyInCreation.keyId = 123; + + expect(publicKeyInCreation.keyId).to.equal(123); + }); + + it('should allow to set purpose', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + publicKeyInCreation.purpose = 'OWNER'; + + expect(publicKeyInCreation.purpose).to.equal('OWNER'); + }); + + it('should allow to set security level', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + publicKeyInCreation.securityLevel = 'critical'; + + expect(publicKeyInCreation.securityLevel).to.equal('CRITICAL'); + }); + + it('should allow to set key type', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + publicKeyInCreation.keyType = 'ECDSA_HASH160'; + + expect(publicKeyInCreation.keyType).to.equal('ECDSA_HASH160'); + }); + + it('should allow to set read only', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + publicKeyInCreation.readOnly = true; + + expect(publicKeyInCreation.readOnly).to.equal(true); + }); + + it('should allow to set data', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + publicKeyInCreation.data = Buffer.from('333333333334001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'); + + expect(Buffer.from(publicKeyInCreation.data)).to.deep.equal(Buffer.from('333333333334001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex')); + }); + + it('should allow to set signature', () => { + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + 0, + 'AUTHENTICATION', + 'master', + 'ECDSA_SECP256K1', + false, + Buffer.from('0333d5cf3674001d2f64c55617b7b11a2e8fc62aab09708b49355e30c7205bdb2e', 'hex'), + [], + ); + + publicKeyInCreation.signature = [1, 2, 3, 4, 5, 6]; + + expect([...publicKeyInCreation.signature]).to.deep.equal([1, 2, 3, 4, 5, 6]); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/RewardDistributionType.spec.mjs b/packages/wasm-dpp2/tests/unit/RewardDistributionType.spec.mjs new file mode 100644 index 00000000000..c7b93934b7b --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/RewardDistributionType.spec.mjs @@ -0,0 +1,94 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('RewardDistributionType', () => { + describe('serialization / deserialization', () => { + it('shoulda allow to create BlockBasedDistribution', () => { + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + BigInt(111), + distributionFunction, + ); + + expect(distributionFunction.__wbg_ptr).to.not.equal(0); + expect(distributionType.__wbg_ptr).to.not.equal(0); + }); + + it('shoulda allow to create TimeBasedDistribution', () => { + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.TimeBasedDistribution( + BigInt(111), + distributionFunction, + ); + + expect(distributionFunction.__wbg_ptr).to.not.equal(0); + expect(distributionType.__wbg_ptr).to.not.equal(0); + }); + + it('shoulda allow to create EpochBasedDistribution', () => { + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.EpochBasedDistribution( + 111, + distributionFunction, + ); + + expect(distributionFunction.__wbg_ptr).to.not.equal(0); + expect(distributionType.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('shoulda allow return value BlockBasedDistribution', () => { + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + BigInt(111), + distributionFunction, + ); + + expect(distributionType.getDistribution().constructor.name).to.equal('BlockBasedDistributionWASM'); + }); + + it('shoulda allow return value TimeBasedDistribution', () => { + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.TimeBasedDistribution( + BigInt(111), + distributionFunction, + ); + + expect(distributionType.getDistribution().constructor.name).to.equal('TimeBasedDistributionWASM'); + }); + + it('shoulda allow return value EpochBasedDistribution', () => { + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.EpochBasedDistribution( + 111, + distributionFunction, + ); + + expect(distributionType.getDistribution().constructor.name).to.equal('EpochBasedDistributionWASM'); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs new file mode 100644 index 00000000000..c40c02b5f68 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs @@ -0,0 +1,100 @@ +import getWasm from './helpers/wasm.js'; +import { dataContractId, ownerId } from './mocks/Document/index.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('TokenBaseTransition', function () { + describe('serialization / deserialization', function () { + it('should allow to create from values', () => { + const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + + expect(baseTransition.__wbg_ptr).to.not.equal(0) + }) + }) + + describe('getters', function () { + it('should allow to get identityContractNonce', () => { + const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + + expect(baseTransition.identityContractNonce).to.deep.equal(1n) + }) + + it('should allow to get tokenContractPosition', () => { + const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + + expect(baseTransition.tokenContractPosition).to.deep.equal(1) + }) + + it('should allow to get dataContractId', () => { + const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + + expect(baseTransition.dataContractId.base58()).to.deep.equal(dataContractId) + }) + + it('should allow to get tokenId', () => { + const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + + expect(baseTransition.tokenId.base58()).to.deep.equal(ownerId) + }) + + it('should allow to get usingGroupInfo', () => { + const groupStInfo = new wasm.GroupStateTransitionInfoWASM(2, dataContractId, false) + + const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId, groupStInfo) + + expect(groupStInfo.__wbg_ptr).to.not.equal(0) + expect(baseTransition.usingGroupInfo.constructor.name).to.deep.equal('GroupStateTransitionInfoWASM') + }) + }) + + describe('setters', function () { + it('should allow to set identityContractNonce', () => { + const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + + baseTransition.identityContractNonce = 3n + + expect(baseTransition.identityContractNonce).to.deep.equal(3n) + }) + + it('should allow to set tokenContractPosition', () => { + const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + + baseTransition.tokenContractPosition = 3 + + expect(baseTransition.tokenContractPosition).to.deep.equal(3) + }) + + it('should allow to set dataContractId', () => { + const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + + baseTransition.dataContractId = ownerId + + expect(baseTransition.dataContractId.base58()).to.deep.equal(ownerId) + }) + + it('should allow to set tokenId', () => { + const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + + baseTransition.tokenId = dataContractId + + expect(baseTransition.tokenId.base58()).to.deep.equal(dataContractId) + }) + + it('should allow to set usingGroupInfo', () => { + const groupStInfo = new wasm.GroupStateTransitionInfoWASM(2, dataContractId, false) + + const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + + expect(baseTransition.usingGroupInfo).to.deep.equal(undefined) + + baseTransition.usingGroupInfo = groupStInfo + + expect(groupStInfo.__wbg_ptr).to.not.equal(0) + expect(baseTransition.usingGroupInfo.constructor.name).to.deep.equal('GroupStateTransitionInfoWASM') + }) + }) +}) diff --git a/packages/wasm-dpp2/tests/unit/TokenConfiguration.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenConfiguration.spec.mjs new file mode 100644 index 00000000000..af4d7d31385 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/TokenConfiguration.spec.mjs @@ -0,0 +1,194 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('TokenConfiguration', () => { + describe('serialization / deserialization', () => { + it('Should allow to create from values', () => { + const convention = new wasm.TokenConfigurationConventionWASM( + { + ru: { + shouldCapitalize: true, + singularForm: 'TOKEN', + pluralForm: 'TOKENS', + }, + }, + 1, + ); + + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + const keepHistory = new wasm.TokenKeepsHistoryRulesWASM( + true, + true, + true, + true, + true, + true, + ); + + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + { + 1750140416485: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10000), + }, + }, + ); + + const distributionRules = new wasm.TokenDistributionRulesWASM( + undefined, + changeRules, + preProgrammedDistribution, + undefined, + changeRules, + true, + changeRules, + changeRules, + ); + + const tradeMode = wasm.TokenTradeModeWASM.NotTradeable(); + + const marketplaceRules = new wasm.TokenMarketplaceRulesWASM( + tradeMode, + changeRules, + ); + + const config = new wasm.TokenConfigurationWASM( + convention, + changeRules, + BigInt(999999999), + undefined, + keepHistory, + false, + false, + changeRules, + distributionRules, + marketplaceRules, + changeRules, + changeRules, + changeRules, + changeRules, + changeRules, + changeRules, + undefined, + noOne, + 'note', + ); + + expect(config.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get getters', () => { + const convention = new wasm.TokenConfigurationConventionWASM( + { + ru: { + shouldCapitalize: true, + singularForm: 'TOKEN', + pluralForm: 'TOKENS', + }, + }, + 1, + ); + + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + const keepHistory = new wasm.TokenKeepsHistoryRulesWASM( + true, + true, + true, + true, + true, + true, + ); + + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + { + 1750140416485: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10000), + }, + }, + ); + + const distributionRules = new wasm.TokenDistributionRulesWASM( + undefined, + changeRules, + preProgrammedDistribution, + undefined, + changeRules, + true, + changeRules, + changeRules, + ); + + const tradeMode = wasm.TokenTradeModeWASM.NotTradeable(); + + const marketplaceRules = new wasm.TokenMarketplaceRulesWASM( + tradeMode, + changeRules, + ); + + const config = new wasm.TokenConfigurationWASM( + convention, + changeRules, + BigInt(999999999), + undefined, + keepHistory, + false, + false, + changeRules, + distributionRules, + marketplaceRules, + changeRules, + changeRules, + changeRules, + changeRules, + changeRules, + changeRules, + undefined, + noOne, + 'note', + ); + + expect(config.conventions.constructor.name).to.equal('TokenConfigurationConventionWASM'); + expect(config.conventionsChangeRules.constructor.name).to.equal('ChangeControlRulesWASM'); + expect(config.baseSupply.constructor.name).to.equal('BigInt'); + expect(config.keepsHistory.constructor.name).to.equal('TokenKeepsHistoryRulesWASM'); + expect(config.startAsPaused.constructor.name).to.equal('Boolean'); + expect(config.isAllowedTransferToFrozenBalance.constructor.name).to.equal('Boolean'); + expect(config.maxSupply).to.equal(undefined); + expect(config.maxSupplyChangeRules.constructor.name).to.equal('ChangeControlRulesWASM'); + expect(config.distributionRules.constructor.name).to.equal('TokenDistributionRulesWASM'); + expect(config.marketplaceRules.constructor.name).to.equal('TokenMarketplaceRulesWASM'); + expect(config.manualMintingRules.constructor.name).to.equal('ChangeControlRulesWASM'); + expect(config.manualBurningRules.constructor.name).to.equal('ChangeControlRulesWASM'); + expect(config.freezeRules.constructor.name).to.equal('ChangeControlRulesWASM'); + expect(config.unfreezeRules.constructor.name).to.equal('ChangeControlRulesWASM'); + expect(config.destroyFrozenFundsRules.constructor.name).to.equal('ChangeControlRulesWASM'); + expect(config.emergencyActionRules.constructor.name).to.equal('ChangeControlRulesWASM'); + expect(config.mainControlGroup).to.equal(undefined); + expect(config.description.constructor.name).to.equal('String'); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/TokenConfigurationConvention.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenConfigurationConvention.spec.mjs new file mode 100644 index 00000000000..11305a993cb --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/TokenConfigurationConvention.spec.mjs @@ -0,0 +1,103 @@ +import getWasm from './helpers/wasm.js'; +import { tokenLocalization } from './mocks/TokenConfiguration/index.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('TokenConfigurationConvention', () => { + describe('serialization / deserialization', () => { + it('Should allow to create from object', () => { + const convention = new wasm.TokenConfigurationConventionWASM( + { + ru: tokenLocalization, + }, + 1, + ); + + expect(convention.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('Should allow to get object of convention in JSON', () => { + const convention = new wasm.TokenConfigurationConventionWASM( + { + ru: tokenLocalization, + }, + 1, + ); + + expect(convention.localizations.ru.toJSON()).to.deep.equal(tokenLocalization); + }); + + it('Should allow to get object of convention in wasm instance', () => { + const convention = new wasm.TokenConfigurationConventionWASM( + { + ru: tokenLocalization, + }, + 1, + ); + + expect(convention.localizations.constructor.name).to.deep.equal('Object'); + expect(convention.localizations.ru.constructor.name).to.deep.equal('TokenConfigurationLocalizationWASM'); + }); + + it('Should allow to get decimals', () => { + const convention = new wasm.TokenConfigurationConventionWASM( + { + ru: tokenLocalization, + }, + 1, + ); + + expect(convention.decimals).to.deep.equal(1); + }); + }); + + describe('setters', () => { + it('Should allow to set localizations object ', () => { + const convention = new wasm.TokenConfigurationConventionWASM( + { + ru: tokenLocalization, + }, + 1, + ); + + convention.localizations = { + en: tokenLocalization, + }; + + expect(convention.localizations.constructor.name).to.deep.equal('Object'); + expect(convention.localizations.ru).to.deep.equal(undefined); + expect(convention.localizations.en.constructor.name).to.deep.equal('TokenConfigurationLocalizationWASM'); + }); + + it('Should allow to set localizations object with wasm ', () => { + const convention = new wasm.TokenConfigurationConventionWASM( + { + ru: tokenLocalization, + }, + 1, + ); + + const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + + convention.localizations = { + en: localization, + }; + + expect(convention.localizations.constructor.name).to.deep.equal('Object'); + expect(convention.localizations.ru).to.deep.equal(undefined); + expect(convention.localizations.en.constructor.name).to.deep.equal('TokenConfigurationLocalizationWASM'); + expect(convention.localizations.en.toJSON()).to.deep.equal({ + shouldCapitalize: false, + singularForm: 'singularForm', + pluralForm: 'pluralForm', + }); + expect(localization.__wbg_ptr).to.not.equal(0); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs new file mode 100644 index 00000000000..28687d219a8 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs @@ -0,0 +1,63 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('TokenConfigurationLocalization', () => { + describe('serialization / deserialization', () => { + it('should allow to create from values', () => { + const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + + expect(localization.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get shouldCapitalize', () => { + const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + + expect(localization.shouldCapitalize).to.equal(false); + }); + + it('should allow to get pluralForm', () => { + const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + + expect(localization.pluralForm).to.equal('pluralForm'); + }); + + it('should allow to get singularForm', () => { + const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + + expect(localization.singularForm).to.equal('singularForm'); + }); + }); + + describe('setters', () => { + it('should allow to set shouldCapitalize', () => { + const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + + localization.shouldCapitalize = true; + + expect(localization.shouldCapitalize).to.equal(true); + }); + + it('should allow to set pluralForm', () => { + const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + + localization.pluralForm = 'pluralForm1212'; + + expect(localization.pluralForm).to.equal('pluralForm1212'); + }); + + it('should allow to set singularForm', () => { + const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + + localization.singularForm = 'singularForm12121'; + + expect(localization.singularForm).to.equal('singularForm12121'); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs new file mode 100644 index 00000000000..796a776ecfc --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs @@ -0,0 +1,53 @@ +import getWasm from './helpers/wasm.js'; +import { identifier } from './mocks/Identity/index.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('TokenDistributionRecipient', () => { + describe('serialization / deserialization', () => { + it('should allow to create from values ContractOwner', () => { + const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + + expect(recipient.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create from values Identity', () => { + const recipient = wasm.TokenDistributionRecipientWASM.Identity(identifier); + + expect(recipient.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create from values EvonodesByParticipation', () => { + const recipient = wasm.TokenDistributionRecipientWASM.EvonodesByParticipation(); + + expect(recipient.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get values ContractOwner', () => { + const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + + expect(recipient.getType()).to.equal('ContractOwner'); + expect(recipient.getValue()).to.equal(undefined); + }); + + it('should allow to get values Identity', () => { + const recipient = wasm.TokenDistributionRecipientWASM.Identity(identifier); + + expect(recipient.getType()).to.equal(`Identity(${identifier})`); + expect(recipient.getValue().base58()).to.equal(identifier); + }); + + it('should allow to get values EvonodesByParticipation', () => { + const recipient = wasm.TokenDistributionRecipientWASM.EvonodesByParticipation(); + + expect(recipient.getType()).to.equal('EvonodesByParticipation'); + expect(recipient.getValue()).to.equal(undefined); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs new file mode 100644 index 00000000000..fb864504d9a --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs @@ -0,0 +1,317 @@ +import getWasm from './helpers/wasm.js'; +import { identifier } from './mocks/Identity/index.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('TokenDistributionRules', () => { + describe('serialization / deserialization', () => { + it('shoulda allow to create with undefined values', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + const distributionRules = new wasm.TokenDistributionRulesWASM( + undefined, + changeRules, + undefined, + undefined, + changeRules, + true, + changeRules, + changeRules, + ); + + expect(distributionRules.__wbg_ptr).to.not.equal(0); + expect(changeRules.__wbg_ptr).to.not.equal(0); + }); + + it('shoulda allow to create without undefined values', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + { + 1750140416485: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10000), + }, + }, + ); + + const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + BigInt(111), + distributionFunction, + ); + + const perpetualDistribution = new wasm.TokenPerpetualDistributionWASM( + distributionType, + recipient, + ); + + const distributionRules = new wasm.TokenDistributionRulesWASM( + perpetualDistribution, + changeRules, + preProgrammedDistribution, + identifier, + changeRules, + true, + changeRules, + changeRules, + ); + + expect(distributionRules.__wbg_ptr).to.not.equal(0); + expect(perpetualDistribution.__wbg_ptr).to.not.equal(0); + expect(preProgrammedDistribution.__wbg_ptr).to.not.equal(0); + expect(changeRules.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('shoulda allow to get values', () => { + const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + + const changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + { + 1750140416485: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10000), + }, + }, + ); + + const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + BigInt(111), + distributionFunction, + ); + + const perpetualDistribution = new wasm.TokenPerpetualDistributionWASM( + distributionType, + recipient, + ); + + const distributionRules = new wasm.TokenDistributionRulesWASM( + perpetualDistribution, + changeRules, + preProgrammedDistribution, + identifier, + changeRules, + true, + changeRules, + changeRules, + ); + + expect(distributionRules.perpetualDistribution.constructor.name).to.deep.equal('TokenPerpetualDistributionWASM'); + expect(distributionRules.perpetualDistributionRules.constructor.name).to.deep.equal('ChangeControlRulesWASM'); + expect(distributionRules.preProgrammedDistribution.constructor.name).to.deep.equal('TokenPreProgrammedDistributionWASM'); + expect(distributionRules.newTokenDestinationIdentity.constructor.name).to.deep.equal('IdentifierWASM'); + expect(distributionRules.newTokenDestinationIdentityRules.constructor.name).to.deep.equal('ChangeControlRulesWASM'); + expect(distributionRules.mintingAllowChoosingDestination).to.deep.equal(true); + expect(distributionRules.mintingAllowChoosingDestinationRules.constructor.name).to.deep.equal('ChangeControlRulesWASM'); + expect(distributionRules.changeDirectPurchasePricingRules.constructor.name).to.deep.equal('ChangeControlRulesWASM'); + }); + }); + + describe('setters', () => { + let noOne; + + let changeRules; + + let preProgrammedDistribution; + + let recipient; + + let distributionFunction; + + let distributionType; + + let perpetualDistribution; + + let distributionRules; + + before(() => { + noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + changeRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + true, + true, + true, + ); + preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + { + 1750140416485: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10000), + }, + }, + ); + recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + BigInt(111), + distributionFunction, + ); + perpetualDistribution = new wasm.TokenPerpetualDistributionWASM( + distributionType, + recipient, + ); + distributionRules = new wasm.TokenDistributionRulesWASM( + perpetualDistribution, + changeRules, + preProgrammedDistribution, + identifier, + changeRules, + true, + changeRules, + changeRules, + ); + }); + + it('should allow to set mintingAllowChoosingDestination', () => { + distributionRules.mintingAllowChoosingDestination = false; + + expect(distributionRules.mintingAllowChoosingDestination).to.deep.equal(false); + }); + + it('should allow to set changeDirectPurchasePricingRules', () => { + const newRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + false, + false, + false, + ); + + distributionRules.changeDirectPurchasePricingRules = newRules; + + expect(newRules.__wbg_ptr).to.not.equal(0); + expect(distributionRules.changeDirectPurchasePricingRules.selfChangingAdminActionTakersAllowed).to.deep.equal(false); + expect(distributionRules.changeDirectPurchasePricingRules.changingAdminActionTakersToNoOneAllowed).to.deep.equal(false); + expect(distributionRules.changeDirectPurchasePricingRules.changingAuthorizedActionTakersToNoOneAllowed).to.deep.equal(false); + }); + + it('should allow to set mintingAllowChoosingDestinationRules', () => { + const newRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + false, + false, + false, + ); + + distributionRules.mintingAllowChoosingDestinationRules = newRules; + + expect(newRules.__wbg_ptr).to.not.equal(0); + expect(distributionRules.mintingAllowChoosingDestinationRules.selfChangingAdminActionTakersAllowed).to.deep.equal(false); + expect(distributionRules.mintingAllowChoosingDestinationRules.changingAdminActionTakersToNoOneAllowed).to.deep.equal(false); + expect(distributionRules.mintingAllowChoosingDestinationRules.changingAuthorizedActionTakersToNoOneAllowed).to.deep.equal(false); + }); + + it('should allow to set newTokenDestinationIdentityRules', () => { + const newRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + false, + false, + false, + ); + + distributionRules.newTokenDestinationIdentityRules = newRules; + + expect(newRules.__wbg_ptr).to.not.equal(0); + expect(distributionRules.newTokenDestinationIdentityRules.selfChangingAdminActionTakersAllowed).to.deep.equal(false); + expect(distributionRules.newTokenDestinationIdentityRules.changingAdminActionTakersToNoOneAllowed).to.deep.equal(false); + expect(distributionRules.newTokenDestinationIdentityRules.changingAuthorizedActionTakersToNoOneAllowed).to.deep.equal(false); + }); + + it('should allow to set newTokenDestinationIdentity', () => { + distributionRules.newTokenDestinationIdentity = '12p3355tKpjLinncBYeMsXkdDYXCbsFzzVmssce6pSJ1'; + + expect(distributionRules.newTokenDestinationIdentity.base58()).to.deep.equal('12p3355tKpjLinncBYeMsXkdDYXCbsFzzVmssce6pSJ1'); + }); + + it('should allow to set preProgrammedDistribution', () => { + const newPreProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + { + 1750140416411: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10011120), + }, + }, + ); + + distributionRules.preProgrammedDistribution = newPreProgrammedDistribution; + + expect(newPreProgrammedDistribution.__wbg_ptr).to.not.equal(0); + expect(distributionRules.preProgrammedDistribution.distributions).to.deep.equal({ + 1750140416411: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10011120), + }, + }); + }); + + it('should allow to set perpetualDistributionRules', () => { + const newPerpetualDistributionRules = new wasm.ChangeControlRulesWASM( + noOne, + noOne, + false, + false, + false, + ); + + distributionRules.perpetualDistributionRules = newPerpetualDistributionRules; + + expect(newPerpetualDistributionRules.__wbg_ptr).to.not.equal(0); + expect(distributionRules.perpetualDistributionRules.changingAuthorizedActionTakersToNoOneAllowed).to.deep.equal(false); + }); + + it('should allow to set perpetualDistribution', () => { + const newRecipient = wasm.TokenDistributionRecipientWASM.EvonodesByParticipation(); + + const newPerpetualDistribution = new wasm.TokenPerpetualDistributionWASM( + distributionType, + newRecipient, + ); + + distributionRules.perpetualDistribution = newPerpetualDistribution; + + expect(newPerpetualDistribution.__wbg_ptr).to.not.equal(0); + expect(distributionRules.perpetualDistribution.distributionRecipient.getType()).to.deep.equal('EvonodesByParticipation'); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/TokenKeepsHistoryRules.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenKeepsHistoryRules.spec.mjs new file mode 100644 index 00000000000..e8d12752392 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/TokenKeepsHistoryRules.spec.mjs @@ -0,0 +1,71 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('TokenKeepsHistoryRules', () => { + describe('serialization / deserialization', () => { + it('should allow to create TokenKeepsHistoryRules from values', () => { + const keepHistory = new wasm.TokenKeepsHistoryRulesWASM( + true, + true, + true, + true, + true, + true, + ); + + expect(keepHistory.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get values', () => { + const keepHistory = new wasm.TokenKeepsHistoryRulesWASM( + true, + true, + true, + true, + true, + true, + ); + + expect(keepHistory.keepsTransferHistory).to.equal(true); + expect(keepHistory.keepsFreezingHistory).to.equal(true); + expect(keepHistory.keepsMintingHistory).to.equal(true); + expect(keepHistory.keepsBurningHistory).to.equal(true); + expect(keepHistory.keepsDirectPricingHistory).to.equal(true); + expect(keepHistory.keepsDirectPurchaseHistory).to.equal(true); + }); + }); + + describe('setters', () => { + it('should allow to set values', () => { + const keepHistory = new wasm.TokenKeepsHistoryRulesWASM( + true, + true, + true, + true, + true, + true, + ); + + keepHistory.keepsTransferHistory = false; + keepHistory.keepsFreezingHistory = false; + keepHistory.keepsMintingHistory = false; + keepHistory.keepsBurningHistory = false; + keepHistory.keepsDirectPricingHistory = false; + keepHistory.keepsDirectPurchaseHistory = false; + + expect(keepHistory.keepsTransferHistory).to.equal(false); + expect(keepHistory.keepsFreezingHistory).to.equal(false); + expect(keepHistory.keepsMintingHistory).to.equal(false); + expect(keepHistory.keepsBurningHistory).to.equal(false); + expect(keepHistory.keepsDirectPricingHistory).to.equal(false); + expect(keepHistory.keepsDirectPurchaseHistory).to.equal(false); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/TokenPerpetualDistribution.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenPerpetualDistribution.spec.mjs new file mode 100644 index 00000000000..b17c7e490d1 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/TokenPerpetualDistribution.spec.mjs @@ -0,0 +1,134 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('TokenPerpetualDistribution', () => { + describe('serialization / deserialization', () => { + it('should allow to create from values', () => { + const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + BigInt(111), + distributionFunction, + ); + + const distribution = new wasm.TokenPerpetualDistributionWASM( + distributionType, + recipient, + ); + + expect(recipient.__wbg_ptr).to.not.equal(0); + expect(distributionFunction.__wbg_ptr).to.not.equal(0); + expect(distributionType.__wbg_ptr).to.not.equal(0); + expect(distribution.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get distributionType', () => { + const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + BigInt(111), + distributionFunction, + ); + + const distribution = new wasm.TokenPerpetualDistributionWASM( + distributionType, + recipient, + ); + + expect(distribution.distributionType.constructor.name).to.deep.equal('RewardDistributionTypeWASM'); + }); + + it('should allow to get distributionRecipient', () => { + const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + BigInt(111), + distributionFunction, + ); + + const distribution = new wasm.TokenPerpetualDistributionWASM( + distributionType, + recipient, + ); + + expect(distribution.distributionRecipient.constructor.name).to.deep.equal('TokenDistributionRecipientWASM'); + expect(distribution.distributionRecipient.getType()).to.deep.equal('ContractOwner'); + }); + }); + + describe('setters', () => { + it('should allow to set distributionType', () => { + const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + BigInt(111), + distributionFunction, + ); + + const distribution = new wasm.TokenPerpetualDistributionWASM( + distributionType, + recipient, + ); + + const newDistribution = wasm.RewardDistributionTypeWASM.TimeBasedDistribution( + BigInt(111), + distributionFunction, + ); + + distribution.distributionType = newDistribution; + + expect(newDistribution.__wbg_ptr).to.not.equal(0); + expect(distribution.distributionType.constructor.name).to.deep.equal('RewardDistributionTypeWASM'); + expect(distribution.distributionType.getDistribution().constructor.name).to.deep.equal('TimeBasedDistributionWASM'); + }); + + it('should allow to set distributionRecipient', () => { + const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + + const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + BigInt(111), + ); + + const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + BigInt(111), + distributionFunction, + ); + + const distribution = new wasm.TokenPerpetualDistributionWASM( + distributionType, + recipient, + ); + + const newRecipient = wasm.TokenDistributionRecipientWASM.EvonodesByParticipation(); + + distribution.distributionRecipient = newRecipient; + + expect(newRecipient.__wbg_ptr).to.not.equal(0); + expect(distribution.distributionRecipient.constructor.name).to.deep.equal('TokenDistributionRecipientWASM'); + expect(distribution.distributionRecipient.getType()).to.deep.equal('EvonodesByParticipation'); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/TokenPreProgrammedDistribution.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenPreProgrammedDistribution.spec.mjs new file mode 100644 index 00000000000..d4008ec4215 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/TokenPreProgrammedDistribution.spec.mjs @@ -0,0 +1,65 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('TokenPreProgrammedDistribution', () => { + describe('serialization / deserialization', () => { + it('should allow to create from values', () => { + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + { + 1750140416485: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10000), + }, + }, + ); + + expect(preProgrammedDistribution.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get distributions', () => { + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + { + 1750140416485: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10100), + }, + }, + ); + + expect(preProgrammedDistribution.distributions).to.deep.equal({ + 1750140416485: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10100), + }, + }); + }); + }); + + describe('setters', () => { + it('should allow to set distributions', () => { + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + { + 1750140416485: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10100), + }, + }, + ); + + preProgrammedDistribution.distributions = { + 1750140416415: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(9999999), + }, + }; + + expect(preProgrammedDistribution.distributions).to.deep.equal({ + 1750140416415: { + PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(9999999), + }, + }); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs b/packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs new file mode 100644 index 00000000000..8b0700dccb5 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs @@ -0,0 +1,513 @@ +import getWasm from './helpers/wasm.js'; +import { dataContractId, ownerId } from './mocks/Document/index.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +let baseTransition; + +describe('TokenTransitions', () => { + before(async () => { + baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId); + }); + + describe('serialize/deserialize', () => { + it('should allow to create burn transition', () => { + const burnTransition = new wasm.TokenBurnTransitionWASM(baseTransition, BigInt(11), 'bbbb'); + + expect(burnTransition.constructor.name).to.equal('TokenBurnTransitionWASM'); + expect(burnTransition.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create mint transition', () => { + const mintTransition = new wasm.TokenMintTransitionWASM(baseTransition, ownerId, BigInt(11), 'bbbb'); + + expect(mintTransition.constructor.name).to.equal('TokenMintTransitionWASM'); + expect(mintTransition.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create transfer transition', () => { + const transferTransition = new wasm.TokenTransferTransitionWASM( + baseTransition, + ownerId, + BigInt(11), + 'bbbb', + ); + + expect(transferTransition.constructor.name).to.equal('TokenTransferTransitionWASM'); + expect(transferTransition.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create transfer transition with shared encrypted note', () => { + const sharedEncryptedNote = new wasm.SharedEncryptedNoteWASM(0, 0, [0, 0, 0]); + + const transferTransition = new wasm.TokenTransferTransitionWASM( + baseTransition, + ownerId, + BigInt(11), + 'bbbb', + sharedEncryptedNote, + ); + + expect(sharedEncryptedNote.constructor.name).to.equal('SharedEncryptedNoteWASM'); + expect(transferTransition.constructor.name).to.equal('TokenTransferTransitionWASM'); + expect(transferTransition.__wbg_ptr).to.not.equal(0); + expect(sharedEncryptedNote.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create transfer transition with private encrypted note', () => { + const privateEncryptedNote = new wasm.PrivateEncryptedNoteWASM(0, 0, [0, 0, 0]); + + const transferTransition = new wasm.TokenTransferTransitionWASM( + baseTransition, + ownerId, + BigInt(11), + 'bbbb', + undefined, + privateEncryptedNote, + ); + + expect(privateEncryptedNote.constructor.name).to.equal('PrivateEncryptedNoteWASM'); + expect(transferTransition.constructor.name).to.equal('TokenTransferTransitionWASM'); + expect(transferTransition.__wbg_ptr).to.not.equal(0); + expect(privateEncryptedNote.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create freeze transition', () => { + const freezeTransition = new wasm.TokenFreezeTransitionWASM( + baseTransition, + ownerId, + 'bbbb', + ); + + expect(freezeTransition.constructor.name).to.equal('TokenFreezeTransitionWASM'); + expect(freezeTransition.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create unfreeze transition', () => { + const unfreezeTransition = new wasm.TokenUnFreezeTransitionWASM( + baseTransition, + ownerId, + 'bbbb', + ); + + expect(unfreezeTransition.constructor.name).to.equal('TokenUnFreezeTransitionWASM'); + expect(unfreezeTransition.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create destroy frozen funds transition', () => { + const tokenDestroyFrozenFundsTransition = new wasm.TokenDestroyFrozenFundsTransitionWASM( + baseTransition, + ownerId, + 'bbbb', + ); + + expect(tokenDestroyFrozenFundsTransition.constructor.name).to.equal('TokenDestroyFrozenFundsTransitionWASM'); + expect(tokenDestroyFrozenFundsTransition.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create claim transition', () => { + const claimTransition = new wasm.TokenClaimTransitionWASM( + baseTransition, + wasm.TokenDistributionTypeWASM.PreProgrammed, + 'bbbb', + ); + + expect(claimTransition.constructor.name).to.equal('TokenClaimTransitionWASM'); + expect(claimTransition.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create claim transition without distribution type', () => { + const claimTransition = new wasm.TokenClaimTransitionWASM( + baseTransition, + ); + + expect(claimTransition.constructor.name).to.equal('TokenClaimTransitionWASM'); + expect(claimTransition.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create emergency action transition', () => { + const emergencyActionTransition = new wasm.TokenEmergencyActionTransitionWASM( + baseTransition, + wasm.TokenDistributionTypeWASM.PreProgrammed, + 'bbbb', + ); + + expect(emergencyActionTransition.constructor.name).to.equal('TokenEmergencyActionTransitionWASM'); + expect(emergencyActionTransition.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create config update transition', () => { + const tradeMode = wasm.TokenTradeModeWASM.NotTradeable(); + + const configUpdateTransition = new wasm.TokenConfigUpdateTransitionWASM( + baseTransition, + wasm.TokenConfigurationChangeItemWASM.MarketplaceTradeModeItem(tradeMode), + 'bbbb', + ); + + expect(configUpdateTransition.constructor.name).to.equal('TokenConfigUpdateTransitionWASM'); + expect(configUpdateTransition.__wbg_ptr).to.not.equal(0); + expect(tradeMode.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create direct purchase transition', () => { + const directPurchaseTransition = new wasm.TokenDirectPurchaseTransitionWASM( + baseTransition, + BigInt(111), + BigInt(111), + ); + + expect(directPurchaseTransition.constructor.name).to.equal('TokenDirectPurchaseTransitionWASM'); + expect(directPurchaseTransition.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create set price direct purchase transition', () => { + const price = wasm.TokenPricingScheduleWASM.SetPrices({ 100: 1000 }); + + const setPriceDirectPurchaseTransition = new wasm.TokenSetPriceForDirectPurchaseTransitionWASM( + baseTransition, + price, + 'bbbb', + ); + + expect(price.constructor.name).to.equal('TokenPricingScheduleWASM'); + expect(setPriceDirectPurchaseTransition.constructor.name).to.equal('TokenSetPriceForDirectPurchaseTransitionWASM'); + expect(setPriceDirectPurchaseTransition.__wbg_ptr).to.not.equal(0); + expect(price.__wbg_ptr).to.not.equal(0); + expect(baseTransition.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to read getters burn transition', () => { + const burnTransition = new wasm.TokenBurnTransitionWASM(baseTransition, BigInt(11), 'bbbb'); + + expect(burnTransition.burnAmount).to.equal(BigInt(11)); + expect(burnTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(burnTransition.publicNote).to.equal('bbbb'); + }); + + it('should allow to read getters mint transition', () => { + const mintTransition = new wasm.TokenMintTransitionWASM(baseTransition, ownerId, BigInt(11), 'bbbb'); + + expect(mintTransition.amount).to.equal(BigInt(11)); + expect(mintTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(mintTransition.publicNote).to.equal('bbbb'); + }); + + it('should allow to read getters transfer transition', () => { + const sharedEncryptedNote = new wasm.SharedEncryptedNoteWASM(0, 0, [0, 0, 0]); + const privateEncryptedNote = new wasm.PrivateEncryptedNoteWASM(0, 0, [0, 0, 0]); + + const transferTransition = new wasm.TokenTransferTransitionWASM( + baseTransition, + ownerId, + BigInt(11), + 'bbbb', + sharedEncryptedNote, + privateEncryptedNote, + ); + + expect(transferTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(transferTransition.amount).to.equal(BigInt(11)); + expect(transferTransition.publicNote).to.equal('bbbb'); + expect(transferTransition.sharedEncryptedNote.constructor.name).to.equal('SharedEncryptedNoteWASM'); + expect(transferTransition.privateEncryptedNote.constructor.name).to.equal('PrivateEncryptedNoteWASM'); + }); + + it('should allow to read getters freeze transition', () => { + const freezeTransition = new wasm.TokenFreezeTransitionWASM( + baseTransition, + ownerId, + 'bbbb', + ); + + expect(freezeTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(freezeTransition.frozenIdentityId.base58()).to.equal(ownerId); + expect(freezeTransition.publicNote).to.equal('bbbb'); + }); + + it('should allow to read getters unfreeze transition', () => { + const unfreezeTransition = new wasm.TokenUnFreezeTransitionWASM( + baseTransition, + ownerId, + 'bbbb', + ); + + expect(unfreezeTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(unfreezeTransition.frozenIdentityId.base58()).to.equal(ownerId); + expect(unfreezeTransition.publicNote).to.equal('bbbb'); + }); + + it('should allow to read getters destroy frozen funds transition', () => { + const tokenDestroyFrozenFundsTransition = new wasm.TokenDestroyFrozenFundsTransitionWASM( + baseTransition, + ownerId, + 'bbbb', + ); + + expect(tokenDestroyFrozenFundsTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(tokenDestroyFrozenFundsTransition.frozenIdentityId.base58()).to.equal(ownerId); + expect(tokenDestroyFrozenFundsTransition.publicNote).to.equal('bbbb'); + }); + + it('should allow to read getters claim transition', () => { + const claimTransition = new wasm.TokenClaimTransitionWASM( + baseTransition, + wasm.TokenDistributionTypeWASM.PreProgrammed, + 'bbbb', + ); + + expect(claimTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(claimTransition.distributionType).to.equal('PreProgrammed'); + expect(claimTransition.publicNote).to.equal('bbbb'); + }); + + it('should allow to read getters emergency action transition', () => { + const emergencyActionTransition = new wasm.TokenEmergencyActionTransitionWASM( + baseTransition, + wasm.TokenEmergencyActionWASM.Pause, + 'bbbb', + ); + + expect(emergencyActionTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(emergencyActionTransition.emergencyAction).to.equal('Pause'); + expect(emergencyActionTransition.publicNote).to.equal('bbbb'); + }); + + it('should allow to read getters config update transition', () => { + const tradeMode = wasm.TokenTradeModeWASM.NotTradeable(); + + const configUpdateTransition = new wasm.TokenConfigUpdateTransitionWASM( + baseTransition, + wasm.TokenConfigurationChangeItemWASM.MarketplaceTradeModeItem(tradeMode), + 'bbbb', + ); + + expect(configUpdateTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(configUpdateTransition.updateTokenConfigurationItem.constructor.name).to.equal('TokenConfigurationChangeItemWASM'); + expect(configUpdateTransition.publicNote).to.equal('bbbb'); + }); + + it('should allow to read getters direct purchase transition', () => { + const directPurchaseTransition = new wasm.TokenDirectPurchaseTransitionWASM( + baseTransition, + BigInt(111), + BigInt(111), + ); + + expect(directPurchaseTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(directPurchaseTransition.tokenCount).to.equal(BigInt(111)); + expect(directPurchaseTransition.totalAgreedPrice).to.equal(BigInt(111)); + }); + + it('should allow to read getters set price direct purchase transition', () => { + const price = wasm.TokenPricingScheduleWASM.SetPrices({ 100: 1000 }); + + const setPriceDirectPurchaseTransition = new wasm.TokenSetPriceForDirectPurchaseTransitionWASM( + baseTransition, + price, + 'bbbb', + ); + + expect(setPriceDirectPurchaseTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(setPriceDirectPurchaseTransition.price.constructor.name).to.equal('TokenPricingScheduleWASM'); + expect(setPriceDirectPurchaseTransition.publicNote).to.equal('bbbb'); + }); + }); + + describe('setters', () => { + it('should allow to set values burn transition', () => { + const burnTransition = new wasm.TokenBurnTransitionWASM(baseTransition, BigInt(11), 'bbbb'); + + burnTransition.burnAmount = BigInt(222); + burnTransition.publicNote = 'aaaa'; + + expect(burnTransition.burnAmount).to.equal(BigInt(222)); + expect(burnTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(burnTransition.publicNote).to.equal('aaaa'); + }); + + it('should allow to set values mint transition', () => { + const mintTransition = new wasm.TokenMintTransitionWASM(baseTransition, ownerId, BigInt(11), 'bbbb'); + + mintTransition.amount = BigInt(222); + mintTransition.publicNote = 'aaaa'; + + expect(mintTransition.amount).to.equal(BigInt(222)); + expect(mintTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(mintTransition.publicNote).to.equal('aaaa'); + }); + + it('should allow to set values transfer transition', () => { + const sharedEncryptedNote = new wasm.SharedEncryptedNoteWASM(0, 0, [0, 0, 0]); + const privateEncryptedNote = new wasm.PrivateEncryptedNoteWASM(0, 0, [0, 0, 0]); + + const transferTransition = new wasm.TokenTransferTransitionWASM( + baseTransition, + ownerId, + BigInt(11), + 'bbbb', + sharedEncryptedNote, + privateEncryptedNote, + ); + + const sharedEncryptedNote2 = new wasm.SharedEncryptedNoteWASM(0, 0, [0, 0, 0]); + const privateEncryptedNote2 = new wasm.PrivateEncryptedNoteWASM(0, 0, [0, 0, 0]); + + transferTransition.sharedEncryptedNote = sharedEncryptedNote2; + transferTransition.privateEncryptedNote = privateEncryptedNote2; + transferTransition.amount = BigInt(222); + transferTransition.publicNote = 'aaaa'; + + expect(transferTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(transferTransition.amount).to.equal(BigInt(222)); + expect(transferTransition.publicNote).to.equal('aaaa'); + expect(transferTransition.sharedEncryptedNote.constructor.name).to.equal('SharedEncryptedNoteWASM'); + expect(transferTransition.privateEncryptedNote.constructor.name).to.equal('PrivateEncryptedNoteWASM'); + expect(sharedEncryptedNote2.__wbg_ptr).to.not.equal(0); + expect(privateEncryptedNote2.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to set values freeze transition', () => { + const freezeTransition = new wasm.TokenFreezeTransitionWASM( + baseTransition, + ownerId, + 'bbbb', + ); + + freezeTransition.frozenIdentityId = dataContractId; + freezeTransition.publicNote = 'aaaa'; + + expect(freezeTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(freezeTransition.frozenIdentityId.base58()).to.equal(dataContractId); + expect(freezeTransition.publicNote).to.equal('aaaa'); + }); + + it('should allow to set values unfreeze transition', () => { + const unfreezeTransition = new wasm.TokenUnFreezeTransitionWASM( + baseTransition, + ownerId, + 'bbbb', + ); + + unfreezeTransition.frozenIdentityId = dataContractId; + unfreezeTransition.publicNote = 'aaaa'; + + expect(unfreezeTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(unfreezeTransition.frozenIdentityId.base58()).to.equal(dataContractId); + expect(unfreezeTransition.publicNote).to.equal('aaaa'); + }); + + it('should allow to set values destroy frozen funds transition', () => { + const tokenDestroyFrozenFundsTransition = new wasm.TokenDestroyFrozenFundsTransitionWASM( + baseTransition, + ownerId, + 'bbbb', + ); + + tokenDestroyFrozenFundsTransition.frozenIdentityId = dataContractId; + tokenDestroyFrozenFundsTransition.publicNote = 'aaaa'; + + expect(tokenDestroyFrozenFundsTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(tokenDestroyFrozenFundsTransition.frozenIdentityId.base58()).to.equal(dataContractId); + expect(tokenDestroyFrozenFundsTransition.publicNote).to.equal('aaaa'); + }); + + it('should allow to set values claim transition', () => { + const claimTransition = new wasm.TokenClaimTransitionWASM( + baseTransition, + wasm.TokenDistributionTypeWASM.Perpetual, + 'bbbb', + ); + + claimTransition.distributionType = wasm.TokenDistributionTypeWASM.Perpetual; + claimTransition.publicNote = 'aaaa'; + + expect(claimTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(claimTransition.distributionType).to.equal('Perpetual'); + expect(claimTransition.publicNote).to.equal('aaaa'); + }); + + it('should allow to set values emergency action transition', () => { + const emergencyActionTransition = new wasm.TokenEmergencyActionTransitionWASM( + baseTransition, + wasm.TokenEmergencyActionWASM.Pause, + 'bbbb', + ); + + emergencyActionTransition.emergencyAction = wasm.TokenEmergencyActionWASM.Resume; + emergencyActionTransition.publicNote = 'aaaa'; + + expect(emergencyActionTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(emergencyActionTransition.emergencyAction).to.equal('Resume'); + expect(emergencyActionTransition.publicNote).to.equal('aaaa'); + }); + + it('should allow to set values config update transition', () => { + // At this moment available only one trade mode + const tradeMode = wasm.TokenTradeModeWASM.NotTradeable(); + + const configUpdateTransition = new wasm.TokenConfigUpdateTransitionWASM( + baseTransition, + wasm.TokenConfigurationChangeItemWASM.MarketplaceTradeModeItem(tradeMode), + 'bbbb', + ); + + configUpdateTransition.publicNote = 'aaaa'; + + expect(configUpdateTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(configUpdateTransition.updateTokenConfigurationItem.constructor.name).to.equal('TokenConfigurationChangeItemWASM'); + expect(configUpdateTransition.publicNote).to.equal('aaaa'); + }); + + it('should allow to set values direct purchase transition', () => { + const directPurchaseTransition = new wasm.TokenDirectPurchaseTransitionWASM( + baseTransition, + BigInt(111), + BigInt(111), + ); + + directPurchaseTransition.tokenCount = BigInt(222); + directPurchaseTransition.totalAgreedPrice = BigInt(222); + + expect(directPurchaseTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(directPurchaseTransition.tokenCount).to.equal(BigInt(222)); + expect(directPurchaseTransition.totalAgreedPrice).to.equal(BigInt(222)); + }); + + it('should allow to set values set price direct purchase transition', () => { + const price = wasm.TokenPricingScheduleWASM.SetPrices({ 100: 1000 }); + + const setPriceDirectPurchaseTransition = new wasm.TokenSetPriceForDirectPurchaseTransitionWASM( + baseTransition, + price, + 'bbbb', + ); + + setPriceDirectPurchaseTransition.price = wasm.TokenPricingScheduleWASM.SetPrices({ 101: 1010 }); + setPriceDirectPurchaseTransition.publicNote = 'aaaa'; + + expect(setPriceDirectPurchaseTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(setPriceDirectPurchaseTransition.price.constructor.name).to.equal('TokenPricingScheduleWASM'); + expect(setPriceDirectPurchaseTransition.publicNote).to.equal('aaaa'); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/TxOut.spec.mjs b/packages/wasm-dpp2/tests/unit/TxOut.spec.mjs new file mode 100644 index 00000000000..46e8cb69926 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/TxOut.spec.mjs @@ -0,0 +1,74 @@ +import getWasm from './helpers/wasm.js'; + +let wasm; + +before(async () => { + wasm = await getWasm(); +}); + +describe('TxOut', () => { + describe('serialization / deserialization', () => { + it('should allow to create from values with pubkey hex', () => { + const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + expect(out.__wbg_ptr).to.not.equal(0); + }); + + it('should allow to create from values with pubkey array', () => { + const out = new wasm.TxOutWASM(BigInt(100), Array.from(Buffer.from('76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac', 'hex'))); + + expect(out.__wbg_ptr).to.not.equal(0); + }); + }); + + describe('getters', () => { + it('should allow to get value', () => { + const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + + expect(out.value).to.equal(BigInt(100)); + }); + + it('should allow to get script hex', () => { + const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + + expect(out.scriptPubKeyHex).to.equal('76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + }); + + it('should allow to get script bytes', () => { + const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + + expect(out.scriptPubKeyBytes).to.deep.equal(Uint8Array.from(Buffer.from('76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac', 'hex'))); + }); + + it('should allow to get script asm', () => { + const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + + expect(out.getScriptPubKeyASM()).to.deep.equal('OP_DUP OP_HASH160 OP_PUSHBYTES_20 1a486a3855e6dc6dd02874424f53a6f2197b3d45 OP_EQUALVERIFY OP_CHECKSIG'); + }); + }); + + describe('setters', () => { + it('should allow to set value', () => { + const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + + out.value = BigInt(101); + + expect(out.value).to.equal(BigInt(101)); + }); + + it('should allow to set script hex', () => { + const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + + out.scriptPubKeyHex = '16a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'; + + expect(out.scriptPubKeyHex).to.equal('16a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + }); + + it('should allow to set script bytes', () => { + const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + + out.scriptPubKeyBytes = Array.from(Buffer.from('76a914f995e42d1aa7a31b0106b63e1b896fe9aeeccc9988ac', 'hex')); + + expect(out.scriptPubKeyBytes).to.deep.equal(Uint8Array.from(Buffer.from('76a914f995e42d1aa7a31b0106b63e1b896fe9aeeccc9988ac', 'hex'))); + }); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/helpers/wasm.js b/packages/wasm-dpp2/tests/unit/helpers/wasm.js new file mode 100644 index 00000000000..f0e65f36c57 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/helpers/wasm.js @@ -0,0 +1,30 @@ +import init, * as wasmModule from '../../../dist/dpp.compressed.js'; + +let initialized = false; +let initPromise; + +/** + * + */ +async function ensureInitialized() { + if (initialized) { + return; + } + + if (!initPromise) { + initPromise = init(); + } + + await initPromise; + initialized = true; +} + +/** + * + */ +export async function getWasm() { + await ensureInitialized(); + return wasmModule; +} + +export default getWasm; diff --git a/packages/wasm-dpp2/tests/unit/mocks/DataContract/DataContract.json b/packages/wasm-dpp2/tests/unit/mocks/DataContract/DataContract.json new file mode 100644 index 00000000000..a71ad037041 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/DataContract/DataContract.json @@ -0,0 +1,153 @@ +{ + "$format_version": "0", + "id": "4fJLR2GYTPFdomuTVvNy3VRrvWgvkKPzqehEBpNf2nk6", + "config": { + "$format_version": "0", + "canBeDeleted": false, + "readonly": false, + "keepsHistory": false, + "documentsKeepHistoryContractDefault": false, + "documentsMutableContractDefault": true, + "documentsCanBeDeletedContractDefault": true, + "requiresIdentityEncryptionBoundedKey": null, + "requiresIdentityDecryptionBoundedKey": null + }, + "version": 1, + "ownerId": "11111111111111111111111111111111", + "schemaDefs": null, + "documentSchemas": { + "withdrawal": { + "description": "Withdrawal document to track underlying withdrawal transactions. Withdrawals should be created with IdentityWithdrawalTransition", + "creationRestrictionMode": 2, + "type": "object", + "indices": [ + { + "name": "identityStatus", + "properties": [ + { + "$ownerId": "asc" + }, + { + "status": "asc" + }, + { + "$createdAt": "asc" + } + ], + "unique": false + }, + { + "name": "identityRecent", + "properties": [ + { + "$ownerId": "asc" + }, + { + "$updatedAt": "asc" + }, + { + "status": "asc" + } + ], + "unique": false + }, + { + "name": "pooling", + "properties": [ + { + "status": "asc" + }, + { + "pooling": "asc" + }, + { + "coreFeePerByte": "asc" + }, + { + "$updatedAt": "asc" + } + ], + "unique": false + }, + { + "name": "transaction", + "properties": [ + { + "status": "asc" + }, + { + "transactionIndex": "asc" + } + ], + "unique": false + } + ], + "properties": { + "transactionIndex": { + "type": "integer", + "description": "Sequential index of asset unlock (withdrawal) transaction. Populated when a withdrawal pooled into withdrawal transaction", + "minimum": 1, + "position": 0 + }, + "transactionSignHeight": { + "type": "integer", + "description": "The Core height on which transaction was signed", + "minimum": 1, + "position": 1 + }, + "amount": { + "type": "integer", + "description": "The amount to be withdrawn", + "minimum": 1000, + "position": 2 + }, + "coreFeePerByte": { + "type": "integer", + "description": "This is the fee that you are willing to spend for this transaction in Duffs/Byte", + "minimum": 1, + "maximum": 4294967295, + "position": 3 + }, + "pooling": { + "type": "integer", + "description": "This indicated the level at which Platform should try to pool this transaction", + "enum": [ + 0, + 1, + 2 + ], + "position": 4 + }, + "outputScript": { + "type": "array", + "byteArray": true, + "minItems": 23, + "maxItems": 25, + "position": 5 + }, + "status": { + "type": "integer", + "enum": [ + 0, + 1, + 2, + 3, + 4 + ], + "description": "0 - Pending, 1 - Signed, 2 - Broadcasted, 3 - Complete, 4 - Expired", + "position": 6 + } + }, + "additionalProperties": false, + "required": [ + "$createdAt", + "$updatedAt", + "amount", + "coreFeePerByte", + "pooling", + "outputScript", + "status" + ] + } + } +} diff --git a/packages/wasm-dpp2/tests/unit/mocks/DataContract/index.js b/packages/wasm-dpp2/tests/unit/mocks/DataContract/index.js new file mode 100644 index 00000000000..bdb1e14f68b --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/DataContract/index.js @@ -0,0 +1,6 @@ +import value from './value.js'; + +export { value }; +export const id = '4fJLR2GYTPFdomuTVvNy3VRrvWgvkKPzqehEBpNf2nk6' +export const ownerId = '11111111111111111111111111111111' +export const dataContractsBytes = ['00ea8920edea52fa400de2ccc43052b2821f45585241a2875d4250e35d4ce937c800000000000101000001ab321b19457b1c16b12762509276d47d952f582d978cbd8b50bbfc2fd8a7767d0001046e6f7465160312047479706512066f626a656374120a70726f70657274696573160112076d65737361676516021204747970651206737472696e671208706f736974696f6e030012146164646974696f6e616c50726f706572746965731300'] diff --git a/packages/wasm-dpp2/tests/unit/mocks/DataContract/value.js b/packages/wasm-dpp2/tests/unit/mocks/DataContract/value.js new file mode 100644 index 00000000000..e79be85d800 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/DataContract/value.js @@ -0,0 +1,155 @@ +/* eslint-disable quote-props, quotes */ + +export default { + "$format_version": "0", + "id": "4fJLR2GYTPFdomuTVvNy3VRrvWgvkKPzqehEBpNf2nk6", + "config": { + "$format_version": "0", + "canBeDeleted": false, + "readonly": false, + "keepsHistory": false, + "documentsKeepHistoryContractDefault": false, + "documentsMutableContractDefault": true, + "documentsCanBeDeletedContractDefault": true, + "requiresIdentityEncryptionBoundedKey": null, + "requiresIdentityDecryptionBoundedKey": null + }, + "version": 1, + "ownerId": "11111111111111111111111111111111", + "schemaDefs": null, + "documentSchemas": { + "withdrawal": { + "description": "Withdrawal document to track underlying withdrawal transactions. Withdrawals should be created with IdentityWithdrawalTransition", + "creationRestrictionMode": 2, + "type": "object", + "indices": [ + { + "name": "identityStatus", + "properties": [ + { + "$ownerId": "asc" + }, + { + "status": "asc" + }, + { + "$createdAt": "asc" + } + ], + "unique": false + }, + { + "name": "identityRecent", + "properties": [ + { + "$ownerId": "asc" + }, + { + "$updatedAt": "asc" + }, + { + "status": "asc" + } + ], + "unique": false + }, + { + "name": "pooling", + "properties": [ + { + "status": "asc" + }, + { + "pooling": "asc" + }, + { + "coreFeePerByte": "asc" + }, + { + "$updatedAt": "asc" + } + ], + "unique": false + }, + { + "name": "transaction", + "properties": [ + { + "status": "asc" + }, + { + "transactionIndex": "asc" + } + ], + "unique": false + } + ], + "properties": { + "transactionIndex": { + "type": "integer", + "description": "Sequential index of asset unlock (withdrawal) transaction. Populated when a withdrawal pooled into withdrawal transaction", + "minimum": 1, + "position": 0 + }, + "transactionSignHeight": { + "type": "integer", + "description": "The Core height on which transaction was signed", + "minimum": 1, + "position": 1 + }, + "amount": { + "type": "integer", + "description": "The amount to be withdrawn", + "minimum": 1000, + "position": 2 + }, + "coreFeePerByte": { + "type": "integer", + "description": "This is the fee that you are willing to spend for this transaction in Duffs/Byte", + "minimum": 1, + "maximum": 4294967295, + "position": 3 + }, + "pooling": { + "type": "integer", + "description": "This indicated the level at which Platform should try to pool this transaction", + "enum": [ + 0, + 1, + 2 + ], + "position": 4 + }, + "outputScript": { + "type": "array", + "byteArray": true, + "minItems": 23, + "maxItems": 25, + "position": 5 + }, + "status": { + "type": "integer", + "enum": [ + 0, + 1, + 2, + 3, + 4 + ], + "description": "0 - Pending, 1 - Signed, 2 - Broadcasted, 3 - Complete, 4 - Expired", + "position": 6 + } + }, + "additionalProperties": false, + "required": [ + "$createdAt", + "$updatedAt", + "amount", + "coreFeePerByte", + "pooling", + "outputScript", + "status" + ] + } + } +} diff --git a/packages/wasm-dpp2/tests/unit/mocks/Document/DataContract.json b/packages/wasm-dpp2/tests/unit/mocks/Document/DataContract.json new file mode 100644 index 00000000000..a31042b882b --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/Document/DataContract.json @@ -0,0 +1,23 @@ +{ + "$format_version": "0", + "version": 1, + "ownerId": "11111111111111111111111111111111", + "schemaDefs": null, + "id": "4fJLR2GYTPFdomuTVvNy3VRrvWgvkKPzqehEBpNf2nk6", + "documentSchemas": { + "note": { + "type": "object", + "properties": { + "author": { + "type": "string", + "position": 1 + }, + "message": { + "type": "string", + "position": 0 + } + }, + "additionalProperties": false + } + } +} diff --git a/packages/wasm-dpp2/tests/unit/mocks/Document/dataContract.js b/packages/wasm-dpp2/tests/unit/mocks/Document/dataContract.js new file mode 100644 index 00000000000..c7edbdb30f3 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/Document/dataContract.js @@ -0,0 +1,25 @@ +/* eslint-disable quote-props, quotes */ + +export default { + "$format_version": "0", + "version": 1, + "ownerId": "11111111111111111111111111111111", + "schemaDefs": null, + "id": "4fJLR2GYTPFdomuTVvNy3VRrvWgvkKPzqehEBpNf2nk6", + "documentSchemas": { + "note": { + "type": "object", + "properties": { + "author": { + "type": "string", + "position": 1 + }, + "message": { + "type": "string", + "position": 0 + } + }, + "additionalProperties": false + } + } +} diff --git a/packages/wasm-dpp2/tests/unit/mocks/Document/document.js b/packages/wasm-dpp2/tests/unit/mocks/Document/document.js new file mode 100644 index 00000000000..1f23b9c20fd --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/Document/document.js @@ -0,0 +1,5 @@ +/* eslint-disable quote-props, quotes */ + +export default { + "message": "Tutorial CI Test @ Tue, 07 Jan 2025 15:27:50 GMT" +} diff --git a/packages/wasm-dpp2/tests/unit/mocks/Document/document.json b/packages/wasm-dpp2/tests/unit/mocks/Document/document.json new file mode 100644 index 00000000000..016d7db8dd9 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/Document/document.json @@ -0,0 +1,3 @@ +{ + "message": "Tutorial CI Test @ Tue, 07 Jan 2025 15:27:50 GMT" +} diff --git a/packages/wasm-dpp2/tests/unit/mocks/Document/document2.js b/packages/wasm-dpp2/tests/unit/mocks/Document/document2.js new file mode 100644 index 00000000000..e894c124b2d --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/Document/document2.js @@ -0,0 +1,5 @@ +/* eslint-disable quote-props, quotes */ + +export default { + "message": "bb" +} diff --git a/packages/wasm-dpp2/tests/unit/mocks/Document/document2.json b/packages/wasm-dpp2/tests/unit/mocks/Document/document2.json new file mode 100644 index 00000000000..2d7bc007f05 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/Document/document2.json @@ -0,0 +1,3 @@ +{ + "message": "bb" +} diff --git a/packages/wasm-dpp2/tests/unit/mocks/Document/index.js b/packages/wasm-dpp2/tests/unit/mocks/Document/index.js new file mode 100644 index 00000000000..19d959a4e46 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/Document/index.js @@ -0,0 +1,12 @@ +import document from './document.js'; +import document2 from './document2.js'; +import dataContractValue from './dataContract.js'; + +export { document, document2, dataContractValue }; + +export const documentTypeName = 'note'; +export const revision = BigInt(1); +export const dataContractId = 'GnXgMaiqAwTxh44ccQe8AoCgFvcseHK5CncH3sUorW4X'; +export const ownerId = 'CXH2kZCATjvDTnQAPVg28EgPg9WySUvwvnR5ZkmNqY5i'; +export const id = '9tSsCqKHTZ8ro16MydChSxgHBukFW36eMLJKKRtebJEn'; +export const documentBytes = '00840b5cec9f0401b1950610e85dcb26829122ac8853464e1e2c7e38ed22b48903ab321b19457b1c16b12762509276d47d952f582d978cbd8b50bbfc2fd8a7767d01000001305475746f7269616c20434920546573742040205475652c203037204a616e20323032352031353a32373a353020474d5400'; diff --git a/packages/wasm-dpp2/tests/unit/mocks/Identity/index.js b/packages/wasm-dpp2/tests/unit/mocks/Identity/index.js new file mode 100644 index 00000000000..759bf0bf021 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/Identity/index.js @@ -0,0 +1,13 @@ +const identifier = 'H2pb35GtKpjLinncBYeMsXkdDYXCbsFzzVmssce6pSJ1'; +const identifierBytes = [238, 50, 96, 211, 63, 140, 169, 225, 76, 97, 8, 6, 212, 109, 184, 253, 51, 67, 82, 42, 208, 228, 72, 192, 215, 137, 161, 88, 144, 55, 244, 230]; +const balance = BigInt(100); +const revision = BigInt(99111); +const identityBytesWithoutKeys = [0, 238, 50, 96, 211, 63, 140, 169, 225, 76, 97, 8, 6, 212, 109, 184, 253, 51, 67, 82, 42, 208, 228, 72, 192, 215, 137, 161, 88, 144, 55, 244, 230, 0, 0, 0]; + +export { + identifier, + identifierBytes, + balance, + revision, + identityBytesWithoutKeys, +}; diff --git a/packages/wasm-dpp2/tests/unit/mocks/Locks/index.js b/packages/wasm-dpp2/tests/unit/mocks/Locks/index.js new file mode 100644 index 00000000000..c13706e2a7f --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/Locks/index.js @@ -0,0 +1,2 @@ +export const instantLockBytes = [1, 1, 89, 68, 206, 254, 139, 111, 183, 115, 169, 122, 19, 26, 29, 175, 97, 14, 156, 207, 215, 16, 92, 152, 110, 29, 167, 34, 91, 149, 243, 48, 250, 217, 0, 0, 0, 0, 61, 111, 50, 237, 225, 255, 25, 159, 133, 89, 244, 234, 150, 19, 61, 198, 218, 144, 144, 44, 45, 189, 109, 187, 247, 117, 93, 95, 156, 46, 12, 216, 1, 49, 33, 55, 67, 236, 100, 131, 20, 54, 98, 71, 159, 60, 21, 2, 116, 197, 18, 154, 171, 227, 15, 30, 21, 0, 0, 0, 0, 0, 0, 0, 169, 241, 49, 98, 108, 73, 162, 241, 131, 183, 162, 245, 99, 173, 29, 197, 10, 200, 34, 1, 144, 219, 237, 184, 5, 32, 155, 96, 142, 184, 100, 224, 29, 98, 241, 139, 201, 250, 166, 10, 139, 138, 39, 245, 160, 199, 200, 185, 20, 250, 58, 20, 54, 10, 47, 37, 85, 142, 224, 224, 166, 147, 177, 143, 172, 203, 181, 158, 195, 155, 155, 60, 174, 67, 14, 11, 118, 235, 8, 7, 82, 206, 16, 61, 247, 101, 55, 161, 165, 131, 104, 10, 89, 20, 82, 157]; +export const transactionBytes = [3, 0, 8, 0, 1, 89, 68, 206, 254, 139, 111, 183, 115, 169, 122, 19, 26, 29, 175, 97, 14, 156, 207, 215, 16, 92, 152, 110, 29, 167, 34, 91, 149, 243, 48, 250, 217, 0, 0, 0, 0, 107, 72, 48, 69, 2, 33, 0, 157, 215, 234, 11, 75, 36, 23, 153, 82, 143, 163, 76, 75, 118, 142, 19, 6, 13, 64, 50, 24, 199, 141, 199, 163, 14, 86, 81, 67, 150, 240, 28, 2, 32, 105, 238, 106, 123, 228, 237, 166, 210, 251, 103, 249, 36, 15, 233, 177, 30, 40, 125, 67, 108, 224, 183, 4, 5, 18, 239, 231, 185, 223, 195, 92, 240, 1, 33, 3, 238, 76, 67, 141, 205, 25, 38, 200, 164, 105, 53, 55, 189, 36, 52, 232, 121, 166, 108, 186, 227, 161, 55, 7, 105, 135, 102, 219, 224, 117, 213, 70, 255, 255, 255, 255, 2, 128, 29, 44, 4, 0, 0, 0, 0, 2, 106, 0, 48, 232, 38, 1, 0, 0, 0, 0, 25, 118, 169, 20, 232, 101, 217, 39, 144, 120, 74, 135, 230, 203, 134, 239, 207, 15, 238, 152, 16, 172, 45, 177, 136, 172, 0, 0, 0, 0, 36, 1, 1, 128, 29, 44, 4, 0, 0, 0, 0, 25, 118, 169, 20, 12, 182, 70, 130, 142, 161, 106, 83, 94, 200, 33, 4, 251, 5, 50, 93, 28, 107, 159, 168, 136, 172]; diff --git a/packages/wasm-dpp2/tests/unit/mocks/PrivateKey/index.js b/packages/wasm-dpp2/tests/unit/mocks/PrivateKey/index.js new file mode 100644 index 00000000000..6750212b433 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/PrivateKey/index.js @@ -0,0 +1,5 @@ +export const wif = 'cR4EZ2nAvCmn2cFepKn7UgSSQFgFTjkySAchvcoiEVdm48eWjQGn'; + +export const bytes = '67ad1669d882da256b6fa05e1b0ae384a6ac8aed146ea53602b8ff0e1e9c18e9'; + +export const publicKeyHash = '622fd260c35f0d826d05983d1f0524b02dec27a0'; diff --git a/packages/wasm-dpp2/tests/unit/mocks/PublicKey/index.js b/packages/wasm-dpp2/tests/unit/mocks/PublicKey/index.js new file mode 100644 index 00000000000..b61580480b3 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/PublicKey/index.js @@ -0,0 +1,11 @@ +export const keyId = 2; +export const purpose = 'AUTHENTICATION'; +export const securityLevel = 'CRITICAL'; +export const keyType = 'ECDSA_SECP256K1'; +export const binaryData = '036a394312e40e81d928fde2bde7880070e4fa9c1d1d9b168da707ea468afa2b48'; + +export const keyIdSet = 3; +export const purposeSet = 'ENCRYPTION'; +export const securityLevelSet = 'HIGH'; +export const keyTypeSet = 'ECDSA_HASH160'; +export const binaryDataSet = '0300000002e40e81d928fde2bde7880070e4fa9c1d1d9b168da707ea468afa2b48'; diff --git a/packages/wasm-dpp2/tests/unit/mocks/TokenConfiguration/index.js b/packages/wasm-dpp2/tests/unit/mocks/TokenConfiguration/index.js new file mode 100644 index 00000000000..8a46860c764 --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/mocks/TokenConfiguration/index.js @@ -0,0 +1,5 @@ +export const tokenLocalization = { + shouldCapitalize: true, + singularForm: 'TOKEN', + pluralForm: 'TOKENS', +}; diff --git a/packages/wasm-dpp2/tests/unit/module-load.spec.mjs b/packages/wasm-dpp2/tests/unit/module-load.spec.mjs new file mode 100644 index 00000000000..de595ab6dfb --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/module-load.spec.mjs @@ -0,0 +1,19 @@ +import init, { + StateTransitionWASM, + ConsensusErrorWASM, +} from '../../dist/dpp.compressed.js'; + +describe('wasm-dpp2 module', () => { + before(async () => { + await init(); + }); + + it('exposes state transition bindings', () => { + expect(StateTransitionWASM).to.be.a('function'); + }); + + it('exposes consensus error helpers', () => { + expect(ConsensusErrorWASM).to.be.a('function'); + expect(ConsensusErrorWASM.deserialize).to.be.a('function'); + }); +}); diff --git a/packages/wasm-dpp2/tests/unit/utils/hex.js b/packages/wasm-dpp2/tests/unit/utils/hex.js new file mode 100644 index 00000000000..5a6f148655d --- /dev/null +++ b/packages/wasm-dpp2/tests/unit/utils/hex.js @@ -0,0 +1,10 @@ +export const toHexString = (byteArray) => Array.prototype.map.call(byteArray, (byte) => (`0${(byte & 0xFF).toString(16)}`).slice(-2)).join(''); + +export const fromHexString = (str) => { + const bytes = []; + for (let i = 0; i < str.length; i += 2) { + bytes.push(parseInt(str.slice(i, i + 2), 16)); + } + + return Uint8Array.from(bytes); +}; diff --git a/yarn.lock b/yarn.lock index 43002093cdb..a698eda92e0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2000,6 +2000,38 @@ __metadata: languageName: unknown linkType: soft +"@dashevo/wasm-dpp2@workspace:packages/wasm-dpp2": + version: 0.0.0-use.local + resolution: "@dashevo/wasm-dpp2@workspace:packages/wasm-dpp2" + dependencies: + assert: "npm:^2.0.0" + buffer: "npm:^6.0.3" + chai: "npm:^4.3.10" + chai-as-promised: "npm:^7.1.1" + dirty-chai: "npm:^2.0.1" + eslint: "npm:^8.53.0" + eslint-config-airbnb-base: "npm:^15.0.0" + eslint-plugin-import: "npm:^2.29.0" + eslint-plugin-jsdoc: "npm:^46.9.0" + events: "npm:^3.3.0" + karma: "npm:^6.4.3" + karma-chai: "npm:^0.1.0" + karma-chrome-launcher: "npm:^3.1.0" + karma-firefox-launcher: "npm:^2.1.2" + karma-mocha: "npm:^2.0.1" + karma-mocha-reporter: "npm:^2.2.5" + karma-webpack: "npm:^5.0.0" + mocha: "npm:^11.1.0" + path-browserify: "npm:^1.0.1" + process: "npm:^0.11.10" + string_decoder: "npm:^1.3.0" + url: "npm:^0.11.3" + util: "npm:^0.12.4" + webpack: "npm:^5.94.0" + webpack-cli: "npm:^4.9.1" + languageName: unknown + linkType: soft + "@dashevo/wasm-dpp@workspace:*, @dashevo/wasm-dpp@workspace:packages/wasm-dpp": version: 0.0.0-use.local resolution: "@dashevo/wasm-dpp@workspace:packages/wasm-dpp" From e99494f6ec1f2ef9cfe150ba9da419beed5c2006 Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Sat, 4 Oct 2025 20:22:54 +0700 Subject: [PATCH 02/44] refactor: remove WASM postfix from JS names --- .../src/asset_lock_proof/chain/mod.rs | 8 +- .../asset_lock_proof/instant/instant_lock.rs | 8 +- .../src/asset_lock_proof/instant/mod.rs | 8 +- .../wasm-dpp2/src/asset_lock_proof/mod.rs | 16 +- .../src/asset_lock_proof/outpoint/mod.rs | 10 +- .../src/asset_lock_proof/tx_out/mod.rs | 8 +- .../src/batch/batched_transition/mod.rs | 16 +- .../src/batch/document_base_transition/mod.rs | 10 +- .../src/batch/document_transition/mod.rs | 8 +- .../batch/document_transitions/create/mod.rs | 12 +- .../batch/document_transitions/delete/mod.rs | 10 +- .../document_transitions/purchase/mod.rs | 10 +- .../batch/document_transitions/replace/mod.rs | 10 +- .../document_transitions/transfer/mod.rs | 10 +- .../document_transitions/update_price/mod.rs | 10 +- packages/wasm-dpp2/src/batch/mod.rs | 12 +- .../src/batch/prefunded_voting_balance/mod.rs | 8 +- .../src/batch/token_base_transition/mod.rs | 12 +- .../src/batch/token_payment_info/mod.rs | 8 +- .../src/batch/token_pricing_schedule/mod.rs | 8 +- .../src/batch/token_transition/mod.rs | 52 ++-- .../batch/token_transitions/config_update.rs | 8 +- .../token_transitions/direct_purchase.rs | 8 +- .../set_price_for_direct_purchase.rs | 12 +- .../src/batch/token_transitions/token_burn.rs | 8 +- .../batch/token_transitions/token_claim.rs | 8 +- .../token_destroy_frozen_funds.rs | 8 +- .../token_emergency_action.rs | 8 +- .../batch/token_transitions/token_freeze.rs | 8 +- .../src/batch/token_transitions/token_mint.rs | 8 +- .../batch/token_transitions/token_transfer.rs | 16 +- .../batch/token_transitions/token_unfreeze.rs | 8 +- packages/wasm-dpp2/src/consensus_error/mod.rs | 4 +- packages/wasm-dpp2/src/contract_bounds/mod.rs | 8 +- packages/wasm-dpp2/src/core_script/mod.rs | 8 +- packages/wasm-dpp2/src/data_contract/mod.rs | 12 +- .../data_contract_transitions/create/mod.rs | 8 +- .../data_contract_transitions/update/mod.rs | 8 +- .../wasm-dpp2/src/document/methods/mod.rs | 6 +- packages/wasm-dpp2/src/document/mod.rs | 2 +- .../private_encrypted_note/mod.rs | 8 +- .../shared_encrypted_note/mod.rs | 8 +- .../src/enums/batch/gas_fees_paid_by.rs | 2 +- .../enums/contested/vote_state_result_type.rs | 2 +- .../wasm-dpp2/src/enums/lock_types/mod.rs | 2 +- packages/wasm-dpp2/src/enums/network/mod.rs | 2 +- packages/wasm-dpp2/src/enums/platform/mod.rs | 2 +- .../wasm-dpp2/src/enums/token/action_goal.rs | 2 +- .../src/enums/token/distribution_type.rs | 2 +- .../src/enums/token/emergency_action.rs | 2 +- .../src/group_state_transition_info/mod.rs | 8 +- packages/wasm-dpp2/src/identifier/mod.rs | 12 +- packages/wasm-dpp2/src/identity/mod.rs | 8 +- .../wasm-dpp2/src/identity_public_key/mod.rs | 12 +- .../create_transition/mod.rs | 8 +- .../credit_withdrawal_transition/mod.rs | 12 +- .../mod.rs | 8 +- .../public_key_in_creation/mod.rs | 14 +- .../top_up_transition/mod.rs | 8 +- .../update_transition/mod.rs | 8 +- packages/wasm-dpp2/src/masternode_vote/mod.rs | 8 +- .../resource_vote_choice/mod.rs | 8 +- .../wasm-dpp2/src/masternode_vote/vote/mod.rs | 8 +- .../src/masternode_vote/vote_poll/mod.rs | 8 +- .../wasm-dpp2/src/partial_identity/mod.rs | 6 +- packages/wasm-dpp2/src/private_key/mod.rs | 10 +- packages/wasm-dpp2/src/public_key/mod.rs | 8 +- .../wasm-dpp2/src/state_transition/mod.rs | 8 +- .../src/token_configuration/action_taker.rs | 8 +- .../authorized_action_takers.rs | 8 +- .../change_control_rules.rs | 10 +- .../configuration_convention.rs | 8 +- .../distribution_function.rs | 8 +- .../distribution_recipient.rs | 8 +- .../token_configuration/distribution_rules.rs | 16 +- .../distribution_structs.rs | 16 +- .../src/token_configuration/group.rs | 8 +- .../keeps_history_rules.rs | 8 +- .../src/token_configuration/localization.rs | 8 +- .../token_configuration/marketplace_rules.rs | 8 +- .../wasm-dpp2/src/token_configuration/mod.rs | 8 +- .../perpetual_distribution.rs | 8 +- .../pre_programmed_distribution.rs | 8 +- .../reward_distribution_type.rs | 32 +- .../src/token_configuration/trade_mode.rs | 8 +- .../items/conventions.rs | 2 +- .../items/destroy_frozen_funds.rs | 2 +- .../items/emergency_action.rs | 2 +- .../items/freeze.rs | 2 +- .../items/main_control_group.rs | 2 +- .../items/manual_burning.rs | 2 +- .../items/manual_minting.rs | 2 +- .../items/marketplace_trade_mode.rs | 2 +- .../items/max_supply.rs | 2 +- .../minting_allow_choosing_destination.rs | 2 +- .../items/new_tokens_destination_identity.rs | 2 +- .../items/no_change.rs | 2 +- .../items/perpetual_distribution.rs | 4 +- .../items/unfreeze.rs | 2 +- .../token_configuration_change_item/mod.rs | 8 +- .../tests/unit/AssetLockProof.spec.mjs | 58 ++-- .../unit/AuthorizedActionTakers.spec.mjs | 20 +- .../tests/unit/BatchTransition.spec.mjs | 68 ++--- .../tests/unit/ChainLockProof.spec.mjs | 28 +- .../tests/unit/ChangeControlRules.spec.mjs | 56 ++-- .../wasm-dpp2/tests/unit/CoreScript.spec.mjs | 12 +- .../tests/unit/DataContract.spec.mjs | 56 ++-- ...DataContractCreateStateTransition.spec.mjs | 42 +-- ...DataContractUpdateStateTransition.spec.mjs | 42 +-- .../tests/unit/DistributionFunction.spec.mjs | 54 ++-- .../wasm-dpp2/tests/unit/Document.spec.mjs | 66 ++--- .../tests/unit/DocumentTransition.spec.mjs | 6 +- .../tests/unit/DocumentsTransitions.spec.mjs | 274 +++++++++--------- .../wasm-dpp2/tests/unit/Identifier.spec.mjs | 24 +- .../wasm-dpp2/tests/unit/Identity.spec.mjs | 26 +- .../unit/IdentityCreateTransition.spec.mjs | 20 +- .../IdentityCreditTransferTransition.spec.mjs | 40 +-- ...dentityCreditWithdrawalTransition.spec.mjs | 106 +++---- .../tests/unit/IdentityPublicKey.spec.mjs | 18 +- .../unit/IdentityTopUpTransition.spec.mjs | 30 +- .../unit/IdentityUpdateTransition.spec.mjs | 40 +-- .../tests/unit/InstantLockProof.spec.mjs | 26 +- .../wasm-dpp2/tests/unit/OutPoint.spec.mjs | 10 +- .../wasm-dpp2/tests/unit/PrivateKey.spec.mjs | 20 +- .../tests/unit/PublicKeyInCreation.spec.mjs | 34 +-- .../unit/RewardDistributionType.spec.mjs | 30 +- .../tests/unit/TokenBaseTransition.spec.mjs | 30 +- .../tests/unit/TokenConfiguration.spec.mjs | 60 ++-- .../TokenConfigurationConvention.spec.mjs | 20 +- .../TokenConfigurationLocalization.spec.mjs | 14 +- .../unit/TokenDistributionRecipient.spec.mjs | 12 +- .../unit/TokenDistributionRules.spec.mjs | 82 +++--- .../unit/TokenKeepsHistoryRules.spec.mjs | 6 +- .../unit/TokenPerpetualDistribution.spec.mjs | 54 ++-- .../TokenPreProgrammedDistribution.spec.mjs | 6 +- .../tests/unit/TokensTransitions.spec.mjs | 220 +++++++------- packages/wasm-dpp2/tests/unit/TxOut.spec.mjs | 18 +- .../wasm-dpp2/tests/unit/module-load.spec.mjs | 10 +- 138 files changed, 1279 insertions(+), 1279 deletions(-) diff --git a/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs index 9e8c60233bf..39d327c545c 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs @@ -12,7 +12,7 @@ struct ChainAssetLockProofParams { out_point: Vec, } -#[wasm_bindgen(js_name = "ChainAssetLockProofWASM")] +#[wasm_bindgen(js_name = "ChainAssetLockProof")] #[derive(Clone)] pub struct ChainAssetLockProofWASM(ChainAssetLockProof); @@ -28,16 +28,16 @@ impl From for ChainAssetLockProofWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = ChainAssetLockProof)] impl ChainAssetLockProofWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "ChainAssetLockProofWASM".to_string() + "ChainAssetLockProof".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "ChainAssetLockProofWASM".to_string() + "ChainAssetLockProof".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs index 3cf5608749e..e6bcb86f3ac 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs @@ -9,7 +9,7 @@ use std::str::FromStr; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "InstantLockWASM")] +#[wasm_bindgen(js_name = "InstantLock")] #[derive(Clone)] pub struct InstantLockWASM(InstantLock); @@ -25,16 +25,16 @@ impl From for InstantLockWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = InstantLock)] impl InstantLockWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "InstantLockWASM".to_string() + "InstantLock".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "InstantLockWASM".to_string() + "InstantLock".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs index 2b12175cfd6..4f404fbf789 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs @@ -21,7 +21,7 @@ struct InstantAssetLockProofRAW { } #[derive(Clone)] -#[wasm_bindgen(js_name = "InstantAssetLockProofWASM")] +#[wasm_bindgen(js_name = "InstantAssetLockProof")] pub struct InstantAssetLockProofWASM(InstantAssetLockProof); impl From for InstantAssetLockProof { @@ -36,16 +36,16 @@ impl From for InstantAssetLockProofWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = InstantAssetLockProof)] impl InstantAssetLockProofWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "InstantAssetLockProofWASM".to_string() + "InstantAssetLockProof".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "InstantAssetLockProofWASM".to_string() + "InstantAssetLockProof".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/asset_lock_proof/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/mod.rs index 4837d556745..49f405c6366 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/mod.rs @@ -15,7 +15,7 @@ use serde::Serialize; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "AssetLockProofWASM")] +#[wasm_bindgen(js_name = "AssetLockProof")] #[derive(Clone)] pub struct AssetLockProofWASM(AssetLockProof); @@ -61,31 +61,31 @@ impl From for InstantAssetLockProofWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = AssetLockProof)] impl AssetLockProofWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "AssetLockProofWASM".to_string() + "AssetLockProof".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "AssetLockProofWASM".to_string() + "AssetLockProof".to_string() } #[wasm_bindgen(constructor)] pub fn new(js_asset_lock_proof: &JsValue) -> Result { match get_class_type(js_asset_lock_proof)?.as_str() { - "ChainAssetLockProofWASM" => { + "ChainAssetLockProof" => { let chain_lock = js_asset_lock_proof - .to_wasm::("ChainAssetLockProofWASM")? + .to_wasm::("ChainAssetLockProof")? .clone(); Ok(AssetLockProofWASM::from(chain_lock)) } - "InstantAssetLockProofWASM" => { + "InstantAssetLockProof" => { let instant_lock = js_asset_lock_proof - .to_wasm::("InstantAssetLockProofWASM")? + .to_wasm::("InstantAssetLockProof")? .clone(); Ok(AssetLockProofWASM::from(instant_lock)) diff --git a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs index 6e6c4b66c7e..b0eb14d8c23 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs @@ -5,7 +5,7 @@ use dpp::platform_value::string_encoding::{decode, encode}; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; -#[wasm_bindgen(js_name = "OutPointWASM")] +#[wasm_bindgen(js_name = "OutPoint")] #[derive(Clone)] pub struct OutPointWASM(OutPoint); @@ -24,22 +24,22 @@ impl From for OutPoint { impl TryFrom for OutPointWASM { type Error = JsValue; fn try_from(value: JsValue) -> Result { - let value = value.to_wasm::("OutPointWASM")?; + let value = value.to_wasm::("OutPoint")?; Ok(value.clone()) } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = OutPoint)] impl OutPointWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "OutPointWASM".to_string() + "OutPoint".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "OutPointWASM".to_string() + "OutPoint".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs index e6050a427ff..c181776e223 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs @@ -3,7 +3,7 @@ use js_sys::Uint8Array; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "TxOutWASM")] +#[wasm_bindgen(js_name = "TxOut")] #[derive(Clone)] pub struct TxOutWASM(TxOut); @@ -19,16 +19,16 @@ impl From for TxOut { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TxOut)] impl TxOutWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TxOutWASM".to_string() + "TxOut".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TxOutWASM".to_string() + "TxOut".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/batch/batched_transition/mod.rs b/packages/wasm-dpp2/src/batch/batched_transition/mod.rs index 697ef08bbfe..bbbd88332e1 100644 --- a/packages/wasm-dpp2/src/batch/batched_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/batched_transition/mod.rs @@ -13,7 +13,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=BatchedTransitionWASM)] +#[wasm_bindgen(js_name=BatchedTransition)] pub struct BatchedTransitionWASM(BatchedTransition); impl From for BatchedTransitionWASM { @@ -28,16 +28,16 @@ impl From for BatchedTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = BatchedTransition)] impl BatchedTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "BatchedTransitionWASM".to_string() + "BatchedTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "BatchedTransitionWASM".to_string() + "BatchedTransition".to_string() } #[wasm_bindgen(constructor)] @@ -45,17 +45,17 @@ impl BatchedTransitionWASM { match js_transition.is_undefined() && js_transition.is_object() { true => Err(JsValue::from_str("transition is undefined")), false => match get_class_type(js_transition)?.as_str() { - "TokenTransitionWASM" => Ok(BatchedTransitionWASM::from(BatchedTransition::from( + "TokenTransition" => Ok(BatchedTransitionWASM::from(BatchedTransition::from( TokenTransition::from( js_transition - .to_wasm::("TokenTransitionWASM")? + .to_wasm::("TokenTransition")? .clone(), ), ))), - "DocumentTransitionWASM" => Ok(BatchedTransitionWASM(BatchedTransition::Document( + "DocumentTransition" => Ok(BatchedTransitionWASM(BatchedTransition::Document( DocumentTransition::from( js_transition - .to_wasm::("DocumentTransitionWASM")? + .to_wasm::("DocumentTransition")? .clone(), ), ))), diff --git a/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs b/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs index dfc91e50c7a..30c3ca6a802 100644 --- a/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs @@ -11,7 +11,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] -#[wasm_bindgen(js_name = "DocumentBaseTransitionWASM")] +#[wasm_bindgen(js_name = "DocumentBaseTransition")] pub struct DocumentBaseTransitionWASM(DocumentBaseTransition); impl From for DocumentBaseTransitionWASM { @@ -26,16 +26,16 @@ impl From for DocumentBaseTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = DocumentBaseTransition)] impl DocumentBaseTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DocumentBaseTransitionWASM".to_string() + "DocumentBaseTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DocumentBaseTransitionWASM".to_string() + "DocumentBaseTransition".to_string() } #[wasm_bindgen(constructor)] @@ -51,7 +51,7 @@ impl DocumentBaseTransitionWASM { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfoWASM")? + .to_wasm::("TokenPaymentInfo")? .clone() .into(), ), diff --git a/packages/wasm-dpp2/src/batch/document_transition/mod.rs b/packages/wasm-dpp2/src/batch/document_transition/mod.rs index cdfcebb9160..b902f5169cd 100644 --- a/packages/wasm-dpp2/src/batch/document_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transition/mod.rs @@ -15,7 +15,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] -#[wasm_bindgen(js_name = "DocumentTransitionWASM")] +#[wasm_bindgen(js_name = "DocumentTransition")] pub struct DocumentTransitionWASM(DocumentTransition); impl From for DocumentTransitionWASM { @@ -30,16 +30,16 @@ impl From for DocumentTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = DocumentTransition)] impl DocumentTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DocumentTransitionWASM".to_string() + "DocumentTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DocumentTransitionWASM".to_string() + "DocumentTransition".to_string() } #[wasm_bindgen(getter = "actionType")] diff --git a/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs index 76eb10a02e1..e8ae89c1f2e 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs @@ -14,7 +14,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use crate::batch::prefunded_voting_balance::PrefundedVotingBalanceWASM; use crate::batch::token_payment_info::TokenPaymentInfoWASM; -#[wasm_bindgen(js_name = "DocumentCreateTransitionWASM")] +#[wasm_bindgen(js_name = "DocumentCreateTransition")] #[derive(Clone)] pub struct DocumentCreateTransitionWASM(DocumentCreateTransition); @@ -30,16 +30,16 @@ impl From for DocumentCreateTransitionWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = DocumentCreateTransition)] impl DocumentCreateTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DocumentCreateTransitionWASM".to_string() + "DocumentCreateTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DocumentCreateTransitionWASM".to_string() + "DocumentCreateTransition".to_string() } #[wasm_bindgen(constructor)] @@ -55,7 +55,7 @@ impl DocumentCreateTransitionWASM { true => None, false => Some( js_prefunded_voting_balance - .to_wasm::("PrefundedVotingBalanceWASM")? + .to_wasm::("PrefundedVotingBalance")? .clone(), ), }; @@ -65,7 +65,7 @@ impl DocumentCreateTransitionWASM { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfoWASM")? + .to_wasm::("TokenPaymentInfo")? .clone(), ), }; diff --git a/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs index 31c5ad26d66..ad8cb8e41a1 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs @@ -11,7 +11,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use crate::utils::IntoWasm; use crate::batch::token_payment_info::TokenPaymentInfoWASM; -#[wasm_bindgen(js_name = "DocumentDeleteTransitionWASM")] +#[wasm_bindgen(js_name = "DocumentDeleteTransition")] pub struct DocumentDeleteTransitionWASM(DocumentDeleteTransition); impl From for DocumentDeleteTransitionWASM { @@ -20,16 +20,16 @@ impl From for DocumentDeleteTransitionWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = DocumentDeleteTransition)] impl DocumentDeleteTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DocumentDeleteTransitionWASM".to_string() + "DocumentDeleteTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DocumentDeleteTransitionWASM".to_string() + "DocumentDeleteTransition".to_string() } #[wasm_bindgen(constructor)] @@ -43,7 +43,7 @@ impl DocumentDeleteTransitionWASM { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfoWASM")? + .to_wasm::("TokenPaymentInfo")? .clone(), ), }; diff --git a/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs index 4b9dd62ac85..fc5f941a05e 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs @@ -13,7 +13,7 @@ use crate::batch::document_transition::DocumentTransitionWASM; use crate::batch::generators::generate_purchase_transition; use crate::batch::token_payment_info::TokenPaymentInfoWASM; -#[wasm_bindgen(js_name = "DocumentPurchaseTransitionWASM")] +#[wasm_bindgen(js_name = "DocumentPurchaseTransition")] pub struct DocumentPurchaseTransitionWASM(DocumentPurchaseTransition); impl From for DocumentPurchaseTransition { @@ -28,16 +28,16 @@ impl From for DocumentPurchaseTransitionWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = DocumentPurchaseTransition)] impl DocumentPurchaseTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DocumentPurchaseTransitionWASM".to_string() + "DocumentPurchaseTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DocumentPurchaseTransitionWASM".to_string() + "DocumentPurchaseTransition".to_string() } #[wasm_bindgen(constructor)] @@ -52,7 +52,7 @@ impl DocumentPurchaseTransitionWASM { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfoWASM")? + .to_wasm::("TokenPaymentInfo")? .clone(), ), }; diff --git a/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs index ed0f5969734..15a570e9bc4 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs @@ -13,7 +13,7 @@ use crate::batch::generators::generate_replace_transition; use crate::batch::document_transition::DocumentTransitionWASM; use crate::batch::token_payment_info::TokenPaymentInfoWASM; -#[wasm_bindgen(js_name = "DocumentReplaceTransitionWASM")] +#[wasm_bindgen(js_name = "DocumentReplaceTransition")] pub struct DocumentReplaceTransitionWASM(DocumentReplaceTransition); impl From for DocumentReplaceTransitionWASM { @@ -28,16 +28,16 @@ impl From for DocumentReplaceTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = DocumentReplaceTransition)] impl DocumentReplaceTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DocumentReplaceTransitionWASM".to_string() + "DocumentReplaceTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DocumentReplaceTransitionWASM".to_string() + "DocumentReplaceTransition".to_string() } #[wasm_bindgen(constructor)] @@ -51,7 +51,7 @@ impl DocumentReplaceTransitionWASM { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfoWASM")? + .to_wasm::("TokenPaymentInfo")? .clone(), ), }; diff --git a/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs index 047d24eb88f..f817b0a95d5 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs @@ -13,7 +13,7 @@ use crate::batch::document_transition::DocumentTransitionWASM; use crate::batch::generators::generate_transfer_transition; use crate::batch::token_payment_info::TokenPaymentInfoWASM; -#[wasm_bindgen(js_name = "DocumentTransferTransitionWASM")] +#[wasm_bindgen(js_name = "DocumentTransferTransition")] pub struct DocumentTransferTransitionWASM(DocumentTransferTransition); impl From for DocumentTransferTransitionWASM { @@ -28,16 +28,16 @@ impl From for DocumentTransferTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = DocumentTransferTransition)] impl DocumentTransferTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DocumentTransferTransitionWASM".to_string() + "DocumentTransferTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DocumentTransferTransitionWASM".to_string() + "DocumentTransferTransition".to_string() } #[wasm_bindgen(constructor)] @@ -52,7 +52,7 @@ impl DocumentTransferTransitionWASM { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfoWASM")? + .to_wasm::("TokenPaymentInfo")? .clone(), ), }; diff --git a/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs index 0511d8c8dd0..3e5eb458d72 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs @@ -13,7 +13,7 @@ use crate::batch::document_transition::DocumentTransitionWASM; use crate::batch::generators::generate_update_price_transition; use crate::batch::token_payment_info::TokenPaymentInfoWASM; -#[wasm_bindgen(js_name = "DocumentUpdatePriceTransitionWASM")] +#[wasm_bindgen(js_name = "DocumentUpdatePriceTransition")] pub struct DocumentUpdatePriceTransitionWASM(DocumentUpdatePriceTransition); impl From for DocumentUpdatePriceTransitionWASM { @@ -22,16 +22,16 @@ impl From for DocumentUpdatePriceTransitionWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = DocumentUpdatePriceTransition)] impl DocumentUpdatePriceTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DocumentUpdatePriceTransitionWASM".to_string() + "DocumentUpdatePriceTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DocumentUpdatePriceTransitionWASM".to_string() + "DocumentUpdatePriceTransition".to_string() } #[wasm_bindgen(constructor)] @@ -46,7 +46,7 @@ impl DocumentUpdatePriceTransitionWASM { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfoWASM")? + .to_wasm::("TokenPaymentInfo")? .clone(), ), }; diff --git a/packages/wasm-dpp2/src/batch/mod.rs b/packages/wasm-dpp2/src/batch/mod.rs index 696fb1c8517..ed1be88be55 100644 --- a/packages/wasm-dpp2/src/batch/mod.rs +++ b/packages/wasm-dpp2/src/batch/mod.rs @@ -34,7 +34,7 @@ pub mod token_transition; pub mod token_transitions; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=BatchTransitionWASM)] +#[wasm_bindgen(js_name=BatchTransition)] pub struct BatchTransitionWASM(BatchTransition); impl From for BatchTransitionWASM { @@ -55,7 +55,7 @@ fn convert_array_to_vec_batched(js_batched_transitions: &js_sys::Array) -> Vec("BatchedTransitionWASM") + .to_wasm::("BatchedTransition") .unwrap() .clone(); BatchedTransition::from(batched_transition) @@ -63,16 +63,16 @@ fn convert_array_to_vec_batched(js_batched_transitions: &js_sys::Array) -> Vec String { - "BatchTransitionWASM".to_string() + "BatchTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "BatchTransitionWASM".to_string() + "BatchTransition".to_string() } #[wasm_bindgen(js_name = "fromV1BatchedTransitions")] @@ -111,7 +111,7 @@ impl BatchTransitionWASM { .iter() .map(|js_document_transition| { let document_transition: DocumentTransitionWASM = js_document_transition - .to_wasm::("DocumentTransitionWASM") + .to_wasm::("DocumentTransition") .unwrap() .clone(); diff --git a/packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs b/packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs index 32e2b624b48..3945e3d3d8f 100644 --- a/packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs +++ b/packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs @@ -1,7 +1,7 @@ use dpp::fee::Credits; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "PrefundedVotingBalanceWASM")] +#[wasm_bindgen(js_name = "PrefundedVotingBalance")] #[derive(Clone)] pub struct PrefundedVotingBalanceWASM { index_name: String, @@ -23,16 +23,16 @@ impl From for (String, Credits) { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = PrefundedVotingBalance)] impl PrefundedVotingBalanceWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "PrefundedVotingBalanceWASM".to_string() + "PrefundedVotingBalance".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "PrefundedVotingBalanceWASM".to_string() + "PrefundedVotingBalance".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs b/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs index 75680f48e75..9f0b6214761 100644 --- a/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs @@ -10,7 +10,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=TokenBaseTransitionWASM)] +#[wasm_bindgen(js_name=TokenBaseTransition)] pub struct TokenBaseTransitionWASM(TokenBaseTransition); impl From for TokenBaseTransitionWASM { @@ -25,16 +25,16 @@ impl From for TokenBaseTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenBaseTransition)] impl TokenBaseTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenBaseTransitionWASM".to_string() + "TokenBaseTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenBaseTransitionWASM".to_string() + "TokenBaseTransition".to_string() } #[wasm_bindgen(constructor)] @@ -49,7 +49,7 @@ impl TokenBaseTransitionWASM { match js_using_group_info.is_undefined() { false => Some( js_using_group_info - .to_wasm::("GroupStateTransitionInfoWASM")? + .to_wasm::("GroupStateTransitionInfo")? .clone() .into(), ), @@ -126,7 +126,7 @@ impl TokenBaseTransitionWASM { match js_using_group_info.is_undefined() { false => Some( js_using_group_info - .to_wasm::("GroupStateTransitionInfoWASM")? + .to_wasm::("GroupStateTransitionInfo")? .clone() .into(), ), diff --git a/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs b/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs index 1be9a1ee32d..e972b686e8c 100644 --- a/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs @@ -11,7 +11,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] -#[wasm_bindgen(js_name = "TokenPaymentInfoWASM")] +#[wasm_bindgen(js_name = "TokenPaymentInfo")] pub struct TokenPaymentInfoWASM(TokenPaymentInfo); impl From for TokenPaymentInfoWASM { @@ -26,16 +26,16 @@ impl From for TokenPaymentInfo { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenPaymentInfo)] impl TokenPaymentInfoWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenPaymentInfoWASM".to_string() + "TokenPaymentInfo".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenPaymentInfoWASM".to_string() + "TokenPaymentInfo".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs b/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs index c818f96bca4..7741a9d469f 100644 --- a/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs @@ -8,7 +8,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = "TokenPricingScheduleWASM")] +#[wasm_bindgen(js_name = "TokenPricingSchedule")] pub struct TokenPricingScheduleWASM(TokenPricingSchedule); impl From for TokenPricingSchedule { @@ -23,16 +23,16 @@ impl From for TokenPricingScheduleWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenPricingSchedule)] impl TokenPricingScheduleWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenPricingScheduleWASM".to_string() + "TokenPricingSchedule".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenPricingScheduleWASM".to_string() + "TokenPricingSchedule".to_string() } #[wasm_bindgen(js_name = "SinglePrice")] diff --git a/packages/wasm-dpp2/src/batch/token_transition/mod.rs b/packages/wasm-dpp2/src/batch/token_transition/mod.rs index 82d95391084..dd472dc6ae2 100644 --- a/packages/wasm-dpp2/src/batch/token_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_transition/mod.rs @@ -25,7 +25,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=TokenTransitionWASM)] +#[wasm_bindgen(js_name=TokenTransition)] pub struct TokenTransitionWASM(TokenTransition); impl From for TokenTransitionWASM { @@ -40,101 +40,101 @@ impl From for TokenTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenTransition)] impl TokenTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenTransitionWASM".to_string() + "TokenTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenTransitionWASM".to_string() + "TokenTransition".to_string() } #[wasm_bindgen(constructor)] pub fn new(js_transition: &JsValue) -> Result { let transition = match js_transition.is_object() { true => match get_class_type(js_transition)?.as_str() { - "TokenMintTransitionWASM" => Ok(TokenTransition::from(TokenMintTransition::from( + "TokenMintTransition" => Ok(TokenTransition::from(TokenMintTransition::from( js_transition - .to_wasm::("TokenMintTransitionWASM")? + .to_wasm::("TokenMintTransition")? .clone(), ))), - "TokenUnFreezeTransitionWASM" => { + "TokenUnFreezeTransition" => { Ok(TokenTransition::from(TokenUnfreezeTransition::from( js_transition - .to_wasm::("TokenUnFreezeTransitionWASM")? + .to_wasm::("TokenUnFreezeTransition")? .clone(), ))) } - "TokenTransferTransitionWASM" => { + "TokenTransferTransition" => { Ok(TokenTransition::from(TokenTransferTransition::from( js_transition - .to_wasm::("TokenTransferTransitionWASM")? + .to_wasm::("TokenTransferTransition")? .clone(), ))) } - "TokenFreezeTransitionWASM" => { + "TokenFreezeTransition" => { Ok(TokenTransition::from(TokenFreezeTransition::from( js_transition - .to_wasm::("TokenFreezeTransitionWASM")? + .to_wasm::("TokenFreezeTransition")? .clone(), ))) } - "TokenDestroyFrozenFundsTransitionWASM" => Ok(TokenTransition::from( + "TokenDestroyFrozenFundsTransition" => Ok(TokenTransition::from( TokenDestroyFrozenFundsTransition::from( js_transition .to_wasm::( - "TokenDestroyFrozenFundsTransitionWASM", + "TokenDestroyFrozenFundsTransition", )? .clone(), ), )), - "TokenClaimTransitionWASM" => { + "TokenClaimTransition" => { Ok(TokenTransition::from(TokenClaimTransition::from( js_transition - .to_wasm::("TokenClaimTransitionWASM")? + .to_wasm::("TokenClaimTransition")? .clone(), ))) } - "TokenBurnTransitionWASM" => Ok(TokenTransition::from(TokenBurnTransition::from( + "TokenBurnTransition" => Ok(TokenTransition::from(TokenBurnTransition::from( js_transition - .to_wasm::("TokenBurnTransitionWASM")? + .to_wasm::("TokenBurnTransition")? .clone(), ))), - "TokenSetPriceForDirectPurchaseTransitionWASM" => Ok(TokenTransition::from( + "TokenSetPriceForDirectPurchaseTransition" => Ok(TokenTransition::from( TokenSetPriceForDirectPurchaseTransition::from( js_transition .to_wasm::( - "TokenSetPriceForDirectPurchaseTransitionWASM", + "TokenSetPriceForDirectPurchaseTransition", )? .clone(), ), )), - "TokenDirectPurchaseTransitionWASM" => { + "TokenDirectPurchaseTransition" => { Ok(TokenTransition::from(TokenDirectPurchaseTransition::from( js_transition .to_wasm::( - "TokenDirectPurchaseTransitionWASM", + "TokenDirectPurchaseTransition", )? .clone(), ))) } - "TokenConfigUpdateTransitionWASM" => { + "TokenConfigUpdateTransition" => { Ok(TokenTransition::from(TokenConfigUpdateTransition::from( js_transition .to_wasm::( - "TokenConfigUpdateTransitionWASM", + "TokenConfigUpdateTransition", )? .clone(), ))) } - "TokenEmergencyActionTransitionWASM" => { + "TokenEmergencyActionTransition" => { Ok(TokenTransition::from(TokenEmergencyActionTransition::from( js_transition .to_wasm::( - "TokenEmergencyActionTransitionWASM", + "TokenEmergencyActionTransition", )? .clone(), ))) diff --git a/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs b/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs index 340358d0001..8aea0f801d9 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs @@ -8,7 +8,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name = "TokenConfigUpdateTransitionWASM")] +#[wasm_bindgen(js_name = "TokenConfigUpdateTransition")] pub struct TokenConfigUpdateTransitionWASM(TokenConfigUpdateTransition); impl From for TokenConfigUpdateTransition { @@ -23,16 +23,16 @@ impl From for TokenConfigUpdateTransitionWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigUpdateTransition)] impl TokenConfigUpdateTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenConfigUpdateTransitionWASM".to_string() + "TokenConfigUpdateTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenConfigUpdateTransitionWASM".to_string() + "TokenConfigUpdateTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs b/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs index 8ebc262ef45..cb7076cb5cb 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs @@ -8,7 +8,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use crate::batch::token_base_transition::TokenBaseTransitionWASM; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=TokenDirectPurchaseTransitionWASM)] +#[wasm_bindgen(js_name=TokenDirectPurchaseTransition)] pub struct TokenDirectPurchaseTransitionWASM(TokenDirectPurchaseTransition); impl From for TokenDirectPurchaseTransition { @@ -23,16 +23,16 @@ impl From for TokenDirectPurchaseTransitionWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenDirectPurchaseTransition)] impl TokenDirectPurchaseTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenDirectPurchaseTransitionWASM".to_string() + "TokenDirectPurchaseTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenDirectPurchaseTransitionWASM".to_string() + "TokenDirectPurchaseTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs b/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs index 1058e0a8499..86c575d42a1 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs @@ -10,7 +10,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=TokenSetPriceForDirectPurchaseTransitionWASM)] +#[wasm_bindgen(js_name=TokenSetPriceForDirectPurchaseTransition)] pub struct TokenSetPriceForDirectPurchaseTransitionWASM(TokenSetPriceForDirectPurchaseTransition); impl From @@ -29,16 +29,16 @@ impl From } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenSetPriceForDirectPurchaseTransition)] impl TokenSetPriceForDirectPurchaseTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenSetPriceForDirectPurchaseTransitionWASM".to_string() + "TokenSetPriceForDirectPurchaseTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenSetPriceForDirectPurchaseTransitionWASM".to_string() + "TokenSetPriceForDirectPurchaseTransition".to_string() } #[wasm_bindgen(constructor)] @@ -51,7 +51,7 @@ impl TokenSetPriceForDirectPurchaseTransitionWASM { true => None, false => Some( js_price - .to_wasm::("TokenPricingScheduleWASM")? + .to_wasm::("TokenPricingSchedule")? .clone() .into(), ), @@ -102,7 +102,7 @@ impl TokenSetPriceForDirectPurchaseTransitionWASM { true => None, false => Some( js_price - .to_wasm::("TokenPricingScheduleWASM")? + .to_wasm::("TokenPricingSchedule")? .clone() .into(), ), diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs index 6b06b69df04..73f1700aa9b 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs @@ -7,7 +7,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=TokenBurnTransitionWASM)] +#[wasm_bindgen(js_name=TokenBurnTransition)] pub struct TokenBurnTransitionWASM(TokenBurnTransition); impl From for TokenBurnTransitionWASM { @@ -22,16 +22,16 @@ impl From for TokenBurnTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenBurnTransition)] impl TokenBurnTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenBurnTransitionWASM".to_string() + "TokenBurnTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenBurnTransitionWASM".to_string() + "TokenBurnTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs index 778168349ba..bdb83ac1196 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs @@ -8,7 +8,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use crate::enums::token::distribution_type::TokenDistributionTypeWASM; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name = "TokenClaimTransitionWASM")] +#[wasm_bindgen(js_name = "TokenClaimTransition")] pub struct TokenClaimTransitionWASM(TokenClaimTransition); impl From for TokenClaimTransitionWASM { @@ -23,16 +23,16 @@ impl From for TokenClaimTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenClaimTransition)] impl TokenClaimTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenClaimTransitionWASM".to_string() + "TokenClaimTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenClaimTransitionWASM".to_string() + "TokenClaimTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs index a45d1f92acf..b94ea86d054 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs @@ -9,7 +9,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use crate::identifier::IdentifierWASM; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=TokenDestroyFrozenFundsTransitionWASM)] +#[wasm_bindgen(js_name=TokenDestroyFrozenFundsTransition)] pub struct TokenDestroyFrozenFundsTransitionWASM(TokenDestroyFrozenFundsTransition); impl From for TokenDestroyFrozenFundsTransitionWASM { @@ -24,16 +24,16 @@ impl From for TokenDestroyFrozenFundsTran } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenDestroyFrozenFundsTransition)] impl TokenDestroyFrozenFundsTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenDestroyFrozenFundsTransitionWASM".to_string() + "TokenDestroyFrozenFundsTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenDestroyFrozenFundsTransitionWASM".to_string() + "TokenDestroyFrozenFundsTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs index 197273fe51d..9beea1725ab 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs @@ -7,7 +7,7 @@ use crate::enums::token::emergency_action::TokenEmergencyActionWASM; use crate::batch::token_base_transition::TokenBaseTransitionWASM; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name = "TokenEmergencyActionTransitionWASM")] +#[wasm_bindgen(js_name = "TokenEmergencyActionTransition")] pub struct TokenEmergencyActionTransitionWASM(TokenEmergencyActionTransition); impl From for TokenEmergencyActionTransition { @@ -22,16 +22,16 @@ impl From for TokenEmergencyActionTransitionWASM } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenEmergencyActionTransition)] impl TokenEmergencyActionTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenEmergencyActionTransitionWASM".to_string() + "TokenEmergencyActionTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenEmergencyActionTransitionWASM".to_string() + "TokenEmergencyActionTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs index f97937864e9..808c3b00923 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs @@ -9,7 +9,7 @@ use crate::identifier::IdentifierWASM; use crate::batch::token_base_transition::TokenBaseTransitionWASM; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=TokenFreezeTransitionWASM)] +#[wasm_bindgen(js_name=TokenFreezeTransition)] pub struct TokenFreezeTransitionWASM(TokenFreezeTransition); impl From for TokenFreezeTransition { @@ -24,16 +24,16 @@ impl From for TokenFreezeTransitionWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenFreezeTransition)] impl TokenFreezeTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenFreezeTransitionWASM".to_string() + "TokenFreezeTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenFreezeTransitionWASM".to_string() + "TokenFreezeTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs index f0573858e39..992051f054e 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs @@ -11,7 +11,7 @@ use crate::token_configuration::TokenConfigurationWASM; use crate::utils::WithJsError; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=TokenMintTransitionWASM)] +#[wasm_bindgen(js_name=TokenMintTransition)] pub struct TokenMintTransitionWASM(TokenMintTransition); impl From for TokenMintTransitionWASM { @@ -26,16 +26,16 @@ impl From for TokenMintTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenMintTransition)] impl TokenMintTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenMintTransitionWASM".to_string() + "TokenMintTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenMintTransitionWASM".to_string() + "TokenMintTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs index 589e36f4675..cb64d42db70 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs @@ -13,7 +13,7 @@ use crate::encrypted_note::shared_encrypted_note::SharedEncryptedNoteWASM; use crate::utils::IntoWasm; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=TokenTransferTransitionWASM)] +#[wasm_bindgen(js_name=TokenTransferTransition)] pub struct TokenTransferTransitionWASM(TokenTransferTransition); impl From for TokenTransferTransitionWASM { @@ -28,16 +28,16 @@ impl From for TokenTransferTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenTransferTransition)] impl TokenTransferTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenTransferTransitionWASM".to_string() + "TokenTransferTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenTransferTransitionWASM".to_string() + "TokenTransferTransition".to_string() } #[wasm_bindgen(constructor)] @@ -56,7 +56,7 @@ impl TokenTransferTransitionWASM { true => None, false => Some( js_shared_encrypted_note - .to_wasm::("SharedEncryptedNoteWASM")? + .to_wasm::("SharedEncryptedNote")? .clone() .into(), ), @@ -67,7 +67,7 @@ impl TokenTransferTransitionWASM { true => None, false => Some( js_private_encrypted_note - .to_wasm::("PrivateEncryptedNoteWASM")? + .to_wasm::("PrivateEncryptedNote")? .clone() .into(), ), @@ -155,7 +155,7 @@ impl TokenTransferTransitionWASM { true => None, false => Some( js_shared_encrypted_note - .to_wasm::("SharedEncryptedNoteWASM")? + .to_wasm::("SharedEncryptedNote")? .clone() .into(), ), @@ -174,7 +174,7 @@ impl TokenTransferTransitionWASM { true => None, false => Some( js_private_encrypted_note - .to_wasm::("PrivateEncryptedNoteWASM")? + .to_wasm::("PrivateEncryptedNote")? .clone() .into(), ), diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs index e6c0055edb6..f65a8bac4f8 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs @@ -9,7 +9,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=TokenUnFreezeTransitionWASM)] +#[wasm_bindgen(js_name=TokenUnFreezeTransition)] pub struct TokenUnFreezeTransitionWASM(TokenUnfreezeTransition); impl From for TokenUnFreezeTransitionWASM { @@ -24,16 +24,16 @@ impl From for TokenUnfreezeTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenUnFreezeTransition)] impl TokenUnFreezeTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenUnFreezeTransitionWASM".to_string() + "TokenUnFreezeTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenUnFreezeTransitionWASM".to_string() + "TokenUnFreezeTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/consensus_error/mod.rs b/packages/wasm-dpp2/src/consensus_error/mod.rs index 3cad23d9c2b..1878d1d752b 100644 --- a/packages/wasm-dpp2/src/consensus_error/mod.rs +++ b/packages/wasm-dpp2/src/consensus_error/mod.rs @@ -4,10 +4,10 @@ use dpp::serialization::PlatformDeserializable; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "ConsensusErrorWASM")] +#[wasm_bindgen(js_name = "ConsensusError")] pub struct ConsensusErrorWASM(ConsensusError); -#[wasm_bindgen] +#[wasm_bindgen(js_class = ConsensusError)] impl ConsensusErrorWASM { #[wasm_bindgen(js_name = "deserialize")] pub fn deserialize(error: Vec) -> Result { diff --git a/packages/wasm-dpp2/src/contract_bounds/mod.rs b/packages/wasm-dpp2/src/contract_bounds/mod.rs index c248e638703..0d806625e74 100644 --- a/packages/wasm-dpp2/src/contract_bounds/mod.rs +++ b/packages/wasm-dpp2/src/contract_bounds/mod.rs @@ -3,7 +3,7 @@ use dpp::identity::contract_bounds::ContractBounds; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "ContractBoundsWASM")] +#[wasm_bindgen(js_name = "ContractBounds")] #[derive(Clone)] pub struct ContractBoundsWASM(ContractBounds); @@ -19,16 +19,16 @@ impl From for ContractBounds { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = ContractBounds)] impl ContractBoundsWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "ContractBoundsWASM".to_string() + "ContractBounds".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "ContractBoundsWASM".to_string() + "ContractBounds".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/core_script/mod.rs b/packages/wasm-dpp2/src/core_script/mod.rs index 1dd5fdced7b..bbf88c978b8 100644 --- a/packages/wasm-dpp2/src/core_script/mod.rs +++ b/packages/wasm-dpp2/src/core_script/mod.rs @@ -7,7 +7,7 @@ use dpp::platform_value::string_encoding::encode; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "CoreScriptWASM")] +#[wasm_bindgen(js_name = "CoreScript")] #[derive(Clone)] pub struct CoreScriptWASM(CoreScript); @@ -23,16 +23,16 @@ impl From for CoreScriptWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = CoreScript)] impl CoreScriptWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "CoreScriptWASM".to_string() + "CoreScript".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "CoreScriptWASM".to_string() + "CoreScript".to_string() } #[wasm_bindgen(js_name = "fromBytes")] diff --git a/packages/wasm-dpp2/src/data_contract/mod.rs b/packages/wasm-dpp2/src/data_contract/mod.rs index 39cc4835f09..e16f1124438 100644 --- a/packages/wasm-dpp2/src/data_contract/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/mod.rs @@ -30,7 +30,7 @@ use std::collections::BTreeMap; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; -#[wasm_bindgen(js_name = "DataContractWASM")] +#[wasm_bindgen(js_name = "DataContract")] #[derive(Clone)] pub struct DataContractWASM(DataContract); @@ -63,7 +63,7 @@ pub fn tokens_configuration_from_js_value( }?; let js_config = Reflect::get(&js_configuration, &key)? - .to_wasm::("TokenConfigurationWASM")? + .to_wasm::("TokenConfiguration")? .clone(); configuration.insert(contract_position, js_config.into()); @@ -72,16 +72,16 @@ pub fn tokens_configuration_from_js_value( Ok(configuration) } -#[wasm_bindgen] +#[wasm_bindgen(js_class = DataContract)] impl DataContractWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DataContractWASM".to_string() + "DataContract".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DataContractWASM".to_string() + "DataContract".to_string() } #[wasm_bindgen(constructor)] @@ -456,7 +456,7 @@ impl DataContractWASM { let js_group = Reflect::get(&groups_object, &js_position)?; - let group = js_group.to_wasm::("GroupWASM")?.clone(); + let group = js_group.to_wasm::("Group")?.clone(); groups.insert(position, group.into()); } diff --git a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs index 63103699f87..8a6398758d6 100644 --- a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs +++ b/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs @@ -20,19 +20,19 @@ use dpp::version::{ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; -#[wasm_bindgen(js_name = "DataContractCreateTransitionWASM")] +#[wasm_bindgen(js_name = "DataContractCreateTransition")] pub struct DataContractCreateTransitionWASM(DataContractCreateTransition); -#[wasm_bindgen] +#[wasm_bindgen(js_class = DataContractCreateTransition)] impl DataContractCreateTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DataContractCreateTransitionWASM".to_string() + "DataContractCreateTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DataContractCreateTransitionWASM".to_string() + "DataContractCreateTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs index 09b60db04e5..b3481866527 100644 --- a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs +++ b/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs @@ -15,19 +15,19 @@ use dpp::version::{FeatureVersion, ProtocolVersion, TryFromPlatformVersioned}; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; -#[wasm_bindgen(js_name = "DataContractUpdateTransitionWASM")] +#[wasm_bindgen(js_name = "DataContractUpdateTransition")] pub struct DataContractUpdateTransitionWASM(DataContractUpdateTransition); -#[wasm_bindgen] +#[wasm_bindgen(js_class = DataContractUpdateTransition)] impl DataContractUpdateTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DataContractUpdateTransitionWASM".to_string() + "DataContractUpdateTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DataContractUpdateTransitionWASM".to_string() + "DataContractUpdateTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/document/methods/mod.rs b/packages/wasm-dpp2/src/document/methods/mod.rs index 0cc38e7b852..7e686ccb7f7 100644 --- a/packages/wasm-dpp2/src/document/methods/mod.rs +++ b/packages/wasm-dpp2/src/document/methods/mod.rs @@ -20,16 +20,16 @@ use std::collections::BTreeMap; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; -#[wasm_bindgen] +#[wasm_bindgen(js_class = Document)] impl DocumentWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DocumentWASM".to_string() + "Document".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DocumentWASM".to_string() + "Document".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/document/mod.rs b/packages/wasm-dpp2/src/document/mod.rs index 59ece5a8c2f..be1d1cff8c7 100644 --- a/packages/wasm-dpp2/src/document/mod.rs +++ b/packages/wasm-dpp2/src/document/mod.rs @@ -10,7 +10,7 @@ use std::collections::BTreeMap; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] -#[wasm_bindgen(js_name = DocumentWASM)] +#[wasm_bindgen(js_name = Document)] pub struct DocumentWASM { id: IdentifierWASM, owner_id: IdentifierWASM, diff --git a/packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs b/packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs index 0ca84cb18d9..c1cb09b5b3b 100644 --- a/packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs +++ b/packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs @@ -3,7 +3,7 @@ use dpp::tokens::PrivateEncryptedNote; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name = "PrivateEncryptedNoteWASM")] +#[wasm_bindgen(js_name = "PrivateEncryptedNote")] pub struct PrivateEncryptedNoteWASM(PrivateEncryptedNote); impl From for PrivateEncryptedNoteWASM { @@ -18,16 +18,16 @@ impl From for PrivateEncryptedNote { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = PrivateEncryptedNote)] impl PrivateEncryptedNoteWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "PrivateEncryptedNoteWASM".to_string() + "PrivateEncryptedNote".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "PrivateEncryptedNoteWASM".to_string() + "PrivateEncryptedNote".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs b/packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs index 6ee572adced..5e00b85d2a3 100644 --- a/packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs +++ b/packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs @@ -3,7 +3,7 @@ use dpp::tokens::SharedEncryptedNote; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name = "SharedEncryptedNoteWASM")] +#[wasm_bindgen(js_name = "SharedEncryptedNote")] pub struct SharedEncryptedNoteWASM(SharedEncryptedNote); impl From for SharedEncryptedNoteWASM { @@ -18,16 +18,16 @@ impl From for SharedEncryptedNote { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = SharedEncryptedNote)] impl SharedEncryptedNoteWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "SharedEncryptedNoteWASM".to_string() + "SharedEncryptedNote".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "SharedEncryptedNoteWASM".to_string() + "SharedEncryptedNote".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs b/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs index 39c2fe1338c..00a63b6a5d5 100644 --- a/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs +++ b/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs @@ -3,7 +3,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Default)] -#[wasm_bindgen(js_name = "GasFeesPaidByWASM")] +#[wasm_bindgen(js_name = "GasFeesPaidBy")] pub enum GasFeesPaidByWASM { #[default] DocumentOwner = 0, diff --git a/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs b/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs index 6772bb7609a..355484f33d6 100644 --- a/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs +++ b/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs @@ -1,7 +1,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "VoteStateResultTypeWASM")] +#[wasm_bindgen(js_name = "VoteStateResultType")] #[allow(non_camel_case_types)] #[derive(Default, Clone)] pub enum VoteStateResultTypeWASM { diff --git a/packages/wasm-dpp2/src/enums/lock_types/mod.rs b/packages/wasm-dpp2/src/enums/lock_types/mod.rs index d7d8c52d555..9bd4ab06f31 100644 --- a/packages/wasm-dpp2/src/enums/lock_types/mod.rs +++ b/packages/wasm-dpp2/src/enums/lock_types/mod.rs @@ -1,7 +1,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; -#[wasm_bindgen(js_name = "AssetLockProofTypeWASM")] +#[wasm_bindgen(js_name = "AssetLockProofType")] pub enum AssetLockProofTypeWASM { Instant = 0, Chain = 1, diff --git a/packages/wasm-dpp2/src/enums/network/mod.rs b/packages/wasm-dpp2/src/enums/network/mod.rs index 0ab4825d865..ede74ba8488 100644 --- a/packages/wasm-dpp2/src/enums/network/mod.rs +++ b/packages/wasm-dpp2/src/enums/network/mod.rs @@ -1,7 +1,7 @@ use dpp::dashcore::network::constants::Network; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "NetworkWASM")] +#[wasm_bindgen(js_name = "Network")] #[allow(non_camel_case_types)] pub enum NetworkWASM { Mainnet = 0, diff --git a/packages/wasm-dpp2/src/enums/platform/mod.rs b/packages/wasm-dpp2/src/enums/platform/mod.rs index 845f9abef07..0a8cef9bf60 100644 --- a/packages/wasm-dpp2/src/enums/platform/mod.rs +++ b/packages/wasm-dpp2/src/enums/platform/mod.rs @@ -11,7 +11,7 @@ use dpp::version::v9::PLATFORM_V9; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "PlatformVersionWASM")] +#[wasm_bindgen(js_name = "PlatformVersion")] #[derive(Default)] #[allow(non_camel_case_types)] pub enum PlatformVersionWASM { diff --git a/packages/wasm-dpp2/src/enums/token/action_goal.rs b/packages/wasm-dpp2/src/enums/token/action_goal.rs index 7cdfcedbd75..081ce6edab2 100644 --- a/packages/wasm-dpp2/src/enums/token/action_goal.rs +++ b/packages/wasm-dpp2/src/enums/token/action_goal.rs @@ -2,7 +2,7 @@ use dpp::group::action_taker::ActionGoal; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "ActionGoalWASM")] +#[wasm_bindgen(js_name = "ActionGoal")] #[allow(non_camel_case_types)] #[derive(Default, Clone)] pub enum ActionGoalWASM { diff --git a/packages/wasm-dpp2/src/enums/token/distribution_type.rs b/packages/wasm-dpp2/src/enums/token/distribution_type.rs index c375e8b2344..ab67c199fa1 100644 --- a/packages/wasm-dpp2/src/enums/token/distribution_type.rs +++ b/packages/wasm-dpp2/src/enums/token/distribution_type.rs @@ -2,7 +2,7 @@ use dpp::data_contract::associated_token::token_distribution_key::TokenDistribut use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "TokenDistributionTypeWASM")] +#[wasm_bindgen(js_name = "TokenDistributionType")] #[allow(non_camel_case_types)] #[derive(Default)] pub enum TokenDistributionTypeWASM { diff --git a/packages/wasm-dpp2/src/enums/token/emergency_action.rs b/packages/wasm-dpp2/src/enums/token/emergency_action.rs index 2999e95b8f8..08d49820078 100644 --- a/packages/wasm-dpp2/src/enums/token/emergency_action.rs +++ b/packages/wasm-dpp2/src/enums/token/emergency_action.rs @@ -2,7 +2,7 @@ use dpp::tokens::emergency_action::TokenEmergencyAction; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "TokenEmergencyActionWASM")] +#[wasm_bindgen(js_name = "TokenEmergencyAction")] #[allow(non_camel_case_types)] #[derive(Default)] pub enum TokenEmergencyActionWASM { diff --git a/packages/wasm-dpp2/src/group_state_transition_info/mod.rs b/packages/wasm-dpp2/src/group_state_transition_info/mod.rs index 8d589258502..1089e75e47f 100644 --- a/packages/wasm-dpp2/src/group_state_transition_info/mod.rs +++ b/packages/wasm-dpp2/src/group_state_transition_info/mod.rs @@ -4,7 +4,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=GroupStateTransitionInfoWASM)] +#[wasm_bindgen(js_name=GroupStateTransitionInfo)] pub struct GroupStateTransitionInfoWASM(GroupStateTransitionInfo); impl From for GroupStateTransitionInfo { @@ -19,16 +19,16 @@ impl From for GroupStateTransitionInfoWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = GroupStateTransitionInfo)] impl GroupStateTransitionInfoWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "GroupStateTransitionInfoWASM".to_string() + "GroupStateTransitionInfo".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "GroupStateTransitionInfoWASM".to_string() + "GroupStateTransitionInfo".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/identifier/mod.rs b/packages/wasm-dpp2/src/identifier/mod.rs index 156e81ab5a1..256ef4e16c8 100644 --- a/packages/wasm-dpp2/src/identifier/mod.rs +++ b/packages/wasm-dpp2/src/identifier/mod.rs @@ -5,7 +5,7 @@ use dpp::prelude::Identifier; use wasm_bindgen::prelude::*; #[derive(Copy, Clone)] -#[wasm_bindgen(js_name = "IdentifierWASM")] +#[wasm_bindgen(js_name = "Identifier")] pub struct IdentifierWASM(Identifier); impl From for Identifier { @@ -53,8 +53,8 @@ impl TryFrom for IdentifierWASM { match value.is_object() { true => match get_class_type(&value) { Ok(class_type) => match class_type.as_str() { - "IdentifierWASM" => { - Ok(value.to_wasm::("IdentifierWASM")?.clone()) + "Identifier" => { + Ok(value.to_wasm::("Identifier")?.clone()) } "" => Ok(identifier_from_js_value(&value)?.into()), _ => Err(Self::Error::from_str(&format!( @@ -90,16 +90,16 @@ impl TryFrom<&JsValue> for IdentifierWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = Identifier)] impl IdentifierWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "IdentifierWASM".to_string() + "Identifier".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "IdentifierWASM".to_string() + "Identifier".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/identity/mod.rs b/packages/wasm-dpp2/src/identity/mod.rs index 7a48417b216..c8b6038ec9f 100644 --- a/packages/wasm-dpp2/src/identity/mod.rs +++ b/packages/wasm-dpp2/src/identity/mod.rs @@ -13,7 +13,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; #[derive(Clone)] -#[wasm_bindgen(js_name = "IdentityWASM")] +#[wasm_bindgen(js_name = "Identity")] pub struct IdentityWASM(Identity); impl From for IdentityWASM { @@ -22,16 +22,16 @@ impl From for IdentityWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = Identity)] impl IdentityWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "IdentityWASM".to_string() + "Identity".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "IdentityWASM".to_string() + "Identity".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/identity_public_key/mod.rs b/packages/wasm-dpp2/src/identity_public_key/mod.rs index 6fe019fba8f..fcb2f770381 100644 --- a/packages/wasm-dpp2/src/identity_public_key/mod.rs +++ b/packages/wasm-dpp2/src/identity_public_key/mod.rs @@ -21,7 +21,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; #[derive(Clone)] -#[wasm_bindgen(js_name = IdentityPublicKeyWASM)] +#[wasm_bindgen(js_name = IdentityPublicKey)] pub struct IdentityPublicKeyWASM(IdentityPublicKey); impl From for IdentityPublicKeyWASM { @@ -36,16 +36,16 @@ impl From for IdentityPublicKey { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = IdentityPublicKey)] impl IdentityPublicKeyWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "IdentityPublicKeyWASM".to_string() + "IdentityPublicKey".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "IdentityPublicKeyWASM".to_string() + "IdentityPublicKey".to_string() } #[wasm_bindgen(constructor)] @@ -67,7 +67,7 @@ impl IdentityPublicKeyWASM { true => None, false => Some( js_contract_bounds - .to_wasm::("ContractBoundsWASM")? + .to_wasm::("ContractBounds")? .clone() .into(), ), @@ -88,7 +88,7 @@ impl IdentityPublicKeyWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = IdentityPublicKey)] impl IdentityPublicKeyWASM { #[wasm_bindgen(js_name = "validatePrivateKey")] pub fn validate_private_key( diff --git a/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs index 1a7171312ed..f8467bbc28d 100644 --- a/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs @@ -18,7 +18,7 @@ use dpp::state_transition::{StateTransition, StateTransitionLike}; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; -#[wasm_bindgen(js_name = "IdentityCreateTransitionWASM")] +#[wasm_bindgen(js_name = "IdentityCreateTransition")] #[derive(Clone)] pub struct IdentityCreateTransitionWASM(IdentityCreateTransition); @@ -34,16 +34,16 @@ impl From for IdentityCreateTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = IdentityCreateTransition)] impl IdentityCreateTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "IdentityCreateTransitionWASM".to_string() + "IdentityCreateTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "IdentityCreateTransitionWASM".to_string() + "IdentityCreateTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs index 09e6289a445..7cf0a9afa96 100644 --- a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs @@ -20,19 +20,19 @@ use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, Stat use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; -#[wasm_bindgen(js_name = "IdentityCreditWithdrawalTransitionWASM")] +#[wasm_bindgen(js_name = "IdentityCreditWithdrawalTransition")] pub struct IdentityCreditWithdrawalTransitionWASM(IdentityCreditWithdrawalTransition); -#[wasm_bindgen] +#[wasm_bindgen(js_class = IdentityCreditWithdrawalTransition)] impl IdentityCreditWithdrawalTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "IdentityCreditWithdrawalTransitionWASM".to_string() + "IdentityCreditWithdrawalTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "IdentityCreditWithdrawalTransitionWASM".to_string() + "IdentityCreditWithdrawalTransition".to_string() } #[wasm_bindgen(constructor)] @@ -52,7 +52,7 @@ impl IdentityCreditWithdrawalTransitionWASM { true => None, false => Some( js_output_script - .to_wasm::("CoreScriptWASM")? + .to_wasm::("CoreScript")? .clone() .into(), ), @@ -138,7 +138,7 @@ impl IdentityCreditWithdrawalTransitionWASM { true => self.0.set_output_script(None), false => { let script: CoreScriptWASM = js_script - .to_wasm::("CoreScriptWASM")? + .to_wasm::("CoreScript")? .clone(); self.0.set_output_script(Some(script.clone().into())) } diff --git a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs index 18bd5730eea..e3fdb88010d 100644 --- a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs @@ -13,20 +13,20 @@ use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, Stat use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; -#[wasm_bindgen(js_name = IdentityCreditTransferWASM)] +#[wasm_bindgen(js_name = IdentityCreditTransfer)] #[derive(Clone)] pub struct IdentityCreditTransferWASM(IdentityCreditTransferTransition); -#[wasm_bindgen] +#[wasm_bindgen(js_class = IdentityCreditTransfer)] impl IdentityCreditTransferWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "IdentityCreditTransferWASM".to_string() + "IdentityCreditTransfer".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "IdentityCreditTransferWASM".to_string() + "IdentityCreditTransfer".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs b/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs index 9c6673b4e92..706e41b7085 100644 --- a/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs @@ -18,7 +18,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] -#[wasm_bindgen(js_name = "IdentityPublicKeyInCreationWASM")] +#[wasm_bindgen(js_name = "IdentityPublicKeyInCreation")] pub struct IdentityPublicKeyInCreationWASM(IdentityPublicKeyInCreation); impl From for IdentityPublicKeyInCreationWASM { @@ -37,7 +37,7 @@ impl TryFrom for IdentityPublicKeyInCreationWASM { type Error = JsValue; fn try_from(value: JsValue) -> Result { let value = - value.to_wasm::("IdentityPublicKeyInCreationWASM")?; + value.to_wasm::("IdentityPublicKeyInCreation")?; Ok(value.clone()) } @@ -63,16 +63,16 @@ impl From for IdentityPublicKey { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = IdentityPublicKeyInCreation)] impl IdentityPublicKeyInCreationWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "IdentityPublicKeyInCreationWASM".to_string() + "IdentityPublicKeyInCreation".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "IdentityPublicKeyInCreationWASM".to_string() + "IdentityPublicKeyInCreation".to_string() } #[wasm_bindgen(constructor)] @@ -94,7 +94,7 @@ impl IdentityPublicKeyInCreationWASM { true => None, false => Some( js_contract_bounds - .to_wasm::("ContractBoundsWASM")? + .to_wasm::("ContractBounds")? .clone() .into(), ), @@ -228,7 +228,7 @@ impl IdentityPublicKeyInCreationWASM { true => self.0.set_contract_bounds(None), false => { let bounds = js_bounds - .to_wasm::("ContractBoundsWASM")? + .to_wasm::("ContractBounds")? .clone(); self.0.set_contract_bounds(Some(bounds.into())) diff --git a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs index 2d2d1d95e7c..8636904506d 100644 --- a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs @@ -15,20 +15,20 @@ use dpp::state_transition::{StateTransition, StateTransitionLike}; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; -#[wasm_bindgen(js_name = "IdentityTopUpTransitionWASM")] +#[wasm_bindgen(js_name = "IdentityTopUpTransition")] #[derive(Clone)] pub struct IdentityTopUpTransitionWASM(IdentityTopUpTransition); -#[wasm_bindgen] +#[wasm_bindgen(js_class = IdentityTopUpTransition)] impl IdentityTopUpTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "IdentityTopUpTransitionWASM".to_string() + "IdentityTopUpTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "IdentityTopUpTransitionWASM".to_string() + "IdentityTopUpTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs index 06f7545fed4..ac12b39056d 100644 --- a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs @@ -18,20 +18,20 @@ use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, Stat use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; -#[wasm_bindgen(js_name = "IdentityUpdateTransitionWASM")] +#[wasm_bindgen(js_name = "IdentityUpdateTransition")] #[derive(Clone)] pub struct IdentityUpdateTransitionWASM(IdentityUpdateTransition); -#[wasm_bindgen] +#[wasm_bindgen(js_class = IdentityUpdateTransition)] impl IdentityUpdateTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "IdentityUpdateTransitionWASM".to_string() + "IdentityUpdateTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "IdentityUpdateTransitionWASM".to_string() + "IdentityUpdateTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/masternode_vote/mod.rs b/packages/wasm-dpp2/src/masternode_vote/mod.rs index 3161985de1a..e6057db8c2f 100644 --- a/packages/wasm-dpp2/src/masternode_vote/mod.rs +++ b/packages/wasm-dpp2/src/masternode_vote/mod.rs @@ -21,7 +21,7 @@ use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, Stat use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; -#[wasm_bindgen(js_name = "MasternodeVoteTransitionWASM")] +#[wasm_bindgen(js_name = "MasternodeVoteTransition")] #[derive(Clone)] pub struct MasternodeVoteTransitionWASM(MasternodeVoteTransition); @@ -37,16 +37,16 @@ impl From for MasternodeVoteTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = MasternodeVoteTransition)] impl MasternodeVoteTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "MasternodeVoteTransitionWASM".to_string() + "MasternodeVoteTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "MasternodeVoteTransitionWASM".to_string() + "MasternodeVoteTransition".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs b/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs index 8796b69bc1f..bc5213bcaff 100644 --- a/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs +++ b/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs @@ -4,7 +4,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] -#[wasm_bindgen(js_name = ResourceVoteChoiceWASM)] +#[wasm_bindgen(js_name = ResourceVoteChoice)] pub struct ResourceVoteChoiceWASM(ResourceVoteChoice); impl From for ResourceVoteChoiceWASM { @@ -19,16 +19,16 @@ impl From for ResourceVoteChoice { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = ResourceVoteChoice)] impl ResourceVoteChoiceWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "ResourceVoteChoiceWASM".to_string() + "ResourceVoteChoice".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "ResourceVoteChoiceWASM".to_string() + "ResourceVoteChoice".to_string() } #[wasm_bindgen(js_name = "TowardsIdentity")] diff --git a/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs b/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs index dec275105b1..b548a5f344b 100644 --- a/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs +++ b/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs @@ -7,7 +7,7 @@ use dpp::voting::votes::resource_vote::v0::ResourceVoteV0; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] -#[wasm_bindgen(js_name=VoteWASM)] +#[wasm_bindgen(js_name=Vote)] pub struct VoteWASM(Vote); impl From for VoteWASM { @@ -22,16 +22,16 @@ impl From for Vote { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = Vote)] impl VoteWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "VoteWASM".to_string() + "Vote".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "VoteWASM".to_string() + "Vote".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs b/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs index db83dc63272..86b2b8db037 100644 --- a/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs +++ b/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs @@ -8,7 +8,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] -#[wasm_bindgen(js_name = VotePollWASM)] +#[wasm_bindgen(js_name = VotePoll)] pub struct VotePollWASM(VotePoll); impl From for VotePollWASM { @@ -23,16 +23,16 @@ impl From for VotePoll { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = VotePoll)] impl VotePollWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "VotePollWASM".to_string() + "VotePoll".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "VotePollWASM".to_string() + "VotePoll".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/partial_identity/mod.rs b/packages/wasm-dpp2/src/partial_identity/mod.rs index 216fd49e774..a88ed822086 100644 --- a/packages/wasm-dpp2/src/partial_identity/mod.rs +++ b/packages/wasm-dpp2/src/partial_identity/mod.rs @@ -10,7 +10,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] -#[wasm_bindgen(js_name = "PartialIdentityWASM")] +#[wasm_bindgen(js_name = "PartialIdentity")] pub struct PartialIdentityWASM(PartialIdentity); impl From for PartialIdentityWASM { @@ -19,7 +19,7 @@ impl From for PartialIdentityWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = PartialIdentity)] impl PartialIdentityWASM { #[wasm_bindgen(constructor)] pub fn new( @@ -143,7 +143,7 @@ pub fn js_value_to_loaded_public_keys( let js_key = Reflect::get(&pub_keys_object, &key)?; let key = js_key - .to_wasm::("IdentityPublicKeyWASM")? + .to_wasm::("IdentityPublicKey")? .clone(); map.insert(key_id, IdentityPublicKey::from(key)); diff --git a/packages/wasm-dpp2/src/private_key/mod.rs b/packages/wasm-dpp2/src/private_key/mod.rs index b2eadddf754..bcac2d7561c 100644 --- a/packages/wasm-dpp2/src/private_key/mod.rs +++ b/packages/wasm-dpp2/src/private_key/mod.rs @@ -7,19 +7,19 @@ use dpp::dashcore::secp256k1::hashes::hex::{Case, DisplayHex}; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "PrivateKeyWASM")] +#[wasm_bindgen(js_name = "PrivateKey")] pub struct PrivateKeyWASM(PrivateKey); -#[wasm_bindgen] +#[wasm_bindgen(js_class = PrivateKey)] impl PrivateKeyWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "PrivateKeyWASM".to_string() + "PrivateKey".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "PrivateKeyWASM".to_string() + "PrivateKey".to_string() } #[wasm_bindgen(js_name = "fromWIF")] @@ -64,7 +64,7 @@ impl PrivateKeyWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = PrivateKey)] impl PrivateKeyWASM { #[wasm_bindgen(js_name = "WIF")] pub fn get_wif(&self) -> String { diff --git a/packages/wasm-dpp2/src/public_key/mod.rs b/packages/wasm-dpp2/src/public_key/mod.rs index bb5bdd3ca14..763677d9ff6 100644 --- a/packages/wasm-dpp2/src/public_key/mod.rs +++ b/packages/wasm-dpp2/src/public_key/mod.rs @@ -3,7 +3,7 @@ use dpp::dashcore::{PublicKey, secp256k1}; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "PublicKeyWASM")] +#[wasm_bindgen(js_name = "PublicKey")] pub struct PublicKeyWASM(PublicKey); impl From for PublicKeyWASM { @@ -18,16 +18,16 @@ impl From for PublicKey { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = PublicKey)] impl PublicKeyWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "PublicKeyWASM".to_string() + "PublicKey".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "PublicKeyWASM".to_string() + "PublicKey".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/state_transition/mod.rs b/packages/wasm-dpp2/src/state_transition/mod.rs index ce98734d732..57b67cab504 100644 --- a/packages/wasm-dpp2/src/state_transition/mod.rs +++ b/packages/wasm-dpp2/src/state_transition/mod.rs @@ -41,7 +41,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; #[derive(Clone)] -#[wasm_bindgen(js_name = "StateTransitionWASM")] +#[wasm_bindgen(js_name = "StateTransition")] pub struct StateTransitionWASM(StateTransition); impl From for StateTransitionWASM { @@ -56,16 +56,16 @@ impl From for StateTransition { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = StateTransition)] impl StateTransitionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "StateTransitionWASM".to_string() + "StateTransition".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "StateTransitionWASM".to_string() + "StateTransition".to_string() } #[wasm_bindgen(js_name = "sign")] diff --git a/packages/wasm-dpp2/src/token_configuration/action_taker.rs b/packages/wasm-dpp2/src/token_configuration/action_taker.rs index eb29fa27ee5..f8ab6523b6c 100644 --- a/packages/wasm-dpp2/src/token_configuration/action_taker.rs +++ b/packages/wasm-dpp2/src/token_configuration/action_taker.rs @@ -7,7 +7,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = "ActionTakerWASM")] +#[wasm_bindgen(js_name = "ActionTaker")] pub struct ActionTakerWASM(ActionTaker); impl From for ActionTakerWASM { @@ -22,16 +22,16 @@ impl From for ActionTaker { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = ActionTaker)] impl ActionTakerWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "ActionTakerWASM".to_string() + "ActionTaker".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "ActionTakerWASM".to_string() + "ActionTaker".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs b/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs index 91cd97bcf5a..1c16513fc3e 100644 --- a/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs +++ b/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs @@ -6,7 +6,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = "AuthorizedActionTakersWASM")] +#[wasm_bindgen(js_name = "AuthorizedActionTakers")] pub struct AuthorizedActionTakersWASM(AuthorizedActionTakers); impl From for AuthorizedActionTakersWASM { @@ -21,16 +21,16 @@ impl From for AuthorizedActionTakers { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = AuthorizedActionTakers)] impl AuthorizedActionTakersWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "AuthorizedActionTakersWASM".to_string() + "AuthorizedActionTakers".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "AuthorizedActionTakersWASM".to_string() + "AuthorizedActionTakers".to_string() } #[wasm_bindgen(js_name = "NoOne")] diff --git a/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs b/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs index 38c6bb09e2f..1554e81defc 100644 --- a/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs +++ b/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs @@ -14,7 +14,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = "ChangeControlRulesWASM")] +#[wasm_bindgen(js_name = "ChangeControlRules")] pub struct ChangeControlRulesWASM(ChangeControlRules); impl From for ChangeControlRulesWASM { @@ -29,16 +29,16 @@ impl From for ChangeControlRules { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = ChangeControlRules)] impl ChangeControlRulesWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "ChangeControlRulesWASM".to_string() + "ChangeControlRules".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "ChangeControlRulesWASM".to_string() + "ChangeControlRules".to_string() } #[wasm_bindgen(constructor)] @@ -183,7 +183,7 @@ impl ChangeControlRulesWASM { let group_value = Reflect::get(js_groups, &key)?; - let group = group_value.to_wasm::("GroupWASM")?.clone(); + let group = group_value.to_wasm::("Group")?.clone(); groups.insert(contract_position, group.into()); } diff --git a/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs b/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs index 89581679f08..6aa1e950232 100644 --- a/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs +++ b/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs @@ -13,7 +13,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name = "TokenConfigurationConventionWASM")] +#[wasm_bindgen(js_name = "TokenConfigurationConvention")] pub struct TokenConfigurationConventionWASM(TokenConfigurationConvention); impl From for TokenConfigurationConventionWASM { @@ -28,16 +28,16 @@ impl From for TokenConfigurationConvention { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationConvention)] impl TokenConfigurationConventionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenConfigurationConventionWASM".to_string() + "TokenConfigurationConvention".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenConfigurationConventionWASM".to_string() + "TokenConfigurationConvention".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_function.rs b/packages/wasm-dpp2/src/token_configuration/distribution_function.rs index b400fbd9f7f..5677b04b553 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_function.rs +++ b/packages/wasm-dpp2/src/token_configuration/distribution_function.rs @@ -13,7 +13,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = "DistributionFunctionWASM")] +#[wasm_bindgen(js_name = "DistributionFunction")] pub struct DistributionFunctionWASM(DistributionFunction); impl From for DistributionFunction { @@ -28,16 +28,16 @@ impl From for DistributionFunctionWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = DistributionFunction)] impl DistributionFunctionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "DistributionFunctionWASM".to_string() + "DistributionFunction".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "DistributionFunctionWASM".to_string() + "DistributionFunction".to_string() } #[wasm_bindgen(js_name = "FixedAmountDistribution")] diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs b/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs index c561a9e1729..63f2c3d0e00 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs +++ b/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs @@ -4,7 +4,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = "TokenDistributionRecipientWASM")] +#[wasm_bindgen(js_name = "TokenDistributionRecipient")] pub struct TokenDistributionRecipientWASM(TokenDistributionRecipient); impl From for TokenDistributionRecipientWASM { @@ -19,16 +19,16 @@ impl From for TokenDistributionRecipient { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenDistributionRecipient)] impl TokenDistributionRecipientWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenDistributionRecipientWASM".to_string() + "TokenDistributionRecipient".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenDistributionRecipientWASM".to_string() + "TokenDistributionRecipient".to_string() } #[wasm_bindgen(js_name = "ContractOwner")] diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs b/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs index 123400dbbe6..ea6c392f5df 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs +++ b/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs @@ -15,7 +15,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = "TokenDistributionRulesWASM")] +#[wasm_bindgen(js_name = "TokenDistributionRules")] pub struct TokenDistributionRulesWASM(TokenDistributionRules); impl From for TokenDistributionRules { @@ -30,16 +30,16 @@ impl From for TokenDistributionRulesWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenDistributionRules)] impl TokenDistributionRulesWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenDistributionRulesWASM".to_string() + "TokenDistributionRules".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenDistributionRulesWASM".to_string() + "TokenDistributionRules".to_string() } #[wasm_bindgen(constructor)] @@ -57,7 +57,7 @@ impl TokenDistributionRulesWASM { true => None, false => Some(TokenPerpetualDistribution::from( js_perpetual_distribution - .to_wasm::("TokenPerpetualDistributionWASM")? + .to_wasm::("TokenPerpetualDistribution")? .clone(), )), }; @@ -67,7 +67,7 @@ impl TokenDistributionRulesWASM { false => Some(TokenPreProgrammedDistribution::from( js_pre_programmed_distribution .to_wasm::( - "TokenPreProgrammedDistributionWASM", + "TokenPreProgrammedDistribution", )? .clone(), )), @@ -165,7 +165,7 @@ impl TokenDistributionRulesWASM { true => None, false => Some(TokenPerpetualDistribution::from( js_perpetual_distribution - .to_wasm::("TokenPerpetualDistributionWASM")? + .to_wasm::("TokenPerpetualDistribution")? .clone(), )), }; @@ -189,7 +189,7 @@ impl TokenDistributionRulesWASM { false => Some(TokenPreProgrammedDistribution::from( js_distribution .to_wasm::( - "TokenPreProgrammedDistributionWASM", + "TokenPreProgrammedDistribution", )? .clone(), )), diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_structs.rs b/packages/wasm-dpp2/src/token_configuration/distribution_structs.rs index 0e9d9f28c2b..050dfc18bf3 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_structs.rs +++ b/packages/wasm-dpp2/src/token_configuration/distribution_structs.rs @@ -1,18 +1,18 @@ use dpp::balances::credits::TokenAmount; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen(js_name = "DistributionFixedAmountWASM")] +#[wasm_bindgen(js_name = "DistributionFixedAmount")] pub struct DistributionFixedAmountWASM { pub amount: TokenAmount, } -#[wasm_bindgen(js_name = "DistributionRandomWASM")] +#[wasm_bindgen(js_name = "DistributionRandom")] pub struct DistributionRandomWASM { pub min: TokenAmount, pub max: TokenAmount, } -#[wasm_bindgen(js_name = "DistributionStepDecreasingAmountWASM")] +#[wasm_bindgen(js_name = "DistributionStepDecreasingAmount")] pub struct DistributionStepDecreasingAmountWASM { #[wasm_bindgen(js_name = "stepCount")] pub step_count: u32, @@ -32,7 +32,7 @@ pub struct DistributionStepDecreasingAmountWASM { pub min_value: Option, } -#[wasm_bindgen(js_name = "DistributionLinearWASM")] +#[wasm_bindgen(js_name = "DistributionLinear")] pub struct DistributionLinearWASM { pub a: i64, pub d: u64, @@ -46,7 +46,7 @@ pub struct DistributionLinearWASM { pub max_value: Option, } -#[wasm_bindgen(js_name = "DistributionPolynomialWASM")] +#[wasm_bindgen(js_name = "DistributionPolynomial")] pub struct DistributionPolynomialWASM { pub a: i64, pub d: u64, @@ -62,7 +62,7 @@ pub struct DistributionPolynomialWASM { pub max_value: Option, } -#[wasm_bindgen(js_name = "DistributionExponentialWASM")] +#[wasm_bindgen(js_name = "DistributionExponential")] pub struct DistributionExponentialWASM { pub a: u64, pub d: u64, @@ -78,7 +78,7 @@ pub struct DistributionExponentialWASM { pub max_value: Option, } -#[wasm_bindgen(js_name = "DistributionLogarithmicWASM")] +#[wasm_bindgen(js_name = "DistributionLogarithmic")] pub struct DistributionLogarithmicWASM { pub a: i64, pub d: u64, @@ -94,7 +94,7 @@ pub struct DistributionLogarithmicWASM { pub max_value: Option, } -#[wasm_bindgen(js_name = "DistributionInvertedLogarithmicWASM")] +#[wasm_bindgen(js_name = "DistributionInvertedLogarithmic")] pub struct DistributionInvertedLogarithmicWASM { pub a: i64, pub d: u64, diff --git a/packages/wasm-dpp2/src/token_configuration/group.rs b/packages/wasm-dpp2/src/token_configuration/group.rs index 7f1b4854dac..ed191fef8de 100644 --- a/packages/wasm-dpp2/src/token_configuration/group.rs +++ b/packages/wasm-dpp2/src/token_configuration/group.rs @@ -11,7 +11,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, PartialEq, Debug)] -#[wasm_bindgen(js_name = "GroupWASM")] +#[wasm_bindgen(js_name = "Group")] pub struct GroupWASM(Group); impl From for GroupWASM { @@ -53,16 +53,16 @@ pub fn js_members_to_map( Ok(members) } -#[wasm_bindgen] +#[wasm_bindgen(js_class = Group)] impl GroupWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "GroupWASM".to_string() + "Group".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "GroupWASM".to_string() + "Group".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs b/packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs index 671785a9522..197b343d447 100644 --- a/packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs +++ b/packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs @@ -6,7 +6,7 @@ use dpp::data_contract::associated_token::token_keeps_history_rules::v0::TokenKe use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] -#[wasm_bindgen(js_name = "TokenKeepsHistoryRulesWASM")] +#[wasm_bindgen(js_name = "TokenKeepsHistoryRules")] pub struct TokenKeepsHistoryRulesWASM(TokenKeepsHistoryRules); impl From for TokenKeepsHistoryRules { @@ -21,16 +21,16 @@ impl From for TokenKeepsHistoryRulesWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenKeepsHistoryRules)] impl TokenKeepsHistoryRulesWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenKeepsHistoryRulesWASM".to_string() + "TokenKeepsHistoryRules".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenKeepsHistoryRulesWASM".to_string() + "TokenKeepsHistoryRules".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/token_configuration/localization.rs b/packages/wasm-dpp2/src/token_configuration/localization.rs index d45fb9bfee4..9d562883a99 100644 --- a/packages/wasm-dpp2/src/token_configuration/localization.rs +++ b/packages/wasm-dpp2/src/token_configuration/localization.rs @@ -8,7 +8,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = TokenConfigurationLocalizationWASM)] +#[wasm_bindgen(js_name = TokenConfigurationLocalization)] pub struct TokenConfigurationLocalizationWASM(TokenConfigurationLocalization); impl From for TokenConfigurationLocalizationWASM { @@ -23,16 +23,16 @@ impl From for TokenConfigurationLocalization } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationLocalization)] impl TokenConfigurationLocalizationWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenConfigurationLocalizationWASM".to_string() + "TokenConfigurationLocalization".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenConfigurationLocalizationWASM".to_string() + "TokenConfigurationLocalization".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs b/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs index bbbe69337b7..720395a1216 100644 --- a/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs +++ b/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs @@ -8,7 +8,7 @@ use dpp::data_contract::associated_token::token_marketplace_rules::v0::TokenMark use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, PartialEq, Debug)] -#[wasm_bindgen(js_name = "TokenMarketplaceRulesWASM")] +#[wasm_bindgen(js_name = "TokenMarketplaceRules")] pub struct TokenMarketplaceRulesWASM(TokenMarketplaceRules); impl From for TokenMarketplaceRulesWASM { @@ -23,16 +23,16 @@ impl From for TokenMarketplaceRules { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenMarketplaceRules)] impl TokenMarketplaceRulesWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenMarketplaceRulesWASM".to_string() + "TokenMarketplaceRules".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenMarketplaceRulesWASM".to_string() + "TokenMarketplaceRules".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/token_configuration/mod.rs b/packages/wasm-dpp2/src/token_configuration/mod.rs index 07950edca1c..2453333577f 100644 --- a/packages/wasm-dpp2/src/token_configuration/mod.rs +++ b/packages/wasm-dpp2/src/token_configuration/mod.rs @@ -33,7 +33,7 @@ pub mod reward_distribution_type; pub mod trade_mode; #[derive(Clone, PartialEq, Debug)] -#[wasm_bindgen(js_name = "TokenConfigurationWASM")] +#[wasm_bindgen(js_name = "TokenConfiguration")] pub struct TokenConfigurationWASM(TokenConfiguration); impl From for TokenConfigurationWASM { @@ -48,16 +48,16 @@ impl From for TokenConfiguration { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfiguration)] impl TokenConfigurationWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenConfigurationWASM".to_string() + "TokenConfiguration".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenConfigurationWASM".to_string() + "TokenConfiguration".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs b/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs index 63f4f646987..f679329d9c0 100644 --- a/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs +++ b/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs @@ -6,7 +6,7 @@ use dpp::data_contract::associated_token::token_perpetual_distribution::v0::Toke use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, PartialEq, Debug)] -#[wasm_bindgen(js_name = "TokenPerpetualDistributionWASM")] +#[wasm_bindgen(js_name = "TokenPerpetualDistribution")] pub struct TokenPerpetualDistributionWASM(TokenPerpetualDistribution); impl From for TokenPerpetualDistribution { @@ -21,16 +21,16 @@ impl From for TokenPerpetualDistributionWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenPerpetualDistribution)] impl TokenPerpetualDistributionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenPerpetualDistributionWASM".to_string() + "TokenPerpetualDistribution".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenPerpetualDistributionWASM".to_string() + "TokenPerpetualDistribution".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs b/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs index 6eb3024065a..ae95e6b8f56 100644 --- a/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs +++ b/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs @@ -10,7 +10,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; #[derive(Clone, PartialEq, Debug)] -#[wasm_bindgen(js_name = "TokenPreProgrammedDistributionWASM")] +#[wasm_bindgen(js_name = "TokenPreProgrammedDistribution")] pub struct TokenPreProgrammedDistributionWASM(TokenPreProgrammedDistribution); impl From for TokenPreProgrammedDistribution { @@ -66,16 +66,16 @@ pub fn js_distributions_to_distributions( Ok(distributions) } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenPreProgrammedDistribution)] impl TokenPreProgrammedDistributionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenPreProgrammedDistributionWASM".to_string() + "TokenPreProgrammedDistribution".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenPreProgrammedDistributionWASM".to_string() + "TokenPreProgrammedDistribution".to_string() } #[wasm_bindgen(constructor)] diff --git a/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs b/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs index 41f0c64838e..86c48583809 100644 --- a/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs +++ b/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs @@ -6,7 +6,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use crate::token_configuration::distribution_function::DistributionFunctionWASM; #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = "RewardDistributionTypeWASM")] +#[wasm_bindgen(js_name = "RewardDistributionType")] pub struct RewardDistributionTypeWASM(RewardDistributionType); impl From for RewardDistributionTypeWASM { @@ -21,16 +21,16 @@ impl From for RewardDistributionType { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = RewardDistributionType)] impl RewardDistributionTypeWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "RewardDistributionTypeWASM".to_string() + "RewardDistributionType".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "RewardDistributionTypeWASM".to_string() + "RewardDistributionType".to_string() } #[wasm_bindgen(js_name = "BlockBasedDistribution")] @@ -92,36 +92,36 @@ impl RewardDistributionTypeWASM { } #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = "BlockBasedDistributionWASM")] +#[wasm_bindgen(js_name = "BlockBasedDistribution")] pub struct BlockBasedDistributionWASM { pub interval: BlockHeightInterval, function: DistributionFunctionWASM, } #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = "TimeBasedDistributionWASM")] +#[wasm_bindgen(js_name = "TimeBasedDistribution")] pub struct TimeBasedDistributionWASM { pub interval: TimestampMillisInterval, function: DistributionFunctionWASM, } #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = "EpochBasedDistributionWASM")] +#[wasm_bindgen(js_name = "EpochBasedDistribution")] pub struct EpochBasedDistributionWASM { pub interval: EpochInterval, function: DistributionFunctionWASM, } -#[wasm_bindgen] +#[wasm_bindgen(js_class = BlockBasedDistribution)] impl BlockBasedDistributionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "BlockBasedDistributionWASM".to_string() + "BlockBasedDistribution".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "BlockBasedDistributionWASM".to_string() + "BlockBasedDistribution".to_string() } #[wasm_bindgen(getter = "function")] @@ -135,16 +135,16 @@ impl BlockBasedDistributionWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TimeBasedDistribution)] impl TimeBasedDistributionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TimeBasedDistributionWASM".to_string() + "TimeBasedDistribution".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TimeBasedDistributionWASM".to_string() + "TimeBasedDistribution".to_string() } #[wasm_bindgen(getter = "function")] @@ -158,16 +158,16 @@ impl TimeBasedDistributionWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = EpochBasedDistribution)] impl EpochBasedDistributionWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "EpochBasedDistributionWASM".to_string() + "EpochBasedDistribution".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "EpochBasedDistributionWASM".to_string() + "EpochBasedDistribution".to_string() } #[wasm_bindgen(getter = "function")] diff --git a/packages/wasm-dpp2/src/token_configuration/trade_mode.rs b/packages/wasm-dpp2/src/token_configuration/trade_mode.rs index 43eb7008cc8..32c46ed590f 100644 --- a/packages/wasm-dpp2/src/token_configuration/trade_mode.rs +++ b/packages/wasm-dpp2/src/token_configuration/trade_mode.rs @@ -2,7 +2,7 @@ use dpp::data_contract::associated_token::token_marketplace_rules::v0::TokenTrad use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] -#[wasm_bindgen(js_name = "TokenTradeModeWASM")] +#[wasm_bindgen(js_name = "TokenTradeMode")] pub struct TokenTradeModeWASM(TokenTradeMode); impl From for TokenTradeModeWASM { @@ -17,16 +17,16 @@ impl From for TokenTradeMode { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenTradeMode)] impl TokenTradeModeWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenTradeModeWASM".to_string() + "TokenTradeMode".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenTradeModeWASM".to_string() + "TokenTradeMode".to_string() } #[wasm_bindgen(js_name = "NotTradeable")] diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs index da25fc093ff..f1c5980c316 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs @@ -4,7 +4,7 @@ use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "conventionsItem")] pub fn conventions_item(convention: &TokenConfigurationConventionWASM) -> Self { diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs index 1963aff53fa..3621d5dea7b 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs @@ -3,7 +3,7 @@ use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "DestroyFrozenFundsItem")] pub fn destroy_frozen_funds_item(action_taker: &AuthorizedActionTakersWASM) -> Self { diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs index 7b9196991ca..062bed2a0ec 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs @@ -3,7 +3,7 @@ use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "EmergencyActionItem")] pub fn emergency_action_item( diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs index 1dc566b774e..96f6974ed00 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs @@ -3,7 +3,7 @@ use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "FreezeItem")] pub fn freeze_item( diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs index 270ef068395..5097f5c7888 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs @@ -3,7 +3,7 @@ use dpp::data_contract::GroupContractPosition; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "MainControlGroupItem")] pub fn main_control_group_item(group_contract_position: Option) -> Self { diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs index 29d53e15080..96fa4cfcf09 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs @@ -3,7 +3,7 @@ use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "ManualBurningItem")] pub fn manual_burning_item(action_taker: &AuthorizedActionTakersWASM) -> Self { diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs index fdf53be24f6..5c93c4b3466 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs @@ -3,7 +3,7 @@ use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "ManualMintingItem")] pub fn manual_minting_item(action_taker: &AuthorizedActionTakersWASM) -> Self { diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs index 73dfbf90e00..b45168c3094 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs @@ -4,7 +4,7 @@ use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "MarketplaceTradeModeItem")] pub fn market_trade_mode_item(trade_mode: &TokenTradeModeWASM) -> Self { diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs index 56ca2dff867..cecfecca05c 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs @@ -4,7 +4,7 @@ use dpp::balances::credits::TokenAmount; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "MaxSupplyItem")] pub fn max_supply_item(supply: Option) -> Self { diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs index 82889f337d8..5098adb8ce5 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs @@ -3,7 +3,7 @@ use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "MintingAllowChoosingDestinationItem")] pub fn minting_allow_choosing_destination_item(flag: bool) -> Self { diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs index e99d4a1f113..6373ed548ba 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs @@ -6,7 +6,7 @@ use dpp::prelude::Identifier; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "NewTokensDestinationIdentityItem")] pub fn new_tokens_destination_identity_item( diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs index 5d78200a540..535b4badcfd 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs @@ -2,7 +2,7 @@ use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "noChangeItem")] pub fn no_changes_item() -> Self { diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs index 6055871bc2c..5cf626cff4f 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs @@ -7,7 +7,7 @@ use dpp::data_contract::associated_token::token_perpetual_distribution::TokenPer use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "PerpetualDistributionConfigurationItem")] pub fn perpetual_distribution_item(js_perpetual_distribution_value: JsValue) -> Self { @@ -16,7 +16,7 @@ impl TokenConfigurationChangeItemWASM { true => None, false => Some( js_perpetual_distribution_value - .to_wasm::("TokenPerpetualDistributionWASM") + .to_wasm::("TokenPerpetualDistribution") .unwrap() .clone() .into(), diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs index 180494c629f..6d966268c9f 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs @@ -3,7 +3,7 @@ use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "UnfreezeItem")] pub fn unfreeze_item(action_taker: &AuthorizedActionTakersWASM) -> Self { diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs b/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs index 62c41d73925..5bd43ce5606 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs @@ -10,7 +10,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name = "TokenConfigurationChangeItemWASM")] +#[wasm_bindgen(js_name = "TokenConfigurationChangeItem")] pub struct TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem); impl From for TokenConfigurationChangeItem { @@ -25,16 +25,16 @@ impl From for TokenConfigurationChangeItemWASM { } } -#[wasm_bindgen] +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { - "TokenConfigurationChangeItemWASM".to_string() + "TokenConfigurationChangeItem".to_string() } #[wasm_bindgen(getter = __struct)] pub fn struct_name() -> String { - "TokenConfigurationChangeItemWASM".to_string() + "TokenConfigurationChangeItem".to_string() } #[wasm_bindgen(js_name = "getItemName")] diff --git a/packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs b/packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs index db60e72080a..f4b59e40c2f 100644 --- a/packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs @@ -10,23 +10,23 @@ before(async () => { describe('AssetLockProof', () => { describe('serialization / deserialization', () => { it('should allow to get instant lock proof via constructor', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); - const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint); - const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = new wasm.ChainAssetLockProof(11, outpoint); + const instantLockProof = new wasm.InstantAssetLockProof(instantLockBytes, transactionBytes, 0); - const instantAssetLock = new wasm.AssetLockProofWASM(instantLockProof); - const chainAssetLock = new wasm.AssetLockProofWASM(chainlock); + const instantAssetLock = new wasm.AssetLockProof(instantLockProof); + const chainAssetLock = new wasm.AssetLockProof(chainlock); - expect(instantAssetLock.constructor.name).to.equal('AssetLockProofWASM'); + expect(instantAssetLock.constructor.name).to.equal('AssetLockProof'); expect(instantAssetLock.__wbg_ptr).to.not.equal(0); - expect(chainAssetLock.constructor.name).to.equal('AssetLockProofWASM'); + expect(chainAssetLock.constructor.name).to.equal('AssetLockProof'); expect(chainAssetLock.__wbg_ptr).to.not.equal(0); }); it('shouldn\'t allow to get chain lock proof via constructor', () => { try { // eslint-disable-next-line - new wasm.AssetLockProofWASM('chain') + new wasm.AssetLockProof('chain') } catch (e) { expect(true).to.be.ok; return; @@ -35,26 +35,26 @@ describe('AssetLockProof', () => { }); it('should allow to create instant lock proof from values', () => { - const instantLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof(instantLockBytes, transactionBytes, 0); + const instantLockProof = wasm.AssetLockProof.createInstantAssetLockProof(instantLockBytes, transactionBytes, 0); - expect(instantLockProof.constructor.name).to.equal('AssetLockProofWASM'); + expect(instantLockProof.constructor.name).to.equal('AssetLockProof'); }); it('should allow to create chain lock proof from values', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); - const chainLockProof = wasm.AssetLockProofWASM.createChainAssetLockProof(1, outpoint); + const chainLockProof = wasm.AssetLockProof.createChainAssetLockProof(1, outpoint); - expect(chainLockProof.constructor.name).to.equal('AssetLockProofWASM'); + expect(chainLockProof.constructor.name).to.equal('AssetLockProof'); }); it('should allow to serialize and deserialize asset lock in hex', () => { - const instantLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof(instantLockBytes, transactionBytes, 0); + const instantLockProof = wasm.AssetLockProof.createInstantAssetLockProof(instantLockBytes, transactionBytes, 0); - const newInstantLockProof = wasm.AssetLockProofWASM.fromHex(instantLockProof.hex()); + const newInstantLockProof = wasm.AssetLockProof.fromHex(instantLockProof.hex()); - expect(instantLockProof.constructor.name).to.equal('AssetLockProofWASM'); - expect(newInstantLockProof.constructor.name).to.equal('AssetLockProofWASM'); + expect(instantLockProof.constructor.name).to.equal('AssetLockProof'); + expect(newInstantLockProof.constructor.name).to.equal('AssetLockProof'); expect(newInstantLockProof.toObject()).to.deep.equal(instantLockProof.toObject()); }); @@ -62,31 +62,31 @@ describe('AssetLockProof', () => { describe('getters', () => { it('should allow to get lock type', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); - const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const instantLockProof = new wasm.InstantAssetLockProof(instantLockBytes, transactionBytes, 0); - const instantAssetLockProof = new wasm.AssetLockProofWASM(instantLockProof); - const chainLockProof = wasm.AssetLockProofWASM.createChainAssetLockProof(1, outpoint); + const instantAssetLockProof = new wasm.AssetLockProof(instantLockProof); + const chainLockProof = wasm.AssetLockProof.createChainAssetLockProof(1, outpoint); expect(instantAssetLockProof.getLockType()).to.equal('Instant'); expect(chainLockProof.getLockType()).to.equal('Chain'); }); it('should allow to get lock instances', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); - const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const instantLockProof = new wasm.InstantAssetLockProof(instantLockBytes, transactionBytes, 0); - const chainLockProof = wasm.AssetLockProofWASM.createChainAssetLockProof(1, outpoint); - const instantAssetLockProof = new wasm.AssetLockProofWASM(instantLockProof); + const chainLockProof = wasm.AssetLockProof.createChainAssetLockProof(1, outpoint); + const instantAssetLockProof = new wasm.AssetLockProof(instantLockProof); - expect(chainLockProof.getChainLockProof().constructor.name).to.equal('ChainAssetLockProofWASM'); - expect(instantAssetLockProof.getInstantLockProof().constructor.name).to.equal('InstantAssetLockProofWASM'); + expect(chainLockProof.getChainLockProof().constructor.name).to.equal('ChainAssetLockProof'); + expect(instantAssetLockProof.getInstantLockProof().constructor.name).to.equal('InstantAssetLockProof'); }); it('should allow to return object of lock', () => { - const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + const instantLockProof = new wasm.InstantAssetLockProof(instantLockBytes, transactionBytes, 0); - const instantAssetLockProof = new wasm.AssetLockProofWASM(instantLockProof); + const instantAssetLockProof = new wasm.AssetLockProof(instantLockProof); const expected = { instantLock: instantLockBytes, diff --git a/packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs b/packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs index 53f2f5fd0b0..9a100ebb492 100644 --- a/packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/AuthorizedActionTakers.spec.mjs @@ -10,35 +10,35 @@ before(async () => { describe('AuthorizedActionTakers', () => { describe('serialization / deserialization', () => { it('should allows to create AuthorizedActionTakers with NoOne', () => { - const actionTaker = wasm.AuthorizedActionTakersWASM.NoOne(); + const actionTaker = wasm.AuthorizedActionTakers.NoOne(); expect(actionTaker.__wbg_ptr).to.not.equal(0); expect(actionTaker.getTakerType()).to.deep.equal('NoOne'); }); it('should allows to create AuthorizedActionTakers with ContractOwner', () => { - const actionTaker = wasm.AuthorizedActionTakersWASM.ContractOwner(); + const actionTaker = wasm.AuthorizedActionTakers.ContractOwner(); expect(actionTaker.__wbg_ptr).to.not.equal(0); expect(actionTaker.getTakerType()).to.deep.equal('ContractOwner'); }); it('should allows to create AuthorizedActionTakers with Identity', () => { - const actionTaker = wasm.AuthorizedActionTakersWASM.Identity(identifier); + const actionTaker = wasm.AuthorizedActionTakers.Identity(identifier); expect(actionTaker.__wbg_ptr).to.not.equal(0); expect(actionTaker.getTakerType()).to.deep.equal(`Identity(${identifier})`); }); it('should allows to create AuthorizedActionTakers with MainGroup', () => { - const actionTaker = wasm.AuthorizedActionTakersWASM.MainGroup(); + const actionTaker = wasm.AuthorizedActionTakers.MainGroup(); expect(actionTaker.__wbg_ptr).to.not.equal(0); expect(actionTaker.getTakerType()).to.deep.equal('MainGroup'); }); it('should allows to create AuthorizedActionTakers with Group', () => { - const actionTaker = wasm.AuthorizedActionTakersWASM.Group(12); + const actionTaker = wasm.AuthorizedActionTakers.Group(12); expect(actionTaker.__wbg_ptr).to.not.equal(0); expect(actionTaker.getTakerType()).to.deep.equal('Group(12)'); @@ -47,31 +47,31 @@ describe('AuthorizedActionTakers', () => { describe('getters', () => { it('should allows to get value with NoOne', () => { - const actionTaker = wasm.AuthorizedActionTakersWASM.NoOne(); + const actionTaker = wasm.AuthorizedActionTakers.NoOne(); expect(actionTaker.getValue()).to.deep.equal(undefined); }); it('should allows to get value with ContractOwner', () => { - const actionTaker = wasm.AuthorizedActionTakersWASM.ContractOwner(); + const actionTaker = wasm.AuthorizedActionTakers.ContractOwner(); expect(actionTaker.getValue()).to.deep.equal(undefined); }); it('should allows to get value with Identity', () => { - const actionTaker = wasm.AuthorizedActionTakersWASM.Identity(identifier); + const actionTaker = wasm.AuthorizedActionTakers.Identity(identifier); expect(actionTaker.getValue().base58()).to.deep.equal(identifier); }); it('should allows to get value with MainGroup', () => { - const actionTaker = wasm.AuthorizedActionTakersWASM.MainGroup(); + const actionTaker = wasm.AuthorizedActionTakers.MainGroup(); expect(actionTaker.getValue()).to.deep.equal(undefined); }); it('should allows to get value with Group', () => { - const actionTaker = wasm.AuthorizedActionTakersWASM.Group(12); + const actionTaker = wasm.AuthorizedActionTakers.Group(12); expect(actionTaker.getValue()).to.deep.equal(12); }); diff --git a/packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs index 80a77517a43..50718c10a78 100644 --- a/packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/BatchTransition.spec.mjs @@ -13,12 +13,12 @@ describe('BatchTransition', () => { describe('serialization / deserialization', () => { describe('documents', () => { it('should allow to create from v0 transition', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const documentTransition = createTransition.toDocumentTransition(); - const batch = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1); + const batch = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(createTransition.__wbg_ptr).to.not.equal(0); @@ -27,14 +27,14 @@ describe('BatchTransition', () => { }); it('should allow to create from v1 transition', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const documentTransition = createTransition.toDocumentTransition(); - const batchedTransition = new wasm.BatchedTransitionWASM(documentTransition); + const batchedTransition = new wasm.BatchedTransition(documentTransition); - const batch = wasm.BatchTransitionWASM.fromV1BatchedTransitions([batchedTransition, batchedTransition], documentInstance.ownerId, 1); + const batch = wasm.BatchTransition.fromV1BatchedTransitions([batchedTransition, batchedTransition], documentInstance.ownerId, 1); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(createTransition.__wbg_ptr).to.not.equal(0); @@ -45,15 +45,15 @@ describe('BatchTransition', () => { }); describe('tokens', () => { it('should allow to create from v1 transition', () => { - const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId); + const baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId); - const mintTransition = new wasm.TokenMintTransitionWASM(baseTransition, ownerId, BigInt(9999), 'bbbbbb'); + const mintTransition = new wasm.TokenMintTransition(baseTransition, ownerId, BigInt(9999), 'bbbbbb'); - const transition = new wasm.TokenTransitionWASM(mintTransition); + const transition = new wasm.TokenTransition(mintTransition); - const batchedTransition = new wasm.BatchedTransitionWASM(transition); + const batchedTransition = new wasm.BatchedTransition(transition); - const batch = wasm.BatchTransitionWASM.fromV1BatchedTransitions([batchedTransition, batchedTransition], ownerId, 1); + const batch = wasm.BatchTransition.fromV1BatchedTransitions([batchedTransition, batchedTransition], ownerId, 1); expect(baseTransition.__wbg_ptr).to.not.equal(0); expect(mintTransition.__wbg_ptr).to.not.equal(0); @@ -66,80 +66,80 @@ describe('BatchTransition', () => { describe('getters', () => { it('should allow to get transitions', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const documentTransition = createTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); expect(batchTransition.transitions.length).to.equal(2); }); it('should allow to get signature', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const documentTransition = createTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); expect(batchTransition.signature).to.deep.equal(new Uint8Array(0)); }); it('should allow to get signature public key id', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const documentTransition = createTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); expect(batchTransition.signaturePublicKeyId).to.equal(1); }); it('should allow to get all purchases amount', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); - const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); + const purchaseTransition = new wasm.DocumentPurchaseTransition(documentInstance, BigInt(1), BigInt(100)); const documentTransition = createTransition.toDocumentTransition(); const documentTransition2 = purchaseTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition2], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition2], documentInstance.ownerId, 1, 1); expect(batchTransition.allPurchasesAmount).to.deep.equal(BigInt(100)); }); it('should allow to get owner id', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const documentTransition = createTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); expect(batchTransition.ownerId.base58()).to.deep.equal(documentInstance.ownerId.base58()); }); it('should allow to get modified data ids', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const documentTransition = createTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); expect(batchTransition.modifiedDataIds.map((identifier) => identifier.base58())).to.deep.equal([documentTransition.id.base58(), documentTransition.id.base58()]); }); it('should allow to get allConflictingIndexCollateralVotingFunds', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const documentTransition = createTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); expect(batchTransition.allConflictingIndexCollateralVotingFunds).to.deep.equal(undefined); }); diff --git a/packages/wasm-dpp2/tests/unit/ChainLockProof.spec.mjs b/packages/wasm-dpp2/tests/unit/ChainLockProof.spec.mjs index 3e5b78a3d18..5db059881d5 100644 --- a/packages/wasm-dpp2/tests/unit/ChainLockProof.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/ChainLockProof.spec.mjs @@ -9,15 +9,15 @@ before(async () => { describe('InstantLock', () => { describe('serialization / deserialization', () => { it('should allow to create chain lock proof from values', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); - const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = new wasm.ChainAssetLockProof(11, outpoint); expect(chainlock.__wbg_ptr).to.not.equal(0); }); it('should allow to create chain lock proof from object', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); - const chainlock = wasm.ChainAssetLockProofWASM.fromRawObject({ + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = wasm.ChainAssetLockProof.fromRawObject({ coreChainLockedHeight: 11, outPoint: Array.from(outpoint.bytes()), }); @@ -28,24 +28,24 @@ describe('InstantLock', () => { describe('getters', () => { it('should allow to get coreChainLockedHeight', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); - const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = new wasm.ChainAssetLockProof(11, outpoint); expect(chainlock.coreChainLockedHeight).to.equal(11); }); it('should allow to get outPoint', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); - const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = new wasm.ChainAssetLockProof(11, outpoint); - expect(chainlock.outPoint.constructor.name).to.equal('OutPointWASM'); + expect(chainlock.outPoint.constructor.name).to.equal('OutPoint'); }); }); describe('setters', () => { it('should allow to set coreChainLockedHeight', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); - const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = new wasm.ChainAssetLockProof(11, outpoint); chainlock.coreChainLockedHeight = 33; @@ -53,10 +53,10 @@ describe('InstantLock', () => { }); it('should allow to get outPoint', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); - const chainlock = new wasm.ChainAssetLockProofWASM(11, outpoint); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const chainlock = new wasm.ChainAssetLockProof(11, outpoint); - const newOutpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 222); + const newOutpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 222); chainlock.outPoint = newOutpoint; diff --git a/packages/wasm-dpp2/tests/unit/ChangeControlRules.spec.mjs b/packages/wasm-dpp2/tests/unit/ChangeControlRules.spec.mjs index 8d4da9334f4..e005ddfeb2f 100644 --- a/packages/wasm-dpp2/tests/unit/ChangeControlRules.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/ChangeControlRules.spec.mjs @@ -9,9 +9,9 @@ before(async () => { describe('ChangeControlRules', () => { describe('serialization / deserialization', () => { it('should allow to create rules from values', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -26,9 +26,9 @@ describe('ChangeControlRules', () => { describe('getters', () => { it('should allow to get authorizedToMakeChange', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -36,13 +36,13 @@ describe('ChangeControlRules', () => { true, ); - expect(changeRules.authorizedToMakeChange.constructor.name).to.deep.equal('AuthorizedActionTakersWASM'); + expect(changeRules.authorizedToMakeChange.constructor.name).to.deep.equal('AuthorizedActionTakers'); }); it('should allow to get adminActionTakers', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -50,13 +50,13 @@ describe('ChangeControlRules', () => { true, ); - expect(changeRules.adminActionTakers.constructor.name).to.deep.equal('AuthorizedActionTakersWASM'); + expect(changeRules.adminActionTakers.constructor.name).to.deep.equal('AuthorizedActionTakers'); }); it('should allow to get changingAuthorizedActionTakersToNoOneAllowed', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -68,9 +68,9 @@ describe('ChangeControlRules', () => { }); it('should allow to get changingAdminActionTakersToNoOneAllowed', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -82,9 +82,9 @@ describe('ChangeControlRules', () => { }); it('should allow to get selfChangingAdminActionTakersAllowed', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -98,9 +98,9 @@ describe('ChangeControlRules', () => { describe('setters', () => { it('should allow to set authorizedToMakeChange', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -108,19 +108,19 @@ describe('ChangeControlRules', () => { true, ); - const newActionTaker = wasm.AuthorizedActionTakersWASM.ContractOwner(); + const newActionTaker = wasm.AuthorizedActionTakers.ContractOwner(); changeRules.authorizedToMakeChange = newActionTaker; - expect(changeRules.authorizedToMakeChange.constructor.name).to.deep.equal('AuthorizedActionTakersWASM'); + expect(changeRules.authorizedToMakeChange.constructor.name).to.deep.equal('AuthorizedActionTakers'); expect(changeRules.authorizedToMakeChange.getTakerType()).to.deep.equal('ContractOwner'); expect(newActionTaker.__wbg_ptr).to.not.equal(0); }); it('should allow to set adminActionTakers', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -128,19 +128,19 @@ describe('ChangeControlRules', () => { true, ); - const newActionTaker = wasm.AuthorizedActionTakersWASM.ContractOwner(); + const newActionTaker = wasm.AuthorizedActionTakers.ContractOwner(); changeRules.adminActionTakers = newActionTaker; - expect(changeRules.adminActionTakers.constructor.name).to.deep.equal('AuthorizedActionTakersWASM'); + expect(changeRules.adminActionTakers.constructor.name).to.deep.equal('AuthorizedActionTakers'); expect(changeRules.adminActionTakers.getTakerType()).to.deep.equal('ContractOwner'); expect(newActionTaker.__wbg_ptr).to.not.equal(0); }); it('should allow to set changingAuthorizedActionTakersToNoOneAllowed', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -154,9 +154,9 @@ describe('ChangeControlRules', () => { }); it('should allow to set changingAdminActionTakersToNoOneAllowed', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -170,9 +170,9 @@ describe('ChangeControlRules', () => { }); it('should allow to set selfChangingAdminActionTakersAllowed', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, diff --git a/packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs b/packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs index 79fd513a6bd..e0ea5e46191 100644 --- a/packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/CoreScript.spec.mjs @@ -9,33 +9,33 @@ before(async () => { describe('CoreScript', () => { describe('serialization / deserialization', () => { it('should allow to create from bytes', () => { - const script = wasm.CoreScriptWASM.fromBytes(Buffer.from('76a914c3dbfd40e7f8a4845c2f8e868a167c984049764988ac', 'hex')); + const script = wasm.CoreScript.fromBytes(Buffer.from('76a914c3dbfd40e7f8a4845c2f8e868a167c984049764988ac', 'hex')); expect(script._wbg_ptr).to.not.equal(0); }); it('should allow to create P2PKH', () => { - const script = wasm.CoreScriptWASM.newP2PKH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73]); + const script = wasm.CoreScript.newP2PKH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73]); expect(script._wbg_ptr).to.not.equal(0); }); it('should allow to create P2SH', () => { - const script = wasm.CoreScriptWASM.newP2SH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73]); + const script = wasm.CoreScript.newP2SH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73]); expect(script._wbg_ptr).to.not.equal(0); }); it('should allow to convert to asm P2PKH', () => { - const script = wasm.CoreScriptWASM.newP2PKH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73]); + const script = wasm.CoreScript.newP2PKH([195, 219, 253, 64, 231, 248, 164, 132, 92, 47, 142, 134, 138, 22, 124, 152, 64, 73, 118, 73]); expect(script.ASMString()).to.equal('OP_DUP OP_HASH160 OP_PUSHBYTES_20 c3dbfd40e7f8a4845c2f8e868a167c9840497649 OP_EQUALVERIFY OP_CHECKSIG'); }); it('should allow to convert to adddress', () => { - const script = wasm.CoreScriptWASM.fromBytes(Buffer.from('76a9142de40f87177f6e167fb9fcda9a3b3c64fc42468f88ac', 'hex')); + const script = wasm.CoreScript.fromBytes(Buffer.from('76a9142de40f87177f6e167fb9fcda9a3b3c64fc42468f88ac', 'hex')); - expect(script.toAddress(wasm.NetworkWASM.Testnet)).to.equal('yQW6TmUFef5CDyhEYwjoN8aUTMmKLYYNDm'); + expect(script.toAddress(wasm.Network.Testnet)).to.equal('yQW6TmUFef5CDyhEYwjoN8aUTMmKLYYNDm'); }); }); }); diff --git a/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs b/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs index 899d7c398e9..4e94fc52b39 100644 --- a/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs @@ -3,11 +3,11 @@ import { value, id, ownerId } from './mocks/DataContract/index.js'; import { fromHexString } from './utils/hex.js'; let wasm; -let PlatformVersionWASM; +let PlatformVersion; before(async () => { wasm = await getWasm(); - ({ PlatformVersionWASM } = wasm); + ({ PlatformVersion } = wasm); }); let dataContractsBytes; @@ -19,23 +19,23 @@ describe('DataContract', () => { describe('serialization / deserialization', () => { it('should allows to create DataContract from schema without full validation', () => { - const identifier = new wasm.IdentifierWASM(value.ownerId); + const identifier = new wasm.Identifier(value.ownerId); - const dataContract = new wasm.DataContractWASM(identifier, BigInt(2), value.documentSchemas, null, false); + const dataContract = new wasm.DataContract(identifier, BigInt(2), value.documentSchemas, null, false); expect(dataContract.__wbg_ptr).to.not.equal(0); }); it('should allows to create DataContract from schema with full validation', () => { - const identifier = new wasm.IdentifierWASM(value.ownerId); + const identifier = new wasm.Identifier(value.ownerId); - const dataContract = new wasm.DataContractWASM(identifier, BigInt(2), value.documentSchemas, null, true); + const dataContract = new wasm.DataContract(identifier, BigInt(2), value.documentSchemas, null, true); expect(dataContract.__wbg_ptr).to.not.equal(0); }); it('should allows to create DataContract from value with full validation and without platform version', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); expect(dataContract.__wbg_ptr).to.not.equal(0); }); @@ -43,11 +43,11 @@ describe('DataContract', () => { it('should allows to convert DataContract to bytes and from bytes', () => { const [dataContractBytes] = dataContractsBytes; - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); expect(dataContract.bytes()).to.deep.equal(fromHexString(dataContractBytes)); - const dataContractFromBytes = wasm.DataContractWASM.fromBytes(dataContract.bytes(), false, PlatformVersionWASM.PLATFORM_V1); + const dataContractFromBytes = wasm.DataContract.fromBytes(dataContract.bytes(), false, PlatformVersion.PLATFORM_V1); expect(dataContract.__wbg_ptr).to.not.equal(0); @@ -57,8 +57,8 @@ describe('DataContract', () => { it('should allows to create DataContract from bytes without full validation', () => { const [dataContractBytes] = dataContractsBytes; - const dataContractFromBytes = wasm.DataContractWASM.fromBytes(fromHexString(dataContractBytes), false, PlatformVersionWASM.PLATFORM_V1); - const dataContractFromValue = wasm.DataContractWASM.fromValue(value, true); + const dataContractFromBytes = wasm.DataContract.fromBytes(fromHexString(dataContractBytes), false, PlatformVersion.PLATFORM_V1); + const dataContractFromValue = wasm.DataContract.fromValue(value, true); expect(dataContractFromBytes.toValue()).to.deep.equal(dataContractFromValue.toValue()); }); @@ -66,14 +66,14 @@ describe('DataContract', () => { it('should allows to create DataContract from bytes with full validation and without version', () => { const [dataContractBytes] = dataContractsBytes; - const dataContractFromBytes = wasm.DataContractWASM.fromBytes(fromHexString(dataContractBytes), true); - const dataContractFromValue = wasm.DataContractWASM.fromValue(value, true); + const dataContractFromBytes = wasm.DataContract.fromBytes(fromHexString(dataContractBytes), true); + const dataContractFromValue = wasm.DataContract.fromValue(value, true); expect(dataContractFromBytes.toValue()).to.deep.equal(dataContractFromValue.toValue()); }); it('should allow to get json', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); expect(dataContract.toJson()).to.deep.equal(value); }); @@ -81,31 +81,31 @@ describe('DataContract', () => { describe('getters', () => { it('should allow to get schemas', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); expect(dataContract.getSchemas()).to.deep.equal(value.documentSchemas); }); it('should allow to get version', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); expect(dataContract.version).to.deep.equal(value.version); }); it('should allow to get id', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); expect(dataContract.id.base58()).to.deep.equal(id); }); it('should allow to get owner id', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); expect(dataContract.ownerId.base58()).to.deep.equal(ownerId); }); it('should allow to get config', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); expect(dataContract.getConfig()).to.deep.equal(value.config); }); @@ -113,23 +113,23 @@ describe('DataContract', () => { describe('setters', () => { it('should allow to set id', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); - dataContract.id = new wasm.IdentifierWASM('7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH'); + dataContract.id = new wasm.Identifier('7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH'); expect(dataContract.id.base58()).to.deep.equal('7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH'); }); it('should allow to set owner id', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); - dataContract.ownerId = new wasm.IdentifierWASM('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL'); + dataContract.ownerId = new wasm.Identifier('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL'); expect(dataContract.ownerId.base58()).to.deep.equal('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL'); }); it('should allow to set version', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); dataContract.version = 20; @@ -137,7 +137,7 @@ describe('DataContract', () => { }); it('should allow to set config', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); const oldConfig = dataContract.getConfig(); @@ -149,7 +149,7 @@ describe('DataContract', () => { }); it('should allow to set schema', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, true); + const dataContract = wasm.DataContract.fromValue(value, true); const oldSchema = dataContract.getSchemas(); @@ -165,9 +165,9 @@ describe('DataContract', () => { describe('static', () => { it('should allow to generate id', () => { - const identifier = new wasm.IdentifierWASM('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL'); + const identifier = new wasm.Identifier('3bx13Wd5k4LwHAvXJrayc5HdKPyiccKWYECPQGGYfnVL'); - const generatedId = wasm.DataContractWASM.generateId(identifier, BigInt(4)); + const generatedId = wasm.DataContract.generateId(identifier, BigInt(4)); expect(generatedId.base58()).to.deep.equal('7ckT6Y19HnjfqoPFmfL995i4z2HwgZ8UttNmP99LtCBH'); }); diff --git a/packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs index 3b4b4ed29ba..fbbe1758f99 100644 --- a/packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs @@ -3,32 +3,32 @@ import { value, dataContractsBytes } from './mocks/DataContract/index.js'; import { fromHexString } from './utils/hex.js'; let wasm; -let PlatformVersionWASM; +let PlatformVersion; before(async () => { wasm = await getWasm(); - ({ PlatformVersionWASM } = wasm); + ({ PlatformVersion } = wasm); }); describe('DataContract Create Transition', () => { describe('serialization / deserialization', () => { it('should allow to create document_transitions from data contract', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractCreateTransition(dataContract, BigInt(1)); expect(dataContractTransition.__wbg_ptr).to.not.equal(0); expect(dataContract.__wbg_ptr).to.not.equal(0); }); it('should allow to convert document_transitions to bytes and create from bytes', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractCreateTransition(dataContract, BigInt(1)); const bytes = dataContractTransition.bytes(); - const newDataContractTransition = wasm.DataContractCreateTransitionWASM.fromBytes(bytes); + const newDataContractTransition = wasm.DataContractCreateTransition.fromBytes(bytes); expect(newDataContractTransition.bytes()).to.deep.equal(bytes); expect(newDataContractTransition.__wbg_ptr).to.not.equal(0); @@ -37,13 +37,13 @@ describe('DataContract Create Transition', () => { }); it('should allow to convert data contract transition to state document_transitions and create data contract transition from state transition', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractCreateTransition(dataContract, BigInt(1)); const stateTransition = dataContractTransition.toStateTransition(); - const newDataContractTransition = wasm.DataContractCreateTransitionWASM.fromStateTransition(stateTransition); + const newDataContractTransition = wasm.DataContractCreateTransition.fromStateTransition(stateTransition); expect(dataContractTransition.bytes()).to.deep.equal(newDataContractTransition.bytes()); }); @@ -51,25 +51,25 @@ describe('DataContract Create Transition', () => { describe('getters', () => { it('should allow to get feature version', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractCreateTransition(dataContract, BigInt(1)); expect(dataContractTransition.featureVersion).to.equal(0); }); it('should allow to verify protocol version', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractCreateTransition(dataContract, BigInt(1)); expect(dataContractTransition.verifyProtocolVersion(1)).to.equal(true); }); it('should allow to verify incorrect protocol version', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractCreateTransition(dataContract, BigInt(1)); try { dataContractTransition.verifyProtocolVersion(20); @@ -80,9 +80,9 @@ describe('DataContract Create Transition', () => { }); it('should allow to get data contract', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractCreateTransition(dataContract, BigInt(1)); const newDataContract = dataContractTransition.getDataContract(); @@ -94,11 +94,11 @@ describe('DataContract Create Transition', () => { it('should allow to set the data contract', () => { const [dataContractBytes] = dataContractsBytes; - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractCreateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractCreateTransition(dataContract, BigInt(1)); - const newDataContract = wasm.DataContractWASM.fromBytes(fromHexString(dataContractBytes), false, PlatformVersionWASM.PLATFORM_V1); + const newDataContract = wasm.DataContract.fromBytes(fromHexString(dataContractBytes), false, PlatformVersion.PLATFORM_V1); dataContractTransition.setDataContract(newDataContract); diff --git a/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs index 24759eeb81f..9dbbed988b9 100644 --- a/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs @@ -3,32 +3,32 @@ import { value, dataContractsBytes } from './mocks/DataContract/index.js'; import { fromHexString } from './utils/hex.js'; let wasm; -let PlatformVersionWASM; +let PlatformVersion; before(async () => { wasm = await getWasm(); - ({ PlatformVersionWASM } = wasm); + ({ PlatformVersion } = wasm); }); describe('DataContract Updatet Transition', () => { describe('serialization / deserialization', () => { it('should allow to create document_transitions from data contract', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractUpdateTransition(dataContract, BigInt(1)); expect(dataContractTransition.__wbg_ptr).to.not.equal(0); expect(dataContract.__wbg_ptr).to.not.equal(0); }); it('should allow to convert document_transitions to bytes and create from bytes', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractUpdateTransition(dataContract, BigInt(1)); const bytes = dataContractTransition.bytes(); - const newDataContractTransition = wasm.DataContractUpdateTransitionWASM.fromBytes(bytes); + const newDataContractTransition = wasm.DataContractUpdateTransition.fromBytes(bytes); expect(newDataContractTransition.bytes()).to.deep.equal(bytes); expect(newDataContractTransition.__wbg_ptr).to.not.equal(0); @@ -37,13 +37,13 @@ describe('DataContract Updatet Transition', () => { }); it('should allow to convert data contract transition to state document_transitions and create data contract transition from state transition', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractUpdateTransition(dataContract, BigInt(1)); const stateTransition = dataContractTransition.toStateTransition(); - const newDataContractTransition = wasm.DataContractUpdateTransitionWASM.fromStateTransition(stateTransition); + const newDataContractTransition = wasm.DataContractUpdateTransition.fromStateTransition(stateTransition); expect(dataContractTransition.bytes()).to.deep.equal(newDataContractTransition.bytes()); }); @@ -51,25 +51,25 @@ describe('DataContract Updatet Transition', () => { describe('getters', () => { it('should allow to get feature version', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractUpdateTransition(dataContract, BigInt(1)); expect(dataContractTransition.featureVersion).to.equal(0); }); it('should allow to verify protocol version', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractUpdateTransition(dataContract, BigInt(1)); expect(dataContractTransition.verifyProtocolVersion(1)).to.equal(true); }); it('should allow to verify incorrect protocol version', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractUpdateTransition(dataContract, BigInt(1)); try { dataContractTransition.verifyProtocolVersion(20); @@ -80,9 +80,9 @@ describe('DataContract Updatet Transition', () => { }); it('should allow to get data contract', () => { - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractUpdateTransition(dataContract, BigInt(1)); const newDataContract = dataContractTransition.getDataContract(); @@ -94,11 +94,11 @@ describe('DataContract Updatet Transition', () => { it('should allow to set the data contract', () => { const [dataContractBytes] = dataContractsBytes; - const dataContract = wasm.DataContractWASM.fromValue(value, false, PlatformVersionWASM.PLATFORM_V1); + const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); - const dataContractTransition = new wasm.DataContractUpdateTransitionWASM(dataContract, BigInt(1)); + const dataContractTransition = new wasm.DataContractUpdateTransition(dataContract, BigInt(1)); - const newDataContract = wasm.DataContractWASM.fromBytes(fromHexString(dataContractBytes), false, PlatformVersionWASM.PLATFORM_V1); + const newDataContract = wasm.DataContract.fromBytes(fromHexString(dataContractBytes), false, PlatformVersion.PLATFORM_V1); dataContractTransition.setDataContract(newDataContract); diff --git a/packages/wasm-dpp2/tests/unit/DistributionFunction.spec.mjs b/packages/wasm-dpp2/tests/unit/DistributionFunction.spec.mjs index 70c26692fea..dfb269c8237 100644 --- a/packages/wasm-dpp2/tests/unit/DistributionFunction.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DistributionFunction.spec.mjs @@ -9,7 +9,7 @@ before(async () => { describe('DistributionFunction', function () { describe('serialization / deserialization', function () { it('shoulda allow to create FixedAmountDistribution', () => { - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111) ) @@ -17,7 +17,7 @@ describe('DistributionFunction', function () { }) it('shoulda allow to create Random', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Random( + const distributionFunction = wasm.DistributionFunction.Random( BigInt(111), BigInt(113) ) @@ -26,7 +26,7 @@ describe('DistributionFunction', function () { }) it('shoulda allow to create StepDecreasingAmount', () => { - const distributionFunction = wasm.DistributionFunctionWASM.StepDecreasingAmount( + const distributionFunction = wasm.DistributionFunction.StepDecreasingAmount( 11, 11, 11, @@ -41,7 +41,7 @@ describe('DistributionFunction', function () { }) it('shoulda allow to create Stepwise', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Stepwise( + const distributionFunction = wasm.DistributionFunction.Stepwise( { 11111111121: BigInt(111) } @@ -51,7 +51,7 @@ describe('DistributionFunction', function () { }) it('shoulda allow to create Linear', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Linear( + const distributionFunction = wasm.DistributionFunction.Linear( BigInt(111), BigInt(113), undefined, @@ -64,7 +64,7 @@ describe('DistributionFunction', function () { }) it('shoulda allow to create Polynomial', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Polynomial( + const distributionFunction = wasm.DistributionFunction.Polynomial( BigInt(111), BigInt(113), BigInt(113), @@ -80,7 +80,7 @@ describe('DistributionFunction', function () { }) it('shoulda allow to create Exponential', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Exponential( + const distributionFunction = wasm.DistributionFunction.Exponential( BigInt(111), BigInt(113), BigInt(113), @@ -96,7 +96,7 @@ describe('DistributionFunction', function () { }) it('shoulda allow to create Logarithmic', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Logarithmic( + const distributionFunction = wasm.DistributionFunction.Logarithmic( BigInt(111), BigInt(113), BigInt(113), @@ -112,7 +112,7 @@ describe('DistributionFunction', function () { }) it('shoulda allow to create InvertedLogarithmic', () => { - const distributionFunction = wasm.DistributionFunctionWASM.InvertedLogarithmic( + const distributionFunction = wasm.DistributionFunction.InvertedLogarithmic( BigInt(111), BigInt(113), BigInt(113), @@ -131,7 +131,7 @@ describe('DistributionFunction', function () { describe('getters', function () { describe('function name', function () { it('FixedAmountDistribution', () => { - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111) ) @@ -139,7 +139,7 @@ describe('DistributionFunction', function () { }) it('Random', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Random( + const distributionFunction = wasm.DistributionFunction.Random( BigInt(111), BigInt(113) ) @@ -148,7 +148,7 @@ describe('DistributionFunction', function () { }) it('StepDecreasingAmount', () => { - const distributionFunction = wasm.DistributionFunctionWASM.StepDecreasingAmount( + const distributionFunction = wasm.DistributionFunction.StepDecreasingAmount( 11, 11, 11, @@ -163,7 +163,7 @@ describe('DistributionFunction', function () { }) it('Stepwise', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Stepwise( + const distributionFunction = wasm.DistributionFunction.Stepwise( { 11111111121: BigInt(111) } @@ -173,7 +173,7 @@ describe('DistributionFunction', function () { }) it('Linear', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Linear( + const distributionFunction = wasm.DistributionFunction.Linear( BigInt(111), BigInt(113), undefined, @@ -186,7 +186,7 @@ describe('DistributionFunction', function () { }) it('Polynomial', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Polynomial( + const distributionFunction = wasm.DistributionFunction.Polynomial( BigInt(111), BigInt(113), BigInt(113), @@ -202,7 +202,7 @@ describe('DistributionFunction', function () { }) it('Exponential', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Exponential( + const distributionFunction = wasm.DistributionFunction.Exponential( BigInt(111), BigInt(113), BigInt(113), @@ -218,7 +218,7 @@ describe('DistributionFunction', function () { }) it('Logarithmic', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Logarithmic( + const distributionFunction = wasm.DistributionFunction.Logarithmic( BigInt(111), BigInt(113), BigInt(113), @@ -234,7 +234,7 @@ describe('DistributionFunction', function () { }) it('InvertedLogarithmic', () => { - const distributionFunction = wasm.DistributionFunctionWASM.InvertedLogarithmic( + const distributionFunction = wasm.DistributionFunction.InvertedLogarithmic( BigInt(111), BigInt(113), BigInt(113), @@ -251,7 +251,7 @@ describe('DistributionFunction', function () { }) describe('function value', function () { it('FixedAmountDistribution', () => { - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111) ) @@ -259,7 +259,7 @@ describe('DistributionFunction', function () { }) it('Random', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Random( + const distributionFunction = wasm.DistributionFunction.Random( BigInt(111), BigInt(113) ) @@ -269,7 +269,7 @@ describe('DistributionFunction', function () { }) it('StepDecreasingAmount', () => { - const distributionFunction = wasm.DistributionFunctionWASM.StepDecreasingAmount( + const distributionFunction = wasm.DistributionFunction.StepDecreasingAmount( 11, 11, 11, @@ -291,7 +291,7 @@ describe('DistributionFunction', function () { }) it('Stepwise', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Stepwise( + const distributionFunction = wasm.DistributionFunction.Stepwise( { 11111111121: BigInt(111) } @@ -303,7 +303,7 @@ describe('DistributionFunction', function () { }) it('Linear', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Linear( + const distributionFunction = wasm.DistributionFunction.Linear( BigInt(111), BigInt(113), undefined, @@ -321,7 +321,7 @@ describe('DistributionFunction', function () { }) it('Polynomial', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Polynomial( + const distributionFunction = wasm.DistributionFunction.Polynomial( BigInt(111), BigInt(113), BigInt(113), @@ -345,7 +345,7 @@ describe('DistributionFunction', function () { }) it('Exponential', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Exponential( + const distributionFunction = wasm.DistributionFunction.Exponential( BigInt(111), BigInt(113), BigInt(113), @@ -369,7 +369,7 @@ describe('DistributionFunction', function () { }) it('Logarithmic', () => { - const distributionFunction = wasm.DistributionFunctionWASM.Logarithmic( + const distributionFunction = wasm.DistributionFunction.Logarithmic( BigInt(111), BigInt(113), BigInt(113), @@ -393,7 +393,7 @@ describe('DistributionFunction', function () { }) it('InvertedLogarithmic', () => { - const distributionFunction = wasm.DistributionFunctionWASM.InvertedLogarithmic( + const distributionFunction = wasm.DistributionFunction.InvertedLogarithmic( BigInt(111), BigInt(113), BigInt(113), diff --git a/packages/wasm-dpp2/tests/unit/Document.spec.mjs b/packages/wasm-dpp2/tests/unit/Document.spec.mjs index 773205f8352..7509a26e37f 100644 --- a/packages/wasm-dpp2/tests/unit/Document.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/Document.spec.mjs @@ -5,39 +5,39 @@ import { import { fromHexString } from './utils/hex.js'; let wasm; -let PlatformVersionWASM; +let PlatformVersion; before(async () => { wasm = await getWasm(); - ({ PlatformVersionWASM } = wasm); + ({ PlatformVersion } = wasm); }); describe('Document', () => { describe('serialization / deserialization', () => { it('should allows to create Document from values', () => { - const dataContractIdentifier = new wasm.IdentifierWASM(dataContractId); - const ownerIdentifier = new wasm.IdentifierWASM(ownerId); + const dataContractIdentifier = new wasm.Identifier(dataContractId); + const ownerIdentifier = new wasm.Identifier(ownerId); - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractIdentifier, ownerIdentifier); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractIdentifier, ownerIdentifier); expect(documentInstance.__wbg_ptr).to.not.equal(0); }); it('should allows to create Document from values with custom id', () => { - const dataContractIdentifier = new wasm.IdentifierWASM(dataContractId); - const ownerIdentifier = new wasm.IdentifierWASM(ownerId); - const identifier = new wasm.IdentifierWASM(id); + const dataContractIdentifier = new wasm.Identifier(dataContractId); + const ownerIdentifier = new wasm.Identifier(ownerId); + const identifier = new wasm.Identifier(id); - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractIdentifier, ownerIdentifier, identifier); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractIdentifier, ownerIdentifier, identifier); expect(documentInstance.__wbg_ptr).to.not.equal(0); }); it('should allows to create Document from bytes and convert to bytes', () => { - const dataContract = wasm.DataContractWASM.fromValue(dataContractValue, false); - const documentInstance = wasm.DocumentWASM.fromBytes(fromHexString(documentBytes), dataContract, 'note'); + const dataContract = wasm.DataContract.fromValue(dataContractValue, false); + const documentInstance = wasm.Document.fromBytes(fromHexString(documentBytes), dataContract, 'note'); - const bytes = documentInstance.bytes(dataContract, PlatformVersionWASM.PLATFORM_V1); + const bytes = documentInstance.bytes(dataContract, PlatformVersion.PLATFORM_V1); expect(documentInstance.dataContractId.base58()).to.equal(dataContract.id.base58()); expect(bytes).to.deep.equal(fromHexString(documentBytes)); @@ -47,31 +47,31 @@ describe('Document', () => { describe('getters', () => { it('should return document id', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); expect(documentInstance.id.base58()).to.deep.equal(id); }); it('should return owner id', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); expect(documentInstance.ownerId.base58()).to.deep.equal(ownerId); }); it('should return data contract id', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); expect(documentInstance.dataContractId.base58()).to.deep.equal(dataContractId); }); it('should return properties', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); expect(documentInstance.properties).to.deep.equal(document); }); it('should return revision', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); expect(documentInstance.revision).to.deep.equal(revision); }); @@ -79,7 +79,7 @@ describe('Document', () => { describe('setters', () => { it('should allow to set document id', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); documentInstance.id = ownerId; @@ -87,7 +87,7 @@ describe('Document', () => { }); it('should allow to set document owner id', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); documentInstance.ownerId = id; @@ -95,7 +95,7 @@ describe('Document', () => { }); it('should allow to set entropy', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); const newEntropy = new Array(documentInstance.entropy.length).fill(0); @@ -105,7 +105,7 @@ describe('Document', () => { }); it('should allow to set properties', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); documentInstance.properties = document2; @@ -113,7 +113,7 @@ describe('Document', () => { }); it('should allow to set revision', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); const newRevision = BigInt(1000); @@ -123,7 +123,7 @@ describe('Document', () => { }); it('should allow to set created at', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); const createdAt = BigInt(new Date(1123).getTime()); @@ -133,7 +133,7 @@ describe('Document', () => { }); it('should allow to set updated at', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); const updatedAt = BigInt(new Date(1123).getTime()); @@ -143,7 +143,7 @@ describe('Document', () => { }); it('should allow to set transferred at', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); const transferredAt = BigInt(new Date(11231).getTime()); @@ -153,7 +153,7 @@ describe('Document', () => { }); it('should allow to set create at Block Height', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); const createdAtHeight = BigInt(9172); @@ -163,7 +163,7 @@ describe('Document', () => { }); it('should allow to set updated at Block Height', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); const updatedAtHeight = BigInt(9172); @@ -173,7 +173,7 @@ describe('Document', () => { }); it('should allow to set transferred at Block Height', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); const transferredAtHeight = BigInt(9172); @@ -183,7 +183,7 @@ describe('Document', () => { }); it('should allow to set create at core Block Height', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); const createdAtHeight = 91721; @@ -193,7 +193,7 @@ describe('Document', () => { }); it('should allow to set updated at Block Height', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); const updatedAtHeight = 91722; @@ -203,7 +203,7 @@ describe('Document', () => { }); it('should allow to set transferred at Block Height', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); const transferredAtHeight = 91723; @@ -213,7 +213,7 @@ describe('Document', () => { }); it('should allow to set document type name', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); const newDocumentTypeName = 'bbbb'; @@ -225,7 +225,7 @@ describe('Document', () => { describe('static', () => { it('should allow to generate id', () => { - const generatedId = wasm.DocumentWASM.generateId('note', ownerId, dataContractId); + const generatedId = wasm.Document.generateId('note', ownerId, dataContractId); expect(Array.from(generatedId).length).to.equal(32); }); diff --git a/packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs index 3f4c16f2f41..528ca319cf7 100644 --- a/packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs @@ -15,9 +15,9 @@ let replaceTransition; describe('DocumentTransition', () => { before(async () => { - documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); - replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); + replaceTransition = new wasm.DocumentReplaceTransition(documentInstance, BigInt(1)); }); describe('serialization / deserialization', () => { diff --git a/packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs b/packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs index 34d8bcd361e..23b43be128e 100644 --- a/packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs @@ -13,16 +13,16 @@ describe('DocumentsTransitions', () => { describe('serialization / deserialization', () => { describe('document Create transition', () => { it('should allow to create CreateTransition from document', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(createTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create Document Transition from Create transition', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const documentTransition = createTransition.toDocumentTransition(); @@ -32,12 +32,12 @@ describe('DocumentsTransitions', () => { }); it('should allow to create Document Batch Transition from Document Transitions', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const documentTransition = createTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(createTransition.__wbg_ptr).to.not.equal(0); @@ -46,16 +46,16 @@ describe('DocumentsTransitions', () => { }); it('should allow to create state document_transitions from document and convert state transition to document batch', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const documentTransition = createTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); const st = batchTransition.toStateTransition(); - const deserializedBatch = wasm.BatchTransitionWASM.fromStateTransition(st); + const deserializedBatch = wasm.BatchTransition.fromStateTransition(st); const deserializedTransitions = deserializedBatch.transitions; @@ -75,16 +75,16 @@ describe('DocumentsTransitions', () => { describe('document Delete transition', () => { it('should allow to create DeleteTransition from document', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const deleteTransition = new wasm.DocumentDeleteTransition(documentInstance, BigInt(1)); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(deleteTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create Document Transition from Delete transition', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const deleteTransition = new wasm.DocumentDeleteTransition(documentInstance, BigInt(1)); const documentTransition = deleteTransition.toDocumentTransition(); @@ -94,12 +94,12 @@ describe('DocumentsTransitions', () => { }); it('should allow to create Document Batch Transition from Document Transitions', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const deleteTransition = new wasm.DocumentDeleteTransition(documentInstance, BigInt(1)); const documentTransition = deleteTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(deleteTransition.__wbg_ptr).to.not.equal(0); @@ -108,16 +108,16 @@ describe('DocumentsTransitions', () => { }); it('should allow to create state document_transitions from document and convert state transition to document batch', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const deleteTransition = new wasm.DocumentDeleteTransition(documentInstance, BigInt(1)); const documentTransition = deleteTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); const st = batchTransition.toStateTransition(); - const deserializedBatch = wasm.BatchTransitionWASM.fromStateTransition(st); + const deserializedBatch = wasm.BatchTransition.fromStateTransition(st); const deserializedTransitions = deserializedBatch.transitions; @@ -137,16 +137,16 @@ describe('DocumentsTransitions', () => { describe('document Replace transition', () => { it('should allow to create ReplaceTransition from document', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransition(documentInstance, BigInt(1)); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(replaceTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create Document Transition from Replace transition', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransition(documentInstance, BigInt(1)); const documentTransition = replaceTransition.toDocumentTransition(); @@ -156,12 +156,12 @@ describe('DocumentsTransitions', () => { }); it('should allow to create Document Batch Transition from Document Transitions', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransition(documentInstance, BigInt(1)); const documentTransition = replaceTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(replaceTransition.__wbg_ptr).to.not.equal(0); @@ -170,16 +170,16 @@ describe('DocumentsTransitions', () => { }); it('should allow to create state document_transitions from document and convert state transition to document batch', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransition(documentInstance, BigInt(1)); const documentTransition = replaceTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); const st = batchTransition.toStateTransition(); - const deserializedBatch = wasm.BatchTransitionWASM.fromStateTransition(st); + const deserializedBatch = wasm.BatchTransition.fromStateTransition(st); const deserializedTransitions = deserializedBatch.transitions; @@ -199,16 +199,16 @@ describe('DocumentsTransitions', () => { describe('document Transfer transition', () => { it('should allow to create ReplaceTransition from document', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransition(documentInstance, BigInt(1), documentInstance.ownerId); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(transferTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create Document Transition from Replace transition', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransition(documentInstance, BigInt(1), documentInstance.ownerId); const documentTransition = transferTransition.toDocumentTransition(); @@ -218,12 +218,12 @@ describe('DocumentsTransitions', () => { }); it('should allow to create Document Batch Transition from Document Transitions', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransition(documentInstance, BigInt(1), documentInstance.ownerId); const documentTransition = transferTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(transferTransition.__wbg_ptr).to.not.equal(0); @@ -232,16 +232,16 @@ describe('DocumentsTransitions', () => { }); it('should allow to create state document_transitions from document and convert state transition to document batch', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransition(documentInstance, BigInt(1), documentInstance.ownerId); const documentTransition = transferTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); const st = batchTransition.toStateTransition(); - const deserializedBatch = wasm.BatchTransitionWASM.fromStateTransition(st); + const deserializedBatch = wasm.BatchTransition.fromStateTransition(st); const deserializedTransitions = deserializedBatch.transitions; @@ -261,16 +261,16 @@ describe('DocumentsTransitions', () => { describe('document UpdatePrice transition', () => { it('should allow to create UpdatePriceTransition from document', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransition(documentInstance, BigInt(1), BigInt(100)); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(updatePriceTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create Document Transition from UpdatePrice transition', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransition(documentInstance, BigInt(1), BigInt(100)); const documentTransition = updatePriceTransition.toDocumentTransition(); @@ -280,12 +280,12 @@ describe('DocumentsTransitions', () => { }); it('should allow to create Document Batch Transition from Document Transitions', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransition(documentInstance, BigInt(1), BigInt(100)); const documentTransition = updatePriceTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(updatePriceTransition.__wbg_ptr).to.not.equal(0); @@ -294,16 +294,16 @@ describe('DocumentsTransitions', () => { }); it('should allow to create state document_transitions from document and convert state transition to document batch', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransition(documentInstance, BigInt(1), BigInt(100)); const documentTransition = updatePriceTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); const st = batchTransition.toStateTransition(); - const deserializedBatch = wasm.BatchTransitionWASM.fromStateTransition(st); + const deserializedBatch = wasm.BatchTransition.fromStateTransition(st); const deserializedTransitions = deserializedBatch.transitions; @@ -323,16 +323,16 @@ describe('DocumentsTransitions', () => { describe('document Purchase transition', () => { it('should allow to create PurchaseTransition from document', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransition(documentInstance, BigInt(1), BigInt(100)); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(purchaseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create Document Transition from PurchaseTransition transition', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransition(documentInstance, BigInt(1), BigInt(100)); const documentTransition = purchaseTransition.toDocumentTransition(); @@ -342,12 +342,12 @@ describe('DocumentsTransitions', () => { }); it('should allow to create Document Batch Transition from Document Transitions', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransition(documentInstance, BigInt(1), BigInt(100)); const documentTransition = purchaseTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); expect(documentInstance.__wbg_ptr).to.not.equal(0); expect(purchaseTransition.__wbg_ptr).to.not.equal(0); @@ -356,16 +356,16 @@ describe('DocumentsTransitions', () => { }); it('should allow to create state document_transitions from document and convert state transition to document batch', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransition(documentInstance, BigInt(1), BigInt(100)); const documentTransition = purchaseTransition.toDocumentTransition(); - const batchTransition = wasm.BatchTransitionWASM.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); + const batchTransition = wasm.BatchTransition.fromV0Transitions([documentTransition, documentTransition], documentInstance.ownerId, 1, 1); const st = batchTransition.toStateTransition(); - const deserializedBatch = wasm.BatchTransitionWASM.fromStateTransition(st); + const deserializedBatch = wasm.BatchTransition.fromStateTransition(st); const deserializedTransitions = deserializedBatch.transitions; @@ -386,29 +386,29 @@ describe('DocumentsTransitions', () => { describe('getters', () => { describe('document Create transition', () => { it('get data', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); expect(createTransition.data).to.deep.equal(document); }); it('get base', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); - expect(createTransition.base.constructor.name).to.equal('DocumentBaseTransitionWASM'); + expect(createTransition.base.constructor.name).to.equal('DocumentBaseTransition'); }); it('get entropy', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); expect(createTransition.entropy).to.deep.equal(documentInstance.entropy); }); it('get prefunded voting balance', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); expect(createTransition.prefundedVotingBalance).to.equal(undefined); }); @@ -416,31 +416,31 @@ describe('DocumentsTransitions', () => { describe('document Delete transition', () => { it('get base', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const deleteTransition = new wasm.DocumentDeleteTransition(documentInstance, BigInt(1)); - expect(deleteTransition.base.constructor.name).to.equal('DocumentBaseTransitionWASM'); + expect(deleteTransition.base.constructor.name).to.equal('DocumentBaseTransition'); }); }); describe('document Replace transition', () => { it('get data', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransition(documentInstance, BigInt(1)); expect(replaceTransition.data).to.deep.equal(document); }); it('get base', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransition(documentInstance, BigInt(1)); - expect(replaceTransition.base.constructor.name).to.equal('DocumentBaseTransitionWASM'); + expect(replaceTransition.base.constructor.name).to.equal('DocumentBaseTransition'); }); it('get revision', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransition(documentInstance, BigInt(1)); expect(replaceTransition.revision).to.equal(BigInt(2)); }); @@ -448,15 +448,15 @@ describe('DocumentsTransitions', () => { describe('document Transfer transition', () => { it('get base', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransition(documentInstance, BigInt(1), documentInstance.ownerId); - expect(transferTransition.base.constructor.name).to.equal('DocumentBaseTransitionWASM'); + expect(transferTransition.base.constructor.name).to.equal('DocumentBaseTransition'); }); it('get recipient', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransition(documentInstance, BigInt(1), documentInstance.ownerId); expect(transferTransition.recipientId.base58()).to.deep.equal(documentInstance.ownerId.base58()); }); @@ -464,15 +464,15 @@ describe('DocumentsTransitions', () => { describe('document Update Price transition', () => { it('get base', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransition(documentInstance, BigInt(1), BigInt(100)); - expect(updatePriceTransition.base.constructor.name).to.equal('DocumentBaseTransitionWASM'); + expect(updatePriceTransition.base.constructor.name).to.equal('DocumentBaseTransition'); }); it('get price', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransition(documentInstance, BigInt(1), BigInt(100)); expect(updatePriceTransition.price).to.deep.equal(BigInt(100)); }); @@ -480,15 +480,15 @@ describe('DocumentsTransitions', () => { describe('document Purchase transition', () => { it('get base', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransition(documentInstance, BigInt(1), BigInt(100)); - expect(purchaseTransition.base.constructor.name).to.equal('DocumentBaseTransitionWASM'); + expect(purchaseTransition.base.constructor.name).to.equal('DocumentBaseTransition'); }); it('get price', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransition(documentInstance, BigInt(1), BigInt(100)); expect(purchaseTransition.price).to.deep.equal(BigInt(100)); }); @@ -498,8 +498,8 @@ describe('DocumentsTransitions', () => { describe('setters', () => { describe('document Create transition', () => { it('set data', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const newData = { message: 'bebra' }; @@ -509,10 +509,10 @@ describe('DocumentsTransitions', () => { }); it('set base', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); - const newBase = new wasm.DocumentBaseTransitionWASM( + const newBase = new wasm.DocumentBaseTransition( documentInstance.id, BigInt(12350), 'bbbbb', @@ -526,8 +526,8 @@ describe('DocumentsTransitions', () => { }); it('set entropy', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); const newEntropy = new Uint8Array(32); @@ -537,10 +537,10 @@ describe('DocumentsTransitions', () => { }); it('set prefunded voting balance', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const createTransition = new wasm.DocumentCreateTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const createTransition = new wasm.DocumentCreateTransition(documentInstance, BigInt(1)); - const newPrefundedVotingBalance = new wasm.PrefundedVotingBalanceWASM('note', BigInt(9999)); + const newPrefundedVotingBalance = new wasm.PrefundedVotingBalance('note', BigInt(9999)); createTransition.prefundedVotingBalance = newPrefundedVotingBalance; @@ -551,10 +551,10 @@ describe('DocumentsTransitions', () => { describe('document Delete transition', () => { it('set base', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const deleteTransition = new wasm.DocumentDeleteTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const deleteTransition = new wasm.DocumentDeleteTransition(documentInstance, BigInt(1)); - const newBase = new wasm.DocumentBaseTransitionWASM( + const newBase = new wasm.DocumentBaseTransition( documentInstance.id, BigInt(12350), 'bbbbb', @@ -570,8 +570,8 @@ describe('DocumentsTransitions', () => { describe('document Replace transition', () => { it('set data', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransition(documentInstance, BigInt(1)); const newData = { message: 'bebra' }; @@ -581,10 +581,10 @@ describe('DocumentsTransitions', () => { }); it('set base', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransition(documentInstance, BigInt(1)); - const newBase = new wasm.DocumentBaseTransitionWASM( + const newBase = new wasm.DocumentBaseTransition( documentInstance.id, BigInt(12350), 'bbbbb', @@ -598,8 +598,8 @@ describe('DocumentsTransitions', () => { }); it('set revision', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const replaceTransition = new wasm.DocumentReplaceTransitionWASM(documentInstance, BigInt(1)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const replaceTransition = new wasm.DocumentReplaceTransition(documentInstance, BigInt(1)); replaceTransition.revision = BigInt(11); @@ -609,10 +609,10 @@ describe('DocumentsTransitions', () => { describe('document Transfer transition', () => { it('set base', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransition(documentInstance, BigInt(1), documentInstance.ownerId); - const newBase = new wasm.DocumentBaseTransitionWASM( + const newBase = new wasm.DocumentBaseTransition( documentInstance.id, BigInt(12350), 'bbbbb', @@ -626,8 +626,8 @@ describe('DocumentsTransitions', () => { }); it('set recipient', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const transferTransition = new wasm.DocumentTransferTransitionWASM(documentInstance, BigInt(1), documentInstance.ownerId); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const transferTransition = new wasm.DocumentTransferTransition(documentInstance, BigInt(1), documentInstance.ownerId); const newRecipient = new Uint8Array(32); @@ -639,10 +639,10 @@ describe('DocumentsTransitions', () => { describe('document Update Price transition', () => { it('set base', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransition(documentInstance, BigInt(1), BigInt(100)); - const newBase = new wasm.DocumentBaseTransitionWASM( + const newBase = new wasm.DocumentBaseTransition( documentInstance.id, BigInt(12350), 'bbbbb', @@ -656,8 +656,8 @@ describe('DocumentsTransitions', () => { }); it('set price', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const updatePriceTransition = new wasm.DocumentUpdatePriceTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const updatePriceTransition = new wasm.DocumentUpdatePriceTransition(documentInstance, BigInt(1), BigInt(100)); updatePriceTransition.price = BigInt(1111); @@ -667,10 +667,10 @@ describe('DocumentsTransitions', () => { describe('document Purchase transition', () => { it('set base', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransition(documentInstance, BigInt(1), BigInt(100)); - const newBase = new wasm.DocumentBaseTransitionWASM( + const newBase = new wasm.DocumentBaseTransition( documentInstance.id, BigInt(12350), 'bbbbb', @@ -684,8 +684,8 @@ describe('DocumentsTransitions', () => { }); it('set price', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransition(documentInstance, BigInt(1), BigInt(100)); purchaseTransition.price = BigInt(1111); @@ -693,8 +693,8 @@ describe('DocumentsTransitions', () => { }); it('set revision', () => { - const documentInstance = new wasm.DocumentWASM(document, documentTypeName, revision, dataContractId, ownerId, id); - const purchaseTransition = new wasm.DocumentPurchaseTransitionWASM(documentInstance, BigInt(1), BigInt(100)); + const documentInstance = new wasm.Document(document, documentTypeName, revision, dataContractId, ownerId, id); + const purchaseTransition = new wasm.DocumentPurchaseTransition(documentInstance, BigInt(1), BigInt(100)); purchaseTransition.revision = BigInt(1111); diff --git a/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs b/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs index ad708f26003..24a2753b4dc 100644 --- a/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs @@ -15,44 +15,44 @@ describe('Identifier', () => { describe('serialization / deserialization', () => { it('should allows to create Identifier from base58', () => { - const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + const identifier = wasm.Identifier.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); expect(identifier.bytes()).to.deep.equal(identifierBytes); }); it('should allows to create Identifier from base64', () => { - const identifier = wasm.IdentifierWASM.fromBase64('CSgo7cCB07oaVPBDJZuUE2jyxxiIGwap00eIOyG/4xM='); + const identifier = wasm.Identifier.fromBase64('CSgo7cCB07oaVPBDJZuUE2jyxxiIGwap00eIOyG/4xM='); expect(identifier.bytes()).to.deep.equal(identifierBytes); }); it('should allows to create Identifier from hex', () => { - const identifier = wasm.IdentifierWASM.fromHex('092828edc081d3ba1a54f043259b941368f2c718881b06a9d347883b21bfe313'); + const identifier = wasm.Identifier.fromHex('092828edc081d3ba1a54f043259b941368f2c718881b06a9d347883b21bfe313'); expect(identifier.bytes()).to.deep.equal(identifierBytes); }); it('should allows to create Identifier from bytes', () => { - const identifier = wasm.IdentifierWASM.fromBytes(identifierBytes); + const identifier = wasm.Identifier.fromBytes(identifierBytes); expect(identifier.bytes()).to.deep.equal(identifierBytes); }); it('should allows to create Identifier from Identifier', () => { - const identifier = wasm.IdentifierWASM.fromBytes(identifierBytes); - const identifier2 = new wasm.IdentifierWASM(identifier); + const identifier = wasm.Identifier.fromBytes(identifierBytes); + const identifier2 = new wasm.Identifier(identifier); expect(identifier2.bytes()).to.deep.equal(identifierBytes); }); it('should allows to create Identifier from bytes in constructor', () => { - const identifier = new wasm.IdentifierWASM(identifierBytes); + const identifier = new wasm.Identifier(identifierBytes); expect(identifier.bytes()).to.deep.equal(identifierBytes); }); it('should allows to create Identifier from base58 in constructor', () => { - const identifier = new wasm.IdentifierWASM('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + const identifier = new wasm.Identifier('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); expect(identifier.bytes()).to.deep.equal(identifierBytes); }); @@ -60,25 +60,25 @@ describe('Identifier', () => { describe('getters', () => { it('should allow to get identifier base58', () => { - const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + const identifier = wasm.Identifier.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); expect(identifier.base58()).to.equal('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); }); it('should allow to get identifier base64', () => { - const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + const identifier = wasm.Identifier.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); expect(identifier.base64()).to.equal('CSgo7cCB07oaVPBDJZuUE2jyxxiIGwap00eIOyG/4xM='); }); it('should allow to get identifier hex', () => { - const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + const identifier = wasm.Identifier.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); expect(identifier.hex()).to.equal('092828edc081d3ba1a54f043259b941368f2c718881b06a9d347883b21bfe313'); }); it('should allow to get identifier bytes', () => { - const identifier = wasm.IdentifierWASM.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); + const identifier = wasm.Identifier.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); expect(identifier.bytes()).to.deep.equal(identifierBytes); }); diff --git a/packages/wasm-dpp2/tests/unit/Identity.spec.mjs b/packages/wasm-dpp2/tests/unit/Identity.spec.mjs index cd92b371cb9..f9ac116c43c 100644 --- a/packages/wasm-dpp2/tests/unit/Identity.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/Identity.spec.mjs @@ -15,17 +15,17 @@ before(async () => { describe('Identity', () => { describe('serialization / deserialization', () => { it('should generate identity from identifier', async () => { - const identity = new wasm.IdentityWASM(identifier); + const identity = new wasm.Identity(identifier); expect(identity.__wbg_ptr).to.not.equal(0); }); it('should generate identity from identifier and return bytes', async () => { - const identity = new wasm.IdentityWASM(identifier); + const identity = new wasm.Identity(identifier); expect(Array.from(identity.bytes())).to.deep.equal(identityBytesWithoutKeys); - const newIdentity = wasm.IdentityWASM.fromBytes(identity.bytes()); + const newIdentity = wasm.Identity.fromBytes(identity.bytes()); expect(identity.__wbg_ptr).to.not.equal(0); expect(newIdentity.__wbg_ptr).to.not.equal(0); @@ -34,27 +34,27 @@ describe('Identity', () => { describe('getters', () => { it('should get id buffer', () => { - const identity = new wasm.IdentityWASM(identifier); + const identity = new wasm.Identity(identifier); expect(identity.id.bytes()).to.deep.equal(Uint8Array.from(identifierBytes)); }); it('should get balance', () => { - const identity = new wasm.IdentityWASM(identifier); + const identity = new wasm.Identity(identifier); expect(identity.balance).to.deep.equal(BigInt(0)); }); it('should get revision', () => { - const identity = new wasm.IdentityWASM(identifier); + const identity = new wasm.Identity(identifier); expect(identity.revision).to.deep.equal(BigInt(0)); }); it('should get public keys', () => { - const identity = new wasm.IdentityWASM(identifier); + const identity = new wasm.Identity(identifier); - const pubKey = new wasm.IdentityPublicKeyWASM( + const pubKey = new wasm.IdentityPublicKey( keyId, purpose, securityLevel, @@ -63,7 +63,7 @@ describe('Identity', () => { binaryData, ); - const pubKey2 = new wasm.IdentityPublicKeyWASM( + const pubKey2 = new wasm.IdentityPublicKey( keyId + 1, purpose, securityLevel, @@ -81,7 +81,7 @@ describe('Identity', () => { describe('setters', () => { it('should allows to set public key', () => { - const pubKey = new wasm.IdentityPublicKeyWASM( + const pubKey = new wasm.IdentityPublicKey( keyId, purpose, securityLevel, @@ -90,7 +90,7 @@ describe('Identity', () => { binaryData, ); - const identity = new wasm.IdentityWASM(identifier); + const identity = new wasm.Identity(identifier); identity.addPublicKey(pubKey); @@ -100,7 +100,7 @@ describe('Identity', () => { }); it('should allows to set balance', () => { - const identity = new wasm.IdentityWASM(identifier); + const identity = new wasm.Identity(identifier); identity.balance = balance; @@ -108,7 +108,7 @@ describe('Identity', () => { }); it('should allows to set revision', () => { - const identity = new wasm.IdentityWASM(identifier); + const identity = new wasm.Identity(identifier); identity.revision = revision; diff --git a/packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs index a0051ef9865..9fc4939a36f 100644 --- a/packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs @@ -8,13 +8,13 @@ before(async () => { describe('IdentityCreateTransition', () => { describe('serialization / deserialization', () => { it('should allow to create transition', () => { - const transition = wasm.IdentityCreateTransitionWASM.default(1); + const transition = wasm.IdentityCreateTransition.default(1); expect(transition.__wbg_ptr).to.not.equal(0); }); it('should allow to serialize to bytes', () => { - const transition = wasm.IdentityCreateTransitionWASM.default(1); + const transition = wasm.IdentityCreateTransition.default(1); const bytes = transition.bytes(); @@ -24,7 +24,7 @@ describe('IdentityCreateTransition', () => { it('should allow to deserialize to bytes', () => { const bytes = [0, 0, 0, 162, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 255, 1, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - const transition = wasm.IdentityCreateTransitionWASM.fromBytes(bytes); + const transition = wasm.IdentityCreateTransition.fromBytes(bytes); expect(transition.__wbg_ptr).to.not.equal(0); }); @@ -32,37 +32,37 @@ describe('IdentityCreateTransition', () => { describe('getters', () => { it('should allow to get userFeeIncrease', () => { - const transition = wasm.IdentityCreateTransitionWASM.default(1); + const transition = wasm.IdentityCreateTransition.default(1); expect(transition.userFeeIncrease).to.equal(0); }); it('should allow to get AssetLock', () => { - const transition = wasm.IdentityCreateTransitionWASM.default(1); + const transition = wasm.IdentityCreateTransition.default(1); expect(transition.assetLock.__wbg_ptr).to.not.equal(0); }); it('should allow to get Identifier', () => { - const transition = wasm.IdentityCreateTransitionWASM.default(1); + const transition = wasm.IdentityCreateTransition.default(1); expect(transition.getIdentifier().base58()).to.equal('11111111111111111111111111111111'); }); it('should allow to get PublicKeys', () => { - const transition = wasm.IdentityCreateTransitionWASM.default(1); + const transition = wasm.IdentityCreateTransition.default(1); expect(transition.publicKeys.length).to.equal(0); }); it('should allow to get signature', () => { - const transition = wasm.IdentityCreateTransitionWASM.default(1); + const transition = wasm.IdentityCreateTransition.default(1); expect(transition.signature).to.deep.equal(Uint8Array.from([])); }); it('should allow to get signable bytes', () => { - const transition = wasm.IdentityCreateTransitionWASM.default(1); + const transition = wasm.IdentityCreateTransition.default(1); expect(transition.getSignableBytes().length).to.equal(229); }); @@ -70,7 +70,7 @@ describe('IdentityCreateTransition', () => { describe('setters', () => { it('should allow to set the userFeeIncrease', () => { - const transition = wasm.IdentityCreateTransitionWASM.default(1); + const transition = wasm.IdentityCreateTransition.default(1); transition.userFeeIncrease = 100; diff --git a/packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs index 62a928aa2e2..9eefecf8141 100644 --- a/packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/IdentityCreditTransferTransition.spec.mjs @@ -9,16 +9,16 @@ before(async () => { describe('IdentityCreditTransferTransition', () => { describe('serialization / deserialization', () => { it('Should create IdentityCreditTransferTransition with empty platform version', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); expect(transition.__wbg_ptr).to.not.equal(0); }); it('Should create IdentityCreditTransferTransition with non empty platform version', async () => { - const sender = new wasm.IdentifierWASM('11111111111111111111111111111111'); - const recipient = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const sender = new wasm.Identifier('11111111111111111111111111111111'); + const recipient = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), sender, recipient, BigInt(199), 'platform_v1'); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), sender, recipient, BigInt(199), 'platform_v1'); expect(transition.__wbg_ptr).to.not.equal(0); expect(sender.__wbg_ptr).to.not.equal(0); @@ -28,43 +28,43 @@ describe('IdentityCreditTransferTransition', () => { describe('getters', () => { it('Should return recipientId', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); expect(transition.recipientId.base58()).to.deep.equal('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); }); it('Should return senderId', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); expect(transition.senderId.base58()).to.deep.equal('11111111111111111111111111111111'); }); it('Should return amount', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); expect(transition.amount).to.deep.equal(BigInt(100)); }); it('Should return nonce', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); expect(transition.nonce).to.deep.equal(BigInt(199)); }); it('Should return signature', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); expect(transition.signature).to.deep.equal(Uint8Array.from([])); }); it('Should return signaturePublicKeyId', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); expect(transition.signaturePublicKeyId).to.deep.equal(0); }); it('Should return userFeeIncrease', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); expect(transition.userFeeIncrease).to.deep.equal(0); }); @@ -72,9 +72,9 @@ describe('IdentityCreditTransferTransition', () => { describe('setters', () => { it('Should allow to set recipientId', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); - const recipient = new wasm.IdentifierWASM('11111111111111111111111111111111'); + const recipient = new wasm.Identifier('11111111111111111111111111111111'); transition.recipientId = recipient; @@ -87,9 +87,9 @@ describe('IdentityCreditTransferTransition', () => { }); it('Should return senderId', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); - const sender = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const sender = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); transition.senderId = sender; @@ -102,7 +102,7 @@ describe('IdentityCreditTransferTransition', () => { }); it('Should return amount', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); transition.amount = BigInt(199); @@ -110,7 +110,7 @@ describe('IdentityCreditTransferTransition', () => { }); it('Should return nonce', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); transition.nonce = BigInt(1); @@ -118,7 +118,7 @@ describe('IdentityCreditTransferTransition', () => { }); it('Should return signature', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); transition.signature = [1, 1]; @@ -126,7 +126,7 @@ describe('IdentityCreditTransferTransition', () => { }); it('Should return signaturePublicKeyId', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); transition.signaturePublicKeyId = 11; @@ -134,7 +134,7 @@ describe('IdentityCreditTransferTransition', () => { }); it('Should return userFeeIncrease', async () => { - const transition = new wasm.IdentityCreditTransferWASM(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); + const transition = new wasm.IdentityCreditTransfer(BigInt(100), '11111111111111111111111111111111', 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', BigInt(199)); transition.userFeeIncrease = 11; diff --git a/packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs index 6ccaf16721e..b8c4a396a56 100644 --- a/packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/IdentityCreditWithdrawalTransition.spec.mjs @@ -9,10 +9,10 @@ before(async () => { describe('IdentityCreditWithdrawalTransition', () => { describe('serialization / deserialization', () => { it('Should allow to create IdentityCreditWithdrawalTransition', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); expect(identifier.__wbg_ptr).to.not.equal(0); expect(script.__wbg_ptr).to.not.equal(0); @@ -22,73 +22,73 @@ describe('IdentityCreditWithdrawalTransition', () => { describe('getters', () => { it('Should allow to get outputScript', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); expect(transition.outputScript.toString()).to.deep.equal('dqkUAQEBAQEBAQEBAQEBAQEBAQEBAQGIrA=='); }); it('Should allow to get pooling', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); expect(transition.pooling).to.deep.equal('Never'); }); it('Should allow to get identityId', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); expect(transition.identityId.base58()).to.deep.equal(identifier.base58()); }); it('Should allow to get userFeeIncrease', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); expect(transition.userFeeIncrease).to.deep.equal(1); }); it('Should allow to get nonce', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); expect(transition.nonce).to.deep.equal(BigInt(1)); }); it('Should allow to get amount', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); expect(transition.amount).to.deep.equal(BigInt(111)); }); it('Should allow to get signature', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); expect(transition.signature).to.deep.equal(Uint8Array.from([])); }); it('Should allow to get signaturePublicKeyId', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); expect(transition.signaturePublicKeyId).to.deep.equal(0); }); @@ -96,12 +96,12 @@ describe('IdentityCreditWithdrawalTransition', () => { describe('setters', () => { it('Should allow to set outputScript', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); - const script2 = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const script2 = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); transition.outputScript = script2; @@ -109,10 +109,10 @@ describe('IdentityCreditWithdrawalTransition', () => { }); it('Should allow to set pooling', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); transition.pooling = 'Standard'; @@ -120,12 +120,12 @@ describe('IdentityCreditWithdrawalTransition', () => { }); it('Should allow to set identityId', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); - const identifier2 = new wasm.IdentifierWASM('11SAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const identifier2 = new wasm.Identifier('11SAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); transition.identityId = identifier2; @@ -133,10 +133,10 @@ describe('IdentityCreditWithdrawalTransition', () => { }); it('Should allow to set userFeeIncrease', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); transition.userFeeIncrease = 999; @@ -144,10 +144,10 @@ describe('IdentityCreditWithdrawalTransition', () => { }); it('Should allow to set nonce', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); transition.nonce = BigInt(1111); @@ -155,10 +155,10 @@ describe('IdentityCreditWithdrawalTransition', () => { }); it('Should allow to get amount', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); transition.amount = BigInt(2222); @@ -166,10 +166,10 @@ describe('IdentityCreditWithdrawalTransition', () => { }); it('Should allow to get signature', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); transition.signature = Uint8Array.from([1, 2, 3]); @@ -177,10 +177,10 @@ describe('IdentityCreditWithdrawalTransition', () => { }); it('Should allow to get signaturePublicKeyId', () => { - const identifier = new wasm.IdentifierWASM('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); - const script = wasm.CoreScriptWASM.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const identifier = new wasm.Identifier('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec'); + const script = wasm.CoreScript.newP2PKH([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - const transition = new wasm.IdentityCreditWithdrawalTransitionWASM(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); + const transition = new wasm.IdentityCreditWithdrawalTransition(identifier, BigInt(111), 1, 'never', script, BigInt(1), 1); transition.signaturePublicKeyId = 11; diff --git a/packages/wasm-dpp2/tests/unit/IdentityPublicKey.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityPublicKey.spec.mjs index 5301ceea854..34af1521c7c 100644 --- a/packages/wasm-dpp2/tests/unit/IdentityPublicKey.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/IdentityPublicKey.spec.mjs @@ -14,7 +14,7 @@ before(async () => { describe('PublicKey', () => { describe('serialization / deserialization', () => { it('should generate public key from values with type ECDSA_SECP256K1', () => { - const pubKey = new wasm.IdentityPublicKeyWASM( + const pubKey = new wasm.IdentityPublicKey( keyId, purpose, securityLevel, @@ -27,7 +27,7 @@ describe('PublicKey', () => { }); it('should generate public key from values with type ECDSA_SECP256K1 and generate new from self bytes', () => { - const pubKey = new wasm.IdentityPublicKeyWASM( + const pubKey = new wasm.IdentityPublicKey( keyId, purpose, securityLevel, @@ -38,7 +38,7 @@ describe('PublicKey', () => { const bytes = pubKey.bytes(); - const newPubKey = wasm.IdentityPublicKeyWASM.fromBytes(Array.from(bytes)); + const newPubKey = wasm.IdentityPublicKey.fromBytes(Array.from(bytes)); expect(pubKey.__wbg_ptr).to.not.equal(0); expect(newPubKey.__wbg_ptr).to.not.equal(0); @@ -57,7 +57,7 @@ describe('PublicKey', () => { }); it('should return hash of key', () => { - const pubKey = new wasm.IdentityPublicKeyWASM( + const pubKey = new wasm.IdentityPublicKey( keyId, purpose, securityLevel, @@ -73,7 +73,7 @@ describe('PublicKey', () => { }); describe('getters', () => { it('should generate public key from values with type ECDSA_SECP256K1 and return all fields', () => { - const pubKey = new wasm.IdentityPublicKeyWASM( + const pubKey = new wasm.IdentityPublicKey( keyId, purpose, securityLevel, @@ -91,7 +91,7 @@ describe('PublicKey', () => { }); it('should allow to validate private key', () => { - const pubKey = new wasm.IdentityPublicKeyWASM( + const pubKey = new wasm.IdentityPublicKey( keyId, purpose, securityLevel, @@ -100,15 +100,15 @@ describe('PublicKey', () => { binaryData, ); - const privateKey = wasm.PrivateKeyWASM.fromWIF(wif); + const privateKey = wasm.PrivateKey.fromWIF(wif); - expect(pubKey.validatePrivateKey(privateKey.bytes(), wasm.NetworkWASM.Mainnet)).to.equal(false); + expect(pubKey.validatePrivateKey(privateKey.bytes(), wasm.Network.Mainnet)).to.equal(false); }); }); describe('setters', () => { it('should generate public key from values with type ECDSA_SECP256K1 and return all fields and set another fields', () => { - const pubKey = new wasm.IdentityPublicKeyWASM( + const pubKey = new wasm.IdentityPublicKey( keyId, purpose, securityLevel, diff --git a/packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs index 55b9cd46e84..257247b80d0 100644 --- a/packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/IdentityTopUpTransition.spec.mjs @@ -9,7 +9,7 @@ before(async () => { describe('IdentityTopUpTransition', () => { describe('serialization / deserialization', () => { it('should allow to create IdentityTopUpTransition', () => { - const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + const assetLockProof = wasm.AssetLockProof.createInstantAssetLockProof( // instant lock [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], // transaction @@ -18,7 +18,7 @@ describe('IdentityTopUpTransition', () => { 0, ); - const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + const transition = new wasm.IdentityTopUpTransition(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); expect(transition.__wbg_ptr).to.not.equal(0); expect(assetLockProof.__wbg_ptr).to.not.equal(0); @@ -27,7 +27,7 @@ describe('IdentityTopUpTransition', () => { describe('getters', () => { it('should allow to return userFeeIncrease', () => { - const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + const assetLockProof = wasm.AssetLockProof.createInstantAssetLockProof( // instant lock [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], // transaction @@ -36,13 +36,13 @@ describe('IdentityTopUpTransition', () => { 0, ); - const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + const transition = new wasm.IdentityTopUpTransition(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); expect(transition.userFeeIncrease).to.deep.equal(11); }); it('should allow to return identityIdentifier', () => { - const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + const assetLockProof = wasm.AssetLockProof.createInstantAssetLockProof( // instant lock [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], // transaction @@ -51,13 +51,13 @@ describe('IdentityTopUpTransition', () => { 0, ); - const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + const transition = new wasm.IdentityTopUpTransition(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); expect(transition.identityIdentifier.base58()).to.deep.equal('B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'); }); it('should allow to return signature', () => { - const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + const assetLockProof = wasm.AssetLockProof.createInstantAssetLockProof( // instant lock [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], // transaction @@ -66,7 +66,7 @@ describe('IdentityTopUpTransition', () => { 0, ); - const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + const transition = new wasm.IdentityTopUpTransition(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); expect(transition.signature).to.deep.equal(Uint8Array.from([])); }); @@ -74,7 +74,7 @@ describe('IdentityTopUpTransition', () => { describe('setters', () => { it('should allow to set userFeeIncrease', () => { - const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + const assetLockProof = wasm.AssetLockProof.createInstantAssetLockProof( // instant lock [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], // transaction @@ -83,7 +83,7 @@ describe('IdentityTopUpTransition', () => { 0, ); - const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + const transition = new wasm.IdentityTopUpTransition(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); transition.userFeeIncrease = 21; @@ -91,7 +91,7 @@ describe('IdentityTopUpTransition', () => { }); it('should allow to set identityIdentifier', () => { - const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + const assetLockProof = wasm.AssetLockProof.createInstantAssetLockProof( // instant lock [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], // transaction @@ -100,9 +100,9 @@ describe('IdentityTopUpTransition', () => { 0, ); - const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + const transition = new wasm.IdentityTopUpTransition(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); - const identifier = new wasm.IdentifierWASM('777cE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'); + const identifier = new wasm.Identifier('777cE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH'); transition.identityIdentifier = identifier; @@ -110,7 +110,7 @@ describe('IdentityTopUpTransition', () => { }); it('should allow to set signature', () => { - const assetLockProof = wasm.AssetLockProofWASM.createInstantAssetLockProof( + const assetLockProof = wasm.AssetLockProof.createInstantAssetLockProof( // instant lock [1, 1, 193, 219, 244, 102, 77, 20, 251, 187, 201, 109, 168, 125, 7, 244, 118, 119, 210, 53, 238, 105, 138, 31, 7, 73, 30, 128, 131, 175, 114, 76, 187, 37, 0, 0, 0, 0, 177, 215, 65, 96, 204, 228, 86, 13, 14, 185, 46, 65, 241, 38, 226, 172, 59, 96, 158, 15, 126, 90, 225, 3, 140, 221, 96, 131, 254, 12, 236, 26, 48, 124, 31, 23, 184, 202, 122, 231, 123, 59, 43, 118, 27, 214, 225, 58, 44, 191, 232, 10, 33, 35, 8, 113, 145, 159, 158, 88, 80, 0, 0, 0, 173, 103, 128, 160, 29, 226, 161, 219, 167, 194, 158, 38, 19, 51, 143, 248, 161, 87, 126, 32, 143, 209, 152, 44, 174, 6, 25, 210, 101, 127, 131, 65, 202, 241, 47, 166, 132, 10, 199, 15, 187, 136, 11, 217, 237, 13, 173, 64, 11, 6, 112, 188, 234, 239, 204, 29, 3, 6, 35, 154, 44, 106, 44, 183, 171, 126, 146, 240, 153, 210, 187, 56, 133, 161, 11, 4, 151, 63, 89, 20, 44, 66, 153, 242, 97, 207, 44, 110, 208, 51, 198, 113, 104, 79, 154, 19], // transaction @@ -119,7 +119,7 @@ describe('IdentityTopUpTransition', () => { 0, ); - const transition = new wasm.IdentityTopUpTransitionWASM(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); + const transition = new wasm.IdentityTopUpTransition(assetLockProof, 'B7kcE1juMBWEWkuYRJhVdAE2e6RaevrGxRsa1DrLCpQH', 11); transition.signature = Uint8Array.from([1, 1, 1]); diff --git a/packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs index 14d68c7320a..87820e350fe 100644 --- a/packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/IdentityUpdateTransition.spec.mjs @@ -9,15 +9,15 @@ before(async () => { describe('IdentityUpdateTransition', () => { describe('serialization / deserialization', () => { it('Should create IdentityUpdateTransition', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], []); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], []); expect(transition.__wbg_ptr).to.not.equal(0); }); it('Should create IdentityUpdateTransition with key', () => { - const key = new wasm.IdentityPublicKeyInCreationWASM(1, 'system', 'master', 'ECDSA_SECP256K1', false, [], []); + const key = new wasm.IdentityPublicKeyInCreation(1, 'system', 'master', 'ECDSA_SECP256K1', false, [], []); - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [key], []); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [key], []); expect(transition.__wbg_ptr).to.not.equal(0); expect(key.__wbg_ptr).to.not.equal(0); @@ -26,51 +26,51 @@ describe('IdentityUpdateTransition', () => { describe('getters', () => { it('Should return revision', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], []); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], []); expect(transition.revision).to.deep.equal(BigInt(1)); }); it('Should return nonce', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], []); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], []); expect(transition.nonce).to.deep.equal(BigInt(1)); }); it('Should return identityIdentifier', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], []); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), 1, [], []); expect(transition.identityIdentifier.base58()).to.deep.equal('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3'); }); it('Should return publicKeyIdsToDisable', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); expect(Array.from(transition.publicKeyIdsToDisable)).to.deep.equal([11]); }); it('Should return publicKeyIdsToAdd', () => { - const key = new wasm.IdentityPublicKeyInCreationWASM(1, 'system', 'master', 'ECDSA_SECP256K1', false, [], []); + const key = new wasm.IdentityPublicKeyInCreation(1, 'system', 'master', 'ECDSA_SECP256K1', false, [], []); - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [key], [11]); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [key], [11]); expect(transition.publicKeyIdsToAdd.length).to.deep.equal(1); }); it('Should return userFeeIncrease', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11], 1); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11], 1); expect(transition.userFeeIncrease).to.deep.equal(1); }); it('Should return signature', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11], 1); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11], 1); expect(transition.signature).to.deep.equal(Uint8Array.from([])); }); it('Should return signature public key id', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); expect(transition.signaturePublicKeyId).to.deep.equal(0); }); @@ -78,7 +78,7 @@ describe('IdentityUpdateTransition', () => { describe('setters', () => { it('Should allow to set identityIdentifier', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); transition.identityIdentifier = '11Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3'; @@ -86,7 +86,7 @@ describe('IdentityUpdateTransition', () => { }); it('Should allow to set revision', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); transition.revision = BigInt(11111); @@ -94,7 +94,7 @@ describe('IdentityUpdateTransition', () => { }); it('Should allow to set nonce', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); transition.nonce = BigInt(11111); @@ -102,7 +102,7 @@ describe('IdentityUpdateTransition', () => { }); it('Should allow to set publicKeyIdsToDisable', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); transition.publicKeyIdsToDisable = [1, 2, 3, 4]; @@ -110,9 +110,9 @@ describe('IdentityUpdateTransition', () => { }); it('Should allow to set publicKeyIdsToAdd', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); - const key = new wasm.IdentityPublicKeyInCreationWASM(1, 'system', 'master', 'ECDSA_SECP256K1', false, [], []); + const key = new wasm.IdentityPublicKeyInCreation(1, 'system', 'master', 'ECDSA_SECP256K1', false, [], []); transition.publicKeyIdsToAdd = [key, key]; @@ -121,7 +121,7 @@ describe('IdentityUpdateTransition', () => { }); it('Should allow to set signature', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); transition.signature = [0, 1, 2, 3, 5]; @@ -129,7 +129,7 @@ describe('IdentityUpdateTransition', () => { }); it('Should allow to set signature public key id', () => { - const transition = new wasm.IdentityUpdateTransitionWASM('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); + const transition = new wasm.IdentityUpdateTransition('GL2Rq8L3VuBEQfCAZykmUaiXXrsd1Bwub2gcaMmtNbn3', BigInt(1), BigInt(1), [], [11]); transition.signaturePublicKeyId = 11; diff --git a/packages/wasm-dpp2/tests/unit/InstantLockProof.spec.mjs b/packages/wasm-dpp2/tests/unit/InstantLockProof.spec.mjs index 7486a2d758c..df6c3ce7a5b 100644 --- a/packages/wasm-dpp2/tests/unit/InstantLockProof.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/InstantLockProof.spec.mjs @@ -10,13 +10,13 @@ before(async () => { describe('InstantLock', () => { describe('serialization / deserialization', () => { it('should allow to create InstantLock from values', () => { - const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + const instantLockProof = new wasm.InstantAssetLockProof(instantLockBytes, transactionBytes, 0); expect(instantLockProof.__wbg_ptr).to.not.equal(0); }); it('should allow to convert to object', () => { - const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + const instantLockProof = new wasm.InstantAssetLockProof(instantLockBytes, transactionBytes, 0); const expected = { instantLock: instantLockBytes, @@ -34,7 +34,7 @@ describe('InstantLock', () => { outputIndex: 0, }; - const instantLockProof = wasm.InstantAssetLockProofWASM.fromObject(lockObject); + const instantLockProof = wasm.InstantAssetLockProof.fromObject(lockObject); expect(instantLockProof.__wbg_ptr).to.not.equal(0); }); @@ -42,33 +42,33 @@ describe('InstantLock', () => { describe('getters', () => { it('should allow to get output', () => { - const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + const instantLockProof = new wasm.InstantAssetLockProof(instantLockBytes, transactionBytes, 0); - expect(instantLockProof.getOutput().constructor.name).to.deep.equal('TxOutWASM'); + expect(instantLockProof.getOutput().constructor.name).to.deep.equal('TxOut'); }); it('should allow to convert to get OutPoint', () => { - const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + const instantLockProof = new wasm.InstantAssetLockProof(instantLockBytes, transactionBytes, 0); - expect(instantLockProof.getOutPoint().constructor.name).to.deep.equal('OutPointWASM'); + expect(instantLockProof.getOutPoint().constructor.name).to.deep.equal('OutPoint'); }); it('should allow to get output index', () => { - const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + const instantLockProof = new wasm.InstantAssetLockProof(instantLockBytes, transactionBytes, 0); expect(instantLockProof.outputIndex).to.deep.equal(0); }); it('should allow to get instant lock', () => { - const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + const instantLockProof = new wasm.InstantAssetLockProof(instantLockBytes, transactionBytes, 0); - expect(instantLockProof.instantLock.constructor.name).to.deep.equal('InstantLockWASM'); + expect(instantLockProof.instantLock.constructor.name).to.deep.equal('InstantLock'); }); }); describe('setters', () => { it('should allow to set output index', () => { - const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + const instantLockProof = new wasm.InstantAssetLockProof(instantLockBytes, transactionBytes, 0); instantLockProof.outputIndex = 12; @@ -76,9 +76,9 @@ describe('InstantLock', () => { }); it('should allow to set instant lock', () => { - const instantLockProof = new wasm.InstantAssetLockProofWASM(instantLockBytes, transactionBytes, 0); + const instantLockProof = new wasm.InstantAssetLockProof(instantLockBytes, transactionBytes, 0); - const newInstantLockProof = new wasm.InstantLockWASM( + const newInstantLockProof = new wasm.InstantLock( 0, [], 'dbdb604952d08184b55d48c915ed78aadc81dbc5cc98e8b4821abe5b4bbcbecb', diff --git a/packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs b/packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs index 76732373160..ae5ba80064c 100644 --- a/packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs @@ -9,7 +9,7 @@ before(async () => { describe('OutPoint', () => { describe('serialization / deserialization', () => { it('should allow to create from values', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); expect(outpoint.__wbg_ptr).to.not.equal(0); }); @@ -20,7 +20,7 @@ describe('OutPoint', () => { // 32 bytes for txId and 4 bytes for vout const bytes = [...txIdBytes.reverse(), ...[0, 0, 0, 1].reverse()]; - const outpoint = wasm.OutPointWASM.fromBytes(bytes); + const outpoint = wasm.OutPoint.fromBytes(bytes); expect(outpoint.__wbg_ptr).to.not.equal(0); }); @@ -28,19 +28,19 @@ describe('OutPoint', () => { describe('getters', () => { it('should allow to get txid', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); expect(outpoint.getTXID()).to.equal('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d'); }); it('should allow to get VOUT', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); expect(outpoint.getVOUT()).to.equal(1); }); it('should allow to get bytes', () => { - const outpoint = new wasm.OutPointWASM('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); + const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); const txIdBytes = Buffer.from('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 'hex'); diff --git a/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs b/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs index 590d1e5a27a..19b48a3de5a 100644 --- a/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs @@ -11,33 +11,33 @@ before(async () => { describe('PrivateKey', () => { describe('serialization / deserialization', () => { it('should allows to create PrivateKey from wif', () => { - const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + const pkey = wasm.PrivateKey.fromWIF(wif); expect(pkey.__wbg_ptr).to.not.equal(0); }); it('should allows to create PrivateKey from bytes', () => { - const pkey = wasm.PrivateKeyWASM.fromBytes(fromHexString(bytes), 'Mainnet'); + const pkey = wasm.PrivateKey.fromBytes(fromHexString(bytes), 'Mainnet'); expect(pkey.__wbg_ptr).to.not.equal(0); }); it('should allows to create PrivateKey from hex', () => { - const pkey = wasm.PrivateKeyWASM.fromBytes(fromHexString(bytes), 'Mainnet'); + const pkey = wasm.PrivateKey.fromBytes(fromHexString(bytes), 'Mainnet'); - const pkeyFromHex = wasm.PrivateKeyWASM.fromHex(bytes, 'Mainnet'); + const pkeyFromHex = wasm.PrivateKey.fromHex(bytes, 'Mainnet'); expect(pkey.bytes()).to.deep.equal(pkeyFromHex.bytes()); }); it('should allow to create PrivateKey from wif and read value in wif', () => { - const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + const pkey = wasm.PrivateKey.fromWIF(wif); expect(pkey.WIF()).to.equal(wif); }); it('should allow to create PrivateKey from wif and write value in bytes', () => { - const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + const pkey = wasm.PrivateKey.fromWIF(wif); expect(pkey.bytes()).to.deep.equal(fromHexString(bytes)); }); @@ -45,25 +45,25 @@ describe('PrivateKey', () => { describe('getters', () => { it('should allow to get key wif', () => { - const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + const pkey = wasm.PrivateKey.fromWIF(wif); expect(pkey.WIF()).to.equal(wif); }); it('should allow to get key bytes', () => { - const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + const pkey = wasm.PrivateKey.fromWIF(wif); expect(toHexString(pkey.bytes())).to.equal(bytes); }); it('should allow to get key hex', () => { - const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + const pkey = wasm.PrivateKey.fromWIF(wif); expect(pkey.hex().toLowerCase()).to.equal(bytes); }); it('should allow to get public key hash', () => { - const pkey = wasm.PrivateKeyWASM.fromWIF(wif); + const pkey = wasm.PrivateKey.fromWIF(wif); expect(pkey.getPublicKeyHash()).to.deep.equal(publicKeyHash); }); diff --git a/packages/wasm-dpp2/tests/unit/PublicKeyInCreation.spec.mjs b/packages/wasm-dpp2/tests/unit/PublicKeyInCreation.spec.mjs index b2de85073fd..f74f87a7bc2 100644 --- a/packages/wasm-dpp2/tests/unit/PublicKeyInCreation.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/PublicKeyInCreation.spec.mjs @@ -9,7 +9,7 @@ before(async () => { describe('InstantLock', () => { describe('serialization / deserialization', () => { it('should allow to create from values', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -23,7 +23,7 @@ describe('InstantLock', () => { }); it('should allow to create from values and convert to identity public key', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -36,13 +36,13 @@ describe('InstantLock', () => { const publicKey = publicKeyInCreation.toIdentityPublicKey(); expect(publicKeyInCreation.__wbg_ptr).to.not.equal(0); - expect(publicKey.constructor.name).to.equal('IdentityPublicKeyWASM'); + expect(publicKey.constructor.name).to.equal('IdentityPublicKey'); }); }); describe('getters', () => { it('should allow to get key id', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -56,7 +56,7 @@ describe('InstantLock', () => { }); it('should allow to get purpose', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -70,7 +70,7 @@ describe('InstantLock', () => { }); it('should allow to get security level', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -84,7 +84,7 @@ describe('InstantLock', () => { }); it('should allow to get key type', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -98,7 +98,7 @@ describe('InstantLock', () => { }); it('should allow to get read only', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -112,7 +112,7 @@ describe('InstantLock', () => { }); it('should allow to get data', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -126,7 +126,7 @@ describe('InstantLock', () => { }); it('should allow to get signature', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -142,7 +142,7 @@ describe('InstantLock', () => { describe('setters', () => { it('should allow to set key id', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -158,7 +158,7 @@ describe('InstantLock', () => { }); it('should allow to set purpose', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -174,7 +174,7 @@ describe('InstantLock', () => { }); it('should allow to set security level', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -190,7 +190,7 @@ describe('InstantLock', () => { }); it('should allow to set key type', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -206,7 +206,7 @@ describe('InstantLock', () => { }); it('should allow to set read only', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -222,7 +222,7 @@ describe('InstantLock', () => { }); it('should allow to set data', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', @@ -238,7 +238,7 @@ describe('InstantLock', () => { }); it('should allow to set signature', () => { - const publicKeyInCreation = new wasm.IdentityPublicKeyInCreationWASM( + const publicKeyInCreation = new wasm.IdentityPublicKeyInCreation( 0, 'AUTHENTICATION', 'master', diff --git a/packages/wasm-dpp2/tests/unit/RewardDistributionType.spec.mjs b/packages/wasm-dpp2/tests/unit/RewardDistributionType.spec.mjs index c7b93934b7b..c3882b245d3 100644 --- a/packages/wasm-dpp2/tests/unit/RewardDistributionType.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/RewardDistributionType.spec.mjs @@ -9,11 +9,11 @@ before(async () => { describe('RewardDistributionType', () => { describe('serialization / deserialization', () => { it('shoulda allow to create BlockBasedDistribution', () => { - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + const distributionType = wasm.RewardDistributionType.BlockBasedDistribution( BigInt(111), distributionFunction, ); @@ -23,11 +23,11 @@ describe('RewardDistributionType', () => { }); it('shoulda allow to create TimeBasedDistribution', () => { - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.TimeBasedDistribution( + const distributionType = wasm.RewardDistributionType.TimeBasedDistribution( BigInt(111), distributionFunction, ); @@ -37,11 +37,11 @@ describe('RewardDistributionType', () => { }); it('shoulda allow to create EpochBasedDistribution', () => { - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.EpochBasedDistribution( + const distributionType = wasm.RewardDistributionType.EpochBasedDistribution( 111, distributionFunction, ); @@ -53,42 +53,42 @@ describe('RewardDistributionType', () => { describe('getters', () => { it('shoulda allow return value BlockBasedDistribution', () => { - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + const distributionType = wasm.RewardDistributionType.BlockBasedDistribution( BigInt(111), distributionFunction, ); - expect(distributionType.getDistribution().constructor.name).to.equal('BlockBasedDistributionWASM'); + expect(distributionType.getDistribution().constructor.name).to.equal('BlockBasedDistribution'); }); it('shoulda allow return value TimeBasedDistribution', () => { - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.TimeBasedDistribution( + const distributionType = wasm.RewardDistributionType.TimeBasedDistribution( BigInt(111), distributionFunction, ); - expect(distributionType.getDistribution().constructor.name).to.equal('TimeBasedDistributionWASM'); + expect(distributionType.getDistribution().constructor.name).to.equal('TimeBasedDistribution'); }); it('shoulda allow return value EpochBasedDistribution', () => { - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.EpochBasedDistribution( + const distributionType = wasm.RewardDistributionType.EpochBasedDistribution( 111, distributionFunction, ); - expect(distributionType.getDistribution().constructor.name).to.equal('EpochBasedDistributionWASM'); + expect(distributionType.getDistribution().constructor.name).to.equal('EpochBasedDistribution'); }); }); }); diff --git a/packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs index c40c02b5f68..bbc9bee7c22 100644 --- a/packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/TokenBaseTransition.spec.mjs @@ -10,7 +10,7 @@ before(async () => { describe('TokenBaseTransition', function () { describe('serialization / deserialization', function () { it('should allow to create from values', () => { - const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + const baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId) expect(baseTransition.__wbg_ptr).to.not.equal(0) }) @@ -18,42 +18,42 @@ describe('TokenBaseTransition', function () { describe('getters', function () { it('should allow to get identityContractNonce', () => { - const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + const baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId) expect(baseTransition.identityContractNonce).to.deep.equal(1n) }) it('should allow to get tokenContractPosition', () => { - const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + const baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId) expect(baseTransition.tokenContractPosition).to.deep.equal(1) }) it('should allow to get dataContractId', () => { - const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + const baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId) expect(baseTransition.dataContractId.base58()).to.deep.equal(dataContractId) }) it('should allow to get tokenId', () => { - const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + const baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId) expect(baseTransition.tokenId.base58()).to.deep.equal(ownerId) }) it('should allow to get usingGroupInfo', () => { - const groupStInfo = new wasm.GroupStateTransitionInfoWASM(2, dataContractId, false) + const groupStInfo = new wasm.GroupStateTransitionInfo(2, dataContractId, false) - const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId, groupStInfo) + const baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId, groupStInfo) expect(groupStInfo.__wbg_ptr).to.not.equal(0) - expect(baseTransition.usingGroupInfo.constructor.name).to.deep.equal('GroupStateTransitionInfoWASM') + expect(baseTransition.usingGroupInfo.constructor.name).to.deep.equal('GroupStateTransitionInfo') }) }) describe('setters', function () { it('should allow to set identityContractNonce', () => { - const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + const baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId) baseTransition.identityContractNonce = 3n @@ -61,7 +61,7 @@ describe('TokenBaseTransition', function () { }) it('should allow to set tokenContractPosition', () => { - const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + const baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId) baseTransition.tokenContractPosition = 3 @@ -69,7 +69,7 @@ describe('TokenBaseTransition', function () { }) it('should allow to set dataContractId', () => { - const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + const baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId) baseTransition.dataContractId = ownerId @@ -77,7 +77,7 @@ describe('TokenBaseTransition', function () { }) it('should allow to set tokenId', () => { - const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + const baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId) baseTransition.tokenId = dataContractId @@ -85,16 +85,16 @@ describe('TokenBaseTransition', function () { }) it('should allow to set usingGroupInfo', () => { - const groupStInfo = new wasm.GroupStateTransitionInfoWASM(2, dataContractId, false) + const groupStInfo = new wasm.GroupStateTransitionInfo(2, dataContractId, false) - const baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId) + const baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId) expect(baseTransition.usingGroupInfo).to.deep.equal(undefined) baseTransition.usingGroupInfo = groupStInfo expect(groupStInfo.__wbg_ptr).to.not.equal(0) - expect(baseTransition.usingGroupInfo.constructor.name).to.deep.equal('GroupStateTransitionInfoWASM') + expect(baseTransition.usingGroupInfo.constructor.name).to.deep.equal('GroupStateTransitionInfo') }) }) }) diff --git a/packages/wasm-dpp2/tests/unit/TokenConfiguration.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenConfiguration.spec.mjs index af4d7d31385..0375a69ec1c 100644 --- a/packages/wasm-dpp2/tests/unit/TokenConfiguration.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/TokenConfiguration.spec.mjs @@ -9,7 +9,7 @@ before(async () => { describe('TokenConfiguration', () => { describe('serialization / deserialization', () => { it('Should allow to create from values', () => { - const convention = new wasm.TokenConfigurationConventionWASM( + const convention = new wasm.TokenConfigurationConvention( { ru: { shouldCapitalize: true, @@ -20,9 +20,9 @@ describe('TokenConfiguration', () => { 1, ); - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -30,7 +30,7 @@ describe('TokenConfiguration', () => { true, ); - const keepHistory = new wasm.TokenKeepsHistoryRulesWASM( + const keepHistory = new wasm.TokenKeepsHistoryRules( true, true, true, @@ -39,7 +39,7 @@ describe('TokenConfiguration', () => { true, ); - const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistribution( { 1750140416485: { PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10000), @@ -47,7 +47,7 @@ describe('TokenConfiguration', () => { }, ); - const distributionRules = new wasm.TokenDistributionRulesWASM( + const distributionRules = new wasm.TokenDistributionRules( undefined, changeRules, preProgrammedDistribution, @@ -58,14 +58,14 @@ describe('TokenConfiguration', () => { changeRules, ); - const tradeMode = wasm.TokenTradeModeWASM.NotTradeable(); + const tradeMode = wasm.TokenTradeMode.NotTradeable(); - const marketplaceRules = new wasm.TokenMarketplaceRulesWASM( + const marketplaceRules = new wasm.TokenMarketplaceRules( tradeMode, changeRules, ); - const config = new wasm.TokenConfigurationWASM( + const config = new wasm.TokenConfiguration( convention, changeRules, BigInt(999999999), @@ -93,7 +93,7 @@ describe('TokenConfiguration', () => { describe('getters', () => { it('should allow to get getters', () => { - const convention = new wasm.TokenConfigurationConventionWASM( + const convention = new wasm.TokenConfigurationConvention( { ru: { shouldCapitalize: true, @@ -104,9 +104,9 @@ describe('TokenConfiguration', () => { 1, ); - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -114,7 +114,7 @@ describe('TokenConfiguration', () => { true, ); - const keepHistory = new wasm.TokenKeepsHistoryRulesWASM( + const keepHistory = new wasm.TokenKeepsHistoryRules( true, true, true, @@ -123,7 +123,7 @@ describe('TokenConfiguration', () => { true, ); - const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistribution( { 1750140416485: { PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10000), @@ -131,7 +131,7 @@ describe('TokenConfiguration', () => { }, ); - const distributionRules = new wasm.TokenDistributionRulesWASM( + const distributionRules = new wasm.TokenDistributionRules( undefined, changeRules, preProgrammedDistribution, @@ -142,14 +142,14 @@ describe('TokenConfiguration', () => { changeRules, ); - const tradeMode = wasm.TokenTradeModeWASM.NotTradeable(); + const tradeMode = wasm.TokenTradeMode.NotTradeable(); - const marketplaceRules = new wasm.TokenMarketplaceRulesWASM( + const marketplaceRules = new wasm.TokenMarketplaceRules( tradeMode, changeRules, ); - const config = new wasm.TokenConfigurationWASM( + const config = new wasm.TokenConfiguration( convention, changeRules, BigInt(999999999), @@ -171,22 +171,22 @@ describe('TokenConfiguration', () => { 'note', ); - expect(config.conventions.constructor.name).to.equal('TokenConfigurationConventionWASM'); - expect(config.conventionsChangeRules.constructor.name).to.equal('ChangeControlRulesWASM'); + expect(config.conventions.constructor.name).to.equal('TokenConfigurationConvention'); + expect(config.conventionsChangeRules.constructor.name).to.equal('ChangeControlRules'); expect(config.baseSupply.constructor.name).to.equal('BigInt'); - expect(config.keepsHistory.constructor.name).to.equal('TokenKeepsHistoryRulesWASM'); + expect(config.keepsHistory.constructor.name).to.equal('TokenKeepsHistoryRules'); expect(config.startAsPaused.constructor.name).to.equal('Boolean'); expect(config.isAllowedTransferToFrozenBalance.constructor.name).to.equal('Boolean'); expect(config.maxSupply).to.equal(undefined); - expect(config.maxSupplyChangeRules.constructor.name).to.equal('ChangeControlRulesWASM'); - expect(config.distributionRules.constructor.name).to.equal('TokenDistributionRulesWASM'); - expect(config.marketplaceRules.constructor.name).to.equal('TokenMarketplaceRulesWASM'); - expect(config.manualMintingRules.constructor.name).to.equal('ChangeControlRulesWASM'); - expect(config.manualBurningRules.constructor.name).to.equal('ChangeControlRulesWASM'); - expect(config.freezeRules.constructor.name).to.equal('ChangeControlRulesWASM'); - expect(config.unfreezeRules.constructor.name).to.equal('ChangeControlRulesWASM'); - expect(config.destroyFrozenFundsRules.constructor.name).to.equal('ChangeControlRulesWASM'); - expect(config.emergencyActionRules.constructor.name).to.equal('ChangeControlRulesWASM'); + expect(config.maxSupplyChangeRules.constructor.name).to.equal('ChangeControlRules'); + expect(config.distributionRules.constructor.name).to.equal('TokenDistributionRules'); + expect(config.marketplaceRules.constructor.name).to.equal('TokenMarketplaceRules'); + expect(config.manualMintingRules.constructor.name).to.equal('ChangeControlRules'); + expect(config.manualBurningRules.constructor.name).to.equal('ChangeControlRules'); + expect(config.freezeRules.constructor.name).to.equal('ChangeControlRules'); + expect(config.unfreezeRules.constructor.name).to.equal('ChangeControlRules'); + expect(config.destroyFrozenFundsRules.constructor.name).to.equal('ChangeControlRules'); + expect(config.emergencyActionRules.constructor.name).to.equal('ChangeControlRules'); expect(config.mainControlGroup).to.equal(undefined); expect(config.description.constructor.name).to.equal('String'); }); diff --git a/packages/wasm-dpp2/tests/unit/TokenConfigurationConvention.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenConfigurationConvention.spec.mjs index 11305a993cb..a639308ef0a 100644 --- a/packages/wasm-dpp2/tests/unit/TokenConfigurationConvention.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/TokenConfigurationConvention.spec.mjs @@ -10,7 +10,7 @@ before(async () => { describe('TokenConfigurationConvention', () => { describe('serialization / deserialization', () => { it('Should allow to create from object', () => { - const convention = new wasm.TokenConfigurationConventionWASM( + const convention = new wasm.TokenConfigurationConvention( { ru: tokenLocalization, }, @@ -23,7 +23,7 @@ describe('TokenConfigurationConvention', () => { describe('getters', () => { it('Should allow to get object of convention in JSON', () => { - const convention = new wasm.TokenConfigurationConventionWASM( + const convention = new wasm.TokenConfigurationConvention( { ru: tokenLocalization, }, @@ -34,7 +34,7 @@ describe('TokenConfigurationConvention', () => { }); it('Should allow to get object of convention in wasm instance', () => { - const convention = new wasm.TokenConfigurationConventionWASM( + const convention = new wasm.TokenConfigurationConvention( { ru: tokenLocalization, }, @@ -42,11 +42,11 @@ describe('TokenConfigurationConvention', () => { ); expect(convention.localizations.constructor.name).to.deep.equal('Object'); - expect(convention.localizations.ru.constructor.name).to.deep.equal('TokenConfigurationLocalizationWASM'); + expect(convention.localizations.ru.constructor.name).to.deep.equal('TokenConfigurationLocalization'); }); it('Should allow to get decimals', () => { - const convention = new wasm.TokenConfigurationConventionWASM( + const convention = new wasm.TokenConfigurationConvention( { ru: tokenLocalization, }, @@ -59,7 +59,7 @@ describe('TokenConfigurationConvention', () => { describe('setters', () => { it('Should allow to set localizations object ', () => { - const convention = new wasm.TokenConfigurationConventionWASM( + const convention = new wasm.TokenConfigurationConvention( { ru: tokenLocalization, }, @@ -72,18 +72,18 @@ describe('TokenConfigurationConvention', () => { expect(convention.localizations.constructor.name).to.deep.equal('Object'); expect(convention.localizations.ru).to.deep.equal(undefined); - expect(convention.localizations.en.constructor.name).to.deep.equal('TokenConfigurationLocalizationWASM'); + expect(convention.localizations.en.constructor.name).to.deep.equal('TokenConfigurationLocalization'); }); it('Should allow to set localizations object with wasm ', () => { - const convention = new wasm.TokenConfigurationConventionWASM( + const convention = new wasm.TokenConfigurationConvention( { ru: tokenLocalization, }, 1, ); - const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + const localization = new wasm.TokenConfigurationLocalization(false, 'singularForm', 'pluralForm'); convention.localizations = { en: localization, @@ -91,7 +91,7 @@ describe('TokenConfigurationConvention', () => { expect(convention.localizations.constructor.name).to.deep.equal('Object'); expect(convention.localizations.ru).to.deep.equal(undefined); - expect(convention.localizations.en.constructor.name).to.deep.equal('TokenConfigurationLocalizationWASM'); + expect(convention.localizations.en.constructor.name).to.deep.equal('TokenConfigurationLocalization'); expect(convention.localizations.en.toJSON()).to.deep.equal({ shouldCapitalize: false, singularForm: 'singularForm', diff --git a/packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs index 28687d219a8..55585958baa 100644 --- a/packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/TokenConfigurationLocalization.spec.mjs @@ -9,7 +9,7 @@ before(async () => { describe('TokenConfigurationLocalization', () => { describe('serialization / deserialization', () => { it('should allow to create from values', () => { - const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + const localization = new wasm.TokenConfigurationLocalization(false, 'singularForm', 'pluralForm'); expect(localization.__wbg_ptr).to.not.equal(0); }); @@ -17,19 +17,19 @@ describe('TokenConfigurationLocalization', () => { describe('getters', () => { it('should allow to get shouldCapitalize', () => { - const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + const localization = new wasm.TokenConfigurationLocalization(false, 'singularForm', 'pluralForm'); expect(localization.shouldCapitalize).to.equal(false); }); it('should allow to get pluralForm', () => { - const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + const localization = new wasm.TokenConfigurationLocalization(false, 'singularForm', 'pluralForm'); expect(localization.pluralForm).to.equal('pluralForm'); }); it('should allow to get singularForm', () => { - const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + const localization = new wasm.TokenConfigurationLocalization(false, 'singularForm', 'pluralForm'); expect(localization.singularForm).to.equal('singularForm'); }); @@ -37,7 +37,7 @@ describe('TokenConfigurationLocalization', () => { describe('setters', () => { it('should allow to set shouldCapitalize', () => { - const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + const localization = new wasm.TokenConfigurationLocalization(false, 'singularForm', 'pluralForm'); localization.shouldCapitalize = true; @@ -45,7 +45,7 @@ describe('TokenConfigurationLocalization', () => { }); it('should allow to set pluralForm', () => { - const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + const localization = new wasm.TokenConfigurationLocalization(false, 'singularForm', 'pluralForm'); localization.pluralForm = 'pluralForm1212'; @@ -53,7 +53,7 @@ describe('TokenConfigurationLocalization', () => { }); it('should allow to set singularForm', () => { - const localization = new wasm.TokenConfigurationLocalizationWASM(false, 'singularForm', 'pluralForm'); + const localization = new wasm.TokenConfigurationLocalization(false, 'singularForm', 'pluralForm'); localization.singularForm = 'singularForm12121'; diff --git a/packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs index 796a776ecfc..90a14ccb3aa 100644 --- a/packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/TokenDistributionRecipient.spec.mjs @@ -10,19 +10,19 @@ before(async () => { describe('TokenDistributionRecipient', () => { describe('serialization / deserialization', () => { it('should allow to create from values ContractOwner', () => { - const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + const recipient = wasm.TokenDistributionRecipient.ContractOwner(); expect(recipient.__wbg_ptr).to.not.equal(0); }); it('should allow to create from values Identity', () => { - const recipient = wasm.TokenDistributionRecipientWASM.Identity(identifier); + const recipient = wasm.TokenDistributionRecipient.Identity(identifier); expect(recipient.__wbg_ptr).to.not.equal(0); }); it('should allow to create from values EvonodesByParticipation', () => { - const recipient = wasm.TokenDistributionRecipientWASM.EvonodesByParticipation(); + const recipient = wasm.TokenDistributionRecipient.EvonodesByParticipation(); expect(recipient.__wbg_ptr).to.not.equal(0); }); @@ -30,21 +30,21 @@ describe('TokenDistributionRecipient', () => { describe('getters', () => { it('should allow to get values ContractOwner', () => { - const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + const recipient = wasm.TokenDistributionRecipient.ContractOwner(); expect(recipient.getType()).to.equal('ContractOwner'); expect(recipient.getValue()).to.equal(undefined); }); it('should allow to get values Identity', () => { - const recipient = wasm.TokenDistributionRecipientWASM.Identity(identifier); + const recipient = wasm.TokenDistributionRecipient.Identity(identifier); expect(recipient.getType()).to.equal(`Identity(${identifier})`); expect(recipient.getValue().base58()).to.equal(identifier); }); it('should allow to get values EvonodesByParticipation', () => { - const recipient = wasm.TokenDistributionRecipientWASM.EvonodesByParticipation(); + const recipient = wasm.TokenDistributionRecipient.EvonodesByParticipation(); expect(recipient.getType()).to.equal('EvonodesByParticipation'); expect(recipient.getValue()).to.equal(undefined); diff --git a/packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs index fb864504d9a..c48033c646b 100644 --- a/packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs @@ -10,9 +10,9 @@ before(async () => { describe('TokenDistributionRules', () => { describe('serialization / deserialization', () => { it('shoulda allow to create with undefined values', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -20,7 +20,7 @@ describe('TokenDistributionRules', () => { true, ); - const distributionRules = new wasm.TokenDistributionRulesWASM( + const distributionRules = new wasm.TokenDistributionRules( undefined, changeRules, undefined, @@ -36,9 +36,9 @@ describe('TokenDistributionRules', () => { }); it('shoulda allow to create without undefined values', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -46,7 +46,7 @@ describe('TokenDistributionRules', () => { true, ); - const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistribution( { 1750140416485: { PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10000), @@ -54,23 +54,23 @@ describe('TokenDistributionRules', () => { }, ); - const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + const recipient = wasm.TokenDistributionRecipient.ContractOwner(); - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + const distributionType = wasm.RewardDistributionType.BlockBasedDistribution( BigInt(111), distributionFunction, ); - const perpetualDistribution = new wasm.TokenPerpetualDistributionWASM( + const perpetualDistribution = new wasm.TokenPerpetualDistribution( distributionType, recipient, ); - const distributionRules = new wasm.TokenDistributionRulesWASM( + const distributionRules = new wasm.TokenDistributionRules( perpetualDistribution, changeRules, preProgrammedDistribution, @@ -90,9 +90,9 @@ describe('TokenDistributionRules', () => { describe('getters', () => { it('shoulda allow to get values', () => { - const noOne = wasm.AuthorizedActionTakersWASM.NoOne(); + const noOne = wasm.AuthorizedActionTakers.NoOne(); - const changeRules = new wasm.ChangeControlRulesWASM( + const changeRules = new wasm.ChangeControlRules( noOne, noOne, true, @@ -100,7 +100,7 @@ describe('TokenDistributionRules', () => { true, ); - const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistribution( { 1750140416485: { PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10000), @@ -108,23 +108,23 @@ describe('TokenDistributionRules', () => { }, ); - const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + const recipient = wasm.TokenDistributionRecipient.ContractOwner(); - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + const distributionType = wasm.RewardDistributionType.BlockBasedDistribution( BigInt(111), distributionFunction, ); - const perpetualDistribution = new wasm.TokenPerpetualDistributionWASM( + const perpetualDistribution = new wasm.TokenPerpetualDistribution( distributionType, recipient, ); - const distributionRules = new wasm.TokenDistributionRulesWASM( + const distributionRules = new wasm.TokenDistributionRules( perpetualDistribution, changeRules, preProgrammedDistribution, @@ -135,14 +135,14 @@ describe('TokenDistributionRules', () => { changeRules, ); - expect(distributionRules.perpetualDistribution.constructor.name).to.deep.equal('TokenPerpetualDistributionWASM'); - expect(distributionRules.perpetualDistributionRules.constructor.name).to.deep.equal('ChangeControlRulesWASM'); - expect(distributionRules.preProgrammedDistribution.constructor.name).to.deep.equal('TokenPreProgrammedDistributionWASM'); - expect(distributionRules.newTokenDestinationIdentity.constructor.name).to.deep.equal('IdentifierWASM'); - expect(distributionRules.newTokenDestinationIdentityRules.constructor.name).to.deep.equal('ChangeControlRulesWASM'); + expect(distributionRules.perpetualDistribution.constructor.name).to.deep.equal('TokenPerpetualDistribution'); + expect(distributionRules.perpetualDistributionRules.constructor.name).to.deep.equal('ChangeControlRules'); + expect(distributionRules.preProgrammedDistribution.constructor.name).to.deep.equal('TokenPreProgrammedDistribution'); + expect(distributionRules.newTokenDestinationIdentity.constructor.name).to.deep.equal('Identifier'); + expect(distributionRules.newTokenDestinationIdentityRules.constructor.name).to.deep.equal('ChangeControlRules'); expect(distributionRules.mintingAllowChoosingDestination).to.deep.equal(true); - expect(distributionRules.mintingAllowChoosingDestinationRules.constructor.name).to.deep.equal('ChangeControlRulesWASM'); - expect(distributionRules.changeDirectPurchasePricingRules.constructor.name).to.deep.equal('ChangeControlRulesWASM'); + expect(distributionRules.mintingAllowChoosingDestinationRules.constructor.name).to.deep.equal('ChangeControlRules'); + expect(distributionRules.changeDirectPurchasePricingRules.constructor.name).to.deep.equal('ChangeControlRules'); }); }); @@ -164,34 +164,34 @@ describe('TokenDistributionRules', () => { let distributionRules; before(() => { - noOne = wasm.AuthorizedActionTakersWASM.NoOne(); - changeRules = new wasm.ChangeControlRulesWASM( + noOne = wasm.AuthorizedActionTakers.NoOne(); + changeRules = new wasm.ChangeControlRules( noOne, noOne, true, true, true, ); - preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + preProgrammedDistribution = new wasm.TokenPreProgrammedDistribution( { 1750140416485: { PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10000), }, }, ); - recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); - distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + recipient = wasm.TokenDistributionRecipient.ContractOwner(); + distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + distributionType = wasm.RewardDistributionType.BlockBasedDistribution( BigInt(111), distributionFunction, ); - perpetualDistribution = new wasm.TokenPerpetualDistributionWASM( + perpetualDistribution = new wasm.TokenPerpetualDistribution( distributionType, recipient, ); - distributionRules = new wasm.TokenDistributionRulesWASM( + distributionRules = new wasm.TokenDistributionRules( perpetualDistribution, changeRules, preProgrammedDistribution, @@ -210,7 +210,7 @@ describe('TokenDistributionRules', () => { }); it('should allow to set changeDirectPurchasePricingRules', () => { - const newRules = new wasm.ChangeControlRulesWASM( + const newRules = new wasm.ChangeControlRules( noOne, noOne, false, @@ -227,7 +227,7 @@ describe('TokenDistributionRules', () => { }); it('should allow to set mintingAllowChoosingDestinationRules', () => { - const newRules = new wasm.ChangeControlRulesWASM( + const newRules = new wasm.ChangeControlRules( noOne, noOne, false, @@ -244,7 +244,7 @@ describe('TokenDistributionRules', () => { }); it('should allow to set newTokenDestinationIdentityRules', () => { - const newRules = new wasm.ChangeControlRulesWASM( + const newRules = new wasm.ChangeControlRules( noOne, noOne, false, @@ -267,7 +267,7 @@ describe('TokenDistributionRules', () => { }); it('should allow to set preProgrammedDistribution', () => { - const newPreProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + const newPreProgrammedDistribution = new wasm.TokenPreProgrammedDistribution( { 1750140416411: { PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10011120), @@ -286,7 +286,7 @@ describe('TokenDistributionRules', () => { }); it('should allow to set perpetualDistributionRules', () => { - const newPerpetualDistributionRules = new wasm.ChangeControlRulesWASM( + const newPerpetualDistributionRules = new wasm.ChangeControlRules( noOne, noOne, false, @@ -301,9 +301,9 @@ describe('TokenDistributionRules', () => { }); it('should allow to set perpetualDistribution', () => { - const newRecipient = wasm.TokenDistributionRecipientWASM.EvonodesByParticipation(); + const newRecipient = wasm.TokenDistributionRecipient.EvonodesByParticipation(); - const newPerpetualDistribution = new wasm.TokenPerpetualDistributionWASM( + const newPerpetualDistribution = new wasm.TokenPerpetualDistribution( distributionType, newRecipient, ); diff --git a/packages/wasm-dpp2/tests/unit/TokenKeepsHistoryRules.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenKeepsHistoryRules.spec.mjs index e8d12752392..8f081561138 100644 --- a/packages/wasm-dpp2/tests/unit/TokenKeepsHistoryRules.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/TokenKeepsHistoryRules.spec.mjs @@ -9,7 +9,7 @@ before(async () => { describe('TokenKeepsHistoryRules', () => { describe('serialization / deserialization', () => { it('should allow to create TokenKeepsHistoryRules from values', () => { - const keepHistory = new wasm.TokenKeepsHistoryRulesWASM( + const keepHistory = new wasm.TokenKeepsHistoryRules( true, true, true, @@ -24,7 +24,7 @@ describe('TokenKeepsHistoryRules', () => { describe('getters', () => { it('should allow to get values', () => { - const keepHistory = new wasm.TokenKeepsHistoryRulesWASM( + const keepHistory = new wasm.TokenKeepsHistoryRules( true, true, true, @@ -44,7 +44,7 @@ describe('TokenKeepsHistoryRules', () => { describe('setters', () => { it('should allow to set values', () => { - const keepHistory = new wasm.TokenKeepsHistoryRulesWASM( + const keepHistory = new wasm.TokenKeepsHistoryRules( true, true, true, diff --git a/packages/wasm-dpp2/tests/unit/TokenPerpetualDistribution.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenPerpetualDistribution.spec.mjs index b17c7e490d1..55e708e373f 100644 --- a/packages/wasm-dpp2/tests/unit/TokenPerpetualDistribution.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/TokenPerpetualDistribution.spec.mjs @@ -9,18 +9,18 @@ before(async () => { describe('TokenPerpetualDistribution', () => { describe('serialization / deserialization', () => { it('should allow to create from values', () => { - const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + const recipient = wasm.TokenDistributionRecipient.ContractOwner(); - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + const distributionType = wasm.RewardDistributionType.BlockBasedDistribution( BigInt(111), distributionFunction, ); - const distribution = new wasm.TokenPerpetualDistributionWASM( + const distribution = new wasm.TokenPerpetualDistribution( distributionType, recipient, ); @@ -34,66 +34,66 @@ describe('TokenPerpetualDistribution', () => { describe('getters', () => { it('should allow to get distributionType', () => { - const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + const recipient = wasm.TokenDistributionRecipient.ContractOwner(); - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + const distributionType = wasm.RewardDistributionType.BlockBasedDistribution( BigInt(111), distributionFunction, ); - const distribution = new wasm.TokenPerpetualDistributionWASM( + const distribution = new wasm.TokenPerpetualDistribution( distributionType, recipient, ); - expect(distribution.distributionType.constructor.name).to.deep.equal('RewardDistributionTypeWASM'); + expect(distribution.distributionType.constructor.name).to.deep.equal('RewardDistributionType'); }); it('should allow to get distributionRecipient', () => { - const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + const recipient = wasm.TokenDistributionRecipient.ContractOwner(); - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + const distributionType = wasm.RewardDistributionType.BlockBasedDistribution( BigInt(111), distributionFunction, ); - const distribution = new wasm.TokenPerpetualDistributionWASM( + const distribution = new wasm.TokenPerpetualDistribution( distributionType, recipient, ); - expect(distribution.distributionRecipient.constructor.name).to.deep.equal('TokenDistributionRecipientWASM'); + expect(distribution.distributionRecipient.constructor.name).to.deep.equal('TokenDistributionRecipient'); expect(distribution.distributionRecipient.getType()).to.deep.equal('ContractOwner'); }); }); describe('setters', () => { it('should allow to set distributionType', () => { - const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + const recipient = wasm.TokenDistributionRecipient.ContractOwner(); - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + const distributionType = wasm.RewardDistributionType.BlockBasedDistribution( BigInt(111), distributionFunction, ); - const distribution = new wasm.TokenPerpetualDistributionWASM( + const distribution = new wasm.TokenPerpetualDistribution( distributionType, recipient, ); - const newDistribution = wasm.RewardDistributionTypeWASM.TimeBasedDistribution( + const newDistribution = wasm.RewardDistributionType.TimeBasedDistribution( BigInt(111), distributionFunction, ); @@ -101,33 +101,33 @@ describe('TokenPerpetualDistribution', () => { distribution.distributionType = newDistribution; expect(newDistribution.__wbg_ptr).to.not.equal(0); - expect(distribution.distributionType.constructor.name).to.deep.equal('RewardDistributionTypeWASM'); - expect(distribution.distributionType.getDistribution().constructor.name).to.deep.equal('TimeBasedDistributionWASM'); + expect(distribution.distributionType.constructor.name).to.deep.equal('RewardDistributionType'); + expect(distribution.distributionType.getDistribution().constructor.name).to.deep.equal('TimeBasedDistribution'); }); it('should allow to set distributionRecipient', () => { - const recipient = wasm.TokenDistributionRecipientWASM.ContractOwner(); + const recipient = wasm.TokenDistributionRecipient.ContractOwner(); - const distributionFunction = wasm.DistributionFunctionWASM.FixedAmountDistribution( + const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); - const distributionType = wasm.RewardDistributionTypeWASM.BlockBasedDistribution( + const distributionType = wasm.RewardDistributionType.BlockBasedDistribution( BigInt(111), distributionFunction, ); - const distribution = new wasm.TokenPerpetualDistributionWASM( + const distribution = new wasm.TokenPerpetualDistribution( distributionType, recipient, ); - const newRecipient = wasm.TokenDistributionRecipientWASM.EvonodesByParticipation(); + const newRecipient = wasm.TokenDistributionRecipient.EvonodesByParticipation(); distribution.distributionRecipient = newRecipient; expect(newRecipient.__wbg_ptr).to.not.equal(0); - expect(distribution.distributionRecipient.constructor.name).to.deep.equal('TokenDistributionRecipientWASM'); + expect(distribution.distributionRecipient.constructor.name).to.deep.equal('TokenDistributionRecipient'); expect(distribution.distributionRecipient.getType()).to.deep.equal('EvonodesByParticipation'); }); }); diff --git a/packages/wasm-dpp2/tests/unit/TokenPreProgrammedDistribution.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenPreProgrammedDistribution.spec.mjs index d4008ec4215..ef11317f92e 100644 --- a/packages/wasm-dpp2/tests/unit/TokenPreProgrammedDistribution.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/TokenPreProgrammedDistribution.spec.mjs @@ -9,7 +9,7 @@ before(async () => { describe('TokenPreProgrammedDistribution', () => { describe('serialization / deserialization', () => { it('should allow to create from values', () => { - const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistribution( { 1750140416485: { PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10000), @@ -23,7 +23,7 @@ describe('TokenPreProgrammedDistribution', () => { describe('getters', () => { it('should allow to get distributions', () => { - const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistribution( { 1750140416485: { PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10100), @@ -41,7 +41,7 @@ describe('TokenPreProgrammedDistribution', () => { describe('setters', () => { it('should allow to set distributions', () => { - const preProgrammedDistribution = new wasm.TokenPreProgrammedDistributionWASM( + const preProgrammedDistribution = new wasm.TokenPreProgrammedDistribution( { 1750140416485: { PJUBWbXWmzEYCs99rAAbnCiHRzrnhKLQrXbmSsuPBYB: BigInt(10100), diff --git a/packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs b/packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs index 8b0700dccb5..04ae362bdc6 100644 --- a/packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/TokensTransitions.spec.mjs @@ -11,43 +11,43 @@ let baseTransition; describe('TokenTransitions', () => { before(async () => { - baseTransition = new wasm.TokenBaseTransitionWASM(BigInt(1), 1, dataContractId, ownerId); + baseTransition = new wasm.TokenBaseTransition(BigInt(1), 1, dataContractId, ownerId); }); describe('serialize/deserialize', () => { it('should allow to create burn transition', () => { - const burnTransition = new wasm.TokenBurnTransitionWASM(baseTransition, BigInt(11), 'bbbb'); + const burnTransition = new wasm.TokenBurnTransition(baseTransition, BigInt(11), 'bbbb'); - expect(burnTransition.constructor.name).to.equal('TokenBurnTransitionWASM'); + expect(burnTransition.constructor.name).to.equal('TokenBurnTransition'); expect(burnTransition.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create mint transition', () => { - const mintTransition = new wasm.TokenMintTransitionWASM(baseTransition, ownerId, BigInt(11), 'bbbb'); + const mintTransition = new wasm.TokenMintTransition(baseTransition, ownerId, BigInt(11), 'bbbb'); - expect(mintTransition.constructor.name).to.equal('TokenMintTransitionWASM'); + expect(mintTransition.constructor.name).to.equal('TokenMintTransition'); expect(mintTransition.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create transfer transition', () => { - const transferTransition = new wasm.TokenTransferTransitionWASM( + const transferTransition = new wasm.TokenTransferTransition( baseTransition, ownerId, BigInt(11), 'bbbb', ); - expect(transferTransition.constructor.name).to.equal('TokenTransferTransitionWASM'); + expect(transferTransition.constructor.name).to.equal('TokenTransferTransition'); expect(transferTransition.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create transfer transition with shared encrypted note', () => { - const sharedEncryptedNote = new wasm.SharedEncryptedNoteWASM(0, 0, [0, 0, 0]); + const sharedEncryptedNote = new wasm.SharedEncryptedNote(0, 0, [0, 0, 0]); - const transferTransition = new wasm.TokenTransferTransitionWASM( + const transferTransition = new wasm.TokenTransferTransition( baseTransition, ownerId, BigInt(11), @@ -55,17 +55,17 @@ describe('TokenTransitions', () => { sharedEncryptedNote, ); - expect(sharedEncryptedNote.constructor.name).to.equal('SharedEncryptedNoteWASM'); - expect(transferTransition.constructor.name).to.equal('TokenTransferTransitionWASM'); + expect(sharedEncryptedNote.constructor.name).to.equal('SharedEncryptedNote'); + expect(transferTransition.constructor.name).to.equal('TokenTransferTransition'); expect(transferTransition.__wbg_ptr).to.not.equal(0); expect(sharedEncryptedNote.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create transfer transition with private encrypted note', () => { - const privateEncryptedNote = new wasm.PrivateEncryptedNoteWASM(0, 0, [0, 0, 0]); + const privateEncryptedNote = new wasm.PrivateEncryptedNote(0, 0, [0, 0, 0]); - const transferTransition = new wasm.TokenTransferTransitionWASM( + const transferTransition = new wasm.TokenTransferTransition( baseTransition, ownerId, BigInt(11), @@ -74,121 +74,121 @@ describe('TokenTransitions', () => { privateEncryptedNote, ); - expect(privateEncryptedNote.constructor.name).to.equal('PrivateEncryptedNoteWASM'); - expect(transferTransition.constructor.name).to.equal('TokenTransferTransitionWASM'); + expect(privateEncryptedNote.constructor.name).to.equal('PrivateEncryptedNote'); + expect(transferTransition.constructor.name).to.equal('TokenTransferTransition'); expect(transferTransition.__wbg_ptr).to.not.equal(0); expect(privateEncryptedNote.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create freeze transition', () => { - const freezeTransition = new wasm.TokenFreezeTransitionWASM( + const freezeTransition = new wasm.TokenFreezeTransition( baseTransition, ownerId, 'bbbb', ); - expect(freezeTransition.constructor.name).to.equal('TokenFreezeTransitionWASM'); + expect(freezeTransition.constructor.name).to.equal('TokenFreezeTransition'); expect(freezeTransition.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create unfreeze transition', () => { - const unfreezeTransition = new wasm.TokenUnFreezeTransitionWASM( + const unfreezeTransition = new wasm.TokenUnFreezeTransition( baseTransition, ownerId, 'bbbb', ); - expect(unfreezeTransition.constructor.name).to.equal('TokenUnFreezeTransitionWASM'); + expect(unfreezeTransition.constructor.name).to.equal('TokenUnFreezeTransition'); expect(unfreezeTransition.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create destroy frozen funds transition', () => { - const tokenDestroyFrozenFundsTransition = new wasm.TokenDestroyFrozenFundsTransitionWASM( + const tokenDestroyFrozenFundsTransition = new wasm.TokenDestroyFrozenFundsTransition( baseTransition, ownerId, 'bbbb', ); - expect(tokenDestroyFrozenFundsTransition.constructor.name).to.equal('TokenDestroyFrozenFundsTransitionWASM'); + expect(tokenDestroyFrozenFundsTransition.constructor.name).to.equal('TokenDestroyFrozenFundsTransition'); expect(tokenDestroyFrozenFundsTransition.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create claim transition', () => { - const claimTransition = new wasm.TokenClaimTransitionWASM( + const claimTransition = new wasm.TokenClaimTransition( baseTransition, - wasm.TokenDistributionTypeWASM.PreProgrammed, + wasm.TokenDistributionType.PreProgrammed, 'bbbb', ); - expect(claimTransition.constructor.name).to.equal('TokenClaimTransitionWASM'); + expect(claimTransition.constructor.name).to.equal('TokenClaimTransition'); expect(claimTransition.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create claim transition without distribution type', () => { - const claimTransition = new wasm.TokenClaimTransitionWASM( + const claimTransition = new wasm.TokenClaimTransition( baseTransition, ); - expect(claimTransition.constructor.name).to.equal('TokenClaimTransitionWASM'); + expect(claimTransition.constructor.name).to.equal('TokenClaimTransition'); expect(claimTransition.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create emergency action transition', () => { - const emergencyActionTransition = new wasm.TokenEmergencyActionTransitionWASM( + const emergencyActionTransition = new wasm.TokenEmergencyActionTransition( baseTransition, - wasm.TokenDistributionTypeWASM.PreProgrammed, + wasm.TokenDistributionType.PreProgrammed, 'bbbb', ); - expect(emergencyActionTransition.constructor.name).to.equal('TokenEmergencyActionTransitionWASM'); + expect(emergencyActionTransition.constructor.name).to.equal('TokenEmergencyActionTransition'); expect(emergencyActionTransition.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create config update transition', () => { - const tradeMode = wasm.TokenTradeModeWASM.NotTradeable(); + const tradeMode = wasm.TokenTradeMode.NotTradeable(); - const configUpdateTransition = new wasm.TokenConfigUpdateTransitionWASM( + const configUpdateTransition = new wasm.TokenConfigUpdateTransition( baseTransition, - wasm.TokenConfigurationChangeItemWASM.MarketplaceTradeModeItem(tradeMode), + wasm.TokenConfigurationChangeItem.MarketplaceTradeModeItem(tradeMode), 'bbbb', ); - expect(configUpdateTransition.constructor.name).to.equal('TokenConfigUpdateTransitionWASM'); + expect(configUpdateTransition.constructor.name).to.equal('TokenConfigUpdateTransition'); expect(configUpdateTransition.__wbg_ptr).to.not.equal(0); expect(tradeMode.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create direct purchase transition', () => { - const directPurchaseTransition = new wasm.TokenDirectPurchaseTransitionWASM( + const directPurchaseTransition = new wasm.TokenDirectPurchaseTransition( baseTransition, BigInt(111), BigInt(111), ); - expect(directPurchaseTransition.constructor.name).to.equal('TokenDirectPurchaseTransitionWASM'); + expect(directPurchaseTransition.constructor.name).to.equal('TokenDirectPurchaseTransition'); expect(directPurchaseTransition.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); }); it('should allow to create set price direct purchase transition', () => { - const price = wasm.TokenPricingScheduleWASM.SetPrices({ 100: 1000 }); + const price = wasm.TokenPricingSchedule.SetPrices({ 100: 1000 }); - const setPriceDirectPurchaseTransition = new wasm.TokenSetPriceForDirectPurchaseTransitionWASM( + const setPriceDirectPurchaseTransition = new wasm.TokenSetPriceForDirectPurchaseTransition( baseTransition, price, 'bbbb', ); - expect(price.constructor.name).to.equal('TokenPricingScheduleWASM'); - expect(setPriceDirectPurchaseTransition.constructor.name).to.equal('TokenSetPriceForDirectPurchaseTransitionWASM'); + expect(price.constructor.name).to.equal('TokenPricingSchedule'); + expect(setPriceDirectPurchaseTransition.constructor.name).to.equal('TokenSetPriceForDirectPurchaseTransition'); expect(setPriceDirectPurchaseTransition.__wbg_ptr).to.not.equal(0); expect(price.__wbg_ptr).to.not.equal(0); expect(baseTransition.__wbg_ptr).to.not.equal(0); @@ -197,26 +197,26 @@ describe('TokenTransitions', () => { describe('getters', () => { it('should allow to read getters burn transition', () => { - const burnTransition = new wasm.TokenBurnTransitionWASM(baseTransition, BigInt(11), 'bbbb'); + const burnTransition = new wasm.TokenBurnTransition(baseTransition, BigInt(11), 'bbbb'); expect(burnTransition.burnAmount).to.equal(BigInt(11)); - expect(burnTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(burnTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(burnTransition.publicNote).to.equal('bbbb'); }); it('should allow to read getters mint transition', () => { - const mintTransition = new wasm.TokenMintTransitionWASM(baseTransition, ownerId, BigInt(11), 'bbbb'); + const mintTransition = new wasm.TokenMintTransition(baseTransition, ownerId, BigInt(11), 'bbbb'); expect(mintTransition.amount).to.equal(BigInt(11)); - expect(mintTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(mintTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(mintTransition.publicNote).to.equal('bbbb'); }); it('should allow to read getters transfer transition', () => { - const sharedEncryptedNote = new wasm.SharedEncryptedNoteWASM(0, 0, [0, 0, 0]); - const privateEncryptedNote = new wasm.PrivateEncryptedNoteWASM(0, 0, [0, 0, 0]); + const sharedEncryptedNote = new wasm.SharedEncryptedNote(0, 0, [0, 0, 0]); + const privateEncryptedNote = new wasm.PrivateEncryptedNote(0, 0, [0, 0, 0]); - const transferTransition = new wasm.TokenTransferTransitionWASM( + const transferTransition = new wasm.TokenTransferTransition( baseTransition, ownerId, BigInt(11), @@ -225,142 +225,142 @@ describe('TokenTransitions', () => { privateEncryptedNote, ); - expect(transferTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(transferTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(transferTransition.amount).to.equal(BigInt(11)); expect(transferTransition.publicNote).to.equal('bbbb'); - expect(transferTransition.sharedEncryptedNote.constructor.name).to.equal('SharedEncryptedNoteWASM'); - expect(transferTransition.privateEncryptedNote.constructor.name).to.equal('PrivateEncryptedNoteWASM'); + expect(transferTransition.sharedEncryptedNote.constructor.name).to.equal('SharedEncryptedNote'); + expect(transferTransition.privateEncryptedNote.constructor.name).to.equal('PrivateEncryptedNote'); }); it('should allow to read getters freeze transition', () => { - const freezeTransition = new wasm.TokenFreezeTransitionWASM( + const freezeTransition = new wasm.TokenFreezeTransition( baseTransition, ownerId, 'bbbb', ); - expect(freezeTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(freezeTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(freezeTransition.frozenIdentityId.base58()).to.equal(ownerId); expect(freezeTransition.publicNote).to.equal('bbbb'); }); it('should allow to read getters unfreeze transition', () => { - const unfreezeTransition = new wasm.TokenUnFreezeTransitionWASM( + const unfreezeTransition = new wasm.TokenUnFreezeTransition( baseTransition, ownerId, 'bbbb', ); - expect(unfreezeTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(unfreezeTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(unfreezeTransition.frozenIdentityId.base58()).to.equal(ownerId); expect(unfreezeTransition.publicNote).to.equal('bbbb'); }); it('should allow to read getters destroy frozen funds transition', () => { - const tokenDestroyFrozenFundsTransition = new wasm.TokenDestroyFrozenFundsTransitionWASM( + const tokenDestroyFrozenFundsTransition = new wasm.TokenDestroyFrozenFundsTransition( baseTransition, ownerId, 'bbbb', ); - expect(tokenDestroyFrozenFundsTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(tokenDestroyFrozenFundsTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(tokenDestroyFrozenFundsTransition.frozenIdentityId.base58()).to.equal(ownerId); expect(tokenDestroyFrozenFundsTransition.publicNote).to.equal('bbbb'); }); it('should allow to read getters claim transition', () => { - const claimTransition = new wasm.TokenClaimTransitionWASM( + const claimTransition = new wasm.TokenClaimTransition( baseTransition, - wasm.TokenDistributionTypeWASM.PreProgrammed, + wasm.TokenDistributionType.PreProgrammed, 'bbbb', ); - expect(claimTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(claimTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(claimTransition.distributionType).to.equal('PreProgrammed'); expect(claimTransition.publicNote).to.equal('bbbb'); }); it('should allow to read getters emergency action transition', () => { - const emergencyActionTransition = new wasm.TokenEmergencyActionTransitionWASM( + const emergencyActionTransition = new wasm.TokenEmergencyActionTransition( baseTransition, - wasm.TokenEmergencyActionWASM.Pause, + wasm.TokenEmergencyAction.Pause, 'bbbb', ); - expect(emergencyActionTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(emergencyActionTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(emergencyActionTransition.emergencyAction).to.equal('Pause'); expect(emergencyActionTransition.publicNote).to.equal('bbbb'); }); it('should allow to read getters config update transition', () => { - const tradeMode = wasm.TokenTradeModeWASM.NotTradeable(); + const tradeMode = wasm.TokenTradeMode.NotTradeable(); - const configUpdateTransition = new wasm.TokenConfigUpdateTransitionWASM( + const configUpdateTransition = new wasm.TokenConfigUpdateTransition( baseTransition, - wasm.TokenConfigurationChangeItemWASM.MarketplaceTradeModeItem(tradeMode), + wasm.TokenConfigurationChangeItem.MarketplaceTradeModeItem(tradeMode), 'bbbb', ); - expect(configUpdateTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); - expect(configUpdateTransition.updateTokenConfigurationItem.constructor.name).to.equal('TokenConfigurationChangeItemWASM'); + expect(configUpdateTransition.base.constructor.name).to.equal('TokenBaseTransition'); + expect(configUpdateTransition.updateTokenConfigurationItem.constructor.name).to.equal('TokenConfigurationChangeItem'); expect(configUpdateTransition.publicNote).to.equal('bbbb'); }); it('should allow to read getters direct purchase transition', () => { - const directPurchaseTransition = new wasm.TokenDirectPurchaseTransitionWASM( + const directPurchaseTransition = new wasm.TokenDirectPurchaseTransition( baseTransition, BigInt(111), BigInt(111), ); - expect(directPurchaseTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(directPurchaseTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(directPurchaseTransition.tokenCount).to.equal(BigInt(111)); expect(directPurchaseTransition.totalAgreedPrice).to.equal(BigInt(111)); }); it('should allow to read getters set price direct purchase transition', () => { - const price = wasm.TokenPricingScheduleWASM.SetPrices({ 100: 1000 }); + const price = wasm.TokenPricingSchedule.SetPrices({ 100: 1000 }); - const setPriceDirectPurchaseTransition = new wasm.TokenSetPriceForDirectPurchaseTransitionWASM( + const setPriceDirectPurchaseTransition = new wasm.TokenSetPriceForDirectPurchaseTransition( baseTransition, price, 'bbbb', ); - expect(setPriceDirectPurchaseTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); - expect(setPriceDirectPurchaseTransition.price.constructor.name).to.equal('TokenPricingScheduleWASM'); + expect(setPriceDirectPurchaseTransition.base.constructor.name).to.equal('TokenBaseTransition'); + expect(setPriceDirectPurchaseTransition.price.constructor.name).to.equal('TokenPricingSchedule'); expect(setPriceDirectPurchaseTransition.publicNote).to.equal('bbbb'); }); }); describe('setters', () => { it('should allow to set values burn transition', () => { - const burnTransition = new wasm.TokenBurnTransitionWASM(baseTransition, BigInt(11), 'bbbb'); + const burnTransition = new wasm.TokenBurnTransition(baseTransition, BigInt(11), 'bbbb'); burnTransition.burnAmount = BigInt(222); burnTransition.publicNote = 'aaaa'; expect(burnTransition.burnAmount).to.equal(BigInt(222)); - expect(burnTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(burnTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(burnTransition.publicNote).to.equal('aaaa'); }); it('should allow to set values mint transition', () => { - const mintTransition = new wasm.TokenMintTransitionWASM(baseTransition, ownerId, BigInt(11), 'bbbb'); + const mintTransition = new wasm.TokenMintTransition(baseTransition, ownerId, BigInt(11), 'bbbb'); mintTransition.amount = BigInt(222); mintTransition.publicNote = 'aaaa'; expect(mintTransition.amount).to.equal(BigInt(222)); - expect(mintTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(mintTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(mintTransition.publicNote).to.equal('aaaa'); }); it('should allow to set values transfer transition', () => { - const sharedEncryptedNote = new wasm.SharedEncryptedNoteWASM(0, 0, [0, 0, 0]); - const privateEncryptedNote = new wasm.PrivateEncryptedNoteWASM(0, 0, [0, 0, 0]); + const sharedEncryptedNote = new wasm.SharedEncryptedNote(0, 0, [0, 0, 0]); + const privateEncryptedNote = new wasm.PrivateEncryptedNote(0, 0, [0, 0, 0]); - const transferTransition = new wasm.TokenTransferTransitionWASM( + const transferTransition = new wasm.TokenTransferTransition( baseTransition, ownerId, BigInt(11), @@ -369,25 +369,25 @@ describe('TokenTransitions', () => { privateEncryptedNote, ); - const sharedEncryptedNote2 = new wasm.SharedEncryptedNoteWASM(0, 0, [0, 0, 0]); - const privateEncryptedNote2 = new wasm.PrivateEncryptedNoteWASM(0, 0, [0, 0, 0]); + const sharedEncryptedNote2 = new wasm.SharedEncryptedNote(0, 0, [0, 0, 0]); + const privateEncryptedNote2 = new wasm.PrivateEncryptedNote(0, 0, [0, 0, 0]); transferTransition.sharedEncryptedNote = sharedEncryptedNote2; transferTransition.privateEncryptedNote = privateEncryptedNote2; transferTransition.amount = BigInt(222); transferTransition.publicNote = 'aaaa'; - expect(transferTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(transferTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(transferTransition.amount).to.equal(BigInt(222)); expect(transferTransition.publicNote).to.equal('aaaa'); - expect(transferTransition.sharedEncryptedNote.constructor.name).to.equal('SharedEncryptedNoteWASM'); - expect(transferTransition.privateEncryptedNote.constructor.name).to.equal('PrivateEncryptedNoteWASM'); + expect(transferTransition.sharedEncryptedNote.constructor.name).to.equal('SharedEncryptedNote'); + expect(transferTransition.privateEncryptedNote.constructor.name).to.equal('PrivateEncryptedNote'); expect(sharedEncryptedNote2.__wbg_ptr).to.not.equal(0); expect(privateEncryptedNote2.__wbg_ptr).to.not.equal(0); }); it('should allow to set values freeze transition', () => { - const freezeTransition = new wasm.TokenFreezeTransitionWASM( + const freezeTransition = new wasm.TokenFreezeTransition( baseTransition, ownerId, 'bbbb', @@ -396,13 +396,13 @@ describe('TokenTransitions', () => { freezeTransition.frozenIdentityId = dataContractId; freezeTransition.publicNote = 'aaaa'; - expect(freezeTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(freezeTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(freezeTransition.frozenIdentityId.base58()).to.equal(dataContractId); expect(freezeTransition.publicNote).to.equal('aaaa'); }); it('should allow to set values unfreeze transition', () => { - const unfreezeTransition = new wasm.TokenUnFreezeTransitionWASM( + const unfreezeTransition = new wasm.TokenUnFreezeTransition( baseTransition, ownerId, 'bbbb', @@ -411,13 +411,13 @@ describe('TokenTransitions', () => { unfreezeTransition.frozenIdentityId = dataContractId; unfreezeTransition.publicNote = 'aaaa'; - expect(unfreezeTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(unfreezeTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(unfreezeTransition.frozenIdentityId.base58()).to.equal(dataContractId); expect(unfreezeTransition.publicNote).to.equal('aaaa'); }); it('should allow to set values destroy frozen funds transition', () => { - const tokenDestroyFrozenFundsTransition = new wasm.TokenDestroyFrozenFundsTransitionWASM( + const tokenDestroyFrozenFundsTransition = new wasm.TokenDestroyFrozenFundsTransition( baseTransition, ownerId, 'bbbb', @@ -426,60 +426,60 @@ describe('TokenTransitions', () => { tokenDestroyFrozenFundsTransition.frozenIdentityId = dataContractId; tokenDestroyFrozenFundsTransition.publicNote = 'aaaa'; - expect(tokenDestroyFrozenFundsTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(tokenDestroyFrozenFundsTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(tokenDestroyFrozenFundsTransition.frozenIdentityId.base58()).to.equal(dataContractId); expect(tokenDestroyFrozenFundsTransition.publicNote).to.equal('aaaa'); }); it('should allow to set values claim transition', () => { - const claimTransition = new wasm.TokenClaimTransitionWASM( + const claimTransition = new wasm.TokenClaimTransition( baseTransition, - wasm.TokenDistributionTypeWASM.Perpetual, + wasm.TokenDistributionType.Perpetual, 'bbbb', ); - claimTransition.distributionType = wasm.TokenDistributionTypeWASM.Perpetual; + claimTransition.distributionType = wasm.TokenDistributionType.Perpetual; claimTransition.publicNote = 'aaaa'; - expect(claimTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(claimTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(claimTransition.distributionType).to.equal('Perpetual'); expect(claimTransition.publicNote).to.equal('aaaa'); }); it('should allow to set values emergency action transition', () => { - const emergencyActionTransition = new wasm.TokenEmergencyActionTransitionWASM( + const emergencyActionTransition = new wasm.TokenEmergencyActionTransition( baseTransition, - wasm.TokenEmergencyActionWASM.Pause, + wasm.TokenEmergencyAction.Pause, 'bbbb', ); - emergencyActionTransition.emergencyAction = wasm.TokenEmergencyActionWASM.Resume; + emergencyActionTransition.emergencyAction = wasm.TokenEmergencyAction.Resume; emergencyActionTransition.publicNote = 'aaaa'; - expect(emergencyActionTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(emergencyActionTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(emergencyActionTransition.emergencyAction).to.equal('Resume'); expect(emergencyActionTransition.publicNote).to.equal('aaaa'); }); it('should allow to set values config update transition', () => { // At this moment available only one trade mode - const tradeMode = wasm.TokenTradeModeWASM.NotTradeable(); + const tradeMode = wasm.TokenTradeMode.NotTradeable(); - const configUpdateTransition = new wasm.TokenConfigUpdateTransitionWASM( + const configUpdateTransition = new wasm.TokenConfigUpdateTransition( baseTransition, - wasm.TokenConfigurationChangeItemWASM.MarketplaceTradeModeItem(tradeMode), + wasm.TokenConfigurationChangeItem.MarketplaceTradeModeItem(tradeMode), 'bbbb', ); configUpdateTransition.publicNote = 'aaaa'; - expect(configUpdateTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); - expect(configUpdateTransition.updateTokenConfigurationItem.constructor.name).to.equal('TokenConfigurationChangeItemWASM'); + expect(configUpdateTransition.base.constructor.name).to.equal('TokenBaseTransition'); + expect(configUpdateTransition.updateTokenConfigurationItem.constructor.name).to.equal('TokenConfigurationChangeItem'); expect(configUpdateTransition.publicNote).to.equal('aaaa'); }); it('should allow to set values direct purchase transition', () => { - const directPurchaseTransition = new wasm.TokenDirectPurchaseTransitionWASM( + const directPurchaseTransition = new wasm.TokenDirectPurchaseTransition( baseTransition, BigInt(111), BigInt(111), @@ -488,25 +488,25 @@ describe('TokenTransitions', () => { directPurchaseTransition.tokenCount = BigInt(222); directPurchaseTransition.totalAgreedPrice = BigInt(222); - expect(directPurchaseTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); + expect(directPurchaseTransition.base.constructor.name).to.equal('TokenBaseTransition'); expect(directPurchaseTransition.tokenCount).to.equal(BigInt(222)); expect(directPurchaseTransition.totalAgreedPrice).to.equal(BigInt(222)); }); it('should allow to set values set price direct purchase transition', () => { - const price = wasm.TokenPricingScheduleWASM.SetPrices({ 100: 1000 }); + const price = wasm.TokenPricingSchedule.SetPrices({ 100: 1000 }); - const setPriceDirectPurchaseTransition = new wasm.TokenSetPriceForDirectPurchaseTransitionWASM( + const setPriceDirectPurchaseTransition = new wasm.TokenSetPriceForDirectPurchaseTransition( baseTransition, price, 'bbbb', ); - setPriceDirectPurchaseTransition.price = wasm.TokenPricingScheduleWASM.SetPrices({ 101: 1010 }); + setPriceDirectPurchaseTransition.price = wasm.TokenPricingSchedule.SetPrices({ 101: 1010 }); setPriceDirectPurchaseTransition.publicNote = 'aaaa'; - expect(setPriceDirectPurchaseTransition.base.constructor.name).to.equal('TokenBaseTransitionWASM'); - expect(setPriceDirectPurchaseTransition.price.constructor.name).to.equal('TokenPricingScheduleWASM'); + expect(setPriceDirectPurchaseTransition.base.constructor.name).to.equal('TokenBaseTransition'); + expect(setPriceDirectPurchaseTransition.price.constructor.name).to.equal('TokenPricingSchedule'); expect(setPriceDirectPurchaseTransition.publicNote).to.equal('aaaa'); }); }); diff --git a/packages/wasm-dpp2/tests/unit/TxOut.spec.mjs b/packages/wasm-dpp2/tests/unit/TxOut.spec.mjs index 46e8cb69926..86971b1390f 100644 --- a/packages/wasm-dpp2/tests/unit/TxOut.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/TxOut.spec.mjs @@ -9,12 +9,12 @@ before(async () => { describe('TxOut', () => { describe('serialization / deserialization', () => { it('should allow to create from values with pubkey hex', () => { - const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + const out = new wasm.TxOut(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); expect(out.__wbg_ptr).to.not.equal(0); }); it('should allow to create from values with pubkey array', () => { - const out = new wasm.TxOutWASM(BigInt(100), Array.from(Buffer.from('76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac', 'hex'))); + const out = new wasm.TxOut(BigInt(100), Array.from(Buffer.from('76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac', 'hex'))); expect(out.__wbg_ptr).to.not.equal(0); }); @@ -22,25 +22,25 @@ describe('TxOut', () => { describe('getters', () => { it('should allow to get value', () => { - const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + const out = new wasm.TxOut(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); expect(out.value).to.equal(BigInt(100)); }); it('should allow to get script hex', () => { - const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + const out = new wasm.TxOut(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); expect(out.scriptPubKeyHex).to.equal('76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); }); it('should allow to get script bytes', () => { - const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + const out = new wasm.TxOut(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); expect(out.scriptPubKeyBytes).to.deep.equal(Uint8Array.from(Buffer.from('76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac', 'hex'))); }); it('should allow to get script asm', () => { - const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + const out = new wasm.TxOut(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); expect(out.getScriptPubKeyASM()).to.deep.equal('OP_DUP OP_HASH160 OP_PUSHBYTES_20 1a486a3855e6dc6dd02874424f53a6f2197b3d45 OP_EQUALVERIFY OP_CHECKSIG'); }); @@ -48,7 +48,7 @@ describe('TxOut', () => { describe('setters', () => { it('should allow to set value', () => { - const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + const out = new wasm.TxOut(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); out.value = BigInt(101); @@ -56,7 +56,7 @@ describe('TxOut', () => { }); it('should allow to set script hex', () => { - const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + const out = new wasm.TxOut(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); out.scriptPubKeyHex = '16a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'; @@ -64,7 +64,7 @@ describe('TxOut', () => { }); it('should allow to set script bytes', () => { - const out = new wasm.TxOutWASM(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); + const out = new wasm.TxOut(BigInt(100), '76a9141a486a3855e6dc6dd02874424f53a6f2197b3d4588ac'); out.scriptPubKeyBytes = Array.from(Buffer.from('76a914f995e42d1aa7a31b0106b63e1b896fe9aeeccc9988ac', 'hex')); diff --git a/packages/wasm-dpp2/tests/unit/module-load.spec.mjs b/packages/wasm-dpp2/tests/unit/module-load.spec.mjs index de595ab6dfb..8e749ac8e1f 100644 --- a/packages/wasm-dpp2/tests/unit/module-load.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/module-load.spec.mjs @@ -1,6 +1,6 @@ import init, { - StateTransitionWASM, - ConsensusErrorWASM, + StateTransition, + ConsensusError, } from '../../dist/dpp.compressed.js'; describe('wasm-dpp2 module', () => { @@ -9,11 +9,11 @@ describe('wasm-dpp2 module', () => { }); it('exposes state transition bindings', () => { - expect(StateTransitionWASM).to.be.a('function'); + expect(StateTransition).to.be.a('function'); }); it('exposes consensus error helpers', () => { - expect(ConsensusErrorWASM).to.be.a('function'); - expect(ConsensusErrorWASM.deserialize).to.be.a('function'); + expect(ConsensusError).to.be.a('function'); + expect(ConsensusError.deserialize).to.be.a('function'); }); }); From ee56d789fe4c31f4888567d6315a8e3bdf90296d Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Sat, 4 Oct 2025 20:30:57 +0700 Subject: [PATCH 03/44] refactor: rename WASM postfix to Wasm --- .../src/asset_lock_proof/chain/mod.rs | 32 ++--- .../asset_lock_proof/instant/instant_lock.rs | 24 ++-- .../src/asset_lock_proof/instant/mod.rs | 38 +++--- .../wasm-dpp2/src/asset_lock_proof/mod.rs | 84 ++++++------- .../src/asset_lock_proof/outpoint/mod.rs | 42 +++---- .../src/asset_lock_proof/tx_out/mod.rs | 16 +-- .../src/batch/batched_transition/mod.rs | 36 +++--- .../src/batch/document_base_transition/mod.rs | 38 +++--- .../src/batch/document_transition/mod.rs | 62 +++++----- .../batch/document_transitions/create/mod.rs | 48 ++++---- .../batch/document_transitions/delete/mod.rs | 40 +++---- .../document_transitions/purchase/mod.rs | 40 +++---- .../batch/document_transitions/replace/mod.rs | 40 +++---- .../document_transitions/transfer/mod.rs | 48 ++++---- .../document_transitions/update_price/mod.rs | 36 +++--- packages/wasm-dpp2/src/batch/generators.rs | 32 ++--- packages/wasm-dpp2/src/batch/mod.rs | 70 +++++------ .../src/batch/prefunded_voting_balance/mod.rs | 16 +-- .../src/batch/token_base_transition/mod.rs | 38 +++--- .../src/batch/token_payment_info/mod.rs | 30 ++--- .../src/batch/token_pricing_schedule/mod.rs | 14 +-- .../src/batch/token_transition/mod.rs | 94 +++++++-------- .../batch/token_transitions/config_update.rs | 32 ++--- .../token_transitions/direct_purchase.rs | 22 ++-- .../set_price_for_direct_purchase.rs | 32 ++--- .../src/batch/token_transitions/token_burn.rs | 22 ++-- .../batch/token_transitions/token_claim.rs | 34 +++--- .../token_destroy_frozen_funds.rs | 32 ++--- .../token_emergency_action.rs | 32 ++--- .../batch/token_transitions/token_freeze.rs | 30 ++--- .../src/batch/token_transitions/token_mint.rs | 34 +++--- .../batch/token_transitions/token_transfer.rs | 46 +++---- .../batch/token_transitions/token_unfreeze.rs | 30 ++--- packages/wasm-dpp2/src/consensus_error/mod.rs | 6 +- packages/wasm-dpp2/src/contract_bounds/mod.rs | 36 +++--- packages/wasm-dpp2/src/core_script/mod.rs | 20 ++-- packages/wasm-dpp2/src/data_contract/mod.rs | 96 +++++++-------- .../data_contract_transitions/create/mod.rs | 56 ++++----- .../data_contract_transitions/update/mod.rs | 56 ++++----- .../wasm-dpp2/src/document/methods/mod.rs | 72 +++++------ packages/wasm-dpp2/src/document/mod.rs | 22 ++-- .../private_encrypted_note/mod.rs | 16 +-- .../shared_encrypted_note/mod.rs | 12 +- .../wasm-dpp2/src/enums/batch/batch_enum.rs | 66 +++++------ .../src/enums/batch/gas_fees_paid_by.rs | 44 +++---- .../enums/contested/vote_state_result_type.rs | 28 ++--- packages/wasm-dpp2/src/enums/keys/key_type.rs | 78 ++++++------ packages/wasm-dpp2/src/enums/keys/purpose.rs | 84 ++++++------- .../src/enums/keys/security_level.rs | 54 ++++----- .../wasm-dpp2/src/enums/lock_types/mod.rs | 24 ++-- packages/wasm-dpp2/src/enums/network/mod.rs | 44 +++---- packages/wasm-dpp2/src/enums/platform/mod.rs | 86 +++++++------- .../wasm-dpp2/src/enums/token/action_goal.rs | 36 +++--- .../src/enums/token/distribution_type.rs | 36 +++--- .../src/enums/token/emergency_action.rs | 36 +++--- .../wasm-dpp2/src/enums/withdrawal/mod.rs | 44 +++---- .../src/group_state_transition_info/mod.rs | 24 ++-- packages/wasm-dpp2/src/identifier/mod.rs | 56 ++++----- packages/wasm-dpp2/src/identity/mod.rs | 44 +++---- .../wasm-dpp2/src/identity_public_key/mod.rs | 74 ++++++------ .../create_transition/mod.rs | 74 ++++++------ .../credit_withdrawal_transition/mod.rs | 70 +++++------ .../mod.rs | 48 ++++---- .../public_key_in_creation/mod.rs | 80 ++++++------- .../top_up_transition/mod.rs | 52 ++++---- .../update_transition/mod.rs | 62 +++++----- packages/wasm-dpp2/src/masternode_vote/mod.rs | 70 +++++------ .../resource_vote_choice/mod.rs | 22 ++-- .../wasm-dpp2/src/masternode_vote/vote/mod.rs | 26 ++-- .../src/masternode_vote/vote_poll/mod.rs | 24 ++-- .../wasm-dpp2/src/partial_identity/mod.rs | 22 ++-- packages/wasm-dpp2/src/private_key/mod.rs | 22 ++-- packages/wasm-dpp2/src/public_key/mod.rs | 18 +-- .../wasm-dpp2/src/state_transition/mod.rs | 52 ++++---- .../src/token_configuration/action_taker.rs | 30 ++--- .../authorized_action_takers.rs | 28 ++--- .../change_control_rules.rs | 44 +++---- .../configuration_convention.rs | 20 ++-- .../distribution_function.rs | 64 +++++----- .../distribution_recipient.rs | 32 ++--- .../token_configuration/distribution_rules.rs | 64 +++++----- .../distribution_structs.rs | 16 +-- .../src/token_configuration/group.rs | 22 ++-- .../keeps_history_rules.rs | 14 +-- .../src/token_configuration/localization.rs | 18 +-- .../token_configuration/marketplace_rules.rs | 32 ++--- .../wasm-dpp2/src/token_configuration/mod.rs | 112 +++++++++--------- .../perpetual_distribution.rs | 30 ++--- .../pre_programmed_distribution.rs | 22 ++-- .../reward_distribution_type.rs | 60 +++++----- .../src/token_configuration/trade_mode.rs | 16 +-- .../items/conventions.rs | 20 ++-- .../items/destroy_frozen_funds.rs | 14 +-- .../items/emergency_action.rs | 18 +-- .../items/freeze.rs | 18 +-- .../items/main_control_group.rs | 6 +- .../items/manual_burning.rs | 14 +-- .../items/manual_minting.rs | 14 +-- .../items/marketplace_trade_mode.rs | 20 ++-- .../items/max_supply.rs | 16 +-- .../minting_allow_choosing_destination.rs | 16 +-- .../items/new_tokens_destination_identity.rs | 22 ++-- .../items/no_change.rs | 6 +- .../items/perpetual_distribution.rs | 20 ++-- .../items/unfreeze.rs | 14 +-- .../token_configuration_change_item/mod.rs | 78 ++++++------ 106 files changed, 2038 insertions(+), 2038 deletions(-) diff --git a/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs index 39d327c545c..6ab26da1102 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs @@ -1,5 +1,5 @@ -use crate::asset_lock_proof::outpoint::OutPointWASM; -use crate::identifier::IdentifierWASM; +use crate::asset_lock_proof::outpoint::OutPointWasm; +use crate::identifier::IdentifierWasm; use dpp::identity::state_transition::asset_lock_proof::chain::ChainAssetLockProof; use serde::Deserialize; use wasm_bindgen::prelude::wasm_bindgen; @@ -14,22 +14,22 @@ struct ChainAssetLockProofParams { #[wasm_bindgen(js_name = "ChainAssetLockProof")] #[derive(Clone)] -pub struct ChainAssetLockProofWASM(ChainAssetLockProof); +pub struct ChainAssetLockProofWasm(ChainAssetLockProof); -impl From for ChainAssetLockProof { - fn from(chain_lock: ChainAssetLockProofWASM) -> Self { +impl From for ChainAssetLockProof { + fn from(chain_lock: ChainAssetLockProofWasm) -> Self { chain_lock.0 } } -impl From for ChainAssetLockProofWASM { +impl From for ChainAssetLockProofWasm { fn from(chain_lock: ChainAssetLockProof) -> Self { - ChainAssetLockProofWASM(chain_lock) + ChainAssetLockProofWasm(chain_lock) } } #[wasm_bindgen(js_class = ChainAssetLockProof)] -impl ChainAssetLockProofWASM { +impl ChainAssetLockProofWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "ChainAssetLockProof".to_string() @@ -43,9 +43,9 @@ impl ChainAssetLockProofWASM { #[wasm_bindgen(constructor)] pub fn new( core_chain_locked_height: u32, - out_point: &OutPointWASM, - ) -> Result { - Ok(ChainAssetLockProofWASM(ChainAssetLockProof { + out_point: &OutPointWasm, + ) -> Result { + Ok(ChainAssetLockProofWasm(ChainAssetLockProof { core_chain_locked_height, out_point: out_point.clone().into(), })) @@ -54,7 +54,7 @@ impl ChainAssetLockProofWASM { #[wasm_bindgen(js_name = "fromRawObject")] pub fn from_raw_value( raw_asset_lock_proof: JsValue, - ) -> Result { + ) -> Result { let parameters: ChainAssetLockProofParams = serde_wasm_bindgen::from_value(raw_asset_lock_proof) .map_err(|err| JsError::from(err))?; @@ -66,7 +66,7 @@ impl ChainAssetLockProofWASM { let rs_proof = ChainAssetLockProof::new(parameters.core_chain_locked_height, out_point); - Ok(ChainAssetLockProofWASM(rs_proof)) + Ok(ChainAssetLockProofWasm(rs_proof)) } #[wasm_bindgen(setter = "coreChainLockedHeight")] @@ -75,7 +75,7 @@ impl ChainAssetLockProofWASM { } #[wasm_bindgen(setter = "outPoint")] - pub fn set_out_point(&mut self, outpoint: &OutPointWASM) { + pub fn set_out_point(&mut self, outpoint: &OutPointWasm) { self.0.out_point = outpoint.clone().into(); } @@ -85,12 +85,12 @@ impl ChainAssetLockProofWASM { } #[wasm_bindgen(getter = "outPoint")] - pub fn get_out_point(self) -> OutPointWASM { + pub fn get_out_point(self) -> OutPointWasm { self.0.out_point.into() } #[wasm_bindgen(js_name = "createIdentityId")] - pub fn create_identifier(&self) -> IdentifierWASM { + pub fn create_identifier(&self) -> IdentifierWasm { let identifier = self.0.create_identifier(); identifier.into() diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs index e6bcb86f3ac..3e93acb8e31 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs @@ -1,4 +1,4 @@ -use crate::asset_lock_proof::outpoint::OutPointWASM; +use crate::asset_lock_proof::outpoint::OutPointWasm; use dpp::dashcore::bls_sig_utils::BLSSignature; use dpp::dashcore::hash_types::CycleHash; use dpp::dashcore::hashes::hex::FromHex; @@ -11,22 +11,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "InstantLock")] #[derive(Clone)] -pub struct InstantLockWASM(InstantLock); +pub struct InstantLockWasm(InstantLock); -impl From for InstantLock { - fn from(value: InstantLockWASM) -> Self { +impl From for InstantLock { + fn from(value: InstantLockWasm) -> Self { value.0 } } -impl From for InstantLockWASM { +impl From for InstantLockWasm { fn from(value: InstantLock) -> Self { - InstantLockWASM(value) + InstantLockWasm(value) } } #[wasm_bindgen(js_class = InstantLock)] -impl InstantLockWASM { +impl InstantLockWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "InstantLock".to_string() @@ -44,10 +44,10 @@ impl InstantLockWASM { txid: String, cycle_hash: String, bls_signature: String, - ) -> Result { - let inputs = OutPointWASM::vec_from_js_value(js_inputs)?; + ) -> Result { + let inputs = OutPointWasm::vec_from_js_value(js_inputs)?; - Ok(InstantLockWASM(InstantLock { + Ok(InstantLockWasm(InstantLock { version, inputs: inputs.iter().map(|input| input.clone().into()).collect(), txid: Txid::from_hex(&txid).map_err(|err| JsValue::from(err.to_string()))?, @@ -64,7 +64,7 @@ impl InstantLockWASM { } #[wasm_bindgen(getter = "inputs")] - pub fn get_inputs(&self) -> Vec { + pub fn get_inputs(&self) -> Vec { self.0 .inputs .iter() @@ -94,7 +94,7 @@ impl InstantLockWASM { #[wasm_bindgen(setter = "inputs")] pub fn set_inputs(&mut self, inputs: &js_sys::Array) -> Result<(), JsValue> { - let inputs = OutPointWASM::vec_from_js_value(inputs)?; + let inputs = OutPointWasm::vec_from_js_value(inputs)?; self.0.inputs = inputs.iter().map(|input| input.clone().into()).collect(); Ok(()) } diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs index 4f404fbf789..68573e447dd 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs @@ -1,9 +1,9 @@ mod instant_lock; -use crate::asset_lock_proof::instant::instant_lock::InstantLockWASM; -use crate::asset_lock_proof::outpoint::OutPointWASM; -use crate::asset_lock_proof::tx_out::TxOutWASM; -use crate::identifier::IdentifierWASM; +use crate::asset_lock_proof::instant::instant_lock::InstantLockWasm; +use crate::asset_lock_proof::outpoint::OutPointWasm; +use crate::asset_lock_proof::tx_out::TxOutWasm; +use crate::identifier::IdentifierWasm; use crate::utils::WithJsError; use dpp::dashcore::consensus::{deserialize, serialize}; use dpp::dashcore::{InstantLock, Transaction}; @@ -22,22 +22,22 @@ struct InstantAssetLockProofRAW { #[derive(Clone)] #[wasm_bindgen(js_name = "InstantAssetLockProof")] -pub struct InstantAssetLockProofWASM(InstantAssetLockProof); +pub struct InstantAssetLockProofWasm(InstantAssetLockProof); -impl From for InstantAssetLockProof { - fn from(proof: InstantAssetLockProofWASM) -> Self { +impl From for InstantAssetLockProof { + fn from(proof: InstantAssetLockProofWasm) -> Self { proof.0 } } -impl From for InstantAssetLockProofWASM { +impl From for InstantAssetLockProofWasm { fn from(proof: InstantAssetLockProof) -> Self { - InstantAssetLockProofWASM(proof) + InstantAssetLockProofWasm(proof) } } #[wasm_bindgen(js_class = InstantAssetLockProof)] -impl InstantAssetLockProofWASM { +impl InstantAssetLockProofWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "InstantAssetLockProof".to_string() @@ -53,13 +53,13 @@ impl InstantAssetLockProofWASM { instant_lock: Vec, transaction: Vec, output_index: u32, - ) -> Result { + ) -> Result { let instant_lock: InstantLock = deserialize(instant_lock.as_slice()).map_err(|err| JsValue::from(err.to_string()))?; let transaction: Transaction = deserialize(transaction.as_slice()).map_err(|err| JsValue::from(err.to_string()))?; - Ok(InstantAssetLockProofWASM(InstantAssetLockProof { + Ok(InstantAssetLockProofWasm(InstantAssetLockProof { instant_lock, transaction, output_index, @@ -67,11 +67,11 @@ impl InstantAssetLockProofWASM { } #[wasm_bindgen(js_name = "fromObject")] - pub fn from_object(value: JsValue) -> Result { + pub fn from_object(value: JsValue) -> Result { let parameters: InstantAssetLockProofRAW = serde_wasm_bindgen::from_value(value).map_err(|err| JsValue::from(err.to_string()))?; - InstantAssetLockProofWASM::new( + InstantAssetLockProofWasm::new( parameters.instant_lock, parameters.transaction, parameters.output_index, @@ -90,7 +90,7 @@ impl InstantAssetLockProofWASM { } #[wasm_bindgen(js_name = "getOutput")] - pub fn get_output(&self) -> Option { + pub fn get_output(&self) -> Option { match self.0.output() { Some(output) => Some(output.clone().into()), None => None, @@ -98,7 +98,7 @@ impl InstantAssetLockProofWASM { } #[wasm_bindgen(js_name = "getOutPoint")] - pub fn get_out_point(&self) -> Option { + pub fn get_out_point(&self) -> Option { match self.0.out_point() { Some(output) => Some(output.clone().into()), None => None, @@ -111,7 +111,7 @@ impl InstantAssetLockProofWASM { } #[wasm_bindgen(getter = "instantLock")] - pub fn get_instant_lock(&self) -> InstantLockWASM { + pub fn get_instant_lock(&self) -> InstantLockWasm { self.0.instant_lock.clone().into() } @@ -121,7 +121,7 @@ impl InstantAssetLockProofWASM { } #[wasm_bindgen(setter = "instantLock")] - pub fn set_instant_lock(&mut self, instant_lock: &InstantLockWASM) { + pub fn set_instant_lock(&mut self, instant_lock: &InstantLockWasm) { self.0.instant_lock = instant_lock.clone().into(); } @@ -138,7 +138,7 @@ impl InstantAssetLockProofWASM { } #[wasm_bindgen(js_name = "createIdentityId")] - pub fn create_identifier(&self) -> Result { + pub fn create_identifier(&self) -> Result { let identifier = self.0.create_identifier().with_js_error()?; Ok(identifier.into()) diff --git a/packages/wasm-dpp2/src/asset_lock_proof/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/mod.rs index 49f405c6366..23797039dfa 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/mod.rs @@ -3,12 +3,12 @@ pub mod instant; pub mod outpoint; mod tx_out; -use crate::asset_lock_proof::chain::ChainAssetLockProofWASM; -use crate::asset_lock_proof::instant::InstantAssetLockProofWASM; +use crate::asset_lock_proof::chain::ChainAssetLockProofWasm; +use crate::asset_lock_proof::instant::InstantAssetLockProofWasm; -use crate::asset_lock_proof::outpoint::OutPointWASM; -use crate::enums::lock_types::AssetLockProofTypeWASM; -use crate::identifier::IdentifierWASM; +use crate::asset_lock_proof::outpoint::OutPointWasm; +use crate::enums::lock_types::AssetLockProofTypeWasm; +use crate::identifier::IdentifierWasm; use crate::utils::{IntoWasm, WithJsError, get_class_type}; use dpp::prelude::AssetLockProof; use serde::Serialize; @@ -17,52 +17,52 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "AssetLockProof")] #[derive(Clone)] -pub struct AssetLockProofWASM(AssetLockProof); +pub struct AssetLockProofWasm(AssetLockProof); -impl From for AssetLockProof { - fn from(proof: AssetLockProofWASM) -> Self { +impl From for AssetLockProof { + fn from(proof: AssetLockProofWasm) -> Self { proof.0 } } -impl From for AssetLockProofWASM { +impl From for AssetLockProofWasm { fn from(proof: AssetLockProof) -> Self { - AssetLockProofWASM(proof) + AssetLockProofWasm(proof) } } -impl From for AssetLockProofWASM { - fn from(proof: ChainAssetLockProofWASM) -> Self { - AssetLockProofWASM(AssetLockProof::Chain(proof.into())) +impl From for AssetLockProofWasm { + fn from(proof: ChainAssetLockProofWasm) -> Self { + AssetLockProofWasm(AssetLockProof::Chain(proof.into())) } } -impl From for AssetLockProofWASM { - fn from(proof: InstantAssetLockProofWASM) -> Self { - AssetLockProofWASM(AssetLockProof::Instant(proof.into())) +impl From for AssetLockProofWasm { + fn from(proof: InstantAssetLockProofWasm) -> Self { + AssetLockProofWasm(AssetLockProof::Instant(proof.into())) } } -impl From for ChainAssetLockProofWASM { - fn from(proof: AssetLockProof) -> ChainAssetLockProofWASM { +impl From for ChainAssetLockProofWasm { + fn from(proof: AssetLockProof) -> ChainAssetLockProofWasm { match proof { - AssetLockProof::Chain(chain) => ChainAssetLockProofWASM::from(chain), + AssetLockProof::Chain(chain) => ChainAssetLockProofWasm::from(chain), _ => panic!("invalid asset lock proof. must contains chain lock"), } } } -impl From for InstantAssetLockProofWASM { - fn from(proof: AssetLockProof) -> InstantAssetLockProofWASM { +impl From for InstantAssetLockProofWasm { + fn from(proof: AssetLockProof) -> InstantAssetLockProofWasm { match proof { - AssetLockProof::Instant(instant) => InstantAssetLockProofWASM::from(instant), + AssetLockProof::Instant(instant) => InstantAssetLockProofWasm::from(instant), _ => panic!("invalid asset lock proof. must contains chain lock"), } } } #[wasm_bindgen(js_class = AssetLockProof)] -impl AssetLockProofWASM { +impl AssetLockProofWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "AssetLockProof".to_string() @@ -74,21 +74,21 @@ impl AssetLockProofWASM { } #[wasm_bindgen(constructor)] - pub fn new(js_asset_lock_proof: &JsValue) -> Result { + pub fn new(js_asset_lock_proof: &JsValue) -> Result { match get_class_type(js_asset_lock_proof)?.as_str() { "ChainAssetLockProof" => { let chain_lock = js_asset_lock_proof - .to_wasm::("ChainAssetLockProof")? + .to_wasm::("ChainAssetLockProof")? .clone(); - Ok(AssetLockProofWASM::from(chain_lock)) + Ok(AssetLockProofWasm::from(chain_lock)) } "InstantAssetLockProof" => { let instant_lock = js_asset_lock_proof - .to_wasm::("InstantAssetLockProof")? + .to_wasm::("InstantAssetLockProof")? .clone(); - Ok(AssetLockProofWASM::from(instant_lock)) + Ok(AssetLockProofWasm::from(instant_lock)) } &_ => Err(JsValue::from("Invalid asset lock proof type.")), } @@ -99,46 +99,46 @@ impl AssetLockProofWASM { instant_lock: Vec, transaction: Vec, output_index: u32, - ) -> Result { - Ok(InstantAssetLockProofWASM::new(instant_lock, transaction, output_index)?.into()) + ) -> Result { + Ok(InstantAssetLockProofWasm::new(instant_lock, transaction, output_index)?.into()) } #[wasm_bindgen(js_name = "createChainAssetLockProof")] pub fn new_chain_asset_lock_proof( core_chain_locked_height: u32, - out_point: &OutPointWASM, - ) -> Result { - Ok(ChainAssetLockProofWASM::new(core_chain_locked_height, out_point)?.into()) + out_point: &OutPointWasm, + ) -> Result { + Ok(ChainAssetLockProofWasm::new(core_chain_locked_height, out_point)?.into()) } #[wasm_bindgen(js_name = "getLockType")] pub fn get_lock_type(&self) -> String { match self.0 { - AssetLockProof::Chain(_) => AssetLockProofTypeWASM::Chain.into(), - AssetLockProof::Instant(_) => AssetLockProofTypeWASM::Instant.into(), + AssetLockProof::Chain(_) => AssetLockProofTypeWasm::Chain.into(), + AssetLockProof::Instant(_) => AssetLockProofTypeWasm::Instant.into(), } } #[wasm_bindgen(js_name = "getInstantLockProof")] - pub fn get_instant_lock(&self) -> InstantAssetLockProofWASM { + pub fn get_instant_lock(&self) -> InstantAssetLockProofWasm { self.clone().0.into() } #[wasm_bindgen(js_name = "getChainLockProof")] - pub fn get_chain_lock(&self) -> ChainAssetLockProofWASM { + pub fn get_chain_lock(&self) -> ChainAssetLockProofWasm { self.clone().0.into() } #[wasm_bindgen(js_name = "getOutPoint")] - pub fn get_out_point(&self) -> Option { + pub fn get_out_point(&self) -> Option { match self.0.out_point() { - Some(out_point) => Some(OutPointWASM::from(out_point)), + Some(out_point) => Some(OutPointWasm::from(out_point)), None => None, } } #[wasm_bindgen(js_name = "createIdentityId")] - pub fn create_identifier(&self) -> Result { + pub fn create_identifier(&self) -> Result { let identifier = self.0.create_identifier().with_js_error()?; Ok(identifier.into()) @@ -159,7 +159,7 @@ impl AssetLockProofWASM { } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(asset_lock_proof: String) -> Result { + pub fn from_hex(asset_lock_proof: String) -> Result { let asset_lock_proof_bytes = hex::decode(&asset_lock_proof) .map_err(|e| JsValue::from_str(&format!("Invalid asset lock proof hex: {}", e)))?; @@ -170,6 +170,6 @@ impl AssetLockProofWASM { JsValue::from_str(&format!("Failed to parse asset lock proof JSON: {}", e)) })?; - Ok(AssetLockProofWASM(asset_lock_proof)) + Ok(AssetLockProofWasm(asset_lock_proof)) } } diff --git a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs index b0eb14d8c23..b5b5312ac4a 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs @@ -7,31 +7,31 @@ use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "OutPoint")] #[derive(Clone)] -pub struct OutPointWASM(OutPoint); +pub struct OutPointWasm(OutPoint); -impl From for OutPointWASM { +impl From for OutPointWasm { fn from(outpoint: OutPoint) -> Self { - OutPointWASM(outpoint) + OutPointWasm(outpoint) } } -impl From for OutPoint { - fn from(outpoint: OutPointWASM) -> Self { +impl From for OutPoint { + fn from(outpoint: OutPointWasm) -> Self { outpoint.0 } } -impl TryFrom for OutPointWASM { +impl TryFrom for OutPointWasm { type Error = JsValue; fn try_from(value: JsValue) -> Result { - let value = value.to_wasm::("OutPoint")?; + let value = value.to_wasm::("OutPoint")?; Ok(value.clone()) } } #[wasm_bindgen(js_class = OutPoint)] -impl OutPointWASM { +impl OutPointWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "OutPoint".to_string() @@ -43,10 +43,10 @@ impl OutPointWASM { } #[wasm_bindgen(constructor)] - pub fn new(txid_hex: String, vout: u32) -> Result { + pub fn new(txid_hex: String, vout: u32) -> Result { let out_point = Txid::from_hex(&txid_hex).map_err(|err| JsValue::from(err.to_string()))?; - Ok(OutPointWASM(OutPoint { + Ok(OutPointWasm(OutPoint { txid: out_point, vout, })) @@ -83,36 +83,36 @@ impl OutPointWASM { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(js_buffer: Vec) -> OutPointWASM { + pub fn from_bytes(js_buffer: Vec) -> OutPointWasm { let mut buffer = [0u8; 36]; let bytes = js_buffer.as_slice(); let len = bytes.len(); buffer[..len].copy_from_slice(bytes); - OutPointWASM(OutPoint::from(buffer)) + OutPointWasm(OutPoint::from(buffer)) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - Ok(OutPointWASM::from_bytes( + pub fn from_hex(hex: String) -> Result { + Ok(OutPointWasm::from_bytes( decode(hex.as_str(), Hex).map_err(JsError::from)?, )) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - Ok(OutPointWASM::from_bytes( + pub fn from_base64(base64: String) -> Result { + Ok(OutPointWasm::from_bytes( decode(base64.as_str(), Base64).map_err(JsError::from)?, )) } } -impl OutPointWASM { - pub fn vec_from_js_value(js_outpoints: &js_sys::Array) -> Result, JsValue> { - let outpoints: Vec = js_outpoints +impl OutPointWasm { + pub fn vec_from_js_value(js_outpoints: &js_sys::Array) -> Result, JsValue> { + let outpoints: Vec = js_outpoints .iter() - .map(|key| OutPointWASM::try_from(key)) - .collect::, JsValue>>()?; + .map(|key| OutPointWasm::try_from(key)) + .collect::, JsValue>>()?; Ok(outpoints) } diff --git a/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs index c181776e223..343a5270a19 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs @@ -5,22 +5,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "TxOut")] #[derive(Clone)] -pub struct TxOutWASM(TxOut); +pub struct TxOutWasm(TxOut); -impl From for TxOutWASM { +impl From for TxOutWasm { fn from(value: TxOut) -> Self { - TxOutWASM(value) + TxOutWasm(value) } } -impl From for TxOut { - fn from(value: TxOutWASM) -> Self { +impl From for TxOut { + fn from(value: TxOutWasm) -> Self { value.0 } } #[wasm_bindgen(js_class = TxOut)] -impl TxOutWASM { +impl TxOutWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TxOut".to_string() @@ -32,7 +32,7 @@ impl TxOutWASM { } #[wasm_bindgen(constructor)] - pub fn new(value: u64, script_pubkey: JsValue) -> Result { + pub fn new(value: u64, script_pubkey: JsValue) -> Result { let tx_out: Result = match script_pubkey.is_array() { true => Ok(TxOut { value, @@ -48,7 +48,7 @@ impl TxOutWASM { }, }; - Ok(TxOutWASM(tx_out?)) + Ok(TxOutWasm(tx_out?)) } #[wasm_bindgen(getter = "value")] diff --git a/packages/wasm-dpp2/src/batch/batched_transition/mod.rs b/packages/wasm-dpp2/src/batch/batched_transition/mod.rs index bbbd88332e1..4af0bfadf8a 100644 --- a/packages/wasm-dpp2/src/batch/batched_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/batched_transition/mod.rs @@ -1,6 +1,6 @@ -use crate::batch::document_transition::DocumentTransitionWASM; -use crate::batch::token_transition::TokenTransitionWASM; -use crate::identifier::IdentifierWASM; +use crate::batch::document_transition::DocumentTransitionWasm; +use crate::batch::token_transition::TokenTransitionWasm; +use crate::identifier::IdentifierWasm; use crate::utils::{IntoWasm, get_class_type}; use dpp::state_transition::batch_transition::batched_transition::BatchedTransition; use dpp::state_transition::batch_transition::batched_transition::document_transition::{ @@ -14,22 +14,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=BatchedTransition)] -pub struct BatchedTransitionWASM(BatchedTransition); +pub struct BatchedTransitionWasm(BatchedTransition); -impl From for BatchedTransitionWASM { +impl From for BatchedTransitionWasm { fn from(v: BatchedTransition) -> Self { - BatchedTransitionWASM(v) + BatchedTransitionWasm(v) } } -impl From for BatchedTransition { - fn from(v: BatchedTransitionWASM) -> Self { +impl From for BatchedTransition { + fn from(v: BatchedTransitionWasm) -> Self { v.0 } } #[wasm_bindgen(js_class = BatchedTransition)] -impl BatchedTransitionWASM { +impl BatchedTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "BatchedTransition".to_string() @@ -41,21 +41,21 @@ impl BatchedTransitionWASM { } #[wasm_bindgen(constructor)] - pub fn new(js_transition: &JsValue) -> Result { + pub fn new(js_transition: &JsValue) -> Result { match js_transition.is_undefined() && js_transition.is_object() { true => Err(JsValue::from_str("transition is undefined")), false => match get_class_type(js_transition)?.as_str() { - "TokenTransition" => Ok(BatchedTransitionWASM::from(BatchedTransition::from( + "TokenTransition" => Ok(BatchedTransitionWasm::from(BatchedTransition::from( TokenTransition::from( js_transition - .to_wasm::("TokenTransition")? + .to_wasm::("TokenTransition")? .clone(), ), ))), - "DocumentTransition" => Ok(BatchedTransitionWASM(BatchedTransition::Document( + "DocumentTransition" => Ok(BatchedTransitionWasm(BatchedTransition::Document( DocumentTransition::from( js_transition - .to_wasm::("DocumentTransition")? + .to_wasm::("DocumentTransition")? .clone(), ), ))), @@ -68,16 +68,16 @@ impl BatchedTransitionWASM { pub fn to_transition(&self) -> JsValue { match &self.0 { BatchedTransition::Document(document_transition) => { - DocumentTransitionWASM::from(document_transition.clone()).into() + DocumentTransitionWasm::from(document_transition.clone()).into() } BatchedTransition::Token(token_transition) => { - TokenTransitionWASM::from(token_transition.clone()).into() + TokenTransitionWasm::from(token_transition.clone()).into() } } } #[wasm_bindgen(getter = "dataContractId")] - pub fn data_contract_id(&self) -> IdentifierWASM { + pub fn data_contract_id(&self) -> IdentifierWasm { match self.0.clone() { BatchedTransition::Document(document_transition) => { document_transition.data_contract_id().into() @@ -90,7 +90,7 @@ impl BatchedTransitionWASM { #[wasm_bindgen(setter = "dataContractId")] pub fn set_data_contract_id(&mut self, js_contract_id: &JsValue) -> Result<(), JsValue> { - let contract_id = IdentifierWASM::try_from(js_contract_id)?; + let contract_id = IdentifierWasm::try_from(js_contract_id)?; self.0 = match self.0.clone() { BatchedTransition::Document(mut document_transition) => { diff --git a/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs b/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs index 30c3ca6a802..8d6ebc7505f 100644 --- a/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs @@ -1,5 +1,5 @@ -use crate::batch::token_payment_info::TokenPaymentInfoWASM; -use crate::identifier::IdentifierWASM; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::identifier::IdentifierWasm; use crate::utils::IntoWasm; use dpp::prelude::IdentityNonce; use dpp::state_transition::batch_transition::document_base_transition::DocumentBaseTransition; @@ -12,22 +12,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] #[wasm_bindgen(js_name = "DocumentBaseTransition")] -pub struct DocumentBaseTransitionWASM(DocumentBaseTransition); +pub struct DocumentBaseTransitionWasm(DocumentBaseTransition); -impl From for DocumentBaseTransitionWASM { +impl From for DocumentBaseTransitionWasm { fn from(v: DocumentBaseTransition) -> Self { - DocumentBaseTransitionWASM(v) + DocumentBaseTransitionWasm(v) } } -impl From for DocumentBaseTransition { - fn from(v: DocumentBaseTransitionWASM) -> Self { +impl From for DocumentBaseTransition { + fn from(v: DocumentBaseTransitionWasm) -> Self { v.0 } } #[wasm_bindgen(js_class = DocumentBaseTransition)] -impl DocumentBaseTransitionWASM { +impl DocumentBaseTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "DocumentBaseTransition".to_string() @@ -45,33 +45,33 @@ impl DocumentBaseTransitionWASM { document_type_name: String, js_data_contract_id: &JsValue, js_token_payment_info: &JsValue, - ) -> Result { + ) -> Result { let token_payment_info: Option = match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfo")? + .to_wasm::("TokenPaymentInfo")? .clone() .into(), ), }; let rs_base_v1 = DocumentBaseTransitionV1 { - id: IdentifierWASM::try_from(js_document_id)?.into(), + id: IdentifierWasm::try_from(js_document_id)?.into(), identity_contract_nonce, document_type_name, - data_contract_id: IdentifierWASM::try_from(js_data_contract_id)?.into(), + data_contract_id: IdentifierWasm::try_from(js_data_contract_id)?.into(), token_payment_info, }; - Ok(DocumentBaseTransitionWASM(DocumentBaseTransition::from( + Ok(DocumentBaseTransitionWasm(DocumentBaseTransition::from( rs_base_v1, ))) } #[wasm_bindgen(getter = "id")] - pub fn get_id(&self) -> IdentifierWASM { + pub fn get_id(&self) -> IdentifierWasm { self.0.id().into() } @@ -81,7 +81,7 @@ impl DocumentBaseTransitionWASM { } #[wasm_bindgen(getter = "dataContractId")] - pub fn get_data_contract_id(&self) -> IdentifierWASM { + pub fn get_data_contract_id(&self) -> IdentifierWasm { self.0.data_contract_id().into() } @@ -91,7 +91,7 @@ impl DocumentBaseTransitionWASM { } #[wasm_bindgen(getter = "tokenPaymentInfo")] - pub fn get_token_payment_info(&self) -> Option { + pub fn get_token_payment_info(&self) -> Option { match self.0.token_payment_info() { None => None, Some(info) => Some(info.into()), @@ -100,7 +100,7 @@ impl DocumentBaseTransitionWASM { #[wasm_bindgen(setter = "id")] pub fn set_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { - self.0.set_id(IdentifierWASM::try_from(js_id)?.into()); + self.0.set_id(IdentifierWasm::try_from(js_id)?.into()); Ok(()) } @@ -112,7 +112,7 @@ impl DocumentBaseTransitionWASM { #[wasm_bindgen(setter = "dataContractId")] pub fn set_data_contract_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> { self.0 - .set_data_contract_id(IdentifierWASM::try_from(js_data_contract_id)?.into()); + .set_data_contract_id(IdentifierWasm::try_from(js_data_contract_id)?.into()); Ok(()) } @@ -122,7 +122,7 @@ impl DocumentBaseTransitionWASM { } #[wasm_bindgen(setter = "tokenPaymentInfo")] - pub fn set_token_payment_info(&mut self, token_payment_info: &TokenPaymentInfoWASM) { + pub fn set_token_payment_info(&mut self, token_payment_info: &TokenPaymentInfoWasm) { self.0 .set_token_payment_info(token_payment_info.clone().into()) } diff --git a/packages/wasm-dpp2/src/batch/document_transition/mod.rs b/packages/wasm-dpp2/src/batch/document_transition/mod.rs index b902f5169cd..c51c59eae68 100644 --- a/packages/wasm-dpp2/src/batch/document_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transition/mod.rs @@ -1,37 +1,37 @@ -use crate::batch::document_transitions::create::DocumentCreateTransitionWASM; -use crate::batch::document_transitions::delete::DocumentDeleteTransitionWASM; -use crate::batch::document_transitions::purchase::DocumentPurchaseTransitionWASM; -use crate::batch::document_transitions::replace::DocumentReplaceTransitionWASM; -use crate::batch::document_transitions::transfer::DocumentTransferTransitionWASM; -use crate::batch::document_transitions::update_price::DocumentUpdatePriceTransitionWASM; +use crate::batch::document_transitions::create::DocumentCreateTransitionWasm; +use crate::batch::document_transitions::delete::DocumentDeleteTransitionWasm; +use crate::batch::document_transitions::purchase::DocumentPurchaseTransitionWasm; +use crate::batch::document_transitions::replace::DocumentReplaceTransitionWasm; +use crate::batch::document_transitions::transfer::DocumentTransferTransitionWasm; +use crate::batch::document_transitions::update_price::DocumentUpdatePriceTransitionWasm; use dpp::prelude::{Identifier, IdentityNonce, Revision}; use dpp::state_transition::batch_transition::batched_transition::document_transition::{ DocumentTransition, DocumentTransitionV0Methods, }; use dpp::state_transition::batch_transition::batched_transition::document_transition_action_type::{DocumentTransitionActionType, DocumentTransitionActionTypeGetter}; -use crate::enums::batch::batch_enum::BatchTypeWASM; -use crate::identifier::IdentifierWASM; +use crate::enums::batch::batch_enum::BatchTypeWasm; +use crate::identifier::IdentifierWasm; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] #[wasm_bindgen(js_name = "DocumentTransition")] -pub struct DocumentTransitionWASM(DocumentTransition); +pub struct DocumentTransitionWasm(DocumentTransition); -impl From for DocumentTransitionWASM { +impl From for DocumentTransitionWasm { fn from(transition: DocumentTransition) -> Self { - DocumentTransitionWASM(transition) + DocumentTransitionWasm(transition) } } -impl From for DocumentTransition { - fn from(transition: DocumentTransitionWASM) -> Self { +impl From for DocumentTransition { + fn from(transition: DocumentTransitionWasm) -> Self { transition.0 } } #[wasm_bindgen(js_class = DocumentTransition)] -impl DocumentTransitionWASM { +impl DocumentTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "DocumentTransition".to_string() @@ -44,7 +44,7 @@ impl DocumentTransitionWASM { #[wasm_bindgen(getter = "actionType")] pub fn get_action_type(&self) -> String { - BatchTypeWASM::from(self.0.action_type()).into() + BatchTypeWasm::from(self.0.action_type()).into() } #[wasm_bindgen(getter = "actionTypeNumber")] @@ -61,12 +61,12 @@ impl DocumentTransitionWASM { } #[wasm_bindgen(getter = "dataContractId")] - pub fn get_data_contract_id(&self) -> IdentifierWASM { + pub fn get_data_contract_id(&self) -> IdentifierWasm { self.0.data_contract_id().into() } #[wasm_bindgen(getter = "id")] - pub fn get_id(&self) -> IdentifierWASM { + pub fn get_id(&self) -> IdentifierWasm { self.0.get_id().into() } @@ -91,46 +91,46 @@ impl DocumentTransitionWASM { } #[wasm_bindgen(getter = "createTransition")] - pub fn get_create_transition(&self) -> Result { + pub fn get_create_transition(&self) -> Result { match self.0.clone() { - DocumentTransition::Create(create) => Ok(DocumentCreateTransitionWASM::from(create)), + DocumentTransition::Create(create) => Ok(DocumentCreateTransitionWasm::from(create)), _ => Err(JsValue::undefined()), } } #[wasm_bindgen(getter = "replaceTransition")] - pub fn get_replace_transition(&self) -> Result { + pub fn get_replace_transition(&self) -> Result { match self.0.clone() { DocumentTransition::Replace(replace) => { - Ok(DocumentReplaceTransitionWASM::from(replace)) + Ok(DocumentReplaceTransitionWasm::from(replace)) } _ => Err(JsValue::undefined()), } } #[wasm_bindgen(getter = "deleteTransition")] - pub fn get_delete_transition(&self) -> Result { + pub fn get_delete_transition(&self) -> Result { match self.0.clone() { - DocumentTransition::Delete(delete) => Ok(DocumentDeleteTransitionWASM::from(delete)), + DocumentTransition::Delete(delete) => Ok(DocumentDeleteTransitionWasm::from(delete)), _ => Err(JsValue::undefined()), } } #[wasm_bindgen(getter = "purchaseTransition")] - pub fn get_purchase_transition(&self) -> Result { + pub fn get_purchase_transition(&self) -> Result { match self.0.clone() { DocumentTransition::Purchase(purchase) => { - Ok(DocumentPurchaseTransitionWASM::from(purchase)) + Ok(DocumentPurchaseTransitionWasm::from(purchase)) } _ => Err(JsValue::undefined()), } } #[wasm_bindgen(getter = "transferTransition")] - pub fn get_transfer_transition(&self) -> Result { + pub fn get_transfer_transition(&self) -> Result { match self.0.clone() { DocumentTransition::Transfer(transfer) => { - Ok(DocumentTransferTransitionWASM::from(transfer)) + Ok(DocumentTransferTransitionWasm::from(transfer)) } _ => Err(JsValue::undefined()), } @@ -139,10 +139,10 @@ impl DocumentTransitionWASM { #[wasm_bindgen(getter = "updatePriceTransition")] pub fn get_update_price_transition( &self, - ) -> Result { + ) -> Result { match self.0.clone() { DocumentTransition::UpdatePrice(update_price) => { - Ok(DocumentUpdatePriceTransitionWASM::from(update_price)) + Ok(DocumentUpdatePriceTransitionWasm::from(update_price)) } _ => Err(JsValue::undefined()), } @@ -152,7 +152,7 @@ impl DocumentTransitionWASM { pub fn set_data_contract_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> { Ok(self .0 - .set_data_contract_id(IdentifierWASM::try_from(js_data_contract_id)?.into())) + .set_data_contract_id(IdentifierWasm::try_from(js_data_contract_id)?.into())) } #[wasm_bindgen(setter = "revision")] @@ -166,7 +166,7 @@ impl DocumentTransitionWASM { } } -impl DocumentTransitionWASM { +impl DocumentTransitionWasm { pub fn rs_get_data_contract_id(&self) -> Identifier { self.0.data_contract_id() } diff --git a/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs index e8ae89c1f2e..bbe8a7f41e2 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs @@ -1,5 +1,5 @@ -use crate::batch::document_base_transition::DocumentBaseTransitionWASM; -use crate::batch::document_transition::DocumentTransitionWASM; +use crate::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::batch::document_transition::DocumentTransitionWasm; use crate::batch::generators::generate_create_transition; use dpp::dashcore::hashes::serde::Serialize; use dpp::prelude::IdentityNonce; @@ -7,31 +7,31 @@ use dpp::state_transition::batch_transition::batched_transition::document_transi use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; use dpp::state_transition::batch_transition::document_create_transition::v0::v0_methods::DocumentCreateTransitionV0Methods; use dpp::state_transition::batch_transition::DocumentCreateTransition; -use crate::document::DocumentWASM; +use crate::document::DocumentWasm; use crate::utils::{IntoWasm, ToSerdeJSONExt}; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::batch::prefunded_voting_balance::PrefundedVotingBalanceWASM; -use crate::batch::token_payment_info::TokenPaymentInfoWASM; +use crate::batch::prefunded_voting_balance::PrefundedVotingBalanceWasm; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; #[wasm_bindgen(js_name = "DocumentCreateTransition")] #[derive(Clone)] -pub struct DocumentCreateTransitionWASM(DocumentCreateTransition); +pub struct DocumentCreateTransitionWasm(DocumentCreateTransition); -impl From for DocumentCreateTransition { - fn from(transition: DocumentCreateTransitionWASM) -> Self { +impl From for DocumentCreateTransition { + fn from(transition: DocumentCreateTransitionWasm) -> Self { transition.0 } } -impl From for DocumentCreateTransitionWASM { +impl From for DocumentCreateTransitionWasm { fn from(transition: DocumentCreateTransition) -> Self { - DocumentCreateTransitionWASM(transition) + DocumentCreateTransitionWasm(transition) } } #[wasm_bindgen(js_class = DocumentCreateTransition)] -impl DocumentCreateTransitionWASM { +impl DocumentCreateTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "DocumentCreateTransition".to_string() @@ -44,18 +44,18 @@ impl DocumentCreateTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - document: &DocumentWASM, + document: &DocumentWasm, identity_contract_nonce: IdentityNonce, js_prefunded_voting_balance: &JsValue, js_token_payment_info: &JsValue, - ) -> Result { + ) -> Result { let prefunded_voting_balance = match js_prefunded_voting_balance.is_undefined() | js_prefunded_voting_balance.is_null() { true => None, false => Some( js_prefunded_voting_balance - .to_wasm::("PrefundedVotingBalance")? + .to_wasm::("PrefundedVotingBalance")? .clone(), ), }; @@ -65,7 +65,7 @@ impl DocumentCreateTransitionWASM { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfo")? + .to_wasm::("TokenPaymentInfo")? .clone(), ), }; @@ -78,7 +78,7 @@ impl DocumentCreateTransitionWASM { token_payment_info, ); - Ok(DocumentCreateTransitionWASM(rs_create_transition)) + Ok(DocumentCreateTransitionWasm(rs_create_transition)) } #[wasm_bindgen(getter = "data")] @@ -89,7 +89,7 @@ impl DocumentCreateTransitionWASM { } #[wasm_bindgen(getter = "base")] - pub fn get_base(&self) -> DocumentBaseTransitionWASM { + pub fn get_base(&self) -> DocumentBaseTransitionWasm { self.0.base().clone().into() } @@ -106,7 +106,7 @@ impl DocumentCreateTransitionWASM { } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) { + pub fn set_base(&mut self, base: &DocumentBaseTransitionWasm) { self.0.set_base(base.clone().into()) } @@ -121,7 +121,7 @@ impl DocumentCreateTransitionWASM { } #[wasm_bindgen(getter = "prefundedVotingBalance")] - pub fn get_prefunded_voting_balance(&self) -> Option { + pub fn get_prefunded_voting_balance(&self) -> Option { let rs_balance = self.0.prefunded_voting_balance(); match rs_balance { @@ -133,7 +133,7 @@ impl DocumentCreateTransitionWASM { #[wasm_bindgen(setter = "prefundedVotingBalance")] pub fn set_prefunded_voting_balance( &mut self, - prefunded_voting_balance: &PrefundedVotingBalanceWASM, + prefunded_voting_balance: &PrefundedVotingBalanceWasm, ) { self.0.set_prefunded_voting_balance( prefunded_voting_balance.index_name(), @@ -147,16 +147,16 @@ impl DocumentCreateTransitionWASM { } #[wasm_bindgen(js_name = "toDocumentTransition")] - pub fn to_document_transition(&self) -> DocumentTransitionWASM { + pub fn to_document_transition(&self) -> DocumentTransitionWasm { let rs_transition = DocumentTransition::from(self.0.clone()); - DocumentTransitionWASM::from(rs_transition) + DocumentTransitionWasm::from(rs_transition) } #[wasm_bindgen(js_name = "fromDocumentTransition")] pub fn from_document_transition( - js_transition: DocumentTransitionWASM, - ) -> Result { + js_transition: DocumentTransitionWasm, + ) -> Result { js_transition.get_create_transition() } } diff --git a/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs index ad8cb8e41a1..1e369af7045 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs @@ -1,27 +1,27 @@ -use crate::batch::document_base_transition::DocumentBaseTransitionWASM; -use crate::batch::document_transition::DocumentTransitionWASM; +use crate::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::batch::document_transition::DocumentTransitionWasm; use crate::batch::generators::generate_delete_transition; use dpp::prelude::IdentityNonce; use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; use dpp::state_transition::batch_transition::DocumentDeleteTransition; -use crate::document::DocumentWASM; +use crate::document::DocumentWasm; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; use crate::utils::IntoWasm; -use crate::batch::token_payment_info::TokenPaymentInfoWASM; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; #[wasm_bindgen(js_name = "DocumentDeleteTransition")] -pub struct DocumentDeleteTransitionWASM(DocumentDeleteTransition); +pub struct DocumentDeleteTransitionWasm(DocumentDeleteTransition); -impl From for DocumentDeleteTransitionWASM { +impl From for DocumentDeleteTransitionWasm { fn from(document_delete_transition: DocumentDeleteTransition) -> Self { - DocumentDeleteTransitionWASM(document_delete_transition) + DocumentDeleteTransitionWasm(document_delete_transition) } } #[wasm_bindgen(js_class = DocumentDeleteTransition)] -impl DocumentDeleteTransitionWASM { +impl DocumentDeleteTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "DocumentDeleteTransition".to_string() @@ -34,16 +34,16 @@ impl DocumentDeleteTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - document: &DocumentWASM, + document: &DocumentWasm, identity_contract_nonce: IdentityNonce, js_token_payment_info: &JsValue, - ) -> Result { + ) -> Result { let token_payment_info = match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfo")? + .to_wasm::("TokenPaymentInfo")? .clone(), ), }; @@ -55,36 +55,36 @@ impl DocumentDeleteTransitionWASM { token_payment_info, ); - Ok(DocumentDeleteTransitionWASM(rs_delete_transition)) + Ok(DocumentDeleteTransitionWasm(rs_delete_transition)) } #[wasm_bindgen(getter = "base")] - pub fn get_base(&self) -> DocumentBaseTransitionWASM { + pub fn get_base(&self) -> DocumentBaseTransitionWasm { self.0.base().clone().into() } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) { + pub fn set_base(&mut self, base: &DocumentBaseTransitionWasm) { self.0.set_base(base.clone().into()) } #[wasm_bindgen(js_name = "toDocumentTransition")] - pub fn to_document_transition(&self) -> DocumentTransitionWASM { + pub fn to_document_transition(&self) -> DocumentTransitionWasm { let rs_transition = DocumentTransition::from(self.0.clone()); - DocumentTransitionWASM::from(rs_transition) + DocumentTransitionWasm::from(rs_transition) } #[wasm_bindgen(js_name = "fromDocumentTransition")] pub fn from_document_transition( - js_transition: DocumentTransitionWASM, - ) -> Result { + js_transition: DocumentTransitionWasm, + ) -> Result { js_transition.get_delete_transition() } } -impl From for DocumentDeleteTransition { - fn from(document_delete_transition: DocumentDeleteTransitionWASM) -> Self { +impl From for DocumentDeleteTransition { + fn from(document_delete_transition: DocumentDeleteTransitionWasm) -> Self { document_delete_transition.0 } } diff --git a/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs index fc5f941a05e..4379b817e1e 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs @@ -6,30 +6,30 @@ use dpp::state_transition::batch_transition::batched_transition::DocumentPurchas use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::document::DocumentWASM; +use crate::document::DocumentWasm; use crate::utils::IntoWasm; -use crate::batch::document_base_transition::DocumentBaseTransitionWASM; -use crate::batch::document_transition::DocumentTransitionWASM; +use crate::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::batch::document_transition::DocumentTransitionWasm; use crate::batch::generators::generate_purchase_transition; -use crate::batch::token_payment_info::TokenPaymentInfoWASM; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; #[wasm_bindgen(js_name = "DocumentPurchaseTransition")] -pub struct DocumentPurchaseTransitionWASM(DocumentPurchaseTransition); +pub struct DocumentPurchaseTransitionWasm(DocumentPurchaseTransition); -impl From for DocumentPurchaseTransition { - fn from(transition: DocumentPurchaseTransitionWASM) -> Self { +impl From for DocumentPurchaseTransition { + fn from(transition: DocumentPurchaseTransitionWasm) -> Self { transition.0 } } -impl From for DocumentPurchaseTransitionWASM { +impl From for DocumentPurchaseTransitionWasm { fn from(transition: DocumentPurchaseTransition) -> Self { - DocumentPurchaseTransitionWASM(transition) + DocumentPurchaseTransitionWasm(transition) } } #[wasm_bindgen(js_class = DocumentPurchaseTransition)] -impl DocumentPurchaseTransitionWASM { +impl DocumentPurchaseTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "DocumentPurchaseTransition".to_string() @@ -42,17 +42,17 @@ impl DocumentPurchaseTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - document: &DocumentWASM, + document: &DocumentWasm, identity_contract_nonce: IdentityNonce, amount: Credits, js_token_payment_info: &JsValue, - ) -> Result { + ) -> Result { let token_payment_info = match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfo")? + .to_wasm::("TokenPaymentInfo")? .clone(), ), }; @@ -65,11 +65,11 @@ impl DocumentPurchaseTransitionWASM { token_payment_info, ); - Ok(DocumentPurchaseTransitionWASM(rs_purchase_transition)) + Ok(DocumentPurchaseTransitionWasm(rs_purchase_transition)) } #[wasm_bindgen(getter = "base")] - pub fn get_base(&self) -> DocumentBaseTransitionWASM { + pub fn get_base(&self) -> DocumentBaseTransitionWasm { self.0.base().clone().into() } @@ -84,7 +84,7 @@ impl DocumentPurchaseTransitionWASM { } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) { + pub fn set_base(&mut self, base: &DocumentBaseTransitionWasm) { self.0.set_base(base.clone().into()) } @@ -101,16 +101,16 @@ impl DocumentPurchaseTransitionWASM { } #[wasm_bindgen(js_name = "toDocumentTransition")] - pub fn to_document_transition(&self) -> DocumentTransitionWASM { + pub fn to_document_transition(&self) -> DocumentTransitionWasm { let rs_transition = DocumentTransition::from(self.0.clone()); - DocumentTransitionWASM::from(rs_transition) + DocumentTransitionWasm::from(rs_transition) } #[wasm_bindgen(js_name = "fromDocumentTransition")] pub fn from_document_transition( - js_transition: DocumentTransitionWASM, - ) -> Result { + js_transition: DocumentTransitionWasm, + ) -> Result { js_transition.get_purchase_transition() } } diff --git a/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs index 15a570e9bc4..f097282ee01 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs @@ -6,30 +6,30 @@ use dpp::state_transition::batch_transition::document_replace_transition::v0::v0 use dpp::state_transition::batch_transition::DocumentReplaceTransition; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::document::DocumentWASM; +use crate::document::DocumentWasm; use crate::utils::{IntoWasm, ToSerdeJSONExt}; -use crate::batch::document_base_transition::DocumentBaseTransitionWASM; +use crate::batch::document_base_transition::DocumentBaseTransitionWasm; use crate::batch::generators::generate_replace_transition; -use crate::batch::document_transition::DocumentTransitionWASM; -use crate::batch::token_payment_info::TokenPaymentInfoWASM; +use crate::batch::document_transition::DocumentTransitionWasm; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; #[wasm_bindgen(js_name = "DocumentReplaceTransition")] -pub struct DocumentReplaceTransitionWASM(DocumentReplaceTransition); +pub struct DocumentReplaceTransitionWasm(DocumentReplaceTransition); -impl From for DocumentReplaceTransitionWASM { +impl From for DocumentReplaceTransitionWasm { fn from(document_replace: DocumentReplaceTransition) -> Self { - DocumentReplaceTransitionWASM(document_replace) + DocumentReplaceTransitionWasm(document_replace) } } -impl From for DocumentReplaceTransition { - fn from(document_replace: DocumentReplaceTransitionWASM) -> Self { +impl From for DocumentReplaceTransition { + fn from(document_replace: DocumentReplaceTransitionWasm) -> Self { document_replace.0 } } #[wasm_bindgen(js_class = DocumentReplaceTransition)] -impl DocumentReplaceTransitionWASM { +impl DocumentReplaceTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "DocumentReplaceTransition".to_string() @@ -42,16 +42,16 @@ impl DocumentReplaceTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - document: &DocumentWASM, + document: &DocumentWasm, identity_contract_nonce: IdentityNonce, js_token_payment_info: &JsValue, - ) -> Result { + ) -> Result { let token_payment_info = match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfo")? + .to_wasm::("TokenPaymentInfo")? .clone(), ), }; @@ -63,7 +63,7 @@ impl DocumentReplaceTransitionWASM { token_payment_info, ); - Ok(DocumentReplaceTransitionWASM(rs_update_transition)) + Ok(DocumentReplaceTransitionWasm(rs_update_transition)) } #[wasm_bindgen(getter = "data")] @@ -74,7 +74,7 @@ impl DocumentReplaceTransitionWASM { } #[wasm_bindgen(getter = "base")] - pub fn get_base(&self) -> DocumentBaseTransitionWASM { + pub fn get_base(&self) -> DocumentBaseTransitionWasm { self.0.base().clone().into() } @@ -91,7 +91,7 @@ impl DocumentReplaceTransitionWASM { } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) { + pub fn set_base(&mut self, base: &DocumentBaseTransitionWasm) { self.0.set_base(base.clone().into()) } @@ -101,16 +101,16 @@ impl DocumentReplaceTransitionWASM { } #[wasm_bindgen(js_name = "toDocumentTransition")] - pub fn to_document_transition(&self) -> DocumentTransitionWASM { + pub fn to_document_transition(&self) -> DocumentTransitionWasm { let rs_transition = DocumentTransition::from(self.0.clone()); - DocumentTransitionWASM::from(rs_transition) + DocumentTransitionWasm::from(rs_transition) } #[wasm_bindgen(js_name = "fromDocumentTransition")] pub fn from_document_transition( - js_transition: DocumentTransitionWASM, - ) -> Result { + js_transition: DocumentTransitionWasm, + ) -> Result { js_transition.get_replace_transition() } } diff --git a/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs index f817b0a95d5..a8a9c98c1fc 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs @@ -5,31 +5,31 @@ use dpp::state_transition::batch_transition::batched_transition::DocumentTransfe use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::document::DocumentWASM; -use crate::identifier::IdentifierWASM; +use crate::document::DocumentWasm; +use crate::identifier::IdentifierWasm; use crate::utils::IntoWasm; -use crate::batch::document_base_transition::DocumentBaseTransitionWASM; -use crate::batch::document_transition::DocumentTransitionWASM; +use crate::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::batch::document_transition::DocumentTransitionWasm; use crate::batch::generators::generate_transfer_transition; -use crate::batch::token_payment_info::TokenPaymentInfoWASM; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; #[wasm_bindgen(js_name = "DocumentTransferTransition")] -pub struct DocumentTransferTransitionWASM(DocumentTransferTransition); +pub struct DocumentTransferTransitionWasm(DocumentTransferTransition); -impl From for DocumentTransferTransitionWASM { +impl From for DocumentTransferTransitionWasm { fn from(transition: DocumentTransferTransition) -> Self { - DocumentTransferTransitionWASM(transition) + DocumentTransferTransitionWasm(transition) } } -impl From for DocumentTransferTransition { - fn from(transition: DocumentTransferTransitionWASM) -> Self { +impl From for DocumentTransferTransition { + fn from(transition: DocumentTransferTransitionWasm) -> Self { transition.0 } } #[wasm_bindgen(js_class = DocumentTransferTransition)] -impl DocumentTransferTransitionWASM { +impl DocumentTransferTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "DocumentTransferTransition".to_string() @@ -42,17 +42,17 @@ impl DocumentTransferTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - document: &DocumentWASM, + document: &DocumentWasm, identity_contract_nonce: IdentityNonce, js_recipient_owner_id: &JsValue, js_token_payment_info: &JsValue, - ) -> Result { + ) -> Result { let token_payment_info = match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfo")? + .to_wasm::("TokenPaymentInfo")? .clone(), ), }; @@ -61,25 +61,25 @@ impl DocumentTransferTransitionWASM { document.clone(), identity_contract_nonce, document.get_document_type_name().to_string(), - IdentifierWASM::try_from(js_recipient_owner_id)?.into(), + IdentifierWasm::try_from(js_recipient_owner_id)?.into(), token_payment_info, ); - Ok(DocumentTransferTransitionWASM(rs_transfer_transition)) + Ok(DocumentTransferTransitionWasm(rs_transfer_transition)) } #[wasm_bindgen(getter = "base")] - pub fn get_base(&self) -> DocumentBaseTransitionWASM { + pub fn get_base(&self) -> DocumentBaseTransitionWasm { self.0.base().clone().into() } #[wasm_bindgen(getter = "recipientId")] - pub fn get_recipient_owner_id(&self) -> IdentifierWASM { + pub fn get_recipient_owner_id(&self) -> IdentifierWasm { self.0.recipient_owner_id().into() } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) { + pub fn set_base(&mut self, base: &DocumentBaseTransitionWasm) { self.0.set_base(base.clone().into()) } @@ -89,21 +89,21 @@ impl DocumentTransferTransitionWASM { js_recipient_owner_id: &JsValue, ) -> Result<(), JsValue> { self.0 - .set_recipient_owner_id(IdentifierWASM::try_from(js_recipient_owner_id)?.into()); + .set_recipient_owner_id(IdentifierWasm::try_from(js_recipient_owner_id)?.into()); Ok(()) } #[wasm_bindgen(js_name = "toDocumentTransition")] - pub fn to_document_transition(&self) -> DocumentTransitionWASM { + pub fn to_document_transition(&self) -> DocumentTransitionWasm { let rs_transition = DocumentTransition::from(self.0.clone()); - DocumentTransitionWASM::from(rs_transition) + DocumentTransitionWasm::from(rs_transition) } #[wasm_bindgen(js_name = "fromDocumentTransition")] pub fn from_document_transition( - js_transition: DocumentTransitionWASM, - ) -> Result { + js_transition: DocumentTransitionWasm, + ) -> Result { js_transition.get_transfer_transition() } } diff --git a/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs index 3e5eb458d72..c15cc85138e 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs @@ -6,24 +6,24 @@ use dpp::state_transition::batch_transition::batched_transition::DocumentUpdateP use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::document::DocumentWASM; +use crate::document::DocumentWasm; use crate::utils::IntoWasm; -use crate::batch::document_base_transition::DocumentBaseTransitionWASM; -use crate::batch::document_transition::DocumentTransitionWASM; +use crate::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::batch::document_transition::DocumentTransitionWasm; use crate::batch::generators::generate_update_price_transition; -use crate::batch::token_payment_info::TokenPaymentInfoWASM; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; #[wasm_bindgen(js_name = "DocumentUpdatePriceTransition")] -pub struct DocumentUpdatePriceTransitionWASM(DocumentUpdatePriceTransition); +pub struct DocumentUpdatePriceTransitionWasm(DocumentUpdatePriceTransition); -impl From for DocumentUpdatePriceTransitionWASM { +impl From for DocumentUpdatePriceTransitionWasm { fn from(document_update_price_transition: DocumentUpdatePriceTransition) -> Self { - DocumentUpdatePriceTransitionWASM(document_update_price_transition) + DocumentUpdatePriceTransitionWasm(document_update_price_transition) } } #[wasm_bindgen(js_class = DocumentUpdatePriceTransition)] -impl DocumentUpdatePriceTransitionWASM { +impl DocumentUpdatePriceTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "DocumentUpdatePriceTransition".to_string() @@ -36,17 +36,17 @@ impl DocumentUpdatePriceTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - document: &DocumentWASM, + document: &DocumentWasm, identity_contract_nonce: IdentityNonce, price: Credits, js_token_payment_info: &JsValue, - ) -> Result { + ) -> Result { let token_payment_info = match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { true => None, false => Some( js_token_payment_info - .to_wasm::("TokenPaymentInfo")? + .to_wasm::("TokenPaymentInfo")? .clone(), ), }; @@ -59,13 +59,13 @@ impl DocumentUpdatePriceTransitionWASM { token_payment_info, ); - Ok(DocumentUpdatePriceTransitionWASM( + Ok(DocumentUpdatePriceTransitionWasm( rs_document_update_price_transition, )) } #[wasm_bindgen(getter = "base")] - pub fn get_base(&self) -> DocumentBaseTransitionWASM { + pub fn get_base(&self) -> DocumentBaseTransitionWasm { self.0.base().clone().into() } @@ -75,7 +75,7 @@ impl DocumentUpdatePriceTransitionWASM { } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) { + pub fn set_base(&mut self, base: &DocumentBaseTransitionWasm) { self.0.set_base(base.clone().into()) } @@ -85,16 +85,16 @@ impl DocumentUpdatePriceTransitionWASM { } #[wasm_bindgen(js_name = "toDocumentTransition")] - pub fn to_document_transition(&self) -> DocumentTransitionWASM { + pub fn to_document_transition(&self) -> DocumentTransitionWasm { let rs_transition = DocumentTransition::from(self.0.clone()); - DocumentTransitionWASM::from(rs_transition) + DocumentTransitionWasm::from(rs_transition) } #[wasm_bindgen(js_name = "fromDocumentTransition")] pub fn from_document_transition( - js_transition: DocumentTransitionWASM, - ) -> Result { + js_transition: DocumentTransitionWasm, + ) -> Result { js_transition.get_update_price_transition() } } diff --git a/packages/wasm-dpp2/src/batch/generators.rs b/packages/wasm-dpp2/src/batch/generators.rs index 99d282f74ff..d9cc2e00b9e 100644 --- a/packages/wasm-dpp2/src/batch/generators.rs +++ b/packages/wasm-dpp2/src/batch/generators.rs @@ -1,6 +1,6 @@ -use crate::batch::prefunded_voting_balance::PrefundedVotingBalanceWASM; -use crate::batch::token_payment_info::TokenPaymentInfoWASM; -use crate::document::DocumentWASM; +use crate::batch::prefunded_voting_balance::PrefundedVotingBalanceWasm; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::document::DocumentWasm; use dpp::fee::Credits; use dpp::prelude::{Identifier, IdentityNonce}; use dpp::state_transition::batch_transition::batched_transition::document_purchase_transition::DocumentPurchaseTransitionV0; @@ -20,11 +20,11 @@ use dpp::state_transition::batch_transition::{ use dpp::tokens::token_payment_info::TokenPaymentInfo; pub fn generate_create_transition( - document: DocumentWASM, + document: DocumentWasm, identity_contract_nonce: IdentityNonce, document_type_name: String, - prefunded_voting_balance: Option, - token_payment_info: Option, + prefunded_voting_balance: Option, + token_payment_info: Option, ) -> DocumentCreateTransition { DocumentCreateTransition::V0(DocumentCreateTransitionV0 { base: DocumentBaseTransition::V1(DocumentBaseTransitionV1 { @@ -41,10 +41,10 @@ pub fn generate_create_transition( } pub fn generate_delete_transition( - document: DocumentWASM, + document: DocumentWasm, identity_contract_nonce: IdentityNonce, document_type_name: String, - token_payment_info: Option, + token_payment_info: Option, ) -> DocumentDeleteTransition { DocumentDeleteTransition::V0(DocumentDeleteTransitionV0 { base: DocumentBaseTransition::V1(DocumentBaseTransitionV1 { @@ -58,10 +58,10 @@ pub fn generate_delete_transition( } pub fn generate_replace_transition( - document: DocumentWASM, + document: DocumentWasm, identity_contract_nonce: IdentityNonce, document_type_name: String, - token_payment_info: Option, + token_payment_info: Option, ) -> DocumentReplaceTransition { DocumentReplaceTransition::V0(DocumentReplaceTransitionV0 { base: DocumentBaseTransition::V1(DocumentBaseTransitionV1 { @@ -77,11 +77,11 @@ pub fn generate_replace_transition( } pub fn generate_transfer_transition( - document: DocumentWASM, + document: DocumentWasm, identity_contract_nonce: IdentityNonce, document_type_name: String, recipient_owner_id: Identifier, - token_payment_info: Option, + token_payment_info: Option, ) -> DocumentTransferTransition { DocumentTransferTransition::V0(DocumentTransferTransitionV0 { base: DocumentBaseTransition::V1(DocumentBaseTransitionV1 { @@ -97,11 +97,11 @@ pub fn generate_transfer_transition( } pub fn generate_update_price_transition( - document: DocumentWASM, + document: DocumentWasm, identity_contract_nonce: IdentityNonce, document_type_name: String, price: Credits, - token_payment_info: Option, + token_payment_info: Option, ) -> DocumentUpdatePriceTransition { DocumentUpdatePriceTransition::V0(DocumentUpdatePriceTransitionV0 { base: DocumentBaseTransition::V1(DocumentBaseTransitionV1 { @@ -117,11 +117,11 @@ pub fn generate_update_price_transition( } pub fn generate_purchase_transition( - document: DocumentWASM, + document: DocumentWasm, identity_contract_nonce: IdentityNonce, document_type_name: String, price: Credits, - token_payment_info: Option, + token_payment_info: Option, ) -> DocumentPurchaseTransition { DocumentPurchaseTransition::V0(DocumentPurchaseTransitionV0 { base: DocumentBaseTransition::V1(DocumentBaseTransitionV1 { diff --git a/packages/wasm-dpp2/src/batch/mod.rs b/packages/wasm-dpp2/src/batch/mod.rs index ed1be88be55..acb8c3afc18 100644 --- a/packages/wasm-dpp2/src/batch/mod.rs +++ b/packages/wasm-dpp2/src/batch/mod.rs @@ -1,7 +1,7 @@ -use crate::batch::batched_transition::BatchedTransitionWASM; -use crate::batch::document_transition::DocumentTransitionWASM; -use crate::identifier::IdentifierWASM; -use crate::state_transition::StateTransitionWASM; +use crate::batch::batched_transition::BatchedTransitionWasm; +use crate::batch::document_transition::DocumentTransitionWasm; +use crate::identifier::IdentifierWasm; +use crate::state_transition::StateTransitionWasm; use crate::utils::{IntoWasm, WithJsError}; use dpp::fee::Credits; use dpp::identity::KeyID; @@ -35,16 +35,16 @@ pub mod token_transitions; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=BatchTransition)] -pub struct BatchTransitionWASM(BatchTransition); +pub struct BatchTransitionWasm(BatchTransition); -impl From for BatchTransitionWASM { +impl From for BatchTransitionWasm { fn from(batch: BatchTransition) -> Self { - BatchTransitionWASM(batch) + BatchTransitionWasm(batch) } } -impl From for BatchTransition { - fn from(batch: BatchTransitionWASM) -> Self { +impl From for BatchTransition { + fn from(batch: BatchTransitionWasm) -> Self { batch.0 } } @@ -54,8 +54,8 @@ fn convert_array_to_vec_batched(js_batched_transitions: &js_sys::Array) -> Vec("BatchedTransition") + let batched_transition: BatchedTransitionWasm = js_batched_transition + .to_wasm::("BatchedTransition") .unwrap() .clone(); BatchedTransition::from(batched_transition) @@ -64,7 +64,7 @@ fn convert_array_to_vec_batched(js_batched_transitions: &js_sys::Array) -> Vec String { "BatchTransition".to_string() @@ -82,12 +82,12 @@ impl BatchTransitionWASM { user_fee_increase: UserFeeIncrease, signature_public_key_id: Option, signature: Option>, - ) -> Result { + ) -> Result { let transitions = convert_array_to_vec_batched(&js_batched_transitions); - Ok(BatchTransitionWASM(BatchTransition::V1( + Ok(BatchTransitionWasm(BatchTransition::V1( BatchTransitionV1 { - owner_id: IdentifierWASM::try_from(owner_id)?.into(), + owner_id: IdentifierWasm::try_from(owner_id)?.into(), transitions, user_fee_increase, signature_public_key_id: signature_public_key_id.unwrap_or(0u32), @@ -103,15 +103,15 @@ impl BatchTransitionWASM { user_fee_increase: Option, signature_public_key_id: Option, signature: Option>, - ) -> Result { - let owner_id = IdentifierWASM::try_from(js_owner_id)?; + ) -> Result { + let owner_id = IdentifierWasm::try_from(js_owner_id)?; let transitions: Vec = document_transitions .clone() .iter() .map(|js_document_transition| { - let document_transition: DocumentTransitionWASM = js_document_transition - .to_wasm::("DocumentTransition") + let document_transition: DocumentTransitionWasm = js_document_transition + .to_wasm::("DocumentTransition") .unwrap() .clone(); @@ -119,7 +119,7 @@ impl BatchTransitionWASM { }) .collect(); - Ok(BatchTransitionWASM(BatchTransition::V0( + Ok(BatchTransitionWasm(BatchTransition::V0( BatchTransitionV0 { owner_id: owner_id.into(), transitions, @@ -131,10 +131,10 @@ impl BatchTransitionWASM { } #[wasm_bindgen(getter = "transitions")] - pub fn get_transitions(&self) -> Vec { + pub fn get_transitions(&self) -> Vec { self.0 .transitions_iter() - .map(|transition| BatchedTransitionWASM::from(transition.to_owned_transition())) + .map(|transition| BatchedTransitionWasm::from(transition.to_owned_transition())) .collect() } @@ -161,12 +161,12 @@ impl BatchTransitionWASM { } #[wasm_bindgen(getter = "ownerId")] - pub fn get_owner_id(&self) -> IdentifierWASM { + pub fn get_owner_id(&self) -> IdentifierWasm { self.0.owner_id().into() } #[wasm_bindgen(getter = "modifiedDataIds")] - pub fn get_modified_data_ids(&self) -> Vec { + pub fn get_modified_data_ids(&self) -> Vec { self.0 .modified_data_ids() .iter() @@ -199,20 +199,20 @@ impl BatchTransitionWASM { } #[wasm_bindgen(js_name = "toStateTransition")] - pub fn to_state_transition(&self) -> StateTransitionWASM { + pub fn to_state_transition(&self) -> StateTransitionWasm { let st = StateTransition::from(self.0.clone()); - StateTransitionWASM::from(st) + StateTransitionWasm::from(st) } #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( - state_transition: &StateTransitionWASM, - ) -> Result { + state_transition: &StateTransitionWasm, + ) -> Result { let rs_transition: StateTransition = StateTransition::from(state_transition.clone()); match rs_transition { - StateTransition::Batch(batch) => Ok(BatchTransitionWASM(batch)), + StateTransition::Batch(batch) => Ok(BatchTransitionWasm(batch)), _ => Err(JsValue::from("invalid state document_transition content")), } } @@ -241,19 +241,19 @@ impl BatchTransitionWASM { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { let rs_batch = BatchTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; - Ok(BatchTransitionWASM::from(rs_batch)) + Ok(BatchTransitionWasm::from(rs_batch)) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - BatchTransitionWASM::from_bytes(decode(base64.as_str(), Base64).map_err(JsError::from)?) + pub fn from_base64(base64: String) -> Result { + BatchTransitionWasm::from_bytes(decode(base64.as_str(), Base64).map_err(JsError::from)?) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - BatchTransitionWASM::from_bytes(decode(hex.as_str(), Hex).map_err(JsError::from)?) + pub fn from_hex(hex: String) -> Result { + BatchTransitionWasm::from_bytes(decode(hex.as_str(), Hex).map_err(JsError::from)?) } } diff --git a/packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs b/packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs index 3945e3d3d8f..fdeda7e1cf8 100644 --- a/packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs +++ b/packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs @@ -3,28 +3,28 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "PrefundedVotingBalance")] #[derive(Clone)] -pub struct PrefundedVotingBalanceWASM { +pub struct PrefundedVotingBalanceWasm { index_name: String, credits: Credits, } -impl From<(String, Credits)> for PrefundedVotingBalanceWASM { +impl From<(String, Credits)> for PrefundedVotingBalanceWasm { fn from((index_name, credits): (String, Credits)) -> Self { - PrefundedVotingBalanceWASM { + PrefundedVotingBalanceWasm { index_name, credits, } } } -impl From for (String, Credits) { - fn from(value: PrefundedVotingBalanceWASM) -> Self { +impl From for (String, Credits) { + fn from(value: PrefundedVotingBalanceWasm) -> Self { (value.index_name, value.credits) } } #[wasm_bindgen(js_class = PrefundedVotingBalance)] -impl PrefundedVotingBalanceWASM { +impl PrefundedVotingBalanceWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "PrefundedVotingBalance".to_string() @@ -36,8 +36,8 @@ impl PrefundedVotingBalanceWASM { } #[wasm_bindgen(constructor)] - pub fn new(index_name: String, credits: Credits) -> PrefundedVotingBalanceWASM { - PrefundedVotingBalanceWASM { + pub fn new(index_name: String, credits: Credits) -> PrefundedVotingBalanceWasm { + PrefundedVotingBalanceWasm { index_name, credits, } diff --git a/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs b/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs index 9f0b6214761..86663dabce6 100644 --- a/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs @@ -1,5 +1,5 @@ -use crate::group_state_transition_info::GroupStateTransitionInfoWASM; -use crate::identifier::IdentifierWASM; +use crate::group_state_transition_info::GroupStateTransitionInfoWasm; +use crate::identifier::IdentifierWasm; use crate::utils::IntoWasm; use dpp::group::GroupStateTransitionInfo; use dpp::prelude::IdentityNonce; @@ -11,22 +11,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenBaseTransition)] -pub struct TokenBaseTransitionWASM(TokenBaseTransition); +pub struct TokenBaseTransitionWasm(TokenBaseTransition); -impl From for TokenBaseTransitionWASM { +impl From for TokenBaseTransitionWasm { fn from(t: TokenBaseTransition) -> Self { - TokenBaseTransitionWASM(t) + TokenBaseTransitionWasm(t) } } -impl From for TokenBaseTransition { - fn from(t: TokenBaseTransitionWASM) -> Self { +impl From for TokenBaseTransition { + fn from(t: TokenBaseTransitionWasm) -> Self { t.0 } } #[wasm_bindgen(js_class = TokenBaseTransition)] -impl TokenBaseTransitionWASM { +impl TokenBaseTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenBaseTransition".to_string() @@ -44,24 +44,24 @@ impl TokenBaseTransitionWASM { js_data_contract_id: &JsValue, js_token_id: &JsValue, js_using_group_info: &JsValue, - ) -> Result { + ) -> Result { let using_group_info: Option = match js_using_group_info.is_undefined() { false => Some( js_using_group_info - .to_wasm::("GroupStateTransitionInfo")? + .to_wasm::("GroupStateTransitionInfo")? .clone() .into(), ), true => None, }; - Ok(TokenBaseTransitionWASM(TokenBaseTransition::V0( + Ok(TokenBaseTransitionWasm(TokenBaseTransition::V0( TokenBaseTransitionV0 { identity_contract_nonce, token_contract_position, - data_contract_id: IdentifierWASM::try_from(js_data_contract_id)?.into(), - token_id: IdentifierWASM::try_from(js_token_id)?.into(), + data_contract_id: IdentifierWasm::try_from(js_data_contract_id)?.into(), + token_id: IdentifierWasm::try_from(js_token_id)?.into(), using_group_info, }, ))) @@ -78,17 +78,17 @@ impl TokenBaseTransitionWASM { } #[wasm_bindgen(getter = dataContractId)] - pub fn get_data_contract_id(&self) -> IdentifierWASM { + pub fn get_data_contract_id(&self) -> IdentifierWasm { self.0.data_contract_id().into() } #[wasm_bindgen(getter = tokenId)] - pub fn get_token_id(&self) -> IdentifierWASM { + pub fn get_token_id(&self) -> IdentifierWasm { self.0.token_id().into() } #[wasm_bindgen(getter = usingGroupInfo)] - pub fn get_using_group_info(&self) -> Option { + pub fn get_using_group_info(&self) -> Option { match self.0.using_group_info() { Some(using_group_info) => Some(using_group_info.clone().into()), None => None, @@ -108,14 +108,14 @@ impl TokenBaseTransitionWASM { #[wasm_bindgen(setter = dataContractId)] pub fn set_data_contract_id(&mut self, js_identifier: &JsValue) -> Result<(), JsValue> { self.0 - .set_data_contract_id(IdentifierWASM::try_from(js_identifier)?.into()); + .set_data_contract_id(IdentifierWasm::try_from(js_identifier)?.into()); Ok(()) } #[wasm_bindgen(setter = tokenId)] pub fn set_token_id(&mut self, js_identifier: &JsValue) -> Result<(), JsValue> { self.0 - .set_token_id(IdentifierWASM::try_from(js_identifier)?.into()); + .set_token_id(IdentifierWasm::try_from(js_identifier)?.into()); Ok(()) } @@ -126,7 +126,7 @@ impl TokenBaseTransitionWASM { match js_using_group_info.is_undefined() { false => Some( js_using_group_info - .to_wasm::("GroupStateTransitionInfo")? + .to_wasm::("GroupStateTransitionInfo")? .clone() .into(), ), diff --git a/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs b/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs index e972b686e8c..3925f6db1b7 100644 --- a/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs @@ -1,5 +1,5 @@ -use crate::enums::batch::gas_fees_paid_by::GasFeesPaidByWASM; -use crate::identifier::IdentifierWASM; +use crate::enums::batch::gas_fees_paid_by::GasFeesPaidByWasm; +use crate::identifier::IdentifierWasm; use dpp::balances::credits::TokenAmount; use dpp::data_contract::TokenContractPosition; use dpp::prelude::Identifier; @@ -12,22 +12,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] #[wasm_bindgen(js_name = "TokenPaymentInfo")] -pub struct TokenPaymentInfoWASM(TokenPaymentInfo); +pub struct TokenPaymentInfoWasm(TokenPaymentInfo); -impl From for TokenPaymentInfoWASM { +impl From for TokenPaymentInfoWasm { fn from(info: TokenPaymentInfo) -> Self { - TokenPaymentInfoWASM(info) + TokenPaymentInfoWasm(info) } } -impl From for TokenPaymentInfo { - fn from(info: TokenPaymentInfoWASM) -> Self { +impl From for TokenPaymentInfo { + fn from(info: TokenPaymentInfoWasm) -> Self { info.0 } } #[wasm_bindgen(js_class = TokenPaymentInfo)] -impl TokenPaymentInfoWASM { +impl TokenPaymentInfoWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenPaymentInfo".to_string() @@ -51,18 +51,18 @@ impl TokenPaymentInfoWASM { | js_payment_token_contract_id.is_undefined() { true => None, - false => Some(IdentifierWASM::try_from(js_payment_token_contract_id.clone())?.into()), + false => Some(IdentifierWasm::try_from(js_payment_token_contract_id.clone())?.into()), }; let gas_fees_paid_by = match js_gas_fees_paid_by.is_undefined() | js_gas_fees_paid_by.is_null() { true => GasFeesPaidBy::default(), - false => GasFeesPaidByWASM::try_from(js_gas_fees_paid_by.clone())? + false => GasFeesPaidByWasm::try_from(js_gas_fees_paid_by.clone())? .clone() .into(), }; - Ok(TokenPaymentInfoWASM(TokenPaymentInfo::V0( + Ok(TokenPaymentInfoWasm(TokenPaymentInfo::V0( TokenPaymentInfoV0 { payment_token_contract_id, token_contract_position, @@ -74,7 +74,7 @@ impl TokenPaymentInfoWASM { } #[wasm_bindgen(getter = "paymentTokenContractId")] - pub fn payment_token_contract_id(&self) -> Option { + pub fn payment_token_contract_id(&self) -> Option { self.0.payment_token_contract_id().map(|id| id.into()) } @@ -95,7 +95,7 @@ impl TokenPaymentInfoWASM { #[wasm_bindgen(getter = "gasFeesPaidBy")] pub fn gas_fees_paid_by(&self) -> String { - GasFeesPaidByWASM::from(self.0.gas_fees_paid_by()).into() + GasFeesPaidByWasm::from(self.0.gas_fees_paid_by()).into() } #[wasm_bindgen(setter = "paymentTokenContractId")] @@ -108,7 +108,7 @@ impl TokenPaymentInfoWASM { | js_payment_token_contract_id.is_undefined() { true => None, - false => Some(IdentifierWASM::try_from(js_payment_token_contract_id.clone())?.into()), + false => Some(IdentifierWasm::try_from(js_payment_token_contract_id.clone())?.into()), }; self.0 @@ -137,7 +137,7 @@ impl TokenPaymentInfoWASM { let gas_fees_paid_by = match js_gas_fees_paid_by.is_undefined() | js_gas_fees_paid_by.is_null() { true => GasFeesPaidBy::default(), - false => GasFeesPaidByWASM::try_from(js_gas_fees_paid_by.clone())? + false => GasFeesPaidByWasm::try_from(js_gas_fees_paid_by.clone())? .clone() .into(), }; diff --git a/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs b/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs index 7741a9d469f..d3531fb816e 100644 --- a/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs @@ -9,22 +9,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "TokenPricingSchedule")] -pub struct TokenPricingScheduleWASM(TokenPricingSchedule); +pub struct TokenPricingScheduleWasm(TokenPricingSchedule); -impl From for TokenPricingSchedule { - fn from(schedule: TokenPricingScheduleWASM) -> Self { +impl From for TokenPricingSchedule { + fn from(schedule: TokenPricingScheduleWasm) -> Self { schedule.0 } } -impl From for TokenPricingScheduleWASM { +impl From for TokenPricingScheduleWasm { fn from(schedule: TokenPricingSchedule) -> Self { - TokenPricingScheduleWASM(schedule) + TokenPricingScheduleWasm(schedule) } } #[wasm_bindgen(js_class = TokenPricingSchedule)] -impl TokenPricingScheduleWASM { +impl TokenPricingScheduleWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenPricingSchedule".to_string() @@ -41,7 +41,7 @@ impl TokenPricingScheduleWASM { } #[wasm_bindgen(js_name = "SetPrices")] - pub fn set_prices(js_prices: &JsValue) -> Result { + pub fn set_prices(js_prices: &JsValue) -> Result { let prices: BTreeMap = js_prices .with_serde_to_platform_value_map()? .iter() diff --git a/packages/wasm-dpp2/src/batch/token_transition/mod.rs b/packages/wasm-dpp2/src/batch/token_transition/mod.rs index dd472dc6ae2..5ac5a71470b 100644 --- a/packages/wasm-dpp2/src/batch/token_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_transition/mod.rs @@ -1,15 +1,15 @@ -use crate::batch::token_transitions::config_update::TokenConfigUpdateTransitionWASM; -use crate::batch::token_transitions::direct_purchase::TokenDirectPurchaseTransitionWASM; -use crate::batch::token_transitions::set_price_for_direct_purchase::TokenSetPriceForDirectPurchaseTransitionWASM; -use crate::batch::token_transitions::token_burn::TokenBurnTransitionWASM; -use crate::batch::token_transitions::token_claim::TokenClaimTransitionWASM; -use crate::batch::token_transitions::token_destroy_frozen_funds::TokenDestroyFrozenFundsTransitionWASM; -use crate::batch::token_transitions::token_emergency_action::TokenEmergencyActionTransitionWASM; -use crate::batch::token_transitions::token_freeze::TokenFreezeTransitionWASM; -use crate::batch::token_transitions::token_mint::TokenMintTransitionWASM; -use crate::batch::token_transitions::token_transfer::TokenTransferTransitionWASM; -use crate::batch::token_transitions::token_unfreeze::TokenUnFreezeTransitionWASM; -use crate::identifier::IdentifierWASM; +use crate::batch::token_transitions::config_update::TokenConfigUpdateTransitionWasm; +use crate::batch::token_transitions::direct_purchase::TokenDirectPurchaseTransitionWasm; +use crate::batch::token_transitions::set_price_for_direct_purchase::TokenSetPriceForDirectPurchaseTransitionWasm; +use crate::batch::token_transitions::token_burn::TokenBurnTransitionWasm; +use crate::batch::token_transitions::token_claim::TokenClaimTransitionWasm; +use crate::batch::token_transitions::token_destroy_frozen_funds::TokenDestroyFrozenFundsTransitionWasm; +use crate::batch::token_transitions::token_emergency_action::TokenEmergencyActionTransitionWasm; +use crate::batch::token_transitions::token_freeze::TokenFreezeTransitionWasm; +use crate::batch::token_transitions::token_mint::TokenMintTransitionWasm; +use crate::batch::token_transitions::token_transfer::TokenTransferTransitionWasm; +use crate::batch::token_transitions::token_unfreeze::TokenUnFreezeTransitionWasm; +use crate::identifier::IdentifierWasm; use crate::utils::{IntoWasm, get_class_type}; use dpp::prelude::IdentityNonce; use dpp::state_transition::batch_transition::batched_transition::token_transition::{ @@ -26,22 +26,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenTransition)] -pub struct TokenTransitionWASM(TokenTransition); +pub struct TokenTransitionWasm(TokenTransition); -impl From for TokenTransitionWASM { +impl From for TokenTransitionWasm { fn from(transition: TokenTransition) -> Self { Self(transition) } } -impl From for TokenTransition { - fn from(transition: TokenTransitionWASM) -> Self { +impl From for TokenTransition { + fn from(transition: TokenTransitionWasm) -> Self { transition.0 } } #[wasm_bindgen(js_class = TokenTransition)] -impl TokenTransitionWASM { +impl TokenTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenTransition".to_string() @@ -53,39 +53,39 @@ impl TokenTransitionWASM { } #[wasm_bindgen(constructor)] - pub fn new(js_transition: &JsValue) -> Result { + pub fn new(js_transition: &JsValue) -> Result { let transition = match js_transition.is_object() { true => match get_class_type(js_transition)?.as_str() { "TokenMintTransition" => Ok(TokenTransition::from(TokenMintTransition::from( js_transition - .to_wasm::("TokenMintTransition")? + .to_wasm::("TokenMintTransition")? .clone(), ))), "TokenUnFreezeTransition" => { Ok(TokenTransition::from(TokenUnfreezeTransition::from( js_transition - .to_wasm::("TokenUnFreezeTransition")? + .to_wasm::("TokenUnFreezeTransition")? .clone(), ))) } "TokenTransferTransition" => { Ok(TokenTransition::from(TokenTransferTransition::from( js_transition - .to_wasm::("TokenTransferTransition")? + .to_wasm::("TokenTransferTransition")? .clone(), ))) } "TokenFreezeTransition" => { Ok(TokenTransition::from(TokenFreezeTransition::from( js_transition - .to_wasm::("TokenFreezeTransition")? + .to_wasm::("TokenFreezeTransition")? .clone(), ))) } "TokenDestroyFrozenFundsTransition" => Ok(TokenTransition::from( TokenDestroyFrozenFundsTransition::from( js_transition - .to_wasm::( + .to_wasm::( "TokenDestroyFrozenFundsTransition", )? .clone(), @@ -94,19 +94,19 @@ impl TokenTransitionWASM { "TokenClaimTransition" => { Ok(TokenTransition::from(TokenClaimTransition::from( js_transition - .to_wasm::("TokenClaimTransition")? + .to_wasm::("TokenClaimTransition")? .clone(), ))) } "TokenBurnTransition" => Ok(TokenTransition::from(TokenBurnTransition::from( js_transition - .to_wasm::("TokenBurnTransition")? + .to_wasm::("TokenBurnTransition")? .clone(), ))), "TokenSetPriceForDirectPurchaseTransition" => Ok(TokenTransition::from( TokenSetPriceForDirectPurchaseTransition::from( js_transition - .to_wasm::( + .to_wasm::( "TokenSetPriceForDirectPurchaseTransition", )? .clone(), @@ -115,7 +115,7 @@ impl TokenTransitionWASM { "TokenDirectPurchaseTransition" => { Ok(TokenTransition::from(TokenDirectPurchaseTransition::from( js_transition - .to_wasm::( + .to_wasm::( "TokenDirectPurchaseTransition", )? .clone(), @@ -124,7 +124,7 @@ impl TokenTransitionWASM { "TokenConfigUpdateTransition" => { Ok(TokenTransition::from(TokenConfigUpdateTransition::from( js_transition - .to_wasm::( + .to_wasm::( "TokenConfigUpdateTransition", )? .clone(), @@ -133,7 +133,7 @@ impl TokenTransitionWASM { "TokenEmergencyActionTransition" => { Ok(TokenTransition::from(TokenEmergencyActionTransition::from( js_transition - .to_wasm::( + .to_wasm::( "TokenEmergencyActionTransition", )? .clone(), @@ -144,44 +144,44 @@ impl TokenTransitionWASM { false => Err(JsValue::from("Bad token transition input")), }?; - Ok(TokenTransitionWASM(TokenTransition::from(transition))) + Ok(TokenTransitionWasm(TokenTransition::from(transition))) } #[wasm_bindgen(js_name = "getTransition")] pub fn to_transition(&self) -> JsValue { match self.clone().0 { TokenTransition::Burn(token_transition) => { - TokenBurnTransitionWASM::from(token_transition).into() + TokenBurnTransitionWasm::from(token_transition).into() } TokenTransition::Mint(token_transition) => { - TokenMintTransitionWASM::from(token_transition).into() + TokenMintTransitionWasm::from(token_transition).into() } TokenTransition::Transfer(token_transition) => { - TokenTransferTransitionWASM::from(token_transition).into() + TokenTransferTransitionWasm::from(token_transition).into() } TokenTransition::Freeze(token_transition) => { - TokenFreezeTransitionWASM::from(token_transition).into() + TokenFreezeTransitionWasm::from(token_transition).into() } TokenTransition::Unfreeze(token_transition) => { - TokenUnFreezeTransitionWASM::from(token_transition).into() + TokenUnFreezeTransitionWasm::from(token_transition).into() } TokenTransition::DestroyFrozenFunds(token_transition) => { - TokenDestroyFrozenFundsTransitionWASM::from(token_transition).into() + TokenDestroyFrozenFundsTransitionWasm::from(token_transition).into() } TokenTransition::Claim(token_transition) => { - TokenClaimTransitionWASM::from(token_transition).into() + TokenClaimTransitionWasm::from(token_transition).into() } TokenTransition::EmergencyAction(token_transition) => { - TokenEmergencyActionTransitionWASM::from(token_transition).into() + TokenEmergencyActionTransitionWasm::from(token_transition).into() } TokenTransition::ConfigUpdate(token_transition) => { - TokenConfigUpdateTransitionWASM::from(token_transition).into() + TokenConfigUpdateTransitionWasm::from(token_transition).into() } TokenTransition::DirectPurchase(token_transition) => { - TokenDirectPurchaseTransitionWASM::from(token_transition).into() + TokenDirectPurchaseTransitionWasm::from(token_transition).into() } TokenTransition::SetPriceForDirectPurchase(token_transition) => { - TokenSetPriceForDirectPurchaseTransitionWASM::from(token_transition).into() + TokenSetPriceForDirectPurchaseTransitionWasm::from(token_transition).into() } } } @@ -231,8 +231,8 @@ impl TokenTransitionWASM { pub fn get_historical_document_id( &self, js_owner: &JsValue, - ) -> Result { - let owner = IdentifierWASM::try_from(js_owner)?; + ) -> Result { + let owner = IdentifierWasm::try_from(js_owner)?; Ok(self.0.historical_document_id(owner.into()).into()) } @@ -242,12 +242,12 @@ impl TokenTransitionWASM { } #[wasm_bindgen(getter = "tokenId")] - pub fn get_token_id(&self) -> IdentifierWASM { + pub fn get_token_id(&self) -> IdentifierWasm { self.0.token_id().into() } #[wasm_bindgen(getter = "contractId")] - pub fn get_contract_id(&self) -> IdentifierWASM { + pub fn get_contract_id(&self) -> IdentifierWasm { self.0.data_contract_id().into() } @@ -258,7 +258,7 @@ impl TokenTransitionWASM { #[wasm_bindgen(setter = "tokenId")] pub fn set_token_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { - let id = IdentifierWASM::try_from(js_id)?; + let id = IdentifierWasm::try_from(js_id)?; self.0.set_token_id(id.into()); @@ -267,7 +267,7 @@ impl TokenTransitionWASM { #[wasm_bindgen(setter = "contractId")] pub fn set_contract_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { - let id = IdentifierWASM::try_from(js_id)?; + let id = IdentifierWasm::try_from(js_id)?; self.0.set_data_contract_id(id.into()); diff --git a/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs b/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs index 8aea0f801d9..9b490860164 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs @@ -1,30 +1,30 @@ use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; -use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use crate::batch::token_base_transition::TokenBaseTransitionWasm; use dpp::state_transition::batch_transition::TokenConfigUpdateTransition; use dpp::state_transition::batch_transition::token_config_update_transition::TokenConfigUpdateTransitionV0; use dpp::state_transition::batch_transition::token_config_update_transition::v0::v0_methods::TokenConfigUpdateTransitionV0Methods; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name = "TokenConfigUpdateTransition")] -pub struct TokenConfigUpdateTransitionWASM(TokenConfigUpdateTransition); +pub struct TokenConfigUpdateTransitionWasm(TokenConfigUpdateTransition); -impl From for TokenConfigUpdateTransition { - fn from(transition: TokenConfigUpdateTransitionWASM) -> Self { +impl From for TokenConfigUpdateTransition { + fn from(transition: TokenConfigUpdateTransitionWasm) -> Self { transition.0 } } -impl From for TokenConfigUpdateTransitionWASM { +impl From for TokenConfigUpdateTransitionWasm { fn from(transition: TokenConfigUpdateTransition) -> Self { - TokenConfigUpdateTransitionWASM(transition) + TokenConfigUpdateTransitionWasm(transition) } } #[wasm_bindgen(js_class = TokenConfigUpdateTransition)] -impl TokenConfigUpdateTransitionWASM { +impl TokenConfigUpdateTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenConfigUpdateTransition".to_string() @@ -37,11 +37,11 @@ impl TokenConfigUpdateTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - base: &TokenBaseTransitionWASM, - update_token_configuration_item: &TokenConfigurationChangeItemWASM, + base: &TokenBaseTransitionWasm, + update_token_configuration_item: &TokenConfigurationChangeItemWasm, public_note: Option, - ) -> Result { - Ok(TokenConfigUpdateTransitionWASM( + ) -> Result { + Ok(TokenConfigUpdateTransitionWasm( TokenConfigUpdateTransition::V0(TokenConfigUpdateTransitionV0 { base: base.clone().into(), update_token_configuration_item: update_token_configuration_item.clone().into(), @@ -51,7 +51,7 @@ impl TokenConfigUpdateTransitionWASM { } #[wasm_bindgen(getter = base)] - pub fn get_base(&self) -> TokenBaseTransitionWASM { + pub fn get_base(&self) -> TokenBaseTransitionWasm { self.0.base().clone().into() } @@ -61,12 +61,12 @@ impl TokenConfigUpdateTransitionWASM { } #[wasm_bindgen(getter = updateTokenConfigurationItem)] - pub fn get_update_token_configuration_item(&self) -> TokenConfigurationChangeItemWASM { + pub fn get_update_token_configuration_item(&self) -> TokenConfigurationChangeItemWasm { self.0.update_token_configuration_item().clone().into() } #[wasm_bindgen(setter = base)] - pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + pub fn set_base(&mut self, base: TokenBaseTransitionWasm) { self.0.set_base(base.into()) } @@ -76,7 +76,7 @@ impl TokenConfigUpdateTransitionWASM { } #[wasm_bindgen(setter = updateTokenConfigurationItem)] - pub fn set_update_token_configuration_item(&mut self, item: &TokenConfigurationChangeItemWASM) { + pub fn set_update_token_configuration_item(&mut self, item: &TokenConfigurationChangeItemWasm) { self.0 .set_update_token_configuration_item(item.clone().into()) } diff --git a/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs b/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs index cb7076cb5cb..b18baa73937 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs @@ -5,26 +5,26 @@ use dpp::state_transition::batch_transition::token_direct_purchase_transition::T use dpp::state_transition::batch_transition::token_direct_purchase_transition::v0::v0_methods::TokenDirectPurchaseTransitionV0Methods; use dpp::state_transition::batch_transition::TokenDirectPurchaseTransition; use wasm_bindgen::prelude::wasm_bindgen; -use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use crate::batch::token_base_transition::TokenBaseTransitionWasm; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenDirectPurchaseTransition)] -pub struct TokenDirectPurchaseTransitionWASM(TokenDirectPurchaseTransition); +pub struct TokenDirectPurchaseTransitionWasm(TokenDirectPurchaseTransition); -impl From for TokenDirectPurchaseTransition { - fn from(transition: TokenDirectPurchaseTransitionWASM) -> Self { +impl From for TokenDirectPurchaseTransition { + fn from(transition: TokenDirectPurchaseTransitionWasm) -> Self { transition.0 } } -impl From for TokenDirectPurchaseTransitionWASM { +impl From for TokenDirectPurchaseTransitionWasm { fn from(transition: TokenDirectPurchaseTransition) -> Self { - TokenDirectPurchaseTransitionWASM(transition) + TokenDirectPurchaseTransitionWasm(transition) } } #[wasm_bindgen(js_class = TokenDirectPurchaseTransition)] -impl TokenDirectPurchaseTransitionWASM { +impl TokenDirectPurchaseTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenDirectPurchaseTransition".to_string() @@ -37,11 +37,11 @@ impl TokenDirectPurchaseTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - base: &TokenBaseTransitionWASM, + base: &TokenBaseTransitionWasm, token_count: TokenAmount, total_agreed_price: Credits, ) -> Self { - TokenDirectPurchaseTransitionWASM(TokenDirectPurchaseTransition::V0( + TokenDirectPurchaseTransitionWasm(TokenDirectPurchaseTransition::V0( TokenDirectPurchaseTransitionV0 { base: base.clone().into(), token_count, @@ -51,7 +51,7 @@ impl TokenDirectPurchaseTransitionWASM { } #[wasm_bindgen(getter = base)] - pub fn get_base(&self) -> TokenBaseTransitionWASM { + pub fn get_base(&self) -> TokenBaseTransitionWasm { self.0.base().clone().into() } @@ -66,7 +66,7 @@ impl TokenDirectPurchaseTransitionWASM { } #[wasm_bindgen(setter = base)] - pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + pub fn set_base(&mut self, base: TokenBaseTransitionWasm) { self.0.set_base(base.into()) } diff --git a/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs b/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs index 86c575d42a1..31dfd3148cf 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs @@ -1,5 +1,5 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWASM; -use crate::batch::token_pricing_schedule::TokenPricingScheduleWASM; +use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::batch::token_pricing_schedule::TokenPricingScheduleWasm; use dpp::state_transition::batch_transition::token_set_price_for_direct_purchase_transition::TokenSetPriceForDirectPurchaseTransitionV0; use dpp::state_transition::batch_transition::TokenSetPriceForDirectPurchaseTransition; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; @@ -11,26 +11,26 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenSetPriceForDirectPurchaseTransition)] -pub struct TokenSetPriceForDirectPurchaseTransitionWASM(TokenSetPriceForDirectPurchaseTransition); +pub struct TokenSetPriceForDirectPurchaseTransitionWasm(TokenSetPriceForDirectPurchaseTransition); impl From - for TokenSetPriceForDirectPurchaseTransitionWASM + for TokenSetPriceForDirectPurchaseTransitionWasm { fn from(transition: TokenSetPriceForDirectPurchaseTransition) -> Self { - TokenSetPriceForDirectPurchaseTransitionWASM(transition) + TokenSetPriceForDirectPurchaseTransitionWasm(transition) } } -impl From +impl From for TokenSetPriceForDirectPurchaseTransition { - fn from(transition: TokenSetPriceForDirectPurchaseTransitionWASM) -> Self { + fn from(transition: TokenSetPriceForDirectPurchaseTransitionWasm) -> Self { transition.0 } } #[wasm_bindgen(js_class = TokenSetPriceForDirectPurchaseTransition)] -impl TokenSetPriceForDirectPurchaseTransitionWASM { +impl TokenSetPriceForDirectPurchaseTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenSetPriceForDirectPurchaseTransition".to_string() @@ -43,21 +43,21 @@ impl TokenSetPriceForDirectPurchaseTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - base: &TokenBaseTransitionWASM, + base: &TokenBaseTransitionWasm, js_price: &JsValue, public_note: Option, - ) -> Result { + ) -> Result { let price: Option = match js_price.is_undefined() { true => None, false => Some( js_price - .to_wasm::("TokenPricingSchedule")? + .to_wasm::("TokenPricingSchedule")? .clone() .into(), ), }; - Ok(TokenSetPriceForDirectPurchaseTransitionWASM( + Ok(TokenSetPriceForDirectPurchaseTransitionWasm( TokenSetPriceForDirectPurchaseTransition::V0( TokenSetPriceForDirectPurchaseTransitionV0 { base: base.clone().into(), @@ -69,7 +69,7 @@ impl TokenSetPriceForDirectPurchaseTransitionWASM { } #[wasm_bindgen(getter = base)] - pub fn get_base(&self) -> TokenBaseTransitionWASM { + pub fn get_base(&self) -> TokenBaseTransitionWasm { self.0.base().clone().into() } @@ -82,12 +82,12 @@ impl TokenSetPriceForDirectPurchaseTransitionWASM { pub fn get_price(&self) -> JsValue { match self.0.price() { None => JsValue::null(), - Some(price) => JsValue::from(TokenPricingScheduleWASM::from(price.clone())), + Some(price) => JsValue::from(TokenPricingScheduleWasm::from(price.clone())), } } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + pub fn set_base(&mut self, base: TokenBaseTransitionWasm) { self.0.set_base(base.into()) } @@ -102,7 +102,7 @@ impl TokenSetPriceForDirectPurchaseTransitionWASM { true => None, false => Some( js_price - .to_wasm::("TokenPricingSchedule")? + .to_wasm::("TokenPricingSchedule")? .clone() .into(), ), diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs index 73f1700aa9b..a34bd838ac0 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs @@ -1,4 +1,4 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use crate::batch::token_base_transition::TokenBaseTransitionWasm; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use dpp::state_transition::batch_transition::TokenBurnTransition; use dpp::state_transition::batch_transition::token_burn_transition::TokenBurnTransitionV0; @@ -8,22 +8,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenBurnTransition)] -pub struct TokenBurnTransitionWASM(TokenBurnTransition); +pub struct TokenBurnTransitionWasm(TokenBurnTransition); -impl From for TokenBurnTransitionWASM { +impl From for TokenBurnTransitionWasm { fn from(transition: TokenBurnTransition) -> Self { Self(transition) } } -impl From for TokenBurnTransition { - fn from(transition: TokenBurnTransitionWASM) -> Self { +impl From for TokenBurnTransition { + fn from(transition: TokenBurnTransitionWasm) -> Self { transition.0 } } #[wasm_bindgen(js_class = TokenBurnTransition)] -impl TokenBurnTransitionWASM { +impl TokenBurnTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenBurnTransition".to_string() @@ -36,11 +36,11 @@ impl TokenBurnTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - base: &TokenBaseTransitionWASM, + base: &TokenBaseTransitionWasm, burn_amount: u64, public_note: Option, - ) -> Result { - Ok(TokenBurnTransitionWASM(TokenBurnTransition::V0( + ) -> Result { + Ok(TokenBurnTransitionWasm(TokenBurnTransition::V0( TokenBurnTransitionV0 { base: base.clone().into(), burn_amount, @@ -55,7 +55,7 @@ impl TokenBurnTransitionWASM { } #[wasm_bindgen(getter = base)] - pub fn get_base(&self) -> TokenBaseTransitionWASM { + pub fn get_base(&self) -> TokenBaseTransitionWasm { self.0.base().clone().into() } @@ -70,7 +70,7 @@ impl TokenBurnTransitionWASM { } #[wasm_bindgen(setter = base)] - pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + pub fn set_base(&mut self, base: TokenBaseTransitionWasm) { self.0.set_base(base.into()) } diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs index bdb83ac1196..9da8b940ef6 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs @@ -1,30 +1,30 @@ use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; -use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use crate::batch::token_base_transition::TokenBaseTransitionWasm; use dpp::state_transition::batch_transition::TokenClaimTransition; use dpp::state_transition::batch_transition::token_claim_transition::TokenClaimTransitionV0; use dpp::state_transition::batch_transition::token_claim_transition::v0::v0_methods::TokenClaimTransitionV0Methods; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::enums::token::distribution_type::TokenDistributionTypeWASM; +use crate::enums::token::distribution_type::TokenDistributionTypeWasm; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name = "TokenClaimTransition")] -pub struct TokenClaimTransitionWASM(TokenClaimTransition); +pub struct TokenClaimTransitionWasm(TokenClaimTransition); -impl From for TokenClaimTransitionWASM { +impl From for TokenClaimTransitionWasm { fn from(transition: TokenClaimTransition) -> Self { Self(transition) } } -impl From for TokenClaimTransition { - fn from(transition: TokenClaimTransitionWASM) -> Self { +impl From for TokenClaimTransition { + fn from(transition: TokenClaimTransitionWasm) -> Self { transition.0 } } #[wasm_bindgen(js_class = TokenClaimTransition)] -impl TokenClaimTransitionWASM { +impl TokenClaimTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenClaimTransition".to_string() @@ -37,16 +37,16 @@ impl TokenClaimTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - base: &TokenBaseTransitionWASM, + base: &TokenBaseTransitionWasm, js_distribution_type: &JsValue, public_note: Option, - ) -> Result { + ) -> Result { let distribution_type = match js_distribution_type.is_undefined() { - true => TokenDistributionTypeWASM::default(), - false => TokenDistributionTypeWASM::try_from(js_distribution_type.clone())?, + true => TokenDistributionTypeWasm::default(), + false => TokenDistributionTypeWasm::try_from(js_distribution_type.clone())?, }; - Ok(TokenClaimTransitionWASM(TokenClaimTransition::V0( + Ok(TokenClaimTransitionWasm(TokenClaimTransition::V0( TokenClaimTransitionV0 { base: base.clone().into(), distribution_type: distribution_type.into(), @@ -56,7 +56,7 @@ impl TokenClaimTransitionWASM { } #[wasm_bindgen(getter = "base")] - pub fn get_base(&self) -> TokenBaseTransitionWASM { + pub fn get_base(&self) -> TokenBaseTransitionWasm { self.0.base().clone().into() } @@ -67,11 +67,11 @@ impl TokenClaimTransitionWASM { #[wasm_bindgen(getter = "distributionType")] pub fn get_distribution_type(&self) -> String { - TokenDistributionTypeWASM::from(self.0.distribution_type()).into() + TokenDistributionTypeWasm::from(self.0.distribution_type()).into() } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + pub fn set_base(&mut self, base: TokenBaseTransitionWasm) { self.0.set_base(base.into()) } @@ -83,8 +83,8 @@ impl TokenClaimTransitionWASM { #[wasm_bindgen(setter = "distributionType")] pub fn set_distribution_type(&mut self, js_distribution_type: &JsValue) -> Result<(), JsValue> { let distribution_type = match js_distribution_type.is_undefined() { - true => TokenDistributionTypeWASM::default(), - false => TokenDistributionTypeWASM::try_from(js_distribution_type.clone())?, + true => TokenDistributionTypeWasm::default(), + false => TokenDistributionTypeWasm::try_from(js_distribution_type.clone())?, }; Ok(self.0.set_distribution_type(distribution_type.into())) diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs index b94ea86d054..b51cd43af57 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs @@ -1,31 +1,31 @@ use dpp::identifier::Identifier; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; -use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use crate::batch::token_base_transition::TokenBaseTransitionWasm; use dpp::state_transition::batch_transition::TokenDestroyFrozenFundsTransition; use dpp::state_transition::batch_transition::token_destroy_frozen_funds_transition::TokenDestroyFrozenFundsTransitionV0; use dpp::state_transition::batch_transition::token_destroy_frozen_funds_transition::v0::v0_methods::TokenDestroyFrozenFundsTransitionV0Methods; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenDestroyFrozenFundsTransition)] -pub struct TokenDestroyFrozenFundsTransitionWASM(TokenDestroyFrozenFundsTransition); +pub struct TokenDestroyFrozenFundsTransitionWasm(TokenDestroyFrozenFundsTransition); -impl From for TokenDestroyFrozenFundsTransitionWASM { +impl From for TokenDestroyFrozenFundsTransitionWasm { fn from(transition: TokenDestroyFrozenFundsTransition) -> Self { - TokenDestroyFrozenFundsTransitionWASM(transition) + TokenDestroyFrozenFundsTransitionWasm(transition) } } -impl From for TokenDestroyFrozenFundsTransition { - fn from(transition: TokenDestroyFrozenFundsTransitionWASM) -> Self { +impl From for TokenDestroyFrozenFundsTransition { + fn from(transition: TokenDestroyFrozenFundsTransitionWasm) -> Self { transition.0 } } #[wasm_bindgen(js_class = TokenDestroyFrozenFundsTransition)] -impl TokenDestroyFrozenFundsTransitionWASM { +impl TokenDestroyFrozenFundsTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenDestroyFrozenFundsTransition".to_string() @@ -38,14 +38,14 @@ impl TokenDestroyFrozenFundsTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - base: &TokenBaseTransitionWASM, + base: &TokenBaseTransitionWasm, js_frozen_identity_id: &JsValue, public_note: Option, - ) -> Result { + ) -> Result { let frozen_identity_id: Identifier = - IdentifierWASM::try_from(js_frozen_identity_id)?.into(); + IdentifierWasm::try_from(js_frozen_identity_id)?.into(); - Ok(TokenDestroyFrozenFundsTransitionWASM( + Ok(TokenDestroyFrozenFundsTransitionWasm( TokenDestroyFrozenFundsTransition::V0(TokenDestroyFrozenFundsTransitionV0 { base: base.clone().into(), frozen_identity_id, @@ -55,7 +55,7 @@ impl TokenDestroyFrozenFundsTransitionWASM { } #[wasm_bindgen(getter = "base")] - pub fn get_base(&self) -> TokenBaseTransitionWASM { + pub fn get_base(&self) -> TokenBaseTransitionWasm { self.0.base().clone().into() } @@ -65,12 +65,12 @@ impl TokenDestroyFrozenFundsTransitionWASM { } #[wasm_bindgen(getter = "frozenIdentityId")] - pub fn get_frozen_identity_id(&self) -> IdentifierWASM { + pub fn get_frozen_identity_id(&self) -> IdentifierWasm { self.0.frozen_identity_id().into() } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + pub fn set_base(&mut self, base: TokenBaseTransitionWasm) { self.0.set_base(base.into()) } @@ -85,7 +85,7 @@ impl TokenDestroyFrozenFundsTransitionWASM { js_frozen_identity_id: &JsValue, ) -> Result<(), JsValue> { self.0 - .set_frozen_identity_id(IdentifierWASM::try_from(js_frozen_identity_id)?.into()); + .set_frozen_identity_id(IdentifierWasm::try_from(js_frozen_identity_id)?.into()); Ok(()) } } diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs index 9beea1725ab..b5382f6c7eb 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs @@ -3,27 +3,27 @@ use dpp::state_transition::batch_transition::token_emergency_action_transition:: use dpp::state_transition::batch_transition::token_emergency_action_transition::v0::v0_methods::TokenEmergencyActionTransitionV0Methods; use dpp::state_transition::batch_transition::TokenEmergencyActionTransition; use wasm_bindgen::prelude::wasm_bindgen; -use crate::enums::token::emergency_action::TokenEmergencyActionWASM; -use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use crate::enums::token::emergency_action::TokenEmergencyActionWasm; +use crate::batch::token_base_transition::TokenBaseTransitionWasm; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name = "TokenEmergencyActionTransition")] -pub struct TokenEmergencyActionTransitionWASM(TokenEmergencyActionTransition); +pub struct TokenEmergencyActionTransitionWasm(TokenEmergencyActionTransition); -impl From for TokenEmergencyActionTransition { - fn from(transition: TokenEmergencyActionTransitionWASM) -> Self { +impl From for TokenEmergencyActionTransition { + fn from(transition: TokenEmergencyActionTransitionWasm) -> Self { transition.0 } } -impl From for TokenEmergencyActionTransitionWASM { +impl From for TokenEmergencyActionTransitionWasm { fn from(transition: TokenEmergencyActionTransition) -> Self { - TokenEmergencyActionTransitionWASM(transition) + TokenEmergencyActionTransitionWasm(transition) } } #[wasm_bindgen(js_class = TokenEmergencyActionTransition)] -impl TokenEmergencyActionTransitionWASM { +impl TokenEmergencyActionTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenEmergencyActionTransition".to_string() @@ -36,11 +36,11 @@ impl TokenEmergencyActionTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - base: &TokenBaseTransitionWASM, - emergency_action: TokenEmergencyActionWASM, + base: &TokenBaseTransitionWasm, + emergency_action: TokenEmergencyActionWasm, public_note: Option, - ) -> TokenEmergencyActionTransitionWASM { - TokenEmergencyActionTransitionWASM(TokenEmergencyActionTransition::V0( + ) -> TokenEmergencyActionTransitionWasm { + TokenEmergencyActionTransitionWasm(TokenEmergencyActionTransition::V0( TokenEmergencyActionTransitionV0 { base: base.clone().into(), emergency_action: emergency_action.into(), @@ -50,7 +50,7 @@ impl TokenEmergencyActionTransitionWASM { } #[wasm_bindgen(getter = "base")] - pub fn get_base(&self) -> TokenBaseTransitionWASM { + pub fn get_base(&self) -> TokenBaseTransitionWasm { self.0.base().clone().into() } @@ -61,11 +61,11 @@ impl TokenEmergencyActionTransitionWASM { #[wasm_bindgen(getter = "emergencyAction")] pub fn get_emergency_action(&self) -> String { - TokenEmergencyActionWASM::from(self.0.emergency_action()).into() + TokenEmergencyActionWasm::from(self.0.emergency_action()).into() } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + pub fn set_base(&mut self, base: TokenBaseTransitionWasm) { self.0.set_base(base.into()) } @@ -75,7 +75,7 @@ impl TokenEmergencyActionTransitionWASM { } #[wasm_bindgen(setter = "emergencyAction")] - pub fn set_emergency_action(&mut self, action: TokenEmergencyActionWASM) { + pub fn set_emergency_action(&mut self, action: TokenEmergencyActionWasm) { self.0.set_emergency_action(action.into()) } } diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs index 808c3b00923..5de53173776 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs @@ -5,27 +5,27 @@ use dpp::state_transition::batch_transition::token_freeze_transition::v0::v0_met use dpp::state_transition::batch_transition::TokenFreezeTransition; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::identifier::IdentifierWASM; -use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use crate::identifier::IdentifierWasm; +use crate::batch::token_base_transition::TokenBaseTransitionWasm; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenFreezeTransition)] -pub struct TokenFreezeTransitionWASM(TokenFreezeTransition); +pub struct TokenFreezeTransitionWasm(TokenFreezeTransition); -impl From for TokenFreezeTransition { - fn from(transition: TokenFreezeTransitionWASM) -> Self { +impl From for TokenFreezeTransition { + fn from(transition: TokenFreezeTransitionWasm) -> Self { transition.0 } } -impl From for TokenFreezeTransitionWASM { +impl From for TokenFreezeTransitionWasm { fn from(transition: TokenFreezeTransition) -> Self { Self(transition) } } #[wasm_bindgen(js_class = TokenFreezeTransition)] -impl TokenFreezeTransitionWASM { +impl TokenFreezeTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenFreezeTransition".to_string() @@ -38,14 +38,14 @@ impl TokenFreezeTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - base: &TokenBaseTransitionWASM, + base: &TokenBaseTransitionWasm, js_identity_to_freeze_id: &JsValue, public_note: Option, - ) -> Result { + ) -> Result { let identity_to_freeze_id: Identifier = - IdentifierWASM::try_from(js_identity_to_freeze_id)?.into(); + IdentifierWasm::try_from(js_identity_to_freeze_id)?.into(); - Ok(TokenFreezeTransitionWASM(TokenFreezeTransition::V0( + Ok(TokenFreezeTransitionWasm(TokenFreezeTransition::V0( TokenFreezeTransitionV0 { base: base.clone().into(), identity_to_freeze_id, @@ -55,7 +55,7 @@ impl TokenFreezeTransitionWASM { } #[wasm_bindgen(getter = "base")] - pub fn get_base(&self) -> TokenBaseTransitionWASM { + pub fn get_base(&self) -> TokenBaseTransitionWasm { self.0.base().clone().into() } @@ -65,12 +65,12 @@ impl TokenFreezeTransitionWASM { } #[wasm_bindgen(getter = "frozenIdentityId")] - pub fn get_frozen_identity_id(&self) -> IdentifierWASM { + pub fn get_frozen_identity_id(&self) -> IdentifierWasm { self.0.frozen_identity_id().into() } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + pub fn set_base(&mut self, base: TokenBaseTransitionWasm) { self.0.set_base(base.into()) } @@ -85,7 +85,7 @@ impl TokenFreezeTransitionWASM { js_frozen_identity_id: &JsValue, ) -> Result<(), JsValue> { self.0 - .set_frozen_identity_id(IdentifierWASM::try_from(js_frozen_identity_id)?.into()); + .set_frozen_identity_id(IdentifierWasm::try_from(js_frozen_identity_id)?.into()); Ok(()) } } diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs index 992051f054e..3b2f6689d52 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs @@ -1,33 +1,33 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use crate::batch::token_base_transition::TokenBaseTransitionWasm; use dpp::prelude::Identifier; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use dpp::state_transition::batch_transition::TokenMintTransition; use dpp::state_transition::batch_transition::token_mint_transition::TokenMintTransitionV0; use dpp::state_transition::batch_transition::token_mint_transition::v0::v0_methods::TokenMintTransitionV0Methods; -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::token_configuration::TokenConfigurationWASM; +use crate::token_configuration::TokenConfigurationWasm; use crate::utils::WithJsError; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenMintTransition)] -pub struct TokenMintTransitionWASM(TokenMintTransition); +pub struct TokenMintTransitionWasm(TokenMintTransition); -impl From for TokenMintTransitionWASM { +impl From for TokenMintTransitionWasm { fn from(transition: TokenMintTransition) -> Self { Self(transition) } } -impl From for TokenMintTransition { - fn from(transition: TokenMintTransitionWASM) -> Self { +impl From for TokenMintTransition { + fn from(transition: TokenMintTransitionWasm) -> Self { transition.0 } } #[wasm_bindgen(js_class = TokenMintTransition)] -impl TokenMintTransitionWASM { +impl TokenMintTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenMintTransition".to_string() @@ -40,18 +40,18 @@ impl TokenMintTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - base: &TokenBaseTransitionWASM, + base: &TokenBaseTransitionWasm, js_issued_to_identity_id: &JsValue, amount: u64, public_note: Option, - ) -> Result { + ) -> Result { let issued_to_identity_id: Option = match js_issued_to_identity_id.is_undefined() { - false => Some(IdentifierWASM::try_from(js_issued_to_identity_id)?.into()), + false => Some(IdentifierWasm::try_from(js_issued_to_identity_id)?.into()), true => None, }; - Ok(TokenMintTransitionWASM(TokenMintTransition::V0( + Ok(TokenMintTransitionWasm(TokenMintTransition::V0( TokenMintTransitionV0 { base: base.clone().into(), issued_to_identity_id, @@ -62,7 +62,7 @@ impl TokenMintTransitionWASM { } #[wasm_bindgen(getter = issuedToIdentityId)] - pub fn issued_to_identity_id(&self) -> Option { + pub fn issued_to_identity_id(&self) -> Option { match self.0.issued_to_identity_id() { None => None, Some(id) => Some(id.into()), @@ -75,7 +75,7 @@ impl TokenMintTransitionWASM { } #[wasm_bindgen(getter = base)] - pub fn get_base(&self) -> TokenBaseTransitionWASM { + pub fn get_base(&self) -> TokenBaseTransitionWasm { self.0.base().clone().into() } @@ -85,7 +85,7 @@ impl TokenMintTransitionWASM { } #[wasm_bindgen(js_name = getRecipitnId)] - pub fn recipient_id(&self, config: &TokenConfigurationWASM) -> Result { + pub fn recipient_id(&self, config: &TokenConfigurationWasm) -> Result { Ok(self .0 .recipient_id(&config.clone().into()) @@ -100,7 +100,7 @@ impl TokenMintTransitionWASM { self.0.set_issued_to_identity_id(None); } false => { - let id = IdentifierWASM::try_from(js_id)?; + let id = IdentifierWasm::try_from(js_id)?; self.0.set_issued_to_identity_id(Some(id.into())); } @@ -115,7 +115,7 @@ impl TokenMintTransitionWASM { } #[wasm_bindgen(setter = base)] - pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + pub fn set_base(&mut self, base: TokenBaseTransitionWasm) { self.0.set_base(base.into()) } diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs index cb64d42db70..24839dc370e 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs @@ -1,35 +1,35 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use crate::batch::token_base_transition::TokenBaseTransitionWasm; use dpp::prelude::Identifier; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use dpp::state_transition::batch_transition::TokenTransferTransition; use dpp::state_transition::batch_transition::token_transfer_transition::TokenTransferTransitionV0; use dpp::state_transition::batch_transition::token_transfer_transition::v0::v0_methods::TokenTransferTransitionV0Methods; use dpp::tokens::{PrivateEncryptedNote, SharedEncryptedNote}; -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::encrypted_note::private_encrypted_note::PrivateEncryptedNoteWASM; -use crate::encrypted_note::shared_encrypted_note::SharedEncryptedNoteWASM; +use crate::encrypted_note::private_encrypted_note::PrivateEncryptedNoteWasm; +use crate::encrypted_note::shared_encrypted_note::SharedEncryptedNoteWasm; use crate::utils::IntoWasm; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenTransferTransition)] -pub struct TokenTransferTransitionWASM(TokenTransferTransition); +pub struct TokenTransferTransitionWasm(TokenTransferTransition); -impl From for TokenTransferTransitionWASM { +impl From for TokenTransferTransitionWasm { fn from(transition: TokenTransferTransition) -> Self { Self(transition) } } -impl From for TokenTransferTransition { - fn from(transition: TokenTransferTransitionWASM) -> Self { +impl From for TokenTransferTransition { + fn from(transition: TokenTransferTransitionWasm) -> Self { transition.0 } } #[wasm_bindgen(js_class = TokenTransferTransition)] -impl TokenTransferTransitionWASM { +impl TokenTransferTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenTransferTransition".to_string() @@ -42,21 +42,21 @@ impl TokenTransferTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - base: &TokenBaseTransitionWASM, + base: &TokenBaseTransitionWasm, js_recipient_id: &JsValue, amount: u64, public_note: Option, js_shared_encrypted_note: &JsValue, js_private_encrypted_note: &JsValue, - ) -> Result { - let recipient_id: Identifier = IdentifierWASM::try_from(js_recipient_id)?.into(); + ) -> Result { + let recipient_id: Identifier = IdentifierWasm::try_from(js_recipient_id)?.into(); let shared_encrypted_note: Option = match js_shared_encrypted_note.is_undefined() { true => None, false => Some( js_shared_encrypted_note - .to_wasm::("SharedEncryptedNote")? + .to_wasm::("SharedEncryptedNote")? .clone() .into(), ), @@ -67,13 +67,13 @@ impl TokenTransferTransitionWASM { true => None, false => Some( js_private_encrypted_note - .to_wasm::("PrivateEncryptedNote")? + .to_wasm::("PrivateEncryptedNote")? .clone() .into(), ), }; - Ok(TokenTransferTransitionWASM(TokenTransferTransition::V0( + Ok(TokenTransferTransitionWasm(TokenTransferTransition::V0( TokenTransferTransitionV0 { base: base.clone().into(), recipient_id, @@ -91,7 +91,7 @@ impl TokenTransferTransitionWASM { } #[wasm_bindgen(getter = "base")] - pub fn get_base(&self) -> TokenBaseTransitionWASM { + pub fn get_base(&self) -> TokenBaseTransitionWasm { self.0.base().clone().into() } @@ -101,7 +101,7 @@ impl TokenTransferTransitionWASM { } #[wasm_bindgen(getter = "sharedEncryptedNote")] - pub fn get_shared_encrypted_note(&self) -> Option { + pub fn get_shared_encrypted_note(&self) -> Option { match self.clone().0.shared_encrypted_note_owned() { Some(shared_encrypted_note) => Some(shared_encrypted_note.into()), None => None, @@ -109,7 +109,7 @@ impl TokenTransferTransitionWASM { } #[wasm_bindgen(getter = "privateEncryptedNote")] - pub fn get_private_encrypted_note(&self) -> Option { + pub fn get_private_encrypted_note(&self) -> Option { match self.clone().0.private_encrypted_note_owned() { Some(private_encrypted_note) => Some(private_encrypted_note.into()), None => None, @@ -117,13 +117,13 @@ impl TokenTransferTransitionWASM { } #[wasm_bindgen(getter = recipientId)] - pub fn recipient_id(&self) -> IdentifierWASM { + pub fn recipient_id(&self) -> IdentifierWasm { self.0.recipient_id().into() } #[wasm_bindgen(setter = recipientId)] pub fn set_recipient_id(&mut self, js_recipient: &JsValue) -> Result<(), JsValue> { - let recipient = IdentifierWASM::try_from(js_recipient)?; + let recipient = IdentifierWasm::try_from(js_recipient)?; self.0.set_recipient_id(recipient.into()); @@ -136,7 +136,7 @@ impl TokenTransferTransitionWASM { } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + pub fn set_base(&mut self, base: TokenBaseTransitionWasm) { self.0.set_base(base.into()) } @@ -155,7 +155,7 @@ impl TokenTransferTransitionWASM { true => None, false => Some( js_shared_encrypted_note - .to_wasm::("SharedEncryptedNote")? + .to_wasm::("SharedEncryptedNote")? .clone() .into(), ), @@ -174,7 +174,7 @@ impl TokenTransferTransitionWASM { true => None, false => Some( js_private_encrypted_note - .to_wasm::("PrivateEncryptedNote")? + .to_wasm::("PrivateEncryptedNote")? .clone() .into(), ), diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs index f65a8bac4f8..d59150191f2 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs @@ -1,31 +1,31 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWASM; +use crate::batch::token_base_transition::TokenBaseTransitionWasm; use dpp::identifier::Identifier; use dpp::state_transition::batch_transition::token_unfreeze_transition::TokenUnfreezeTransitionV0; use dpp::state_transition::batch_transition::TokenUnfreezeTransition; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use dpp::state_transition::batch_transition::token_unfreeze_transition::v0::v0_methods::TokenUnfreezeTransitionV0Methods; -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenUnFreezeTransition)] -pub struct TokenUnFreezeTransitionWASM(TokenUnfreezeTransition); +pub struct TokenUnFreezeTransitionWasm(TokenUnfreezeTransition); -impl From for TokenUnFreezeTransitionWASM { +impl From for TokenUnFreezeTransitionWasm { fn from(transition: TokenUnfreezeTransition) -> Self { Self(transition) } } -impl From for TokenUnfreezeTransition { - fn from(transition: TokenUnFreezeTransitionWASM) -> Self { +impl From for TokenUnfreezeTransition { + fn from(transition: TokenUnFreezeTransitionWasm) -> Self { transition.0 } } #[wasm_bindgen(js_class = TokenUnFreezeTransition)] -impl TokenUnFreezeTransitionWASM { +impl TokenUnFreezeTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenUnFreezeTransition".to_string() @@ -38,14 +38,14 @@ impl TokenUnFreezeTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - base: &TokenBaseTransitionWASM, + base: &TokenBaseTransitionWasm, js_frozen_identity_id: &JsValue, public_note: Option, - ) -> Result { + ) -> Result { let frozen_identity_id: Identifier = - IdentifierWASM::try_from(js_frozen_identity_id)?.into(); + IdentifierWasm::try_from(js_frozen_identity_id)?.into(); - Ok(TokenUnFreezeTransitionWASM(TokenUnfreezeTransition::V0( + Ok(TokenUnFreezeTransitionWasm(TokenUnfreezeTransition::V0( TokenUnfreezeTransitionV0 { base: base.clone().into(), frozen_identity_id, @@ -55,7 +55,7 @@ impl TokenUnFreezeTransitionWASM { } #[wasm_bindgen(getter = "base")] - pub fn get_base(&self) -> TokenBaseTransitionWASM { + pub fn get_base(&self) -> TokenBaseTransitionWasm { self.0.base().clone().into() } @@ -65,12 +65,12 @@ impl TokenUnFreezeTransitionWASM { } #[wasm_bindgen(getter = "frozenIdentityId")] - pub fn get_frozen_identity_id(&self) -> IdentifierWASM { + pub fn get_frozen_identity_id(&self) -> IdentifierWasm { self.0.frozen_identity_id().into() } #[wasm_bindgen(setter = "base")] - pub fn set_base(&mut self, base: TokenBaseTransitionWASM) { + pub fn set_base(&mut self, base: TokenBaseTransitionWasm) { self.0.set_base(base.into()) } @@ -85,7 +85,7 @@ impl TokenUnFreezeTransitionWASM { js_frozen_identity_id: &JsValue, ) -> Result<(), JsValue> { self.0 - .set_frozen_identity_id(IdentifierWASM::try_from(js_frozen_identity_id)?.into()); + .set_frozen_identity_id(IdentifierWasm::try_from(js_frozen_identity_id)?.into()); Ok(()) } } diff --git a/packages/wasm-dpp2/src/consensus_error/mod.rs b/packages/wasm-dpp2/src/consensus_error/mod.rs index 1878d1d752b..a837cddabf3 100644 --- a/packages/wasm-dpp2/src/consensus_error/mod.rs +++ b/packages/wasm-dpp2/src/consensus_error/mod.rs @@ -5,13 +5,13 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "ConsensusError")] -pub struct ConsensusErrorWASM(ConsensusError); +pub struct ConsensusErrorWasm(ConsensusError); #[wasm_bindgen(js_class = ConsensusError)] -impl ConsensusErrorWASM { +impl ConsensusErrorWasm { #[wasm_bindgen(js_name = "deserialize")] pub fn deserialize(error: Vec) -> Result { - Ok(ConsensusErrorWASM( + Ok(ConsensusErrorWasm( ConsensusError::deserialize_from_bytes(error.as_slice()).with_js_error()?, )) } diff --git a/packages/wasm-dpp2/src/contract_bounds/mod.rs b/packages/wasm-dpp2/src/contract_bounds/mod.rs index 0d806625e74..398643a2ba1 100644 --- a/packages/wasm-dpp2/src/contract_bounds/mod.rs +++ b/packages/wasm-dpp2/src/contract_bounds/mod.rs @@ -1,26 +1,26 @@ -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use dpp::identity::contract_bounds::ContractBounds; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "ContractBounds")] #[derive(Clone)] -pub struct ContractBoundsWASM(ContractBounds); +pub struct ContractBoundsWasm(ContractBounds); -impl From for ContractBoundsWASM { +impl From for ContractBoundsWasm { fn from(bounds: ContractBounds) -> Self { - ContractBoundsWASM(bounds) + ContractBoundsWasm(bounds) } } -impl From for ContractBounds { - fn from(bounds: ContractBoundsWASM) -> Self { +impl From for ContractBounds { + fn from(bounds: ContractBoundsWasm) -> Self { bounds.0 } } #[wasm_bindgen(js_class = ContractBounds)] -impl ContractBoundsWASM { +impl ContractBoundsWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "ContractBounds".to_string() @@ -35,10 +35,10 @@ impl ContractBoundsWASM { pub fn new( js_contract_id: &JsValue, document_type_name: Option, - ) -> Result { - let contract_id = IdentifierWASM::try_from(js_contract_id)?; + ) -> Result { + let contract_id = IdentifierWasm::try_from(js_contract_id)?; - Ok(ContractBoundsWASM(match document_type_name { + Ok(ContractBoundsWasm(match document_type_name { Some(document_type_name) => ContractBounds::SingleContractDocumentType { id: contract_id.into(), document_type_name, @@ -50,10 +50,10 @@ impl ContractBoundsWASM { } #[wasm_bindgen(js_name = "SingleContract")] - pub fn single_contract(js_contract_id: &JsValue) -> Result { - let contract_id = IdentifierWASM::try_from(js_contract_id)?; + pub fn single_contract(js_contract_id: &JsValue) -> Result { + let contract_id = IdentifierWasm::try_from(js_contract_id)?; - Ok(ContractBoundsWASM(ContractBounds::SingleContract { + Ok(ContractBoundsWasm(ContractBounds::SingleContract { id: contract_id.into(), })) } @@ -62,10 +62,10 @@ impl ContractBoundsWASM { pub fn single_contract_document_type_name( js_contract_id: &JsValue, document_type_name: String, - ) -> Result { - let contract_id = IdentifierWASM::try_from(js_contract_id)?; + ) -> Result { + let contract_id = IdentifierWasm::try_from(js_contract_id)?; - Ok(ContractBoundsWASM( + Ok(ContractBoundsWasm( ContractBounds::SingleContractDocumentType { id: contract_id.into(), document_type_name, @@ -74,7 +74,7 @@ impl ContractBoundsWASM { } #[wasm_bindgen(getter = "identifier")] - pub fn id(&self) -> IdentifierWASM { + pub fn id(&self) -> IdentifierWasm { self.0.identifier().clone().into() } @@ -98,7 +98,7 @@ impl ContractBoundsWASM { #[wasm_bindgen(setter = "identifier")] pub fn set_id(&mut self, js_contract_id: &JsValue) -> Result<(), JsValue> { - let contract_id = IdentifierWASM::try_from(js_contract_id)?; + let contract_id = IdentifierWasm::try_from(js_contract_id)?; self.0 = match self.clone().0 { ContractBounds::SingleContract { .. } => ContractBounds::SingleContract { diff --git a/packages/wasm-dpp2/src/core_script/mod.rs b/packages/wasm-dpp2/src/core_script/mod.rs index bbf88c978b8..52817764b0f 100644 --- a/packages/wasm-dpp2/src/core_script/mod.rs +++ b/packages/wasm-dpp2/src/core_script/mod.rs @@ -1,4 +1,4 @@ -use crate::enums::network::NetworkWASM; +use crate::enums::network::NetworkWasm; use dpp::dashcore::address::Payload; use dpp::dashcore::{Address, opcodes}; use dpp::identity::core_script::CoreScript; @@ -9,22 +9,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "CoreScript")] #[derive(Clone)] -pub struct CoreScriptWASM(CoreScript); +pub struct CoreScriptWasm(CoreScript); -impl From for CoreScript { - fn from(value: CoreScriptWASM) -> Self { +impl From for CoreScript { + fn from(value: CoreScriptWasm) -> Self { value.0 } } -impl From for CoreScriptWASM { +impl From for CoreScriptWasm { fn from(value: CoreScript) -> Self { - CoreScriptWASM(value) + CoreScriptWasm(value) } } #[wasm_bindgen(js_class = CoreScript)] -impl CoreScriptWASM { +impl CoreScriptWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "CoreScript".to_string() @@ -37,7 +37,7 @@ impl CoreScriptWASM { #[wasm_bindgen(js_name = "fromBytes")] pub fn from_bytes(bytes: Vec) -> Self { - CoreScriptWASM(CoreScript::from_bytes(bytes)) + CoreScriptWasm(CoreScript::from_bytes(bytes)) } #[wasm_bindgen(js_name = "newP2PKH")] @@ -47,7 +47,7 @@ impl CoreScriptWASM { let len = bytes.len().min(32); key_hash[..len].copy_from_slice(&bytes[..len]); - CoreScriptWASM(CoreScript::new_p2pkh(key_hash)) + CoreScriptWasm(CoreScript::new_p2pkh(key_hash)) } #[wasm_bindgen(js_name = "newP2SH")] @@ -68,7 +68,7 @@ impl CoreScriptWASM { #[wasm_bindgen(js_name = "toAddress")] pub fn to_address(&self, js_network: &JsValue) -> Result { - let network = NetworkWASM::try_from(js_network.clone())?; + let network = NetworkWasm::try_from(js_network.clone())?; let payload = Payload::from_script(self.0.as_script()).map_err(|e| JsValue::from(e.to_string()))?; diff --git a/packages/wasm-dpp2/src/data_contract/mod.rs b/packages/wasm-dpp2/src/data_contract/mod.rs index e16f1124438..5bb8bb8aa69 100644 --- a/packages/wasm-dpp2/src/data_contract/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/mod.rs @@ -1,7 +1,7 @@ -use crate::enums::platform::PlatformVersionWASM; -use crate::identifier::IdentifierWASM; -use crate::token_configuration::TokenConfigurationWASM; -use crate::token_configuration::group::GroupWASM; +use crate::enums::platform::PlatformVersionWasm; +use crate::identifier::IdentifierWasm; +use crate::token_configuration::TokenConfigurationWasm; +use crate::token_configuration::group::GroupWasm; use crate::utils::{IntoWasm, ToSerdeJSONExt, WithJsError}; use dpp::dashcore::hashes::serde::Serialize; use dpp::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters}; @@ -32,16 +32,16 @@ use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "DataContract")] #[derive(Clone)] -pub struct DataContractWASM(DataContract); +pub struct DataContractWasm(DataContract); -impl From for DataContractWASM { +impl From for DataContractWasm { fn from(v: DataContract) -> Self { - DataContractWASM(v) + DataContractWasm(v) } } -impl From for DataContract { - fn from(v: DataContractWASM) -> Self { +impl From for DataContract { + fn from(v: DataContractWasm) -> Self { v.0 } } @@ -63,7 +63,7 @@ pub fn tokens_configuration_from_js_value( }?; let js_config = Reflect::get(&js_configuration, &key)? - .to_wasm::("TokenConfiguration")? + .to_wasm::("TokenConfiguration")? .clone(); configuration.insert(contract_position, js_config.into()); @@ -73,7 +73,7 @@ pub fn tokens_configuration_from_js_value( } #[wasm_bindgen(js_class = DataContract)] -impl DataContractWASM { +impl DataContractWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "DataContract".to_string() @@ -93,10 +93,10 @@ impl DataContractWASM { js_tokens: &JsValue, full_validation: bool, js_platform_version: JsValue, - ) -> Result { + ) -> Result { let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - let owner_id: IdentifierWASM = js_owner_id.clone().try_into()?; + let owner_id: IdentifierWasm = js_owner_id.clone().try_into()?; let owner_id_value = Value::from(owner_id.get_base58()); @@ -109,8 +109,8 @@ impl DataContractWASM { }; let platform_version: PlatformVersion = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default().into(), - false => PlatformVersionWASM::try_from(js_platform_version)?.into(), + true => PlatformVersionWasm::default().into(), + false => PlatformVersionWasm::try_from(js_platform_version)?.into(), }; let data_contract_structure_version_value = Value::from( @@ -183,7 +183,7 @@ impl DataContractWASM { } }; - Ok(DataContractWASM(data_contract_with_tokens)) + Ok(DataContractWasm(data_contract_with_tokens)) } #[wasm_bindgen(js_name = "fromValue")] @@ -191,10 +191,10 @@ impl DataContractWASM { js_value: JsValue, full_validation: bool, js_platform_version: JsValue, - ) -> Result { + ) -> Result { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let value = js_value.with_serde_to_platform_value()?; @@ -202,7 +202,7 @@ impl DataContractWASM { let contract = DataContract::from_value(value, full_validation, &platform_version.into()) .with_js_error()?; - Ok(DataContractWASM(contract)) + Ok(DataContractWasm(contract)) } #[wasm_bindgen(js_name = "fromBytes")] @@ -210,10 +210,10 @@ impl DataContractWASM { bytes: Vec, full_validation: bool, js_platform_version: JsValue, - ) -> Result { + ) -> Result { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let rs_data_contract = DataContract::versioned_deserialize( @@ -223,7 +223,7 @@ impl DataContractWASM { ) .with_js_error()?; - Ok(DataContractWASM(rs_data_contract)) + Ok(DataContractWasm(rs_data_contract)) } #[wasm_bindgen(js_name = "fromHex")] @@ -231,8 +231,8 @@ impl DataContractWASM { hex: String, full_validation: bool, js_platform_version: JsValue, - ) -> Result { - DataContractWASM::from_bytes( + ) -> Result { + DataContractWasm::from_bytes( decode(hex.as_str(), Hex).map_err(JsError::from)?, full_validation, js_platform_version, @@ -244,8 +244,8 @@ impl DataContractWASM { base64: String, full_validation: bool, js_platform_version: JsValue, - ) -> Result { - DataContractWASM::from_bytes( + ) -> Result { + DataContractWasm::from_bytes( decode(base64.as_str(), Base64).map_err(JsError::from)?, full_validation, js_platform_version, @@ -255,8 +255,8 @@ impl DataContractWASM { #[wasm_bindgen(js_name = "bytes")] pub fn to_bytes(&self, js_platform_version: JsValue) -> Result, JsValue> { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let rs_data_contract: DataContract = self.0.clone(); @@ -282,8 +282,8 @@ impl DataContractWASM { #[wasm_bindgen(js_name = "toValue")] pub fn to_value(&self, js_platform_version: JsValue) -> Result { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let serializer = serde_wasm_bindgen::Serializer::json_compatible(); @@ -312,12 +312,12 @@ impl DataContractWASM { } #[wasm_bindgen(getter = "id")] - pub fn get_id(&self) -> IdentifierWASM { + pub fn get_id(&self) -> IdentifierWasm { self.0.id().into() } #[wasm_bindgen(getter = "ownerId")] - pub fn get_owner_id(&self) -> IdentifierWASM { + pub fn get_owner_id(&self) -> IdentifierWasm { self.0.owner_id().into() } @@ -337,7 +337,7 @@ impl DataContractWASM { Reflect::set( &tokens_object, &JsValue::from(key.clone()), - &JsValue::from(TokenConfigurationWASM::from(value.clone())), + &JsValue::from(TokenConfigurationWasm::from(value.clone())), )?; } @@ -352,7 +352,7 @@ impl DataContractWASM { Reflect::set( &groups_object, &JsValue::from(key.clone()), - &JsValue::from(GroupWASM::from(value.clone())), + &JsValue::from(GroupWasm::from(value.clone())), )?; } @@ -362,14 +362,14 @@ impl DataContractWASM { #[wasm_bindgen(setter = "id")] pub fn set_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> { self.0 - .set_id(IdentifierWASM::try_from(js_data_contract_id)?.into()); + .set_id(IdentifierWasm::try_from(js_data_contract_id)?.into()); Ok(()) } #[wasm_bindgen(setter = "ownerId")] pub fn set_owner_id(&mut self, js_owner_id: &JsValue) -> Result<(), JsValue> { self.0 - .set_owner_id(IdentifierWASM::try_from(js_owner_id)?.into()); + .set_owner_id(IdentifierWasm::try_from(js_owner_id)?.into()); Ok(()) } @@ -385,8 +385,8 @@ impl DataContractWASM { js_platform_version: JsValue, ) -> Result<(), JsValue> { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let config_value: Value = serde_wasm_bindgen::from_value(js_config)?; @@ -408,8 +408,8 @@ impl DataContractWASM { js_platform_version: JsValue, ) -> Result<(), JsValue> { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let schema = js_schema.with_serde_to_platform_value_map()?; @@ -456,7 +456,7 @@ impl DataContractWASM { let js_group = Reflect::get(&groups_object, &js_position)?; - let group = js_group.to_wasm::("Group")?.clone(); + let group = js_group.to_wasm::("Group")?.clone(); groups.insert(position, group.into()); } @@ -469,8 +469,8 @@ impl DataContractWASM { #[wasm_bindgen(js_name = "toJson")] pub fn to_json(&self, js_platform_version: JsValue) -> Result { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let json = self.0.to_json(&platform_version.into()).with_js_error()?; @@ -483,16 +483,16 @@ impl DataContractWASM { pub fn generate_id( js_owner_id: &JsValue, identity_nonce: IdentityNonce, - ) -> Result { + ) -> Result { Ok(DataContract::generate_data_contract_id_v0( - IdentifierWASM::try_from(js_owner_id)?.get_bytes(), + IdentifierWasm::try_from(js_owner_id)?.get_bytes(), identity_nonce, ) .into()) } } -impl DataContractWASM { +impl DataContractWasm { pub fn get_document_type_ref_by_name( &self, name: String, diff --git a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs index 8a6398758d6..842fc022941 100644 --- a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs +++ b/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs @@ -1,6 +1,6 @@ -use crate::data_contract::DataContractWASM; -use crate::enums::platform::PlatformVersionWASM; -use crate::state_transition::StateTransitionWASM; +use crate::data_contract::DataContractWasm; +use crate::enums::platform::PlatformVersionWasm; +use crate::state_transition::StateTransitionWasm; use crate::utils::WithJsError; use dpp::ProtocolError; use dpp::data_contract::serialized_version::DataContractInSerializationFormat; @@ -21,10 +21,10 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "DataContractCreateTransition")] -pub struct DataContractCreateTransitionWASM(DataContractCreateTransition); +pub struct DataContractCreateTransitionWasm(DataContractCreateTransition); #[wasm_bindgen(js_class = DataContractCreateTransition)] -impl DataContractCreateTransitionWASM { +impl DataContractCreateTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "DataContractCreateTransition".to_string() @@ -37,15 +37,15 @@ impl DataContractCreateTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - data_contract: &DataContractWASM, + data_contract: &DataContractWasm, identity_nonce: IdentityNonce, js_platform_version: JsValue, - ) -> Result { + ) -> Result { let rs_data_contract: DataContract = data_contract.clone().into(); let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let rs_data_contract_in_serialized: Result< @@ -65,34 +65,34 @@ impl DataContractCreateTransitionWASM { let rs_data_contract_transition = DataContractCreateTransition::V0(rs_data_contract_create_transition_v0); - Ok(DataContractCreateTransitionWASM( + Ok(DataContractCreateTransitionWasm( rs_data_contract_transition, )) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { let rs_data_contract_create_transition: DataContractCreateTransition = DataContractCreateTransition::deserialize_from_bytes(bytes.as_slice()) .with_js_error()?; - Ok(DataContractCreateTransitionWASM( + Ok(DataContractCreateTransitionWasm( rs_data_contract_create_transition, )) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { + pub fn from_hex(hex: String) -> Result { let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; - DataContractCreateTransitionWASM::from_bytes(bytes) + DataContractCreateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { + pub fn from_base64(base64: String) -> Result { let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; - DataContractCreateTransitionWASM::from_bytes(bytes) + DataContractCreateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "bytes")] @@ -134,12 +134,12 @@ impl DataContractCreateTransitionWASM { #[wasm_bindgen(js_name = "setDataContract")] pub fn set_data_contract( &mut self, - data_contract: &DataContractWASM, + data_contract: &DataContractWasm, js_platform_version: JsValue, ) -> Result<(), JsValue> { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let data_contract_serialization_format = @@ -164,10 +164,10 @@ impl DataContractCreateTransitionWASM { &self, js_platform_version: JsValue, full_validation: Option, - ) -> Result { + ) -> Result { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let rs_data_contract_serialization_format = self.0.data_contract(); @@ -182,25 +182,25 @@ impl DataContractCreateTransitionWASM { ) .with_js_error()?; - Ok(DataContractWASM::from(rs_data_contract)) + Ok(DataContractWasm::from(rs_data_contract)) } #[wasm_bindgen(js_name = "toStateTransition")] - pub fn to_state_transition(&self) -> StateTransitionWASM { + pub fn to_state_transition(&self) -> StateTransitionWasm { let rs_state_transition = StateTransition::from(self.0.clone()); - StateTransitionWASM::from(rs_state_transition) + StateTransitionWasm::from(rs_state_transition) } #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( - state_transition: &StateTransitionWASM, - ) -> Result { + state_transition: &StateTransitionWasm, + ) -> Result { let rs_transition = StateTransition::from(state_transition.clone()); match rs_transition { StateTransition::DataContractCreate(state_transition) => { - Ok(DataContractCreateTransitionWASM(state_transition)) + Ok(DataContractCreateTransitionWasm(state_transition)) } _ => Err(JsValue::from("Incorrect transition type")), } diff --git a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs index b3481866527..75fe1be7428 100644 --- a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs +++ b/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs @@ -1,6 +1,6 @@ -use crate::data_contract::DataContractWASM; -use crate::enums::platform::PlatformVersionWASM; -use crate::state_transition::StateTransitionWASM; +use crate::data_contract::DataContractWasm; +use crate::enums::platform::PlatformVersionWasm; +use crate::state_transition::StateTransitionWasm; use crate::utils::WithJsError; use dpp::data_contract::serialized_version::DataContractInSerializationFormat; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; @@ -16,10 +16,10 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "DataContractUpdateTransition")] -pub struct DataContractUpdateTransitionWASM(DataContractUpdateTransition); +pub struct DataContractUpdateTransitionWasm(DataContractUpdateTransition); #[wasm_bindgen(js_class = DataContractUpdateTransition)] -impl DataContractUpdateTransitionWASM { +impl DataContractUpdateTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "DataContractUpdateTransition".to_string() @@ -32,13 +32,13 @@ impl DataContractUpdateTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - data_contract: &DataContractWASM, + data_contract: &DataContractWasm, identity_nonce: IdentityNonce, js_platform_version: JsValue, - ) -> Result { + ) -> Result { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let rs_data_contract_update_transition = @@ -48,34 +48,34 @@ impl DataContractUpdateTransitionWASM { ) .with_js_error()?; - Ok(DataContractUpdateTransitionWASM( + Ok(DataContractUpdateTransitionWasm( rs_data_contract_update_transition, )) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { let rs_data_contract_update_transition: DataContractUpdateTransition = DataContractUpdateTransition::deserialize_from_bytes(bytes.as_slice()) .with_js_error()?; - Ok(DataContractUpdateTransitionWASM( + Ok(DataContractUpdateTransitionWasm( rs_data_contract_update_transition, )) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { + pub fn from_hex(hex: String) -> Result { let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; - DataContractUpdateTransitionWASM::from_bytes(bytes) + DataContractUpdateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { + pub fn from_base64(base64: String) -> Result { let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; - DataContractUpdateTransitionWASM::from_bytes(bytes) + DataContractUpdateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "bytes")] @@ -117,12 +117,12 @@ impl DataContractUpdateTransitionWASM { #[wasm_bindgen(js_name = "setDataContract")] pub fn set_data_contract( &mut self, - data_contract: &DataContractWASM, + data_contract: &DataContractWasm, js_platform_version: JsValue, ) -> Result<(), JsValue> { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let data_contract_serialization_format = @@ -147,10 +147,10 @@ impl DataContractUpdateTransitionWASM { &self, full_validation: Option, js_platform_version: JsValue, - ) -> Result { + ) -> Result { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let data_contract_serialization_format = self.0.data_contract(); @@ -165,25 +165,25 @@ impl DataContractUpdateTransitionWASM { ) .with_js_error()?; - Ok(DataContractWASM::from(rs_data_contract)) + Ok(DataContractWasm::from(rs_data_contract)) } #[wasm_bindgen(js_name = "toStateTransition")] - pub fn to_state_transition(&self) -> StateTransitionWASM { + pub fn to_state_transition(&self) -> StateTransitionWasm { let rs_state_transition = StateTransition::from(self.0.clone()); - StateTransitionWASM::from(rs_state_transition) + StateTransitionWasm::from(rs_state_transition) } #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( - state_transition: &StateTransitionWASM, - ) -> Result { + state_transition: &StateTransitionWasm, + ) -> Result { let rs_transition = StateTransition::from(state_transition.clone()); match rs_transition { StateTransition::DataContractUpdate(state_transition) => { - Ok(DataContractUpdateTransitionWASM(state_transition)) + Ok(DataContractUpdateTransitionWasm(state_transition)) } _ => Err(JsValue::from("Incorrect transition type")), } diff --git a/packages/wasm-dpp2/src/document/methods/mod.rs b/packages/wasm-dpp2/src/document/methods/mod.rs index 7e686ccb7f7..db76f30cffd 100644 --- a/packages/wasm-dpp2/src/document/methods/mod.rs +++ b/packages/wasm-dpp2/src/document/methods/mod.rs @@ -1,7 +1,7 @@ -use crate::data_contract::DataContractWASM; -use crate::document::DocumentWASM; -use crate::enums::platform::PlatformVersionWASM; -use crate::identifier::IdentifierWASM; +use crate::data_contract::DataContractWasm; +use crate::document::DocumentWasm; +use crate::enums::platform::PlatformVersionWasm; +use crate::identifier::IdentifierWasm; use crate::utils::{ToSerdeJSONExt, WithJsError}; use dpp::ProtocolError; use dpp::dashcore::hashes::serde::Serialize; @@ -21,7 +21,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_class = Document)] -impl DocumentWASM { +impl DocumentWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "Document".to_string() @@ -40,9 +40,9 @@ impl DocumentWASM { js_data_contract_id: &JsValue, js_owner_id: &JsValue, js_document_id: &JsValue, - ) -> Result { - let data_contract_id = IdentifierWASM::try_from(js_data_contract_id)?; - let owner_id = IdentifierWASM::try_from(js_owner_id)?; + ) -> Result { + let data_contract_id = IdentifierWasm::try_from(js_data_contract_id)?; + let owner_id = IdentifierWasm::try_from(js_owner_id)?; let revision = Revision::from(js_revision); @@ -56,7 +56,7 @@ impl DocumentWASM { .generate() .map_err(|err| JsValue::from(err.to_string()))?; - let document_id: IdentifierWASM = match js_document_id.is_undefined() { + let document_id: IdentifierWasm = match js_document_id.is_undefined() { true => crate::utils::generate_document_id_v0( &data_contract_id.into(), &owner_id.into(), @@ -67,7 +67,7 @@ impl DocumentWASM { false => js_document_id.try_into()?, }; - Ok(DocumentWASM { + Ok(DocumentWasm { owner_id, entropy: Some(entropy), id: document_id, @@ -88,7 +88,7 @@ impl DocumentWASM { } #[wasm_bindgen(getter=id)] - pub fn get_id(&self) -> IdentifierWASM { + pub fn get_id(&self) -> IdentifierWasm { self.id } @@ -101,12 +101,12 @@ impl DocumentWASM { } #[wasm_bindgen(getter=dataContractId)] - pub fn get_data_contract_id(&self) -> IdentifierWASM { + pub fn get_data_contract_id(&self) -> IdentifierWasm { self.data_contract_id } #[wasm_bindgen(getter=ownerId)] - pub fn get_owner_id(&self) -> IdentifierWASM { + pub fn get_owner_id(&self) -> IdentifierWasm { self.owner_id } @@ -180,7 +180,7 @@ impl DocumentWASM { #[wasm_bindgen(setter=id)] pub fn set_id(&mut self, id: &JsValue) -> Result<(), JsValue> { - self.id = IdentifierWASM::try_from(id)?.clone(); + self.id = IdentifierWasm::try_from(id)?.clone(); Ok(()) } @@ -202,14 +202,14 @@ impl DocumentWASM { #[wasm_bindgen(setter=dataContractId)] pub fn set_js_data_contract_id(&mut self, js_contract_id: &JsValue) -> Result<(), JsValue> { - self.data_contract_id = IdentifierWASM::try_from(js_contract_id.clone())?; + self.data_contract_id = IdentifierWasm::try_from(js_contract_id.clone())?; Ok(()) } #[wasm_bindgen(setter=ownerId)] pub fn set_owner_id(&mut self, id: &JsValue) -> Result<(), JsValue> { - self.owner_id = IdentifierWASM::try_from(id)?.clone(); + self.owner_id = IdentifierWasm::try_from(id)?.clone(); Ok(()) } @@ -279,12 +279,12 @@ impl DocumentWASM { #[wasm_bindgen(js_name=bytes)] pub fn to_bytes( &self, - data_contract: &DataContractWASM, + data_contract: &DataContractWasm, js_platform_version: JsValue, ) -> Result, JsValue> { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let rs_document: Document = Document::from(self.clone()); @@ -305,7 +305,7 @@ impl DocumentWASM { #[wasm_bindgen(js_name=hex)] pub fn to_hex( &self, - data_contract: &DataContractWASM, + data_contract: &DataContractWasm, js_platform_version: JsValue, ) -> Result { Ok(encode( @@ -318,7 +318,7 @@ impl DocumentWASM { #[wasm_bindgen(js_name=base64)] pub fn to_base64( &self, - data_contract: &DataContractWASM, + data_contract: &DataContractWasm, js_platform_version: JsValue, ) -> Result { Ok(encode( @@ -331,13 +331,13 @@ impl DocumentWASM { #[wasm_bindgen(js_name=fromBytes)] pub fn from_bytes( bytes: Vec, - data_contract: &DataContractWASM, + data_contract: &DataContractWasm, type_name: String, js_platform_version: JsValue, - ) -> Result { + ) -> Result { let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWASM::default(), - false => PlatformVersionWASM::try_from(js_platform_version)?, + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, }; let document_type_ref = match data_contract.get_document_type_ref_by_name(type_name.clone()) @@ -353,7 +353,7 @@ impl DocumentWASM { ) .with_js_error()?; - let mut js_document = DocumentWASM::from(rs_document); + let mut js_document = DocumentWasm::from(rs_document); js_document.set_document_type_name(type_name.clone().as_str()); js_document.set_data_contract_id(&data_contract.get_id()); @@ -364,11 +364,11 @@ impl DocumentWASM { #[wasm_bindgen(js_name=fromHex)] pub fn from_hex( hex: String, - data_contract: &DataContractWASM, + data_contract: &DataContractWasm, type_name: String, js_platform_version: JsValue, - ) -> Result { - DocumentWASM::from_bytes( + ) -> Result { + DocumentWasm::from_bytes( decode(hex.as_str(), Hex).map_err(JsError::from)?, data_contract, type_name, @@ -379,11 +379,11 @@ impl DocumentWASM { #[wasm_bindgen(js_name=fromBase64)] pub fn from_base64( base64: String, - data_contract: &DataContractWASM, + data_contract: &DataContractWasm, type_name: String, js_platform_version: JsValue, - ) -> Result { - DocumentWASM::from_bytes( + ) -> Result { + DocumentWasm::from_bytes( decode(base64.as_str(), Base64).map_err(JsError::from)?, data_contract, type_name, @@ -398,8 +398,8 @@ impl DocumentWASM { js_data_contract_id: &JsValue, opt_entropy: Option>, ) -> Result, JsValue> { - let owner_id = IdentifierWASM::try_from(js_owner_id)?; - let data_contract_id = IdentifierWASM::try_from(js_data_contract_id)?; + let owner_id = IdentifierWasm::try_from(js_owner_id)?; + let data_contract_id = IdentifierWasm::try_from(js_data_contract_id)?; let entropy: [u8; 32] = match opt_entropy { Some(entropy_vec) => { @@ -428,7 +428,7 @@ impl DocumentWASM { } } -impl DocumentWASM { +impl DocumentWasm { pub fn rs_get_owner_id(&self) -> Identifier { self.owner_id.into() } @@ -449,7 +449,7 @@ impl DocumentWASM { self.clone().properties } - fn set_data_contract_id(&mut self, data_contract_id: &IdentifierWASM) { + fn set_data_contract_id(&mut self, data_contract_id: &IdentifierWasm) { self.data_contract_id = data_contract_id.clone(); } } diff --git a/packages/wasm-dpp2/src/document/mod.rs b/packages/wasm-dpp2/src/document/mod.rs index be1d1cff8c7..326fa00f7b9 100644 --- a/packages/wasm-dpp2/src/document/mod.rs +++ b/packages/wasm-dpp2/src/document/mod.rs @@ -1,6 +1,6 @@ pub mod methods; -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use dpp::document::{Document, DocumentV0, DocumentV0Getters}; use dpp::identifier::Identifier; use dpp::identity::TimestampMillis; @@ -11,11 +11,11 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] #[wasm_bindgen(js_name = Document)] -pub struct DocumentWASM { - id: IdentifierWASM, - owner_id: IdentifierWASM, +pub struct DocumentWasm { + id: IdentifierWasm, + owner_id: IdentifierWasm, revision: Option, - data_contract_id: IdentifierWASM, + data_contract_id: IdentifierWasm, document_type_name: String, properties: BTreeMap, created_at: Option, @@ -30,8 +30,8 @@ pub struct DocumentWASM { entropy: Option<[u8; 32]>, } -impl From for Document { - fn from(wasm_doc: DocumentWASM) -> Self { +impl From for Document { + fn from(wasm_doc: DocumentWasm) -> Self { Document::V0(DocumentV0 { id: wasm_doc.id.into(), owner_id: wasm_doc.owner_id.into(), @@ -50,9 +50,9 @@ impl From for Document { } } -impl From for DocumentWASM { +impl From for DocumentWasm { fn from(doc: Document) -> Self { - DocumentWASM { + DocumentWasm { id: doc.id().into(), owner_id: doc.owner_id().into(), revision: doc.revision(), @@ -73,14 +73,14 @@ impl From for DocumentWASM { } } -impl DocumentWASM { +impl DocumentWasm { pub fn from_batch( document: Document, data_contract_id: Identifier, document_type_name: String, entropy: Option<[u8; 32]>, ) -> Self { - DocumentWASM { + DocumentWasm { id: document.id().into(), owner_id: document.owner_id().into(), revision: document.revision(), diff --git a/packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs b/packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs index c1cb09b5b3b..e04ea38607a 100644 --- a/packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs +++ b/packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs @@ -4,22 +4,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name = "PrivateEncryptedNote")] -pub struct PrivateEncryptedNoteWASM(PrivateEncryptedNote); +pub struct PrivateEncryptedNoteWasm(PrivateEncryptedNote); -impl From for PrivateEncryptedNoteWASM { +impl From for PrivateEncryptedNoteWasm { fn from(value: PrivateEncryptedNote) -> Self { - PrivateEncryptedNoteWASM(value) + PrivateEncryptedNoteWasm(value) } } -impl From for PrivateEncryptedNote { - fn from(value: PrivateEncryptedNoteWASM) -> Self { +impl From for PrivateEncryptedNote { + fn from(value: PrivateEncryptedNoteWasm) -> Self { value.0 } } #[wasm_bindgen(js_class = PrivateEncryptedNote)] -impl PrivateEncryptedNoteWASM { +impl PrivateEncryptedNoteWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "PrivateEncryptedNote".to_string() @@ -35,8 +35,8 @@ impl PrivateEncryptedNoteWASM { root_encryption_key_index: RootEncryptionKeyIndex, derivation_encryption_key_index: DerivationEncryptionKeyIndex, value: Vec, - ) -> PrivateEncryptedNoteWASM { - PrivateEncryptedNoteWASM(( + ) -> PrivateEncryptedNoteWasm { + PrivateEncryptedNoteWasm(( root_encryption_key_index, derivation_encryption_key_index, value, diff --git a/packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs b/packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs index 5e00b85d2a3..63ea8b80c70 100644 --- a/packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs +++ b/packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs @@ -4,22 +4,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name = "SharedEncryptedNote")] -pub struct SharedEncryptedNoteWASM(SharedEncryptedNote); +pub struct SharedEncryptedNoteWasm(SharedEncryptedNote); -impl From for SharedEncryptedNoteWASM { +impl From for SharedEncryptedNoteWasm { fn from(note: SharedEncryptedNote) -> Self { Self(note) } } -impl From for SharedEncryptedNote { - fn from(note: SharedEncryptedNoteWASM) -> Self { +impl From for SharedEncryptedNote { + fn from(note: SharedEncryptedNoteWasm) -> Self { note.0 } } #[wasm_bindgen(js_class = SharedEncryptedNote)] -impl SharedEncryptedNoteWASM { +impl SharedEncryptedNoteWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "SharedEncryptedNote".to_string() @@ -36,7 +36,7 @@ impl SharedEncryptedNoteWASM { recipient_key_index: RecipientKeyIndex, value: Vec, ) -> Self { - SharedEncryptedNoteWASM((sender_key_index, recipient_key_index, value)) + SharedEncryptedNoteWasm((sender_key_index, recipient_key_index, value)) } #[wasm_bindgen(getter = "senderKeyIndex")] diff --git a/packages/wasm-dpp2/src/enums/batch/batch_enum.rs b/packages/wasm-dpp2/src/enums/batch/batch_enum.rs index 28b19a2cc4e..452f340d570 100644 --- a/packages/wasm-dpp2/src/enums/batch/batch_enum.rs +++ b/packages/wasm-dpp2/src/enums/batch/batch_enum.rs @@ -3,7 +3,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "BatchType")] -pub enum BatchTypeWASM { +pub enum BatchTypeWasm { Create, Replace, Delete, @@ -13,20 +13,20 @@ pub enum BatchTypeWASM { IgnoreWhileBumpingRevision, } -impl TryFrom for BatchTypeWASM { +impl TryFrom for BatchTypeWasm { type Error = JsValue; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "create" => Ok(BatchTypeWASM::Create), - "replace" => Ok(BatchTypeWASM::Replace), - "delete" => Ok(BatchTypeWASM::Delete), - "transfer" => Ok(BatchTypeWASM::Transfer), - "purchase" => Ok(BatchTypeWASM::Purchase), - "updateprice" => Ok(BatchTypeWASM::UpdatePrice), - "ignorewhilebumpingrevision" => Ok(BatchTypeWASM::IgnoreWhileBumpingRevision), + "create" => Ok(BatchTypeWasm::Create), + "replace" => Ok(BatchTypeWasm::Replace), + "delete" => Ok(BatchTypeWasm::Delete), + "transfer" => Ok(BatchTypeWasm::Transfer), + "purchase" => Ok(BatchTypeWasm::Purchase), + "updateprice" => Ok(BatchTypeWasm::UpdatePrice), + "ignorewhilebumpingrevision" => Ok(BatchTypeWasm::IgnoreWhileBumpingRevision), _ => Err(JsValue::from(format!( "unknown batch type value: {}", enum_val @@ -36,13 +36,13 @@ impl TryFrom for BatchTypeWASM { false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 0 => Ok(BatchTypeWASM::Create), - 1 => Ok(BatchTypeWASM::Replace), - 2 => Ok(BatchTypeWASM::Delete), - 3 => Ok(BatchTypeWASM::Transfer), - 4 => Ok(BatchTypeWASM::Purchase), - 5 => Ok(BatchTypeWASM::UpdatePrice), - 6 => Ok(BatchTypeWASM::IgnoreWhileBumpingRevision), + 0 => Ok(BatchTypeWasm::Create), + 1 => Ok(BatchTypeWasm::Replace), + 2 => Ok(BatchTypeWasm::Delete), + 3 => Ok(BatchTypeWasm::Transfer), + 4 => Ok(BatchTypeWasm::Purchase), + 5 => Ok(BatchTypeWasm::UpdatePrice), + 6 => Ok(BatchTypeWasm::IgnoreWhileBumpingRevision), _ => Err(JsValue::from(format!( "unknown batch type value: {}", enum_val @@ -53,31 +53,31 @@ impl TryFrom for BatchTypeWASM { } } -impl From for String { - fn from(value: BatchTypeWASM) -> Self { +impl From for String { + fn from(value: BatchTypeWasm) -> Self { match value { - BatchTypeWASM::Create => String::from("create"), - BatchTypeWASM::Replace => String::from("replace"), - BatchTypeWASM::Delete => String::from("delete"), - BatchTypeWASM::Transfer => String::from("transfer"), - BatchTypeWASM::Purchase => String::from("purchase"), - BatchTypeWASM::UpdatePrice => String::from("updatePrice"), - BatchTypeWASM::IgnoreWhileBumpingRevision => String::from("ignoreWhileBumpingRevision"), + BatchTypeWasm::Create => String::from("create"), + BatchTypeWasm::Replace => String::from("replace"), + BatchTypeWasm::Delete => String::from("delete"), + BatchTypeWasm::Transfer => String::from("transfer"), + BatchTypeWasm::Purchase => String::from("purchase"), + BatchTypeWasm::UpdatePrice => String::from("updatePrice"), + BatchTypeWasm::IgnoreWhileBumpingRevision => String::from("ignoreWhileBumpingRevision"), } } } -impl From for BatchTypeWASM { +impl From for BatchTypeWasm { fn from(action_type: DocumentTransitionActionType) -> Self { match action_type { - DocumentTransitionActionType::Create => BatchTypeWASM::Create, - DocumentTransitionActionType::Replace => BatchTypeWASM::Replace, - DocumentTransitionActionType::Delete => BatchTypeWASM::Delete, - DocumentTransitionActionType::Transfer => BatchTypeWASM::Transfer, - DocumentTransitionActionType::Purchase => BatchTypeWASM::Purchase, - DocumentTransitionActionType::UpdatePrice => BatchTypeWASM::UpdatePrice, + DocumentTransitionActionType::Create => BatchTypeWasm::Create, + DocumentTransitionActionType::Replace => BatchTypeWasm::Replace, + DocumentTransitionActionType::Delete => BatchTypeWasm::Delete, + DocumentTransitionActionType::Transfer => BatchTypeWasm::Transfer, + DocumentTransitionActionType::Purchase => BatchTypeWasm::Purchase, + DocumentTransitionActionType::UpdatePrice => BatchTypeWasm::UpdatePrice, DocumentTransitionActionType::IgnoreWhileBumpingRevision => { - BatchTypeWASM::IgnoreWhileBumpingRevision + BatchTypeWasm::IgnoreWhileBumpingRevision } } } diff --git a/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs b/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs index 00a63b6a5d5..7eb8b6faab3 100644 --- a/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs +++ b/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs @@ -4,23 +4,23 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Default)] #[wasm_bindgen(js_name = "GasFeesPaidBy")] -pub enum GasFeesPaidByWASM { +pub enum GasFeesPaidByWasm { #[default] DocumentOwner = 0, ContractOwner = 1, PreferContractOwner = 2, } -impl TryFrom for GasFeesPaidByWASM { +impl TryFrom for GasFeesPaidByWasm { type Error = JsValue; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "documentowner" => Ok(GasFeesPaidByWASM::DocumentOwner), - "contractowner" => Ok(GasFeesPaidByWASM::ContractOwner), - "prefercontractowner" => Ok(GasFeesPaidByWASM::PreferContractOwner), + "documentowner" => Ok(GasFeesPaidByWasm::DocumentOwner), + "contractowner" => Ok(GasFeesPaidByWasm::ContractOwner), + "prefercontractowner" => Ok(GasFeesPaidByWasm::PreferContractOwner), _ => Err(JsValue::from(format!( "unknown batch type value: {}", enum_val @@ -30,9 +30,9 @@ impl TryFrom for GasFeesPaidByWASM { false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 0 => Ok(GasFeesPaidByWASM::DocumentOwner), - 1 => Ok(GasFeesPaidByWASM::ContractOwner), - 2 => Ok(GasFeesPaidByWASM::PreferContractOwner), + 0 => Ok(GasFeesPaidByWasm::DocumentOwner), + 1 => Ok(GasFeesPaidByWasm::ContractOwner), + 2 => Ok(GasFeesPaidByWasm::PreferContractOwner), _ => Err(JsValue::from(format!( "unknown batch type value: {}", enum_val @@ -43,32 +43,32 @@ impl TryFrom for GasFeesPaidByWASM { } } -impl From for String { - fn from(value: GasFeesPaidByWASM) -> Self { +impl From for String { + fn from(value: GasFeesPaidByWasm) -> Self { match value { - GasFeesPaidByWASM::DocumentOwner => String::from("DocumentOwner"), - GasFeesPaidByWASM::ContractOwner => String::from("ContractOwner"), - GasFeesPaidByWASM::PreferContractOwner => String::from("PreferContractOwner"), + GasFeesPaidByWasm::DocumentOwner => String::from("DocumentOwner"), + GasFeesPaidByWasm::ContractOwner => String::from("ContractOwner"), + GasFeesPaidByWasm::PreferContractOwner => String::from("PreferContractOwner"), } } } -impl From for GasFeesPaidByWASM { +impl From for GasFeesPaidByWasm { fn from(value: GasFeesPaidBy) -> Self { match value { - GasFeesPaidBy::DocumentOwner => GasFeesPaidByWASM::DocumentOwner, - GasFeesPaidBy::ContractOwner => GasFeesPaidByWASM::ContractOwner, - GasFeesPaidBy::PreferContractOwner => GasFeesPaidByWASM::PreferContractOwner, + GasFeesPaidBy::DocumentOwner => GasFeesPaidByWasm::DocumentOwner, + GasFeesPaidBy::ContractOwner => GasFeesPaidByWasm::ContractOwner, + GasFeesPaidBy::PreferContractOwner => GasFeesPaidByWasm::PreferContractOwner, } } } -impl From for GasFeesPaidBy { - fn from(value: GasFeesPaidByWASM) -> Self { +impl From for GasFeesPaidBy { + fn from(value: GasFeesPaidByWasm) -> Self { match value { - GasFeesPaidByWASM::DocumentOwner => GasFeesPaidBy::DocumentOwner, - GasFeesPaidByWASM::ContractOwner => GasFeesPaidBy::ContractOwner, - GasFeesPaidByWASM::PreferContractOwner => GasFeesPaidBy::PreferContractOwner, + GasFeesPaidByWasm::DocumentOwner => GasFeesPaidBy::DocumentOwner, + GasFeesPaidByWasm::ContractOwner => GasFeesPaidBy::ContractOwner, + GasFeesPaidByWasm::PreferContractOwner => GasFeesPaidBy::PreferContractOwner, } } } diff --git a/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs b/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs index 355484f33d6..f86900c9bf1 100644 --- a/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs +++ b/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs @@ -4,33 +4,33 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "VoteStateResultType")] #[allow(non_camel_case_types)] #[derive(Default, Clone)] -pub enum VoteStateResultTypeWASM { +pub enum VoteStateResultTypeWasm { #[default] Documents = 0, VoteTally = 1, DocumentsAndVoteTally = 2, } -impl TryFrom for VoteStateResultTypeWASM { +impl TryFrom for VoteStateResultTypeWasm { type Error = JsValue; - fn try_from(value: JsValue) -> Result { + fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "documents" => Ok(VoteStateResultTypeWASM::Documents), - "votetally" => Ok(VoteStateResultTypeWASM::VoteTally), - "documentsandvotetally" => Ok(VoteStateResultTypeWASM::DocumentsAndVoteTally), + "documents" => Ok(VoteStateResultTypeWasm::Documents), + "votetally" => Ok(VoteStateResultTypeWasm::VoteTally), + "documentsandvotetally" => Ok(VoteStateResultTypeWasm::DocumentsAndVoteTally), _ => Err(JsValue::from("unknown result type")), }, }, false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 0 => Ok(VoteStateResultTypeWASM::Documents), - 1 => Ok(VoteStateResultTypeWASM::VoteTally), - 2 => Ok(VoteStateResultTypeWASM::DocumentsAndVoteTally), + 0 => Ok(VoteStateResultTypeWasm::Documents), + 1 => Ok(VoteStateResultTypeWasm::VoteTally), + 2 => Ok(VoteStateResultTypeWasm::DocumentsAndVoteTally), _ => Err(JsValue::from("unknown action type")), }, }, @@ -38,12 +38,12 @@ impl TryFrom for VoteStateResultTypeWASM { } } -impl From for String { - fn from(result_type: VoteStateResultTypeWASM) -> Self { +impl From for String { + fn from(result_type: VoteStateResultTypeWasm) -> Self { match result_type { - VoteStateResultTypeWASM::Documents => String::from("Documents"), - VoteStateResultTypeWASM::VoteTally => String::from("VoteTally"), - VoteStateResultTypeWASM::DocumentsAndVoteTally => String::from("DocumentsAndVoteTally"), + VoteStateResultTypeWasm::Documents => String::from("Documents"), + VoteStateResultTypeWasm::VoteTally => String::from("VoteTally"), + VoteStateResultTypeWasm::DocumentsAndVoteTally => String::from("DocumentsAndVoteTally"), } } } diff --git a/packages/wasm-dpp2/src/enums/keys/key_type.rs b/packages/wasm-dpp2/src/enums/keys/key_type.rs index 64872bdc9c7..9b774a605b0 100644 --- a/packages/wasm-dpp2/src/enums/keys/key_type.rs +++ b/packages/wasm-dpp2/src/enums/keys/key_type.rs @@ -4,7 +4,7 @@ use wasm_bindgen::prelude::wasm_bindgen; #[allow(non_camel_case_types)] #[wasm_bindgen(js_name = "KeyType")] -pub enum KeyTypeWASM { +pub enum KeyTypeWasm { ECDSA_SECP256K1 = 0, BLS12_381 = 1, ECDSA_HASH160 = 2, @@ -12,29 +12,29 @@ pub enum KeyTypeWASM { EDDSA_25519_HASH160 = 4, } -impl TryFrom for KeyTypeWASM { +impl TryFrom for KeyTypeWasm { type Error = JsValue; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "ecdsa_secp256k1" => Ok(KeyTypeWASM::ECDSA_SECP256K1), - "bls12_381" => Ok(KeyTypeWASM::BLS12_381), - "ecdsa_hash160" => Ok(KeyTypeWASM::ECDSA_HASH160), - "bip13_script_hash" => Ok(KeyTypeWASM::BIP13_SCRIPT_HASH), - "eddsa_25519_hash160" => Ok(KeyTypeWASM::EDDSA_25519_HASH160), + "ecdsa_secp256k1" => Ok(KeyTypeWasm::ECDSA_SECP256K1), + "bls12_381" => Ok(KeyTypeWasm::BLS12_381), + "ecdsa_hash160" => Ok(KeyTypeWasm::ECDSA_HASH160), + "bip13_script_hash" => Ok(KeyTypeWasm::BIP13_SCRIPT_HASH), + "eddsa_25519_hash160" => Ok(KeyTypeWasm::EDDSA_25519_HASH160), _ => Err(JsValue::from(format!("unsupported key type {}", enum_val))), }, }, false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 0 => Ok(KeyTypeWASM::ECDSA_SECP256K1), - 1 => Ok(KeyTypeWASM::BLS12_381), - 2 => Ok(KeyTypeWASM::ECDSA_HASH160), - 3 => Ok(KeyTypeWASM::BIP13_SCRIPT_HASH), - 4 => Ok(KeyTypeWASM::EDDSA_25519_HASH160), + 0 => Ok(KeyTypeWasm::ECDSA_SECP256K1), + 1 => Ok(KeyTypeWasm::BLS12_381), + 2 => Ok(KeyTypeWasm::ECDSA_HASH160), + 3 => Ok(KeyTypeWasm::BIP13_SCRIPT_HASH), + 4 => Ok(KeyTypeWasm::EDDSA_25519_HASH160), _ => Err(JsValue::from(format!( "unsupported key type ({})", enum_val @@ -45,50 +45,50 @@ impl TryFrom for KeyTypeWASM { } } -impl From for String { - fn from(value: KeyTypeWASM) -> Self { +impl From for String { + fn from(value: KeyTypeWasm) -> Self { match value { - KeyTypeWASM::ECDSA_SECP256K1 => String::from("ECDSA_SECP256K1"), - KeyTypeWASM::BLS12_381 => String::from("BLS12_381"), - KeyTypeWASM::ECDSA_HASH160 => String::from("ECDSA_HASH160"), - KeyTypeWASM::BIP13_SCRIPT_HASH => String::from("BIP13_SCRIPT_HASH"), - KeyTypeWASM::EDDSA_25519_HASH160 => String::from("EDDSA_25519_HASH160"), + KeyTypeWasm::ECDSA_SECP256K1 => String::from("ECDSA_SECP256K1"), + KeyTypeWasm::BLS12_381 => String::from("BLS12_381"), + KeyTypeWasm::ECDSA_HASH160 => String::from("ECDSA_HASH160"), + KeyTypeWasm::BIP13_SCRIPT_HASH => String::from("BIP13_SCRIPT_HASH"), + KeyTypeWasm::EDDSA_25519_HASH160 => String::from("EDDSA_25519_HASH160"), } } } -impl From for KeyType { - fn from(key_type: KeyTypeWASM) -> Self { +impl From for KeyType { + fn from(key_type: KeyTypeWasm) -> Self { match key_type { - KeyTypeWASM::ECDSA_SECP256K1 => KeyType::ECDSA_SECP256K1, - KeyTypeWASM::BLS12_381 => KeyType::BLS12_381, - KeyTypeWASM::ECDSA_HASH160 => KeyType::ECDSA_HASH160, - KeyTypeWASM::BIP13_SCRIPT_HASH => KeyType::BIP13_SCRIPT_HASH, - KeyTypeWASM::EDDSA_25519_HASH160 => KeyType::EDDSA_25519_HASH160, + KeyTypeWasm::ECDSA_SECP256K1 => KeyType::ECDSA_SECP256K1, + KeyTypeWasm::BLS12_381 => KeyType::BLS12_381, + KeyTypeWasm::ECDSA_HASH160 => KeyType::ECDSA_HASH160, + KeyTypeWasm::BIP13_SCRIPT_HASH => KeyType::BIP13_SCRIPT_HASH, + KeyTypeWasm::EDDSA_25519_HASH160 => KeyType::EDDSA_25519_HASH160, } } } -impl From for KeyTypeWASM { +impl From for KeyTypeWasm { fn from(key_type: KeyType) -> Self { match key_type { - KeyType::ECDSA_SECP256K1 => KeyTypeWASM::ECDSA_SECP256K1, - KeyType::BLS12_381 => KeyTypeWASM::BLS12_381, - KeyType::ECDSA_HASH160 => KeyTypeWASM::ECDSA_HASH160, - KeyType::BIP13_SCRIPT_HASH => KeyTypeWASM::BIP13_SCRIPT_HASH, - KeyType::EDDSA_25519_HASH160 => KeyTypeWASM::EDDSA_25519_HASH160, + KeyType::ECDSA_SECP256K1 => KeyTypeWasm::ECDSA_SECP256K1, + KeyType::BLS12_381 => KeyTypeWasm::BLS12_381, + KeyType::ECDSA_HASH160 => KeyTypeWasm::ECDSA_HASH160, + KeyType::BIP13_SCRIPT_HASH => KeyTypeWasm::BIP13_SCRIPT_HASH, + KeyType::EDDSA_25519_HASH160 => KeyTypeWasm::EDDSA_25519_HASH160, } } } -impl From for u8 { - fn from(key_type: KeyTypeWASM) -> Self { +impl From for u8 { + fn from(key_type: KeyTypeWasm) -> Self { match key_type { - KeyTypeWASM::ECDSA_SECP256K1 => 0, - KeyTypeWASM::BLS12_381 => 1, - KeyTypeWASM::ECDSA_HASH160 => 2, - KeyTypeWASM::BIP13_SCRIPT_HASH => 3, - KeyTypeWASM::EDDSA_25519_HASH160 => 4, + KeyTypeWasm::ECDSA_SECP256K1 => 0, + KeyTypeWasm::BLS12_381 => 1, + KeyTypeWasm::ECDSA_HASH160 => 2, + KeyTypeWasm::BIP13_SCRIPT_HASH => 3, + KeyTypeWasm::EDDSA_25519_HASH160 => 4, } } } diff --git a/packages/wasm-dpp2/src/enums/keys/purpose.rs b/packages/wasm-dpp2/src/enums/keys/purpose.rs index 35c237ade6e..4e9aca6c324 100644 --- a/packages/wasm-dpp2/src/enums/keys/purpose.rs +++ b/packages/wasm-dpp2/src/enums/keys/purpose.rs @@ -3,7 +3,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "Purpose")] -pub enum PurposeWASM { +pub enum PurposeWasm { AUTHENTICATION = 0, ENCRYPTION = 1, DECRYPTION = 2, @@ -13,20 +13,20 @@ pub enum PurposeWASM { OWNER = 6, } -impl TryFrom for PurposeWASM { +impl TryFrom for PurposeWasm { type Error = JsValue; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "authentication" => Ok(PurposeWASM::AUTHENTICATION), - "encryption" => Ok(PurposeWASM::ENCRYPTION), - "decryption" => Ok(PurposeWASM::DECRYPTION), - "transfer" => Ok(PurposeWASM::TRANSFER), - "system" => Ok(PurposeWASM::SYSTEM), - "voting" => Ok(PurposeWASM::VOTING), - "owner" => Ok(PurposeWASM::OWNER), + "authentication" => Ok(PurposeWasm::AUTHENTICATION), + "encryption" => Ok(PurposeWasm::ENCRYPTION), + "decryption" => Ok(PurposeWasm::DECRYPTION), + "transfer" => Ok(PurposeWasm::TRANSFER), + "system" => Ok(PurposeWasm::SYSTEM), + "voting" => Ok(PurposeWasm::VOTING), + "owner" => Ok(PurposeWasm::OWNER), _ => Err(JsValue::from(format!( "unsupported purpose value ({})", enum_val @@ -36,13 +36,13 @@ impl TryFrom for PurposeWASM { false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 0 => Ok(PurposeWASM::AUTHENTICATION), - 1 => Ok(PurposeWASM::ENCRYPTION), - 2 => Ok(PurposeWASM::DECRYPTION), - 3 => Ok(PurposeWASM::TRANSFER), - 4 => Ok(PurposeWASM::SYSTEM), - 5 => Ok(PurposeWASM::VOTING), - 6 => Ok(PurposeWASM::OWNER), + 0 => Ok(PurposeWasm::AUTHENTICATION), + 1 => Ok(PurposeWasm::ENCRYPTION), + 2 => Ok(PurposeWasm::DECRYPTION), + 3 => Ok(PurposeWasm::TRANSFER), + 4 => Ok(PurposeWasm::SYSTEM), + 5 => Ok(PurposeWasm::VOTING), + 6 => Ok(PurposeWasm::OWNER), _ => Err(JsValue::from(format!( "unsupported purpose value ({})", enum_val @@ -53,44 +53,44 @@ impl TryFrom for PurposeWASM { } } -impl From for String { - fn from(value: PurposeWASM) -> Self { +impl From for String { + fn from(value: PurposeWasm) -> Self { match value { - PurposeWASM::AUTHENTICATION => String::from("AUTHENTICATION"), - PurposeWASM::ENCRYPTION => String::from("ENCRYPTION"), - PurposeWASM::DECRYPTION => String::from("DECRYPTION"), - PurposeWASM::TRANSFER => String::from("TRANSFER"), - PurposeWASM::SYSTEM => String::from("SYSTEM"), - PurposeWASM::VOTING => String::from("VOTING"), - PurposeWASM::OWNER => String::from("OWNER"), + PurposeWasm::AUTHENTICATION => String::from("AUTHENTICATION"), + PurposeWasm::ENCRYPTION => String::from("ENCRYPTION"), + PurposeWasm::DECRYPTION => String::from("DECRYPTION"), + PurposeWasm::TRANSFER => String::from("TRANSFER"), + PurposeWasm::SYSTEM => String::from("SYSTEM"), + PurposeWasm::VOTING => String::from("VOTING"), + PurposeWasm::OWNER => String::from("OWNER"), } } } -impl From for Purpose { - fn from(purpose: PurposeWASM) -> Self { +impl From for Purpose { + fn from(purpose: PurposeWasm) -> Self { match purpose { - PurposeWASM::AUTHENTICATION => Purpose::AUTHENTICATION, - PurposeWASM::ENCRYPTION => Purpose::ENCRYPTION, - PurposeWASM::DECRYPTION => Purpose::DECRYPTION, - PurposeWASM::TRANSFER => Purpose::TRANSFER, - PurposeWASM::SYSTEM => Purpose::SYSTEM, - PurposeWASM::VOTING => Purpose::VOTING, - PurposeWASM::OWNER => Purpose::OWNER, + PurposeWasm::AUTHENTICATION => Purpose::AUTHENTICATION, + PurposeWasm::ENCRYPTION => Purpose::ENCRYPTION, + PurposeWasm::DECRYPTION => Purpose::DECRYPTION, + PurposeWasm::TRANSFER => Purpose::TRANSFER, + PurposeWasm::SYSTEM => Purpose::SYSTEM, + PurposeWasm::VOTING => Purpose::VOTING, + PurposeWasm::OWNER => Purpose::OWNER, } } } -impl From for PurposeWASM { +impl From for PurposeWasm { fn from(purpose: Purpose) -> Self { match purpose { - Purpose::AUTHENTICATION => PurposeWASM::AUTHENTICATION, - Purpose::ENCRYPTION => PurposeWASM::ENCRYPTION, - Purpose::DECRYPTION => PurposeWASM::DECRYPTION, - Purpose::TRANSFER => PurposeWASM::TRANSFER, - Purpose::SYSTEM => PurposeWASM::SYSTEM, - Purpose::VOTING => PurposeWASM::VOTING, - Purpose::OWNER => PurposeWASM::OWNER, + Purpose::AUTHENTICATION => PurposeWasm::AUTHENTICATION, + Purpose::ENCRYPTION => PurposeWasm::ENCRYPTION, + Purpose::DECRYPTION => PurposeWasm::DECRYPTION, + Purpose::TRANSFER => PurposeWasm::TRANSFER, + Purpose::SYSTEM => PurposeWasm::SYSTEM, + Purpose::VOTING => PurposeWasm::VOTING, + Purpose::OWNER => PurposeWasm::OWNER, } } } diff --git a/packages/wasm-dpp2/src/enums/keys/security_level.rs b/packages/wasm-dpp2/src/enums/keys/security_level.rs index 33db627b0e6..d3133e824eb 100644 --- a/packages/wasm-dpp2/src/enums/keys/security_level.rs +++ b/packages/wasm-dpp2/src/enums/keys/security_level.rs @@ -3,24 +3,24 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = SecurityLevel)] -pub enum SecurityLevelWASM { +pub enum SecurityLevelWasm { MASTER = 0, CRITICAL = 1, HIGH = 2, MEDIUM = 3, } -impl TryFrom for SecurityLevelWASM { +impl TryFrom for SecurityLevelWasm { type Error = JsValue; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "master" => Ok(SecurityLevelWASM::MASTER), - "critical" => Ok(SecurityLevelWASM::CRITICAL), - "high" => Ok(SecurityLevelWASM::HIGH), - "medium" => Ok(SecurityLevelWASM::MEDIUM), + "master" => Ok(SecurityLevelWasm::MASTER), + "critical" => Ok(SecurityLevelWasm::CRITICAL), + "high" => Ok(SecurityLevelWasm::HIGH), + "medium" => Ok(SecurityLevelWasm::MEDIUM), _ => Err(JsValue::from(format!( "unsupported security level value ({})", enum_val @@ -30,10 +30,10 @@ impl TryFrom for SecurityLevelWASM { false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 0 => Ok(SecurityLevelWASM::MASTER), - 1 => Ok(SecurityLevelWASM::CRITICAL), - 2 => Ok(SecurityLevelWASM::HIGH), - 3 => Ok(SecurityLevelWASM::MEDIUM), + 0 => Ok(SecurityLevelWasm::MASTER), + 1 => Ok(SecurityLevelWasm::CRITICAL), + 2 => Ok(SecurityLevelWasm::HIGH), + 3 => Ok(SecurityLevelWasm::MEDIUM), _ => Err(JsValue::from(format!( "unsupported security level value ({})", enum_val @@ -44,35 +44,35 @@ impl TryFrom for SecurityLevelWASM { } } -impl From for String { - fn from(level: SecurityLevelWASM) -> String { +impl From for String { + fn from(level: SecurityLevelWasm) -> String { match level { - SecurityLevelWASM::MASTER => String::from("MASTER"), - SecurityLevelWASM::CRITICAL => String::from("CRITICAL"), - SecurityLevelWASM::HIGH => String::from("HIGH"), - SecurityLevelWASM::MEDIUM => String::from("MEDIUM"), + SecurityLevelWasm::MASTER => String::from("MASTER"), + SecurityLevelWasm::CRITICAL => String::from("CRITICAL"), + SecurityLevelWasm::HIGH => String::from("HIGH"), + SecurityLevelWasm::MEDIUM => String::from("MEDIUM"), } } } -impl From for SecurityLevel { - fn from(security_level: SecurityLevelWASM) -> Self { +impl From for SecurityLevel { + fn from(security_level: SecurityLevelWasm) -> Self { match security_level { - SecurityLevelWASM::MASTER => SecurityLevel::MASTER, - SecurityLevelWASM::CRITICAL => SecurityLevel::CRITICAL, - SecurityLevelWASM::HIGH => SecurityLevel::HIGH, - SecurityLevelWASM::MEDIUM => SecurityLevel::MEDIUM, + SecurityLevelWasm::MASTER => SecurityLevel::MASTER, + SecurityLevelWasm::CRITICAL => SecurityLevel::CRITICAL, + SecurityLevelWasm::HIGH => SecurityLevel::HIGH, + SecurityLevelWasm::MEDIUM => SecurityLevel::MEDIUM, } } } -impl From for SecurityLevelWASM { +impl From for SecurityLevelWasm { fn from(security_level: SecurityLevel) -> Self { match security_level { - SecurityLevel::MASTER => SecurityLevelWASM::MASTER, - SecurityLevel::CRITICAL => SecurityLevelWASM::CRITICAL, - SecurityLevel::HIGH => SecurityLevelWASM::HIGH, - SecurityLevel::MEDIUM => SecurityLevelWASM::MEDIUM, + SecurityLevel::MASTER => SecurityLevelWasm::MASTER, + SecurityLevel::CRITICAL => SecurityLevelWasm::CRITICAL, + SecurityLevel::HIGH => SecurityLevelWasm::HIGH, + SecurityLevel::MEDIUM => SecurityLevelWasm::MEDIUM, } } } diff --git a/packages/wasm-dpp2/src/enums/lock_types/mod.rs b/packages/wasm-dpp2/src/enums/lock_types/mod.rs index 9bd4ab06f31..64439d8f0a9 100644 --- a/packages/wasm-dpp2/src/enums/lock_types/mod.rs +++ b/packages/wasm-dpp2/src/enums/lock_types/mod.rs @@ -2,21 +2,21 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "AssetLockProofType")] -pub enum AssetLockProofTypeWASM { +pub enum AssetLockProofTypeWasm { Instant = 0, Chain = 1, } -impl From for String { - fn from(value: AssetLockProofTypeWASM) -> Self { +impl From for String { + fn from(value: AssetLockProofTypeWasm) -> Self { match value { - AssetLockProofTypeWASM::Instant => String::from("Instant"), - AssetLockProofTypeWASM::Chain => String::from("Chain"), + AssetLockProofTypeWasm::Instant => String::from("Instant"), + AssetLockProofTypeWasm::Chain => String::from("Chain"), } } } -impl TryFrom for AssetLockProofTypeWASM { +impl TryFrom for AssetLockProofTypeWasm { type Error = JsValue; fn try_from(value: JsValue) -> Result { @@ -24,16 +24,16 @@ impl TryFrom for AssetLockProofTypeWASM { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "instant" => Ok(AssetLockProofTypeWASM::Instant), - "chain" => Ok(AssetLockProofTypeWASM::Chain), + "instant" => Ok(AssetLockProofTypeWasm::Instant), + "chain" => Ok(AssetLockProofTypeWasm::Chain), _ => Err(JsValue::from(format!("unsupported lock type {}", enum_val))), }, }, false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 0 => Ok(AssetLockProofTypeWASM::Instant), - 1 => Ok(AssetLockProofTypeWASM::Chain), + 0 => Ok(AssetLockProofTypeWasm::Instant), + 1 => Ok(AssetLockProofTypeWasm::Chain), _ => Err(JsValue::from(format!("unsupported lock type {}", enum_val))), }, }, @@ -41,7 +41,7 @@ impl TryFrom for AssetLockProofTypeWASM { } } -impl TryFrom for AssetLockProofTypeWASM { +impl TryFrom for AssetLockProofTypeWasm { type Error = JsError; fn try_from(value: u8) -> Result { match value { @@ -52,7 +52,7 @@ impl TryFrom for AssetLockProofTypeWASM { } } -impl TryFrom for AssetLockProofTypeWASM { +impl TryFrom for AssetLockProofTypeWasm { type Error = JsError; fn try_from(value: u64) -> Result { diff --git a/packages/wasm-dpp2/src/enums/network/mod.rs b/packages/wasm-dpp2/src/enums/network/mod.rs index ede74ba8488..1bd5b75b2b2 100644 --- a/packages/wasm-dpp2/src/enums/network/mod.rs +++ b/packages/wasm-dpp2/src/enums/network/mod.rs @@ -3,24 +3,24 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "Network")] #[allow(non_camel_case_types)] -pub enum NetworkWASM { +pub enum NetworkWasm { Mainnet = 0, Testnet = 1, Devnet = 2, Regtest = 3, } -impl TryFrom for NetworkWASM { +impl TryFrom for NetworkWasm { type Error = JsValue; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "mainnet" => Ok(NetworkWASM::Mainnet), - "testnet" => Ok(NetworkWASM::Testnet), - "devnet" => Ok(NetworkWASM::Devnet), - "regtest" => Ok(NetworkWASM::Regtest), + "mainnet" => Ok(NetworkWasm::Mainnet), + "testnet" => Ok(NetworkWasm::Testnet), + "devnet" => Ok(NetworkWasm::Devnet), + "regtest" => Ok(NetworkWasm::Regtest), _ => Err(JsValue::from(format!( "unsupported network name ({})", enum_val @@ -30,10 +30,10 @@ impl TryFrom for NetworkWASM { false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 0 => Ok(NetworkWASM::Mainnet), - 1 => Ok(NetworkWASM::Testnet), - 2 => Ok(NetworkWASM::Devnet), - 3 => Ok(NetworkWASM::Regtest), + 0 => Ok(NetworkWasm::Mainnet), + 1 => Ok(NetworkWasm::Testnet), + 2 => Ok(NetworkWasm::Devnet), + 3 => Ok(NetworkWasm::Regtest), _ => Err(JsValue::from(format!( "unsupported network name ({})", enum_val @@ -44,24 +44,24 @@ impl TryFrom for NetworkWASM { } } -impl From for String { - fn from(value: NetworkWASM) -> Self { +impl From for String { + fn from(value: NetworkWasm) -> Self { match value { - NetworkWASM::Mainnet => "Mainnet".to_string(), - NetworkWASM::Testnet => "Testnet".to_string(), - NetworkWASM::Devnet => "Devnet".to_string(), - NetworkWASM::Regtest => "Regtest".to_string(), + NetworkWasm::Mainnet => "Mainnet".to_string(), + NetworkWasm::Testnet => "Testnet".to_string(), + NetworkWasm::Devnet => "Devnet".to_string(), + NetworkWasm::Regtest => "Regtest".to_string(), } } } -impl From for Network { - fn from(network: NetworkWASM) -> Self { +impl From for Network { + fn from(network: NetworkWasm) -> Self { match network { - NetworkWASM::Mainnet => Network::Dash, - NetworkWASM::Testnet => Network::Testnet, - NetworkWASM::Devnet => Network::Devnet, - NetworkWASM::Regtest => Network::Regtest, + NetworkWasm::Mainnet => Network::Dash, + NetworkWasm::Testnet => Network::Testnet, + NetworkWasm::Devnet => Network::Devnet, + NetworkWasm::Regtest => Network::Regtest, } } } diff --git a/packages/wasm-dpp2/src/enums/platform/mod.rs b/packages/wasm-dpp2/src/enums/platform/mod.rs index 0a8cef9bf60..05609e78c9f 100644 --- a/packages/wasm-dpp2/src/enums/platform/mod.rs +++ b/packages/wasm-dpp2/src/enums/platform/mod.rs @@ -14,7 +14,7 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "PlatformVersion")] #[derive(Default)] #[allow(non_camel_case_types)] -pub enum PlatformVersionWASM { +pub enum PlatformVersionWasm { #[default] PLATFORM_V1 = 1, PLATFORM_V2 = 2, @@ -27,22 +27,22 @@ pub enum PlatformVersionWASM { PLATFORM_V9 = 9, } -impl TryFrom for PlatformVersionWASM { +impl TryFrom for PlatformVersionWasm { type Error = JsValue; - fn try_from(value: JsValue) -> Result { + fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "platform_v1" => Ok(PlatformVersionWASM::PLATFORM_V1), - "platform_v2" => Ok(PlatformVersionWASM::PLATFORM_V2), - "platform_v3" => Ok(PlatformVersionWASM::PLATFORM_V3), - "platform_v4" => Ok(PlatformVersionWASM::PLATFORM_V4), - "platform_v5" => Ok(PlatformVersionWASM::PLATFORM_V5), - "platform_v6" => Ok(PlatformVersionWASM::PLATFORM_V6), - "platform_v7" => Ok(PlatformVersionWASM::PLATFORM_V7), - "platform_v8" => Ok(PlatformVersionWASM::PLATFORM_V8), - "platform_v9" => Ok(PlatformVersionWASM::PLATFORM_V9), + "platform_v1" => Ok(PlatformVersionWasm::PLATFORM_V1), + "platform_v2" => Ok(PlatformVersionWasm::PLATFORM_V2), + "platform_v3" => Ok(PlatformVersionWasm::PLATFORM_V3), + "platform_v4" => Ok(PlatformVersionWasm::PLATFORM_V4), + "platform_v5" => Ok(PlatformVersionWasm::PLATFORM_V5), + "platform_v6" => Ok(PlatformVersionWasm::PLATFORM_V6), + "platform_v7" => Ok(PlatformVersionWasm::PLATFORM_V7), + "platform_v8" => Ok(PlatformVersionWasm::PLATFORM_V8), + "platform_v9" => Ok(PlatformVersionWasm::PLATFORM_V9), _ => Err(JsValue::from(format!( "unknown platform version value: {}", enum_val @@ -52,15 +52,15 @@ impl TryFrom for PlatformVersionWASM { false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 1 => Ok(PlatformVersionWASM::PLATFORM_V1), - 2 => Ok(PlatformVersionWASM::PLATFORM_V2), - 3 => Ok(PlatformVersionWASM::PLATFORM_V3), - 4 => Ok(PlatformVersionWASM::PLATFORM_V4), - 5 => Ok(PlatformVersionWASM::PLATFORM_V5), - 6 => Ok(PlatformVersionWASM::PLATFORM_V6), - 7 => Ok(PlatformVersionWASM::PLATFORM_V7), - 8 => Ok(PlatformVersionWASM::PLATFORM_V8), - 9 => Ok(PlatformVersionWASM::PLATFORM_V9), + 1 => Ok(PlatformVersionWasm::PLATFORM_V1), + 2 => Ok(PlatformVersionWasm::PLATFORM_V2), + 3 => Ok(PlatformVersionWasm::PLATFORM_V3), + 4 => Ok(PlatformVersionWasm::PLATFORM_V4), + 5 => Ok(PlatformVersionWasm::PLATFORM_V5), + 6 => Ok(PlatformVersionWasm::PLATFORM_V6), + 7 => Ok(PlatformVersionWasm::PLATFORM_V7), + 8 => Ok(PlatformVersionWasm::PLATFORM_V8), + 9 => Ok(PlatformVersionWasm::PLATFORM_V9), _ => Err(JsValue::from(format!( "unknown platform version value: {}", enum_val @@ -71,34 +71,34 @@ impl TryFrom for PlatformVersionWASM { } } -impl From for String { - fn from(version: PlatformVersionWASM) -> String { +impl From for String { + fn from(version: PlatformVersionWasm) -> String { match version { - PlatformVersionWASM::PLATFORM_V1 => String::from("PLATFORM_V1"), - PlatformVersionWASM::PLATFORM_V2 => String::from("PLATFORM_V2"), - PlatformVersionWASM::PLATFORM_V3 => String::from("PLATFORM_V3"), - PlatformVersionWASM::PLATFORM_V4 => String::from("PLATFORM_V4"), - PlatformVersionWASM::PLATFORM_V5 => String::from("PLATFORM_V5"), - PlatformVersionWASM::PLATFORM_V6 => String::from("PLATFORM_V6"), - PlatformVersionWASM::PLATFORM_V7 => String::from("PLATFORM_V7"), - PlatformVersionWASM::PLATFORM_V8 => String::from("PLATFORM_V8"), - PlatformVersionWASM::PLATFORM_V9 => String::from("PLATFORM_V9"), + PlatformVersionWasm::PLATFORM_V1 => String::from("PLATFORM_V1"), + PlatformVersionWasm::PLATFORM_V2 => String::from("PLATFORM_V2"), + PlatformVersionWasm::PLATFORM_V3 => String::from("PLATFORM_V3"), + PlatformVersionWasm::PLATFORM_V4 => String::from("PLATFORM_V4"), + PlatformVersionWasm::PLATFORM_V5 => String::from("PLATFORM_V5"), + PlatformVersionWasm::PLATFORM_V6 => String::from("PLATFORM_V6"), + PlatformVersionWasm::PLATFORM_V7 => String::from("PLATFORM_V7"), + PlatformVersionWasm::PLATFORM_V8 => String::from("PLATFORM_V8"), + PlatformVersionWasm::PLATFORM_V9 => String::from("PLATFORM_V9"), } } } -impl From for PlatformVersion { - fn from(value: PlatformVersionWASM) -> Self { +impl From for PlatformVersion { + fn from(value: PlatformVersionWasm) -> Self { match value { - PlatformVersionWASM::PLATFORM_V1 => PLATFORM_V1, - PlatformVersionWASM::PLATFORM_V2 => PLATFORM_V2, - PlatformVersionWASM::PLATFORM_V3 => PLATFORM_V3, - PlatformVersionWASM::PLATFORM_V4 => PLATFORM_V4, - PlatformVersionWASM::PLATFORM_V5 => PLATFORM_V5, - PlatformVersionWASM::PLATFORM_V6 => PLATFORM_V6, - PlatformVersionWASM::PLATFORM_V7 => PLATFORM_V7, - PlatformVersionWASM::PLATFORM_V8 => PLATFORM_V8, - PlatformVersionWASM::PLATFORM_V9 => PLATFORM_V9, + PlatformVersionWasm::PLATFORM_V1 => PLATFORM_V1, + PlatformVersionWasm::PLATFORM_V2 => PLATFORM_V2, + PlatformVersionWasm::PLATFORM_V3 => PLATFORM_V3, + PlatformVersionWasm::PLATFORM_V4 => PLATFORM_V4, + PlatformVersionWasm::PLATFORM_V5 => PLATFORM_V5, + PlatformVersionWasm::PLATFORM_V6 => PLATFORM_V6, + PlatformVersionWasm::PLATFORM_V7 => PLATFORM_V7, + PlatformVersionWasm::PLATFORM_V8 => PLATFORM_V8, + PlatformVersionWasm::PLATFORM_V9 => PLATFORM_V9, } } } diff --git a/packages/wasm-dpp2/src/enums/token/action_goal.rs b/packages/wasm-dpp2/src/enums/token/action_goal.rs index 081ce6edab2..a34ae8d5325 100644 --- a/packages/wasm-dpp2/src/enums/token/action_goal.rs +++ b/packages/wasm-dpp2/src/enums/token/action_goal.rs @@ -5,48 +5,48 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "ActionGoal")] #[allow(non_camel_case_types)] #[derive(Default, Clone)] -pub enum ActionGoalWASM { +pub enum ActionGoalWasm { #[default] ActionCompletion = 0, ActionParticipation = 1, } -impl From for ActionGoal { - fn from(action_goal: ActionGoalWASM) -> Self { +impl From for ActionGoal { + fn from(action_goal: ActionGoalWasm) -> Self { match action_goal { - ActionGoalWASM::ActionCompletion => ActionGoal::ActionCompletion, - ActionGoalWASM::ActionParticipation => ActionGoal::ActionParticipation, + ActionGoalWasm::ActionCompletion => ActionGoal::ActionCompletion, + ActionGoalWasm::ActionParticipation => ActionGoal::ActionParticipation, } } } -impl From for ActionGoalWASM { +impl From for ActionGoalWasm { fn from(action_goal: ActionGoal) -> Self { match action_goal { - ActionGoal::ActionCompletion => ActionGoalWASM::ActionCompletion, - ActionGoal::ActionParticipation => ActionGoalWASM::ActionParticipation, + ActionGoal::ActionCompletion => ActionGoalWasm::ActionCompletion, + ActionGoal::ActionParticipation => ActionGoalWasm::ActionParticipation, } } } -impl TryFrom for ActionGoalWASM { +impl TryFrom for ActionGoalWasm { type Error = JsValue; - fn try_from(value: JsValue) -> Result { + fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "actioncompletion" => Ok(ActionGoalWASM::ActionCompletion), - "actionparticipation" => Ok(ActionGoalWASM::ActionParticipation), + "actioncompletion" => Ok(ActionGoalWasm::ActionCompletion), + "actionparticipation" => Ok(ActionGoalWasm::ActionParticipation), _ => Err(JsValue::from("unknown action type")), }, }, false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 0 => Ok(ActionGoalWASM::ActionCompletion), - 1 => Ok(ActionGoalWASM::ActionParticipation), + 0 => Ok(ActionGoalWasm::ActionCompletion), + 1 => Ok(ActionGoalWasm::ActionParticipation), _ => Err(JsValue::from("unknown action type")), }, }, @@ -54,11 +54,11 @@ impl TryFrom for ActionGoalWASM { } } -impl From for String { - fn from(action_goal: ActionGoalWASM) -> Self { +impl From for String { + fn from(action_goal: ActionGoalWasm) -> Self { match action_goal { - ActionGoalWASM::ActionCompletion => String::from("ActionCompletion"), - ActionGoalWASM::ActionParticipation => String::from("ActionParticipation"), + ActionGoalWasm::ActionCompletion => String::from("ActionCompletion"), + ActionGoalWasm::ActionParticipation => String::from("ActionParticipation"), } } } diff --git a/packages/wasm-dpp2/src/enums/token/distribution_type.rs b/packages/wasm-dpp2/src/enums/token/distribution_type.rs index ab67c199fa1..6905d315b94 100644 --- a/packages/wasm-dpp2/src/enums/token/distribution_type.rs +++ b/packages/wasm-dpp2/src/enums/token/distribution_type.rs @@ -5,48 +5,48 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "TokenDistributionType")] #[allow(non_camel_case_types)] #[derive(Default)] -pub enum TokenDistributionTypeWASM { +pub enum TokenDistributionTypeWasm { #[default] PreProgrammed = 0, Perpetual = 1, } -impl From for TokenDistributionType { - fn from(distribution_type: TokenDistributionTypeWASM) -> Self { +impl From for TokenDistributionType { + fn from(distribution_type: TokenDistributionTypeWasm) -> Self { match distribution_type { - TokenDistributionTypeWASM::PreProgrammed => TokenDistributionType::PreProgrammed, - TokenDistributionTypeWASM::Perpetual => TokenDistributionType::Perpetual, + TokenDistributionTypeWasm::PreProgrammed => TokenDistributionType::PreProgrammed, + TokenDistributionTypeWasm::Perpetual => TokenDistributionType::Perpetual, } } } -impl From for TokenDistributionTypeWASM { +impl From for TokenDistributionTypeWasm { fn from(distribution_type: TokenDistributionType) -> Self { match distribution_type { - TokenDistributionType::Perpetual => TokenDistributionTypeWASM::Perpetual, - TokenDistributionType::PreProgrammed => TokenDistributionTypeWASM::PreProgrammed, + TokenDistributionType::Perpetual => TokenDistributionTypeWasm::Perpetual, + TokenDistributionType::PreProgrammed => TokenDistributionTypeWasm::PreProgrammed, } } } -impl TryFrom for TokenDistributionTypeWASM { +impl TryFrom for TokenDistributionTypeWasm { type Error = JsValue; - fn try_from(value: JsValue) -> Result { + fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "preprogrammed" => Ok(TokenDistributionTypeWASM::PreProgrammed), - "perpetual" => Ok(TokenDistributionTypeWASM::Perpetual), + "preprogrammed" => Ok(TokenDistributionTypeWasm::PreProgrammed), + "perpetual" => Ok(TokenDistributionTypeWasm::Perpetual), _ => Err(JsValue::from("unknown distribution type")), }, }, false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 0 => Ok(TokenDistributionTypeWASM::PreProgrammed), - 1 => Ok(TokenDistributionTypeWASM::Perpetual), + 0 => Ok(TokenDistributionTypeWasm::PreProgrammed), + 1 => Ok(TokenDistributionTypeWasm::Perpetual), _ => Err(JsValue::from("unknown distribution type")), }, }, @@ -54,11 +54,11 @@ impl TryFrom for TokenDistributionTypeWASM { } } -impl From for String { - fn from(distribution_type: TokenDistributionTypeWASM) -> Self { +impl From for String { + fn from(distribution_type: TokenDistributionTypeWasm) -> Self { match distribution_type { - TokenDistributionTypeWASM::PreProgrammed => String::from("PreProgrammed"), - TokenDistributionTypeWASM::Perpetual => String::from("Perpetual"), + TokenDistributionTypeWasm::PreProgrammed => String::from("PreProgrammed"), + TokenDistributionTypeWasm::Perpetual => String::from("Perpetual"), } } } diff --git a/packages/wasm-dpp2/src/enums/token/emergency_action.rs b/packages/wasm-dpp2/src/enums/token/emergency_action.rs index 08d49820078..eb75962a439 100644 --- a/packages/wasm-dpp2/src/enums/token/emergency_action.rs +++ b/packages/wasm-dpp2/src/enums/token/emergency_action.rs @@ -5,48 +5,48 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "TokenEmergencyAction")] #[allow(non_camel_case_types)] #[derive(Default)] -pub enum TokenEmergencyActionWASM { +pub enum TokenEmergencyActionWasm { #[default] Pause = 0, Resume = 1, } -impl From for TokenEmergencyAction { - fn from(distribution_type: TokenEmergencyActionWASM) -> Self { +impl From for TokenEmergencyAction { + fn from(distribution_type: TokenEmergencyActionWasm) -> Self { match distribution_type { - TokenEmergencyActionWASM::Pause => TokenEmergencyAction::Pause, - TokenEmergencyActionWASM::Resume => TokenEmergencyAction::Resume, + TokenEmergencyActionWasm::Pause => TokenEmergencyAction::Pause, + TokenEmergencyActionWasm::Resume => TokenEmergencyAction::Resume, } } } -impl From for TokenEmergencyActionWASM { +impl From for TokenEmergencyActionWasm { fn from(distribution_type: TokenEmergencyAction) -> Self { match distribution_type { - TokenEmergencyAction::Pause => TokenEmergencyActionWASM::Pause, - TokenEmergencyAction::Resume => TokenEmergencyActionWASM::Resume, + TokenEmergencyAction::Pause => TokenEmergencyActionWasm::Pause, + TokenEmergencyAction::Resume => TokenEmergencyActionWasm::Resume, } } } -impl TryFrom for TokenEmergencyActionWASM { +impl TryFrom for TokenEmergencyActionWasm { type Error = JsValue; - fn try_from(value: JsValue) -> Result { + fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "pause" => Ok(TokenEmergencyActionWASM::Pause), - "resume" => Ok(TokenEmergencyActionWASM::Resume), + "pause" => Ok(TokenEmergencyActionWasm::Pause), + "resume" => Ok(TokenEmergencyActionWasm::Resume), _ => Err(JsValue::from("unknown distribution type")), }, }, false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 0 => Ok(TokenEmergencyActionWASM::Pause), - 1 => Ok(TokenEmergencyActionWASM::Resume), + 0 => Ok(TokenEmergencyActionWasm::Pause), + 1 => Ok(TokenEmergencyActionWasm::Resume), _ => Err(JsValue::from("unknown distribution type")), }, }, @@ -54,11 +54,11 @@ impl TryFrom for TokenEmergencyActionWASM { } } -impl From for String { - fn from(distribution_type: TokenEmergencyActionWASM) -> Self { +impl From for String { + fn from(distribution_type: TokenEmergencyActionWasm) -> Self { match distribution_type { - TokenEmergencyActionWASM::Pause => String::from("Pause"), - TokenEmergencyActionWASM::Resume => String::from("Resume"), + TokenEmergencyActionWasm::Pause => String::from("Pause"), + TokenEmergencyActionWasm::Resume => String::from("Resume"), } } } diff --git a/packages/wasm-dpp2/src/enums/withdrawal/mod.rs b/packages/wasm-dpp2/src/enums/withdrawal/mod.rs index 226ba34716b..1b2f9096446 100644 --- a/packages/wasm-dpp2/src/enums/withdrawal/mod.rs +++ b/packages/wasm-dpp2/src/enums/withdrawal/mod.rs @@ -3,42 +3,42 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen] -pub enum PoolingWASM { +pub enum PoolingWasm { Never = 0, IfAvailable = 1, Standard = 2, } -impl From for Pooling { - fn from(pooling: PoolingWASM) -> Self { +impl From for Pooling { + fn from(pooling: PoolingWasm) -> Self { match pooling { - PoolingWASM::Never => Pooling::Never, - PoolingWASM::IfAvailable => Pooling::IfAvailable, - PoolingWASM::Standard => Pooling::Standard, + PoolingWasm::Never => Pooling::Never, + PoolingWasm::IfAvailable => Pooling::IfAvailable, + PoolingWasm::Standard => Pooling::Standard, } } } -impl From for PoolingWASM { +impl From for PoolingWasm { fn from(pooling: Pooling) -> Self { match pooling { - Pooling::Never => PoolingWASM::Never, - Pooling::IfAvailable => PoolingWASM::IfAvailable, - Pooling::Standard => PoolingWASM::Standard, + Pooling::Never => PoolingWasm::Never, + Pooling::IfAvailable => PoolingWasm::IfAvailable, + Pooling::Standard => PoolingWasm::Standard, } } } -impl TryFrom for PoolingWASM { +impl TryFrom for PoolingWasm { type Error = JsValue; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val.to_lowercase().as_str() { - "never" => Ok(PoolingWASM::Never), - "ifavailable" => Ok(PoolingWASM::IfAvailable), - "standard" => Ok(PoolingWASM::Standard), + "never" => Ok(PoolingWasm::Never), + "ifavailable" => Ok(PoolingWasm::IfAvailable), + "standard" => Ok(PoolingWasm::Standard), _ => Err(JsValue::from(format!( "unsupported pooling value ({})", enum_val @@ -48,9 +48,9 @@ impl TryFrom for PoolingWASM { false => match value.as_f64() { None => Err(JsValue::from("cannot read value from enum")), Some(enum_val) => match enum_val as u8 { - 0 => Ok(PoolingWASM::Never), - 1 => Ok(PoolingWASM::IfAvailable), - 2 => Ok(PoolingWASM::Standard), + 0 => Ok(PoolingWasm::Never), + 1 => Ok(PoolingWasm::IfAvailable), + 2 => Ok(PoolingWasm::Standard), _ => Err(JsValue::from(format!( "unsupported pooling value ({})", enum_val @@ -61,12 +61,12 @@ impl TryFrom for PoolingWASM { } } -impl From for String { - fn from(pooling_wasm: PoolingWASM) -> String { +impl From for String { + fn from(pooling_wasm: PoolingWasm) -> String { match pooling_wasm { - PoolingWASM::Never => String::from("Never"), - PoolingWASM::IfAvailable => String::from("IfAvailable"), - PoolingWASM::Standard => String::from("Standard"), + PoolingWasm::Never => String::from("Never"), + PoolingWasm::IfAvailable => String::from("IfAvailable"), + PoolingWasm::Standard => String::from("Standard"), } } } diff --git a/packages/wasm-dpp2/src/group_state_transition_info/mod.rs b/packages/wasm-dpp2/src/group_state_transition_info/mod.rs index 1089e75e47f..52c899611cb 100644 --- a/packages/wasm-dpp2/src/group_state_transition_info/mod.rs +++ b/packages/wasm-dpp2/src/group_state_transition_info/mod.rs @@ -1,26 +1,26 @@ -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use dpp::group::GroupStateTransitionInfo; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=GroupStateTransitionInfo)] -pub struct GroupStateTransitionInfoWASM(GroupStateTransitionInfo); +pub struct GroupStateTransitionInfoWasm(GroupStateTransitionInfo); -impl From for GroupStateTransitionInfo { - fn from(info: GroupStateTransitionInfoWASM) -> Self { +impl From for GroupStateTransitionInfo { + fn from(info: GroupStateTransitionInfoWasm) -> Self { info.0 } } -impl From for GroupStateTransitionInfoWASM { +impl From for GroupStateTransitionInfoWasm { fn from(info: GroupStateTransitionInfo) -> Self { - GroupStateTransitionInfoWASM(info) + GroupStateTransitionInfoWasm(info) } } #[wasm_bindgen(js_class = GroupStateTransitionInfo)] -impl GroupStateTransitionInfoWASM { +impl GroupStateTransitionInfoWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "GroupStateTransitionInfo".to_string() @@ -36,10 +36,10 @@ impl GroupStateTransitionInfoWASM { group_contract_position: u16, action_id: &JsValue, action_is_proposer: bool, - ) -> Result { - Ok(GroupStateTransitionInfoWASM(GroupStateTransitionInfo { + ) -> Result { + Ok(GroupStateTransitionInfoWasm(GroupStateTransitionInfo { group_contract_position, - action_id: IdentifierWASM::try_from(action_id)?.into(), + action_id: IdentifierWasm::try_from(action_id)?.into(), action_is_proposer, })) } @@ -51,7 +51,7 @@ impl GroupStateTransitionInfoWASM { #[wasm_bindgen(setter = "actionId")] pub fn set_action_id(&mut self, action_id: &JsValue) -> Result<(), JsValue> { - self.0.action_id = IdentifierWASM::try_from(action_id)?.into(); + self.0.action_id = IdentifierWasm::try_from(action_id)?.into(); Ok(()) } @@ -66,7 +66,7 @@ impl GroupStateTransitionInfoWASM { } #[wasm_bindgen(getter = "actionId")] - pub fn get_action_id(&self) -> IdentifierWASM { + pub fn get_action_id(&self) -> IdentifierWasm { self.0.action_id.into() } diff --git a/packages/wasm-dpp2/src/identifier/mod.rs b/packages/wasm-dpp2/src/identifier/mod.rs index 256ef4e16c8..e28a9891385 100644 --- a/packages/wasm-dpp2/src/identifier/mod.rs +++ b/packages/wasm-dpp2/src/identifier/mod.rs @@ -6,33 +6,33 @@ use wasm_bindgen::prelude::*; #[derive(Copy, Clone)] #[wasm_bindgen(js_name = "Identifier")] -pub struct IdentifierWASM(Identifier); +pub struct IdentifierWasm(Identifier); -impl From for Identifier { - fn from(identifier: IdentifierWASM) -> Self { +impl From for Identifier { + fn from(identifier: IdentifierWasm) -> Self { identifier.0 } } -impl From for IdentifierWASM { +impl From for IdentifierWasm { fn from(identifier: Identifier) -> Self { - IdentifierWASM(identifier) + IdentifierWasm(identifier) } } -impl From<[u8; 32]> for IdentifierWASM { +impl From<[u8; 32]> for IdentifierWasm { fn from(identifier: [u8; 32]) -> Self { - IdentifierWASM(Identifier::new(identifier)) + IdentifierWasm(Identifier::new(identifier)) } } -impl From<&IdentifierWASM> for Identifier { - fn from(identifier: &IdentifierWASM) -> Self { +impl From<&IdentifierWasm> for Identifier { + fn from(identifier: &IdentifierWasm) -> Self { identifier.clone().into() } } -impl TryFrom<&[u8]> for IdentifierWASM { +impl TryFrom<&[u8]> for IdentifierWasm { type Error = JsValue; fn try_from(value: &[u8]) -> Result { if value.len() != 32 { @@ -43,18 +43,18 @@ impl TryFrom<&[u8]> for IdentifierWASM { .try_into() .map_err(|_| JsValue::from("Cannot parse identifier"))?; - Ok(IdentifierWASM(Identifier::new(norm_slice))) + Ok(IdentifierWasm(Identifier::new(norm_slice))) } } -impl TryFrom for IdentifierWASM { +impl TryFrom for IdentifierWasm { type Error = JsValue; fn try_from(value: JsValue) -> Result { match value.is_object() { true => match get_class_type(&value) { Ok(class_type) => match class_type.as_str() { "Identifier" => { - Ok(value.to_wasm::("Identifier")?.clone()) + Ok(value.to_wasm::("Identifier")?.clone()) } "" => Ok(identifier_from_js_value(&value)?.into()), _ => Err(Self::Error::from_str(&format!( @@ -73,7 +73,7 @@ impl TryFrom for IdentifierWASM { let bytes = decode(value.as_string().unwrap().as_str(), Hex) .map_err(|err| JsValue::from(err.to_string()))?; - Ok(IdentifierWASM::try_from(bytes.as_slice())?) + Ok(IdentifierWasm::try_from(bytes.as_slice())?) } false => Ok(identifier_from_js_value(&value)?.into()), } @@ -83,15 +83,15 @@ impl TryFrom for IdentifierWASM { } } -impl TryFrom<&JsValue> for IdentifierWASM { +impl TryFrom<&JsValue> for IdentifierWasm { type Error = JsValue; fn try_from(value: &JsValue) -> Result { - IdentifierWASM::try_from(value.clone()) + IdentifierWasm::try_from(value.clone()) } } #[wasm_bindgen(js_class = Identifier)] -impl IdentifierWASM { +impl IdentifierWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "Identifier".to_string() @@ -103,8 +103,8 @@ impl IdentifierWASM { } #[wasm_bindgen(constructor)] - pub fn new(js_identifier: &JsValue) -> Result { - IdentifierWASM::try_from(js_identifier) + pub fn new(js_identifier: &JsValue) -> Result { + IdentifierWasm::try_from(js_identifier) } #[wasm_bindgen(js_name = "base58")] @@ -128,39 +128,39 @@ impl IdentifierWASM { } #[wasm_bindgen(js_name = "fromBase58")] - pub fn from_base58(base58: String) -> Result { + pub fn from_base58(base58: String) -> Result { let identitfier = Identifier::from_string(base58.as_str(), Base58) .map_err(|err| JsValue::from(err.to_string()))?; - Ok(IdentifierWASM(identitfier)) + Ok(IdentifierWasm(identitfier)) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { + pub fn from_base64(base64: String) -> Result { let identitfier = Identifier::from_string(base64.as_str(), Base64) .map_err(|err| JsValue::from(err.to_string()))?; - Ok(IdentifierWASM(identitfier)) + Ok(IdentifierWasm(identitfier)) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { + pub fn from_hex(hex: String) -> Result { let identitfier = Identifier::from_string(hex.as_str(), Hex) .map_err(|err| JsValue::from(err.to_string()))?; - Ok(IdentifierWASM(identitfier)) + Ok(IdentifierWasm(identitfier)) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { let identifier = Identifier::from_vec(bytes).map_err(|err| JsValue::from(err.to_string()))?; - Ok(IdentifierWASM(identifier)) + Ok(IdentifierWasm(identifier)) } } -impl IdentifierWASM { +impl IdentifierWasm { pub fn to_slice(&self) -> [u8; 32] { self.0.as_bytes().clone() } diff --git a/packages/wasm-dpp2/src/identity/mod.rs b/packages/wasm-dpp2/src/identity/mod.rs index c8b6038ec9f..8361803a117 100644 --- a/packages/wasm-dpp2/src/identity/mod.rs +++ b/packages/wasm-dpp2/src/identity/mod.rs @@ -1,5 +1,5 @@ -use crate::identifier::IdentifierWASM; -use crate::identity_public_key::IdentityPublicKeyWASM; +use crate::identifier::IdentifierWasm; +use crate::identity_public_key::IdentityPublicKeyWasm; use crate::utils::WithJsError; use dpp::identity::accessors::{IdentityGettersV0, IdentitySettersV0}; use dpp::identity::{Identity, KeyID}; @@ -14,16 +14,16 @@ use wasm_bindgen::{JsError, JsValue}; #[derive(Clone)] #[wasm_bindgen(js_name = "Identity")] -pub struct IdentityWASM(Identity); +pub struct IdentityWasm(Identity); -impl From for IdentityWASM { +impl From for IdentityWasm { fn from(identity: Identity) -> Self { Self(identity) } } #[wasm_bindgen(js_class = Identity)] -impl IdentityWASM { +impl IdentityWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "Identity".to_string() @@ -35,20 +35,20 @@ impl IdentityWASM { } #[wasm_bindgen(constructor)] - pub fn new(js_identifier: &JsValue) -> Result { - let identifier: IdentifierWASM = js_identifier.try_into()?; + pub fn new(js_identifier: &JsValue) -> Result { + let identifier: IdentifierWasm = js_identifier.try_into()?; let identity = Identity::create_basic_identity(identifier.into(), PlatformVersion::first()) .with_js_error()?; - Ok(IdentityWASM(identity)) + Ok(IdentityWasm(identity)) } #[wasm_bindgen(setter = "id")] pub fn set_id(&mut self, js_identifier: &JsValue) -> Result<(), JsValue> { Ok(self .0 - .set_id(IdentifierWASM::try_from(js_identifier)?.into())) + .set_id(IdentifierWasm::try_from(js_identifier)?.into())) } #[wasm_bindgen(setter = "balance")] @@ -62,14 +62,14 @@ impl IdentityWASM { } #[wasm_bindgen(js_name = "addPublicKey")] - pub fn add_public_key(&mut self, public_key: &IdentityPublicKeyWASM) { + pub fn add_public_key(&mut self, public_key: &IdentityPublicKeyWasm) { self.0.add_public_key(public_key.clone().into()); } // GETTERS #[wasm_bindgen(getter = "id")] - pub fn get_id(&self) -> IdentifierWASM { + pub fn get_id(&self) -> IdentifierWasm { self.0.id().into() } @@ -84,35 +84,35 @@ impl IdentityWASM { } #[wasm_bindgen(js_name = "getPublicKeyById")] - pub fn get_public_key_by_id(&self, key_id: KeyID) -> IdentityPublicKeyWASM { + pub fn get_public_key_by_id(&self, key_id: KeyID) -> IdentityPublicKeyWasm { let identity_public_key = self.0.get_public_key_by_id(key_id); - IdentityPublicKeyWASM::from(identity_public_key.unwrap().clone()) + IdentityPublicKeyWasm::from(identity_public_key.unwrap().clone()) } #[wasm_bindgen(js_name = "getPublicKeys")] - pub fn get_public_keys(&self) -> Vec { + pub fn get_public_keys(&self) -> Vec { let keys = self .0 .public_keys() .iter() - .map(|(_index, key)| IdentityPublicKeyWASM::from(key.clone())) + .map(|(_index, key)| IdentityPublicKeyWasm::from(key.clone())) .collect(); keys } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { + pub fn from_hex(hex: String) -> Result { let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; - IdentityWASM::from_bytes(bytes) + IdentityWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { + pub fn from_base64(base64: String) -> Result { let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; - IdentityWASM::from_bytes(bytes) + IdentityWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "bytes")] @@ -137,15 +137,15 @@ impl IdentityWASM { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { match Identity::deserialize_from_bytes(bytes.as_slice()).with_js_error() { - Ok(identity) => Ok(IdentityWASM(identity)), + Ok(identity) => Ok(IdentityWasm(identity)), Err(err) => Err(err), } } } -impl IdentityWASM { +impl IdentityWasm { pub fn get_rs_public_keys(&self) -> BTreeMap { self.0.public_keys().clone() } diff --git a/packages/wasm-dpp2/src/identity_public_key/mod.rs b/packages/wasm-dpp2/src/identity_public_key/mod.rs index fcb2f770381..1893a0f71e0 100644 --- a/packages/wasm-dpp2/src/identity_public_key/mod.rs +++ b/packages/wasm-dpp2/src/identity_public_key/mod.rs @@ -1,8 +1,8 @@ -use crate::contract_bounds::ContractBoundsWASM; -use crate::enums::keys::key_type::KeyTypeWASM; -use crate::enums::keys::purpose::PurposeWASM; -use crate::enums::keys::security_level::SecurityLevelWASM; -use crate::enums::network::NetworkWASM; +use crate::contract_bounds::ContractBoundsWasm; +use crate::enums::keys::key_type::KeyTypeWasm; +use crate::enums::keys::purpose::PurposeWasm; +use crate::enums::keys::security_level::SecurityLevelWasm; +use crate::enums::network::NetworkWasm; use crate::utils::{IntoWasm, WithJsError}; use dpp::dashcore::Network; use dpp::dashcore::secp256k1::hashes::hex::{Case, DisplayHex}; @@ -22,22 +22,22 @@ use wasm_bindgen::{JsError, JsValue}; #[derive(Clone)] #[wasm_bindgen(js_name = IdentityPublicKey)] -pub struct IdentityPublicKeyWASM(IdentityPublicKey); +pub struct IdentityPublicKeyWasm(IdentityPublicKey); -impl From for IdentityPublicKeyWASM { +impl From for IdentityPublicKeyWasm { fn from(value: IdentityPublicKey) -> Self { - IdentityPublicKeyWASM(value) + IdentityPublicKeyWasm(value) } } -impl From for IdentityPublicKey { - fn from(value: IdentityPublicKeyWASM) -> Self { +impl From for IdentityPublicKey { + fn from(value: IdentityPublicKeyWasm) -> Self { value.0 } } #[wasm_bindgen(js_class = IdentityPublicKey)] -impl IdentityPublicKeyWASM { +impl IdentityPublicKeyWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "IdentityPublicKey".to_string() @@ -59,21 +59,21 @@ impl IdentityPublicKeyWASM { disabled_at: Option, js_contract_bounds: &JsValue, ) -> Result { - let purpose = PurposeWASM::try_from(js_purpose)?; - let security_level = SecurityLevelWASM::try_from(js_security_level)?; - let key_type = KeyTypeWASM::try_from(js_key_type)?; + let purpose = PurposeWasm::try_from(js_purpose)?; + let security_level = SecurityLevelWasm::try_from(js_security_level)?; + let key_type = KeyTypeWasm::try_from(js_key_type)?; let contract_bounds: Option = match js_contract_bounds.is_undefined() | js_contract_bounds.is_null() { true => None, false => Some( js_contract_bounds - .to_wasm::("ContractBounds")? + .to_wasm::("ContractBounds")? .clone() .into(), ), }; - Ok(IdentityPublicKeyWASM(IdentityPublicKey::from( + Ok(IdentityPublicKeyWasm(IdentityPublicKey::from( IdentityPublicKeyV0 { id, purpose: Purpose::from(purpose), @@ -89,7 +89,7 @@ impl IdentityPublicKeyWASM { } #[wasm_bindgen(js_class = IdentityPublicKey)] -impl IdentityPublicKeyWASM { +impl IdentityPublicKeyWasm { #[wasm_bindgen(js_name = "validatePrivateKey")] pub fn validate_private_key( &self, @@ -100,7 +100,7 @@ impl IdentityPublicKeyWASM { let len = js_private_key_bytes.len().min(32); private_key_bytes[..len].copy_from_slice(&js_private_key_bytes[..len]); - let network = Network::from(NetworkWASM::try_from(js_network)?); + let network = Network::from(NetworkWasm::try_from(js_network)?); self.0 .validate_private_key_bytes(&private_key_bytes, network) @@ -111,7 +111,7 @@ impl IdentityPublicKeyWASM { pub fn contract_bounds(&self) -> JsValue { match self.0.contract_bounds() { None => JsValue::undefined(), - Some(bounds) => JsValue::from(ContractBoundsWASM::from(bounds.clone())), + Some(bounds) => JsValue::from(ContractBoundsWasm::from(bounds.clone())), } } @@ -122,32 +122,32 @@ impl IdentityPublicKeyWASM { #[wasm_bindgen(getter = purpose)] pub fn get_purpose(&self) -> String { - PurposeWASM::from(self.0.purpose()).into() + PurposeWasm::from(self.0.purpose()).into() } #[wasm_bindgen(getter = purposeNumber)] - pub fn get_purpose_number(&self) -> PurposeWASM { - PurposeWASM::from(self.0.purpose()) + pub fn get_purpose_number(&self) -> PurposeWasm { + PurposeWasm::from(self.0.purpose()) } #[wasm_bindgen(getter = securityLevel)] pub fn get_security_level(&self) -> String { - SecurityLevelWASM::from(self.0.security_level()).into() + SecurityLevelWasm::from(self.0.security_level()).into() } #[wasm_bindgen(getter = securityLevelNumber)] - pub fn get_security_level_number(&self) -> SecurityLevelWASM { - SecurityLevelWASM::from(self.0.security_level()) + pub fn get_security_level_number(&self) -> SecurityLevelWasm { + SecurityLevelWasm::from(self.0.security_level()) } #[wasm_bindgen(getter = keyType)] pub fn get_key_type(&self) -> String { - KeyTypeWASM::from(self.0.key_type()).into() + KeyTypeWasm::from(self.0.key_type()).into() } #[wasm_bindgen(getter = keyTypeNumber)] - pub fn get_key_type_number(&self) -> KeyTypeWASM { - KeyTypeWASM::from(self.0.key_type()) + pub fn get_key_type_number(&self) -> KeyTypeWasm { + KeyTypeWasm::from(self.0.key_type()) } #[wasm_bindgen(getter = readOnly)] @@ -174,7 +174,7 @@ impl IdentityPublicKeyWASM { pub fn set_purpose(&mut self, purpose: JsValue) -> Result<(), JsValue> { Ok(self .0 - .set_purpose(Purpose::from(PurposeWASM::try_from(purpose)?))) + .set_purpose(Purpose::from(PurposeWasm::try_from(purpose)?))) } #[wasm_bindgen(setter = purposeNumber)] @@ -186,7 +186,7 @@ impl IdentityPublicKeyWASM { pub fn set_security_level(&mut self, security_level: JsValue) -> Result<(), JsValue> { Ok(self .0 - .set_security_level(SecurityLevel::from(SecurityLevelWASM::try_from( + .set_security_level(SecurityLevel::from(SecurityLevelWasm::try_from( security_level, )?))) } @@ -200,7 +200,7 @@ impl IdentityPublicKeyWASM { pub fn set_key_type(&mut self, key_type: JsValue) -> Result<(), JsValue> { Ok(self .0 - .set_key_type(KeyType::from(KeyTypeWASM::try_from(key_type)?))) + .set_key_type(KeyType::from(KeyTypeWasm::try_from(key_type)?))) } #[wasm_bindgen(setter = keyTypeNumber)] @@ -264,30 +264,30 @@ impl IdentityPublicKeyWASM { } #[wasm_bindgen(js_name = fromBytes)] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { let public_key = IdentityPublicKey::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; - Ok(IdentityPublicKeyWASM(public_key)) + Ok(IdentityPublicKeyWasm(public_key)) } #[wasm_bindgen(js_name = fromHex)] - pub fn from_hex(hex: String) -> Result { + pub fn from_hex(hex: String) -> Result { let bytes = decode(&hex, Hex).map_err(|err| JsValue::from(JsError::from(err)))?; let public_key = IdentityPublicKey::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; - Ok(IdentityPublicKeyWASM(public_key)) + Ok(IdentityPublicKeyWasm(public_key)) } #[wasm_bindgen(js_name = fromBase64)] - pub fn from_base64(hex: String) -> Result { + pub fn from_base64(hex: String) -> Result { let bytes = decode(&hex, Base64).map_err(|err| JsValue::from(JsError::from(err)))?; let public_key = IdentityPublicKey::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; - Ok(IdentityPublicKeyWASM(public_key)) + Ok(IdentityPublicKeyWasm(public_key)) } } diff --git a/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs index f8467bbc28d..339839b010a 100644 --- a/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs @@ -1,8 +1,8 @@ -use crate::asset_lock_proof::AssetLockProofWASM; -use crate::enums::platform::PlatformVersionWASM; -use crate::identifier::IdentifierWASM; -use crate::identity_transitions::public_key_in_creation::IdentityPublicKeyInCreationWASM; -use crate::state_transition::StateTransitionWASM; +use crate::asset_lock_proof::AssetLockProofWasm; +use crate::enums::platform::PlatformVersionWasm; +use crate::identifier::IdentifierWasm; +use crate::identity_transitions::public_key_in_creation::IdentityPublicKeyInCreationWasm; +use crate::state_transition::StateTransitionWasm; use crate::utils::WithJsError; use dpp::identity::state_transition::AssetLockProved; use dpp::platform_value::BinaryData; @@ -20,22 +20,22 @@ use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "IdentityCreateTransition")] #[derive(Clone)] -pub struct IdentityCreateTransitionWASM(IdentityCreateTransition); +pub struct IdentityCreateTransitionWasm(IdentityCreateTransition); -impl From for IdentityCreateTransitionWASM { +impl From for IdentityCreateTransitionWasm { fn from(val: IdentityCreateTransition) -> Self { - IdentityCreateTransitionWASM(val) + IdentityCreateTransitionWasm(val) } } -impl From for IdentityCreateTransition { - fn from(val: IdentityCreateTransitionWASM) -> Self { +impl From for IdentityCreateTransition { + fn from(val: IdentityCreateTransitionWasm) -> Self { val.0 } } #[wasm_bindgen(js_class = IdentityCreateTransition)] -impl IdentityCreateTransitionWASM { +impl IdentityCreateTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "IdentityCreateTransition".to_string() @@ -49,14 +49,14 @@ impl IdentityCreateTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( js_public_keys: &js_sys::Array, - asset_lock: &AssetLockProofWASM, + asset_lock: &AssetLockProofWasm, signature: Option>, user_fee_increase: Option, - ) -> Result { - let public_keys: Vec = - IdentityPublicKeyInCreationWASM::vec_from_js_value(js_public_keys)?; + ) -> Result { + let public_keys: Vec = + IdentityPublicKeyInCreationWasm::vec_from_js_value(js_public_keys)?; - Ok(IdentityCreateTransitionWASM(IdentityCreateTransition::V0( + Ok(IdentityCreateTransitionWasm(IdentityCreateTransition::V0( IdentityCreateTransitionV0 { public_keys: public_keys.iter().map(|key| key.clone().into()).collect(), asset_lock_proof: asset_lock.clone().into(), @@ -68,8 +68,8 @@ impl IdentityCreateTransitionWASM { } #[wasm_bindgen(js_name = "default")] - pub fn default(js_platform_version: JsValue) -> Result { - let platform_version = PlatformVersionWASM::try_from(js_platform_version)?; + pub fn default(js_platform_version: JsValue) -> Result { + let platform_version = PlatformVersionWasm::try_from(js_platform_version)?; IdentityCreateTransition::default_versioned(&platform_version.into()) .map_err(|err| JsValue::from_str(&*err.to_string())) @@ -77,17 +77,17 @@ impl IdentityCreateTransitionWASM { } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { + pub fn from_hex(hex: String) -> Result { let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; - IdentityCreateTransitionWASM::from_bytes(bytes) + IdentityCreateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { + pub fn from_base64(base64: String) -> Result { let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; - IdentityCreateTransitionWASM::from_bytes(bytes) + IdentityCreateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "bytes")] @@ -96,24 +96,24 @@ impl IdentityCreateTransitionWASM { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { let rs_transition = IdentityCreateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; - Ok(IdentityCreateTransitionWASM(rs_transition)) + Ok(IdentityCreateTransitionWasm(rs_transition)) } #[wasm_bindgen(getter = "publicKeys")] - pub fn get_public_keys(&self) -> Vec { + pub fn get_public_keys(&self) -> Vec { self.0 .public_keys() .iter() - .map(|key| IdentityPublicKeyInCreationWASM::from(key.clone())) + .map(|key| IdentityPublicKeyInCreationWasm::from(key.clone())) .collect() } #[wasm_bindgen(js_name = "getIdentifier")] - pub fn get_identity_id(&self) -> IdentifierWASM { + pub fn get_identity_id(&self) -> IdentifierWasm { self.0.identity_id().into() } @@ -133,14 +133,14 @@ impl IdentityCreateTransitionWASM { } #[wasm_bindgen(getter = "assetLock")] - pub fn get_asset_lock_proof(&self) -> AssetLockProofWASM { - AssetLockProofWASM::from(self.0.asset_lock_proof().clone()) + pub fn get_asset_lock_proof(&self) -> AssetLockProofWasm { + AssetLockProofWasm::from(self.0.asset_lock_proof().clone()) } #[wasm_bindgen(setter = "publicKeys")] pub fn set_public_keys(&mut self, js_public_keys: &js_sys::Array) -> Result<(), JsValue> { - let public_keys: Vec = - IdentityPublicKeyInCreationWASM::vec_from_js_value(js_public_keys)?; + let public_keys: Vec = + IdentityPublicKeyInCreationWasm::vec_from_js_value(js_public_keys)?; self.0.set_public_keys( public_keys @@ -163,23 +163,23 @@ impl IdentityCreateTransitionWASM { } #[wasm_bindgen(setter = "assetLock")] - pub fn set_asset_lock_proof(&mut self, proof: AssetLockProofWASM) -> Result<(), JsValue> { + pub fn set_asset_lock_proof(&mut self, proof: AssetLockProofWasm) -> Result<(), JsValue> { self.0.set_asset_lock_proof(proof.into()).with_js_error() } #[wasm_bindgen(js_name = "toStateTransition")] - pub fn to_state_transition(&self) -> StateTransitionWASM { - StateTransitionWASM::from(StateTransition::IdentityCreate(self.clone().0)) + pub fn to_state_transition(&self) -> StateTransitionWasm { + StateTransitionWasm::from(StateTransition::IdentityCreate(self.clone().0)) } #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( - st: &StateTransitionWASM, - ) -> Result { + st: &StateTransitionWasm, + ) -> Result { let rs_st: StateTransition = st.clone().into(); match rs_st { - StateTransition::IdentityCreate(st) => Ok(IdentityCreateTransitionWASM(st)), + StateTransition::IdentityCreate(st) => Ok(IdentityCreateTransitionWasm(st)), _ => Err(JsValue::from_str( &"Invalid state document_transition type)", )), diff --git a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs index 7cf0a9afa96..64ce8a2cbc7 100644 --- a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs @@ -1,9 +1,9 @@ -use crate::asset_lock_proof::AssetLockProofWASM; -use crate::core_script::CoreScriptWASM; -use crate::enums::keys::purpose::PurposeWASM; -use crate::enums::withdrawal::PoolingWASM; -use crate::identifier::IdentifierWASM; -use crate::state_transition::StateTransitionWASM; +use crate::asset_lock_proof::AssetLockProofWasm; +use crate::core_script::CoreScriptWasm; +use crate::enums::keys::purpose::PurposeWasm; +use crate::enums::withdrawal::PoolingWasm; +use crate::identifier::IdentifierWasm; +use crate::state_transition::StateTransitionWasm; use crate::utils::{IntoWasm, WithJsError}; use dpp::identity::KeyID; use dpp::identity::core_script::CoreScript; @@ -21,10 +21,10 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "IdentityCreditWithdrawalTransition")] -pub struct IdentityCreditWithdrawalTransitionWASM(IdentityCreditWithdrawalTransition); +pub struct IdentityCreditWithdrawalTransitionWasm(IdentityCreditWithdrawalTransition); #[wasm_bindgen(js_class = IdentityCreditWithdrawalTransition)] -impl IdentityCreditWithdrawalTransitionWASM { +impl IdentityCreditWithdrawalTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "IdentityCreditWithdrawalTransition".to_string() @@ -44,21 +44,21 @@ impl IdentityCreditWithdrawalTransitionWASM { js_output_script: &JsValue, nonce: Option, user_fee_increase: Option, - ) -> Result { - let pooling = PoolingWASM::try_from(js_pooling)?; - let identity_id: Identifier = IdentifierWASM::try_from(js_identity_id)?.into(); + ) -> Result { + let pooling = PoolingWasm::try_from(js_pooling)?; + let identity_id: Identifier = IdentifierWasm::try_from(js_identity_id)?.into(); let output_script: Option = match js_output_script.is_undefined() { true => None, false => Some( js_output_script - .to_wasm::("CoreScript")? + .to_wasm::("CoreScript")? .clone() .into(), ), }; - Ok(IdentityCreditWithdrawalTransitionWASM( + Ok(IdentityCreditWithdrawalTransitionWasm( IdentityCreditWithdrawalTransition::V1(IdentityCreditWithdrawalTransitionV1 { amount, identity_id, @@ -74,7 +74,7 @@ impl IdentityCreditWithdrawalTransitionWASM { } #[wasm_bindgen(getter = "outputScript")] - pub fn get_output_script(&self) -> Option { + pub fn get_output_script(&self) -> Option { match self.0.output_script() { None => None, Some(script) => Some(script.into()), @@ -83,12 +83,12 @@ impl IdentityCreditWithdrawalTransitionWASM { #[wasm_bindgen(getter = "pooling")] pub fn get_pooling(&self) -> String { - PoolingWASM::from(self.0.pooling()).into() + PoolingWasm::from(self.0.pooling()).into() } #[wasm_bindgen(getter = "identityId")] - pub fn get_identity_id(&self) -> IdentifierWASM { - IdentifierWASM::from(self.0.identity_id()) + pub fn get_identity_id(&self) -> IdentifierWasm { + IdentifierWasm::from(self.0.identity_id()) } #[wasm_bindgen(getter = "userFeeIncrease")] @@ -111,12 +111,12 @@ impl IdentityCreditWithdrawalTransitionWASM { self.0 .purpose_requirement() .iter() - .map(|purpose| PurposeWASM::from(purpose.clone()).into()) + .map(|purpose| PurposeWasm::from(purpose.clone()).into()) .collect() } #[wasm_bindgen(js_name = "getModifiedDataIds")] - pub fn get_modified_data_ids(&self) -> Vec { + pub fn get_modified_data_ids(&self) -> Vec { self.0 .modified_data_ids() .iter() @@ -127,7 +127,7 @@ impl IdentityCreditWithdrawalTransitionWASM { #[wasm_bindgen(js_name = "getOptionalAssetLockProof")] pub fn get_optional_asset_lock_proof(&self) -> JsValue { match self.0.optional_asset_lock_proof() { - Some(asset_lock) => JsValue::from(AssetLockProofWASM::from(asset_lock.clone())), + Some(asset_lock) => JsValue::from(AssetLockProofWasm::from(asset_lock.clone())), None => JsValue::null(), } } @@ -137,8 +137,8 @@ impl IdentityCreditWithdrawalTransitionWASM { match js_script.is_undefined() { true => self.0.set_output_script(None), false => { - let script: CoreScriptWASM = js_script - .to_wasm::("CoreScript")? + let script: CoreScriptWasm = js_script + .to_wasm::("CoreScript")? .clone(); self.0.set_output_script(Some(script.clone().into())) } @@ -149,13 +149,13 @@ impl IdentityCreditWithdrawalTransitionWASM { #[wasm_bindgen(setter = "pooling")] pub fn set_pooling(&mut self, js_pooling: JsValue) -> Result<(), JsValue> { - let pooling: PoolingWASM = PoolingWASM::try_from(js_pooling)?; + let pooling: PoolingWasm = PoolingWasm::try_from(js_pooling)?; Ok(self.0.set_pooling(pooling.into())) } #[wasm_bindgen(setter = "identityId")] pub fn set_identity_id(&mut self, js_identity_id: JsValue) -> Result<(), JsValue> { - let identity_id = IdentifierWASM::try_from(js_identity_id)?; + let identity_id = IdentifierWasm::try_from(js_identity_id)?; Ok(self.0.set_identity_id(identity_id.into())) } @@ -211,17 +211,17 @@ impl IdentityCreditWithdrawalTransitionWASM { } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { + pub fn from_hex(hex: String) -> Result { let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; - IdentityCreditWithdrawalTransitionWASM::from_bytes(bytes) + IdentityCreditWithdrawalTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { + pub fn from_base64(base64: String) -> Result { let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; - IdentityCreditWithdrawalTransitionWASM::from_bytes(bytes) + IdentityCreditWithdrawalTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "bytes")] @@ -246,28 +246,28 @@ impl IdentityCreditWithdrawalTransitionWASM { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { let rs_transition = IdentityCreditWithdrawalTransition::deserialize_from_bytes(bytes.as_slice()) .with_js_error()?; - Ok(IdentityCreditWithdrawalTransitionWASM(rs_transition)) + Ok(IdentityCreditWithdrawalTransitionWasm(rs_transition)) } #[wasm_bindgen(js_name = "toStateTransition")] - pub fn to_state_transition(&self) -> StateTransitionWASM { - StateTransitionWASM::from(StateTransition::from(self.0.clone())) + pub fn to_state_transition(&self) -> StateTransitionWasm { + StateTransitionWasm::from(StateTransition::from(self.0.clone())) } #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( - st: &StateTransitionWASM, - ) -> Result { + st: &StateTransitionWasm, + ) -> Result { let rs_st: StateTransition = st.clone().into(); match rs_st { StateTransition::IdentityCreditWithdrawal(st) => { - Ok(IdentityCreditWithdrawalTransitionWASM(st)) + Ok(IdentityCreditWithdrawalTransitionWasm(st)) } _ => Err(JsValue::from_str(&"Invalid state transition type)")), } diff --git a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs index e3fdb88010d..d31475ef5fd 100644 --- a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs @@ -1,5 +1,5 @@ -use crate::identifier::IdentifierWASM; -use crate::state_transition::StateTransitionWASM; +use crate::identifier::IdentifierWasm; +use crate::state_transition::StateTransitionWasm; use crate::utils::WithJsError; use dpp::platform_value::BinaryData; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; @@ -15,10 +15,10 @@ use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = IdentityCreditTransfer)] #[derive(Clone)] -pub struct IdentityCreditTransferWASM(IdentityCreditTransferTransition); +pub struct IdentityCreditTransferWasm(IdentityCreditTransferTransition); #[wasm_bindgen(js_class = IdentityCreditTransfer)] -impl IdentityCreditTransferWASM { +impl IdentityCreditTransferWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "IdentityCreditTransfer".to_string() @@ -36,12 +36,12 @@ impl IdentityCreditTransferWASM { js_recipient: &JsValue, nonce: u64, user_fee_increase: Option, - ) -> Result { - let sender: Identifier = IdentifierWASM::try_from(js_sender)?.into(); + ) -> Result { + let sender: Identifier = IdentifierWasm::try_from(js_sender)?.into(); - let recipient: Identifier = IdentifierWASM::try_from(js_recipient)?.into(); + let recipient: Identifier = IdentifierWasm::try_from(js_recipient)?.into(); - Ok(IdentityCreditTransferWASM( + Ok(IdentityCreditTransferWasm( IdentityCreditTransferTransition::V0(IdentityCreditTransferTransitionV0 { identity_id: sender, recipient_id: recipient, @@ -76,34 +76,34 @@ impl IdentityCreditTransferWASM { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { let rs_transition = IdentityCreditTransferTransition::deserialize_from_bytes(bytes.as_slice()) .with_js_error()?; - Ok(IdentityCreditTransferWASM(rs_transition)) + Ok(IdentityCreditTransferWasm(rs_transition)) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - IdentityCreditTransferWASM::from_bytes(decode(hex.as_str(), Hex).map_err(JsError::from)?) + pub fn from_hex(hex: String) -> Result { + IdentityCreditTransferWasm::from_bytes(decode(hex.as_str(), Hex).map_err(JsError::from)?) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(hex: String) -> Result { - IdentityCreditTransferWASM::from_bytes(decode(hex.as_str(), Base64).map_err(JsError::from)?) + pub fn from_base64(hex: String) -> Result { + IdentityCreditTransferWasm::from_bytes(decode(hex.as_str(), Base64).map_err(JsError::from)?) } #[wasm_bindgen(setter = "recipientId")] pub fn set_recipient_id(&mut self, js_recipient: &JsValue) -> Result<(), JsValue> { - let recipient: Identifier = IdentifierWASM::try_from(js_recipient)?.into(); + let recipient: Identifier = IdentifierWasm::try_from(js_recipient)?.into(); Ok(self.0.set_recipient_id(recipient)) } #[wasm_bindgen(setter = "senderId")] pub fn set_sender_id(&mut self, js_sender: &JsValue) -> Result<(), JsValue> { - let sender: Identifier = IdentifierWASM::try_from(js_sender)?.into(); + let sender: Identifier = IdentifierWasm::try_from(js_sender)?.into(); Ok(self.0.set_identity_id(sender)) } @@ -154,12 +154,12 @@ impl IdentityCreditTransferWASM { } #[wasm_bindgen(getter = "recipientId")] - pub fn get_recipient_id(&self) -> IdentifierWASM { + pub fn get_recipient_id(&self) -> IdentifierWasm { self.0.recipient_id().into() } #[wasm_bindgen(getter = "senderId")] - pub fn get_identity_id(&self) -> IdentifierWASM { + pub fn get_identity_id(&self) -> IdentifierWasm { self.0.identity_id().into() } @@ -174,24 +174,24 @@ impl IdentityCreditTransferWASM { } #[wasm_bindgen(js_name = "toStateTransition")] - pub fn to_state_transition(&self) -> StateTransitionWASM { - StateTransitionWASM::from(StateTransition::from(self.0.clone())) + pub fn to_state_transition(&self) -> StateTransitionWasm { + StateTransitionWasm::from(StateTransition::from(self.0.clone())) } #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( - st: &StateTransitionWASM, - ) -> Result { + st: &StateTransitionWasm, + ) -> Result { let rs_st: StateTransition = st.clone().into(); match rs_st { - StateTransition::IdentityCreditTransfer(st) => Ok(IdentityCreditTransferWASM(st)), + StateTransition::IdentityCreditTransfer(st) => Ok(IdentityCreditTransferWasm(st)), _ => Err(JsValue::from_str(&"Invalid state transition type)")), } } } -impl IdentityCreditTransferWASM { +impl IdentityCreditTransferWasm { pub fn set_signature_binary_data(&mut self, data: BinaryData) { self.0.set_signature(data) } diff --git a/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs b/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs index 706e41b7085..13c5a5d4160 100644 --- a/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs @@ -1,8 +1,8 @@ -use crate::contract_bounds::ContractBoundsWASM; -use crate::enums::keys::key_type::KeyTypeWASM; -use crate::enums::keys::purpose::PurposeWASM; -use crate::enums::keys::security_level::SecurityLevelWASM; -use crate::identity_public_key::IdentityPublicKeyWASM; +use crate::contract_bounds::ContractBoundsWasm; +use crate::enums::keys::key_type::KeyTypeWasm; +use crate::enums::keys::purpose::PurposeWasm; +use crate::enums::keys::security_level::SecurityLevelWasm; +use crate::identity_public_key::IdentityPublicKeyWasm; use crate::utils::{IntoWasm, WithJsError}; use dpp::identity::contract_bounds::ContractBounds; use dpp::identity::identity_public_key::v0::IdentityPublicKeyV0; @@ -19,32 +19,32 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] #[wasm_bindgen(js_name = "IdentityPublicKeyInCreation")] -pub struct IdentityPublicKeyInCreationWASM(IdentityPublicKeyInCreation); +pub struct IdentityPublicKeyInCreationWasm(IdentityPublicKeyInCreation); -impl From for IdentityPublicKeyInCreationWASM { +impl From for IdentityPublicKeyInCreationWasm { fn from(value: IdentityPublicKeyInCreation) -> Self { - IdentityPublicKeyInCreationWASM(value) + IdentityPublicKeyInCreationWasm(value) } } -impl From for IdentityPublicKeyInCreation { - fn from(value: IdentityPublicKeyInCreationWASM) -> Self { +impl From for IdentityPublicKeyInCreation { + fn from(value: IdentityPublicKeyInCreationWasm) -> Self { value.0 } } -impl TryFrom for IdentityPublicKeyInCreationWASM { +impl TryFrom for IdentityPublicKeyInCreationWasm { type Error = JsValue; fn try_from(value: JsValue) -> Result { let value = - value.to_wasm::("IdentityPublicKeyInCreation")?; + value.to_wasm::("IdentityPublicKeyInCreation")?; Ok(value.clone()) } } -impl From for IdentityPublicKey { - fn from(value: IdentityPublicKeyInCreationWASM) -> Self { +impl From for IdentityPublicKey { + fn from(value: IdentityPublicKeyInCreationWasm) -> Self { let contract_bounds = match value.0.contract_bounds() { None => None, Some(bounds) => Some(bounds.clone()), @@ -64,7 +64,7 @@ impl From for IdentityPublicKey { } #[wasm_bindgen(js_class = IdentityPublicKeyInCreation)] -impl IdentityPublicKeyInCreationWASM { +impl IdentityPublicKeyInCreationWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "IdentityPublicKeyInCreation".to_string() @@ -85,22 +85,22 @@ impl IdentityPublicKeyInCreationWASM { binary_data: Vec, signature: Option>, js_contract_bounds: &JsValue, - ) -> Result { - let purpose = PurposeWASM::try_from(js_purpose)?; - let security_level = SecurityLevelWASM::try_from(js_security_level)?; - let key_type = KeyTypeWASM::try_from(js_key_type)?; + ) -> Result { + let purpose = PurposeWasm::try_from(js_purpose)?; + let security_level = SecurityLevelWasm::try_from(js_security_level)?; + let key_type = KeyTypeWasm::try_from(js_key_type)?; let contract_bounds: Option = match js_contract_bounds.is_undefined() | js_contract_bounds.is_null() { true => None, false => Some( js_contract_bounds - .to_wasm::("ContractBounds")? + .to_wasm::("ContractBounds")? .clone() .into(), ), }; - Ok(IdentityPublicKeyInCreationWASM( + Ok(IdentityPublicKeyInCreationWasm( IdentityPublicKeyInCreation::V0(IdentityPublicKeyInCreationV0 { id, key_type: KeyType::from(key_type), @@ -115,12 +115,12 @@ impl IdentityPublicKeyInCreationWASM { } #[wasm_bindgen(js_name = toIdentityPublicKey)] - pub fn to_identity_public_key(&self) -> Result { - IdentityPublicKeyWASM::new( + pub fn to_identity_public_key(&self) -> Result { + IdentityPublicKeyWasm::new( self.0.id(), - JsValue::from(PurposeWASM::from(self.0.purpose())), - JsValue::from(SecurityLevelWASM::from(self.0.security_level())), - JsValue::from(KeyTypeWASM::from(self.0.key_type())), + JsValue::from(PurposeWasm::from(self.0.purpose())), + JsValue::from(SecurityLevelWasm::from(self.0.security_level())), + JsValue::from(KeyTypeWasm::from(self.0.key_type())), self.0.read_only(), self.0.data().to_string(Hex).as_str(), None, @@ -137,9 +137,9 @@ impl IdentityPublicKeyInCreationWASM { } #[wasm_bindgen(getter = "contractBounds")] - pub fn get_contract_bounds(&self) -> Option { + pub fn get_contract_bounds(&self) -> Option { match self.0.contract_bounds() { - Some(bounds) => Some(ContractBoundsWASM::from(bounds.clone())), + Some(bounds) => Some(ContractBoundsWasm::from(bounds.clone())), None => None, } } @@ -151,17 +151,17 @@ impl IdentityPublicKeyInCreationWASM { #[wasm_bindgen(getter = purpose)] pub fn get_purpose(&self) -> String { - PurposeWASM::from(self.0.purpose()).into() + PurposeWasm::from(self.0.purpose()).into() } #[wasm_bindgen(getter = securityLevel)] pub fn get_security_level(&self) -> String { - SecurityLevelWASM::from(self.0.security_level()).into() + SecurityLevelWasm::from(self.0.security_level()).into() } #[wasm_bindgen(getter = keyType)] pub fn get_key_type(&self) -> String { - KeyTypeWASM::from(self.0.key_type()).into() + KeyTypeWasm::from(self.0.key_type()).into() } #[wasm_bindgen(getter = readOnly)] @@ -186,13 +186,13 @@ impl IdentityPublicKeyInCreationWASM { #[wasm_bindgen(setter = purpose)] pub fn set_purpose(&mut self, js_purpose: JsValue) -> Result<(), JsValue> { - let purpose = PurposeWASM::try_from(js_purpose)?; + let purpose = PurposeWasm::try_from(js_purpose)?; Ok(self.0.set_purpose(Purpose::from(purpose))) } #[wasm_bindgen(setter = securityLevel)] pub fn set_security_level(&mut self, js_security_level: JsValue) -> Result<(), JsValue> { - let security_level = SecurityLevelWASM::try_from(js_security_level)?; + let security_level = SecurityLevelWasm::try_from(js_security_level)?; Ok(self .0 .set_security_level(SecurityLevel::from(security_level))) @@ -200,7 +200,7 @@ impl IdentityPublicKeyInCreationWASM { #[wasm_bindgen(setter = keyType)] pub fn set_key_type(&mut self, key_type: JsValue) -> Result<(), JsValue> { - let key_type = KeyTypeWASM::try_from(key_type)?; + let key_type = KeyTypeWasm::try_from(key_type)?; self.0.set_type(key_type.into()); Ok(()) } @@ -228,7 +228,7 @@ impl IdentityPublicKeyInCreationWASM { true => self.0.set_contract_bounds(None), false => { let bounds = js_bounds - .to_wasm::("ContractBounds")? + .to_wasm::("ContractBounds")? .clone(); self.0.set_contract_bounds(Some(bounds.into())) @@ -239,14 +239,14 @@ impl IdentityPublicKeyInCreationWASM { } } -impl IdentityPublicKeyInCreationWASM { +impl IdentityPublicKeyInCreationWasm { pub fn vec_from_js_value( js_add_public_keys: &js_sys::Array, - ) -> Result, JsValue> { - let add_public_keys: Vec = js_add_public_keys + ) -> Result, JsValue> { + let add_public_keys: Vec = js_add_public_keys .iter() - .map(|key| IdentityPublicKeyInCreationWASM::try_from(key)) - .collect::, JsValue>>()?; + .map(|key| IdentityPublicKeyInCreationWasm::try_from(key)) + .collect::, JsValue>>()?; Ok(add_public_keys) } diff --git a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs index 8636904506d..1b0cf542474 100644 --- a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs @@ -1,6 +1,6 @@ -use crate::asset_lock_proof::AssetLockProofWASM; -use crate::identifier::IdentifierWASM; -use crate::state_transition::StateTransitionWASM; +use crate::asset_lock_proof::AssetLockProofWasm; +use crate::identifier::IdentifierWasm; +use crate::state_transition::StateTransitionWasm; use crate::utils::WithJsError; use dpp::identifier::Identifier; use dpp::identity::state_transition::{AssetLockProved, OptionallyAssetLockProved}; @@ -17,10 +17,10 @@ use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "IdentityTopUpTransition")] #[derive(Clone)] -pub struct IdentityTopUpTransitionWASM(IdentityTopUpTransition); +pub struct IdentityTopUpTransitionWasm(IdentityTopUpTransition); #[wasm_bindgen(js_class = IdentityTopUpTransition)] -impl IdentityTopUpTransitionWASM { +impl IdentityTopUpTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "IdentityTopUpTransition".to_string() @@ -33,13 +33,13 @@ impl IdentityTopUpTransitionWASM { #[wasm_bindgen(constructor)] pub fn new( - asset_lock_proof: &AssetLockProofWASM, + asset_lock_proof: &AssetLockProofWasm, js_identity_id: JsValue, user_fee_increase: Option, - ) -> Result { - let identity_id: Identifier = IdentifierWASM::try_from(js_identity_id)?.into(); + ) -> Result { + let identity_id: Identifier = IdentifierWasm::try_from(js_identity_id)?.into(); - Ok(IdentityTopUpTransitionWASM(IdentityTopUpTransition::V0( + Ok(IdentityTopUpTransitionWasm(IdentityTopUpTransition::V0( IdentityTopUpTransitionV0 { asset_lock_proof: asset_lock_proof.clone().into(), identity_id, @@ -50,7 +50,7 @@ impl IdentityTopUpTransitionWASM { } #[wasm_bindgen(js_name = "getModifiedDataIds")] - pub fn get_modified_data_ids(&self) -> Vec { + pub fn get_modified_data_ids(&self) -> Vec { self.0 .modified_data_ids() .iter() @@ -61,7 +61,7 @@ impl IdentityTopUpTransitionWASM { #[wasm_bindgen(js_name = "getOptionalAssetLockProof")] pub fn get_optional_asset_lock_proof(&self) -> JsValue { match self.0.optional_asset_lock_proof() { - Some(asset_lock) => JsValue::from(AssetLockProofWASM::from(asset_lock.clone())), + Some(asset_lock) => JsValue::from(AssetLockProofWasm::from(asset_lock.clone())), None => JsValue::null(), } } @@ -72,12 +72,12 @@ impl IdentityTopUpTransitionWASM { } #[wasm_bindgen(getter = "identityIdentifier")] - pub fn get_identity_identifier(&self) -> IdentifierWASM { + pub fn get_identity_identifier(&self) -> IdentifierWasm { self.0.identity_id().clone().into() } #[wasm_bindgen(getter = "assetLockProof")] - pub fn get_asset_lock_proof(&self) -> AssetLockProofWASM { + pub fn get_asset_lock_proof(&self) -> AssetLockProofWasm { self.0.asset_lock_proof().clone().into() } @@ -92,14 +92,14 @@ impl IdentityTopUpTransitionWASM { js_identity_identifier: &JsValue, ) -> Result<(), JsValue> { let identity_identifier: Identifier = - IdentifierWASM::try_from(js_identity_identifier)?.into(); + IdentifierWasm::try_from(js_identity_identifier)?.into(); Ok(self.0.set_identity_id(identity_identifier.clone().into())) } #[wasm_bindgen(setter = "assetLockProof")] pub fn set_asset_lock_proof( &mut self, - asset_lock_proof: &AssetLockProofWASM, + asset_lock_proof: &AssetLockProofWasm, ) -> Result<(), JsValue> { self.0 .set_asset_lock_proof(asset_lock_proof.clone().into()) @@ -143,38 +143,38 @@ impl IdentityTopUpTransitionWASM { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { let rs_transition = IdentityTopUpTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; - Ok(IdentityTopUpTransitionWASM(rs_transition)) + Ok(IdentityTopUpTransitionWasm(rs_transition)) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - IdentityTopUpTransitionWASM::from_bytes(decode(hex.as_str(), Hex).map_err(JsError::from)?) + pub fn from_hex(hex: String) -> Result { + IdentityTopUpTransitionWasm::from_bytes(decode(hex.as_str(), Hex).map_err(JsError::from)?) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - IdentityTopUpTransitionWASM::from_bytes( + pub fn from_base64(base64: String) -> Result { + IdentityTopUpTransitionWasm::from_bytes( decode(base64.as_str(), Base64).map_err(JsError::from)?, ) } #[wasm_bindgen(js_name = "toStateTransition")] - pub fn to_state_transition(&self) -> StateTransitionWASM { - StateTransitionWASM::from(StateTransition::from(self.0.clone())) + pub fn to_state_transition(&self) -> StateTransitionWasm { + StateTransitionWasm::from(StateTransition::from(self.0.clone())) } #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( - st: &StateTransitionWASM, - ) -> Result { + st: &StateTransitionWasm, + ) -> Result { let rs_st: StateTransition = st.clone().into(); match rs_st { - StateTransition::IdentityTopUp(st) => Ok(IdentityTopUpTransitionWASM(st)), + StateTransition::IdentityTopUp(st) => Ok(IdentityTopUpTransitionWasm(st)), _ => Err(JsValue::from_str(&"Invalid state transition type)")), } } diff --git a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs index ac12b39056d..763f11341ea 100644 --- a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs @@ -1,8 +1,8 @@ -use crate::asset_lock_proof::AssetLockProofWASM; -use crate::enums::keys::purpose::PurposeWASM; -use crate::identifier::IdentifierWASM; -use crate::identity_transitions::public_key_in_creation::IdentityPublicKeyInCreationWASM; -use crate::state_transition::StateTransitionWASM; +use crate::asset_lock_proof::AssetLockProofWasm; +use crate::enums::keys::purpose::PurposeWasm; +use crate::identifier::IdentifierWasm; +use crate::identity_transitions::public_key_in_creation::IdentityPublicKeyInCreationWasm; +use crate::state_transition::StateTransitionWasm; use crate::utils::WithJsError; use dpp::identity::KeyID; use dpp::identity::state_transition::OptionallyAssetLockProved; @@ -20,10 +20,10 @@ use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "IdentityUpdateTransition")] #[derive(Clone)] -pub struct IdentityUpdateTransitionWASM(IdentityUpdateTransition); +pub struct IdentityUpdateTransitionWasm(IdentityUpdateTransition); #[wasm_bindgen(js_class = IdentityUpdateTransition)] -impl IdentityUpdateTransitionWASM { +impl IdentityUpdateTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "IdentityUpdateTransition".to_string() @@ -42,13 +42,13 @@ impl IdentityUpdateTransitionWASM { js_add_public_keys: &js_sys::Array, disable_public_keys: Vec, user_fee_increase: Option, - ) -> Result { - let identity_id = IdentifierWASM::try_from(js_identity_id)?; + ) -> Result { + let identity_id = IdentifierWasm::try_from(js_identity_id)?; - let add_public_keys: Vec = - IdentityPublicKeyInCreationWASM::vec_from_js_value(js_add_public_keys)?; + let add_public_keys: Vec = + IdentityPublicKeyInCreationWasm::vec_from_js_value(js_add_public_keys)?; - Ok(IdentityUpdateTransitionWASM(IdentityUpdateTransition::V0( + Ok(IdentityUpdateTransitionWasm(IdentityUpdateTransition::V0( IdentityUpdateTransitionV0 { identity_id: identity_id.into(), revision, @@ -77,7 +77,7 @@ impl IdentityUpdateTransitionWASM { } #[wasm_bindgen(getter = "identityIdentifier")] - pub fn get_identity_identifier(&self) -> IdentifierWASM { + pub fn get_identity_identifier(&self) -> IdentifierWasm { self.0.identity_id().into() } @@ -86,12 +86,12 @@ impl IdentityUpdateTransitionWASM { self.0 .purpose_requirement() .iter() - .map(|purpose| PurposeWASM::from(purpose.clone()).into()) + .map(|purpose| PurposeWasm::from(purpose.clone()).into()) .collect() } #[wasm_bindgen(js_name = "getModifiedDataIds")] - pub fn get_modified_data_ids(&self) -> Vec { + pub fn get_modified_data_ids(&self) -> Vec { self.0 .modified_data_ids() .iter() @@ -102,7 +102,7 @@ impl IdentityUpdateTransitionWASM { #[wasm_bindgen(js_name = "getOptionalAssetLockProof")] pub fn get_optional_asset_lock_proof(&self) -> JsValue { match self.0.optional_asset_lock_proof() { - Some(asset_lock) => JsValue::from(AssetLockProofWASM::from(asset_lock.clone())), + Some(asset_lock) => JsValue::from(AssetLockProofWasm::from(asset_lock.clone())), None => JsValue::null(), } } @@ -113,7 +113,7 @@ impl IdentityUpdateTransitionWASM { } #[wasm_bindgen(getter = "publicKeyIdsToAdd")] - pub fn get_public_key_ids_to_add(&self) -> Vec { + pub fn get_public_key_ids_to_add(&self) -> Vec { self.0 .public_keys_to_add() .to_vec() @@ -139,7 +139,7 @@ impl IdentityUpdateTransitionWASM { #[wasm_bindgen(setter = "identityIdentifier")] pub fn set_identity_identifier(&mut self, js_identity_id: &JsValue) -> Result<(), JsValue> { - let identity_id = IdentifierWASM::try_from(js_identity_id)?; + let identity_id = IdentifierWasm::try_from(js_identity_id)?; self.0.set_identity_id(identity_id.clone().into()); Ok(()) } @@ -149,8 +149,8 @@ impl IdentityUpdateTransitionWASM { &mut self, js_add_public_keys: &js_sys::Array, ) -> Result<(), JsValue> { - let add_public_keys: Vec = - IdentityPublicKeyInCreationWASM::vec_from_js_value(js_add_public_keys)?; + let add_public_keys: Vec = + IdentityPublicKeyInCreationWasm::vec_from_js_value(js_add_public_keys)?; let keys: Vec = add_public_keys.iter().map(|id| id.clone().into()).collect(); @@ -194,17 +194,17 @@ impl IdentityUpdateTransitionWASM { } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { + pub fn from_hex(hex: String) -> Result { let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; - IdentityUpdateTransitionWASM::from_bytes(bytes) + IdentityUpdateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { + pub fn from_base64(base64: String) -> Result { let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; - IdentityUpdateTransitionWASM::from_bytes(bytes) + IdentityUpdateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "bytes")] @@ -229,26 +229,26 @@ impl IdentityUpdateTransitionWASM { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { let rs_transition = IdentityUpdateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; - Ok(IdentityUpdateTransitionWASM(rs_transition)) + Ok(IdentityUpdateTransitionWasm(rs_transition)) } #[wasm_bindgen(js_name = "toStateTransition")] - pub fn to_state_transition(&self) -> StateTransitionWASM { - StateTransitionWASM::from(StateTransition::from(self.0.clone())) + pub fn to_state_transition(&self) -> StateTransitionWasm { + StateTransitionWasm::from(StateTransition::from(self.0.clone())) } #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( - st: &StateTransitionWASM, - ) -> Result { + st: &StateTransitionWasm, + ) -> Result { let rs_st: StateTransition = st.clone().into(); match rs_st { - StateTransition::IdentityUpdate(st) => Ok(IdentityUpdateTransitionWASM(st)), + StateTransition::IdentityUpdate(st) => Ok(IdentityUpdateTransitionWasm(st)), _ => Err(JsValue::from_str(&"Invalid state transition type)")), } } diff --git a/packages/wasm-dpp2/src/masternode_vote/mod.rs b/packages/wasm-dpp2/src/masternode_vote/mod.rs index e6057db8c2f..8206a38039d 100644 --- a/packages/wasm-dpp2/src/masternode_vote/mod.rs +++ b/packages/wasm-dpp2/src/masternode_vote/mod.rs @@ -2,10 +2,10 @@ pub mod resource_vote_choice; pub mod vote; pub mod vote_poll; -use crate::asset_lock_proof::AssetLockProofWASM; -use crate::identifier::IdentifierWASM; -use crate::masternode_vote::vote::VoteWASM; -use crate::state_transition::StateTransitionWASM; +use crate::asset_lock_proof::AssetLockProofWasm; +use crate::identifier::IdentifierWasm; +use crate::masternode_vote::vote::VoteWasm; +use crate::state_transition::StateTransitionWasm; use crate::utils::WithJsError; use dpp::identity::KeyID; use dpp::identity::state_transition::OptionallyAssetLockProved; @@ -23,22 +23,22 @@ use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "MasternodeVoteTransition")] #[derive(Clone)] -pub struct MasternodeVoteTransitionWASM(MasternodeVoteTransition); +pub struct MasternodeVoteTransitionWasm(MasternodeVoteTransition); -impl From for MasternodeVoteTransitionWASM { +impl From for MasternodeVoteTransitionWasm { fn from(val: MasternodeVoteTransition) -> Self { - MasternodeVoteTransitionWASM(val) + MasternodeVoteTransitionWasm(val) } } -impl From for MasternodeVoteTransition { - fn from(val: MasternodeVoteTransitionWASM) -> Self { +impl From for MasternodeVoteTransition { + fn from(val: MasternodeVoteTransitionWasm) -> Self { val.0 } } #[wasm_bindgen(js_class = MasternodeVoteTransition)] -impl MasternodeVoteTransitionWASM { +impl MasternodeVoteTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "MasternodeVoteTransition".to_string() @@ -53,15 +53,15 @@ impl MasternodeVoteTransitionWASM { pub fn new( js_pro_tx_hash: &JsValue, js_voter_identity_id: &JsValue, - vote: &VoteWASM, + vote: &VoteWasm, nonce: IdentityNonce, signature_public_key: Option, signature: Option>, - ) -> Result { - let pro_tx_hash = IdentifierWASM::try_from(js_pro_tx_hash)?; - let voter_identity_id = IdentifierWASM::try_from(js_voter_identity_id)?; + ) -> Result { + let pro_tx_hash = IdentifierWasm::try_from(js_pro_tx_hash)?; + let voter_identity_id = IdentifierWasm::try_from(js_voter_identity_id)?; - Ok(MasternodeVoteTransitionWASM(MasternodeVoteTransition::V0( + Ok(MasternodeVoteTransitionWasm(MasternodeVoteTransition::V0( MasternodeVoteTransitionV0 { pro_tx_hash: pro_tx_hash.into(), voter_identity_id: voter_identity_id.into(), @@ -74,17 +74,17 @@ impl MasternodeVoteTransitionWASM { } #[wasm_bindgen(getter = proTxHash)] - pub fn pro_tx_hash(&self) -> IdentifierWASM { + pub fn pro_tx_hash(&self) -> IdentifierWasm { self.0.pro_tx_hash().into() } #[wasm_bindgen(getter = voterIdentityId)] - pub fn voter_identity_id(&self) -> IdentifierWASM { + pub fn voter_identity_id(&self) -> IdentifierWasm { self.0.voter_identity_id().into() } #[wasm_bindgen(getter = vote)] - pub fn vote(&self) -> VoteWASM { + pub fn vote(&self) -> VoteWasm { self.0.vote().clone().into() } @@ -105,7 +105,7 @@ impl MasternodeVoteTransitionWASM { #[wasm_bindgen(setter = proTxHash)] pub fn set_pro_tx_hash(&mut self, js_pro_tx_hash: &JsValue) -> Result<(), JsValue> { - let pro_tx_hash = IdentifierWASM::try_from(js_pro_tx_hash)?; + let pro_tx_hash = IdentifierWasm::try_from(js_pro_tx_hash)?; self.0.set_pro_tx_hash(pro_tx_hash.into()); @@ -114,7 +114,7 @@ impl MasternodeVoteTransitionWASM { #[wasm_bindgen(setter = voterIdentityId)] pub fn set_voter_identity_id(&mut self, js_voter_identity_id: &JsValue) -> Result<(), JsValue> { - let voter_identity_id = IdentifierWASM::try_from(js_voter_identity_id)?; + let voter_identity_id = IdentifierWasm::try_from(js_voter_identity_id)?; self.0.set_voter_identity_id(voter_identity_id.into()); @@ -122,7 +122,7 @@ impl MasternodeVoteTransitionWASM { } #[wasm_bindgen(setter = vote)] - pub fn set_vote(&mut self, vote: &VoteWASM) { + pub fn set_vote(&mut self, vote: &VoteWasm) { self.0.set_vote(vote.clone().into()) } @@ -148,17 +148,17 @@ impl MasternodeVoteTransitionWASM { } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { + pub fn from_hex(hex: String) -> Result { let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; - MasternodeVoteTransitionWASM::from_bytes(bytes) + MasternodeVoteTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { + pub fn from_base64(base64: String) -> Result { let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; - MasternodeVoteTransitionWASM::from_bytes(bytes) + MasternodeVoteTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "bytes")] @@ -167,11 +167,11 @@ impl MasternodeVoteTransitionWASM { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { let rs_transition = MasternodeVoteTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; - Ok(MasternodeVoteTransitionWASM(rs_transition)) + Ok(MasternodeVoteTransitionWasm(rs_transition)) } #[wasm_bindgen(getter = "userFeeIncrease")] @@ -185,10 +185,10 @@ impl MasternodeVoteTransitionWASM { } #[wasm_bindgen(getter = "assetLock")] - pub fn get_asset_lock_proof(&self) -> Option { + pub fn get_asset_lock_proof(&self) -> Option { match self.0.optional_asset_lock_proof().clone() { None => None, - Some(asset_lock_proof) => Some(AssetLockProofWASM::from(asset_lock_proof.clone())), + Some(asset_lock_proof) => Some(AssetLockProofWasm::from(asset_lock_proof.clone())), } } @@ -198,7 +198,7 @@ impl MasternodeVoteTransitionWASM { } #[wasm_bindgen(getter = "modifiedDataIds")] - pub fn get_modified_data_ids(&self) -> Vec { + pub fn get_modified_data_ids(&self) -> Vec { self.0 .modified_data_ids() .iter() @@ -207,18 +207,18 @@ impl MasternodeVoteTransitionWASM { } #[wasm_bindgen(js_name = "toStateTransition")] - pub fn to_state_transition(&self) -> StateTransitionWASM { - StateTransitionWASM::from(StateTransition::MasternodeVote(self.clone().0)) + pub fn to_state_transition(&self) -> StateTransitionWasm { + StateTransitionWasm::from(StateTransition::MasternodeVote(self.clone().0)) } #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( - st: &StateTransitionWASM, - ) -> Result { + st: &StateTransitionWasm, + ) -> Result { let rs_st: StateTransition = st.clone().into(); match rs_st { - StateTransition::MasternodeVote(st) => Ok(MasternodeVoteTransitionWASM(st)), + StateTransition::MasternodeVote(st) => Ok(MasternodeVoteTransitionWasm(st)), _ => Err(JsValue::from_str( &"Invalid state document_transition type)", )), diff --git a/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs b/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs index bc5213bcaff..8f900569800 100644 --- a/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs +++ b/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs @@ -1,26 +1,26 @@ -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use dpp::voting::vote_choices::resource_vote_choice::ResourceVoteChoice; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] #[wasm_bindgen(js_name = ResourceVoteChoice)] -pub struct ResourceVoteChoiceWASM(ResourceVoteChoice); +pub struct ResourceVoteChoiceWasm(ResourceVoteChoice); -impl From for ResourceVoteChoiceWASM { +impl From for ResourceVoteChoiceWasm { fn from(choice: ResourceVoteChoice) -> Self { Self(choice) } } -impl From for ResourceVoteChoice { - fn from(choice: ResourceVoteChoiceWASM) -> Self { +impl From for ResourceVoteChoice { + fn from(choice: ResourceVoteChoiceWasm) -> Self { choice.0 } } #[wasm_bindgen(js_class = ResourceVoteChoice)] -impl ResourceVoteChoiceWASM { +impl ResourceVoteChoiceWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "ResourceVoteChoice".to_string() @@ -33,27 +33,27 @@ impl ResourceVoteChoiceWASM { #[wasm_bindgen(js_name = "TowardsIdentity")] pub fn towards_identity(js_id: &JsValue) -> Result { - let id = IdentifierWASM::try_from(js_id)?; + let id = IdentifierWasm::try_from(js_id)?; - Ok(ResourceVoteChoiceWASM(ResourceVoteChoice::TowardsIdentity( + Ok(ResourceVoteChoiceWasm(ResourceVoteChoice::TowardsIdentity( id.into(), ))) } #[wasm_bindgen(js_name = "Abstain")] pub fn abstain() -> Self { - ResourceVoteChoiceWASM(ResourceVoteChoice::Abstain) + ResourceVoteChoiceWasm(ResourceVoteChoice::Abstain) } #[wasm_bindgen(js_name = "Lock")] pub fn lock() -> Self { - ResourceVoteChoiceWASM(ResourceVoteChoice::Lock) + ResourceVoteChoiceWasm(ResourceVoteChoice::Lock) } #[wasm_bindgen(js_name = "getValue")] pub fn get_value(&self) -> JsValue { match self.0.clone() { - ResourceVoteChoice::TowardsIdentity(id) => JsValue::from(IdentifierWASM::from(id)), + ResourceVoteChoice::TowardsIdentity(id) => JsValue::from(IdentifierWasm::from(id)), ResourceVoteChoice::Abstain => JsValue::undefined(), ResourceVoteChoice::Lock => JsValue::undefined(), } diff --git a/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs b/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs index b548a5f344b..a86b48e0bf7 100644 --- a/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs +++ b/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs @@ -1,5 +1,5 @@ -use crate::masternode_vote::resource_vote_choice::ResourceVoteChoiceWASM; -use crate::masternode_vote::vote_poll::VotePollWASM; +use crate::masternode_vote::resource_vote_choice::ResourceVoteChoiceWasm; +use crate::masternode_vote::vote_poll::VotePollWasm; use dpp::voting::votes::Vote; use dpp::voting::votes::resource_vote::ResourceVote; use dpp::voting::votes::resource_vote::accessors::v0::ResourceVoteGettersV0; @@ -8,22 +8,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] #[wasm_bindgen(js_name=Vote)] -pub struct VoteWASM(Vote); +pub struct VoteWasm(Vote); -impl From for VoteWASM { +impl From for VoteWasm { fn from(vote: Vote) -> Self { Self(vote) } } -impl From for Vote { - fn from(vote: VoteWASM) -> Self { +impl From for Vote { + fn from(vote: VoteWasm) -> Self { vote.0 } } #[wasm_bindgen(js_class = Vote)] -impl VoteWASM { +impl VoteWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "Vote".to_string() @@ -35,29 +35,29 @@ impl VoteWASM { } #[wasm_bindgen(constructor)] - pub fn new(vote_poll: &VotePollWASM, resource_vote_choice: &ResourceVoteChoiceWASM) -> Self { - VoteWASM(Vote::ResourceVote(ResourceVote::V0(ResourceVoteV0 { + pub fn new(vote_poll: &VotePollWasm, resource_vote_choice: &ResourceVoteChoiceWasm) -> Self { + VoteWasm(Vote::ResourceVote(ResourceVote::V0(ResourceVoteV0 { vote_poll: vote_poll.clone().into(), resource_vote_choice: resource_vote_choice.clone().into(), }))) } #[wasm_bindgen(getter = votePoll)] - pub fn vote_poll(&self) -> VotePollWASM { + pub fn vote_poll(&self) -> VotePollWasm { match self.0.clone() { Vote::ResourceVote(vote) => vote.vote_poll().clone().into(), } } #[wasm_bindgen(getter = resourceVoteChoice)] - pub fn resource_vote_choice(&self) -> ResourceVoteChoiceWASM { + pub fn resource_vote_choice(&self) -> ResourceVoteChoiceWasm { match self.0.clone() { Vote::ResourceVote(vote) => vote.resource_vote_choice().clone().into(), } } #[wasm_bindgen(setter = votePoll)] - pub fn set_vote_poll(&mut self, vote_poll: &VotePollWASM) { + pub fn set_vote_poll(&mut self, vote_poll: &VotePollWasm) { self.0 = match self.0.clone() { Vote::ResourceVote(vote) => Vote::ResourceVote(ResourceVote::V0(ResourceVoteV0 { vote_poll: vote_poll.clone().into(), @@ -67,7 +67,7 @@ impl VoteWASM { } #[wasm_bindgen(setter = resourceVoteChoice)] - pub fn set_resource_vote_choice(&mut self, resource_vote_choice: &ResourceVoteChoiceWASM) { + pub fn set_resource_vote_choice(&mut self, resource_vote_choice: &ResourceVoteChoiceWasm) { self.0 = match self.0.clone() { Vote::ResourceVote(vote) => Vote::ResourceVote(ResourceVote::V0(ResourceVoteV0 { vote_poll: vote.vote_poll().clone(), diff --git a/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs b/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs index 86b2b8db037..1911a4b18c3 100644 --- a/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs +++ b/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs @@ -1,4 +1,4 @@ -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use crate::utils::ToSerdeJSONExt; use dpp::bincode; use dpp::voting::vote_polls::VotePoll; @@ -9,22 +9,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] #[wasm_bindgen(js_name = VotePoll)] -pub struct VotePollWASM(VotePoll); +pub struct VotePollWasm(VotePoll); -impl From for VotePollWASM { +impl From for VotePollWasm { fn from(poll: VotePoll) -> Self { - VotePollWASM(poll) + VotePollWasm(poll) } } -impl From for VotePoll { - fn from(poll: VotePollWASM) -> Self { +impl From for VotePoll { + fn from(poll: VotePollWasm) -> Self { poll.0 } } #[wasm_bindgen(js_class = VotePoll)] -impl VotePollWASM { +impl VotePollWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "VotePoll".to_string() @@ -41,8 +41,8 @@ impl VotePollWASM { document_type_name: String, index_name: String, js_index_values: JsValue, - ) -> Result { - let contract_id = IdentifierWASM::try_from(js_contract_id)?; + ) -> Result { + let contract_id = IdentifierWasm::try_from(js_contract_id)?; let index_values = js_index_values .with_serde_to_platform_value()? @@ -50,7 +50,7 @@ impl VotePollWASM { .unwrap() .clone(); - Ok(VotePollWASM(VotePoll::ContestedDocumentResourceVotePoll( + Ok(VotePollWasm(VotePoll::ContestedDocumentResourceVotePoll( ContestedDocumentResourceVotePoll { contract_id: contract_id.into(), document_type_name, @@ -66,7 +66,7 @@ impl VotePollWASM { } #[wasm_bindgen(getter = "contractId")] - pub fn contract_id(&self) -> IdentifierWASM { + pub fn contract_id(&self) -> IdentifierWasm { match self.0.clone() { VotePoll::ContestedDocumentResourceVotePoll(poll) => poll.contract_id.into(), } @@ -116,7 +116,7 @@ impl VotePollWASM { #[wasm_bindgen(setter = "contractId")] pub fn set_contract_id(&mut self, js_contract_id: &JsValue) -> Result<(), JsValue> { - let contract_id = IdentifierWASM::try_from(js_contract_id)?; + let contract_id = IdentifierWasm::try_from(js_contract_id)?; self.0 = match self.0.clone() { VotePoll::ContestedDocumentResourceVotePoll(mut poll) => { diff --git a/packages/wasm-dpp2/src/partial_identity/mod.rs b/packages/wasm-dpp2/src/partial_identity/mod.rs index a88ed822086..586c30a8e34 100644 --- a/packages/wasm-dpp2/src/partial_identity/mod.rs +++ b/packages/wasm-dpp2/src/partial_identity/mod.rs @@ -1,5 +1,5 @@ -use crate::identifier::IdentifierWASM; -use crate::identity_public_key::IdentityPublicKeyWASM; +use crate::identifier::IdentifierWasm; +use crate::identity_public_key::IdentityPublicKeyWasm; use crate::utils::IntoWasm; use dpp::fee::Credits; use dpp::identity::{IdentityPublicKey, KeyID, PartialIdentity}; @@ -11,16 +11,16 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] #[wasm_bindgen(js_name = "PartialIdentity")] -pub struct PartialIdentityWASM(PartialIdentity); +pub struct PartialIdentityWasm(PartialIdentity); -impl From for PartialIdentityWASM { +impl From for PartialIdentityWasm { fn from(value: PartialIdentity) -> Self { Self(value) } } #[wasm_bindgen(js_class = PartialIdentity)] -impl PartialIdentityWASM { +impl PartialIdentityWasm { #[wasm_bindgen(constructor)] pub fn new( js_id: &JsValue, @@ -29,13 +29,13 @@ impl PartialIdentityWASM { revision: Option, js_not_found_public_keys: Option, ) -> Result { - let id = IdentifierWASM::try_from(js_id)?; + let id = IdentifierWasm::try_from(js_id)?; let loaded_public_keys = js_value_to_loaded_public_keys(js_loaded_public_keys)?; let not_found_public_keys: BTreeSet = option_array_to_not_found(js_not_found_public_keys)?; - Ok(PartialIdentityWASM(PartialIdentity { + Ok(PartialIdentityWasm(PartialIdentity { id: id.into(), loaded_public_keys, balance, @@ -45,7 +45,7 @@ impl PartialIdentityWASM { } #[wasm_bindgen(getter = "id")] - pub fn id(&self) -> IdentifierWASM { + pub fn id(&self) -> IdentifierWasm { self.0.id.into() } @@ -57,7 +57,7 @@ impl PartialIdentityWASM { Reflect::set( &obj, &k.to_string().into(), - &IdentityPublicKeyWASM::from(v).into(), + &IdentityPublicKeyWasm::from(v).into(), )?; } @@ -87,7 +87,7 @@ impl PartialIdentityWASM { #[wasm_bindgen(setter = "id")] pub fn set_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { - let identifier: IdentifierWASM = IdentifierWASM::try_from(js_id)?; + let identifier: IdentifierWasm = IdentifierWasm::try_from(js_id)?; self.0.id = identifier.into(); @@ -143,7 +143,7 @@ pub fn js_value_to_loaded_public_keys( let js_key = Reflect::get(&pub_keys_object, &key)?; let key = js_key - .to_wasm::("IdentityPublicKey")? + .to_wasm::("IdentityPublicKey")? .clone(); map.insert(key_id, IdentityPublicKey::from(key)); diff --git a/packages/wasm-dpp2/src/private_key/mod.rs b/packages/wasm-dpp2/src/private_key/mod.rs index bcac2d7561c..0d6c5344210 100644 --- a/packages/wasm-dpp2/src/private_key/mod.rs +++ b/packages/wasm-dpp2/src/private_key/mod.rs @@ -1,5 +1,5 @@ -use crate::enums::network::NetworkWASM; -use crate::public_key::PublicKeyWASM; +use crate::enums::network::NetworkWasm; +use crate::public_key::PublicKeyWasm; use dpp::dashcore::PrivateKey; use dpp::dashcore::hashes::hex::FromHex; use dpp::dashcore::key::Secp256k1; @@ -8,10 +8,10 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "PrivateKey")] -pub struct PrivateKeyWASM(PrivateKey); +pub struct PrivateKeyWasm(PrivateKey); #[wasm_bindgen(js_class = PrivateKey)] -impl PrivateKeyWASM { +impl PrivateKeyWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "PrivateKey".to_string() @@ -27,35 +27,35 @@ impl PrivateKeyWASM { let pk = PrivateKey::from_wif(wif).map_err(|err| JsValue::from_str(&*err.to_string())); match pk { - Ok(pk) => Ok(PrivateKeyWASM(pk)), + Ok(pk) => Ok(PrivateKeyWasm(pk)), Err(err) => Err(err), } } #[wasm_bindgen(js_name = "fromBytes")] pub fn from_bytes(bytes: Vec, js_network: JsValue) -> Result { - let network = NetworkWASM::try_from(js_network)?; + let network = NetworkWasm::try_from(js_network)?; let pk = PrivateKey::from_slice(bytes.as_slice(), network.into()) .map_err(|err| JsValue::from_str(&*err.to_string()))?; - Ok(PrivateKeyWASM(pk)) + Ok(PrivateKeyWasm(pk)) } #[wasm_bindgen(js_name = "fromHex")] pub fn from_hex(hex_key: &str, js_network: JsValue) -> Result { - let network = NetworkWASM::try_from(js_network)?; + let network = NetworkWasm::try_from(js_network)?; let bytes = Vec::from_hex(hex_key).map_err(|err| JsValue::from(err.to_string()))?; let pk = PrivateKey::from_slice(bytes.as_slice(), network.into()) .map_err(|err| JsValue::from_str(&*err.to_string()))?; - Ok(PrivateKeyWASM(pk)) + Ok(PrivateKeyWasm(pk)) } #[wasm_bindgen(js_name = "getPublicKey")] - pub fn get_public_key(&self) -> PublicKeyWASM { + pub fn get_public_key(&self) -> PublicKeyWasm { let secp = Secp256k1::new(); let public_key = self.0.public_key(&secp); @@ -65,7 +65,7 @@ impl PrivateKeyWASM { } #[wasm_bindgen(js_class = PrivateKey)] -impl PrivateKeyWASM { +impl PrivateKeyWasm { #[wasm_bindgen(js_name = "WIF")] pub fn get_wif(&self) -> String { self.0.to_wif() diff --git a/packages/wasm-dpp2/src/public_key/mod.rs b/packages/wasm-dpp2/src/public_key/mod.rs index 763677d9ff6..b745a5e8f39 100644 --- a/packages/wasm-dpp2/src/public_key/mod.rs +++ b/packages/wasm-dpp2/src/public_key/mod.rs @@ -4,22 +4,22 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "PublicKey")] -pub struct PublicKeyWASM(PublicKey); +pub struct PublicKeyWasm(PublicKey); -impl From for PublicKeyWASM { +impl From for PublicKeyWasm { fn from(pk: PublicKey) -> Self { Self(pk) } } -impl From for PublicKey { - fn from(pk: PublicKeyWASM) -> Self { +impl From for PublicKey { + fn from(pk: PublicKeyWasm) -> Self { pk.0 } } #[wasm_bindgen(js_class = PublicKey)] -impl PublicKeyWASM { +impl PublicKeyWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "PublicKey".to_string() @@ -31,7 +31,7 @@ impl PublicKeyWASM { } #[wasm_bindgen(constructor)] - pub fn new(compressed: bool, public_key_bytes: Vec) -> Result { + pub fn new(compressed: bool, public_key_bytes: Vec) -> Result { let inner = match compressed { true => { if public_key_bytes.len() != constants::PUBLIC_KEY_SIZE { @@ -56,7 +56,7 @@ impl PublicKeyWASM { } .map_err(|err| JsValue::from(err.to_string()))?; - Ok(PublicKeyWASM(PublicKey { compressed, inner })) + Ok(PublicKeyWasm(PublicKey { compressed, inner })) } #[wasm_bindgen(getter = "compressed")] @@ -114,8 +114,8 @@ impl PublicKeyWASM { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { - Ok(PublicKeyWASM( + pub fn from_bytes(bytes: Vec) -> Result { + Ok(PublicKeyWasm( PublicKey::from_slice(bytes.as_slice()) .map_err(|err| JsValue::from(err.to_string()))?, )) diff --git a/packages/wasm-dpp2/src/state_transition/mod.rs b/packages/wasm-dpp2/src/state_transition/mod.rs index 57b67cab504..0ff37c58bbe 100644 --- a/packages/wasm-dpp2/src/state_transition/mod.rs +++ b/packages/wasm-dpp2/src/state_transition/mod.rs @@ -1,10 +1,10 @@ -use crate::enums::keys::key_type::KeyTypeWASM; -use crate::enums::keys::purpose::PurposeWASM; -use crate::enums::keys::security_level::SecurityLevelWASM; -use crate::identifier::IdentifierWASM; -use crate::identity_public_key::IdentityPublicKeyWASM; +use crate::enums::keys::key_type::KeyTypeWasm; +use crate::enums::keys::purpose::PurposeWasm; +use crate::enums::keys::security_level::SecurityLevelWasm; +use crate::identifier::IdentifierWasm; +use crate::identity_public_key::IdentityPublicKeyWasm; use crate::mock_bls::MockBLS; -use crate::private_key::PrivateKeyWASM; +use crate::private_key::PrivateKeyWasm; use crate::utils::WithJsError; use dpp::dashcore::secp256k1::hashes::hex::Case::Lower; use dpp::dashcore::secp256k1::hashes::hex::DisplayHex; @@ -42,22 +42,22 @@ use wasm_bindgen::{JsError, JsValue}; #[derive(Clone)] #[wasm_bindgen(js_name = "StateTransition")] -pub struct StateTransitionWASM(StateTransition); +pub struct StateTransitionWasm(StateTransition); -impl From for StateTransitionWASM { +impl From for StateTransitionWasm { fn from(transition: StateTransition) -> Self { - StateTransitionWASM(transition) + StateTransitionWasm(transition) } } -impl From for StateTransition { - fn from(transition: StateTransitionWASM) -> Self { +impl From for StateTransition { + fn from(transition: StateTransitionWasm) -> Self { transition.0 } } #[wasm_bindgen(js_class = StateTransition)] -impl StateTransitionWASM { +impl StateTransitionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "StateTransition".to_string() @@ -71,8 +71,8 @@ impl StateTransitionWASM { #[wasm_bindgen(js_name = "sign")] pub fn sign( &mut self, - private_key: &PrivateKeyWASM, - public_key: &IdentityPublicKeyWASM, + private_key: &PrivateKeyWasm, + public_key: &IdentityPublicKeyWasm, ) -> Result, JsValue> { self.0 .sign( @@ -92,13 +92,13 @@ impl StateTransitionWASM { #[wasm_bindgen(js_name = "signByPrivateKey")] pub fn sign_by_private_key( &mut self, - private_key: &PrivateKeyWASM, + private_key: &PrivateKeyWasm, key_id: Option, js_key_type: JsValue, ) -> Result, JsValue> { let key_type = match js_key_type.is_undefined() { - true => KeyTypeWASM::ECDSA_SECP256K1, - false => KeyTypeWASM::try_from(js_key_type)?, + true => KeyTypeWasm::ECDSA_SECP256K1, + false => KeyTypeWasm::try_from(js_key_type)?, }; let _sig = self @@ -120,7 +120,7 @@ impl StateTransitionWASM { #[wasm_bindgen(js_name = "verifyPublicKey")] pub fn verify_public_key( &self, - public_key: &IdentityPublicKeyWASM, + public_key: &IdentityPublicKeyWasm, js_allow_signing_with_any_security_level: Option, js_allow_signing_with_any_purpose: Option, ) -> Result<(), JsValue> { @@ -248,14 +248,14 @@ impl StateTransitionWASM { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> Result { let st = StateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; Ok(st.into()) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { + pub fn from_hex(hex: String) -> Result { let bytes = decode(&hex, Encoding::Hex).map_err(JsError::from)?; let st = StateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; @@ -264,7 +264,7 @@ impl StateTransitionWASM { } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { + pub fn from_base64(base64: String) -> Result { let bytes = decode(&base64, Encoding::Base64).map_err(JsError::from)?; let st = StateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; @@ -307,7 +307,7 @@ impl StateTransitionWASM { } #[wasm_bindgen(js_name = "getOwnerId")] - pub fn get_owner_id(&self) -> IdentifierWASM { + pub fn get_owner_id(&self) -> IdentifierWasm { self.0.owner_id().into() } @@ -334,7 +334,7 @@ impl StateTransitionWASM { None => None, Some(req) => Some( req.iter() - .map(|purpose| PurposeWASM::from(purpose.clone())) + .map(|purpose| PurposeWasm::from(purpose.clone())) .map(String::from) .collect(), ), @@ -346,7 +346,7 @@ impl StateTransitionWASM { &self, js_purpose: &JsValue, ) -> Result>, JsValue> { - let purpose = PurposeWASM::try_from(js_purpose.clone())?; + let purpose = PurposeWasm::try_from(js_purpose.clone())?; let requirements = self.0.security_level_requirement(purpose.into()); @@ -354,7 +354,7 @@ impl StateTransitionWASM { None => Ok(None), Some(req) => Ok(Some( req.iter() - .map(|security_level| SecurityLevelWASM::from(security_level.clone())) + .map(|security_level| SecurityLevelWasm::from(security_level.clone())) .map(String::from) .collect(), )), @@ -418,7 +418,7 @@ impl StateTransitionWASM { #[wasm_bindgen(js_name = "setOwnerId")] pub fn set_owner_id(&mut self, js_owner_id: &JsValue) -> Result<(), JsValue> { - let owner_id = IdentifierWASM::try_from(js_owner_id.clone())?; + let owner_id = IdentifierWasm::try_from(js_owner_id.clone())?; match self.0.clone() { DataContractCreate(mut contract_create) => { diff --git a/packages/wasm-dpp2/src/token_configuration/action_taker.rs b/packages/wasm-dpp2/src/token_configuration/action_taker.rs index f8ab6523b6c..e31594d4da6 100644 --- a/packages/wasm-dpp2/src/token_configuration/action_taker.rs +++ b/packages/wasm-dpp2/src/token_configuration/action_taker.rs @@ -1,4 +1,4 @@ -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use dpp::group::action_taker::ActionTaker; use dpp::prelude::Identifier; use js_sys::Array; @@ -8,22 +8,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "ActionTaker")] -pub struct ActionTakerWASM(ActionTaker); +pub struct ActionTakerWasm(ActionTaker); -impl From for ActionTakerWASM { +impl From for ActionTakerWasm { fn from(action_taker: ActionTaker) -> Self { - ActionTakerWASM(action_taker) + ActionTakerWasm(action_taker) } } -impl From for ActionTaker { - fn from(action_taker: ActionTakerWASM) -> Self { +impl From for ActionTaker { + fn from(action_taker: ActionTakerWasm) -> Self { action_taker.0 } } #[wasm_bindgen(js_class = ActionTaker)] -impl ActionTakerWASM { +impl ActionTakerWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "ActionTaker".to_string() @@ -35,23 +35,23 @@ impl ActionTakerWASM { } #[wasm_bindgen(constructor)] - pub fn new(value: &JsValue) -> Result { - let identifier = IdentifierWASM::try_from(value); + pub fn new(value: &JsValue) -> Result { + let identifier = IdentifierWasm::try_from(value); if identifier.is_err() { let set_of_identifiers: Vec = Array::from(value) .to_vec() .iter() .map(|js_value: &JsValue| { - Identifier::from(IdentifierWASM::try_from(js_value).expect("err")) + Identifier::from(IdentifierWasm::try_from(js_value).expect("err")) }) .collect(); - Ok(ActionTakerWASM(ActionTaker::SpecifiedIdentities( + Ok(ActionTakerWasm(ActionTaker::SpecifiedIdentities( BTreeSet::from_iter(set_of_identifiers), ))) } else { - Ok(ActionTakerWASM(ActionTaker::SingleIdentity( + Ok(ActionTakerWasm(ActionTaker::SingleIdentity( identifier?.into(), ))) } @@ -69,12 +69,12 @@ impl ActionTakerWASM { pub fn get_value(&self) -> JsValue { match &self.0 { ActionTaker::SingleIdentity(value) => { - JsValue::from(IdentifierWASM::from(value.clone())) + JsValue::from(IdentifierWasm::from(value.clone())) } ActionTaker::SpecifiedIdentities(value) => { - let identifiers: Vec = value + let identifiers: Vec = value .iter() - .map(|identifier: &Identifier| IdentifierWASM::from(identifier.clone())) + .map(|identifier: &Identifier| IdentifierWasm::from(identifier.clone())) .collect(); JsValue::from(identifiers) diff --git a/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs b/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs index 1c16513fc3e..559837f46d0 100644 --- a/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs +++ b/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs @@ -1,4 +1,4 @@ -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use dpp::data_contract::change_control_rules::authorized_action_takers::AuthorizedActionTakers; use dpp::platform_value::string_encoding::Encoding::Base58; use dpp::platform_value::string_encoding::encode; @@ -7,22 +7,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "AuthorizedActionTakers")] -pub struct AuthorizedActionTakersWASM(AuthorizedActionTakers); +pub struct AuthorizedActionTakersWasm(AuthorizedActionTakers); -impl From for AuthorizedActionTakersWASM { +impl From for AuthorizedActionTakersWasm { fn from(action: AuthorizedActionTakers) -> Self { - AuthorizedActionTakersWASM(action) + AuthorizedActionTakersWasm(action) } } -impl From for AuthorizedActionTakers { - fn from(action: AuthorizedActionTakersWASM) -> Self { +impl From for AuthorizedActionTakers { + fn from(action: AuthorizedActionTakersWasm) -> Self { action.0 } } #[wasm_bindgen(js_class = AuthorizedActionTakers)] -impl AuthorizedActionTakersWASM { +impl AuthorizedActionTakersWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "AuthorizedActionTakers".to_string() @@ -35,31 +35,31 @@ impl AuthorizedActionTakersWASM { #[wasm_bindgen(js_name = "NoOne")] pub fn no_one() -> Self { - AuthorizedActionTakersWASM(AuthorizedActionTakers::NoOne) + AuthorizedActionTakersWasm(AuthorizedActionTakers::NoOne) } #[wasm_bindgen(js_name = "ContractOwner")] pub fn contract_owner() -> Self { - AuthorizedActionTakersWASM(AuthorizedActionTakers::ContractOwner) + AuthorizedActionTakersWasm(AuthorizedActionTakers::ContractOwner) } #[wasm_bindgen(js_name = "Identity")] pub fn identity(js_identity_id: &JsValue) -> Result { - let identity_id = IdentifierWASM::try_from(js_identity_id)?; + let identity_id = IdentifierWasm::try_from(js_identity_id)?; - Ok(AuthorizedActionTakersWASM( + Ok(AuthorizedActionTakersWasm( AuthorizedActionTakers::Identity(identity_id.into()), )) } #[wasm_bindgen(js_name = "MainGroup")] pub fn main_group() -> Self { - AuthorizedActionTakersWASM(AuthorizedActionTakers::MainGroup) + AuthorizedActionTakersWasm(AuthorizedActionTakers::MainGroup) } #[wasm_bindgen(js_name = "Group")] pub fn group(group_contract_position: u16) -> Self { - AuthorizedActionTakersWASM(AuthorizedActionTakers::Group(group_contract_position)) + AuthorizedActionTakersWasm(AuthorizedActionTakers::Group(group_contract_position)) } #[wasm_bindgen(js_name = "getTakerType")] @@ -81,7 +81,7 @@ impl AuthorizedActionTakersWASM { AuthorizedActionTakers::NoOne => JsValue::undefined(), AuthorizedActionTakers::ContractOwner => JsValue::undefined(), AuthorizedActionTakers::Identity(identifier) => { - JsValue::from(IdentifierWASM::from(identifier)) + JsValue::from(IdentifierWasm::from(identifier)) } AuthorizedActionTakers::MainGroup => JsValue::undefined(), AuthorizedActionTakers::Group(position) => JsValue::from(position), diff --git a/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs b/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs index 1554e81defc..0e4156c12a9 100644 --- a/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs +++ b/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs @@ -1,8 +1,8 @@ -use crate::enums::token::action_goal::ActionGoalWASM; -use crate::identifier::IdentifierWASM; -use crate::token_configuration::action_taker::ActionTakerWASM; -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration::group::GroupWASM; +use crate::enums::token::action_goal::ActionGoalWasm; +use crate::identifier::IdentifierWasm; +use crate::token_configuration::action_taker::ActionTakerWasm; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration::group::GroupWasm; use crate::utils::IntoWasm; use dpp::data_contract::GroupContractPosition; use dpp::data_contract::change_control_rules::ChangeControlRules; @@ -15,22 +15,22 @@ use wasm_bindgen::{JsError, JsValue}; #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "ChangeControlRules")] -pub struct ChangeControlRulesWASM(ChangeControlRules); +pub struct ChangeControlRulesWasm(ChangeControlRules); -impl From for ChangeControlRulesWASM { +impl From for ChangeControlRulesWasm { fn from(value: ChangeControlRules) -> Self { Self(value) } } -impl From for ChangeControlRules { - fn from(value: ChangeControlRulesWASM) -> Self { +impl From for ChangeControlRules { + fn from(value: ChangeControlRulesWasm) -> Self { value.0 } } #[wasm_bindgen(js_class = ChangeControlRules)] -impl ChangeControlRulesWASM { +impl ChangeControlRulesWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "ChangeControlRules".to_string() @@ -43,13 +43,13 @@ impl ChangeControlRulesWASM { #[wasm_bindgen(constructor)] pub fn new( - authorized_to_make_change: &AuthorizedActionTakersWASM, - admin_action_takers: &AuthorizedActionTakersWASM, + authorized_to_make_change: &AuthorizedActionTakersWasm, + admin_action_takers: &AuthorizedActionTakersWasm, changing_authorized_action_takers_to_no_one_allowed: bool, changing_admin_action_takers_to_no_one_allowed: bool, self_changing_admin_action_takers_allowed: bool, ) -> Self { - ChangeControlRulesWASM(ChangeControlRules::V0(ChangeControlRulesV0 { + ChangeControlRulesWasm(ChangeControlRules::V0(ChangeControlRulesV0 { authorized_to_make_change: authorized_to_make_change.clone().into(), admin_action_takers: admin_action_takers.clone().into(), changing_authorized_action_takers_to_no_one_allowed, @@ -59,7 +59,7 @@ impl ChangeControlRulesWASM { } #[wasm_bindgen(getter = "authorizedToMakeChange")] - pub fn get_authorized_to_make_change(&self) -> AuthorizedActionTakersWASM { + pub fn get_authorized_to_make_change(&self) -> AuthorizedActionTakersWasm { self.0 .authorized_to_make_change_action_takers() .clone() @@ -67,7 +67,7 @@ impl ChangeControlRulesWASM { } #[wasm_bindgen(getter = "adminActionTakers")] - pub fn get_admin_action_takers(&self) -> AuthorizedActionTakersWASM { + pub fn get_admin_action_takers(&self) -> AuthorizedActionTakersWasm { self.0.admin_action_takers().clone().into() } @@ -95,14 +95,14 @@ impl ChangeControlRulesWASM { #[wasm_bindgen(setter = "authorizedToMakeChange")] pub fn set_authorized_to_make_change( &mut self, - authorized_to_make_change: &AuthorizedActionTakersWASM, + authorized_to_make_change: &AuthorizedActionTakersWasm, ) { self.0 .set_authorized_to_make_change_action_takers(authorized_to_make_change.clone().into()); } #[wasm_bindgen(setter = "adminActionTakers")] - pub fn set_admin_action_takers(&mut self, admin_action_takers: &AuthorizedActionTakersWASM) { + pub fn set_admin_action_takers(&mut self, admin_action_takers: &AuthorizedActionTakersWasm) { self.0 .set_admin_action_takers(admin_action_takers.clone().into()); } @@ -158,15 +158,15 @@ impl ChangeControlRulesWASM { #[wasm_bindgen(js_name = "canChangeAdminActionTakers")] pub fn can_change_admin_action_takers( &self, - admin_action_takers: &AuthorizedActionTakersWASM, + admin_action_takers: &AuthorizedActionTakersWasm, js_contract_owner_id: &JsValue, main_group: Option, js_groups: &JsValue, - action_taker: &ActionTakerWASM, + action_taker: &ActionTakerWasm, js_goal: &JsValue, ) -> Result { - let contract_owner_id = IdentifierWASM::try_from(js_contract_owner_id)?; - let goal = ActionGoalWASM::try_from(js_goal.clone())?; + let contract_owner_id = IdentifierWasm::try_from(js_contract_owner_id)?; + let goal = ActionGoalWasm::try_from(js_goal.clone())?; let groups_object = Object::from(js_groups.clone()); let groups_keys = Object::keys(&groups_object); @@ -183,7 +183,7 @@ impl ChangeControlRulesWASM { let group_value = Reflect::get(js_groups, &key)?; - let group = group_value.to_wasm::("Group")?.clone(); + let group = group_value.to_wasm::("Group")?.clone(); groups.insert(contract_position, group.into()); } diff --git a/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs b/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs index 6aa1e950232..099bbe8163f 100644 --- a/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs +++ b/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs @@ -1,4 +1,4 @@ -use crate::token_configuration::localization::TokenConfigurationLocalizationWASM; +use crate::token_configuration::localization::TokenConfigurationLocalizationWasm; use crate::utils::ToSerdeJSONExt; use dpp::data_contract::associated_token::token_configuration_convention::TokenConfigurationConvention; use dpp::data_contract::associated_token::token_configuration_convention::accessors::v0::{ @@ -14,22 +14,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name = "TokenConfigurationConvention")] -pub struct TokenConfigurationConventionWASM(TokenConfigurationConvention); +pub struct TokenConfigurationConventionWasm(TokenConfigurationConvention); -impl From for TokenConfigurationConventionWASM { +impl From for TokenConfigurationConventionWasm { fn from(convention: TokenConfigurationConvention) -> Self { - TokenConfigurationConventionWASM(convention) + TokenConfigurationConventionWasm(convention) } } -impl From for TokenConfigurationConvention { - fn from(convention: TokenConfigurationConventionWASM) -> Self { +impl From for TokenConfigurationConvention { + fn from(convention: TokenConfigurationConventionWasm) -> Self { convention.0 } } #[wasm_bindgen(js_class = TokenConfigurationConvention)] -impl TokenConfigurationConventionWASM { +impl TokenConfigurationConventionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenConfigurationConvention".to_string() @@ -44,11 +44,11 @@ impl TokenConfigurationConventionWASM { pub fn new( js_localizations: &JsValue, decimals: u8, - ) -> Result { + ) -> Result { let localizations: BTreeMap = js_value_to_localizations(js_localizations)?; - Ok(TokenConfigurationConventionWASM( + Ok(TokenConfigurationConventionWasm( TokenConfigurationConvention::V0(TokenConfigurationConventionV0 { localizations, decimals, @@ -69,7 +69,7 @@ impl TokenConfigurationConventionWASM { Reflect::set( &object, &JsValue::from(key.clone()), - &TokenConfigurationLocalizationWASM::from(value.clone()).into(), + &TokenConfigurationLocalizationWasm::from(value.clone()).into(), )?; } diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_function.rs b/packages/wasm-dpp2/src/token_configuration/distribution_function.rs index 5677b04b553..94f81485c11 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_function.rs +++ b/packages/wasm-dpp2/src/token_configuration/distribution_function.rs @@ -1,7 +1,7 @@ use crate::token_configuration::distribution_structs::{ - DistributionExponentialWASM, DistributionFixedAmountWASM, DistributionInvertedLogarithmicWASM, - DistributionLinearWASM, DistributionLogarithmicWASM, DistributionPolynomialWASM, - DistributionRandomWASM, DistributionStepDecreasingAmountWASM, + DistributionExponentialWasm, DistributionFixedAmountWasm, DistributionInvertedLogarithmicWasm, + DistributionLinearWasm, DistributionLogarithmicWasm, DistributionPolynomialWasm, + DistributionRandomWasm, DistributionStepDecreasingAmountWasm, }; use crate::utils::try_to_u64; use dpp::balances::credits::TokenAmount; @@ -14,22 +14,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "DistributionFunction")] -pub struct DistributionFunctionWASM(DistributionFunction); +pub struct DistributionFunctionWasm(DistributionFunction); -impl From for DistributionFunction { - fn from(function: DistributionFunctionWASM) -> Self { +impl From for DistributionFunction { + fn from(function: DistributionFunctionWasm) -> Self { function.0 } } -impl From for DistributionFunctionWASM { +impl From for DistributionFunctionWasm { fn from(function: DistributionFunction) -> Self { Self(function) } } #[wasm_bindgen(js_class = DistributionFunction)] -impl DistributionFunctionWASM { +impl DistributionFunctionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "DistributionFunction".to_string() @@ -41,13 +41,13 @@ impl DistributionFunctionWASM { } #[wasm_bindgen(js_name = "FixedAmountDistribution")] - pub fn fixed_amount_distribution(amount: TokenAmount) -> DistributionFunctionWASM { - DistributionFunctionWASM(DistributionFunction::FixedAmount { amount }) + pub fn fixed_amount_distribution(amount: TokenAmount) -> DistributionFunctionWasm { + DistributionFunctionWasm(DistributionFunction::FixedAmount { amount }) } #[wasm_bindgen(js_name = "Random")] pub fn random(min: TokenAmount, max: TokenAmount) -> Self { - DistributionFunctionWASM(DistributionFunction::Random { min, max }) + DistributionFunctionWasm(DistributionFunction::Random { min, max }) } #[wasm_bindgen(js_name = "StepDecreasingAmount")] @@ -61,7 +61,7 @@ impl DistributionFunctionWASM { trailing_distribution_interval_amount: TokenAmount, min_value: Option, ) -> Self { - DistributionFunctionWASM(DistributionFunction::StepDecreasingAmount { + DistributionFunctionWasm(DistributionFunction::StepDecreasingAmount { step_count, decrease_per_interval_numerator, decrease_per_interval_denominator, @@ -74,7 +74,7 @@ impl DistributionFunctionWASM { } #[wasm_bindgen(js_name = "Stepwise")] - pub fn stepwise(js_steps_with_amount: JsValue) -> Result { + pub fn stepwise(js_steps_with_amount: JsValue) -> Result { let obj = Object::from(js_steps_with_amount); let mut steps_with_amount: BTreeMap = BTreeMap::new(); @@ -88,7 +88,7 @@ impl DistributionFunctionWASM { ); } - Ok(DistributionFunctionWASM(DistributionFunction::Stepwise( + Ok(DistributionFunctionWasm(DistributionFunction::Stepwise( steps_with_amount, ))) } @@ -101,8 +101,8 @@ impl DistributionFunctionWASM { starting_amount: TokenAmount, min_value: Option, max_value: Option, - ) -> DistributionFunctionWASM { - DistributionFunctionWASM(DistributionFunction::Linear { + ) -> DistributionFunctionWasm { + DistributionFunctionWasm(DistributionFunction::Linear { a, d, start_step, @@ -123,8 +123,8 @@ impl DistributionFunctionWASM { b: TokenAmount, min_value: Option, max_value: Option, - ) -> DistributionFunctionWASM { - DistributionFunctionWASM(DistributionFunction::Polynomial { + ) -> DistributionFunctionWasm { + DistributionFunctionWasm(DistributionFunction::Polynomial { a, d, m, @@ -148,8 +148,8 @@ impl DistributionFunctionWASM { b: TokenAmount, min_value: Option, max_value: Option, - ) -> DistributionFunctionWASM { - DistributionFunctionWASM(DistributionFunction::Exponential { + ) -> DistributionFunctionWasm { + DistributionFunctionWasm(DistributionFunction::Exponential { a, d, m, @@ -173,8 +173,8 @@ impl DistributionFunctionWASM { b: TokenAmount, min_value: Option, max_value: Option, - ) -> DistributionFunctionWASM { - DistributionFunctionWASM(DistributionFunction::Logarithmic { + ) -> DistributionFunctionWasm { + DistributionFunctionWasm(DistributionFunction::Logarithmic { a, d, m, @@ -198,8 +198,8 @@ impl DistributionFunctionWASM { b: TokenAmount, min_value: Option, max_value: Option, - ) -> DistributionFunctionWASM { - DistributionFunctionWASM(DistributionFunction::InvertedLogarithmic { + ) -> DistributionFunctionWasm { + DistributionFunctionWasm(DistributionFunction::InvertedLogarithmic { a, d, m, @@ -233,10 +233,10 @@ impl DistributionFunctionWASM { pub fn get_function_values(&self) -> Result { match self.0.clone() { DistributionFunction::FixedAmount { amount } => { - Ok(JsValue::from(DistributionFixedAmountWASM { amount })) + Ok(JsValue::from(DistributionFixedAmountWasm { amount })) } DistributionFunction::Random { min, max } => { - Ok(JsValue::from(DistributionRandomWASM { min, max })) + Ok(JsValue::from(DistributionRandomWasm { min, max })) } DistributionFunction::StepDecreasingAmount { step_count, @@ -247,7 +247,7 @@ impl DistributionFunctionWASM { distribution_start_amount, trailing_distribution_interval_amount, min_value, - } => Ok(JsValue::from(DistributionStepDecreasingAmountWASM { + } => Ok(JsValue::from(DistributionStepDecreasingAmountWasm { step_count, decrease_per_interval_numerator, decrease_per_interval_denominator, @@ -277,7 +277,7 @@ impl DistributionFunctionWASM { starting_amount, min_value, max_value, - } => Ok(JsValue::from(DistributionLinearWASM { + } => Ok(JsValue::from(DistributionLinearWasm { a, d, start_step, @@ -295,7 +295,7 @@ impl DistributionFunctionWASM { b, min_value, max_value, - } => Ok(JsValue::from(DistributionPolynomialWASM { + } => Ok(JsValue::from(DistributionPolynomialWasm { a, d, m, @@ -316,7 +316,7 @@ impl DistributionFunctionWASM { b, min_value, max_value, - } => Ok(JsValue::from(DistributionExponentialWASM { + } => Ok(JsValue::from(DistributionExponentialWasm { a, d, m, @@ -337,7 +337,7 @@ impl DistributionFunctionWASM { b, min_value, max_value, - } => Ok(JsValue::from(DistributionLogarithmicWASM { + } => Ok(JsValue::from(DistributionLogarithmicWasm { a, d, m, @@ -358,7 +358,7 @@ impl DistributionFunctionWASM { b, min_value, max_value, - } => Ok(JsValue::from(DistributionInvertedLogarithmicWASM { + } => Ok(JsValue::from(DistributionInvertedLogarithmicWasm { a, d, m, diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs b/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs index 63f2c3d0e00..c29c087948b 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs +++ b/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs @@ -1,26 +1,26 @@ -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use dpp::data_contract::associated_token::token_perpetual_distribution::distribution_recipient::TokenDistributionRecipient; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "TokenDistributionRecipient")] -pub struct TokenDistributionRecipientWASM(TokenDistributionRecipient); +pub struct TokenDistributionRecipientWasm(TokenDistributionRecipient); -impl From for TokenDistributionRecipientWASM { +impl From for TokenDistributionRecipientWasm { fn from(distribution_recipient: TokenDistributionRecipient) -> Self { - TokenDistributionRecipientWASM(distribution_recipient) + TokenDistributionRecipientWasm(distribution_recipient) } } -impl From for TokenDistributionRecipient { - fn from(distribution_recipient: TokenDistributionRecipientWASM) -> Self { +impl From for TokenDistributionRecipient { + fn from(distribution_recipient: TokenDistributionRecipientWasm) -> Self { distribution_recipient.0 } } #[wasm_bindgen(js_class = TokenDistributionRecipient)] -impl TokenDistributionRecipientWASM { +impl TokenDistributionRecipientWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenDistributionRecipient".to_string() @@ -32,22 +32,22 @@ impl TokenDistributionRecipientWASM { } #[wasm_bindgen(js_name = "ContractOwner")] - pub fn contract_owner() -> TokenDistributionRecipientWASM { - TokenDistributionRecipientWASM(TokenDistributionRecipient::ContractOwner) + pub fn contract_owner() -> TokenDistributionRecipientWasm { + TokenDistributionRecipientWasm(TokenDistributionRecipient::ContractOwner) } #[wasm_bindgen(js_name = "Identity")] - pub fn identity(js_identity_id: &JsValue) -> Result { - let identity_id = IdentifierWASM::try_from(js_identity_id)?; + pub fn identity(js_identity_id: &JsValue) -> Result { + let identity_id = IdentifierWasm::try_from(js_identity_id)?; - Ok(TokenDistributionRecipientWASM( + Ok(TokenDistributionRecipientWasm( TokenDistributionRecipient::Identity(identity_id.into()), )) } #[wasm_bindgen(js_name = "EvonodesByParticipation")] - pub fn evonodes_by_participation() -> TokenDistributionRecipientWASM { - TokenDistributionRecipientWASM(TokenDistributionRecipient::EvonodesByParticipation) + pub fn evonodes_by_participation() -> TokenDistributionRecipientWasm { + TokenDistributionRecipientWasm(TokenDistributionRecipient::EvonodesByParticipation) } #[wasm_bindgen(js_name = "getType")] @@ -59,7 +59,7 @@ impl TokenDistributionRecipientWASM { TokenDistributionRecipient::ContractOwner => String::from("ContractOwner"), TokenDistributionRecipient::Identity(identity) => String::from(format!( "Identity({})", - IdentifierWASM::from(identity).get_base58() + IdentifierWasm::from(identity).get_base58() )), } } @@ -70,7 +70,7 @@ impl TokenDistributionRecipientWASM { TokenDistributionRecipient::EvonodesByParticipation => JsValue::undefined(), TokenDistributionRecipient::ContractOwner => JsValue::undefined(), TokenDistributionRecipient::Identity(identifier) => { - IdentifierWASM::from(identifier).into() + IdentifierWasm::from(identifier).into() } } } diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs b/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs index ea6c392f5df..407ebc6a7f3 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs +++ b/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs @@ -1,7 +1,7 @@ -use crate::identifier::IdentifierWASM; -use crate::token_configuration::change_control_rules::ChangeControlRulesWASM; -use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWASM; -use crate::token_configuration::pre_programmed_distribution::TokenPreProgrammedDistributionWASM; +use crate::identifier::IdentifierWasm; +use crate::token_configuration::change_control_rules::ChangeControlRulesWasm; +use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWasm; +use crate::token_configuration::pre_programmed_distribution::TokenPreProgrammedDistributionWasm; use crate::utils::IntoWasm; use dpp::data_contract::associated_token::token_distribution_rules::TokenDistributionRules; use dpp::data_contract::associated_token::token_distribution_rules::accessors::v0::{ @@ -16,22 +16,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "TokenDistributionRules")] -pub struct TokenDistributionRulesWASM(TokenDistributionRules); +pub struct TokenDistributionRulesWasm(TokenDistributionRules); -impl From for TokenDistributionRules { - fn from(rules: TokenDistributionRulesWASM) -> Self { +impl From for TokenDistributionRules { + fn from(rules: TokenDistributionRulesWasm) -> Self { rules.0 } } -impl From for TokenDistributionRulesWASM { +impl From for TokenDistributionRulesWasm { fn from(rules: TokenDistributionRules) -> Self { Self(rules) } } #[wasm_bindgen(js_class = TokenDistributionRules)] -impl TokenDistributionRulesWASM { +impl TokenDistributionRulesWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenDistributionRules".to_string() @@ -45,19 +45,19 @@ impl TokenDistributionRulesWASM { #[wasm_bindgen(constructor)] pub fn new( js_perpetual_distribution: &JsValue, - perpetual_distribution_rules: &ChangeControlRulesWASM, + perpetual_distribution_rules: &ChangeControlRulesWasm, js_pre_programmed_distribution: &JsValue, js_new_tokens_destination_identity: &JsValue, - new_tokens_destination_identity_rules: &ChangeControlRulesWASM, + new_tokens_destination_identity_rules: &ChangeControlRulesWasm, minting_allow_choosing_destination: bool, - minting_allow_choosing_destination_rules: &ChangeControlRulesWASM, - change_direct_purchase_pricing_rules: &ChangeControlRulesWASM, - ) -> Result { + minting_allow_choosing_destination_rules: &ChangeControlRulesWasm, + change_direct_purchase_pricing_rules: &ChangeControlRulesWasm, + ) -> Result { let perpetual_distribution = match js_perpetual_distribution.is_undefined() { true => None, false => Some(TokenPerpetualDistribution::from( js_perpetual_distribution - .to_wasm::("TokenPerpetualDistribution")? + .to_wasm::("TokenPerpetualDistribution")? .clone(), )), }; @@ -66,7 +66,7 @@ impl TokenDistributionRulesWASM { true => None, false => Some(TokenPreProgrammedDistribution::from( js_pre_programmed_distribution - .to_wasm::( + .to_wasm::( "TokenPreProgrammedDistribution", )? .clone(), @@ -76,12 +76,12 @@ impl TokenDistributionRulesWASM { let new_tokens_destination_identity = match js_new_tokens_destination_identity.is_undefined() { true => None, - false => Some(Identifier::from(IdentifierWASM::try_from( + false => Some(Identifier::from(IdentifierWasm::try_from( js_new_tokens_destination_identity, )?)), }; - Ok(TokenDistributionRulesWASM(TokenDistributionRules::V0( + Ok(TokenDistributionRulesWasm(TokenDistributionRules::V0( TokenDistributionRulesV0 { perpetual_distribution, perpetual_distribution_rules: perpetual_distribution_rules.clone().into(), @@ -102,7 +102,7 @@ impl TokenDistributionRulesWASM { } #[wasm_bindgen(getter = "perpetualDistribution")] - pub fn get_perpetual_distribution(&self) -> Option { + pub fn get_perpetual_distribution(&self) -> Option { match self.0.perpetual_distribution() { Some(perp) => Some(perp.clone().into()), None => None, @@ -110,12 +110,12 @@ impl TokenDistributionRulesWASM { } #[wasm_bindgen(getter = "perpetualDistributionRules")] - pub fn get_perpetual_distribution_rules(&self) -> ChangeControlRulesWASM { + pub fn get_perpetual_distribution_rules(&self) -> ChangeControlRulesWasm { self.0.perpetual_distribution_rules().clone().into() } #[wasm_bindgen(getter = "preProgrammedDistribution")] - pub fn get_pre_programmed_distribution(&self) -> Option { + pub fn get_pre_programmed_distribution(&self) -> Option { match self.0.pre_programmed_distribution() { Some(pre) => Some(pre.clone().into()), None => None, @@ -123,7 +123,7 @@ impl TokenDistributionRulesWASM { } #[wasm_bindgen(getter = "newTokenDestinationIdentity")] - pub fn get_new_tokens_destination_identity(&self) -> Option { + pub fn get_new_tokens_destination_identity(&self) -> Option { match self.0.new_tokens_destination_identity().clone() { Some(id) => Some(id.clone().into()), None => None, @@ -131,7 +131,7 @@ impl TokenDistributionRulesWASM { } #[wasm_bindgen(getter = "newTokenDestinationIdentityRules")] - pub fn get_new_tokens_destination_identity_rules(&self) -> ChangeControlRulesWASM { + pub fn get_new_tokens_destination_identity_rules(&self) -> ChangeControlRulesWasm { self.0 .new_tokens_destination_identity_rules() .clone() @@ -144,7 +144,7 @@ impl TokenDistributionRulesWASM { } #[wasm_bindgen(getter = "mintingAllowChoosingDestinationRules")] - pub fn get_minting_allow_choosing_destination_rules(&self) -> ChangeControlRulesWASM { + pub fn get_minting_allow_choosing_destination_rules(&self) -> ChangeControlRulesWasm { self.0 .minting_allow_choosing_destination_rules() .clone() @@ -152,7 +152,7 @@ impl TokenDistributionRulesWASM { } #[wasm_bindgen(getter = "changeDirectPurchasePricingRules")] - pub fn get_change_direct_purchase_pricing_rules(&self) -> ChangeControlRulesWASM { + pub fn get_change_direct_purchase_pricing_rules(&self) -> ChangeControlRulesWasm { self.0.change_direct_purchase_pricing_rules().clone().into() } @@ -165,7 +165,7 @@ impl TokenDistributionRulesWASM { true => None, false => Some(TokenPerpetualDistribution::from( js_perpetual_distribution - .to_wasm::("TokenPerpetualDistribution")? + .to_wasm::("TokenPerpetualDistribution")? .clone(), )), }; @@ -174,7 +174,7 @@ impl TokenDistributionRulesWASM { } #[wasm_bindgen(setter = "perpetualDistributionRules")] - pub fn set_perpetual_distribution_rules(&mut self, rules: &ChangeControlRulesWASM) { + pub fn set_perpetual_distribution_rules(&mut self, rules: &ChangeControlRulesWasm) { self.0 .set_perpetual_distribution_rules(rules.clone().into()) } @@ -188,7 +188,7 @@ impl TokenDistributionRulesWASM { true => None, false => Some(TokenPreProgrammedDistribution::from( js_distribution - .to_wasm::( + .to_wasm::( "TokenPreProgrammedDistribution", )? .clone(), @@ -206,7 +206,7 @@ impl TokenDistributionRulesWASM { let identifier = match js_identifier.is_undefined() { true => None, false => Some(Identifier::from( - IdentifierWASM::try_from(js_identifier)?.clone(), + IdentifierWasm::try_from(js_identifier)?.clone(), )), }; @@ -214,7 +214,7 @@ impl TokenDistributionRulesWASM { } #[wasm_bindgen(setter = "newTokenDestinationIdentityRules")] - pub fn set_new_tokens_destination_identity_rules(&mut self, rules: &ChangeControlRulesWASM) { + pub fn set_new_tokens_destination_identity_rules(&mut self, rules: &ChangeControlRulesWasm) { self.0 .set_new_tokens_destination_identity_rules(rules.clone().into()); } @@ -225,13 +225,13 @@ impl TokenDistributionRulesWASM { } #[wasm_bindgen(setter = "mintingAllowChoosingDestinationRules")] - pub fn set_minting_allow_choosing_destination_rules(&mut self, rules: &ChangeControlRulesWASM) { + pub fn set_minting_allow_choosing_destination_rules(&mut self, rules: &ChangeControlRulesWasm) { self.0 .set_minting_allow_choosing_destination_rules(rules.clone().into()); } #[wasm_bindgen(setter = "changeDirectPurchasePricingRules")] - pub fn set_change_direct_purchase_pricing_rules(&mut self, rules: &ChangeControlRulesWASM) { + pub fn set_change_direct_purchase_pricing_rules(&mut self, rules: &ChangeControlRulesWasm) { self.0 .set_change_direct_purchase_pricing_rules(rules.clone().into()); } diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_structs.rs b/packages/wasm-dpp2/src/token_configuration/distribution_structs.rs index 050dfc18bf3..b3952154879 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_structs.rs +++ b/packages/wasm-dpp2/src/token_configuration/distribution_structs.rs @@ -2,18 +2,18 @@ use dpp::balances::credits::TokenAmount; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "DistributionFixedAmount")] -pub struct DistributionFixedAmountWASM { +pub struct DistributionFixedAmountWasm { pub amount: TokenAmount, } #[wasm_bindgen(js_name = "DistributionRandom")] -pub struct DistributionRandomWASM { +pub struct DistributionRandomWasm { pub min: TokenAmount, pub max: TokenAmount, } #[wasm_bindgen(js_name = "DistributionStepDecreasingAmount")] -pub struct DistributionStepDecreasingAmountWASM { +pub struct DistributionStepDecreasingAmountWasm { #[wasm_bindgen(js_name = "stepCount")] pub step_count: u32, #[wasm_bindgen(js_name = "decreasePerIntervalNumerator")] @@ -33,7 +33,7 @@ pub struct DistributionStepDecreasingAmountWASM { } #[wasm_bindgen(js_name = "DistributionLinear")] -pub struct DistributionLinearWASM { +pub struct DistributionLinearWasm { pub a: i64, pub d: u64, #[wasm_bindgen(js_name = "startStep")] @@ -47,7 +47,7 @@ pub struct DistributionLinearWASM { } #[wasm_bindgen(js_name = "DistributionPolynomial")] -pub struct DistributionPolynomialWASM { +pub struct DistributionPolynomialWasm { pub a: i64, pub d: u64, pub m: i64, @@ -63,7 +63,7 @@ pub struct DistributionPolynomialWASM { } #[wasm_bindgen(js_name = "DistributionExponential")] -pub struct DistributionExponentialWASM { +pub struct DistributionExponentialWasm { pub a: u64, pub d: u64, pub m: i64, @@ -79,7 +79,7 @@ pub struct DistributionExponentialWASM { } #[wasm_bindgen(js_name = "DistributionLogarithmic")] -pub struct DistributionLogarithmicWASM { +pub struct DistributionLogarithmicWasm { pub a: i64, pub d: u64, pub m: u64, @@ -95,7 +95,7 @@ pub struct DistributionLogarithmicWASM { } #[wasm_bindgen(js_name = "DistributionInvertedLogarithmic")] -pub struct DistributionInvertedLogarithmicWASM { +pub struct DistributionInvertedLogarithmicWasm { pub a: i64, pub d: u64, pub m: u64, diff --git a/packages/wasm-dpp2/src/token_configuration/group.rs b/packages/wasm-dpp2/src/token_configuration/group.rs index ed191fef8de..bf90e5d2103 100644 --- a/packages/wasm-dpp2/src/token_configuration/group.rs +++ b/packages/wasm-dpp2/src/token_configuration/group.rs @@ -1,4 +1,4 @@ -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use dpp::data_contract::group::accessors::v0::{GroupV0Getters, GroupV0Setters}; use dpp::data_contract::group::v0::GroupV0; use dpp::data_contract::group::{Group, GroupMemberPower, GroupRequiredPower}; @@ -12,16 +12,16 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, PartialEq, Debug)] #[wasm_bindgen(js_name = "Group")] -pub struct GroupWASM(Group); +pub struct GroupWasm(Group); -impl From for GroupWASM { +impl From for GroupWasm { fn from(group: Group) -> Self { - GroupWASM(group) + GroupWasm(group) } } -impl From for Group { - fn from(group: GroupWASM) -> Self { +impl From for Group { + fn from(group: GroupWasm) -> Self { group.0 } } @@ -39,7 +39,7 @@ pub fn js_members_to_map( .as_string() .ok_or_else(|| JsValue::from_str("cannot convert key to string"))?; - let id_wasm = IdentifierWASM::try_from(key.clone()) + let id_wasm = IdentifierWasm::try_from(key.clone()) .map_err(|_| JsValue::from_str(&format!("Invalid identifier: {}", key_str)))?; let val = Reflect::get(js_members, &key) @@ -54,7 +54,7 @@ pub fn js_members_to_map( } #[wasm_bindgen(js_class = Group)] -impl GroupWASM { +impl GroupWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "Group".to_string() @@ -69,10 +69,10 @@ impl GroupWASM { pub fn new( js_members: &JsValue, required_power: GroupRequiredPower, - ) -> Result { + ) -> Result { let members = js_members_to_map(js_members)?; - Ok(GroupWASM(Group::V0(GroupV0 { + Ok(GroupWasm(Group::V0(GroupV0 { members, required_power, }))) @@ -120,7 +120,7 @@ impl GroupWASM { js_member: &JsValue, member_required_power: GroupRequiredPower, ) -> Result<(), JsValue> { - let member = IdentifierWASM::try_from(js_member.clone())?; + let member = IdentifierWasm::try_from(js_member.clone())?; self.0 .set_member_power(member.into(), member_required_power); diff --git a/packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs b/packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs index 197b343d447..8578d708223 100644 --- a/packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs +++ b/packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs @@ -7,22 +7,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone)] #[wasm_bindgen(js_name = "TokenKeepsHistoryRules")] -pub struct TokenKeepsHistoryRulesWASM(TokenKeepsHistoryRules); +pub struct TokenKeepsHistoryRulesWasm(TokenKeepsHistoryRules); -impl From for TokenKeepsHistoryRules { - fn from(rules: TokenKeepsHistoryRulesWASM) -> Self { +impl From for TokenKeepsHistoryRules { + fn from(rules: TokenKeepsHistoryRulesWasm) -> Self { rules.0 } } -impl From for TokenKeepsHistoryRulesWASM { +impl From for TokenKeepsHistoryRulesWasm { fn from(rules: TokenKeepsHistoryRules) -> Self { Self(rules) } } #[wasm_bindgen(js_class = TokenKeepsHistoryRules)] -impl TokenKeepsHistoryRulesWASM { +impl TokenKeepsHistoryRulesWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenKeepsHistoryRules".to_string() @@ -41,8 +41,8 @@ impl TokenKeepsHistoryRulesWASM { keeps_burning_history: bool, keeps_direct_pricing_history: bool, keeps_direct_purchase_history: bool, - ) -> TokenKeepsHistoryRulesWASM { - TokenKeepsHistoryRulesWASM(TokenKeepsHistoryRules::V0(TokenKeepsHistoryRulesV0 { + ) -> TokenKeepsHistoryRulesWasm { + TokenKeepsHistoryRulesWasm(TokenKeepsHistoryRules::V0(TokenKeepsHistoryRulesV0 { keeps_transfer_history, keeps_freezing_history, keeps_minting_history, diff --git a/packages/wasm-dpp2/src/token_configuration/localization.rs b/packages/wasm-dpp2/src/token_configuration/localization.rs index 9d562883a99..0db9cad8e4f 100644 --- a/packages/wasm-dpp2/src/token_configuration/localization.rs +++ b/packages/wasm-dpp2/src/token_configuration/localization.rs @@ -9,22 +9,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = TokenConfigurationLocalization)] -pub struct TokenConfigurationLocalizationWASM(TokenConfigurationLocalization); +pub struct TokenConfigurationLocalizationWasm(TokenConfigurationLocalization); -impl From for TokenConfigurationLocalizationWASM { - fn from(configuration: TokenConfigurationLocalization) -> TokenConfigurationLocalizationWASM { - TokenConfigurationLocalizationWASM(configuration) +impl From for TokenConfigurationLocalizationWasm { + fn from(configuration: TokenConfigurationLocalization) -> TokenConfigurationLocalizationWasm { + TokenConfigurationLocalizationWasm(configuration) } } -impl From for TokenConfigurationLocalization { - fn from(configuration: TokenConfigurationLocalizationWASM) -> TokenConfigurationLocalization { +impl From for TokenConfigurationLocalization { + fn from(configuration: TokenConfigurationLocalizationWasm) -> TokenConfigurationLocalization { configuration.0 } } #[wasm_bindgen(js_class = TokenConfigurationLocalization)] -impl TokenConfigurationLocalizationWASM { +impl TokenConfigurationLocalizationWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenConfigurationLocalization".to_string() @@ -40,8 +40,8 @@ impl TokenConfigurationLocalizationWASM { should_capitalize: bool, singular_form: String, plural_form: String, - ) -> TokenConfigurationLocalizationWASM { - TokenConfigurationLocalizationWASM(TokenConfigurationLocalization::V0( + ) -> TokenConfigurationLocalizationWasm { + TokenConfigurationLocalizationWasm(TokenConfigurationLocalization::V0( TokenConfigurationLocalizationV0 { should_capitalize, singular_form, diff --git a/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs b/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs index 720395a1216..8adeacef3eb 100644 --- a/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs +++ b/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs @@ -1,5 +1,5 @@ -use crate::token_configuration::change_control_rules::ChangeControlRulesWASM; -use crate::token_configuration::trade_mode::TokenTradeModeWASM; +use crate::token_configuration::change_control_rules::ChangeControlRulesWasm; +use crate::token_configuration::trade_mode::TokenTradeModeWasm; use dpp::data_contract::associated_token::token_marketplace_rules::TokenMarketplaceRules; use dpp::data_contract::associated_token::token_marketplace_rules::accessors::v0::{ TokenMarketplaceRulesV0Getters, TokenMarketplaceRulesV0Setters, @@ -9,22 +9,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, PartialEq, Debug)] #[wasm_bindgen(js_name = "TokenMarketplaceRules")] -pub struct TokenMarketplaceRulesWASM(TokenMarketplaceRules); +pub struct TokenMarketplaceRulesWasm(TokenMarketplaceRules); -impl From for TokenMarketplaceRulesWASM { +impl From for TokenMarketplaceRulesWasm { fn from(rules: TokenMarketplaceRules) -> Self { - TokenMarketplaceRulesWASM(rules) + TokenMarketplaceRulesWasm(rules) } } -impl From for TokenMarketplaceRules { - fn from(rules: TokenMarketplaceRulesWASM) -> Self { +impl From for TokenMarketplaceRules { + fn from(rules: TokenMarketplaceRulesWasm) -> Self { rules.0 } } #[wasm_bindgen(js_class = TokenMarketplaceRules)] -impl TokenMarketplaceRulesWASM { +impl TokenMarketplaceRulesWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenMarketplaceRules".to_string() @@ -37,10 +37,10 @@ impl TokenMarketplaceRulesWASM { #[wasm_bindgen(constructor)] pub fn new( - trade_mode: &TokenTradeModeWASM, - trade_mode_change_rules: &ChangeControlRulesWASM, - ) -> TokenMarketplaceRulesWASM { - TokenMarketplaceRulesWASM(TokenMarketplaceRules::V0({ + trade_mode: &TokenTradeModeWasm, + trade_mode_change_rules: &ChangeControlRulesWasm, + ) -> TokenMarketplaceRulesWasm { + TokenMarketplaceRulesWasm(TokenMarketplaceRules::V0({ TokenMarketplaceRulesV0 { trade_mode: trade_mode.clone().into(), trade_mode_change_rules: trade_mode_change_rules.clone().into(), @@ -49,24 +49,24 @@ impl TokenMarketplaceRulesWASM { } #[wasm_bindgen(getter = "tradeMode")] - pub fn trade_mode(&self) -> TokenTradeModeWASM { + pub fn trade_mode(&self) -> TokenTradeModeWasm { self.0.trade_mode().clone().into() } #[wasm_bindgen(getter = "tradeModeChangeRules")] - pub fn trade_mode_change_rules(&self) -> ChangeControlRulesWASM { + pub fn trade_mode_change_rules(&self) -> ChangeControlRulesWasm { self.0.trade_mode_change_rules().clone().into() } #[wasm_bindgen(setter = "tradeMode")] - pub fn set_trade_mode(&mut self, trade_mode: &TokenTradeModeWASM) { + pub fn set_trade_mode(&mut self, trade_mode: &TokenTradeModeWasm) { self.0.set_trade_mode(trade_mode.clone().into()); } #[wasm_bindgen(setter = "tradeModeChangeRules")] pub fn set_trade_mode_change_rules( &mut self, - trade_mode_change_rules: &ChangeControlRulesWASM, + trade_mode_change_rules: &ChangeControlRulesWasm, ) { self.0 .set_trade_mode_change_rules(trade_mode_change_rules.clone().into()); diff --git a/packages/wasm-dpp2/src/token_configuration/mod.rs b/packages/wasm-dpp2/src/token_configuration/mod.rs index 2453333577f..4113af0ee63 100644 --- a/packages/wasm-dpp2/src/token_configuration/mod.rs +++ b/packages/wasm-dpp2/src/token_configuration/mod.rs @@ -1,10 +1,10 @@ -use crate::identifier::IdentifierWASM; -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration::change_control_rules::ChangeControlRulesWASM; -use crate::token_configuration::configuration_convention::TokenConfigurationConventionWASM; -use crate::token_configuration::distribution_rules::TokenDistributionRulesWASM; -use crate::token_configuration::keeps_history_rules::TokenKeepsHistoryRulesWASM; -use crate::token_configuration::marketplace_rules::TokenMarketplaceRulesWASM; +use crate::identifier::IdentifierWasm; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration::change_control_rules::ChangeControlRulesWasm; +use crate::token_configuration::configuration_convention::TokenConfigurationConventionWasm; +use crate::token_configuration::distribution_rules::TokenDistributionRulesWasm; +use crate::token_configuration::keeps_history_rules::TokenKeepsHistoryRulesWasm; +use crate::token_configuration::marketplace_rules::TokenMarketplaceRulesWasm; use dpp::balances::credits::TokenAmount; use dpp::data_contract::associated_token::token_configuration::accessors::v0::{ TokenConfigurationV0Getters, TokenConfigurationV0Setters, @@ -34,22 +34,22 @@ pub mod trade_mode; #[derive(Clone, PartialEq, Debug)] #[wasm_bindgen(js_name = "TokenConfiguration")] -pub struct TokenConfigurationWASM(TokenConfiguration); +pub struct TokenConfigurationWasm(TokenConfiguration); -impl From for TokenConfigurationWASM { +impl From for TokenConfigurationWasm { fn from(configuration: TokenConfiguration) -> Self { Self(configuration) } } -impl From for TokenConfiguration { - fn from(configuration: TokenConfigurationWASM) -> Self { +impl From for TokenConfiguration { + fn from(configuration: TokenConfigurationWasm) -> Self { configuration.0 } } #[wasm_bindgen(js_class = TokenConfiguration)] -impl TokenConfigurationWASM { +impl TokenConfigurationWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenConfiguration".to_string() @@ -62,27 +62,27 @@ impl TokenConfigurationWASM { #[wasm_bindgen(constructor)] pub fn new( - conventions: &TokenConfigurationConventionWASM, - conventions_change_rules: &ChangeControlRulesWASM, + conventions: &TokenConfigurationConventionWasm, + conventions_change_rules: &ChangeControlRulesWasm, base_supply: TokenAmount, max_supply: Option, - keeps_history: &TokenKeepsHistoryRulesWASM, + keeps_history: &TokenKeepsHistoryRulesWasm, start_as_paused: bool, allow_transfer_to_frozen_balance: bool, - max_supply_change_rules: &ChangeControlRulesWASM, - distribution_rules: &TokenDistributionRulesWASM, - marketplace_rules: &TokenMarketplaceRulesWASM, - manual_minting_rules: &ChangeControlRulesWASM, - manual_burning_rules: &ChangeControlRulesWASM, - freeze_rules: &ChangeControlRulesWASM, - unfreeze_rules: &ChangeControlRulesWASM, - destroy_frozen_funds_rules: &ChangeControlRulesWASM, - emergency_action_rules: &ChangeControlRulesWASM, + max_supply_change_rules: &ChangeControlRulesWasm, + distribution_rules: &TokenDistributionRulesWasm, + marketplace_rules: &TokenMarketplaceRulesWasm, + manual_minting_rules: &ChangeControlRulesWasm, + manual_burning_rules: &ChangeControlRulesWasm, + freeze_rules: &ChangeControlRulesWasm, + unfreeze_rules: &ChangeControlRulesWasm, + destroy_frozen_funds_rules: &ChangeControlRulesWasm, + emergency_action_rules: &ChangeControlRulesWasm, main_control_group: Option, - main_control_group_can_be_modified: &AuthorizedActionTakersWASM, + main_control_group_can_be_modified: &AuthorizedActionTakersWasm, description: Option, - ) -> TokenConfigurationWASM { - TokenConfigurationWASM(TokenConfiguration::V0(TokenConfigurationV0 { + ) -> TokenConfigurationWasm { + TokenConfigurationWasm(TokenConfiguration::V0(TokenConfigurationV0 { conventions: conventions.clone().into(), conventions_change_rules: conventions_change_rules.clone().into(), base_supply, @@ -106,12 +106,12 @@ impl TokenConfigurationWASM { } #[wasm_bindgen(getter = "conventions")] - pub fn get_conventions(&self) -> TokenConfigurationConventionWASM { + pub fn get_conventions(&self) -> TokenConfigurationConventionWasm { self.0.conventions().clone().into() } #[wasm_bindgen(getter = "conventionsChangeRules")] - pub fn get_conventions_change_rules(&self) -> ChangeControlRulesWASM { + pub fn get_conventions_change_rules(&self) -> ChangeControlRulesWasm { self.0.conventions_change_rules().clone().into() } @@ -121,7 +121,7 @@ impl TokenConfigurationWASM { } #[wasm_bindgen(getter = "keepsHistory")] - pub fn get_keeps_history(&self) -> TokenKeepsHistoryRulesWASM { + pub fn get_keeps_history(&self) -> TokenKeepsHistoryRulesWasm { self.0.keeps_history().clone().into() } @@ -141,49 +141,49 @@ impl TokenConfigurationWASM { } #[wasm_bindgen(getter = "maxSupplyChangeRules")] - pub fn get_max_supply_change_rules(&self) -> ChangeControlRulesWASM { + pub fn get_max_supply_change_rules(&self) -> ChangeControlRulesWasm { self.0.max_supply_change_rules().clone().into() } #[wasm_bindgen(getter = "distributionRules")] - pub fn get_distribution_rules(&self) -> TokenDistributionRulesWASM { + pub fn get_distribution_rules(&self) -> TokenDistributionRulesWasm { self.0.distribution_rules().clone().into() } #[wasm_bindgen(getter = "marketplaceRules")] - pub fn get_marketplace_rules(&self) -> TokenMarketplaceRulesWASM { + pub fn get_marketplace_rules(&self) -> TokenMarketplaceRulesWasm { match self.0.clone() { TokenConfiguration::V0(v0) => v0.marketplace_rules.clone().into(), } } #[wasm_bindgen(getter = "manualMintingRules")] - pub fn get_manual_minting_rules(&self) -> ChangeControlRulesWASM { + pub fn get_manual_minting_rules(&self) -> ChangeControlRulesWasm { self.0.manual_minting_rules().clone().into() } #[wasm_bindgen(getter = "manualBurningRules")] - pub fn get_manual_burning_rules(&self) -> ChangeControlRulesWASM { + pub fn get_manual_burning_rules(&self) -> ChangeControlRulesWasm { self.0.manual_burning_rules().clone().into() } #[wasm_bindgen(getter = "freezeRules")] - pub fn get_freeze_rules(&self) -> ChangeControlRulesWASM { + pub fn get_freeze_rules(&self) -> ChangeControlRulesWasm { self.0.freeze_rules().clone().into() } #[wasm_bindgen(getter = "unfreezeRules")] - pub fn get_unfreeze_rules(&self) -> ChangeControlRulesWASM { + pub fn get_unfreeze_rules(&self) -> ChangeControlRulesWasm { self.0.unfreeze_rules().clone().into() } #[wasm_bindgen(getter = "destroyFrozenFundsRules")] - pub fn get_destroy_frozen_funds_rules(&self) -> ChangeControlRulesWASM { + pub fn get_destroy_frozen_funds_rules(&self) -> ChangeControlRulesWasm { self.0.destroy_frozen_funds_rules().clone().into() } #[wasm_bindgen(getter = "emergencyActionRules")] - pub fn get_emergency_action_rules(&self) -> ChangeControlRulesWASM { + pub fn get_emergency_action_rules(&self) -> ChangeControlRulesWasm { self.0.emergency_action_rules().clone().into() } @@ -193,7 +193,7 @@ impl TokenConfigurationWASM { } #[wasm_bindgen(getter = "mainControlGroupCanBeModified")] - pub fn get_main_control_group_can_be_modified(&self) -> AuthorizedActionTakersWASM { + pub fn get_main_control_group_can_be_modified(&self) -> AuthorizedActionTakersWasm { self.0.main_control_group_can_be_modified().clone().into() } @@ -203,12 +203,12 @@ impl TokenConfigurationWASM { } #[wasm_bindgen(setter = "conventions")] - pub fn set_conventions(&mut self, conventions: &TokenConfigurationConventionWASM) { + pub fn set_conventions(&mut self, conventions: &TokenConfigurationConventionWasm) { self.0.set_conventions(conventions.clone().into()) } #[wasm_bindgen(setter = "conventionsChangeRules")] - pub fn set_conventions_change_rules(&mut self, rules: &ChangeControlRulesWASM) { + pub fn set_conventions_change_rules(&mut self, rules: &ChangeControlRulesWasm) { self.0.set_conventions_change_rules(rules.clone().into()) } @@ -218,7 +218,7 @@ impl TokenConfigurationWASM { } #[wasm_bindgen(setter = "keepsHistory")] - pub fn set_keeps_history(&mut self, keeps_history: &TokenKeepsHistoryRulesWASM) { + pub fn set_keeps_history(&mut self, keeps_history: &TokenKeepsHistoryRulesWasm) { self.0 = match self.0.clone() { TokenConfiguration::V0(mut v0) => { v0.keeps_history = keeps_history.clone().into(); @@ -248,17 +248,17 @@ impl TokenConfigurationWASM { } #[wasm_bindgen(setter = "maxSupplyChangeRules")] - pub fn set_max_supply_change_rules(&mut self, rules: &ChangeControlRulesWASM) { + pub fn set_max_supply_change_rules(&mut self, rules: &ChangeControlRulesWasm) { self.0.set_max_supply_change_rules(rules.clone().into()) } #[wasm_bindgen(setter = "distributionRules")] - pub fn set_distribution_rules(&mut self, rules: &TokenDistributionRulesWASM) { + pub fn set_distribution_rules(&mut self, rules: &TokenDistributionRulesWasm) { self.0.set_distribution_rules(rules.clone().into()) } #[wasm_bindgen(setter = "marketplaceRules")] - pub fn set_marketplace_rules(&mut self, marketplace_rules: &TokenMarketplaceRulesWASM) { + pub fn set_marketplace_rules(&mut self, marketplace_rules: &TokenMarketplaceRulesWasm) { self.0 = match self.0.clone() { TokenConfiguration::V0(mut v0) => { v0.marketplace_rules = marketplace_rules.clone().into(); @@ -269,32 +269,32 @@ impl TokenConfigurationWASM { } #[wasm_bindgen(setter = "manualMintingRules")] - pub fn set_manual_minting_rules(&mut self, rules: &ChangeControlRulesWASM) { + pub fn set_manual_minting_rules(&mut self, rules: &ChangeControlRulesWasm) { self.0.set_manual_minting_rules(rules.clone().into()) } #[wasm_bindgen(setter = "manualBurningRules")] - pub fn set_manual_burning_rules(&mut self, rules: &ChangeControlRulesWASM) { + pub fn set_manual_burning_rules(&mut self, rules: &ChangeControlRulesWasm) { self.0.set_manual_burning_rules(rules.clone().into()) } #[wasm_bindgen(setter = "freezeRules")] - pub fn set_freeze_rules(&mut self, rules: &ChangeControlRulesWASM) { + pub fn set_freeze_rules(&mut self, rules: &ChangeControlRulesWasm) { self.0.set_freeze_rules(rules.clone().into()) } #[wasm_bindgen(setter = "unfreezeRules")] - pub fn set_unfreeze_rules(&mut self, rules: &ChangeControlRulesWASM) { + pub fn set_unfreeze_rules(&mut self, rules: &ChangeControlRulesWasm) { self.0.set_unfreeze_rules(rules.clone().into()) } #[wasm_bindgen(setter = "destroyFrozenFundsRules")] - pub fn set_destroy_frozen_funds_rules(&mut self, rules: &ChangeControlRulesWASM) { + pub fn set_destroy_frozen_funds_rules(&mut self, rules: &ChangeControlRulesWasm) { self.0.set_destroy_frozen_funds_rules(rules.clone().into()) } #[wasm_bindgen(setter = "emergencyActionRules")] - pub fn set_emergency_action_rules(&mut self, rules: &ChangeControlRulesWASM) { + pub fn set_emergency_action_rules(&mut self, rules: &ChangeControlRulesWasm) { self.0.set_emergency_action_rules(rules.clone().into()) } @@ -306,7 +306,7 @@ impl TokenConfigurationWASM { #[wasm_bindgen(setter = "mainControlGroupCanBeModified")] pub fn set_main_control_group_can_be_modified( &mut self, - authorized_action_taker: &AuthorizedActionTakersWASM, + authorized_action_taker: &AuthorizedActionTakersWasm, ) { self.0 .set_main_control_group_can_be_modified(authorized_action_taker.clone().into()) @@ -321,10 +321,10 @@ impl TokenConfigurationWASM { pub fn calculate_token_id( js_contract_id: &JsValue, token_pos: TokenContractPosition, - ) -> Result { - let contract_id = IdentifierWASM::try_from(js_contract_id)?; + ) -> Result { + let contract_id = IdentifierWasm::try_from(js_contract_id)?; - Ok(IdentifierWASM::from(calculate_token_id( + Ok(IdentifierWasm::from(calculate_token_id( &contract_id.to_slice(), token_pos, ))) diff --git a/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs b/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs index f679329d9c0..9130979a7f7 100644 --- a/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs +++ b/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs @@ -1,5 +1,5 @@ -use crate::token_configuration::distribution_recipient::TokenDistributionRecipientWASM; -use crate::token_configuration::reward_distribution_type::RewardDistributionTypeWASM; +use crate::token_configuration::distribution_recipient::TokenDistributionRecipientWasm; +use crate::token_configuration::reward_distribution_type::RewardDistributionTypeWasm; use dpp::data_contract::associated_token::token_perpetual_distribution::TokenPerpetualDistribution; use dpp::data_contract::associated_token::token_perpetual_distribution::methods::v0::TokenPerpetualDistributionV0Accessors; use dpp::data_contract::associated_token::token_perpetual_distribution::v0::TokenPerpetualDistributionV0; @@ -7,22 +7,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, PartialEq, Debug)] #[wasm_bindgen(js_name = "TokenPerpetualDistribution")] -pub struct TokenPerpetualDistributionWASM(TokenPerpetualDistribution); +pub struct TokenPerpetualDistributionWasm(TokenPerpetualDistribution); -impl From for TokenPerpetualDistribution { - fn from(value: TokenPerpetualDistributionWASM) -> Self { +impl From for TokenPerpetualDistribution { + fn from(value: TokenPerpetualDistributionWasm) -> Self { value.0 } } -impl From for TokenPerpetualDistributionWASM { +impl From for TokenPerpetualDistributionWasm { fn from(value: TokenPerpetualDistribution) -> Self { - TokenPerpetualDistributionWASM(value) + TokenPerpetualDistributionWasm(value) } } #[wasm_bindgen(js_class = TokenPerpetualDistribution)] -impl TokenPerpetualDistributionWASM { +impl TokenPerpetualDistributionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenPerpetualDistribution".to_string() @@ -35,10 +35,10 @@ impl TokenPerpetualDistributionWASM { #[wasm_bindgen(constructor)] pub fn new( - distribution_type: &RewardDistributionTypeWASM, - recipient: &TokenDistributionRecipientWASM, + distribution_type: &RewardDistributionTypeWasm, + recipient: &TokenDistributionRecipientWasm, ) -> Self { - TokenPerpetualDistributionWASM(TokenPerpetualDistribution::V0( + TokenPerpetualDistributionWasm(TokenPerpetualDistribution::V0( TokenPerpetualDistributionV0 { distribution_type: distribution_type.clone().into(), distribution_recipient: recipient.clone().into(), @@ -47,23 +47,23 @@ impl TokenPerpetualDistributionWASM { } #[wasm_bindgen(getter = distributionType)] - pub fn distribution_type(&self) -> RewardDistributionTypeWASM { + pub fn distribution_type(&self) -> RewardDistributionTypeWasm { self.0.distribution_type().clone().into() } #[wasm_bindgen(getter = distributionRecipient)] - pub fn recipient(&self) -> TokenDistributionRecipientWASM { + pub fn recipient(&self) -> TokenDistributionRecipientWasm { self.0.distribution_recipient().clone().into() } #[wasm_bindgen(setter = distributionType)] - pub fn set_distribution_type(&mut self, distribution_type: &RewardDistributionTypeWASM) { + pub fn set_distribution_type(&mut self, distribution_type: &RewardDistributionTypeWasm) { self.0 .set_distribution_type(distribution_type.clone().into()); } #[wasm_bindgen(setter = distributionRecipient)] - pub fn set_recipient(&mut self, distribution_recipient: &TokenDistributionRecipientWASM) { + pub fn set_recipient(&mut self, distribution_recipient: &TokenDistributionRecipientWasm) { self.0 .set_distribution_recipient(distribution_recipient.clone().into()); } diff --git a/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs b/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs index ae95e6b8f56..380fcbb275d 100644 --- a/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs +++ b/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs @@ -1,4 +1,4 @@ -use crate::identifier::IdentifierWASM; +use crate::identifier::IdentifierWasm; use dpp::balances::credits::TokenAmount; use dpp::data_contract::associated_token::token_pre_programmed_distribution::TokenPreProgrammedDistribution; use dpp::data_contract::associated_token::token_pre_programmed_distribution::accessors::v0::TokenPreProgrammedDistributionV0Methods; @@ -11,17 +11,17 @@ use wasm_bindgen::{JsError, JsValue}; #[derive(Clone, PartialEq, Debug)] #[wasm_bindgen(js_name = "TokenPreProgrammedDistribution")] -pub struct TokenPreProgrammedDistributionWASM(TokenPreProgrammedDistribution); +pub struct TokenPreProgrammedDistributionWasm(TokenPreProgrammedDistribution); -impl From for TokenPreProgrammedDistribution { - fn from(value: TokenPreProgrammedDistributionWASM) -> Self { +impl From for TokenPreProgrammedDistribution { + fn from(value: TokenPreProgrammedDistributionWasm) -> Self { value.0 } } -impl From for TokenPreProgrammedDistributionWASM { +impl From for TokenPreProgrammedDistributionWasm { fn from(value: TokenPreProgrammedDistribution) -> Self { - TokenPreProgrammedDistributionWASM(value) + TokenPreProgrammedDistributionWasm(value) } } @@ -47,7 +47,7 @@ pub fn js_distributions_to_distributions( let mut ids = BTreeMap::new(); for id_key in identifiers_keys.iter() { - let identifier = Identifier::from(IdentifierWASM::try_from(id_key.clone())?); + let identifier = Identifier::from(IdentifierWasm::try_from(id_key.clone())?); let token_amount = BigInt::new(&Reflect::get(&identifiers_object, &id_key.clone())?)? .to_string(10) @@ -67,7 +67,7 @@ pub fn js_distributions_to_distributions( } #[wasm_bindgen(js_class = TokenPreProgrammedDistribution)] -impl TokenPreProgrammedDistributionWASM { +impl TokenPreProgrammedDistributionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenPreProgrammedDistribution".to_string() @@ -79,10 +79,10 @@ impl TokenPreProgrammedDistributionWASM { } #[wasm_bindgen(constructor)] - pub fn new(js_distributions: &JsValue) -> Result { + pub fn new(js_distributions: &JsValue) -> Result { let distributions = js_distributions_to_distributions(js_distributions)?; - Ok(TokenPreProgrammedDistributionWASM( + Ok(TokenPreProgrammedDistributionWasm( TokenPreProgrammedDistribution::V0(TokenPreProgrammedDistributionV0 { distributions }), )) } @@ -98,7 +98,7 @@ impl TokenPreProgrammedDistributionWASM { for (identifiers_key, identifiers_value) in value { Reflect::set( &identifiers_obj, - &IdentifierWASM::from(identifiers_key.clone()) + &IdentifierWasm::from(identifiers_key.clone()) .get_base58() .into(), &BigInt::from(identifiers_value.clone()).into(), diff --git a/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs b/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs index 86c48583809..431746b8778 100644 --- a/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs +++ b/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs @@ -3,26 +3,26 @@ use dpp::data_contract::associated_token::token_perpetual_distribution::reward_d use dpp::prelude::{BlockHeightInterval, EpochInterval, TimestampMillisInterval}; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::token_configuration::distribution_function::DistributionFunctionWASM; +use crate::token_configuration::distribution_function::DistributionFunctionWasm; #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "RewardDistributionType")] -pub struct RewardDistributionTypeWASM(RewardDistributionType); +pub struct RewardDistributionTypeWasm(RewardDistributionType); -impl From for RewardDistributionTypeWASM { +impl From for RewardDistributionTypeWasm { fn from(reward_distribution_type: RewardDistributionType) -> Self { Self(reward_distribution_type) } } -impl From for RewardDistributionType { - fn from(reward_distribution_type: RewardDistributionTypeWASM) -> Self { +impl From for RewardDistributionType { + fn from(reward_distribution_type: RewardDistributionTypeWasm) -> Self { reward_distribution_type.0 } } #[wasm_bindgen(js_class = RewardDistributionType)] -impl RewardDistributionTypeWASM { +impl RewardDistributionTypeWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "RewardDistributionType".to_string() @@ -36,9 +36,9 @@ impl RewardDistributionTypeWASM { #[wasm_bindgen(js_name = "BlockBasedDistribution")] pub fn block_based_distribution( interval: BlockHeightInterval, - function: &DistributionFunctionWASM, + function: &DistributionFunctionWasm, ) -> Self { - RewardDistributionTypeWASM(BlockBasedDistribution { + RewardDistributionTypeWasm(BlockBasedDistribution { interval, function: function.clone().into(), }) @@ -47,9 +47,9 @@ impl RewardDistributionTypeWASM { #[wasm_bindgen(js_name = "TimeBasedDistribution")] pub fn time_based_distribution( interval: TimestampMillisInterval, - function: &DistributionFunctionWASM, + function: &DistributionFunctionWasm, ) -> Self { - RewardDistributionTypeWASM(TimeBasedDistribution { + RewardDistributionTypeWasm(TimeBasedDistribution { interval, function: function.clone().into(), }) @@ -58,9 +58,9 @@ impl RewardDistributionTypeWASM { #[wasm_bindgen(js_name = "EpochBasedDistribution")] pub fn epoch_based_distribution( interval: EpochInterval, - function: &DistributionFunctionWASM, + function: &DistributionFunctionWasm, ) -> Self { - RewardDistributionTypeWASM(EpochBasedDistribution { + RewardDistributionTypeWasm(EpochBasedDistribution { interval, function: function.clone().into(), }) @@ -70,19 +70,19 @@ impl RewardDistributionTypeWASM { pub fn get_distribution(&self) -> JsValue { match self.0.clone() { RewardDistributionType::BlockBasedDistribution { interval, function } => { - JsValue::from(BlockBasedDistributionWASM { + JsValue::from(BlockBasedDistributionWasm { interval, function: function.clone().into(), }) } RewardDistributionType::TimeBasedDistribution { interval, function } => { - JsValue::from(TimeBasedDistributionWASM { + JsValue::from(TimeBasedDistributionWasm { interval, function: function.clone().into(), }) } RewardDistributionType::EpochBasedDistribution { interval, function } => { - JsValue::from(EpochBasedDistributionWASM { + JsValue::from(EpochBasedDistributionWasm { interval, function: function.clone().into(), }) @@ -93,27 +93,27 @@ impl RewardDistributionTypeWASM { #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "BlockBasedDistribution")] -pub struct BlockBasedDistributionWASM { +pub struct BlockBasedDistributionWasm { pub interval: BlockHeightInterval, - function: DistributionFunctionWASM, + function: DistributionFunctionWasm, } #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "TimeBasedDistribution")] -pub struct TimeBasedDistributionWASM { +pub struct TimeBasedDistributionWasm { pub interval: TimestampMillisInterval, - function: DistributionFunctionWASM, + function: DistributionFunctionWasm, } #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "EpochBasedDistribution")] -pub struct EpochBasedDistributionWASM { +pub struct EpochBasedDistributionWasm { pub interval: EpochInterval, - function: DistributionFunctionWASM, + function: DistributionFunctionWasm, } #[wasm_bindgen(js_class = BlockBasedDistribution)] -impl BlockBasedDistributionWASM { +impl BlockBasedDistributionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "BlockBasedDistribution".to_string() @@ -125,18 +125,18 @@ impl BlockBasedDistributionWASM { } #[wasm_bindgen(getter = "function")] - pub fn get_function(&self) -> DistributionFunctionWASM { + pub fn get_function(&self) -> DistributionFunctionWasm { self.function.clone() } #[wasm_bindgen(setter = "function")] - pub fn set_function(&mut self, function: &DistributionFunctionWASM) { + pub fn set_function(&mut self, function: &DistributionFunctionWasm) { self.function = function.clone() } } #[wasm_bindgen(js_class = TimeBasedDistribution)] -impl TimeBasedDistributionWASM { +impl TimeBasedDistributionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TimeBasedDistribution".to_string() @@ -148,18 +148,18 @@ impl TimeBasedDistributionWASM { } #[wasm_bindgen(getter = "function")] - pub fn get_function(&self) -> DistributionFunctionWASM { + pub fn get_function(&self) -> DistributionFunctionWasm { self.function.clone() } #[wasm_bindgen(setter = "function")] - pub fn set_function(&mut self, function: &DistributionFunctionWASM) { + pub fn set_function(&mut self, function: &DistributionFunctionWasm) { self.function = function.clone() } } #[wasm_bindgen(js_class = EpochBasedDistribution)] -impl EpochBasedDistributionWASM { +impl EpochBasedDistributionWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "EpochBasedDistribution".to_string() @@ -171,12 +171,12 @@ impl EpochBasedDistributionWASM { } #[wasm_bindgen(getter = "function")] - pub fn get_function(&self) -> DistributionFunctionWASM { + pub fn get_function(&self) -> DistributionFunctionWasm { self.function.clone() } #[wasm_bindgen(setter = "function")] - pub fn set_function(&mut self, function: &DistributionFunctionWASM) { + pub fn set_function(&mut self, function: &DistributionFunctionWasm) { self.function = function.clone() } } diff --git a/packages/wasm-dpp2/src/token_configuration/trade_mode.rs b/packages/wasm-dpp2/src/token_configuration/trade_mode.rs index 32c46ed590f..e16b38463f1 100644 --- a/packages/wasm-dpp2/src/token_configuration/trade_mode.rs +++ b/packages/wasm-dpp2/src/token_configuration/trade_mode.rs @@ -3,22 +3,22 @@ use wasm_bindgen::prelude::wasm_bindgen; #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "TokenTradeMode")] -pub struct TokenTradeModeWASM(TokenTradeMode); +pub struct TokenTradeModeWasm(TokenTradeMode); -impl From for TokenTradeModeWASM { +impl From for TokenTradeModeWasm { fn from(trade_mode: TokenTradeMode) -> Self { - TokenTradeModeWASM(trade_mode) + TokenTradeModeWasm(trade_mode) } } -impl From for TokenTradeMode { - fn from(trade_mode: TokenTradeModeWASM) -> Self { +impl From for TokenTradeMode { + fn from(trade_mode: TokenTradeModeWasm) -> Self { trade_mode.0 } } #[wasm_bindgen(js_class = TokenTradeMode)] -impl TokenTradeModeWASM { +impl TokenTradeModeWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenTradeMode".to_string() @@ -30,8 +30,8 @@ impl TokenTradeModeWASM { } #[wasm_bindgen(js_name = "NotTradeable")] - pub fn not_tradeable() -> TokenTradeModeWASM { - TokenTradeModeWASM(TokenTradeMode::NotTradeable) + pub fn not_tradeable() -> TokenTradeModeWasm { + TokenTradeModeWasm(TokenTradeMode::NotTradeable) } #[wasm_bindgen(js_name = "getValue")] diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs index f1c5980c316..aa4d3c57cb9 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs @@ -1,28 +1,28 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration::configuration_convention::TokenConfigurationConventionWASM; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration::configuration_convention::TokenConfigurationConventionWasm; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "conventionsItem")] - pub fn conventions_item(convention: &TokenConfigurationConventionWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::Conventions( + pub fn conventions_item(convention: &TokenConfigurationConventionWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::Conventions( convention.clone().into(), )) } #[wasm_bindgen(js_name = "ConventionsAdminGroupItem")] - pub fn conventions_admin_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::ConventionsAdminGroup( + pub fn conventions_admin_group_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::ConventionsAdminGroup( action_taker.clone().into(), )) } #[wasm_bindgen(js_name = "ConventionsControlGroupItem")] - pub fn conventions_control_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::ConventionsControlGroup( + pub fn conventions_control_group_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::ConventionsControlGroup( action_taker.clone().into(), )) } diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs index 3621d5dea7b..ea7799f9ae0 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs @@ -1,22 +1,22 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "DestroyFrozenFundsItem")] - pub fn destroy_frozen_funds_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::DestroyFrozenFunds( + pub fn destroy_frozen_funds_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::DestroyFrozenFunds( action_taker.clone().into(), )) } #[wasm_bindgen(js_name = "DestroyFrozenFundsAdminGroupItem")] pub fn destroy_frozen_funds_admin_group_item( - action_taker: &AuthorizedActionTakersWASM, + action_taker: &AuthorizedActionTakersWasm, ) -> Self { - TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItemWasm( TokenConfigurationChangeItem::DestroyFrozenFundsAdminGroup(action_taker.clone().into()), ) } diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs index 062bed2a0ec..08aab4ea0ba 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs @@ -1,24 +1,24 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "EmergencyActionItem")] pub fn emergency_action_item( - action_taker: &AuthorizedActionTakersWASM, - ) -> TokenConfigurationChangeItemWASM { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::EmergencyAction( + action_taker: &AuthorizedActionTakersWasm, + ) -> TokenConfigurationChangeItemWasm { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::EmergencyAction( action_taker.clone().into(), )) } #[wasm_bindgen(js_name = "EmergencyActionAdminGroupItem")] pub fn emergency_action_admin_group_item( - action_taker: &AuthorizedActionTakersWASM, - ) -> TokenConfigurationChangeItemWASM { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::EmergencyActionAdminGroup( + action_taker: &AuthorizedActionTakersWasm, + ) -> TokenConfigurationChangeItemWasm { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::EmergencyActionAdminGroup( action_taker.clone().into(), )) } diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs index 96f6974ed00..7f598423e7e 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs @@ -1,24 +1,24 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "FreezeItem")] pub fn freeze_item( - action_taker: &AuthorizedActionTakersWASM, - ) -> TokenConfigurationChangeItemWASM { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::Freeze( + action_taker: &AuthorizedActionTakersWasm, + ) -> TokenConfigurationChangeItemWasm { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::Freeze( action_taker.clone().into(), )) } #[wasm_bindgen(js_name = "FreezeAdminGroupItem")] pub fn freeze_admin_group_item( - action_taker: &AuthorizedActionTakersWASM, - ) -> TokenConfigurationChangeItemWASM { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::FreezeAdminGroup( + action_taker: &AuthorizedActionTakersWasm, + ) -> TokenConfigurationChangeItemWasm { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::FreezeAdminGroup( action_taker.clone().into(), )) } diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs index 5097f5c7888..025d9b2cfc1 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs @@ -1,13 +1,13 @@ -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::GroupContractPosition; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "MainControlGroupItem")] pub fn main_control_group_item(group_contract_position: Option) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::MainControlGroup( + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::MainControlGroup( group_contract_position, )) } diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs index 96fa4cfcf09..26857201b72 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs @@ -1,20 +1,20 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "ManualBurningItem")] - pub fn manual_burning_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::ManualBurning( + pub fn manual_burning_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::ManualBurning( action_taker.clone().into(), )) } #[wasm_bindgen(js_name = "ManualBurningAdminGroupItem")] - pub fn manual_burning_admin_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::ManualBurningAdminGroup( + pub fn manual_burning_admin_group_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::ManualBurningAdminGroup( action_taker.clone().into(), )) } diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs index 5c93c4b3466..3765496fae7 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs @@ -1,20 +1,20 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "ManualMintingItem")] - pub fn manual_minting_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::ManualMinting( + pub fn manual_minting_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::ManualMinting( action_taker.clone().into(), )) } #[wasm_bindgen(js_name = "ManualMintingAdminGroupItem")] - pub fn manual_minting_admin_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::ManualMintingAdminGroup( + pub fn manual_minting_admin_group_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::ManualMintingAdminGroup( action_taker.clone().into(), )) } diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs index b45168c3094..a45204058a2 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs @@ -1,21 +1,21 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration::trade_mode::TokenTradeModeWASM; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration::trade_mode::TokenTradeModeWasm; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "MarketplaceTradeModeItem")] - pub fn market_trade_mode_item(trade_mode: &TokenTradeModeWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::MarketplaceTradeMode( + pub fn market_trade_mode_item(trade_mode: &TokenTradeModeWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::MarketplaceTradeMode( trade_mode.clone().into(), )) } #[wasm_bindgen(js_name = "MarketplaceTradeModeControlGroupItem")] - pub fn market_trade_mode_control_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM( + pub fn market_trade_mode_control_group_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm( TokenConfigurationChangeItem::MarketplaceTradeModeControlGroup( action_taker.clone().into(), ), @@ -23,8 +23,8 @@ impl TokenConfigurationChangeItemWASM { } #[wasm_bindgen(js_name = "MarketplaceTradeModeAdminGroupItem")] - pub fn market_trade_mode_admin_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM( + pub fn market_trade_mode_admin_group_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm( TokenConfigurationChangeItem::MarketplaceTradeModeAdminGroup( action_taker.clone().into(), ), diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs index cecfecca05c..a7b85ac99a4 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs @@ -1,26 +1,26 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::balances::credits::TokenAmount; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "MaxSupplyItem")] pub fn max_supply_item(supply: Option) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::MaxSupply(supply)) + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::MaxSupply(supply)) } #[wasm_bindgen(js_name = "MaxSupplyControlGroupItem")] - pub fn max_supply_control_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::MaxSupplyControlGroup( + pub fn max_supply_control_group_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::MaxSupplyControlGroup( action_taker.clone().into(), )) } #[wasm_bindgen(js_name = "MaxSupplyAdminGroupItem")] - pub fn max_supply_admin_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::MaxSupplyAdminGroup( + pub fn max_supply_admin_group_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::MaxSupplyAdminGroup( action_taker.clone().into(), )) } diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs index 5098adb8ce5..9b782009522 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs @@ -1,22 +1,22 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "MintingAllowChoosingDestinationItem")] pub fn minting_allow_choosing_destination_item(flag: bool) -> Self { - TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItemWasm( TokenConfigurationChangeItem::MintingAllowChoosingDestination(flag), ) } #[wasm_bindgen(js_name = "MintingAllowChoosingDestinationControlGroupItem")] pub fn minting_allow_choosing_destination_control_group_item( - action_taker: &AuthorizedActionTakersWASM, + action_taker: &AuthorizedActionTakersWasm, ) -> Self { - TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItemWasm( TokenConfigurationChangeItem::MintingAllowChoosingDestinationControlGroup( action_taker.clone().into(), ), @@ -25,9 +25,9 @@ impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "MintingAllowChoosingDestinationAdminGroupItem")] pub fn minting_allow_choosing_destination_admin_group_item( - action_taker: &AuthorizedActionTakersWASM, + action_taker: &AuthorizedActionTakersWasm, ) -> Self { - TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItemWasm( TokenConfigurationChangeItem::MintingAllowChoosingDestinationAdminGroup( action_taker.clone().into(), ), diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs index 6373ed548ba..5ab9299771e 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs @@ -1,32 +1,32 @@ -use crate::identifier::IdentifierWASM; -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::identifier::IdentifierWasm; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use dpp::prelude::Identifier; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "NewTokensDestinationIdentityItem")] pub fn new_tokens_destination_identity_item( js_identity_id: &JsValue, - ) -> Result { + ) -> Result { let identity_id: Option = match js_identity_id.is_undefined() { true => None, - false => Some(IdentifierWASM::try_from(js_identity_id)?.into()), + false => Some(IdentifierWasm::try_from(js_identity_id)?.into()), }; - Ok(TokenConfigurationChangeItemWASM( + Ok(TokenConfigurationChangeItemWasm( TokenConfigurationChangeItem::NewTokensDestinationIdentity(identity_id), )) } #[wasm_bindgen(js_name = "NewTokensDestinationIdentityControlGroupItem")] pub fn new_tokens_destination_identity_control_group_item( - action_taker: &AuthorizedActionTakersWASM, + action_taker: &AuthorizedActionTakersWasm, ) -> Self { - TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItemWasm( TokenConfigurationChangeItem::NewTokensDestinationIdentityControlGroup( action_taker.clone().into(), ), @@ -35,9 +35,9 @@ impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "NewTokensDestinationIdentityAdminGroupItem")] pub fn new_tokens_destination_identity_admin_group_item( - action_taker: &AuthorizedActionTakersWASM, + action_taker: &AuthorizedActionTakersWasm, ) -> Self { - TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItemWasm( TokenConfigurationChangeItem::NewTokensDestinationIdentityAdminGroup( action_taker.clone().into(), ), diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs index 535b4badcfd..5adb0730883 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs @@ -1,11 +1,11 @@ -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "noChangeItem")] pub fn no_changes_item() -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::TokenConfigurationNoChange) + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::TokenConfigurationNoChange) } } diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs index 5cf626cff4f..bf55777f5dd 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs @@ -1,6 +1,6 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWASM; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWasm; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use crate::utils::IntoWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use dpp::data_contract::associated_token::token_perpetual_distribution::TokenPerpetualDistribution; @@ -8,7 +8,7 @@ use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "PerpetualDistributionConfigurationItem")] pub fn perpetual_distribution_item(js_perpetual_distribution_value: JsValue) -> Self { let perpetual_distribution_value: Option = @@ -16,23 +16,23 @@ impl TokenConfigurationChangeItemWASM { true => None, false => Some( js_perpetual_distribution_value - .to_wasm::("TokenPerpetualDistribution") + .to_wasm::("TokenPerpetualDistribution") .unwrap() .clone() .into(), ), }; - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::PerpetualDistribution( + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::PerpetualDistribution( perpetual_distribution_value, )) } #[wasm_bindgen(js_name = "PerpetualDistributionControlGroupItem")] pub fn perpetual_distribution_control_group_item( - action_taker: &AuthorizedActionTakersWASM, + action_taker: &AuthorizedActionTakersWasm, ) -> Self { - TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItemWasm( TokenConfigurationChangeItem::PerpetualDistributionControlGroup( action_taker.clone().into(), ), @@ -41,9 +41,9 @@ impl TokenConfigurationChangeItemWASM { #[wasm_bindgen(js_name = "PerpetualDistributionAdminGroupItem")] pub fn perpetual_distribution_admin_group_item( - action_taker: &AuthorizedActionTakersWASM, + action_taker: &AuthorizedActionTakersWasm, ) -> Self { - TokenConfigurationChangeItemWASM( + TokenConfigurationChangeItemWasm( TokenConfigurationChangeItem::PerpetualDistributionAdminGroup( action_taker.clone().into(), ), diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs index 6d966268c9f..380246558f5 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs @@ -1,20 +1,20 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWASM; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "UnfreezeItem")] - pub fn unfreeze_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::Unfreeze( + pub fn unfreeze_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::Unfreeze( action_taker.clone().into(), )) } #[wasm_bindgen(js_name = "UnfreezeAdminGroupItem")] - pub fn unfreeze_admin_group_item(action_taker: &AuthorizedActionTakersWASM) -> Self { - TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem::UnfreezeAdminGroup( + pub fn unfreeze_admin_group_item(action_taker: &AuthorizedActionTakersWasm) -> Self { + TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem::UnfreezeAdminGroup( action_taker.clone().into(), )) } diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs b/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs index 5bd43ce5606..28624860a7e 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs @@ -1,32 +1,32 @@ pub mod items; -use crate::identifier::IdentifierWASM; -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWASM; -use crate::token_configuration::configuration_convention::TokenConfigurationConventionWASM; -use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWASM; -use crate::token_configuration::trade_mode::TokenTradeModeWASM; +use crate::identifier::IdentifierWasm; +use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::token_configuration::configuration_convention::TokenConfigurationConventionWasm; +use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWasm; +use crate::token_configuration::trade_mode::TokenTradeModeWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name = "TokenConfigurationChangeItem")] -pub struct TokenConfigurationChangeItemWASM(TokenConfigurationChangeItem); +pub struct TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem); -impl From for TokenConfigurationChangeItem { - fn from(item: TokenConfigurationChangeItemWASM) -> Self { +impl From for TokenConfigurationChangeItem { + fn from(item: TokenConfigurationChangeItemWasm) -> Self { item.0 } } -impl From for TokenConfigurationChangeItemWASM { +impl From for TokenConfigurationChangeItemWasm { fn from(item: TokenConfigurationChangeItem) -> Self { - TokenConfigurationChangeItemWASM(item) + TokenConfigurationChangeItemWasm(item) } } #[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWASM { +impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(getter = __type)] pub fn type_name(&self) -> String { "TokenConfigurationChangeItem".to_string() @@ -128,100 +128,100 @@ impl TokenConfigurationChangeItemWASM { JsValue::from_str("TokenConfigurationNoChange") } TokenConfigurationChangeItem::Conventions(convention) => { - JsValue::from(TokenConfigurationConventionWASM::from(convention)) + JsValue::from(TokenConfigurationConventionWasm::from(convention)) } TokenConfigurationChangeItem::ConventionsControlGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::ConventionsAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::MaxSupply(amount) => JsValue::from(amount), TokenConfigurationChangeItem::MaxSupplyControlGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::MaxSupplyAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::PerpetualDistribution(perpetual_distribution) => { match perpetual_distribution { Some(token_perpetual_distribution) => JsValue::from( - TokenPerpetualDistributionWASM::from(token_perpetual_distribution), + TokenPerpetualDistributionWasm::from(token_perpetual_distribution), ), None => JsValue::null(), } } TokenConfigurationChangeItem::PerpetualDistributionControlGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::PerpetualDistributionAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::NewTokensDestinationIdentity(identifier) => { match identifier { - Some(id) => JsValue::from(IdentifierWASM::from(id)), + Some(id) => JsValue::from(IdentifierWasm::from(id)), None => JsValue::null(), } } TokenConfigurationChangeItem::NewTokensDestinationIdentityControlGroup( action_takers, - ) => JsValue::from(AuthorizedActionTakersWASM::from(action_takers)), + ) => JsValue::from(AuthorizedActionTakersWasm::from(action_takers)), TokenConfigurationChangeItem::NewTokensDestinationIdentityAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::MintingAllowChoosingDestination(flag) => { JsValue::from_bool(flag) } TokenConfigurationChangeItem::MintingAllowChoosingDestinationControlGroup( action_takers, - ) => JsValue::from(AuthorizedActionTakersWASM::from(action_takers)), + ) => JsValue::from(AuthorizedActionTakersWasm::from(action_takers)), TokenConfigurationChangeItem::MintingAllowChoosingDestinationAdminGroup( action_takers, - ) => JsValue::from(AuthorizedActionTakersWASM::from(action_takers)), + ) => JsValue::from(AuthorizedActionTakersWasm::from(action_takers)), TokenConfigurationChangeItem::ManualMinting(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::ManualMintingAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::ManualBurning(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::ManualBurningAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::Freeze(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::FreezeAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::Unfreeze(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::UnfreezeAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::DestroyFrozenFunds(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::DestroyFrozenFundsAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::EmergencyAction(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::EmergencyActionAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::MarketplaceTradeMode(trade_mode) => { - JsValue::from(TokenTradeModeWASM::from(trade_mode)) + JsValue::from(TokenTradeModeWasm::from(trade_mode)) } TokenConfigurationChangeItem::MarketplaceTradeModeControlGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::MarketplaceTradeModeAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWASM::from(action_takers)) + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) } TokenConfigurationChangeItem::MainControlGroup(group_contract_position) => { JsValue::from(group_contract_position) From 2814fe123c3a6978c5a0ca642f7466e8dd92735f Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Sat, 4 Oct 2025 20:37:21 +0700 Subject: [PATCH 04/44] ci: add to CI --- .github/package-filters/rs-packages-direct.yml | 3 +++ .github/package-filters/rs-packages-no-workflows.yml | 4 ++++ .github/package-filters/rs-packages.yml | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/.github/package-filters/rs-packages-direct.yml b/.github/package-filters/rs-packages-direct.yml index 5cb84f53283..8d8ba186099 100644 --- a/.github/package-filters/rs-packages-direct.yml +++ b/.github/package-filters/rs-packages-direct.yml @@ -25,6 +25,9 @@ dpp: wasm-dpp: - packages/wasm-dpp/** +wasm-dpp2: + - packages/wasm-dpp2/** + drive: - packages/rs-drive/** diff --git a/.github/package-filters/rs-packages-no-workflows.yml b/.github/package-filters/rs-packages-no-workflows.yml index 51c1f01fd43..c628f0d8edf 100644 --- a/.github/package-filters/rs-packages-no-workflows.yml +++ b/.github/package-filters/rs-packages-no-workflows.yml @@ -39,6 +39,10 @@ wasm-dpp: - packages/wasm-dpp/** - *dpp +wasm-dpp2: + - packages/wasm-dpp2/** + - *dpp + drive: &drive - packages/rs-drive/** - *dpp diff --git a/.github/package-filters/rs-packages.yml b/.github/package-filters/rs-packages.yml index 78129be673c..07e640b9001 100644 --- a/.github/package-filters/rs-packages.yml +++ b/.github/package-filters/rs-packages.yml @@ -48,6 +48,11 @@ wasm-dpp: - packages/wasm-dpp/** - *dpp +wasm-dpp2: + - .github/workflows/tests* + - packages/wasm-dpp2/** + - *dpp + drive: &drive - .github/workflows/tests* - packages/rs-drive/** From 24711ffe6c845f135a785ebc287137194e462186 Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Sat, 4 Oct 2025 22:36:20 +0700 Subject: [PATCH 05/44] chore: switch to local dpp --- Cargo.lock | 314 ++++-------------- packages/wasm-dpp2/Cargo.toml | 2 +- .../wasm-dpp2/src/document/methods/mod.rs | 1 + packages/wasm-dpp2/src/document/mod.rs | 4 + packages/wasm-dpp2/src/enums/network/mod.rs | 2 +- 5 files changed, 78 insertions(+), 245 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d0033e4cf3..5fc82800fa5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -665,32 +665,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "blsful" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d267776bf4742935d219fcdbdf590bed0f7e5fccdf5bd168fb30b2543a0b2b24" -dependencies = [ - "anyhow", - "blstrs_plus", - "hex", - "hkdf", - "merlin", - "pairing", - "rand 0.8.5", - "rand_chacha 0.3.1", - "rand_core 0.6.4", - "serde", - "serde_bare", - "sha2", - "sha3", - "subtle", - "thiserror 2.0.16", - "uint-zigzag", - "vsss-rs", - "zeroize", -] - [[package]] name = "blst" version = "0.3.12" @@ -1345,7 +1319,7 @@ dependencies = [ "dapi-grpc-macros", "futures-core", "getrandom 0.2.16", - "platform-version 2.1.0-dev.8", + "platform-version", "prost 0.14.1", "serde", "serde_bytes", @@ -1405,7 +1379,7 @@ dependencies = [ name = "dash-context-provider" version = "2.1.0-dev.8" dependencies = [ - "dpp 2.1.0-dev.8", + "dpp", "drive", "hex", "serde", @@ -1432,7 +1406,7 @@ dependencies = [ "clap", "dapi-grpc", "dash-sdk", - "dpp 2.1.0-dev.8", + "dpp", "drive-proof-verifier", "rpassword", "rs-dapi-client", @@ -1458,7 +1432,7 @@ dependencies = [ "dash-context-provider", "derive_more 1.0.0", "dotenvy", - "dpp 2.1.0-dev.8", + "dpp", "drive", "drive-proof-verifier", "envy", @@ -1492,11 +1466,11 @@ dependencies = [ "anyhow", "async-trait", "bincode 1.3.3", - "blsful 3.0.0-pre8", + "blsful", "clap", "crossterm", - "dashcore 0.40.0", - "dashcore_hashes 0.40.0", + "dashcore", + "dashcore_hashes", "hex", "hickory-resolver", "indexmap 2.11.3", @@ -1519,7 +1493,7 @@ source = "git+https://github.com/dashpay/rust-dashcore?rev=befd0356bebfcd0d06d10 dependencies = [ "cbindgen 0.29.0", "dash-spv", - "dashcore 0.40.0", + "dashcore", "env_logger 0.10.2", "hex", "key-wallet", @@ -1535,27 +1509,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "dashcore" -version = "0.39.6" -source = "git+https://github.com/dashpay/rust-dashcore?tag=v0.39.6#51df58f5d5d499f5ee80ab17076ff70b5347c7db" -dependencies = [ - "anyhow", - "base64-compat", - "bech32", - "bitflags 2.9.4", - "blake3", - "blsful 3.0.0", - "dashcore-private 0.39.6", - "dashcore_hashes 0.39.6", - "hex", - "hex_lit", - "rustversion", - "secp256k1", - "serde", - "thiserror 2.0.16", -] - [[package]] name = "dashcore" version = "0.40.0" @@ -1568,10 +1521,10 @@ dependencies = [ "bincode_derive", "bitvec", "blake3", - "blsful 3.0.0-pre8", + "blsful", "dash-network", - "dashcore-private 0.40.0", - "dashcore_hashes 0.40.0", + "dashcore-private", + "dashcore_hashes", "ed25519-dalek", "hex", "hex_lit", @@ -1582,11 +1535,6 @@ dependencies = [ "thiserror 2.0.16", ] -[[package]] -name = "dashcore-private" -version = "0.39.6" -source = "git+https://github.com/dashpay/rust-dashcore?tag=v0.39.6#51df58f5d5d499f5ee80ab17076ff70b5347c7db" - [[package]] name = "dashcore-private" version = "0.40.0" @@ -1611,7 +1559,7 @@ version = "0.40.0" source = "git+https://github.com/dashpay/rust-dashcore?rev=befd0356bebfcd0d06d1028d8a03bfa4c78bd219#befd0356bebfcd0d06d1028d8a03bfa4c78bd219" dependencies = [ "bincode 2.0.0-rc.3", - "dashcore 0.40.0", + "dashcore", "hex", "key-wallet", "serde", @@ -1620,23 +1568,13 @@ dependencies = [ "serde_with 2.3.3", ] -[[package]] -name = "dashcore_hashes" -version = "0.39.6" -source = "git+https://github.com/dashpay/rust-dashcore?tag=v0.39.6#51df58f5d5d499f5ee80ab17076ff70b5347c7db" -dependencies = [ - "dashcore-private 0.39.6", - "secp256k1", - "serde", -] - [[package]] name = "dashcore_hashes" version = "0.40.0" source = "git+https://github.com/dashpay/rust-dashcore?rev=befd0356bebfcd0d06d1028d8a03bfa4c78bd219#befd0356bebfcd0d06d1028d8a03bfa4c78bd219" dependencies = [ "bincode 2.0.0-rc.3", - "dashcore-private 0.40.0", + "dashcore-private", "rs-x11-hash", "secp256k1", "serde", @@ -1646,8 +1584,8 @@ dependencies = [ name = "dashpay-contract" version = "2.1.0-dev.8" dependencies = [ - "platform-value 2.1.0-dev.8", - "platform-version 2.1.0-dev.8", + "platform-value", + "platform-version", "serde_json", "thiserror 2.0.16", ] @@ -1661,8 +1599,8 @@ dependencies = [ "feature-flags-contract", "keyword-search-contract", "masternode-reward-shares-contract", - "platform-value 2.1.0-dev.8", - "platform-version 2.1.0-dev.8", + "platform-value", + "platform-version", "serde_json", "thiserror 2.0.16", "token-history-contract", @@ -1803,52 +1741,12 @@ checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" name = "dpns-contract" version = "2.1.0-dev.8" dependencies = [ - "platform-value 2.1.0-dev.8", - "platform-version 2.1.0-dev.8", + "platform-value", + "platform-version", "serde_json", "thiserror 2.0.16", ] -[[package]] -name = "dpp" -version = "2.0.1" -source = "git+https://github.com/owl352/platform?branch=v2.0.1#f6d7390361861f5a62b7cb413310b5ec42c26387" -dependencies = [ - "anyhow", - "async-trait", - "base64 0.22.1", - "bincode 2.0.0-rc.3", - "bincode_derive", - "bs58", - "byteorder", - "chrono", - "dashcore 0.39.6", - "derive_more 1.0.0", - "env_logger 0.11.8", - "getrandom 0.2.16", - "hex", - "indexmap 2.11.3", - "integer-encoding", - "itertools 0.13.0", - "lazy_static", - "nohash-hasher", - "num_enum 0.7.4", - "once_cell", - "platform-serialization 2.0.1", - "platform-serialization-derive 2.0.1", - "platform-value 2.0.1", - "platform-version 2.0.1", - "platform-versioning 2.0.1", - "rand 0.8.5", - "regex", - "serde", - "serde_json", - "serde_repr", - "sha2", - "strum 0.26.3", - "thiserror 2.0.16", -] - [[package]] name = "dpp" version = "2.1.0-dev.8" @@ -1865,11 +1763,11 @@ dependencies = [ "chrono-tz", "ciborium", "dash-spv", - "dashcore 0.40.0", + "dashcore", "dashcore-rpc", "data-contracts", "derive_more 1.0.0", - "dpp 2.1.0-dev.8", + "dpp", "env_logger 0.11.8", "getrandom 0.2.16", "hex", @@ -1885,11 +1783,11 @@ dependencies = [ "nohash-hasher", "num_enum 0.7.4", "once_cell", - "platform-serialization 2.1.0-dev.8", - "platform-serialization-derive 2.1.0-dev.8", - "platform-value 2.1.0-dev.8", - "platform-version 2.1.0-dev.8", - "platform-versioning 2.1.0-dev.8", + "platform-serialization", + "platform-serialization-derive", + "platform-value", + "platform-version", + "platform-versioning", "pretty_assertions", "rand 0.8.5", "regex", @@ -1919,14 +1817,14 @@ dependencies = [ "ciborium", "criterion", "derive_more 1.0.0", - "dpp 2.1.0-dev.8", + "dpp", "enum-map", "grovedb", "grovedb-costs", "grovedb-epoch-based-storage-flags", "grovedb-path", "grovedb-storage", - "grovedb-version 3.0.0 (git+https://github.com/dashpay/grovedb?rev=1ecedf530fbc5b5e12edf1bc607bd288c187ddde)", + "grovedb-version", "hex", "indexmap 2.11.3", "integer-encoding", @@ -1936,7 +1834,7 @@ dependencies = [ "nohash-hasher", "once_cell", "parking_lot", - "platform-version 2.1.0-dev.8", + "platform-version", "rand 0.8.5", "serde", "serde_json", @@ -1965,7 +1863,7 @@ dependencies = [ "delegate", "derive_more 1.0.0", "dotenvy", - "dpp 2.1.0-dev.8", + "dpp", "drive", "drive-abci", "envy", @@ -1978,7 +1876,7 @@ dependencies = [ "metrics", "metrics-exporter-prometheus", "mockall", - "platform-version 2.1.0-dev.8", + "platform-version", "prost 0.14.1", "rand 0.8.5", "regex", @@ -2008,12 +1906,12 @@ dependencies = [ "dapi-grpc", "dash-context-provider", "derive_more 1.0.0", - "dpp 2.1.0-dev.8", + "dpp", "drive", "hex", "indexmap 2.11.3", - "platform-serialization 2.1.0-dev.8", - "platform-serialization-derive 2.1.0-dev.8", + "platform-serialization", + "platform-serialization-derive", "serde", "serde_json", "tenderdash-abci", @@ -2258,8 +2156,8 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" name = "feature-flags-contract" version = "2.1.0-dev.8" dependencies = [ - "platform-value 2.1.0-dev.8", - "platform-version 2.1.0-dev.8", + "platform-value", + "platform-version", "serde_json", "thiserror 2.0.16", ] @@ -2585,7 +2483,7 @@ dependencies = [ "grovedb-merk", "grovedb-path", "grovedb-storage", - "grovedb-version 3.0.0 (git+https://github.com/dashpay/grovedb?rev=1ecedf530fbc5b5e12edf1bc607bd288c187ddde)", + "grovedb-version", "grovedb-visualize", "grovedbg-types", "hex", @@ -2640,7 +2538,7 @@ dependencies = [ "grovedb-costs", "grovedb-path", "grovedb-storage", - "grovedb-version 3.0.0 (git+https://github.com/dashpay/grovedb?rev=1ecedf530fbc5b5e12edf1bc607bd288c187ddde)", + "grovedb-version", "grovedb-visualize", "hex", "indexmap 2.11.3", @@ -2677,16 +2575,6 @@ dependencies = [ "thiserror 2.0.16", ] -[[package]] -name = "grovedb-version" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d61d27c76d49758b365a9e4a9da7f995f976b9525626bf645aef258024defd2" -dependencies = [ - "thiserror 2.0.16", - "versioned-feature-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "grovedb-version" version = "3.0.0" @@ -3504,9 +3392,9 @@ dependencies = [ "bitflags 2.9.4", "bs58", "dash-network", - "dashcore 0.40.0", - "dashcore-private 0.40.0", - "dashcore_hashes 0.40.0", + "dashcore", + "dashcore-private", + "dashcore_hashes", "getrandom 0.2.16", "hex", "hkdf", @@ -3526,7 +3414,7 @@ source = "git+https://github.com/dashpay/rust-dashcore?rev=befd0356bebfcd0d06d10 dependencies = [ "cbindgen 0.29.0", "dash-network", - "dashcore 0.40.0", + "dashcore", "hex", "key-wallet", "key-wallet-manager", @@ -3542,8 +3430,8 @@ source = "git+https://github.com/dashpay/rust-dashcore?rev=befd0356bebfcd0d06d10 dependencies = [ "async-trait", "bincode 2.0.0-rc.3", - "dashcore 0.40.0", - "dashcore_hashes 0.40.0", + "dashcore", + "dashcore_hashes", "key-wallet", "secp256k1", "zeroize", @@ -3554,8 +3442,8 @@ name = "keyword-search-contract" version = "2.1.0-dev.8" dependencies = [ "base58", - "platform-value 2.1.0-dev.8", - "platform-version 2.1.0-dev.8", + "platform-value", + "platform-version", "serde_json", "thiserror 2.0.16", ] @@ -3705,8 +3593,8 @@ dependencies = [ name = "masternode-reward-shares-contract" version = "2.1.0-dev.8" dependencies = [ - "platform-value 2.1.0-dev.8", - "platform-version 2.1.0-dev.8", + "platform-value", + "platform-version", "serde_json", "thiserror 2.0.16", ] @@ -4413,32 +4301,12 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" -[[package]] -name = "platform-serialization" -version = "2.0.1" -source = "git+https://github.com/owl352/platform?branch=v2.0.1#f6d7390361861f5a62b7cb413310b5ec42c26387" -dependencies = [ - "bincode 2.0.0-rc.3", - "platform-version 2.0.1", -] - [[package]] name = "platform-serialization" version = "2.1.0-dev.8" dependencies = [ "bincode 2.0.0-rc.3", - "platform-version 2.1.0-dev.8", -] - -[[package]] -name = "platform-serialization-derive" -version = "2.0.1" -source = "git+https://github.com/owl352/platform?branch=v2.0.1#f6d7390361861f5a62b7cb413310b5ec42c26387" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", - "virtue 0.0.17", + "platform-version", ] [[package]] @@ -4451,25 +4319,6 @@ dependencies = [ "virtue 0.0.17", ] -[[package]] -name = "platform-value" -version = "2.0.1" -source = "git+https://github.com/owl352/platform?branch=v2.0.1#f6d7390361861f5a62b7cb413310b5ec42c26387" -dependencies = [ - "base64 0.22.1", - "bincode 2.0.0-rc.3", - "bs58", - "hex", - "indexmap 2.11.3", - "platform-serialization 2.0.1", - "platform-version 2.0.1", - "rand 0.8.5", - "serde", - "serde_json", - "thiserror 2.0.16", - "treediff", -] - [[package]] name = "platform-value" version = "2.1.0-dev.8" @@ -4480,8 +4329,8 @@ dependencies = [ "ciborium", "hex", "indexmap 2.11.3", - "platform-serialization 2.1.0-dev.8", - "platform-version 2.1.0-dev.8", + "platform-serialization", + "platform-version", "rand 0.8.5", "serde", "serde_json", @@ -4497,39 +4346,17 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "platform-version" -version = "2.0.1" -source = "git+https://github.com/owl352/platform?branch=v2.0.1#f6d7390361861f5a62b7cb413310b5ec42c26387" -dependencies = [ - "bincode 2.0.0-rc.3", - "grovedb-version 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "once_cell", - "thiserror 2.0.16", - "versioned-feature-core 1.0.0 (git+https://github.com/dashpay/versioned-feature-core)", -] - [[package]] name = "platform-version" version = "2.1.0-dev.8" dependencies = [ "bincode 2.0.0-rc.3", - "grovedb-version 3.0.0 (git+https://github.com/dashpay/grovedb?rev=1ecedf530fbc5b5e12edf1bc607bd288c187ddde)", + "grovedb-version", "once_cell", "thiserror 2.0.16", "versioned-feature-core 1.0.0 (git+https://github.com/dashpay/versioned-feature-core)", ] -[[package]] -name = "platform-versioning" -version = "2.0.1" -source = "git+https://github.com/owl352/platform?branch=v2.0.1#f6d7390361861f5a62b7cb413310b5ec42c26387" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", -] - [[package]] name = "platform-versioning" version = "2.1.0-dev.8" @@ -4543,8 +4370,8 @@ dependencies = [ name = "platform-wallet" version = "2.1.0-dev.8" dependencies = [ - "dashcore 0.40.0", - "dpp 2.1.0-dev.8", + "dashcore", + "dpp", "indexmap 2.11.3", "key-wallet", "key-wallet-manager", @@ -5282,7 +5109,7 @@ dependencies = [ "arc-swap", "async-trait", "dash-context-provider", - "dpp 2.1.0-dev.8", + "dpp", "futures", "hex", "lru", @@ -5932,7 +5759,7 @@ version = "2.1.0-dev.8" dependencies = [ "base64 0.22.1", "bincode 2.0.0-rc.3", - "dpp 2.1.0-dev.8", + "dpp", "hex", "tracing", ] @@ -6028,13 +5855,13 @@ name = "strategy-tests" version = "2.1.0-dev.8" dependencies = [ "bincode 2.0.0-rc.3", - "dpp 2.1.0-dev.8", + "dpp", "drive", "futures", "hex", - "platform-serialization 2.1.0-dev.8", - "platform-serialization-derive 2.1.0-dev.8", - "platform-version 2.1.0-dev.8", + "platform-serialization", + "platform-serialization-derive", + "platform-version", "rand 0.8.5", "rocksdb 0.23.0", "serde_json", @@ -6433,8 +6260,8 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" name = "token-history-contract" version = "2.1.0-dev.8" dependencies = [ - "platform-value 2.1.0-dev.8", - "platform-version 2.1.0-dev.8", + "platform-value", + "platform-version", "serde_json", "thiserror 2.0.16", ] @@ -7107,8 +6934,8 @@ dependencies = [ name = "wallet-utils-contract" version = "2.1.0-dev.8" dependencies = [ - "platform-value 2.1.0-dev.8", - "platform-version 2.1.0-dev.8", + "platform-value", + "platform-version", "serde_json", "thiserror 2.0.16", ] @@ -7250,7 +7077,7 @@ dependencies = [ "anyhow", "async-trait", "bincode 2.0.0-rc.3", - "dpp 2.1.0-dev.8", + "dpp", "hex", "itertools 0.13.0", "js-sys", @@ -7274,7 +7101,7 @@ dependencies = [ "anyhow", "bincode 2.0.0-rc.3", "bincode_derive", - "dpp 2.0.1", + "dpp", "hex", "js-sys", "serde", @@ -7295,7 +7122,7 @@ dependencies = [ "ciborium", "console_error_panic_hook", "criterion", - "dpp 2.1.0-dev.8", + "dpp", "drive", "hex", "indexmap 2.11.3", @@ -7337,7 +7164,7 @@ dependencies = [ "hmac", "js-sys", "once_cell", - "platform-value 2.1.0-dev.8", + "platform-value", "rand 0.8.5", "rs-dapi-client", "rs-sdk-trusted-context-provider", @@ -7352,6 +7179,7 @@ dependencies = [ "tracing-wasm", "wasm-bindgen", "wasm-bindgen-futures", + "wasm-dpp2", "wasm-sdk", "web-sys", "wee_alloc", @@ -7889,8 +7717,8 @@ name = "withdrawals-contract" version = "2.1.0-dev.8" dependencies = [ "num_enum 0.5.11", - "platform-value 2.1.0-dev.8", - "platform-version 2.1.0-dev.8", + "platform-value", + "platform-version", "serde", "serde_json", "serde_repr", diff --git a/packages/wasm-dpp2/Cargo.toml b/packages/wasm-dpp2/Cargo.toml index 40539121b64..0837c26a20d 100644 --- a/packages/wasm-dpp2/Cargo.toml +++ b/packages/wasm-dpp2/Cargo.toml @@ -11,7 +11,7 @@ talc = { version = "=4.4.2", default-features = false, features = ["lock_api"] } bincode = "=2.0.0-rc.3" bincode_derive = "=2.0.0-rc.3" wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] } -dpp = { git = "https://github.com/owl352/platform", branch = "v2.0.1", default-features = false, features = [ +dpp = { path = "../rs-dpp", default-features = false, features = [ "state-transition-signing", "document-json-conversion", "identity-serialization", diff --git a/packages/wasm-dpp2/src/document/methods/mod.rs b/packages/wasm-dpp2/src/document/methods/mod.rs index db76f30cffd..9bca4bd2fd1 100644 --- a/packages/wasm-dpp2/src/document/methods/mod.rs +++ b/packages/wasm-dpp2/src/document/methods/mod.rs @@ -84,6 +84,7 @@ impl DocumentWasm { created_at_core_block_height: None, updated_at_core_block_height: None, transferred_at_core_block_height: None, + creator_id: None, }) } diff --git a/packages/wasm-dpp2/src/document/mod.rs b/packages/wasm-dpp2/src/document/mod.rs index 326fa00f7b9..2d5eb39d683 100644 --- a/packages/wasm-dpp2/src/document/mod.rs +++ b/packages/wasm-dpp2/src/document/mod.rs @@ -28,6 +28,7 @@ pub struct DocumentWasm { updated_at_core_block_height: Option, transferred_at_core_block_height: Option, entropy: Option<[u8; 32]>, + creator_id: Option, } impl From for Document { @@ -46,6 +47,7 @@ impl From for Document { created_at_core_block_height: wasm_doc.created_at_core_block_height, updated_at_core_block_height: wasm_doc.updated_at_core_block_height, transferred_at_core_block_height: wasm_doc.transferred_at_core_block_height, + creator_id: wasm_doc.creator_id.map(Into::into), }) } } @@ -69,6 +71,7 @@ impl From for DocumentWasm { updated_at_core_block_height: doc.updated_at_core_block_height(), transferred_at_core_block_height: doc.transferred_at_core_block_height(), entropy: None, + creator_id: doc.creator_id().map(Into::into), } } } @@ -97,6 +100,7 @@ impl DocumentWasm { updated_at_core_block_height: document.updated_at_core_block_height(), transferred_at_core_block_height: document.transferred_at_core_block_height(), entropy, + creator_id: document.creator_id().map(Into::into), } } } diff --git a/packages/wasm-dpp2/src/enums/network/mod.rs b/packages/wasm-dpp2/src/enums/network/mod.rs index 1bd5b75b2b2..8e09b7a5bac 100644 --- a/packages/wasm-dpp2/src/enums/network/mod.rs +++ b/packages/wasm-dpp2/src/enums/network/mod.rs @@ -1,4 +1,4 @@ -use dpp::dashcore::network::constants::Network; +use dpp::dashcore::Network; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "Network")] From bc476ce0b6c8d645aef289ad4fa6011b24c964f2 Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Mon, 6 Oct 2025 11:50:27 +0700 Subject: [PATCH 06/44] feat: integrate wasm-dpp2 entities --- .../src/batch/token_transition/mod.rs | 24 +- packages/wasm-dpp2/src/identifier/mod.rs | 4 +- packages/wasm-dpp2/src/identity/mod.rs | 46 ++- .../credit_withdrawal_transition/mod.rs | 5 +- packages/wasm-sdk/Cargo.toml | 1 + packages/wasm-sdk/src/dpp.rs | 351 ------------------ packages/wasm-sdk/src/lib.rs | 3 +- .../wasm-sdk/src/queries/data_contract.rs | 2 +- packages/wasm-sdk/src/queries/identity.rs | 68 ++-- packages/wasm-sdk/src/verify.rs | 2 +- 10 files changed, 83 insertions(+), 423 deletions(-) delete mode 100644 packages/wasm-sdk/src/dpp.rs diff --git a/packages/wasm-dpp2/src/batch/token_transition/mod.rs b/packages/wasm-dpp2/src/batch/token_transition/mod.rs index 5ac5a71470b..399f77853f3 100644 --- a/packages/wasm-dpp2/src/batch/token_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_transition/mod.rs @@ -75,13 +75,11 @@ impl TokenTransitionWasm { .clone(), ))) } - "TokenFreezeTransition" => { - Ok(TokenTransition::from(TokenFreezeTransition::from( - js_transition - .to_wasm::("TokenFreezeTransition")? - .clone(), - ))) - } + "TokenFreezeTransition" => Ok(TokenTransition::from(TokenFreezeTransition::from( + js_transition + .to_wasm::("TokenFreezeTransition")? + .clone(), + ))), "TokenDestroyFrozenFundsTransition" => Ok(TokenTransition::from( TokenDestroyFrozenFundsTransition::from( js_transition @@ -91,13 +89,11 @@ impl TokenTransitionWasm { .clone(), ), )), - "TokenClaimTransition" => { - Ok(TokenTransition::from(TokenClaimTransition::from( - js_transition - .to_wasm::("TokenClaimTransition")? - .clone(), - ))) - } + "TokenClaimTransition" => Ok(TokenTransition::from(TokenClaimTransition::from( + js_transition + .to_wasm::("TokenClaimTransition")? + .clone(), + ))), "TokenBurnTransition" => Ok(TokenTransition::from(TokenBurnTransition::from( js_transition .to_wasm::("TokenBurnTransition")? diff --git a/packages/wasm-dpp2/src/identifier/mod.rs b/packages/wasm-dpp2/src/identifier/mod.rs index e28a9891385..01f778b8db3 100644 --- a/packages/wasm-dpp2/src/identifier/mod.rs +++ b/packages/wasm-dpp2/src/identifier/mod.rs @@ -53,9 +53,7 @@ impl TryFrom for IdentifierWasm { match value.is_object() { true => match get_class_type(&value) { Ok(class_type) => match class_type.as_str() { - "Identifier" => { - Ok(value.to_wasm::("Identifier")?.clone()) - } + "Identifier" => Ok(value.to_wasm::("Identifier")?.clone()), "" => Ok(identifier_from_js_value(&value)?.into()), _ => Err(Self::Error::from_str(&format!( "Invalid type of data for identifier (passed {})", diff --git a/packages/wasm-dpp2/src/identity/mod.rs b/packages/wasm-dpp2/src/identity/mod.rs index 8361803a117..d533fc867fc 100644 --- a/packages/wasm-dpp2/src/identity/mod.rs +++ b/packages/wasm-dpp2/src/identity/mod.rs @@ -2,12 +2,15 @@ use crate::identifier::IdentifierWasm; use crate::identity_public_key::IdentityPublicKeyWasm; use crate::utils::WithJsError; use dpp::identity::accessors::{IdentityGettersV0, IdentitySettersV0}; -use dpp::identity::{Identity, KeyID}; +use dpp::identity::{self, Identity, KeyID}; +use dpp::platform_value::ReplacementType; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; use dpp::platform_value::string_encoding::{decode, encode}; use dpp::prelude::IdentityPublicKey; -use dpp::serialization::{PlatformDeserializable, PlatformSerializable}; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable, ValueConvertible}; use dpp::version::PlatformVersion; +use serde_json::Value as JsonValue; +use serde_wasm_bindgen::to_value; use std::collections::BTreeMap; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; @@ -136,6 +139,45 @@ impl IdentityWasm { )) } + fn cleaned_json_value(&self) -> Result { + let mut value = self.0.to_object().with_js_error()?; + + value + .replace_at_paths( + identity::IDENTIFIER_FIELDS_RAW_OBJECT, + ReplacementType::TextBase58, + ) + .map_err(|e| JsValue::from_str(&e.to_string()))?; + + if let Some(public_keys) = value + .get_optional_array_mut_ref(identity::property_names::PUBLIC_KEYS) + .map_err(|e| JsValue::from_str(&e.to_string()))? + { + for key in public_keys.iter_mut() { + key.replace_at_paths( + identity::identity_public_key::BINARY_DATA_FIELDS, + ReplacementType::TextBase64, + ) + .map_err(|e| JsValue::from_str(&e.to_string()))?; + } + } + + value + .try_into_validating_json() + .map_err(|e| JsValue::from_str(&e.to_string())) + } + + #[wasm_bindgen(js_name = "toObject")] + pub fn to_object(&self) -> Result { + let json_value = self.cleaned_json_value()?; + to_value(&json_value).map_err(|e| JsValue::from_str(&e.to_string())) + } + + #[wasm_bindgen(js_name = "toJSON")] + pub fn to_json(&self) -> Result { + self.to_object() + } + #[wasm_bindgen(js_name = "fromBytes")] pub fn from_bytes(bytes: Vec) -> Result { match Identity::deserialize_from_bytes(bytes.as_slice()).with_js_error() { diff --git a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs index 64ce8a2cbc7..37b8806c109 100644 --- a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs @@ -137,9 +137,8 @@ impl IdentityCreditWithdrawalTransitionWasm { match js_script.is_undefined() { true => self.0.set_output_script(None), false => { - let script: CoreScriptWasm = js_script - .to_wasm::("CoreScript")? - .clone(); + let script: CoreScriptWasm = + js_script.to_wasm::("CoreScript")?.clone(); self.0.set_output_script(Some(script.clone().into())) } }; diff --git a/packages/wasm-sdk/Cargo.toml b/packages/wasm-sdk/Cargo.toml index 00aa7f1a246..3fe641bf978 100644 --- a/packages/wasm-sdk/Cargo.toml +++ b/packages/wasm-sdk/Cargo.toml @@ -65,6 +65,7 @@ dapi-grpc = { path = "../dapi-grpc" } rs-dapi-client = { path = "../rs-dapi-client" } hmac = { version = "0.12" } sha2 = { version = "0.10" } +wasm-dpp2 = { path = "../wasm-dpp2" } [dev-dependencies] wasm-sdk = { path = ".", features = ["mocks", "all-system-contracts"] } diff --git a/packages/wasm-sdk/src/dpp.rs b/packages/wasm-sdk/src/dpp.rs deleted file mode 100644 index cd14ea733b5..00000000000 --- a/packages/wasm-sdk/src/dpp.rs +++ /dev/null @@ -1,351 +0,0 @@ -use dash_sdk::dpp::identity::accessors::{IdentityGettersV0, IdentitySettersV0}; -use dash_sdk::dpp::platform_value::ReplacementType; -use dash_sdk::dpp::serialization::PlatformDeserializable; -use dash_sdk::dpp::serialization::ValueConvertible; - -use crate::WasmSdkError; -use dash_sdk::dpp::dashcore::hashes::serde::Serialize; -use dash_sdk::dpp::data_contract::accessors::v0::DataContractV0Getters; -use dash_sdk::dpp::data_contract::conversion::json::DataContractJsonConversionMethodsV0; -use dash_sdk::dpp::version::PlatformVersion; -use dash_sdk::platform::{DataContract, Identity}; -use platform_value::string_encoding::Encoding; -use wasm_bindgen::prelude::*; -use web_sys::js_sys; - -#[wasm_bindgen] -#[derive(Clone)] -pub struct IdentityWasm { - inner: Identity, - // metadata: Option, -} - -impl From for Identity { - fn from(identity: IdentityWasm) -> Self { - identity.inner - } -} - -impl From for IdentityWasm { - fn from(identity: Identity) -> Self { - Self { - inner: identity, - // metadata: None, - } - } -} -#[wasm_bindgen] -impl IdentityWasm { - #[wasm_bindgen(constructor)] - pub fn new(platform_version: u32) -> Result { - let platform_version = &PlatformVersion::get(platform_version).map_err(|e| { - WasmSdkError::invalid_argument(format!( - "unknown platform version {platform_version}: {e}" - )) - })?; - - let identity = Identity::default_versioned(platform_version)?; - - Ok(identity.into()) - } - // - // #[wasm_bindgen(js_name=getId)] - // pub fn get_id(&self) -> IdentifierWrapper { - // self.inner.id().into() - // } - // - // #[wasm_bindgen(js_name=setId)] - // pub fn set_id(&mut self, id: IdentifierWrapper) { - // self.inner.set_id(id.into()); - // } - - #[wasm_bindgen(js_name=setPublicKeys)] - pub fn set_public_keys(&mut self, public_keys: js_sys::Array) -> Result { - if public_keys.length() == 0 { - return Err(WasmSdkError::invalid_argument(format!("Setting public keys failed. The input ('{}') is invalid. You must use array of PublicKeys", public_keys.to_string()))); - } - - // let public_keys = public_keys - // .iter() - // .map(|key| { - // key.to_wasm::("IdentityPublicKey") - // .map(|key| { - // let key = IdentityPublicKey::from(key.to_owned()); - // (key.id(), key) - // }) - // }) - // .collect::>()?; - // - // self.inner.set_public_keys(public_keys); - - Ok(self.inner.public_keys().len()) - } - // - // #[wasm_bindgen(js_name=getPublicKeys)] - // pub fn get_public_keys(&self) -> Vec { - // self.inner - // .public_keys() - // .iter() - // .map(|(_, k)| k.to_owned()) - // .map(IdentityPublicKeyWasm::from) - // .map(JsValue::from) - // .collect() - // } - // - // #[wasm_bindgen(js_name=getPublicKeyById)] - // pub fn get_public_key_by_id(&self, key_id: u32) -> Option { - // let key_id = key_id as KeyID; - // self.inner - // .get_public_key_by_id(key_id) - // .map(IdentityPublicKey::to_owned) - // .map(Into::into) - // } - - #[wasm_bindgen(getter)] - pub fn balance(&self) -> f64 { - self.inner.balance() as f64 - } - - #[wasm_bindgen(js_name=getBalance)] - pub fn get_balance(&self) -> f64 { - self.inner.balance() as f64 - } - - #[wasm_bindgen(js_name=setBalance)] - pub fn set_balance(&mut self, balance: f64) { - self.inner.set_balance(balance as u64); - } - - #[wasm_bindgen(js_name=increaseBalance)] - pub fn increase_balance(&mut self, amount: f64) -> f64 { - self.inner.increase_balance(amount as u64) as f64 - } - - #[wasm_bindgen(js_name=reduceBalance)] - pub fn reduce_balance(&mut self, amount: f64) -> f64 { - self.inner.reduce_balance(amount as u64) as f64 - } - - #[wasm_bindgen(js_name=setRevision)] - pub fn set_revision(&mut self, revision: f64) { - self.inner.set_revision(revision as u64); - } - - #[wasm_bindgen(js_name=getRevision)] - pub fn get_revision(&self) -> f64 { - self.inner.revision() as f64 - } - // - // #[wasm_bindgen(js_name=setMetadata)] - // pub fn set_metadata(&mut self, metadata: JsValue) -> Result<(), JsValue> { - // if !metadata.is_falsy() { - // let metadata = metadata.to_wasm::("Metadata")?.to_owned(); - // self.metadata = Some(metadata.into()); - // } - // - // Ok(()) - // } - // - // #[wasm_bindgen(js_name=getMetadata)] - // pub fn get_metadata(&self) -> Option { - // self.metadata.map(|metadata| metadata.to_owned().into()) - // } - - // #[wasm_bindgen(js_name=from)] - // pub fn from(object: JsValue) -> Self { - // let i: Identity = serde_json::from_str(&object.as_string().unwrap()).unwrap(); - // IdentityWasm { - // inner: i, - // metadata: None, - // } - // } - - #[wasm_bindgen(js_name=toJSON)] - pub fn to_json(&self) -> Result { - let mut value = self.inner.to_object().map_err(|e| { - WasmSdkError::serialization(format!("failed to convert identity to Object: {e}")) - })?; - - value - .replace_at_paths( - dash_sdk::dpp::identity::IDENTIFIER_FIELDS_RAW_OBJECT, - ReplacementType::TextBase58, - ) - .map_err(|e| WasmSdkError::serialization(e.to_string()))?; - - // Monkey patch public keys data to be deserializable - let public_keys = value - .get_array_mut_ref(dash_sdk::dpp::identity::property_names::PUBLIC_KEYS) - .map_err(|e| WasmSdkError::serialization(e.to_string()))?; - - for key in public_keys.iter_mut() { - key.replace_at_paths( - dash_sdk::dpp::identity::identity_public_key::BINARY_DATA_FIELDS, - ReplacementType::TextBase64, - ) - .map_err(|e| WasmSdkError::serialization(e.to_string()))?; - } - - let json = value - .try_into_validating_json() - .map_err(|e| WasmSdkError::serialization(e.to_string()))? - .to_string(); - - js_sys::JSON::parse(&json) - .map_err(|e| WasmSdkError::serialization(format!("failed to parse JSON: {:?}", e))) - } - // - // #[wasm_bindgen(js_name=toObject)] - // pub fn to_object(&self) -> Result { - // let js_public_keys = js_sys::Array::new(); - // for pk in self.inner.public_keys().values() { - // let pk_wasm = IdentityPublicKeyWasm::from(pk.to_owned()); - // js_public_keys.push(&pk_wasm.to_object()?); - // } - // - // let value = self.inner.to_object().with_js_error()?; - // - // let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - // let js_object = with_js_error!(value.serialize(&serializer))?; - // - // let id = Buffer::from_bytes(self.inner.id().as_slice()); - // - // js_sys::Reflect::set(&js_object, &"id".to_owned().into(), &id)?; - // - // js_sys::Reflect::set( - // &js_object, - // &"publicKeys".to_owned().into(), - // &JsValue::from(&js_public_keys), - // )?; - // - // Ok(js_object) - // } - // - // #[wasm_bindgen(js_name=toBuffer)] - // pub fn to_buffer(&self) -> Result { - // let bytes = - // PlatformSerializable::serialize_to_bytes(&self.inner.clone()).with_js_error()?; - // Ok(Buffer::from_bytes(&bytes)) - // } - - #[wasm_bindgen(js_name = "hash")] - pub fn hash(&self) -> Result, WasmSdkError> { - let hash_bytes = self.inner.hash()?; - - Ok(hash_bytes) - } - - // #[wasm_bindgen(js_name=addPublicKey)] - // pub fn add_public_key(&mut self, public_key: IdentityPublicKeyWasm) { - // self.inner - // .public_keys_mut() - // .insert(public_key.get_id(), public_key.into()); - // } - // - // #[wasm_bindgen(js_name=addPublicKeys)] - // pub fn add_public_keys(&mut self, public_keys: js_sys::Array) -> Result<(), JsValue> { - // if public_keys.length() == 0 { - // return Err(format!("Setting public keys failed. The input ('{}') is invalid. You must use array of PublicKeys", public_keys.to_string()).into()); - // } - // - // let public_keys: Vec = public_keys - // .iter() - // .map(|key| { - // key.to_wasm::("IdentityPublicKey") - // .map(|key| key.to_owned().into()) - // }) - // .collect::>()?; - // - // self.inner.add_public_keys(public_keys); - // - // Ok(()) - // } - - #[wasm_bindgen(js_name=getPublicKeyMaxId)] - pub fn get_public_key_max_id(&self) -> f64 { - self.inner.get_public_key_max_id() as f64 - } - - #[wasm_bindgen(js_name=fromBuffer)] - pub fn from_buffer(buffer: Vec) -> Result { - let identity: Identity = PlatformDeserializable::deserialize_from_bytes(buffer.as_slice()) - .map_err(|e| { - WasmSdkError::serialization(format!( - "failed to deserialize identity from bytes: {e}" - )) - })?; - Ok(identity.into()) - } -} -// -// impl Inner for IdentityWasm { -// type InnerItem = Identity; -// -// fn into_inner(self) -> Self::InnerItem { -// self.inner -// } -// -// fn inner(&self) -> &Self::InnerItem { -// &self.inner -// } -// -// fn inner_mut(&mut self) -> &mut Self::InnerItem { -// &mut self.inner -// } -// } - -#[wasm_bindgen(js_name=DataContract)] -pub struct DataContractWasm(DataContract); - -impl From for DataContractWasm { - fn from(value: DataContract) -> Self { - Self(value) - } -} - -#[wasm_bindgen(js_class=DataContract)] -impl DataContractWasm { - pub fn id(&self) -> String { - self.0.id().to_string(Encoding::Base58) - } - - #[wasm_bindgen(js_name=fromJSON)] - pub fn from_json( - json: &JsValue, - platform_version: u32, - ) -> Result { - let platform_version = &PlatformVersion::get(platform_version).map_err(|e| { - WasmSdkError::invalid_argument(format!( - "unknown platform version {platform_version}: {e}" - )) - })?; - - let data_contract = DataContract::from_json( - serde_wasm_bindgen::from_value(json.clone()).map_err(|e| { - WasmSdkError::serialization(format!("failed to convert json: {}", e)) - })?, - true, - platform_version, - ) - .map_err(|e| { - WasmSdkError::serialization(format!("failed to create DataContract from json: {}", e)) - })?; - - Ok(data_contract.into()) - } - - #[wasm_bindgen(js_name=toJSON)] - pub fn to_json(&self) -> Result { - let platform_version = PlatformVersion::first(); - - let json = self.0.to_json(platform_version).map_err(|e| { - WasmSdkError::serialization(format!( - "failed to convert data contract convert to json: {}", - e - )) - })?; - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - json.serialize(&serializer) - .map_err(|e| WasmSdkError::serialization(format!("can't serialize to json: {}", e))) - } -} diff --git a/packages/wasm-sdk/src/lib.rs b/packages/wasm-sdk/src/lib.rs index a8df479f868..b77c833947a 100644 --- a/packages/wasm-sdk/src/lib.rs +++ b/packages/wasm-sdk/src/lib.rs @@ -2,7 +2,6 @@ use wasm_bindgen::prelude::wasm_bindgen; pub mod context_provider; pub mod dpns; -pub mod dpp; pub mod error; pub mod logging; pub mod queries; @@ -18,6 +17,8 @@ pub use queries::{group::*, identity as query_identity}; pub use sdk::{WasmSdk, WasmSdkBuilder}; pub use state_transitions::identity as state_transition_identity; pub use wallet::*; +pub use wasm_dpp2::data_contract::DataContractWasm; +pub use wasm_dpp2::identity::IdentityWasm; #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; diff --git a/packages/wasm-sdk/src/queries/data_contract.rs b/packages/wasm-sdk/src/queries/data_contract.rs index 67bcbe5d0eb..246daab2b6e 100644 --- a/packages/wasm-sdk/src/queries/data_contract.rs +++ b/packages/wasm-sdk/src/queries/data_contract.rs @@ -1,6 +1,6 @@ -use crate::dpp::DataContractWasm; use crate::queries::ProofMetadataResponse; use crate::sdk::WasmSdk; +use crate::DataContractWasm; use crate::WasmSdkError; use dash_sdk::dpp::data_contract::conversion::json::DataContractJsonConversionMethodsV0; use dash_sdk::platform::query::LimitQuery; diff --git a/packages/wasm-sdk/src/queries/identity.rs b/packages/wasm-sdk/src/queries/identity.rs index 9f7be0925ff..78354a5e31a 100644 --- a/packages/wasm-sdk/src/queries/identity.rs +++ b/packages/wasm-sdk/src/queries/identity.rs @@ -1,7 +1,7 @@ -use crate::dpp::IdentityWasm; use crate::error::WasmSdkError; use crate::queries::{ProofInfo, ProofMetadataResponse, ResponseMetadata}; use crate::sdk::WasmSdk; +use crate::IdentityWasm; use dash_sdk::dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0; use dash_sdk::dpp::identity::identity_public_key::IdentityPublicKey; use dash_sdk::platform::{Fetch, FetchMany, Identifier, Identity}; @@ -9,9 +9,22 @@ use drive_proof_verifier::types::{IdentityPublicKeys, IndexMap}; use js_sys::Array; use rs_dapi_client::IntoInner; use serde::{Deserialize, Serialize}; +use serde_json::Value as JsonValue; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; +fn identity_to_js_value(identity: Identity) -> Result { + IdentityWasm::from(identity).to_object().map_err(|e| { + WasmSdkError::serialization(format!("Failed to convert identity to Object: {:?}", e)) + }) +} + +fn identity_to_json_value(identity: Identity) -> Result { + let identity_js = identity_to_js_value(identity)?; + serde_wasm_bindgen::from_value(identity_js) + .map_err(|e| WasmSdkError::serialization(format!("Failed to convert to JSON value: {}", e))) +} + #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] pub(crate) struct IdentityKeyResponse { @@ -97,20 +110,7 @@ impl WasmSdk { match identity { Some(identity) => { - // Convert identity to JSON value first - let identity_json = IdentityWasm::from(identity).to_json().map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to convert identity to JSON: {:?}", - e - )) - })?; - let identity_value: serde_json::Value = - serde_wasm_bindgen::from_value(identity_json).map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to convert to JSON value: {}", - e - )) - })?; + let identity_value = identity_to_json_value(identity)?; let response = ProofMetadataResponse { data: identity_value, @@ -941,15 +941,10 @@ impl WasmSdk { vec![] }; - // Convert results to IdentityWasm - let identities: Vec = results.into_iter().map(Into::into).collect(); - // Create JS array directly let js_array = Array::new(); - for identity in identities { - let json = identity.to_json().map_err(|e| { - WasmSdkError::serialization(format!("Failed to convert identity to JSON: {:?}", e)) - })?; + for identity in results { + let json = identity_to_js_value(identity)?; js_array.push(&json); } Ok(js_array.into()) @@ -1356,19 +1351,7 @@ impl WasmSdk { match result { Some(identity) => { - let identity_json = IdentityWasm::from(identity).to_json().map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to convert identity to JSON: {:?}", - e - )) - })?; - let identity_value: serde_json::Value = - serde_wasm_bindgen::from_value(identity_json).map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to convert to JSON value: {}", - e - )) - })?; + let identity_value = identity_to_json_value(identity)?; let response = ProofMetadataResponse { data: identity_value, @@ -1445,19 +1428,10 @@ impl WasmSdk { }; // Convert results to JSON - let identities_json: Vec = results + let identities_json: Vec = results .into_iter() - .map(|identity| { - let identity_wasm: IdentityWasm = identity.into(); - let json = identity_wasm.to_json().map_err(|_| { - serde_wasm_bindgen::Error::new("Failed to convert identity to JSON") - })?; - serde_wasm_bindgen::from_value(json) - }) - .collect::, _>>() - .map_err(|e| { - WasmSdkError::serialization(format!("Failed to convert identity to JSON: {}", e)) - })?; + .map(|identity| identity_to_json_value(identity)) + .collect::, _>>()?; let response = ProofMetadataResponse { data: identities_json, diff --git a/packages/wasm-sdk/src/verify.rs b/packages/wasm-sdk/src/verify.rs index 012c63a5977..9a0b133d243 100644 --- a/packages/wasm-sdk/src/verify.rs +++ b/packages/wasm-sdk/src/verify.rs @@ -20,7 +20,7 @@ use drive_proof_verifier::FromProof; use wasm_bindgen::prelude::wasm_bindgen; use crate::context_provider::WasmContext; -use crate::dpp::{DataContractWasm, IdentityWasm}; +use crate::{DataContractWasm, IdentityWasm}; #[wasm_bindgen(js_name = "verifyIdentityResponse")] pub async fn verify_identity_response() -> Option { From 84a4ce9e5e474258ea0390fb82529a2dc05ea9ab Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 6 Oct 2025 18:37:22 +0700 Subject: [PATCH 07/44] refactor: rename `hex` to `toHex` --- packages/wasm-dpp2/src/asset_lock_proof/mod.rs | 2 +- packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs | 2 +- packages/wasm-dpp2/src/batch/mod.rs | 2 +- packages/wasm-dpp2/src/core_script/mod.rs | 2 +- packages/wasm-dpp2/src/data_contract/mod.rs | 2 +- .../wasm-dpp2/src/data_contract_transitions/create/mod.rs | 2 +- .../wasm-dpp2/src/data_contract_transitions/update/mod.rs | 2 +- packages/wasm-dpp2/src/identifier/mod.rs | 4 ++-- packages/wasm-dpp2/src/identity/mod.rs | 2 +- .../identity_transitions/credit_withdrawal_transition/mod.rs | 2 +- .../identity_credit_transfer_transition/mod.rs | 2 +- .../src/identity_transitions/top_up_transition/mod.rs | 2 +- .../src/identity_transitions/update_transition/mod.rs | 2 +- packages/wasm-dpp2/src/private_key/mod.rs | 4 ++-- packages/wasm-dpp2/src/state_transition/mod.rs | 2 +- packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs | 2 +- packages/wasm-dpp2/tests/unit/Identifier.spec.mjs | 2 +- packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs | 2 +- 18 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/wasm-dpp2/src/asset_lock_proof/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/mod.rs index 23797039dfa..4e10b8da08a 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/mod.rs @@ -151,7 +151,7 @@ impl AssetLockProofWasm { Ok(json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?) } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_string(&self) -> Result { Ok(hex::encode( serde_json::to_string(&self.0).map_err(|err| JsValue::from(err.to_string()))?, diff --git a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs index b5b5312ac4a..8848b5efbdd 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs @@ -68,7 +68,7 @@ impl OutPointWasm { slice.to_vec() } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_hex(&self) -> String { let slice: [u8; 36] = self.0.into(); diff --git a/packages/wasm-dpp2/src/batch/mod.rs b/packages/wasm-dpp2/src/batch/mod.rs index acb8c3afc18..fe7178d0285 100644 --- a/packages/wasm-dpp2/src/batch/mod.rs +++ b/packages/wasm-dpp2/src/batch/mod.rs @@ -224,7 +224,7 @@ impl BatchTransitionWasm { Ok(bytes) } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_hex(&self) -> Result { Ok(encode( self.0.serialize_to_bytes().with_js_error()?.as_slice(), diff --git a/packages/wasm-dpp2/src/core_script/mod.rs b/packages/wasm-dpp2/src/core_script/mod.rs index 52817764b0f..0d59f8fe6dd 100644 --- a/packages/wasm-dpp2/src/core_script/mod.rs +++ b/packages/wasm-dpp2/src/core_script/mod.rs @@ -88,7 +88,7 @@ impl CoreScriptWasm { self.0.to_bytes() } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_hex(&self) -> String { encode(self.0.to_bytes().as_slice(), Hex) } diff --git a/packages/wasm-dpp2/src/data_contract/mod.rs b/packages/wasm-dpp2/src/data_contract/mod.rs index 5bb8bb8aa69..84cd38128aa 100644 --- a/packages/wasm-dpp2/src/data_contract/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/mod.rs @@ -266,7 +266,7 @@ impl DataContractWasm { .with_js_error() } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_hex(&self, js_platform_version: JsValue) -> Result { Ok(encode(self.to_bytes(js_platform_version)?.as_slice(), Hex)) } diff --git a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs index 842fc022941..411bff2fa8d 100644 --- a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs +++ b/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs @@ -100,7 +100,7 @@ impl DataContractCreateTransitionWasm { self.0.serialize_to_bytes().with_js_error() } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_hex(&self) -> Result { Ok(encode( self.0.serialize_to_bytes().with_js_error()?.as_slice(), diff --git a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs index 75fe1be7428..7aef87bb64c 100644 --- a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs +++ b/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs @@ -83,7 +83,7 @@ impl DataContractUpdateTransitionWasm { self.0.serialize_to_bytes().with_js_error() } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_hex(&self) -> Result { Ok(encode( self.0.serialize_to_bytes().with_js_error()?.as_slice(), diff --git a/packages/wasm-dpp2/src/identifier/mod.rs b/packages/wasm-dpp2/src/identifier/mod.rs index 01f778b8db3..025b72237b2 100644 --- a/packages/wasm-dpp2/src/identifier/mod.rs +++ b/packages/wasm-dpp2/src/identifier/mod.rs @@ -115,8 +115,8 @@ impl IdentifierWasm { self.0.to_string(Base64) } - #[wasm_bindgen(js_name = "hex")] - pub fn get_hex(&self) -> String { + #[wasm_bindgen(js_name = "toHex")] + pub fn to_hex(&self) -> String { self.0.to_string(Hex) } diff --git a/packages/wasm-dpp2/src/identity/mod.rs b/packages/wasm-dpp2/src/identity/mod.rs index d533fc867fc..6bf4b0fa062 100644 --- a/packages/wasm-dpp2/src/identity/mod.rs +++ b/packages/wasm-dpp2/src/identity/mod.rs @@ -123,7 +123,7 @@ impl IdentityWasm { self.0.serialize_to_bytes().with_js_error() } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_hex(&self) -> Result { Ok(encode( self.0.serialize_to_bytes().with_js_error()?.as_slice(), diff --git a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs index 37b8806c109..dc6d11f8a30 100644 --- a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs @@ -228,7 +228,7 @@ impl IdentityCreditWithdrawalTransitionWasm { self.0.serialize_to_bytes().with_js_error() } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_hex(&self) -> Result { Ok(encode( self.0.serialize_to_bytes().with_js_error()?.as_slice(), diff --git a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs index d31475ef5fd..a05aadcfdd2 100644 --- a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs @@ -59,7 +59,7 @@ impl IdentityCreditTransferWasm { self.0.serialize_to_bytes().with_js_error() } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_hex(&self) -> Result { Ok(encode( self.0.serialize_to_bytes().with_js_error()?.as_slice(), diff --git a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs index 1b0cf542474..05a2ecd188f 100644 --- a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs @@ -126,7 +126,7 @@ impl IdentityTopUpTransitionWasm { self.0.serialize_to_bytes().with_js_error() } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_hex(&self) -> Result { Ok(encode( self.0.serialize_to_bytes().with_js_error()?.as_slice(), diff --git a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs index 763f11341ea..d0ffa8bb2e6 100644 --- a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs @@ -212,7 +212,7 @@ impl IdentityUpdateTransitionWasm { self.0.serialize_to_bytes().with_js_error() } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_hex(&self) -> Result { Ok(encode( self.0.serialize_to_bytes().with_js_error()?.as_slice(), diff --git a/packages/wasm-dpp2/src/private_key/mod.rs b/packages/wasm-dpp2/src/private_key/mod.rs index 0d6c5344210..b6ea976b11a 100644 --- a/packages/wasm-dpp2/src/private_key/mod.rs +++ b/packages/wasm-dpp2/src/private_key/mod.rs @@ -76,8 +76,8 @@ impl PrivateKeyWasm { self.0.to_bytes() } - #[wasm_bindgen(js_name = "hex")] - pub fn get_hex(&self) -> String { + #[wasm_bindgen(js_name = "toHex")] + pub fn to_hex(&self) -> String { self.0.to_bytes().to_hex_string(Case::Upper) } diff --git a/packages/wasm-dpp2/src/state_transition/mod.rs b/packages/wasm-dpp2/src/state_transition/mod.rs index 0ff37c58bbe..66a8f2bdce7 100644 --- a/packages/wasm-dpp2/src/state_transition/mod.rs +++ b/packages/wasm-dpp2/src/state_transition/mod.rs @@ -233,7 +233,7 @@ impl StateTransitionWasm { Ok(JsValue::from(bytes.clone())) } - #[wasm_bindgen(js_name = "hex")] + #[wasm_bindgen(js_name = "toHex")] pub fn to_hex(&self) -> Result { let bytes = self.0.serialize_to_bytes().with_js_error()?; diff --git a/packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs b/packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs index f4b59e40c2f..af3f6028545 100644 --- a/packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/AssetLockProof.spec.mjs @@ -51,7 +51,7 @@ describe('AssetLockProof', () => { it('should allow to serialize and deserialize asset lock in hex', () => { const instantLockProof = wasm.AssetLockProof.createInstantAssetLockProof(instantLockBytes, transactionBytes, 0); - const newInstantLockProof = wasm.AssetLockProof.fromHex(instantLockProof.hex()); + const newInstantLockProof = wasm.AssetLockProof.fromHex(instantLockProof.toHex()); expect(instantLockProof.constructor.name).to.equal('AssetLockProof'); expect(newInstantLockProof.constructor.name).to.equal('AssetLockProof'); diff --git a/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs b/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs index 24a2753b4dc..448dd60b390 100644 --- a/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs @@ -74,7 +74,7 @@ describe('Identifier', () => { it('should allow to get identifier hex', () => { const identifier = wasm.Identifier.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); - expect(identifier.hex()).to.equal('092828edc081d3ba1a54f043259b941368f2c718881b06a9d347883b21bfe313'); + expect(identifier.toHex()).to.equal('092828edc081d3ba1a54f043259b941368f2c718881b06a9d347883b21bfe313'); }); it('should allow to get identifier bytes', () => { diff --git a/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs b/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs index 19b48a3de5a..f7eca30733f 100644 --- a/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs @@ -59,7 +59,7 @@ describe('PrivateKey', () => { it('should allow to get key hex', () => { const pkey = wasm.PrivateKey.fromWIF(wif); - expect(pkey.hex().toLowerCase()).to.equal(bytes); + expect(pkey.toHex().toLowerCase()).to.equal(bytes); }); it('should allow to get public key hash', () => { From aa70d633e749cef686a86f169b2f8c659d230610 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 6 Oct 2025 18:43:41 +0700 Subject: [PATCH 08/44] refactor: rename `bytes` to `toBytes` --- .../src/asset_lock_proof/outpoint/mod.rs | 2 +- packages/wasm-dpp2/src/batch/mod.rs | 2 +- packages/wasm-dpp2/src/core_script/mod.rs | 2 +- packages/wasm-dpp2/src/data_contract/mod.rs | 6 +++--- .../src/data_contract_transitions/create/mod.rs | 2 +- .../src/data_contract_transitions/update/mod.rs | 2 +- packages/wasm-dpp2/src/identifier/mod.rs | 4 ++-- packages/wasm-dpp2/src/identity/mod.rs | 2 +- .../wasm-dpp2/src/identity_public_key/mod.rs | 4 ++-- .../create_transition/mod.rs | 2 +- .../credit_withdrawal_transition/mod.rs | 2 +- .../identity_credit_transfer_transition/mod.rs | 2 +- .../top_up_transition/mod.rs | 2 +- .../update_transition/mod.rs | 2 +- packages/wasm-dpp2/src/masternode_vote/mod.rs | 2 +- packages/wasm-dpp2/src/private_key/mod.rs | 4 ++-- packages/wasm-dpp2/src/public_key/mod.rs | 2 +- packages/wasm-dpp2/src/state_transition/mod.rs | 6 +++--- .../wasm-dpp2/tests/unit/ChainLockProof.spec.mjs | 2 +- .../wasm-dpp2/tests/unit/DataContract.spec.mjs | 6 +++--- .../DataContractCreateStateTransition.spec.mjs | 10 +++++----- .../DataContractUpdateStateTransition.spec.mjs | 10 +++++----- .../tests/unit/DocumentTransition.spec.mjs | 2 +- .../tests/unit/DocumentsTransitions.spec.mjs | 2 +- .../wasm-dpp2/tests/unit/Identifier.spec.mjs | 16 ++++++++-------- packages/wasm-dpp2/tests/unit/Identity.spec.mjs | 8 ++++---- .../tests/unit/IdentityCreateTransition.spec.mjs | 2 +- .../tests/unit/IdentityPublicKey.spec.mjs | 6 +++--- packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs | 2 +- .../wasm-dpp2/tests/unit/PrivateKey.spec.mjs | 6 +++--- 30 files changed, 61 insertions(+), 61 deletions(-) diff --git a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs index 8848b5efbdd..60180d92501 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs @@ -62,7 +62,7 @@ impl OutPointWasm { self.0.txid.to_hex() } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Vec { let slice: [u8; 36] = self.0.into(); slice.to_vec() diff --git a/packages/wasm-dpp2/src/batch/mod.rs b/packages/wasm-dpp2/src/batch/mod.rs index fe7178d0285..a5150760693 100644 --- a/packages/wasm-dpp2/src/batch/mod.rs +++ b/packages/wasm-dpp2/src/batch/mod.rs @@ -217,7 +217,7 @@ impl BatchTransitionWasm { } } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Result, JsValue> { let bytes = self.0.serialize_to_bytes().with_js_error()?; diff --git a/packages/wasm-dpp2/src/core_script/mod.rs b/packages/wasm-dpp2/src/core_script/mod.rs index 0d59f8fe6dd..11509ec87a9 100644 --- a/packages/wasm-dpp2/src/core_script/mod.rs +++ b/packages/wasm-dpp2/src/core_script/mod.rs @@ -83,7 +83,7 @@ impl CoreScriptWasm { self.0.to_string(Base64) } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Vec { self.0.to_bytes() } diff --git a/packages/wasm-dpp2/src/data_contract/mod.rs b/packages/wasm-dpp2/src/data_contract/mod.rs index 84cd38128aa..98a2ff502f4 100644 --- a/packages/wasm-dpp2/src/data_contract/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/mod.rs @@ -128,7 +128,7 @@ impl DataContractWasm { let definitions_value = Value::from(definitions); let data_contract_id = - DataContract::generate_data_contract_id_v0(owner_id.get_bytes(), identity_nonce); + DataContract::generate_data_contract_id_v0(owner_id.to_bytes(), identity_nonce); let data_contract_id_value = Value::from(data_contract_id.to_string(Base58)); @@ -252,7 +252,7 @@ impl DataContractWasm { ) } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self, js_platform_version: JsValue) -> Result, JsValue> { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), @@ -485,7 +485,7 @@ impl DataContractWasm { identity_nonce: IdentityNonce, ) -> Result { Ok(DataContract::generate_data_contract_id_v0( - IdentifierWasm::try_from(js_owner_id)?.get_bytes(), + IdentifierWasm::try_from(js_owner_id)?.to_bytes(), identity_nonce, ) .into()) diff --git a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs index 411bff2fa8d..64ab72c5b49 100644 --- a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs +++ b/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs @@ -95,7 +95,7 @@ impl DataContractCreateTransitionWasm { DataContractCreateTransitionWasm::from_bytes(bytes) } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Result, JsValue> { self.0.serialize_to_bytes().with_js_error() } diff --git a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs index 7aef87bb64c..3508ef98b55 100644 --- a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs +++ b/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs @@ -78,7 +78,7 @@ impl DataContractUpdateTransitionWasm { DataContractUpdateTransitionWasm::from_bytes(bytes) } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Result, JsValue> { self.0.serialize_to_bytes().with_js_error() } diff --git a/packages/wasm-dpp2/src/identifier/mod.rs b/packages/wasm-dpp2/src/identifier/mod.rs index 025b72237b2..54002170f67 100644 --- a/packages/wasm-dpp2/src/identifier/mod.rs +++ b/packages/wasm-dpp2/src/identifier/mod.rs @@ -120,8 +120,8 @@ impl IdentifierWasm { self.0.to_string(Hex) } - #[wasm_bindgen(js_name = "bytes")] - pub fn get_bytes(&self) -> Vec { + #[wasm_bindgen(js_name = "toBytes")] + pub fn to_bytes(&self) -> Vec { self.0.to_vec() } diff --git a/packages/wasm-dpp2/src/identity/mod.rs b/packages/wasm-dpp2/src/identity/mod.rs index 6bf4b0fa062..5ba0cd1c46d 100644 --- a/packages/wasm-dpp2/src/identity/mod.rs +++ b/packages/wasm-dpp2/src/identity/mod.rs @@ -118,7 +118,7 @@ impl IdentityWasm { IdentityWasm::from_bytes(bytes) } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Result, JsValue> { self.0.serialize_to_bytes().with_js_error() } diff --git a/packages/wasm-dpp2/src/identity_public_key/mod.rs b/packages/wasm-dpp2/src/identity_public_key/mod.rs index 1893a0f71e0..8c9cd07b26f 100644 --- a/packages/wasm-dpp2/src/identity_public_key/mod.rs +++ b/packages/wasm-dpp2/src/identity_public_key/mod.rs @@ -242,8 +242,8 @@ impl IdentityPublicKeyWasm { self.0.is_master() } - #[wasm_bindgen(js_name = bytes)] - pub fn to_byes(&self) -> Result, JsValue> { + #[wasm_bindgen(js_name = "toBytes")] + pub fn to_bytes(&self) -> Result, JsValue> { self.0.serialize_to_bytes().with_js_error() } diff --git a/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs index 339839b010a..7ae168492b7 100644 --- a/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs @@ -90,7 +90,7 @@ impl IdentityCreateTransitionWasm { IdentityCreateTransitionWasm::from_bytes(bytes) } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Result, JsValue> { self.0.serialize_to_bytes().with_js_error() } diff --git a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs index dc6d11f8a30..ccf88364505 100644 --- a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs @@ -223,7 +223,7 @@ impl IdentityCreditWithdrawalTransitionWasm { IdentityCreditWithdrawalTransitionWasm::from_bytes(bytes) } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Result, JsValue> { self.0.serialize_to_bytes().with_js_error() } diff --git a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs index a05aadcfdd2..8a6e81d3666 100644 --- a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs @@ -54,7 +54,7 @@ impl IdentityCreditTransferWasm { )) } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Result, JsValue> { self.0.serialize_to_bytes().with_js_error() } diff --git a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs index 05a2ecd188f..f186e82ae7b 100644 --- a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs @@ -121,7 +121,7 @@ impl IdentityTopUpTransitionWasm { self.0.set_signature_bytes(signature) } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Result, JsValue> { self.0.serialize_to_bytes().with_js_error() } diff --git a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs index d0ffa8bb2e6..6403867a00d 100644 --- a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs @@ -207,7 +207,7 @@ impl IdentityUpdateTransitionWasm { IdentityUpdateTransitionWasm::from_bytes(bytes) } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Result, JsValue> { self.0.serialize_to_bytes().with_js_error() } diff --git a/packages/wasm-dpp2/src/masternode_vote/mod.rs b/packages/wasm-dpp2/src/masternode_vote/mod.rs index 8206a38039d..38164b1027a 100644 --- a/packages/wasm-dpp2/src/masternode_vote/mod.rs +++ b/packages/wasm-dpp2/src/masternode_vote/mod.rs @@ -161,7 +161,7 @@ impl MasternodeVoteTransitionWasm { MasternodeVoteTransitionWasm::from_bytes(bytes) } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Result, JsValue> { self.0.serialize_to_bytes().with_js_error() } diff --git a/packages/wasm-dpp2/src/private_key/mod.rs b/packages/wasm-dpp2/src/private_key/mod.rs index b6ea976b11a..ee5f7ab3f70 100644 --- a/packages/wasm-dpp2/src/private_key/mod.rs +++ b/packages/wasm-dpp2/src/private_key/mod.rs @@ -71,8 +71,8 @@ impl PrivateKeyWasm { self.0.to_wif() } - #[wasm_bindgen(js_name = "bytes")] - pub fn get_bytes(&self) -> Vec { + #[wasm_bindgen(js_name = "toBytes")] + pub fn to_bytes(&self) -> Vec { self.0.to_bytes() } diff --git a/packages/wasm-dpp2/src/public_key/mod.rs b/packages/wasm-dpp2/src/public_key/mod.rs index b745a5e8f39..ea0f77fec50 100644 --- a/packages/wasm-dpp2/src/public_key/mod.rs +++ b/packages/wasm-dpp2/src/public_key/mod.rs @@ -108,7 +108,7 @@ impl PublicKeyWasm { self.0.pubkey_hash().to_hex() } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Vec { self.0.to_bytes() } diff --git a/packages/wasm-dpp2/src/state_transition/mod.rs b/packages/wasm-dpp2/src/state_transition/mod.rs index 66a8f2bdce7..35ec05449c5 100644 --- a/packages/wasm-dpp2/src/state_transition/mod.rs +++ b/packages/wasm-dpp2/src/state_transition/mod.rs @@ -77,7 +77,7 @@ impl StateTransitionWasm { self.0 .sign( &public_key.clone().into(), - private_key.get_bytes().as_slice(), + private_key.to_bytes().as_slice(), &MockBLS {}, ) .with_js_error()?; @@ -104,7 +104,7 @@ impl StateTransitionWasm { let _sig = self .0 .sign_by_private_key( - &private_key.get_bytes().as_slice(), + &private_key.to_bytes().as_slice(), KeyType::from(key_type), &MockBLS {}, ) @@ -226,7 +226,7 @@ impl StateTransitionWasm { Ok(()) } - #[wasm_bindgen(js_name = "bytes")] + #[wasm_bindgen(js_name = "toBytes")] pub fn to_bytes(&self) -> Result { let bytes = self.0.serialize_to_bytes().with_js_error()?; diff --git a/packages/wasm-dpp2/tests/unit/ChainLockProof.spec.mjs b/packages/wasm-dpp2/tests/unit/ChainLockProof.spec.mjs index 5db059881d5..7bccf6e1eb9 100644 --- a/packages/wasm-dpp2/tests/unit/ChainLockProof.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/ChainLockProof.spec.mjs @@ -19,7 +19,7 @@ describe('InstantLock', () => { const outpoint = new wasm.OutPoint('e8b43025641eea4fd21190f01bd870ef90f1a8b199d8fc3376c5b62c0b1a179d', 1); const chainlock = wasm.ChainAssetLockProof.fromRawObject({ coreChainLockedHeight: 11, - outPoint: Array.from(outpoint.bytes()), + outPoint: Array.from(outpoint.toBytes()), }); expect(chainlock.__wbg_ptr).to.not.equal(0); diff --git a/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs b/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs index 4e94fc52b39..5464e657dcb 100644 --- a/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs @@ -45,13 +45,13 @@ describe('DataContract', () => { const dataContract = wasm.DataContract.fromValue(value, true); - expect(dataContract.bytes()).to.deep.equal(fromHexString(dataContractBytes)); + expect(dataContract.toBytes()).to.deep.equal(fromHexString(dataContractBytes)); - const dataContractFromBytes = wasm.DataContract.fromBytes(dataContract.bytes(), false, PlatformVersion.PLATFORM_V1); + const dataContractFromBytes = wasm.DataContract.fromBytes(dataContract.toBytes(), false, PlatformVersion.PLATFORM_V1); expect(dataContract.__wbg_ptr).to.not.equal(0); - expect(dataContractFromBytes.bytes()).to.deep.equal(fromHexString(dataContractBytes)); + expect(dataContractFromBytes.toBytes()).to.deep.equal(fromHexString(dataContractBytes)); }); it('should allows to create DataContract from bytes without full validation', () => { diff --git a/packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs index fbbe1758f99..ac6ed7a9409 100644 --- a/packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DataContractCreateStateTransition.spec.mjs @@ -26,11 +26,11 @@ describe('DataContract Create Transition', () => { const dataContractTransition = new wasm.DataContractCreateTransition(dataContract, BigInt(1)); - const bytes = dataContractTransition.bytes(); + const bytes = dataContractTransition.toBytes(); const newDataContractTransition = wasm.DataContractCreateTransition.fromBytes(bytes); - expect(newDataContractTransition.bytes()).to.deep.equal(bytes); + expect(newDataContractTransition.toBytes()).to.deep.equal(bytes); expect(newDataContractTransition.__wbg_ptr).to.not.equal(0); expect(dataContractTransition.__wbg_ptr).to.not.equal(0); expect(dataContract.__wbg_ptr).to.not.equal(0); @@ -45,7 +45,7 @@ describe('DataContract Create Transition', () => { const newDataContractTransition = wasm.DataContractCreateTransition.fromStateTransition(stateTransition); - expect(dataContractTransition.bytes()).to.deep.equal(newDataContractTransition.bytes()); + expect(dataContractTransition.toBytes()).to.deep.equal(newDataContractTransition.toBytes()); }); }); @@ -86,7 +86,7 @@ describe('DataContract Create Transition', () => { const newDataContract = dataContractTransition.getDataContract(); - expect(dataContract.bytes()).to.deep.equal(newDataContract.bytes()); + expect(dataContract.toBytes()).to.deep.equal(newDataContract.toBytes()); }); }); @@ -102,7 +102,7 @@ describe('DataContract Create Transition', () => { dataContractTransition.setDataContract(newDataContract); - expect(fromHexString(dataContractBytes)).to.deep.equal(dataContractTransition.getDataContract().bytes()); + expect(fromHexString(dataContractBytes)).to.deep.equal(dataContractTransition.getDataContract().toBytes()); }); }); }); diff --git a/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs index 9dbbed988b9..ab3124862d5 100644 --- a/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs @@ -26,11 +26,11 @@ describe('DataContract Updatet Transition', () => { const dataContractTransition = new wasm.DataContractUpdateTransition(dataContract, BigInt(1)); - const bytes = dataContractTransition.bytes(); + const bytes = dataContractTransition.toBytes(); const newDataContractTransition = wasm.DataContractUpdateTransition.fromBytes(bytes); - expect(newDataContractTransition.bytes()).to.deep.equal(bytes); + expect(newDataContractTransition.toBytes()).to.deep.equal(bytes); expect(newDataContractTransition.__wbg_ptr).to.not.equal(0); expect(dataContractTransition.__wbg_ptr).to.not.equal(0); expect(dataContract.__wbg_ptr).to.not.equal(0); @@ -45,7 +45,7 @@ describe('DataContract Updatet Transition', () => { const newDataContractTransition = wasm.DataContractUpdateTransition.fromStateTransition(stateTransition); - expect(dataContractTransition.bytes()).to.deep.equal(newDataContractTransition.bytes()); + expect(dataContractTransition.toBytes()).to.deep.equal(newDataContractTransition.toBytes()); }); }); @@ -86,7 +86,7 @@ describe('DataContract Updatet Transition', () => { const newDataContract = dataContractTransition.getDataContract(); - expect(dataContract.bytes()).to.deep.equal(newDataContract.bytes()); + expect(dataContract.toBytes()).to.deep.equal(newDataContract.toBytes()); }); }); @@ -102,7 +102,7 @@ describe('DataContract Updatet Transition', () => { dataContractTransition.setDataContract(newDataContract); - expect(fromHexString(dataContractBytes)).to.deep.equal(newDataContract.bytes()); + expect(fromHexString(dataContractBytes)).to.deep.equal(newDataContract.toBytes()); }); }); }); diff --git a/packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs index 528ca319cf7..bdaef71751b 100644 --- a/packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DocumentTransition.spec.mjs @@ -78,7 +78,7 @@ describe('DocumentTransition', () => { documentTransition.dataContractId = new Uint8Array(32); - expect(documentTransition.dataContractId.bytes()).to.deep.equal(new Uint8Array(32)); + expect(documentTransition.dataContractId.toBytes()).to.deep.equal(new Uint8Array(32)); }); it('should allow to set identityContractNonce', () => { diff --git a/packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs b/packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs index 23b43be128e..d99aa0264c6 100644 --- a/packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.mjs @@ -633,7 +633,7 @@ describe('DocumentsTransitions', () => { transferTransition.recipientId = newRecipient; - expect(transferTransition.recipientId.bytes()).to.deep.equal(newRecipient); + expect(transferTransition.recipientId.toBytes()).to.deep.equal(newRecipient); }); }); diff --git a/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs b/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs index 448dd60b390..55019951ba4 100644 --- a/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/Identifier.spec.mjs @@ -17,44 +17,44 @@ describe('Identifier', () => { it('should allows to create Identifier from base58', () => { const identifier = wasm.Identifier.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); - expect(identifier.bytes()).to.deep.equal(identifierBytes); + expect(identifier.toBytes()).to.deep.equal(identifierBytes); }); it('should allows to create Identifier from base64', () => { const identifier = wasm.Identifier.fromBase64('CSgo7cCB07oaVPBDJZuUE2jyxxiIGwap00eIOyG/4xM='); - expect(identifier.bytes()).to.deep.equal(identifierBytes); + expect(identifier.toBytes()).to.deep.equal(identifierBytes); }); it('should allows to create Identifier from hex', () => { const identifier = wasm.Identifier.fromHex('092828edc081d3ba1a54f043259b941368f2c718881b06a9d347883b21bfe313'); - expect(identifier.bytes()).to.deep.equal(identifierBytes); + expect(identifier.toBytes()).to.deep.equal(identifierBytes); }); it('should allows to create Identifier from bytes', () => { const identifier = wasm.Identifier.fromBytes(identifierBytes); - expect(identifier.bytes()).to.deep.equal(identifierBytes); + expect(identifier.toBytes()).to.deep.equal(identifierBytes); }); it('should allows to create Identifier from Identifier', () => { const identifier = wasm.Identifier.fromBytes(identifierBytes); const identifier2 = new wasm.Identifier(identifier); - expect(identifier2.bytes()).to.deep.equal(identifierBytes); + expect(identifier2.toBytes()).to.deep.equal(identifierBytes); }); it('should allows to create Identifier from bytes in constructor', () => { const identifier = new wasm.Identifier(identifierBytes); - expect(identifier.bytes()).to.deep.equal(identifierBytes); + expect(identifier.toBytes()).to.deep.equal(identifierBytes); }); it('should allows to create Identifier from base58 in constructor', () => { const identifier = new wasm.Identifier('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); - expect(identifier.bytes()).to.deep.equal(identifierBytes); + expect(identifier.toBytes()).to.deep.equal(identifierBytes); }); }); @@ -80,7 +80,7 @@ describe('Identifier', () => { it('should allow to get identifier bytes', () => { const identifier = wasm.Identifier.fromBase58('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U'); - expect(identifier.bytes()).to.deep.equal(identifierBytes); + expect(identifier.toBytes()).to.deep.equal(identifierBytes); }); }); }); diff --git a/packages/wasm-dpp2/tests/unit/Identity.spec.mjs b/packages/wasm-dpp2/tests/unit/Identity.spec.mjs index f9ac116c43c..8f8fe2fd0d0 100644 --- a/packages/wasm-dpp2/tests/unit/Identity.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/Identity.spec.mjs @@ -23,9 +23,9 @@ describe('Identity', () => { it('should generate identity from identifier and return bytes', async () => { const identity = new wasm.Identity(identifier); - expect(Array.from(identity.bytes())).to.deep.equal(identityBytesWithoutKeys); + expect(Array.from(identity.toBytes())).to.deep.equal(identityBytesWithoutKeys); - const newIdentity = wasm.Identity.fromBytes(identity.bytes()); + const newIdentity = wasm.Identity.fromBytes(identity.toBytes()); expect(identity.__wbg_ptr).to.not.equal(0); expect(newIdentity.__wbg_ptr).to.not.equal(0); @@ -36,7 +36,7 @@ describe('Identity', () => { it('should get id buffer', () => { const identity = new wasm.Identity(identifier); - expect(identity.id.bytes()).to.deep.equal(Uint8Array.from(identifierBytes)); + expect(identity.id.toBytes()).to.deep.equal(Uint8Array.from(identifierBytes)); }); it('should get balance', () => { @@ -96,7 +96,7 @@ describe('Identity', () => { expect(identity.__wbg_ptr).to.not.equal(0); - expect(identity.getPublicKeyById(keyId).bytes()).to.deep.equal(pubKey.bytes()); + expect(identity.getPublicKeyById(keyId).toBytes()).to.deep.equal(pubKey.toBytes()); }); it('should allows to set balance', () => { diff --git a/packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs index 9fc4939a36f..70bce6ea269 100644 --- a/packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/IdentityCreateTransition.spec.mjs @@ -16,7 +16,7 @@ describe('IdentityCreateTransition', () => { it('should allow to serialize to bytes', () => { const transition = wasm.IdentityCreateTransition.default(1); - const bytes = transition.bytes(); + const bytes = transition.toBytes(); expect(bytes.length > 0).to.equal(true); }); diff --git a/packages/wasm-dpp2/tests/unit/IdentityPublicKey.spec.mjs b/packages/wasm-dpp2/tests/unit/IdentityPublicKey.spec.mjs index 34af1521c7c..9caa63bc1ae 100644 --- a/packages/wasm-dpp2/tests/unit/IdentityPublicKey.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/IdentityPublicKey.spec.mjs @@ -36,7 +36,7 @@ describe('PublicKey', () => { binaryData, ); - const bytes = pubKey.bytes(); + const bytes = pubKey.toBytes(); const newPubKey = wasm.IdentityPublicKey.fromBytes(Array.from(bytes)); @@ -50,7 +50,7 @@ describe('PublicKey', () => { expect(pubKey.readOnly).to.equal(newPubKey.readOnly); expect(pubKey.data).to.equal(newPubKey.data); - expect(pubKey.bytes()).to.deep.equal(newPubKey.bytes()); + expect(pubKey.toBytes()).to.deep.equal(newPubKey.toBytes()); expect(pubKey.__wbg_ptr).to.not.equal(0); expect(newPubKey.__wbg_ptr).to.not.equal(0); @@ -102,7 +102,7 @@ describe('PublicKey', () => { const privateKey = wasm.PrivateKey.fromWIF(wif); - expect(pubKey.validatePrivateKey(privateKey.bytes(), wasm.Network.Mainnet)).to.equal(false); + expect(pubKey.validatePrivateKey(privateKey.toBytes(), wasm.Network.Mainnet)).to.equal(false); }); }); diff --git a/packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs b/packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs index ae5ba80064c..2b3c55d8066 100644 --- a/packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/OutPoint.spec.mjs @@ -47,7 +47,7 @@ describe('OutPoint', () => { // 32 bytes for txId and 4 bytes for vout const bytes = [...txIdBytes.reverse(), ...[0, 0, 0, 1].reverse()]; - expect(outpoint.bytes()).to.deep.equal(Uint8Array.from(bytes)); + expect(outpoint.toBytes()).to.deep.equal(Uint8Array.from(bytes)); }); }); }); diff --git a/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs b/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs index f7eca30733f..c500a6324dd 100644 --- a/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/PrivateKey.spec.mjs @@ -27,7 +27,7 @@ describe('PrivateKey', () => { const pkeyFromHex = wasm.PrivateKey.fromHex(bytes, 'Mainnet'); - expect(pkey.bytes()).to.deep.equal(pkeyFromHex.bytes()); + expect(pkey.toBytes()).to.deep.equal(pkeyFromHex.toBytes()); }); it('should allow to create PrivateKey from wif and read value in wif', () => { @@ -39,7 +39,7 @@ describe('PrivateKey', () => { it('should allow to create PrivateKey from wif and write value in bytes', () => { const pkey = wasm.PrivateKey.fromWIF(wif); - expect(pkey.bytes()).to.deep.equal(fromHexString(bytes)); + expect(pkey.toBytes()).to.deep.equal(fromHexString(bytes)); }); }); @@ -53,7 +53,7 @@ describe('PrivateKey', () => { it('should allow to get key bytes', () => { const pkey = wasm.PrivateKey.fromWIF(wif); - expect(toHexString(pkey.bytes())).to.equal(bytes); + expect(toHexString(pkey.toBytes())).to.equal(bytes); }); it('should allow to get key hex', () => { From 44fd7d91bf5e5f7616d913d96de2c0a2d394460b Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 6 Oct 2025 18:46:44 +0700 Subject: [PATCH 09/44] refactor: rename `toJson` to `toJSON` --- .../clients/core/v0/nodejs/core_protoc.js | 76 +- .../dapi-grpc/clients/core/v0/web/core_pb.js | 76 +- .../clients/drive/v0/nodejs/drive_protoc.js | 8 +- .../clients/drive/v0/web/drive_pb.js | 8 +- .../platform/v0/nodejs/platform_protoc.js | 908 +++++++++--------- .../clients/platform/v0/web/platform_pb.js | 908 +++++++++--------- packages/wasm-dpp2/src/data_contract/mod.rs | 2 +- .../tests/unit/DataContract.spec.mjs | 2 +- 8 files changed, 994 insertions(+), 994 deletions(-) diff --git a/packages/dapi-grpc/clients/core/v0/nodejs/core_protoc.js b/packages/dapi-grpc/clients/core/v0/nodejs/core_protoc.js index 5bf2a3edaeb..5d91bb2c010 100644 --- a/packages/dapi-grpc/clients/core/v0/nodejs/core_protoc.js +++ b/packages/dapi-grpc/clients/core/v0/nodejs/core_protoc.js @@ -13,44 +13,44 @@ var jspb = require('google-protobuf'); var goog = jspb; -const proto = {}; - -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest.FromBlockCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse.ResponsesCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BloomFilter', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest.BlockCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Chain', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Network', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.NetworkFee', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Status', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Time', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Version', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse.Status', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.InstantSendLockMessages', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.RawTransactions', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest.FromBlockCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse.ResponsesCase', null, { proto }); +var global = Function('return this')(); + +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest.FromBlockCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse.ResponsesCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BloomFilter', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest.BlockCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Chain', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Network', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.NetworkFee', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Status', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Time', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Version', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse.Status', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.InstantSendLockMessages', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.RawTransactions', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest.FromBlockCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse.ResponsesCase', null, global); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a diff --git a/packages/dapi-grpc/clients/core/v0/web/core_pb.js b/packages/dapi-grpc/clients/core/v0/web/core_pb.js index 5bf2a3edaeb..5d91bb2c010 100644 --- a/packages/dapi-grpc/clients/core/v0/web/core_pb.js +++ b/packages/dapi-grpc/clients/core/v0/web/core_pb.js @@ -13,44 +13,44 @@ var jspb = require('google-protobuf'); var goog = jspb; -const proto = {}; - -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest.FromBlockCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse.ResponsesCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BloomFilter', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest.BlockCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Chain', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Network', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.NetworkFee', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Status', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Time', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Version', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse.Status', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.InstantSendLockMessages', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.RawTransactions', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest.FromBlockCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse.ResponsesCase', null, { proto }); +var global = Function('return this')(); + +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest.FromBlockCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse.ResponsesCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BloomFilter', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest.BlockCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Chain', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Network', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.NetworkFee', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Status', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Time', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Version', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse.Status', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.InstantSendLockMessages', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.RawTransactions', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest.FromBlockCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse.ResponsesCase', null, global); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a diff --git a/packages/dapi-grpc/clients/drive/v0/nodejs/drive_protoc.js b/packages/dapi-grpc/clients/drive/v0/nodejs/drive_protoc.js index d43136990a8..1373c867d42 100644 --- a/packages/dapi-grpc/clients/drive/v0/nodejs/drive_protoc.js +++ b/packages/dapi-grpc/clients/drive/v0/nodejs/drive_protoc.js @@ -13,12 +13,12 @@ var jspb = require('google-protobuf'); var goog = jspb; -const proto = {}; +var global = Function('return this')(); -var platform_v0_platform_pb = require('../../../platform/v0/web/platform_pb.js'); +var platform_v0_platform_pb = require('./platform/v0/platform_pb.js'); goog.object.extend(proto, platform_v0_platform_pb); -goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsResponse', null, global); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a diff --git a/packages/dapi-grpc/clients/drive/v0/web/drive_pb.js b/packages/dapi-grpc/clients/drive/v0/web/drive_pb.js index d43136990a8..1373c867d42 100644 --- a/packages/dapi-grpc/clients/drive/v0/web/drive_pb.js +++ b/packages/dapi-grpc/clients/drive/v0/web/drive_pb.js @@ -13,12 +13,12 @@ var jspb = require('google-protobuf'); var goog = jspb; -const proto = {}; +var global = Function('return this')(); -var platform_v0_platform_pb = require('../../../platform/v0/web/platform_pb.js'); +var platform_v0_platform_pb = require('./platform/v0/platform_pb.js'); goog.object.extend(proto, platform_v0_platform_pb); -goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsResponse', null, global); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a diff --git a/packages/dapi-grpc/clients/platform/v0/nodejs/platform_protoc.js b/packages/dapi-grpc/clients/platform/v0/nodejs/platform_protoc.js index 59e21a649c9..96cbdb47698 100644 --- a/packages/dapi-grpc/clients/platform/v0/nodejs/platform_protoc.js +++ b/packages/dapi-grpc/clients/platform/v0/nodejs/platform_protoc.js @@ -13,7 +13,7 @@ var jspb = require('google-protobuf'); var goog = jspb; -const proto = {}; +var global = Function('return this')(); var google_protobuf_wrappers_pb = require('google-protobuf/google/protobuf/wrappers_pb.js'); goog.object.extend(proto, google_protobuf_wrappers_pb); @@ -21,459 +21,459 @@ var google_protobuf_struct_pb = require('google-protobuf/google/protobuf/struct_ goog.object.extend(proto, google_protobuf_struct_pb); var google_protobuf_timestamp_pb = require('google-protobuf/google/protobuf/timestamp_pb.js'); goog.object.extend(proto, google_protobuf_timestamp_pb); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.AllKeys', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.GetConsensusParamsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsBlock', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsEvidence', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.GetConsensusParamsResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0.StartAtVotePollIdInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVote', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVotes', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice.VoteChoiceType', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.ResultType', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.StartAtIdentifierInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.Contender', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ContestedResourceContenders', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo.FinishedVoteOutcome', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0.StartAtIdentifierInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ContestedResourceVoters', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0.StartAtValueInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ContestedResourceValues', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.GetCurrentQuorumsInfoRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.GetCurrentQuorumsInfoResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorSetV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.GetDataContractHistoryRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistory', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistoryEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.GetDataContractRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.GetDataContractsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContractEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContracts', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0.StartCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.Documents', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.GetEpochsInfoRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfos', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.GetEvonodesProposedEpochBlocksByIdsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0.StartCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodeProposedBlocks', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodesProposedBlocks', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.GetFinalizedEpochInfosRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.BlockProposer', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfos', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.ActionStatus', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.GetGroupActionSignersRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigner', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigners', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.ActionStatus', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.GetGroupActionsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.StartAtActionId', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.BurnEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent.TypeCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractUpdateEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DestroyFrozenFundsEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentCreateEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent.TypeCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent.ActionType', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.FreezeEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent.EventTypeCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActions', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.MintEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.PersonalEncryptedNote', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.SharedEncryptedNote', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenConfigUpdateEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent.TypeCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UnfreezeEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceForQuantity', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PricingSchedule', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.GetGroupInfoRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfoEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupMemberEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.GetGroupInfosRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.StartAtGroupContractPosition', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupInfos', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupMemberEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupPositionInfoEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.GetIdentitiesBalancesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentitiesBalances', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentityBalance', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.GetIdentitiesContractKeysRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentitiesKeys', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentityKeys', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.PurposeKeys', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.GetIdentitiesTokenBalancesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalanceEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalances', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.GetIdentitiesTokenInfosRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.IdentityTokenInfos', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenIdentityInfoEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenInfoEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.GetIdentityBalanceAndRevisionRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.BalanceAndRevision', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.GetIdentityBalanceRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.GetIdentityByNonUniquePublicKeyHashRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityProvedResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.GetIdentityByPublicKeyHashRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.GetIdentityContractNonceRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.GetIdentityKeysRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.Keys', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.GetIdentityNonceRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.GetIdentityRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.GetIdentityTokenBalancesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalanceEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalances', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.GetIdentityTokenInfosRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenIdentityInfoEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfoEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfos', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.GetPathElementsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.Elements', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.GetPrefundedSpecializedBalanceRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.GetProtocolVersionUpgradeStateRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.VersionEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.Versions', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.GetProtocolVersionUpgradeVoteStatusRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignal', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignals', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.GetStatusRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Chain', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Network', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Node', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.StateSync', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Time', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Drive', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Tenderdash', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Software', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.GetTokenContractInfoRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.TokenContractInfoData', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.GetTokenDirectPurchasePricesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PriceForQuantity', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PricingSchedule', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry.PriceCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePrices', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.ContractTokenInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.GetTokenPerpetualDistributionLastClaimRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo.PaidAtCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0.StartAtInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributionEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributions', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenTimedDistributionEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.GetTokenStatusesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatusEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatuses', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.GetTokenTotalSupplyRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.TokenTotalSupplyEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.GetTotalCreditsInPlatformRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.EndAtTimeInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.StartAtTimeInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamp', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamps', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyPurpose', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType.RequestCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.Proof', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.ResponseMetadata', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SearchKey', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap.KeyKindRequestType', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SpecificKeys', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.StateTransitionBroadcastError', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.WaitForStateTransitionResultRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.AllKeys', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.GetConsensusParamsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsBlock', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsEvidence', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.GetConsensusParamsResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0.StartAtVotePollIdInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVote', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVotes', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice.VoteChoiceType', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.ResultType', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.StartAtIdentifierInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.Contender', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ContestedResourceContenders', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo.FinishedVoteOutcome', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0.StartAtIdentifierInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ContestedResourceVoters', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0.StartAtValueInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ContestedResourceValues', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.GetCurrentQuorumsInfoRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.GetCurrentQuorumsInfoResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorSetV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.GetDataContractHistoryRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistory', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistoryEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.GetDataContractRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.GetDataContractsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContractEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContracts', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0.StartCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.Documents', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.GetEpochsInfoRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfos', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.GetEvonodesProposedEpochBlocksByIdsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0.StartCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodeProposedBlocks', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodesProposedBlocks', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.GetFinalizedEpochInfosRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.BlockProposer', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfos', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.ActionStatus', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.GetGroupActionSignersRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigner', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigners', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.ActionStatus', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.GetGroupActionsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.StartAtActionId', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.BurnEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent.TypeCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractUpdateEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DestroyFrozenFundsEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentCreateEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent.TypeCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent.ActionType', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.FreezeEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent.EventTypeCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActions', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.MintEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.PersonalEncryptedNote', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.SharedEncryptedNote', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenConfigUpdateEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent.TypeCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UnfreezeEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceForQuantity', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PricingSchedule', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.GetGroupInfoRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfoEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupMemberEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.GetGroupInfosRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.StartAtGroupContractPosition', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupInfos', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupMemberEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupPositionInfoEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.GetIdentitiesBalancesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentitiesBalances', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentityBalance', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.GetIdentitiesContractKeysRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentitiesKeys', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentityKeys', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.PurposeKeys', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.GetIdentitiesTokenBalancesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalanceEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalances', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.GetIdentitiesTokenInfosRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.IdentityTokenInfos', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenIdentityInfoEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenInfoEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.GetIdentityBalanceAndRevisionRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.BalanceAndRevision', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.GetIdentityBalanceRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.GetIdentityByNonUniquePublicKeyHashRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityProvedResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.GetIdentityByPublicKeyHashRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.GetIdentityContractNonceRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.GetIdentityKeysRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.Keys', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.GetIdentityNonceRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.GetIdentityRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.GetIdentityTokenBalancesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalanceEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalances', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.GetIdentityTokenInfosRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenIdentityInfoEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfoEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfos', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.GetPathElementsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.Elements', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.GetPrefundedSpecializedBalanceRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.GetProtocolVersionUpgradeStateRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.VersionEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.Versions', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.GetProtocolVersionUpgradeVoteStatusRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignal', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignals', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.GetStatusRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Chain', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Network', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Node', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.StateSync', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Time', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Drive', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Tenderdash', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Software', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.GetTokenContractInfoRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.TokenContractInfoData', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.GetTokenDirectPurchasePricesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PriceForQuantity', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PricingSchedule', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry.PriceCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePrices', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.ContractTokenInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.GetTokenPerpetualDistributionLastClaimRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo.PaidAtCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0.StartAtInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributionEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributions', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenTimedDistributionEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.GetTokenStatusesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatusEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatuses', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.GetTokenTotalSupplyRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.TokenTotalSupplyEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.GetTotalCreditsInPlatformRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.EndAtTimeInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.StartAtTimeInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamp', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamps', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyPurpose', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType.RequestCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.Proof', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.ResponseMetadata', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SearchKey', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap.KeyKindRequestType', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SpecificKeys', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.StateTransitionBroadcastError', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.WaitForStateTransitionResultRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0.ResultCase', null, global); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a diff --git a/packages/dapi-grpc/clients/platform/v0/web/platform_pb.js b/packages/dapi-grpc/clients/platform/v0/web/platform_pb.js index 59e21a649c9..96cbdb47698 100644 --- a/packages/dapi-grpc/clients/platform/v0/web/platform_pb.js +++ b/packages/dapi-grpc/clients/platform/v0/web/platform_pb.js @@ -13,7 +13,7 @@ var jspb = require('google-protobuf'); var goog = jspb; -const proto = {}; +var global = Function('return this')(); var google_protobuf_wrappers_pb = require('google-protobuf/google/protobuf/wrappers_pb.js'); goog.object.extend(proto, google_protobuf_wrappers_pb); @@ -21,459 +21,459 @@ var google_protobuf_struct_pb = require('google-protobuf/google/protobuf/struct_ goog.object.extend(proto, google_protobuf_struct_pb); var google_protobuf_timestamp_pb = require('google-protobuf/google/protobuf/timestamp_pb.js'); goog.object.extend(proto, google_protobuf_timestamp_pb); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.AllKeys', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.GetConsensusParamsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsBlock', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsEvidence', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.GetConsensusParamsResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0.StartAtVotePollIdInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVote', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVotes', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice.VoteChoiceType', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.ResultType', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.StartAtIdentifierInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.Contender', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ContestedResourceContenders', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo.FinishedVoteOutcome', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0.StartAtIdentifierInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ContestedResourceVoters', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0.StartAtValueInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ContestedResourceValues', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.GetCurrentQuorumsInfoRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.GetCurrentQuorumsInfoResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorSetV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.GetDataContractHistoryRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistory', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistoryEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.GetDataContractRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.GetDataContractsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContractEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContracts', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0.StartCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.Documents', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.GetEpochsInfoRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfos', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.GetEvonodesProposedEpochBlocksByIdsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0.StartCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodeProposedBlocks', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodesProposedBlocks', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.GetFinalizedEpochInfosRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.BlockProposer', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfos', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.ActionStatus', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.GetGroupActionSignersRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigner', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigners', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.ActionStatus', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.GetGroupActionsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.StartAtActionId', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.BurnEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent.TypeCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractUpdateEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DestroyFrozenFundsEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentCreateEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent.TypeCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent.ActionType', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.FreezeEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent.EventTypeCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActions', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.MintEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.PersonalEncryptedNote', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.SharedEncryptedNote', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenConfigUpdateEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent.TypeCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UnfreezeEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceForQuantity', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PricingSchedule', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.GetGroupInfoRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfoEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupMemberEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.GetGroupInfosRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.StartAtGroupContractPosition', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupInfos', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupMemberEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupPositionInfoEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.GetIdentitiesBalancesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentitiesBalances', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentityBalance', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.GetIdentitiesContractKeysRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentitiesKeys', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentityKeys', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.PurposeKeys', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.GetIdentitiesTokenBalancesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalanceEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalances', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.GetIdentitiesTokenInfosRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.IdentityTokenInfos', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenIdentityInfoEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenInfoEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.GetIdentityBalanceAndRevisionRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.BalanceAndRevision', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.GetIdentityBalanceRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.GetIdentityByNonUniquePublicKeyHashRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityProvedResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.GetIdentityByPublicKeyHashRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.GetIdentityContractNonceRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.GetIdentityKeysRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.Keys', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.GetIdentityNonceRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.GetIdentityRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.GetIdentityTokenBalancesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalanceEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalances', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.GetIdentityTokenInfosRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenIdentityInfoEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfoEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfos', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.GetPathElementsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.Elements', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.GetPrefundedSpecializedBalanceRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.GetProtocolVersionUpgradeStateRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.VersionEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.Versions', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.GetProtocolVersionUpgradeVoteStatusRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignal', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignals', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.GetStatusRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Chain', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Network', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Node', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.StateSync', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Time', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Drive', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Tenderdash', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Software', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.GetTokenContractInfoRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.TokenContractInfoData', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.GetTokenDirectPurchasePricesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PriceForQuantity', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PricingSchedule', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry.PriceCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePrices', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.ContractTokenInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.GetTokenPerpetualDistributionLastClaimRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo.PaidAtCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0.StartAtInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributionEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributions', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenTimedDistributionEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.GetTokenStatusesRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatusEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatuses', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.GetTokenTotalSupplyRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.TokenTotalSupplyEntry', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.GetTotalCreditsInPlatformRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.EndAtTimeInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.StartAtTimeInfo', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.ResultCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamp', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamps', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyPurpose', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType.RequestCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.Proof', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.ResponseMetadata', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SearchKey', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap.KeyKindRequestType', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SpecificKeys', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.StateTransitionBroadcastError', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.WaitForStateTransitionResultRequestV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.VersionCase', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0', null, { proto }); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.AllKeys', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.GetConsensusParamsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsBlock', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsEvidence', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.GetConsensusParamsResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0.StartAtVotePollIdInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVote', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVotes', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice.VoteChoiceType', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.ResultType', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.StartAtIdentifierInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.Contender', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ContestedResourceContenders', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo.FinishedVoteOutcome', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0.StartAtIdentifierInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ContestedResourceVoters', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0.StartAtValueInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ContestedResourceValues', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.GetCurrentQuorumsInfoRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.GetCurrentQuorumsInfoResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorSetV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.GetDataContractHistoryRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistory', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistoryEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.GetDataContractRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.GetDataContractsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContractEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContracts', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0.StartCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.Documents', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.GetEpochsInfoRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfos', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.GetEvonodesProposedEpochBlocksByIdsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0.StartCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodeProposedBlocks', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodesProposedBlocks', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.GetFinalizedEpochInfosRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.BlockProposer', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfos', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.ActionStatus', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.GetGroupActionSignersRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigner', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigners', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.ActionStatus', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.GetGroupActionsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.StartAtActionId', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.BurnEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent.TypeCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractUpdateEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DestroyFrozenFundsEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentCreateEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent.TypeCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent.ActionType', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.FreezeEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent.EventTypeCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActions', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.MintEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.PersonalEncryptedNote', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.SharedEncryptedNote', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenConfigUpdateEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent.TypeCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UnfreezeEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceForQuantity', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PricingSchedule', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.GetGroupInfoRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfoEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupMemberEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.GetGroupInfosRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.StartAtGroupContractPosition', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupInfos', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupMemberEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupPositionInfoEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.GetIdentitiesBalancesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentitiesBalances', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentityBalance', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.GetIdentitiesContractKeysRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentitiesKeys', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentityKeys', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.PurposeKeys', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.GetIdentitiesTokenBalancesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalanceEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalances', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.GetIdentitiesTokenInfosRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.IdentityTokenInfos', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenIdentityInfoEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenInfoEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.GetIdentityBalanceAndRevisionRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.BalanceAndRevision', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.GetIdentityBalanceRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.GetIdentityByNonUniquePublicKeyHashRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityProvedResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.GetIdentityByPublicKeyHashRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.GetIdentityContractNonceRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.GetIdentityKeysRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.Keys', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.GetIdentityNonceRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.GetIdentityRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.GetIdentityTokenBalancesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalanceEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalances', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.GetIdentityTokenInfosRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenIdentityInfoEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfoEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfos', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.GetPathElementsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.Elements', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.GetPrefundedSpecializedBalanceRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.GetProtocolVersionUpgradeStateRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.VersionEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.Versions', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.GetProtocolVersionUpgradeVoteStatusRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignal', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignals', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.GetStatusRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Chain', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Network', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Node', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.StateSync', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Time', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Drive', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Tenderdash', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Software', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.GetTokenContractInfoRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.TokenContractInfoData', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.GetTokenDirectPurchasePricesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PriceForQuantity', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PricingSchedule', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry.PriceCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePrices', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.ContractTokenInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.GetTokenPerpetualDistributionLastClaimRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo.PaidAtCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0.StartAtInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributionEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributions', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenTimedDistributionEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.GetTokenStatusesRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatusEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatuses', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.GetTokenTotalSupplyRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.TokenTotalSupplyEntry', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.GetTotalCreditsInPlatformRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.EndAtTimeInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.StartAtTimeInfo', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamp', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamps', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyPurpose', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType.RequestCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.Proof', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.ResponseMetadata', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SearchKey', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap.KeyKindRequestType', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SpecificKeys', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.StateTransitionBroadcastError', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.WaitForStateTransitionResultRequestV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.VersionCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0.ResultCase', null, global); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a diff --git a/packages/wasm-dpp2/src/data_contract/mod.rs b/packages/wasm-dpp2/src/data_contract/mod.rs index 98a2ff502f4..f5ea3b4576b 100644 --- a/packages/wasm-dpp2/src/data_contract/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/mod.rs @@ -466,7 +466,7 @@ impl DataContractWasm { Ok(()) } - #[wasm_bindgen(js_name = "toJson")] + #[wasm_bindgen(js_name = "toJSON")] pub fn to_json(&self, js_platform_version: JsValue) -> Result { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), diff --git a/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs b/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs index 5464e657dcb..8812cf9088c 100644 --- a/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DataContract.spec.mjs @@ -75,7 +75,7 @@ describe('DataContract', () => { it('should allow to get json', () => { const dataContract = wasm.DataContract.fromValue(value, true); - expect(dataContract.toJson()).to.deep.equal(value); + expect(dataContract.toJSON()).to.deep.equal(value); }); }); From bd0c39a46ae4e0e7ef01fcdcc1705d2fc3f7aa31 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 6 Oct 2025 22:52:30 +0700 Subject: [PATCH 10/44] refactor: return error instead of jsvalue --- Cargo.lock | 1 + packages/wasm-dpp2/Cargo.toml | 1 + .../asset_lock_proof/instant/instant_lock.rs | 30 +-- .../src/asset_lock_proof/instant/mod.rs | 29 ++- .../wasm-dpp2/src/asset_lock_proof/mod.rs | 49 ++-- .../src/asset_lock_proof/outpoint/mod.rs | 31 +-- packages/wasm-dpp2/src/consensus_error/mod.rs | 11 +- packages/wasm-dpp2/src/data_contract/mod.rs | 189 ++++++++------- packages/wasm-dpp2/src/error.rs | 140 +++++++++++ packages/wasm-dpp2/src/identity/mod.rs | 76 +++--- .../wasm-dpp2/src/identity_public_key/mod.rs | 107 ++++---- .../create_transition/mod.rs | 46 ++-- .../credit_withdrawal_transition/mod.rs | 78 +++--- .../mod.rs | 64 ++--- .../public_key_in_creation/mod.rs | 40 +-- .../top_up_transition/mod.rs | 66 ++--- .../update_transition/mod.rs | 58 ++--- packages/wasm-dpp2/src/lib.rs | 1 + .../wasm-dpp2/src/state_transition/mod.rs | 229 +++++++++--------- packages/wasm-dpp2/src/utils/mod.rs | 26 ++ 20 files changed, 729 insertions(+), 543 deletions(-) create mode 100644 packages/wasm-dpp2/src/error.rs diff --git a/Cargo.lock b/Cargo.lock index 5fc82800fa5..83755b2eea1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7109,6 +7109,7 @@ dependencies = [ "serde_json", "sha2", "talc", + "thiserror 1.0.69", "wasm-bindgen", ] diff --git a/packages/wasm-dpp2/Cargo.toml b/packages/wasm-dpp2/Cargo.toml index 0837c26a20d..8472da2ae9d 100644 --- a/packages/wasm-dpp2/Cargo.toml +++ b/packages/wasm-dpp2/Cargo.toml @@ -29,4 +29,5 @@ serde_json = { version = "1.0", features = ["preserve_order"] } js-sys = "0.3.77" hex = "0.4.3" anyhow = "1.0.75" +thiserror = "1.0" sha2 = "0.10.8" diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs index 3e93acb8e31..86d771ebe9e 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs @@ -1,4 +1,5 @@ use crate::asset_lock_proof::outpoint::OutPointWasm; +use crate::error::{WasmDppError, WasmDppResult}; use dpp::dashcore::bls_sig_utils::BLSSignature; use dpp::dashcore::hash_types::CycleHash; use dpp::dashcore::hashes::hex::FromHex; @@ -6,7 +7,6 @@ use dpp::dashcore::secp256k1::hashes::hex::Case::Lower; use dpp::dashcore::secp256k1::hashes::hex::DisplayHex; use dpp::dashcore::{InstantLock, Txid}; use std::str::FromStr; -use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "InstantLock")] @@ -44,17 +44,18 @@ impl InstantLockWasm { txid: String, cycle_hash: String, bls_signature: String, - ) -> Result { + ) -> WasmDppResult { let inputs = OutPointWasm::vec_from_js_value(js_inputs)?; Ok(InstantLockWasm(InstantLock { version, inputs: inputs.iter().map(|input| input.clone().into()).collect(), - txid: Txid::from_hex(&txid).map_err(|err| JsValue::from(err.to_string()))?, + txid: Txid::from_hex(&txid) + .map_err(|err| WasmDppError::serialization(err.to_string()))?, cyclehash: CycleHash::from_str(&cycle_hash) - .map_err(|err| JsValue::from(err.to_string()))?, + .map_err(|err| WasmDppError::serialization(err.to_string()))?, signature: BLSSignature::from_hex(&bls_signature) - .map_err(|err| JsValue::from(err.to_string()))?, + .map_err(|err| WasmDppError::serialization(err.to_string()))?, })) } @@ -93,29 +94,30 @@ impl InstantLockWasm { } #[wasm_bindgen(setter = "inputs")] - pub fn set_inputs(&mut self, inputs: &js_sys::Array) -> Result<(), JsValue> { + pub fn set_inputs(&mut self, inputs: &js_sys::Array) -> WasmDppResult<()> { let inputs = OutPointWasm::vec_from_js_value(inputs)?; self.0.inputs = inputs.iter().map(|input| input.clone().into()).collect(); Ok(()) } #[wasm_bindgen(setter = "txid")] - pub fn set_txid(&mut self, txid: String) -> Result<(), JsValue> { - self.0.txid = Txid::from_hex(&txid).map_err(|err| JsValue::from(err.to_string()))?; + pub fn set_txid(&mut self, txid: String) -> WasmDppResult<()> { + self.0.txid = + Txid::from_hex(&txid).map_err(|err| WasmDppError::serialization(err.to_string()))?; Ok(()) } #[wasm_bindgen(setter = "cyclehash")] - pub fn set_cycle_hash(&mut self, cycle_hash: String) -> Result<(), JsValue> { - self.0.cyclehash = - CycleHash::from_str(&cycle_hash).map_err(|err| JsValue::from(err.to_string()))?; + pub fn set_cycle_hash(&mut self, cycle_hash: String) -> WasmDppResult<()> { + self.0.cyclehash = CycleHash::from_str(&cycle_hash) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; Ok(()) } #[wasm_bindgen(setter = "blsSignature")] - pub fn set_bls_signature(&mut self, bls_signature: String) -> Result<(), JsValue> { - self.0.signature = - BLSSignature::from_hex(&bls_signature).map_err(|err| JsValue::from(err.to_string()))?; + pub fn set_bls_signature(&mut self, bls_signature: String) -> WasmDppResult<()> { + self.0.signature = BLSSignature::from_hex(&bls_signature) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; Ok(()) } } diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs index 68573e447dd..a624f285550 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs @@ -3,8 +3,8 @@ mod instant_lock; use crate::asset_lock_proof::instant::instant_lock::InstantLockWasm; use crate::asset_lock_proof::outpoint::OutPointWasm; use crate::asset_lock_proof::tx_out::TxOutWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::utils::WithJsError; use dpp::dashcore::consensus::{deserialize, serialize}; use dpp::dashcore::{InstantLock, Transaction}; use dpp::identity::state_transition::asset_lock_proof::InstantAssetLockProof; @@ -53,11 +53,11 @@ impl InstantAssetLockProofWasm { instant_lock: Vec, transaction: Vec, output_index: u32, - ) -> Result { - let instant_lock: InstantLock = - deserialize(instant_lock.as_slice()).map_err(|err| JsValue::from(err.to_string()))?; - let transaction: Transaction = - deserialize(transaction.as_slice()).map_err(|err| JsValue::from(err.to_string()))?; + ) -> WasmDppResult { + let instant_lock: InstantLock = deserialize(instant_lock.as_slice()) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + let transaction: Transaction = deserialize(transaction.as_slice()) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; Ok(InstantAssetLockProofWasm(InstantAssetLockProof { instant_lock, @@ -67,9 +67,9 @@ impl InstantAssetLockProofWasm { } #[wasm_bindgen(js_name = "fromObject")] - pub fn from_object(value: JsValue) -> Result { - let parameters: InstantAssetLockProofRAW = - serde_wasm_bindgen::from_value(value).map_err(|err| JsValue::from(err.to_string()))?; + pub fn from_object(value: JsValue) -> WasmDppResult { + let parameters: InstantAssetLockProofRAW = serde_wasm_bindgen::from_value(value) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; InstantAssetLockProofWasm::new( parameters.instant_lock, @@ -79,14 +79,13 @@ impl InstantAssetLockProofWasm { } #[wasm_bindgen(js_name = "toObject")] - pub fn to_object(&self) -> Result { + pub fn to_object(&self) -> WasmDppResult { let serializer = serde_wasm_bindgen::Serializer::json_compatible(); self.0 - .to_object() - .with_js_error()? + .to_object()? .serialize(&serializer) - .map_err(JsValue::from) + .map_err(|e| WasmDppError::serialization(e.to_string())) } #[wasm_bindgen(js_name = "getOutput")] @@ -138,8 +137,8 @@ impl InstantAssetLockProofWasm { } #[wasm_bindgen(js_name = "createIdentityId")] - pub fn create_identifier(&self) -> Result { - let identifier = self.0.create_identifier().with_js_error()?; + pub fn create_identifier(&self) -> WasmDppResult { + let identifier = self.0.create_identifier()?; Ok(identifier.into()) } diff --git a/packages/wasm-dpp2/src/asset_lock_proof/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/mod.rs index 4e10b8da08a..fe0e6e5a2fa 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/mod.rs @@ -8,8 +8,9 @@ use crate::asset_lock_proof::instant::InstantAssetLockProofWasm; use crate::asset_lock_proof::outpoint::OutPointWasm; use crate::enums::lock_types::AssetLockProofTypeWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::utils::{IntoWasm, WithJsError, get_class_type}; +use crate::utils::{IntoWasm, get_class_type}; use dpp::prelude::AssetLockProof; use serde::Serialize; use wasm_bindgen::JsValue; @@ -74,7 +75,7 @@ impl AssetLockProofWasm { } #[wasm_bindgen(constructor)] - pub fn new(js_asset_lock_proof: &JsValue) -> Result { + pub fn new(js_asset_lock_proof: &JsValue) -> WasmDppResult { match get_class_type(js_asset_lock_proof)?.as_str() { "ChainAssetLockProof" => { let chain_lock = js_asset_lock_proof @@ -90,7 +91,9 @@ impl AssetLockProofWasm { Ok(AssetLockProofWasm::from(instant_lock)) } - &_ => Err(JsValue::from("Invalid asset lock proof type.")), + &_ => Err(WasmDppError::invalid_argument( + "Invalid asset lock proof type", + )), } } @@ -99,7 +102,7 @@ impl AssetLockProofWasm { instant_lock: Vec, transaction: Vec, output_index: u32, - ) -> Result { + ) -> WasmDppResult { Ok(InstantAssetLockProofWasm::new(instant_lock, transaction, output_index)?.into()) } @@ -107,7 +110,7 @@ impl AssetLockProofWasm { pub fn new_chain_asset_lock_proof( core_chain_locked_height: u32, out_point: &OutPointWasm, - ) -> Result { + ) -> WasmDppResult { Ok(ChainAssetLockProofWasm::new(core_chain_locked_height, out_point)?.into()) } @@ -138,36 +141,40 @@ impl AssetLockProofWasm { } #[wasm_bindgen(js_name = "createIdentityId")] - pub fn create_identifier(&self) -> Result { - let identifier = self.0.create_identifier().with_js_error()?; + pub fn create_identifier(&self) -> WasmDppResult { + let identifier = self.0.create_identifier()?; Ok(identifier.into()) } #[wasm_bindgen(js_name = "toObject")] - pub fn to_object(&self) -> Result { - let json_value = self.0.to_raw_object().with_js_error()?; + pub fn to_object(&self) -> WasmDppResult { + let json_value = self.0.to_raw_object()?; - Ok(json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?) + json_value + .serialize(&serde_wasm_bindgen::Serializer::json_compatible()) + .map_err(|e| WasmDppError::serialization(e.to_string())) } #[wasm_bindgen(js_name = "toHex")] - pub fn to_string(&self) -> Result { - Ok(hex::encode( - serde_json::to_string(&self.0).map_err(|err| JsValue::from(err.to_string()))?, - )) + pub fn to_string(&self) -> WasmDppResult { + let json = serde_json::to_string(&self.0) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + Ok(hex::encode(json)) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(asset_lock_proof: String) -> Result { - let asset_lock_proof_bytes = hex::decode(&asset_lock_proof) - .map_err(|e| JsValue::from_str(&format!("Invalid asset lock proof hex: {}", e)))?; + pub fn from_hex(asset_lock_proof: String) -> WasmDppResult { + let asset_lock_proof_bytes = hex::decode(&asset_lock_proof).map_err(|e| { + WasmDppError::serialization(format!("Invalid asset lock proof hex: {}", e)) + })?; - let json_str = String::from_utf8(asset_lock_proof_bytes) - .map_err(|e| JsValue::from_str(&format!("Invalid UTF-8 in asset lock proof: {}", e)))?; + let json_str = String::from_utf8(asset_lock_proof_bytes).map_err(|e| { + WasmDppError::serialization(format!("Invalid UTF-8 in asset lock proof: {}", e)) + })?; - let asset_lock_proof = serde_json::from_str(&json_str).map_err(|e| { - JsValue::from_str(&format!("Failed to parse asset lock proof JSON: {}", e)) + let asset_lock_proof: AssetLockProof = serde_json::from_str(&json_str).map_err(|e| { + WasmDppError::serialization(format!("Failed to parse asset lock proof JSON: {}", e)) })?; Ok(AssetLockProofWasm(asset_lock_proof)) diff --git a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs index 60180d92501..5c8c382f002 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs @@ -1,9 +1,10 @@ +use crate::error::{WasmDppError, WasmDppResult}; use crate::utils::IntoWasm; use dpp::dashcore::{OutPoint, Txid}; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; use dpp::platform_value::string_encoding::{decode, encode}; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "OutPoint")] #[derive(Clone)] @@ -43,8 +44,9 @@ impl OutPointWasm { } #[wasm_bindgen(constructor)] - pub fn new(txid_hex: String, vout: u32) -> Result { - let out_point = Txid::from_hex(&txid_hex).map_err(|err| JsValue::from(err.to_string()))?; + pub fn new(txid_hex: String, vout: u32) -> WasmDppResult { + let out_point = Txid::from_hex(&txid_hex) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; Ok(OutPointWasm(OutPoint { txid: out_point, @@ -93,26 +95,27 @@ impl OutPointWasm { } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - Ok(OutPointWasm::from_bytes( - decode(hex.as_str(), Hex).map_err(JsError::from)?, - )) + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = + decode(hex.as_str(), Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; + Ok(OutPointWasm::from_bytes(bytes)) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - Ok(OutPointWasm::from_bytes( - decode(base64.as_str(), Base64).map_err(JsError::from)?, - )) + pub fn from_base64(base64: String) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; + Ok(OutPointWasm::from_bytes(bytes)) } } impl OutPointWasm { - pub fn vec_from_js_value(js_outpoints: &js_sys::Array) -> Result, JsValue> { + pub fn vec_from_js_value(js_outpoints: &js_sys::Array) -> WasmDppResult> { let outpoints: Vec = js_outpoints .iter() - .map(|key| OutPointWasm::try_from(key)) - .collect::, JsValue>>()?; + .map(OutPointWasm::try_from) + .collect::, JsValue>>() + .map_err(|e| WasmDppError::invalid_argument(e.as_string().unwrap_or_default()))?; Ok(outpoints) } diff --git a/packages/wasm-dpp2/src/consensus_error/mod.rs b/packages/wasm-dpp2/src/consensus_error/mod.rs index a837cddabf3..3385bf3dfb2 100644 --- a/packages/wasm-dpp2/src/consensus_error/mod.rs +++ b/packages/wasm-dpp2/src/consensus_error/mod.rs @@ -1,7 +1,6 @@ -use crate::utils::WithJsError; +use crate::error::WasmDppResult; use dpp::consensus::ConsensusError; use dpp::serialization::PlatformDeserializable; -use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "ConsensusError")] @@ -10,10 +9,10 @@ pub struct ConsensusErrorWasm(ConsensusError); #[wasm_bindgen(js_class = ConsensusError)] impl ConsensusErrorWasm { #[wasm_bindgen(js_name = "deserialize")] - pub fn deserialize(error: Vec) -> Result { - Ok(ConsensusErrorWasm( - ConsensusError::deserialize_from_bytes(error.as_slice()).with_js_error()?, - )) + pub fn deserialize(error: Vec) -> WasmDppResult { + Ok(ConsensusErrorWasm(ConsensusError::deserialize_from_bytes( + error.as_slice(), + )?)) } #[wasm_bindgen(getter = "message")] diff --git a/packages/wasm-dpp2/src/data_contract/mod.rs b/packages/wasm-dpp2/src/data_contract/mod.rs index f5ea3b4576b..2b3af1452c1 100644 --- a/packages/wasm-dpp2/src/data_contract/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/mod.rs @@ -1,8 +1,9 @@ use crate::enums::platform::PlatformVersionWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::token_configuration::TokenConfigurationWasm; use crate::token_configuration::group::GroupWasm; -use crate::utils::{IntoWasm, ToSerdeJSONExt, WithJsError}; +use crate::utils::{IntoWasm, ToSerdeJSONExt}; use dpp::dashcore::hashes::serde::Serialize; use dpp::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters}; use dpp::data_contract::accessors::v1::{DataContractV1Getters, DataContractV1Setters}; @@ -27,8 +28,8 @@ use dpp::serialization::{ use dpp::version::PlatformVersion; use js_sys::{Object, Reflect}; use std::collections::BTreeMap; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "DataContract")] #[derive(Clone)] @@ -48,7 +49,7 @@ impl From for DataContract { pub fn tokens_configuration_from_js_value( js_configuration: &JsValue, -) -> Result, JsValue> { +) -> WasmDppResult> { let configuration_object = Object::from(js_configuration.clone()); let configuration_keys = Object::keys(&configuration_object); @@ -56,10 +57,12 @@ pub fn tokens_configuration_from_js_value( for key in configuration_keys.iter() { let contract_position = match key.as_string() { - None => Err(JsValue::from("Cannot read timestamp in distribution rules")), + None => Err(WasmDppError::invalid_argument( + "Cannot read timestamp in distribution rules", + )), Some(contract_position) => Ok(contract_position .parse::() - .map_err(JsError::from)?), + .map_err(|e| WasmDppError::serialization(e.to_string()))?), }?; let js_config = Reflect::get(&js_configuration, &key)? @@ -93,14 +96,15 @@ impl DataContractWasm { js_tokens: &JsValue, full_validation: bool, js_platform_version: JsValue, - ) -> Result { + ) -> WasmDppResult { let serializer = serde_wasm_bindgen::Serializer::json_compatible(); let owner_id: IdentifierWasm = js_owner_id.clone().try_into()?; let owner_id_value = Value::from(owner_id.get_base58()); - let schema: Value = serde_wasm_bindgen::from_value(js_schema)?; + let schema: Value = serde_wasm_bindgen::from_value(js_schema) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; let tokens: BTreeMap = match js_tokens.is_undefined() { @@ -123,7 +127,8 @@ impl DataContractWasm { let definitions = js_definitions .map(|definitions| serde_wasm_bindgen::from_value(definitions.into())) - .transpose()?; + .transpose() + .map_err(|err| WasmDppError::serialization(err.to_string()))?; let definitions_value = Value::from(definitions); @@ -132,47 +137,45 @@ impl DataContractWasm { let data_contract_id_value = Value::from(data_contract_id.to_string(Base58)); - let config = - DataContractConfig::default_for_version(&platform_version.clone()).with_js_error()?; + let config = DataContractConfig::default_for_version(&platform_version.clone())?; let config_value = config .serialize(&serializer) - .map_err(JsValue::from)? + .map_err(|e| WasmDppError::serialization(e.to_string()))? .with_serde_to_platform_value_map()?; let mut contract_value = Value::Map(ValueMap::new()); contract_value .set_value("$format_version", data_contract_structure_version_value) - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::serialization(err.to_string()))?; contract_value .set_value("id", data_contract_id_value) - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::serialization(err.to_string()))?; contract_value .set_value("config", Value::from(config_value)) - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::serialization(err.to_string()))?; contract_value .set_value("version", Value::from(1u16)) - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::serialization(err.to_string()))?; contract_value .set_value("ownerId", owner_id_value) - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::serialization(err.to_string()))?; contract_value .set_value("schemaDefs", definitions_value) - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::serialization(err.to_string()))?; contract_value .set_value("documentSchemas", schema) - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::serialization(err.to_string()))?; let data_contract = - DataContract::from_value(contract_value, full_validation, &platform_version) - .with_js_error()?; + DataContract::from_value(contract_value, full_validation, &platform_version)?; let data_contract_with_tokens = match data_contract { DataContract::V0(v0) => DataContract::from(v0), @@ -191,7 +194,7 @@ impl DataContractWasm { js_value: JsValue, full_validation: bool, js_platform_version: JsValue, - ) -> Result { + ) -> WasmDppResult { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, @@ -199,8 +202,7 @@ impl DataContractWasm { let value = js_value.with_serde_to_platform_value()?; - let contract = DataContract::from_value(value, full_validation, &platform_version.into()) - .with_js_error()?; + let contract = DataContract::from_value(value, full_validation, &platform_version.into())?; Ok(DataContractWasm(contract)) } @@ -210,7 +212,7 @@ impl DataContractWasm { bytes: Vec, full_validation: bool, js_platform_version: JsValue, - ) -> Result { + ) -> WasmDppResult { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, @@ -220,8 +222,7 @@ impl DataContractWasm { &bytes.as_slice(), full_validation, &platform_version.into(), - ) - .with_js_error()?; + )?; Ok(DataContractWasm(rs_data_contract)) } @@ -231,12 +232,11 @@ impl DataContractWasm { hex: String, full_validation: bool, js_platform_version: JsValue, - ) -> Result { - DataContractWasm::from_bytes( - decode(hex.as_str(), Hex).map_err(JsError::from)?, - full_validation, - js_platform_version, - ) + ) -> WasmDppResult { + let bytes = + decode(hex.as_str(), Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; + + DataContractWasm::from_bytes(bytes, full_validation, js_platform_version) } #[wasm_bindgen(js_name = "fromBase64")] @@ -244,16 +244,15 @@ impl DataContractWasm { base64: String, full_validation: bool, js_platform_version: JsValue, - ) -> Result { - DataContractWasm::from_bytes( - decode(base64.as_str(), Base64).map_err(JsError::from)?, - full_validation, - js_platform_version, - ) + ) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; + + DataContractWasm::from_bytes(bytes, full_validation, js_platform_version) } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self, js_platform_version: JsValue) -> Result, JsValue> { + pub fn to_bytes(&self, js_platform_version: JsValue) -> WasmDppResult> { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, @@ -261,18 +260,16 @@ impl DataContractWasm { let rs_data_contract: DataContract = self.0.clone(); - rs_data_contract - .serialize_to_bytes_with_platform_version(&platform_version.into()) - .with_js_error() + Ok(rs_data_contract.serialize_to_bytes_with_platform_version(&platform_version.into())?) } #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self, js_platform_version: JsValue) -> Result { + pub fn to_hex(&self, js_platform_version: JsValue) -> WasmDppResult { Ok(encode(self.to_bytes(js_platform_version)?.as_slice(), Hex)) } #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self, js_platform_version: JsValue) -> Result { + pub fn to_base64(&self, js_platform_version: JsValue) -> WasmDppResult { Ok(encode( self.to_bytes(js_platform_version)?.as_slice(), Base64, @@ -280,7 +277,7 @@ impl DataContractWasm { } #[wasm_bindgen(js_name = "toValue")] - pub fn to_value(&self, js_platform_version: JsValue) -> Result { + pub fn to_value(&self, js_platform_version: JsValue) -> WasmDppResult { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, @@ -290,20 +287,19 @@ impl DataContractWasm { self.0 .clone() - .to_value(&platform_version.into()) - .with_js_error()? + .to_value(&platform_version.into())? .serialize(&serializer) - .map_err(JsValue::from) + .map_err(|e| WasmDppError::serialization(e.to_string())) } #[wasm_bindgen(js_name = "getSchemas")] - pub fn get_schemas(&self) -> Result { + pub fn get_schemas(&self) -> WasmDppResult { let serializer = serde_wasm_bindgen::Serializer::json_compatible(); self.0 .document_schemas() .serialize(&serializer) - .map_err(JsValue::from) + .map_err(|e| WasmDppError::serialization(e.to_string())) } #[wasm_bindgen(getter = "version")] @@ -322,15 +318,15 @@ impl DataContractWasm { } #[wasm_bindgen(js_name = "getConfig")] - pub fn get_config(&self) -> Result { + pub fn get_config(&self) -> WasmDppResult { self.0 .config() .serialize(&serde_wasm_bindgen::Serializer::json_compatible()) - .map_err(JsValue::from) + .map_err(|e| WasmDppError::serialization(e.to_string())) } #[wasm_bindgen(getter = "tokens")] - pub fn get_tokens(&self) -> Result { + pub fn get_tokens(&self) -> WasmDppResult { let tokens_object = Object::new(); for (key, value) in self.0.tokens().iter() { @@ -338,14 +334,15 @@ impl DataContractWasm { &tokens_object, &JsValue::from(key.clone()), &JsValue::from(TokenConfigurationWasm::from(value.clone())), - )?; + ) + .map_err(|e| WasmDppError::invalid_argument(e.as_string().unwrap_or_default()))?; } Ok(tokens_object) } #[wasm_bindgen(getter = "groups")] - pub fn get_groups(&self) -> Result { + pub fn get_groups(&self) -> WasmDppResult { let groups_object = Object::new(); for (key, value) in self.0.groups().iter() { @@ -353,21 +350,22 @@ impl DataContractWasm { &groups_object, &JsValue::from(key.clone()), &JsValue::from(GroupWasm::from(value.clone())), - )?; + ) + .map_err(|e| WasmDppError::invalid_argument(e.as_string().unwrap_or_default()))?; } Ok(groups_object.into()) } #[wasm_bindgen(setter = "id")] - pub fn set_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> { + pub fn set_id(&mut self, js_data_contract_id: &JsValue) -> WasmDppResult<()> { self.0 .set_id(IdentifierWasm::try_from(js_data_contract_id)?.into()); Ok(()) } #[wasm_bindgen(setter = "ownerId")] - pub fn set_owner_id(&mut self, js_owner_id: &JsValue) -> Result<(), JsValue> { + pub fn set_owner_id(&mut self, js_owner_id: &JsValue) -> WasmDppResult<()> { self.0 .set_owner_id(IdentifierWasm::try_from(js_owner_id)?.into()); Ok(()) @@ -383,16 +381,16 @@ impl DataContractWasm { &mut self, js_config: JsValue, js_platform_version: JsValue, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, }; - let config_value: Value = serde_wasm_bindgen::from_value(js_config)?; + let config_value: Value = serde_wasm_bindgen::from_value(js_config) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; - let config = DataContractConfig::from_value(config_value, &platform_version.into()) - .with_js_error()?; + let config = DataContractConfig::from_value(config_value, &platform_version.into())?; self.0.set_config(config); @@ -406,7 +404,7 @@ impl DataContractWasm { js_definitions: Option, full_validation: bool, js_platform_version: JsValue, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, @@ -416,45 +414,50 @@ impl DataContractWasm { let definitions: Option> = js_definitions .map(|definitions| serde_wasm_bindgen::from_value(definitions.into())) - .transpose()?; + .transpose() + .map_err(|err| WasmDppError::serialization(err.to_string()))?; - self.0 - .set_document_schemas( - schema, - definitions, - full_validation, - &mut Vec::new(), - &platform_version.into(), - ) - .with_js_error()?; + self.0.set_document_schemas( + schema, + definitions, + full_validation, + &mut Vec::new(), + &platform_version.into(), + )?; Ok(()) } #[wasm_bindgen(setter = "tokens")] - pub fn set_tokens(&mut self, js_tokens: &JsValue) -> Result<(), JsValue> { - Ok(self - .0 - .set_tokens(tokens_configuration_from_js_value(js_tokens)?)) + pub fn set_tokens(&mut self, js_tokens: &JsValue) -> WasmDppResult<()> { + self.0 + .set_tokens(tokens_configuration_from_js_value(js_tokens)?); + Ok(()) } #[wasm_bindgen(setter = "groups")] - pub fn set_groups(&mut self, js_groups: &JsValue) -> Result<(), JsValue> { + pub fn set_groups(&mut self, js_groups: &JsValue) -> WasmDppResult<()> { let groups_object = Object::from(js_groups.clone()); let mut groups: BTreeMap = BTreeMap::new(); for js_position in Object::keys(&groups_object) { - if js_position.as_f64().unwrap() > u16::MAX as f64 { - return Err(JsValue::from_str(&format!( - "Position value '{:?}' exceeds the maximum limit for u16.", - js_position.as_string() - ))); - } - - let position = js_position.as_f64().unwrap() as u16; - - let js_group = Reflect::get(&groups_object, &js_position)?; + let position_str = js_position.as_string().ok_or_else(|| { + WasmDppError::invalid_argument(format!( + "Group position '{:?}' must be a stringified number.", + js_position + )) + })?; + + let position = position_str.parse::().map_err(|err| { + WasmDppError::invalid_argument(format!( + "Invalid group position '{}': {}.", + position_str, err + )) + })?; + + let js_group = Reflect::get(&groups_object, &js_position) + .map_err(|e| WasmDppError::invalid_argument(e.as_string().unwrap_or_default()))?; let group = js_group.to_wasm::("Group")?.clone(); @@ -467,23 +470,23 @@ impl DataContractWasm { } #[wasm_bindgen(js_name = "toJSON")] - pub fn to_json(&self, js_platform_version: JsValue) -> Result { + pub fn to_json(&self, js_platform_version: JsValue) -> WasmDppResult { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, }; - let json = self.0.to_json(&platform_version.into()).with_js_error()?; + let json = self.0.to_json(&platform_version.into())?; json.serialize(&serde_wasm_bindgen::Serializer::json_compatible()) - .map_err(JsValue::from) + .map_err(|e| WasmDppError::serialization(e.to_string())) } #[wasm_bindgen(js_name = "generateId")] pub fn generate_id( js_owner_id: &JsValue, identity_nonce: IdentityNonce, - ) -> Result { + ) -> WasmDppResult { Ok(DataContract::generate_data_contract_id_v0( IdentifierWasm::try_from(js_owner_id)?.to_bytes(), identity_nonce, @@ -496,7 +499,7 @@ impl DataContractWasm { pub fn get_document_type_ref_by_name( &self, name: String, - ) -> Result { + ) -> Result, DataContractError> { self.0.document_type_for_name(name.as_str()).clone() } } diff --git a/packages/wasm-dpp2/src/error.rs b/packages/wasm-dpp2/src/error.rs new file mode 100644 index 00000000000..f8bdc59dcd9 --- /dev/null +++ b/packages/wasm-dpp2/src/error.rs @@ -0,0 +1,140 @@ +use anyhow::Error as AnyhowError; +use dpp::ProtocolError; +use js_sys::Error as JsError; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{JsCast, JsValue}; + +/// Structured error returned by wasm-dpp2 APIs. +#[wasm_bindgen] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum WasmDppErrorKind { + /// Error raised by Dash Platform Protocol. + Protocol, + /// Invalid argument provided by the caller. + InvalidArgument, + /// Serialization or deserialization failure. + Serialization, + /// Type conversion failure. + Conversion, + /// Catch-all for other failure modes. + Generic, +} + +/// Structured error returned by wasm-dpp2 APIs. +#[wasm_bindgen] +#[derive(thiserror::Error, Debug, Clone)] +#[error("{message}")] +pub struct WasmDppError { + kind: WasmDppErrorKind, + message: String, + /// Optional numeric error code. `-1` indicates absence. + code: i32, +} + +impl WasmDppError { + pub(crate) fn new( + kind: WasmDppErrorKind, + message: impl Into, + code: Option, + ) -> Self { + Self { + kind, + message: message.into(), + code: code.unwrap_or(-1), + } + } + + pub(crate) fn protocol(message: impl Into) -> Self { + Self::new(WasmDppErrorKind::Protocol, message, None) + } + + #[allow(dead_code)] + pub(crate) fn invalid_argument(message: impl Into) -> Self { + Self::new(WasmDppErrorKind::InvalidArgument, message, None) + } + + pub(crate) fn serialization(message: impl Into) -> Self { + Self::new(WasmDppErrorKind::Serialization, message, None) + } + + #[allow(dead_code)] + pub(crate) fn conversion(message: impl Into) -> Self { + Self::new(WasmDppErrorKind::Conversion, message, None) + } + + pub(crate) fn generic(message: impl Into) -> Self { + Self::new(WasmDppErrorKind::Generic, message, None) + } +} + +impl From for WasmDppError { + fn from(error: ProtocolError) -> Self { + Self::protocol(error.to_string()) + } +} + +impl From for WasmDppError { + fn from(error: AnyhowError) -> Self { + Self::generic(error.to_string()) + } +} + +impl From for WasmDppError { + fn from(value: JsValue) -> Self { + if value.is_null() || value.is_undefined() { + return WasmDppError::invalid_argument("JavaScript error: value is null or undefined"); + } + + if let Some(js_error) = value.dyn_ref::() { + return WasmDppError::invalid_argument(js_error.message()); + } + + if let Some(message) = value.as_string() { + return WasmDppError::invalid_argument(message); + } + + let message = js_sys::JSON::stringify(&value) + .ok() + .and_then(|v| v.as_string()) + .unwrap_or_else(|| "Unknown JavaScript error".to_string()); + + WasmDppError::invalid_argument(message) + } +} + +#[wasm_bindgen] +impl WasmDppError { + /// Returns the structured error kind. + #[wasm_bindgen(getter)] + pub fn kind(&self) -> WasmDppErrorKind { + self.kind + } + + /// Backwards-compatible string representation of the kind. + #[wasm_bindgen(getter)] + pub fn name(&self) -> String { + match self.kind { + WasmDppErrorKind::Protocol => "Protocol", + WasmDppErrorKind::InvalidArgument => "InvalidArgument", + WasmDppErrorKind::Serialization => "Serialization", + WasmDppErrorKind::Conversion => "Conversion", + WasmDppErrorKind::Generic => "Generic", + } + .to_string() + } + + /// Human-readable error message. + #[wasm_bindgen(getter)] + pub fn message(&self) -> String { + self.message.clone() + } + + /// Optional numeric code. `-1` means absent. + #[wasm_bindgen(getter)] + pub fn code(&self) -> i32 { + self.code + } +} + +/// Result alias that uses `WasmDppError` as the error type. +pub type WasmDppResult = Result; diff --git a/packages/wasm-dpp2/src/identity/mod.rs b/packages/wasm-dpp2/src/identity/mod.rs index 5ba0cd1c46d..d3beb34195f 100644 --- a/packages/wasm-dpp2/src/identity/mod.rs +++ b/packages/wasm-dpp2/src/identity/mod.rs @@ -1,6 +1,6 @@ +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::identity_public_key::IdentityPublicKeyWasm; -use crate::utils::WithJsError; use dpp::identity::accessors::{IdentityGettersV0, IdentitySettersV0}; use dpp::identity::{self, Identity, KeyID}; use dpp::platform_value::ReplacementType; @@ -12,8 +12,8 @@ use dpp::version::PlatformVersion; use serde_json::Value as JsonValue; use serde_wasm_bindgen::to_value; use std::collections::BTreeMap; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[derive(Clone)] #[wasm_bindgen(js_name = "Identity")] @@ -38,20 +38,20 @@ impl IdentityWasm { } #[wasm_bindgen(constructor)] - pub fn new(js_identifier: &JsValue) -> Result { - let identifier: IdentifierWasm = js_identifier.try_into()?; + pub fn new(js_identifier: &JsValue) -> WasmDppResult { + let identifier = IdentifierWasm::try_from(js_identifier)?; - let identity = Identity::create_basic_identity(identifier.into(), PlatformVersion::first()) - .with_js_error()?; + let identity = + Identity::create_basic_identity(identifier.into(), PlatformVersion::first())?; Ok(IdentityWasm(identity)) } #[wasm_bindgen(setter = "id")] - pub fn set_id(&mut self, js_identifier: &JsValue) -> Result<(), JsValue> { - Ok(self - .0 - .set_id(IdentifierWasm::try_from(js_identifier)?.into())) + pub fn set_id(&mut self, js_identifier: &JsValue) -> WasmDppResult<()> { + let identifier = IdentifierWasm::try_from(js_identifier)?; + self.0.set_id(identifier.into()); + Ok(()) } #[wasm_bindgen(setter = "balance")] @@ -105,85 +105,81 @@ impl IdentityWasm { } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = + decode(hex.as_str(), Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; IdentityWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + pub fn from_base64(base64: String) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; IdentityWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> Result, JsValue> { - self.0.serialize_to_bytes().with_js_error() + pub fn to_bytes(&self) -> WasmDppResult> { + Ok(self.0.serialize_to_bytes()?) } #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Hex, - )) + pub fn to_hex(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; + Ok(encode(bytes.as_slice(), Hex)) } #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Base64, - )) + pub fn to_base64(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; + Ok(encode(bytes.as_slice(), Base64)) } - fn cleaned_json_value(&self) -> Result { - let mut value = self.0.to_object().with_js_error()?; + fn cleaned_json_value(&self) -> WasmDppResult { + let mut value = self.0.to_object()?; value .replace_at_paths( identity::IDENTIFIER_FIELDS_RAW_OBJECT, ReplacementType::TextBase58, ) - .map_err(|e| JsValue::from_str(&e.to_string()))?; + .map_err(|e| WasmDppError::serialization(e.to_string()))?; if let Some(public_keys) = value .get_optional_array_mut_ref(identity::property_names::PUBLIC_KEYS) - .map_err(|e| JsValue::from_str(&e.to_string()))? + .map_err(|e| WasmDppError::serialization(e.to_string()))? { for key in public_keys.iter_mut() { key.replace_at_paths( identity::identity_public_key::BINARY_DATA_FIELDS, ReplacementType::TextBase64, ) - .map_err(|e| JsValue::from_str(&e.to_string()))?; + .map_err(|e| WasmDppError::serialization(e.to_string()))?; } } value .try_into_validating_json() - .map_err(|e| JsValue::from_str(&e.to_string())) + .map_err(|e| WasmDppError::serialization(e.to_string())) } #[wasm_bindgen(js_name = "toObject")] - pub fn to_object(&self) -> Result { + pub fn to_object(&self) -> WasmDppResult { let json_value = self.cleaned_json_value()?; - to_value(&json_value).map_err(|e| JsValue::from_str(&e.to_string())) + to_value(&json_value).map_err(|e| WasmDppError::serialization(e.to_string())) } #[wasm_bindgen(js_name = "toJSON")] - pub fn to_json(&self) -> Result { + pub fn to_json(&self) -> WasmDppResult { self.to_object() } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { - match Identity::deserialize_from_bytes(bytes.as_slice()).with_js_error() { - Ok(identity) => Ok(IdentityWasm(identity)), - Err(err) => Err(err), - } + pub fn from_bytes(bytes: Vec) -> WasmDppResult { + let identity = Identity::deserialize_from_bytes(bytes.as_slice())?; + Ok(IdentityWasm(identity)) } } diff --git a/packages/wasm-dpp2/src/identity_public_key/mod.rs b/packages/wasm-dpp2/src/identity_public_key/mod.rs index 8c9cd07b26f..95ae9f1f245 100644 --- a/packages/wasm-dpp2/src/identity_public_key/mod.rs +++ b/packages/wasm-dpp2/src/identity_public_key/mod.rs @@ -3,7 +3,8 @@ use crate::enums::keys::key_type::KeyTypeWasm; use crate::enums::keys::purpose::PurposeWasm; use crate::enums::keys::security_level::SecurityLevelWasm; use crate::enums::network::NetworkWasm; -use crate::utils::{IntoWasm, WithJsError}; +use crate::error::{WasmDppError, WasmDppResult}; +use crate::utils::IntoWasm; use dpp::dashcore::Network; use dpp::dashcore::secp256k1::hashes::hex::{Case, DisplayHex}; use dpp::identity::contract_bounds::ContractBounds; @@ -17,8 +18,8 @@ use dpp::platform_value::BinaryData; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; use dpp::platform_value::string_encoding::{decode, encode}; use dpp::serialization::{PlatformDeserializable, PlatformSerializable}; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[derive(Clone)] #[wasm_bindgen(js_name = IdentityPublicKey)] @@ -58,7 +59,7 @@ impl IdentityPublicKeyWasm { binary_data: &str, disabled_at: Option, js_contract_bounds: &JsValue, - ) -> Result { + ) -> WasmDppResult { let purpose = PurposeWasm::try_from(js_purpose)?; let security_level = SecurityLevelWasm::try_from(js_security_level)?; let key_type = KeyTypeWasm::try_from(js_key_type)?; @@ -81,7 +82,8 @@ impl IdentityPublicKeyWasm { contract_bounds, key_type: KeyType::from(key_type), read_only, - data: BinaryData::from_string(binary_data, Hex).unwrap(), + data: BinaryData::from_string(binary_data, Hex) + .map_err(|e| WasmDppError::serialization(e.to_string()))?, disabled_at, }, ))) @@ -95,16 +97,18 @@ impl IdentityPublicKeyWasm { &self, js_private_key_bytes: Vec, js_network: JsValue, - ) -> Result { + ) -> WasmDppResult { let mut private_key_bytes = [0u8; 32]; let len = js_private_key_bytes.len().min(32); private_key_bytes[..len].copy_from_slice(&js_private_key_bytes[..len]); let network = Network::from(NetworkWasm::try_from(js_network)?); - self.0 - .validate_private_key_bytes(&private_key_bytes, network) - .with_js_error() + let is_valid = self + .0 + .validate_private_key_bytes(&private_key_bytes, network)?; + + Ok(is_valid) } #[wasm_bindgen(js_name = "getContractBounds")] @@ -171,40 +175,39 @@ impl IdentityPublicKeyWasm { } #[wasm_bindgen(setter = purpose)] - pub fn set_purpose(&mut self, purpose: JsValue) -> Result<(), JsValue> { - Ok(self - .0 - .set_purpose(Purpose::from(PurposeWasm::try_from(purpose)?))) + pub fn set_purpose(&mut self, purpose: JsValue) -> WasmDppResult<()> { + let purpose = PurposeWasm::try_from(purpose)?; + self.0.set_purpose(Purpose::from(purpose)); + Ok(()) } #[wasm_bindgen(setter = purposeNumber)] - pub fn set_purpose_number(&mut self, purpose: JsValue) -> Result<(), JsValue> { + pub fn set_purpose_number(&mut self, purpose: JsValue) -> WasmDppResult<()> { self.set_purpose(purpose) } #[wasm_bindgen(setter = securityLevel)] - pub fn set_security_level(&mut self, security_level: JsValue) -> Result<(), JsValue> { - Ok(self - .0 - .set_security_level(SecurityLevel::from(SecurityLevelWasm::try_from( - security_level, - )?))) + pub fn set_security_level(&mut self, security_level: JsValue) -> WasmDppResult<()> { + let security_level = SecurityLevelWasm::try_from(security_level)?; + self.0 + .set_security_level(SecurityLevel::from(security_level)); + Ok(()) } #[wasm_bindgen(setter = securityLevelNumber)] - pub fn set_security_level_number(&mut self, security_level: JsValue) -> Result<(), JsValue> { + pub fn set_security_level_number(&mut self, security_level: JsValue) -> WasmDppResult<()> { self.set_security_level(security_level) } #[wasm_bindgen(setter = keyType)] - pub fn set_key_type(&mut self, key_type: JsValue) -> Result<(), JsValue> { - Ok(self - .0 - .set_key_type(KeyType::from(KeyTypeWasm::try_from(key_type)?))) + pub fn set_key_type(&mut self, key_type: JsValue) -> WasmDppResult<()> { + let key_type = KeyTypeWasm::try_from(key_type)?; + self.0.set_key_type(KeyType::from(key_type)); + Ok(()) } #[wasm_bindgen(setter = keyTypeNumber)] - pub fn set_key_type_number(&mut self, key_type: JsValue) -> Result<(), JsValue> { + pub fn set_key_type_number(&mut self, key_type: JsValue) -> WasmDppResult<()> { self.set_key_type(key_type) } @@ -214,10 +217,12 @@ impl IdentityPublicKeyWasm { } #[wasm_bindgen(setter = data)] - pub fn set_data(&mut self, binary_data: &str) { - let data = BinaryData::from_string(binary_data, Hex).unwrap(); + pub fn set_data(&mut self, binary_data: &str) -> WasmDppResult<()> { + let data = BinaryData::from_string(binary_data, Hex) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; - self.0.set_data(data) + self.0.set_data(data); + Ok(()) } #[wasm_bindgen(setter = disabledAt)] @@ -226,12 +231,11 @@ impl IdentityPublicKeyWasm { } #[wasm_bindgen(js_name = "getPublicKeyHash")] - pub fn public_key_hash(&self) -> Result { + pub fn public_key_hash(&self) -> WasmDppResult { let hash = self .0 - .public_key_hash() - .with_js_error() - .map(|slice| slice.to_vec())? + .public_key_hash()? + .to_vec() .to_hex_string(Case::Lower); Ok(hash) @@ -243,50 +247,43 @@ impl IdentityPublicKeyWasm { } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> Result, JsValue> { - self.0.serialize_to_bytes().with_js_error() + pub fn to_bytes(&self) -> WasmDppResult> { + Ok(self.0.serialize_to_bytes()?) } #[wasm_bindgen(js_name = hex)] - pub fn to_hex(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Hex, - )) + pub fn to_hex(&self) -> WasmDppResult { + Ok(encode(self.0.serialize_to_bytes()?.as_slice(), Hex)) } #[wasm_bindgen(js_name = base64)] - pub fn to_base64(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Base64, - )) + pub fn to_base64(&self) -> WasmDppResult { + Ok(encode(self.0.serialize_to_bytes()?.as_slice(), Base64)) } #[wasm_bindgen(js_name = fromBytes)] - pub fn from_bytes(bytes: Vec) -> Result { - let public_key = - IdentityPublicKey::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + pub fn from_bytes(bytes: Vec) -> WasmDppResult { + let public_key = IdentityPublicKey::deserialize_from_bytes(bytes.as_slice())?; Ok(IdentityPublicKeyWasm(public_key)) } #[wasm_bindgen(js_name = fromHex)] - pub fn from_hex(hex: String) -> Result { - let bytes = decode(&hex, Hex).map_err(|err| JsValue::from(JsError::from(err)))?; + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = + decode(&hex, Hex).map_err(|err| WasmDppError::serialization(err.to_string()))?; - let public_key = - IdentityPublicKey::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + let public_key = IdentityPublicKey::deserialize_from_bytes(bytes.as_slice())?; Ok(IdentityPublicKeyWasm(public_key)) } #[wasm_bindgen(js_name = fromBase64)] - pub fn from_base64(hex: String) -> Result { - let bytes = decode(&hex, Base64).map_err(|err| JsValue::from(JsError::from(err)))?; + pub fn from_base64(hex: String) -> WasmDppResult { + let bytes = + decode(&hex, Base64).map_err(|err| WasmDppError::serialization(err.to_string()))?; - let public_key = - IdentityPublicKey::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + let public_key = IdentityPublicKey::deserialize_from_bytes(bytes.as_slice())?; Ok(IdentityPublicKeyWasm(public_key)) } diff --git a/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs index 7ae168492b7..34bab76d618 100644 --- a/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs @@ -1,9 +1,9 @@ use crate::asset_lock_proof::AssetLockProofWasm; use crate::enums::platform::PlatformVersionWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::identity_transitions::public_key_in_creation::IdentityPublicKeyInCreationWasm; use crate::state_transition::StateTransitionWasm; -use crate::utils::WithJsError; use dpp::identity::state_transition::AssetLockProved; use dpp::platform_value::BinaryData; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; @@ -15,8 +15,8 @@ use dpp::state_transition::identity_create_transition::accessors::IdentityCreate use dpp::state_transition::identity_create_transition::v0::IdentityCreateTransitionV0; use dpp::state_transition::public_key_in_creation::IdentityPublicKeyInCreation; use dpp::state_transition::{StateTransition, StateTransitionLike}; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "IdentityCreateTransition")] #[derive(Clone)] @@ -52,7 +52,7 @@ impl IdentityCreateTransitionWasm { asset_lock: &AssetLockProofWasm, signature: Option>, user_fee_increase: Option, - ) -> Result { + ) -> WasmDppResult { let public_keys: Vec = IdentityPublicKeyInCreationWasm::vec_from_js_value(js_public_keys)?; @@ -68,37 +68,38 @@ impl IdentityCreateTransitionWasm { } #[wasm_bindgen(js_name = "default")] - pub fn default(js_platform_version: JsValue) -> Result { + pub fn default(js_platform_version: JsValue) -> WasmDppResult { let platform_version = PlatformVersionWasm::try_from(js_platform_version)?; IdentityCreateTransition::default_versioned(&platform_version.into()) - .map_err(|err| JsValue::from_str(&*err.to_string())) + .map_err(|err| WasmDppError::generic(err.to_string())) .map(Into::into) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = + decode(hex.as_str(), Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; IdentityCreateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + pub fn from_base64(base64: String) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; IdentityCreateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> Result, JsValue> { - self.0.serialize_to_bytes().with_js_error() + pub fn to_bytes(&self) -> WasmDppResult> { + Ok(self.0.serialize_to_bytes()?) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { - let rs_transition = - IdentityCreateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + pub fn from_bytes(bytes: Vec) -> WasmDppResult { + let rs_transition = IdentityCreateTransition::deserialize_from_bytes(bytes.as_slice())?; Ok(IdentityCreateTransitionWasm(rs_transition)) } @@ -128,8 +129,8 @@ impl IdentityCreateTransitionWasm { } #[wasm_bindgen(js_name = "getSignableBytes")] - pub fn get_signable_bytes(&self) -> Result, JsValue> { - self.0.signable_bytes().with_js_error() + pub fn get_signable_bytes(&self) -> WasmDppResult> { + Ok(self.0.signable_bytes()?) } #[wasm_bindgen(getter = "assetLock")] @@ -138,7 +139,7 @@ impl IdentityCreateTransitionWasm { } #[wasm_bindgen(setter = "publicKeys")] - pub fn set_public_keys(&mut self, js_public_keys: &js_sys::Array) -> Result<(), JsValue> { + pub fn set_public_keys(&mut self, js_public_keys: &js_sys::Array) -> WasmDppResult<()> { let public_keys: Vec = IdentityPublicKeyInCreationWasm::vec_from_js_value(js_public_keys)?; @@ -163,8 +164,9 @@ impl IdentityCreateTransitionWasm { } #[wasm_bindgen(setter = "assetLock")] - pub fn set_asset_lock_proof(&mut self, proof: AssetLockProofWasm) -> Result<(), JsValue> { - self.0.set_asset_lock_proof(proof.into()).with_js_error() + pub fn set_asset_lock_proof(&mut self, proof: AssetLockProofWasm) -> WasmDppResult<()> { + self.0.set_asset_lock_proof(proof.into())?; + Ok(()) } #[wasm_bindgen(js_name = "toStateTransition")] @@ -175,13 +177,13 @@ impl IdentityCreateTransitionWasm { #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( st: &StateTransitionWasm, - ) -> Result { + ) -> WasmDppResult { let rs_st: StateTransition = st.clone().into(); match rs_st { StateTransition::IdentityCreate(st) => Ok(IdentityCreateTransitionWasm(st)), - _ => Err(JsValue::from_str( - &"Invalid state document_transition type)", + _ => Err(WasmDppError::invalid_argument( + "Invalid state transition type", )), } } diff --git a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs index ccf88364505..bc339e62f79 100644 --- a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs @@ -2,9 +2,10 @@ use crate::asset_lock_proof::AssetLockProofWasm; use crate::core_script::CoreScriptWasm; use crate::enums::keys::purpose::PurposeWasm; use crate::enums::withdrawal::PoolingWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::state_transition::StateTransitionWasm; -use crate::utils::{IntoWasm, WithJsError}; +use crate::utils::IntoWasm; use dpp::identity::KeyID; use dpp::identity::core_script::CoreScript; use dpp::identity::state_transition::OptionallyAssetLockProved; @@ -17,8 +18,8 @@ use dpp::state_transition::identity_credit_withdrawal_transition::IdentityCredit use dpp::state_transition::identity_credit_withdrawal_transition::accessors::IdentityCreditWithdrawalTransitionAccessorsV0; use dpp::state_transition::identity_credit_withdrawal_transition::v1::IdentityCreditWithdrawalTransitionV1; use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "IdentityCreditWithdrawalTransition")] pub struct IdentityCreditWithdrawalTransitionWasm(IdentityCreditWithdrawalTransition); @@ -44,7 +45,7 @@ impl IdentityCreditWithdrawalTransitionWasm { js_output_script: &JsValue, nonce: Option, user_fee_increase: Option, - ) -> Result { + ) -> WasmDppResult { let pooling = PoolingWasm::try_from(js_pooling)?; let identity_id: Identifier = IdentifierWasm::try_from(js_identity_id)?.into(); @@ -133,30 +134,30 @@ impl IdentityCreditWithdrawalTransitionWasm { } #[wasm_bindgen(setter = "outputScript")] - pub fn set_output_script(&mut self, js_script: &JsValue) -> Result<(), JsValue> { - match js_script.is_undefined() { - true => self.0.set_output_script(None), - false => { - let script: CoreScriptWasm = - js_script.to_wasm::("CoreScript")?.clone(); - self.0.set_output_script(Some(script.clone().into())) - } - }; + pub fn set_output_script(&mut self, js_script: &JsValue) -> WasmDppResult<()> { + if js_script.is_undefined() { + self.0.set_output_script(None); + } else { + let script: CoreScriptWasm = js_script.to_wasm::("CoreScript")?.clone(); + self.0.set_output_script(Some(script.clone().into())); + } Ok(()) } #[wasm_bindgen(setter = "pooling")] - pub fn set_pooling(&mut self, js_pooling: JsValue) -> Result<(), JsValue> { + pub fn set_pooling(&mut self, js_pooling: JsValue) -> WasmDppResult<()> { let pooling: PoolingWasm = PoolingWasm::try_from(js_pooling)?; - Ok(self.0.set_pooling(pooling.into())) + self.0.set_pooling(pooling.into()); + Ok(()) } #[wasm_bindgen(setter = "identityId")] - pub fn set_identity_id(&mut self, js_identity_id: JsValue) -> Result<(), JsValue> { + pub fn set_identity_id(&mut self, js_identity_id: JsValue) -> WasmDppResult<()> { let identity_id = IdentifierWasm::try_from(js_identity_id)?; - Ok(self.0.set_identity_id(identity_id.into())) + self.0.set_identity_id(identity_id.into()); + Ok(()) } #[wasm_bindgen(setter = "userFeeIncrease")] @@ -190,8 +191,8 @@ impl IdentityCreditWithdrawalTransitionWasm { } #[wasm_bindgen(js_name = "getSignableBytes")] - pub fn get_signable_bytes(&self) -> Result, JsValue> { - self.0.signable_bytes().with_js_error() + pub fn get_signable_bytes(&self) -> WasmDppResult> { + Ok(self.0.signable_bytes()?) } #[wasm_bindgen(getter = "signaturePublicKeyId")] @@ -210,45 +211,42 @@ impl IdentityCreditWithdrawalTransitionWasm { } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = + decode(hex.as_str(), Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; IdentityCreditWithdrawalTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + pub fn from_base64(base64: String) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; IdentityCreditWithdrawalTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> Result, JsValue> { - self.0.serialize_to_bytes().with_js_error() + pub fn to_bytes(&self) -> WasmDppResult> { + Ok(self.0.serialize_to_bytes()?) } #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Hex, - )) + pub fn to_hex(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; + Ok(encode(bytes.as_slice(), Hex)) } #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Base64, - )) + pub fn to_base64(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; + Ok(encode(bytes.as_slice(), Base64)) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> WasmDppResult { let rs_transition = - IdentityCreditWithdrawalTransition::deserialize_from_bytes(bytes.as_slice()) - .with_js_error()?; + IdentityCreditWithdrawalTransition::deserialize_from_bytes(bytes.as_slice())?; Ok(IdentityCreditWithdrawalTransitionWasm(rs_transition)) } @@ -261,14 +259,16 @@ impl IdentityCreditWithdrawalTransitionWasm { #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( st: &StateTransitionWasm, - ) -> Result { + ) -> WasmDppResult { let rs_st: StateTransition = st.clone().into(); match rs_st { StateTransition::IdentityCreditWithdrawal(st) => { Ok(IdentityCreditWithdrawalTransitionWasm(st)) } - _ => Err(JsValue::from_str(&"Invalid state transition type)")), + _ => Err(WasmDppError::invalid_argument( + "Invalid state transition type", + )), } } } diff --git a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs index 8a6e81d3666..f9e7150fdb7 100644 --- a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs @@ -1,6 +1,6 @@ +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::state_transition::StateTransitionWasm; -use crate::utils::WithJsError; use dpp::platform_value::BinaryData; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; use dpp::platform_value::string_encoding::{decode, encode}; @@ -10,8 +10,8 @@ use dpp::state_transition::identity_credit_transfer_transition::IdentityCreditTr use dpp::state_transition::identity_credit_transfer_transition::accessors::IdentityCreditTransferTransitionAccessorsV0; use dpp::state_transition::identity_credit_transfer_transition::v0::IdentityCreditTransferTransitionV0; use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = IdentityCreditTransfer)] #[derive(Clone)] @@ -36,9 +36,8 @@ impl IdentityCreditTransferWasm { js_recipient: &JsValue, nonce: u64, user_fee_increase: Option, - ) -> Result { + ) -> WasmDppResult { let sender: Identifier = IdentifierWasm::try_from(js_sender)?.into(); - let recipient: Identifier = IdentifierWasm::try_from(js_recipient)?.into(); Ok(IdentityCreditTransferWasm( @@ -55,57 +54,58 @@ impl IdentityCreditTransferWasm { } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> Result, JsValue> { - self.0.serialize_to_bytes().with_js_error() + pub fn to_bytes(&self) -> WasmDppResult> { + Ok(self.0.serialize_to_bytes()?) } #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Hex, - )) + pub fn to_hex(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; + Ok(encode(bytes.as_slice(), Hex)) } #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Base64, - )) + pub fn to_base64(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; + Ok(encode(bytes.as_slice(), Base64)) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> WasmDppResult { let rs_transition = - IdentityCreditTransferTransition::deserialize_from_bytes(bytes.as_slice()) - .with_js_error()?; + IdentityCreditTransferTransition::deserialize_from_bytes(bytes.as_slice())?; Ok(IdentityCreditTransferWasm(rs_transition)) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - IdentityCreditTransferWasm::from_bytes(decode(hex.as_str(), Hex).map_err(JsError::from)?) + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = + decode(hex.as_str(), Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; + IdentityCreditTransferWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(hex: String) -> Result { - IdentityCreditTransferWasm::from_bytes(decode(hex.as_str(), Base64).map_err(JsError::from)?) + pub fn from_base64(hex: String) -> WasmDppResult { + let bytes = + decode(hex.as_str(), Base64).map_err(|e| WasmDppError::serialization(e.to_string()))?; + IdentityCreditTransferWasm::from_bytes(bytes) } #[wasm_bindgen(setter = "recipientId")] - pub fn set_recipient_id(&mut self, js_recipient: &JsValue) -> Result<(), JsValue> { + pub fn set_recipient_id(&mut self, js_recipient: &JsValue) -> WasmDppResult<()> { let recipient: Identifier = IdentifierWasm::try_from(js_recipient)?.into(); - Ok(self.0.set_recipient_id(recipient)) + self.0.set_recipient_id(recipient); + Ok(()) } #[wasm_bindgen(setter = "senderId")] - pub fn set_sender_id(&mut self, js_sender: &JsValue) -> Result<(), JsValue> { + pub fn set_sender_id(&mut self, js_sender: &JsValue) -> WasmDppResult<()> { let sender: Identifier = IdentifierWasm::try_from(js_sender)?.into(); - Ok(self.0.set_identity_id(sender)) + self.0.set_identity_id(sender); + Ok(()) } #[wasm_bindgen(setter = "amount")] @@ -139,8 +139,8 @@ impl IdentityCreditTransferWasm { } #[wasm_bindgen(js_name = "getSignableBytes")] - pub fn get_signable_bytes(&self) -> Result, JsValue> { - self.0.signable_bytes().with_js_error() + pub fn get_signable_bytes(&self) -> WasmDppResult> { + Ok(self.0.signable_bytes()?) } #[wasm_bindgen(getter = "signaturePublicKeyId")] @@ -181,12 +181,14 @@ impl IdentityCreditTransferWasm { #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( st: &StateTransitionWasm, - ) -> Result { + ) -> WasmDppResult { let rs_st: StateTransition = st.clone().into(); match rs_st { StateTransition::IdentityCreditTransfer(st) => Ok(IdentityCreditTransferWasm(st)), - _ => Err(JsValue::from_str(&"Invalid state transition type)")), + _ => Err(WasmDppError::invalid_argument( + "Invalid state transition type", + )), } } } diff --git a/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs b/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs index 13c5a5d4160..85b552ca542 100644 --- a/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs @@ -2,8 +2,9 @@ use crate::contract_bounds::ContractBoundsWasm; use crate::enums::keys::key_type::KeyTypeWasm; use crate::enums::keys::purpose::PurposeWasm; use crate::enums::keys::security_level::SecurityLevelWasm; +use crate::error::WasmDppResult; use crate::identity_public_key::IdentityPublicKeyWasm; -use crate::utils::{IntoWasm, WithJsError}; +use crate::utils::IntoWasm; use dpp::identity::contract_bounds::ContractBounds; use dpp::identity::identity_public_key::v0::IdentityPublicKeyV0; use dpp::identity::{IdentityPublicKey, KeyType, Purpose, SecurityLevel}; @@ -85,7 +86,7 @@ impl IdentityPublicKeyInCreationWasm { binary_data: Vec, signature: Option>, js_contract_bounds: &JsValue, - ) -> Result { + ) -> WasmDppResult { let purpose = PurposeWasm::try_from(js_purpose)?; let security_level = SecurityLevelWasm::try_from(js_security_level)?; let key_type = KeyTypeWasm::try_from(js_key_type)?; @@ -115,8 +116,8 @@ impl IdentityPublicKeyInCreationWasm { } #[wasm_bindgen(js_name = toIdentityPublicKey)] - pub fn to_identity_public_key(&self) -> Result { - IdentityPublicKeyWasm::new( + pub fn to_identity_public_key(&self) -> WasmDppResult { + Ok(IdentityPublicKeyWasm::new( self.0.id(), JsValue::from(PurposeWasm::from(self.0.purpose())), JsValue::from(SecurityLevelWasm::from(self.0.security_level())), @@ -125,15 +126,13 @@ impl IdentityPublicKeyInCreationWasm { self.0.data().to_string(Hex).as_str(), None, &JsValue::from(self.get_contract_bounds().clone()), - ) + )?) } #[wasm_bindgen(js_name = "getHash")] - pub fn get_hash(&self) -> Result, JsValue> { - match self.0.hash().with_js_error() { - Ok(hash) => Ok(hash.to_vec()), - Err(err) => Err(err), - } + pub fn get_hash(&self) -> WasmDppResult> { + let hash = self.0.hash()?; + Ok(hash.to_vec()) } #[wasm_bindgen(getter = "contractBounds")] @@ -185,21 +184,22 @@ impl IdentityPublicKeyInCreationWasm { } #[wasm_bindgen(setter = purpose)] - pub fn set_purpose(&mut self, js_purpose: JsValue) -> Result<(), JsValue> { + pub fn set_purpose(&mut self, js_purpose: JsValue) -> WasmDppResult<()> { let purpose = PurposeWasm::try_from(js_purpose)?; - Ok(self.0.set_purpose(Purpose::from(purpose))) + self.0.set_purpose(Purpose::from(purpose)); + Ok(()) } #[wasm_bindgen(setter = securityLevel)] - pub fn set_security_level(&mut self, js_security_level: JsValue) -> Result<(), JsValue> { + pub fn set_security_level(&mut self, js_security_level: JsValue) -> WasmDppResult<()> { let security_level = SecurityLevelWasm::try_from(js_security_level)?; - Ok(self - .0 - .set_security_level(SecurityLevel::from(security_level))) + self.0 + .set_security_level(SecurityLevel::from(security_level)); + Ok(()) } #[wasm_bindgen(setter = keyType)] - pub fn set_key_type(&mut self, key_type: JsValue) -> Result<(), JsValue> { + pub fn set_key_type(&mut self, key_type: JsValue) -> WasmDppResult<()> { let key_type = KeyTypeWasm::try_from(key_type)?; self.0.set_type(key_type.into()); Ok(()) @@ -223,7 +223,7 @@ impl IdentityPublicKeyInCreationWasm { } #[wasm_bindgen(setter = "contractBounds")] - pub fn set_contract_bounds(&mut self, js_bounds: &JsValue) -> Result<(), JsValue> { + pub fn set_contract_bounds(&mut self, js_bounds: &JsValue) -> WasmDppResult<()> { match js_bounds.is_undefined() { true => self.0.set_contract_bounds(None), false => { @@ -242,10 +242,10 @@ impl IdentityPublicKeyInCreationWasm { impl IdentityPublicKeyInCreationWasm { pub fn vec_from_js_value( js_add_public_keys: &js_sys::Array, - ) -> Result, JsValue> { + ) -> WasmDppResult> { let add_public_keys: Vec = js_add_public_keys .iter() - .map(|key| IdentityPublicKeyInCreationWasm::try_from(key)) + .map(IdentityPublicKeyInCreationWasm::try_from) .collect::, JsValue>>()?; Ok(add_public_keys) diff --git a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs index f186e82ae7b..9c4b6f3ba12 100644 --- a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs @@ -1,7 +1,7 @@ use crate::asset_lock_proof::AssetLockProofWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::state_transition::StateTransitionWasm; -use crate::utils::WithJsError; use dpp::identifier::Identifier; use dpp::identity::state_transition::{AssetLockProved, OptionallyAssetLockProved}; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; @@ -12,8 +12,8 @@ use dpp::state_transition::identity_topup_transition::IdentityTopUpTransition; use dpp::state_transition::identity_topup_transition::accessors::IdentityTopUpTransitionAccessorsV0; use dpp::state_transition::identity_topup_transition::v0::IdentityTopUpTransitionV0; use dpp::state_transition::{StateTransition, StateTransitionLike}; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "IdentityTopUpTransition")] #[derive(Clone)] @@ -36,7 +36,7 @@ impl IdentityTopUpTransitionWasm { asset_lock_proof: &AssetLockProofWasm, js_identity_id: JsValue, user_fee_increase: Option, - ) -> Result { + ) -> WasmDppResult { let identity_id: Identifier = IdentifierWasm::try_from(js_identity_id)?.into(); Ok(IdentityTopUpTransitionWasm(IdentityTopUpTransition::V0( @@ -90,20 +90,21 @@ impl IdentityTopUpTransitionWasm { pub fn set_identity_identifier( &mut self, js_identity_identifier: &JsValue, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let identity_identifier: Identifier = IdentifierWasm::try_from(js_identity_identifier)?.into(); - Ok(self.0.set_identity_id(identity_identifier.clone().into())) + self.0.set_identity_id(identity_identifier.clone().into()); + Ok(()) } #[wasm_bindgen(setter = "assetLockProof")] pub fn set_asset_lock_proof( &mut self, asset_lock_proof: &AssetLockProofWasm, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { self.0 - .set_asset_lock_proof(asset_lock_proof.clone().into()) - .with_js_error() + .set_asset_lock_proof(asset_lock_proof.clone().into())?; + Ok(()) } #[wasm_bindgen(getter = "signature")] @@ -112,8 +113,8 @@ impl IdentityTopUpTransitionWasm { } #[wasm_bindgen(js_name = "getSignableBytes")] - pub fn get_signable_bytes(&self) -> Result, JsValue> { - self.0.signable_bytes().with_js_error() + pub fn get_signable_bytes(&self) -> WasmDppResult> { + Ok(self.0.signable_bytes()?) } #[wasm_bindgen(setter = "signature")] @@ -122,44 +123,41 @@ impl IdentityTopUpTransitionWasm { } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> Result, JsValue> { - self.0.serialize_to_bytes().with_js_error() + pub fn to_bytes(&self) -> WasmDppResult> { + Ok(self.0.serialize_to_bytes()?) } #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Hex, - )) + pub fn to_hex(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; + Ok(encode(bytes.as_slice(), Hex)) } #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Base64, - )) + pub fn to_base64(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; + Ok(encode(bytes.as_slice(), Base64)) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { - let rs_transition = - IdentityTopUpTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + pub fn from_bytes(bytes: Vec) -> WasmDppResult { + let rs_transition = IdentityTopUpTransition::deserialize_from_bytes(bytes.as_slice())?; Ok(IdentityTopUpTransitionWasm(rs_transition)) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - IdentityTopUpTransitionWasm::from_bytes(decode(hex.as_str(), Hex).map_err(JsError::from)?) + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = + decode(hex.as_str(), Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; + IdentityTopUpTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - IdentityTopUpTransitionWasm::from_bytes( - decode(base64.as_str(), Base64).map_err(JsError::from)?, - ) + pub fn from_base64(base64: String) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; + IdentityTopUpTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "toStateTransition")] @@ -170,12 +168,14 @@ impl IdentityTopUpTransitionWasm { #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( st: &StateTransitionWasm, - ) -> Result { + ) -> WasmDppResult { let rs_st: StateTransition = st.clone().into(); match rs_st { StateTransition::IdentityTopUp(st) => Ok(IdentityTopUpTransitionWasm(st)), - _ => Err(JsValue::from_str(&"Invalid state transition type)")), + _ => Err(WasmDppError::invalid_argument( + "Invalid state transition type", + )), } } } diff --git a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs b/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs index 6403867a00d..803c587d4da 100644 --- a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs @@ -1,9 +1,9 @@ use crate::asset_lock_proof::AssetLockProofWasm; use crate::enums::keys::purpose::PurposeWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::identity_transitions::public_key_in_creation::IdentityPublicKeyInCreationWasm; use crate::state_transition::StateTransitionWasm; -use crate::utils::WithJsError; use dpp::identity::KeyID; use dpp::identity::state_transition::OptionallyAssetLockProved; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; @@ -15,8 +15,8 @@ use dpp::state_transition::identity_update_transition::accessors::IdentityUpdate use dpp::state_transition::identity_update_transition::v0::IdentityUpdateTransitionV0; use dpp::state_transition::public_key_in_creation::IdentityPublicKeyInCreation; use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "IdentityUpdateTransition")] #[derive(Clone)] @@ -42,7 +42,7 @@ impl IdentityUpdateTransitionWasm { js_add_public_keys: &js_sys::Array, disable_public_keys: Vec, user_fee_increase: Option, - ) -> Result { + ) -> WasmDppResult { let identity_id = IdentifierWasm::try_from(js_identity_id)?; let add_public_keys: Vec = @@ -138,7 +138,7 @@ impl IdentityUpdateTransitionWasm { } #[wasm_bindgen(setter = "identityIdentifier")] - pub fn set_identity_identifier(&mut self, js_identity_id: &JsValue) -> Result<(), JsValue> { + pub fn set_identity_identifier(&mut self, js_identity_id: &JsValue) -> WasmDppResult<()> { let identity_id = IdentifierWasm::try_from(js_identity_id)?; self.0.set_identity_id(identity_id.clone().into()); Ok(()) @@ -148,14 +148,15 @@ impl IdentityUpdateTransitionWasm { pub fn set_public_key_ids_to_add( &mut self, js_add_public_keys: &js_sys::Array, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let add_public_keys: Vec = IdentityPublicKeyInCreationWasm::vec_from_js_value(js_add_public_keys)?; let keys: Vec = add_public_keys.iter().map(|id| id.clone().into()).collect(); - Ok(self.0.set_public_keys_to_add(keys)) + self.0.set_public_keys_to_add(keys); + Ok(()) } #[wasm_bindgen(setter = "publicKeyIdsToDisable")] @@ -174,8 +175,8 @@ impl IdentityUpdateTransitionWasm { } #[wasm_bindgen(js_name = "getSignableBytes")] - pub fn get_signable_bytes(&self) -> Result, JsValue> { - self.0.signable_bytes().with_js_error() + pub fn get_signable_bytes(&self) -> WasmDppResult> { + Ok(self.0.signable_bytes()?) } #[wasm_bindgen(getter = "signaturePublicKeyId")] @@ -194,44 +195,41 @@ impl IdentityUpdateTransitionWasm { } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = + decode(hex.as_str(), Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; IdentityUpdateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + pub fn from_base64(base64: String) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; IdentityUpdateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> Result, JsValue> { - self.0.serialize_to_bytes().with_js_error() + pub fn to_bytes(&self) -> WasmDppResult> { + Ok(self.0.serialize_to_bytes()?) } #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Hex, - )) + pub fn to_hex(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; + Ok(encode(bytes.as_slice(), Hex)) } #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Base64, - )) + pub fn to_base64(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; + Ok(encode(bytes.as_slice(), Base64)) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { - let rs_transition = - IdentityUpdateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + pub fn from_bytes(bytes: Vec) -> WasmDppResult { + let rs_transition = IdentityUpdateTransition::deserialize_from_bytes(bytes.as_slice())?; Ok(IdentityUpdateTransitionWasm(rs_transition)) } @@ -244,12 +242,14 @@ impl IdentityUpdateTransitionWasm { #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( st: &StateTransitionWasm, - ) -> Result { + ) -> WasmDppResult { let rs_st: StateTransition = st.clone().into(); match rs_st { StateTransition::IdentityUpdate(st) => Ok(IdentityUpdateTransitionWasm(st)), - _ => Err(JsValue::from_str(&"Invalid state transition type)")), + _ => Err(WasmDppError::invalid_argument( + "Invalid state transition type", + )), } } } diff --git a/packages/wasm-dpp2/src/lib.rs b/packages/wasm-dpp2/src/lib.rs index c0d9a6e4cb5..ccaea68839c 100644 --- a/packages/wasm-dpp2/src/lib.rs +++ b/packages/wasm-dpp2/src/lib.rs @@ -19,6 +19,7 @@ pub mod data_contract_transitions; pub mod document; pub mod encrypted_note; pub mod enums; +pub mod error; pub mod group_state_transition_info; pub mod identifier; pub mod identity; diff --git a/packages/wasm-dpp2/src/state_transition/mod.rs b/packages/wasm-dpp2/src/state_transition/mod.rs index 35ec05449c5..397ce291225 100644 --- a/packages/wasm-dpp2/src/state_transition/mod.rs +++ b/packages/wasm-dpp2/src/state_transition/mod.rs @@ -1,11 +1,11 @@ use crate::enums::keys::key_type::KeyTypeWasm; use crate::enums::keys::purpose::PurposeWasm; use crate::enums::keys::security_level::SecurityLevelWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::identity_public_key::IdentityPublicKeyWasm; use crate::mock_bls::MockBLS; use crate::private_key::PrivateKeyWasm; -use crate::utils::WithJsError; use dpp::dashcore::secp256k1::hashes::hex::Case::Lower; use dpp::dashcore::secp256k1::hashes::hex::DisplayHex; use dpp::data_contract::serialized_version::DataContractInSerializationFormat; @@ -37,8 +37,8 @@ use dpp::state_transition::{ StateTransition, StateTransitionIdentitySigned, StateTransitionSigningOptions, }; use sha2::{Digest, Sha256}; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[derive(Clone)] #[wasm_bindgen(js_name = "StateTransition")] @@ -73,20 +73,18 @@ impl StateTransitionWasm { &mut self, private_key: &PrivateKeyWasm, public_key: &IdentityPublicKeyWasm, - ) -> Result, JsValue> { - self.0 - .sign( - &public_key.clone().into(), - private_key.to_bytes().as_slice(), - &MockBLS {}, - ) - .with_js_error()?; + ) -> WasmDppResult> { + self.0.sign( + &public_key.clone().into(), + private_key.to_bytes().as_slice(), + &MockBLS {}, + )?; self.0.set_signature(self.0.signature().clone()); self.0 .set_signature_public_key_id(self.0.signature_public_key_id().unwrap()); - self.0.serialize_to_bytes().with_js_error() + Ok(self.0.serialize_to_bytes()?) } #[wasm_bindgen(js_name = "signByPrivateKey")] @@ -95,26 +93,24 @@ impl StateTransitionWasm { private_key: &PrivateKeyWasm, key_id: Option, js_key_type: JsValue, - ) -> Result, JsValue> { - let key_type = match js_key_type.is_undefined() { - true => KeyTypeWasm::ECDSA_SECP256K1, - false => KeyTypeWasm::try_from(js_key_type)?, + ) -> WasmDppResult> { + let key_type = if js_key_type.is_undefined() { + KeyTypeWasm::ECDSA_SECP256K1 + } else { + KeyTypeWasm::try_from(js_key_type)? }; - let _sig = self - .0 - .sign_by_private_key( - &private_key.to_bytes().as_slice(), - KeyType::from(key_type), - &MockBLS {}, - ) - .with_js_error(); - - if key_id.is_some() { - self.0.set_signature_public_key_id(key_id.unwrap()); + self.0.sign_by_private_key( + &private_key.to_bytes().as_slice(), + KeyType::from(key_type), + &MockBLS {}, + )?; + + if let Some(key_id) = key_id { + self.0.set_signature_public_key_id(key_id); } - self.0.serialize_to_bytes().with_js_error() + Ok(self.0.serialize_to_bytes()?) } #[wasm_bindgen(js_name = "verifyPublicKey")] @@ -123,7 +119,7 @@ impl StateTransitionWasm { public_key: &IdentityPublicKeyWasm, js_allow_signing_with_any_security_level: Option, js_allow_signing_with_any_purpose: Option, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let allow_signing_with_any_security_level = js_allow_signing_with_any_security_level.unwrap_or(false); let allow_signing_with_any_purpose = js_allow_signing_with_any_purpose.unwrap_or(false); @@ -136,11 +132,9 @@ impl StateTransitionWasm { allow_signing_with_any_security_level, allow_signing_with_any_purpose, }, - ) - .with_js_error()?; + )?; - st.verify_public_key_is_enabled(&public_key.clone().into()) - .with_js_error()?; + st.verify_public_key_is_enabled(&public_key.clone().into())?; } DataContractUpdate(st) => { st.verify_public_key_level_and_purpose( @@ -149,11 +143,9 @@ impl StateTransitionWasm { allow_signing_with_any_security_level, allow_signing_with_any_purpose, }, - ) - .with_js_error()?; + )?; - st.verify_public_key_is_enabled(&public_key.clone().into()) - .with_js_error()?; + st.verify_public_key_is_enabled(&public_key.clone().into())?; } Batch(st) => { st.verify_public_key_level_and_purpose( @@ -162,11 +154,9 @@ impl StateTransitionWasm { allow_signing_with_any_security_level, allow_signing_with_any_purpose, }, - ) - .with_js_error()?; + )?; - st.verify_public_key_is_enabled(&public_key.clone().into()) - .with_js_error()?; + st.verify_public_key_is_enabled(&public_key.clone().into())?; } IdentityCreditWithdrawal(st) => { st.verify_public_key_level_and_purpose( @@ -175,11 +165,9 @@ impl StateTransitionWasm { allow_signing_with_any_security_level, allow_signing_with_any_purpose, }, - ) - .with_js_error()?; + )?; - st.verify_public_key_is_enabled(&public_key.clone().into()) - .with_js_error()?; + st.verify_public_key_is_enabled(&public_key.clone().into())?; } IdentityUpdate(st) => { st.verify_public_key_level_and_purpose( @@ -188,11 +176,9 @@ impl StateTransitionWasm { allow_signing_with_any_security_level, allow_signing_with_any_purpose, }, - ) - .with_js_error()?; + )?; - st.verify_public_key_is_enabled(&public_key.clone().into()) - .with_js_error()?; + st.verify_public_key_is_enabled(&public_key.clone().into())?; } IdentityCreditTransfer(st) => { st.verify_public_key_level_and_purpose( @@ -201,11 +187,9 @@ impl StateTransitionWasm { allow_signing_with_any_security_level, allow_signing_with_any_purpose, }, - ) - .with_js_error()?; + )?; - st.verify_public_key_is_enabled(&public_key.clone().into()) - .with_js_error()?; + st.verify_public_key_is_enabled(&public_key.clone().into())?; } MasternodeVote(st) => { st.verify_public_key_level_and_purpose( @@ -214,11 +198,9 @@ impl StateTransitionWasm { allow_signing_with_any_security_level, allow_signing_with_any_purpose, }, - ) - .with_js_error()?; + )?; - st.verify_public_key_is_enabled(&public_key.clone().into()) - .with_js_error()?; + st.verify_public_key_is_enabled(&public_key.clone().into())?; } _ => {} } @@ -227,60 +209,61 @@ impl StateTransitionWasm { } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> Result { - let bytes = self.0.serialize_to_bytes().with_js_error()?; + pub fn to_bytes(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; Ok(JsValue::from(bytes.clone())) } #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self) -> Result { - let bytes = self.0.serialize_to_bytes().with_js_error()?; + pub fn to_hex(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; Ok(JsValue::from(encode(bytes.as_slice(), Encoding::Hex))) } #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self) -> Result { - let bytes = self.0.serialize_to_bytes().with_js_error()?; + pub fn to_base64(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; Ok(JsValue::from(encode(bytes.as_slice(), Encoding::Base64))) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { - let st = StateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + pub fn from_bytes(bytes: Vec) -> WasmDppResult { + let st = StateTransition::deserialize_from_bytes(bytes.as_slice())?; Ok(st.into()) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - let bytes = decode(&hex, Encoding::Hex).map_err(JsError::from)?; + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = + decode(&hex, Encoding::Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; - let st = StateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + let st = StateTransition::deserialize_from_bytes(bytes.as_slice())?; Ok(st.into()) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - let bytes = decode(&base64, Encoding::Base64).map_err(JsError::from)?; + pub fn from_base64(base64: String) -> WasmDppResult { + let bytes = decode(&base64, Encoding::Base64) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; - let st = StateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + let st = StateTransition::deserialize_from_bytes(bytes.as_slice())?; Ok(st.into()) } #[wasm_bindgen(js_name = "hash")] - pub fn get_hash(&self, skip_signature: bool) -> Result { + pub fn get_hash(&self, skip_signature: bool) -> WasmDppResult { let payload: Vec; if skip_signature { - payload = self.0.signable_bytes().with_js_error()?; + payload = self.0.signable_bytes()?; } else { - payload = dpp::serialization::PlatformSerializable::serialize_to_bytes(&self.0) - .with_js_error()?; + payload = dpp::serialization::PlatformSerializable::serialize_to_bytes(&self.0)?; } Ok(Sha256::digest(payload).to_hex_string(Lower)) @@ -345,7 +328,7 @@ impl StateTransitionWasm { pub fn get_key_level_requirement( &self, js_purpose: &JsValue, - ) -> Result>, JsValue> { + ) -> WasmDppResult>> { let purpose = PurposeWasm::try_from(js_purpose.clone())?; let requirements = self.0.security_level_requirement(purpose.into()); @@ -417,7 +400,7 @@ impl StateTransitionWasm { } #[wasm_bindgen(js_name = "setOwnerId")] - pub fn set_owner_id(&mut self, js_owner_id: &JsValue) -> Result<(), JsValue> { + pub fn set_owner_id(&mut self, js_owner_id: &JsValue) -> WasmDppResult<()> { let owner_id = IdentifierWasm::try_from(js_owner_id.clone())?; match self.0.clone() { @@ -474,9 +457,9 @@ impl StateTransitionWasm { self.0 = Batch(batch); } StateTransition::IdentityCreate(_) => { - Err(JsValue::from_str( + return Err(WasmDppError::invalid_argument( "Cannot set owner for identity create transition", - ))?; + )); } IdentityTopUp(mut top_up) => { top_up.set_identity_id(owner_id.into()); @@ -509,11 +492,13 @@ impl StateTransitionWasm { } #[wasm_bindgen(js_name = "setIdentityContractNonce")] - pub fn set_identity_contract_nonce(&mut self, nonce: IdentityNonce) -> Result<(), JsValue> { + pub fn set_identity_contract_nonce(&mut self, nonce: IdentityNonce) -> WasmDppResult<()> { self.0 = match self.0.clone() { - DataContractCreate(_) => Err(JsValue::from_str( - "Cannot set identity contract nonce for Data Contract Create", - ))?, + DataContractCreate(_) => { + return Err(WasmDppError::invalid_argument( + "Cannot set identity contract nonce for Data Contract Create", + )); + } DataContractUpdate(contract_update) => match contract_update { DataContractUpdateTransition::V0(mut v0) => { v0.identity_contract_nonce = nonce; @@ -526,31 +511,43 @@ impl StateTransitionWasm { batch.into() } - StateTransition::IdentityCreate(_) => Err(JsValue::from_str( - "Cannot set identity contract nonce for Identity Create", - ))?, - IdentityTopUp(_) => Err(JsValue::from_str( - "Cannot set identity contract nonce for Identity Top Up", - ))?, - IdentityCreditWithdrawal(_) => Err(JsValue::from_str( - "Cannot set identity contract nonce for Identity Credit Withdrawal", - ))?, - IdentityUpdate(_) => Err(JsValue::from_str( - "Cannot set identity contract nonce for Identity Update", - ))?, - IdentityCreditTransfer(_) => Err(JsValue::from_str( - "Cannot set identity contract nonce for Identity Credit Transfer", - ))?, - MasternodeVote(_) => Err(JsValue::from_str( - "Cannot set identity contract nonce for Masternode Vote", - ))?, + StateTransition::IdentityCreate(_) => { + return Err(WasmDppError::invalid_argument( + "Cannot set identity contract nonce for Identity Create", + )); + } + IdentityTopUp(_) => { + return Err(WasmDppError::invalid_argument( + "Cannot set identity contract nonce for Identity Top Up", + )); + } + IdentityCreditWithdrawal(_) => { + return Err(WasmDppError::invalid_argument( + "Cannot set identity contract nonce for Identity Credit Withdrawal", + )); + } + IdentityUpdate(_) => { + return Err(WasmDppError::invalid_argument( + "Cannot set identity contract nonce for Identity Update", + )); + } + IdentityCreditTransfer(_) => { + return Err(WasmDppError::invalid_argument( + "Cannot set identity contract nonce for Identity Credit Transfer", + )); + } + MasternodeVote(_) => { + return Err(WasmDppError::invalid_argument( + "Cannot set identity contract nonce for Masternode Vote", + )); + } }; Ok(()) } #[wasm_bindgen(js_name = "setIdentityNonce")] - pub fn set_identity_nonce(&mut self, nonce: IdentityNonce) -> Result<(), JsValue> { + pub fn set_identity_nonce(&mut self, nonce: IdentityNonce) -> WasmDppResult<()> { self.0 = match self.0.clone() { DataContractCreate(mut contract_create) => { contract_create = match contract_create { @@ -562,16 +559,26 @@ impl StateTransitionWasm { contract_create.into() } - DataContractUpdate(_) => Err(JsValue::from_str( - "Cannot set identity nonce for Data Contract Update", - ))?, - Batch(_) => Err(JsValue::from_str("Cannot set identity nonce for Batch"))?, - StateTransition::IdentityCreate(_) => Err(JsValue::from_str( - "Cannot set identity nonce for Identity Create", - ))?, - IdentityTopUp(_) => Err(JsValue::from_str( - "Cannot set identity nonce for Identity Top Up", - ))?, + DataContractUpdate(_) => { + return Err(WasmDppError::invalid_argument( + "Cannot set identity nonce for Data Contract Update", + )); + } + Batch(_) => { + return Err(WasmDppError::invalid_argument( + "Cannot set identity nonce for Batch", + )); + } + StateTransition::IdentityCreate(_) => { + return Err(WasmDppError::invalid_argument( + "Cannot set identity nonce for Identity Create", + )); + } + IdentityTopUp(_) => { + return Err(WasmDppError::invalid_argument( + "Cannot set identity nonce for Identity Top Up", + )); + } IdentityCreditWithdrawal(mut withdrawal) => { withdrawal.set_nonce(nonce); diff --git a/packages/wasm-dpp2/src/utils/mod.rs b/packages/wasm-dpp2/src/utils/mod.rs index ccf5cd2a8cf..23100fb7a74 100644 --- a/packages/wasm-dpp2/src/utils/mod.rs +++ b/packages/wasm-dpp2/src/utils/mod.rs @@ -1,3 +1,4 @@ +use crate::error::{WasmDppError, WasmDppResult}; use anyhow::{Context, anyhow, bail}; use dpp::ProtocolError; use dpp::identifier::Identifier; @@ -11,6 +12,31 @@ use std::convert::TryInto; use wasm_bindgen::JsValue; use wasm_bindgen::{convert::RefFromWasmAbi, prelude::*}; +pub fn stringify_wasm(data: &JsValue) -> WasmDppResult { + let replacer_func = Function::new_with_args( + "key, value", + "return (value != undefined && value.type=='Buffer') ? value.data : value ", + ); + + let data_string = js_sys::JSON::stringify_with_replacer(data, &JsValue::from(replacer_func)) + .map_err(|_| WasmDppError::serialization("Failed to stringify value"))?; + + Ok(data_string.into()) +} + +pub fn with_serde_to_json_value_wasm(data: JsValue) -> WasmDppResult { + let data = stringify_wasm(&data)?; + serde_json::from_str(&data).map_err(|e| { + WasmDppError::serialization(format!( + "unable to convert value to serde_json::Value: {e:#}" + )) + }) +} + +pub fn with_serde_to_platform_value_wasm(data: &JsValue) -> WasmDppResult { + Ok(with_serde_to_json_value_wasm(data.clone())?.into()) +} + pub trait ToSerdeJSONExt { fn with_serde_to_json_value(&self) -> Result; fn with_serde_to_platform_value(&self) -> Result; From 9d4796b7dcf1f1c8968ed5aff43cfecc6590e0a4 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 7 Oct 2025 14:10:13 +0700 Subject: [PATCH 11/44] refactor: replace jsvalue to error --- .../src/asset_lock_proof/chain/mod.rs | 13 +- .../src/asset_lock_proof/outpoint/mod.rs | 5 +- .../src/asset_lock_proof/tx_out/mod.rs | 29 +-- .../src/batch/batched_transition/mod.rs | 44 ++--- .../src/batch/document_base_transition/mod.rs | 7 +- .../src/batch/document_transition/mod.rs | 57 +++--- .../batch/document_transitions/create/mod.rs | 32 ++-- .../batch/document_transitions/delete/mod.rs | 13 +- .../document_transitions/purchase/mod.rs | 19 +- .../batch/document_transitions/replace/mod.rs | 31 ++-- .../document_transitions/transfer/mod.rs | 26 ++- .../document_transitions/update_price/mod.rs | 19 +- packages/wasm-dpp2/src/batch/mod.rs | 120 ++++++------- .../src/batch/token_base_transition/mod.rs | 9 +- .../src/batch/token_payment_info/mod.rs | 7 +- .../src/batch/token_pricing_schedule/mod.rs | 34 +++- .../src/batch/token_transition/mod.rs | 165 +++++++++--------- .../batch/token_transitions/config_update.rs | 12 +- .../set_price_for_direct_purchase.rs | 16 +- .../src/batch/token_transitions/token_burn.rs | 8 +- .../batch/token_transitions/token_claim.rs | 18 +- .../token_destroy_frozen_funds.rs | 18 +- .../batch/token_transitions/token_freeze.rs | 16 +- .../src/batch/token_transitions/token_mint.rs | 24 ++- .../batch/token_transitions/token_transfer.rs | 29 +-- .../batch/token_transitions/token_unfreeze.rs | 16 +- packages/wasm-dpp2/src/contract_bounds/mod.rs | 9 +- packages/wasm-dpp2/src/core_script/mod.rs | 7 +- packages/wasm-dpp2/src/data_contract/mod.rs | 3 +- .../data_contract_transitions/create/mod.rs | 66 +++---- .../data_contract_transitions/update/mod.rs | 60 +++---- .../wasm-dpp2/src/document/methods/mod.rs | 101 +++++------ .../wasm-dpp2/src/enums/batch/batch_enum.rs | 15 +- .../src/enums/batch/gas_fees_paid_by.rs | 54 +++--- .../enums/contested/vote_state_result_type.rs | 15 +- packages/wasm-dpp2/src/enums/keys/key_type.rs | 18 +- packages/wasm-dpp2/src/enums/keys/purpose.rs | 70 ++++---- .../src/enums/keys/security_level.rs | 58 +++--- .../wasm-dpp2/src/enums/lock_types/mod.rs | 21 ++- packages/wasm-dpp2/src/enums/network/mod.rs | 58 +++--- packages/wasm-dpp2/src/enums/platform/mod.rs | 15 +- .../wasm-dpp2/src/enums/token/action_goal.rs | 38 ++-- .../src/enums/token/distribution_type.rs | 38 ++-- .../src/enums/token/emergency_action.rs | 42 +++-- .../wasm-dpp2/src/enums/withdrawal/mod.rs | 15 +- packages/wasm-dpp2/src/error.rs | 28 ++- .../src/group_state_transition_info/mod.rs | 5 +- packages/wasm-dpp2/src/identifier/mod.rs | 37 ++-- .../public_key_in_creation/mod.rs | 6 +- packages/wasm-dpp2/src/masternode_vote/mod.rs | 39 +++-- .../resource_vote_choice/mod.rs | 3 +- .../src/masternode_vote/vote_poll/mod.rs | 27 ++- .../wasm-dpp2/src/partial_identity/mod.rs | 56 +++--- packages/wasm-dpp2/src/private_key/mod.rs | 22 +-- packages/wasm-dpp2/src/public_key/mod.rs | 79 +++++---- .../src/token_configuration/action_taker.rs | 58 +++--- .../authorized_action_takers.rs | 3 +- .../change_control_rules.rs | 26 +-- .../configuration_convention.rs | 60 +++---- .../distribution_function.rs | 30 ++-- .../distribution_recipient.rs | 3 +- .../token_configuration/distribution_rules.rs | 19 +- .../src/token_configuration/group.rs | 29 +-- .../src/token_configuration/localization.rs | 76 +++++++- .../wasm-dpp2/src/token_configuration/mod.rs | 3 +- .../pre_programmed_distribution.rs | 52 +++--- .../items/new_tokens_destination_identity.rs | 3 +- packages/wasm-dpp2/src/utils/mod.rs | 111 +++++------- 68 files changed, 1232 insertions(+), 1033 deletions(-) diff --git a/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs index 6ab26da1102..e46389aaf17 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs @@ -1,9 +1,10 @@ use crate::asset_lock_proof::outpoint::OutPointWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use dpp::identity::state_transition::asset_lock_proof::chain::ChainAssetLockProof; use serde::Deserialize; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[derive(Deserialize)] #[serde(rename_all = "camelCase")] @@ -44,7 +45,7 @@ impl ChainAssetLockProofWasm { pub fn new( core_chain_locked_height: u32, out_point: &OutPointWasm, - ) -> Result { + ) -> WasmDppResult { Ok(ChainAssetLockProofWasm(ChainAssetLockProof { core_chain_locked_height, out_point: out_point.clone().into(), @@ -52,17 +53,15 @@ impl ChainAssetLockProofWasm { } #[wasm_bindgen(js_name = "fromRawObject")] - pub fn from_raw_value( - raw_asset_lock_proof: JsValue, - ) -> Result { + pub fn from_raw_value(raw_asset_lock_proof: JsValue) -> WasmDppResult { let parameters: ChainAssetLockProofParams = serde_wasm_bindgen::from_value(raw_asset_lock_proof) - .map_err(|err| JsError::from(err))?; + .map_err(|err| WasmDppError::serialization(err.to_string()))?; let out_point: [u8; 36] = parameters .out_point .try_into() - .map_err(|_| JsError::new("outPoint must be a 36 byte array"))?; + .map_err(|_| WasmDppError::invalid_argument("outPoint must be a 36 byte array"))?; let rs_proof = ChainAssetLockProof::new(parameters.core_chain_locked_height, out_point); diff --git a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs index 5c8c382f002..77f3621d6f5 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs @@ -23,7 +23,7 @@ impl From for OutPoint { } impl TryFrom for OutPointWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { let value = value.to_wasm::("OutPoint")?; @@ -114,8 +114,7 @@ impl OutPointWasm { let outpoints: Vec = js_outpoints .iter() .map(OutPointWasm::try_from) - .collect::, JsValue>>() - .map_err(|e| WasmDppError::invalid_argument(e.as_string().unwrap_or_default()))?; + .collect::, WasmDppError>>()?; Ok(outpoints) } diff --git a/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs index 343a5270a19..51df4ca0ae2 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs @@ -1,3 +1,4 @@ +use crate::error::{WasmDppError, WasmDppResult}; use dpp::dashcore::{ScriptBuf, TxOut}; use js_sys::Uint8Array; use wasm_bindgen::JsValue; @@ -32,19 +33,27 @@ impl TxOutWasm { } #[wasm_bindgen(constructor)] - pub fn new(value: u64, script_pubkey: JsValue) -> Result { - let tx_out: Result = match script_pubkey.is_array() { + pub fn new(value: u64, script_pubkey: JsValue) -> WasmDppResult { + let tx_out: WasmDppResult = match script_pubkey.is_array() { true => Ok(TxOut { value, script_pubkey: ScriptBuf::from_bytes(Uint8Array::from(script_pubkey).to_vec()), }), false => match script_pubkey.is_string() { - true => Ok(TxOut { - value, - script_pubkey: ScriptBuf::from_hex(&script_pubkey.as_string().unwrap()) - .map_err(|err| JsValue::from(err.to_string()))?, - }), - false => Err(JsValue::from("Invalid script pubkey")), + true => { + let hex = script_pubkey.as_string().ok_or_else(|| { + WasmDppError::invalid_argument("Script pubkey must be string") + })?; + + let script = ScriptBuf::from_hex(&hex) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + Ok(TxOut { + value, + script_pubkey: script, + }) + } + false => Err(WasmDppError::invalid_argument("Invalid script pubkey")), }, }; @@ -72,9 +81,9 @@ impl TxOutWasm { } #[wasm_bindgen(setter = "scriptPubKeyHex")] - pub fn set_script_pubkey_hex(&mut self, script_pubkey_hex: String) -> Result<(), JsValue> { + pub fn set_script_pubkey_hex(&mut self, script_pubkey_hex: String) -> WasmDppResult<()> { self.0.script_pubkey = ScriptBuf::from_hex(&script_pubkey_hex) - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::serialization(err.to_string()))?; Ok(()) } diff --git a/packages/wasm-dpp2/src/batch/batched_transition/mod.rs b/packages/wasm-dpp2/src/batch/batched_transition/mod.rs index 4af0bfadf8a..fb31e87fcc5 100644 --- a/packages/wasm-dpp2/src/batch/batched_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/batched_transition/mod.rs @@ -1,5 +1,6 @@ use crate::batch::document_transition::DocumentTransitionWasm; use crate::batch::token_transition::TokenTransitionWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::utils::{IntoWasm, get_class_type}; use dpp::state_transition::batch_transition::batched_transition::BatchedTransition; @@ -41,26 +42,27 @@ impl BatchedTransitionWasm { } #[wasm_bindgen(constructor)] - pub fn new(js_transition: &JsValue) -> Result { - match js_transition.is_undefined() && js_transition.is_object() { - true => Err(JsValue::from_str("transition is undefined")), - false => match get_class_type(js_transition)?.as_str() { - "TokenTransition" => Ok(BatchedTransitionWasm::from(BatchedTransition::from( - TokenTransition::from( - js_transition - .to_wasm::("TokenTransition")? - .clone(), - ), - ))), - "DocumentTransition" => Ok(BatchedTransitionWasm(BatchedTransition::Document( - DocumentTransition::from( - js_transition - .to_wasm::("DocumentTransition")? - .clone(), - ), - ))), - _ => Err(JsValue::from_str("Invalid transition type")), - }, + pub fn new(js_transition: &JsValue) -> WasmDppResult { + if js_transition.is_undefined() || !js_transition.is_object() { + return Err(WasmDppError::invalid_argument("transition is undefined")); + } + + match get_class_type(js_transition)?.as_str() { + "TokenTransition" => Ok(BatchedTransitionWasm::from(BatchedTransition::from( + TokenTransition::from( + js_transition + .to_wasm::("TokenTransition")? + .clone(), + ), + ))), + "DocumentTransition" => Ok(BatchedTransitionWasm(BatchedTransition::Document( + DocumentTransition::from( + js_transition + .to_wasm::("DocumentTransition")? + .clone(), + ), + ))), + _ => Err(WasmDppError::invalid_argument("Invalid transition type")), } } @@ -89,7 +91,7 @@ impl BatchedTransitionWasm { } #[wasm_bindgen(setter = "dataContractId")] - pub fn set_data_contract_id(&mut self, js_contract_id: &JsValue) -> Result<(), JsValue> { + pub fn set_data_contract_id(&mut self, js_contract_id: &JsValue) -> WasmDppResult<()> { let contract_id = IdentifierWasm::try_from(js_contract_id)?; self.0 = match self.0.clone() { diff --git a/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs b/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs index 8d6ebc7505f..44b6c14b830 100644 --- a/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs @@ -1,4 +1,5 @@ use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use crate::utils::IntoWasm; use dpp::prelude::IdentityNonce; @@ -45,7 +46,7 @@ impl DocumentBaseTransitionWasm { document_type_name: String, js_data_contract_id: &JsValue, js_token_payment_info: &JsValue, - ) -> Result { + ) -> WasmDppResult { let token_payment_info: Option = match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { true => None, @@ -99,7 +100,7 @@ impl DocumentBaseTransitionWasm { } #[wasm_bindgen(setter = "id")] - pub fn set_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { + pub fn set_id(&mut self, js_id: &JsValue) -> WasmDppResult<()> { self.0.set_id(IdentifierWasm::try_from(js_id)?.into()); Ok(()) } @@ -110,7 +111,7 @@ impl DocumentBaseTransitionWasm { } #[wasm_bindgen(setter = "dataContractId")] - pub fn set_data_contract_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> { + pub fn set_data_contract_id(&mut self, js_data_contract_id: &JsValue) -> WasmDppResult<()> { self.0 .set_data_contract_id(IdentifierWasm::try_from(js_data_contract_id)?.into()); Ok(()) diff --git a/packages/wasm-dpp2/src/batch/document_transition/mod.rs b/packages/wasm-dpp2/src/batch/document_transition/mod.rs index c51c59eae68..4f8535aef59 100644 --- a/packages/wasm-dpp2/src/batch/document_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transition/mod.rs @@ -4,15 +4,18 @@ use crate::batch::document_transitions::purchase::DocumentPurchaseTransitionWasm use crate::batch::document_transitions::replace::DocumentReplaceTransitionWasm; use crate::batch::document_transitions::transfer::DocumentTransferTransitionWasm; use crate::batch::document_transitions::update_price::DocumentUpdatePriceTransitionWasm; +use crate::enums::batch::batch_enum::BatchTypeWasm; +use crate::error::{WasmDppError, WasmDppResult}; +use crate::identifier::IdentifierWasm; use dpp::prelude::{Identifier, IdentityNonce, Revision}; use dpp::state_transition::batch_transition::batched_transition::document_transition::{ DocumentTransition, DocumentTransitionV0Methods, }; -use dpp::state_transition::batch_transition::batched_transition::document_transition_action_type::{DocumentTransitionActionType, DocumentTransitionActionTypeGetter}; -use crate::enums::batch::batch_enum::BatchTypeWasm; -use crate::identifier::IdentifierWasm; -use wasm_bindgen::JsValue; +use dpp::state_transition::batch_transition::batched_transition::document_transition_action_type::{ + DocumentTransitionActionType, DocumentTransitionActionTypeGetter, +}; use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::JsValue; #[derive(Clone)] #[wasm_bindgen(js_name = "DocumentTransition")] @@ -91,68 +94,78 @@ impl DocumentTransitionWasm { } #[wasm_bindgen(getter = "createTransition")] - pub fn get_create_transition(&self) -> Result { + pub fn get_create_transition(&self) -> WasmDppResult { match self.0.clone() { DocumentTransition::Create(create) => Ok(DocumentCreateTransitionWasm::from(create)), - _ => Err(JsValue::undefined()), + _ => Err(WasmDppError::invalid_argument( + "Document transition is not a create transition", + )), } } #[wasm_bindgen(getter = "replaceTransition")] - pub fn get_replace_transition(&self) -> Result { + pub fn get_replace_transition(&self) -> WasmDppResult { match self.0.clone() { DocumentTransition::Replace(replace) => { Ok(DocumentReplaceTransitionWasm::from(replace)) } - _ => Err(JsValue::undefined()), + _ => Err(WasmDppError::invalid_argument( + "Document transition is not a replace transition", + )), } } #[wasm_bindgen(getter = "deleteTransition")] - pub fn get_delete_transition(&self) -> Result { + pub fn get_delete_transition(&self) -> WasmDppResult { match self.0.clone() { DocumentTransition::Delete(delete) => Ok(DocumentDeleteTransitionWasm::from(delete)), - _ => Err(JsValue::undefined()), + _ => Err(WasmDppError::invalid_argument( + "Document transition is not a delete transition", + )), } } #[wasm_bindgen(getter = "purchaseTransition")] - pub fn get_purchase_transition(&self) -> Result { + pub fn get_purchase_transition(&self) -> WasmDppResult { match self.0.clone() { DocumentTransition::Purchase(purchase) => { Ok(DocumentPurchaseTransitionWasm::from(purchase)) } - _ => Err(JsValue::undefined()), + _ => Err(WasmDppError::invalid_argument( + "Document transition is not a purchase transition", + )), } } #[wasm_bindgen(getter = "transferTransition")] - pub fn get_transfer_transition(&self) -> Result { + pub fn get_transfer_transition(&self) -> WasmDppResult { match self.0.clone() { DocumentTransition::Transfer(transfer) => { Ok(DocumentTransferTransitionWasm::from(transfer)) } - _ => Err(JsValue::undefined()), + _ => Err(WasmDppError::invalid_argument( + "Document transition is not a transfer transition", + )), } } #[wasm_bindgen(getter = "updatePriceTransition")] - pub fn get_update_price_transition( - &self, - ) -> Result { + pub fn get_update_price_transition(&self) -> WasmDppResult { match self.0.clone() { DocumentTransition::UpdatePrice(update_price) => { Ok(DocumentUpdatePriceTransitionWasm::from(update_price)) } - _ => Err(JsValue::undefined()), + _ => Err(WasmDppError::invalid_argument( + "Document transition is not an update price transition", + )), } } #[wasm_bindgen(setter = "dataContractId")] - pub fn set_data_contract_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> { - Ok(self - .0 - .set_data_contract_id(IdentifierWasm::try_from(js_data_contract_id)?.into())) + pub fn set_data_contract_id(&mut self, js_data_contract_id: &JsValue) -> WasmDppResult<()> { + self.0 + .set_data_contract_id(IdentifierWasm::try_from(js_data_contract_id)?.into()); + Ok(()) } #[wasm_bindgen(setter = "revision")] diff --git a/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs index bbe8a7f41e2..8f918a259f0 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs @@ -1,18 +1,19 @@ use crate::batch::document_base_transition::DocumentBaseTransitionWasm; use crate::batch::document_transition::DocumentTransitionWasm; use crate::batch::generators::generate_create_transition; +use crate::batch::prefunded_voting_balance::PrefundedVotingBalanceWasm; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::document::DocumentWasm; +use crate::error::{WasmDppError, WasmDppResult}; +use crate::utils::{IntoWasm, ToSerdeJSONExt}; use dpp::dashcore::hashes::serde::Serialize; use dpp::prelude::IdentityNonce; use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; use dpp::state_transition::batch_transition::document_create_transition::v0::v0_methods::DocumentCreateTransitionV0Methods; use dpp::state_transition::batch_transition::DocumentCreateTransition; -use crate::document::DocumentWasm; -use crate::utils::{IntoWasm, ToSerdeJSONExt}; -use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::batch::prefunded_voting_balance::PrefundedVotingBalanceWasm; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use wasm_bindgen::JsValue; #[wasm_bindgen(js_name = "DocumentCreateTransition")] #[derive(Clone)] @@ -48,7 +49,7 @@ impl DocumentCreateTransitionWasm { identity_contract_nonce: IdentityNonce, js_prefunded_voting_balance: &JsValue, js_token_payment_info: &JsValue, - ) -> Result { + ) -> WasmDppResult { let prefunded_voting_balance = match js_prefunded_voting_balance.is_undefined() | js_prefunded_voting_balance.is_null() { @@ -82,10 +83,13 @@ impl DocumentCreateTransitionWasm { } #[wasm_bindgen(getter = "data")] - pub fn get_data(&self) -> Result { + pub fn get_data(&self) -> WasmDppResult { let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - self.0.data().serialize(&serializer).map_err(JsValue::from) + self.0 + .data() + .serialize(&serializer) + .map_err(|err| WasmDppError::serialization(err.to_string())) } #[wasm_bindgen(getter = "base")] @@ -99,10 +103,11 @@ impl DocumentCreateTransitionWasm { } #[wasm_bindgen(setter = "data")] - pub fn set_data(&mut self, js_data: JsValue) -> Result<(), JsValue> { + pub fn set_data(&mut self, js_data: JsValue) -> WasmDppResult<()> { let data = js_data.with_serde_to_platform_value_map()?; - Ok(self.0.set_data(data)) + self.0.set_data(data); + Ok(()) } #[wasm_bindgen(setter = "base")] @@ -111,13 +116,14 @@ impl DocumentCreateTransitionWasm { } #[wasm_bindgen(setter = "entropy")] - pub fn set_entropy(&mut self, js_entropy: Vec) -> Result<(), JsValue> { + pub fn set_entropy(&mut self, js_entropy: Vec) -> WasmDppResult<()> { let mut entropy = [0u8; 32]; let bytes = js_entropy.as_slice(); let len = bytes.len().min(32); entropy[..len].copy_from_slice(&bytes[..len]); - Ok(self.0.set_entropy(entropy)) + self.0.set_entropy(entropy); + Ok(()) } #[wasm_bindgen(getter = "prefundedVotingBalance")] @@ -156,7 +162,7 @@ impl DocumentCreateTransitionWasm { #[wasm_bindgen(js_name = "fromDocumentTransition")] pub fn from_document_transition( js_transition: DocumentTransitionWasm, - ) -> Result { + ) -> WasmDppResult { js_transition.get_create_transition() } } diff --git a/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs index 1e369af7045..7c1dce4206c 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs @@ -1,15 +1,16 @@ use crate::batch::document_base_transition::DocumentBaseTransitionWasm; use crate::batch::document_transition::DocumentTransitionWasm; use crate::batch::generators::generate_delete_transition; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::document::DocumentWasm; +use crate::error::WasmDppResult; +use crate::utils::IntoWasm; use dpp::prelude::IdentityNonce; use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; use dpp::state_transition::batch_transition::DocumentDeleteTransition; -use crate::document::DocumentWasm; -use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::utils::IntoWasm; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use wasm_bindgen::JsValue; #[wasm_bindgen(js_name = "DocumentDeleteTransition")] pub struct DocumentDeleteTransitionWasm(DocumentDeleteTransition); @@ -37,7 +38,7 @@ impl DocumentDeleteTransitionWasm { document: &DocumentWasm, identity_contract_nonce: IdentityNonce, js_token_payment_info: &JsValue, - ) -> Result { + ) -> WasmDppResult { let token_payment_info = match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { true => None, @@ -78,7 +79,7 @@ impl DocumentDeleteTransitionWasm { #[wasm_bindgen(js_name = "fromDocumentTransition")] pub fn from_document_transition( js_transition: DocumentTransitionWasm, - ) -> Result { + ) -> WasmDppResult { js_transition.get_delete_transition() } } diff --git a/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs index 4379b817e1e..91c5a9810a7 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs @@ -1,17 +1,18 @@ +use crate::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::batch::document_transition::DocumentTransitionWasm; +use crate::batch::generators::generate_purchase_transition; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::document::DocumentWasm; +use crate::error::WasmDppResult; +use crate::utils::IntoWasm; use dpp::fee::Credits; use dpp::prelude::{IdentityNonce, Revision}; use dpp::state_transition::batch_transition::batched_transition::document_purchase_transition::v0::v0_methods::DocumentPurchaseTransitionV0Methods; use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; use dpp::state_transition::batch_transition::batched_transition::DocumentPurchaseTransition; use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; -use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::document::DocumentWasm; -use crate::utils::IntoWasm; -use crate::batch::document_base_transition::DocumentBaseTransitionWasm; -use crate::batch::document_transition::DocumentTransitionWasm; -use crate::batch::generators::generate_purchase_transition; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use wasm_bindgen::JsValue; #[wasm_bindgen(js_name = "DocumentPurchaseTransition")] pub struct DocumentPurchaseTransitionWasm(DocumentPurchaseTransition); @@ -46,7 +47,7 @@ impl DocumentPurchaseTransitionWasm { identity_contract_nonce: IdentityNonce, amount: Credits, js_token_payment_info: &JsValue, - ) -> Result { + ) -> WasmDppResult { let token_payment_info = match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { true => None, @@ -110,7 +111,7 @@ impl DocumentPurchaseTransitionWasm { #[wasm_bindgen(js_name = "fromDocumentTransition")] pub fn from_document_transition( js_transition: DocumentTransitionWasm, - ) -> Result { + ) -> WasmDppResult { js_transition.get_purchase_transition() } } diff --git a/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs index f097282ee01..b9921186c4c 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs @@ -1,17 +1,18 @@ +use crate::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::batch::document_transition::DocumentTransitionWasm; +use crate::batch::generators::generate_replace_transition; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::document::DocumentWasm; +use crate::error::{WasmDppError, WasmDppResult}; +use crate::utils::{IntoWasm, ToSerdeJSONExt}; use dpp::dashcore::hashes::serde::Serialize; use dpp::prelude::{IdentityNonce, Revision}; use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; use dpp::state_transition::batch_transition::document_replace_transition::v0::v0_methods::DocumentReplaceTransitionV0Methods; use dpp::state_transition::batch_transition::DocumentReplaceTransition; -use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::document::DocumentWasm; -use crate::utils::{IntoWasm, ToSerdeJSONExt}; -use crate::batch::document_base_transition::DocumentBaseTransitionWasm; -use crate::batch::generators::generate_replace_transition; -use crate::batch::document_transition::DocumentTransitionWasm; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use wasm_bindgen::JsValue; #[wasm_bindgen(js_name = "DocumentReplaceTransition")] pub struct DocumentReplaceTransitionWasm(DocumentReplaceTransition); @@ -45,7 +46,7 @@ impl DocumentReplaceTransitionWasm { document: &DocumentWasm, identity_contract_nonce: IdentityNonce, js_token_payment_info: &JsValue, - ) -> Result { + ) -> WasmDppResult { let token_payment_info = match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { true => None, @@ -67,10 +68,13 @@ impl DocumentReplaceTransitionWasm { } #[wasm_bindgen(getter = "data")] - pub fn get_data(&self) -> Result { + pub fn get_data(&self) -> WasmDppResult { let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - self.0.data().serialize(&serializer).map_err(JsValue::from) + self.0 + .data() + .serialize(&serializer) + .map_err(|err| WasmDppError::serialization(err.to_string())) } #[wasm_bindgen(getter = "base")] @@ -84,10 +88,11 @@ impl DocumentReplaceTransitionWasm { } #[wasm_bindgen(setter = "data")] - pub fn set_data(&mut self, js_data: JsValue) -> Result<(), JsValue> { + pub fn set_data(&mut self, js_data: JsValue) -> WasmDppResult<()> { let data = js_data.with_serde_to_platform_value_map()?; - Ok(self.0.set_data(data)) + self.0.set_data(data); + Ok(()) } #[wasm_bindgen(setter = "base")] @@ -110,7 +115,7 @@ impl DocumentReplaceTransitionWasm { #[wasm_bindgen(js_name = "fromDocumentTransition")] pub fn from_document_transition( js_transition: DocumentTransitionWasm, - ) -> Result { + ) -> WasmDppResult { js_transition.get_replace_transition() } } diff --git a/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs index a8a9c98c1fc..165813dddc8 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs @@ -1,17 +1,18 @@ +use crate::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::batch::document_transition::DocumentTransitionWasm; +use crate::batch::generators::generate_transfer_transition; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::document::DocumentWasm; +use crate::error::WasmDppResult; +use crate::identifier::IdentifierWasm; +use crate::utils::IntoWasm; use dpp::prelude::IdentityNonce; use dpp::state_transition::batch_transition::batched_transition::document_transfer_transition::v0::v0_methods::DocumentTransferTransitionV0Methods; use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; use dpp::state_transition::batch_transition::batched_transition::DocumentTransferTransition; use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; -use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::document::DocumentWasm; -use crate::identifier::IdentifierWasm; -use crate::utils::IntoWasm; -use crate::batch::document_base_transition::DocumentBaseTransitionWasm; -use crate::batch::document_transition::DocumentTransitionWasm; -use crate::batch::generators::generate_transfer_transition; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use wasm_bindgen::JsValue; #[wasm_bindgen(js_name = "DocumentTransferTransition")] pub struct DocumentTransferTransitionWasm(DocumentTransferTransition); @@ -46,7 +47,7 @@ impl DocumentTransferTransitionWasm { identity_contract_nonce: IdentityNonce, js_recipient_owner_id: &JsValue, js_token_payment_info: &JsValue, - ) -> Result { + ) -> WasmDppResult { let token_payment_info = match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { true => None, @@ -84,10 +85,7 @@ impl DocumentTransferTransitionWasm { } #[wasm_bindgen(setter = "recipientId")] - pub fn set_recipient_owner_id( - &mut self, - js_recipient_owner_id: &JsValue, - ) -> Result<(), JsValue> { + pub fn set_recipient_owner_id(&mut self, js_recipient_owner_id: &JsValue) -> WasmDppResult<()> { self.0 .set_recipient_owner_id(IdentifierWasm::try_from(js_recipient_owner_id)?.into()); Ok(()) @@ -103,7 +101,7 @@ impl DocumentTransferTransitionWasm { #[wasm_bindgen(js_name = "fromDocumentTransition")] pub fn from_document_transition( js_transition: DocumentTransitionWasm, - ) -> Result { + ) -> WasmDppResult { js_transition.get_transfer_transition() } } diff --git a/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs b/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs index c15cc85138e..04c0dd851ec 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs +++ b/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs @@ -1,17 +1,18 @@ +use crate::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::batch::document_transition::DocumentTransitionWasm; +use crate::batch::generators::generate_update_price_transition; +use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::document::DocumentWasm; +use crate::error::WasmDppResult; +use crate::utils::IntoWasm; use dpp::fee::Credits; use dpp::prelude::IdentityNonce; use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; use dpp::state_transition::batch_transition::batched_transition::document_update_price_transition::v0::v0_methods::DocumentUpdatePriceTransitionV0Methods; use dpp::state_transition::batch_transition::batched_transition::DocumentUpdatePriceTransition; use dpp::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; -use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::document::DocumentWasm; -use crate::utils::IntoWasm; -use crate::batch::document_base_transition::DocumentBaseTransitionWasm; -use crate::batch::document_transition::DocumentTransitionWasm; -use crate::batch::generators::generate_update_price_transition; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; +use wasm_bindgen::JsValue; #[wasm_bindgen(js_name = "DocumentUpdatePriceTransition")] pub struct DocumentUpdatePriceTransitionWasm(DocumentUpdatePriceTransition); @@ -40,7 +41,7 @@ impl DocumentUpdatePriceTransitionWasm { identity_contract_nonce: IdentityNonce, price: Credits, js_token_payment_info: &JsValue, - ) -> Result { + ) -> WasmDppResult { let token_payment_info = match js_token_payment_info.is_null() | js_token_payment_info.is_undefined() { true => None, @@ -94,7 +95,7 @@ impl DocumentUpdatePriceTransitionWasm { #[wasm_bindgen(js_name = "fromDocumentTransition")] pub fn from_document_transition( js_transition: DocumentTransitionWasm, - ) -> Result { + ) -> WasmDppResult { js_transition.get_update_price_transition() } } diff --git a/packages/wasm-dpp2/src/batch/mod.rs b/packages/wasm-dpp2/src/batch/mod.rs index a5150760693..a373e33c7fd 100644 --- a/packages/wasm-dpp2/src/batch/mod.rs +++ b/packages/wasm-dpp2/src/batch/mod.rs @@ -1,8 +1,9 @@ use crate::batch::batched_transition::BatchedTransitionWasm; use crate::batch::document_transition::DocumentTransitionWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::state_transition::StateTransitionWasm; -use crate::utils::{IntoWasm, WithJsError}; +use crate::utils::IntoWasm; use dpp::fee::Credits; use dpp::identity::KeyID; use dpp::platform_value::BinaryData; @@ -18,8 +19,8 @@ use dpp::state_transition::batch_transition::{ BatchTransition, BatchTransitionV0, BatchTransitionV1, }; use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; pub mod batched_transition; pub mod document_base_transition; @@ -49,18 +50,20 @@ impl From for BatchTransition { } } -fn convert_array_to_vec_batched(js_batched_transitions: &js_sys::Array) -> Vec { - js_batched_transitions - .clone() - .iter() - .map(|js_batched_transition| { - let batched_transition: BatchedTransitionWasm = js_batched_transition - .to_wasm::("BatchedTransition") - .unwrap() - .clone(); - BatchedTransition::from(batched_transition) - }) - .collect() +fn convert_array_to_vec_batched( + js_batched_transitions: &js_sys::Array, +) -> WasmDppResult> { + let mut transitions = Vec::with_capacity(js_batched_transitions.length() as usize); + + for js_batched_transition in js_batched_transitions.iter() { + let batched_transition: BatchedTransitionWasm = js_batched_transition + .to_wasm::("BatchedTransition")? + .clone(); + + transitions.push(BatchedTransition::from(batched_transition)); + } + + Ok(transitions) } #[wasm_bindgen(js_class = BatchTransition)] @@ -82,8 +85,8 @@ impl BatchTransitionWasm { user_fee_increase: UserFeeIncrease, signature_public_key_id: Option, signature: Option>, - ) -> Result { - let transitions = convert_array_to_vec_batched(&js_batched_transitions); + ) -> WasmDppResult { + let transitions = convert_array_to_vec_batched(js_batched_transitions)?; Ok(BatchTransitionWasm(BatchTransition::V1( BatchTransitionV1 { @@ -91,7 +94,7 @@ impl BatchTransitionWasm { transitions, user_fee_increase, signature_public_key_id: signature_public_key_id.unwrap_or(0u32), - signature: BinaryData::from(signature.unwrap_or(Vec::new())), + signature: BinaryData::from(signature.unwrap_or_default()), }, ))) } @@ -103,21 +106,19 @@ impl BatchTransitionWasm { user_fee_increase: Option, signature_public_key_id: Option, signature: Option>, - ) -> Result { + ) -> WasmDppResult { let owner_id = IdentifierWasm::try_from(js_owner_id)?; - let transitions: Vec = document_transitions - .clone() - .iter() - .map(|js_document_transition| { - let document_transition: DocumentTransitionWasm = js_document_transition - .to_wasm::("DocumentTransition") - .unwrap() - .clone(); + let mut transitions: Vec = + Vec::with_capacity(document_transitions.length() as usize); - DocumentTransition::from(document_transition.clone().clone()) - }) - .collect(); + for js_document_transition in document_transitions.iter() { + let document_transition: DocumentTransitionWasm = js_document_transition + .to_wasm::("DocumentTransition")? + .clone(); + + transitions.push(DocumentTransition::from(document_transition)); + } Ok(BatchTransitionWasm(BatchTransition::V0( BatchTransitionV0 { @@ -125,7 +126,7 @@ impl BatchTransitionWasm { transitions, user_fee_increase: user_fee_increase.unwrap_or(0), signature_public_key_id: signature_public_key_id.unwrap_or(0), - signature: BinaryData::from(signature.unwrap_or(Vec::new())), + signature: BinaryData::from(signature.unwrap_or_default()), }, ))) } @@ -139,10 +140,11 @@ impl BatchTransitionWasm { } #[wasm_bindgen(setter = "transitions")] - pub fn set_transitions(&mut self, js_batched_transitions: &js_sys::Array) { - let transitions = convert_array_to_vec_batched(&js_batched_transitions); + pub fn set_transitions(&mut self, js_batched_transitions: &js_sys::Array) -> WasmDppResult<()> { + let transitions = convert_array_to_vec_batched(js_batched_transitions)?; - self.0.set_transitions(transitions) + self.0.set_transitions(transitions); + Ok(()) } #[wasm_bindgen(getter = "signature")] @@ -156,8 +158,8 @@ impl BatchTransitionWasm { } #[wasm_bindgen(getter = "allPurchasesAmount")] - pub fn get_all_purchases_amount(&self) -> Result, JsValue> { - self.0.all_document_purchases_amount().with_js_error() + pub fn get_all_purchases_amount(&self) -> WasmDppResult> { + self.0.all_document_purchases_amount().map_err(Into::into) } #[wasm_bindgen(getter = "ownerId")] @@ -177,10 +179,10 @@ impl BatchTransitionWasm { #[wasm_bindgen(getter = "allConflictingIndexCollateralVotingFunds")] pub fn get_all_conflicting_index_collateral_voting_funds( &self, - ) -> Result, JsValue> { + ) -> WasmDppResult> { self.0 .all_conflicting_index_collateral_voting_funds() - .with_js_error() + .map_err(Into::into) } #[wasm_bindgen(setter = "signature")] @@ -208,52 +210,52 @@ impl BatchTransitionWasm { #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( state_transition: &StateTransitionWasm, - ) -> Result { + ) -> WasmDppResult { let rs_transition: StateTransition = StateTransition::from(state_transition.clone()); match rs_transition { StateTransition::Batch(batch) => Ok(BatchTransitionWasm(batch)), - _ => Err(JsValue::from("invalid state document_transition content")), + _ => Err(WasmDppError::invalid_argument( + "invalid state document_transition content", + )), } } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> Result, JsValue> { - let bytes = self.0.serialize_to_bytes().with_js_error()?; - - Ok(bytes) + pub fn to_bytes(&self) -> WasmDppResult> { + self.0.serialize_to_bytes().map_err(Into::into) } #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Hex, - )) + pub fn to_hex(&self) -> WasmDppResult { + Ok(encode(self.to_bytes()?.as_slice(), Hex)) } #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Base64, - )) + pub fn to_base64(&self) -> WasmDppResult { + Ok(encode(self.to_bytes()?.as_slice(), Base64)) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { - let rs_batch = BatchTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + pub fn from_bytes(bytes: Vec) -> WasmDppResult { + let rs_batch = BatchTransition::deserialize_from_bytes(bytes.as_slice())?; Ok(BatchTransitionWasm::from(rs_batch)) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - BatchTransitionWasm::from_bytes(decode(base64.as_str(), Base64).map_err(JsError::from)?) + pub fn from_base64(base64: String) -> WasmDppResult { + BatchTransitionWasm::from_bytes( + decode(base64.as_str(), Base64) + .map_err(|err| WasmDppError::serialization(err.to_string()))?, + ) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - BatchTransitionWasm::from_bytes(decode(hex.as_str(), Hex).map_err(JsError::from)?) + pub fn from_hex(hex: String) -> WasmDppResult { + BatchTransitionWasm::from_bytes( + decode(hex.as_str(), Hex) + .map_err(|err| WasmDppError::serialization(err.to_string()))?, + ) } } diff --git a/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs b/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs index 86663dabce6..4482ad68612 100644 --- a/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppResult; use crate::group_state_transition_info::GroupStateTransitionInfoWasm; use crate::identifier::IdentifierWasm; use crate::utils::IntoWasm; @@ -44,7 +45,7 @@ impl TokenBaseTransitionWasm { js_data_contract_id: &JsValue, js_token_id: &JsValue, js_using_group_info: &JsValue, - ) -> Result { + ) -> WasmDppResult { let using_group_info: Option = match js_using_group_info.is_undefined() { false => Some( @@ -106,14 +107,14 @@ impl TokenBaseTransitionWasm { } #[wasm_bindgen(setter = dataContractId)] - pub fn set_data_contract_id(&mut self, js_identifier: &JsValue) -> Result<(), JsValue> { + pub fn set_data_contract_id(&mut self, js_identifier: &JsValue) -> WasmDppResult<()> { self.0 .set_data_contract_id(IdentifierWasm::try_from(js_identifier)?.into()); Ok(()) } #[wasm_bindgen(setter = tokenId)] - pub fn set_token_id(&mut self, js_identifier: &JsValue) -> Result<(), JsValue> { + pub fn set_token_id(&mut self, js_identifier: &JsValue) -> WasmDppResult<()> { self.0 .set_token_id(IdentifierWasm::try_from(js_identifier)?.into()); @@ -121,7 +122,7 @@ impl TokenBaseTransitionWasm { } #[wasm_bindgen(setter = usingGroupInfo)] - pub fn set_using_group_info(&mut self, js_using_group_info: &JsValue) -> Result<(), JsValue> { + pub fn set_using_group_info(&mut self, js_using_group_info: &JsValue) -> WasmDppResult<()> { let using_group_info: Option = match js_using_group_info.is_undefined() { false => Some( diff --git a/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs b/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs index 3925f6db1b7..0f604b35e49 100644 --- a/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs @@ -1,4 +1,5 @@ use crate::enums::batch::gas_fees_paid_by::GasFeesPaidByWasm; +use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use dpp::balances::credits::TokenAmount; use dpp::data_contract::TokenContractPosition; @@ -45,7 +46,7 @@ impl TokenPaymentInfoWasm { minimum_token_cost: Option, maximum_token_cost: Option, js_gas_fees_paid_by: &JsValue, - ) -> Result { + ) -> WasmDppResult { let payment_token_contract_id: Option = match js_payment_token_contract_id .is_null() | js_payment_token_contract_id.is_undefined() @@ -102,7 +103,7 @@ impl TokenPaymentInfoWasm { pub fn set_payment_token_contract_id( &mut self, js_payment_token_contract_id: &JsValue, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let payment_token_contract_id: Option = match js_payment_token_contract_id .is_null() | js_payment_token_contract_id.is_undefined() @@ -133,7 +134,7 @@ impl TokenPaymentInfoWasm { } #[wasm_bindgen(setter = "gasFeesPaidBy")] - pub fn set_gas_fees_paid_by(&mut self, js_gas_fees_paid_by: &JsValue) -> Result<(), JsValue> { + pub fn set_gas_fees_paid_by(&mut self, js_gas_fees_paid_by: &JsValue) -> WasmDppResult<()> { let gas_fees_paid_by = match js_gas_fees_paid_by.is_undefined() | js_gas_fees_paid_by.is_null() { true => GasFeesPaidBy::default(), diff --git a/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs b/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs index d3531fb816e..a3f9051f3a5 100644 --- a/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs @@ -1,3 +1,4 @@ +use crate::error::{WasmDppError, WasmDppResult}; use crate::utils::ToSerdeJSONExt; use dpp::balances::credits::TokenAmount; use dpp::fee::Credits; @@ -41,12 +42,28 @@ impl TokenPricingScheduleWasm { } #[wasm_bindgen(js_name = "SetPrices")] - pub fn set_prices(js_prices: &JsValue) -> Result { - let prices: BTreeMap = js_prices - .with_serde_to_platform_value_map()? - .iter() - .map(|(k, v)| (k.clone().parse().unwrap(), v.clone().as_integer().unwrap())) - .collect(); + pub fn set_prices(js_prices: &JsValue) -> WasmDppResult { + let raw_prices = js_prices.with_serde_to_platform_value_map()?; + + let mut prices: BTreeMap = BTreeMap::new(); + + for (amount_str, value) in raw_prices.iter() { + let amount = amount_str.parse::().map_err(|err| { + WasmDppError::invalid_argument(format!( + "Invalid token amount '{}': {}", + amount_str, err + )) + })?; + + let credits_value = value.as_integer::().ok_or_else(|| { + WasmDppError::invalid_argument(format!( + "Price for amount '{}' must be an integer", + amount_str + )) + })?; + + prices.insert(amount, credits_value); + } Ok(Self(TokenPricingSchedule::SetPrices(prices))) } @@ -60,7 +77,7 @@ impl TokenPricingScheduleWasm { } #[wasm_bindgen(js_name = "getValue")] - pub fn get_value(&self) -> Result { + pub fn get_value(&self) -> WasmDppResult { match &self.0 { TokenPricingSchedule::SinglePrice(credits) => { Ok(JsValue::bigint_from_str(&credits.to_string())) @@ -73,7 +90,8 @@ impl TokenPricingScheduleWasm { &price_object, &JsValue::from(key.to_string()), &value.clone().into(), - )?; + ) + .map_err(WasmDppError::from_js_value)?; } Ok(price_object.into()) diff --git a/packages/wasm-dpp2/src/batch/token_transition/mod.rs b/packages/wasm-dpp2/src/batch/token_transition/mod.rs index 399f77853f3..02f8056a113 100644 --- a/packages/wasm-dpp2/src/batch/token_transition/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_transition/mod.rs @@ -9,6 +9,7 @@ use crate::batch::token_transitions::token_freeze::TokenFreezeTransitionWasm; use crate::batch::token_transitions::token_mint::TokenMintTransitionWasm; use crate::batch::token_transitions::token_transfer::TokenTransferTransitionWasm; use crate::batch::token_transitions::token_unfreeze::TokenUnFreezeTransitionWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::utils::{IntoWasm, get_class_type}; use dpp::prelude::IdentityNonce; @@ -53,94 +54,91 @@ impl TokenTransitionWasm { } #[wasm_bindgen(constructor)] - pub fn new(js_transition: &JsValue) -> Result { - let transition = match js_transition.is_object() { - true => match get_class_type(js_transition)?.as_str() { - "TokenMintTransition" => Ok(TokenTransition::from(TokenMintTransition::from( + pub fn new(js_transition: &JsValue) -> WasmDppResult { + if !js_transition.is_object() { + return Err(WasmDppError::invalid_argument("Bad token transition input")); + } + + let transition = match get_class_type(js_transition)?.as_str() { + "TokenMintTransition" => TokenTransition::from(TokenMintTransition::from( + js_transition + .to_wasm::("TokenMintTransition")? + .clone(), + )), + "TokenUnFreezeTransition" => TokenTransition::from(TokenUnfreezeTransition::from( + js_transition + .to_wasm::("TokenUnFreezeTransition")? + .clone(), + )), + "TokenTransferTransition" => TokenTransition::from(TokenTransferTransition::from( + js_transition + .to_wasm::("TokenTransferTransition")? + .clone(), + )), + "TokenFreezeTransition" => TokenTransition::from(TokenFreezeTransition::from( + js_transition + .to_wasm::("TokenFreezeTransition")? + .clone(), + )), + "TokenDestroyFrozenFundsTransition" => { + TokenTransition::from(TokenDestroyFrozenFundsTransition::from( + js_transition + .to_wasm::( + "TokenDestroyFrozenFundsTransition", + )? + .clone(), + )) + } + "TokenClaimTransition" => TokenTransition::from(TokenClaimTransition::from( + js_transition + .to_wasm::("TokenClaimTransition")? + .clone(), + )), + "TokenBurnTransition" => TokenTransition::from(TokenBurnTransition::from( + js_transition + .to_wasm::("TokenBurnTransition")? + .clone(), + )), + "TokenSetPriceForDirectPurchaseTransition" => { + TokenTransition::from(TokenSetPriceForDirectPurchaseTransition::from( js_transition - .to_wasm::("TokenMintTransition")? + .to_wasm::( + "TokenSetPriceForDirectPurchaseTransition", + )? .clone(), - ))), - "TokenUnFreezeTransition" => { - Ok(TokenTransition::from(TokenUnfreezeTransition::from( - js_transition - .to_wasm::("TokenUnFreezeTransition")? - .clone(), - ))) - } - "TokenTransferTransition" => { - Ok(TokenTransition::from(TokenTransferTransition::from( - js_transition - .to_wasm::("TokenTransferTransition")? - .clone(), - ))) - } - "TokenFreezeTransition" => Ok(TokenTransition::from(TokenFreezeTransition::from( + )) + } + "TokenDirectPurchaseTransition" => { + TokenTransition::from(TokenDirectPurchaseTransition::from( js_transition - .to_wasm::("TokenFreezeTransition")? + .to_wasm::( + "TokenDirectPurchaseTransition", + )? .clone(), - ))), - "TokenDestroyFrozenFundsTransition" => Ok(TokenTransition::from( - TokenDestroyFrozenFundsTransition::from( - js_transition - .to_wasm::( - "TokenDestroyFrozenFundsTransition", - )? - .clone(), - ), - )), - "TokenClaimTransition" => Ok(TokenTransition::from(TokenClaimTransition::from( + )) + } + "TokenConfigUpdateTransition" => { + TokenTransition::from(TokenConfigUpdateTransition::from( js_transition - .to_wasm::("TokenClaimTransition")? + .to_wasm::("TokenConfigUpdateTransition")? .clone(), - ))), - "TokenBurnTransition" => Ok(TokenTransition::from(TokenBurnTransition::from( + )) + } + "TokenEmergencyActionTransition" => { + TokenTransition::from(TokenEmergencyActionTransition::from( js_transition - .to_wasm::("TokenBurnTransition")? + .to_wasm::( + "TokenEmergencyActionTransition", + )? .clone(), - ))), - "TokenSetPriceForDirectPurchaseTransition" => Ok(TokenTransition::from( - TokenSetPriceForDirectPurchaseTransition::from( - js_transition - .to_wasm::( - "TokenSetPriceForDirectPurchaseTransition", - )? - .clone(), - ), - )), - "TokenDirectPurchaseTransition" => { - Ok(TokenTransition::from(TokenDirectPurchaseTransition::from( - js_transition - .to_wasm::( - "TokenDirectPurchaseTransition", - )? - .clone(), - ))) - } - "TokenConfigUpdateTransition" => { - Ok(TokenTransition::from(TokenConfigUpdateTransition::from( - js_transition - .to_wasm::( - "TokenConfigUpdateTransition", - )? - .clone(), - ))) - } - "TokenEmergencyActionTransition" => { - Ok(TokenTransition::from(TokenEmergencyActionTransition::from( - js_transition - .to_wasm::( - "TokenEmergencyActionTransition", - )? - .clone(), - ))) - } - _ => Err(JsValue::from("Bad token transition input")), - }, - false => Err(JsValue::from("Bad token transition input")), - }?; + )) + } + _ => { + return Err(WasmDppError::invalid_argument("Bad token transition input")); + } + }; - Ok(TokenTransitionWasm(TokenTransition::from(transition))) + Ok(TokenTransitionWasm(transition)) } #[wasm_bindgen(js_name = "getTransition")] @@ -224,10 +222,7 @@ impl TokenTransitionWasm { } #[wasm_bindgen(js_name = "getHistoricalDocumentId")] - pub fn get_historical_document_id( - &self, - js_owner: &JsValue, - ) -> Result { + pub fn get_historical_document_id(&self, js_owner: &JsValue) -> WasmDppResult { let owner = IdentifierWasm::try_from(js_owner)?; Ok(self.0.historical_document_id(owner.into()).into()) } @@ -253,7 +248,7 @@ impl TokenTransitionWasm { } #[wasm_bindgen(setter = "tokenId")] - pub fn set_token_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { + pub fn set_token_id(&mut self, js_id: &JsValue) -> WasmDppResult<()> { let id = IdentifierWasm::try_from(js_id)?; self.0.set_token_id(id.into()); @@ -262,7 +257,7 @@ impl TokenTransitionWasm { } #[wasm_bindgen(setter = "contractId")] - pub fn set_contract_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { + pub fn set_contract_id(&mut self, js_id: &JsValue) -> WasmDppResult<()> { let id = IdentifierWasm::try_from(js_id)?; self.0.set_data_contract_id(id.into()); diff --git a/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs b/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs index 9b490860164..6fd6feba539 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs @@ -1,10 +1,10 @@ -use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use crate::batch::token_base_transition::TokenBaseTransitionWasm; -use dpp::state_transition::batch_transition::TokenConfigUpdateTransition; -use dpp::state_transition::batch_transition::token_config_update_transition::TokenConfigUpdateTransitionV0; -use dpp::state_transition::batch_transition::token_config_update_transition::v0::v0_methods::TokenConfigUpdateTransitionV0Methods; +use crate::error::WasmDppResult; use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; -use wasm_bindgen::JsValue; +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; +use dpp::state_transition::batch_transition::token_config_update_transition::v0::v0_methods::TokenConfigUpdateTransitionV0Methods; +use dpp::state_transition::batch_transition::token_config_update_transition::TokenConfigUpdateTransitionV0; +use dpp::state_transition::batch_transition::TokenConfigUpdateTransition; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] @@ -40,7 +40,7 @@ impl TokenConfigUpdateTransitionWasm { base: &TokenBaseTransitionWasm, update_token_configuration_item: &TokenConfigurationChangeItemWasm, public_note: Option, - ) -> Result { + ) -> WasmDppResult { Ok(TokenConfigUpdateTransitionWasm( TokenConfigUpdateTransition::V0(TokenConfigUpdateTransitionV0 { base: base.clone().into(), diff --git a/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs b/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs index 31dfd3148cf..12cba460f69 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs @@ -1,13 +1,14 @@ use crate::batch::token_base_transition::TokenBaseTransitionWasm; use crate::batch::token_pricing_schedule::TokenPricingScheduleWasm; -use dpp::state_transition::batch_transition::token_set_price_for_direct_purchase_transition::TokenSetPriceForDirectPurchaseTransitionV0; -use dpp::state_transition::batch_transition::TokenSetPriceForDirectPurchaseTransition; +use crate::error::WasmDppResult; +use crate::utils::IntoWasm; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use dpp::state_transition::batch_transition::token_set_price_for_direct_purchase_transition::v0::v0_methods::TokenSetPriceForDirectPurchaseTransitionV0Methods; +use dpp::state_transition::batch_transition::token_set_price_for_direct_purchase_transition::TokenSetPriceForDirectPurchaseTransitionV0; +use dpp::state_transition::batch_transition::TokenSetPriceForDirectPurchaseTransition; use dpp::tokens::token_pricing_schedule::TokenPricingSchedule; -use crate::utils::IntoWasm; -use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::JsValue; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenSetPriceForDirectPurchaseTransition)] @@ -46,7 +47,7 @@ impl TokenSetPriceForDirectPurchaseTransitionWasm { base: &TokenBaseTransitionWasm, js_price: &JsValue, public_note: Option, - ) -> Result { + ) -> WasmDppResult { let price: Option = match js_price.is_undefined() { true => None, false => Some( @@ -97,7 +98,7 @@ impl TokenSetPriceForDirectPurchaseTransitionWasm { } #[wasm_bindgen(setter = "price")] - pub fn set_price(&mut self, js_price: &JsValue) -> Result<(), JsValue> { + pub fn set_price(&mut self, js_price: &JsValue) -> WasmDppResult<()> { let price: Option = match js_price.is_undefined() { true => None, false => Some( @@ -108,6 +109,7 @@ impl TokenSetPriceForDirectPurchaseTransitionWasm { ), }; - Ok(self.0.set_price(price)) + self.0.set_price(price); + Ok(()) } } diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs index a34bd838ac0..e3f96ba60ff 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs @@ -1,9 +1,9 @@ use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::error::WasmDppResult; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; -use dpp::state_transition::batch_transition::TokenBurnTransition; -use dpp::state_transition::batch_transition::token_burn_transition::TokenBurnTransitionV0; use dpp::state_transition::batch_transition::token_burn_transition::v0::v0_methods::TokenBurnTransitionV0Methods; -use wasm_bindgen::JsValue; +use dpp::state_transition::batch_transition::token_burn_transition::TokenBurnTransitionV0; +use dpp::state_transition::batch_transition::TokenBurnTransition; use wasm_bindgen::prelude::wasm_bindgen; #[derive(Debug, Clone, PartialEq)] @@ -39,7 +39,7 @@ impl TokenBurnTransitionWasm { base: &TokenBaseTransitionWasm, burn_amount: u64, public_note: Option, - ) -> Result { + ) -> WasmDppResult { Ok(TokenBurnTransitionWasm(TokenBurnTransition::V0( TokenBurnTransitionV0 { base: base.clone().into(), diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs index 9da8b940ef6..448f5a2f465 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs @@ -1,11 +1,12 @@ -use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use crate::batch::token_base_transition::TokenBaseTransitionWasm; -use dpp::state_transition::batch_transition::TokenClaimTransition; -use dpp::state_transition::batch_transition::token_claim_transition::TokenClaimTransitionV0; +use crate::enums::token::distribution_type::TokenDistributionTypeWasm; +use crate::error::WasmDppResult; +use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use dpp::state_transition::batch_transition::token_claim_transition::v0::v0_methods::TokenClaimTransitionV0Methods; -use wasm_bindgen::JsValue; +use dpp::state_transition::batch_transition::token_claim_transition::TokenClaimTransitionV0; +use dpp::state_transition::batch_transition::TokenClaimTransition; use wasm_bindgen::prelude::wasm_bindgen; -use crate::enums::token::distribution_type::TokenDistributionTypeWasm; +use wasm_bindgen::JsValue; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name = "TokenClaimTransition")] @@ -40,7 +41,7 @@ impl TokenClaimTransitionWasm { base: &TokenBaseTransitionWasm, js_distribution_type: &JsValue, public_note: Option, - ) -> Result { + ) -> WasmDppResult { let distribution_type = match js_distribution_type.is_undefined() { true => TokenDistributionTypeWasm::default(), false => TokenDistributionTypeWasm::try_from(js_distribution_type.clone())?, @@ -81,12 +82,13 @@ impl TokenClaimTransitionWasm { } #[wasm_bindgen(setter = "distributionType")] - pub fn set_distribution_type(&mut self, js_distribution_type: &JsValue) -> Result<(), JsValue> { + pub fn set_distribution_type(&mut self, js_distribution_type: &JsValue) -> WasmDppResult<()> { let distribution_type = match js_distribution_type.is_undefined() { true => TokenDistributionTypeWasm::default(), false => TokenDistributionTypeWasm::try_from(js_distribution_type.clone())?, }; - Ok(self.0.set_distribution_type(distribution_type.into())) + self.0.set_distribution_type(distribution_type.into()); + Ok(()) } } diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs index b51cd43af57..99f07c3cc28 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs @@ -1,12 +1,13 @@ +use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::error::WasmDppResult; +use crate::identifier::IdentifierWasm; use dpp::identifier::Identifier; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; -use crate::batch::token_base_transition::TokenBaseTransitionWasm; -use dpp::state_transition::batch_transition::TokenDestroyFrozenFundsTransition; -use dpp::state_transition::batch_transition::token_destroy_frozen_funds_transition::TokenDestroyFrozenFundsTransitionV0; use dpp::state_transition::batch_transition::token_destroy_frozen_funds_transition::v0::v0_methods::TokenDestroyFrozenFundsTransitionV0Methods; -use wasm_bindgen::JsValue; +use dpp::state_transition::batch_transition::token_destroy_frozen_funds_transition::TokenDestroyFrozenFundsTransitionV0; +use dpp::state_transition::batch_transition::TokenDestroyFrozenFundsTransition; use wasm_bindgen::prelude::wasm_bindgen; -use crate::identifier::IdentifierWasm; +use wasm_bindgen::JsValue; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenDestroyFrozenFundsTransition)] @@ -41,7 +42,7 @@ impl TokenDestroyFrozenFundsTransitionWasm { base: &TokenBaseTransitionWasm, js_frozen_identity_id: &JsValue, public_note: Option, - ) -> Result { + ) -> WasmDppResult { let frozen_identity_id: Identifier = IdentifierWasm::try_from(js_frozen_identity_id)?.into(); @@ -80,10 +81,7 @@ impl TokenDestroyFrozenFundsTransitionWasm { } #[wasm_bindgen(setter = "frozenIdentityId")] - pub fn set_frozen_identity_id( - &mut self, - js_frozen_identity_id: &JsValue, - ) -> Result<(), JsValue> { + pub fn set_frozen_identity_id(&mut self, js_frozen_identity_id: &JsValue) -> WasmDppResult<()> { self.0 .set_frozen_identity_id(IdentifierWasm::try_from(js_frozen_identity_id)?.into()); Ok(()) diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs index 5de53173776..a1bfe9f1568 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs @@ -1,12 +1,13 @@ +use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::error::WasmDppResult; +use crate::identifier::IdentifierWasm; use dpp::identifier::Identifier; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; -use dpp::state_transition::batch_transition::token_freeze_transition::TokenFreezeTransitionV0; use dpp::state_transition::batch_transition::token_freeze_transition::v0::v0_methods::TokenFreezeTransitionV0Methods; +use dpp::state_transition::batch_transition::token_freeze_transition::TokenFreezeTransitionV0; use dpp::state_transition::batch_transition::TokenFreezeTransition; -use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::identifier::IdentifierWasm; -use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use wasm_bindgen::JsValue; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenFreezeTransition)] @@ -41,7 +42,7 @@ impl TokenFreezeTransitionWasm { base: &TokenBaseTransitionWasm, js_identity_to_freeze_id: &JsValue, public_note: Option, - ) -> Result { + ) -> WasmDppResult { let identity_to_freeze_id: Identifier = IdentifierWasm::try_from(js_identity_to_freeze_id)?.into(); @@ -80,10 +81,7 @@ impl TokenFreezeTransitionWasm { } #[wasm_bindgen(setter = "frozenIdentityId")] - pub fn set_frozen_identity_id( - &mut self, - js_frozen_identity_id: &JsValue, - ) -> Result<(), JsValue> { + pub fn set_frozen_identity_id(&mut self, js_frozen_identity_id: &JsValue) -> WasmDppResult<()> { self.0 .set_frozen_identity_id(IdentifierWasm::try_from(js_frozen_identity_id)?.into()); Ok(()) diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs index 3b2f6689d52..004ad643a64 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs @@ -1,14 +1,14 @@ use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::error::WasmDppResult; +use crate::identifier::IdentifierWasm; +use crate::token_configuration::TokenConfigurationWasm; use dpp::prelude::Identifier; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; -use dpp::state_transition::batch_transition::TokenMintTransition; -use dpp::state_transition::batch_transition::token_mint_transition::TokenMintTransitionV0; use dpp::state_transition::batch_transition::token_mint_transition::v0::v0_methods::TokenMintTransitionV0Methods; -use crate::identifier::IdentifierWasm; -use wasm_bindgen::JsValue; +use dpp::state_transition::batch_transition::token_mint_transition::TokenMintTransitionV0; +use dpp::state_transition::batch_transition::TokenMintTransition; use wasm_bindgen::prelude::wasm_bindgen; -use crate::token_configuration::TokenConfigurationWasm; -use crate::utils::WithJsError; +use wasm_bindgen::JsValue; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenMintTransition)] @@ -44,7 +44,7 @@ impl TokenMintTransitionWasm { js_issued_to_identity_id: &JsValue, amount: u64, public_note: Option, - ) -> Result { + ) -> WasmDppResult { let issued_to_identity_id: Option = match js_issued_to_identity_id.is_undefined() { false => Some(IdentifierWasm::try_from(js_issued_to_identity_id)?.into()), @@ -85,16 +85,12 @@ impl TokenMintTransitionWasm { } #[wasm_bindgen(js_name = getRecipitnId)] - pub fn recipient_id(&self, config: &TokenConfigurationWasm) -> Result { - Ok(self - .0 - .recipient_id(&config.clone().into()) - .with_js_error()? - .into()) + pub fn recipient_id(&self, config: &TokenConfigurationWasm) -> WasmDppResult { + Ok(self.0.recipient_id(&config.clone().into())?.into()) } #[wasm_bindgen(setter = issuedToIdentityId)] - pub fn set_issued_to_identity_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { + pub fn set_issued_to_identity_id(&mut self, js_id: &JsValue) -> WasmDppResult<()> { match js_id.is_undefined() { true => { self.0.set_issued_to_identity_id(None); diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs index 24839dc370e..c6a1923f6ab 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs @@ -1,16 +1,17 @@ use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::encrypted_note::private_encrypted_note::PrivateEncryptedNoteWasm; +use crate::encrypted_note::shared_encrypted_note::SharedEncryptedNoteWasm; +use crate::error::WasmDppResult; +use crate::identifier::IdentifierWasm; +use crate::utils::IntoWasm; use dpp::prelude::Identifier; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; -use dpp::state_transition::batch_transition::TokenTransferTransition; -use dpp::state_transition::batch_transition::token_transfer_transition::TokenTransferTransitionV0; use dpp::state_transition::batch_transition::token_transfer_transition::v0::v0_methods::TokenTransferTransitionV0Methods; +use dpp::state_transition::batch_transition::token_transfer_transition::TokenTransferTransitionV0; +use dpp::state_transition::batch_transition::TokenTransferTransition; use dpp::tokens::{PrivateEncryptedNote, SharedEncryptedNote}; -use crate::identifier::IdentifierWasm; -use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::encrypted_note::private_encrypted_note::PrivateEncryptedNoteWasm; -use crate::encrypted_note::shared_encrypted_note::SharedEncryptedNoteWasm; -use crate::utils::IntoWasm; +use wasm_bindgen::JsValue; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenTransferTransition)] @@ -48,7 +49,7 @@ impl TokenTransferTransitionWasm { public_note: Option, js_shared_encrypted_note: &JsValue, js_private_encrypted_note: &JsValue, - ) -> Result { + ) -> WasmDppResult { let recipient_id: Identifier = IdentifierWasm::try_from(js_recipient_id)?.into(); let shared_encrypted_note: Option = @@ -122,7 +123,7 @@ impl TokenTransferTransitionWasm { } #[wasm_bindgen(setter = recipientId)] - pub fn set_recipient_id(&mut self, js_recipient: &JsValue) -> Result<(), JsValue> { + pub fn set_recipient_id(&mut self, js_recipient: &JsValue) -> WasmDppResult<()> { let recipient = IdentifierWasm::try_from(js_recipient)?; self.0.set_recipient_id(recipient.into()); @@ -149,7 +150,7 @@ impl TokenTransferTransitionWasm { pub fn set_shared_encrypted_note( &mut self, js_shared_encrypted_note: &JsValue, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let shared_encrypted_note: Option = match js_shared_encrypted_note.is_undefined() { true => None, @@ -161,14 +162,15 @@ impl TokenTransferTransitionWasm { ), }; - Ok(self.0.set_shared_encrypted_note(shared_encrypted_note)) + self.0.set_shared_encrypted_note(shared_encrypted_note); + Ok(()) } #[wasm_bindgen(setter = "privateEncryptedNote")] pub fn set_private_encrypted_note( &mut self, js_private_encrypted_note: &JsValue, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let private_encrypted_note: Option = match js_private_encrypted_note.is_undefined() { true => None, @@ -180,6 +182,7 @@ impl TokenTransferTransitionWasm { ), }; - Ok(self.0.set_private_encrypted_note(private_encrypted_note)) + self.0.set_private_encrypted_note(private_encrypted_note); + Ok(()) } } diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs b/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs index d59150191f2..bae8134daf8 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs +++ b/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs @@ -1,12 +1,13 @@ use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::error::WasmDppResult; +use crate::identifier::IdentifierWasm; use dpp::identifier::Identifier; -use dpp::state_transition::batch_transition::token_unfreeze_transition::TokenUnfreezeTransitionV0; -use dpp::state_transition::batch_transition::TokenUnfreezeTransition; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use dpp::state_transition::batch_transition::token_unfreeze_transition::v0::v0_methods::TokenUnfreezeTransitionV0Methods; -use crate::identifier::IdentifierWasm; -use wasm_bindgen::JsValue; +use dpp::state_transition::batch_transition::token_unfreeze_transition::TokenUnfreezeTransitionV0; +use dpp::state_transition::batch_transition::TokenUnfreezeTransition; use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::JsValue; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenUnFreezeTransition)] @@ -41,7 +42,7 @@ impl TokenUnFreezeTransitionWasm { base: &TokenBaseTransitionWasm, js_frozen_identity_id: &JsValue, public_note: Option, - ) -> Result { + ) -> WasmDppResult { let frozen_identity_id: Identifier = IdentifierWasm::try_from(js_frozen_identity_id)?.into(); @@ -80,10 +81,7 @@ impl TokenUnFreezeTransitionWasm { } #[wasm_bindgen(setter = "frozenIdentityId")] - pub fn set_frozen_identity_id( - &mut self, - js_frozen_identity_id: &JsValue, - ) -> Result<(), JsValue> { + pub fn set_frozen_identity_id(&mut self, js_frozen_identity_id: &JsValue) -> WasmDppResult<()> { self.0 .set_frozen_identity_id(IdentifierWasm::try_from(js_frozen_identity_id)?.into()); Ok(()) diff --git a/packages/wasm-dpp2/src/contract_bounds/mod.rs b/packages/wasm-dpp2/src/contract_bounds/mod.rs index 398643a2ba1..14fc0694d43 100644 --- a/packages/wasm-dpp2/src/contract_bounds/mod.rs +++ b/packages/wasm-dpp2/src/contract_bounds/mod.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use dpp::identity::contract_bounds::ContractBounds; use wasm_bindgen::JsValue; @@ -35,7 +36,7 @@ impl ContractBoundsWasm { pub fn new( js_contract_id: &JsValue, document_type_name: Option, - ) -> Result { + ) -> WasmDppResult { let contract_id = IdentifierWasm::try_from(js_contract_id)?; Ok(ContractBoundsWasm(match document_type_name { @@ -50,7 +51,7 @@ impl ContractBoundsWasm { } #[wasm_bindgen(js_name = "SingleContract")] - pub fn single_contract(js_contract_id: &JsValue) -> Result { + pub fn single_contract(js_contract_id: &JsValue) -> WasmDppResult { let contract_id = IdentifierWasm::try_from(js_contract_id)?; Ok(ContractBoundsWasm(ContractBounds::SingleContract { @@ -62,7 +63,7 @@ impl ContractBoundsWasm { pub fn single_contract_document_type_name( js_contract_id: &JsValue, document_type_name: String, - ) -> Result { + ) -> WasmDppResult { let contract_id = IdentifierWasm::try_from(js_contract_id)?; Ok(ContractBoundsWasm( @@ -97,7 +98,7 @@ impl ContractBoundsWasm { } #[wasm_bindgen(setter = "identifier")] - pub fn set_id(&mut self, js_contract_id: &JsValue) -> Result<(), JsValue> { + pub fn set_id(&mut self, js_contract_id: &JsValue) -> WasmDppResult<()> { let contract_id = IdentifierWasm::try_from(js_contract_id)?; self.0 = match self.clone().0 { diff --git a/packages/wasm-dpp2/src/core_script/mod.rs b/packages/wasm-dpp2/src/core_script/mod.rs index 11509ec87a9..35b703e5778 100644 --- a/packages/wasm-dpp2/src/core_script/mod.rs +++ b/packages/wasm-dpp2/src/core_script/mod.rs @@ -1,4 +1,5 @@ use crate::enums::network::NetworkWasm; +use crate::error::{WasmDppError, WasmDppResult}; use dpp::dashcore::address::Payload; use dpp::dashcore::{Address, opcodes}; use dpp::identity::core_script::CoreScript; @@ -67,11 +68,11 @@ impl CoreScriptWasm { } #[wasm_bindgen(js_name = "toAddress")] - pub fn to_address(&self, js_network: &JsValue) -> Result { + pub fn to_address(&self, js_network: &JsValue) -> WasmDppResult { let network = NetworkWasm::try_from(js_network.clone())?; - let payload = - Payload::from_script(self.0.as_script()).map_err(|e| JsValue::from(e.to_string()))?; + let payload = Payload::from_script(self.0.as_script()) + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; let address = Address::new(network.into(), payload); diff --git a/packages/wasm-dpp2/src/data_contract/mod.rs b/packages/wasm-dpp2/src/data_contract/mod.rs index 2b3af1452c1..7ee33ca671a 100644 --- a/packages/wasm-dpp2/src/data_contract/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/mod.rs @@ -65,7 +65,8 @@ pub fn tokens_configuration_from_js_value( .map_err(|e| WasmDppError::serialization(e.to_string()))?), }?; - let js_config = Reflect::get(&js_configuration, &key)? + let js_config = Reflect::get(&configuration_object, &key) + .map_err(WasmDppError::from_js_value)? .to_wasm::("TokenConfiguration")? .clone(); diff --git a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs index 64ab72c5b49..fcc5cb11ee7 100644 --- a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs +++ b/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs @@ -1,8 +1,7 @@ use crate::data_contract::DataContractWasm; use crate::enums::platform::PlatformVersionWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::state_transition::StateTransitionWasm; -use crate::utils::WithJsError; -use dpp::ProtocolError; use dpp::data_contract::serialized_version::DataContractInSerializationFormat; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; use dpp::platform_value::string_encoding::{decode, encode}; @@ -17,8 +16,8 @@ use dpp::validation::operations::ProtocolValidationOperation; use dpp::version::{ FeatureVersion, ProtocolVersion, TryFromPlatformVersioned, TryIntoPlatformVersioned, }; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "DataContractCreateTransition")] pub struct DataContractCreateTransitionWasm(DataContractCreateTransition); @@ -40,7 +39,7 @@ impl DataContractCreateTransitionWasm { data_contract: &DataContractWasm, identity_nonce: IdentityNonce, js_platform_version: JsValue, - ) -> Result { + ) -> WasmDppResult { let rs_data_contract: DataContract = data_contract.clone().into(); let platform_version = match js_platform_version.is_undefined() { @@ -48,14 +47,10 @@ impl DataContractCreateTransitionWasm { false => PlatformVersionWasm::try_from(js_platform_version)?, }; - let rs_data_contract_in_serialized: Result< - DataContractInSerializationFormat, - ProtocolError, - > = rs_data_contract.try_into_platform_versioned(&platform_version.into()); - let rs_data_contract_create_transition_v0: DataContractCreateTransitionV0 = DataContractCreateTransitionV0 { - data_contract: rs_data_contract_in_serialized.with_js_error()?, + data_contract: rs_data_contract + .try_into_platform_versioned(&platform_version.into())?, identity_nonce, user_fee_increase: 0, signature_public_key_id: 0, @@ -71,10 +66,9 @@ impl DataContractCreateTransitionWasm { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> WasmDppResult { let rs_data_contract_create_transition: DataContractCreateTransition = - DataContractCreateTransition::deserialize_from_bytes(bytes.as_slice()) - .with_js_error()?; + DataContractCreateTransition::deserialize_from_bytes(bytes.as_slice())?; Ok(DataContractCreateTransitionWasm( rs_data_contract_create_transition, @@ -82,38 +76,34 @@ impl DataContractCreateTransitionWasm { } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = decode(hex.as_str(), Hex) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; DataContractCreateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + pub fn from_base64(base64: String) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; DataContractCreateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> Result, JsValue> { - self.0.serialize_to_bytes().with_js_error() + pub fn to_bytes(&self) -> WasmDppResult> { + self.0.serialize_to_bytes().map_err(Into::into) } #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Hex, - )) + pub fn to_hex(&self) -> WasmDppResult { + Ok(encode(self.to_bytes()?.as_slice(), Hex)) } #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Base64, - )) + pub fn to_base64(&self) -> WasmDppResult { + Ok(encode(self.to_bytes()?.as_slice(), Base64)) } #[wasm_bindgen(getter = "featureVersion")] @@ -125,10 +115,10 @@ impl DataContractCreateTransitionWasm { pub fn verify_protocol_version( &self, protocol_version: ProtocolVersion, - ) -> Result { + ) -> WasmDppResult { self.0 .verify_protocol_version(protocol_version) - .with_js_error() + .map_err(Into::into) } #[wasm_bindgen(js_name = "setDataContract")] @@ -136,7 +126,7 @@ impl DataContractCreateTransitionWasm { &mut self, data_contract: &DataContractWasm, js_platform_version: JsValue, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, @@ -146,8 +136,7 @@ impl DataContractCreateTransitionWasm { DataContractInSerializationFormat::try_from_platform_versioned( DataContract::from(data_contract.clone()), &platform_version.into(), - ) - .with_js_error()?; + )?; self.0.set_data_contract(data_contract_serialization_format); @@ -164,7 +153,7 @@ impl DataContractCreateTransitionWasm { &self, js_platform_version: JsValue, full_validation: Option, - ) -> Result { + ) -> WasmDppResult { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, @@ -179,8 +168,7 @@ impl DataContractCreateTransitionWasm { full_validation.unwrap_or(false), &mut validation_operations, &platform_version.into(), - ) - .with_js_error()?; + )?; Ok(DataContractWasm::from(rs_data_contract)) } @@ -195,14 +183,14 @@ impl DataContractCreateTransitionWasm { #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( state_transition: &StateTransitionWasm, - ) -> Result { + ) -> WasmDppResult { let rs_transition = StateTransition::from(state_transition.clone()); match rs_transition { StateTransition::DataContractCreate(state_transition) => { Ok(DataContractCreateTransitionWasm(state_transition)) } - _ => Err(JsValue::from("Incorrect transition type")), + _ => Err(WasmDppError::invalid_argument("Incorrect transition type")), } } } diff --git a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs b/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs index 3508ef98b55..dcb92de98ca 100644 --- a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs +++ b/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs @@ -1,7 +1,7 @@ use crate::data_contract::DataContractWasm; use crate::enums::platform::PlatformVersionWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::state_transition::StateTransitionWasm; -use crate::utils::WithJsError; use dpp::data_contract::serialized_version::DataContractInSerializationFormat; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; use dpp::platform_value::string_encoding::{decode, encode}; @@ -12,8 +12,8 @@ use dpp::state_transition::data_contract_update_transition::DataContractUpdateTr use dpp::state_transition::data_contract_update_transition::accessors::DataContractUpdateTransitionAccessorsV0; use dpp::validation::operations::ProtocolValidationOperation; use dpp::version::{FeatureVersion, ProtocolVersion, TryFromPlatformVersioned}; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "DataContractUpdateTransition")] pub struct DataContractUpdateTransitionWasm(DataContractUpdateTransition); @@ -35,7 +35,7 @@ impl DataContractUpdateTransitionWasm { data_contract: &DataContractWasm, identity_nonce: IdentityNonce, js_platform_version: JsValue, - ) -> Result { + ) -> WasmDppResult { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, @@ -45,8 +45,7 @@ impl DataContractUpdateTransitionWasm { DataContractUpdateTransition::try_from_platform_versioned( (DataContract::from(data_contract.clone()), identity_nonce), &platform_version.into(), - ) - .with_js_error()?; + )?; Ok(DataContractUpdateTransitionWasm( rs_data_contract_update_transition, @@ -54,10 +53,9 @@ impl DataContractUpdateTransitionWasm { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> WasmDppResult { let rs_data_contract_update_transition: DataContractUpdateTransition = - DataContractUpdateTransition::deserialize_from_bytes(bytes.as_slice()) - .with_js_error()?; + DataContractUpdateTransition::deserialize_from_bytes(bytes.as_slice())?; Ok(DataContractUpdateTransitionWasm( rs_data_contract_update_transition, @@ -65,38 +63,34 @@ impl DataContractUpdateTransitionWasm { } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = decode(hex.as_str(), Hex) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; DataContractUpdateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + pub fn from_base64(base64: String) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; DataContractUpdateTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> Result, JsValue> { - self.0.serialize_to_bytes().with_js_error() + pub fn to_bytes(&self) -> WasmDppResult> { + self.0.serialize_to_bytes().map_err(Into::into) } #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Hex, - )) + pub fn to_hex(&self) -> WasmDppResult { + Ok(encode(self.to_bytes()?.as_slice(), Hex)) } #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self) -> Result { - Ok(encode( - self.0.serialize_to_bytes().with_js_error()?.as_slice(), - Base64, - )) + pub fn to_base64(&self) -> WasmDppResult { + Ok(encode(self.to_bytes()?.as_slice(), Base64)) } #[wasm_bindgen(getter = "featureVersion")] @@ -108,10 +102,10 @@ impl DataContractUpdateTransitionWasm { pub fn verify_protocol_version( &self, protocol_version: ProtocolVersion, - ) -> Result { + ) -> WasmDppResult { self.0 .verify_protocol_version(protocol_version) - .with_js_error() + .map_err(Into::into) } #[wasm_bindgen(js_name = "setDataContract")] @@ -119,7 +113,7 @@ impl DataContractUpdateTransitionWasm { &mut self, data_contract: &DataContractWasm, js_platform_version: JsValue, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, @@ -129,8 +123,7 @@ impl DataContractUpdateTransitionWasm { DataContractInSerializationFormat::try_from_platform_versioned( DataContract::from(data_contract.clone()), &platform_version.into(), - ) - .with_js_error()?; + )?; self.0.set_data_contract(data_contract_serialization_format); @@ -147,7 +140,7 @@ impl DataContractUpdateTransitionWasm { &self, full_validation: Option, js_platform_version: JsValue, - ) -> Result { + ) -> WasmDppResult { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, @@ -162,8 +155,7 @@ impl DataContractUpdateTransitionWasm { full_validation.unwrap_or(false), &mut validation_operations, &platform_version.into(), - ) - .with_js_error()?; + )?; Ok(DataContractWasm::from(rs_data_contract)) } @@ -178,14 +170,14 @@ impl DataContractUpdateTransitionWasm { #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( state_transition: &StateTransitionWasm, - ) -> Result { + ) -> WasmDppResult { let rs_transition = StateTransition::from(state_transition.clone()); match rs_transition { StateTransition::DataContractUpdate(state_transition) => { Ok(DataContractUpdateTransitionWasm(state_transition)) } - _ => Err(JsValue::from("Incorrect transition type")), + _ => Err(WasmDppError::invalid_argument("Incorrect transition type")), } } } diff --git a/packages/wasm-dpp2/src/document/methods/mod.rs b/packages/wasm-dpp2/src/document/methods/mod.rs index 9bca4bd2fd1..3b44231dd04 100644 --- a/packages/wasm-dpp2/src/document/methods/mod.rs +++ b/packages/wasm-dpp2/src/document/methods/mod.rs @@ -1,9 +1,9 @@ use crate::data_contract::DataContractWasm; use crate::document::DocumentWasm; use crate::enums::platform::PlatformVersionWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::utils::{ToSerdeJSONExt, WithJsError}; -use dpp::ProtocolError; +use crate::utils::ToSerdeJSONExt; use dpp::dashcore::hashes::serde::Serialize; use dpp::data_contract::JsonValue; use dpp::document::Document; @@ -17,8 +17,8 @@ use dpp::prelude::Revision; use dpp::util::entropy_generator; use dpp::util::entropy_generator::EntropyGenerator; use std::collections::BTreeMap; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_class = Document)] impl DocumentWasm { @@ -40,21 +40,19 @@ impl DocumentWasm { js_data_contract_id: &JsValue, js_owner_id: &JsValue, js_document_id: &JsValue, - ) -> Result { + ) -> WasmDppResult { let data_contract_id = IdentifierWasm::try_from(js_data_contract_id)?; let owner_id = IdentifierWasm::try_from(js_owner_id)?; let revision = Revision::from(js_revision); - let document = js_raw_document - .with_serde_to_platform_value_map() - .expect("cannot convert document to platform value map"); + let document = js_raw_document.with_serde_to_platform_value_map()?; let revision = Revision::from(revision); let entropy = entropy_generator::DefaultEntropyGenerator .generate() - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::serialization(err.to_string()))?; let document_id: IdentifierWasm = match js_document_id.is_undefined() { true => crate::utils::generate_document_id_v0( @@ -112,15 +110,16 @@ impl DocumentWasm { } #[wasm_bindgen(getter=properties)] - pub fn get_properties(&self) -> Result { + pub fn get_properties(&self) -> WasmDppResult { let json_value: JsonValue = self .properties .clone() .to_json_value() - .map_err(ProtocolError::ValueError) - .with_js_error()?; + .map_err(|err| WasmDppError::serialization(err.to_string()))?; - let js_value = json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?; + let js_value = json_value + .serialize(&serde_wasm_bindgen::Serializer::json_compatible()) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; Ok(js_value) } @@ -180,43 +179,49 @@ impl DocumentWasm { } #[wasm_bindgen(setter=id)] - pub fn set_id(&mut self, id: &JsValue) -> Result<(), JsValue> { + pub fn set_id(&mut self, id: &JsValue) -> WasmDppResult<()> { self.id = IdentifierWasm::try_from(id)?.clone(); Ok(()) } #[wasm_bindgen(setter=entropy)] - pub fn set_entropy(&mut self, entropy: JsValue) { - match entropy.is_undefined() { - false => { - let value = entropy.with_serde_to_platform_value().unwrap(); - - let mut entropy = [0u8; 32]; - let bytes = value.as_bytes().unwrap(); - let len = bytes.len().min(32); - entropy[..len].copy_from_slice(&bytes[..len]); - self.entropy = Some(entropy); - } - true => self.entropy = None, + pub fn set_entropy(&mut self, entropy: JsValue) -> WasmDppResult<()> { + if entropy.is_undefined() { + self.entropy = None; + return Ok(()); } + + let value = entropy.with_serde_to_platform_value()?; + + let bytes = value.as_bytes().ok_or_else(|| { + WasmDppError::invalid_argument("Entropy must be provided as a byte array") + })?; + + let mut entropy_bytes = [0u8; 32]; + let len = bytes.len().min(32); + entropy_bytes[..len].copy_from_slice(&bytes[..len]); + self.entropy = Some(entropy_bytes); + + Ok(()) } #[wasm_bindgen(setter=dataContractId)] - pub fn set_js_data_contract_id(&mut self, js_contract_id: &JsValue) -> Result<(), JsValue> { + pub fn set_js_data_contract_id(&mut self, js_contract_id: &JsValue) -> WasmDppResult<()> { self.data_contract_id = IdentifierWasm::try_from(js_contract_id.clone())?; Ok(()) } #[wasm_bindgen(setter=ownerId)] - pub fn set_owner_id(&mut self, id: &JsValue) -> Result<(), JsValue> { + pub fn set_owner_id(&mut self, id: &JsValue) -> WasmDppResult<()> { self.owner_id = IdentifierWasm::try_from(id)?.clone(); Ok(()) } #[wasm_bindgen(setter=properties)] - pub fn set_properties(&mut self, properties: JsValue) { - self.properties = properties.with_serde_to_platform_value_map().unwrap() + pub fn set_properties(&mut self, properties: JsValue) -> WasmDppResult<()> { + self.properties = properties.with_serde_to_platform_value_map()?; + Ok(()) } #[wasm_bindgen(setter=revision)] @@ -282,7 +287,7 @@ impl DocumentWasm { &self, data_contract: &DataContractWasm, js_platform_version: JsValue, - ) -> Result, JsValue> { + ) -> WasmDppResult> { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, @@ -292,7 +297,7 @@ impl DocumentWasm { let document_type_ref = data_contract .get_document_type_ref_by_name(self.get_document_type_name()) - .map_err(|err| JsValue::from_str(err.to_string().as_str()))?; + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; DocumentPlatformConversionMethodsV0::serialize( &rs_document, @@ -300,7 +305,7 @@ impl DocumentWasm { &data_contract.clone().into(), &platform_version.into(), ) - .with_js_error() + .map_err(Into::into) } #[wasm_bindgen(js_name=hex)] @@ -308,7 +313,7 @@ impl DocumentWasm { &self, data_contract: &DataContractWasm, js_platform_version: JsValue, - ) -> Result { + ) -> WasmDppResult { Ok(encode( self.to_bytes(data_contract, js_platform_version)? .as_slice(), @@ -321,7 +326,7 @@ impl DocumentWasm { &self, data_contract: &DataContractWasm, js_platform_version: JsValue, - ) -> Result { + ) -> WasmDppResult { Ok(encode( self.to_bytes(data_contract, js_platform_version)? .as_slice(), @@ -335,7 +340,7 @@ impl DocumentWasm { data_contract: &DataContractWasm, type_name: String, js_platform_version: JsValue, - ) -> Result { + ) -> WasmDppResult { let platform_version = match js_platform_version.is_undefined() { true => PlatformVersionWasm::default(), false => PlatformVersionWasm::try_from(js_platform_version)?, @@ -344,15 +349,14 @@ impl DocumentWasm { let document_type_ref = match data_contract.get_document_type_ref_by_name(type_name.clone()) { Ok(type_ref) => Ok(type_ref), - Err(err) => Err(JsValue::from_str(err.to_string().as_str())), + Err(err) => Err(WasmDppError::invalid_argument(err.to_string())), }?; let rs_document = Document::from_bytes( bytes.as_slice(), document_type_ref, &platform_version.into(), - ) - .with_js_error()?; + )?; let mut js_document = DocumentWasm::from(rs_document); @@ -368,9 +372,10 @@ impl DocumentWasm { data_contract: &DataContractWasm, type_name: String, js_platform_version: JsValue, - ) -> Result { + ) -> WasmDppResult { DocumentWasm::from_bytes( - decode(hex.as_str(), Hex).map_err(JsError::from)?, + decode(hex.as_str(), Hex) + .map_err(|err| WasmDppError::serialization(err.to_string()))?, data_contract, type_name, js_platform_version, @@ -383,9 +388,10 @@ impl DocumentWasm { data_contract: &DataContractWasm, type_name: String, js_platform_version: JsValue, - ) -> Result { + ) -> WasmDppResult { DocumentWasm::from_bytes( - decode(base64.as_str(), Base64).map_err(JsError::from)?, + decode(base64.as_str(), Base64) + .map_err(|err| WasmDppError::serialization(err.to_string()))?, data_contract, type_name, js_platform_version, @@ -398,7 +404,7 @@ impl DocumentWasm { js_owner_id: &JsValue, js_data_contract_id: &JsValue, opt_entropy: Option>, - ) -> Result, JsValue> { + ) -> WasmDppResult> { let owner_id = IdentifierWasm::try_from(js_owner_id)?; let data_contract_id = IdentifierWasm::try_from(js_data_contract_id)?; @@ -412,7 +418,7 @@ impl DocumentWasm { } None => entropy_generator::DefaultEntropyGenerator .generate() - .with_js_error()?, + .map_err(|err| WasmDppError::serialization(err.to_string()))?, }; let identifier = crate::utils::generate_document_id_v0( @@ -420,12 +426,9 @@ impl DocumentWasm { &owner_id.into(), js_document_type_name, &entropy, - ); + )?; - match identifier { - Ok(identifier) => Ok(identifier.to_vec()), - Err(err) => Err(err), - } + Ok(identifier.to_vec()) } } diff --git a/packages/wasm-dpp2/src/enums/batch/batch_enum.rs b/packages/wasm-dpp2/src/enums/batch/batch_enum.rs index 452f340d570..65d66ae3518 100644 --- a/packages/wasm-dpp2/src/enums/batch/batch_enum.rs +++ b/packages/wasm-dpp2/src/enums/batch/batch_enum.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use dpp::state_transition::batch_transition::batched_transition::document_transition_action_type::DocumentTransitionActionType; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -14,11 +15,13 @@ pub enum BatchTypeWasm { } impl TryFrom for BatchTypeWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), + None => Err(WasmDppError::invalid_argument( + "cannot read value from enum", + )), Some(enum_val) => match enum_val.to_lowercase().as_str() { "create" => Ok(BatchTypeWasm::Create), "replace" => Ok(BatchTypeWasm::Replace), @@ -27,14 +30,16 @@ impl TryFrom for BatchTypeWasm { "purchase" => Ok(BatchTypeWasm::Purchase), "updateprice" => Ok(BatchTypeWasm::UpdatePrice), "ignorewhilebumpingrevision" => Ok(BatchTypeWasm::IgnoreWhileBumpingRevision), - _ => Err(JsValue::from(format!( + _ => Err(WasmDppError::invalid_argument(format!( "unknown batch type value: {}", enum_val ))), }, }, false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), + None => Err(WasmDppError::invalid_argument( + "cannot read value from enum", + )), Some(enum_val) => match enum_val as u8 { 0 => Ok(BatchTypeWasm::Create), 1 => Ok(BatchTypeWasm::Replace), @@ -43,7 +48,7 @@ impl TryFrom for BatchTypeWasm { 4 => Ok(BatchTypeWasm::Purchase), 5 => Ok(BatchTypeWasm::UpdatePrice), 6 => Ok(BatchTypeWasm::IgnoreWhileBumpingRevision), - _ => Err(JsValue::from(format!( + _ => Err(WasmDppError::invalid_argument(format!( "unknown batch type value: {}", enum_val ))), diff --git a/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs b/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs index 7eb8b6faab3..e6186061db3 100644 --- a/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs +++ b/packages/wasm-dpp2/src/enums/batch/gas_fees_paid_by.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use dpp::tokens::gas_fees_paid_by::GasFeesPaidBy; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -12,34 +13,35 @@ pub enum GasFeesPaidByWasm { } impl TryFrom for GasFeesPaidByWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { - match value.is_string() { - true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val.to_lowercase().as_str() { - "documentowner" => Ok(GasFeesPaidByWasm::DocumentOwner), - "contractowner" => Ok(GasFeesPaidByWasm::ContractOwner), - "prefercontractowner" => Ok(GasFeesPaidByWasm::PreferContractOwner), - _ => Err(JsValue::from(format!( - "unknown batch type value: {}", - enum_val - ))), - }, - }, - false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val as u8 { - 0 => Ok(GasFeesPaidByWasm::DocumentOwner), - 1 => Ok(GasFeesPaidByWasm::ContractOwner), - 2 => Ok(GasFeesPaidByWasm::PreferContractOwner), - _ => Err(JsValue::from(format!( - "unknown batch type value: {}", - enum_val - ))), - }, - }, + if let Some(enum_val) = value.as_string() { + return match enum_val.to_lowercase().as_str() { + "documentowner" => Ok(GasFeesPaidByWasm::DocumentOwner), + "contractowner" => Ok(GasFeesPaidByWasm::ContractOwner), + "prefercontractowner" => Ok(GasFeesPaidByWasm::PreferContractOwner), + _ => Err(WasmDppError::invalid_argument(format!( + "unknown batch type value: {}", + enum_val + ))), + }; } + + if let Some(enum_val) = value.as_f64() { + return match enum_val as u8 { + 0 => Ok(GasFeesPaidByWasm::DocumentOwner), + 1 => Ok(GasFeesPaidByWasm::ContractOwner), + 2 => Ok(GasFeesPaidByWasm::PreferContractOwner), + _ => Err(WasmDppError::invalid_argument(format!( + "unknown batch type value: {}", + enum_val + ))), + }; + } + + Err(WasmDppError::invalid_argument( + "cannot read value from gas fees enum", + )) } } diff --git a/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs b/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs index f86900c9bf1..eab6da424ef 100644 --- a/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs +++ b/packages/wasm-dpp2/src/enums/contested/vote_state_result_type.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -12,26 +13,30 @@ pub enum VoteStateResultTypeWasm { } impl TryFrom for VoteStateResultTypeWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), + None => Err(WasmDppError::invalid_argument( + "cannot read value from enum", + )), Some(enum_val) => match enum_val.to_lowercase().as_str() { "documents" => Ok(VoteStateResultTypeWasm::Documents), "votetally" => Ok(VoteStateResultTypeWasm::VoteTally), "documentsandvotetally" => Ok(VoteStateResultTypeWasm::DocumentsAndVoteTally), - _ => Err(JsValue::from("unknown result type")), + _ => Err(WasmDppError::invalid_argument("unknown result type")), }, }, false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), + None => Err(WasmDppError::invalid_argument( + "cannot read value from enum", + )), Some(enum_val) => match enum_val as u8 { 0 => Ok(VoteStateResultTypeWasm::Documents), 1 => Ok(VoteStateResultTypeWasm::VoteTally), 2 => Ok(VoteStateResultTypeWasm::DocumentsAndVoteTally), - _ => Err(JsValue::from("unknown action type")), + _ => Err(WasmDppError::invalid_argument("unknown action type")), }, }, } diff --git a/packages/wasm-dpp2/src/enums/keys/key_type.rs b/packages/wasm-dpp2/src/enums/keys/key_type.rs index 9b774a605b0..3e82da3aa86 100644 --- a/packages/wasm-dpp2/src/enums/keys/key_type.rs +++ b/packages/wasm-dpp2/src/enums/keys/key_type.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use dpp::identity::KeyType; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -13,29 +14,36 @@ pub enum KeyTypeWasm { } impl TryFrom for KeyTypeWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), + None => Err(WasmDppError::invalid_argument( + "cannot read value from enum", + )), Some(enum_val) => match enum_val.to_lowercase().as_str() { "ecdsa_secp256k1" => Ok(KeyTypeWasm::ECDSA_SECP256K1), "bls12_381" => Ok(KeyTypeWasm::BLS12_381), "ecdsa_hash160" => Ok(KeyTypeWasm::ECDSA_HASH160), "bip13_script_hash" => Ok(KeyTypeWasm::BIP13_SCRIPT_HASH), "eddsa_25519_hash160" => Ok(KeyTypeWasm::EDDSA_25519_HASH160), - _ => Err(JsValue::from(format!("unsupported key type {}", enum_val))), + _ => Err(WasmDppError::invalid_argument(format!( + "unsupported key type {}", + enum_val + ))), }, }, false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), + None => Err(WasmDppError::invalid_argument( + "cannot read value from enum", + )), Some(enum_val) => match enum_val as u8 { 0 => Ok(KeyTypeWasm::ECDSA_SECP256K1), 1 => Ok(KeyTypeWasm::BLS12_381), 2 => Ok(KeyTypeWasm::ECDSA_HASH160), 3 => Ok(KeyTypeWasm::BIP13_SCRIPT_HASH), 4 => Ok(KeyTypeWasm::EDDSA_25519_HASH160), - _ => Err(JsValue::from(format!( + _ => Err(WasmDppError::invalid_argument(format!( "unsupported key type ({})", enum_val ))), diff --git a/packages/wasm-dpp2/src/enums/keys/purpose.rs b/packages/wasm-dpp2/src/enums/keys/purpose.rs index 4e9aca6c324..bdf1c2a0b22 100644 --- a/packages/wasm-dpp2/src/enums/keys/purpose.rs +++ b/packages/wasm-dpp2/src/enums/keys/purpose.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use dpp::identity::Purpose; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -14,42 +15,43 @@ pub enum PurposeWasm { } impl TryFrom for PurposeWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { - match value.is_string() { - true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val.to_lowercase().as_str() { - "authentication" => Ok(PurposeWasm::AUTHENTICATION), - "encryption" => Ok(PurposeWasm::ENCRYPTION), - "decryption" => Ok(PurposeWasm::DECRYPTION), - "transfer" => Ok(PurposeWasm::TRANSFER), - "system" => Ok(PurposeWasm::SYSTEM), - "voting" => Ok(PurposeWasm::VOTING), - "owner" => Ok(PurposeWasm::OWNER), - _ => Err(JsValue::from(format!( - "unsupported purpose value ({})", - enum_val - ))), - }, - }, - false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val as u8 { - 0 => Ok(PurposeWasm::AUTHENTICATION), - 1 => Ok(PurposeWasm::ENCRYPTION), - 2 => Ok(PurposeWasm::DECRYPTION), - 3 => Ok(PurposeWasm::TRANSFER), - 4 => Ok(PurposeWasm::SYSTEM), - 5 => Ok(PurposeWasm::VOTING), - 6 => Ok(PurposeWasm::OWNER), - _ => Err(JsValue::from(format!( - "unsupported purpose value ({})", - enum_val - ))), - }, - }, + if let Some(enum_val) = value.as_string() { + return match enum_val.to_lowercase().as_str() { + "authentication" => Ok(PurposeWasm::AUTHENTICATION), + "encryption" => Ok(PurposeWasm::ENCRYPTION), + "decryption" => Ok(PurposeWasm::DECRYPTION), + "transfer" => Ok(PurposeWasm::TRANSFER), + "system" => Ok(PurposeWasm::SYSTEM), + "voting" => Ok(PurposeWasm::VOTING), + "owner" => Ok(PurposeWasm::OWNER), + _ => Err(WasmDppError::invalid_argument(format!( + "unsupported purpose value ({})", + enum_val + ))), + }; } + + if let Some(enum_val) = value.as_f64() { + return match enum_val as u8 { + 0 => Ok(PurposeWasm::AUTHENTICATION), + 1 => Ok(PurposeWasm::ENCRYPTION), + 2 => Ok(PurposeWasm::DECRYPTION), + 3 => Ok(PurposeWasm::TRANSFER), + 4 => Ok(PurposeWasm::SYSTEM), + 5 => Ok(PurposeWasm::VOTING), + 6 => Ok(PurposeWasm::OWNER), + _ => Err(WasmDppError::invalid_argument(format!( + "unsupported purpose value ({})", + enum_val + ))), + }; + } + + Err(WasmDppError::invalid_argument( + "cannot read value from purpose enum", + )) } } diff --git a/packages/wasm-dpp2/src/enums/keys/security_level.rs b/packages/wasm-dpp2/src/enums/keys/security_level.rs index d3133e824eb..9bc1c534724 100644 --- a/packages/wasm-dpp2/src/enums/keys/security_level.rs +++ b/packages/wasm-dpp2/src/enums/keys/security_level.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use dpp::identity::SecurityLevel; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -11,36 +12,37 @@ pub enum SecurityLevelWasm { } impl TryFrom for SecurityLevelWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { - match value.is_string() { - true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val.to_lowercase().as_str() { - "master" => Ok(SecurityLevelWasm::MASTER), - "critical" => Ok(SecurityLevelWasm::CRITICAL), - "high" => Ok(SecurityLevelWasm::HIGH), - "medium" => Ok(SecurityLevelWasm::MEDIUM), - _ => Err(JsValue::from(format!( - "unsupported security level value ({})", - enum_val - ))), - }, - }, - false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val as u8 { - 0 => Ok(SecurityLevelWasm::MASTER), - 1 => Ok(SecurityLevelWasm::CRITICAL), - 2 => Ok(SecurityLevelWasm::HIGH), - 3 => Ok(SecurityLevelWasm::MEDIUM), - _ => Err(JsValue::from(format!( - "unsupported security level value ({})", - enum_val - ))), - }, - }, + if let Some(enum_val) = value.as_string() { + return match enum_val.to_lowercase().as_str() { + "master" => Ok(SecurityLevelWasm::MASTER), + "critical" => Ok(SecurityLevelWasm::CRITICAL), + "high" => Ok(SecurityLevelWasm::HIGH), + "medium" => Ok(SecurityLevelWasm::MEDIUM), + _ => Err(WasmDppError::invalid_argument(format!( + "unsupported security level value ({})", + enum_val + ))), + }; } + + if let Some(enum_val) = value.as_f64() { + return match enum_val as u8 { + 0 => Ok(SecurityLevelWasm::MASTER), + 1 => Ok(SecurityLevelWasm::CRITICAL), + 2 => Ok(SecurityLevelWasm::HIGH), + 3 => Ok(SecurityLevelWasm::MEDIUM), + _ => Err(WasmDppError::invalid_argument(format!( + "unsupported security level value ({})", + enum_val + ))), + }; + } + + Err(WasmDppError::invalid_argument( + "cannot read value from security level enum", + )) } } diff --git a/packages/wasm-dpp2/src/enums/lock_types/mod.rs b/packages/wasm-dpp2/src/enums/lock_types/mod.rs index 64439d8f0a9..dacb3f8ebea 100644 --- a/packages/wasm-dpp2/src/enums/lock_types/mod.rs +++ b/packages/wasm-dpp2/src/enums/lock_types/mod.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::{JsError, JsValue}; @@ -17,24 +18,34 @@ impl From for String { } impl TryFrom for AssetLockProofTypeWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), + None => Err(WasmDppError::invalid_argument( + "cannot read value from enum", + )), Some(enum_val) => match enum_val.to_lowercase().as_str() { "instant" => Ok(AssetLockProofTypeWasm::Instant), "chain" => Ok(AssetLockProofTypeWasm::Chain), - _ => Err(JsValue::from(format!("unsupported lock type {}", enum_val))), + _ => Err(WasmDppError::invalid_argument(format!( + "unsupported lock type {}", + enum_val + ))), }, }, false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), + None => Err(WasmDppError::invalid_argument( + "cannot read value from enum", + )), Some(enum_val) => match enum_val as u8 { 0 => Ok(AssetLockProofTypeWasm::Instant), 1 => Ok(AssetLockProofTypeWasm::Chain), - _ => Err(JsValue::from(format!("unsupported lock type {}", enum_val))), + _ => Err(WasmDppError::invalid_argument(format!( + "unsupported lock type {}", + enum_val + ))), }, }, } diff --git a/packages/wasm-dpp2/src/enums/network/mod.rs b/packages/wasm-dpp2/src/enums/network/mod.rs index 8e09b7a5bac..91a51f238f2 100644 --- a/packages/wasm-dpp2/src/enums/network/mod.rs +++ b/packages/wasm-dpp2/src/enums/network/mod.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use dpp::dashcore::Network; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -11,36 +12,37 @@ pub enum NetworkWasm { } impl TryFrom for NetworkWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { - match value.is_string() { - true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val.to_lowercase().as_str() { - "mainnet" => Ok(NetworkWasm::Mainnet), - "testnet" => Ok(NetworkWasm::Testnet), - "devnet" => Ok(NetworkWasm::Devnet), - "regtest" => Ok(NetworkWasm::Regtest), - _ => Err(JsValue::from(format!( - "unsupported network name ({})", - enum_val - ))), - }, - }, - false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val as u8 { - 0 => Ok(NetworkWasm::Mainnet), - 1 => Ok(NetworkWasm::Testnet), - 2 => Ok(NetworkWasm::Devnet), - 3 => Ok(NetworkWasm::Regtest), - _ => Err(JsValue::from(format!( - "unsupported network name ({})", - enum_val - ))), - }, - }, + if let Some(enum_val) = value.as_string() { + return match enum_val.to_lowercase().as_str() { + "mainnet" => Ok(NetworkWasm::Mainnet), + "testnet" => Ok(NetworkWasm::Testnet), + "devnet" => Ok(NetworkWasm::Devnet), + "regtest" => Ok(NetworkWasm::Regtest), + _ => Err(WasmDppError::invalid_argument(format!( + "unsupported network name ({})", + enum_val + ))), + }; } + + if let Some(enum_val) = value.as_f64() { + return match enum_val as u8 { + 0 => Ok(NetworkWasm::Mainnet), + 1 => Ok(NetworkWasm::Testnet), + 2 => Ok(NetworkWasm::Devnet), + 3 => Ok(NetworkWasm::Regtest), + _ => Err(WasmDppError::invalid_argument(format!( + "unsupported network name ({})", + enum_val + ))), + }; + } + + Err(WasmDppError::invalid_argument( + "cannot read value from network enum", + )) } } diff --git a/packages/wasm-dpp2/src/enums/platform/mod.rs b/packages/wasm-dpp2/src/enums/platform/mod.rs index 05609e78c9f..63b1f69c8d7 100644 --- a/packages/wasm-dpp2/src/enums/platform/mod.rs +++ b/packages/wasm-dpp2/src/enums/platform/mod.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use dpp::version::PlatformVersion; use dpp::version::v1::PLATFORM_V1; use dpp::version::v2::PLATFORM_V2; @@ -28,11 +29,13 @@ pub enum PlatformVersionWasm { } impl TryFrom for PlatformVersionWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), + None => Err(WasmDppError::invalid_argument( + "cannot read value from enum", + )), Some(enum_val) => match enum_val.to_lowercase().as_str() { "platform_v1" => Ok(PlatformVersionWasm::PLATFORM_V1), "platform_v2" => Ok(PlatformVersionWasm::PLATFORM_V2), @@ -43,14 +46,16 @@ impl TryFrom for PlatformVersionWasm { "platform_v7" => Ok(PlatformVersionWasm::PLATFORM_V7), "platform_v8" => Ok(PlatformVersionWasm::PLATFORM_V8), "platform_v9" => Ok(PlatformVersionWasm::PLATFORM_V9), - _ => Err(JsValue::from(format!( + _ => Err(WasmDppError::invalid_argument(format!( "unknown platform version value: {}", enum_val ))), }, }, false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), + None => Err(WasmDppError::invalid_argument( + "cannot read value from enum", + )), Some(enum_val) => match enum_val as u8 { 1 => Ok(PlatformVersionWasm::PLATFORM_V1), 2 => Ok(PlatformVersionWasm::PLATFORM_V2), @@ -61,7 +66,7 @@ impl TryFrom for PlatformVersionWasm { 7 => Ok(PlatformVersionWasm::PLATFORM_V7), 8 => Ok(PlatformVersionWasm::PLATFORM_V8), 9 => Ok(PlatformVersionWasm::PLATFORM_V9), - _ => Err(JsValue::from(format!( + _ => Err(WasmDppError::invalid_argument(format!( "unknown platform version value: {}", enum_val ))), diff --git a/packages/wasm-dpp2/src/enums/token/action_goal.rs b/packages/wasm-dpp2/src/enums/token/action_goal.rs index a34ae8d5325..ec7623bbe76 100644 --- a/packages/wasm-dpp2/src/enums/token/action_goal.rs +++ b/packages/wasm-dpp2/src/enums/token/action_goal.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use dpp::group::action_taker::ActionGoal; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -30,27 +31,28 @@ impl From for ActionGoalWasm { } impl TryFrom for ActionGoalWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { - match value.is_string() { - true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val.to_lowercase().as_str() { - "actioncompletion" => Ok(ActionGoalWasm::ActionCompletion), - "actionparticipation" => Ok(ActionGoalWasm::ActionParticipation), - _ => Err(JsValue::from("unknown action type")), - }, - }, - false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val as u8 { - 0 => Ok(ActionGoalWasm::ActionCompletion), - 1 => Ok(ActionGoalWasm::ActionParticipation), - _ => Err(JsValue::from("unknown action type")), - }, - }, + if let Some(enum_val) = value.as_string() { + return match enum_val.to_lowercase().as_str() { + "actioncompletion" => Ok(ActionGoalWasm::ActionCompletion), + "actionparticipation" => Ok(ActionGoalWasm::ActionParticipation), + _ => Err(WasmDppError::invalid_argument("unknown action type")), + }; } + + if let Some(enum_val) = value.as_f64() { + return match enum_val as u8 { + 0 => Ok(ActionGoalWasm::ActionCompletion), + 1 => Ok(ActionGoalWasm::ActionParticipation), + _ => Err(WasmDppError::invalid_argument("unknown action type")), + }; + } + + Err(WasmDppError::invalid_argument( + "cannot read value from action goal enum", + )) } } diff --git a/packages/wasm-dpp2/src/enums/token/distribution_type.rs b/packages/wasm-dpp2/src/enums/token/distribution_type.rs index 6905d315b94..dab69e8d00e 100644 --- a/packages/wasm-dpp2/src/enums/token/distribution_type.rs +++ b/packages/wasm-dpp2/src/enums/token/distribution_type.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use dpp::data_contract::associated_token::token_distribution_key::TokenDistributionType; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -30,27 +31,28 @@ impl From for TokenDistributionTypeWasm { } impl TryFrom for TokenDistributionTypeWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { - match value.is_string() { - true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val.to_lowercase().as_str() { - "preprogrammed" => Ok(TokenDistributionTypeWasm::PreProgrammed), - "perpetual" => Ok(TokenDistributionTypeWasm::Perpetual), - _ => Err(JsValue::from("unknown distribution type")), - }, - }, - false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val as u8 { - 0 => Ok(TokenDistributionTypeWasm::PreProgrammed), - 1 => Ok(TokenDistributionTypeWasm::Perpetual), - _ => Err(JsValue::from("unknown distribution type")), - }, - }, + if let Some(enum_val) = value.as_string() { + return match enum_val.to_lowercase().as_str() { + "preprogrammed" => Ok(TokenDistributionTypeWasm::PreProgrammed), + "perpetual" => Ok(TokenDistributionTypeWasm::Perpetual), + _ => Err(WasmDppError::invalid_argument("unknown distribution type")), + }; } + + if let Some(enum_val) = value.as_f64() { + return match enum_val as u8 { + 0 => Ok(TokenDistributionTypeWasm::PreProgrammed), + 1 => Ok(TokenDistributionTypeWasm::Perpetual), + _ => Err(WasmDppError::invalid_argument("unknown distribution type")), + }; + } + + Err(WasmDppError::invalid_argument( + "cannot read value from distribution type enum", + )) } } diff --git a/packages/wasm-dpp2/src/enums/token/emergency_action.rs b/packages/wasm-dpp2/src/enums/token/emergency_action.rs index eb75962a439..0781f7d6111 100644 --- a/packages/wasm-dpp2/src/enums/token/emergency_action.rs +++ b/packages/wasm-dpp2/src/enums/token/emergency_action.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use dpp::tokens::emergency_action::TokenEmergencyAction; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -30,27 +31,32 @@ impl From for TokenEmergencyActionWasm { } impl TryFrom for TokenEmergencyActionWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { - match value.is_string() { - true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val.to_lowercase().as_str() { - "pause" => Ok(TokenEmergencyActionWasm::Pause), - "resume" => Ok(TokenEmergencyActionWasm::Resume), - _ => Err(JsValue::from("unknown distribution type")), - }, - }, - false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), - Some(enum_val) => match enum_val as u8 { - 0 => Ok(TokenEmergencyActionWasm::Pause), - 1 => Ok(TokenEmergencyActionWasm::Resume), - _ => Err(JsValue::from("unknown distribution type")), - }, - }, + if let Some(enum_val) = value.as_string() { + return match enum_val.to_lowercase().as_str() { + "pause" => Ok(TokenEmergencyActionWasm::Pause), + "resume" => Ok(TokenEmergencyActionWasm::Resume), + _ => Err(WasmDppError::invalid_argument( + "unknown emergency action type", + )), + }; } + + if let Some(enum_val) = value.as_f64() { + return match enum_val as u8 { + 0 => Ok(TokenEmergencyActionWasm::Pause), + 1 => Ok(TokenEmergencyActionWasm::Resume), + _ => Err(WasmDppError::invalid_argument( + "unknown emergency action type", + )), + }; + } + + Err(WasmDppError::invalid_argument( + "cannot read value from emergency action enum", + )) } } diff --git a/packages/wasm-dpp2/src/enums/withdrawal/mod.rs b/packages/wasm-dpp2/src/enums/withdrawal/mod.rs index 1b2f9096446..4d24ca10d33 100644 --- a/packages/wasm-dpp2/src/enums/withdrawal/mod.rs +++ b/packages/wasm-dpp2/src/enums/withdrawal/mod.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppError; use dpp::withdrawal::Pooling; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -30,28 +31,32 @@ impl From for PoolingWasm { } impl TryFrom for PoolingWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { match value.is_string() { true => match value.as_string() { - None => Err(JsValue::from("cannot read value from enum")), + None => Err(WasmDppError::invalid_argument( + "cannot read value from enum", + )), Some(enum_val) => match enum_val.to_lowercase().as_str() { "never" => Ok(PoolingWasm::Never), "ifavailable" => Ok(PoolingWasm::IfAvailable), "standard" => Ok(PoolingWasm::Standard), - _ => Err(JsValue::from(format!( + _ => Err(WasmDppError::invalid_argument(format!( "unsupported pooling value ({})", enum_val ))), }, }, false => match value.as_f64() { - None => Err(JsValue::from("cannot read value from enum")), + None => Err(WasmDppError::invalid_argument( + "cannot read value from enum", + )), Some(enum_val) => match enum_val as u8 { 0 => Ok(PoolingWasm::Never), 1 => Ok(PoolingWasm::IfAvailable), 2 => Ok(PoolingWasm::Standard), - _ => Err(JsValue::from(format!( + _ => Err(WasmDppError::invalid_argument(format!( "unsupported pooling value ({})", enum_val ))), diff --git a/packages/wasm-dpp2/src/error.rs b/packages/wasm-dpp2/src/error.rs index f8bdc59dcd9..15fe34f05d8 100644 --- a/packages/wasm-dpp2/src/error.rs +++ b/packages/wasm-dpp2/src/error.rs @@ -65,22 +65,8 @@ impl WasmDppError { pub(crate) fn generic(message: impl Into) -> Self { Self::new(WasmDppErrorKind::Generic, message, None) } -} - -impl From for WasmDppError { - fn from(error: ProtocolError) -> Self { - Self::protocol(error.to_string()) - } -} - -impl From for WasmDppError { - fn from(error: AnyhowError) -> Self { - Self::generic(error.to_string()) - } -} -impl From for WasmDppError { - fn from(value: JsValue) -> Self { + pub(crate) fn from_js_value(value: JsValue) -> Self { if value.is_null() || value.is_undefined() { return WasmDppError::invalid_argument("JavaScript error: value is null or undefined"); } @@ -102,6 +88,18 @@ impl From for WasmDppError { } } +impl From for WasmDppError { + fn from(error: ProtocolError) -> Self { + Self::protocol(error.to_string()) + } +} + +impl From for WasmDppError { + fn from(error: AnyhowError) -> Self { + Self::generic(error.to_string()) + } +} + #[wasm_bindgen] impl WasmDppError { /// Returns the structured error kind. diff --git a/packages/wasm-dpp2/src/group_state_transition_info/mod.rs b/packages/wasm-dpp2/src/group_state_transition_info/mod.rs index 52c899611cb..71c8043c8f2 100644 --- a/packages/wasm-dpp2/src/group_state_transition_info/mod.rs +++ b/packages/wasm-dpp2/src/group_state_transition_info/mod.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use dpp::group::GroupStateTransitionInfo; use wasm_bindgen::JsValue; @@ -36,7 +37,7 @@ impl GroupStateTransitionInfoWasm { group_contract_position: u16, action_id: &JsValue, action_is_proposer: bool, - ) -> Result { + ) -> WasmDppResult { Ok(GroupStateTransitionInfoWasm(GroupStateTransitionInfo { group_contract_position, action_id: IdentifierWasm::try_from(action_id)?.into(), @@ -50,7 +51,7 @@ impl GroupStateTransitionInfoWasm { } #[wasm_bindgen(setter = "actionId")] - pub fn set_action_id(&mut self, action_id: &JsValue) -> Result<(), JsValue> { + pub fn set_action_id(&mut self, action_id: &JsValue) -> WasmDppResult<()> { self.0.action_id = IdentifierWasm::try_from(action_id)?.into(); Ok(()) } diff --git a/packages/wasm-dpp2/src/identifier/mod.rs b/packages/wasm-dpp2/src/identifier/mod.rs index 54002170f67..2b827f08db7 100644 --- a/packages/wasm-dpp2/src/identifier/mod.rs +++ b/packages/wasm-dpp2/src/identifier/mod.rs @@ -1,3 +1,4 @@ +use crate::error::{WasmDppError, WasmDppResult}; use crate::utils::{IntoWasm, get_class_type, identifier_from_js_value}; use dpp::platform_value::string_encoding::Encoding::{Base58, Base64, Hex}; use dpp::platform_value::string_encoding::decode; @@ -33,29 +34,31 @@ impl From<&IdentifierWasm> for Identifier { } impl TryFrom<&[u8]> for IdentifierWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: &[u8]) -> Result { if value.len() != 32 { - return Err(JsValue::from("Identifier must be 32 bytes length")); + return Err(WasmDppError::invalid_argument( + "Identifier must be 32 bytes length", + )); } let norm_slice: [u8; 32] = value .try_into() - .map_err(|_| JsValue::from("Cannot parse identifier"))?; + .map_err(|_| WasmDppError::invalid_argument("Cannot parse identifier"))?; Ok(IdentifierWasm(Identifier::new(norm_slice))) } } impl TryFrom for IdentifierWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { match value.is_object() { true => match get_class_type(&value) { Ok(class_type) => match class_type.as_str() { "Identifier" => Ok(value.to_wasm::("Identifier")?.clone()), "" => Ok(identifier_from_js_value(&value)?.into()), - _ => Err(Self::Error::from_str(&format!( + _ => Err(WasmDppError::invalid_argument(format!( "Invalid type of data for identifier (passed {})", class_type ))), @@ -69,7 +72,7 @@ impl TryFrom for IdentifierWasm { match id_str.len() == 64 { true => { let bytes = decode(value.as_string().unwrap().as_str(), Hex) - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; Ok(IdentifierWasm::try_from(bytes.as_slice())?) } @@ -82,7 +85,7 @@ impl TryFrom for IdentifierWasm { } impl TryFrom<&JsValue> for IdentifierWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: &JsValue) -> Result { IdentifierWasm::try_from(value.clone()) } @@ -101,7 +104,7 @@ impl IdentifierWasm { } #[wasm_bindgen(constructor)] - pub fn new(js_identifier: &JsValue) -> Result { + pub fn new(js_identifier: &JsValue) -> WasmDppResult { IdentifierWasm::try_from(js_identifier) } @@ -126,33 +129,33 @@ impl IdentifierWasm { } #[wasm_bindgen(js_name = "fromBase58")] - pub fn from_base58(base58: String) -> Result { + pub fn from_base58(base58: String) -> WasmDppResult { let identitfier = Identifier::from_string(base58.as_str(), Base58) - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; Ok(IdentifierWasm(identitfier)) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { + pub fn from_base64(base64: String) -> WasmDppResult { let identitfier = Identifier::from_string(base64.as_str(), Base64) - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; Ok(IdentifierWasm(identitfier)) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { + pub fn from_hex(hex: String) -> WasmDppResult { let identitfier = Identifier::from_string(hex.as_str(), Hex) - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; Ok(IdentifierWasm(identitfier)) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { - let identifier = - Identifier::from_vec(bytes).map_err(|err| JsValue::from(err.to_string()))?; + pub fn from_bytes(bytes: Vec) -> WasmDppResult { + let identifier = Identifier::from_vec(bytes) + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; Ok(IdentifierWasm(identifier)) } diff --git a/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs b/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs index 85b552ca542..2751a018041 100644 --- a/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs +++ b/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs @@ -2,7 +2,7 @@ use crate::contract_bounds::ContractBoundsWasm; use crate::enums::keys::key_type::KeyTypeWasm; use crate::enums::keys::purpose::PurposeWasm; use crate::enums::keys::security_level::SecurityLevelWasm; -use crate::error::WasmDppResult; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identity_public_key::IdentityPublicKeyWasm; use crate::utils::IntoWasm; use dpp::identity::contract_bounds::ContractBounds; @@ -35,7 +35,7 @@ impl From for IdentityPublicKeyInCreation { } impl TryFrom for IdentityPublicKeyInCreationWasm { - type Error = JsValue; + type Error = WasmDppError; fn try_from(value: JsValue) -> Result { let value = value.to_wasm::("IdentityPublicKeyInCreation")?; @@ -246,7 +246,7 @@ impl IdentityPublicKeyInCreationWasm { let add_public_keys: Vec = js_add_public_keys .iter() .map(IdentityPublicKeyInCreationWasm::try_from) - .collect::, JsValue>>()?; + .collect::, WasmDppError>>()?; Ok(add_public_keys) } diff --git a/packages/wasm-dpp2/src/masternode_vote/mod.rs b/packages/wasm-dpp2/src/masternode_vote/mod.rs index 38164b1027a..570c06f23d8 100644 --- a/packages/wasm-dpp2/src/masternode_vote/mod.rs +++ b/packages/wasm-dpp2/src/masternode_vote/mod.rs @@ -3,10 +3,10 @@ pub mod vote; pub mod vote_poll; use crate::asset_lock_proof::AssetLockProofWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::masternode_vote::vote::VoteWasm; use crate::state_transition::StateTransitionWasm; -use crate::utils::WithJsError; use dpp::identity::KeyID; use dpp::identity::state_transition::OptionallyAssetLockProved; use dpp::platform_value::BinaryData; @@ -18,8 +18,8 @@ use dpp::state_transition::masternode_vote_transition::MasternodeVoteTransition; use dpp::state_transition::masternode_vote_transition::accessors::MasternodeVoteTransitionAccessorsV0; use dpp::state_transition::masternode_vote_transition::v0::MasternodeVoteTransitionV0; use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[wasm_bindgen(js_name = "MasternodeVoteTransition")] #[derive(Clone)] @@ -57,7 +57,7 @@ impl MasternodeVoteTransitionWasm { nonce: IdentityNonce, signature_public_key: Option, signature: Option>, - ) -> Result { + ) -> WasmDppResult { let pro_tx_hash = IdentifierWasm::try_from(js_pro_tx_hash)?; let voter_identity_id = IdentifierWasm::try_from(js_voter_identity_id)?; @@ -104,7 +104,7 @@ impl MasternodeVoteTransitionWasm { } #[wasm_bindgen(setter = proTxHash)] - pub fn set_pro_tx_hash(&mut self, js_pro_tx_hash: &JsValue) -> Result<(), JsValue> { + pub fn set_pro_tx_hash(&mut self, js_pro_tx_hash: &JsValue) -> WasmDppResult<()> { let pro_tx_hash = IdentifierWasm::try_from(js_pro_tx_hash)?; self.0.set_pro_tx_hash(pro_tx_hash.into()); @@ -113,7 +113,7 @@ impl MasternodeVoteTransitionWasm { } #[wasm_bindgen(setter = voterIdentityId)] - pub fn set_voter_identity_id(&mut self, js_voter_identity_id: &JsValue) -> Result<(), JsValue> { + pub fn set_voter_identity_id(&mut self, js_voter_identity_id: &JsValue) -> WasmDppResult<()> { let voter_identity_id = IdentifierWasm::try_from(js_voter_identity_id)?; self.0.set_voter_identity_id(voter_identity_id.into()); @@ -148,28 +148,29 @@ impl MasternodeVoteTransitionWasm { } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> Result { - let bytes = decode(hex.as_str(), Hex).map_err(JsError::from)?; + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = decode(hex.as_str(), Hex) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; MasternodeVoteTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> Result { - let bytes = decode(base64.as_str(), Base64).map_err(JsError::from)?; + pub fn from_base64(base64: String) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; MasternodeVoteTransitionWasm::from_bytes(bytes) } #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> Result, JsValue> { - self.0.serialize_to_bytes().with_js_error() + pub fn to_bytes(&self) -> WasmDppResult> { + self.0.serialize_to_bytes().map_err(Into::into) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { - let rs_transition = - MasternodeVoteTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?; + pub fn from_bytes(bytes: Vec) -> WasmDppResult { + let rs_transition = MasternodeVoteTransition::deserialize_from_bytes(bytes.as_slice())?; Ok(MasternodeVoteTransitionWasm(rs_transition)) } @@ -180,8 +181,8 @@ impl MasternodeVoteTransitionWasm { } #[wasm_bindgen(js_name = "getSignableBytes")] - pub fn get_signable_bytes(&self) -> Result, JsValue> { - self.0.signable_bytes().with_js_error() + pub fn get_signable_bytes(&self) -> WasmDppResult> { + self.0.signable_bytes().map_err(Into::into) } #[wasm_bindgen(getter = "assetLock")] @@ -214,13 +215,13 @@ impl MasternodeVoteTransitionWasm { #[wasm_bindgen(js_name = "fromStateTransition")] pub fn from_state_transition( st: &StateTransitionWasm, - ) -> Result { + ) -> WasmDppResult { let rs_st: StateTransition = st.clone().into(); match rs_st { StateTransition::MasternodeVote(st) => Ok(MasternodeVoteTransitionWasm(st)), - _ => Err(JsValue::from_str( - &"Invalid state document_transition type)", + _ => Err(WasmDppError::invalid_argument( + "Invalid state document_transition type", )), } } diff --git a/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs b/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs index 8f900569800..95680b39275 100644 --- a/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs +++ b/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use dpp::voting::vote_choices::resource_vote_choice::ResourceVoteChoice; use wasm_bindgen::JsValue; @@ -32,7 +33,7 @@ impl ResourceVoteChoiceWasm { } #[wasm_bindgen(js_name = "TowardsIdentity")] - pub fn towards_identity(js_id: &JsValue) -> Result { + pub fn towards_identity(js_id: &JsValue) -> WasmDppResult { let id = IdentifierWasm::try_from(js_id)?; Ok(ResourceVoteChoiceWasm(ResourceVoteChoice::TowardsIdentity( diff --git a/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs b/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs index 1911a4b18c3..458a870a665 100644 --- a/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs +++ b/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs @@ -1,3 +1,4 @@ +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::utils::ToSerdeJSONExt; use dpp::bincode; @@ -41,14 +42,13 @@ impl VotePollWasm { document_type_name: String, index_name: String, js_index_values: JsValue, - ) -> Result { + ) -> WasmDppResult { let contract_id = IdentifierWasm::try_from(js_contract_id)?; - let index_values = js_index_values - .with_serde_to_platform_value()? - .as_array() - .unwrap() - .clone(); + let index_values_value = js_index_values.with_serde_to_platform_value()?; + let index_values = index_values_value + .into_array() + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; Ok(VotePollWasm(VotePoll::ContestedDocumentResourceVotePoll( ContestedDocumentResourceVotePoll { @@ -87,19 +87,19 @@ impl VotePollWasm { } #[wasm_bindgen(getter = "indexValues")] - pub fn index_values(&self) -> Result { + pub fn index_values(&self) -> WasmDppResult { let config = bincode::config::standard() .with_big_endian() .with_no_limit(); match self.0.clone() { VotePoll::ContestedDocumentResourceVotePoll(poll) => { - let encoded: Result>, JsValue> = poll + let encoded: WasmDppResult>> = poll .index_values .iter() .map(|value| { bincode::encode_to_vec(value, config) - .map_err(|err| JsValue::from(err.to_string())) + .map_err(|err| WasmDppError::serialization(err.to_string())) }) .collect(); @@ -115,7 +115,7 @@ impl VotePollWasm { } #[wasm_bindgen(setter = "contractId")] - pub fn set_contract_id(&mut self, js_contract_id: &JsValue) -> Result<(), JsValue> { + pub fn set_contract_id(&mut self, js_contract_id: &JsValue) -> WasmDppResult<()> { let contract_id = IdentifierWasm::try_from(js_contract_id)?; self.0 = match self.0.clone() { @@ -152,12 +152,11 @@ impl VotePollWasm { } #[wasm_bindgen(setter = "indexValues")] - pub fn set_index_values(&mut self, js_index_values: JsValue) -> Result<(), JsValue> { + pub fn set_index_values(&mut self, js_index_values: JsValue) -> WasmDppResult<()> { let index_values = js_index_values .with_serde_to_platform_value()? - .as_array() - .unwrap() - .clone(); + .into_array() + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; self.0 = match self.0.clone() { VotePoll::ContestedDocumentResourceVotePoll(mut poll) => { diff --git a/packages/wasm-dpp2/src/partial_identity/mod.rs b/packages/wasm-dpp2/src/partial_identity/mod.rs index 586c30a8e34..9b21e544824 100644 --- a/packages/wasm-dpp2/src/partial_identity/mod.rs +++ b/packages/wasm-dpp2/src/partial_identity/mod.rs @@ -1,3 +1,4 @@ +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::identity_public_key::IdentityPublicKeyWasm; use crate::utils::IntoWasm; @@ -28,7 +29,7 @@ impl PartialIdentityWasm { balance: Option, revision: Option, js_not_found_public_keys: Option, - ) -> Result { + ) -> WasmDppResult { let id = IdentifierWasm::try_from(js_id)?; let loaded_public_keys = js_value_to_loaded_public_keys(js_loaded_public_keys)?; @@ -50,7 +51,7 @@ impl PartialIdentityWasm { } #[wasm_bindgen(getter = "loadedPublicKeys")] - pub fn loaded_public_keys(&self) -> Result { + pub fn loaded_public_keys(&self) -> WasmDppResult { let obj = Object::new(); for (k, v) in self.0.loaded_public_keys.clone() { @@ -58,7 +59,8 @@ impl PartialIdentityWasm { &obj, &k.to_string().into(), &IdentityPublicKeyWasm::from(v).into(), - )?; + ) + .map_err(|err| WasmDppError::from_js_value(err))?; } Ok(obj) @@ -86,7 +88,7 @@ impl PartialIdentityWasm { } #[wasm_bindgen(setter = "id")] - pub fn set_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> { + pub fn set_id(&mut self, js_id: &JsValue) -> WasmDppResult<()> { let identifier: IdentifierWasm = IdentifierWasm::try_from(js_id)?; self.0.id = identifier.into(); @@ -95,7 +97,7 @@ impl PartialIdentityWasm { } #[wasm_bindgen(setter = "loadedPublicKeys")] - pub fn set_loaded_public_keys(&mut self, loaded_public_keys: &JsValue) -> Result<(), JsValue> { + pub fn set_loaded_public_keys(&mut self, loaded_public_keys: &JsValue) -> WasmDppResult<()> { self.0.loaded_public_keys = js_value_to_loaded_public_keys(loaded_public_keys)?; Ok(()) @@ -112,7 +114,7 @@ impl PartialIdentityWasm { } #[wasm_bindgen(setter = "notFoundPublicKeys")] - pub fn set_not_found_public_keys(&mut self, keys: Option) -> Result<(), JsValue> { + pub fn set_not_found_public_keys(&mut self, keys: Option) -> WasmDppResult<()> { self.0.not_found_public_keys = option_array_to_not_found(keys)?; Ok(()) @@ -121,9 +123,11 @@ impl PartialIdentityWasm { pub fn js_value_to_loaded_public_keys( js_loaded_public_keys: &JsValue, -) -> Result, JsValue> { +) -> WasmDppResult> { match js_loaded_public_keys.is_object() { - false => Err(JsValue::from("loaded_public_keys must be an object")), + false => Err(WasmDppError::invalid_argument( + "loaded_public_keys must be an object", + )), true => { let mut map = BTreeMap::new(); @@ -131,16 +135,21 @@ pub fn js_value_to_loaded_public_keys( let keys = Object::keys(&pub_keys_object); for key in keys.iter() { - if key.as_f64().unwrap() > u32::MAX as f64 { - return Err(JsValue::from_str(&format!( + let key_val = key.as_f64().ok_or_else(|| { + WasmDppError::invalid_argument("Key identifier must be numeric") + })?; + + if key_val > u32::MAX as f64 { + return Err(WasmDppError::invalid_argument(format!( "Key id '{:?}' exceeds the maximum limit for u32.", key.as_string() ))); } - let key_id = KeyID::from(key.as_f64().unwrap() as u32); + let key_id = KeyID::from(key_val as u32); - let js_key = Reflect::get(&pub_keys_object, &key)?; + let js_key = + Reflect::get(&pub_keys_object, &key).map_err(WasmDppError::from_js_value)?; let key = js_key .to_wasm::("IdentityPublicKey")? @@ -156,29 +165,30 @@ pub fn js_value_to_loaded_public_keys( pub fn option_array_to_not_found( js_not_found_public_keys: Option, -) -> Result, JsValue> { +) -> WasmDppResult> { match js_not_found_public_keys { - None => Ok::, JsValue>(BTreeSet::new()), + None => Ok(BTreeSet::new()), Some(keys) => { let keys_iter: Vec = keys .to_vec() .iter() .map(|key| { - if key.as_f64().unwrap() > u32::MAX as f64 { - return Err(JsValue::from_str(&format!( + let key_val = key.as_f64().ok_or_else(|| { + WasmDppError::invalid_argument("Key id must be a numeric value") + })?; + + if key_val > u32::MAX as f64 { + return Err(WasmDppError::invalid_argument(format!( "Key id '{:?}' exceeds the maximum limit for u32.", key.as_string() - )))?; + ))); } - Ok(key.as_f64().unwrap() as KeyID) + Ok(key_val as KeyID) }) - .collect::, JsValue>>()?; + .collect::>>()?; - Ok(BTreeSet::from_iter(keys_iter.iter().map(|id| id.clone())) - .iter() - .map(|key| key.clone()) - .collect()) + Ok(keys_iter.into_iter().collect()) } } } diff --git a/packages/wasm-dpp2/src/private_key/mod.rs b/packages/wasm-dpp2/src/private_key/mod.rs index ee5f7ab3f70..1df7a1d7d37 100644 --- a/packages/wasm-dpp2/src/private_key/mod.rs +++ b/packages/wasm-dpp2/src/private_key/mod.rs @@ -1,4 +1,5 @@ use crate::enums::network::NetworkWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::public_key::PublicKeyWasm; use dpp::dashcore::PrivateKey; use dpp::dashcore::hashes::hex::FromHex; @@ -23,33 +24,32 @@ impl PrivateKeyWasm { } #[wasm_bindgen(js_name = "fromWIF")] - pub fn from_wif(wif: &str) -> Result { - let pk = PrivateKey::from_wif(wif).map_err(|err| JsValue::from_str(&*err.to_string())); + pub fn from_wif(wif: &str) -> WasmDppResult { + let pk = PrivateKey::from_wif(wif) + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; - match pk { - Ok(pk) => Ok(PrivateKeyWasm(pk)), - Err(err) => Err(err), - } + Ok(PrivateKeyWasm(pk)) } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec, js_network: JsValue) -> Result { + pub fn from_bytes(bytes: Vec, js_network: JsValue) -> WasmDppResult { let network = NetworkWasm::try_from(js_network)?; let pk = PrivateKey::from_slice(bytes.as_slice(), network.into()) - .map_err(|err| JsValue::from_str(&*err.to_string()))?; + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; Ok(PrivateKeyWasm(pk)) } #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex_key: &str, js_network: JsValue) -> Result { + pub fn from_hex(hex_key: &str, js_network: JsValue) -> WasmDppResult { let network = NetworkWasm::try_from(js_network)?; - let bytes = Vec::from_hex(hex_key).map_err(|err| JsValue::from(err.to_string()))?; + let bytes = Vec::from_hex(hex_key) + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; let pk = PrivateKey::from_slice(bytes.as_slice(), network.into()) - .map_err(|err| JsValue::from_str(&*err.to_string()))?; + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; Ok(PrivateKeyWasm(pk)) } diff --git a/packages/wasm-dpp2/src/public_key/mod.rs b/packages/wasm-dpp2/src/public_key/mod.rs index ea0f77fec50..588e52895b9 100644 --- a/packages/wasm-dpp2/src/public_key/mod.rs +++ b/packages/wasm-dpp2/src/public_key/mod.rs @@ -1,6 +1,7 @@ +use crate::error::{WasmDppError, WasmDppResult}; use dpp::dashcore::key::constants; use dpp::dashcore::{PublicKey, secp256k1}; -use wasm_bindgen::JsValue; +use std::convert::TryInto; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "PublicKey")] @@ -31,30 +32,43 @@ impl PublicKeyWasm { } #[wasm_bindgen(constructor)] - pub fn new(compressed: bool, public_key_bytes: Vec) -> Result { + pub fn new(compressed: bool, public_key_bytes: Vec) -> WasmDppResult { let inner = match compressed { true => { if public_key_bytes.len() != constants::PUBLIC_KEY_SIZE { - return Err(JsValue::from(String::from(format!( + return Err(WasmDppError::invalid_argument(format!( "compressed public key size must be equal to {}", constants::PUBLIC_KEY_SIZE - )))); + ))); } - secp256k1::PublicKey::from_byte_array_compressed(&public_key_bytes.try_into()?) + let bytes: [u8; constants::PUBLIC_KEY_SIZE] = + public_key_bytes.try_into().map_err(|_| { + WasmDppError::invalid_argument( + "compressed public key must contain 33 bytes", + ) + })?; + secp256k1::PublicKey::from_byte_array_compressed(&bytes) } false => { if public_key_bytes.len() != constants::UNCOMPRESSED_PUBLIC_KEY_SIZE { - return Err(JsValue::from(String::from(format!( + return Err(WasmDppError::invalid_argument(format!( "uncompressed public key size must be equal to {}", constants::UNCOMPRESSED_PUBLIC_KEY_SIZE - )))); + ))); } - secp256k1::PublicKey::from_byte_array_uncompressed(&public_key_bytes.try_into()?) + let bytes: [u8; constants::UNCOMPRESSED_PUBLIC_KEY_SIZE] = + public_key_bytes.try_into().map_err(|_| { + WasmDppError::invalid_argument( + "uncompressed public key must contain 65 bytes", + ) + })?; + + secp256k1::PublicKey::from_byte_array_uncompressed(&bytes) } } - .map_err(|err| JsValue::from(err.to_string()))?; + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; Ok(PublicKeyWasm(PublicKey { compressed, inner })) } @@ -78,27 +92,32 @@ impl PublicKeyWasm { } #[wasm_bindgen(setter = "inner")] - pub fn set_inner(&mut self, inner: Vec) -> Result<(), JsValue> { - match inner.len() == constants::PUBLIC_KEY_SIZE { - true => { - self.0.compressed = true; - self.0.inner = secp256k1::PublicKey::from_byte_array_compressed(&inner.try_into()?) - .map_err(|err| JsValue::from(err.to_string()))? + pub fn set_inner(&mut self, inner: Vec) -> WasmDppResult<()> { + if inner.len() == constants::PUBLIC_KEY_SIZE { + let bytes: [u8; constants::PUBLIC_KEY_SIZE] = inner.try_into().map_err(|_| { + WasmDppError::invalid_argument("compressed public key must contain 33 bytes") + })?; + + self.0.compressed = true; + self.0.inner = secp256k1::PublicKey::from_byte_array_compressed(&bytes) + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; + } else { + if inner.len() != constants::UNCOMPRESSED_PUBLIC_KEY_SIZE { + return Err(WasmDppError::invalid_argument(format!( + "uncompressed public key size must be equal to {}", + constants::UNCOMPRESSED_PUBLIC_KEY_SIZE + ))); } - false => { - if inner.len() != constants::UNCOMPRESSED_PUBLIC_KEY_SIZE { - return Err(JsValue::from(String::from(format!( - "uncompressed public key size must be equal to {}", - constants::UNCOMPRESSED_PUBLIC_KEY_SIZE - )))); - } - self.0.compressed = false; - self.0.inner = - secp256k1::PublicKey::from_byte_array_uncompressed(&inner.try_into()?) - .map_err(|err| JsValue::from(err.to_string()))? - } - }; + let bytes: [u8; constants::UNCOMPRESSED_PUBLIC_KEY_SIZE] = + inner.try_into().map_err(|_| { + WasmDppError::invalid_argument("uncompressed public key must contain 65 bytes") + })?; + + self.0.compressed = false; + self.0.inner = secp256k1::PublicKey::from_byte_array_uncompressed(&bytes) + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; + } Ok(()) } @@ -114,10 +133,10 @@ impl PublicKeyWasm { } #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> Result { + pub fn from_bytes(bytes: Vec) -> WasmDppResult { Ok(PublicKeyWasm( PublicKey::from_slice(bytes.as_slice()) - .map_err(|err| JsValue::from(err.to_string()))?, + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?, )) } } diff --git a/packages/wasm-dpp2/src/token_configuration/action_taker.rs b/packages/wasm-dpp2/src/token_configuration/action_taker.rs index e31594d4da6..f7dbae79b17 100644 --- a/packages/wasm-dpp2/src/token_configuration/action_taker.rs +++ b/packages/wasm-dpp2/src/token_configuration/action_taker.rs @@ -1,3 +1,4 @@ +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use dpp::group::action_taker::ActionTaker; use dpp::prelude::Identifier; @@ -35,26 +36,36 @@ impl ActionTakerWasm { } #[wasm_bindgen(constructor)] - pub fn new(value: &JsValue) -> Result { - let identifier = IdentifierWasm::try_from(value); + pub fn new(value: &JsValue) -> WasmDppResult { + if let Ok(identifier) = IdentifierWasm::try_from(value.clone()) { + return Ok(ActionTakerWasm(ActionTaker::SingleIdentity( + identifier.into(), + ))); + } + + if !value.is_object() && !value.is_array() { + return Err(WasmDppError::invalid_argument( + "ActionTaker value must be an Identifier or array of Identifiers", + )); + } - if identifier.is_err() { - let set_of_identifiers: Vec = Array::from(value) - .to_vec() - .iter() - .map(|js_value: &JsValue| { - Identifier::from(IdentifierWasm::try_from(js_value).expect("err")) - }) - .collect(); + let array = Array::from(value); + let mut identifiers = BTreeSet::new(); - Ok(ActionTakerWasm(ActionTaker::SpecifiedIdentities( - BTreeSet::from_iter(set_of_identifiers), - ))) - } else { - Ok(ActionTakerWasm(ActionTaker::SingleIdentity( - identifier?.into(), - ))) + for js_value in array.to_vec() { + let identifier = IdentifierWasm::try_from(js_value)?; + identifiers.insert(Identifier::from(identifier)); } + + if identifiers.is_empty() { + return Err(WasmDppError::invalid_argument( + "ActionTaker array must contain at least one identifier", + )); + } + + Ok(ActionTakerWasm(ActionTaker::SpecifiedIdentities( + identifiers, + ))) } #[wasm_bindgen(js_name = "getType")] @@ -72,18 +83,17 @@ impl ActionTakerWasm { JsValue::from(IdentifierWasm::from(value.clone())) } ActionTaker::SpecifiedIdentities(value) => { - let identifiers: Vec = value - .iter() - .map(|identifier: &Identifier| IdentifierWasm::from(identifier.clone())) - .collect(); - - JsValue::from(identifiers) + let array = Array::new(); + for identifier in value.iter() { + array.push(&IdentifierWasm::from(identifier.clone()).into()); + } + array.into() } } } #[wasm_bindgen(setter = "value")] - pub fn set_value(&mut self, value: &JsValue) -> Result<(), JsValue> { + pub fn set_value(&mut self, value: &JsValue) -> WasmDppResult<()> { self.0 = Self::new(value)?.0; Ok(()) diff --git a/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs b/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs index 559837f46d0..fd4edf7189c 100644 --- a/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs +++ b/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use dpp::data_contract::change_control_rules::authorized_action_takers::AuthorizedActionTakers; use dpp::platform_value::string_encoding::Encoding::Base58; @@ -44,7 +45,7 @@ impl AuthorizedActionTakersWasm { } #[wasm_bindgen(js_name = "Identity")] - pub fn identity(js_identity_id: &JsValue) -> Result { + pub fn identity(js_identity_id: &JsValue) -> WasmDppResult { let identity_id = IdentifierWasm::try_from(js_identity_id)?; Ok(AuthorizedActionTakersWasm( diff --git a/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs b/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs index 0e4156c12a9..e0841f46b79 100644 --- a/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs +++ b/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs @@ -1,4 +1,5 @@ use crate::enums::token::action_goal::ActionGoalWasm; +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::token_configuration::action_taker::ActionTakerWasm; use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; @@ -10,8 +11,8 @@ use dpp::data_contract::change_control_rules::v0::ChangeControlRulesV0; use dpp::data_contract::group::Group; use js_sys::{Object, Reflect}; use std::collections::BTreeMap; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "ChangeControlRules")] @@ -164,7 +165,7 @@ impl ChangeControlRulesWasm { js_groups: &JsValue, action_taker: &ActionTakerWasm, js_goal: &JsValue, - ) -> Result { + ) -> WasmDppResult { let contract_owner_id = IdentifierWasm::try_from(js_contract_owner_id)?; let goal = ActionGoalWasm::try_from(js_goal.clone())?; @@ -174,14 +175,19 @@ impl ChangeControlRulesWasm { let mut groups: BTreeMap = BTreeMap::new(); for key in groups_keys.iter() { - let contract_position = match key.as_string() { - None => Err(JsValue::from("Cannot read timestamp in distribution rules")), - Some(contract_position) => Ok(contract_position - .parse::() - .map_err(JsError::from)?), - }?; - - let group_value = Reflect::get(js_groups, &key)?; + let key_str = key.as_string().ok_or_else(|| { + WasmDppError::invalid_argument("Cannot read group contract position") + })?; + + let contract_position = key_str.parse::().map_err(|err| { + WasmDppError::invalid_argument(format!( + "Invalid group contract position '{}': {}", + key_str, err + )) + })?; + + let group_value = + Reflect::get(js_groups, &key).map_err(|err| WasmDppError::from_js_value(err))?; let group = group_value.to_wasm::("Group")?.clone(); diff --git a/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs b/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs index 099bbe8163f..e86e080158c 100644 --- a/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs +++ b/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs @@ -1,12 +1,11 @@ +use crate::error::{WasmDppError, WasmDppResult}; use crate::token_configuration::localization::TokenConfigurationLocalizationWasm; -use crate::utils::ToSerdeJSONExt; use dpp::data_contract::associated_token::token_configuration_convention::TokenConfigurationConvention; use dpp::data_contract::associated_token::token_configuration_convention::accessors::v0::{ TokenConfigurationConventionV0Getters, TokenConfigurationConventionV0Setters, }; use dpp::data_contract::associated_token::token_configuration_convention::v0::TokenConfigurationConventionV0; use dpp::data_contract::associated_token::token_configuration_localization::TokenConfigurationLocalization; -use dpp::data_contract::associated_token::token_configuration_localization::v0::TokenConfigurationLocalizationV0; use js_sys::{Object, Reflect}; use std::collections::BTreeMap; use wasm_bindgen::JsValue; @@ -44,7 +43,7 @@ impl TokenConfigurationConventionWasm { pub fn new( js_localizations: &JsValue, decimals: u8, - ) -> Result { + ) -> WasmDppResult { let localizations: BTreeMap = js_value_to_localizations(js_localizations)?; @@ -62,7 +61,7 @@ impl TokenConfigurationConventionWasm { } #[wasm_bindgen(getter = "localizations")] - pub fn localizations(&self) -> Result { + pub fn localizations(&self) -> WasmDppResult { let object = Object::new(); for (key, value) in &self.0.localizations().clone() { @@ -70,7 +69,8 @@ impl TokenConfigurationConventionWasm { &object, &JsValue::from(key.clone()), &TokenConfigurationLocalizationWasm::from(value.clone()).into(), - )?; + ) + .map_err(|err| WasmDppError::from_js_value(err))?; } Ok(object.into()) @@ -82,46 +82,32 @@ impl TokenConfigurationConventionWasm { } #[wasm_bindgen(setter = "localizations")] - pub fn set_localizations(&mut self, js_localizations: &JsValue) -> Result<(), JsValue> { + pub fn set_localizations(&mut self, js_localizations: &JsValue) -> WasmDppResult<()> { let localizations: BTreeMap = js_value_to_localizations(js_localizations)?; - Ok(self.0.set_localizations(localizations)) + self.0.set_localizations(localizations); + Ok(()) } } fn js_value_to_localizations( js_localizations: &JsValue, -) -> Result, JsValue> { - let localizations: BTreeMap = js_localizations - .clone() - .with_serde_to_platform_value_map()? - .iter() - .map(|(key, value)| { - ( - key.clone(), - TokenConfigurationLocalization::V0(TokenConfigurationLocalizationV0 { - should_capitalize: value - .get_value("shouldCapitalize") - .unwrap() - .as_bool() - .unwrap(), - singular_form: value - .get_value("singularForm") - .unwrap() - .as_str() - .unwrap() - .to_string(), - plural_form: value - .get_value("pluralForm") - .unwrap() - .as_str() - .unwrap() - .to_string(), - }), - ) - }) - .collect(); +) -> WasmDppResult> { + let js_object = Object::from(js_localizations.clone()); + let mut localizations = BTreeMap::new(); + + for key in Object::keys(&js_object) { + let key_str = key + .as_string() + .ok_or_else(|| WasmDppError::invalid_argument("Localization key must be string"))?; + + let js_value = Reflect::get(&js_object, &key).map_err(WasmDppError::from_js_value)?; + + let localization = TokenConfigurationLocalizationWasm::from_js_value(&js_value)?; + + localizations.insert(key_str, localization); + } Ok(localizations) } diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_function.rs b/packages/wasm-dpp2/src/token_configuration/distribution_function.rs index 94f81485c11..851795d6512 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_function.rs +++ b/packages/wasm-dpp2/src/token_configuration/distribution_function.rs @@ -1,3 +1,4 @@ +use crate::error::{WasmDppError, WasmDppResult}; use crate::token_configuration::distribution_structs::{ DistributionExponentialWasm, DistributionFixedAmountWasm, DistributionInvertedLogarithmicWasm, DistributionLinearWasm, DistributionLogarithmicWasm, DistributionPolynomialWasm, @@ -8,7 +9,6 @@ use dpp::balances::credits::TokenAmount; use dpp::data_contract::associated_token::token_perpetual_distribution::distribution_function::DistributionFunction; use js_sys::{BigInt, Object, Reflect}; use std::collections::BTreeMap; -use std::str::FromStr; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -74,18 +74,27 @@ impl DistributionFunctionWasm { } #[wasm_bindgen(js_name = "Stepwise")] - pub fn stepwise(js_steps_with_amount: JsValue) -> Result { + pub fn stepwise(js_steps_with_amount: JsValue) -> WasmDppResult { let obj = Object::from(js_steps_with_amount); let mut steps_with_amount: BTreeMap = BTreeMap::new(); for key in Object::keys(&obj) { - steps_with_amount.insert( - try_to_u64(BigInt::from_str(key.as_string().unwrap().as_str())?.into()) - .map_err(|err| JsValue::from(err.to_string()))?, - try_to_u64(Reflect::get(&obj, &key)?) - .map_err(|err| JsValue::from(err.to_string()))?, - ); + let key_str = key + .as_string() + .ok_or_else(|| WasmDppError::invalid_argument("step key must be string"))?; + + let step = key_str.parse::().map_err(|err| { + WasmDppError::invalid_argument(format!("Invalid step key '{}': {}", key_str, err)) + })?; + + let amount_js = + Reflect::get(&obj, &key).map_err(|err| WasmDppError::from_js_value(err))?; + + let amount = try_to_u64(amount_js) + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; + + steps_with_amount.insert(step, amount); } Ok(DistributionFunctionWasm(DistributionFunction::Stepwise( @@ -230,7 +239,7 @@ impl DistributionFunctionWasm { } #[wasm_bindgen(js_name = "getFunctionValue")] - pub fn get_function_values(&self) -> Result { + pub fn get_function_values(&self) -> WasmDppResult { match self.0.clone() { DistributionFunction::FixedAmount { amount } => { Ok(JsValue::from(DistributionFixedAmountWasm { amount })) @@ -265,7 +274,8 @@ impl DistributionFunctionWasm { &object, &key.to_string().into(), &BigInt::from(value).into(), - )?; + ) + .map_err(WasmDppError::from_js_value)?; } Ok(object.into()) diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs b/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs index c29c087948b..44c0febef10 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs +++ b/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use dpp::data_contract::associated_token::token_perpetual_distribution::distribution_recipient::TokenDistributionRecipient; use wasm_bindgen::JsValue; @@ -37,7 +38,7 @@ impl TokenDistributionRecipientWasm { } #[wasm_bindgen(js_name = "Identity")] - pub fn identity(js_identity_id: &JsValue) -> Result { + pub fn identity(js_identity_id: &JsValue) -> WasmDppResult { let identity_id = IdentifierWasm::try_from(js_identity_id)?; Ok(TokenDistributionRecipientWasm( diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs b/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs index 407ebc6a7f3..3f2040468ef 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs +++ b/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use crate::token_configuration::change_control_rules::ChangeControlRulesWasm; use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWasm; @@ -52,7 +53,7 @@ impl TokenDistributionRulesWasm { minting_allow_choosing_destination: bool, minting_allow_choosing_destination_rules: &ChangeControlRulesWasm, change_direct_purchase_pricing_rules: &ChangeControlRulesWasm, - ) -> Result { + ) -> WasmDppResult { let perpetual_distribution = match js_perpetual_distribution.is_undefined() { true => None, false => Some(TokenPerpetualDistribution::from( @@ -160,7 +161,7 @@ impl TokenDistributionRulesWasm { pub fn set_perpetual_distribution( &mut self, js_perpetual_distribution: &JsValue, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let perpetual_distribution = match js_perpetual_distribution.is_undefined() { true => None, false => Some(TokenPerpetualDistribution::from( @@ -170,7 +171,8 @@ impl TokenDistributionRulesWasm { )), }; - Ok(self.0.set_perpetual_distribution(perpetual_distribution)) + self.0.set_perpetual_distribution(perpetual_distribution); + Ok(()) } #[wasm_bindgen(setter = "perpetualDistributionRules")] @@ -183,7 +185,7 @@ impl TokenDistributionRulesWasm { pub fn set_pre_programmed_distribution( &mut self, js_distribution: &JsValue, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let distribution = match js_distribution.is_undefined() { true => None, false => Some(TokenPreProgrammedDistribution::from( @@ -195,14 +197,15 @@ impl TokenDistributionRulesWasm { )), }; - Ok(self.0.set_pre_programmed_distribution(distribution)) + self.0.set_pre_programmed_distribution(distribution); + Ok(()) } #[wasm_bindgen(setter = "newTokenDestinationIdentity")] pub fn set_new_tokens_destination_identity( &mut self, js_identifier: &JsValue, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let identifier = match js_identifier.is_undefined() { true => None, false => Some(Identifier::from( @@ -210,7 +213,9 @@ impl TokenDistributionRulesWasm { )), }; - Ok(self.0.set_new_tokens_destination_identity(identifier)) + self.0.set_new_tokens_destination_identity(identifier); + + Ok(()) } #[wasm_bindgen(setter = "newTokenDestinationIdentityRules")] diff --git a/packages/wasm-dpp2/src/token_configuration/group.rs b/packages/wasm-dpp2/src/token_configuration/group.rs index bf90e5d2103..a472b3681b4 100644 --- a/packages/wasm-dpp2/src/token_configuration/group.rs +++ b/packages/wasm-dpp2/src/token_configuration/group.rs @@ -1,3 +1,4 @@ +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use dpp::data_contract::group::accessors::v0::{GroupV0Getters, GroupV0Setters}; use dpp::data_contract::group::v0::GroupV0; @@ -28,7 +29,7 @@ impl From for Group { pub fn js_members_to_map( js_members: &JsValue, -) -> Result, JsValue> { +) -> WasmDppResult> { let members_object = Object::from(js_members.clone()); let members_keys = Object::keys(&members_object); @@ -37,15 +38,18 @@ pub fn js_members_to_map( for key in members_keys.iter() { let key_str = key .as_string() - .ok_or_else(|| JsValue::from_str("cannot convert key to string"))?; + .ok_or_else(|| WasmDppError::invalid_argument("cannot convert key to string"))?; - let id_wasm = IdentifierWasm::try_from(key.clone()) - .map_err(|_| JsValue::from_str(&format!("Invalid identifier: {}", key_str)))?; + let id_wasm = IdentifierWasm::try_from(key.clone()).map_err(|_| { + WasmDppError::invalid_argument(format!("Invalid identifier: {}", key_str)) + })?; - let val = Reflect::get(js_members, &key) - .map_err(|_| JsValue::from_str(&format!("Invalid value at key '{}'", key_str)))?; + let val = Reflect::get(js_members, &key).map_err(|_| { + WasmDppError::invalid_argument(format!("Invalid value at key '{}'", key_str)) + })?; - let power: GroupMemberPower = serde_wasm_bindgen::from_value(val)?; + let power: GroupMemberPower = serde_wasm_bindgen::from_value(val) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; members.insert(Identifier::from(id_wasm), power); } @@ -69,7 +73,7 @@ impl GroupWasm { pub fn new( js_members: &JsValue, required_power: GroupRequiredPower, - ) -> Result { + ) -> WasmDppResult { let members = js_members_to_map(js_members)?; Ok(GroupWasm(Group::V0(GroupV0 { @@ -79,7 +83,7 @@ impl GroupWasm { } #[wasm_bindgen(getter = "members")] - pub fn get_members(&self) -> Result { + pub fn get_members(&self) -> WasmDppResult { let members = self.0.members(); let js_members = Object::new(); @@ -89,7 +93,8 @@ impl GroupWasm { &js_members, &JsValue::from(k.to_string(Encoding::Base58)), &JsValue::from(v.clone()), - )?; + ) + .map_err(|err| WasmDppError::from_js_value(err))?; } Ok(js_members.into()) @@ -101,7 +106,7 @@ impl GroupWasm { } #[wasm_bindgen(setter = "members")] - pub fn set_members(&mut self, js_members: &JsValue) -> Result<(), JsValue> { + pub fn set_members(&mut self, js_members: &JsValue) -> WasmDppResult<()> { let members = js_members_to_map(js_members)?; self.0.set_members(members); @@ -119,7 +124,7 @@ impl GroupWasm { &mut self, js_member: &JsValue, member_required_power: GroupRequiredPower, - ) -> Result<(), JsValue> { + ) -> WasmDppResult<()> { let member = IdentifierWasm::try_from(js_member.clone())?; self.0 diff --git a/packages/wasm-dpp2/src/token_configuration/localization.rs b/packages/wasm-dpp2/src/token_configuration/localization.rs index 0db9cad8e4f..ce940cac972 100644 --- a/packages/wasm-dpp2/src/token_configuration/localization.rs +++ b/packages/wasm-dpp2/src/token_configuration/localization.rs @@ -1,3 +1,5 @@ +use crate::error::{WasmDppError, WasmDppResult}; +use crate::utils::IntoWasm; use dpp::data_contract::associated_token::token_configuration_localization::TokenConfigurationLocalization; use dpp::data_contract::associated_token::token_configuration_localization::accessors::v0::{ TokenConfigurationLocalizationV0Getters, TokenConfigurationLocalizationV0Setters, @@ -81,25 +83,91 @@ impl TokenConfigurationLocalizationWasm { } #[wasm_bindgen(js_name = "toJSON")] - pub fn to_json(&self) -> Result { + pub fn to_json(&self) -> WasmDppResult { let object = Object::new(); Reflect::set( &object, &JsValue::from("shouldCapitalize"), &JsValue::from(self.0.should_capitalize()), - )?; + ) + .map_err(|err| WasmDppError::from_js_value(err))?; Reflect::set( &object, &JsValue::from("pluralForm"), &JsValue::from(self.0.plural_form()), - )?; + ) + .map_err(WasmDppError::from_js_value)?; Reflect::set( &object, &JsValue::from("singularForm"), &JsValue::from(self.0.singular_form()), - )?; + ) + .map_err(WasmDppError::from_js_value)?; Ok(object.into()) } } + +impl TokenConfigurationLocalizationWasm { + pub(crate) fn from_js_value( + js_value: &JsValue, + ) -> WasmDppResult { + match js_value + .to_wasm::("TokenConfigurationLocalization") + { + Ok(wasm_localization) => Ok(TokenConfigurationLocalization::from( + wasm_localization.clone(), + )), + Err(err) => { + let message = err.message(); + + if message.contains("constructor name mismatch") { + localization_from_plain_js_value(js_value) + } else { + Err(err) + } + } + } + } +} + +fn localization_from_plain_js_value( + js_value: &JsValue, +) -> WasmDppResult { + if !js_value.is_object() { + return Err(WasmDppError::invalid_argument( + "TokenConfigurationLocalization must be an object", + )); + } + + let should_capitalize_value = Reflect::get(js_value, &JsValue::from_str("shouldCapitalize")) + .map_err(WasmDppError::from_js_value)?; + let should_capitalize = should_capitalize_value.as_bool().ok_or_else(|| { + WasmDppError::invalid_argument( + "TokenConfigurationLocalization.shouldCapitalize must be a boolean", + ) + })?; + + let singular_form_value = Reflect::get(js_value, &JsValue::from_str("singularForm")) + .map_err(WasmDppError::from_js_value)?; + let singular_form = singular_form_value.as_string().ok_or_else(|| { + WasmDppError::invalid_argument( + "TokenConfigurationLocalization.singularForm must be a string", + ) + })?; + + let plural_form_value = Reflect::get(js_value, &JsValue::from_str("pluralForm")) + .map_err(WasmDppError::from_js_value)?; + let plural_form = plural_form_value.as_string().ok_or_else(|| { + WasmDppError::invalid_argument("TokenConfigurationLocalization.pluralForm must be a string") + })?; + + Ok(TokenConfigurationLocalization::V0( + TokenConfigurationLocalizationV0 { + should_capitalize, + singular_form, + plural_form, + }, + )) +} diff --git a/packages/wasm-dpp2/src/token_configuration/mod.rs b/packages/wasm-dpp2/src/token_configuration/mod.rs index 4113af0ee63..45d22ba3c66 100644 --- a/packages/wasm-dpp2/src/token_configuration/mod.rs +++ b/packages/wasm-dpp2/src/token_configuration/mod.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; use crate::token_configuration::change_control_rules::ChangeControlRulesWasm; @@ -321,7 +322,7 @@ impl TokenConfigurationWasm { pub fn calculate_token_id( js_contract_id: &JsValue, token_pos: TokenContractPosition, - ) -> Result { + ) -> WasmDppResult { let contract_id = IdentifierWasm::try_from(js_contract_id)?; Ok(IdentifierWasm::from(calculate_token_id( diff --git a/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs b/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs index 380fcbb275d..73f34d5724b 100644 --- a/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs +++ b/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs @@ -1,4 +1,6 @@ +use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; +use crate::utils::try_to_u64; use dpp::balances::credits::TokenAmount; use dpp::data_contract::associated_token::token_pre_programmed_distribution::TokenPreProgrammedDistribution; use dpp::data_contract::associated_token::token_pre_programmed_distribution::accessors::v0::TokenPreProgrammedDistributionV0Methods; @@ -6,8 +8,8 @@ use dpp::data_contract::associated_token::token_pre_programmed_distribution::v0: use dpp::prelude::{Identifier, TimestampMillis}; use js_sys::{BigInt, Object, Reflect}; use std::collections::BTreeMap; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsError, JsValue}; #[derive(Clone, PartialEq, Debug)] #[wasm_bindgen(js_name = "TokenPreProgrammedDistribution")] @@ -27,21 +29,27 @@ impl From for TokenPreProgrammedDistributionWasm pub fn js_distributions_to_distributions( js_distributions: &JsValue, -) -> Result>, JsValue> { +) -> WasmDppResult>> { let distributions_object = Object::from(js_distributions.clone()); let distributions_keys = Object::keys(&distributions_object); let mut distributions = BTreeMap::new(); for key in distributions_keys.iter() { - let timestamp = match key.as_string() { - None => Err(JsValue::from("Cannot read timestamp in distribution rules")), - Some(timestamp) => Ok(timestamp - .parse::() - .map_err(JsError::from)?), - }?; - - let identifiers_object = Object::from(Reflect::get(&distributions_object, &key)?.clone()); + let timestamp_str = key.as_string().ok_or_else(|| { + WasmDppError::invalid_argument("Cannot read timestamp in distribution rules") + })?; + + let timestamp = timestamp_str.parse::().map_err(|err| { + WasmDppError::invalid_argument(format!( + "Invalid timestamp '{}': {}", + timestamp_str, err + )) + })?; + + let identifiers_js = Reflect::get(&distributions_object, &key) + .map_err(|err| WasmDppError::from_js_value(err))?; + let identifiers_object = Object::from(identifiers_js); let identifiers_keys = Object::keys(&identifiers_object); let mut ids = BTreeMap::new(); @@ -49,13 +57,11 @@ pub fn js_distributions_to_distributions( for id_key in identifiers_keys.iter() { let identifier = Identifier::from(IdentifierWasm::try_from(id_key.clone())?); - let token_amount = BigInt::new(&Reflect::get(&identifiers_object, &id_key.clone())?)? - .to_string(10) - .map_err(|err| JsValue::from(format!("bigint to string: {}", err.to_string())))? - .as_string() - .ok_or_else(|| JsValue::from_str("Failed to convert BigInt to string"))? - .parse::() - .map_err(JsError::from)?; + let amount_js = + Reflect::get(&identifiers_object, &id_key).map_err(WasmDppError::from_js_value)?; + + let token_amount = try_to_u64(amount_js) + .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; ids.insert(identifier, token_amount); } @@ -79,7 +85,7 @@ impl TokenPreProgrammedDistributionWasm { } #[wasm_bindgen(constructor)] - pub fn new(js_distributions: &JsValue) -> Result { + pub fn new(js_distributions: &JsValue) -> WasmDppResult { let distributions = js_distributions_to_distributions(js_distributions)?; Ok(TokenPreProgrammedDistributionWasm( @@ -88,7 +94,7 @@ impl TokenPreProgrammedDistributionWasm { } #[wasm_bindgen(getter = "distributions")] - pub fn get_distributions(&self) -> Result { + pub fn get_distributions(&self) -> WasmDppResult { let obj = Object::new(); for (key, value) in self.0.distributions() { @@ -102,17 +108,19 @@ impl TokenPreProgrammedDistributionWasm { .get_base58() .into(), &BigInt::from(identifiers_value.clone()).into(), - )?; + ) + .map_err(WasmDppError::from_js_value)?; } - Reflect::set(&obj, &key.to_string().into(), &identifiers_obj.into())?; + Reflect::set(&obj, &key.to_string().into(), &identifiers_obj.into()) + .map_err(WasmDppError::from_js_value)?; } Ok(obj.into()) } #[wasm_bindgen(setter = "distributions")] - pub fn set_distributions(&mut self, js_distributions: &JsValue) -> Result<(), JsValue> { + pub fn set_distributions(&mut self, js_distributions: &JsValue) -> WasmDppResult<()> { let distributions = js_distributions_to_distributions(js_distributions)?; self.0.set_distributions(distributions); diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs b/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs index 5ab9299771e..b04f3d4d989 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs +++ b/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs @@ -1,3 +1,4 @@ +use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; @@ -11,7 +12,7 @@ impl TokenConfigurationChangeItemWasm { #[wasm_bindgen(js_name = "NewTokensDestinationIdentityItem")] pub fn new_tokens_destination_identity_item( js_identity_id: &JsValue, - ) -> Result { + ) -> WasmDppResult { let identity_id: Option = match js_identity_id.is_undefined() { true => None, false => Some(IdentifierWasm::try_from(js_identity_id)?.into()), diff --git a/packages/wasm-dpp2/src/utils/mod.rs b/packages/wasm-dpp2/src/utils/mod.rs index 23100fb7a74..14c33f6ff7f 100644 --- a/packages/wasm-dpp2/src/utils/mod.rs +++ b/packages/wasm-dpp2/src/utils/mod.rs @@ -1,6 +1,5 @@ use crate::error::{WasmDppError, WasmDppResult}; use anyhow::{Context, anyhow, bail}; -use dpp::ProtocolError; use dpp::identifier::Identifier; use dpp::platform_value::Value; use dpp::platform_value::string_encoding::Encoding::Base58; @@ -10,7 +9,7 @@ use serde_json::Value as JsonValue; use std::collections::BTreeMap; use std::convert::TryInto; use wasm_bindgen::JsValue; -use wasm_bindgen::{convert::RefFromWasmAbi, prelude::*}; +use wasm_bindgen::convert::RefFromWasmAbi; pub fn stringify_wasm(data: &JsValue) -> WasmDppResult { let replacer_func = Function::new_with_args( @@ -38,33 +37,32 @@ pub fn with_serde_to_platform_value_wasm(data: &JsValue) -> WasmDppResult } pub trait ToSerdeJSONExt { - fn with_serde_to_json_value(&self) -> Result; - fn with_serde_to_platform_value(&self) -> Result; + fn with_serde_to_json_value(&self) -> WasmDppResult; + fn with_serde_to_platform_value(&self) -> WasmDppResult; /// Converts the `JsValue` into `platform::Value`. It's an expensive conversion, /// as `JsValue` must be stringified first - fn with_serde_to_platform_value_map(&self) -> Result, JsValue>; + fn with_serde_to_platform_value_map(&self) -> WasmDppResult>; } impl ToSerdeJSONExt for JsValue { /// Converts the `JsValue` into `serde_json::Value`. It's an expensive conversion, /// as `JsValue` must be stringified first - fn with_serde_to_json_value(&self) -> Result { + fn with_serde_to_json_value(&self) -> WasmDppResult { with_serde_to_json_value(self.clone()) } /// Converts the `JsValue` into `platform::Value`. It's an expensive conversion, /// as `JsValue` must be stringified first - fn with_serde_to_platform_value(&self) -> Result { + fn with_serde_to_platform_value(&self) -> WasmDppResult { with_serde_to_platform_value(self) } /// Converts the `JsValue` into `platform::Value`. It's an expensive conversion, /// as `JsValue` must be stringified first - fn with_serde_to_platform_value_map(&self) -> Result, JsValue> { + fn with_serde_to_platform_value_map(&self) -> WasmDppResult> { self.with_serde_to_platform_value()? .into_btree_string_map() - .map_err(ProtocolError::ValueError) - .with_js_error() + .map_err(|err| WasmDppError::invalid_argument(err.to_string())) } } @@ -80,7 +78,7 @@ where #[allow(deprecated)] pub fn to_vec_of_serde_values( values: impl IntoIterator>, -) -> Result, JsValue> { +) -> WasmDppResult> { values .into_iter() .map(|v| v.as_ref().with_serde_to_json_value()) @@ -89,70 +87,45 @@ pub fn to_vec_of_serde_values( pub fn to_vec_of_platform_values( values: impl IntoIterator>, -) -> Result, JsValue> { +) -> WasmDppResult> { values .into_iter() .map(|v| v.as_ref().with_serde_to_platform_value()) .collect() } -pub fn with_serde_to_json_value(data: JsValue) -> Result { +pub fn with_serde_to_json_value(data: JsValue) -> WasmDppResult { let data = stringify(&data)?; let value: JsonValue = serde_json::from_str(&data) .with_context(|| format!("cant convert {data:#?} to serde json value")) - .map_err(|e| format!("{e:#}"))?; + .map_err(|e| WasmDppError::serialization(format!("{e:#}")))?; Ok(value) } -pub fn with_serde_to_platform_value(data: &JsValue) -> Result { +pub fn with_serde_to_platform_value(data: &JsValue) -> WasmDppResult { Ok(with_serde_to_json_value(data.clone())?.into()) } -pub fn stringify(data: &JsValue) -> Result { +pub fn stringify(data: &JsValue) -> WasmDppResult { let replacer_func = Function::new_with_args( "key, value", "return (value != undefined && value.type=='Buffer') ? value.data : value ", ); let data_string: String = - js_sys::JSON::stringify_with_replacer(data, &JsValue::from(replacer_func))?.into(); + js_sys::JSON::stringify_with_replacer(data, &JsValue::from(replacer_func)) + .map_err(|err| WasmDppError::from_js_value(err))? + .into(); Ok(data_string) } -pub trait WithJsError { - /// Converts the error into JsValue - fn with_js_error(self) -> Result; -} - -impl WithJsError for Result { - fn with_js_error(self) -> Result { - match self { - Ok(ok) => Ok(ok), - Err(error) => Err(format!("{error:#}").into()), - } - } -} - -impl WithJsError for Result { - fn with_js_error(self) -> Result { - match self { - Ok(ok) => Ok(ok), - Err(error) => Err(JsValue::from_str(&error.to_string())), - } - } -} - pub trait IntoWasm { - fn to_wasm>(&self, class_name: &str) - -> Result; + fn to_wasm>(&self, class_name: &str) -> WasmDppResult; } impl IntoWasm for JsValue { - fn to_wasm>( - &self, - class_name: &str, - ) -> Result { + fn to_wasm>(&self, class_name: &str) -> WasmDppResult { generic_of_js_val::(self, class_name) } } @@ -160,21 +133,22 @@ impl IntoWasm for JsValue { pub fn generic_of_js_val>( js_value: &JsValue, class_name: &str, -) -> Result { +) -> WasmDppResult { if !js_value.is_object() { - return Err(JsError::new( - format!("Value supplied as {} is not an object", class_name).as_str(), - ) - .into()); + return Err(WasmDppError::invalid_argument(format!( + "Value supplied as {} is not an object", + class_name + ))); } let ctor_name = get_class_type(js_value)?; if ctor_name == class_name { - let ptr = js_sys::Reflect::get(js_value, &JsValue::from_str("__wbg_ptr"))?; + let ptr = js_sys::Reflect::get(js_value, &JsValue::from_str("__wbg_ptr")) + .map_err(WasmDppError::from_js_value)?; let ptr_u32: u32 = ptr .as_f64() - .ok_or_else(|| JsValue::from(JsError::new("Invalid JS object pointer")))? + .ok_or_else(|| WasmDppError::invalid_argument("Invalid JS object pointer"))? as u32; let reference = unsafe { T::ref_from_abi(ptr_u32) }; Ok(reference) @@ -183,17 +157,15 @@ pub fn generic_of_js_val>( "JS object constructor name mismatch. Expected {}, provided {}.", class_name, ctor_name ); - Err(JsError::new(&error_string).into()) + Err(WasmDppError::invalid_argument(error_string)) } } -pub fn get_class_type(value: &JsValue) -> Result { - let class_type = js_sys::Reflect::get(&value, &JsValue::from_str("__type")); +pub fn get_class_type(value: &JsValue) -> WasmDppResult { + let class_type = js_sys::Reflect::get(&value, &JsValue::from_str("__type")) + .map_err(WasmDppError::from_js_value)?; - match class_type { - Ok(class_type) => Ok(class_type.as_string().unwrap_or("".to_string())), - Err(_) => Err(JsValue::from_str(&"")), - } + Ok(class_type.as_string().unwrap_or_default()) } pub fn try_to_u64(value: JsValue) -> Result { @@ -235,7 +207,7 @@ pub fn generate_document_id_v0( owner_id: &Identifier, document_type_name: &str, entropy: &[u8], -) -> Result { +) -> WasmDppResult { let mut buf: Vec = vec![]; buf.extend_from_slice(&contract_id.to_buffer()); @@ -243,32 +215,33 @@ pub fn generate_document_id_v0( buf.extend_from_slice(document_type_name.as_bytes()); buf.extend_from_slice(entropy); - Identifier::from_bytes(&hash_double_to_vec(&buf)).map_err(|e| JsValue::from(e.to_string())) + Identifier::from_bytes(&hash_double_to_vec(&buf)) + .map_err(|err| WasmDppError::invalid_argument(err.to_string())) } // Try to extract Identifier from **stringified** identifier_utils. // The `js_value` can be a stringified instance of: `Identifier`, `Buffer` or `Array` -pub fn identifier_from_js_value(js_value: &JsValue) -> Result { +pub fn identifier_from_js_value(js_value: &JsValue) -> WasmDppResult { if js_value.is_undefined() || js_value.is_null() { - wasm_bindgen::throw_val(JsValue::from_str( + return Err(WasmDppError::invalid_argument( "the identifier cannot be null or undefined", )); } match js_value.is_string() { true => Identifier::from_string(js_value.as_string().unwrap_or("".into()).as_str(), Base58) - .map_err(ProtocolError::ValueError) - .with_js_error(), + .map_err(|err| WasmDppError::invalid_argument(err.to_string())), false => match js_value.is_object() || js_value.is_array() { true => { let uint8_array = Uint8Array::from(js_value.clone()); let bytes = uint8_array.to_vec(); Identifier::from_bytes(&bytes) - .map_err(ProtocolError::ValueError) - .with_js_error() + .map_err(|err| WasmDppError::invalid_argument(err.to_string())) } - false => Err(JsValue::from_str("Invalid ID. Expected array or string")), + false => Err(WasmDppError::invalid_argument( + "Invalid ID. Expected array or string", + )), }, } } From 06c576ff0611430bf49bf8915ea682412dcd180d Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 7 Oct 2025 16:32:44 +0700 Subject: [PATCH 12/44] refactor: accomplish error refactoring --- .../src/batch/token_pricing_schedule/mod.rs | 10 +++- packages/wasm-dpp2/src/data_contract/mod.rs | 35 ++++++++++-- packages/wasm-dpp2/src/error.rs | 26 +-------- .../wasm-dpp2/src/partial_identity/mod.rs | 19 +++++-- .../change_control_rules.rs | 11 +++- .../configuration_convention.rs | 17 +++++- .../distribution_function.rs | 19 +++++-- .../src/token_configuration/group.rs | 10 +++- .../src/token_configuration/localization.rs | 54 +++++++++++++++--- .../pre_programmed_distribution.rs | 39 ++++++++++--- packages/wasm-dpp2/src/utils/mod.rs | 56 ++++++++++++++++--- 11 files changed, 227 insertions(+), 69 deletions(-) diff --git a/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs b/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs index a3f9051f3a5..239ac4b87ab 100644 --- a/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs +++ b/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs @@ -1,5 +1,5 @@ use crate::error::{WasmDppError, WasmDppResult}; -use crate::utils::ToSerdeJSONExt; +use crate::utils::{JsValueExt, ToSerdeJSONExt}; use dpp::balances::credits::TokenAmount; use dpp::fee::Credits; use dpp::tokens::token_pricing_schedule::TokenPricingSchedule; @@ -91,7 +91,13 @@ impl TokenPricingScheduleWasm { &JsValue::from(key.to_string()), &value.clone().into(), ) - .map_err(WasmDppError::from_js_value)?; + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to serialize price for amount '{}': {}", + key, message + )) + })?; } Ok(price_object.into()) diff --git a/packages/wasm-dpp2/src/data_contract/mod.rs b/packages/wasm-dpp2/src/data_contract/mod.rs index 7ee33ca671a..7a467d164d8 100644 --- a/packages/wasm-dpp2/src/data_contract/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/mod.rs @@ -3,7 +3,7 @@ use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::token_configuration::TokenConfigurationWasm; use crate::token_configuration::group::GroupWasm; -use crate::utils::{IntoWasm, ToSerdeJSONExt}; +use crate::utils::{IntoWasm, JsValueExt, ToSerdeJSONExt}; use dpp::dashcore::hashes::serde::Serialize; use dpp::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters}; use dpp::data_contract::accessors::v1::{DataContractV1Getters, DataContractV1Setters}; @@ -66,7 +66,13 @@ pub fn tokens_configuration_from_js_value( }?; let js_config = Reflect::get(&configuration_object, &key) - .map_err(WasmDppError::from_js_value)? + .map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "unable to read token configuration at contract position '{}': {}", + contract_position, message + )) + })? .to_wasm::("TokenConfiguration")? .clone(); @@ -336,7 +342,13 @@ impl DataContractWasm { &JsValue::from(key.clone()), &JsValue::from(TokenConfigurationWasm::from(value.clone())), ) - .map_err(|e| WasmDppError::invalid_argument(e.as_string().unwrap_or_default()))?; + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to serialize token configuration at position '{}': {}", + key, message + )) + })?; } Ok(tokens_object) @@ -352,7 +364,13 @@ impl DataContractWasm { &JsValue::from(key.clone()), &JsValue::from(GroupWasm::from(value.clone())), ) - .map_err(|e| WasmDppError::invalid_argument(e.as_string().unwrap_or_default()))?; + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to serialize group at position '{}': {}", + key, message + )) + })?; } Ok(groups_object.into()) @@ -457,8 +475,13 @@ impl DataContractWasm { )) })?; - let js_group = Reflect::get(&groups_object, &js_position) - .map_err(|e| WasmDppError::invalid_argument(e.as_string().unwrap_or_default()))?; + let js_group = Reflect::get(&groups_object, &js_position).map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "unable to read group at position '{}': {}", + position_str, message + )) + })?; let group = js_group.to_wasm::("Group")?.clone(); diff --git a/packages/wasm-dpp2/src/error.rs b/packages/wasm-dpp2/src/error.rs index 15fe34f05d8..a884609742c 100644 --- a/packages/wasm-dpp2/src/error.rs +++ b/packages/wasm-dpp2/src/error.rs @@ -1,8 +1,9 @@ use anyhow::Error as AnyhowError; use dpp::ProtocolError; -use js_sys::Error as JsError; +use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsCast, JsValue}; + +use crate::utils::JsValueExt; /// Structured error returned by wasm-dpp2 APIs. #[wasm_bindgen] @@ -65,27 +66,6 @@ impl WasmDppError { pub(crate) fn generic(message: impl Into) -> Self { Self::new(WasmDppErrorKind::Generic, message, None) } - - pub(crate) fn from_js_value(value: JsValue) -> Self { - if value.is_null() || value.is_undefined() { - return WasmDppError::invalid_argument("JavaScript error: value is null or undefined"); - } - - if let Some(js_error) = value.dyn_ref::() { - return WasmDppError::invalid_argument(js_error.message()); - } - - if let Some(message) = value.as_string() { - return WasmDppError::invalid_argument(message); - } - - let message = js_sys::JSON::stringify(&value) - .ok() - .and_then(|v| v.as_string()) - .unwrap_or_else(|| "Unknown JavaScript error".to_string()); - - WasmDppError::invalid_argument(message) - } } impl From for WasmDppError { diff --git a/packages/wasm-dpp2/src/partial_identity/mod.rs b/packages/wasm-dpp2/src/partial_identity/mod.rs index 9b21e544824..dbac05a5257 100644 --- a/packages/wasm-dpp2/src/partial_identity/mod.rs +++ b/packages/wasm-dpp2/src/partial_identity/mod.rs @@ -1,7 +1,7 @@ use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; use crate::identity_public_key::IdentityPublicKeyWasm; -use crate::utils::IntoWasm; +use crate::utils::{IntoWasm, JsValueExt}; use dpp::fee::Credits; use dpp::identity::{IdentityPublicKey, KeyID, PartialIdentity}; use dpp::prelude::Revision; @@ -60,7 +60,13 @@ impl PartialIdentityWasm { &k.to_string().into(), &IdentityPublicKeyWasm::from(v).into(), ) - .map_err(|err| WasmDppError::from_js_value(err))?; + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "failed to write loaded public key '{}' into JS object: {}", + k, message + )) + })?; } Ok(obj) @@ -148,8 +154,13 @@ pub fn js_value_to_loaded_public_keys( let key_id = KeyID::from(key_val as u32); - let js_key = - Reflect::get(&pub_keys_object, &key).map_err(WasmDppError::from_js_value)?; + let js_key = Reflect::get(&pub_keys_object, &key).map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "unable to access loaded public key '{}': {}", + key_val as u32, message + )) + })?; let key = js_key .to_wasm::("IdentityPublicKey")? diff --git a/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs b/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs index e0841f46b79..6c9f398519f 100644 --- a/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs +++ b/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs @@ -4,7 +4,7 @@ use crate::identifier::IdentifierWasm; use crate::token_configuration::action_taker::ActionTakerWasm; use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; use crate::token_configuration::group::GroupWasm; -use crate::utils::IntoWasm; +use crate::utils::{IntoWasm, JsValueExt}; use dpp::data_contract::GroupContractPosition; use dpp::data_contract::change_control_rules::ChangeControlRules; use dpp::data_contract::change_control_rules::v0::ChangeControlRulesV0; @@ -186,8 +186,13 @@ impl ChangeControlRulesWasm { )) })?; - let group_value = - Reflect::get(js_groups, &key).map_err(|err| WasmDppError::from_js_value(err))?; + let group_value = Reflect::get(js_groups, &key).map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "unable to read group at contract position '{}': {}", + key_str, message + )) + })?; let group = group_value.to_wasm::("Group")?.clone(); diff --git a/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs b/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs index e86e080158c..7fa08892c62 100644 --- a/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs +++ b/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs @@ -1,5 +1,6 @@ use crate::error::{WasmDppError, WasmDppResult}; use crate::token_configuration::localization::TokenConfigurationLocalizationWasm; +use crate::utils::JsValueExt; use dpp::data_contract::associated_token::token_configuration_convention::TokenConfigurationConvention; use dpp::data_contract::associated_token::token_configuration_convention::accessors::v0::{ TokenConfigurationConventionV0Getters, TokenConfigurationConventionV0Setters, @@ -70,7 +71,13 @@ impl TokenConfigurationConventionWasm { &JsValue::from(key.clone()), &TokenConfigurationLocalizationWasm::from(value.clone()).into(), ) - .map_err(|err| WasmDppError::from_js_value(err))?; + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to serialize localization '{}': {}", + key, message + )) + })?; } Ok(object.into()) @@ -102,7 +109,13 @@ fn js_value_to_localizations( .as_string() .ok_or_else(|| WasmDppError::invalid_argument("Localization key must be string"))?; - let js_value = Reflect::get(&js_object, &key).map_err(WasmDppError::from_js_value)?; + let js_value = Reflect::get(&js_object, &key).map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "unable to read localization '{}': {}", + key_str, message + )) + })?; let localization = TokenConfigurationLocalizationWasm::from_js_value(&js_value)?; diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_function.rs b/packages/wasm-dpp2/src/token_configuration/distribution_function.rs index 851795d6512..4f34d734763 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_function.rs +++ b/packages/wasm-dpp2/src/token_configuration/distribution_function.rs @@ -4,7 +4,7 @@ use crate::token_configuration::distribution_structs::{ DistributionLinearWasm, DistributionLogarithmicWasm, DistributionPolynomialWasm, DistributionRandomWasm, DistributionStepDecreasingAmountWasm, }; -use crate::utils::try_to_u64; +use crate::utils::{JsValueExt, try_to_u64}; use dpp::balances::credits::TokenAmount; use dpp::data_contract::associated_token::token_perpetual_distribution::distribution_function::DistributionFunction; use js_sys::{BigInt, Object, Reflect}; @@ -88,8 +88,13 @@ impl DistributionFunctionWasm { WasmDppError::invalid_argument(format!("Invalid step key '{}': {}", key_str, err)) })?; - let amount_js = - Reflect::get(&obj, &key).map_err(|err| WasmDppError::from_js_value(err))?; + let amount_js = Reflect::get(&obj, &key).map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "unable to read distribution step '{}': {}", + key_str, message + )) + })?; let amount = try_to_u64(amount_js) .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; @@ -275,7 +280,13 @@ impl DistributionFunctionWasm { &key.to_string().into(), &BigInt::from(value).into(), ) - .map_err(WasmDppError::from_js_value)?; + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to serialize distribution function step '{}': {}", + key, message + )) + })?; } Ok(object.into()) diff --git a/packages/wasm-dpp2/src/token_configuration/group.rs b/packages/wasm-dpp2/src/token_configuration/group.rs index a472b3681b4..b642d28dc08 100644 --- a/packages/wasm-dpp2/src/token_configuration/group.rs +++ b/packages/wasm-dpp2/src/token_configuration/group.rs @@ -1,5 +1,6 @@ use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; +use crate::utils::JsValueExt; use dpp::data_contract::group::accessors::v0::{GroupV0Getters, GroupV0Setters}; use dpp::data_contract::group::v0::GroupV0; use dpp::data_contract::group::{Group, GroupMemberPower, GroupRequiredPower}; @@ -94,7 +95,14 @@ impl GroupWasm { &JsValue::from(k.to_string(Encoding::Base58)), &JsValue::from(v.clone()), ) - .map_err(|err| WasmDppError::from_js_value(err))?; + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to write group member '{}' into JS object: {}", + k.to_string(Encoding::Base58), + message + )) + })?; } Ok(js_members.into()) diff --git a/packages/wasm-dpp2/src/token_configuration/localization.rs b/packages/wasm-dpp2/src/token_configuration/localization.rs index ce940cac972..5014162b889 100644 --- a/packages/wasm-dpp2/src/token_configuration/localization.rs +++ b/packages/wasm-dpp2/src/token_configuration/localization.rs @@ -1,5 +1,5 @@ use crate::error::{WasmDppError, WasmDppResult}; -use crate::utils::IntoWasm; +use crate::utils::{IntoWasm, JsValueExt}; use dpp::data_contract::associated_token::token_configuration_localization::TokenConfigurationLocalization; use dpp::data_contract::associated_token::token_configuration_localization::accessors::v0::{ TokenConfigurationLocalizationV0Getters, TokenConfigurationLocalizationV0Setters, @@ -91,19 +91,37 @@ impl TokenConfigurationLocalizationWasm { &JsValue::from("shouldCapitalize"), &JsValue::from(self.0.should_capitalize()), ) - .map_err(|err| WasmDppError::from_js_value(err))?; + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to set 'shouldCapitalize' on TokenConfigurationLocalization: {}", + message + )) + })?; Reflect::set( &object, &JsValue::from("pluralForm"), &JsValue::from(self.0.plural_form()), ) - .map_err(WasmDppError::from_js_value)?; + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to set 'pluralForm' on TokenConfigurationLocalization: {}", + message + )) + })?; Reflect::set( &object, &JsValue::from("singularForm"), &JsValue::from(self.0.singular_form()), ) - .map_err(WasmDppError::from_js_value)?; + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to set 'singularForm' on TokenConfigurationLocalization: {}", + message + )) + })?; Ok(object.into()) } @@ -142,23 +160,41 @@ fn localization_from_plain_js_value( } let should_capitalize_value = Reflect::get(js_value, &JsValue::from_str("shouldCapitalize")) - .map_err(WasmDppError::from_js_value)?; + .map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "TokenConfigurationLocalization.shouldCapitalize could not be read: {}", + message + )) + })?; let should_capitalize = should_capitalize_value.as_bool().ok_or_else(|| { WasmDppError::invalid_argument( "TokenConfigurationLocalization.shouldCapitalize must be a boolean", ) })?; - let singular_form_value = Reflect::get(js_value, &JsValue::from_str("singularForm")) - .map_err(WasmDppError::from_js_value)?; + let singular_form_value = + Reflect::get(js_value, &JsValue::from_str("singularForm")).map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "TokenConfigurationLocalization.singularForm could not be read: {}", + message + )) + })?; let singular_form = singular_form_value.as_string().ok_or_else(|| { WasmDppError::invalid_argument( "TokenConfigurationLocalization.singularForm must be a string", ) })?; - let plural_form_value = Reflect::get(js_value, &JsValue::from_str("pluralForm")) - .map_err(WasmDppError::from_js_value)?; + let plural_form_value = + Reflect::get(js_value, &JsValue::from_str("pluralForm")).map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "TokenConfigurationLocalization.pluralForm could not be read: {}", + message + )) + })?; let plural_form = plural_form_value.as_string().ok_or_else(|| { WasmDppError::invalid_argument("TokenConfigurationLocalization.pluralForm must be a string") })?; diff --git a/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs b/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs index 73f34d5724b..5e3d49dd333 100644 --- a/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs +++ b/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs @@ -1,6 +1,6 @@ use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::utils::try_to_u64; +use crate::utils::{JsValueExt, try_to_u64}; use dpp::balances::credits::TokenAmount; use dpp::data_contract::associated_token::token_pre_programmed_distribution::TokenPreProgrammedDistribution; use dpp::data_contract::associated_token::token_pre_programmed_distribution::accessors::v0::TokenPreProgrammedDistributionV0Methods; @@ -47,8 +47,13 @@ pub fn js_distributions_to_distributions( )) })?; - let identifiers_js = Reflect::get(&distributions_object, &key) - .map_err(|err| WasmDppError::from_js_value(err))?; + let identifiers_js = Reflect::get(&distributions_object, &key).map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "unable to access distribution entry for timestamp '{}': {}", + timestamp_str, message + )) + })?; let identifiers_object = Object::from(identifiers_js); let identifiers_keys = Object::keys(&identifiers_object); @@ -57,8 +62,13 @@ pub fn js_distributions_to_distributions( for id_key in identifiers_keys.iter() { let identifier = Identifier::from(IdentifierWasm::try_from(id_key.clone())?); - let amount_js = - Reflect::get(&identifiers_object, &id_key).map_err(WasmDppError::from_js_value)?; + let amount_js = Reflect::get(&identifiers_object, &id_key).map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "unable to access distribution amount for identity '{}' at '{}': {}", + identifier, timestamp, message + )) + })?; let token_amount = try_to_u64(amount_js) .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; @@ -109,11 +119,24 @@ impl TokenPreProgrammedDistributionWasm { .into(), &BigInt::from(identifiers_value.clone()).into(), ) - .map_err(WasmDppError::from_js_value)?; + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to serialize distribution amount for identity '{}' at '{}': {}", + identifiers_key, key, message + )) + })?; } - Reflect::set(&obj, &key.to_string().into(), &identifiers_obj.into()) - .map_err(WasmDppError::from_js_value)?; + Reflect::set(&obj, &key.to_string().into(), &identifiers_obj.into()).map_err( + |err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to serialize distribution for timestamp '{}': {}", + key, message + )) + }, + )?; } Ok(obj.into()) diff --git a/packages/wasm-dpp2/src/utils/mod.rs b/packages/wasm-dpp2/src/utils/mod.rs index 14c33f6ff7f..eb93cbda01e 100644 --- a/packages/wasm-dpp2/src/utils/mod.rs +++ b/packages/wasm-dpp2/src/utils/mod.rs @@ -4,12 +4,12 @@ use dpp::identifier::Identifier; use dpp::platform_value::Value; use dpp::platform_value::string_encoding::Encoding::Base58; use dpp::util::hash::hash_double_to_vec; -use js_sys::{Function, Uint8Array}; +use js_sys::{Error as JsError, Function, Uint8Array}; use serde_json::Value as JsonValue; use std::collections::BTreeMap; use std::convert::TryInto; -use wasm_bindgen::JsValue; use wasm_bindgen::convert::RefFromWasmAbi; +use wasm_bindgen::{JsCast, JsValue}; pub fn stringify_wasm(data: &JsValue) -> WasmDppResult { let replacer_func = Function::new_with_args( @@ -23,6 +23,31 @@ pub fn stringify_wasm(data: &JsValue) -> WasmDppResult { Ok(data_string.into()) } +pub trait JsValueExt { + fn error_message(&self) -> String; +} + +impl JsValueExt for JsValue { + fn error_message(&self) -> String { + if self.is_null() || self.is_undefined() { + return "JavaScript error: value is null or undefined".to_string(); + } + + if let Some(js_error) = self.dyn_ref::() { + return js_error.message().into(); + } + + if let Some(message) = self.as_string() { + return message; + } + + js_sys::JSON::stringify(self) + .ok() + .and_then(|v| v.as_string()) + .unwrap_or_else(|| "Unknown JavaScript error".to_string()) + } +} + pub fn with_serde_to_json_value_wasm(data: JsValue) -> WasmDppResult { let data = stringify_wasm(&data)?; serde_json::from_str(&data).map_err(|e| { @@ -114,7 +139,13 @@ pub fn stringify(data: &JsValue) -> WasmDppResult { let data_string: String = js_sys::JSON::stringify_with_replacer(data, &JsValue::from(replacer_func)) - .map_err(|err| WasmDppError::from_js_value(err))? + .map_err(|err| { + let message = err.error_message(); + WasmDppError::serialization(format!( + "unable to stringify value to JSON: {}", + message + )) + })? .into(); Ok(data_string) @@ -144,8 +175,14 @@ pub fn generic_of_js_val>( let ctor_name = get_class_type(js_value)?; if ctor_name == class_name { - let ptr = js_sys::Reflect::get(js_value, &JsValue::from_str("__wbg_ptr")) - .map_err(WasmDppError::from_js_value)?; + let ptr = + js_sys::Reflect::get(js_value, &JsValue::from_str("__wbg_ptr")).map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "failed to read internal pointer from JS object '{}': {}", + class_name, message + )) + })?; let ptr_u32: u32 = ptr .as_f64() .ok_or_else(|| WasmDppError::invalid_argument("Invalid JS object pointer"))? @@ -162,8 +199,13 @@ pub fn generic_of_js_val>( } pub fn get_class_type(value: &JsValue) -> WasmDppResult { - let class_type = js_sys::Reflect::get(&value, &JsValue::from_str("__type")) - .map_err(WasmDppError::from_js_value)?; + let class_type = js_sys::Reflect::get(&value, &JsValue::from_str("__type")).map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "failed to read '__type' property from JS value: {}", + message + )) + })?; Ok(class_type.as_string().unwrap_or_default()) } From ee6ecc2deff21f419655a4ed802cbd043f094322 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 7 Oct 2025 18:48:22 +0700 Subject: [PATCH 13/44] refactor: structure modules --- .../contract_bounds/mod.rs | 0 .../document/methods/mod.rs | 2 +- .../src/{ => data_contract}/document/mod.rs | 0 packages/wasm-dpp2/src/data_contract/mod.rs | 539 +----------------- packages/wasm-dpp2/src/data_contract/model.rs | 529 +++++++++++++++++ .../transitions}/create/mod.rs | 2 +- .../transitions}/mod.rs | 0 .../transitions}/update/mod.rs | 2 +- .../governance}/masternode_vote/mod.rs | 4 +- .../resource_vote_choice/mod.rs | 0 .../governance}/masternode_vote/vote/mod.rs | 4 +- .../masternode_vote/vote_poll/mod.rs | 0 .../wasm-dpp2/src/identity/governance/mod.rs | 6 + packages/wasm-dpp2/src/identity/mod.rs | 208 +------ packages/wasm-dpp2/src/identity/model.rs | 190 ++++++ .../{ => identity}/partial_identity/mod.rs | 2 +- .../public_key}/mod.rs | 2 +- .../transitions}/create_transition/mod.rs | 4 +- .../credit_withdrawal_transition/mod.rs | 2 +- .../mod.rs | 2 +- .../transitions}/mod.rs | 0 .../public_key_in_creation/mod.rs | 4 +- .../transitions}/top_up_transition/mod.rs | 2 +- .../transitions}/update_transition/mod.rs | 4 +- packages/wasm-dpp2/src/lib.rs | 34 +- .../base}/group_state_transition_info/mod.rs | 0 .../src/state_transitions/base/mod.rs | 5 + .../base}/state_transition/mod.rs | 2 +- .../batch/batched_transition/mod.rs | 4 +- .../batch/document_base_transition/mod.rs | 2 +- .../batch/document_transition/mod.rs | 12 +- .../batch/document_transitions/create/mod.rs | 12 +- .../batch/document_transitions/delete/mod.rs | 10 +- .../batch/document_transitions/mod.rs | 0 .../document_transitions/purchase/mod.rs | 10 +- .../batch/document_transitions/replace/mod.rs | 10 +- .../document_transitions/transfer/mod.rs | 10 +- .../document_transitions/update_price/mod.rs | 10 +- .../batch/generators.rs | 6 +- .../src/{ => state_transitions}/batch/mod.rs | 6 +- .../batch/prefunded_voting_balance/mod.rs | 0 .../batch/token_base_transition/mod.rs | 2 +- .../batch/token_payment_info/mod.rs | 0 .../batch/token_pricing_schedule/mod.rs | 0 .../batch/token_transition/mod.rs | 22 +- .../batch/token_transitions/config_update.rs | 4 +- .../token_transitions/direct_purchase.rs | 2 +- .../batch/token_transitions/mod.rs | 0 .../set_price_for_direct_purchase.rs | 4 +- .../batch/token_transitions/token_burn.rs | 2 +- .../batch/token_transitions/token_claim.rs | 2 +- .../token_destroy_frozen_funds.rs | 2 +- .../token_emergency_action.rs | 2 +- .../batch/token_transitions/token_freeze.rs | 2 +- .../batch/token_transitions/token_mint.rs | 4 +- .../batch/token_transitions/token_transfer.rs | 6 +- .../batch/token_transitions/token_unfreeze.rs | 2 +- .../wasm-dpp2/src/state_transitions/mod.rs | 4 + .../configuration}/action_taker.rs | 0 .../authorized_action_takers.rs | 0 .../configuration}/change_control_rules.rs | 6 +- .../configuration_convention.rs | 2 +- .../configuration}/distribution_function.rs | 2 +- .../configuration}/distribution_recipient.rs | 0 .../configuration}/distribution_rules.rs | 6 +- .../configuration}/distribution_structs.rs | 0 .../configuration}/group.rs | 0 .../configuration}/keeps_history_rules.rs | 0 .../configuration}/localization.rs | 0 .../configuration}/marketplace_rules.rs | 4 +- .../configuration}/mod.rs | 12 +- .../configuration}/perpetual_distribution.rs | 4 +- .../pre_programmed_distribution.rs | 0 .../reward_distribution_type.rs | 2 +- .../configuration}/trade_mode.rs | 0 .../items/conventions.rs | 6 +- .../items/destroy_frozen_funds.rs | 4 +- .../items/emergency_action.rs | 4 +- .../items/freeze.rs | 4 +- .../items/main_control_group.rs | 2 +- .../items/manual_burning.rs | 4 +- .../items/manual_minting.rs | 4 +- .../items/marketplace_trade_mode.rs | 6 +- .../items/max_supply.rs | 4 +- .../minting_allow_choosing_destination.rs | 4 +- .../configuration_change_item}/items/mod.rs | 0 .../items/new_tokens_destination_identity.rs | 4 +- .../items/no_change.rs | 2 +- .../items/perpetual_distribution.rs | 6 +- .../items/unfreeze.rs | 4 +- .../configuration_change_item}/mod.rs | 8 +- .../src/{ => tokens}/encrypted_note/mod.rs | 0 .../private_encrypted_note/mod.rs | 0 .../shared_encrypted_note/mod.rs | 0 packages/wasm-dpp2/src/tokens/mod.rs | 11 + 95 files changed, 939 insertions(+), 877 deletions(-) rename packages/wasm-dpp2/src/{ => data_contract}/contract_bounds/mod.rs (100%) rename packages/wasm-dpp2/src/{ => data_contract}/document/methods/mod.rs (99%) rename packages/wasm-dpp2/src/{ => data_contract}/document/mod.rs (100%) create mode 100644 packages/wasm-dpp2/src/data_contract/model.rs rename packages/wasm-dpp2/src/{data_contract_transitions => data_contract/transitions}/create/mod.rs (99%) rename packages/wasm-dpp2/src/{data_contract_transitions => data_contract/transitions}/mod.rs (100%) rename packages/wasm-dpp2/src/{data_contract_transitions => data_contract/transitions}/update/mod.rs (99%) rename packages/wasm-dpp2/src/{ => identity/governance}/masternode_vote/mod.rs (98%) rename packages/wasm-dpp2/src/{ => identity/governance}/masternode_vote/resource_vote_choice/mod.rs (100%) rename packages/wasm-dpp2/src/{ => identity/governance}/masternode_vote/vote/mod.rs (93%) rename packages/wasm-dpp2/src/{ => identity/governance}/masternode_vote/vote_poll/mod.rs (100%) create mode 100644 packages/wasm-dpp2/src/identity/governance/mod.rs create mode 100644 packages/wasm-dpp2/src/identity/model.rs rename packages/wasm-dpp2/src/{ => identity}/partial_identity/mod.rs (99%) rename packages/wasm-dpp2/src/{identity_public_key => identity/public_key}/mod.rs (99%) rename packages/wasm-dpp2/src/{identity_transitions => identity/transitions}/create_transition/mod.rs (97%) rename packages/wasm-dpp2/src/{identity_transitions => identity/transitions}/credit_withdrawal_transition/mod.rs (99%) rename packages/wasm-dpp2/src/{identity_transitions => identity/transitions}/identity_credit_transfer_transition/mod.rs (99%) rename packages/wasm-dpp2/src/{identity_transitions => identity/transitions}/mod.rs (100%) rename packages/wasm-dpp2/src/{identity_transitions => identity/transitions}/public_key_in_creation/mod.rs (98%) rename packages/wasm-dpp2/src/{identity_transitions => identity/transitions}/top_up_transition/mod.rs (99%) rename packages/wasm-dpp2/src/{identity_transitions => identity/transitions}/update_transition/mod.rs (98%) rename packages/wasm-dpp2/src/{ => state_transitions/base}/group_state_transition_info/mod.rs (100%) create mode 100644 packages/wasm-dpp2/src/state_transitions/base/mod.rs rename packages/wasm-dpp2/src/{ => state_transitions/base}/state_transition/mod.rs (99%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/batched_transition/mod.rs (96%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/document_base_transition/mod.rs (98%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/document_transition/mod.rs (91%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/document_transitions/create/mod.rs (92%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/document_transitions/delete/mod.rs (89%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/document_transitions/mod.rs (100%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/document_transitions/purchase/mod.rs (91%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/document_transitions/replace/mod.rs (91%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/document_transitions/transfer/mod.rs (90%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/document_transitions/update_price/mod.rs (90%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/generators.rs (96%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/mod.rs (97%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/prefunded_voting_balance/mod.rs (100%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_base_transition/mod.rs (98%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_payment_info/mod.rs (100%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_pricing_schedule/mod.rs (100%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transition/mod.rs (90%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transitions/config_update.rs (94%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transitions/direct_purchase.rs (97%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transitions/mod.rs (100%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transitions/set_price_for_direct_purchase.rs (95%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transitions/token_burn.rs (96%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transitions/token_claim.rs (97%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transitions/token_destroy_frozen_funds.rs (97%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transitions/token_emergency_action.rs (97%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transitions/token_freeze.rs (97%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transitions/token_mint.rs (96%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transitions/token_transfer.rs (96%) rename packages/wasm-dpp2/src/{ => state_transitions}/batch/token_transitions/token_unfreeze.rs (97%) create mode 100644 packages/wasm-dpp2/src/state_transitions/mod.rs rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/action_taker.rs (100%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/authorized_action_takers.rs (100%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/change_control_rules.rs (97%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/configuration_convention.rs (98%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/distribution_function.rs (99%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/distribution_recipient.rs (100%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/distribution_rules.rs (97%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/distribution_structs.rs (100%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/group.rs (100%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/keeps_history_rules.rs (100%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/localization.rs (100%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/marketplace_rules.rs (94%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/mod.rs (95%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/perpetual_distribution.rs (93%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/pre_programmed_distribution.rs (100%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/reward_distribution_type.rs (98%) rename packages/wasm-dpp2/src/{token_configuration => tokens/configuration}/trade_mode.rs (100%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/conventions.rs (81%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/destroy_frozen_funds.rs (83%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/emergency_action.rs (84%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/freeze.rs (83%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/main_control_group.rs (87%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/manual_burning.rs (83%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/manual_minting.rs (83%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/marketplace_trade_mode.rs (84%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/max_supply.rs (86%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/minting_allow_choosing_destination.rs (88%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/mod.rs (100%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/new_tokens_destination_identity.rs (91%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/no_change.rs (84%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/perpetual_distribution.rs (88%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/items/unfreeze.rs (82%) rename packages/wasm-dpp2/src/{token_configuration_change_item => tokens/configuration_change_item}/mod.rs (97%) rename packages/wasm-dpp2/src/{ => tokens}/encrypted_note/mod.rs (100%) rename packages/wasm-dpp2/src/{ => tokens}/encrypted_note/private_encrypted_note/mod.rs (100%) rename packages/wasm-dpp2/src/{ => tokens}/encrypted_note/shared_encrypted_note/mod.rs (100%) create mode 100644 packages/wasm-dpp2/src/tokens/mod.rs diff --git a/packages/wasm-dpp2/src/contract_bounds/mod.rs b/packages/wasm-dpp2/src/data_contract/contract_bounds/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/contract_bounds/mod.rs rename to packages/wasm-dpp2/src/data_contract/contract_bounds/mod.rs diff --git a/packages/wasm-dpp2/src/document/methods/mod.rs b/packages/wasm-dpp2/src/data_contract/document/methods/mod.rs similarity index 99% rename from packages/wasm-dpp2/src/document/methods/mod.rs rename to packages/wasm-dpp2/src/data_contract/document/methods/mod.rs index 3b44231dd04..29247a01d12 100644 --- a/packages/wasm-dpp2/src/document/methods/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/document/methods/mod.rs @@ -1,5 +1,5 @@ use crate::data_contract::DataContractWasm; -use crate::document::DocumentWasm; +use crate::data_contract::document::DocumentWasm; use crate::enums::platform::PlatformVersionWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; diff --git a/packages/wasm-dpp2/src/document/mod.rs b/packages/wasm-dpp2/src/data_contract/document/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/document/mod.rs rename to packages/wasm-dpp2/src/data_contract/document/mod.rs diff --git a/packages/wasm-dpp2/src/data_contract/mod.rs b/packages/wasm-dpp2/src/data_contract/mod.rs index 7a467d164d8..e617bb9b790 100644 --- a/packages/wasm-dpp2/src/data_contract/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/mod.rs @@ -1,529 +1,10 @@ -use crate::enums::platform::PlatformVersionWasm; -use crate::error::{WasmDppError, WasmDppResult}; -use crate::identifier::IdentifierWasm; -use crate::token_configuration::TokenConfigurationWasm; -use crate::token_configuration::group::GroupWasm; -use crate::utils::{IntoWasm, JsValueExt, ToSerdeJSONExt}; -use dpp::dashcore::hashes::serde::Serialize; -use dpp::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters}; -use dpp::data_contract::accessors::v1::{DataContractV1Getters, DataContractV1Setters}; -use dpp::data_contract::config::DataContractConfig; -use dpp::data_contract::conversion::json::DataContractJsonConversionMethodsV0; -use dpp::data_contract::conversion::value::v0::DataContractValueConversionMethodsV0; -use dpp::data_contract::document_type::DocumentTypeRef; -use dpp::data_contract::errors::DataContractError; -use dpp::data_contract::group::Group; -use dpp::data_contract::schema::DataContractSchemaMethodsV0; -use dpp::data_contract::{ - DataContract, GroupContractPosition, TokenConfiguration, TokenContractPosition, -}; -use dpp::platform_value::string_encoding::Encoding::{Base58, Base64, Hex}; -use dpp::platform_value::string_encoding::{decode, encode}; -use dpp::platform_value::{Value, ValueMap}; -use dpp::prelude::IdentityNonce; -use dpp::serialization::{ - PlatformDeserializableWithPotentialValidationFromVersionedStructure, - PlatformSerializableWithPlatformVersion, -}; -use dpp::version::PlatformVersion; -use js_sys::{Object, Reflect}; -use std::collections::BTreeMap; -use wasm_bindgen::JsValue; -use wasm_bindgen::prelude::wasm_bindgen; - -#[wasm_bindgen(js_name = "DataContract")] -#[derive(Clone)] -pub struct DataContractWasm(DataContract); - -impl From for DataContractWasm { - fn from(v: DataContract) -> Self { - DataContractWasm(v) - } -} - -impl From for DataContract { - fn from(v: DataContractWasm) -> Self { - v.0 - } -} - -pub fn tokens_configuration_from_js_value( - js_configuration: &JsValue, -) -> WasmDppResult> { - let configuration_object = Object::from(js_configuration.clone()); - let configuration_keys = Object::keys(&configuration_object); - - let mut configuration: BTreeMap = BTreeMap::new(); - - for key in configuration_keys.iter() { - let contract_position = match key.as_string() { - None => Err(WasmDppError::invalid_argument( - "Cannot read timestamp in distribution rules", - )), - Some(contract_position) => Ok(contract_position - .parse::() - .map_err(|e| WasmDppError::serialization(e.to_string()))?), - }?; - - let js_config = Reflect::get(&configuration_object, &key) - .map_err(|err| { - let message = err.error_message(); - WasmDppError::invalid_argument(format!( - "unable to read token configuration at contract position '{}': {}", - contract_position, message - )) - })? - .to_wasm::("TokenConfiguration")? - .clone(); - - configuration.insert(contract_position, js_config.into()); - } - - Ok(configuration) -} - -#[wasm_bindgen(js_class = DataContract)] -impl DataContractWasm { - #[wasm_bindgen(getter = __type)] - pub fn type_name(&self) -> String { - "DataContract".to_string() - } - - #[wasm_bindgen(getter = __struct)] - pub fn struct_name() -> String { - "DataContract".to_string() - } - - #[wasm_bindgen(constructor)] - pub fn from_js_values( - js_owner_id: &JsValue, - identity_nonce: IdentityNonce, - js_schema: JsValue, - js_definitions: Option, - js_tokens: &JsValue, - full_validation: bool, - js_platform_version: JsValue, - ) -> WasmDppResult { - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - - let owner_id: IdentifierWasm = js_owner_id.clone().try_into()?; - - let owner_id_value = Value::from(owner_id.get_base58()); - - let schema: Value = serde_wasm_bindgen::from_value(js_schema) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - let tokens: BTreeMap = - match js_tokens.is_undefined() { - true => BTreeMap::new(), - false => tokens_configuration_from_js_value(js_tokens)?, - }; - - let platform_version: PlatformVersion = match js_platform_version.is_undefined() { - true => PlatformVersionWasm::default().into(), - false => PlatformVersionWasm::try_from(js_platform_version)?.into(), - }; - - let data_contract_structure_version_value = Value::from( - platform_version - .dpp - .contract_versions - .contract_structure_version - .to_string(), - ); - - let definitions = js_definitions - .map(|definitions| serde_wasm_bindgen::from_value(definitions.into())) - .transpose() - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - let definitions_value = Value::from(definitions); - - let data_contract_id = - DataContract::generate_data_contract_id_v0(owner_id.to_bytes(), identity_nonce); - - let data_contract_id_value = Value::from(data_contract_id.to_string(Base58)); - - let config = DataContractConfig::default_for_version(&platform_version.clone())?; - - let config_value = config - .serialize(&serializer) - .map_err(|e| WasmDppError::serialization(e.to_string()))? - .with_serde_to_platform_value_map()?; - - let mut contract_value = Value::Map(ValueMap::new()); - - contract_value - .set_value("$format_version", data_contract_structure_version_value) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - contract_value - .set_value("id", data_contract_id_value) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - contract_value - .set_value("config", Value::from(config_value)) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - contract_value - .set_value("version", Value::from(1u16)) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - contract_value - .set_value("ownerId", owner_id_value) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - contract_value - .set_value("schemaDefs", definitions_value) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - contract_value - .set_value("documentSchemas", schema) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - let data_contract = - DataContract::from_value(contract_value, full_validation, &platform_version)?; - - let data_contract_with_tokens = match data_contract { - DataContract::V0(v0) => DataContract::from(v0), - DataContract::V1(mut v1) => { - v1.set_tokens(tokens); - - DataContract::from(v1) - } - }; - - Ok(DataContractWasm(data_contract_with_tokens)) - } - - #[wasm_bindgen(js_name = "fromValue")] - pub fn from_value( - js_value: JsValue, - full_validation: bool, - js_platform_version: JsValue, - ) -> WasmDppResult { - let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWasm::default(), - false => PlatformVersionWasm::try_from(js_platform_version)?, - }; - - let value = js_value.with_serde_to_platform_value()?; - - let contract = DataContract::from_value(value, full_validation, &platform_version.into())?; - - Ok(DataContractWasm(contract)) - } - - #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes( - bytes: Vec, - full_validation: bool, - js_platform_version: JsValue, - ) -> WasmDppResult { - let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWasm::default(), - false => PlatformVersionWasm::try_from(js_platform_version)?, - }; - - let rs_data_contract = DataContract::versioned_deserialize( - &bytes.as_slice(), - full_validation, - &platform_version.into(), - )?; - - Ok(DataContractWasm(rs_data_contract)) - } - - #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex( - hex: String, - full_validation: bool, - js_platform_version: JsValue, - ) -> WasmDppResult { - let bytes = - decode(hex.as_str(), Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; - - DataContractWasm::from_bytes(bytes, full_validation, js_platform_version) - } - - #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64( - base64: String, - full_validation: bool, - js_platform_version: JsValue, - ) -> WasmDppResult { - let bytes = decode(base64.as_str(), Base64) - .map_err(|e| WasmDppError::serialization(e.to_string()))?; - - DataContractWasm::from_bytes(bytes, full_validation, js_platform_version) - } - - #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self, js_platform_version: JsValue) -> WasmDppResult> { - let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWasm::default(), - false => PlatformVersionWasm::try_from(js_platform_version)?, - }; - - let rs_data_contract: DataContract = self.0.clone(); - - Ok(rs_data_contract.serialize_to_bytes_with_platform_version(&platform_version.into())?) - } - - #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self, js_platform_version: JsValue) -> WasmDppResult { - Ok(encode(self.to_bytes(js_platform_version)?.as_slice(), Hex)) - } - - #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self, js_platform_version: JsValue) -> WasmDppResult { - Ok(encode( - self.to_bytes(js_platform_version)?.as_slice(), - Base64, - )) - } - - #[wasm_bindgen(js_name = "toValue")] - pub fn to_value(&self, js_platform_version: JsValue) -> WasmDppResult { - let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWasm::default(), - false => PlatformVersionWasm::try_from(js_platform_version)?, - }; - - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - - self.0 - .clone() - .to_value(&platform_version.into())? - .serialize(&serializer) - .map_err(|e| WasmDppError::serialization(e.to_string())) - } - - #[wasm_bindgen(js_name = "getSchemas")] - pub fn get_schemas(&self) -> WasmDppResult { - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - - self.0 - .document_schemas() - .serialize(&serializer) - .map_err(|e| WasmDppError::serialization(e.to_string())) - } - - #[wasm_bindgen(getter = "version")] - pub fn get_version(&self) -> u32 { - self.0.version() - } - - #[wasm_bindgen(getter = "id")] - pub fn get_id(&self) -> IdentifierWasm { - self.0.id().into() - } - - #[wasm_bindgen(getter = "ownerId")] - pub fn get_owner_id(&self) -> IdentifierWasm { - self.0.owner_id().into() - } - - #[wasm_bindgen(js_name = "getConfig")] - pub fn get_config(&self) -> WasmDppResult { - self.0 - .config() - .serialize(&serde_wasm_bindgen::Serializer::json_compatible()) - .map_err(|e| WasmDppError::serialization(e.to_string())) - } - - #[wasm_bindgen(getter = "tokens")] - pub fn get_tokens(&self) -> WasmDppResult { - let tokens_object = Object::new(); - - for (key, value) in self.0.tokens().iter() { - Reflect::set( - &tokens_object, - &JsValue::from(key.clone()), - &JsValue::from(TokenConfigurationWasm::from(value.clone())), - ) - .map_err(|err| { - let message = err.error_message(); - WasmDppError::generic(format!( - "unable to serialize token configuration at position '{}': {}", - key, message - )) - })?; - } - - Ok(tokens_object) - } - - #[wasm_bindgen(getter = "groups")] - pub fn get_groups(&self) -> WasmDppResult { - let groups_object = Object::new(); - - for (key, value) in self.0.groups().iter() { - Reflect::set( - &groups_object, - &JsValue::from(key.clone()), - &JsValue::from(GroupWasm::from(value.clone())), - ) - .map_err(|err| { - let message = err.error_message(); - WasmDppError::generic(format!( - "unable to serialize group at position '{}': {}", - key, message - )) - })?; - } - - Ok(groups_object.into()) - } - - #[wasm_bindgen(setter = "id")] - pub fn set_id(&mut self, js_data_contract_id: &JsValue) -> WasmDppResult<()> { - self.0 - .set_id(IdentifierWasm::try_from(js_data_contract_id)?.into()); - Ok(()) - } - - #[wasm_bindgen(setter = "ownerId")] - pub fn set_owner_id(&mut self, js_owner_id: &JsValue) -> WasmDppResult<()> { - self.0 - .set_owner_id(IdentifierWasm::try_from(js_owner_id)?.into()); - Ok(()) - } - - #[wasm_bindgen(setter = "version")] - pub fn set_version(&mut self, version: u32) { - self.0.set_version(version) - } - - #[wasm_bindgen(js_name = "setConfig")] - pub fn set_config( - &mut self, - js_config: JsValue, - js_platform_version: JsValue, - ) -> WasmDppResult<()> { - let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWasm::default(), - false => PlatformVersionWasm::try_from(js_platform_version)?, - }; - - let config_value: Value = serde_wasm_bindgen::from_value(js_config) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - let config = DataContractConfig::from_value(config_value, &platform_version.into())?; - - self.0.set_config(config); - - Ok(()) - } - - #[wasm_bindgen(js_name = "setSchemas")] - pub fn set_schemas( - &mut self, - js_schema: JsValue, - js_definitions: Option, - full_validation: bool, - js_platform_version: JsValue, - ) -> WasmDppResult<()> { - let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWasm::default(), - false => PlatformVersionWasm::try_from(js_platform_version)?, - }; - - let schema = js_schema.with_serde_to_platform_value_map()?; - - let definitions: Option> = js_definitions - .map(|definitions| serde_wasm_bindgen::from_value(definitions.into())) - .transpose() - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - self.0.set_document_schemas( - schema, - definitions, - full_validation, - &mut Vec::new(), - &platform_version.into(), - )?; - - Ok(()) - } - - #[wasm_bindgen(setter = "tokens")] - pub fn set_tokens(&mut self, js_tokens: &JsValue) -> WasmDppResult<()> { - self.0 - .set_tokens(tokens_configuration_from_js_value(js_tokens)?); - Ok(()) - } - - #[wasm_bindgen(setter = "groups")] - pub fn set_groups(&mut self, js_groups: &JsValue) -> WasmDppResult<()> { - let groups_object = Object::from(js_groups.clone()); - - let mut groups: BTreeMap = BTreeMap::new(); - - for js_position in Object::keys(&groups_object) { - let position_str = js_position.as_string().ok_or_else(|| { - WasmDppError::invalid_argument(format!( - "Group position '{:?}' must be a stringified number.", - js_position - )) - })?; - - let position = position_str.parse::().map_err(|err| { - WasmDppError::invalid_argument(format!( - "Invalid group position '{}': {}.", - position_str, err - )) - })?; - - let js_group = Reflect::get(&groups_object, &js_position).map_err(|err| { - let message = err.error_message(); - WasmDppError::invalid_argument(format!( - "unable to read group at position '{}': {}", - position_str, message - )) - })?; - - let group = js_group.to_wasm::("Group")?.clone(); - - groups.insert(position, group.into()); - } - - self.0.set_groups(groups); - - Ok(()) - } - - #[wasm_bindgen(js_name = "toJSON")] - pub fn to_json(&self, js_platform_version: JsValue) -> WasmDppResult { - let platform_version = match js_platform_version.is_undefined() { - true => PlatformVersionWasm::default(), - false => PlatformVersionWasm::try_from(js_platform_version)?, - }; - - let json = self.0.to_json(&platform_version.into())?; - - json.serialize(&serde_wasm_bindgen::Serializer::json_compatible()) - .map_err(|e| WasmDppError::serialization(e.to_string())) - } - - #[wasm_bindgen(js_name = "generateId")] - pub fn generate_id( - js_owner_id: &JsValue, - identity_nonce: IdentityNonce, - ) -> WasmDppResult { - Ok(DataContract::generate_data_contract_id_v0( - IdentifierWasm::try_from(js_owner_id)?.to_bytes(), - identity_nonce, - ) - .into()) - } -} - -impl DataContractWasm { - pub fn get_document_type_ref_by_name( - &self, - name: String, - ) -> Result, DataContractError> { - self.0.document_type_for_name(name.as_str()).clone() - } -} +pub mod contract_bounds; +pub mod document; +pub mod model; +pub mod transitions; + +pub use contract_bounds::ContractBoundsWasm; +pub use document::DocumentWasm; +pub use model::{DataContractWasm, tokens_configuration_from_js_value}; +pub use transitions::create::DataContractCreateTransitionWasm; +pub use transitions::update::DataContractUpdateTransitionWasm; diff --git a/packages/wasm-dpp2/src/data_contract/model.rs b/packages/wasm-dpp2/src/data_contract/model.rs new file mode 100644 index 00000000000..69f3d768a3d --- /dev/null +++ b/packages/wasm-dpp2/src/data_contract/model.rs @@ -0,0 +1,529 @@ +use crate::enums::platform::PlatformVersionWasm; +use crate::error::{WasmDppError, WasmDppResult}; +use crate::identifier::IdentifierWasm; +use crate::tokens::configuration::TokenConfigurationWasm; +use crate::tokens::configuration::group::GroupWasm; +use crate::utils::{IntoWasm, JsValueExt, ToSerdeJSONExt}; +use dpp::dashcore::hashes::serde::Serialize; +use dpp::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters}; +use dpp::data_contract::accessors::v1::{DataContractV1Getters, DataContractV1Setters}; +use dpp::data_contract::config::DataContractConfig; +use dpp::data_contract::conversion::json::DataContractJsonConversionMethodsV0; +use dpp::data_contract::conversion::value::v0::DataContractValueConversionMethodsV0; +use dpp::data_contract::document_type::DocumentTypeRef; +use dpp::data_contract::errors::DataContractError; +use dpp::data_contract::group::Group; +use dpp::data_contract::schema::DataContractSchemaMethodsV0; +use dpp::data_contract::{ + DataContract, GroupContractPosition, TokenConfiguration, TokenContractPosition, +}; +use dpp::platform_value::string_encoding::Encoding::{Base58, Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::platform_value::{Value, ValueMap}; +use dpp::prelude::IdentityNonce; +use dpp::serialization::{ + PlatformDeserializableWithPotentialValidationFromVersionedStructure, + PlatformSerializableWithPlatformVersion, +}; +use dpp::version::PlatformVersion; +use js_sys::{Object, Reflect}; +use std::collections::BTreeMap; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "DataContract")] +#[derive(Clone)] +pub struct DataContractWasm(DataContract); + +impl From for DataContractWasm { + fn from(v: DataContract) -> Self { + DataContractWasm(v) + } +} + +impl From for DataContract { + fn from(v: DataContractWasm) -> Self { + v.0 + } +} + +pub fn tokens_configuration_from_js_value( + js_configuration: &JsValue, +) -> WasmDppResult> { + let configuration_object = Object::from(js_configuration.clone()); + let configuration_keys = Object::keys(&configuration_object); + + let mut configuration: BTreeMap = BTreeMap::new(); + + for key in configuration_keys.iter() { + let contract_position = match key.as_string() { + None => Err(WasmDppError::invalid_argument( + "Cannot read timestamp in distribution rules", + )), + Some(contract_position) => Ok(contract_position + .parse::() + .map_err(|e| WasmDppError::serialization(e.to_string()))?), + }?; + + let js_config = Reflect::get(&configuration_object, &key) + .map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "unable to read token configuration at contract position '{}': {}", + contract_position, message + )) + })? + .to_wasm::("TokenConfiguration")? + .clone(); + + configuration.insert(contract_position, js_config.into()); + } + + Ok(configuration) +} + +#[wasm_bindgen(js_class = DataContract)] +impl DataContractWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "DataContract".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "DataContract".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn from_js_values( + js_owner_id: &JsValue, + identity_nonce: IdentityNonce, + js_schema: JsValue, + js_definitions: Option, + js_tokens: &JsValue, + full_validation: bool, + js_platform_version: JsValue, + ) -> WasmDppResult { + let serializer = serde_wasm_bindgen::Serializer::json_compatible(); + + let owner_id: IdentifierWasm = js_owner_id.clone().try_into()?; + + let owner_id_value = Value::from(owner_id.get_base58()); + + let schema: Value = serde_wasm_bindgen::from_value(js_schema) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + let tokens: BTreeMap = + match js_tokens.is_undefined() { + true => BTreeMap::new(), + false => tokens_configuration_from_js_value(js_tokens)?, + }; + + let platform_version: PlatformVersion = match js_platform_version.is_undefined() { + true => PlatformVersionWasm::default().into(), + false => PlatformVersionWasm::try_from(js_platform_version)?.into(), + }; + + let data_contract_structure_version_value = Value::from( + platform_version + .dpp + .contract_versions + .contract_structure_version + .to_string(), + ); + + let definitions = js_definitions + .map(|definitions| serde_wasm_bindgen::from_value(definitions.into())) + .transpose() + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + let definitions_value = Value::from(definitions); + + let data_contract_id = + DataContract::generate_data_contract_id_v0(owner_id.to_bytes(), identity_nonce); + + let data_contract_id_value = Value::from(data_contract_id.to_string(Base58)); + + let config = DataContractConfig::default_for_version(&platform_version.clone())?; + + let config_value = config + .serialize(&serializer) + .map_err(|e| WasmDppError::serialization(e.to_string()))? + .with_serde_to_platform_value_map()?; + + let mut contract_value = Value::Map(ValueMap::new()); + + contract_value + .set_value("$format_version", data_contract_structure_version_value) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + contract_value + .set_value("id", data_contract_id_value) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + contract_value + .set_value("config", Value::from(config_value)) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + contract_value + .set_value("version", Value::from(1u16)) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + contract_value + .set_value("ownerId", owner_id_value) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + contract_value + .set_value("schemaDefs", definitions_value) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + contract_value + .set_value("documentSchemas", schema) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + let data_contract = + DataContract::from_value(contract_value, full_validation, &platform_version)?; + + let data_contract_with_tokens = match data_contract { + DataContract::V0(v0) => DataContract::from(v0), + DataContract::V1(mut v1) => { + v1.set_tokens(tokens); + + DataContract::from(v1) + } + }; + + Ok(DataContractWasm(data_contract_with_tokens)) + } + + #[wasm_bindgen(js_name = "fromValue")] + pub fn from_value( + js_value: JsValue, + full_validation: bool, + js_platform_version: JsValue, + ) -> WasmDppResult { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, + }; + + let value = js_value.with_serde_to_platform_value()?; + + let contract = DataContract::from_value(value, full_validation, &platform_version.into())?; + + Ok(DataContractWasm(contract)) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes( + bytes: Vec, + full_validation: bool, + js_platform_version: JsValue, + ) -> WasmDppResult { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, + }; + + let rs_data_contract = DataContract::versioned_deserialize( + &bytes.as_slice(), + full_validation, + &platform_version.into(), + )?; + + Ok(DataContractWasm(rs_data_contract)) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex( + hex: String, + full_validation: bool, + js_platform_version: JsValue, + ) -> WasmDppResult { + let bytes = + decode(hex.as_str(), Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; + + DataContractWasm::from_bytes(bytes, full_validation, js_platform_version) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64( + base64: String, + full_validation: bool, + js_platform_version: JsValue, + ) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; + + DataContractWasm::from_bytes(bytes, full_validation, js_platform_version) + } + + #[wasm_bindgen(js_name = "toBytes")] + pub fn to_bytes(&self, js_platform_version: JsValue) -> WasmDppResult> { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, + }; + + let rs_data_contract: DataContract = self.0.clone(); + + Ok(rs_data_contract.serialize_to_bytes_with_platform_version(&platform_version.into())?) + } + + #[wasm_bindgen(js_name = "toHex")] + pub fn to_hex(&self, js_platform_version: JsValue) -> WasmDppResult { + Ok(encode(self.to_bytes(js_platform_version)?.as_slice(), Hex)) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self, js_platform_version: JsValue) -> WasmDppResult { + Ok(encode( + self.to_bytes(js_platform_version)?.as_slice(), + Base64, + )) + } + + #[wasm_bindgen(js_name = "toValue")] + pub fn to_value(&self, js_platform_version: JsValue) -> WasmDppResult { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, + }; + + let serializer = serde_wasm_bindgen::Serializer::json_compatible(); + + self.0 + .clone() + .to_value(&platform_version.into())? + .serialize(&serializer) + .map_err(|e| WasmDppError::serialization(e.to_string())) + } + + #[wasm_bindgen(js_name = "getSchemas")] + pub fn get_schemas(&self) -> WasmDppResult { + let serializer = serde_wasm_bindgen::Serializer::json_compatible(); + + self.0 + .document_schemas() + .serialize(&serializer) + .map_err(|e| WasmDppError::serialization(e.to_string())) + } + + #[wasm_bindgen(getter = "version")] + pub fn get_version(&self) -> u32 { + self.0.version() + } + + #[wasm_bindgen(getter = "id")] + pub fn get_id(&self) -> IdentifierWasm { + self.0.id().into() + } + + #[wasm_bindgen(getter = "ownerId")] + pub fn get_owner_id(&self) -> IdentifierWasm { + self.0.owner_id().into() + } + + #[wasm_bindgen(js_name = "getConfig")] + pub fn get_config(&self) -> WasmDppResult { + self.0 + .config() + .serialize(&serde_wasm_bindgen::Serializer::json_compatible()) + .map_err(|e| WasmDppError::serialization(e.to_string())) + } + + #[wasm_bindgen(getter = "tokens")] + pub fn get_tokens(&self) -> WasmDppResult { + let tokens_object = Object::new(); + + for (key, value) in self.0.tokens().iter() { + Reflect::set( + &tokens_object, + &JsValue::from(key.clone()), + &JsValue::from(TokenConfigurationWasm::from(value.clone())), + ) + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to serialize token configuration at position '{}': {}", + key, message + )) + })?; + } + + Ok(tokens_object) + } + + #[wasm_bindgen(getter = "groups")] + pub fn get_groups(&self) -> WasmDppResult { + let groups_object = Object::new(); + + for (key, value) in self.0.groups().iter() { + Reflect::set( + &groups_object, + &JsValue::from(key.clone()), + &JsValue::from(GroupWasm::from(value.clone())), + ) + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to serialize group at position '{}': {}", + key, message + )) + })?; + } + + Ok(groups_object.into()) + } + + #[wasm_bindgen(setter = "id")] + pub fn set_id(&mut self, js_data_contract_id: &JsValue) -> WasmDppResult<()> { + self.0 + .set_id(IdentifierWasm::try_from(js_data_contract_id)?.into()); + Ok(()) + } + + #[wasm_bindgen(setter = "ownerId")] + pub fn set_owner_id(&mut self, js_owner_id: &JsValue) -> WasmDppResult<()> { + self.0 + .set_owner_id(IdentifierWasm::try_from(js_owner_id)?.into()); + Ok(()) + } + + #[wasm_bindgen(setter = "version")] + pub fn set_version(&mut self, version: u32) { + self.0.set_version(version) + } + + #[wasm_bindgen(js_name = "setConfig")] + pub fn set_config( + &mut self, + js_config: JsValue, + js_platform_version: JsValue, + ) -> WasmDppResult<()> { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, + }; + + let config_value: Value = serde_wasm_bindgen::from_value(js_config) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + let config = DataContractConfig::from_value(config_value, &platform_version.into())?; + + self.0.set_config(config); + + Ok(()) + } + + #[wasm_bindgen(js_name = "setSchemas")] + pub fn set_schemas( + &mut self, + js_schema: JsValue, + js_definitions: Option, + full_validation: bool, + js_platform_version: JsValue, + ) -> WasmDppResult<()> { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, + }; + + let schema = js_schema.with_serde_to_platform_value_map()?; + + let definitions: Option> = js_definitions + .map(|definitions| serde_wasm_bindgen::from_value(definitions.into())) + .transpose() + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + self.0.set_document_schemas( + schema, + definitions, + full_validation, + &mut Vec::new(), + &platform_version.into(), + )?; + + Ok(()) + } + + #[wasm_bindgen(setter = "tokens")] + pub fn set_tokens(&mut self, js_tokens: &JsValue) -> WasmDppResult<()> { + self.0 + .set_tokens(tokens_configuration_from_js_value(js_tokens)?); + Ok(()) + } + + #[wasm_bindgen(setter = "groups")] + pub fn set_groups(&mut self, js_groups: &JsValue) -> WasmDppResult<()> { + let groups_object = Object::from(js_groups.clone()); + + let mut groups: BTreeMap = BTreeMap::new(); + + for js_position in Object::keys(&groups_object) { + let position_str = js_position.as_string().ok_or_else(|| { + WasmDppError::invalid_argument(format!( + "Group position '{:?}' must be a stringified number.", + js_position + )) + })?; + + let position = position_str.parse::().map_err(|err| { + WasmDppError::invalid_argument(format!( + "Invalid group position '{}': {}.", + position_str, err + )) + })?; + + let js_group = Reflect::get(&groups_object, &js_position).map_err(|err| { + let message = err.error_message(); + WasmDppError::invalid_argument(format!( + "unable to read group at position '{}': {}", + position_str, message + )) + })?; + + let group = js_group.to_wasm::("Group")?.clone(); + + groups.insert(position, group.into()); + } + + self.0.set_groups(groups); + + Ok(()) + } + + #[wasm_bindgen(js_name = "toJSON")] + pub fn to_json(&self, js_platform_version: JsValue) -> WasmDppResult { + let platform_version = match js_platform_version.is_undefined() { + true => PlatformVersionWasm::default(), + false => PlatformVersionWasm::try_from(js_platform_version)?, + }; + + let json = self.0.to_json(&platform_version.into())?; + + json.serialize(&serde_wasm_bindgen::Serializer::json_compatible()) + .map_err(|e| WasmDppError::serialization(e.to_string())) + } + + #[wasm_bindgen(js_name = "generateId")] + pub fn generate_id( + js_owner_id: &JsValue, + identity_nonce: IdentityNonce, + ) -> WasmDppResult { + Ok(DataContract::generate_data_contract_id_v0( + IdentifierWasm::try_from(js_owner_id)?.to_bytes(), + identity_nonce, + ) + .into()) + } +} + +impl DataContractWasm { + pub fn get_document_type_ref_by_name( + &self, + name: String, + ) -> Result, DataContractError> { + self.0.document_type_for_name(name.as_str()).clone() + } +} diff --git a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs b/packages/wasm-dpp2/src/data_contract/transitions/create/mod.rs similarity index 99% rename from packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs rename to packages/wasm-dpp2/src/data_contract/transitions/create/mod.rs index fcc5cb11ee7..8eefbcb3db1 100644 --- a/packages/wasm-dpp2/src/data_contract_transitions/create/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/transitions/create/mod.rs @@ -1,7 +1,7 @@ use crate::data_contract::DataContractWasm; use crate::enums::platform::PlatformVersionWasm; use crate::error::{WasmDppError, WasmDppResult}; -use crate::state_transition::StateTransitionWasm; +use crate::state_transitions::StateTransitionWasm; use dpp::data_contract::serialized_version::DataContractInSerializationFormat; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; use dpp::platform_value::string_encoding::{decode, encode}; diff --git a/packages/wasm-dpp2/src/data_contract_transitions/mod.rs b/packages/wasm-dpp2/src/data_contract/transitions/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/data_contract_transitions/mod.rs rename to packages/wasm-dpp2/src/data_contract/transitions/mod.rs diff --git a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs b/packages/wasm-dpp2/src/data_contract/transitions/update/mod.rs similarity index 99% rename from packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs rename to packages/wasm-dpp2/src/data_contract/transitions/update/mod.rs index dcb92de98ca..60a793267ec 100644 --- a/packages/wasm-dpp2/src/data_contract_transitions/update/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/transitions/update/mod.rs @@ -1,7 +1,7 @@ use crate::data_contract::DataContractWasm; use crate::enums::platform::PlatformVersionWasm; use crate::error::{WasmDppError, WasmDppResult}; -use crate::state_transition::StateTransitionWasm; +use crate::state_transitions::StateTransitionWasm; use dpp::data_contract::serialized_version::DataContractInSerializationFormat; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; use dpp::platform_value::string_encoding::{decode, encode}; diff --git a/packages/wasm-dpp2/src/masternode_vote/mod.rs b/packages/wasm-dpp2/src/identity/governance/masternode_vote/mod.rs similarity index 98% rename from packages/wasm-dpp2/src/masternode_vote/mod.rs rename to packages/wasm-dpp2/src/identity/governance/masternode_vote/mod.rs index 570c06f23d8..1aa28eeaa9c 100644 --- a/packages/wasm-dpp2/src/masternode_vote/mod.rs +++ b/packages/wasm-dpp2/src/identity/governance/masternode_vote/mod.rs @@ -5,8 +5,8 @@ pub mod vote_poll; use crate::asset_lock_proof::AssetLockProofWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::masternode_vote::vote::VoteWasm; -use crate::state_transition::StateTransitionWasm; +use crate::identity::governance::masternode_vote::vote::VoteWasm; +use crate::state_transitions::StateTransitionWasm; use dpp::identity::KeyID; use dpp::identity::state_transition::OptionallyAssetLockProved; use dpp::platform_value::BinaryData; diff --git a/packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs b/packages/wasm-dpp2/src/identity/governance/masternode_vote/resource_vote_choice/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/masternode_vote/resource_vote_choice/mod.rs rename to packages/wasm-dpp2/src/identity/governance/masternode_vote/resource_vote_choice/mod.rs diff --git a/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs b/packages/wasm-dpp2/src/identity/governance/masternode_vote/vote/mod.rs similarity index 93% rename from packages/wasm-dpp2/src/masternode_vote/vote/mod.rs rename to packages/wasm-dpp2/src/identity/governance/masternode_vote/vote/mod.rs index a86b48e0bf7..8e793102f31 100644 --- a/packages/wasm-dpp2/src/masternode_vote/vote/mod.rs +++ b/packages/wasm-dpp2/src/identity/governance/masternode_vote/vote/mod.rs @@ -1,5 +1,5 @@ -use crate::masternode_vote::resource_vote_choice::ResourceVoteChoiceWasm; -use crate::masternode_vote::vote_poll::VotePollWasm; +use crate::identity::governance::masternode_vote::resource_vote_choice::ResourceVoteChoiceWasm; +use crate::identity::governance::masternode_vote::vote_poll::VotePollWasm; use dpp::voting::votes::Vote; use dpp::voting::votes::resource_vote::ResourceVote; use dpp::voting::votes::resource_vote::accessors::v0::ResourceVoteGettersV0; diff --git a/packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs b/packages/wasm-dpp2/src/identity/governance/masternode_vote/vote_poll/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/masternode_vote/vote_poll/mod.rs rename to packages/wasm-dpp2/src/identity/governance/masternode_vote/vote_poll/mod.rs diff --git a/packages/wasm-dpp2/src/identity/governance/mod.rs b/packages/wasm-dpp2/src/identity/governance/mod.rs new file mode 100644 index 00000000000..391735c6b93 --- /dev/null +++ b/packages/wasm-dpp2/src/identity/governance/mod.rs @@ -0,0 +1,6 @@ +pub mod masternode_vote; + +pub use masternode_vote::MasternodeVoteTransitionWasm; +pub use masternode_vote::resource_vote_choice::ResourceVoteChoiceWasm; +pub use masternode_vote::vote::VoteWasm; +pub use masternode_vote::vote_poll::VotePollWasm; diff --git a/packages/wasm-dpp2/src/identity/mod.rs b/packages/wasm-dpp2/src/identity/mod.rs index d3beb34195f..80974248901 100644 --- a/packages/wasm-dpp2/src/identity/mod.rs +++ b/packages/wasm-dpp2/src/identity/mod.rs @@ -1,190 +1,18 @@ -use crate::error::{WasmDppError, WasmDppResult}; -use crate::identifier::IdentifierWasm; -use crate::identity_public_key::IdentityPublicKeyWasm; -use dpp::identity::accessors::{IdentityGettersV0, IdentitySettersV0}; -use dpp::identity::{self, Identity, KeyID}; -use dpp::platform_value::ReplacementType; -use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; -use dpp::platform_value::string_encoding::{decode, encode}; -use dpp::prelude::IdentityPublicKey; -use dpp::serialization::{PlatformDeserializable, PlatformSerializable, ValueConvertible}; -use dpp::version::PlatformVersion; -use serde_json::Value as JsonValue; -use serde_wasm_bindgen::to_value; -use std::collections::BTreeMap; -use wasm_bindgen::JsValue; -use wasm_bindgen::prelude::wasm_bindgen; - -#[derive(Clone)] -#[wasm_bindgen(js_name = "Identity")] -pub struct IdentityWasm(Identity); - -impl From for IdentityWasm { - fn from(identity: Identity) -> Self { - Self(identity) - } -} - -#[wasm_bindgen(js_class = Identity)] -impl IdentityWasm { - #[wasm_bindgen(getter = __type)] - pub fn type_name(&self) -> String { - "Identity".to_string() - } - - #[wasm_bindgen(getter = __struct)] - pub fn struct_name() -> String { - "Identity".to_string() - } - - #[wasm_bindgen(constructor)] - pub fn new(js_identifier: &JsValue) -> WasmDppResult { - let identifier = IdentifierWasm::try_from(js_identifier)?; - - let identity = - Identity::create_basic_identity(identifier.into(), PlatformVersion::first())?; - - Ok(IdentityWasm(identity)) - } - - #[wasm_bindgen(setter = "id")] - pub fn set_id(&mut self, js_identifier: &JsValue) -> WasmDppResult<()> { - let identifier = IdentifierWasm::try_from(js_identifier)?; - self.0.set_id(identifier.into()); - Ok(()) - } - - #[wasm_bindgen(setter = "balance")] - pub fn set_balance(&mut self, balance: u64) { - self.0.set_balance(balance); - } - - #[wasm_bindgen(setter = "revision")] - pub fn set_revision(&mut self, revision: u64) { - self.0.set_revision(revision); - } - - #[wasm_bindgen(js_name = "addPublicKey")] - pub fn add_public_key(&mut self, public_key: &IdentityPublicKeyWasm) { - self.0.add_public_key(public_key.clone().into()); - } - - // GETTERS - - #[wasm_bindgen(getter = "id")] - pub fn get_id(&self) -> IdentifierWasm { - self.0.id().into() - } - - #[wasm_bindgen(getter = "balance")] - pub fn get_balance(&self) -> u64 { - self.0.balance() - } - - #[wasm_bindgen(getter = "revision")] - pub fn get_revision(&self) -> u64 { - self.0.revision() - } - - #[wasm_bindgen(js_name = "getPublicKeyById")] - pub fn get_public_key_by_id(&self, key_id: KeyID) -> IdentityPublicKeyWasm { - let identity_public_key = self.0.get_public_key_by_id(key_id); - IdentityPublicKeyWasm::from(identity_public_key.unwrap().clone()) - } - - #[wasm_bindgen(js_name = "getPublicKeys")] - pub fn get_public_keys(&self) -> Vec { - let keys = self - .0 - .public_keys() - .iter() - .map(|(_index, key)| IdentityPublicKeyWasm::from(key.clone())) - .collect(); - - keys - } - - #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> WasmDppResult { - let bytes = - decode(hex.as_str(), Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; - - IdentityWasm::from_bytes(bytes) - } - - #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> WasmDppResult { - let bytes = decode(base64.as_str(), Base64) - .map_err(|e| WasmDppError::serialization(e.to_string()))?; - - IdentityWasm::from_bytes(bytes) - } - - #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> WasmDppResult> { - Ok(self.0.serialize_to_bytes()?) - } - - #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self) -> WasmDppResult { - let bytes = self.0.serialize_to_bytes()?; - Ok(encode(bytes.as_slice(), Hex)) - } - - #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self) -> WasmDppResult { - let bytes = self.0.serialize_to_bytes()?; - Ok(encode(bytes.as_slice(), Base64)) - } - - fn cleaned_json_value(&self) -> WasmDppResult { - let mut value = self.0.to_object()?; - - value - .replace_at_paths( - identity::IDENTIFIER_FIELDS_RAW_OBJECT, - ReplacementType::TextBase58, - ) - .map_err(|e| WasmDppError::serialization(e.to_string()))?; - - if let Some(public_keys) = value - .get_optional_array_mut_ref(identity::property_names::PUBLIC_KEYS) - .map_err(|e| WasmDppError::serialization(e.to_string()))? - { - for key in public_keys.iter_mut() { - key.replace_at_paths( - identity::identity_public_key::BINARY_DATA_FIELDS, - ReplacementType::TextBase64, - ) - .map_err(|e| WasmDppError::serialization(e.to_string()))?; - } - } - - value - .try_into_validating_json() - .map_err(|e| WasmDppError::serialization(e.to_string())) - } - - #[wasm_bindgen(js_name = "toObject")] - pub fn to_object(&self) -> WasmDppResult { - let json_value = self.cleaned_json_value()?; - to_value(&json_value).map_err(|e| WasmDppError::serialization(e.to_string())) - } - - #[wasm_bindgen(js_name = "toJSON")] - pub fn to_json(&self) -> WasmDppResult { - self.to_object() - } - - #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> WasmDppResult { - let identity = Identity::deserialize_from_bytes(bytes.as_slice())?; - Ok(IdentityWasm(identity)) - } -} - -impl IdentityWasm { - pub fn get_rs_public_keys(&self) -> BTreeMap { - self.0.public_keys().clone() - } -} +pub mod governance; +pub mod model; +pub mod partial_identity; +pub mod public_key; +pub mod transitions; + +pub use governance::{ + MasternodeVoteTransitionWasm, ResourceVoteChoiceWasm, VotePollWasm, VoteWasm, +}; +pub use model::IdentityWasm; +pub use partial_identity::PartialIdentityWasm; +pub use public_key::IdentityPublicKeyWasm; +pub use transitions::create_transition::IdentityCreateTransitionWasm; +pub use transitions::credit_withdrawal_transition::IdentityCreditWithdrawalTransitionWasm; +pub use transitions::identity_credit_transfer_transition::IdentityCreditTransferWasm; +pub use transitions::public_key_in_creation::IdentityPublicKeyInCreationWasm; +pub use transitions::top_up_transition::IdentityTopUpTransitionWasm; +pub use transitions::update_transition::IdentityUpdateTransitionWasm; diff --git a/packages/wasm-dpp2/src/identity/model.rs b/packages/wasm-dpp2/src/identity/model.rs new file mode 100644 index 00000000000..6020210f173 --- /dev/null +++ b/packages/wasm-dpp2/src/identity/model.rs @@ -0,0 +1,190 @@ +use crate::error::{WasmDppError, WasmDppResult}; +use crate::identifier::IdentifierWasm; +use crate::identity::public_key::IdentityPublicKeyWasm; +use dpp::identity::accessors::{IdentityGettersV0, IdentitySettersV0}; +use dpp::identity::{self, Identity, KeyID}; +use dpp::platform_value::ReplacementType; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::prelude::IdentityPublicKey; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable, ValueConvertible}; +use dpp::version::PlatformVersion; +use serde_json::Value as JsonValue; +use serde_wasm_bindgen::to_value; +use std::collections::BTreeMap; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name = "Identity")] +pub struct IdentityWasm(Identity); + +impl From for IdentityWasm { + fn from(identity: Identity) -> Self { + Self(identity) + } +} + +#[wasm_bindgen(js_class = Identity)] +impl IdentityWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "Identity".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "Identity".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(js_identifier: &JsValue) -> WasmDppResult { + let identifier = IdentifierWasm::try_from(js_identifier)?; + + let identity = + Identity::create_basic_identity(identifier.into(), PlatformVersion::first())?; + + Ok(IdentityWasm(identity)) + } + + #[wasm_bindgen(setter = "id")] + pub fn set_id(&mut self, js_identifier: &JsValue) -> WasmDppResult<()> { + let identifier = IdentifierWasm::try_from(js_identifier)?; + self.0.set_id(identifier.into()); + Ok(()) + } + + #[wasm_bindgen(setter = "balance")] + pub fn set_balance(&mut self, balance: u64) { + self.0.set_balance(balance); + } + + #[wasm_bindgen(setter = "revision")] + pub fn set_revision(&mut self, revision: u64) { + self.0.set_revision(revision); + } + + #[wasm_bindgen(js_name = "addPublicKey")] + pub fn add_public_key(&mut self, public_key: &IdentityPublicKeyWasm) { + self.0.add_public_key(public_key.clone().into()); + } + + // GETTERS + + #[wasm_bindgen(getter = "id")] + pub fn get_id(&self) -> IdentifierWasm { + self.0.id().into() + } + + #[wasm_bindgen(getter = "balance")] + pub fn get_balance(&self) -> u64 { + self.0.balance() + } + + #[wasm_bindgen(getter = "revision")] + pub fn get_revision(&self) -> u64 { + self.0.revision() + } + + #[wasm_bindgen(js_name = "getPublicKeyById")] + pub fn get_public_key_by_id(&self, key_id: KeyID) -> IdentityPublicKeyWasm { + let identity_public_key = self.0.get_public_key_by_id(key_id); + IdentityPublicKeyWasm::from(identity_public_key.unwrap().clone()) + } + + #[wasm_bindgen(js_name = "getPublicKeys")] + pub fn get_public_keys(&self) -> Vec { + let keys = self + .0 + .public_keys() + .iter() + .map(|(_index, key)| IdentityPublicKeyWasm::from(key.clone())) + .collect(); + + keys + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = + decode(hex.as_str(), Hex).map_err(|e| WasmDppError::serialization(e.to_string()))?; + + IdentityWasm::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; + + IdentityWasm::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "toBytes")] + pub fn to_bytes(&self) -> WasmDppResult> { + Ok(self.0.serialize_to_bytes()?) + } + + #[wasm_bindgen(js_name = "toHex")] + pub fn to_hex(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; + Ok(encode(bytes.as_slice(), Hex)) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> WasmDppResult { + let bytes = self.0.serialize_to_bytes()?; + Ok(encode(bytes.as_slice(), Base64)) + } + + fn cleaned_json_value(&self) -> WasmDppResult { + let mut value = self.0.to_object()?; + + value + .replace_at_paths( + identity::IDENTIFIER_FIELDS_RAW_OBJECT, + ReplacementType::TextBase58, + ) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; + + if let Some(public_keys) = value + .get_optional_array_mut_ref(identity::property_names::PUBLIC_KEYS) + .map_err(|e| WasmDppError::serialization(e.to_string()))? + { + for key in public_keys.iter_mut() { + key.replace_at_paths( + identity::identity_public_key::BINARY_DATA_FIELDS, + ReplacementType::TextBase64, + ) + .map_err(|e| WasmDppError::serialization(e.to_string()))?; + } + } + + value + .try_into_validating_json() + .map_err(|e| WasmDppError::serialization(e.to_string())) + } + + #[wasm_bindgen(js_name = "toObject")] + pub fn to_object(&self) -> WasmDppResult { + let json_value = self.cleaned_json_value()?; + to_value(&json_value).map_err(|e| WasmDppError::serialization(e.to_string())) + } + + #[wasm_bindgen(js_name = "toJSON")] + pub fn to_json(&self) -> WasmDppResult { + self.to_object() + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> WasmDppResult { + let identity = Identity::deserialize_from_bytes(bytes.as_slice())?; + Ok(IdentityWasm(identity)) + } +} + +impl IdentityWasm { + pub fn get_rs_public_keys(&self) -> BTreeMap { + self.0.public_keys().clone() + } +} diff --git a/packages/wasm-dpp2/src/partial_identity/mod.rs b/packages/wasm-dpp2/src/identity/partial_identity/mod.rs similarity index 99% rename from packages/wasm-dpp2/src/partial_identity/mod.rs rename to packages/wasm-dpp2/src/identity/partial_identity/mod.rs index dbac05a5257..3b9bdb3fd81 100644 --- a/packages/wasm-dpp2/src/partial_identity/mod.rs +++ b/packages/wasm-dpp2/src/identity/partial_identity/mod.rs @@ -1,6 +1,6 @@ use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::identity_public_key::IdentityPublicKeyWasm; +use crate::identity::public_key::IdentityPublicKeyWasm; use crate::utils::{IntoWasm, JsValueExt}; use dpp::fee::Credits; use dpp::identity::{IdentityPublicKey, KeyID, PartialIdentity}; diff --git a/packages/wasm-dpp2/src/identity_public_key/mod.rs b/packages/wasm-dpp2/src/identity/public_key/mod.rs similarity index 99% rename from packages/wasm-dpp2/src/identity_public_key/mod.rs rename to packages/wasm-dpp2/src/identity/public_key/mod.rs index 95ae9f1f245..dfa8ec8d058 100644 --- a/packages/wasm-dpp2/src/identity_public_key/mod.rs +++ b/packages/wasm-dpp2/src/identity/public_key/mod.rs @@ -1,4 +1,4 @@ -use crate::contract_bounds::ContractBoundsWasm; +use crate::data_contract::contract_bounds::ContractBoundsWasm; use crate::enums::keys::key_type::KeyTypeWasm; use crate::enums::keys::purpose::PurposeWasm; use crate::enums::keys::security_level::SecurityLevelWasm; diff --git a/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs b/packages/wasm-dpp2/src/identity/transitions/create_transition/mod.rs similarity index 97% rename from packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/create_transition/mod.rs index 34bab76d618..57a68060814 100644 --- a/packages/wasm-dpp2/src/identity_transitions/create_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity/transitions/create_transition/mod.rs @@ -2,8 +2,8 @@ use crate::asset_lock_proof::AssetLockProofWasm; use crate::enums::platform::PlatformVersionWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::identity_transitions::public_key_in_creation::IdentityPublicKeyInCreationWasm; -use crate::state_transition::StateTransitionWasm; +use crate::identity::transitions::public_key_in_creation::IdentityPublicKeyInCreationWasm; +use crate::state_transitions::StateTransitionWasm; use dpp::identity::state_transition::AssetLockProved; use dpp::platform_value::BinaryData; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; diff --git a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs b/packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition/mod.rs similarity index 99% rename from packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition/mod.rs index bc339e62f79..7527e66c32f 100644 --- a/packages/wasm-dpp2/src/identity_transitions/credit_withdrawal_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition/mod.rs @@ -4,7 +4,7 @@ use crate::enums::keys::purpose::PurposeWasm; use crate::enums::withdrawal::PoolingWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::state_transition::StateTransitionWasm; +use crate::state_transitions::StateTransitionWasm; use crate::utils::IntoWasm; use dpp::identity::KeyID; use dpp::identity::core_script::CoreScript; diff --git a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs b/packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition/mod.rs similarity index 99% rename from packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition/mod.rs index f9e7150fdb7..6140e384947 100644 --- a/packages/wasm-dpp2/src/identity_transitions/identity_credit_transfer_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition/mod.rs @@ -1,6 +1,6 @@ use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::state_transition::StateTransitionWasm; +use crate::state_transitions::StateTransitionWasm; use dpp::platform_value::BinaryData; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; use dpp::platform_value::string_encoding::{decode, encode}; diff --git a/packages/wasm-dpp2/src/identity_transitions/mod.rs b/packages/wasm-dpp2/src/identity/transitions/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/identity_transitions/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/mod.rs diff --git a/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs b/packages/wasm-dpp2/src/identity/transitions/public_key_in_creation/mod.rs similarity index 98% rename from packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/public_key_in_creation/mod.rs index 2751a018041..a5073584dfe 100644 --- a/packages/wasm-dpp2/src/identity_transitions/public_key_in_creation/mod.rs +++ b/packages/wasm-dpp2/src/identity/transitions/public_key_in_creation/mod.rs @@ -1,9 +1,9 @@ -use crate::contract_bounds::ContractBoundsWasm; +use crate::data_contract::contract_bounds::ContractBoundsWasm; use crate::enums::keys::key_type::KeyTypeWasm; use crate::enums::keys::purpose::PurposeWasm; use crate::enums::keys::security_level::SecurityLevelWasm; use crate::error::{WasmDppError, WasmDppResult}; -use crate::identity_public_key::IdentityPublicKeyWasm; +use crate::identity::public_key::IdentityPublicKeyWasm; use crate::utils::IntoWasm; use dpp::identity::contract_bounds::ContractBounds; use dpp::identity::identity_public_key::v0::IdentityPublicKeyV0; diff --git a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs b/packages/wasm-dpp2/src/identity/transitions/top_up_transition/mod.rs similarity index 99% rename from packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/top_up_transition/mod.rs index 9c4b6f3ba12..7faab098e3b 100644 --- a/packages/wasm-dpp2/src/identity_transitions/top_up_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity/transitions/top_up_transition/mod.rs @@ -1,7 +1,7 @@ use crate::asset_lock_proof::AssetLockProofWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::state_transition::StateTransitionWasm; +use crate::state_transitions::StateTransitionWasm; use dpp::identifier::Identifier; use dpp::identity::state_transition::{AssetLockProved, OptionallyAssetLockProved}; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; diff --git a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs b/packages/wasm-dpp2/src/identity/transitions/update_transition/mod.rs similarity index 98% rename from packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/update_transition/mod.rs index 803c587d4da..cfdfb48d763 100644 --- a/packages/wasm-dpp2/src/identity_transitions/update_transition/mod.rs +++ b/packages/wasm-dpp2/src/identity/transitions/update_transition/mod.rs @@ -2,8 +2,8 @@ use crate::asset_lock_proof::AssetLockProofWasm; use crate::enums::keys::purpose::PurposeWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::identity_transitions::public_key_in_creation::IdentityPublicKeyInCreationWasm; -use crate::state_transition::StateTransitionWasm; +use crate::identity::transitions::public_key_in_creation::IdentityPublicKeyInCreationWasm; +use crate::state_transitions::StateTransitionWasm; use dpp::identity::KeyID; use dpp::identity::state_transition::OptionallyAssetLockProved; use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; diff --git a/packages/wasm-dpp2/src/lib.rs b/packages/wasm-dpp2/src/lib.rs index ccaea68839c..3bc07b7a300 100644 --- a/packages/wasm-dpp2/src/lib.rs +++ b/packages/wasm-dpp2/src/lib.rs @@ -10,27 +10,35 @@ // }; pub mod asset_lock_proof; -pub mod batch; pub mod consensus_error; -pub mod contract_bounds; pub mod core_script; pub mod data_contract; -pub mod data_contract_transitions; -pub mod document; -pub mod encrypted_note; pub mod enums; pub mod error; -pub mod group_state_transition_info; pub mod identifier; pub mod identity; -pub mod identity_public_key; -pub mod identity_transitions; -pub mod masternode_vote; pub mod mock_bls; -pub mod partial_identity; pub mod private_key; pub mod public_key; -pub mod state_transition; -pub mod token_configuration; -pub mod token_configuration_change_item; +pub mod state_transitions; +pub mod tokens; pub mod utils; + +pub use data_contract::{ + ContractBoundsWasm, DataContractCreateTransitionWasm, DataContractUpdateTransitionWasm, + DataContractWasm, DocumentWasm, +}; + +pub use identity::{ + IdentityCreateTransitionWasm, IdentityCreditTransferWasm, + IdentityCreditWithdrawalTransitionWasm, IdentityPublicKeyInCreationWasm, IdentityPublicKeyWasm, + IdentityTopUpTransitionWasm, IdentityUpdateTransitionWasm, MasternodeVoteTransitionWasm, + PartialIdentityWasm, ResourceVoteChoiceWasm, VotePollWasm, VoteWasm, +}; + +pub use state_transitions::base::{GroupStateTransitionInfoWasm, StateTransitionWasm}; + +pub use tokens::{ + AuthorizedActionTakersWasm, GroupWasm, PrivateEncryptedNoteWasm, SharedEncryptedNoteWasm, + TokenConfigurationChangeItemWasm, TokenConfigurationLocalizationWasm, TokenConfigurationWasm, +}; diff --git a/packages/wasm-dpp2/src/group_state_transition_info/mod.rs b/packages/wasm-dpp2/src/state_transitions/base/group_state_transition_info/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/group_state_transition_info/mod.rs rename to packages/wasm-dpp2/src/state_transitions/base/group_state_transition_info/mod.rs diff --git a/packages/wasm-dpp2/src/state_transitions/base/mod.rs b/packages/wasm-dpp2/src/state_transitions/base/mod.rs new file mode 100644 index 00000000000..03a0d4eb9cf --- /dev/null +++ b/packages/wasm-dpp2/src/state_transitions/base/mod.rs @@ -0,0 +1,5 @@ +pub mod group_state_transition_info; +pub mod state_transition; + +pub use group_state_transition_info::GroupStateTransitionInfoWasm; +pub use state_transition::StateTransitionWasm; diff --git a/packages/wasm-dpp2/src/state_transition/mod.rs b/packages/wasm-dpp2/src/state_transitions/base/state_transition/mod.rs similarity index 99% rename from packages/wasm-dpp2/src/state_transition/mod.rs rename to packages/wasm-dpp2/src/state_transitions/base/state_transition/mod.rs index 397ce291225..af2ebf2479b 100644 --- a/packages/wasm-dpp2/src/state_transition/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/base/state_transition/mod.rs @@ -3,7 +3,7 @@ use crate::enums::keys::purpose::PurposeWasm; use crate::enums::keys::security_level::SecurityLevelWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::identity_public_key::IdentityPublicKeyWasm; +use crate::identity::public_key::IdentityPublicKeyWasm; use crate::mock_bls::MockBLS; use crate::private_key::PrivateKeyWasm; use dpp::dashcore::secp256k1::hashes::hex::Case::Lower; diff --git a/packages/wasm-dpp2/src/batch/batched_transition/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/batched_transition/mod.rs similarity index 96% rename from packages/wasm-dpp2/src/batch/batched_transition/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/batched_transition/mod.rs index fb31e87fcc5..c1d9fa8bd76 100644 --- a/packages/wasm-dpp2/src/batch/batched_transition/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/batched_transition/mod.rs @@ -1,7 +1,7 @@ -use crate::batch::document_transition::DocumentTransitionWasm; -use crate::batch::token_transition::TokenTransitionWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; +use crate::state_transitions::batch::document_transition::DocumentTransitionWasm; +use crate::state_transitions::batch::token_transition::TokenTransitionWasm; use crate::utils::{IntoWasm, get_class_type}; use dpp::state_transition::batch_transition::batched_transition::BatchedTransition; use dpp::state_transition::batch_transition::batched_transition::document_transition::{ diff --git a/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_base_transition/mod.rs similarity index 98% rename from packages/wasm-dpp2/src/batch/document_base_transition/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_base_transition/mod.rs index 44b6c14b830..a66bb0294e2 100644 --- a/packages/wasm-dpp2/src/batch/document_base_transition/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/document_base_transition/mod.rs @@ -1,6 +1,6 @@ -use crate::batch::token_payment_info::TokenPaymentInfoWasm; use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; +use crate::state_transitions::batch::token_payment_info::TokenPaymentInfoWasm; use crate::utils::IntoWasm; use dpp::prelude::IdentityNonce; use dpp::state_transition::batch_transition::document_base_transition::DocumentBaseTransition; diff --git a/packages/wasm-dpp2/src/batch/document_transition/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transition/mod.rs similarity index 91% rename from packages/wasm-dpp2/src/batch/document_transition/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transition/mod.rs index 4f8535aef59..c25edf51e41 100644 --- a/packages/wasm-dpp2/src/batch/document_transition/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/document_transition/mod.rs @@ -1,9 +1,9 @@ -use crate::batch::document_transitions::create::DocumentCreateTransitionWasm; -use crate::batch::document_transitions::delete::DocumentDeleteTransitionWasm; -use crate::batch::document_transitions::purchase::DocumentPurchaseTransitionWasm; -use crate::batch::document_transitions::replace::DocumentReplaceTransitionWasm; -use crate::batch::document_transitions::transfer::DocumentTransferTransitionWasm; -use crate::batch::document_transitions::update_price::DocumentUpdatePriceTransitionWasm; +use crate::state_transitions::batch::document_transitions::create::DocumentCreateTransitionWasm; +use crate::state_transitions::batch::document_transitions::delete::DocumentDeleteTransitionWasm; +use crate::state_transitions::batch::document_transitions::purchase::DocumentPurchaseTransitionWasm; +use crate::state_transitions::batch::document_transitions::replace::DocumentReplaceTransitionWasm; +use crate::state_transitions::batch::document_transitions::transfer::DocumentTransferTransitionWasm; +use crate::state_transitions::batch::document_transitions::update_price::DocumentUpdatePriceTransitionWasm; use crate::enums::batch::batch_enum::BatchTypeWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; diff --git a/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/create/mod.rs similarity index 92% rename from packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/create/mod.rs index 8f918a259f0..ec785ce76fe 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/create/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/create/mod.rs @@ -1,9 +1,9 @@ -use crate::batch::document_base_transition::DocumentBaseTransitionWasm; -use crate::batch::document_transition::DocumentTransitionWasm; -use crate::batch::generators::generate_create_transition; -use crate::batch::prefunded_voting_balance::PrefundedVotingBalanceWasm; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; -use crate::document::DocumentWasm; +use crate::state_transitions::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::state_transitions::batch::document_transition::DocumentTransitionWasm; +use crate::state_transitions::batch::generators::generate_create_transition; +use crate::state_transitions::batch::prefunded_voting_balance::PrefundedVotingBalanceWasm; +use crate::state_transitions::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::data_contract::document::DocumentWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::utils::{IntoWasm, ToSerdeJSONExt}; use dpp::dashcore::hashes::serde::Serialize; diff --git a/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/delete/mod.rs similarity index 89% rename from packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/delete/mod.rs index 7c1dce4206c..79d23c1a44c 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/delete/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/delete/mod.rs @@ -1,8 +1,8 @@ -use crate::batch::document_base_transition::DocumentBaseTransitionWasm; -use crate::batch::document_transition::DocumentTransitionWasm; -use crate::batch::generators::generate_delete_transition; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; -use crate::document::DocumentWasm; +use crate::state_transitions::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::state_transitions::batch::document_transition::DocumentTransitionWasm; +use crate::state_transitions::batch::generators::generate_delete_transition; +use crate::state_transitions::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::data_contract::document::DocumentWasm; use crate::error::WasmDppResult; use crate::utils::IntoWasm; use dpp::prelude::IdentityNonce; diff --git a/packages/wasm-dpp2/src/batch/document_transitions/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/batch/document_transitions/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/mod.rs diff --git a/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/purchase/mod.rs similarity index 91% rename from packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/purchase/mod.rs index 91c5a9810a7..19e9575b24f 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/purchase/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/purchase/mod.rs @@ -1,8 +1,8 @@ -use crate::batch::document_base_transition::DocumentBaseTransitionWasm; -use crate::batch::document_transition::DocumentTransitionWasm; -use crate::batch::generators::generate_purchase_transition; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; -use crate::document::DocumentWasm; +use crate::state_transitions::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::state_transitions::batch::document_transition::DocumentTransitionWasm; +use crate::state_transitions::batch::generators::generate_purchase_transition; +use crate::state_transitions::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::data_contract::document::DocumentWasm; use crate::error::WasmDppResult; use crate::utils::IntoWasm; use dpp::fee::Credits; diff --git a/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/replace/mod.rs similarity index 91% rename from packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/replace/mod.rs index b9921186c4c..33b9ff298fe 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/replace/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/replace/mod.rs @@ -1,8 +1,8 @@ -use crate::batch::document_base_transition::DocumentBaseTransitionWasm; -use crate::batch::document_transition::DocumentTransitionWasm; -use crate::batch::generators::generate_replace_transition; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; -use crate::document::DocumentWasm; +use crate::state_transitions::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::state_transitions::batch::document_transition::DocumentTransitionWasm; +use crate::state_transitions::batch::generators::generate_replace_transition; +use crate::state_transitions::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::data_contract::document::DocumentWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::utils::{IntoWasm, ToSerdeJSONExt}; use dpp::dashcore::hashes::serde::Serialize; diff --git a/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/transfer/mod.rs similarity index 90% rename from packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/transfer/mod.rs index 165813dddc8..38c158ca2ad 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/transfer/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/transfer/mod.rs @@ -1,8 +1,8 @@ -use crate::batch::document_base_transition::DocumentBaseTransitionWasm; -use crate::batch::document_transition::DocumentTransitionWasm; -use crate::batch::generators::generate_transfer_transition; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; -use crate::document::DocumentWasm; +use crate::state_transitions::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::state_transitions::batch::document_transition::DocumentTransitionWasm; +use crate::state_transitions::batch::generators::generate_transfer_transition; +use crate::state_transitions::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::data_contract::document::DocumentWasm; use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use crate::utils::IntoWasm; diff --git a/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/update_price/mod.rs similarity index 90% rename from packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/update_price/mod.rs index 04c0dd851ec..168ee2fe56e 100644 --- a/packages/wasm-dpp2/src/batch/document_transitions/update_price/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/update_price/mod.rs @@ -1,8 +1,8 @@ -use crate::batch::document_base_transition::DocumentBaseTransitionWasm; -use crate::batch::document_transition::DocumentTransitionWasm; -use crate::batch::generators::generate_update_price_transition; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; -use crate::document::DocumentWasm; +use crate::state_transitions::batch::document_base_transition::DocumentBaseTransitionWasm; +use crate::state_transitions::batch::document_transition::DocumentTransitionWasm; +use crate::state_transitions::batch::generators::generate_update_price_transition; +use crate::state_transitions::batch::token_payment_info::TokenPaymentInfoWasm; +use crate::data_contract::document::DocumentWasm; use crate::error::WasmDppResult; use crate::utils::IntoWasm; use dpp::fee::Credits; diff --git a/packages/wasm-dpp2/src/batch/generators.rs b/packages/wasm-dpp2/src/state_transitions/batch/generators.rs similarity index 96% rename from packages/wasm-dpp2/src/batch/generators.rs rename to packages/wasm-dpp2/src/state_transitions/batch/generators.rs index d9cc2e00b9e..d10f2203f43 100644 --- a/packages/wasm-dpp2/src/batch/generators.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/generators.rs @@ -1,6 +1,6 @@ -use crate::batch::prefunded_voting_balance::PrefundedVotingBalanceWasm; -use crate::batch::token_payment_info::TokenPaymentInfoWasm; -use crate::document::DocumentWasm; +use crate::data_contract::document::DocumentWasm; +use crate::state_transitions::batch::prefunded_voting_balance::PrefundedVotingBalanceWasm; +use crate::state_transitions::batch::token_payment_info::TokenPaymentInfoWasm; use dpp::fee::Credits; use dpp::prelude::{Identifier, IdentityNonce}; use dpp::state_transition::batch_transition::batched_transition::document_purchase_transition::DocumentPurchaseTransitionV0; diff --git a/packages/wasm-dpp2/src/batch/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/mod.rs similarity index 97% rename from packages/wasm-dpp2/src/batch/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/mod.rs index a373e33c7fd..60167d97a20 100644 --- a/packages/wasm-dpp2/src/batch/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/mod.rs @@ -1,8 +1,8 @@ -use crate::batch::batched_transition::BatchedTransitionWasm; -use crate::batch::document_transition::DocumentTransitionWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::state_transition::StateTransitionWasm; +use crate::state_transitions::StateTransitionWasm; +use crate::state_transitions::batch::batched_transition::BatchedTransitionWasm; +use crate::state_transitions::batch::document_transition::DocumentTransitionWasm; use crate::utils::IntoWasm; use dpp::fee::Credits; use dpp::identity::KeyID; diff --git a/packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/prefunded_voting_balance/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/batch/prefunded_voting_balance/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/prefunded_voting_balance/mod.rs diff --git a/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_base_transition/mod.rs similarity index 98% rename from packages/wasm-dpp2/src/batch/token_base_transition/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_base_transition/mod.rs index 4482ad68612..736f63aa1d2 100644 --- a/packages/wasm-dpp2/src/batch/token_base_transition/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_base_transition/mod.rs @@ -1,6 +1,6 @@ use crate::error::WasmDppResult; -use crate::group_state_transition_info::GroupStateTransitionInfoWasm; use crate::identifier::IdentifierWasm; +use crate::state_transitions::GroupStateTransitionInfoWasm; use crate::utils::IntoWasm; use dpp::group::GroupStateTransitionInfo; use dpp::prelude::IdentityNonce; diff --git a/packages/wasm-dpp2/src/batch/token_payment_info/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_payment_info/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/batch/token_payment_info/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_payment_info/mod.rs diff --git a/packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_pricing_schedule/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/batch/token_pricing_schedule/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_pricing_schedule/mod.rs diff --git a/packages/wasm-dpp2/src/batch/token_transition/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transition/mod.rs similarity index 90% rename from packages/wasm-dpp2/src/batch/token_transition/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transition/mod.rs index 02f8056a113..37ae2141eab 100644 --- a/packages/wasm-dpp2/src/batch/token_transition/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transition/mod.rs @@ -1,16 +1,16 @@ -use crate::batch::token_transitions::config_update::TokenConfigUpdateTransitionWasm; -use crate::batch::token_transitions::direct_purchase::TokenDirectPurchaseTransitionWasm; -use crate::batch::token_transitions::set_price_for_direct_purchase::TokenSetPriceForDirectPurchaseTransitionWasm; -use crate::batch::token_transitions::token_burn::TokenBurnTransitionWasm; -use crate::batch::token_transitions::token_claim::TokenClaimTransitionWasm; -use crate::batch::token_transitions::token_destroy_frozen_funds::TokenDestroyFrozenFundsTransitionWasm; -use crate::batch::token_transitions::token_emergency_action::TokenEmergencyActionTransitionWasm; -use crate::batch::token_transitions::token_freeze::TokenFreezeTransitionWasm; -use crate::batch::token_transitions::token_mint::TokenMintTransitionWasm; -use crate::batch::token_transitions::token_transfer::TokenTransferTransitionWasm; -use crate::batch::token_transitions::token_unfreeze::TokenUnFreezeTransitionWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; +use crate::state_transitions::batch::token_transitions::config_update::TokenConfigUpdateTransitionWasm; +use crate::state_transitions::batch::token_transitions::direct_purchase::TokenDirectPurchaseTransitionWasm; +use crate::state_transitions::batch::token_transitions::set_price_for_direct_purchase::TokenSetPriceForDirectPurchaseTransitionWasm; +use crate::state_transitions::batch::token_transitions::token_burn::TokenBurnTransitionWasm; +use crate::state_transitions::batch::token_transitions::token_claim::TokenClaimTransitionWasm; +use crate::state_transitions::batch::token_transitions::token_destroy_frozen_funds::TokenDestroyFrozenFundsTransitionWasm; +use crate::state_transitions::batch::token_transitions::token_emergency_action::TokenEmergencyActionTransitionWasm; +use crate::state_transitions::batch::token_transitions::token_freeze::TokenFreezeTransitionWasm; +use crate::state_transitions::batch::token_transitions::token_mint::TokenMintTransitionWasm; +use crate::state_transitions::batch::token_transitions::token_transfer::TokenTransferTransitionWasm; +use crate::state_transitions::batch::token_transitions::token_unfreeze::TokenUnFreezeTransitionWasm; use crate::utils::{IntoWasm, get_class_type}; use dpp::prelude::IdentityNonce; use dpp::state_transition::batch_transition::batched_transition::token_transition::{ diff --git a/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/config_update.rs similarity index 94% rename from packages/wasm-dpp2/src/batch/token_transitions/config_update.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transitions/config_update.rs index 6fd6feba539..4d82c2a6c67 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/config_update.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/config_update.rs @@ -1,6 +1,6 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::state_transitions::batch::token_base_transition::TokenBaseTransitionWasm; use crate::error::WasmDppResult; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use dpp::state_transition::batch_transition::token_config_update_transition::v0::v0_methods::TokenConfigUpdateTransitionV0Methods; use dpp::state_transition::batch_transition::token_config_update_transition::TokenConfigUpdateTransitionV0; diff --git a/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/direct_purchase.rs similarity index 97% rename from packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transitions/direct_purchase.rs index b18baa73937..d2b131606f7 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/direct_purchase.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/direct_purchase.rs @@ -5,7 +5,7 @@ use dpp::state_transition::batch_transition::token_direct_purchase_transition::T use dpp::state_transition::batch_transition::token_direct_purchase_transition::v0::v0_methods::TokenDirectPurchaseTransitionV0Methods; use dpp::state_transition::batch_transition::TokenDirectPurchaseTransition; use wasm_bindgen::prelude::wasm_bindgen; -use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::state_transitions::batch::token_base_transition::TokenBaseTransitionWasm; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name=TokenDirectPurchaseTransition)] diff --git a/packages/wasm-dpp2/src/batch/token_transitions/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/batch/token_transitions/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transitions/mod.rs diff --git a/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/set_price_for_direct_purchase.rs similarity index 95% rename from packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transitions/set_price_for_direct_purchase.rs index 12cba460f69..0ff21ff5740 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/set_price_for_direct_purchase.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/set_price_for_direct_purchase.rs @@ -1,5 +1,5 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWasm; -use crate::batch::token_pricing_schedule::TokenPricingScheduleWasm; +use crate::state_transitions::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::state_transitions::batch::token_pricing_schedule::TokenPricingScheduleWasm; use crate::error::WasmDppResult; use crate::utils::IntoWasm; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_burn.rs similarity index 96% rename from packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_burn.rs index e3f96ba60ff..3d60bbff39e 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_burn.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_burn.rs @@ -1,4 +1,4 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::state_transitions::batch::token_base_transition::TokenBaseTransitionWasm; use crate::error::WasmDppResult; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use dpp::state_transition::batch_transition::token_burn_transition::v0::v0_methods::TokenBurnTransitionV0Methods; diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_claim.rs similarity index 97% rename from packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_claim.rs index 448f5a2f465..b78ab15a300 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_claim.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_claim.rs @@ -1,4 +1,4 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::state_transitions::batch::token_base_transition::TokenBaseTransitionWasm; use crate::enums::token::distribution_type::TokenDistributionTypeWasm; use crate::error::WasmDppResult; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_destroy_frozen_funds.rs similarity index 97% rename from packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_destroy_frozen_funds.rs index 99f07c3cc28..265b2efd706 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_destroy_frozen_funds.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_destroy_frozen_funds.rs @@ -1,4 +1,4 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::state_transitions::batch::token_base_transition::TokenBaseTransitionWasm; use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use dpp::identifier::Identifier; diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_emergency_action.rs similarity index 97% rename from packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_emergency_action.rs index b5382f6c7eb..c308fb2adda 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_emergency_action.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_emergency_action.rs @@ -4,7 +4,7 @@ use dpp::state_transition::batch_transition::token_emergency_action_transition:: use dpp::state_transition::batch_transition::TokenEmergencyActionTransition; use wasm_bindgen::prelude::wasm_bindgen; use crate::enums::token::emergency_action::TokenEmergencyActionWasm; -use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::state_transitions::batch::token_base_transition::TokenBaseTransitionWasm; #[derive(Debug, Clone, PartialEq)] #[wasm_bindgen(js_name = "TokenEmergencyActionTransition")] diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_freeze.rs similarity index 97% rename from packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_freeze.rs index a1bfe9f1568..ebe18406028 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_freeze.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_freeze.rs @@ -1,4 +1,4 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::state_transitions::batch::token_base_transition::TokenBaseTransitionWasm; use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use dpp::identifier::Identifier; diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_mint.rs similarity index 96% rename from packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_mint.rs index 004ad643a64..522bd661f95 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_mint.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_mint.rs @@ -1,7 +1,7 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::state_transitions::batch::token_base_transition::TokenBaseTransitionWasm; use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; -use crate::token_configuration::TokenConfigurationWasm; +use crate::tokens::configuration::TokenConfigurationWasm; use dpp::prelude::Identifier; use dpp::state_transition::batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors; use dpp::state_transition::batch_transition::token_mint_transition::v0::v0_methods::TokenMintTransitionV0Methods; diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_transfer.rs similarity index 96% rename from packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_transfer.rs index c6a1923f6ab..0fc5e974e09 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_transfer.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_transfer.rs @@ -1,6 +1,6 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWasm; -use crate::encrypted_note::private_encrypted_note::PrivateEncryptedNoteWasm; -use crate::encrypted_note::shared_encrypted_note::SharedEncryptedNoteWasm; +use crate::state_transitions::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::tokens::encrypted_note::private_encrypted_note::PrivateEncryptedNoteWasm; +use crate::tokens::encrypted_note::shared_encrypted_note::SharedEncryptedNoteWasm; use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use crate::utils::IntoWasm; diff --git a/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_unfreeze.rs similarity index 97% rename from packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_unfreeze.rs index bae8134daf8..ded0d76952e 100644 --- a/packages/wasm-dpp2/src/batch/token_transitions/token_unfreeze.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_unfreeze.rs @@ -1,4 +1,4 @@ -use crate::batch::token_base_transition::TokenBaseTransitionWasm; +use crate::state_transitions::batch::token_base_transition::TokenBaseTransitionWasm; use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; use dpp::identifier::Identifier; diff --git a/packages/wasm-dpp2/src/state_transitions/mod.rs b/packages/wasm-dpp2/src/state_transitions/mod.rs new file mode 100644 index 00000000000..7e1dcccf95c --- /dev/null +++ b/packages/wasm-dpp2/src/state_transitions/mod.rs @@ -0,0 +1,4 @@ +pub mod base; +pub mod batch; + +pub use base::{GroupStateTransitionInfoWasm, StateTransitionWasm}; diff --git a/packages/wasm-dpp2/src/token_configuration/action_taker.rs b/packages/wasm-dpp2/src/tokens/configuration/action_taker.rs similarity index 100% rename from packages/wasm-dpp2/src/token_configuration/action_taker.rs rename to packages/wasm-dpp2/src/tokens/configuration/action_taker.rs diff --git a/packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs b/packages/wasm-dpp2/src/tokens/configuration/authorized_action_takers.rs similarity index 100% rename from packages/wasm-dpp2/src/token_configuration/authorized_action_takers.rs rename to packages/wasm-dpp2/src/tokens/configuration/authorized_action_takers.rs diff --git a/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs b/packages/wasm-dpp2/src/tokens/configuration/change_control_rules.rs similarity index 97% rename from packages/wasm-dpp2/src/token_configuration/change_control_rules.rs rename to packages/wasm-dpp2/src/tokens/configuration/change_control_rules.rs index 6c9f398519f..35923acd97c 100644 --- a/packages/wasm-dpp2/src/token_configuration/change_control_rules.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/change_control_rules.rs @@ -1,9 +1,9 @@ use crate::enums::token::action_goal::ActionGoalWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::token_configuration::action_taker::ActionTakerWasm; -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration::group::GroupWasm; +use crate::tokens::configuration::action_taker::ActionTakerWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration::group::GroupWasm; use crate::utils::{IntoWasm, JsValueExt}; use dpp::data_contract::GroupContractPosition; use dpp::data_contract::change_control_rules::ChangeControlRules; diff --git a/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs b/packages/wasm-dpp2/src/tokens/configuration/configuration_convention.rs similarity index 98% rename from packages/wasm-dpp2/src/token_configuration/configuration_convention.rs rename to packages/wasm-dpp2/src/tokens/configuration/configuration_convention.rs index 7fa08892c62..d8e772c8557 100644 --- a/packages/wasm-dpp2/src/token_configuration/configuration_convention.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/configuration_convention.rs @@ -1,5 +1,5 @@ use crate::error::{WasmDppError, WasmDppResult}; -use crate::token_configuration::localization::TokenConfigurationLocalizationWasm; +use crate::tokens::configuration::localization::TokenConfigurationLocalizationWasm; use crate::utils::JsValueExt; use dpp::data_contract::associated_token::token_configuration_convention::TokenConfigurationConvention; use dpp::data_contract::associated_token::token_configuration_convention::accessors::v0::{ diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_function.rs b/packages/wasm-dpp2/src/tokens/configuration/distribution_function.rs similarity index 99% rename from packages/wasm-dpp2/src/token_configuration/distribution_function.rs rename to packages/wasm-dpp2/src/tokens/configuration/distribution_function.rs index 4f34d734763..e5c137912b6 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_function.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/distribution_function.rs @@ -1,5 +1,5 @@ use crate::error::{WasmDppError, WasmDppResult}; -use crate::token_configuration::distribution_structs::{ +use crate::tokens::configuration::distribution_structs::{ DistributionExponentialWasm, DistributionFixedAmountWasm, DistributionInvertedLogarithmicWasm, DistributionLinearWasm, DistributionLogarithmicWasm, DistributionPolynomialWasm, DistributionRandomWasm, DistributionStepDecreasingAmountWasm, diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs b/packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs similarity index 100% rename from packages/wasm-dpp2/src/token_configuration/distribution_recipient.rs rename to packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs b/packages/wasm-dpp2/src/tokens/configuration/distribution_rules.rs similarity index 97% rename from packages/wasm-dpp2/src/token_configuration/distribution_rules.rs rename to packages/wasm-dpp2/src/tokens/configuration/distribution_rules.rs index 3f2040468ef..83b8521fe66 100644 --- a/packages/wasm-dpp2/src/token_configuration/distribution_rules.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/distribution_rules.rs @@ -1,8 +1,8 @@ use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; -use crate::token_configuration::change_control_rules::ChangeControlRulesWasm; -use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWasm; -use crate::token_configuration::pre_programmed_distribution::TokenPreProgrammedDistributionWasm; +use crate::tokens::configuration::change_control_rules::ChangeControlRulesWasm; +use crate::tokens::configuration::perpetual_distribution::TokenPerpetualDistributionWasm; +use crate::tokens::configuration::pre_programmed_distribution::TokenPreProgrammedDistributionWasm; use crate::utils::IntoWasm; use dpp::data_contract::associated_token::token_distribution_rules::TokenDistributionRules; use dpp::data_contract::associated_token::token_distribution_rules::accessors::v0::{ diff --git a/packages/wasm-dpp2/src/token_configuration/distribution_structs.rs b/packages/wasm-dpp2/src/tokens/configuration/distribution_structs.rs similarity index 100% rename from packages/wasm-dpp2/src/token_configuration/distribution_structs.rs rename to packages/wasm-dpp2/src/tokens/configuration/distribution_structs.rs diff --git a/packages/wasm-dpp2/src/token_configuration/group.rs b/packages/wasm-dpp2/src/tokens/configuration/group.rs similarity index 100% rename from packages/wasm-dpp2/src/token_configuration/group.rs rename to packages/wasm-dpp2/src/tokens/configuration/group.rs diff --git a/packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs b/packages/wasm-dpp2/src/tokens/configuration/keeps_history_rules.rs similarity index 100% rename from packages/wasm-dpp2/src/token_configuration/keeps_history_rules.rs rename to packages/wasm-dpp2/src/tokens/configuration/keeps_history_rules.rs diff --git a/packages/wasm-dpp2/src/token_configuration/localization.rs b/packages/wasm-dpp2/src/tokens/configuration/localization.rs similarity index 100% rename from packages/wasm-dpp2/src/token_configuration/localization.rs rename to packages/wasm-dpp2/src/tokens/configuration/localization.rs diff --git a/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs b/packages/wasm-dpp2/src/tokens/configuration/marketplace_rules.rs similarity index 94% rename from packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs rename to packages/wasm-dpp2/src/tokens/configuration/marketplace_rules.rs index 8adeacef3eb..91d7dadf676 100644 --- a/packages/wasm-dpp2/src/token_configuration/marketplace_rules.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/marketplace_rules.rs @@ -1,5 +1,5 @@ -use crate::token_configuration::change_control_rules::ChangeControlRulesWasm; -use crate::token_configuration::trade_mode::TokenTradeModeWasm; +use crate::tokens::configuration::change_control_rules::ChangeControlRulesWasm; +use crate::tokens::configuration::trade_mode::TokenTradeModeWasm; use dpp::data_contract::associated_token::token_marketplace_rules::TokenMarketplaceRules; use dpp::data_contract::associated_token::token_marketplace_rules::accessors::v0::{ TokenMarketplaceRulesV0Getters, TokenMarketplaceRulesV0Setters, diff --git a/packages/wasm-dpp2/src/token_configuration/mod.rs b/packages/wasm-dpp2/src/tokens/configuration/mod.rs similarity index 95% rename from packages/wasm-dpp2/src/token_configuration/mod.rs rename to packages/wasm-dpp2/src/tokens/configuration/mod.rs index 45d22ba3c66..a12c17078d5 100644 --- a/packages/wasm-dpp2/src/token_configuration/mod.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/mod.rs @@ -1,11 +1,11 @@ use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration::change_control_rules::ChangeControlRulesWasm; -use crate::token_configuration::configuration_convention::TokenConfigurationConventionWasm; -use crate::token_configuration::distribution_rules::TokenDistributionRulesWasm; -use crate::token_configuration::keeps_history_rules::TokenKeepsHistoryRulesWasm; -use crate::token_configuration::marketplace_rules::TokenMarketplaceRulesWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration::change_control_rules::ChangeControlRulesWasm; +use crate::tokens::configuration::configuration_convention::TokenConfigurationConventionWasm; +use crate::tokens::configuration::distribution_rules::TokenDistributionRulesWasm; +use crate::tokens::configuration::keeps_history_rules::TokenKeepsHistoryRulesWasm; +use crate::tokens::configuration::marketplace_rules::TokenMarketplaceRulesWasm; use dpp::balances::credits::TokenAmount; use dpp::data_contract::associated_token::token_configuration::accessors::v0::{ TokenConfigurationV0Getters, TokenConfigurationV0Setters, diff --git a/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs b/packages/wasm-dpp2/src/tokens/configuration/perpetual_distribution.rs similarity index 93% rename from packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs rename to packages/wasm-dpp2/src/tokens/configuration/perpetual_distribution.rs index 9130979a7f7..f76f992b233 100644 --- a/packages/wasm-dpp2/src/token_configuration/perpetual_distribution.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/perpetual_distribution.rs @@ -1,5 +1,5 @@ -use crate::token_configuration::distribution_recipient::TokenDistributionRecipientWasm; -use crate::token_configuration::reward_distribution_type::RewardDistributionTypeWasm; +use crate::tokens::configuration::distribution_recipient::TokenDistributionRecipientWasm; +use crate::tokens::configuration::reward_distribution_type::RewardDistributionTypeWasm; use dpp::data_contract::associated_token::token_perpetual_distribution::TokenPerpetualDistribution; use dpp::data_contract::associated_token::token_perpetual_distribution::methods::v0::TokenPerpetualDistributionV0Accessors; use dpp::data_contract::associated_token::token_perpetual_distribution::v0::TokenPerpetualDistributionV0; diff --git a/packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs b/packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs similarity index 100% rename from packages/wasm-dpp2/src/token_configuration/pre_programmed_distribution.rs rename to packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs diff --git a/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs b/packages/wasm-dpp2/src/tokens/configuration/reward_distribution_type.rs similarity index 98% rename from packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs rename to packages/wasm-dpp2/src/tokens/configuration/reward_distribution_type.rs index 431746b8778..cfd6091e4e2 100644 --- a/packages/wasm-dpp2/src/token_configuration/reward_distribution_type.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/reward_distribution_type.rs @@ -3,7 +3,7 @@ use dpp::data_contract::associated_token::token_perpetual_distribution::reward_d use dpp::prelude::{BlockHeightInterval, EpochInterval, TimestampMillisInterval}; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::token_configuration::distribution_function::DistributionFunctionWasm; +use crate::tokens::configuration::distribution_function::DistributionFunctionWasm; #[derive(Clone, Debug, PartialEq)] #[wasm_bindgen(js_name = "RewardDistributionType")] diff --git a/packages/wasm-dpp2/src/token_configuration/trade_mode.rs b/packages/wasm-dpp2/src/tokens/configuration/trade_mode.rs similarity index 100% rename from packages/wasm-dpp2/src/token_configuration/trade_mode.rs rename to packages/wasm-dpp2/src/tokens/configuration/trade_mode.rs diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/conventions.rs similarity index 81% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/conventions.rs index aa4d3c57cb9..644233e34e4 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/conventions.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/conventions.rs @@ -1,6 +1,6 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration::configuration_convention::TokenConfigurationConventionWasm; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration::configuration_convention::TokenConfigurationConventionWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/destroy_frozen_funds.rs similarity index 83% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/destroy_frozen_funds.rs index ea7799f9ae0..8381bb8a92f 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/destroy_frozen_funds.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/destroy_frozen_funds.rs @@ -1,5 +1,5 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/emergency_action.rs similarity index 84% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/emergency_action.rs index 08aab4ea0ba..9ce6444cd8b 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/emergency_action.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/emergency_action.rs @@ -1,5 +1,5 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/freeze.rs similarity index 83% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/freeze.rs index 7f598423e7e..bf0b5cde9c3 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/freeze.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/freeze.rs @@ -1,5 +1,5 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/main_control_group.rs similarity index 87% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/main_control_group.rs index 025d9b2cfc1..32fab4af0a8 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/main_control_group.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/main_control_group.rs @@ -1,4 +1,4 @@ -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::GroupContractPosition; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/manual_burning.rs similarity index 83% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/manual_burning.rs index 26857201b72..a3e02cc338c 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_burning.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/manual_burning.rs @@ -1,5 +1,5 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/manual_minting.rs similarity index 83% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/manual_minting.rs index 3765496fae7..81bb0b40936 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/manual_minting.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/manual_minting.rs @@ -1,5 +1,5 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/marketplace_trade_mode.rs similarity index 84% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/marketplace_trade_mode.rs index a45204058a2..0e99c8fce69 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/marketplace_trade_mode.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/marketplace_trade_mode.rs @@ -1,6 +1,6 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration::trade_mode::TokenTradeModeWasm; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration::trade_mode::TokenTradeModeWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/max_supply.rs similarity index 86% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/max_supply.rs index a7b85ac99a4..d977ea3b696 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/max_supply.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/max_supply.rs @@ -1,5 +1,5 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::balances::credits::TokenAmount; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/minting_allow_choosing_destination.rs similarity index 88% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/minting_allow_choosing_destination.rs index 9b782009522..e9722eb5135 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/minting_allow_choosing_destination.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/minting_allow_choosing_destination.rs @@ -1,5 +1,5 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/mod.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/mod.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/mod.rs diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/new_tokens_destination_identity.rs similarity index 91% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/new_tokens_destination_identity.rs index b04f3d4d989..7b69f63b0b1 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/new_tokens_destination_identity.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/new_tokens_destination_identity.rs @@ -1,7 +1,7 @@ use crate::error::WasmDppResult; use crate::identifier::IdentifierWasm; -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use dpp::prelude::Identifier; use wasm_bindgen::JsValue; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/no_change.rs similarity index 84% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/no_change.rs index 5adb0730883..cfc05564dee 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/no_change.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/no_change.rs @@ -1,4 +1,4 @@ -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/perpetual_distribution.rs similarity index 88% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/perpetual_distribution.rs index bf55777f5dd..fcbc9c62123 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/perpetual_distribution.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/perpetual_distribution.rs @@ -1,6 +1,6 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWasm; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration::perpetual_distribution::TokenPerpetualDistributionWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use crate::utils::IntoWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use dpp::data_contract::associated_token::token_perpetual_distribution::TokenPerpetualDistribution; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/unfreeze.rs similarity index 82% rename from packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/items/unfreeze.rs index 380246558f5..439228bcac6 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/items/unfreeze.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/items/unfreeze.rs @@ -1,5 +1,5 @@ -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/mod.rs similarity index 97% rename from packages/wasm-dpp2/src/token_configuration_change_item/mod.rs rename to packages/wasm-dpp2/src/tokens/configuration_change_item/mod.rs index 28624860a7e..1fb13ff2bed 100644 --- a/packages/wasm-dpp2/src/token_configuration_change_item/mod.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/mod.rs @@ -1,10 +1,10 @@ pub mod items; use crate::identifier::IdentifierWasm; -use crate::token_configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::token_configuration::configuration_convention::TokenConfigurationConventionWasm; -use crate::token_configuration::perpetual_distribution::TokenPerpetualDistributionWasm; -use crate::token_configuration::trade_mode::TokenTradeModeWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration::configuration_convention::TokenConfigurationConventionWasm; +use crate::tokens::configuration::perpetual_distribution::TokenPerpetualDistributionWasm; +use crate::tokens::configuration::trade_mode::TokenTradeModeWasm; use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/packages/wasm-dpp2/src/encrypted_note/mod.rs b/packages/wasm-dpp2/src/tokens/encrypted_note/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/encrypted_note/mod.rs rename to packages/wasm-dpp2/src/tokens/encrypted_note/mod.rs diff --git a/packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs b/packages/wasm-dpp2/src/tokens/encrypted_note/private_encrypted_note/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/encrypted_note/private_encrypted_note/mod.rs rename to packages/wasm-dpp2/src/tokens/encrypted_note/private_encrypted_note/mod.rs diff --git a/packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs b/packages/wasm-dpp2/src/tokens/encrypted_note/shared_encrypted_note/mod.rs similarity index 100% rename from packages/wasm-dpp2/src/encrypted_note/shared_encrypted_note/mod.rs rename to packages/wasm-dpp2/src/tokens/encrypted_note/shared_encrypted_note/mod.rs diff --git a/packages/wasm-dpp2/src/tokens/mod.rs b/packages/wasm-dpp2/src/tokens/mod.rs new file mode 100644 index 00000000000..8f47f59a11c --- /dev/null +++ b/packages/wasm-dpp2/src/tokens/mod.rs @@ -0,0 +1,11 @@ +pub mod configuration; +pub mod configuration_change_item; +pub mod encrypted_note; + +pub use configuration::TokenConfigurationWasm; +pub use configuration::authorized_action_takers::AuthorizedActionTakersWasm; +pub use configuration::group::GroupWasm; +pub use configuration::localization::TokenConfigurationLocalizationWasm; +pub use configuration_change_item::TokenConfigurationChangeItemWasm; +pub use encrypted_note::private_encrypted_note::PrivateEncryptedNoteWasm; +pub use encrypted_note::shared_encrypted_note::SharedEncryptedNoteWasm; From 3adc61d19e14442681700171a5db3ee1da561e5c Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 7 Oct 2025 18:51:44 +0700 Subject: [PATCH 14/44] refactor: downgrade to file modules --- .../wasm-dpp2/src/asset_lock_proof/{chain/mod.rs => chain.rs} | 0 .../src/asset_lock_proof/{outpoint/mod.rs => outpoint.rs} | 0 .../wasm-dpp2/src/asset_lock_proof/{tx_out/mod.rs => tx_out.rs} | 0 .../wasm-dpp2/src/{consensus_error/mod.rs => consensus_error.rs} | 0 packages/wasm-dpp2/src/{core_script/mod.rs => core_script.rs} | 0 .../data_contract/{contract_bounds/mod.rs => contract_bounds.rs} | 0 .../src/data_contract/document/{methods/mod.rs => methods.rs} | 0 .../src/data_contract/transitions/{create/mod.rs => create.rs} | 0 .../src/data_contract/transitions/{update/mod.rs => update.rs} | 0 packages/wasm-dpp2/src/enums/{lock_types/mod.rs => lock_types.rs} | 0 packages/wasm-dpp2/src/enums/{network/mod.rs => network.rs} | 0 packages/wasm-dpp2/src/enums/{platform/mod.rs => platform.rs} | 0 packages/wasm-dpp2/src/enums/{withdrawal/mod.rs => withdrawal.rs} | 0 packages/wasm-dpp2/src/{identifier/mod.rs => identifier.rs} | 0 .../{resource_vote_choice/mod.rs => resource_vote_choice.rs} | 0 .../identity/governance/masternode_vote/{vote/mod.rs => vote.rs} | 0 .../governance/masternode_vote/{vote_poll/mod.rs => vote_poll.rs} | 0 .../src/identity/{partial_identity/mod.rs => partial_identity.rs} | 0 .../wasm-dpp2/src/identity/{public_key/mod.rs => public_key.rs} | 0 .../{create_transition/mod.rs => create_transition.rs} | 0 .../mod.rs => credit_withdrawal_transition.rs} | 0 .../mod.rs => identity_credit_transfer_transition.rs} | 0 .../{public_key_in_creation/mod.rs => public_key_in_creation.rs} | 0 .../{top_up_transition/mod.rs => top_up_transition.rs} | 0 .../{update_transition/mod.rs => update_transition.rs} | 0 packages/wasm-dpp2/src/{mock_bls/mod.rs => mock_bls.rs} | 0 packages/wasm-dpp2/src/{private_key/mod.rs => private_key.rs} | 0 packages/wasm-dpp2/src/{public_key/mod.rs => public_key.rs} | 0 .../mod.rs => group_state_transition_info.rs} | 0 .../base/{state_transition/mod.rs => state_transition.rs} | 0 .../batch/{batched_transition/mod.rs => batched_transition.rs} | 0 .../mod.rs => document_base_transition.rs} | 0 .../batch/{document_transition/mod.rs => document_transition.rs} | 0 .../batch/document_transitions/{create/mod.rs => create.rs} | 0 .../batch/document_transitions/{delete/mod.rs => delete.rs} | 0 .../batch/document_transitions/{purchase/mod.rs => purchase.rs} | 0 .../batch/document_transitions/{replace/mod.rs => replace.rs} | 0 .../batch/document_transitions/{transfer/mod.rs => transfer.rs} | 0 .../document_transitions/{update_price/mod.rs => update_price.rs} | 0 .../mod.rs => prefunded_voting_balance.rs} | 0 .../{token_base_transition/mod.rs => token_base_transition.rs} | 0 .../batch/{token_payment_info/mod.rs => token_payment_info.rs} | 0 .../{token_pricing_schedule/mod.rs => token_pricing_schedule.rs} | 0 .../batch/{token_transition/mod.rs => token_transition.rs} | 0 .../{private_encrypted_note/mod.rs => private_encrypted_note.rs} | 0 .../{shared_encrypted_note/mod.rs => shared_encrypted_note.rs} | 0 packages/wasm-dpp2/src/{utils/mod.rs => utils.rs} | 0 47 files changed, 0 insertions(+), 0 deletions(-) rename packages/wasm-dpp2/src/asset_lock_proof/{chain/mod.rs => chain.rs} (100%) rename packages/wasm-dpp2/src/asset_lock_proof/{outpoint/mod.rs => outpoint.rs} (100%) rename packages/wasm-dpp2/src/asset_lock_proof/{tx_out/mod.rs => tx_out.rs} (100%) rename packages/wasm-dpp2/src/{consensus_error/mod.rs => consensus_error.rs} (100%) rename packages/wasm-dpp2/src/{core_script/mod.rs => core_script.rs} (100%) rename packages/wasm-dpp2/src/data_contract/{contract_bounds/mod.rs => contract_bounds.rs} (100%) rename packages/wasm-dpp2/src/data_contract/document/{methods/mod.rs => methods.rs} (100%) rename packages/wasm-dpp2/src/data_contract/transitions/{create/mod.rs => create.rs} (100%) rename packages/wasm-dpp2/src/data_contract/transitions/{update/mod.rs => update.rs} (100%) rename packages/wasm-dpp2/src/enums/{lock_types/mod.rs => lock_types.rs} (100%) rename packages/wasm-dpp2/src/enums/{network/mod.rs => network.rs} (100%) rename packages/wasm-dpp2/src/enums/{platform/mod.rs => platform.rs} (100%) rename packages/wasm-dpp2/src/enums/{withdrawal/mod.rs => withdrawal.rs} (100%) rename packages/wasm-dpp2/src/{identifier/mod.rs => identifier.rs} (100%) rename packages/wasm-dpp2/src/identity/governance/masternode_vote/{resource_vote_choice/mod.rs => resource_vote_choice.rs} (100%) rename packages/wasm-dpp2/src/identity/governance/masternode_vote/{vote/mod.rs => vote.rs} (100%) rename packages/wasm-dpp2/src/identity/governance/masternode_vote/{vote_poll/mod.rs => vote_poll.rs} (100%) rename packages/wasm-dpp2/src/identity/{partial_identity/mod.rs => partial_identity.rs} (100%) rename packages/wasm-dpp2/src/identity/{public_key/mod.rs => public_key.rs} (100%) rename packages/wasm-dpp2/src/identity/transitions/{create_transition/mod.rs => create_transition.rs} (100%) rename packages/wasm-dpp2/src/identity/transitions/{credit_withdrawal_transition/mod.rs => credit_withdrawal_transition.rs} (100%) rename packages/wasm-dpp2/src/identity/transitions/{identity_credit_transfer_transition/mod.rs => identity_credit_transfer_transition.rs} (100%) rename packages/wasm-dpp2/src/identity/transitions/{public_key_in_creation/mod.rs => public_key_in_creation.rs} (100%) rename packages/wasm-dpp2/src/identity/transitions/{top_up_transition/mod.rs => top_up_transition.rs} (100%) rename packages/wasm-dpp2/src/identity/transitions/{update_transition/mod.rs => update_transition.rs} (100%) rename packages/wasm-dpp2/src/{mock_bls/mod.rs => mock_bls.rs} (100%) rename packages/wasm-dpp2/src/{private_key/mod.rs => private_key.rs} (100%) rename packages/wasm-dpp2/src/{public_key/mod.rs => public_key.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/base/{group_state_transition_info/mod.rs => group_state_transition_info.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/base/{state_transition/mod.rs => state_transition.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/{batched_transition/mod.rs => batched_transition.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/{document_base_transition/mod.rs => document_base_transition.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/{document_transition/mod.rs => document_transition.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/document_transitions/{create/mod.rs => create.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/document_transitions/{delete/mod.rs => delete.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/document_transitions/{purchase/mod.rs => purchase.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/document_transitions/{replace/mod.rs => replace.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/document_transitions/{transfer/mod.rs => transfer.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/document_transitions/{update_price/mod.rs => update_price.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/{prefunded_voting_balance/mod.rs => prefunded_voting_balance.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/{token_base_transition/mod.rs => token_base_transition.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/{token_payment_info/mod.rs => token_payment_info.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/{token_pricing_schedule/mod.rs => token_pricing_schedule.rs} (100%) rename packages/wasm-dpp2/src/state_transitions/batch/{token_transition/mod.rs => token_transition.rs} (100%) rename packages/wasm-dpp2/src/tokens/encrypted_note/{private_encrypted_note/mod.rs => private_encrypted_note.rs} (100%) rename packages/wasm-dpp2/src/tokens/encrypted_note/{shared_encrypted_note/mod.rs => shared_encrypted_note.rs} (100%) rename packages/wasm-dpp2/src/{utils/mod.rs => utils.rs} (100%) diff --git a/packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/chain.rs similarity index 100% rename from packages/wasm-dpp2/src/asset_lock_proof/chain/mod.rs rename to packages/wasm-dpp2/src/asset_lock_proof/chain.rs diff --git a/packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/outpoint.rs similarity index 100% rename from packages/wasm-dpp2/src/asset_lock_proof/outpoint/mod.rs rename to packages/wasm-dpp2/src/asset_lock_proof/outpoint.rs diff --git a/packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/tx_out.rs similarity index 100% rename from packages/wasm-dpp2/src/asset_lock_proof/tx_out/mod.rs rename to packages/wasm-dpp2/src/asset_lock_proof/tx_out.rs diff --git a/packages/wasm-dpp2/src/consensus_error/mod.rs b/packages/wasm-dpp2/src/consensus_error.rs similarity index 100% rename from packages/wasm-dpp2/src/consensus_error/mod.rs rename to packages/wasm-dpp2/src/consensus_error.rs diff --git a/packages/wasm-dpp2/src/core_script/mod.rs b/packages/wasm-dpp2/src/core_script.rs similarity index 100% rename from packages/wasm-dpp2/src/core_script/mod.rs rename to packages/wasm-dpp2/src/core_script.rs diff --git a/packages/wasm-dpp2/src/data_contract/contract_bounds/mod.rs b/packages/wasm-dpp2/src/data_contract/contract_bounds.rs similarity index 100% rename from packages/wasm-dpp2/src/data_contract/contract_bounds/mod.rs rename to packages/wasm-dpp2/src/data_contract/contract_bounds.rs diff --git a/packages/wasm-dpp2/src/data_contract/document/methods/mod.rs b/packages/wasm-dpp2/src/data_contract/document/methods.rs similarity index 100% rename from packages/wasm-dpp2/src/data_contract/document/methods/mod.rs rename to packages/wasm-dpp2/src/data_contract/document/methods.rs diff --git a/packages/wasm-dpp2/src/data_contract/transitions/create/mod.rs b/packages/wasm-dpp2/src/data_contract/transitions/create.rs similarity index 100% rename from packages/wasm-dpp2/src/data_contract/transitions/create/mod.rs rename to packages/wasm-dpp2/src/data_contract/transitions/create.rs diff --git a/packages/wasm-dpp2/src/data_contract/transitions/update/mod.rs b/packages/wasm-dpp2/src/data_contract/transitions/update.rs similarity index 100% rename from packages/wasm-dpp2/src/data_contract/transitions/update/mod.rs rename to packages/wasm-dpp2/src/data_contract/transitions/update.rs diff --git a/packages/wasm-dpp2/src/enums/lock_types/mod.rs b/packages/wasm-dpp2/src/enums/lock_types.rs similarity index 100% rename from packages/wasm-dpp2/src/enums/lock_types/mod.rs rename to packages/wasm-dpp2/src/enums/lock_types.rs diff --git a/packages/wasm-dpp2/src/enums/network/mod.rs b/packages/wasm-dpp2/src/enums/network.rs similarity index 100% rename from packages/wasm-dpp2/src/enums/network/mod.rs rename to packages/wasm-dpp2/src/enums/network.rs diff --git a/packages/wasm-dpp2/src/enums/platform/mod.rs b/packages/wasm-dpp2/src/enums/platform.rs similarity index 100% rename from packages/wasm-dpp2/src/enums/platform/mod.rs rename to packages/wasm-dpp2/src/enums/platform.rs diff --git a/packages/wasm-dpp2/src/enums/withdrawal/mod.rs b/packages/wasm-dpp2/src/enums/withdrawal.rs similarity index 100% rename from packages/wasm-dpp2/src/enums/withdrawal/mod.rs rename to packages/wasm-dpp2/src/enums/withdrawal.rs diff --git a/packages/wasm-dpp2/src/identifier/mod.rs b/packages/wasm-dpp2/src/identifier.rs similarity index 100% rename from packages/wasm-dpp2/src/identifier/mod.rs rename to packages/wasm-dpp2/src/identifier.rs diff --git a/packages/wasm-dpp2/src/identity/governance/masternode_vote/resource_vote_choice/mod.rs b/packages/wasm-dpp2/src/identity/governance/masternode_vote/resource_vote_choice.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/governance/masternode_vote/resource_vote_choice/mod.rs rename to packages/wasm-dpp2/src/identity/governance/masternode_vote/resource_vote_choice.rs diff --git a/packages/wasm-dpp2/src/identity/governance/masternode_vote/vote/mod.rs b/packages/wasm-dpp2/src/identity/governance/masternode_vote/vote.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/governance/masternode_vote/vote/mod.rs rename to packages/wasm-dpp2/src/identity/governance/masternode_vote/vote.rs diff --git a/packages/wasm-dpp2/src/identity/governance/masternode_vote/vote_poll/mod.rs b/packages/wasm-dpp2/src/identity/governance/masternode_vote/vote_poll.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/governance/masternode_vote/vote_poll/mod.rs rename to packages/wasm-dpp2/src/identity/governance/masternode_vote/vote_poll.rs diff --git a/packages/wasm-dpp2/src/identity/partial_identity/mod.rs b/packages/wasm-dpp2/src/identity/partial_identity.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/partial_identity/mod.rs rename to packages/wasm-dpp2/src/identity/partial_identity.rs diff --git a/packages/wasm-dpp2/src/identity/public_key/mod.rs b/packages/wasm-dpp2/src/identity/public_key.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/public_key/mod.rs rename to packages/wasm-dpp2/src/identity/public_key.rs diff --git a/packages/wasm-dpp2/src/identity/transitions/create_transition/mod.rs b/packages/wasm-dpp2/src/identity/transitions/create_transition.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/transitions/create_transition/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/create_transition.rs diff --git a/packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition/mod.rs b/packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs diff --git a/packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition/mod.rs b/packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/identity_credit_transfer_transition.rs diff --git a/packages/wasm-dpp2/src/identity/transitions/public_key_in_creation/mod.rs b/packages/wasm-dpp2/src/identity/transitions/public_key_in_creation.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/transitions/public_key_in_creation/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/public_key_in_creation.rs diff --git a/packages/wasm-dpp2/src/identity/transitions/top_up_transition/mod.rs b/packages/wasm-dpp2/src/identity/transitions/top_up_transition.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/transitions/top_up_transition/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/top_up_transition.rs diff --git a/packages/wasm-dpp2/src/identity/transitions/update_transition/mod.rs b/packages/wasm-dpp2/src/identity/transitions/update_transition.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/transitions/update_transition/mod.rs rename to packages/wasm-dpp2/src/identity/transitions/update_transition.rs diff --git a/packages/wasm-dpp2/src/mock_bls/mod.rs b/packages/wasm-dpp2/src/mock_bls.rs similarity index 100% rename from packages/wasm-dpp2/src/mock_bls/mod.rs rename to packages/wasm-dpp2/src/mock_bls.rs diff --git a/packages/wasm-dpp2/src/private_key/mod.rs b/packages/wasm-dpp2/src/private_key.rs similarity index 100% rename from packages/wasm-dpp2/src/private_key/mod.rs rename to packages/wasm-dpp2/src/private_key.rs diff --git a/packages/wasm-dpp2/src/public_key/mod.rs b/packages/wasm-dpp2/src/public_key.rs similarity index 100% rename from packages/wasm-dpp2/src/public_key/mod.rs rename to packages/wasm-dpp2/src/public_key.rs diff --git a/packages/wasm-dpp2/src/state_transitions/base/group_state_transition_info/mod.rs b/packages/wasm-dpp2/src/state_transitions/base/group_state_transition_info.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/base/group_state_transition_info/mod.rs rename to packages/wasm-dpp2/src/state_transitions/base/group_state_transition_info.rs diff --git a/packages/wasm-dpp2/src/state_transitions/base/state_transition/mod.rs b/packages/wasm-dpp2/src/state_transitions/base/state_transition.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/base/state_transition/mod.rs rename to packages/wasm-dpp2/src/state_transitions/base/state_transition.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/batched_transition/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/batched_transition.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/batched_transition/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/batched_transition.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/document_base_transition/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_base_transition.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/document_base_transition/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_base_transition.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/document_transition/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transition.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/document_transition/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transition.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/create/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/create.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/document_transitions/create/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/create.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/delete/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/delete.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/document_transitions/delete/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/delete.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/purchase/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/purchase.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/document_transitions/purchase/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/purchase.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/replace/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/replace.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/document_transitions/replace/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/replace.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/transfer/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/transfer.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/document_transitions/transfer/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/transfer.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/update_price/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/update_price.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/document_transitions/update_price/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/document_transitions/update_price.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/prefunded_voting_balance/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/prefunded_voting_balance.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/prefunded_voting_balance/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/prefunded_voting_balance.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/token_base_transition/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_base_transition.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/token_base_transition/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_base_transition.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/token_payment_info/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_payment_info.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/token_payment_info/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_payment_info.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/token_pricing_schedule/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_pricing_schedule.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/token_pricing_schedule/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_pricing_schedule.rs diff --git a/packages/wasm-dpp2/src/state_transitions/batch/token_transition/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transition.rs similarity index 100% rename from packages/wasm-dpp2/src/state_transitions/batch/token_transition/mod.rs rename to packages/wasm-dpp2/src/state_transitions/batch/token_transition.rs diff --git a/packages/wasm-dpp2/src/tokens/encrypted_note/private_encrypted_note/mod.rs b/packages/wasm-dpp2/src/tokens/encrypted_note/private_encrypted_note.rs similarity index 100% rename from packages/wasm-dpp2/src/tokens/encrypted_note/private_encrypted_note/mod.rs rename to packages/wasm-dpp2/src/tokens/encrypted_note/private_encrypted_note.rs diff --git a/packages/wasm-dpp2/src/tokens/encrypted_note/shared_encrypted_note/mod.rs b/packages/wasm-dpp2/src/tokens/encrypted_note/shared_encrypted_note.rs similarity index 100% rename from packages/wasm-dpp2/src/tokens/encrypted_note/shared_encrypted_note/mod.rs rename to packages/wasm-dpp2/src/tokens/encrypted_note/shared_encrypted_note.rs diff --git a/packages/wasm-dpp2/src/utils/mod.rs b/packages/wasm-dpp2/src/utils.rs similarity index 100% rename from packages/wasm-dpp2/src/utils/mod.rs rename to packages/wasm-dpp2/src/utils.rs From f1d296ddb32c0af65f79abc9cff88b2779bd895e Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 7 Oct 2025 19:16:08 +0700 Subject: [PATCH 15/44] refactor: move code from mod.rs --- .../instant/instant_asset_lock_proof.rs | 143 ++++++++ .../src/asset_lock_proof/instant/mod.rs | 145 +------- .../wasm-dpp2/src/asset_lock_proof/mod.rs | 179 +--------- .../wasm-dpp2/src/asset_lock_proof/proof.rs | 177 ++++++++++ .../src/data_contract/document/mod.rs | 106 +----- .../src/data_contract/document/model.rs | 104 ++++++ .../masternode_vote_transition.rs | 224 ++++++++++++ .../governance/masternode_vote/mod.rs | 226 +------------ .../batch/batch_transition.rs | 248 ++++++++++++++ .../src/state_transitions/batch/mod.rs | 251 +------------- .../wasm-dpp2/src/tokens/configuration/mod.rs | 318 +----------------- .../configuration/token_configuration.rs | 315 +++++++++++++++++ .../tokens/configuration_change_item/mod.rs | 231 +------------ .../token_configuration_change_item.rs | 229 +++++++++++++ 14 files changed, 1454 insertions(+), 1442 deletions(-) create mode 100644 packages/wasm-dpp2/src/asset_lock_proof/instant/instant_asset_lock_proof.rs create mode 100644 packages/wasm-dpp2/src/asset_lock_proof/proof.rs create mode 100644 packages/wasm-dpp2/src/data_contract/document/model.rs create mode 100644 packages/wasm-dpp2/src/identity/governance/masternode_vote/masternode_vote_transition.rs create mode 100644 packages/wasm-dpp2/src/state_transitions/batch/batch_transition.rs create mode 100644 packages/wasm-dpp2/src/tokens/configuration/token_configuration.rs create mode 100644 packages/wasm-dpp2/src/tokens/configuration_change_item/token_configuration_change_item.rs diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_asset_lock_proof.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_asset_lock_proof.rs new file mode 100644 index 00000000000..075d7031eba --- /dev/null +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_asset_lock_proof.rs @@ -0,0 +1,143 @@ +use crate::asset_lock_proof::instant::instant_lock::InstantLockWasm; +use crate::asset_lock_proof::outpoint::OutPointWasm; +use crate::asset_lock_proof::tx_out::TxOutWasm; +use crate::error::{WasmDppError, WasmDppResult}; +use crate::identifier::IdentifierWasm; +use dpp::dashcore::consensus::{deserialize, serialize}; +use dpp::dashcore::{InstantLock, Transaction}; +use dpp::identity::state_transition::asset_lock_proof::InstantAssetLockProof; +use serde::{Deserialize, Serialize}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +struct InstantAssetLockProofRAW { + instant_lock: Vec, + transaction: Vec, + output_index: u32, +} + +#[derive(Clone)] +#[wasm_bindgen(js_name = "InstantAssetLockProof")] +pub struct InstantAssetLockProofWasm(InstantAssetLockProof); + +impl From for InstantAssetLockProof { + fn from(proof: InstantAssetLockProofWasm) -> Self { + proof.0 + } +} + +impl From for InstantAssetLockProofWasm { + fn from(proof: InstantAssetLockProof) -> Self { + InstantAssetLockProofWasm(proof) + } +} + +#[wasm_bindgen(js_class = InstantAssetLockProof)] +impl InstantAssetLockProofWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "InstantAssetLockProof".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "InstantAssetLockProof".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + instant_lock: Vec, + transaction: Vec, + output_index: u32, + ) -> WasmDppResult { + let instant_lock: InstantLock = deserialize(instant_lock.as_slice()) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + let transaction: Transaction = deserialize(transaction.as_slice()) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + Ok(InstantAssetLockProofWasm(InstantAssetLockProof { + instant_lock, + transaction, + output_index, + })) + } + + #[wasm_bindgen(js_name = "fromObject")] + pub fn from_object(value: JsValue) -> WasmDppResult { + let parameters: InstantAssetLockProofRAW = serde_wasm_bindgen::from_value(value) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + InstantAssetLockProofWasm::new( + parameters.instant_lock, + parameters.transaction, + parameters.output_index, + ) + } + + #[wasm_bindgen(js_name = "toObject")] + pub fn to_object(&self) -> WasmDppResult { + let serializer = serde_wasm_bindgen::Serializer::json_compatible(); + + self.0 + .to_object()? + .serialize(&serializer) + .map_err(|e| WasmDppError::serialization(e.to_string())) + } + + #[wasm_bindgen(js_name = "getOutput")] + pub fn get_output(&self) -> Option { + match self.0.output() { + Some(output) => Some(output.clone().into()), + None => None, + } + } + + #[wasm_bindgen(js_name = "getOutPoint")] + pub fn get_out_point(&self) -> Option { + match self.0.out_point() { + Some(output) => Some(output.clone().into()), + None => None, + } + } + + #[wasm_bindgen(getter = "outputIndex")] + pub fn get_output_index(&self) -> u32 { + self.0.output_index() + } + + #[wasm_bindgen(getter = "instantLock")] + pub fn get_instant_lock(&self) -> InstantLockWasm { + self.0.instant_lock.clone().into() + } + + #[wasm_bindgen(setter = "outputIndex")] + pub fn set_output_index(&mut self, output_index: u32) { + self.0.output_index = output_index; + } + + #[wasm_bindgen(setter = "instantLock")] + pub fn set_instant_lock(&mut self, instant_lock: &InstantLockWasm) { + self.0.instant_lock = instant_lock.clone().into(); + } + + #[wasm_bindgen(js_name=getTransaction)] + pub fn get_transaction(&self) -> Vec { + let transaction = self.0.transaction(); + serialize(transaction) + } + + #[wasm_bindgen(js_name=getInstantLockBytes)] + pub fn get_instant_lock_bytes(&self) -> Vec { + let instant_lock = self.0.instant_lock(); + serialize(instant_lock) + } + + #[wasm_bindgen(js_name = "createIdentityId")] + pub fn create_identifier(&self) -> WasmDppResult { + let identifier = self.0.create_identifier()?; + + Ok(identifier.into()) + } +} diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs index a624f285550..a4eeeddb6ed 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/mod.rs @@ -1,145 +1,4 @@ +mod instant_asset_lock_proof; mod instant_lock; -use crate::asset_lock_proof::instant::instant_lock::InstantLockWasm; -use crate::asset_lock_proof::outpoint::OutPointWasm; -use crate::asset_lock_proof::tx_out::TxOutWasm; -use crate::error::{WasmDppError, WasmDppResult}; -use crate::identifier::IdentifierWasm; -use dpp::dashcore::consensus::{deserialize, serialize}; -use dpp::dashcore::{InstantLock, Transaction}; -use dpp::identity::state_transition::asset_lock_proof::InstantAssetLockProof; -use serde::{Deserialize, Serialize}; -use wasm_bindgen::JsValue; -use wasm_bindgen::prelude::wasm_bindgen; - -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -struct InstantAssetLockProofRAW { - instant_lock: Vec, - transaction: Vec, - output_index: u32, -} - -#[derive(Clone)] -#[wasm_bindgen(js_name = "InstantAssetLockProof")] -pub struct InstantAssetLockProofWasm(InstantAssetLockProof); - -impl From for InstantAssetLockProof { - fn from(proof: InstantAssetLockProofWasm) -> Self { - proof.0 - } -} - -impl From for InstantAssetLockProofWasm { - fn from(proof: InstantAssetLockProof) -> Self { - InstantAssetLockProofWasm(proof) - } -} - -#[wasm_bindgen(js_class = InstantAssetLockProof)] -impl InstantAssetLockProofWasm { - #[wasm_bindgen(getter = __type)] - pub fn type_name(&self) -> String { - "InstantAssetLockProof".to_string() - } - - #[wasm_bindgen(getter = __struct)] - pub fn struct_name() -> String { - "InstantAssetLockProof".to_string() - } - - #[wasm_bindgen(constructor)] - pub fn new( - instant_lock: Vec, - transaction: Vec, - output_index: u32, - ) -> WasmDppResult { - let instant_lock: InstantLock = deserialize(instant_lock.as_slice()) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - let transaction: Transaction = deserialize(transaction.as_slice()) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - Ok(InstantAssetLockProofWasm(InstantAssetLockProof { - instant_lock, - transaction, - output_index, - })) - } - - #[wasm_bindgen(js_name = "fromObject")] - pub fn from_object(value: JsValue) -> WasmDppResult { - let parameters: InstantAssetLockProofRAW = serde_wasm_bindgen::from_value(value) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - InstantAssetLockProofWasm::new( - parameters.instant_lock, - parameters.transaction, - parameters.output_index, - ) - } - - #[wasm_bindgen(js_name = "toObject")] - pub fn to_object(&self) -> WasmDppResult { - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - - self.0 - .to_object()? - .serialize(&serializer) - .map_err(|e| WasmDppError::serialization(e.to_string())) - } - - #[wasm_bindgen(js_name = "getOutput")] - pub fn get_output(&self) -> Option { - match self.0.output() { - Some(output) => Some(output.clone().into()), - None => None, - } - } - - #[wasm_bindgen(js_name = "getOutPoint")] - pub fn get_out_point(&self) -> Option { - match self.0.out_point() { - Some(output) => Some(output.clone().into()), - None => None, - } - } - - #[wasm_bindgen(getter = "outputIndex")] - pub fn get_output_index(&self) -> u32 { - self.0.output_index() - } - - #[wasm_bindgen(getter = "instantLock")] - pub fn get_instant_lock(&self) -> InstantLockWasm { - self.0.instant_lock.clone().into() - } - - #[wasm_bindgen(setter = "outputIndex")] - pub fn set_output_index(&mut self, output_index: u32) { - self.0.output_index = output_index; - } - - #[wasm_bindgen(setter = "instantLock")] - pub fn set_instant_lock(&mut self, instant_lock: &InstantLockWasm) { - self.0.instant_lock = instant_lock.clone().into(); - } - - #[wasm_bindgen(js_name=getTransaction)] - pub fn get_transaction(&self) -> Vec { - let transaction = self.0.transaction(); - serialize(transaction) - } - - #[wasm_bindgen(js_name=getInstantLockBytes)] - pub fn get_instant_lock_bytes(&self) -> Vec { - let instant_lock = self.0.instant_lock(); - serialize(instant_lock) - } - - #[wasm_bindgen(js_name = "createIdentityId")] - pub fn create_identifier(&self) -> WasmDppResult { - let identifier = self.0.create_identifier()?; - - Ok(identifier.into()) - } -} +pub use instant_asset_lock_proof::InstantAssetLockProofWasm; diff --git a/packages/wasm-dpp2/src/asset_lock_proof/mod.rs b/packages/wasm-dpp2/src/asset_lock_proof/mod.rs index fe0e6e5a2fa..3bff8ec26b7 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/mod.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/mod.rs @@ -1,182 +1,7 @@ pub mod chain; pub mod instant; pub mod outpoint; +mod proof; mod tx_out; -use crate::asset_lock_proof::chain::ChainAssetLockProofWasm; -use crate::asset_lock_proof::instant::InstantAssetLockProofWasm; - -use crate::asset_lock_proof::outpoint::OutPointWasm; -use crate::enums::lock_types::AssetLockProofTypeWasm; -use crate::error::{WasmDppError, WasmDppResult}; -use crate::identifier::IdentifierWasm; -use crate::utils::{IntoWasm, get_class_type}; -use dpp::prelude::AssetLockProof; -use serde::Serialize; -use wasm_bindgen::JsValue; -use wasm_bindgen::prelude::wasm_bindgen; - -#[wasm_bindgen(js_name = "AssetLockProof")] -#[derive(Clone)] -pub struct AssetLockProofWasm(AssetLockProof); - -impl From for AssetLockProof { - fn from(proof: AssetLockProofWasm) -> Self { - proof.0 - } -} - -impl From for AssetLockProofWasm { - fn from(proof: AssetLockProof) -> Self { - AssetLockProofWasm(proof) - } -} - -impl From for AssetLockProofWasm { - fn from(proof: ChainAssetLockProofWasm) -> Self { - AssetLockProofWasm(AssetLockProof::Chain(proof.into())) - } -} - -impl From for AssetLockProofWasm { - fn from(proof: InstantAssetLockProofWasm) -> Self { - AssetLockProofWasm(AssetLockProof::Instant(proof.into())) - } -} - -impl From for ChainAssetLockProofWasm { - fn from(proof: AssetLockProof) -> ChainAssetLockProofWasm { - match proof { - AssetLockProof::Chain(chain) => ChainAssetLockProofWasm::from(chain), - _ => panic!("invalid asset lock proof. must contains chain lock"), - } - } -} - -impl From for InstantAssetLockProofWasm { - fn from(proof: AssetLockProof) -> InstantAssetLockProofWasm { - match proof { - AssetLockProof::Instant(instant) => InstantAssetLockProofWasm::from(instant), - _ => panic!("invalid asset lock proof. must contains chain lock"), - } - } -} - -#[wasm_bindgen(js_class = AssetLockProof)] -impl AssetLockProofWasm { - #[wasm_bindgen(getter = __type)] - pub fn type_name(&self) -> String { - "AssetLockProof".to_string() - } - - #[wasm_bindgen(getter = __struct)] - pub fn struct_name() -> String { - "AssetLockProof".to_string() - } - - #[wasm_bindgen(constructor)] - pub fn new(js_asset_lock_proof: &JsValue) -> WasmDppResult { - match get_class_type(js_asset_lock_proof)?.as_str() { - "ChainAssetLockProof" => { - let chain_lock = js_asset_lock_proof - .to_wasm::("ChainAssetLockProof")? - .clone(); - - Ok(AssetLockProofWasm::from(chain_lock)) - } - "InstantAssetLockProof" => { - let instant_lock = js_asset_lock_proof - .to_wasm::("InstantAssetLockProof")? - .clone(); - - Ok(AssetLockProofWasm::from(instant_lock)) - } - &_ => Err(WasmDppError::invalid_argument( - "Invalid asset lock proof type", - )), - } - } - - #[wasm_bindgen(js_name = "createInstantAssetLockProof")] - pub fn new_instant_asset_lock_proof( - instant_lock: Vec, - transaction: Vec, - output_index: u32, - ) -> WasmDppResult { - Ok(InstantAssetLockProofWasm::new(instant_lock, transaction, output_index)?.into()) - } - - #[wasm_bindgen(js_name = "createChainAssetLockProof")] - pub fn new_chain_asset_lock_proof( - core_chain_locked_height: u32, - out_point: &OutPointWasm, - ) -> WasmDppResult { - Ok(ChainAssetLockProofWasm::new(core_chain_locked_height, out_point)?.into()) - } - - #[wasm_bindgen(js_name = "getLockType")] - pub fn get_lock_type(&self) -> String { - match self.0 { - AssetLockProof::Chain(_) => AssetLockProofTypeWasm::Chain.into(), - AssetLockProof::Instant(_) => AssetLockProofTypeWasm::Instant.into(), - } - } - - #[wasm_bindgen(js_name = "getInstantLockProof")] - pub fn get_instant_lock(&self) -> InstantAssetLockProofWasm { - self.clone().0.into() - } - - #[wasm_bindgen(js_name = "getChainLockProof")] - pub fn get_chain_lock(&self) -> ChainAssetLockProofWasm { - self.clone().0.into() - } - - #[wasm_bindgen(js_name = "getOutPoint")] - pub fn get_out_point(&self) -> Option { - match self.0.out_point() { - Some(out_point) => Some(OutPointWasm::from(out_point)), - None => None, - } - } - - #[wasm_bindgen(js_name = "createIdentityId")] - pub fn create_identifier(&self) -> WasmDppResult { - let identifier = self.0.create_identifier()?; - - Ok(identifier.into()) - } - - #[wasm_bindgen(js_name = "toObject")] - pub fn to_object(&self) -> WasmDppResult { - let json_value = self.0.to_raw_object()?; - - json_value - .serialize(&serde_wasm_bindgen::Serializer::json_compatible()) - .map_err(|e| WasmDppError::serialization(e.to_string())) - } - - #[wasm_bindgen(js_name = "toHex")] - pub fn to_string(&self) -> WasmDppResult { - let json = serde_json::to_string(&self.0) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - Ok(hex::encode(json)) - } - - #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(asset_lock_proof: String) -> WasmDppResult { - let asset_lock_proof_bytes = hex::decode(&asset_lock_proof).map_err(|e| { - WasmDppError::serialization(format!("Invalid asset lock proof hex: {}", e)) - })?; - - let json_str = String::from_utf8(asset_lock_proof_bytes).map_err(|e| { - WasmDppError::serialization(format!("Invalid UTF-8 in asset lock proof: {}", e)) - })?; - - let asset_lock_proof: AssetLockProof = serde_json::from_str(&json_str).map_err(|e| { - WasmDppError::serialization(format!("Failed to parse asset lock proof JSON: {}", e)) - })?; - - Ok(AssetLockProofWasm(asset_lock_proof)) - } -} +pub use proof::AssetLockProofWasm; diff --git a/packages/wasm-dpp2/src/asset_lock_proof/proof.rs b/packages/wasm-dpp2/src/asset_lock_proof/proof.rs new file mode 100644 index 00000000000..08fdb45e774 --- /dev/null +++ b/packages/wasm-dpp2/src/asset_lock_proof/proof.rs @@ -0,0 +1,177 @@ +use crate::asset_lock_proof::chain::ChainAssetLockProofWasm; +use crate::asset_lock_proof::instant::InstantAssetLockProofWasm; + +use crate::asset_lock_proof::outpoint::OutPointWasm; +use crate::enums::lock_types::AssetLockProofTypeWasm; +use crate::error::{WasmDppError, WasmDppResult}; +use crate::identifier::IdentifierWasm; +use crate::utils::{IntoWasm, get_class_type}; +use dpp::prelude::AssetLockProof; +use serde::Serialize; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "AssetLockProof")] +#[derive(Clone)] +pub struct AssetLockProofWasm(AssetLockProof); + +impl From for AssetLockProof { + fn from(proof: AssetLockProofWasm) -> Self { + proof.0 + } +} + +impl From for AssetLockProofWasm { + fn from(proof: AssetLockProof) -> Self { + AssetLockProofWasm(proof) + } +} + +impl From for AssetLockProofWasm { + fn from(proof: ChainAssetLockProofWasm) -> Self { + AssetLockProofWasm(AssetLockProof::Chain(proof.into())) + } +} + +impl From for AssetLockProofWasm { + fn from(proof: InstantAssetLockProofWasm) -> Self { + AssetLockProofWasm(AssetLockProof::Instant(proof.into())) + } +} + +impl From for ChainAssetLockProofWasm { + fn from(proof: AssetLockProof) -> ChainAssetLockProofWasm { + match proof { + AssetLockProof::Chain(chain) => ChainAssetLockProofWasm::from(chain), + _ => panic!("invalid asset lock proof. must contains chain lock"), + } + } +} + +impl From for InstantAssetLockProofWasm { + fn from(proof: AssetLockProof) -> InstantAssetLockProofWasm { + match proof { + AssetLockProof::Instant(instant) => InstantAssetLockProofWasm::from(instant), + _ => panic!("invalid asset lock proof. must contains chain lock"), + } + } +} + +#[wasm_bindgen(js_class = AssetLockProof)] +impl AssetLockProofWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "AssetLockProof".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "AssetLockProof".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new(js_asset_lock_proof: &JsValue) -> WasmDppResult { + match get_class_type(js_asset_lock_proof)?.as_str() { + "ChainAssetLockProof" => { + let chain_lock = js_asset_lock_proof + .to_wasm::("ChainAssetLockProof")? + .clone(); + + Ok(AssetLockProofWasm::from(chain_lock)) + } + "InstantAssetLockProof" => { + let instant_lock = js_asset_lock_proof + .to_wasm::("InstantAssetLockProof")? + .clone(); + + Ok(AssetLockProofWasm::from(instant_lock)) + } + &_ => Err(WasmDppError::invalid_argument( + "Invalid asset lock proof type", + )), + } + } + + #[wasm_bindgen(js_name = "createInstantAssetLockProof")] + pub fn new_instant_asset_lock_proof( + instant_lock: Vec, + transaction: Vec, + output_index: u32, + ) -> WasmDppResult { + Ok(InstantAssetLockProofWasm::new(instant_lock, transaction, output_index)?.into()) + } + + #[wasm_bindgen(js_name = "createChainAssetLockProof")] + pub fn new_chain_asset_lock_proof( + core_chain_locked_height: u32, + out_point: &OutPointWasm, + ) -> WasmDppResult { + Ok(ChainAssetLockProofWasm::new(core_chain_locked_height, out_point)?.into()) + } + + #[wasm_bindgen(js_name = "getLockType")] + pub fn get_lock_type(&self) -> String { + match self.0 { + AssetLockProof::Chain(_) => AssetLockProofTypeWasm::Chain.into(), + AssetLockProof::Instant(_) => AssetLockProofTypeWasm::Instant.into(), + } + } + + #[wasm_bindgen(js_name = "getInstantLockProof")] + pub fn get_instant_lock(&self) -> InstantAssetLockProofWasm { + self.clone().0.into() + } + + #[wasm_bindgen(js_name = "getChainLockProof")] + pub fn get_chain_lock(&self) -> ChainAssetLockProofWasm { + self.clone().0.into() + } + + #[wasm_bindgen(js_name = "getOutPoint")] + pub fn get_out_point(&self) -> Option { + match self.0.out_point() { + Some(out_point) => Some(OutPointWasm::from(out_point)), + None => None, + } + } + + #[wasm_bindgen(js_name = "createIdentityId")] + pub fn create_identifier(&self) -> WasmDppResult { + let identifier = self.0.create_identifier()?; + + Ok(identifier.into()) + } + + #[wasm_bindgen(js_name = "toObject")] + pub fn to_object(&self) -> WasmDppResult { + let json_value = self.0.to_raw_object()?; + + json_value + .serialize(&serde_wasm_bindgen::Serializer::json_compatible()) + .map_err(|e| WasmDppError::serialization(e.to_string())) + } + + #[wasm_bindgen(js_name = "toHex")] + pub fn to_string(&self) -> WasmDppResult { + let json = serde_json::to_string(&self.0) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + Ok(hex::encode(json)) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(asset_lock_proof: String) -> WasmDppResult { + let asset_lock_proof_bytes = hex::decode(&asset_lock_proof).map_err(|e| { + WasmDppError::serialization(format!("Invalid asset lock proof hex: {}", e)) + })?; + + let json_str = String::from_utf8(asset_lock_proof_bytes).map_err(|e| { + WasmDppError::serialization(format!("Invalid UTF-8 in asset lock proof: {}", e)) + })?; + + let asset_lock_proof: AssetLockProof = serde_json::from_str(&json_str).map_err(|e| { + WasmDppError::serialization(format!("Failed to parse asset lock proof JSON: {}", e)) + })?; + + Ok(AssetLockProofWasm(asset_lock_proof)) + } +} diff --git a/packages/wasm-dpp2/src/data_contract/document/mod.rs b/packages/wasm-dpp2/src/data_contract/document/mod.rs index 2d5eb39d683..1088b7fdcb8 100644 --- a/packages/wasm-dpp2/src/data_contract/document/mod.rs +++ b/packages/wasm-dpp2/src/data_contract/document/mod.rs @@ -1,106 +1,4 @@ pub mod methods; +mod model; -use crate::identifier::IdentifierWasm; -use dpp::document::{Document, DocumentV0, DocumentV0Getters}; -use dpp::identifier::Identifier; -use dpp::identity::TimestampMillis; -use dpp::platform_value::Value; -use dpp::prelude::{BlockHeight, CoreBlockHeight, Revision}; -use std::collections::BTreeMap; -use wasm_bindgen::prelude::wasm_bindgen; - -#[derive(Clone)] -#[wasm_bindgen(js_name = Document)] -pub struct DocumentWasm { - id: IdentifierWasm, - owner_id: IdentifierWasm, - revision: Option, - data_contract_id: IdentifierWasm, - document_type_name: String, - properties: BTreeMap, - created_at: Option, - updated_at: Option, - transferred_at: Option, - created_at_block_height: Option, - updated_at_block_height: Option, - transferred_at_block_height: Option, - created_at_core_block_height: Option, - updated_at_core_block_height: Option, - transferred_at_core_block_height: Option, - entropy: Option<[u8; 32]>, - creator_id: Option, -} - -impl From for Document { - fn from(wasm_doc: DocumentWasm) -> Self { - Document::V0(DocumentV0 { - id: wasm_doc.id.into(), - owner_id: wasm_doc.owner_id.into(), - properties: wasm_doc.properties, - revision: wasm_doc.revision, - created_at: wasm_doc.created_at, - updated_at: wasm_doc.updated_at, - transferred_at: wasm_doc.transferred_at, - created_at_block_height: wasm_doc.created_at_block_height, - updated_at_block_height: wasm_doc.updated_at_block_height, - transferred_at_block_height: wasm_doc.transferred_at_block_height, - created_at_core_block_height: wasm_doc.created_at_core_block_height, - updated_at_core_block_height: wasm_doc.updated_at_core_block_height, - transferred_at_core_block_height: wasm_doc.transferred_at_core_block_height, - creator_id: wasm_doc.creator_id.map(Into::into), - }) - } -} - -impl From for DocumentWasm { - fn from(doc: Document) -> Self { - DocumentWasm { - id: doc.id().into(), - owner_id: doc.owner_id().into(), - revision: doc.revision(), - data_contract_id: Identifier::default().into(), - document_type_name: "".to_string(), - properties: doc.properties().clone(), - created_at: doc.created_at(), - updated_at: doc.updated_at(), - transferred_at: doc.transferred_at(), - created_at_block_height: doc.created_at_block_height(), - updated_at_block_height: doc.updated_at_block_height(), - transferred_at_block_height: doc.transferred_at_block_height(), - created_at_core_block_height: doc.created_at_core_block_height(), - updated_at_core_block_height: doc.updated_at_core_block_height(), - transferred_at_core_block_height: doc.transferred_at_core_block_height(), - entropy: None, - creator_id: doc.creator_id().map(Into::into), - } - } -} - -impl DocumentWasm { - pub fn from_batch( - document: Document, - data_contract_id: Identifier, - document_type_name: String, - entropy: Option<[u8; 32]>, - ) -> Self { - DocumentWasm { - id: document.id().into(), - owner_id: document.owner_id().into(), - revision: document.revision(), - data_contract_id: data_contract_id.into(), - document_type_name, - properties: document.properties().clone(), - created_at: document.created_at(), - updated_at: document.updated_at(), - transferred_at: document.transferred_at(), - created_at_block_height: document.created_at_block_height(), - updated_at_block_height: document.updated_at_block_height(), - transferred_at_block_height: document.transferred_at_block_height(), - created_at_core_block_height: document.created_at_core_block_height(), - updated_at_core_block_height: document.updated_at_core_block_height(), - transferred_at_core_block_height: document.transferred_at_core_block_height(), - entropy, - creator_id: document.creator_id().map(Into::into), - } - } -} +pub use model::DocumentWasm; diff --git a/packages/wasm-dpp2/src/data_contract/document/model.rs b/packages/wasm-dpp2/src/data_contract/document/model.rs new file mode 100644 index 00000000000..441c66725c5 --- /dev/null +++ b/packages/wasm-dpp2/src/data_contract/document/model.rs @@ -0,0 +1,104 @@ +use crate::identifier::IdentifierWasm; +use dpp::document::{Document, DocumentV0, DocumentV0Getters}; +use dpp::identifier::Identifier; +use dpp::identity::TimestampMillis; +use dpp::platform_value::Value; +use dpp::prelude::{BlockHeight, CoreBlockHeight, Revision}; +use std::collections::BTreeMap; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name = Document)] +pub struct DocumentWasm { + pub(crate) id: IdentifierWasm, + pub(crate) owner_id: IdentifierWasm, + pub(crate) revision: Option, + pub(crate) data_contract_id: IdentifierWasm, + pub(crate) document_type_name: String, + pub(crate) properties: BTreeMap, + pub(crate) created_at: Option, + pub(crate) updated_at: Option, + pub(crate) transferred_at: Option, + pub(crate) created_at_block_height: Option, + pub(crate) updated_at_block_height: Option, + pub(crate) transferred_at_block_height: Option, + pub(crate) created_at_core_block_height: Option, + pub(crate) updated_at_core_block_height: Option, + pub(crate) transferred_at_core_block_height: Option, + pub(crate) entropy: Option<[u8; 32]>, + pub(crate) creator_id: Option, +} + +impl From for Document { + fn from(wasm_doc: DocumentWasm) -> Self { + Document::V0(DocumentV0 { + id: wasm_doc.id.into(), + owner_id: wasm_doc.owner_id.into(), + properties: wasm_doc.properties, + revision: wasm_doc.revision, + created_at: wasm_doc.created_at, + updated_at: wasm_doc.updated_at, + transferred_at: wasm_doc.transferred_at, + created_at_block_height: wasm_doc.created_at_block_height, + updated_at_block_height: wasm_doc.updated_at_block_height, + transferred_at_block_height: wasm_doc.transferred_at_block_height, + created_at_core_block_height: wasm_doc.created_at_core_block_height, + updated_at_core_block_height: wasm_doc.updated_at_core_block_height, + transferred_at_core_block_height: wasm_doc.transferred_at_core_block_height, + creator_id: wasm_doc.creator_id.map(Into::into), + }) + } +} + +impl From for DocumentWasm { + fn from(doc: Document) -> Self { + DocumentWasm { + id: doc.id().into(), + owner_id: doc.owner_id().into(), + revision: doc.revision(), + data_contract_id: Identifier::default().into(), + document_type_name: "".to_string(), + properties: doc.properties().clone(), + created_at: doc.created_at(), + updated_at: doc.updated_at(), + transferred_at: doc.transferred_at(), + created_at_block_height: doc.created_at_block_height(), + updated_at_block_height: doc.updated_at_block_height(), + transferred_at_block_height: doc.transferred_at_block_height(), + created_at_core_block_height: doc.created_at_core_block_height(), + updated_at_core_block_height: doc.updated_at_core_block_height(), + transferred_at_core_block_height: doc.transferred_at_core_block_height(), + entropy: None, + creator_id: doc.creator_id().map(Into::into), + } + } +} + +impl DocumentWasm { + pub fn from_batch( + document: Document, + data_contract_id: Identifier, + document_type_name: String, + entropy: Option<[u8; 32]>, + ) -> Self { + DocumentWasm { + id: document.id().into(), + owner_id: document.owner_id().into(), + revision: document.revision(), + data_contract_id: data_contract_id.into(), + document_type_name, + properties: document.properties().clone(), + created_at: document.created_at(), + updated_at: document.updated_at(), + transferred_at: document.transferred_at(), + created_at_block_height: document.created_at_block_height(), + updated_at_block_height: document.updated_at_block_height(), + transferred_at_block_height: document.transferred_at_block_height(), + created_at_core_block_height: document.created_at_core_block_height(), + updated_at_core_block_height: document.updated_at_core_block_height(), + transferred_at_core_block_height: document.transferred_at_core_block_height(), + entropy, + creator_id: document.creator_id().map(Into::into), + } + } +} diff --git a/packages/wasm-dpp2/src/identity/governance/masternode_vote/masternode_vote_transition.rs b/packages/wasm-dpp2/src/identity/governance/masternode_vote/masternode_vote_transition.rs new file mode 100644 index 00000000000..4b0da1907d6 --- /dev/null +++ b/packages/wasm-dpp2/src/identity/governance/masternode_vote/masternode_vote_transition.rs @@ -0,0 +1,224 @@ +use crate::asset_lock_proof::AssetLockProofWasm; +use crate::error::{WasmDppError, WasmDppResult}; +use crate::identifier::IdentifierWasm; +use crate::identity::governance::masternode_vote::vote::VoteWasm; +use crate::state_transitions::StateTransitionWasm; +use dpp::identity::KeyID; +use dpp::identity::state_transition::OptionallyAssetLockProved; +use dpp::platform_value::BinaryData; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::decode; +use dpp::prelude::IdentityNonce; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable}; +use dpp::state_transition::masternode_vote_transition::MasternodeVoteTransition; +use dpp::state_transition::masternode_vote_transition::accessors::MasternodeVoteTransitionAccessorsV0; +use dpp::state_transition::masternode_vote_transition::v0::MasternodeVoteTransitionV0; +use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "MasternodeVoteTransition")] +#[derive(Clone)] +pub struct MasternodeVoteTransitionWasm(MasternodeVoteTransition); + +impl From for MasternodeVoteTransitionWasm { + fn from(val: MasternodeVoteTransition) -> Self { + MasternodeVoteTransitionWasm(val) + } +} + +impl From for MasternodeVoteTransition { + fn from(val: MasternodeVoteTransitionWasm) -> Self { + val.0 + } +} + +#[wasm_bindgen(js_class = MasternodeVoteTransition)] +impl MasternodeVoteTransitionWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "MasternodeVoteTransition".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "MasternodeVoteTransition".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + js_pro_tx_hash: &JsValue, + js_voter_identity_id: &JsValue, + vote: &VoteWasm, + nonce: IdentityNonce, + signature_public_key: Option, + signature: Option>, + ) -> WasmDppResult { + let pro_tx_hash = IdentifierWasm::try_from(js_pro_tx_hash)?; + let voter_identity_id = IdentifierWasm::try_from(js_voter_identity_id)?; + + Ok(MasternodeVoteTransitionWasm(MasternodeVoteTransition::V0( + MasternodeVoteTransitionV0 { + pro_tx_hash: pro_tx_hash.into(), + voter_identity_id: voter_identity_id.into(), + vote: vote.clone().into(), + nonce, + signature_public_key_id: signature_public_key.unwrap_or(0), + signature: BinaryData::from(signature.unwrap_or(vec![])), + }, + ))) + } + + #[wasm_bindgen(getter = proTxHash)] + pub fn pro_tx_hash(&self) -> IdentifierWasm { + self.0.pro_tx_hash().into() + } + + #[wasm_bindgen(getter = voterIdentityId)] + pub fn voter_identity_id(&self) -> IdentifierWasm { + self.0.voter_identity_id().into() + } + + #[wasm_bindgen(getter = vote)] + pub fn vote(&self) -> VoteWasm { + self.0.vote().clone().into() + } + + #[wasm_bindgen(getter = nonce)] + pub fn nonce(&self) -> IdentityNonce { + self.0.nonce() + } + + #[wasm_bindgen(getter=signaturePublicKeyId)] + pub fn signature_public_key_id(&self) -> KeyID { + self.0.signature_public_key_id() + } + + #[wasm_bindgen(getter=signature)] + pub fn signature(&self) -> Vec { + self.0.signature().clone().to_vec() + } + + #[wasm_bindgen(setter = proTxHash)] + pub fn set_pro_tx_hash(&mut self, js_pro_tx_hash: &JsValue) -> WasmDppResult<()> { + let pro_tx_hash = IdentifierWasm::try_from(js_pro_tx_hash)?; + + self.0.set_pro_tx_hash(pro_tx_hash.into()); + + Ok(()) + } + + #[wasm_bindgen(setter = voterIdentityId)] + pub fn set_voter_identity_id(&mut self, js_voter_identity_id: &JsValue) -> WasmDppResult<()> { + let voter_identity_id = IdentifierWasm::try_from(js_voter_identity_id)?; + + self.0.set_voter_identity_id(voter_identity_id.into()); + + Ok(()) + } + + #[wasm_bindgen(setter = vote)] + pub fn set_vote(&mut self, vote: &VoteWasm) { + self.0.set_vote(vote.clone().into()) + } + + #[wasm_bindgen(setter = nonce)] + pub fn set_nonce(&mut self, nonce: IdentityNonce) { + self.0 = match self.0.clone() { + MasternodeVoteTransition::V0(mut vote) => { + vote.nonce = nonce; + + MasternodeVoteTransition::V0(vote) + } + } + } + + #[wasm_bindgen(setter=signaturePublicKeyId)] + pub fn set_signature_public_key_id(&mut self, signature_public_key_id: KeyID) { + self.0.set_signature_public_key_id(signature_public_key_id) + } + + #[wasm_bindgen(setter=signature)] + pub fn set_signature(&mut self, signature: Vec) { + self.0.set_signature_bytes(signature); + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> WasmDppResult { + let bytes = decode(hex.as_str(), Hex) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + MasternodeVoteTransitionWasm::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> WasmDppResult { + let bytes = decode(base64.as_str(), Base64) + .map_err(|err| WasmDppError::serialization(err.to_string()))?; + + MasternodeVoteTransitionWasm::from_bytes(bytes) + } + + #[wasm_bindgen(js_name = "toBytes")] + pub fn to_bytes(&self) -> WasmDppResult> { + self.0.serialize_to_bytes().map_err(Into::into) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> WasmDppResult { + let rs_transition = MasternodeVoteTransition::deserialize_from_bytes(bytes.as_slice())?; + + Ok(MasternodeVoteTransitionWasm(rs_transition)) + } + + #[wasm_bindgen(getter = "userFeeIncrease")] + pub fn get_user_fee_increase(&self) -> u16 { + self.0.user_fee_increase() + } + + #[wasm_bindgen(js_name = "getSignableBytes")] + pub fn get_signable_bytes(&self) -> WasmDppResult> { + self.0.signable_bytes().map_err(Into::into) + } + + #[wasm_bindgen(getter = "assetLock")] + pub fn get_asset_lock_proof(&self) -> Option { + match self.0.optional_asset_lock_proof().clone() { + None => None, + Some(asset_lock_proof) => Some(AssetLockProofWasm::from(asset_lock_proof.clone())), + } + } + + #[wasm_bindgen(setter = "userFeeIncrease")] + pub fn set_user_fee_increase(&mut self, amount: u16) { + self.0.set_user_fee_increase(amount) + } + + #[wasm_bindgen(getter = "modifiedDataIds")] + pub fn get_modified_data_ids(&self) -> Vec { + self.0 + .modified_data_ids() + .iter() + .map(|id| id.clone().into()) + .collect() + } + + #[wasm_bindgen(js_name = "toStateTransition")] + pub fn to_state_transition(&self) -> StateTransitionWasm { + StateTransitionWasm::from(StateTransition::MasternodeVote(self.clone().0)) + } + + #[wasm_bindgen(js_name = "fromStateTransition")] + pub fn from_state_transition( + st: &StateTransitionWasm, + ) -> WasmDppResult { + let rs_st: StateTransition = st.clone().into(); + + match rs_st { + StateTransition::MasternodeVote(st) => Ok(MasternodeVoteTransitionWasm(st)), + _ => Err(WasmDppError::invalid_argument( + "Invalid state document_transition type", + )), + } + } +} diff --git a/packages/wasm-dpp2/src/identity/governance/masternode_vote/mod.rs b/packages/wasm-dpp2/src/identity/governance/masternode_vote/mod.rs index 1aa28eeaa9c..53e3c4f1926 100644 --- a/packages/wasm-dpp2/src/identity/governance/masternode_vote/mod.rs +++ b/packages/wasm-dpp2/src/identity/governance/masternode_vote/mod.rs @@ -1,228 +1,6 @@ +mod masternode_vote_transition; pub mod resource_vote_choice; pub mod vote; pub mod vote_poll; -use crate::asset_lock_proof::AssetLockProofWasm; -use crate::error::{WasmDppError, WasmDppResult}; -use crate::identifier::IdentifierWasm; -use crate::identity::governance::masternode_vote::vote::VoteWasm; -use crate::state_transitions::StateTransitionWasm; -use dpp::identity::KeyID; -use dpp::identity::state_transition::OptionallyAssetLockProved; -use dpp::platform_value::BinaryData; -use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; -use dpp::platform_value::string_encoding::decode; -use dpp::prelude::IdentityNonce; -use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable}; -use dpp::state_transition::masternode_vote_transition::MasternodeVoteTransition; -use dpp::state_transition::masternode_vote_transition::accessors::MasternodeVoteTransitionAccessorsV0; -use dpp::state_transition::masternode_vote_transition::v0::MasternodeVoteTransitionV0; -use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; -use wasm_bindgen::JsValue; -use wasm_bindgen::prelude::wasm_bindgen; - -#[wasm_bindgen(js_name = "MasternodeVoteTransition")] -#[derive(Clone)] -pub struct MasternodeVoteTransitionWasm(MasternodeVoteTransition); - -impl From for MasternodeVoteTransitionWasm { - fn from(val: MasternodeVoteTransition) -> Self { - MasternodeVoteTransitionWasm(val) - } -} - -impl From for MasternodeVoteTransition { - fn from(val: MasternodeVoteTransitionWasm) -> Self { - val.0 - } -} - -#[wasm_bindgen(js_class = MasternodeVoteTransition)] -impl MasternodeVoteTransitionWasm { - #[wasm_bindgen(getter = __type)] - pub fn type_name(&self) -> String { - "MasternodeVoteTransition".to_string() - } - - #[wasm_bindgen(getter = __struct)] - pub fn struct_name() -> String { - "MasternodeVoteTransition".to_string() - } - - #[wasm_bindgen(constructor)] - pub fn new( - js_pro_tx_hash: &JsValue, - js_voter_identity_id: &JsValue, - vote: &VoteWasm, - nonce: IdentityNonce, - signature_public_key: Option, - signature: Option>, - ) -> WasmDppResult { - let pro_tx_hash = IdentifierWasm::try_from(js_pro_tx_hash)?; - let voter_identity_id = IdentifierWasm::try_from(js_voter_identity_id)?; - - Ok(MasternodeVoteTransitionWasm(MasternodeVoteTransition::V0( - MasternodeVoteTransitionV0 { - pro_tx_hash: pro_tx_hash.into(), - voter_identity_id: voter_identity_id.into(), - vote: vote.clone().into(), - nonce, - signature_public_key_id: signature_public_key.unwrap_or(0), - signature: BinaryData::from(signature.unwrap_or(vec![])), - }, - ))) - } - - #[wasm_bindgen(getter = proTxHash)] - pub fn pro_tx_hash(&self) -> IdentifierWasm { - self.0.pro_tx_hash().into() - } - - #[wasm_bindgen(getter = voterIdentityId)] - pub fn voter_identity_id(&self) -> IdentifierWasm { - self.0.voter_identity_id().into() - } - - #[wasm_bindgen(getter = vote)] - pub fn vote(&self) -> VoteWasm { - self.0.vote().clone().into() - } - - #[wasm_bindgen(getter = nonce)] - pub fn nonce(&self) -> IdentityNonce { - self.0.nonce() - } - - #[wasm_bindgen(getter=signaturePublicKeyId)] - pub fn signature_public_key_id(&self) -> KeyID { - self.0.signature_public_key_id() - } - - #[wasm_bindgen(getter=signature)] - pub fn signature(&self) -> Vec { - self.0.signature().clone().to_vec() - } - - #[wasm_bindgen(setter = proTxHash)] - pub fn set_pro_tx_hash(&mut self, js_pro_tx_hash: &JsValue) -> WasmDppResult<()> { - let pro_tx_hash = IdentifierWasm::try_from(js_pro_tx_hash)?; - - self.0.set_pro_tx_hash(pro_tx_hash.into()); - - Ok(()) - } - - #[wasm_bindgen(setter = voterIdentityId)] - pub fn set_voter_identity_id(&mut self, js_voter_identity_id: &JsValue) -> WasmDppResult<()> { - let voter_identity_id = IdentifierWasm::try_from(js_voter_identity_id)?; - - self.0.set_voter_identity_id(voter_identity_id.into()); - - Ok(()) - } - - #[wasm_bindgen(setter = vote)] - pub fn set_vote(&mut self, vote: &VoteWasm) { - self.0.set_vote(vote.clone().into()) - } - - #[wasm_bindgen(setter = nonce)] - pub fn set_nonce(&mut self, nonce: IdentityNonce) { - self.0 = match self.0.clone() { - MasternodeVoteTransition::V0(mut vote) => { - vote.nonce = nonce; - - MasternodeVoteTransition::V0(vote) - } - } - } - - #[wasm_bindgen(setter=signaturePublicKeyId)] - pub fn set_signature_public_key_id(&mut self, signature_public_key_id: KeyID) { - self.0.set_signature_public_key_id(signature_public_key_id) - } - - #[wasm_bindgen(setter=signature)] - pub fn set_signature(&mut self, signature: Vec) { - self.0.set_signature_bytes(signature); - } - - #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> WasmDppResult { - let bytes = decode(hex.as_str(), Hex) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - MasternodeVoteTransitionWasm::from_bytes(bytes) - } - - #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> WasmDppResult { - let bytes = decode(base64.as_str(), Base64) - .map_err(|err| WasmDppError::serialization(err.to_string()))?; - - MasternodeVoteTransitionWasm::from_bytes(bytes) - } - - #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> WasmDppResult> { - self.0.serialize_to_bytes().map_err(Into::into) - } - - #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> WasmDppResult { - let rs_transition = MasternodeVoteTransition::deserialize_from_bytes(bytes.as_slice())?; - - Ok(MasternodeVoteTransitionWasm(rs_transition)) - } - - #[wasm_bindgen(getter = "userFeeIncrease")] - pub fn get_user_fee_increase(&self) -> u16 { - self.0.user_fee_increase() - } - - #[wasm_bindgen(js_name = "getSignableBytes")] - pub fn get_signable_bytes(&self) -> WasmDppResult> { - self.0.signable_bytes().map_err(Into::into) - } - - #[wasm_bindgen(getter = "assetLock")] - pub fn get_asset_lock_proof(&self) -> Option { - match self.0.optional_asset_lock_proof().clone() { - None => None, - Some(asset_lock_proof) => Some(AssetLockProofWasm::from(asset_lock_proof.clone())), - } - } - - #[wasm_bindgen(setter = "userFeeIncrease")] - pub fn set_user_fee_increase(&mut self, amount: u16) { - self.0.set_user_fee_increase(amount) - } - - #[wasm_bindgen(getter = "modifiedDataIds")] - pub fn get_modified_data_ids(&self) -> Vec { - self.0 - .modified_data_ids() - .iter() - .map(|id| id.clone().into()) - .collect() - } - - #[wasm_bindgen(js_name = "toStateTransition")] - pub fn to_state_transition(&self) -> StateTransitionWasm { - StateTransitionWasm::from(StateTransition::MasternodeVote(self.clone().0)) - } - - #[wasm_bindgen(js_name = "fromStateTransition")] - pub fn from_state_transition( - st: &StateTransitionWasm, - ) -> WasmDppResult { - let rs_st: StateTransition = st.clone().into(); - - match rs_st { - StateTransition::MasternodeVote(st) => Ok(MasternodeVoteTransitionWasm(st)), - _ => Err(WasmDppError::invalid_argument( - "Invalid state document_transition type", - )), - } - } -} +pub use masternode_vote_transition::MasternodeVoteTransitionWasm; diff --git a/packages/wasm-dpp2/src/state_transitions/batch/batch_transition.rs b/packages/wasm-dpp2/src/state_transitions/batch/batch_transition.rs new file mode 100644 index 00000000000..e1600cb94da --- /dev/null +++ b/packages/wasm-dpp2/src/state_transitions/batch/batch_transition.rs @@ -0,0 +1,248 @@ +use crate::error::{WasmDppError, WasmDppResult}; +use crate::identifier::IdentifierWasm; +use crate::state_transitions::StateTransitionWasm; +use crate::state_transitions::batch::batched_transition::BatchedTransitionWasm; +use crate::state_transitions::batch::document_transition::DocumentTransitionWasm; +use crate::utils::IntoWasm; +use dpp::fee::Credits; +use dpp::identity::KeyID; +use dpp::platform_value::BinaryData; +use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; +use dpp::platform_value::string_encoding::{decode, encode}; +use dpp::prelude::{IdentityNonce, UserFeeIncrease}; +use dpp::serialization::{PlatformDeserializable, PlatformSerializable}; +use dpp::state_transition::batch_transition::accessors::DocumentsBatchTransitionAccessorsV0; +use dpp::state_transition::batch_transition::batched_transition::BatchedTransition; +use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; +use dpp::state_transition::batch_transition::methods::v0::DocumentsBatchTransitionMethodsV0; +use dpp::state_transition::batch_transition::{ + BatchTransition, BatchTransitionV0, BatchTransitionV1, +}; +use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name=BatchTransition)] +pub struct BatchTransitionWasm(BatchTransition); + +impl From for BatchTransitionWasm { + fn from(batch: BatchTransition) -> Self { + BatchTransitionWasm(batch) + } +} + +impl From for BatchTransition { + fn from(batch: BatchTransitionWasm) -> Self { + batch.0 + } +} + +fn convert_array_to_vec_batched( + js_batched_transitions: &js_sys::Array, +) -> WasmDppResult> { + let mut transitions = Vec::with_capacity(js_batched_transitions.length() as usize); + + for js_batched_transition in js_batched_transitions.iter() { + let batched_transition: BatchedTransitionWasm = js_batched_transition + .to_wasm::("BatchedTransition")? + .clone(); + + transitions.push(BatchedTransition::from(batched_transition)); + } + + Ok(transitions) +} + +#[wasm_bindgen(js_class = BatchTransition)] +impl BatchTransitionWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "BatchTransition".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "BatchTransition".to_string() + } + + #[wasm_bindgen(js_name = "fromV1BatchedTransitions")] + pub fn from_v1_batched_transitions( + js_batched_transitions: &js_sys::Array, + owner_id: &JsValue, + user_fee_increase: UserFeeIncrease, + signature_public_key_id: Option, + signature: Option>, + ) -> WasmDppResult { + let transitions = convert_array_to_vec_batched(js_batched_transitions)?; + + Ok(BatchTransitionWasm(BatchTransition::V1( + BatchTransitionV1 { + owner_id: IdentifierWasm::try_from(owner_id)?.into(), + transitions, + user_fee_increase, + signature_public_key_id: signature_public_key_id.unwrap_or(0u32), + signature: BinaryData::from(signature.unwrap_or_default()), + }, + ))) + } + + #[wasm_bindgen(js_name = "fromV0Transitions")] + pub fn from_v0_transitions( + document_transitions: &js_sys::Array, + js_owner_id: &JsValue, + user_fee_increase: Option, + signature_public_key_id: Option, + signature: Option>, + ) -> WasmDppResult { + let owner_id = IdentifierWasm::try_from(js_owner_id)?; + + let mut transitions: Vec = + Vec::with_capacity(document_transitions.length() as usize); + + for js_document_transition in document_transitions.iter() { + let document_transition: DocumentTransitionWasm = js_document_transition + .to_wasm::("DocumentTransition")? + .clone(); + + transitions.push(DocumentTransition::from(document_transition)); + } + + Ok(BatchTransitionWasm(BatchTransition::V0( + BatchTransitionV0 { + owner_id: owner_id.into(), + transitions, + user_fee_increase: user_fee_increase.unwrap_or(0), + signature_public_key_id: signature_public_key_id.unwrap_or(0), + signature: BinaryData::from(signature.unwrap_or_default()), + }, + ))) + } + + #[wasm_bindgen(getter = "transitions")] + pub fn get_transitions(&self) -> Vec { + self.0 + .transitions_iter() + .map(|transition| BatchedTransitionWasm::from(transition.to_owned_transition())) + .collect() + } + + #[wasm_bindgen(setter = "transitions")] + pub fn set_transitions(&mut self, js_batched_transitions: &js_sys::Array) -> WasmDppResult<()> { + let transitions = convert_array_to_vec_batched(js_batched_transitions)?; + + self.0.set_transitions(transitions); + Ok(()) + } + + #[wasm_bindgen(getter = "signature")] + pub fn get_signature(&self) -> Vec { + self.0.signature().to_vec() + } + + #[wasm_bindgen(getter = "signaturePublicKeyId")] + pub fn get_signature_public_key_id(&self) -> KeyID { + self.0.signature_public_key_id() + } + + #[wasm_bindgen(getter = "allPurchasesAmount")] + pub fn get_all_purchases_amount(&self) -> WasmDppResult> { + self.0.all_document_purchases_amount().map_err(Into::into) + } + + #[wasm_bindgen(getter = "ownerId")] + pub fn get_owner_id(&self) -> IdentifierWasm { + self.0.owner_id().into() + } + + #[wasm_bindgen(getter = "modifiedDataIds")] + pub fn get_modified_data_ids(&self) -> Vec { + self.0 + .modified_data_ids() + .iter() + .map(|id| id.clone().into()) + .collect() + } + + #[wasm_bindgen(getter = "allConflictingIndexCollateralVotingFunds")] + pub fn get_all_conflicting_index_collateral_voting_funds( + &self, + ) -> WasmDppResult> { + self.0 + .all_conflicting_index_collateral_voting_funds() + .map_err(Into::into) + } + + #[wasm_bindgen(setter = "signature")] + pub fn set_signature(&mut self, js_signature: Vec) { + self.0.set_signature(BinaryData::from(js_signature)) + } + + #[wasm_bindgen(setter = "signaturePublicKeyId")] + pub fn set_signature_public_key_id(&mut self, key_id: KeyID) { + self.0.set_signature_public_key_id(key_id) + } + + #[wasm_bindgen(js_name = "setIdentityContractNonce")] + pub fn set_identity_contract_nonce(&mut self, nonce: IdentityNonce) { + self.0.set_identity_contract_nonce(nonce) + } + + #[wasm_bindgen(js_name = "toStateTransition")] + pub fn to_state_transition(&self) -> StateTransitionWasm { + let st = StateTransition::from(self.0.clone()); + + StateTransitionWasm::from(st) + } + + #[wasm_bindgen(js_name = "fromStateTransition")] + pub fn from_state_transition( + state_transition: &StateTransitionWasm, + ) -> WasmDppResult { + let rs_transition: StateTransition = StateTransition::from(state_transition.clone()); + + match rs_transition { + StateTransition::Batch(batch) => Ok(BatchTransitionWasm(batch)), + _ => Err(WasmDppError::invalid_argument( + "invalid state document_transition content", + )), + } + } + + #[wasm_bindgen(js_name = "toBytes")] + pub fn to_bytes(&self) -> WasmDppResult> { + self.0.serialize_to_bytes().map_err(Into::into) + } + + #[wasm_bindgen(js_name = "toHex")] + pub fn to_hex(&self) -> WasmDppResult { + Ok(encode(self.to_bytes()?.as_slice(), Hex)) + } + + #[wasm_bindgen(js_name = "base64")] + pub fn to_base64(&self) -> WasmDppResult { + Ok(encode(self.to_bytes()?.as_slice(), Base64)) + } + + #[wasm_bindgen(js_name = "fromBytes")] + pub fn from_bytes(bytes: Vec) -> WasmDppResult { + let rs_batch = BatchTransition::deserialize_from_bytes(bytes.as_slice())?; + + Ok(BatchTransitionWasm::from(rs_batch)) + } + + #[wasm_bindgen(js_name = "fromBase64")] + pub fn from_base64(base64: String) -> WasmDppResult { + BatchTransitionWasm::from_bytes( + decode(base64.as_str(), Base64) + .map_err(|err| WasmDppError::serialization(err.to_string()))?, + ) + } + + #[wasm_bindgen(js_name = "fromHex")] + pub fn from_hex(hex: String) -> WasmDppResult { + BatchTransitionWasm::from_bytes( + decode(hex.as_str(), Hex) + .map_err(|err| WasmDppError::serialization(err.to_string()))?, + ) + } +} diff --git a/packages/wasm-dpp2/src/state_transitions/batch/mod.rs b/packages/wasm-dpp2/src/state_transitions/batch/mod.rs index 60167d97a20..c5dd2d14610 100644 --- a/packages/wasm-dpp2/src/state_transitions/batch/mod.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/mod.rs @@ -1,27 +1,4 @@ -use crate::error::{WasmDppError, WasmDppResult}; -use crate::identifier::IdentifierWasm; -use crate::state_transitions::StateTransitionWasm; -use crate::state_transitions::batch::batched_transition::BatchedTransitionWasm; -use crate::state_transitions::batch::document_transition::DocumentTransitionWasm; -use crate::utils::IntoWasm; -use dpp::fee::Credits; -use dpp::identity::KeyID; -use dpp::platform_value::BinaryData; -use dpp::platform_value::string_encoding::Encoding::{Base64, Hex}; -use dpp::platform_value::string_encoding::{decode, encode}; -use dpp::prelude::{IdentityNonce, UserFeeIncrease}; -use dpp::serialization::{PlatformDeserializable, PlatformSerializable}; -use dpp::state_transition::batch_transition::accessors::DocumentsBatchTransitionAccessorsV0; -use dpp::state_transition::batch_transition::batched_transition::BatchedTransition; -use dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition; -use dpp::state_transition::batch_transition::methods::v0::DocumentsBatchTransitionMethodsV0; -use dpp::state_transition::batch_transition::{ - BatchTransition, BatchTransitionV0, BatchTransitionV1, -}; -use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike}; -use wasm_bindgen::JsValue; -use wasm_bindgen::prelude::wasm_bindgen; - +mod batch_transition; pub mod batched_transition; pub mod document_base_transition; pub mod document_transition; @@ -34,228 +11,4 @@ pub mod token_pricing_schedule; pub mod token_transition; pub mod token_transitions; -#[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name=BatchTransition)] -pub struct BatchTransitionWasm(BatchTransition); - -impl From for BatchTransitionWasm { - fn from(batch: BatchTransition) -> Self { - BatchTransitionWasm(batch) - } -} - -impl From for BatchTransition { - fn from(batch: BatchTransitionWasm) -> Self { - batch.0 - } -} - -fn convert_array_to_vec_batched( - js_batched_transitions: &js_sys::Array, -) -> WasmDppResult> { - let mut transitions = Vec::with_capacity(js_batched_transitions.length() as usize); - - for js_batched_transition in js_batched_transitions.iter() { - let batched_transition: BatchedTransitionWasm = js_batched_transition - .to_wasm::("BatchedTransition")? - .clone(); - - transitions.push(BatchedTransition::from(batched_transition)); - } - - Ok(transitions) -} - -#[wasm_bindgen(js_class = BatchTransition)] -impl BatchTransitionWasm { - #[wasm_bindgen(getter = __type)] - pub fn type_name(&self) -> String { - "BatchTransition".to_string() - } - - #[wasm_bindgen(getter = __struct)] - pub fn struct_name() -> String { - "BatchTransition".to_string() - } - - #[wasm_bindgen(js_name = "fromV1BatchedTransitions")] - pub fn from_v1_batched_transitions( - js_batched_transitions: &js_sys::Array, - owner_id: &JsValue, - user_fee_increase: UserFeeIncrease, - signature_public_key_id: Option, - signature: Option>, - ) -> WasmDppResult { - let transitions = convert_array_to_vec_batched(js_batched_transitions)?; - - Ok(BatchTransitionWasm(BatchTransition::V1( - BatchTransitionV1 { - owner_id: IdentifierWasm::try_from(owner_id)?.into(), - transitions, - user_fee_increase, - signature_public_key_id: signature_public_key_id.unwrap_or(0u32), - signature: BinaryData::from(signature.unwrap_or_default()), - }, - ))) - } - - #[wasm_bindgen(js_name = "fromV0Transitions")] - pub fn from_v0_transitions( - document_transitions: &js_sys::Array, - js_owner_id: &JsValue, - user_fee_increase: Option, - signature_public_key_id: Option, - signature: Option>, - ) -> WasmDppResult { - let owner_id = IdentifierWasm::try_from(js_owner_id)?; - - let mut transitions: Vec = - Vec::with_capacity(document_transitions.length() as usize); - - for js_document_transition in document_transitions.iter() { - let document_transition: DocumentTransitionWasm = js_document_transition - .to_wasm::("DocumentTransition")? - .clone(); - - transitions.push(DocumentTransition::from(document_transition)); - } - - Ok(BatchTransitionWasm(BatchTransition::V0( - BatchTransitionV0 { - owner_id: owner_id.into(), - transitions, - user_fee_increase: user_fee_increase.unwrap_or(0), - signature_public_key_id: signature_public_key_id.unwrap_or(0), - signature: BinaryData::from(signature.unwrap_or_default()), - }, - ))) - } - - #[wasm_bindgen(getter = "transitions")] - pub fn get_transitions(&self) -> Vec { - self.0 - .transitions_iter() - .map(|transition| BatchedTransitionWasm::from(transition.to_owned_transition())) - .collect() - } - - #[wasm_bindgen(setter = "transitions")] - pub fn set_transitions(&mut self, js_batched_transitions: &js_sys::Array) -> WasmDppResult<()> { - let transitions = convert_array_to_vec_batched(js_batched_transitions)?; - - self.0.set_transitions(transitions); - Ok(()) - } - - #[wasm_bindgen(getter = "signature")] - pub fn get_signature(&self) -> Vec { - self.0.signature().to_vec() - } - - #[wasm_bindgen(getter = "signaturePublicKeyId")] - pub fn get_signature_public_key_id(&self) -> KeyID { - self.0.signature_public_key_id() - } - - #[wasm_bindgen(getter = "allPurchasesAmount")] - pub fn get_all_purchases_amount(&self) -> WasmDppResult> { - self.0.all_document_purchases_amount().map_err(Into::into) - } - - #[wasm_bindgen(getter = "ownerId")] - pub fn get_owner_id(&self) -> IdentifierWasm { - self.0.owner_id().into() - } - - #[wasm_bindgen(getter = "modifiedDataIds")] - pub fn get_modified_data_ids(&self) -> Vec { - self.0 - .modified_data_ids() - .iter() - .map(|id| id.clone().into()) - .collect() - } - - #[wasm_bindgen(getter = "allConflictingIndexCollateralVotingFunds")] - pub fn get_all_conflicting_index_collateral_voting_funds( - &self, - ) -> WasmDppResult> { - self.0 - .all_conflicting_index_collateral_voting_funds() - .map_err(Into::into) - } - - #[wasm_bindgen(setter = "signature")] - pub fn set_signature(&mut self, js_signature: Vec) { - self.0.set_signature(BinaryData::from(js_signature)) - } - - #[wasm_bindgen(setter = "signaturePublicKeyId")] - pub fn set_signature_public_key_id(&mut self, key_id: KeyID) { - self.0.set_signature_public_key_id(key_id) - } - - #[wasm_bindgen(js_name = "setIdentityContractNonce")] - pub fn set_identity_contract_nonce(&mut self, nonce: IdentityNonce) { - self.0.set_identity_contract_nonce(nonce) - } - - #[wasm_bindgen(js_name = "toStateTransition")] - pub fn to_state_transition(&self) -> StateTransitionWasm { - let st = StateTransition::from(self.0.clone()); - - StateTransitionWasm::from(st) - } - - #[wasm_bindgen(js_name = "fromStateTransition")] - pub fn from_state_transition( - state_transition: &StateTransitionWasm, - ) -> WasmDppResult { - let rs_transition: StateTransition = StateTransition::from(state_transition.clone()); - - match rs_transition { - StateTransition::Batch(batch) => Ok(BatchTransitionWasm(batch)), - _ => Err(WasmDppError::invalid_argument( - "invalid state document_transition content", - )), - } - } - - #[wasm_bindgen(js_name = "toBytes")] - pub fn to_bytes(&self) -> WasmDppResult> { - self.0.serialize_to_bytes().map_err(Into::into) - } - - #[wasm_bindgen(js_name = "toHex")] - pub fn to_hex(&self) -> WasmDppResult { - Ok(encode(self.to_bytes()?.as_slice(), Hex)) - } - - #[wasm_bindgen(js_name = "base64")] - pub fn to_base64(&self) -> WasmDppResult { - Ok(encode(self.to_bytes()?.as_slice(), Base64)) - } - - #[wasm_bindgen(js_name = "fromBytes")] - pub fn from_bytes(bytes: Vec) -> WasmDppResult { - let rs_batch = BatchTransition::deserialize_from_bytes(bytes.as_slice())?; - - Ok(BatchTransitionWasm::from(rs_batch)) - } - - #[wasm_bindgen(js_name = "fromBase64")] - pub fn from_base64(base64: String) -> WasmDppResult { - BatchTransitionWasm::from_bytes( - decode(base64.as_str(), Base64) - .map_err(|err| WasmDppError::serialization(err.to_string()))?, - ) - } - - #[wasm_bindgen(js_name = "fromHex")] - pub fn from_hex(hex: String) -> WasmDppResult { - BatchTransitionWasm::from_bytes( - decode(hex.as_str(), Hex) - .map_err(|err| WasmDppError::serialization(err.to_string()))?, - ) - } -} +pub use batch_transition::BatchTransitionWasm; diff --git a/packages/wasm-dpp2/src/tokens/configuration/mod.rs b/packages/wasm-dpp2/src/tokens/configuration/mod.rs index a12c17078d5..86af0337db0 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/mod.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/mod.rs @@ -1,21 +1,3 @@ -use crate::error::WasmDppResult; -use crate::identifier::IdentifierWasm; -use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::tokens::configuration::change_control_rules::ChangeControlRulesWasm; -use crate::tokens::configuration::configuration_convention::TokenConfigurationConventionWasm; -use crate::tokens::configuration::distribution_rules::TokenDistributionRulesWasm; -use crate::tokens::configuration::keeps_history_rules::TokenKeepsHistoryRulesWasm; -use crate::tokens::configuration::marketplace_rules::TokenMarketplaceRulesWasm; -use dpp::balances::credits::TokenAmount; -use dpp::data_contract::associated_token::token_configuration::accessors::v0::{ - TokenConfigurationV0Getters, TokenConfigurationV0Setters, -}; -use dpp::data_contract::associated_token::token_configuration::v0::TokenConfigurationV0; -use dpp::data_contract::{GroupContractPosition, TokenConfiguration, TokenContractPosition}; -use dpp::tokens::calculate_token_id; -use wasm_bindgen::JsValue; -use wasm_bindgen::prelude::wasm_bindgen; - pub mod action_taker; pub mod authorized_action_takers; pub mod change_control_rules; @@ -31,303 +13,7 @@ pub mod marketplace_rules; pub mod perpetual_distribution; pub mod pre_programmed_distribution; pub mod reward_distribution_type; +mod token_configuration; pub mod trade_mode; -#[derive(Clone, PartialEq, Debug)] -#[wasm_bindgen(js_name = "TokenConfiguration")] -pub struct TokenConfigurationWasm(TokenConfiguration); - -impl From for TokenConfigurationWasm { - fn from(configuration: TokenConfiguration) -> Self { - Self(configuration) - } -} - -impl From for TokenConfiguration { - fn from(configuration: TokenConfigurationWasm) -> Self { - configuration.0 - } -} - -#[wasm_bindgen(js_class = TokenConfiguration)] -impl TokenConfigurationWasm { - #[wasm_bindgen(getter = __type)] - pub fn type_name(&self) -> String { - "TokenConfiguration".to_string() - } - - #[wasm_bindgen(getter = __struct)] - pub fn struct_name() -> String { - "TokenConfiguration".to_string() - } - - #[wasm_bindgen(constructor)] - pub fn new( - conventions: &TokenConfigurationConventionWasm, - conventions_change_rules: &ChangeControlRulesWasm, - base_supply: TokenAmount, - max_supply: Option, - keeps_history: &TokenKeepsHistoryRulesWasm, - start_as_paused: bool, - allow_transfer_to_frozen_balance: bool, - max_supply_change_rules: &ChangeControlRulesWasm, - distribution_rules: &TokenDistributionRulesWasm, - marketplace_rules: &TokenMarketplaceRulesWasm, - manual_minting_rules: &ChangeControlRulesWasm, - manual_burning_rules: &ChangeControlRulesWasm, - freeze_rules: &ChangeControlRulesWasm, - unfreeze_rules: &ChangeControlRulesWasm, - destroy_frozen_funds_rules: &ChangeControlRulesWasm, - emergency_action_rules: &ChangeControlRulesWasm, - main_control_group: Option, - main_control_group_can_be_modified: &AuthorizedActionTakersWasm, - description: Option, - ) -> TokenConfigurationWasm { - TokenConfigurationWasm(TokenConfiguration::V0(TokenConfigurationV0 { - conventions: conventions.clone().into(), - conventions_change_rules: conventions_change_rules.clone().into(), - base_supply, - max_supply, - keeps_history: keeps_history.clone().into(), - start_as_paused, - allow_transfer_to_frozen_balance, - max_supply_change_rules: max_supply_change_rules.clone().into(), - distribution_rules: distribution_rules.clone().into(), - marketplace_rules: marketplace_rules.clone().into(), - manual_minting_rules: manual_minting_rules.clone().into(), - manual_burning_rules: manual_burning_rules.clone().into(), - freeze_rules: freeze_rules.clone().into(), - unfreeze_rules: unfreeze_rules.clone().into(), - destroy_frozen_funds_rules: destroy_frozen_funds_rules.clone().into(), - emergency_action_rules: emergency_action_rules.clone().into(), - main_control_group, - main_control_group_can_be_modified: main_control_group_can_be_modified.clone().into(), - description, - })) - } - - #[wasm_bindgen(getter = "conventions")] - pub fn get_conventions(&self) -> TokenConfigurationConventionWasm { - self.0.conventions().clone().into() - } - - #[wasm_bindgen(getter = "conventionsChangeRules")] - pub fn get_conventions_change_rules(&self) -> ChangeControlRulesWasm { - self.0.conventions_change_rules().clone().into() - } - - #[wasm_bindgen(getter = "baseSupply")] - pub fn get_base_supply(&self) -> TokenAmount { - self.0.base_supply() - } - - #[wasm_bindgen(getter = "keepsHistory")] - pub fn get_keeps_history(&self) -> TokenKeepsHistoryRulesWasm { - self.0.keeps_history().clone().into() - } - - #[wasm_bindgen(getter = "startAsPaused")] - pub fn get_start_as_paused(&self) -> bool { - self.0.start_as_paused() - } - - #[wasm_bindgen(getter = "isAllowedTransferToFrozenBalance")] - pub fn get_is_allowed_transfer_to_frozen_balance(&self) -> bool { - self.0.is_allowed_transfer_to_frozen_balance() - } - - #[wasm_bindgen(getter = "maxSupply")] - pub fn get_max_supply(&self) -> Option { - self.0.max_supply() - } - - #[wasm_bindgen(getter = "maxSupplyChangeRules")] - pub fn get_max_supply_change_rules(&self) -> ChangeControlRulesWasm { - self.0.max_supply_change_rules().clone().into() - } - - #[wasm_bindgen(getter = "distributionRules")] - pub fn get_distribution_rules(&self) -> TokenDistributionRulesWasm { - self.0.distribution_rules().clone().into() - } - - #[wasm_bindgen(getter = "marketplaceRules")] - pub fn get_marketplace_rules(&self) -> TokenMarketplaceRulesWasm { - match self.0.clone() { - TokenConfiguration::V0(v0) => v0.marketplace_rules.clone().into(), - } - } - - #[wasm_bindgen(getter = "manualMintingRules")] - pub fn get_manual_minting_rules(&self) -> ChangeControlRulesWasm { - self.0.manual_minting_rules().clone().into() - } - - #[wasm_bindgen(getter = "manualBurningRules")] - pub fn get_manual_burning_rules(&self) -> ChangeControlRulesWasm { - self.0.manual_burning_rules().clone().into() - } - - #[wasm_bindgen(getter = "freezeRules")] - pub fn get_freeze_rules(&self) -> ChangeControlRulesWasm { - self.0.freeze_rules().clone().into() - } - - #[wasm_bindgen(getter = "unfreezeRules")] - pub fn get_unfreeze_rules(&self) -> ChangeControlRulesWasm { - self.0.unfreeze_rules().clone().into() - } - - #[wasm_bindgen(getter = "destroyFrozenFundsRules")] - pub fn get_destroy_frozen_funds_rules(&self) -> ChangeControlRulesWasm { - self.0.destroy_frozen_funds_rules().clone().into() - } - - #[wasm_bindgen(getter = "emergencyActionRules")] - pub fn get_emergency_action_rules(&self) -> ChangeControlRulesWasm { - self.0.emergency_action_rules().clone().into() - } - - #[wasm_bindgen(getter = "mainControlGroup")] - pub fn get_main_control_group(&self) -> Option { - self.0.main_control_group() - } - - #[wasm_bindgen(getter = "mainControlGroupCanBeModified")] - pub fn get_main_control_group_can_be_modified(&self) -> AuthorizedActionTakersWasm { - self.0.main_control_group_can_be_modified().clone().into() - } - - #[wasm_bindgen(getter = "description")] - pub fn get_description(&self) -> Option { - self.0.description().clone() - } - - #[wasm_bindgen(setter = "conventions")] - pub fn set_conventions(&mut self, conventions: &TokenConfigurationConventionWasm) { - self.0.set_conventions(conventions.clone().into()) - } - - #[wasm_bindgen(setter = "conventionsChangeRules")] - pub fn set_conventions_change_rules(&mut self, rules: &ChangeControlRulesWasm) { - self.0.set_conventions_change_rules(rules.clone().into()) - } - - #[wasm_bindgen(setter = "baseSupply")] - pub fn set_base_supply(&mut self, base_supply: TokenAmount) { - self.0.set_base_supply(base_supply) - } - - #[wasm_bindgen(setter = "keepsHistory")] - pub fn set_keeps_history(&mut self, keeps_history: &TokenKeepsHistoryRulesWasm) { - self.0 = match self.0.clone() { - TokenConfiguration::V0(mut v0) => { - v0.keeps_history = keeps_history.clone().into(); - - TokenConfiguration::V0(v0) - } - }; - } - - #[wasm_bindgen(setter = "startAsPaused")] - pub fn set_start_as_paused(&mut self, start_as_paused: bool) { - self.0.set_start_as_paused(start_as_paused) - } - - #[wasm_bindgen(setter = "isAllowedTransferToFrozenBalance")] - pub fn set_is_allowed_transfer_to_frozen_balance( - &mut self, - is_allowed_transfer_to_frozen_balance: bool, - ) { - self.0 - .allow_transfer_to_frozen_balance(is_allowed_transfer_to_frozen_balance); - } - - #[wasm_bindgen(setter = "maxSupply")] - pub fn set_max_supply(&mut self, max_supply: Option) { - self.0.set_max_supply(max_supply) - } - - #[wasm_bindgen(setter = "maxSupplyChangeRules")] - pub fn set_max_supply_change_rules(&mut self, rules: &ChangeControlRulesWasm) { - self.0.set_max_supply_change_rules(rules.clone().into()) - } - - #[wasm_bindgen(setter = "distributionRules")] - pub fn set_distribution_rules(&mut self, rules: &TokenDistributionRulesWasm) { - self.0.set_distribution_rules(rules.clone().into()) - } - - #[wasm_bindgen(setter = "marketplaceRules")] - pub fn set_marketplace_rules(&mut self, marketplace_rules: &TokenMarketplaceRulesWasm) { - self.0 = match self.0.clone() { - TokenConfiguration::V0(mut v0) => { - v0.marketplace_rules = marketplace_rules.clone().into(); - - TokenConfiguration::V0(v0) - } - } - } - - #[wasm_bindgen(setter = "manualMintingRules")] - pub fn set_manual_minting_rules(&mut self, rules: &ChangeControlRulesWasm) { - self.0.set_manual_minting_rules(rules.clone().into()) - } - - #[wasm_bindgen(setter = "manualBurningRules")] - pub fn set_manual_burning_rules(&mut self, rules: &ChangeControlRulesWasm) { - self.0.set_manual_burning_rules(rules.clone().into()) - } - - #[wasm_bindgen(setter = "freezeRules")] - pub fn set_freeze_rules(&mut self, rules: &ChangeControlRulesWasm) { - self.0.set_freeze_rules(rules.clone().into()) - } - - #[wasm_bindgen(setter = "unfreezeRules")] - pub fn set_unfreeze_rules(&mut self, rules: &ChangeControlRulesWasm) { - self.0.set_unfreeze_rules(rules.clone().into()) - } - - #[wasm_bindgen(setter = "destroyFrozenFundsRules")] - pub fn set_destroy_frozen_funds_rules(&mut self, rules: &ChangeControlRulesWasm) { - self.0.set_destroy_frozen_funds_rules(rules.clone().into()) - } - - #[wasm_bindgen(setter = "emergencyActionRules")] - pub fn set_emergency_action_rules(&mut self, rules: &ChangeControlRulesWasm) { - self.0.set_emergency_action_rules(rules.clone().into()) - } - - #[wasm_bindgen(setter = "mainControlGroup")] - pub fn set_main_control_group(&mut self, group: Option) { - self.0.set_main_control_group(group) - } - - #[wasm_bindgen(setter = "mainControlGroupCanBeModified")] - pub fn set_main_control_group_can_be_modified( - &mut self, - authorized_action_taker: &AuthorizedActionTakersWasm, - ) { - self.0 - .set_main_control_group_can_be_modified(authorized_action_taker.clone().into()) - } - - #[wasm_bindgen(setter = "description")] - pub fn set_description(&mut self, description: Option) { - self.0.set_description(description) - } - - #[wasm_bindgen(js_name = "calculateTokenId")] - pub fn calculate_token_id( - js_contract_id: &JsValue, - token_pos: TokenContractPosition, - ) -> WasmDppResult { - let contract_id = IdentifierWasm::try_from(js_contract_id)?; - - Ok(IdentifierWasm::from(calculate_token_id( - &contract_id.to_slice(), - token_pos, - ))) - } -} +pub use token_configuration::TokenConfigurationWasm; diff --git a/packages/wasm-dpp2/src/tokens/configuration/token_configuration.rs b/packages/wasm-dpp2/src/tokens/configuration/token_configuration.rs new file mode 100644 index 00000000000..8f6d14bb4bd --- /dev/null +++ b/packages/wasm-dpp2/src/tokens/configuration/token_configuration.rs @@ -0,0 +1,315 @@ +use crate::error::WasmDppResult; +use crate::identifier::IdentifierWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration::change_control_rules::ChangeControlRulesWasm; +use crate::tokens::configuration::configuration_convention::TokenConfigurationConventionWasm; +use crate::tokens::configuration::distribution_rules::TokenDistributionRulesWasm; +use crate::tokens::configuration::keeps_history_rules::TokenKeepsHistoryRulesWasm; +use crate::tokens::configuration::marketplace_rules::TokenMarketplaceRulesWasm; +use dpp::balances::credits::TokenAmount; +use dpp::data_contract::associated_token::token_configuration::accessors::v0::{ + TokenConfigurationV0Getters, TokenConfigurationV0Setters, +}; +use dpp::data_contract::associated_token::token_configuration::v0::TokenConfigurationV0; +use dpp::data_contract::{GroupContractPosition, TokenConfiguration, TokenContractPosition}; +use dpp::tokens::calculate_token_id; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; +#[derive(Clone, PartialEq, Debug)] +#[wasm_bindgen(js_name = "TokenConfiguration")] +pub struct TokenConfigurationWasm(TokenConfiguration); + +impl From for TokenConfigurationWasm { + fn from(configuration: TokenConfiguration) -> Self { + Self(configuration) + } +} + +impl From for TokenConfiguration { + fn from(configuration: TokenConfigurationWasm) -> Self { + configuration.0 + } +} + +#[wasm_bindgen(js_class = TokenConfiguration)] +impl TokenConfigurationWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenConfiguration".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenConfiguration".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + conventions: &TokenConfigurationConventionWasm, + conventions_change_rules: &ChangeControlRulesWasm, + base_supply: TokenAmount, + max_supply: Option, + keeps_history: &TokenKeepsHistoryRulesWasm, + start_as_paused: bool, + allow_transfer_to_frozen_balance: bool, + max_supply_change_rules: &ChangeControlRulesWasm, + distribution_rules: &TokenDistributionRulesWasm, + marketplace_rules: &TokenMarketplaceRulesWasm, + manual_minting_rules: &ChangeControlRulesWasm, + manual_burning_rules: &ChangeControlRulesWasm, + freeze_rules: &ChangeControlRulesWasm, + unfreeze_rules: &ChangeControlRulesWasm, + destroy_frozen_funds_rules: &ChangeControlRulesWasm, + emergency_action_rules: &ChangeControlRulesWasm, + main_control_group: Option, + main_control_group_can_be_modified: &AuthorizedActionTakersWasm, + description: Option, + ) -> TokenConfigurationWasm { + TokenConfigurationWasm(TokenConfiguration::V0(TokenConfigurationV0 { + conventions: conventions.clone().into(), + conventions_change_rules: conventions_change_rules.clone().into(), + base_supply, + max_supply, + keeps_history: keeps_history.clone().into(), + start_as_paused, + allow_transfer_to_frozen_balance, + max_supply_change_rules: max_supply_change_rules.clone().into(), + distribution_rules: distribution_rules.clone().into(), + marketplace_rules: marketplace_rules.clone().into(), + manual_minting_rules: manual_minting_rules.clone().into(), + manual_burning_rules: manual_burning_rules.clone().into(), + freeze_rules: freeze_rules.clone().into(), + unfreeze_rules: unfreeze_rules.clone().into(), + destroy_frozen_funds_rules: destroy_frozen_funds_rules.clone().into(), + emergency_action_rules: emergency_action_rules.clone().into(), + main_control_group, + main_control_group_can_be_modified: main_control_group_can_be_modified.clone().into(), + description, + })) + } + + #[wasm_bindgen(getter = "conventions")] + pub fn get_conventions(&self) -> TokenConfigurationConventionWasm { + self.0.conventions().clone().into() + } + + #[wasm_bindgen(getter = "conventionsChangeRules")] + pub fn get_conventions_change_rules(&self) -> ChangeControlRulesWasm { + self.0.conventions_change_rules().clone().into() + } + + #[wasm_bindgen(getter = "baseSupply")] + pub fn get_base_supply(&self) -> TokenAmount { + self.0.base_supply() + } + + #[wasm_bindgen(getter = "keepsHistory")] + pub fn get_keeps_history(&self) -> TokenKeepsHistoryRulesWasm { + self.0.keeps_history().clone().into() + } + + #[wasm_bindgen(getter = "startAsPaused")] + pub fn get_start_as_paused(&self) -> bool { + self.0.start_as_paused() + } + + #[wasm_bindgen(getter = "isAllowedTransferToFrozenBalance")] + pub fn get_is_allowed_transfer_to_frozen_balance(&self) -> bool { + self.0.is_allowed_transfer_to_frozen_balance() + } + + #[wasm_bindgen(getter = "maxSupply")] + pub fn get_max_supply(&self) -> Option { + self.0.max_supply() + } + + #[wasm_bindgen(getter = "maxSupplyChangeRules")] + pub fn get_max_supply_change_rules(&self) -> ChangeControlRulesWasm { + self.0.max_supply_change_rules().clone().into() + } + + #[wasm_bindgen(getter = "distributionRules")] + pub fn get_distribution_rules(&self) -> TokenDistributionRulesWasm { + self.0.distribution_rules().clone().into() + } + + #[wasm_bindgen(getter = "marketplaceRules")] + pub fn get_marketplace_rules(&self) -> TokenMarketplaceRulesWasm { + match self.0.clone() { + TokenConfiguration::V0(v0) => v0.marketplace_rules.clone().into(), + } + } + + #[wasm_bindgen(getter = "manualMintingRules")] + pub fn get_manual_minting_rules(&self) -> ChangeControlRulesWasm { + self.0.manual_minting_rules().clone().into() + } + + #[wasm_bindgen(getter = "manualBurningRules")] + pub fn get_manual_burning_rules(&self) -> ChangeControlRulesWasm { + self.0.manual_burning_rules().clone().into() + } + + #[wasm_bindgen(getter = "freezeRules")] + pub fn get_freeze_rules(&self) -> ChangeControlRulesWasm { + self.0.freeze_rules().clone().into() + } + + #[wasm_bindgen(getter = "unfreezeRules")] + pub fn get_unfreeze_rules(&self) -> ChangeControlRulesWasm { + self.0.unfreeze_rules().clone().into() + } + + #[wasm_bindgen(getter = "destroyFrozenFundsRules")] + pub fn get_destroy_frozen_funds_rules(&self) -> ChangeControlRulesWasm { + self.0.destroy_frozen_funds_rules().clone().into() + } + + #[wasm_bindgen(getter = "emergencyActionRules")] + pub fn get_emergency_action_rules(&self) -> ChangeControlRulesWasm { + self.0.emergency_action_rules().clone().into() + } + + #[wasm_bindgen(getter = "mainControlGroup")] + pub fn get_main_control_group(&self) -> Option { + self.0.main_control_group() + } + + #[wasm_bindgen(getter = "mainControlGroupCanBeModified")] + pub fn get_main_control_group_can_be_modified(&self) -> AuthorizedActionTakersWasm { + self.0.main_control_group_can_be_modified().clone().into() + } + + #[wasm_bindgen(getter = "description")] + pub fn get_description(&self) -> Option { + self.0.description().clone() + } + + #[wasm_bindgen(setter = "conventions")] + pub fn set_conventions(&mut self, conventions: &TokenConfigurationConventionWasm) { + self.0.set_conventions(conventions.clone().into()) + } + + #[wasm_bindgen(setter = "conventionsChangeRules")] + pub fn set_conventions_change_rules(&mut self, rules: &ChangeControlRulesWasm) { + self.0.set_conventions_change_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "baseSupply")] + pub fn set_base_supply(&mut self, base_supply: TokenAmount) { + self.0.set_base_supply(base_supply) + } + + #[wasm_bindgen(setter = "keepsHistory")] + pub fn set_keeps_history(&mut self, keeps_history: &TokenKeepsHistoryRulesWasm) { + self.0 = match self.0.clone() { + TokenConfiguration::V0(mut v0) => { + v0.keeps_history = keeps_history.clone().into(); + + TokenConfiguration::V0(v0) + } + }; + } + + #[wasm_bindgen(setter = "startAsPaused")] + pub fn set_start_as_paused(&mut self, start_as_paused: bool) { + self.0.set_start_as_paused(start_as_paused) + } + + #[wasm_bindgen(setter = "isAllowedTransferToFrozenBalance")] + pub fn set_is_allowed_transfer_to_frozen_balance( + &mut self, + is_allowed_transfer_to_frozen_balance: bool, + ) { + self.0 + .allow_transfer_to_frozen_balance(is_allowed_transfer_to_frozen_balance); + } + + #[wasm_bindgen(setter = "maxSupply")] + pub fn set_max_supply(&mut self, max_supply: Option) { + self.0.set_max_supply(max_supply) + } + + #[wasm_bindgen(setter = "maxSupplyChangeRules")] + pub fn set_max_supply_change_rules(&mut self, rules: &ChangeControlRulesWasm) { + self.0.set_max_supply_change_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "distributionRules")] + pub fn set_distribution_rules(&mut self, rules: &TokenDistributionRulesWasm) { + self.0.set_distribution_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "marketplaceRules")] + pub fn set_marketplace_rules(&mut self, marketplace_rules: &TokenMarketplaceRulesWasm) { + self.0 = match self.0.clone() { + TokenConfiguration::V0(mut v0) => { + v0.marketplace_rules = marketplace_rules.clone().into(); + + TokenConfiguration::V0(v0) + } + } + } + + #[wasm_bindgen(setter = "manualMintingRules")] + pub fn set_manual_minting_rules(&mut self, rules: &ChangeControlRulesWasm) { + self.0.set_manual_minting_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "manualBurningRules")] + pub fn set_manual_burning_rules(&mut self, rules: &ChangeControlRulesWasm) { + self.0.set_manual_burning_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "freezeRules")] + pub fn set_freeze_rules(&mut self, rules: &ChangeControlRulesWasm) { + self.0.set_freeze_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "unfreezeRules")] + pub fn set_unfreeze_rules(&mut self, rules: &ChangeControlRulesWasm) { + self.0.set_unfreeze_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "destroyFrozenFundsRules")] + pub fn set_destroy_frozen_funds_rules(&mut self, rules: &ChangeControlRulesWasm) { + self.0.set_destroy_frozen_funds_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "emergencyActionRules")] + pub fn set_emergency_action_rules(&mut self, rules: &ChangeControlRulesWasm) { + self.0.set_emergency_action_rules(rules.clone().into()) + } + + #[wasm_bindgen(setter = "mainControlGroup")] + pub fn set_main_control_group(&mut self, group: Option) { + self.0.set_main_control_group(group) + } + + #[wasm_bindgen(setter = "mainControlGroupCanBeModified")] + pub fn set_main_control_group_can_be_modified( + &mut self, + authorized_action_taker: &AuthorizedActionTakersWasm, + ) { + self.0 + .set_main_control_group_can_be_modified(authorized_action_taker.clone().into()) + } + + #[wasm_bindgen(setter = "description")] + pub fn set_description(&mut self, description: Option) { + self.0.set_description(description) + } + + #[wasm_bindgen(js_name = "calculateTokenId")] + pub fn calculate_token_id( + js_contract_id: &JsValue, + token_pos: TokenContractPosition, + ) -> WasmDppResult { + let contract_id = IdentifierWasm::try_from(js_contract_id)?; + + Ok(IdentifierWasm::from(calculate_token_id( + &contract_id.to_slice(), + token_pos, + ))) + } +} diff --git a/packages/wasm-dpp2/src/tokens/configuration_change_item/mod.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/mod.rs index 1fb13ff2bed..ee3343aa7c6 100644 --- a/packages/wasm-dpp2/src/tokens/configuration_change_item/mod.rs +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/mod.rs @@ -1,231 +1,4 @@ pub mod items; +mod token_configuration_change_item; -use crate::identifier::IdentifierWasm; -use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; -use crate::tokens::configuration::configuration_convention::TokenConfigurationConventionWasm; -use crate::tokens::configuration::perpetual_distribution::TokenPerpetualDistributionWasm; -use crate::tokens::configuration::trade_mode::TokenTradeModeWasm; -use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; -use wasm_bindgen::JsValue; -use wasm_bindgen::prelude::wasm_bindgen; - -#[derive(Debug, Clone, PartialEq)] -#[wasm_bindgen(js_name = "TokenConfigurationChangeItem")] -pub struct TokenConfigurationChangeItemWasm(TokenConfigurationChangeItem); - -impl From for TokenConfigurationChangeItem { - fn from(item: TokenConfigurationChangeItemWasm) -> Self { - item.0 - } -} - -impl From for TokenConfigurationChangeItemWasm { - fn from(item: TokenConfigurationChangeItem) -> Self { - TokenConfigurationChangeItemWasm(item) - } -} - -#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] -impl TokenConfigurationChangeItemWasm { - #[wasm_bindgen(getter = __type)] - pub fn type_name(&self) -> String { - "TokenConfigurationChangeItem".to_string() - } - - #[wasm_bindgen(getter = __struct)] - pub fn struct_name() -> String { - "TokenConfigurationChangeItem".to_string() - } - - #[wasm_bindgen(js_name = "getItemName")] - pub fn get_item_name(&self) -> String { - match self.0.clone() { - TokenConfigurationChangeItem::TokenConfigurationNoChange => { - String::from("TokenConfigurationNoChange") - } - TokenConfigurationChangeItem::Conventions(_) => String::from("Conventions"), - TokenConfigurationChangeItem::ConventionsControlGroup(_) => { - String::from("ConventionsControlGroup") - } - TokenConfigurationChangeItem::ConventionsAdminGroup(_) => { - String::from("ConventionsAdminGroup") - } - TokenConfigurationChangeItem::MaxSupply(_) => String::from("MaxSupply"), - TokenConfigurationChangeItem::MaxSupplyControlGroup(_) => { - String::from("MaxSupplyControlGroup") - } - TokenConfigurationChangeItem::MaxSupplyAdminGroup(_) => { - String::from("MaxSupplyAdminGroup") - } - TokenConfigurationChangeItem::PerpetualDistribution(_) => { - String::from("PerpetualDistribution") - } - TokenConfigurationChangeItem::PerpetualDistributionControlGroup(_) => { - String::from("PerpetualDistributionControlGroup") - } - TokenConfigurationChangeItem::PerpetualDistributionAdminGroup(_) => { - String::from("PerpetualDistributionAdminGroup") - } - TokenConfigurationChangeItem::NewTokensDestinationIdentity(_) => { - String::from("NewTokensDestinationIdentity") - } - TokenConfigurationChangeItem::NewTokensDestinationIdentityControlGroup(_) => { - String::from("NewTokensDestinationIdentityControlGroup") - } - TokenConfigurationChangeItem::NewTokensDestinationIdentityAdminGroup(_) => { - String::from("NewTokensDestinationIdentityAdminGroup") - } - TokenConfigurationChangeItem::MintingAllowChoosingDestination(_) => { - String::from("MintingAllowChoosingDestination") - } - TokenConfigurationChangeItem::MintingAllowChoosingDestinationControlGroup(_) => { - String::from("MintingAllowChoosingDestinationControlGroup") - } - TokenConfigurationChangeItem::MintingAllowChoosingDestinationAdminGroup(_) => { - String::from("MintingAllowChoosingDestinationAdminGroup") - } - TokenConfigurationChangeItem::ManualMinting(_) => String::from("ManualMinting"), - TokenConfigurationChangeItem::ManualMintingAdminGroup(_) => { - String::from("ManualMintingAdminGroup") - } - TokenConfigurationChangeItem::ManualBurning(_) => String::from("ManualBurning"), - TokenConfigurationChangeItem::ManualBurningAdminGroup(_) => { - String::from("ManualBurningAdminGroup") - } - TokenConfigurationChangeItem::Freeze(_) => String::from("Freeze"), - TokenConfigurationChangeItem::FreezeAdminGroup(_) => String::from("FreezeAdminGroup"), - TokenConfigurationChangeItem::Unfreeze(_) => String::from("Unfreeze"), - TokenConfigurationChangeItem::UnfreezeAdminGroup(_) => { - String::from("UnfreezeAdminGroup") - } - TokenConfigurationChangeItem::DestroyFrozenFunds(_) => { - String::from("DestroyFrozenFunds") - } - TokenConfigurationChangeItem::DestroyFrozenFundsAdminGroup(_) => { - String::from("DestroyFrozenFundsAdminGroup") - } - TokenConfigurationChangeItem::EmergencyAction(_) => String::from("EmergencyAction"), - TokenConfigurationChangeItem::EmergencyActionAdminGroup(_) => { - String::from("EmergencyActionAdminGroup") - } - TokenConfigurationChangeItem::MarketplaceTradeMode(_) => { - String::from("MarketplaceTradeMode") - } - TokenConfigurationChangeItem::MarketplaceTradeModeControlGroup(_) => { - String::from("MarketplaceTradeModeControlGroup") - } - TokenConfigurationChangeItem::MarketplaceTradeModeAdminGroup(_) => { - String::from("MarketplaceTradeModeAdminGroup") - } - TokenConfigurationChangeItem::MainControlGroup(_) => String::from("MainControlGroup"), - } - } - - #[wasm_bindgen(js_name = "getItem")] - pub fn get_item(&self) -> JsValue { - match self.0.clone() { - TokenConfigurationChangeItem::TokenConfigurationNoChange => { - JsValue::from_str("TokenConfigurationNoChange") - } - TokenConfigurationChangeItem::Conventions(convention) => { - JsValue::from(TokenConfigurationConventionWasm::from(convention)) - } - TokenConfigurationChangeItem::ConventionsControlGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::ConventionsAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::MaxSupply(amount) => JsValue::from(amount), - TokenConfigurationChangeItem::MaxSupplyControlGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::MaxSupplyAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::PerpetualDistribution(perpetual_distribution) => { - match perpetual_distribution { - Some(token_perpetual_distribution) => JsValue::from( - TokenPerpetualDistributionWasm::from(token_perpetual_distribution), - ), - None => JsValue::null(), - } - } - TokenConfigurationChangeItem::PerpetualDistributionControlGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::PerpetualDistributionAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::NewTokensDestinationIdentity(identifier) => { - match identifier { - Some(id) => JsValue::from(IdentifierWasm::from(id)), - None => JsValue::null(), - } - } - TokenConfigurationChangeItem::NewTokensDestinationIdentityControlGroup( - action_takers, - ) => JsValue::from(AuthorizedActionTakersWasm::from(action_takers)), - TokenConfigurationChangeItem::NewTokensDestinationIdentityAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::MintingAllowChoosingDestination(flag) => { - JsValue::from_bool(flag) - } - TokenConfigurationChangeItem::MintingAllowChoosingDestinationControlGroup( - action_takers, - ) => JsValue::from(AuthorizedActionTakersWasm::from(action_takers)), - TokenConfigurationChangeItem::MintingAllowChoosingDestinationAdminGroup( - action_takers, - ) => JsValue::from(AuthorizedActionTakersWasm::from(action_takers)), - TokenConfigurationChangeItem::ManualMinting(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::ManualMintingAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::ManualBurning(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::ManualBurningAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::Freeze(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::FreezeAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::Unfreeze(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::UnfreezeAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::DestroyFrozenFunds(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::DestroyFrozenFundsAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::EmergencyAction(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::EmergencyActionAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::MarketplaceTradeMode(trade_mode) => { - JsValue::from(TokenTradeModeWasm::from(trade_mode)) - } - TokenConfigurationChangeItem::MarketplaceTradeModeControlGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::MarketplaceTradeModeAdminGroup(action_takers) => { - JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) - } - TokenConfigurationChangeItem::MainControlGroup(group_contract_position) => { - JsValue::from(group_contract_position) - } - } - } -} +pub use token_configuration_change_item::TokenConfigurationChangeItemWasm; diff --git a/packages/wasm-dpp2/src/tokens/configuration_change_item/token_configuration_change_item.rs b/packages/wasm-dpp2/src/tokens/configuration_change_item/token_configuration_change_item.rs new file mode 100644 index 00000000000..4c15b08f79d --- /dev/null +++ b/packages/wasm-dpp2/src/tokens/configuration_change_item/token_configuration_change_item.rs @@ -0,0 +1,229 @@ +use crate::identifier::IdentifierWasm; +use crate::tokens::configuration::authorized_action_takers::AuthorizedActionTakersWasm; +use crate::tokens::configuration::configuration_convention::TokenConfigurationConventionWasm; +use crate::tokens::configuration::perpetual_distribution::TokenPerpetualDistributionWasm; +use crate::tokens::configuration::trade_mode::TokenTradeModeWasm; +use dpp::data_contract::associated_token::token_configuration_item::TokenConfigurationChangeItem; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Debug, Clone, PartialEq)] +#[wasm_bindgen(js_name = "TokenConfigurationChangeItem")] +pub struct TokenConfigurationChangeItemWasm(pub(crate) TokenConfigurationChangeItem); + +impl From for TokenConfigurationChangeItem { + fn from(item: TokenConfigurationChangeItemWasm) -> Self { + item.0 + } +} + +impl From for TokenConfigurationChangeItemWasm { + fn from(item: TokenConfigurationChangeItem) -> Self { + TokenConfigurationChangeItemWasm(item) + } +} + +#[wasm_bindgen(js_class = TokenConfigurationChangeItem)] +impl TokenConfigurationChangeItemWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenConfigurationChangeItem".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "TokenConfigurationChangeItem".to_string() + } + + #[wasm_bindgen(js_name = "getItemName")] + pub fn get_item_name(&self) -> String { + match self.0.clone() { + TokenConfigurationChangeItem::TokenConfigurationNoChange => { + String::from("TokenConfigurationNoChange") + } + TokenConfigurationChangeItem::Conventions(_) => String::from("Conventions"), + TokenConfigurationChangeItem::ConventionsControlGroup(_) => { + String::from("ConventionsControlGroup") + } + TokenConfigurationChangeItem::ConventionsAdminGroup(_) => { + String::from("ConventionsAdminGroup") + } + TokenConfigurationChangeItem::MaxSupply(_) => String::from("MaxSupply"), + TokenConfigurationChangeItem::MaxSupplyControlGroup(_) => { + String::from("MaxSupplyControlGroup") + } + TokenConfigurationChangeItem::MaxSupplyAdminGroup(_) => { + String::from("MaxSupplyAdminGroup") + } + TokenConfigurationChangeItem::PerpetualDistribution(_) => { + String::from("PerpetualDistribution") + } + TokenConfigurationChangeItem::PerpetualDistributionControlGroup(_) => { + String::from("PerpetualDistributionControlGroup") + } + TokenConfigurationChangeItem::PerpetualDistributionAdminGroup(_) => { + String::from("PerpetualDistributionAdminGroup") + } + TokenConfigurationChangeItem::NewTokensDestinationIdentity(_) => { + String::from("NewTokensDestinationIdentity") + } + TokenConfigurationChangeItem::NewTokensDestinationIdentityControlGroup(_) => { + String::from("NewTokensDestinationIdentityControlGroup") + } + TokenConfigurationChangeItem::NewTokensDestinationIdentityAdminGroup(_) => { + String::from("NewTokensDestinationIdentityAdminGroup") + } + TokenConfigurationChangeItem::MintingAllowChoosingDestination(_) => { + String::from("MintingAllowChoosingDestination") + } + TokenConfigurationChangeItem::MintingAllowChoosingDestinationControlGroup(_) => { + String::from("MintingAllowChoosingDestinationControlGroup") + } + TokenConfigurationChangeItem::MintingAllowChoosingDestinationAdminGroup(_) => { + String::from("MintingAllowChoosingDestinationAdminGroup") + } + TokenConfigurationChangeItem::ManualMinting(_) => String::from("ManualMinting"), + TokenConfigurationChangeItem::ManualMintingAdminGroup(_) => { + String::from("ManualMintingAdminGroup") + } + TokenConfigurationChangeItem::ManualBurning(_) => String::from("ManualBurning"), + TokenConfigurationChangeItem::ManualBurningAdminGroup(_) => { + String::from("ManualBurningAdminGroup") + } + TokenConfigurationChangeItem::Freeze(_) => String::from("Freeze"), + TokenConfigurationChangeItem::FreezeAdminGroup(_) => String::from("FreezeAdminGroup"), + TokenConfigurationChangeItem::Unfreeze(_) => String::from("Unfreeze"), + TokenConfigurationChangeItem::UnfreezeAdminGroup(_) => { + String::from("UnfreezeAdminGroup") + } + TokenConfigurationChangeItem::DestroyFrozenFunds(_) => { + String::from("DestroyFrozenFunds") + } + TokenConfigurationChangeItem::DestroyFrozenFundsAdminGroup(_) => { + String::from("DestroyFrozenFundsAdminGroup") + } + TokenConfigurationChangeItem::EmergencyAction(_) => String::from("EmergencyAction"), + TokenConfigurationChangeItem::EmergencyActionAdminGroup(_) => { + String::from("EmergencyActionAdminGroup") + } + TokenConfigurationChangeItem::MarketplaceTradeMode(_) => { + String::from("MarketplaceTradeMode") + } + TokenConfigurationChangeItem::MarketplaceTradeModeControlGroup(_) => { + String::from("MarketplaceTradeModeControlGroup") + } + TokenConfigurationChangeItem::MarketplaceTradeModeAdminGroup(_) => { + String::from("MarketplaceTradeModeAdminGroup") + } + TokenConfigurationChangeItem::MainControlGroup(_) => String::from("MainControlGroup"), + } + } + + #[wasm_bindgen(js_name = "getItem")] + pub fn get_item(&self) -> JsValue { + match self.0.clone() { + TokenConfigurationChangeItem::TokenConfigurationNoChange => { + JsValue::from_str("TokenConfigurationNoChange") + } + TokenConfigurationChangeItem::Conventions(convention) => { + JsValue::from(TokenConfigurationConventionWasm::from(convention)) + } + TokenConfigurationChangeItem::ConventionsControlGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::ConventionsAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::MaxSupply(amount) => JsValue::from(amount), + TokenConfigurationChangeItem::MaxSupplyControlGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::MaxSupplyAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::PerpetualDistribution(perpetual_distribution) => { + match perpetual_distribution { + Some(token_perpetual_distribution) => JsValue::from( + TokenPerpetualDistributionWasm::from(token_perpetual_distribution), + ), + None => JsValue::null(), + } + } + TokenConfigurationChangeItem::PerpetualDistributionControlGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::PerpetualDistributionAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::NewTokensDestinationIdentity(identifier) => { + match identifier { + Some(id) => JsValue::from(IdentifierWasm::from(id)), + None => JsValue::null(), + } + } + TokenConfigurationChangeItem::NewTokensDestinationIdentityControlGroup( + action_takers, + ) => JsValue::from(AuthorizedActionTakersWasm::from(action_takers)), + TokenConfigurationChangeItem::NewTokensDestinationIdentityAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::MintingAllowChoosingDestination(flag) => { + JsValue::from_bool(flag) + } + TokenConfigurationChangeItem::MintingAllowChoosingDestinationControlGroup( + action_takers, + ) => JsValue::from(AuthorizedActionTakersWasm::from(action_takers)), + TokenConfigurationChangeItem::MintingAllowChoosingDestinationAdminGroup( + action_takers, + ) => JsValue::from(AuthorizedActionTakersWasm::from(action_takers)), + TokenConfigurationChangeItem::ManualMinting(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::ManualMintingAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::ManualBurning(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::ManualBurningAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::Freeze(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::FreezeAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::Unfreeze(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::UnfreezeAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::DestroyFrozenFunds(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::DestroyFrozenFundsAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::EmergencyAction(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::EmergencyActionAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::MarketplaceTradeMode(trade_mode) => { + JsValue::from(TokenTradeModeWasm::from(trade_mode)) + } + TokenConfigurationChangeItem::MarketplaceTradeModeControlGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::MarketplaceTradeModeAdminGroup(action_takers) => { + JsValue::from(AuthorizedActionTakersWasm::from(action_takers)) + } + TokenConfigurationChangeItem::MainControlGroup(group_contract_position) => { + JsValue::from(group_contract_position) + } + } + } +} From 77e95aef65d89d1a02cf1bc06d7f3d9caa601255 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 8 Oct 2025 10:59:39 +0700 Subject: [PATCH 16/44] refactor: use entities for data contract and documents --- packages/wasm-sdk/src/dpns.rs | 351 +++++++++++-- packages/wasm-sdk/src/lib.rs | 53 +- .../wasm-sdk/src/queries/data_contract.rs | 224 ++++---- packages/wasm-sdk/src/queries/document.rs | 480 ++++-------------- packages/wasm-sdk/src/queries/dpns.rs | 170 ------- packages/wasm-sdk/src/queries/identity.rs | 2 +- packages/wasm-sdk/src/queries/mod.rs | 320 +++++++++++- packages/wasm-sdk/src/verify.rs | 189 ------- .../src/wallet/extended_derivation.rs | 2 +- .../wasm-sdk/src/wallet/key_derivation.rs | 2 +- .../wasm-sdk/src/wallet/key_generation.rs | 2 +- .../wasm-sdk/tests/functional/dpns.spec.mjs | 10 +- .../tests/unit/api-availability.spec.mjs | 9 - .../tests/unit/data-contract.spec.mjs | 4 +- 14 files changed, 872 insertions(+), 946 deletions(-) delete mode 100644 packages/wasm-sdk/src/queries/dpns.rs delete mode 100644 packages/wasm-sdk/src/verify.rs diff --git a/packages/wasm-sdk/src/dpns.rs b/packages/wasm-sdk/src/dpns.rs index 89945e17695..cfdf4a28f47 100644 --- a/packages/wasm-sdk/src/dpns.rs +++ b/packages/wasm-sdk/src/dpns.rs @@ -1,13 +1,18 @@ use crate::error::WasmSdkError; +use crate::queries::{ProofInfoWasm, ProofMetadataResponse, ResponseMetadataWasm}; use crate::sdk::WasmSdk; use dash_sdk::dpp::document::{Document, DocumentV0Getters}; use dash_sdk::dpp::identity::accessors::IdentityGettersV0; +use dash_sdk::dpp::platform_value::{string_encoding::Encoding, Value}; use dash_sdk::dpp::prelude::Identifier; use dash_sdk::platform::dpns_usernames::{ convert_to_homograph_safe_chars, is_contested_username, is_valid_username, RegisterDpnsNameInput, }; -use dash_sdk::platform::{Fetch, Identity}; +use dash_sdk::platform::{documents::document_query::DocumentQuery, Fetch, FetchMany, Identity}; +use drive::query::{WhereClause, WhereOperator}; +use drive_proof_verifier::types::Documents; +use js_sys::Array; use serde::{Deserialize, Serialize}; use simple_signer::SingleKeySigner; use wasm_bindgen::prelude::wasm_bindgen; @@ -21,27 +26,53 @@ pub struct RegisterDpnsNameResult { pub full_domain_name: String, } +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +struct DpnsUsernameInfo { + username: String, + identity_id: String, + document_id: String, +} + +#[wasm_bindgen(js_name = "DpnsUsernamesProofResponse")] +#[derive(Clone)] +pub struct DpnsUsernamesProofResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub usernames: Array, + #[wasm_bindgen(getter_with_clone)] + pub metadata: ResponseMetadataWasm, + #[wasm_bindgen(getter_with_clone)] + pub proof: ProofInfoWasm, +} + +#[wasm_bindgen(js_name = "DpnsUsernameProofResponse")] +#[derive(Clone)] +pub struct DpnsUsernameProofResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub username: JsValue, + #[wasm_bindgen(getter_with_clone)] + pub metadata: ResponseMetadataWasm, + #[wasm_bindgen(getter_with_clone)] + pub proof: ProofInfoWasm, +} + #[wasm_bindgen] impl WasmSdk { - /// Convert a string to homograph-safe characters #[wasm_bindgen(js_name = "dpnsConvertToHomographSafe")] pub fn dpns_convert_to_homograph_safe(input: &str) -> String { convert_to_homograph_safe_chars(input) } - /// Check if a username is valid according to DPNS rules #[wasm_bindgen(js_name = "dpnsIsValidUsername")] pub fn dpns_is_valid_username(label: &str) -> bool { is_valid_username(label) } - /// Check if a username is contested (requires masternode voting) #[wasm_bindgen(js_name = "dpnsIsContestedUsername")] pub fn dpns_is_contested_username(label: &str) -> bool { is_contested_username(label) } - /// Register a DPNS username #[wasm_bindgen(js_name = "dpnsRegisterName")] pub async fn dpns_register_name( &self, @@ -51,24 +82,19 @@ impl WasmSdk { private_key_wif: &str, preorder_callback: Option, ) -> Result { - // Parse identity ID let identity_id_parsed = Identifier::from_string( identity_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + Encoding::Base58, ) .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; - // Fetch the identity let identity = Identity::fetch(self.as_ref(), identity_id_parsed) .await? .ok_or_else(|| WasmSdkError::not_found("Identity not found"))?; - // Create signer - let signer = SingleKeySigner::new(private_key_wif).map_err(|e| { - WasmSdkError::invalid_argument(format!("Invalid private key WIF: {}", e)) - })?; + let signer = SingleKeySigner::new(private_key_wif) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid private key WIF: {}", e)))?; - // Get the specific identity public key let identity_public_key = identity .get_public_key_by_id(public_key_id) .ok_or_else(|| { @@ -76,26 +102,23 @@ impl WasmSdk { })? .clone(); - // Store the JS callback in a thread-local variable that we can access from the closure thread_local! { static PREORDER_CALLBACK: std::cell::RefCell> = const { std::cell::RefCell::new(None) }; } - // Set the callback if provided if let Some(ref js_callback) = preorder_callback { PREORDER_CALLBACK.with(|cb| { *cb.borrow_mut() = Some(js_callback.clone()); }); } - // Create a Rust callback that will call the JavaScript callback let callback_box = if preorder_callback.is_some() { Some(Box::new(move |doc: &Document| { PREORDER_CALLBACK.with(|cb| { if let Some(js_callback) = cb.borrow().as_ref() { let preorder_info = serde_json::json!({ - "documentId": doc.id().to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), - "ownerId": doc.owner_id().to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), + "documentId": doc.id().to_string(Encoding::Base58), + "ownerId": doc.owner_id().to_string(Encoding::Base58), "revision": doc.revision().unwrap_or(0), "createdAt": doc.created_at(), "createdAtBlockHeight": doc.created_at_block_height(), @@ -104,7 +127,7 @@ impl WasmSdk { }); if let Ok(js_value) = serde_wasm_bindgen::to_value(&preorder_info) { - let _ = js_callback.call1(&wasm_bindgen::JsValue::NULL, &js_value); + let _ = js_callback.call1(&JsValue::NULL, &js_value); } } }); @@ -113,7 +136,6 @@ impl WasmSdk { None }; - // Create registration input with the callback let input = RegisterDpnsNameInput { label: label.to_string(), identity, @@ -122,35 +144,30 @@ impl WasmSdk { preorder_callback: callback_box, }; - // Register the name let result = self.as_ref().register_dpns_name(input).await?; - // Clear the thread-local callback PREORDER_CALLBACK.with(|cb| { *cb.borrow_mut() = None; }); - // Convert result to JS-friendly format let js_result = RegisterDpnsNameResult { preorder_document_id: result .preorder_document .id() - .to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), + .to_string(Encoding::Base58), domain_document_id: result .domain_document .id() - .to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), + .to_string(Encoding::Base58), full_domain_name: result.full_domain_name, }; - // Serialize to JsValue let serializer = serde_wasm_bindgen::Serializer::json_compatible(); js_result .serialize(&serializer) .map_err(|e| WasmSdkError::serialization(format!("Failed to serialize result: {}", e))) } - /// Check if a DPNS name is available #[wasm_bindgen(js_name = "dpnsIsNameAvailable")] pub async fn dpns_is_name_available(&self, label: &str) -> Result { self.as_ref() @@ -159,18 +176,286 @@ impl WasmSdk { .map_err(WasmSdkError::from) } - /// Resolve a DPNS name to an identity ID #[wasm_bindgen(js_name = "dpnsResolveName")] pub async fn dpns_resolve_name(&self, name: &str) -> Result { let result = self.as_ref().resolve_dpns_name(name).await?; match result { - Some(identity_id) => { - let id_string = identity_id - .to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58); - Ok(wasm_bindgen::JsValue::from_str(&id_string)) + Some(identity_id) => Ok(JsValue::from_str(&identity_id.to_string(Encoding::Base58))), + None => Ok(JsValue::NULL), + } + } + + #[wasm_bindgen(js_name = "getDpnsUsernameByName")] + pub async fn get_dpns_username_by_name( + &self, + username: &str, + ) -> Result { + const DPNS_CONTRACT_ID: &str = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"; + const DPNS_DOCUMENT_TYPE: &str = "domain"; + + let parts: Vec<&str> = username.split('.').collect(); + if parts.len() != 2 { + return Err(WasmSdkError::invalid_argument( + "Invalid username format. Expected format: label.domain", + )); + } + let label = parts[0]; + let domain = parts[1]; + + let contract_id = Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)))?; + + let mut query = DocumentQuery::new_with_data_contract_id( + self.as_ref(), + contract_id, + DPNS_DOCUMENT_TYPE, + ) + .await?; + + query = query.with_where(WhereClause { + field: "normalizedLabel".to_string(), + operator: WhereOperator::Equal, + value: Value::Text(label.to_lowercase()), + }); + + query = query.with_where(WhereClause { + field: "normalizedParentDomainName".to_string(), + operator: WhereOperator::Equal, + value: Value::Text(domain.to_lowercase()), + }); + + let documents = Document::fetch_many(self.as_ref(), query).await?; + + if let Some((_, Some(document))) = documents.into_iter().next() { + let result = DpnsUsernameInfo { + username: username.to_string(), + identity_id: document.owner_id().to_string(Encoding::Base58), + document_id: document.id().to_string(Encoding::Base58), + }; + + serde_wasm_bindgen::to_value(&result).map_err(|e| { + WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) + }) + } else { + Err(WasmSdkError::not_found(format!( + "Username '{}' not found", + username + ))) + } + } + + #[wasm_bindgen(js_name = "getDpnsUsernameByNameWithProofInfo")] + pub async fn get_dpns_username_by_name_with_proof_info( + &self, + username: &str, + ) -> Result { + const DPNS_CONTRACT_ID: &str = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"; + const DPNS_DOCUMENT_TYPE: &str = "domain"; + + let parts: Vec<&str> = username.split('.').collect(); + if parts.len() != 2 { + return Err(WasmSdkError::invalid_argument( + "Invalid username format. Expected format: label.domain", + )); + } + let label = parts[0]; + let domain = parts[1]; + + let contract_id = Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)))?; + + let mut query = DocumentQuery::new_with_data_contract_id( + self.as_ref(), + contract_id, + DPNS_DOCUMENT_TYPE, + ) + .await?; + + query = query.with_where(WhereClause { + field: "normalizedLabel".to_string(), + operator: WhereOperator::Equal, + value: Value::Text(label.to_lowercase()), + }); + + query = query.with_where(WhereClause { + field: "normalizedParentDomainName".to_string(), + operator: WhereOperator::Equal, + value: Value::Text(domain.to_lowercase()), + }); + + let (documents, metadata, proof) = + Document::fetch_many_with_metadata_and_proof(self.as_ref(), query, None).await?; + + if let Some((_, Some(document))) = documents.into_iter().next() { + let result = DpnsUsernameInfo { + username: username.to_string(), + identity_id: document.owner_id().to_string(Encoding::Base58), + document_id: document.id().to_string(Encoding::Base58), + }; + + let response = ProofMetadataResponse { + data: result, + metadata: metadata.into(), + proof: proof.into(), + }; + + let serializer = serde_wasm_bindgen::Serializer::json_compatible(); + response.serialize(&serializer).map_err(|e| { + WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) + }) + } else { + Err(WasmSdkError::not_found(format!( + "Username '{}' not found", + username + ))) + } + } + + #[wasm_bindgen(js_name = "getDpnsUsernames")] + pub async fn get_dpns_usernames( + &self, + identity_id: &str, + limit: Option, + ) -> Result { + const DPNS_CONTRACT_ID: &str = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"; + const DPNS_DOCUMENT_TYPE: &str = "domain"; + + let identity_id_parsed = Identifier::from_string(identity_id, Encoding::Base58) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; + + let contract_id = Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)))?; + + let mut query = DocumentQuery::new_with_data_contract_id( + self.as_ref(), + contract_id, + DPNS_DOCUMENT_TYPE, + ) + .await?; + + let where_clause = WhereClause { + field: "records.identity".to_string(), + operator: WhereOperator::Equal, + value: Value::Identifier(identity_id_parsed.to_buffer()), + }; + + query = query.with_where(where_clause); + query.limit = limit.unwrap_or(10); + + let documents_result: Documents = Document::fetch_many(self.as_ref(), query).await?; + + let usernames_array = Array::new(); + + for (_, doc_opt) in documents_result { + if let Some(doc) = doc_opt { + let properties = doc.properties(); + + if let (Some(Value::Text(label)), Some(Value::Text(parent_domain))) = ( + properties.get("label"), + properties.get("normalizedParentDomainName"), + ) { + let username = format!("{}.{}", label, parent_domain); + usernames_array.push(&JsValue::from(username)); + } + } + } + + Ok(usernames_array.into()) + } + + #[wasm_bindgen(js_name = "getDpnsUsername")] + pub async fn get_dpns_username(&self, identity_id: &str) -> Result { + let result = self.get_dpns_usernames(identity_id, Some(1)).await?; + let array = Array::from(&result); + + if array.length() > 0 { + Ok(array.get(0)) + } else { + Ok(JsValue::NULL) + } + } + + #[wasm_bindgen(js_name = "getDpnsUsernamesWithProofInfo")] + pub async fn get_dpns_usernames_with_proof_info( + &self, + identity_id: &str, + limit: Option, + ) -> Result { + const DPNS_CONTRACT_ID: &str = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"; + const DPNS_DOCUMENT_TYPE: &str = "domain"; + + let identity_id_parsed = Identifier::from_string(identity_id, Encoding::Base58) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; + + let contract_id = Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)))?; + + let mut query = DocumentQuery::new_with_data_contract_id( + self.as_ref(), + contract_id, + DPNS_DOCUMENT_TYPE, + ) + .await?; + + let where_clause = WhereClause { + field: "records.identity".to_string(), + operator: WhereOperator::Equal, + value: Value::Identifier(identity_id_parsed.to_buffer()), + }; + + query = query.with_where(where_clause); + query.limit = limit.unwrap_or(10); + + let (documents_result, metadata, proof) = + Document::fetch_many_with_metadata_and_proof(self.as_ref(), query, None).await?; + + let usernames_array = Array::new(); + + for (_, doc_opt) in documents_result { + if let Some(doc) = doc_opt { + let properties = doc.properties(); + + if let (Some(Value::Text(label)), Some(Value::Text(parent_domain))) = ( + properties.get("label"), + properties.get("normalizedParentDomainName"), + ) { + let username = format!("{}.{}", label, parent_domain); + usernames_array.push(&JsValue::from(username)); + } } - None => Ok(wasm_bindgen::JsValue::NULL), } + + Ok(DpnsUsernamesProofResponseWasm { + usernames: usernames_array, + metadata: metadata.into(), + proof: proof.into(), + }) + } + + #[wasm_bindgen(js_name = "getDpnsUsernameWithProofInfo")] + pub async fn get_dpns_username_with_proof_info( + &self, + identity_id: &str, + ) -> Result { + let DpnsUsernamesProofResponseWasm { + usernames, + metadata, + proof, + } = self + .get_dpns_usernames_with_proof_info(identity_id, Some(1)) + .await?; + + let username = if usernames.length() > 0 { + usernames.get(0) + } else { + JsValue::NULL + }; + + Ok(DpnsUsernameProofResponseWasm { + username, + metadata, + proof, + }) } } diff --git a/packages/wasm-sdk/src/lib.rs b/packages/wasm-sdk/src/lib.rs index b77c833947a..e34c2116360 100644 --- a/packages/wasm-sdk/src/lib.rs +++ b/packages/wasm-sdk/src/lib.rs @@ -7,18 +7,61 @@ pub mod logging; pub mod queries; pub mod sdk; pub mod state_transitions; -pub mod verify; pub mod wallet; // Re-export commonly used items pub use dpns::*; pub use error::{WasmSdkError, WasmSdkErrorKind}; -pub use queries::{group::*, identity as query_identity}; -pub use sdk::{WasmSdk, WasmSdkBuilder}; +pub use queries::*; pub use state_transitions::identity as state_transition_identity; pub use wallet::*; -pub use wasm_dpp2::data_contract::DataContractWasm; -pub use wasm_dpp2::identity::IdentityWasm; +pub use wasm_dpp2::*; + +// pub use wasm_dpp2::asset_lock_proof::{ +// chain::ChainAssetLockProofWasm, instant::InstantAssetLockProofWasm, outpoint::OutPointWasm, +// AssetLockProofWasm, +// }; +// pub use wasm_dpp2::consensus_error::ConsensusErrorWasm; +// pub use wasm_dpp2::core_script::CoreScriptWasm; +// pub use wasm_dpp2::data_contract::{ +// ContractBoundsWasm, DataContractCreateTransitionWasm, DataContractUpdateTransitionWasm, +// DataContractWasm, DocumentWasm, +// }; +// pub use wasm_dpp2::enums::{ +// batch::batch_enum::BatchTypeWasm, +// batch::gas_fees_paid_by::GasFeesPaidByWasm, +// contested::vote_state_result_type::VoteStateResultTypeWasm, +// keys::{key_type::KeyTypeWasm, purpose::PurposeWasm, security_level::SecurityLevelWasm}, +// lock_types::AssetLockProofTypeWasm, +// network::NetworkWasm, +// platform::PlatformVersionWasm, +// token::{ +// action_goal::ActionGoalWasm, distribution_type::TokenDistributionTypeWasm, +// emergency_action::TokenEmergencyActionWasm, +// }, +// withdrawal::PoolingWasm, +// }; +// pub use wasm_dpp2::error::{WasmDppError, WasmDppErrorKind}; +// pub use wasm_dpp2::identifier::IdentifierWasm; +// pub use wasm_dpp2::identity::{ +// IdentityCreateTransitionWasm, IdentityCreditTransferWasm, +// IdentityCreditWithdrawalTransitionWasm, IdentityPublicKeyInCreationWasm, IdentityPublicKeyWasm, +// IdentityTopUpTransitionWasm, IdentityUpdateTransitionWasm, IdentityWasm, +// MasternodeVoteTransitionWasm, PartialIdentityWasm, ResourceVoteChoiceWasm, VotePollWasm, +// VoteWasm, +// }; +// pub use wasm_dpp2::private_key::PrivateKeyWasm; +// pub use wasm_dpp2::public_key::PublicKeyWasm; +// pub use wasm_dpp2::state_transitions::{ +// base::{GroupStateTransitionInfoWasm, StateTransitionWasm}, +// batch::{batched_transition::BatchedTransitionWasm, BatchTransitionWasm}, +// }; +// pub use wasm_dpp2::tokens::configuration::action_taker::ActionTakerWasm; +// pub use wasm_dpp2::tokens::configuration::change_control_rules::ChangeControlRulesWasm; +// pub use wasm_dpp2::tokens::{ +// AuthorizedActionTakersWasm, GroupWasm, PrivateEncryptedNoteWasm, SharedEncryptedNoteWasm, +// TokenConfigurationChangeItemWasm, TokenConfigurationLocalizationWasm, TokenConfigurationWasm, +// }; #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; diff --git a/packages/wasm-sdk/src/queries/data_contract.rs b/packages/wasm-sdk/src/queries/data_contract.rs index 246daab2b6e..7648a3ef66c 100644 --- a/packages/wasm-sdk/src/queries/data_contract.rs +++ b/packages/wasm-sdk/src/queries/data_contract.rs @@ -1,26 +1,46 @@ -use crate::queries::ProofMetadataResponse; +use crate::queries::{ProofInfoWasm, ResponseMetadataWasm}; use crate::sdk::WasmSdk; -use crate::DataContractWasm; use crate::WasmSdkError; -use dash_sdk::dpp::data_contract::conversion::json::DataContractJsonConversionMethodsV0; use dash_sdk::platform::query::LimitQuery; use dash_sdk::platform::{DataContract, Fetch, FetchMany, Identifier}; use drive_proof_verifier::types::{DataContractHistory, DataContracts}; -use serde::{Deserialize, Serialize}; -use std::collections::BTreeMap; -use wasm_bindgen::prelude::wasm_bindgen; +use js_sys::{BigInt, Map}; +use wasm_bindgen::prelude::*; use wasm_bindgen::JsValue; +use wasm_dpp2::DataContractWasm; +use wasm_dpp2::identifier::IdentifierWasm; + +#[wasm_bindgen(js_name = "DataContractProofResponse")] +#[derive(Clone)] +pub struct DataContractProofResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub contract: DataContractWasm, + #[wasm_bindgen(getter_with_clone)] + pub metadata: ResponseMetadataWasm, + #[wasm_bindgen(getter_with_clone)] + pub proof: ProofInfoWasm, +} -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct DataContractHistoryResponse { - versions: BTreeMap, +#[wasm_bindgen(js_name = "DataContractHistoryProofResponse")] +#[derive(Clone)] +pub struct DataContractHistoryProofResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub history: Map, + #[wasm_bindgen(getter_with_clone)] + pub metadata: ResponseMetadataWasm, + #[wasm_bindgen(getter_with_clone)] + pub proof: ProofInfoWasm, } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct DataContractsResponse { - data_contracts: BTreeMap>, +#[wasm_bindgen(js_name = "DataContractsProofResponse")] +#[derive(Clone)] +pub struct DataContractsProofResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub contracts: Map, + #[wasm_bindgen(getter_with_clone)] + pub metadata: ResponseMetadataWasm, + #[wasm_bindgen(getter_with_clone)] + pub proof: ProofInfoWasm, } #[wasm_bindgen] @@ -29,24 +49,25 @@ impl WasmSdk { pub async fn get_data_contract( &self, base58_id: &str, - ) -> Result { + ) -> Result, WasmSdkError> { let id = Identifier::from_string( base58_id, dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, ) .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid data contract ID: {}", e)))?; - DataContract::fetch_by_identifier(self.as_ref(), id) + let data_contract = DataContract::fetch_by_identifier(self.as_ref(), id) .await? - .ok_or_else(|| WasmSdkError::not_found("Data contract not found")) - .map(Into::into) + .map(DataContractWasm::from); + + Ok(data_contract) } #[wasm_bindgen(js_name = "getDataContractWithProofInfo")] pub async fn get_data_contract_with_proof_info( &self, base58_id: &str, - ) -> Result { + ) -> Result { let id = Identifier::from_string( base58_id, dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, @@ -57,28 +78,11 @@ impl WasmSdk { DataContract::fetch_with_metadata_and_proof(self.as_ref(), id, None).await?; match contract { - Some(contract) => { - let response = ProofMetadataResponse { - data: contract - .to_json( - dash_sdk::dpp::version::PlatformVersion::get(self.version()).unwrap(), - ) - .map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to convert contract to JSON: {}", - e - )) - })?, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } + Some(contract) => Ok(DataContractProofResponseWasm { + contract: DataContractWasm::from(contract), + metadata: metadata.into(), + proof: proof.into(), + }), None => Err(WasmSdkError::not_found("Data contract not found")), } } @@ -90,7 +94,7 @@ impl WasmSdk { limit: Option, _offset: Option, start_at_ms: Option, - ) -> Result { + ) -> Result { // Parse contract ID let contract_id = Identifier::from_string( id, @@ -108,35 +112,22 @@ impl WasmSdk { // Fetch contract history let history_result = DataContractHistory::fetch(self.as_ref(), query).await?; - // Convert to response format - let mut versions = BTreeMap::new(); - let platform_version = self.as_ref().version(); + let history_map = Map::new(); if let Some(history) = history_result { - for (revision, contract) in history { - versions.insert( - revision.to_string(), - contract.to_json(platform_version).map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to convert contract to JSON: {}", - e - )) - })?, - ); + for (block_time_ms, contract) in history { + let contract_js = JsValue::from(DataContractWasm::from(contract)); + let key = JsValue::from(BigInt::from(block_time_ms)); + + history_map.set(&key, &contract_js); } } - let response = DataContractHistoryResponse { versions }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(history_map) } #[wasm_bindgen(js_name = "getDataContracts")] - pub async fn get_data_contracts(&self, ids: Vec) -> Result { + pub async fn get_data_contracts(&self, ids: Vec) -> Result { // Parse all contract IDs let identifiers: Result, WasmSdkError> = ids .iter() @@ -156,31 +147,22 @@ impl WasmSdk { let contracts_result: DataContracts = DataContract::fetch_many(self.as_ref(), identifiers).await?; - // Convert to response format - let mut data_contracts = BTreeMap::new(); - let platform_version = self.as_ref().version(); + let contracts_map = Map::new(); + for (id, contract_opt) in contracts_result { - let id_str = - id.to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58); - let contract_json = match contract_opt { - Some(contract) => Some(contract.to_json(platform_version).map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to convert contract to JSON: {}", - e - )) - })?), - None => None, - }; - data_contracts.insert(id_str, contract_json); + let key = JsValue::from(IdentifierWasm::from(id)); + + match contract_opt { + Some(contract) => { + contracts_map.set(&key, &JsValue::from(DataContractWasm::from(contract))); + } + None => { + contracts_map.set(&key, &JsValue::NULL); + } + } } - let response = DataContractsResponse { data_contracts }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(contracts_map) } // Proof info versions for data contract queries @@ -192,7 +174,7 @@ impl WasmSdk { limit: Option, _offset: Option, start_at_ms: Option, - ) -> Result { + ) -> Result { // Parse contract ID let contract_id = Identifier::from_string( id, @@ -211,36 +193,21 @@ impl WasmSdk { let (history_result, metadata, proof) = DataContractHistory::fetch_with_metadata_and_proof(self.as_ref(), query, None).await?; - // Convert to response format - let mut versions = BTreeMap::new(); - let platform_version = self.as_ref().version(); + let history_map = Map::new(); if let Some(history) = history_result { - for (revision, contract) in history { - versions.insert( - revision.to_string(), - contract.to_json(platform_version).map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to convert contract to JSON: {}", - e - )) - })?, - ); + for (block_time_ms, contract) in history { + let contract_js = JsValue::from(DataContractWasm::from(contract)); + let key = JsValue::from(BigInt::from(block_time_ms)); + + history_map.set(&key, &contract_js); } } - let data = DataContractHistoryResponse { versions }; - - let response = ProofMetadataResponse { - data, + Ok(DataContractHistoryProofResponseWasm { + history: history_map, metadata: metadata.into(), proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) }) } @@ -248,7 +215,7 @@ impl WasmSdk { pub async fn get_data_contracts_with_proof_info( &self, ids: Vec, - ) -> Result { + ) -> Result { // Parse all contract IDs let identifiers: Result, WasmSdkError> = ids .iter() @@ -269,36 +236,25 @@ impl WasmSdk { DataContract::fetch_many_with_metadata_and_proof(self.as_ref(), identifiers, None) .await?; - // Convert to response format - let mut data_contracts = BTreeMap::new(); - let platform_version = self.as_ref().version(); + let contracts_map = Map::new(); + for (id, contract_opt) in contracts_result { - let id_str = - id.to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58); - let contract_json = match contract_opt { - Some(contract) => Some(contract.to_json(platform_version).map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to convert contract to JSON: {}", - e - )) - })?), - None => None, + let key = JsValue::from( + id.to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), + ); + + let value = match contract_opt { + Some(contract) => JsValue::from(DataContractWasm::from(contract)), + None => JsValue::NULL, }; - data_contracts.insert(id_str, contract_json); - } - let data = DataContractsResponse { data_contracts }; + contracts_map.set(&key, &value); + } - let response = ProofMetadataResponse { - data, + Ok(DataContractsProofResponseWasm { + contracts: contracts_map, metadata: metadata.into(), proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) }) } } diff --git a/packages/wasm-sdk/src/queries/document.rs b/packages/wasm-sdk/src/queries/document.rs index 9c453209d8d..ee3cbdb5ad7 100644 --- a/packages/wasm-sdk/src/queries/document.rs +++ b/packages/wasm-sdk/src/queries/document.rs @@ -1,93 +1,42 @@ -use crate::queries::ProofMetadataResponse; +use crate::queries::{ProofInfoWasm, ResponseMetadataWasm}; use crate::sdk::WasmSdk; use crate::WasmSdkError; use dash_sdk::dpp::data_contract::accessors::v0::DataContractV0Getters; use dash_sdk::dpp::document::Document; -use dash_sdk::dpp::document::DocumentV0Getters; use dash_sdk::dpp::platform_value::{platform_value, Value}; use dash_sdk::dpp::prelude::Identifier; use dash_sdk::platform::Fetch; use drive::query::{OrderClause, WhereClause, WhereOperator}; -use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::{JsCast, JsValue}; - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct DocumentResponse { - id: String, - owner_id: String, - revision: u64, - #[serde(skip_serializing_if = "Option::is_none")] - created_at: Option, - #[serde(skip_serializing_if = "Option::is_none")] - updated_at: Option, - #[serde(skip_serializing_if = "Option::is_none")] - transferred_at: Option, - #[serde(skip_serializing_if = "Option::is_none")] - created_at_block_height: Option, - #[serde(skip_serializing_if = "Option::is_none")] - updated_at_block_height: Option, - #[serde(skip_serializing_if = "Option::is_none")] - transferred_at_block_height: Option, - #[serde(skip_serializing_if = "Option::is_none")] - created_at_core_block_height: Option, - #[serde(skip_serializing_if = "Option::is_none")] - updated_at_core_block_height: Option, - #[serde(skip_serializing_if = "Option::is_none")] - transferred_at_core_block_height: Option, - data: serde_json::Map, +use wasm_bindgen::JsValue; +use js_sys::Map; +use wasm_dpp2::data_contract::document::DocumentWasm; +use wasm_dpp2::identifier::IdentifierWasm; + +#[wasm_bindgen(js_name = "DocumentProofResponse")] +#[derive(Clone)] +pub struct DocumentProofResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub document: Option, + #[wasm_bindgen(getter_with_clone)] + pub metadata: ResponseMetadataWasm, + #[wasm_bindgen(getter_with_clone)] + pub proof: ProofInfoWasm, } -impl DocumentResponse { - fn from_document( - doc: &Document, - _data_contract: &dash_sdk::platform::DataContract, - _document_type: dash_sdk::dpp::data_contract::document_type::DocumentTypeRef, - ) -> Result { - use dash_sdk::dpp::document::DocumentV0Getters; - - // For now, we'll continue with the existing approach - // In the future, we could use the document type to better interpret the data - - // Get document properties and convert each to JSON - let mut data = serde_json::Map::new(); - let properties = doc.properties(); - - for (key, value) in properties { - // Convert platform Value to JSON - let json_value: JsonValue = value.clone().try_into().map_err(|e| { - WasmSdkError::generic(format!("Failed to convert value to JSON: {:?}", e)) - })?; - - data.insert(key.clone(), json_value); - } - - let response = Self { - id: doc - .id() - .to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), - owner_id: doc - .owner_id() - .to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), - revision: doc.revision().unwrap_or(0), - created_at: doc.created_at(), - updated_at: doc.updated_at(), - transferred_at: doc.transferred_at(), - created_at_block_height: doc.created_at_block_height(), - updated_at_block_height: doc.updated_at_block_height(), - transferred_at_block_height: doc.transferred_at_block_height(), - created_at_core_block_height: doc.created_at_core_block_height(), - updated_at_core_block_height: doc.updated_at_core_block_height(), - transferred_at_core_block_height: doc.transferred_at_core_block_height(), - data, - }; - - Ok(response) - } +#[wasm_bindgen(js_name = "DocumentsProofResponse")] +#[derive(Clone)] +pub struct DocumentsProofResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub documents: Map, + #[wasm_bindgen(getter_with_clone)] + pub metadata: ResponseMetadataWasm, + #[wasm_bindgen(getter_with_clone)] + pub proof: ProofInfoWasm, } + /// Parse JSON where clause into WhereClause fn parse_where_clause(json_clause: &JsonValue) -> Result { let clause_array = json_clause @@ -232,7 +181,7 @@ impl WasmSdk { limit: Option, start_after: Option, start_at: Option, - ) -> Result { + ) -> Result { use dash_sdk::platform::documents::document_query::DocumentQuery; use dash_sdk::platform::FetchMany; use drive_proof_verifier::types::Documents; @@ -323,28 +272,36 @@ impl WasmSdk { .await? .ok_or_else(|| WasmSdkError::not_found("Data contract not found"))?; - // Get the document type - let document_type_ref = data_contract + // Ensure the document type exists + data_contract .document_type_for_name(document_type) .map_err(|e| WasmSdkError::not_found(format!("Document type not found: {}", e)))?; - // Convert documents to response format - let mut responses: Vec = Vec::new(); - for (_, doc_opt) in documents_result { - if let Some(doc) = doc_opt { - responses.push(DocumentResponse::from_document( - &doc, - &data_contract, - document_type_ref, - )?); + let documents_map = Map::new(); + let doc_type_name = document_type.to_string(); + + for (doc_id, doc_opt) in documents_result { + let key = JsValue::from( + IdentifierWasm::from(doc_id), + ); + + match doc_opt { + Some(doc) => { + let wasm_doc = DocumentWasm::from_batch( + doc, + contract_id, + doc_type_name.clone(), + None, + ); + documents_map.set(&key, &JsValue::from(wasm_doc)); + } + None => { + documents_map.set(&key, &JsValue::NULL); + } } } - // Use json_compatible serializer to convert maps to objects - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - responses.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(documents_map) } #[allow(clippy::too_many_arguments)] @@ -358,7 +315,7 @@ impl WasmSdk { limit: Option, start_after: Option, start_at: Option, - ) -> Result { + ) -> Result { use dash_sdk::platform::documents::document_query::DocumentQuery; use dash_sdk::platform::FetchMany; @@ -430,42 +387,37 @@ impl WasmSdk { } } - // Execute query with proof let (documents_result, metadata, proof) = Document::fetch_many_with_metadata_and_proof(self.as_ref(), query, None).await?; - // Fetch the data contract to get the document type - let data_contract = dash_sdk::platform::DataContract::fetch(self.as_ref(), contract_id) - .await? - .ok_or_else(|| WasmSdkError::not_found("Data contract not found"))?; - - // Get the document type - let document_type_ref = data_contract - .document_type_for_name(document_type) - .map_err(|e| WasmSdkError::not_found(format!("Document type not found: {}", e)))?; - - // Convert documents to response format - let mut responses: Vec = Vec::new(); - for (_, doc_opt) in documents_result { - if let Some(doc) = doc_opt { - responses.push(DocumentResponse::from_document( - &doc, - &data_contract, - document_type_ref, - )?); + let documents_map = Map::new(); + let doc_type_name = document_type.to_string(); + + for (doc_id, doc_opt) in documents_result { + let key = JsValue::from( + IdentifierWasm::from(doc_id), + ); + + match doc_opt { + Some(doc) => { + let wasm_doc = DocumentWasm::from_batch( + doc, + contract_id, + doc_type_name.clone(), + None, + ); + documents_map.set(&key, &JsValue::from(wasm_doc)); + } + None => { + documents_map.set(&key, &JsValue::NULL); + } } } - let response = ProofMetadataResponse { - data: responses, + Ok(DocumentsProofResponseWasm { + documents: documents_map, metadata: metadata.into(), proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) }) } @@ -475,7 +427,7 @@ impl WasmSdk { data_contract_id: &str, document_type: &str, document_id: &str, - ) -> Result { + ) -> Result, WasmSdkError> { use dash_sdk::platform::documents::document_query::DocumentQuery; // Parse IDs @@ -502,27 +454,19 @@ impl WasmSdk { .await? .ok_or_else(|| WasmSdkError::not_found("Data contract not found"))?; - // Get the document type - let document_type = data_contract + data_contract .document_type_for_name(document_type) .map_err(|e| WasmSdkError::not_found(format!("Document type not found: {}", e)))?; // Execute query - let document_result: Option = Document::fetch(self.as_ref(), query).await?; - - match document_result { - Some(doc) => { - let response = - DocumentResponse::from_document(&doc, &data_contract, document_type)?; - - // Use json_compatible serializer to convert maps to objects - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } - None => Ok(JsValue::NULL), - } + let document = Document::fetch(self.as_ref(), query).await?.map(|doc| DocumentWasm::from_batch( + doc, + contract_id, + document_type.to_string(), + None, + )); + + Ok(document) } #[wasm_bindgen(js_name = "getDocumentWithProofInfo")] @@ -531,7 +475,7 @@ impl WasmSdk { data_contract_id: &str, document_type: &str, document_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::documents::document_query::DocumentQuery; // Parse IDs @@ -558,8 +502,7 @@ impl WasmSdk { .await? .ok_or_else(|| WasmSdkError::not_found("Data contract not found"))?; - // Get the document type - let document_type_ref = data_contract + data_contract .document_type_for_name(document_type) .map_err(|e| WasmSdkError::not_found(format!("Document type not found: {}", e)))?; @@ -567,253 +510,16 @@ impl WasmSdk { let (document_result, metadata, proof) = Document::fetch_with_metadata_and_proof(self.as_ref(), query, None).await?; - match document_result { - Some(doc) => { - let doc_response = - DocumentResponse::from_document(&doc, &data_contract, document_type_ref)?; - - let response = ProofMetadataResponse { - data: doc_response, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } - None => { - // Return null data with proof - let response = ProofMetadataResponse { - data: Option::::None, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } - } - } - - #[wasm_bindgen(js_name = "getDpnsUsernames")] - pub async fn get_dpns_usernames( - &self, - identity_id: &str, - limit: Option, - ) -> Result { - use dash_sdk::platform::documents::document_query::DocumentQuery; - use dash_sdk::platform::FetchMany; - use drive_proof_verifier::types::Documents; - - // DPNS contract ID on testnet - const DPNS_CONTRACT_ID: &str = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"; - const DPNS_DOCUMENT_TYPE: &str = "domain"; - - // Parse identity ID - let identity_id_parsed = Identifier::from_string( - identity_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; - - // Parse DPNS contract ID - let contract_id = Identifier::from_string( - DPNS_CONTRACT_ID, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)))?; - - // Create document query for DPNS domains owned by this identity - let mut query = DocumentQuery::new_with_data_contract_id( - self.as_ref(), - contract_id, - DPNS_DOCUMENT_TYPE, - ) - .await?; - - // Query by records.identity using the identityId index - let where_clause = WhereClause { - field: "records.identity".to_string(), - operator: WhereOperator::Equal, - value: Value::Identifier(identity_id_parsed.to_buffer()), - }; - - query = query.with_where(where_clause); - - // Set limit from parameter or default to 10 - query.limit = limit.unwrap_or(10); - - // Execute query - let documents_result: Documents = Document::fetch_many(self.as_ref(), query).await?; - - // Collect all usernames - let mut usernames: Vec = Vec::new(); - - // Process all results - for (_, doc_opt) in documents_result { - if let Some(doc) = doc_opt { - // Extract the username from the document - let properties = doc.properties(); - - if let (Some(Value::Text(label)), Some(Value::Text(parent_domain))) = ( - properties.get("label"), - properties.get("normalizedParentDomainName"), - ) { - // Construct the full username - let username = format!("{}.{}", label, parent_domain); - usernames.push(username); - } - } - } - - // Return usernames as a JSON array - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - usernames.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize usernames: {}", e)) - }) - } - - // Keep the old function for backward compatibility but have it call the new one - #[wasm_bindgen(js_name = "getDpnsUsername")] - pub async fn get_dpns_username(&self, identity_id: &str) -> Result { - // Call the new function with limit 1 - let result = self.get_dpns_usernames(identity_id, Some(1)).await?; - - // Extract the first username from the array - if let Some(array) = result.dyn_ref::() { - if array.length() > 0 { - return Ok(array.get(0)); - } - } - - Ok(JsValue::NULL) - } - - // Proof info versions for DPNS queries - - #[wasm_bindgen(js_name = "getDpnsUsernamesWithProofInfo")] - pub async fn get_dpns_usernames_with_proof_info( - &self, - identity_id: &str, - limit: Option, - ) -> Result { - use dash_sdk::platform::documents::document_query::DocumentQuery; - use dash_sdk::platform::FetchMany; - - // DPNS contract ID on testnet - const DPNS_CONTRACT_ID: &str = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"; - const DPNS_DOCUMENT_TYPE: &str = "domain"; - - // Parse identity ID - let identity_id_parsed = Identifier::from_string( - identity_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; - - // Parse DPNS contract ID - let contract_id = Identifier::from_string( - DPNS_CONTRACT_ID, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)))?; - - // Create document query for DPNS domains owned by this identity - let mut query = DocumentQuery::new_with_data_contract_id( - self.as_ref(), - contract_id, - DPNS_DOCUMENT_TYPE, - ) - .await?; - - // Query by records.identity using the identityId index - let where_clause = WhereClause { - field: "records.identity".to_string(), - operator: WhereOperator::Equal, - value: Value::Identifier(identity_id_parsed.to_buffer()), - }; - - query = query.with_where(where_clause); - - // Set limit from parameter or default to 10 - query.limit = limit.unwrap_or(10); - - // Execute query with proof - let (documents_result, metadata, proof) = - Document::fetch_many_with_metadata_and_proof(self.as_ref(), query, None).await?; - - // Collect all usernames - let mut usernames: Vec = Vec::new(); - - // Process all results - for (_, doc_opt) in documents_result { - if let Some(doc) = doc_opt { - // Extract the username from the document - let properties = doc.properties(); - - if let (Some(Value::Text(label)), Some(Value::Text(parent_domain))) = ( - properties.get("label"), - properties.get("normalizedParentDomainName"), - ) { - // Construct the full username - let username = format!("{}.{}", label, parent_domain); - usernames.push(username); - } - } - } - - let response = ProofMetadataResponse { - data: usernames, + Ok(DocumentProofResponseWasm { + document: document_result.map(|doc| DocumentWasm::from_batch( + doc, + contract_id, + document_type.to_string(), + None, + )), metadata: metadata.into(), proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) }) } - #[wasm_bindgen(js_name = "getDpnsUsernameWithProofInfo")] - pub async fn get_dpns_username_with_proof_info( - &self, - identity_id: &str, - ) -> Result { - // Call the new function with limit 1 - let result = self - .get_dpns_usernames_with_proof_info(identity_id, Some(1)) - .await?; - - // The result already contains proof info, just modify the data field - // Parse the result to extract first username - let result_obj: serde_json::Value = serde_wasm_bindgen::from_value(result.clone()) - .map_err(|e| WasmSdkError::serialization(format!("Failed to parse JSON: {}", e)))?; - - if let Some(data_array) = result_obj.get("data").and_then(|d| d.as_array()) { - if let Some(first_username) = data_array.first() { - // Create a new response with just the first username - let mut modified_result = result_obj.clone(); - modified_result["data"] = first_username.clone(); - - return serde_wasm_bindgen::to_value(&modified_result).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }); - } - } - - // If no username found, return null data with proof info - let mut modified_result = result_obj.clone(); - modified_result["data"] = serde_json::Value::Null; - - serde_wasm_bindgen::to_value(&modified_result).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } } diff --git a/packages/wasm-sdk/src/queries/dpns.rs b/packages/wasm-sdk/src/queries/dpns.rs deleted file mode 100644 index 41b836b36a1..00000000000 --- a/packages/wasm-sdk/src/queries/dpns.rs +++ /dev/null @@ -1,170 +0,0 @@ -use crate::error::WasmSdkError; -use crate::queries::ProofMetadataResponse; -use crate::sdk::WasmSdk; -use dash_sdk::dpp::document::DocumentV0Getters; -use dash_sdk::dpp::platform_value::string_encoding::Encoding; -use dash_sdk::platform::{Document, FetchMany}; -use serde::{Deserialize, Serialize}; -use wasm_bindgen::prelude::wasm_bindgen; - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct DpnsUsernameInfo { - username: String, - identity_id: String, - document_id: String, -} - -#[wasm_bindgen] -impl WasmSdk { - #[wasm_bindgen(js_name = "getDpnsUsernameByName")] - pub async fn get_dpns_username_by_name( - &self, - username: &str, - ) -> Result { - use dash_sdk::dpp::platform_value::Value; - use dash_sdk::platform::documents::document_query::DocumentQuery; - use drive::query::{WhereClause, WhereOperator}; - - // DPNS contract ID on testnet - const DPNS_CONTRACT_ID: &str = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"; - const DPNS_DOCUMENT_TYPE: &str = "domain"; - - // Parse username into label and domain - let parts: Vec<&str> = username.split('.').collect(); - if parts.len() != 2 { - return Err(WasmSdkError::invalid_argument( - "Invalid username format. Expected format: label.dash", - )); - } - let label = parts[0]; - let domain = parts[1]; - - // Parse DPNS contract ID - let contract_id = - dash_sdk::dpp::prelude::Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58) - .map_err(|e| { - WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)) - })?; - - // Create document query - let mut query = DocumentQuery::new_with_data_contract_id( - self.as_ref(), - contract_id, - DPNS_DOCUMENT_TYPE, - ) - .await?; - - // Query by label and normalizedParentDomainName - query = query.with_where(WhereClause { - field: "normalizedLabel".to_string(), - operator: WhereOperator::Equal, - value: Value::Text(label.to_lowercase()), - }); - - query = query.with_where(WhereClause { - field: "normalizedParentDomainName".to_string(), - operator: WhereOperator::Equal, - value: Value::Text(domain.to_lowercase()), - }); - - let documents = Document::fetch_many(self.as_ref(), query).await?; - - if let Some((_, Some(document))) = documents.into_iter().next() { - let result = DpnsUsernameInfo { - username: username.to_string(), - identity_id: document.owner_id().to_string(Encoding::Base58), - document_id: document.id().to_string(Encoding::Base58), - }; - - serde_wasm_bindgen::to_value(&result).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } else { - Err(WasmSdkError::not_found(format!( - "Username '{}' not found", - username - ))) - } - } - - #[wasm_bindgen(js_name = "getDpnsUsernameByNameWithProofInfo")] - pub async fn get_dpns_username_by_name_with_proof_info( - &self, - username: &str, - ) -> Result { - use dash_sdk::dpp::platform_value::Value; - use dash_sdk::platform::documents::document_query::DocumentQuery; - use drive::query::{WhereClause, WhereOperator}; - - // DPNS contract ID on testnet - const DPNS_CONTRACT_ID: &str = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"; - const DPNS_DOCUMENT_TYPE: &str = "domain"; - - // Parse username into label and domain - let parts: Vec<&str> = username.split('.').collect(); - if parts.len() != 2 { - return Err(WasmSdkError::invalid_argument( - "Invalid username format. Expected format: label.dash", - )); - } - let label = parts[0]; - let domain = parts[1]; - - // Parse DPNS contract ID - let contract_id = - dash_sdk::dpp::prelude::Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58) - .map_err(|e| { - WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)) - })?; - - // Create document query - let mut query = DocumentQuery::new_with_data_contract_id( - self.as_ref(), - contract_id, - DPNS_DOCUMENT_TYPE, - ) - .await?; - - // Query by label and normalizedParentDomainName - query = query.with_where(WhereClause { - field: "normalizedLabel".to_string(), - operator: WhereOperator::Equal, - value: Value::Text(label.to_lowercase()), - }); - - query = query.with_where(WhereClause { - field: "normalizedParentDomainName".to_string(), - operator: WhereOperator::Equal, - value: Value::Text(domain.to_lowercase()), - }); - - let (documents, metadata, proof) = - Document::fetch_many_with_metadata_and_proof(self.as_ref(), query, None).await?; - - if let Some((_, Some(document))) = documents.into_iter().next() { - let result = DpnsUsernameInfo { - username: username.to_string(), - identity_id: document.owner_id().to_string(Encoding::Base58), - document_id: document.id().to_string(Encoding::Base58), - }; - - let response = ProofMetadataResponse { - data: result, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } else { - Err(WasmSdkError::not_found(format!( - "Username '{}' not found", - username - ))) - } - } -} diff --git a/packages/wasm-sdk/src/queries/identity.rs b/packages/wasm-sdk/src/queries/identity.rs index 78354a5e31a..32d194d4e1d 100644 --- a/packages/wasm-sdk/src/queries/identity.rs +++ b/packages/wasm-sdk/src/queries/identity.rs @@ -1,7 +1,7 @@ use crate::error::WasmSdkError; use crate::queries::{ProofInfo, ProofMetadataResponse, ResponseMetadata}; use crate::sdk::WasmSdk; -use crate::IdentityWasm; +use wasm_dpp2::identity::IdentityWasm; use dash_sdk::dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0; use dash_sdk::dpp::identity::identity_public_key::IdentityPublicKey; use dash_sdk::platform::{Fetch, FetchMany, Identifier, Identity}; diff --git a/packages/wasm-sdk/src/queries/mod.rs b/packages/wasm-sdk/src/queries/mod.rs index e1c7b3141a1..9ab259f4d77 100644 --- a/packages/wasm-sdk/src/queries/mod.rs +++ b/packages/wasm-sdk/src/queries/mod.rs @@ -1,6 +1,5 @@ pub mod data_contract; pub mod document; -pub mod dpns; pub mod epoch; pub mod group; pub mod identity; @@ -12,9 +11,13 @@ pub mod voting; // Re-export all query functions for easy access pub use group::*; +use crate::WasmSdkError; +use js_sys::{Object, Uint8Array}; use serde::{Deserialize, Serialize}; +use wasm_bindgen::prelude::*; +use wasm_bindgen::JsValue; -// Common response structure for queries with proof and metadata +// Legacy JSON-friendly response structures kept for compatibility with existing code paths #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] pub struct ProofMetadataResponse { @@ -37,15 +40,14 @@ pub struct ResponseMetadata { #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] pub struct ProofInfo { - pub grovedb_proof: String, // Base64 encoded - pub quorum_hash: String, // Hex encoded - pub signature: String, // Base64 encoded + pub grovedb_proof: String, + pub quorum_hash: String, + pub signature: String, pub round: u32, - pub block_id_hash: String, // Hex encoded + pub block_id_hash: String, pub quorum_type: u32, } -// Helper function to convert platform ResponseMetadata to our ResponseMetadata impl From for ResponseMetadata { fn from(metadata: dash_sdk::platform::proto::ResponseMetadata) -> Self { ResponseMetadata { @@ -59,7 +61,6 @@ impl From for ResponseMetadata { } } -// Helper function to convert platform Proof to our ProofInfo impl From for ProofInfo { fn from(proof: dash_sdk::platform::proto::Proof) -> Self { use base64::{engine::general_purpose, Engine as _}; @@ -74,3 +75,306 @@ impl From for ProofInfo { } } } + +#[wasm_bindgen(js_name = "ResponseMetadata")] +#[derive(Clone, Debug)] +pub struct ResponseMetadataWasm { + height: u64, + core_chain_locked_height: u32, + epoch: u32, + time_ms: u64, + protocol_version: u32, + chain_id: Vec, +} + +#[wasm_bindgen(js_class = ResponseMetadata)] +impl ResponseMetadataWasm { + #[wasm_bindgen(constructor)] + pub fn new( + height: u64, + core_chain_locked_height: u32, + epoch: u32, + time_ms: u64, + protocol_version: u32, + chain_id: Uint8Array, + ) -> Self { + ResponseMetadataWasm { + height, + core_chain_locked_height, + epoch, + time_ms, + protocol_version, + chain_id: chain_id.to_vec(), + } + } + + #[wasm_bindgen(getter)] + pub fn height(&self) -> u64 { + self.height + } + + #[wasm_bindgen(getter = coreChainLockedHeight)] + pub fn core_chain_locked_height(&self) -> u32 { + self.core_chain_locked_height + } + + #[wasm_bindgen(getter)] + pub fn epoch(&self) -> u32 { + self.epoch + } + + #[wasm_bindgen(getter = timeMs)] + pub fn time_ms(&self) -> u64 { + self.time_ms + } + + #[wasm_bindgen(getter = protocolVersion)] + pub fn protocol_version(&self) -> u32 { + self.protocol_version + } + + #[wasm_bindgen(getter = chainId)] + pub fn chain_id(&self) -> Uint8Array { + Uint8Array::from(self.chain_id.as_slice()) + } + + #[wasm_bindgen(js_name = "setChainId")] + pub fn set_chain_id(&mut self, chain_id: Uint8Array) { + self.chain_id = chain_id.to_vec(); + } +} + +// Helper function to convert platform ResponseMetadata to our ResponseMetadata +impl From for ResponseMetadataWasm { + fn from(metadata: dash_sdk::platform::proto::ResponseMetadata) -> Self { + ResponseMetadataWasm { + height: metadata.height, + core_chain_locked_height: metadata.core_chain_locked_height, + epoch: metadata.epoch, + time_ms: metadata.time_ms, + protocol_version: metadata.protocol_version, + chain_id: metadata.chain_id.into_bytes(), + } + } +} + +#[wasm_bindgen(js_name = "ProofInfo")] +#[derive(Clone, Debug)] +pub struct ProofInfoWasm { + grovedb_proof: Vec, + quorum_hash: Vec, + signature: Vec, + round: u32, + block_id_hash: Vec, + quorum_type: u32, +} + +#[wasm_bindgen(js_class = ProofInfo)] +impl ProofInfoWasm { + #[wasm_bindgen(constructor)] + pub fn new( + grovedb_proof: Uint8Array, + quorum_hash: Uint8Array, + signature: Uint8Array, + round: u32, + block_id_hash: Uint8Array, + quorum_type: u32, + ) -> Self { + ProofInfoWasm { + grovedb_proof: grovedb_proof.to_vec(), + quorum_hash: quorum_hash.to_vec(), + signature: signature.to_vec(), + round, + block_id_hash: block_id_hash.to_vec(), + quorum_type, + } + } + + #[wasm_bindgen(getter = grovedbProof)] + pub fn grovedb_proof(&self) -> Uint8Array { + Uint8Array::from(self.grovedb_proof.as_slice()) + } + + #[wasm_bindgen(getter = quorumHash)] + pub fn quorum_hash(&self) -> Uint8Array { + Uint8Array::from(self.quorum_hash.as_slice()) + } + + #[wasm_bindgen(getter)] + pub fn signature(&self) -> Uint8Array { + Uint8Array::from(self.signature.as_slice()) + } + + #[wasm_bindgen(getter)] + pub fn round(&self) -> u32 { + self.round + } + + #[wasm_bindgen(getter = blockIdHash)] + pub fn block_id_hash(&self) -> Uint8Array { + Uint8Array::from(self.block_id_hash.as_slice()) + } + + #[wasm_bindgen(getter = quorumType)] + pub fn quorum_type(&self) -> u32 { + self.quorum_type + } + + #[wasm_bindgen(js_name = "setGrovedbProof")] + pub fn set_grovedb_proof(&mut self, grovedb_proof: Uint8Array) { + self.grovedb_proof = grovedb_proof.to_vec(); + } + + #[wasm_bindgen(js_name = "setQuorumHash")] + pub fn set_quorum_hash(&mut self, quorum_hash: Uint8Array) { + self.quorum_hash = quorum_hash.to_vec(); + } + + #[wasm_bindgen(js_name = "setSignature")] + pub fn set_signature(&mut self, signature: Uint8Array) { + self.signature = signature.to_vec(); + } + + #[wasm_bindgen(js_name = "setBlockIdHash")] + pub fn set_block_id_hash(&mut self, block_id_hash: Uint8Array) { + self.block_id_hash = block_id_hash.to_vec(); + } +} + +// Helper function to convert platform Proof to our ProofInfo +impl From for ProofInfoWasm { + fn from(proof: dash_sdk::platform::proto::Proof) -> Self { + ProofInfoWasm { + grovedb_proof: proof.grovedb_proof, + quorum_hash: proof.quorum_hash, + signature: proof.signature, + round: proof.round, + block_id_hash: proof.block_id_hash, + quorum_type: proof.quorum_type, + } + } +} + +#[wasm_bindgen(js_name = "ProofMetadataResponse")] +#[derive(Clone, Debug)] +pub struct ProofMetadataResponseWasm { + data: JsValue, + metadata: ResponseMetadataWasm, + proof: ProofInfoWasm, +} + +#[wasm_bindgen(js_class = ProofMetadataResponse)] +impl ProofMetadataResponseWasm { + #[wasm_bindgen(constructor)] + pub fn new(data: JsValue, metadata: ResponseMetadataWasm, proof: ProofInfoWasm) -> Self { + ProofMetadataResponseWasm { + data, + metadata, + proof, + } + } + + #[wasm_bindgen(getter)] + pub fn data(&self) -> JsValue { + self.data.clone() + } + + #[wasm_bindgen(js_name = "setData")] + pub fn set_data(&mut self, data: JsValue) { + self.data = data; + } + + #[wasm_bindgen(getter)] + pub fn metadata(&self) -> ResponseMetadataWasm { + self.metadata.clone() + } + + #[wasm_bindgen(js_name = "setMetadata")] + pub fn set_metadata(&mut self, metadata: ResponseMetadataWasm) { + self.metadata = metadata; + } + + #[wasm_bindgen(getter)] + pub fn proof(&self) -> ProofInfoWasm { + self.proof.clone() + } + + #[wasm_bindgen(js_name = "setProof")] + pub fn set_proof(&mut self, proof: ProofInfoWasm) { + self.proof = proof; + } +} + +impl ProofMetadataResponseWasm { + pub(crate) fn from_parts( + data: JsValue, + metadata: ResponseMetadataWasm, + proof: ProofInfoWasm, + ) -> Self { + ProofMetadataResponseWasm { + data, + metadata, + proof, + } + } + + pub(crate) fn from_sdk_parts( + data: impl Into, + metadata: dash_sdk::platform::proto::ResponseMetadata, + proof: dash_sdk::platform::proto::Proof, + ) -> Self { + ProofMetadataResponseWasm { + data: data.into(), + metadata: metadata.into(), + proof: proof.into(), + } + } + + pub(crate) fn into_parts( + self, + ) -> ( + JsValue, + ResponseMetadataWasm, + ProofInfoWasm, + ) { + (self.data, self.metadata, self.proof) + } +} + +pub(crate) fn proof_response_from_js_value( + data: JsValue, + metadata: ResponseMetadata, + proof: ProofInfo, +) -> Result { + let metadata_js = serialize_to_js(&metadata)?; + let proof_js = serialize_to_js(&proof)?; + + let response = Object::new(); + set_property(&response, "data", &data)?; + set_property(&response, "metadata", &metadata_js)?; + set_property(&response, "proof", &proof_js)?; + + Ok(response.into()) +} + +pub(crate) fn proof_response_from_serializable( + data: T, + metadata: ResponseMetadata, + proof: ProofInfo, +) -> Result { + proof_response_from_js_value(serialize_to_js(&data)?, metadata, proof) +} + +fn serialize_to_js(value: &T) -> Result { + serde_wasm_bindgen::to_value(value).map_err(|e| { + WasmSdkError::serialization(format!("Failed to serialize response component: {}", e)) + }) +} + +fn set_property(object: &Object, key: &str, value: &JsValue) -> Result<(), WasmSdkError> { + js_sys::Reflect::set(object, &JsValue::from_str(key), value).map_err(|err| { + WasmSdkError::serialization(format!("Failed to set '{}' on proof response: {:?}", key, err)) + })?; + + Ok(()) +} diff --git a/packages/wasm-sdk/src/verify.rs b/packages/wasm-sdk/src/verify.rs deleted file mode 100644 index 9a0b133d243..00000000000 --- a/packages/wasm-sdk/src/verify.rs +++ /dev/null @@ -1,189 +0,0 @@ -use dash_sdk::dpp::dashcore::Network; -use dash_sdk::dpp::data_contract::DataContract; -use dash_sdk::dpp::document::{Document, DocumentV0Getters}; -use dash_sdk::dpp::identity::Identity; -use dash_sdk::dpp::platform_value::string_encoding::Encoding; -use dash_sdk::dpp::serialization::PlatformDeserializableWithPotentialValidationFromVersionedStructure; -use dash_sdk::dpp::version::PlatformVersion; -use dash_sdk::platform::proto::get_identity_request::{ - GetIdentityRequestV0, Version as GetIdentityRequestVersion, -}; -use dash_sdk::platform::proto::get_identity_response::{ - get_identity_response_v0, GetIdentityResponseV0, Version, -}; -use dash_sdk::platform::proto::{ - GetDocumentsResponse, GetIdentityRequest, Proof, ResponseMetadata, -}; -use dash_sdk::platform::DocumentQuery; -use drive_proof_verifier::types::Documents; -use drive_proof_verifier::FromProof; -use wasm_bindgen::prelude::wasm_bindgen; - -use crate::context_provider::WasmContext; -use crate::{DataContractWasm, IdentityWasm}; - -#[wasm_bindgen(js_name = "verifyIdentityResponse")] -pub async fn verify_identity_response() -> Option { - let request = dash_sdk::dapi_grpc::platform::v0::GetIdentityRequest { - version: Some(GetIdentityRequestVersion::V0(GetIdentityRequestV0 { - id: vec![], - prove: true, - })), - }; - - let response = dash_sdk::dapi_grpc::platform::v0::GetIdentityResponse { - version: Some(Version::V0(GetIdentityResponseV0 { - result: Some(get_identity_response_v0::Result::Proof(Proof { - grovedb_proof: vec![], - quorum_hash: vec![], - signature: vec![], - round: 0, - block_id_hash: vec![], - quorum_type: 0, - })), - metadata: Some(ResponseMetadata { - height: 0, - core_chain_locked_height: 0, - epoch: 0, - time_ms: 0, - protocol_version: 0, - chain_id: "".to_string(), - }), - })), - }; - - let context = WasmContext {}; - - let (response, _metadata, _proof) = - >::maybe_from_proof_with_metadata( - request, - response, - Network::Dash, - PlatformVersion::latest(), - &context, - ) - .expect("parse proof"); - - response.map(IdentityWasm::from) -} - -#[wasm_bindgen(js_name = "verifyDataContract")] -pub async fn verify_data_contract() -> Option { - let request = dash_sdk::dapi_grpc::platform::v0::GetDataContractRequest { - version: Some( - dash_sdk::platform::proto::get_data_contract_request::Version::V0( - dash_sdk::platform::proto::get_data_contract_request::GetDataContractRequestV0 { - id: vec![], - prove: true, - }, - ), - ), - }; - - let response = dash_sdk::dapi_grpc::platform::v0::GetDataContractResponse { - version: Some( - dash_sdk::platform::proto::get_data_contract_response::Version::V0( - dash_sdk::platform::proto::get_data_contract_response::GetDataContractResponseV0 { - result: Some( - dash_sdk::platform::proto::get_data_contract_response::get_data_contract_response_v0::Result::Proof( - dash_sdk::platform::proto::Proof { - grovedb_proof: vec![], - quorum_hash: vec![], - signature: vec![], - round: 0, - block_id_hash: vec![], - quorum_type: 0, - }, - ), - ), - metadata: Some(dash_sdk::platform::proto::ResponseMetadata { - height: 0, - core_chain_locked_height: 0, - epoch: 0, - time_ms: 0, - protocol_version: 0, - chain_id: "".to_string(), - }), - }, - ), - ), - }; - - let context = WasmContext {}; - - let (response, _, _) = >::maybe_from_proof_with_metadata( - request, - response, - Network::Dash, - PlatformVersion::latest(), - &context, - ) - .expect("parse proof"); - - response.map(DataContractWasm::from) -} - -#[wasm_bindgen(js_name = "verifyDocuments")] -pub async fn verify_documents() -> Vec { - // TODO: this is a dummy implementation, replace with actual verification - let data_contract = - DataContract::versioned_deserialize(&[13, 13, 13], false, PlatformVersion::latest()) - .expect("create data contract"); - - let query = DocumentQuery::new(data_contract, "asd").expect("create query"); - - let response = GetDocumentsResponse { - version: Some(dash_sdk::platform::proto::get_documents_response::Version::V0( - dash_sdk::platform::proto::get_documents_response::GetDocumentsResponseV0 { - result: Some( - dash_sdk::platform::proto::get_documents_response::get_documents_response_v0::Result::Proof( - Proof { - grovedb_proof: vec![], - quorum_hash: vec![], - signature: vec![], - round: 0, - block_id_hash: vec![], - quorum_type: 0, - }, - ), - ), - metadata: Some(ResponseMetadata { - height: 0, - core_chain_locked_height: 0, - epoch: 0, - time_ms: 0, - protocol_version: 0, - chain_id: "".to_string(), - }), - }, - )), - }; - - let (documents, _, _) = - >::maybe_from_proof_with_metadata( - query, - response, - Network::Dash, - PlatformVersion::latest(), - &WasmContext {}, - ) - .expect("parse proof"); - - documents - .unwrap() - .into_iter() - .filter(|(_, doc)| doc.is_some()) - .map(|(_, doc)| DocumentWasm(doc.unwrap())) - .collect() -} - -#[wasm_bindgen] -pub struct DocumentWasm(Document); -#[wasm_bindgen] -impl DocumentWasm { - pub fn id(&self) -> String { - self.0.id().to_string(Encoding::Base58) - } -} diff --git a/packages/wasm-sdk/src/wallet/extended_derivation.rs b/packages/wasm-sdk/src/wallet/extended_derivation.rs index b97c0d89cef..dc42d6ed22d 100644 --- a/packages/wasm-sdk/src/wallet/extended_derivation.rs +++ b/packages/wasm-sdk/src/wallet/extended_derivation.rs @@ -3,7 +3,7 @@ //! Implements 256-bit derivation paths for DashPay contact keys use crate::error::WasmSdkError; -use crate::WasmSdk; +use crate::sdk::WasmSdk; use dash_sdk::dpp::dashcore; use dash_sdk::dpp::dashcore::secp256k1::Secp256k1; use dash_sdk::dpp::key_wallet::{bip32, DerivationPath, ExtendedPrivKey}; diff --git a/packages/wasm-sdk/src/wallet/key_derivation.rs b/packages/wasm-sdk/src/wallet/key_derivation.rs index f7627cdb855..c1c03086bd1 100644 --- a/packages/wasm-sdk/src/wallet/key_derivation.rs +++ b/packages/wasm-sdk/src/wallet/key_derivation.rs @@ -3,7 +3,7 @@ //! Implements BIP32, BIP39, and BIP44 standards for hierarchical deterministic key derivation use crate::error::WasmSdkError; -use crate::WasmSdk; +use crate::sdk::WasmSdk; use bip39::{Language, Mnemonic}; use dash_sdk::dpp::dashcore; use dash_sdk::dpp::dashcore::secp256k1::Secp256k1; diff --git a/packages/wasm-sdk/src/wallet/key_generation.rs b/packages/wasm-sdk/src/wallet/key_generation.rs index 1cbc8d30540..676a4ac98a5 100644 --- a/packages/wasm-sdk/src/wallet/key_generation.rs +++ b/packages/wasm-sdk/src/wallet/key_generation.rs @@ -3,7 +3,7 @@ //! Provides key generation and address derivation without full HD wallet support use crate::error::WasmSdkError; -use crate::WasmSdk; +use crate::sdk::WasmSdk; use dash_sdk::dpp::dashcore::hashes::{sha256, Hash}; use dash_sdk::dpp::dashcore::secp256k1::{Secp256k1, SecretKey}; use dash_sdk::dpp::dashcore::{Address, Network, PrivateKey, PublicKey}; diff --git a/packages/wasm-sdk/tests/functional/dpns.spec.mjs b/packages/wasm-sdk/tests/functional/dpns.spec.mjs index ac4ac011326..62800917ab8 100644 --- a/packages/wasm-sdk/tests/functional/dpns.spec.mjs +++ b/packages/wasm-sdk/tests/functional/dpns.spec.mjs @@ -21,26 +21,26 @@ describe('Document queries', function describeDocumentQueries() { it('lists DPNS documents (no filters)', async () => { const docs = await client.getDocuments(DPNS_CONTRACT, 'domain', null, null, 5, null, null); - expect(docs).to.be.an('array'); + expect(docs instanceof Map).to.be(true); }); it('queries with where clause', async () => { const where = JSON.stringify([['normalizedParentDomainName', '==', 'dash']]); const docs = await client.getDocuments(DPNS_CONTRACT, 'domain', where, null, 5, null, null); - expect(docs).to.be.an('array'); + expect(docs instanceof Map).to.be(true); }); it('queries with orderBy', async () => { const orderBy = JSON.stringify([['normalizedParentDomainName', 'asc']]); const docs = await client.getDocuments(DPNS_CONTRACT, 'domain', null, orderBy, 5, null, null); - expect(docs).to.be.an('array'); + expect(docs instanceof Map).to.be(true); }); it('complex where + orderBy', async () => { const where = JSON.stringify([['normalizedLabel', 'startsWith', 'test'], ['normalizedParentDomainName', '==', 'dash']]); const orderBy = JSON.stringify([['normalizedParentDomainName', 'asc'], ['normalizedLabel', 'asc']]); const docs = await client.getDocuments(DPNS_CONTRACT, 'domain', where, orderBy, 5, null, null); - expect(docs).to.be.an('array'); + expect(docs instanceof Map).to.be(true); }); it('getDocument by id (should handle invalid id gracefully)', async () => { @@ -52,6 +52,6 @@ describe('Document queries', function describeDocumentQueries() { it('fetches usernames for a known identity and verifies fields', async () => { const TEST_IDENTITY = '5DbLwAxGBzUzo81VewMUwn4b5P4bpv9FNFybi25XB5Bk'; const list = await client.getDpnsUsernames(TEST_IDENTITY, 10); - expect(list).to.be.an('array'); + expect(Array.isArray(list)).to.be(true); }); }); diff --git a/packages/wasm-sdk/tests/unit/api-availability.spec.mjs b/packages/wasm-sdk/tests/unit/api-availability.spec.mjs index f321ddd31c8..a6e9c4a7d38 100644 --- a/packages/wasm-sdk/tests/unit/api-availability.spec.mjs +++ b/packages/wasm-sdk/tests/unit/api-availability.spec.mjs @@ -25,13 +25,4 @@ describe('API availability (exports and methods)', () => { expect(typeof sdk.WasmSdk.prototype[fn]).to.be.oneOf(['function', 'undefined']); } }); - - it('standalone verification helpers are exported', () => { - const moduleFns = [ - 'verifyIdentityResponse', 'verifyDataContract', 'verifyDocuments', - ]; - for (const fn of moduleFns) { - expect(typeof sdk[fn]).to.be.oneOf(['function', 'undefined']); - } - }); }); diff --git a/packages/wasm-sdk/tests/unit/data-contract.spec.mjs b/packages/wasm-sdk/tests/unit/data-contract.spec.mjs index e04eb4f21c4..00bb7e2c1ef 100644 --- a/packages/wasm-sdk/tests/unit/data-contract.spec.mjs +++ b/packages/wasm-sdk/tests/unit/data-contract.spec.mjs @@ -9,10 +9,10 @@ describe('DataContract', () => { }); it('should create a contract from JSON and expose identifiers', async () => { - const contract = sdk.DataContract.fromJSON(contractFixture, PLATFORM_VERSION); + const contract = sdk.DataContract.fromValue(contractFixture, true, PLATFORM_VERSION); expect(contract).to.be.ok(); - expect(contract.id()).to.equal(contractFixture.id); + expect(contract.id.base58()).to.equal(contractFixture.id); const roundTripped = contract.toJSON(); expect(roundTripped).to.be.an('object'); From 6796ba374199afc2dfb3e398a73d5c6a281c8abf Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 8 Oct 2025 22:30:49 +0700 Subject: [PATCH 17/44] feat: epoch entities --- .../src/epoch/extended_epoch_info.rs | 125 ++++++++ .../src/epoch/finalized_epoch_info.rs | 290 ++++++++++++++++++ packages/wasm-dpp2/src/epoch/mod.rs | 5 + packages/wasm-dpp2/src/lib.rs | 2 + packages/wasm-sdk/src/dpns.rs | 51 ++- .../wasm-sdk/src/queries/data_contract.rs | 2 +- packages/wasm-sdk/src/queries/document.rs | 46 +-- packages/wasm-sdk/src/queries/epoch.rs | 273 ++++++----------- packages/wasm-sdk/src/queries/identity.rs | 2 +- packages/wasm-sdk/src/queries/mod.rs | 13 +- .../tests/functional/epochs-blocks.spec.mjs | 11 +- 11 files changed, 561 insertions(+), 259 deletions(-) create mode 100644 packages/wasm-dpp2/src/epoch/extended_epoch_info.rs create mode 100644 packages/wasm-dpp2/src/epoch/finalized_epoch_info.rs create mode 100644 packages/wasm-dpp2/src/epoch/mod.rs diff --git a/packages/wasm-dpp2/src/epoch/extended_epoch_info.rs b/packages/wasm-dpp2/src/epoch/extended_epoch_info.rs new file mode 100644 index 00000000000..f0b7f449516 --- /dev/null +++ b/packages/wasm-dpp2/src/epoch/extended_epoch_info.rs @@ -0,0 +1,125 @@ +use dpp::block::extended_epoch_info::ExtendedEpochInfo; +use dpp::block::extended_epoch_info::v0::{ExtendedEpochInfoV0, ExtendedEpochInfoV0Getters}; +use js_sys::BigInt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "ExtendedEpochInfo")] +pub struct ExtendedEpochInfoWasm(ExtendedEpochInfo); + +impl From for ExtendedEpochInfoWasm { + fn from(info: ExtendedEpochInfo) -> Self { + ExtendedEpochInfoWasm(info) + } +} + +impl From for ExtendedEpochInfo { + fn from(info: ExtendedEpochInfoWasm) -> Self { + info.0 + } +} + +impl ExtendedEpochInfoWasm { + fn v0_mut(&mut self) -> &mut ExtendedEpochInfoV0 { + match &mut self.0 { + ExtendedEpochInfo::V0(v0) => v0, + } + } +} + +#[wasm_bindgen(js_class = ExtendedEpochInfo)] +impl ExtendedEpochInfoWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "ExtendedEpochInfo".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "ExtendedEpochInfo".to_string() + } + + #[wasm_bindgen(constructor)] + pub fn new( + index: u16, + first_block_time: u64, + first_block_height: u64, + first_core_block_height: u32, + fee_multiplier_permille: u64, + protocol_version: u32, + ) -> ExtendedEpochInfoWasm { + ExtendedEpochInfoWasm(ExtendedEpochInfo::V0(ExtendedEpochInfoV0 { + index, + first_block_time, + first_block_height, + first_core_block_height, + fee_multiplier_permille, + protocol_version, + })) + } + + #[wasm_bindgen(getter = "index")] + pub fn index(&self) -> u16 { + self.0.index() + } + + #[wasm_bindgen(getter = "firstBlockTime")] + pub fn first_block_time(&self) -> BigInt { + BigInt::from(self.0.first_block_time()) + } + + #[wasm_bindgen(getter = "firstBlockHeight")] + pub fn first_block_height(&self) -> BigInt { + BigInt::from(self.0.first_block_height()) + } + + #[wasm_bindgen(getter = "firstCoreBlockHeight")] + pub fn first_core_block_height(&self) -> u32 { + self.0.first_core_block_height() + } + + #[wasm_bindgen(getter = "feeMultiplierPermille")] + pub fn fee_multiplier_permille(&self) -> u64 { + self.0.fee_multiplier_permille() + } + + #[wasm_bindgen(getter = "feeMultiplier")] + pub fn fee_multiplier(&self) -> f64 { + self.0.fee_multiplier_permille() as f64 / 1000.0 + } + + #[wasm_bindgen(getter = "protocolVersion")] + pub fn protocol_version(&self) -> u32 { + self.0.protocol_version() + } + + #[wasm_bindgen(setter = "index")] + pub fn set_index(&mut self, index: u16) { + self.v0_mut().index = index; + } + + #[wasm_bindgen(setter = "firstBlockTime")] + pub fn set_first_block_time(&mut self, first_block_time: u64) { + self.v0_mut().first_block_time = first_block_time; + } + + #[wasm_bindgen(setter = "firstBlockHeight")] + pub fn set_first_block_height(&mut self, first_block_height: u64) { + self.v0_mut().first_block_height = first_block_height; + } + + #[wasm_bindgen(setter = "firstCoreBlockHeight")] + pub fn set_first_core_block_height(&mut self, first_core_block_height: u32) { + self.v0_mut().first_core_block_height = first_core_block_height; + } + + #[wasm_bindgen(setter = "feeMultiplierPermille")] + pub fn set_fee_multiplier_permille(&mut self, fee_multiplier_permille: u64) { + self.v0_mut().fee_multiplier_permille = fee_multiplier_permille; + } + + #[wasm_bindgen(setter = "protocolVersion")] + pub fn set_protocol_version(&mut self, protocol_version: u32) { + self.v0_mut().protocol_version = protocol_version; + } +} diff --git a/packages/wasm-dpp2/src/epoch/finalized_epoch_info.rs b/packages/wasm-dpp2/src/epoch/finalized_epoch_info.rs new file mode 100644 index 00000000000..b003683fff8 --- /dev/null +++ b/packages/wasm-dpp2/src/epoch/finalized_epoch_info.rs @@ -0,0 +1,290 @@ +use crate::error::{WasmDppError, WasmDppResult}; +use crate::identifier::IdentifierWasm; +use crate::utils::{JsValueExt, try_to_u64}; +use dpp::block::finalized_epoch_info::FinalizedEpochInfo; +use dpp::block::finalized_epoch_info::v0::FinalizedEpochInfoV0; +use dpp::block::finalized_epoch_info::v0::getters::FinalizedEpochInfoGettersV0; +use dpp::platform_value::string_encoding::Encoding; +use dpp::prelude::Identifier; +use js_sys::{BigInt, Object, Reflect}; +use std::collections::BTreeMap; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "FinalizedEpochInfo")] +pub struct FinalizedEpochInfoWasm(FinalizedEpochInfo); + +impl From for FinalizedEpochInfoWasm { + fn from(info: FinalizedEpochInfo) -> Self { + FinalizedEpochInfoWasm(info) + } +} + +impl From for FinalizedEpochInfo { + fn from(info: FinalizedEpochInfoWasm) -> Self { + info.0 + } +} + +impl FinalizedEpochInfoWasm { + fn v0(&self) -> &FinalizedEpochInfoV0 { + match &self.0 { + FinalizedEpochInfo::V0(v0) => v0, + } + } + + fn v0_mut(&mut self) -> &mut FinalizedEpochInfoV0 { + match &mut self.0 { + FinalizedEpochInfo::V0(v0) => v0, + } + } +} + +fn block_proposers_from_js(js_value: &JsValue) -> WasmDppResult> { + if js_value.is_undefined() || js_value.is_null() { + return Ok(BTreeMap::new()); + } + + if !js_value.is_object() { + return Err(WasmDppError::invalid_argument( + "blockProposers must be an object", + )); + } + + let object = Object::from(js_value.clone()); + let keys = Object::keys(&object); + let mut map = BTreeMap::new(); + + for key in keys.iter() { + let identifier = + Identifier::from(IdentifierWasm::try_from(key.clone()).map_err(|err| { + WasmDppError::invalid_argument(format!( + "invalid block proposer identifier: {}", + err + )) + })?); + + let value = Reflect::get(&object, &key).map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to read block proposer '{}': {}", + identifier.to_string(Encoding::Base58), + message + )) + })?; + + let credits = try_to_u64(value.clone()).map_err(|err| { + WasmDppError::invalid_argument(format!( + "block proposer value for '{}' is not a valid u64: {:#}", + identifier.to_string(Encoding::Base58), + err + )) + })?; + + map.insert(identifier, credits); + } + + Ok(map) +} + +fn block_proposers_to_js(map: &BTreeMap) -> WasmDppResult { + let object = Object::new(); + + for (identifier, value) in map { + Reflect::set( + &object, + &JsValue::from(identifier.to_string(Encoding::Base58)), + &BigInt::from(*value).into(), + ) + .map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!( + "unable to serialize block proposer '{}': {}", + identifier.to_string(Encoding::Base58), + message + )) + })?; + } + + Ok(object.into()) +} + +#[wasm_bindgen(js_class = FinalizedEpochInfo)] +impl FinalizedEpochInfoWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "FinalizedEpochInfo".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name(&self) -> String { + "FinalizedEpochInfo".to_string() + } + + #[wasm_bindgen(constructor)] + #[allow(clippy::too_many_arguments)] + pub fn new( + first_block_time: u64, + first_block_height: u64, + total_blocks_in_epoch: u64, + first_core_block_height: u32, + next_epoch_start_core_block_height: u32, + total_processing_fees: u64, + total_distributed_storage_fees: u64, + total_created_storage_fees: u64, + core_block_rewards: u64, + block_proposers: &JsValue, + fee_multiplier_permille: u64, + protocol_version: u32, + ) -> WasmDppResult { + let block_proposers = block_proposers_from_js(block_proposers)?; + + Ok(FinalizedEpochInfoWasm(FinalizedEpochInfo::V0( + FinalizedEpochInfoV0 { + first_block_time, + first_block_height, + total_blocks_in_epoch, + first_core_block_height, + next_epoch_start_core_block_height, + total_processing_fees, + total_distributed_storage_fees, + total_created_storage_fees, + core_block_rewards, + block_proposers, + fee_multiplier_permille, + protocol_version, + }, + ))) + } + + #[wasm_bindgen(getter = "firstBlockTime")] + pub fn first_block_time(&self) -> BigInt { + BigInt::from(self.v0().first_block_time()) + } + + #[wasm_bindgen(getter = "firstBlockHeight")] + pub fn first_block_height(&self) -> BigInt { + BigInt::from(self.v0().first_block_height()) + } + + #[wasm_bindgen(getter = "totalBlocksInEpoch")] + pub fn total_blocks_in_epoch(&self) -> BigInt { + BigInt::from(self.v0().total_blocks_in_epoch()) + } + + #[wasm_bindgen(getter = "firstCoreBlockHeight")] + pub fn first_core_block_height(&self) -> u32 { + self.v0().first_core_block_height() + } + + #[wasm_bindgen(getter = "nextEpochStartCoreBlockHeight")] + pub fn next_epoch_start_core_block_height(&self) -> u32 { + self.v0().next_epoch_start_core_block_height() + } + + #[wasm_bindgen(getter = "totalProcessingFees")] + pub fn total_processing_fees(&self) -> BigInt { + BigInt::from(self.v0().total_processing_fees()) + } + + #[wasm_bindgen(getter = "totalDistributedStorageFees")] + pub fn total_distributed_storage_fees(&self) -> BigInt { + BigInt::from(self.v0().total_distributed_storage_fees()) + } + + #[wasm_bindgen(getter = "totalCreatedStorageFees")] + pub fn total_created_storage_fees(&self) -> BigInt { + BigInt::from(self.v0().total_created_storage_fees()) + } + + #[wasm_bindgen(getter = "coreBlockRewards")] + pub fn core_block_rewards(&self) -> BigInt { + BigInt::from(self.v0().core_block_rewards()) + } + + #[wasm_bindgen(getter = "blockProposers")] + pub fn block_proposers(&self) -> WasmDppResult { + block_proposers_to_js(self.v0().block_proposers()) + } + + #[wasm_bindgen(getter = "feeMultiplierPermille")] + pub fn fee_multiplier_permille(&self) -> u64 { + self.v0().fee_multiplier_permille() + } + + #[wasm_bindgen(getter = "feeMultiplier")] + pub fn fee_multiplier(&self) -> f64 { + self.v0().fee_multiplier_permille() as f64 / 1000.0 + } + + #[wasm_bindgen(getter = "protocolVersion")] + pub fn protocol_version(&self) -> u32 { + self.v0().protocol_version() + } + + #[wasm_bindgen(setter = "firstBlockTime")] + pub fn set_first_block_time(&mut self, first_block_time: u64) { + self.v0_mut().first_block_time = first_block_time; + } + + #[wasm_bindgen(setter = "firstBlockHeight")] + pub fn set_first_block_height(&mut self, first_block_height: u64) { + self.v0_mut().first_block_height = first_block_height; + } + + #[wasm_bindgen(setter = "totalBlocksInEpoch")] + pub fn set_total_blocks_in_epoch(&mut self, total_blocks_in_epoch: u64) { + self.v0_mut().total_blocks_in_epoch = total_blocks_in_epoch; + } + + #[wasm_bindgen(setter = "firstCoreBlockHeight")] + pub fn set_first_core_block_height(&mut self, first_core_block_height: u32) { + self.v0_mut().first_core_block_height = first_core_block_height; + } + + #[wasm_bindgen(setter = "nextEpochStartCoreBlockHeight")] + pub fn set_next_epoch_start_core_block_height( + &mut self, + next_epoch_start_core_block_height: u32, + ) { + self.v0_mut().next_epoch_start_core_block_height = next_epoch_start_core_block_height; + } + + #[wasm_bindgen(setter = "totalProcessingFees")] + pub fn set_total_processing_fees(&mut self, total_processing_fees: u64) { + self.v0_mut().total_processing_fees = total_processing_fees; + } + + #[wasm_bindgen(setter = "totalDistributedStorageFees")] + pub fn set_total_distributed_storage_fees(&mut self, total_distributed_storage_fees: u64) { + self.v0_mut().total_distributed_storage_fees = total_distributed_storage_fees; + } + + #[wasm_bindgen(setter = "totalCreatedStorageFees")] + pub fn set_total_created_storage_fees(&mut self, total_created_storage_fees: u64) { + self.v0_mut().total_created_storage_fees = total_created_storage_fees; + } + + #[wasm_bindgen(setter = "coreBlockRewards")] + pub fn set_core_block_rewards(&mut self, core_block_rewards: u64) { + self.v0_mut().core_block_rewards = core_block_rewards; + } + + #[wasm_bindgen(setter = "blockProposers")] + pub fn set_block_proposers(&mut self, js_block_proposers: &JsValue) -> WasmDppResult<()> { + let block_proposers = block_proposers_from_js(js_block_proposers)?; + self.v0_mut().block_proposers = block_proposers; + Ok(()) + } + + #[wasm_bindgen(setter = "feeMultiplierPermille")] + pub fn set_fee_multiplier_permille(&mut self, fee_multiplier_permille: u64) { + self.v0_mut().fee_multiplier_permille = fee_multiplier_permille; + } + + #[wasm_bindgen(setter = "protocolVersion")] + pub fn set_protocol_version(&mut self, protocol_version: u32) { + self.v0_mut().protocol_version = protocol_version; + } +} diff --git a/packages/wasm-dpp2/src/epoch/mod.rs b/packages/wasm-dpp2/src/epoch/mod.rs new file mode 100644 index 00000000000..01ea574260a --- /dev/null +++ b/packages/wasm-dpp2/src/epoch/mod.rs @@ -0,0 +1,5 @@ +mod extended_epoch_info; +mod finalized_epoch_info; + +pub use extended_epoch_info::ExtendedEpochInfoWasm; +pub use finalized_epoch_info::FinalizedEpochInfoWasm; diff --git a/packages/wasm-dpp2/src/lib.rs b/packages/wasm-dpp2/src/lib.rs index 3bc07b7a300..cd7aadccca5 100644 --- a/packages/wasm-dpp2/src/lib.rs +++ b/packages/wasm-dpp2/src/lib.rs @@ -14,6 +14,7 @@ pub mod consensus_error; pub mod core_script; pub mod data_contract; pub mod enums; +pub mod epoch; pub mod error; pub mod identifier; pub mod identity; @@ -28,6 +29,7 @@ pub use data_contract::{ ContractBoundsWasm, DataContractCreateTransitionWasm, DataContractUpdateTransitionWasm, DataContractWasm, DocumentWasm, }; +pub use epoch::{ExtendedEpochInfoWasm, FinalizedEpochInfoWasm}; pub use identity::{ IdentityCreateTransitionWasm, IdentityCreditTransferWasm, diff --git a/packages/wasm-sdk/src/dpns.rs b/packages/wasm-sdk/src/dpns.rs index cfdf4a28f47..dc98f46a90f 100644 --- a/packages/wasm-sdk/src/dpns.rs +++ b/packages/wasm-sdk/src/dpns.rs @@ -82,18 +82,16 @@ impl WasmSdk { private_key_wif: &str, preorder_callback: Option, ) -> Result { - let identity_id_parsed = Identifier::from_string( - identity_id, - Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; + let identity_id_parsed = Identifier::from_string(identity_id, Encoding::Base58) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; let identity = Identity::fetch(self.as_ref(), identity_id_parsed) .await? .ok_or_else(|| WasmSdkError::not_found("Identity not found"))?; - let signer = SingleKeySigner::new(private_key_wif) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid private key WIF: {}", e)))?; + let signer = SingleKeySigner::new(private_key_wif).map_err(|e| { + WasmSdkError::invalid_argument(format!("Invalid private key WIF: {}", e)) + })?; let identity_public_key = identity .get_public_key_by_id(public_key_id) @@ -151,14 +149,8 @@ impl WasmSdk { }); let js_result = RegisterDpnsNameResult { - preorder_document_id: result - .preorder_document - .id() - .to_string(Encoding::Base58), - domain_document_id: result - .domain_document - .id() - .to_string(Encoding::Base58), + preorder_document_id: result.preorder_document.id().to_string(Encoding::Base58), + domain_document_id: result.domain_document.id().to_string(Encoding::Base58), full_domain_name: result.full_domain_name, }; @@ -187,10 +179,7 @@ impl WasmSdk { } #[wasm_bindgen(js_name = "getDpnsUsernameByName")] - pub async fn get_dpns_username_by_name( - &self, - username: &str, - ) -> Result { + pub async fn get_dpns_username_by_name(&self, username: &str) -> Result { const DPNS_CONTRACT_ID: &str = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"; const DPNS_DOCUMENT_TYPE: &str = "domain"; @@ -203,8 +192,10 @@ impl WasmSdk { let label = parts[0]; let domain = parts[1]; - let contract_id = Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)))?; + let contract_id = + Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58).map_err(|e| { + WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)) + })?; let mut query = DocumentQuery::new_with_data_contract_id( self.as_ref(), @@ -262,8 +253,10 @@ impl WasmSdk { let label = parts[0]; let domain = parts[1]; - let contract_id = Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)))?; + let contract_id = + Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58).map_err(|e| { + WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)) + })?; let mut query = DocumentQuery::new_with_data_contract_id( self.as_ref(), @@ -324,8 +317,10 @@ impl WasmSdk { let identity_id_parsed = Identifier::from_string(identity_id, Encoding::Base58) .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; - let contract_id = Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)))?; + let contract_id = + Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58).map_err(|e| { + WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)) + })?; let mut query = DocumentQuery::new_with_data_contract_id( self.as_ref(), @@ -388,8 +383,10 @@ impl WasmSdk { let identity_id_parsed = Identifier::from_string(identity_id, Encoding::Base58) .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; - let contract_id = Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)))?; + let contract_id = + Identifier::from_string(DPNS_CONTRACT_ID, Encoding::Base58).map_err(|e| { + WasmSdkError::invalid_argument(format!("Invalid DPNS contract ID: {}", e)) + })?; let mut query = DocumentQuery::new_with_data_contract_id( self.as_ref(), diff --git a/packages/wasm-sdk/src/queries/data_contract.rs b/packages/wasm-sdk/src/queries/data_contract.rs index 7648a3ef66c..fcf3c1274fe 100644 --- a/packages/wasm-sdk/src/queries/data_contract.rs +++ b/packages/wasm-sdk/src/queries/data_contract.rs @@ -7,8 +7,8 @@ use drive_proof_verifier::types::{DataContractHistory, DataContracts}; use js_sys::{BigInt, Map}; use wasm_bindgen::prelude::*; use wasm_bindgen::JsValue; -use wasm_dpp2::DataContractWasm; use wasm_dpp2::identifier::IdentifierWasm; +use wasm_dpp2::DataContractWasm; #[wasm_bindgen(js_name = "DataContractProofResponse")] #[derive(Clone)] diff --git a/packages/wasm-sdk/src/queries/document.rs b/packages/wasm-sdk/src/queries/document.rs index ee3cbdb5ad7..8cc83b11cbc 100644 --- a/packages/wasm-sdk/src/queries/document.rs +++ b/packages/wasm-sdk/src/queries/document.rs @@ -7,10 +7,10 @@ use dash_sdk::dpp::platform_value::{platform_value, Value}; use dash_sdk::dpp::prelude::Identifier; use dash_sdk::platform::Fetch; use drive::query::{OrderClause, WhereClause, WhereOperator}; +use js_sys::Map; use serde_json::Value as JsonValue; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; -use js_sys::Map; use wasm_dpp2::data_contract::document::DocumentWasm; use wasm_dpp2::identifier::IdentifierWasm; @@ -36,7 +36,6 @@ pub struct DocumentsProofResponseWasm { pub proof: ProofInfoWasm, } - /// Parse JSON where clause into WhereClause fn parse_where_clause(json_clause: &JsonValue) -> Result { let clause_array = json_clause @@ -281,18 +280,12 @@ impl WasmSdk { let doc_type_name = document_type.to_string(); for (doc_id, doc_opt) in documents_result { - let key = JsValue::from( - IdentifierWasm::from(doc_id), - ); + let key = JsValue::from(IdentifierWasm::from(doc_id)); match doc_opt { Some(doc) => { - let wasm_doc = DocumentWasm::from_batch( - doc, - contract_id, - doc_type_name.clone(), - None, - ); + let wasm_doc = + DocumentWasm::from_batch(doc, contract_id, doc_type_name.clone(), None); documents_map.set(&key, &JsValue::from(wasm_doc)); } None => { @@ -394,18 +387,12 @@ impl WasmSdk { let doc_type_name = document_type.to_string(); for (doc_id, doc_opt) in documents_result { - let key = JsValue::from( - IdentifierWasm::from(doc_id), - ); + let key = JsValue::from(IdentifierWasm::from(doc_id)); match doc_opt { Some(doc) => { - let wasm_doc = DocumentWasm::from_batch( - doc, - contract_id, - doc_type_name.clone(), - None, - ); + let wasm_doc = + DocumentWasm::from_batch(doc, contract_id, doc_type_name.clone(), None); documents_map.set(&key, &JsValue::from(wasm_doc)); } None => { @@ -459,12 +446,9 @@ impl WasmSdk { .map_err(|e| WasmSdkError::not_found(format!("Document type not found: {}", e)))?; // Execute query - let document = Document::fetch(self.as_ref(), query).await?.map(|doc| DocumentWasm::from_batch( - doc, - contract_id, - document_type.to_string(), - None, - )); + let document = Document::fetch(self.as_ref(), query) + .await? + .map(|doc| DocumentWasm::from_batch(doc, contract_id, document_type.to_string(), None)); Ok(document) } @@ -511,15 +495,11 @@ impl WasmSdk { Document::fetch_with_metadata_and_proof(self.as_ref(), query, None).await?; Ok(DocumentProofResponseWasm { - document: document_result.map(|doc| DocumentWasm::from_batch( - doc, - contract_id, - document_type.to_string(), - None, - )), + document: document_result.map(|doc| { + DocumentWasm::from_batch(doc, contract_id, document_type.to_string(), None) + }), metadata: metadata.into(), proof: proof.into(), }) } - } diff --git a/packages/wasm-sdk/src/queries/epoch.rs b/packages/wasm-sdk/src/queries/epoch.rs index 4e5e82cec17..30dbf0b8796 100644 --- a/packages/wasm-sdk/src/queries/epoch.rs +++ b/packages/wasm-sdk/src/queries/epoch.rs @@ -1,53 +1,50 @@ use crate::error::WasmSdkError; -use crate::queries::ProofMetadataResponse; +use crate::queries::{ProofInfoWasm, ResponseMetadataWasm}; use crate::sdk::WasmSdk; -use dash_sdk::dpp::block::extended_epoch_info::v0::ExtendedEpochInfoV0Getters; use dash_sdk::dpp::block::extended_epoch_info::ExtendedEpochInfo; use dash_sdk::dpp::dashcore::hashes::Hash; use dash_sdk::dpp::dashcore::ProTxHash; use dash_sdk::platform::fetch_current_no_parameters::FetchCurrent; +use dash_sdk::platform::types::proposed_blocks::ProposedBlockCountEx; use dash_sdk::platform::{FetchMany, LimitQuery}; -use serde::{Deserialize, Serialize}; -use std::collections::BTreeMap; +use js_sys::{BigInt, Map, Number}; use std::str::FromStr; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct EpochInfo { - index: u16, - first_core_block_height: u32, - first_block_height: u64, - start_time: u64, - fee_multiplier: f64, - protocol_version: u32, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct EvonodesProposedBlocksResponse { - evonodes_proposed_block_counts: BTreeMap, +use wasm_dpp2::epoch::{ExtendedEpochInfoWasm, FinalizedEpochInfoWasm}; +use wasm_dpp2::identifier::IdentifierWasm; + +#[wasm_bindgen(js_name = "EpochsProofResponse")] +#[derive(Clone)] +pub struct EpochsProofResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub epochs: Map, + #[wasm_bindgen(getter_with_clone)] + pub metadata: ResponseMetadataWasm, + #[wasm_bindgen(getter_with_clone)] + pub proof: ProofInfoWasm, } -impl From for EpochInfo { - fn from(epoch: ExtendedEpochInfo) -> Self { - Self { - index: epoch.index(), - first_core_block_height: epoch.first_core_block_height(), - first_block_height: epoch.first_block_height(), - start_time: epoch.first_block_time(), - fee_multiplier: epoch.fee_multiplier_permille() as f64 / 1000.0, - protocol_version: epoch.protocol_version(), - } - } +#[wasm_bindgen(js_name = "EpochProofResponse")] +#[derive(Clone)] +pub struct EpochProofResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub epoch: ExtendedEpochInfoWasm, + #[wasm_bindgen(getter_with_clone)] + pub metadata: ResponseMetadataWasm, + #[wasm_bindgen(getter_with_clone)] + pub proof: ProofInfoWasm, } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct ProposerBlockCount { - proposer_pro_tx_hash: String, - count: u64, +#[wasm_bindgen(js_name = "FinalizedEpochsProofResponse")] +#[derive(Clone)] +pub struct FinalizedEpochsProofResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub epochs: Map, + #[wasm_bindgen(getter_with_clone)] + pub metadata: ResponseMetadataWasm, + #[wasm_bindgen(getter_with_clone)] + pub proof: ProofInfoWasm, } #[wasm_bindgen] @@ -58,7 +55,7 @@ impl WasmSdk { start_epoch: Option, count: Option, ascending: Option, - ) -> Result { + ) -> Result { use dash_sdk::platform::types::epoch::EpochQuery; let query = LimitQuery { @@ -73,15 +70,15 @@ impl WasmSdk { let epochs_result: drive_proof_verifier::types::ExtendedEpochInfos = ExtendedEpochInfo::fetch_many(self.as_ref(), query).await?; - // Convert to our response format - let epochs: Vec = epochs_result - .into_iter() - .filter_map(|(_, epoch_opt)| epoch_opt.map(Into::into)) - .collect(); + let epochs_map = Map::new(); - serde_wasm_bindgen::to_value(&epochs).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + for (epoch_index, epoch_info) in epochs_result { + let key = Number::from(epoch_index as u32); + let value = epoch_info.map(ExtendedEpochInfoWasm::from); + epochs_map.set(&key.into(), &JsValue::from(value)); + } + + Ok(epochs_map) } #[wasm_bindgen(js_name = "getFinalizedEpochInfos")] @@ -90,7 +87,7 @@ impl WasmSdk { start_epoch: Option, count: Option, ascending: Option, - ) -> Result { + ) -> Result { use dash_sdk::platform::types::finalized_epoch::FinalizedEpochQuery; if start_epoch.is_none() { @@ -136,36 +133,14 @@ impl WasmSdk { ) .await?; - // Convert to our response format and sort by epoch index - let mut epochs: Vec = epochs_result - .into_iter() - .filter_map(|(epoch_index, epoch_opt)| { - epoch_opt.map(|epoch| { - use dash_sdk::dpp::block::finalized_epoch_info::v0::getters::FinalizedEpochInfoGettersV0; - EpochInfo { - index: epoch_index, - first_core_block_height: epoch.first_core_block_height(), - first_block_height: epoch.first_block_height(), - start_time: epoch.first_block_time(), - fee_multiplier: epoch.fee_multiplier_permille() as f64 / 1000.0, - protocol_version: epoch.protocol_version(), - } - }) - }) - .collect(); - - // Sort based on ascending flag - epochs.sort_by(|a, b| { - if is_ascending { - a.index.cmp(&b.index) - } else { - b.index.cmp(&a.index) - } - }); + let epochs_map = Map::new(); + for (epoch_index, epoch_info) in epochs_result { + let key = Number::from(epoch_index as u32); + let value = epoch_info.map(FinalizedEpochInfoWasm::from); + epochs_map.set(&key.into(), &JsValue::from(value)); + } - serde_wasm_bindgen::to_value(&epochs).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(epochs_map) } #[wasm_bindgen(js_name = "getEvonodesProposedEpochBlocksByIds")] @@ -173,7 +148,7 @@ impl WasmSdk { &self, epoch: u16, ids: Vec, - ) -> Result { + ) -> Result { use drive_proof_verifier::types::ProposerBlockCountById; // Parse the ProTxHash strings @@ -193,21 +168,14 @@ impl WasmSdk { let counts = ProposerBlockCountById::fetch_many(self.as_ref(), (epoch, pro_tx_hashes)).await?; - // Convert to response format - let mut evonodes_proposed_block_counts = BTreeMap::new(); + let map = Map::new(); + for (identifier, count) in counts.0 { - // Convert Identifier to ProTxHash for consistent output format - let pro_tx_hash = ProTxHash::from_byte_array(identifier.to_buffer()); - evonodes_proposed_block_counts.insert(pro_tx_hash.to_string(), count); + let key = JsValue::from(IdentifierWasm::from(identifier)); + map.set(&key, &JsValue::from(BigInt::from(count))); } - let response = EvonodesProposedBlocksResponse { - evonodes_proposed_block_counts, - }; - - serde_wasm_bindgen::to_value(&response).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(map) } #[wasm_bindgen(js_name = "getEvonodesProposedEpochBlocksByRange")] @@ -217,8 +185,7 @@ impl WasmSdk { limit: Option, start_after: Option, order_ascending: Option, - ) -> Result { - use dash_sdk::platform::types::proposed_blocks::ProposedBlockCountEx; + ) -> Result { use dash_sdk::platform::QueryStartInfo; use drive_proof_verifier::types::ProposerBlockCounts; @@ -243,47 +210,20 @@ impl WasmSdk { ) .await?; - // Convert to response format - let mut responses: Vec = counts_result - .0 - .into_iter() - .map(|(identifier, count)| { - // Convert Identifier back to ProTxHash - let bytes = identifier.to_buffer(); - let hash = - dash_sdk::dpp::dashcore::hashes::sha256d::Hash::from_slice(&bytes).unwrap(); - let pro_tx_hash = ProTxHash::from_raw_hash(hash); - ProposerBlockCount { - proposer_pro_tx_hash: pro_tx_hash.to_string(), - count, - } - }) - .collect(); - - // Sort based on order_ascending (default is true) - let ascending = order_ascending.unwrap_or(true); - responses.sort_by(|a, b| { - if ascending { - a.proposer_pro_tx_hash.cmp(&b.proposer_pro_tx_hash) - } else { - b.proposer_pro_tx_hash.cmp(&a.proposer_pro_tx_hash) - } - }); + let map = Map::new(); + for (identifier, count) in counts_result.0 { + let key = JsValue::from(IdentifierWasm::from(identifier)); + map.set(&key, &JsValue::from(BigInt::from(count))); + } - serde_wasm_bindgen::to_value(&responses).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(map) } #[wasm_bindgen(js_name = "getCurrentEpoch")] - pub async fn get_current_epoch(&self) -> Result { + pub async fn get_current_epoch(&self) -> Result { let epoch = ExtendedEpochInfo::fetch_current(self.as_ref()).await?; - let epoch_info = EpochInfo::from(epoch); - - serde_wasm_bindgen::to_value(&epoch_info).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ExtendedEpochInfoWasm::from(epoch)) } #[wasm_bindgen(js_name = "getEpochsInfoWithProofInfo")] @@ -292,7 +232,7 @@ impl WasmSdk { start_epoch: Option, count: Option, ascending: Option, - ) -> Result { + ) -> Result { use dash_sdk::platform::types::epoch::EpochQuery; let query = LimitQuery { @@ -308,42 +248,31 @@ impl WasmSdk { ExtendedEpochInfo::fetch_many_with_metadata_and_proof(self.as_ref(), query, None) .await?; - // Convert to our response format - let epochs: Vec = epochs_result - .into_iter() - .filter_map(|(_, epoch_opt)| epoch_opt.map(Into::into)) - .collect(); + let epochs_map = Map::new(); + for (epoch_index, epoch_info) in epochs_result { + let key = Number::from(epoch_index as u32); + let value = epoch_info.map(ExtendedEpochInfoWasm::from); + epochs_map.set(&key.into(), &JsValue::from(value)); + } - let response = ProofMetadataResponse { - data: epochs, + Ok(EpochsProofResponseWasm { + epochs: epochs_map, metadata: metadata.into(), proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) }) } #[wasm_bindgen(js_name = "getCurrentEpochWithProofInfo")] - pub async fn get_current_epoch_with_proof_info(&self) -> Result { + pub async fn get_current_epoch_with_proof_info( + &self, + ) -> Result { let (epoch, metadata, proof) = ExtendedEpochInfo::fetch_current_with_metadata_and_proof(self.as_ref()).await?; - let epoch_info = EpochInfo::from(epoch); - - let response = ProofMetadataResponse { - data: epoch_info, + Ok(EpochProofResponseWasm { + epoch: ExtendedEpochInfoWasm::from(epoch), metadata: metadata.into(), proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) }) } @@ -355,7 +284,7 @@ impl WasmSdk { start_epoch: Option, count: Option, ascending: Option, - ) -> Result { + ) -> Result { use dash_sdk::platform::types::finalized_epoch::FinalizedEpochQuery; if start_epoch.is_none() { @@ -397,43 +326,17 @@ impl WasmSdk { let (epochs_result, metadata, proof) = dash_sdk::dpp::block::finalized_epoch_info::FinalizedEpochInfo::fetch_many_with_metadata_and_proof(self.as_ref(), query, None) .await?; - // Convert to our response format and sort by epoch index - let mut epochs: Vec = epochs_result - .into_iter() - .filter_map(|(epoch_index, epoch_opt)| { - epoch_opt.map(|epoch| { - use dash_sdk::dpp::block::finalized_epoch_info::v0::getters::FinalizedEpochInfoGettersV0; - EpochInfo { - index: epoch_index, - first_core_block_height: epoch.first_core_block_height(), - first_block_height: epoch.first_block_height(), - start_time: epoch.first_block_time(), - fee_multiplier: epoch.fee_multiplier_permille() as f64 / 1000.0, - protocol_version: epoch.protocol_version(), - } - }) - }) - .collect(); - - // Sort based on ascending flag - epochs.sort_by(|a, b| { - if is_ascending { - a.index.cmp(&b.index) - } else { - b.index.cmp(&a.index) - } - }); + let epochs_map = Map::new(); + for (index, epoch) in epochs_result { + let key = Number::from(index as u32); + let value = epoch.map(FinalizedEpochInfoWasm::from); + epochs_map.set(&key.into(), &JsValue::from(value)); + } - let response = ProofMetadataResponse { - data: epochs, + Ok(FinalizedEpochsProofResponseWasm { + epochs: epochs_map, metadata: metadata.into(), proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) }) } diff --git a/packages/wasm-sdk/src/queries/identity.rs b/packages/wasm-sdk/src/queries/identity.rs index 32d194d4e1d..58f0d1326ff 100644 --- a/packages/wasm-sdk/src/queries/identity.rs +++ b/packages/wasm-sdk/src/queries/identity.rs @@ -1,7 +1,6 @@ use crate::error::WasmSdkError; use crate::queries::{ProofInfo, ProofMetadataResponse, ResponseMetadata}; use crate::sdk::WasmSdk; -use wasm_dpp2::identity::IdentityWasm; use dash_sdk::dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0; use dash_sdk::dpp::identity::identity_public_key::IdentityPublicKey; use dash_sdk::platform::{Fetch, FetchMany, Identifier, Identity}; @@ -12,6 +11,7 @@ use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; +use wasm_dpp2::identity::IdentityWasm; fn identity_to_js_value(identity: Identity) -> Result { IdentityWasm::from(identity).to_object().map_err(|e| { diff --git a/packages/wasm-sdk/src/queries/mod.rs b/packages/wasm-sdk/src/queries/mod.rs index 9ab259f4d77..fb252f80224 100644 --- a/packages/wasm-sdk/src/queries/mod.rs +++ b/packages/wasm-sdk/src/queries/mod.rs @@ -330,13 +330,7 @@ impl ProofMetadataResponseWasm { } } - pub(crate) fn into_parts( - self, - ) -> ( - JsValue, - ResponseMetadataWasm, - ProofInfoWasm, - ) { + pub(crate) fn into_parts(self) -> (JsValue, ResponseMetadataWasm, ProofInfoWasm) { (self.data, self.metadata, self.proof) } } @@ -373,7 +367,10 @@ fn serialize_to_js(value: &T) -> Result { fn set_property(object: &Object, key: &str, value: &JsValue) -> Result<(), WasmSdkError> { js_sys::Reflect::set(object, &JsValue::from_str(key), value).map_err(|err| { - WasmSdkError::serialization(format!("Failed to set '{}' on proof response: {:?}", key, err)) + WasmSdkError::serialization(format!( + "Failed to set '{}' on proof response: {:?}", + key, err + )) })?; Ok(()) diff --git a/packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs b/packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs index 632614ba4bf..34e472ffece 100644 --- a/packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs +++ b/packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs @@ -18,12 +18,15 @@ describe('Epochs and evonode blocks', function describeEpochs() { }); it('gets epochs info and finalized epochs', async () => { - const current = await client.getCurrentEpoch().catch(() => 1000); - const start = Math.max(0, (current || 1000) - 5); + const current = await client.getCurrentEpoch().catch(() => null); + const currentIndex = current ? Number(current.index) : 1000; + const start = Math.max(0, currentIndex - 5); + const infos = await client.getEpochsInfo(start, 5, true); - expect(infos).to.be.an('array'); + expect(infos instanceof Map).to.be(true); + const finalized = await client.getFinalizedEpochInfos(start, 5); - expect(finalized).to.be.an('array'); + expect(finalized instanceof Map).to.be(true); }); it('queries evonode proposed blocks by id/range', async () => { From 8717ec2be31b530be11b5c1ce96946fa3f8904e2 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 9 Oct 2025 08:58:20 +0700 Subject: [PATCH 18/44] feat: groups --- packages/wasm-dpp2/src/group/action.rs | 54 ++ packages/wasm-dpp2/src/group/action_event.rs | 56 ++ packages/wasm-dpp2/src/group/mod.rs | 7 + packages/wasm-dpp2/src/group/token_event.rs | 196 +++++ packages/wasm-dpp2/src/lib.rs | 2 + .../wasm-sdk/src/queries/data_contract.rs | 25 +- packages/wasm-sdk/src/queries/group.rs | 824 ++++++------------ 7 files changed, 587 insertions(+), 577 deletions(-) create mode 100644 packages/wasm-dpp2/src/group/action.rs create mode 100644 packages/wasm-dpp2/src/group/action_event.rs create mode 100644 packages/wasm-dpp2/src/group/mod.rs create mode 100644 packages/wasm-dpp2/src/group/token_event.rs diff --git a/packages/wasm-dpp2/src/group/action.rs b/packages/wasm-dpp2/src/group/action.rs new file mode 100644 index 00000000000..7886cc375d8 --- /dev/null +++ b/packages/wasm-dpp2/src/group/action.rs @@ -0,0 +1,54 @@ +use crate::group::action_event::GroupActionEventWasm; +use crate::identifier::IdentifierWasm; +use dpp::data_contract::TokenContractPosition; +use dpp::group::group_action::{GroupAction, GroupActionAccessors}; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "GroupAction")] +pub struct GroupActionWasm(GroupAction); + +impl From for GroupActionWasm { + fn from(action: GroupAction) -> Self { + GroupActionWasm(action) + } +} + +impl From for GroupAction { + fn from(action: GroupActionWasm) -> Self { + action.0 + } +} + +#[wasm_bindgen(js_class = GroupAction)] +impl GroupActionWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "GroupAction".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name() -> String { + "GroupAction".to_string() + } + + #[wasm_bindgen(getter = "contractId")] + pub fn contract_id(&self) -> IdentifierWasm { + self.0.contract_id().into() + } + + #[wasm_bindgen(getter = "proposerId")] + pub fn proposer_id(&self) -> IdentifierWasm { + self.0.proposer_id().into() + } + + #[wasm_bindgen(getter = "tokenContractPosition")] + pub fn token_contract_position(&self) -> TokenContractPosition { + self.0.token_contract_position() + } + + #[wasm_bindgen(getter = "event")] + pub fn event(&self) -> GroupActionEventWasm { + GroupActionEventWasm::from(self.0.event().clone()) + } +} diff --git a/packages/wasm-dpp2/src/group/action_event.rs b/packages/wasm-dpp2/src/group/action_event.rs new file mode 100644 index 00000000000..3a9315addb5 --- /dev/null +++ b/packages/wasm-dpp2/src/group/action_event.rs @@ -0,0 +1,56 @@ +use crate::group::token_event::TokenEventWasm; +use dpp::group::action_event::GroupActionEvent; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "GroupActionEvent")] +pub struct GroupActionEventWasm(GroupActionEvent); + +impl From for GroupActionEventWasm { + fn from(event: GroupActionEvent) -> Self { + GroupActionEventWasm(event) + } +} + +impl From for GroupActionEvent { + fn from(event: GroupActionEventWasm) -> Self { + event.0 + } +} + +#[wasm_bindgen(js_class = GroupActionEvent)] +impl GroupActionEventWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "GroupActionEvent".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name(&self) -> String { + "GroupActionEvent".to_string() + } + + #[wasm_bindgen(getter = "variant")] + pub fn variant(&self) -> String { + match &self.0 { + GroupActionEvent::TokenEvent(_) => "TokenEvent".to_string(), + } + } + + #[wasm_bindgen(js_name = "tokenEvent")] + pub fn token_event(&self) -> TokenEventWasm { + match &self.0 { + GroupActionEvent::TokenEvent(event) => TokenEventWasm::from(event.clone()), + } + } + + #[wasm_bindgen(js_name = "eventName")] + pub fn event_name(&self) -> String { + self.0.event_name() + } + + #[wasm_bindgen(js_name = "publicNote")] + pub fn public_note(&self) -> Option { + self.0.public_note().map(|note| note.to_string()) + } +} diff --git a/packages/wasm-dpp2/src/group/mod.rs b/packages/wasm-dpp2/src/group/mod.rs new file mode 100644 index 00000000000..cf070d8ef91 --- /dev/null +++ b/packages/wasm-dpp2/src/group/mod.rs @@ -0,0 +1,7 @@ +mod action; +mod action_event; +mod token_event; + +pub use action::GroupActionWasm; +pub use action_event::GroupActionEventWasm; +pub use token_event::TokenEventWasm; diff --git a/packages/wasm-dpp2/src/group/token_event.rs b/packages/wasm-dpp2/src/group/token_event.rs new file mode 100644 index 00000000000..d72e479d015 --- /dev/null +++ b/packages/wasm-dpp2/src/group/token_event.rs @@ -0,0 +1,196 @@ +use crate::enums::token::emergency_action::TokenEmergencyActionWasm; +use crate::error::{WasmDppError, WasmDppResult}; +use crate::identifier::IdentifierWasm; +use crate::state_transitions::batch::token_pricing_schedule::TokenPricingScheduleWasm; +use crate::tokens::configuration_change_item::TokenConfigurationChangeItemWasm; +use crate::tokens::encrypted_note::private_encrypted_note::PrivateEncryptedNoteWasm; +use crate::tokens::encrypted_note::shared_encrypted_note::SharedEncryptedNoteWasm; +use crate::utils::JsValueExt; +use dpp::tokens::token_event::TokenEvent; +use js_sys::{BigInt, Object, Reflect}; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Debug, PartialEq)] +#[wasm_bindgen(js_name = "TokenEvent")] +pub struct TokenEventWasm(TokenEvent); + +impl From for TokenEventWasm { + fn from(event: TokenEvent) -> Self { + TokenEventWasm(event) + } +} + +impl From for TokenEvent { + fn from(event: TokenEventWasm) -> Self { + event.0 + } +} + +#[wasm_bindgen(js_class = TokenEvent)] +impl TokenEventWasm { + #[wasm_bindgen(getter = __type)] + pub fn type_name(&self) -> String { + "TokenEvent".to_string() + } + + #[wasm_bindgen(getter = __struct)] + pub fn struct_name(&self) -> String { + "TokenEvent".to_string() + } + + #[wasm_bindgen(getter = "variant")] + pub fn variant(&self) -> String { + match &self.0 { + TokenEvent::Mint(..) => "Mint", + TokenEvent::Burn(..) => "Burn", + TokenEvent::Freeze(..) => "Freeze", + TokenEvent::Unfreeze(..) => "Unfreeze", + TokenEvent::DestroyFrozenFunds(..) => "DestroyFrozenFunds", + TokenEvent::Transfer(..) => "Transfer", + TokenEvent::Claim(..) => "Claim", + TokenEvent::EmergencyAction(..) => "EmergencyAction", + TokenEvent::ConfigUpdate(..) => "ConfigUpdate", + TokenEvent::ChangePriceForDirectPurchase(..) => "ChangePriceForDirectPurchase", + TokenEvent::DirectPurchase(..) => "DirectPurchase", + } + .to_string() + } + + #[wasm_bindgen(js_name = "toObject")] + pub fn to_object(&self) -> WasmDppResult { + let object = Object::new(); + set_property(&object, "variant", &JsValue::from_str(&self.variant()))?; + + match &self.0 { + TokenEvent::Mint(amount, recipient, note) => { + set_amount(&object, *amount)?; + set_property( + &object, + "recipient", + &JsValue::from(IdentifierWasm::from(*recipient)), + )?; + set_note(&object, note)?; + } + TokenEvent::Burn(amount, burn_from, note) => { + set_amount(&object, *amount)?; + set_property( + &object, + "burnFrom", + &JsValue::from(IdentifierWasm::from(*burn_from)), + )?; + set_note(&object, note)?; + } + TokenEvent::Freeze(identity, note) | TokenEvent::Unfreeze(identity, note) => { + set_property( + &object, + "identity", + &JsValue::from(IdentifierWasm::from(*identity)), + )?; + set_note(&object, note)?; + } + TokenEvent::DestroyFrozenFunds(identity, amount, note) => { + set_property( + &object, + "identity", + &JsValue::from(IdentifierWasm::from(*identity)), + )?; + set_amount(&object, *amount)?; + set_note(&object, note)?; + } + TokenEvent::Transfer(recipient, note, shared, private, amount) => { + set_property( + &object, + "recipient", + &JsValue::from(IdentifierWasm::from(*recipient)), + )?; + set_note(&object, note)?; + + match shared { + Some(value) => set_property( + &object, + "sharedEncryptedNote", + &JsValue::from(SharedEncryptedNoteWasm::from(value.clone())), + )?, + None => set_property(&object, "sharedEncryptedNote", &JsValue::NULL)?, + } + + match private { + Some(value) => set_property( + &object, + "privateEncryptedNote", + &JsValue::from(PrivateEncryptedNoteWasm::from(value.clone())), + )?, + None => set_property(&object, "privateEncryptedNote", &JsValue::NULL)?, + } + + set_amount(&object, *amount)?; + } + TokenEvent::Claim(distribution, amount, note) => { + let distribution_js = + serde_wasm_bindgen::to_value(distribution).map_err(|err| { + WasmDppError::serialization(format!( + "unable to serialize token distribution recipient: {}", + err + )) + })?; + set_property(&object, "distribution", &distribution_js)?; + set_amount(&object, *amount)?; + set_note(&object, note)?; + } + TokenEvent::EmergencyAction(action, note) => { + set_property( + &object, + "action", + &JsValue::from(TokenEmergencyActionWasm::from(*action)), + )?; + set_note(&object, note)?; + } + TokenEvent::ConfigUpdate(change, note) => { + set_property( + &object, + "change", + &JsValue::from(TokenConfigurationChangeItemWasm::from(change.clone())), + )?; + set_note(&object, note)?; + } + TokenEvent::ChangePriceForDirectPurchase(schedule, note) => { + match schedule { + Some(s) => set_property( + &object, + "pricingSchedule", + &JsValue::from(TokenPricingScheduleWasm::from(s.clone())), + )?, + None => set_property(&object, "pricingSchedule", &JsValue::NULL)?, + } + set_note(&object, note)?; + } + TokenEvent::DirectPurchase(amount, credits) => { + set_amount(&object, *amount)?; + set_property(&object, "credits", &BigInt::from(*credits))?; + } + } + + Ok(object.into()) + } +} + +fn set_amount(object: &Object, amount: u64) -> WasmDppResult<()> { + set_property(object, "amount", &BigInt::from(amount)) +} + +fn set_note(object: &Object, note: &Option) -> WasmDppResult<()> { + match note { + Some(value) => set_property(object, "note", &JsValue::from_str(value)), + None => set_property(object, "note", &JsValue::NULL), + } +} + +fn set_property(object: &Object, key: &str, value: &JsValue) -> WasmDppResult<()> { + Reflect::set(object, &JsValue::from_str(key), value).map_err(|err| { + let message = err.error_message(); + WasmDppError::generic(format!("unable to set property '{key}': {message}")) + })?; + + Ok(()) +} diff --git a/packages/wasm-dpp2/src/lib.rs b/packages/wasm-dpp2/src/lib.rs index cd7aadccca5..ec2b0eb42f2 100644 --- a/packages/wasm-dpp2/src/lib.rs +++ b/packages/wasm-dpp2/src/lib.rs @@ -16,6 +16,7 @@ pub mod data_contract; pub mod enums; pub mod epoch; pub mod error; +pub mod group; pub mod identifier; pub mod identity; pub mod mock_bls; @@ -30,6 +31,7 @@ pub use data_contract::{ DataContractWasm, DocumentWasm, }; pub use epoch::{ExtendedEpochInfoWasm, FinalizedEpochInfoWasm}; +pub use group::{GroupActionEventWasm, GroupActionWasm, TokenEventWasm}; pub use identity::{ IdentityCreateTransitionWasm, IdentityCreditTransferWasm, diff --git a/packages/wasm-sdk/src/queries/data_contract.rs b/packages/wasm-sdk/src/queries/data_contract.rs index fcf3c1274fe..e84a74093bb 100644 --- a/packages/wasm-sdk/src/queries/data_contract.rs +++ b/packages/wasm-sdk/src/queries/data_contract.rs @@ -149,17 +149,10 @@ impl WasmSdk { let contracts_map = Map::new(); - for (id, contract_opt) in contracts_result { + for (id, contract) in contracts_result { let key = JsValue::from(IdentifierWasm::from(id)); - - match contract_opt { - Some(contract) => { - contracts_map.set(&key, &JsValue::from(DataContractWasm::from(contract))); - } - None => { - contracts_map.set(&key, &JsValue::NULL); - } - } + let value = contract.map(DataContractWasm::from); + contracts_map.set(&key, &JsValue::from(value)); } Ok(contracts_map) @@ -239,16 +232,10 @@ impl WasmSdk { let contracts_map = Map::new(); for (id, contract_opt) in contracts_result { - let key = JsValue::from( - id.to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), - ); - - let value = match contract_opt { - Some(contract) => JsValue::from(DataContractWasm::from(contract)), - None => JsValue::NULL, - }; + let key = JsValue::from(IdentifierWasm::from(id)); + let value = contract_opt.map(DataContractWasm::from); - contracts_map.set(&key, &value); + contracts_map.set(&key, &JsValue::from(value)); } Ok(DataContractsProofResponseWasm { diff --git a/packages/wasm-sdk/src/queries/group.rs b/packages/wasm-sdk/src/queries/group.rs index a680b29426f..928d4bce587 100644 --- a/packages/wasm-sdk/src/queries/group.rs +++ b/packages/wasm-sdk/src/queries/group.rs @@ -1,5 +1,6 @@ +use super::set_property; use crate::error::WasmSdkError; -use crate::queries::{ProofInfo, ProofMetadataResponse, ResponseMetadata}; +use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; use dash_sdk::dpp::data_contract::group::accessors::v0::GroupV0Getters; use dash_sdk::dpp::data_contract::group::Group; @@ -11,70 +12,16 @@ use dash_sdk::platform::group_actions::{ GroupActionSignersQuery, GroupActionsQuery, GroupInfosQuery, GroupQuery, }; use dash_sdk::platform::{Fetch, FetchMany, Identifier}; -use serde::{Deserialize, Serialize}; -use std::collections::BTreeMap; +use js_sys::{Array, BigInt, Map, Number, Object, Reflect}; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; +use wasm_dpp2::group::GroupActionWasm; +use wasm_dpp2::identifier::IdentifierWasm; +use wasm_dpp2::tokens::GroupWasm; +use wasm_dpp2::utils::JsValueExt; // Proof info functions are now included below -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct GroupInfoResponse { - members: BTreeMap, - required_power: u32, -} - -impl GroupInfoResponse { - fn from_group(group: &Group) -> Self { - let members = group - .members() - .iter() - .map(|(id, power)| { - ( - id.to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), - *power, - ) - }) - .collect(); - - Self { - members, - required_power: group.required_power(), - } - } -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct GroupMember { - member_id: String, - power: u32, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct IdentityGroupInfo { - data_contract_id: String, - group_contract_position: u32, - role: String, // "member", "owner", or "moderator" - power: Option, // Only for members -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct GroupsDataContractInfo { - data_contract_id: String, - groups: Vec, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct GroupContractPositionInfo { - position: u32, - group: GroupInfoResponse, -} - #[wasm_bindgen] impl WasmSdk { #[wasm_bindgen(js_name = "getGroupInfo")] @@ -100,15 +47,7 @@ impl WasmSdk { let group_result: Option = Group::fetch(self.as_ref(), query).await?; match group_result { - Some(group) => { - let response = GroupInfoResponse::from_group(&group); - - // Use json_compatible serializer to convert maps to objects - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } + Some(group) => Ok(JsValue::from(GroupWasm::from(group))), None => Ok(JsValue::NULL), } } @@ -139,83 +78,8 @@ impl WasmSdk { let group_result: Option = Group::fetch(self.as_ref(), query).await?; match group_result { - Some(group) => { - let mut members: Vec = Vec::new(); - - // If specific member IDs are requested, filter by them - if let Some(requested_ids) = member_ids { - let requested_identifiers: Result, _> = requested_ids - .iter() - .map(|id| { - Identifier::from_string( - id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - }) - .collect(); - let requested_identifiers = requested_identifiers.map_err(|e| { - WasmSdkError::invalid_argument(format!("Invalid member identity ID: {}", e)) - })?; - - for id in requested_identifiers { - if let Ok(power) = group.member_power(id) { - members.push(GroupMember { - member_id: id.to_string( - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ), - power, - }); - } - } - } else { - // Return all members with pagination - let all_members = group.members(); - let mut sorted_members: Vec<_> = all_members.iter().collect(); - sorted_members.sort_by_key(|(id, _)| *id); - - // Apply start_at if provided - let start_index = if let Some(start_id) = start_at { - let start_identifier = Identifier::from_string( - &start_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| { - WasmSdkError::invalid_argument(format!( - "Invalid start identity ID: {}", - e - )) - })?; - sorted_members - .iter() - .position(|(id, _)| **id > start_identifier) - .unwrap_or(sorted_members.len()) - } else { - 0 - }; - - // Apply limit - let end_index = if let Some(lim) = limit { - (start_index + lim as usize).min(sorted_members.len()) - } else { - sorted_members.len() - }; - - for (id, power) in &sorted_members[start_index..end_index] { - members.push(GroupMember { - member_id: (*id).to_string( - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ), - power: **power, - }); - } - } - - // Use json_compatible serializer to convert response - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - members.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } + Some(group) => collect_group_members_map(&group, &member_ids, &start_at, limit) + .map(|map| map.into()), None => Ok(JsValue::NULL), } } @@ -235,7 +99,7 @@ impl WasmSdk { ) .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; - let mut groups: Vec = Vec::new(); + let groups_array = Array::new(); // Check member data contracts if let Some(contracts) = member_data_contracts { @@ -264,12 +128,20 @@ impl WasmSdk { for (position, group_opt) in groups_result { if let Some(group) = group_opt { if let Ok(power) = group.member_power(id) { - groups.push(IdentityGroupInfo { - data_contract_id: contract_id_str.clone(), - group_contract_position: position as u32, - role: "member".to_string(), - power: Some(power), - }); + let entry = Object::new(); + set_property( + &entry, + "dataContractId", + &JsValue::from_str(&contract_id_str), + )?; + set_property( + &entry, + "groupContractPosition", + &Number::from(position as u32).into(), + )?; + set_property(&entry, "role", &JsValue::from_str("member"))?; + set_property(&entry, "power", &BigInt::from(power as u64))?; + groups_array.push(&entry.into()); } } } @@ -285,11 +157,7 @@ impl WasmSdk { ); } - // Use json_compatible serializer to convert response - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - groups.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(groups_array.into()) } #[wasm_bindgen(js_name = "getGroupInfos")] @@ -307,22 +175,25 @@ impl WasmSdk { .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; // Parse start at info if provided - let start_group_contract_position = - if !start_at_info.is_null() && !start_at_info.is_undefined() { - let info = serde_wasm_bindgen::from_value::(start_at_info); - match info { - Ok(json) => { - let position = json["position"].as_u64().ok_or_else(|| { - WasmSdkError::invalid_argument("Invalid start position") - })? as u32; - let included = json["included"].as_bool().unwrap_or(false); - Some((position as GroupContractPosition, included)) - } - Err(_) => None, - } - } else { - None - }; + let start_group_contract_position = if !start_at_info.is_null() + && !start_at_info.is_undefined() + { + let position_value = Reflect::get(&start_at_info, &JsValue::from_str("position")) + .map_err(|err| WasmSdkError::invalid_argument(err.error_message()))?; + let position = position_value + .as_f64() + .ok_or_else(|| WasmSdkError::invalid_argument("Invalid start position"))? + as GroupContractPosition; + + let included = Reflect::get(&start_at_info, &JsValue::from_str("included")) + .ok() + .and_then(|value| value.as_bool()) + .unwrap_or(false); + + Some((position, included)) + } else { + None + }; // Create query let query = GroupInfosQuery { @@ -335,36 +206,16 @@ impl WasmSdk { let groups_result = Group::fetch_many(self.as_ref(), query).await?; // Convert result to response format - let mut group_infos = Vec::new(); + let infos_map = Map::new(); for (position, group_opt) in groups_result { if let Some(group) = group_opt { - let members: Vec = group.members() - .iter() - .map(|(id, power)| { - serde_json::json!({ - "memberId": id.to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), - "power": *power - }) - }) - .collect(); - - group_infos.push(serde_json::json!({ - "groupContractPosition": position, - "members": members, - "groupRequiredPower": group.required_power() - })); + let key = Number::from(position as u32); + let value = JsValue::from(GroupWasm::from(group)); + infos_map.set(&key.into(), &value); } } - let response = serde_json::json!({ - "groupInfos": group_infos - }); - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(JsValue::from(infos_map)) } #[wasm_bindgen(js_name = "getGroupActions")] @@ -397,26 +248,21 @@ impl WasmSdk { // Parse start action ID if provided let start_at_action_id = if !start_at_info.is_null() && !start_at_info.is_undefined() { - let info = serde_wasm_bindgen::from_value::(start_at_info); - match info { - Ok(json) => { - let action_id = json["actionId"] - .as_str() - .ok_or_else(|| WasmSdkError::invalid_argument("Invalid action ID"))?; - let included = json["included"].as_bool().unwrap_or(false); - Some(( - Identifier::from_string( - action_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| { - WasmSdkError::invalid_argument(format!("Invalid action ID: {}", e)) - })?, - included, - )) - } - Err(_) => None, - } + let action_id_value = Reflect::get(&start_at_info, &JsValue::from_str("actionId")) + .map_err(|err| WasmSdkError::invalid_argument(err.error_message()))?; + let action_id_str = action_id_value + .as_string() + .ok_or_else(|| WasmSdkError::invalid_argument("Invalid action ID"))?; + let included = Reflect::get(&start_at_info, &JsValue::from_str("included")) + .ok() + .and_then(|value| value.as_bool()) + .unwrap_or(false); + let identifier = Identifier::from_string( + &action_id_str, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid action ID: {}", e)))?; + Some((identifier, included)) } else { None }; @@ -433,28 +279,17 @@ impl WasmSdk { // Fetch actions let actions_result = GroupAction::fetch_many(self.as_ref(), query).await?; - // Convert result to response format - let mut group_actions = Vec::new(); + let actions_map = Map::new(); for (action_id, action_opt) in actions_result { - if let Some(_action) = action_opt { - // For now, just return the action ID - // The full action structure requires custom serialization - group_actions.push(serde_json::json!({ - "actionId": action_id.to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), - // TODO: Serialize the full action event structure - })); - } + let key = JsValue::from(IdentifierWasm::from(action_id)); + let value = match action_opt { + Some(action) => JsValue::from(GroupActionWasm::from(action)), + None => JsValue::NULL, + }; + actions_map.set(&key, &value); } - let response = serde_json::json!({ - "groupActions": group_actions - }); - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(JsValue::from(actions_map)) } #[wasm_bindgen(js_name = "getGroupActionSigners")] @@ -502,26 +337,16 @@ impl WasmSdk { // Fetch signers let signers_result = GroupMemberPower::fetch_many(self.as_ref(), query).await?; - // Convert result to response format - let mut signers = Vec::new(); + let signers_map = Map::new(); for (signer_id, power_opt) in signers_result { if let Some(power) = power_opt { - signers.push(serde_json::json!({ - "signerId": signer_id.to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), - "power": power - })); + let key = JsValue::from(IdentifierWasm::from(signer_id)); + let value = JsValue::from(BigInt::from(power as u64)); + signers_map.set(&key, &value); } } - let response = serde_json::json!({ - "signers": signers - }); - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(JsValue::from(signers_map)) } #[wasm_bindgen(js_name = "getGroupsDataContracts")] @@ -529,7 +354,7 @@ impl WasmSdk { &self, data_contract_ids: Vec, ) -> Result { - let mut results: Vec = Vec::new(); + let contracts_map = Map::new(); for contract_id_str in data_contract_ids { let contract_id = Identifier::from_string( @@ -552,28 +377,22 @@ impl WasmSdk { let groups_result = Group::fetch_many(self.as_ref(), query).await?; - let mut groups: Vec = Vec::new(); + let groups_map = Map::new(); for (position, group_opt) in groups_result { - if let Some(group) = group_opt { - groups.push(GroupContractPositionInfo { - position: position as u32, - group: GroupInfoResponse::from_group(&group), - }); - } + let key = Number::from(position as u32); + let value = match group_opt { + Some(group) => JsValue::from(GroupWasm::from(group)), + None => JsValue::NULL, + }; + groups_map.set(&key.into(), &value); } - results.push(GroupsDataContractInfo { - data_contract_id: contract_id_str, - groups, - }); + let groups_value = JsValue::from(groups_map); + contracts_map.set(&JsValue::from_str(&contract_id_str), &groups_value); } - // Use json_compatible serializer to convert response - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - results.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(JsValue::from(contracts_map)) } // Proof versions for group queries @@ -584,8 +403,6 @@ impl WasmSdk { data_contract_id: &str, group_contract_position: u32, ) -> Result { - use crate::queries::ProofMetadataResponse; - // Parse data contract ID let contract_id = Identifier::from_string( data_contract_id, @@ -603,19 +420,9 @@ impl WasmSdk { let (group_result, metadata, proof) = Group::fetch_with_metadata_and_proof(self.as_ref(), query, None).await?; - let data = group_result.map(|group| GroupInfoResponse::from_group(&group)); - - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; + let response = ProofMetadataResponseWasm::from_sdk_parts(group_result.map(GroupWasm::from), metadata, proof); - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(JsValue::from(response)) } #[wasm_bindgen(js_name = "getGroupInfosWithProofInfo")] @@ -625,8 +432,6 @@ impl WasmSdk { start_at_info: JsValue, count: Option, ) -> Result { - use crate::queries::ProofMetadataResponse; - // Parse contract ID let contract_id = Identifier::from_string( contract_id, @@ -635,22 +440,25 @@ impl WasmSdk { .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; // Parse start at info if provided - let start_group_contract_position = - if !start_at_info.is_null() && !start_at_info.is_undefined() { - let info = serde_wasm_bindgen::from_value::(start_at_info); - match info { - Ok(json) => { - let position = json["position"].as_u64().ok_or_else(|| { - WasmSdkError::invalid_argument("Invalid start position") - })? as u32; - let included = json["included"].as_bool().unwrap_or(false); - Some((position as GroupContractPosition, included)) - } - Err(_) => None, - } - } else { - None - }; + let start_group_contract_position = if !start_at_info.is_null() + && !start_at_info.is_undefined() + { + let position_value = Reflect::get(&start_at_info, &JsValue::from_str("position")) + .map_err(|err| WasmSdkError::invalid_argument(err.error_message()))?; + let position = position_value + .as_f64() + .ok_or_else(|| WasmSdkError::invalid_argument("Invalid start position"))? + as GroupContractPosition; + + let included = Reflect::get(&start_at_info, &JsValue::from_str("included")) + .ok() + .and_then(|value| value.as_bool()) + .unwrap_or(false); + + Some((position, included)) + } else { + None + }; // Create query let query = GroupInfosQuery { @@ -663,32 +471,20 @@ impl WasmSdk { let (groups_result, metadata, proof) = Group::fetch_many_with_metadata_and_proof(self.as_ref(), query, None).await?; - // Convert result to response format - let mut group_infos = Vec::new(); + let infos_map = Map::new(); for (position, group_opt) in groups_result { - if let Some(group) = group_opt { - group_infos.push(GroupContractPositionInfo { - position: position as u32, - group: GroupInfoResponse::from_group(&group), - }); - } + let key = Number::from(position as u32); + let value = match group_opt { + Some(group) => JsValue::from(GroupWasm::from(group)), + None => JsValue::NULL, + }; + infos_map.set(&key.into(), &value); } - let data = serde_json::json!({ - "groupInfos": group_infos - }); - - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; + let data = JsValue::from(infos_map); + let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(JsValue::from(response)) } // Additional proof info versions for remaining group queries @@ -720,93 +516,13 @@ impl WasmSdk { Group::fetch_with_metadata_and_proof(self.as_ref(), query, None).await?; let data = match group_result { - Some(group) => { - let mut members: Vec = Vec::new(); - - // If specific member IDs are requested, filter by them - if let Some(requested_ids) = member_ids { - let requested_identifiers: Result, _> = requested_ids - .iter() - .map(|id| { - Identifier::from_string( - id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - }) - .collect(); - let requested_identifiers = requested_identifiers.map_err(|e| { - WasmSdkError::invalid_argument(format!("Invalid member identity ID: {}", e)) - })?; - - for id in requested_identifiers { - if let Ok(power) = group.member_power(id) { - members.push(GroupMember { - member_id: id.to_string( - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ), - power, - }); - } - } - } else { - // Return all members with pagination - let all_members = group.members(); - let mut sorted_members: Vec<_> = all_members.iter().collect(); - sorted_members.sort_by_key(|(id, _)| *id); - - // Apply start_at if provided - let start_index = if let Some(start_id) = start_at { - let start_identifier = Identifier::from_string( - &start_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| { - WasmSdkError::invalid_argument(format!( - "Invalid start identity ID: {}", - e - )) - })?; - sorted_members - .iter() - .position(|(id, _)| **id > start_identifier) - .unwrap_or(sorted_members.len()) - } else { - 0 - }; - - // Apply limit - let end_index = if let Some(lim) = limit { - (start_index + lim as usize).min(sorted_members.len()) - } else { - sorted_members.len() - }; - - for (id, power) in &sorted_members[start_index..end_index] { - members.push(GroupMember { - member_id: (*id).to_string( - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ), - power: **power, - }); - } - } - - Some(members) - } - None => None, + Some(group) => collect_group_members_map(&group, &member_ids, &start_at, limit)?.into(), + None => JsValue::NULL, }; - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; + let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(JsValue::from(response)) } #[wasm_bindgen(js_name = "getIdentityGroupsWithProofInfo")] @@ -817,15 +533,6 @@ impl WasmSdk { owner_data_contracts: Option>, moderator_data_contracts: Option>, ) -> Result { - #[derive(Serialize, Deserialize, Debug)] - #[serde(rename_all = "camelCase")] - struct IdentityGroupInfo { - data_contract_id: String, - group_contract_position: u32, - role: String, // "member", "owner", or "moderator" - power: Option, // Only for members - } - // Parse identity ID let id = Identifier::from_string( identity_id, @@ -833,9 +540,9 @@ impl WasmSdk { ) .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; - let mut groups: Vec = Vec::new(); - let mut combined_metadata: Option = None; - let mut combined_proof: Option = None; + let groups_array = Array::new(); + let mut combined_metadata: Option = None; + let mut combined_proof: Option = None; // Check member data contracts if let Some(contracts) = member_data_contracts { @@ -863,20 +570,28 @@ impl WasmSdk { // Store first metadata and proof if combined_metadata.is_none() { - combined_metadata = Some(metadata.into()); - combined_proof = Some(proof.into()); + combined_metadata = Some(metadata); + combined_proof = Some(proof); } // Check each group for the identity for (position, group_opt) in groups_result { if let Some(group) = group_opt { if let Ok(power) = group.member_power(id) { - groups.push(IdentityGroupInfo { - data_contract_id: contract_id_str.clone(), - group_contract_position: position as u32, - role: "member".to_string(), - power: Some(power), - }); + let entry = Object::new(); + set_property( + &entry, + "dataContractId", + &JsValue::from_str(&contract_id_str), + )?; + set_property( + &entry, + "groupContractPosition", + &Number::from(position as u32).into(), + )?; + set_property(&entry, "role", &JsValue::from_str("member"))?; + set_property(&entry, "power", &BigInt::from(power as u64))?; + groups_array.push(&entry.into()); } } } @@ -892,31 +607,12 @@ impl WasmSdk { ); } - let response = ProofMetadataResponse { - data: groups, - metadata: combined_metadata.unwrap_or_else(|| ResponseMetadata { - height: 0, - core_chain_locked_height: 0, - epoch: 0, - time_ms: 0, - protocol_version: 0, - chain_id: String::new(), - }), - proof: combined_proof.unwrap_or_else(|| ProofInfo { - grovedb_proof: String::new(), - quorum_hash: String::new(), - signature: String::new(), - round: 0, - block_id_hash: String::new(), - quorum_type: 0, - }), - }; + let metadata = combined_metadata.unwrap_or_default(); + let proof = combined_proof.unwrap_or_default(); + let data = JsValue::from(groups_array); + let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(JsValue::from(response)) } #[wasm_bindgen(js_name = "getGroupActionsWithProofInfo")] @@ -949,26 +645,21 @@ impl WasmSdk { // Parse start action ID if provided let start_at_action_id = if !start_at_info.is_null() && !start_at_info.is_undefined() { - let info = serde_wasm_bindgen::from_value::(start_at_info); - match info { - Ok(json) => { - let action_id = json["actionId"] - .as_str() - .ok_or_else(|| WasmSdkError::invalid_argument("Invalid action ID"))?; - let included = json["included"].as_bool().unwrap_or(false); - Some(( - Identifier::from_string( - action_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| { - WasmSdkError::invalid_argument(format!("Invalid action ID: {}", e)) - })?, - included, - )) - } - Err(_) => None, - } + let action_id_value = Reflect::get(&start_at_info, &JsValue::from_str("actionId")) + .map_err(|err| WasmSdkError::invalid_argument(err.error_message()))?; + let action_id_str = action_id_value + .as_string() + .ok_or_else(|| WasmSdkError::invalid_argument("Invalid action ID"))?; + let included = Reflect::get(&start_at_info, &JsValue::from_str("included")) + .ok() + .and_then(|value| value.as_bool()) + .unwrap_or(false); + let identifier = Identifier::from_string( + &action_id_str, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid action ID: {}", e)))?; + Some((identifier, included)) } else { None }; @@ -986,34 +677,20 @@ impl WasmSdk { let (actions_result, metadata, proof) = GroupAction::fetch_many_with_metadata_and_proof(self.as_ref(), query, None).await?; - // Convert result to response format - let mut group_actions = Vec::new(); + let actions_map = Map::new(); for (action_id, action_opt) in actions_result { - if let Some(_action) = action_opt { - // For now, just return the action ID - // The full action structure requires custom serialization - group_actions.push(serde_json::json!({ - "actionId": action_id.to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), - // TODO: Serialize the full action event structure - })); - } + let key = JsValue::from(IdentifierWasm::from(action_id)); + let value = match action_opt { + Some(action) => JsValue::from(GroupActionWasm::from(action)), + None => JsValue::NULL, + }; + actions_map.set(&key, &value); } - let data = serde_json::json!({ - "groupActions": group_actions - }); + let data = JsValue::from(actions_map); + let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(JsValue::from(response)) } #[wasm_bindgen(js_name = "getGroupActionSignersWithProofInfo")] @@ -1063,32 +740,19 @@ impl WasmSdk { GroupMemberPower::fetch_many_with_metadata_and_proof(self.as_ref(), query, None) .await?; - // Convert result to response format - let mut signers = Vec::new(); + let signers_map = Map::new(); for (signer_id, power_opt) in signers_result { if let Some(power) = power_opt { - signers.push(serde_json::json!({ - "signerId": signer_id.to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), - "power": power - })); + let key = JsValue::from(IdentifierWasm::from(signer_id)); + let value = JsValue::from(BigInt::from(power as u64)); + signers_map.set(&key, &value); } } - let data = serde_json::json!({ - "signers": signers - }); + let data = JsValue::from(signers_map); + let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(JsValue::from(response)) } #[wasm_bindgen(js_name = "getGroupsDataContractsWithProofInfo")] @@ -1096,9 +760,9 @@ impl WasmSdk { &self, data_contract_ids: Vec, ) -> Result { - let mut results: Vec = Vec::new(); - let mut combined_metadata: Option = None; - let mut combined_proof: Option = None; + let contracts_map = Map::new(); + let mut combined_metadata: Option = None; + let mut combined_proof: Option = None; for contract_id_str in data_contract_ids { let contract_id = Identifier::from_string( @@ -1122,53 +786,97 @@ impl WasmSdk { let (groups_result, metadata, proof) = Group::fetch_many_with_metadata_and_proof(self.as_ref(), query, None).await?; - // Store first metadata and proof if combined_metadata.is_none() { - combined_metadata = Some(metadata.into()); - combined_proof = Some(proof.into()); + combined_metadata = Some(metadata.clone()); + combined_proof = Some(proof.clone()); } - let mut groups: Vec = Vec::new(); - + let groups_map = Map::new(); for (position, group_opt) in groups_result { - if let Some(group) = group_opt { - groups.push(GroupContractPositionInfo { - position: position as u32, - group: GroupInfoResponse::from_group(&group), - }); - } + let key = Number::from(position as u32); + let value = match group_opt { + Some(group) => JsValue::from(GroupWasm::from(group)), + None => JsValue::NULL, + }; + groups_map.set(&key.into(), &value); } - results.push(GroupsDataContractInfo { - data_contract_id: contract_id_str, - groups, - }); + contracts_map.set(&JsValue::from_str(&contract_id_str), &groups_map.into()); } - let response = ProofMetadataResponse { - data: results, - metadata: combined_metadata.unwrap_or_else(|| ResponseMetadata { - height: 0, - core_chain_locked_height: 0, - epoch: 0, - time_ms: 0, - protocol_version: 0, - chain_id: String::new(), - }), - proof: combined_proof.unwrap_or_else(|| ProofInfo { - grovedb_proof: String::new(), - quorum_hash: String::new(), - signature: String::new(), - round: 0, - block_id_hash: String::new(), - quorum_type: 0, - }), - }; + let metadata = combined_metadata.unwrap_or_default(); + let proof = combined_proof.unwrap_or_default(); + let data = JsValue::from(contracts_map); + let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); + + Ok(JsValue::from(response)) + } +} + +fn insert_member( + map: &Map, + identifier: Identifier, + power: GroupMemberPower, +) -> Result<(), WasmSdkError> { + let key = JsValue::from(IdentifierWasm::from(identifier)); + let value = JsValue::from(BigInt::from(power as u64)); + map.set(&key, &value); + Ok(()) +} + +fn collect_group_members_map( + group: &Group, + member_ids: &Option>, + start_at: &Option, + limit: Option, +) -> Result { + let members_map = Map::new(); + + if let Some(requested_ids) = member_ids { + for id_str in requested_ids { + let identifier = Identifier::from_string( + id_str, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| { + WasmSdkError::invalid_argument(format!("Invalid member identity ID: {}", e)) + })?; + + if let Ok(power) = group.member_power(identifier) { + insert_member(&members_map, identifier, power)?; + } + } + } else { + let mut start_identifier = None; + if let Some(start_id) = start_at { + let identifier = Identifier::from_string( + start_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| { + WasmSdkError::invalid_argument(format!("Invalid start identity ID: {}", e)) + })?; + start_identifier = Some(identifier); + } + + let mut added = 0usize; + for (identifier, power) in group.members().iter() { + if let Some(start_id) = start_identifier { + if *identifier <= start_id { + continue; + } + } - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + insert_member(&members_map, *identifier, *power)?; + added += 1; + + if let Some(lim) = limit { + if added >= lim as usize { + break; + } + } + } } + + Ok(members_map) } From b62ce96a11f8c3a5996c7260e6d081290a06ea1e Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 9 Oct 2025 18:32:02 +0700 Subject: [PATCH 19/44] refactor: group responses --- packages/wasm-sdk/src/queries/group.rs | 176 +++++++++++++++---------- 1 file changed, 106 insertions(+), 70 deletions(-) diff --git a/packages/wasm-sdk/src/queries/group.rs b/packages/wasm-sdk/src/queries/group.rs index 928d4bce587..a555629c947 100644 --- a/packages/wasm-sdk/src/queries/group.rs +++ b/packages/wasm-sdk/src/queries/group.rs @@ -1,4 +1,3 @@ -use super::set_property; use crate::error::WasmSdkError; use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; @@ -12,7 +11,7 @@ use dash_sdk::platform::group_actions::{ GroupActionSignersQuery, GroupActionsQuery, GroupInfosQuery, GroupQuery, }; use dash_sdk::platform::{Fetch, FetchMany, Identifier}; -use js_sys::{Array, BigInt, Map, Number, Object, Reflect}; +use js_sys::{Array, BigInt, Map, Number, Reflect}; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; use wasm_dpp2::group::GroupActionWasm; @@ -22,6 +21,53 @@ use wasm_dpp2::utils::JsValueExt; // Proof info functions are now included below +#[wasm_bindgen(js_name = "IdentityGroupInfo")] +pub struct IdentityGroupInfoWasm { + data_contract_id: String, + group_contract_position: u32, + role: String, + power: Option, +} + +impl IdentityGroupInfoWasm { + fn new( + data_contract_id: String, + group_contract_position: u32, + role: String, + power: Option, + ) -> Self { + IdentityGroupInfoWasm { + data_contract_id, + group_contract_position, + role, + power, + } + } +} + +#[wasm_bindgen(js_class = IdentityGroupInfo)] +impl IdentityGroupInfoWasm { + #[wasm_bindgen(getter = "dataContractId")] + pub fn data_contract_id(&self) -> String { + self.data_contract_id.clone() + } + + #[wasm_bindgen(getter = "groupContractPosition")] + pub fn group_contract_position(&self) -> u32 { + self.group_contract_position + } + + #[wasm_bindgen(getter = "role")] + pub fn role(&self) -> String { + self.role.clone() + } + + #[wasm_bindgen(getter = "power")] + pub fn power(&self) -> Option { + self.power.map(|value| BigInt::from(value as u64)) + } +} + #[wasm_bindgen] impl WasmSdk { #[wasm_bindgen(js_name = "getGroupInfo")] @@ -29,7 +75,7 @@ impl WasmSdk { &self, data_contract_id: &str, group_contract_position: u32, - ) -> Result { + ) -> Result, WasmSdkError> { // Parse data contract ID let contract_id = Identifier::from_string( data_contract_id, @@ -44,12 +90,9 @@ impl WasmSdk { }; // Fetch the group - let group_result: Option = Group::fetch(self.as_ref(), query).await?; + let group = Group::fetch(self.as_ref(), query).await?; - match group_result { - Some(group) => Ok(JsValue::from(GroupWasm::from(group))), - None => Ok(JsValue::NULL), - } + Ok(group.map(Into::into)) } #[wasm_bindgen(js_name = "getGroupMembers")] @@ -60,7 +103,7 @@ impl WasmSdk { member_ids: Option>, start_at: Option, limit: Option, - ) -> Result { + ) -> Result { // Parse data contract ID let contract_id = Identifier::from_string( data_contract_id, @@ -75,13 +118,14 @@ impl WasmSdk { }; // Fetch the group - let group_result: Option = Group::fetch(self.as_ref(), query).await?; + let group = Group::fetch(self.as_ref(), query).await?; - match group_result { - Some(group) => collect_group_members_map(&group, &member_ids, &start_at, limit) - .map(|map| map.into()), - None => Ok(JsValue::NULL), - } + if let Some(group) = group { + let members = collect_group_members_map(&group, &member_ids, &start_at, limit)?; + return Ok(members) + }; + + Ok(Map::new()) } #[wasm_bindgen(js_name = "getIdentityGroups")] @@ -91,7 +135,7 @@ impl WasmSdk { member_data_contracts: Option>, owner_data_contracts: Option>, moderator_data_contracts: Option>, - ) -> Result { + ) -> Result { // Parse identity ID let id = Identifier::from_string( identity_id, @@ -128,20 +172,13 @@ impl WasmSdk { for (position, group_opt) in groups_result { if let Some(group) = group_opt { if let Ok(power) = group.member_power(id) { - let entry = Object::new(); - set_property( - &entry, - "dataContractId", - &JsValue::from_str(&contract_id_str), - )?; - set_property( - &entry, - "groupContractPosition", - &Number::from(position as u32).into(), - )?; - set_property(&entry, "role", &JsValue::from_str("member"))?; - set_property(&entry, "power", &BigInt::from(power as u64))?; - groups_array.push(&entry.into()); + let entry = IdentityGroupInfoWasm::new( + contract_id_str.clone(), + position as u32, + "member".to_string(), + Some(power), + ); + groups_array.push(&JsValue::from(entry)); } } } @@ -157,7 +194,7 @@ impl WasmSdk { ); } - Ok(groups_array.into()) + Ok(groups_array) } #[wasm_bindgen(js_name = "getGroupInfos")] @@ -166,7 +203,7 @@ impl WasmSdk { contract_id: &str, start_at_info: JsValue, count: Option, - ) -> Result { + ) -> Result { // Parse contract ID let contract_id = Identifier::from_string( contract_id, @@ -215,7 +252,7 @@ impl WasmSdk { } } - Ok(JsValue::from(infos_map)) + Ok(infos_map) } #[wasm_bindgen(js_name = "getGroupActions")] @@ -226,7 +263,7 @@ impl WasmSdk { status: &str, start_at_info: JsValue, count: Option, - ) -> Result { + ) -> Result { // Parse contract ID let contract_id = Identifier::from_string( contract_id, @@ -289,7 +326,7 @@ impl WasmSdk { actions_map.set(&key, &value); } - Ok(JsValue::from(actions_map)) + Ok(actions_map) } #[wasm_bindgen(js_name = "getGroupActionSigners")] @@ -299,7 +336,7 @@ impl WasmSdk { group_contract_position: u32, status: &str, action_id: &str, - ) -> Result { + ) -> Result { // Parse contract ID let contract_id = Identifier::from_string( contract_id, @@ -346,14 +383,14 @@ impl WasmSdk { } } - Ok(JsValue::from(signers_map)) + Ok(signers_map) } #[wasm_bindgen(js_name = "getGroupsDataContracts")] pub async fn get_groups_data_contracts( &self, data_contract_ids: Vec, - ) -> Result { + ) -> Result { let contracts_map = Map::new(); for contract_id_str in data_contract_ids { @@ -388,11 +425,13 @@ impl WasmSdk { groups_map.set(&key.into(), &value); } - let groups_value = JsValue::from(groups_map); - contracts_map.set(&JsValue::from_str(&contract_id_str), &groups_value); + contracts_map.set( + &JsValue::from_str(&contract_id_str), + &JsValue::from(groups_map), + ); } - Ok(JsValue::from(contracts_map)) + Ok(contracts_map) } // Proof versions for group queries @@ -402,7 +441,7 @@ impl WasmSdk { &self, data_contract_id: &str, group_contract_position: u32, - ) -> Result { + ) -> Result { // Parse data contract ID let contract_id = Identifier::from_string( data_contract_id, @@ -420,9 +459,13 @@ impl WasmSdk { let (group_result, metadata, proof) = Group::fetch_with_metadata_and_proof(self.as_ref(), query, None).await?; - let response = ProofMetadataResponseWasm::from_sdk_parts(group_result.map(GroupWasm::from), metadata, proof); + let response = ProofMetadataResponseWasm::from_sdk_parts( + group_result.map(GroupWasm::from), + metadata, + proof, + ); - Ok(JsValue::from(response)) + Ok(response) } #[wasm_bindgen(js_name = "getGroupInfosWithProofInfo")] @@ -431,7 +474,7 @@ impl WasmSdk { contract_id: &str, start_at_info: JsValue, count: Option, - ) -> Result { + ) -> Result { // Parse contract ID let contract_id = Identifier::from_string( contract_id, @@ -484,7 +527,7 @@ impl WasmSdk { let data = JsValue::from(infos_map); let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); - Ok(JsValue::from(response)) + Ok(response) } // Additional proof info versions for remaining group queries @@ -497,7 +540,7 @@ impl WasmSdk { member_ids: Option>, start_at: Option, limit: Option, - ) -> Result { + ) -> Result { // Parse data contract ID let contract_id = Identifier::from_string( data_contract_id, @@ -522,7 +565,7 @@ impl WasmSdk { let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); - Ok(JsValue::from(response)) + Ok(response) } #[wasm_bindgen(js_name = "getIdentityGroupsWithProofInfo")] @@ -532,7 +575,7 @@ impl WasmSdk { member_data_contracts: Option>, owner_data_contracts: Option>, moderator_data_contracts: Option>, - ) -> Result { + ) -> Result { // Parse identity ID let id = Identifier::from_string( identity_id, @@ -578,20 +621,13 @@ impl WasmSdk { for (position, group_opt) in groups_result { if let Some(group) = group_opt { if let Ok(power) = group.member_power(id) { - let entry = Object::new(); - set_property( - &entry, - "dataContractId", - &JsValue::from_str(&contract_id_str), - )?; - set_property( - &entry, - "groupContractPosition", - &Number::from(position as u32).into(), - )?; - set_property(&entry, "role", &JsValue::from_str("member"))?; - set_property(&entry, "power", &BigInt::from(power as u64))?; - groups_array.push(&entry.into()); + let entry = IdentityGroupInfoWasm::new( + contract_id_str.clone(), + position as u32, + "member".to_string(), + Some(power), + ); + groups_array.push(&JsValue::from(entry)); } } } @@ -612,7 +648,7 @@ impl WasmSdk { let data = JsValue::from(groups_array); let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); - Ok(JsValue::from(response)) + Ok(response) } #[wasm_bindgen(js_name = "getGroupActionsWithProofInfo")] @@ -623,7 +659,7 @@ impl WasmSdk { status: &str, start_at_info: JsValue, count: Option, - ) -> Result { + ) -> Result { // Parse contract ID let contract_id = Identifier::from_string( contract_id, @@ -690,7 +726,7 @@ impl WasmSdk { let data = JsValue::from(actions_map); let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); - Ok(JsValue::from(response)) + Ok(response) } #[wasm_bindgen(js_name = "getGroupActionSignersWithProofInfo")] @@ -700,7 +736,7 @@ impl WasmSdk { group_contract_position: u32, status: &str, action_id: &str, - ) -> Result { + ) -> Result { // Parse contract ID let contract_id = Identifier::from_string( contract_id, @@ -752,14 +788,14 @@ impl WasmSdk { let data = JsValue::from(signers_map); let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); - Ok(JsValue::from(response)) + Ok(response) } #[wasm_bindgen(js_name = "getGroupsDataContractsWithProofInfo")] pub async fn get_groups_data_contracts_with_proof_info( &self, data_contract_ids: Vec, - ) -> Result { + ) -> Result { let contracts_map = Map::new(); let mut combined_metadata: Option = None; let mut combined_proof: Option = None; @@ -809,7 +845,7 @@ impl WasmSdk { let data = JsValue::from(contracts_map); let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); - Ok(JsValue::from(response)) + Ok(response) } } From 9703af97425059436be32050d731faca2b89cee8 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 9 Oct 2025 21:04:13 +0700 Subject: [PATCH 20/44] refactor: identity and group --- packages/wasm-sdk/src/queries/group.rs | 62 +- packages/wasm-sdk/src/queries/identity.rs | 840 ++++++++++------------ 2 files changed, 405 insertions(+), 497 deletions(-) diff --git a/packages/wasm-sdk/src/queries/group.rs b/packages/wasm-sdk/src/queries/group.rs index a555629c947..ad3264ce50d 100644 --- a/packages/wasm-sdk/src/queries/group.rs +++ b/packages/wasm-sdk/src/queries/group.rs @@ -122,7 +122,7 @@ impl WasmSdk { if let Some(group) = group { let members = collect_group_members_map(&group, &member_ids, &start_at, limit)?; - return Ok(members) + return Ok(members); }; Ok(Map::new()) @@ -245,11 +245,9 @@ impl WasmSdk { // Convert result to response format let infos_map = Map::new(); for (position, group_opt) in groups_result { - if let Some(group) = group_opt { - let key = Number::from(position as u32); - let value = JsValue::from(GroupWasm::from(group)); - infos_map.set(&key.into(), &value); - } + let key = Number::from(position as u32); + let value = JsValue::from(group_opt.map(GroupWasm::from)); + infos_map.set(&key.into(), &value); } Ok(infos_map) @@ -319,10 +317,7 @@ impl WasmSdk { let actions_map = Map::new(); for (action_id, action_opt) in actions_result { let key = JsValue::from(IdentifierWasm::from(action_id)); - let value = match action_opt { - Some(action) => JsValue::from(GroupActionWasm::from(action)), - None => JsValue::NULL, - }; + let value = JsValue::from(action_opt.map(GroupActionWasm::from)); actions_map.set(&key, &value); } @@ -405,6 +400,8 @@ impl WasmSdk { )) })?; + let contract_key = JsValue::from(IdentifierWasm::from(contract_id.clone())); + // Fetch all groups for this contract let query = GroupInfosQuery { contract_id, @@ -418,17 +415,11 @@ impl WasmSdk { for (position, group_opt) in groups_result { let key = Number::from(position as u32); - let value = match group_opt { - Some(group) => JsValue::from(GroupWasm::from(group)), - None => JsValue::NULL, - }; + let value = JsValue::from(group_opt.map(GroupWasm::from)); groups_map.set(&key.into(), &value); } - contracts_map.set( - &JsValue::from_str(&contract_id_str), - &JsValue::from(groups_map), - ); + contracts_map.set(&contract_key, &JsValue::from(groups_map)); } Ok(contracts_map) @@ -517,15 +508,11 @@ impl WasmSdk { let infos_map = Map::new(); for (position, group_opt) in groups_result { let key = Number::from(position as u32); - let value = match group_opt { - Some(group) => JsValue::from(GroupWasm::from(group)), - None => JsValue::NULL, - }; + let value = JsValue::from(group_opt.map(GroupWasm::from)); infos_map.set(&key.into(), &value); } - let data = JsValue::from(infos_map); - let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); + let response = ProofMetadataResponseWasm::from_sdk_parts(infos_map, metadata, proof); Ok(response) } @@ -560,7 +547,7 @@ impl WasmSdk { let data = match group_result { Some(group) => collect_group_members_map(&group, &member_ids, &start_at, limit)?.into(), - None => JsValue::NULL, + None => JsValue::UNDEFINED, }; let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); @@ -645,8 +632,7 @@ impl WasmSdk { let metadata = combined_metadata.unwrap_or_default(); let proof = combined_proof.unwrap_or_default(); - let data = JsValue::from(groups_array); - let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); + let response = ProofMetadataResponseWasm::from_sdk_parts(groups_array, metadata, proof); Ok(response) } @@ -716,15 +702,11 @@ impl WasmSdk { let actions_map = Map::new(); for (action_id, action_opt) in actions_result { let key = JsValue::from(IdentifierWasm::from(action_id)); - let value = match action_opt { - Some(action) => JsValue::from(GroupActionWasm::from(action)), - None => JsValue::NULL, - }; + let value = JsValue::from(action_opt.map(GroupActionWasm::from)); actions_map.set(&key, &value); } - let data = JsValue::from(actions_map); - let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); + let response = ProofMetadataResponseWasm::from_sdk_parts(actions_map, metadata, proof); Ok(response) } @@ -785,8 +767,7 @@ impl WasmSdk { } } - let data = JsValue::from(signers_map); - let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); + let response = ProofMetadataResponseWasm::from_sdk_parts(signers_map, metadata, proof); Ok(response) } @@ -811,6 +792,7 @@ impl WasmSdk { contract_id_str, e )) })?; + let contract_key = JsValue::from(IdentifierWasm::from(contract_id.clone())); // Fetch all groups for this contract with proof let query = GroupInfosQuery { @@ -830,20 +812,16 @@ impl WasmSdk { let groups_map = Map::new(); for (position, group_opt) in groups_result { let key = Number::from(position as u32); - let value = match group_opt { - Some(group) => JsValue::from(GroupWasm::from(group)), - None => JsValue::NULL, - }; + let value = JsValue::from(group_opt.map(GroupWasm::from)); groups_map.set(&key.into(), &value); } - contracts_map.set(&JsValue::from_str(&contract_id_str), &groups_map.into()); + contracts_map.set(&contract_key, &JsValue::from(groups_map)); } let metadata = combined_metadata.unwrap_or_default(); let proof = combined_proof.unwrap_or_default(); - let data = JsValue::from(contracts_map); - let response = ProofMetadataResponseWasm::from_sdk_parts(data, metadata, proof); + let response = ProofMetadataResponseWasm::from_sdk_parts(contracts_map, metadata, proof); Ok(response) } diff --git a/packages/wasm-sdk/src/queries/identity.rs b/packages/wasm-sdk/src/queries/identity.rs index 58f0d1326ff..e7351e64682 100644 --- a/packages/wasm-sdk/src/queries/identity.rs +++ b/packages/wasm-sdk/src/queries/identity.rs @@ -1,33 +1,21 @@ use crate::error::WasmSdkError; -use crate::queries::{ProofInfo, ProofMetadataResponse, ResponseMetadata}; +use crate::queries::{ProofInfoWasm, ProofMetadataResponseWasm, ResponseMetadataWasm}; use crate::sdk::WasmSdk; use dash_sdk::dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0; use dash_sdk::dpp::identity::identity_public_key::IdentityPublicKey; use dash_sdk::platform::{Fetch, FetchMany, Identifier, Identity}; use drive_proof_verifier::types::{IdentityPublicKeys, IndexMap}; -use js_sys::Array; +use js_sys::{Array, BigInt, Map}; use rs_dapi_client::IntoInner; -use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; +use wasm_dpp2::identifier::IdentifierWasm; use wasm_dpp2::identity::IdentityWasm; -fn identity_to_js_value(identity: Identity) -> Result { - IdentityWasm::from(identity).to_object().map_err(|e| { - WasmSdkError::serialization(format!("Failed to convert identity to Object: {:?}", e)) - }) -} - -fn identity_to_json_value(identity: Identity) -> Result { - let identity_js = identity_to_js_value(identity)?; - serde_wasm_bindgen::from_value(identity_js) - .map_err(|e| WasmSdkError::serialization(format!("Failed to convert to JSON value: {}", e))) -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub(crate) struct IdentityKeyResponse { +#[wasm_bindgen(js_name = "IdentityKeyInfo")] +#[derive(Clone)] +pub struct IdentityKeyInfoWasm { key_id: u32, key_type: String, public_key_data: String, @@ -37,68 +25,228 @@ pub(crate) struct IdentityKeyResponse { disabled: bool, } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub(crate) struct IdentityBalanceResponse { - identity_id: String, - balance: String, // String to handle large numbers +impl IdentityKeyInfoWasm { + fn from_entry(key_id: u32, key: &IdentityPublicKey) -> Self { + IdentityKeyInfoWasm { + key_id, + key_type: format!("{:?}", key.key_type()), + public_key_data: hex::encode(key.data().as_slice()), + purpose: format!("{:?}", key.purpose()), + security_level: format!("{:?}", key.security_level()), + read_only: key.read_only(), + disabled: key.disabled_at().is_some(), + } + } } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub(crate) struct IdentityBalanceAndRevisionResponse { - balance: String, // String to handle large numbers - revision: u64, +#[wasm_bindgen(js_class = IdentityKeyInfo)] +impl IdentityKeyInfoWasm { + #[wasm_bindgen(getter = "keyId")] + pub fn key_id(&self) -> u32 { + self.key_id + } + + #[wasm_bindgen(getter = "keyType")] + pub fn key_type(&self) -> String { + self.key_type.clone() + } + + #[wasm_bindgen(getter = "publicKeyData")] + pub fn public_key_data(&self) -> String { + self.public_key_data.clone() + } + + #[wasm_bindgen(getter = "purpose")] + pub fn purpose(&self) -> String { + self.purpose.clone() + } + + #[wasm_bindgen(getter = "securityLevel")] + pub fn security_level(&self) -> String { + self.security_level.clone() + } + + #[wasm_bindgen(getter = "readOnly")] + pub fn read_only(&self) -> bool { + self.read_only + } + + #[wasm_bindgen(getter = "disabled")] + pub fn disabled(&self) -> bool { + self.disabled + } } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub(crate) struct IdentityContractKeyResponse { +#[wasm_bindgen(js_name = "IdentityContractKeys")] +#[derive(Clone)] +pub struct IdentityContractKeysWasm { identity_id: String, - purpose: u32, - key_id: u32, - key_type: String, - public_key_data: String, - security_level: String, - read_only: bool, - disabled: bool, + keys: Vec, } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub(crate) struct IdentityContractKeysResponse { +impl IdentityContractKeysWasm { + fn new(identity_id: String, keys: Vec) -> Self { + IdentityContractKeysWasm { identity_id, keys } + } +} + +#[wasm_bindgen(js_class = IdentityContractKeys)] +impl IdentityContractKeysWasm { + #[wasm_bindgen(getter = "identityId")] + pub fn identity_id(&self) -> String { + self.identity_id.clone() + } + + #[wasm_bindgen(getter = "keys")] + pub fn keys(&self) -> Array { + let array = Array::new(); + for key in &self.keys { + array.push(&JsValue::from(key.clone())); + } + array + } +} + +#[wasm_bindgen(js_name = "IdentityBalanceInfo")] +#[derive(Clone)] +pub struct IdentityBalanceWasm { + balance: u64, +} + +impl IdentityBalanceWasm { + fn new(balance: u64) -> Self { + IdentityBalanceWasm { balance } + } +} + +#[wasm_bindgen(js_class = IdentityBalanceInfo)] +impl IdentityBalanceWasm { + #[wasm_bindgen(getter = "balance")] + pub fn balance(&self) -> BigInt { + BigInt::from(self.balance) + } +} + +#[wasm_bindgen(js_name = "IdentityBalanceEntry")] +#[derive(Clone)] +pub struct IdentityBalanceEntryWasm { identity_id: String, - keys: Vec, + balance: u64, +} + +impl IdentityBalanceEntryWasm { + fn new(identity_id: String, balance: u64) -> Self { + IdentityBalanceEntryWasm { + identity_id, + balance, + } + } +} + +#[wasm_bindgen(js_class = IdentityBalanceEntry)] +impl IdentityBalanceEntryWasm { + #[wasm_bindgen(getter = "identityId")] + pub fn identity_id(&self) -> String { + self.identity_id.clone() + } + + #[wasm_bindgen(getter = "balance")] + pub fn balance(&self) -> BigInt { + BigInt::from(self.balance) + } } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub(crate) struct TokenBalanceResponse { - token_id: String, - balance: String, // String to handle large numbers +#[wasm_bindgen(js_name = "IdentityBalanceAndRevision")] +#[derive(Clone)] +pub struct IdentityBalanceAndRevisionWasm { + balance: u64, + revision: u64, +} + +impl IdentityBalanceAndRevisionWasm { + fn new(balance: u64, revision: u64) -> Self { + IdentityBalanceAndRevisionWasm { balance, revision } + } +} + +#[wasm_bindgen(js_class = IdentityBalanceAndRevision)] +impl IdentityBalanceAndRevisionWasm { + #[wasm_bindgen(getter = "balance")] + pub fn balance(&self) -> BigInt { + BigInt::from(self.balance) + } + + #[wasm_bindgen(getter = "revision")] + pub fn revision(&self) -> u64 { + self.revision + } +} + +#[wasm_bindgen(js_name = "IdentityNonce")] +#[derive(Clone)] +pub struct IdentityNonceWasm { + nonce: u64, +} + +impl IdentityNonceWasm { + fn new(nonce: u64) -> Self { + IdentityNonceWasm { nonce } + } +} + +#[wasm_bindgen(js_class = IdentityNonce)] +impl IdentityNonceWasm { + #[wasm_bindgen(getter = "nonce")] + pub fn nonce(&self) -> BigInt { + BigInt::from(self.nonce) + } +} + +#[wasm_bindgen(js_name = "IdentityProofResponse")] +#[derive(Clone)] +pub struct IdentityProofResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub identity: Option, + #[wasm_bindgen(getter_with_clone)] + pub metadata: ResponseMetadataWasm, + #[wasm_bindgen(getter_with_clone)] + pub proof: ProofInfoWasm, +} + +#[wasm_bindgen(js_name = "IdentityKeysProofResponse")] +#[derive(Clone)] +pub struct IdentityKeysProofResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub keys: Array, + #[wasm_bindgen(getter_with_clone)] + pub metadata: ResponseMetadataWasm, + #[wasm_bindgen(getter_with_clone)] + pub proof: ProofInfoWasm, } #[wasm_bindgen] impl WasmSdk { #[wasm_bindgen(js_name = "getIdentity")] - pub async fn get_identity(&self, base58_id: &str) -> Result { + pub async fn get_identity( + &self, + base58_id: &str, + ) -> Result, WasmSdkError> { let id = Identifier::from_string( base58_id, dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, ) .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; - Identity::fetch_by_identifier(self.as_ref(), id) - .await? - .ok_or_else(|| WasmSdkError::not_found("Identity not found")) - .map(Into::into) + let identity = Identity::fetch_by_identifier(self.as_ref(), id).await?; + + Ok(identity.map(IdentityWasm::from)) } #[wasm_bindgen(js_name = "getIdentityWithProofInfo")] pub async fn get_identity_with_proof_info( &self, base58_id: &str, - ) -> Result { + ) -> Result { let id = Identifier::from_string( base58_id, dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, @@ -109,21 +257,11 @@ impl WasmSdk { Identity::fetch_with_metadata_and_proof(self.as_ref(), id, None).await?; match identity { - Some(identity) => { - let identity_value = identity_to_json_value(identity)?; - - let response = ProofMetadataResponse { - data: identity_value, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } + Some(identity) => Ok(IdentityProofResponseWasm { + identity: Some(IdentityWasm::from(identity)), + metadata: metadata.into(), + proof: proof.into(), + }), None => Err(WasmSdkError::not_found("Identity not found")), } } @@ -189,7 +327,7 @@ impl WasmSdk { search_purpose_map: Option, // JSON string for SearchKey purpose map limit: Option, offset: Option, - ) -> Result { + ) -> Result { // DapiRequestExecutor not needed anymore if identity_id.is_empty() { @@ -294,8 +432,8 @@ impl WasmSdk { })?; // Parse the JSON purpose map - let purpose_map_json: serde_json::Value = serde_json::from_str(&purpose_map_str) - .map_err(|e| { + let purpose_map_json: JsonValue = + serde_json::from_str(&purpose_map_str).map_err(|e| { WasmSdkError::invalid_argument(format!( "Invalid JSON in search_purpose_map: {}", e @@ -305,7 +443,7 @@ impl WasmSdk { // Convert JSON to gRPC structure let mut purpose_map = HashMap::new(); - if let serde_json::Value::Object(map) = purpose_map_json { + if let JsonValue::Object(map) = purpose_map_json { for (purpose_str, security_levels) in map { let purpose = purpose_str.parse::().map_err(|_| { WasmSdkError::invalid_argument(format!( @@ -316,7 +454,7 @@ impl WasmSdk { let mut security_level_map = HashMap::new(); - if let serde_json::Value::Object(levels) = security_levels { + if let JsonValue::Object(levels) = security_levels { for (level_str, kind_str) in levels { let level = level_str.parse::().map_err(|_| { WasmSdkError::invalid_argument(format!( @@ -413,7 +551,7 @@ impl WasmSdk { }; // Convert keys to response format - let mut keys: Vec = Vec::new(); + let mut keys: Vec = Vec::new(); // Apply offset and limit if provided let start = offset.unwrap_or(0) as usize; @@ -432,25 +570,23 @@ impl WasmSdk { } if let Some(key) = key_opt { - keys.push(IdentityKeyResponse { - key_id, - key_type: format!("{:?}", key.key_type()), - public_key_data: hex::encode(key.data().as_slice()), - purpose: format!("{:?}", key.purpose()), - security_level: format!("{:?}", key.security_level()), - read_only: key.read_only(), - disabled: key.disabled_at().is_some(), - }); + keys.push(IdentityKeyInfoWasm::from_entry(key_id, &key)); } } - serde_wasm_bindgen::to_value(&keys).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + let array = Array::new(); + for key in keys { + array.push(&JsValue::from(key)); + } + + Ok(array) } #[wasm_bindgen(js_name = "getIdentityNonce")] - pub async fn get_identity_nonce(&self, identity_id: &str) -> Result { + pub async fn get_identity_nonce( + &self, + identity_id: &str, + ) -> Result { use dash_sdk::platform::Fetch; use drive_proof_verifier::types::IdentityNonceFetcher; @@ -470,28 +606,14 @@ impl WasmSdk { .map(|fetcher| fetcher.0) .ok_or_else(|| WasmSdkError::not_found("Identity nonce not found"))?; - // Return as a JSON object with nonce as string to avoid BigInt serialization issues - #[derive(Serialize)] - struct NonceResponse { - nonce: String, - } - - let response = NonceResponse { - nonce: nonce.to_string(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(IdentityNonceWasm::new(nonce)) } #[wasm_bindgen(js_name = "getIdentityNonceWithProofInfo")] pub async fn get_identity_nonce_with_proof_info( &self, identity_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::Fetch; use drive_proof_verifier::types::IdentityNonceFetcher; @@ -512,21 +634,12 @@ impl WasmSdk { .map(|fetcher| fetcher.0) .ok_or_else(|| WasmSdkError::not_found("Identity nonce not found"))?; - let data = serde_json::json!({ - "nonce": nonce.to_string() - }); - - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + let data = IdentityNonceWasm::new(nonce); + Ok(ProofMetadataResponseWasm::from_sdk_parts( + JsValue::from(data), + metadata, + proof, + )) } #[wasm_bindgen(js_name = "getIdentityContractNonce")] @@ -534,7 +647,7 @@ impl WasmSdk { &self, identity_id: &str, contract_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::Fetch; use drive_proof_verifier::types::IdentityContractNonceFetcher; @@ -565,21 +678,7 @@ impl WasmSdk { .map(|fetcher| fetcher.0) .ok_or_else(|| WasmSdkError::not_found("Identity contract nonce not found"))?; - // Return as a JSON object with nonce as string to avoid BigInt serialization issues - #[derive(Serialize)] - struct NonceResponse { - nonce: String, - } - - let response = NonceResponse { - nonce: nonce.to_string(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(IdentityNonceWasm::new(nonce)) } #[wasm_bindgen(js_name = "getIdentityContractNonceWithProofInfo")] @@ -587,7 +686,7 @@ impl WasmSdk { &self, identity_id: &str, contract_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::Fetch; use drive_proof_verifier::types::IdentityContractNonceFetcher; @@ -623,25 +722,19 @@ impl WasmSdk { .map(|fetcher| fetcher.0) .ok_or_else(|| WasmSdkError::not_found("Identity contract nonce not found"))?; - let data = serde_json::json!({ - "nonce": nonce.to_string() - }); - - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + let data = IdentityNonceWasm::new(nonce); + Ok(ProofMetadataResponseWasm::from_sdk_parts( + JsValue::from(data), + metadata, + proof, + )) } #[wasm_bindgen(js_name = "getIdentityBalance")] - pub async fn get_identity_balance(&self, id: &str) -> Result { + pub async fn get_identity_balance( + &self, + id: &str, + ) -> Result { use dash_sdk::platform::Fetch; use drive_proof_verifier::types::IdentityBalance; @@ -657,32 +750,16 @@ impl WasmSdk { let balance_result = IdentityBalance::fetch(self.as_ref(), identity_id).await?; - if let Some(balance) = balance_result { - // Return as object with balance as string to handle large numbers - #[derive(Serialize)] - struct BalanceResponse { - balance: String, - } - - let response = BalanceResponse { - balance: balance.to_string(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } else { - Err(WasmSdkError::not_found("Identity balance not found")) - } + balance_result + .map(IdentityBalanceWasm::new) + .ok_or_else(|| WasmSdkError::not_found("Identity balance not found")) } #[wasm_bindgen(js_name = "getIdentitiesBalances")] pub async fn get_identities_balances( &self, identity_ids: Vec, - ) -> Result { + ) -> Result { use drive_proof_verifier::types::IdentityBalance; // Convert string IDs to Identifiers @@ -700,31 +777,27 @@ impl WasmSdk { let balances_result: drive_proof_verifier::types::IdentityBalances = IdentityBalance::fetch_many(self.as_ref(), identifiers.clone()).await?; - // Convert to response format - let responses: Vec = identifiers - .into_iter() - .filter_map(|id| { - balances_result.get(&id).and_then(|balance_opt| { - balance_opt.map(|balance| IdentityBalanceResponse { - identity_id: id.to_string( - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ), - balance: balance.to_string(), - }) - }) - }) - .collect(); + let results_array = Array::new(); - serde_wasm_bindgen::to_value(&responses).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + for id in identifiers { + if let Some(Some(balance)) = balances_result.get(&id) { + let identity_id = + id.to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58); + results_array.push(&JsValue::from(IdentityBalanceEntryWasm::new( + identity_id, + *balance, + ))); + } + } + + Ok(results_array) } #[wasm_bindgen(js_name = "getIdentityBalanceAndRevision")] pub async fn get_identity_balance_and_revision( &self, identity_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::Fetch; use drive_proof_verifier::types::IdentityBalanceAndRevision; @@ -740,22 +813,9 @@ impl WasmSdk { let result = IdentityBalanceAndRevision::fetch(self.as_ref(), id).await?; - if let Some(balance_and_revision) = result { - let response = IdentityBalanceAndRevisionResponse { - balance: balance_and_revision.0.to_string(), - revision: balance_and_revision.1, - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } else { - Err(WasmSdkError::not_found( - "Identity balance and revision not found", - )) - } + result + .map(|(balance, revision)| IdentityBalanceAndRevisionWasm::new(balance, revision)) + .ok_or_else(|| WasmSdkError::not_found("Identity balance and revision not found")) } #[wasm_bindgen(js_name = "getIdentityByPublicKeyHash")] @@ -792,7 +852,7 @@ impl WasmSdk { identities_ids: Vec, contract_id: &str, purposes: Option>, - ) -> Result { + ) -> Result { use dash_sdk::dpp::identity::Purpose; // Convert string IDs to Identifiers @@ -831,7 +891,7 @@ impl WasmSdk { // For now, we'll implement this by fetching keys for each identity individually // The SDK doesn't fully expose the batch query yet - let mut responses: Vec = Vec::new(); + let mut responses: Vec = Vec::new(); for identity_id_str in identities_ids { let identity_id = Identifier::from_string( @@ -860,30 +920,24 @@ impl WasmSdk { } } - let key_response = IdentityKeyResponse { - key_id, - key_type: format!("{:?}", key.key_type()), - public_key_data: hex::encode(key.data().as_slice()), - purpose: format!("{:?}", key.purpose()), - security_level: format!("{:?}", key.security_level()), - read_only: key.read_only(), - disabled: key.disabled_at().is_some(), - }; - identity_keys.push(key_response); + identity_keys.push(IdentityKeyInfoWasm::from_entry(key_id, &key)); } } if !identity_keys.is_empty() { - responses.push(IdentityContractKeysResponse { - identity_id: identity_id_str, - keys: identity_keys, - }); + responses.push(IdentityContractKeysWasm::new( + identity_id_str, + identity_keys, + )); } } - serde_wasm_bindgen::to_value(&responses).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + let array = Array::new(); + for response in responses { + array.push(&JsValue::from(response)); + } + + Ok(array) } #[wasm_bindgen(js_name = "getIdentityByNonUniquePublicKeyHash")] @@ -891,7 +945,7 @@ impl WasmSdk { &self, public_key_hash: &str, start_after: Option, - ) -> Result { + ) -> Result { // Parse the hex-encoded public key hash let hash_bytes = hex::decode(public_key_hash).map_err(|e| { WasmSdkError::invalid_argument(format!("Invalid public key hash hex: {}", e)) @@ -931,23 +985,13 @@ impl WasmSdk { after: start_id.map(|id| *id.as_bytes()), }; - // Fetch identity by non-unique public key hash let identity = Identity::fetch(self.as_ref(), query).await?; - // Return array with single identity if found - let results = if let Some(id) = identity { - vec![id] - } else { - vec![] - }; - - // Create JS array directly let js_array = Array::new(); - for identity in results { - let json = identity_to_js_value(identity)?; - js_array.push(&json); + if let Some(identity) = identity { + js_array.push(&JsValue::from(IdentityWasm::from(identity))); } - Ok(js_array.into()) + Ok(js_array) } #[wasm_bindgen(js_name = "getIdentityTokenBalances")] @@ -955,7 +999,7 @@ impl WasmSdk { &self, identity_id: &str, token_ids: Vec, - ) -> Result { + ) -> Result { use dash_sdk::dpp::balances::credits::TokenAmount; use dash_sdk::platform::tokens::identity_token_balances::IdentityTokenBalancesQuery; @@ -986,23 +1030,16 @@ impl WasmSdk { let balances: drive_proof_verifier::types::identity_token_balance::IdentityTokenBalances = TokenAmount::fetch_many(self.as_ref(), query).await?; - // Convert to response format - let responses: Vec = token_identifiers - .into_iter() - .zip(token_ids.into_iter()) - .filter_map(|(token_id, token_id_str)| { - balances.get(&token_id).and_then(|balance_opt| { - balance_opt.map(|balance| TokenBalanceResponse { - token_id: token_id_str, - balance: balance.to_string(), - }) - }) - }) - .collect(); + let balances_map = Map::new(); + for token_id in token_identifiers { + if let Some(Some(balance)) = balances.get(&token_id) { + let key = JsValue::from(IdentifierWasm::from(token_id)); + let value = JsValue::from(BigInt::from(*balance as u64)); + balances_map.set(&key, &value); + } + } - serde_wasm_bindgen::to_value(&responses).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(balances_map) } // Proof info versions for identity queries @@ -1015,7 +1052,7 @@ impl WasmSdk { specific_key_ids: Option>, limit: Option, offset: Option, - ) -> Result { + ) -> Result { if identity_id.is_empty() { return Err(WasmSdkError::invalid_argument("Identity ID is required")); } @@ -1128,7 +1165,7 @@ impl WasmSdk { }; // Convert keys to response format - let mut keys: Vec = Vec::new(); + let mut keys: Vec = Vec::new(); // Apply offset and limit if provided let start = offset.unwrap_or(0) as usize; @@ -1147,28 +1184,19 @@ impl WasmSdk { } if let Some(key) = key_opt { - keys.push(IdentityKeyResponse { - key_id, - key_type: format!("{:?}", key.key_type()), - public_key_data: hex::encode(key.data().as_slice()), - purpose: format!("{:?}", key.purpose()), - security_level: format!("{:?}", key.security_level()), - read_only: key.read_only(), - disabled: key.disabled_at().is_some(), - }); + keys.push(IdentityKeyInfoWasm::from_entry(key_id, &key)); } } - let response = ProofMetadataResponse { - data: keys, + let keys_array = Array::new(); + for key in keys { + keys_array.push(&JsValue::from(key)); + } + + Ok(IdentityKeysProofResponseWasm { + keys: keys_array, metadata: metadata.into(), proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) }) } @@ -1176,7 +1204,7 @@ impl WasmSdk { pub async fn get_identity_balance_with_proof_info( &self, id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::Fetch; use drive_proof_verifier::types::IdentityBalance; @@ -1194,37 +1222,22 @@ impl WasmSdk { IdentityBalance::fetch_with_metadata_and_proof(self.as_ref(), identity_id, None) .await?; - if let Some(balance) = balance_result { - #[derive(Serialize)] - struct BalanceResponse { - balance: String, - } - - let data = BalanceResponse { - balance: balance.to_string(), - }; - - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) + balance_result + .map(|balance| { + ProofMetadataResponseWasm::from_sdk_parts( + JsValue::from(IdentityBalanceWasm::new(balance)), + metadata, + proof, + ) }) - } else { - Err(WasmSdkError::not_found("Identity balance not found")) - } + .ok_or_else(|| WasmSdkError::not_found("Identity balance not found")) } #[wasm_bindgen(js_name = "getIdentitiesBalancesWithProofInfo")] pub async fn get_identities_balances_with_proof_info( &self, identity_ids: Vec, - ) -> Result { + ) -> Result { use drive_proof_verifier::types::IdentityBalance; // Convert string IDs to Identifiers @@ -1250,39 +1263,28 @@ impl WasmSdk { ) .await?; - // Convert to response format - let responses: Vec = identifiers - .into_iter() - .filter_map(|id| { - balances_result.get(&id).and_then(|balance_opt| { - balance_opt.map(|balance| IdentityBalanceResponse { - identity_id: id.to_string( - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ), - balance: balance.to_string(), - }) - }) - }) - .collect(); - - let response = ProofMetadataResponse { - data: responses, - metadata: metadata.into(), - proof: proof.into(), - }; + let balances_array = Array::new(); + for id in identifiers { + if let Some(Some(balance)) = balances_result.get(&id) { + balances_array.push(&JsValue::from(IdentityBalanceEntryWasm::new( + id.to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), + *balance, + ))); + } + } - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + balances_array, + metadata, + proof, + )) } #[wasm_bindgen(js_name = "getIdentityBalanceAndRevisionWithProofInfo")] pub async fn get_identity_balance_and_revision_with_proof_info( &self, identity_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::Fetch; use drive_proof_verifier::types::IdentityBalanceAndRevision; @@ -1300,35 +1302,22 @@ impl WasmSdk { IdentityBalanceAndRevision::fetch_with_metadata_and_proof(self.as_ref(), id, None) .await?; - if let Some(balance_and_revision) = result { - let data = IdentityBalanceAndRevisionResponse { - balance: balance_and_revision.0.to_string(), - revision: balance_and_revision.1, - }; - - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) + result + .map(|(balance, revision)| { + ProofMetadataResponseWasm::from_sdk_parts( + JsValue::from(IdentityBalanceAndRevisionWasm::new(balance, revision)), + metadata, + proof, + ) }) - } else { - Err(WasmSdkError::not_found( - "Identity balance and revision not found", - )) - } + .ok_or_else(|| WasmSdkError::not_found("Identity balance and revision not found")) } #[wasm_bindgen(js_name = "getIdentityByPublicKeyHashWithProofInfo")] pub async fn get_identity_by_public_key_hash_with_proof_info( &self, public_key_hash: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::types::identity::PublicKeyHash; // Parse the hex-encoded public key hash @@ -1350,21 +1339,11 @@ impl WasmSdk { .await?; match result { - Some(identity) => { - let identity_value = identity_to_json_value(identity)?; - - let response = ProofMetadataResponse { - data: identity_value, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } + Some(identity) => Ok(IdentityProofResponseWasm { + identity: Some(IdentityWasm::from(identity)), + metadata: metadata.into(), + proof: proof.into(), + }), None => Err(WasmSdkError::not_found( "Identity not found for public key hash", )), @@ -1376,7 +1355,7 @@ impl WasmSdk { &self, public_key_hash: &str, start_after: Option, - ) -> Result { + ) -> Result { // Parse the hex-encoded public key hash let hash_bytes = hex::decode(public_key_hash).map_err(|e| { WasmSdkError::invalid_argument(format!("Invalid public key hash hex: {}", e)) @@ -1420,30 +1399,16 @@ impl WasmSdk { let (identity, metadata, proof) = Identity::fetch_with_metadata_and_proof(self.as_ref(), query, None).await?; - // Return array with single identity if found - let results = if let Some(id) = identity { - vec![id] - } else { - vec![] - }; - - // Convert results to JSON - let identities_json: Vec = results - .into_iter() - .map(|identity| identity_to_json_value(identity)) - .collect::, _>>()?; - - let response = ProofMetadataResponse { - data: identities_json, - metadata: metadata.into(), - proof: proof.into(), - }; + let identities_array = Array::new(); + if let Some(identity) = identity { + identities_array.push(&JsValue::from(IdentityWasm::from(identity))); + } - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + identities_array, + metadata, + proof, + )) } #[wasm_bindgen(js_name = "getIdentitiesContractKeysWithProofInfo")] @@ -1452,7 +1417,7 @@ impl WasmSdk { identities_ids: Vec, contract_id: &str, purposes: Option>, - ) -> Result { + ) -> Result { use dash_sdk::dpp::identity::Purpose; // Convert string IDs to Identifiers @@ -1491,9 +1456,9 @@ impl WasmSdk { // For now, we'll implement this by fetching keys for each identity individually with proof // The SDK doesn't fully expose the batch query with proof yet - let mut all_responses: Vec = Vec::new(); - let mut combined_metadata: Option = None; - let mut combined_proof: Option = None; + let mut all_responses: Vec = Vec::new(); + let mut combined_metadata: Option = None; + let mut combined_proof: Option = None; for identity_id_str in identities_ids { let identity_id = Identifier::from_string( @@ -1518,8 +1483,8 @@ impl WasmSdk { // Store first metadata and proof if combined_metadata.is_none() { - combined_metadata = Some(metadata.into()); - combined_proof = Some(proof.into()); + combined_metadata = Some(metadata); + combined_proof = Some(proof); } let mut identity_keys = Vec::new(); @@ -1534,52 +1499,28 @@ impl WasmSdk { } } - let key_response = IdentityKeyResponse { - key_id, - key_type: format!("{:?}", key.key_type()), - public_key_data: hex::encode(key.data().as_slice()), - purpose: format!("{:?}", key.purpose()), - security_level: format!("{:?}", key.security_level()), - read_only: key.read_only(), - disabled: key.disabled_at().is_some(), - }; - identity_keys.push(key_response); + identity_keys.push(IdentityKeyInfoWasm::from_entry(key_id, &key)); } } if !identity_keys.is_empty() { - all_responses.push(IdentityContractKeysResponse { - identity_id: identity_id_str, - keys: identity_keys, - }); + all_responses.push(IdentityContractKeysWasm::new( + identity_id_str, + identity_keys, + )); } } - let response = ProofMetadataResponse { - data: all_responses, - metadata: combined_metadata.unwrap_or_else(|| ResponseMetadata { - height: 0, - core_chain_locked_height: 0, - epoch: 0, - time_ms: 0, - protocol_version: 0, - chain_id: String::new(), - }), - proof: combined_proof.unwrap_or_else(|| ProofInfo { - grovedb_proof: String::new(), - quorum_hash: String::new(), - signature: String::new(), - round: 0, - block_id_hash: String::new(), - quorum_type: 0, - }), - }; + let responses_array = Array::new(); + for response in all_responses { + responses_array.push(&JsValue::from(response)); + } - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + responses_array, + combined_metadata.unwrap_or_default(), + combined_proof.unwrap_or_default(), + )) } #[wasm_bindgen(js_name = "getIdentityTokenBalancesWithProofInfo")] @@ -1587,7 +1528,7 @@ impl WasmSdk { &self, identity_id: &str, token_ids: Vec, - ) -> Result { + ) -> Result { use dash_sdk::dpp::balances::credits::TokenAmount; use dash_sdk::platform::tokens::identity_token_balances::IdentityTokenBalancesQuery; @@ -1621,30 +1562,19 @@ impl WasmSdk { _, ) = TokenAmount::fetch_many_with_metadata_and_proof(self.as_ref(), query, None).await?; - // Convert to response format - let responses: Vec = token_identifiers - .into_iter() - .zip(token_ids.into_iter()) - .filter_map(|(token_id, token_id_str)| { - balances.get(&token_id).and_then(|balance_opt| { - balance_opt.map(|balance| TokenBalanceResponse { - token_id: token_id_str, - balance: balance.to_string(), - }) - }) - }) - .collect(); - - let response = ProofMetadataResponse { - data: responses, - metadata: metadata.into(), - proof: proof.into(), - }; + let balances_map = Map::new(); + for token_id in token_identifiers { + if let Some(Some(balance)) = balances.get(&token_id) { + let key = JsValue::from(IdentifierWasm::from(token_id)); + let value = JsValue::from(BigInt::from(*balance as u64)); + balances_map.set(&key, &value); + } + } - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + JsValue::from(balances_map), + metadata, + proof, + )) } } From cb0ad52b7476d6770b4c2e0d70af1735db78c296 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 9 Oct 2025 21:13:30 +0700 Subject: [PATCH 21/44] refactor: protocol --- packages/wasm-sdk/src/queries/protocol.rs | 155 +++++++++++++++------- 1 file changed, 106 insertions(+), 49 deletions(-) diff --git a/packages/wasm-sdk/src/queries/protocol.rs b/packages/wasm-sdk/src/queries/protocol.rs index 9c91ac6c4b7..5184418a176 100644 --- a/packages/wasm-sdk/src/queries/protocol.rs +++ b/packages/wasm-sdk/src/queries/protocol.rs @@ -1,12 +1,13 @@ use crate::error::WasmSdkError; +use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; -use serde::{Deserialize, Serialize}; +use js_sys::Map; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct ProtocolVersionUpgradeState { +#[wasm_bindgen(js_name = "ProtocolVersionUpgradeState")] +#[derive(Clone)] +pub struct ProtocolVersionUpgradeStateWasm { current_protocol_version: u32, next_protocol_version: Option, activation_height: Option, @@ -14,17 +15,87 @@ struct ProtocolVersionUpgradeState { threshold_reached: bool, } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct ProtocolVersionUpgradeVoteStatus { +impl ProtocolVersionUpgradeStateWasm { + fn new( + current_protocol_version: u32, + next_protocol_version: Option, + activation_height: Option, + vote_count: Option, + threshold_reached: bool, + ) -> Self { + Self { + current_protocol_version, + next_protocol_version, + activation_height, + vote_count, + threshold_reached, + } + } +} + +#[wasm_bindgen(js_class = ProtocolVersionUpgradeState)] +impl ProtocolVersionUpgradeStateWasm { + #[wasm_bindgen(getter = "currentProtocolVersion")] + pub fn current_protocol_version(&self) -> u32 { + self.current_protocol_version + } + + #[wasm_bindgen(getter = "nextProtocolVersion")] + pub fn next_protocol_version(&self) -> Option { + self.next_protocol_version + } + + #[wasm_bindgen(getter = "activationHeight")] + pub fn activation_height(&self) -> Option { + self.activation_height + } + + #[wasm_bindgen(getter = "voteCount")] + pub fn vote_count(&self) -> Option { + self.vote_count + } + + #[wasm_bindgen(getter = "thresholdReached")] + pub fn threshold_reached(&self) -> bool { + self.threshold_reached + } +} + +#[wasm_bindgen(js_name = "ProtocolVersionUpgradeVoteStatus")] +#[derive(Clone)] +pub struct ProtocolVersionUpgradeVoteStatusWasm { pro_tx_hash: String, version: u32, } +impl ProtocolVersionUpgradeVoteStatusWasm { + fn new(pro_tx_hash: String, version: u32) -> Self { + Self { + pro_tx_hash, + version, + } + } +} + +#[wasm_bindgen(js_class = ProtocolVersionUpgradeVoteStatus)] +impl ProtocolVersionUpgradeVoteStatusWasm { + #[wasm_bindgen(getter = "proTxHash")] + pub fn pro_tx_hash(&self) -> String { + self.pro_tx_hash.clone() + } + + #[wasm_bindgen(getter = "version")] + pub fn version(&self) -> u32 { + self.version + } +} + #[wasm_bindgen] impl WasmSdk { #[wasm_bindgen(js_name = "getProtocolVersionUpgradeState")] - pub async fn get_protocol_version_upgrade_state(&self) -> Result { + pub async fn get_protocol_version_upgrade_state( + &self, + ) -> Result { use dash_sdk::platform::FetchMany; use drive_proof_verifier::types::ProtocolVersionVoteCount; @@ -52,17 +123,13 @@ impl WasmSdk { } } - let state = ProtocolVersionUpgradeState { - current_protocol_version: current_version, - next_protocol_version: next_version, + Ok(ProtocolVersionUpgradeStateWasm::new( + current_version, + next_version, activation_height, vote_count, threshold_reached, - }; - - serde_wasm_bindgen::to_value(&state).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + )) } #[wasm_bindgen(js_name = "getProtocolVersionUpgradeVoteStatus")] @@ -70,7 +137,7 @@ impl WasmSdk { &self, start_pro_tx_hash: &str, count: u32, - ) -> Result { + ) -> Result { use dash_sdk::dpp::dashcore::ProTxHash; use dash_sdk::platform::types::version_votes::MasternodeProtocolVoteEx; use drive_proof_verifier::types::MasternodeProtocolVote; @@ -90,20 +157,19 @@ impl WasmSdk { MasternodeProtocolVote::fetch_votes(self.as_ref(), start_hash, Some(count)).await?; // Convert to our response format - let votes: Vec = votes_result - .into_iter() - .filter_map(|(pro_tx_hash, vote_opt)| { - // vote_opt is Option - vote_opt.map(|vote| ProtocolVersionUpgradeVoteStatus { - pro_tx_hash: pro_tx_hash.to_string(), - version: vote.voted_version, - }) - }) - .collect(); - - serde_wasm_bindgen::to_value(&votes).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + let votes_map = Map::new(); + for (pro_tx_hash, vote_opt) in votes_result { + if let Some(vote) = vote_opt { + let key = JsValue::from_str(&pro_tx_hash.to_string()); + let value = JsValue::from(ProtocolVersionUpgradeVoteStatusWasm::new( + pro_tx_hash.to_string(), + vote.voted_version, + )); + votes_map.set(&key, &value); + } + } + + Ok(votes_map) } // Proof versions for protocol queries @@ -111,8 +177,7 @@ impl WasmSdk { #[wasm_bindgen(js_name = "getProtocolVersionUpgradeStateWithProofInfo")] pub async fn get_protocol_version_upgrade_state_with_proof_info( &self, - ) -> Result { - use crate::queries::ProofMetadataResponse; + ) -> Result { use dash_sdk::platform::FetchMany; use drive_proof_verifier::types::ProtocolVersionVoteCount; @@ -142,25 +207,17 @@ impl WasmSdk { } } - let state = ProtocolVersionUpgradeState { - current_protocol_version: current_version, - next_protocol_version: next_version, + let state = ProtocolVersionUpgradeStateWasm::new( + current_version, + next_version, activation_height, vote_count, threshold_reached, - }; - - let response = ProofMetadataResponse { - data: state, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + ); + + Ok(ProofMetadataResponseWasm::from_sdk_parts( + state, metadata, proof, + )) } #[wasm_bindgen(js_name = "getProtocolVersionUpgradeVoteStatusWithProofInfo")] From d09e11fb1eace12ae2a4a0f55485a8d8f25ed343 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 9 Oct 2025 21:55:56 +0700 Subject: [PATCH 22/44] refactor: system --- packages/wasm-sdk/src/queries/system.rs | 1186 ++++++++++++++--------- 1 file changed, 705 insertions(+), 481 deletions(-) diff --git a/packages/wasm-sdk/src/queries/system.rs b/packages/wasm-sdk/src/queries/system.rs index be78fdd0621..2df8344c6f7 100644 --- a/packages/wasm-sdk/src/queries/system.rs +++ b/packages/wasm-sdk/src/queries/system.rs @@ -1,112 +1,292 @@ use crate::error::WasmSdkError; +use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; use dash_sdk::dpp::core_types::validator_set::v0::ValidatorSetV0Getters; -use serde::{Deserialize, Serialize}; +use js_sys::{Array, BigInt}; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; -// Response structures for the gRPC getStatus endpoint -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StatusResponse { - version: StatusVersion, - node: StatusNode, - chain: StatusChain, - network: StatusNetwork, - state_sync: StatusStateSync, - time: StatusTime, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StatusVersion { - software: StatusSoftware, - protocol: StatusProtocol, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StatusSoftware { - dapi: String, - drive: Option, - tenderdash: Option, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StatusProtocol { - tenderdash: StatusTenderdashProtocol, - drive: StatusDriveProtocol, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StatusTenderdashProtocol { - p2p: u32, - block: u32, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StatusDriveProtocol { - latest: u32, - current: u32, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StatusNode { - id: String, - pro_tx_hash: Option, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StatusChain { - catching_up: bool, - latest_block_hash: String, - latest_app_hash: String, - latest_block_height: String, - earliest_block_hash: String, - earliest_app_hash: String, - earliest_block_height: String, - max_peer_block_height: String, - core_chain_locked_height: Option, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StatusNetwork { - chain_id: String, - peers_count: u32, - listening: bool, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StatusStateSync { - total_synced_time: String, - remaining_time: String, - total_snapshots: u32, - chunk_process_avg_time: String, - snapshot_height: String, - snapshot_chunks_count: String, - backfilled_blocks: String, - backfill_blocks_total: String, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StatusTime { - local: String, - block: Option, - genesis: Option, - epoch: Option, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct QuorumInfo { +#[wasm_bindgen(js_name = "StatusSoftware")] +#[derive(Clone)] +pub struct StatusSoftwareWasm { + #[wasm_bindgen(getter_with_clone)] + pub dapi: String, + #[wasm_bindgen(getter_with_clone)] + pub drive: Option, + #[wasm_bindgen(getter_with_clone)] + pub tenderdash: Option, +} + +impl StatusSoftwareWasm { + fn new(dapi: String, drive: Option, tenderdash: Option) -> Self { + Self { + dapi, + drive, + tenderdash, + } + } +} + +#[wasm_bindgen(js_name = "StatusTenderdashProtocol")] +#[derive(Clone)] +pub struct StatusTenderdashProtocolWasm { + #[wasm_bindgen(getter_with_clone)] + pub p2p: u32, + #[wasm_bindgen(getter_with_clone)] + pub block: u32, +} + +impl StatusTenderdashProtocolWasm { + fn new(p2p: u32, block: u32) -> Self { + Self { p2p, block } + } +} + +#[wasm_bindgen(js_name = "StatusDriveProtocol")] +#[derive(Clone)] +pub struct StatusDriveProtocolWasm { + #[wasm_bindgen(getter_with_clone)] + pub latest: u32, + #[wasm_bindgen(getter_with_clone)] + pub current: u32, +} + +impl StatusDriveProtocolWasm { + fn new(latest: u32, current: u32) -> Self { + Self { latest, current } + } +} + +#[wasm_bindgen(js_name = "StatusProtocol")] +#[derive(Clone)] +pub struct StatusProtocolWasm { + #[wasm_bindgen(getter_with_clone)] + pub tenderdash: StatusTenderdashProtocolWasm, + #[wasm_bindgen(getter_with_clone)] + pub drive: StatusDriveProtocolWasm, +} + +impl StatusProtocolWasm { + fn new(tenderdash: StatusTenderdashProtocolWasm, drive: StatusDriveProtocolWasm) -> Self { + Self { tenderdash, drive } + } +} + +#[wasm_bindgen(js_name = "StatusVersion")] +#[derive(Clone)] +pub struct StatusVersionWasm { + #[wasm_bindgen(getter_with_clone)] + pub software: StatusSoftwareWasm, + #[wasm_bindgen(getter_with_clone)] + pub protocol: StatusProtocolWasm, +} + +impl StatusVersionWasm { + fn new(software: StatusSoftwareWasm, protocol: StatusProtocolWasm) -> Self { + Self { software, protocol } + } +} + +#[wasm_bindgen(js_name = "StatusNode")] +#[derive(Clone)] +pub struct StatusNodeWasm { + #[wasm_bindgen(getter_with_clone)] + pub id: String, + #[wasm_bindgen(getter_with_clone)] + pub pro_tx_hash: Option, +} + +impl StatusNodeWasm { + fn new(id: String, pro_tx_hash: Option) -> Self { + Self { id, pro_tx_hash } + } +} + +#[wasm_bindgen(js_name = "StatusChain")] +#[derive(Clone)] +pub struct StatusChainWasm { + #[wasm_bindgen(getter_with_clone)] + pub catching_up: bool, + #[wasm_bindgen(getter_with_clone)] + pub latest_block_hash: String, + #[wasm_bindgen(getter_with_clone)] + pub latest_app_hash: String, + #[wasm_bindgen(getter_with_clone)] + pub latest_block_height: String, + #[wasm_bindgen(getter_with_clone)] + pub earliest_block_hash: String, + #[wasm_bindgen(getter_with_clone)] + pub earliest_app_hash: String, + #[wasm_bindgen(getter_with_clone)] + pub earliest_block_height: String, + #[wasm_bindgen(getter_with_clone)] + pub max_peer_block_height: String, + #[wasm_bindgen(getter_with_clone)] + pub core_chain_locked_height: Option, +} + +impl StatusChainWasm { + #[allow(clippy::too_many_arguments)] + fn new( + catching_up: bool, + latest_block_hash: String, + latest_app_hash: String, + latest_block_height: String, + earliest_block_hash: String, + earliest_app_hash: String, + earliest_block_height: String, + max_peer_block_height: String, + core_chain_locked_height: Option, + ) -> Self { + Self { + catching_up, + latest_block_hash, + latest_app_hash, + latest_block_height, + earliest_block_hash, + earliest_app_hash, + earliest_block_height, + max_peer_block_height, + core_chain_locked_height, + } + } +} + +#[wasm_bindgen(js_name = "StatusNetwork")] +#[derive(Clone)] +pub struct StatusNetworkWasm { + #[wasm_bindgen(getter_with_clone)] + pub chain_id: String, + #[wasm_bindgen(getter_with_clone)] + pub peers_count: u32, + #[wasm_bindgen(getter_with_clone)] + pub listening: bool, +} + +impl StatusNetworkWasm { + fn new(chain_id: String, peers_count: u32, listening: bool) -> Self { + Self { + chain_id, + peers_count, + listening, + } + } +} + +#[wasm_bindgen(js_name = "StatusStateSync")] +#[derive(Clone)] +pub struct StatusStateSyncWasm { + #[wasm_bindgen(getter_with_clone)] + pub total_synced_time: String, + #[wasm_bindgen(getter_with_clone)] + pub remaining_time: String, + #[wasm_bindgen(getter_with_clone)] + pub total_snapshots: u32, + #[wasm_bindgen(getter_with_clone)] + pub chunk_process_avg_time: String, + #[wasm_bindgen(getter_with_clone)] + pub snapshot_height: String, + #[wasm_bindgen(getter_with_clone)] + pub snapshot_chunks_count: String, + #[wasm_bindgen(getter_with_clone)] + pub backfilled_blocks: String, + #[wasm_bindgen(getter_with_clone)] + pub backfill_blocks_total: String, +} + +impl StatusStateSyncWasm { + fn new( + total_synced_time: String, + remaining_time: String, + total_snapshots: u32, + chunk_process_avg_time: String, + snapshot_height: String, + snapshot_chunks_count: String, + backfilled_blocks: String, + backfill_blocks_total: String, + ) -> Self { + Self { + total_synced_time, + remaining_time, + total_snapshots, + chunk_process_avg_time, + snapshot_height, + snapshot_chunks_count, + backfilled_blocks, + backfill_blocks_total, + } + } +} + +#[wasm_bindgen(js_name = "StatusTime")] +#[derive(Clone)] +pub struct StatusTimeWasm { + #[wasm_bindgen(getter_with_clone)] + pub local: String, + #[wasm_bindgen(getter_with_clone)] + pub block: Option, + #[wasm_bindgen(getter_with_clone)] + pub genesis: Option, + #[wasm_bindgen(getter_with_clone)] + pub epoch: Option, +} + +impl StatusTimeWasm { + fn new( + local: String, + block: Option, + genesis: Option, + epoch: Option, + ) -> Self { + Self { + local, + block, + genesis, + epoch, + } + } +} + +#[wasm_bindgen(js_name = "StatusResponse")] +#[derive(Clone)] +pub struct StatusResponseWasm { + #[wasm_bindgen(getter_with_clone)] + pub version: StatusVersionWasm, + #[wasm_bindgen(getter_with_clone)] + pub node: StatusNodeWasm, + #[wasm_bindgen(getter_with_clone)] + pub chain: StatusChainWasm, + #[wasm_bindgen(getter_with_clone)] + pub network: StatusNetworkWasm, + #[wasm_bindgen(getter_with_clone)] + pub state_sync: StatusStateSyncWasm, + #[wasm_bindgen(getter_with_clone)] + pub time: StatusTimeWasm, +} + +impl StatusResponseWasm { + fn new( + version: StatusVersionWasm, + node: StatusNodeWasm, + chain: StatusChainWasm, + network: StatusNetworkWasm, + state_sync: StatusStateSyncWasm, + time: StatusTimeWasm, + ) -> Self { + Self { + version, + node, + chain, + network, + state_sync, + time, + } + } +} + +#[wasm_bindgen(js_name = "QuorumInfo")] +#[derive(Clone)] +pub struct QuorumInfoWasm { quorum_hash: String, quorum_type: String, member_count: u32, @@ -114,45 +294,162 @@ struct QuorumInfo { is_verified: bool, } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct CurrentQuorumsInfo { - quorums: Vec, +impl QuorumInfoWasm { + fn new( + quorum_hash: String, + quorum_type: String, + member_count: u32, + threshold: u32, + is_verified: bool, + ) -> Self { + Self { + quorum_hash, + quorum_type, + member_count, + threshold, + is_verified, + } + } +} + +#[wasm_bindgen(js_class = QuorumInfo)] +impl QuorumInfoWasm { + #[wasm_bindgen(getter = "quorumHash")] + pub fn quorum_hash(&self) -> String { + self.quorum_hash.clone() + } + + #[wasm_bindgen(getter = "quorumType")] + pub fn quorum_type(&self) -> String { + self.quorum_type.clone() + } + + #[wasm_bindgen(getter = "memberCount")] + pub fn member_count(&self) -> u32 { + self.member_count + } + + #[wasm_bindgen(getter = "threshold")] + pub fn threshold(&self) -> u32 { + self.threshold + } + + #[wasm_bindgen(getter = "isVerified")] + pub fn is_verified(&self) -> bool { + self.is_verified + } +} + +#[wasm_bindgen(js_name = "CurrentQuorumsInfo")] +#[derive(Clone)] +pub struct CurrentQuorumsInfoWasm { + quorums: Vec, height: u64, } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct TotalCreditsResponse { - total_credits_in_platform: String, // Use String to handle large numbers +impl CurrentQuorumsInfoWasm { + fn new(quorums: Vec, height: u64) -> Self { + Self { quorums, height } + } } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StateTransitionResult { - state_transition_hash: String, - status: String, - error: Option, +#[wasm_bindgen(js_class = CurrentQuorumsInfo)] +impl CurrentQuorumsInfoWasm { + #[wasm_bindgen(getter = "quorums")] + pub fn quorums(&self) -> Array { + let array = Array::new(); + for quorum in &self.quorums { + array.push(&JsValue::from(quorum.clone())); + } + array + } + + #[wasm_bindgen(getter = "height")] + pub fn height(&self) -> u64 { + self.height + } } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct PrefundedSpecializedBalance { - identity_id: String, +#[wasm_bindgen(js_name = "PrefundedSpecializedBalance")] +#[derive(Clone)] +pub struct PrefundedSpecializedBalanceWasm { + #[wasm_bindgen(getter_with_clone)] + pub identity_id: String, balance: u64, } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct PathElement { +impl PrefundedSpecializedBalanceWasm { + fn new(identity_id: String, balance: u64) -> Self { + Self { + identity_id, + balance, + } + } +} + +#[wasm_bindgen(js_class = PrefundedSpecializedBalance)] +impl PrefundedSpecializedBalanceWasm { + #[wasm_bindgen(getter = "balance")] + pub fn balance(&self) -> BigInt { + BigInt::from(self.balance as u64) + } +} + +#[wasm_bindgen(js_name = "PathElement")] +#[derive(Clone)] +pub struct PathElementWasm { path: Vec, value: Option, } +impl PathElementWasm { + fn new(path: Vec, value: Option) -> Self { + Self { path, value } + } +} + +#[wasm_bindgen(js_class = PathElement)] +impl PathElementWasm { + #[wasm_bindgen(getter = "path")] + pub fn path(&self) -> Array { + let array = Array::new(); + for segment in &self.path { + array.push(&JsValue::from_str(segment)); + } + array + } + + #[wasm_bindgen(getter = "value")] + pub fn value(&self) -> Option { + self.value.clone() + } +} + +#[wasm_bindgen(js_name = "StateTransitionResult")] +#[derive(Clone)] +pub struct StateTransitionResultWasm { + #[wasm_bindgen(getter_with_clone)] + pub state_transition_hash: String, + #[wasm_bindgen(getter_with_clone)] + pub status: String, + #[wasm_bindgen(getter_with_clone)] + pub error: Option, +} + +impl StateTransitionResultWasm { + fn new(state_transition_hash: String, status: String, error: Option) -> Self { + Self { + state_transition_hash, + status, + error, + } + } +} + #[wasm_bindgen] impl WasmSdk { #[wasm_bindgen(js_name = "getStatus")] - pub async fn get_status(&self) -> Result { + pub async fn get_status(&self) -> Result { use dapi_grpc::platform::v0::get_status_request::{GetStatusRequestV0, Version}; use dapi_grpc::platform::v0::GetStatusRequest; use dash_sdk::RequestSettings; @@ -179,205 +476,209 @@ impl WasmSdk { }; // Map the response to our StatusResponse structure - let status = StatusResponse { - version: StatusVersion { - software: StatusSoftware { - dapi: v0_response - .version - .as_ref() - .and_then(|v| v.software.as_ref()) - .map(|s| s.dapi.clone()) - .unwrap_or_else(|| "unknown".to_string()), - drive: v0_response - .version - .as_ref() - .and_then(|v| v.software.as_ref()) - .and_then(|s| s.drive.clone()), - tenderdash: v0_response - .version - .as_ref() - .and_then(|v| v.software.as_ref()) - .and_then(|s| s.tenderdash.clone()), - }, - protocol: StatusProtocol { - tenderdash: StatusTenderdashProtocol { - p2p: v0_response - .version - .as_ref() - .and_then(|v| v.protocol.as_ref()) - .and_then(|p| p.tenderdash.as_ref()) - .map(|t| t.p2p) - .unwrap_or(0), - block: v0_response - .version - .as_ref() - .and_then(|v| v.protocol.as_ref()) - .and_then(|p| p.tenderdash.as_ref()) - .map(|t| t.block) - .unwrap_or(0), - }, - drive: StatusDriveProtocol { - latest: v0_response - .version - .as_ref() - .and_then(|v| v.protocol.as_ref()) - .and_then(|p| p.drive.as_ref()) - .map(|d| d.latest) - .unwrap_or(0), - current: v0_response - .version - .as_ref() - .and_then(|v| v.protocol.as_ref()) - .and_then(|p| p.drive.as_ref()) - .map(|d| d.current) - .unwrap_or(0), - }, - }, - }, - node: StatusNode { - id: v0_response - .node - .as_ref() - .map(|n| hex::encode(&n.id)) - .unwrap_or_else(|| "unknown".to_string()), - pro_tx_hash: v0_response - .node - .as_ref() - .and_then(|n| n.pro_tx_hash.as_ref()) - .map(hex::encode), - }, - chain: StatusChain { - catching_up: v0_response - .chain - .as_ref() - .map(|c| c.catching_up) - .unwrap_or(false), - latest_block_hash: v0_response - .chain - .as_ref() - .map(|c| hex::encode(&c.latest_block_hash)) - .unwrap_or_else(|| "unknown".to_string()), - latest_app_hash: v0_response - .chain - .as_ref() - .map(|c| hex::encode(&c.latest_app_hash)) - .unwrap_or_else(|| "unknown".to_string()), - latest_block_height: v0_response - .chain - .as_ref() - .map(|c| c.latest_block_height.to_string()) - .unwrap_or_else(|| "0".to_string()), - earliest_block_hash: v0_response - .chain - .as_ref() - .map(|c| hex::encode(&c.earliest_block_hash)) - .unwrap_or_else(|| "unknown".to_string()), - earliest_app_hash: v0_response - .chain - .as_ref() - .map(|c| hex::encode(&c.earliest_app_hash)) - .unwrap_or_else(|| "unknown".to_string()), - earliest_block_height: v0_response - .chain - .as_ref() - .map(|c| c.earliest_block_height.to_string()) - .unwrap_or_else(|| "0".to_string()), - max_peer_block_height: v0_response - .chain - .as_ref() - .map(|c| c.max_peer_block_height.to_string()) - .unwrap_or_else(|| "0".to_string()), - core_chain_locked_height: v0_response - .chain - .as_ref() - .and_then(|c| c.core_chain_locked_height), - }, - network: StatusNetwork { - chain_id: v0_response - .network - .as_ref() - .map(|n| n.chain_id.clone()) - .unwrap_or_else(|| "unknown".to_string()), - peers_count: v0_response - .network - .as_ref() - .map(|n| n.peers_count) - .unwrap_or(0), - listening: v0_response - .network - .as_ref() - .map(|n| n.listening) - .unwrap_or(false), - }, - state_sync: StatusStateSync { - total_synced_time: v0_response - .state_sync - .as_ref() - .map(|s| s.total_synced_time.to_string()) - .unwrap_or_else(|| "0".to_string()), - remaining_time: v0_response - .state_sync - .as_ref() - .map(|s| s.remaining_time.to_string()) - .unwrap_or_else(|| "0".to_string()), - total_snapshots: v0_response - .state_sync - .as_ref() - .map(|s| s.total_snapshots) - .unwrap_or(0), - chunk_process_avg_time: v0_response - .state_sync - .as_ref() - .map(|s| s.chunk_process_avg_time.to_string()) - .unwrap_or_else(|| "0".to_string()), - snapshot_height: v0_response - .state_sync - .as_ref() - .map(|s| s.snapshot_height.to_string()) - .unwrap_or_else(|| "0".to_string()), - snapshot_chunks_count: v0_response - .state_sync - .as_ref() - .map(|s| s.snapshot_chunks_count.to_string()) - .unwrap_or_else(|| "0".to_string()), - backfilled_blocks: v0_response - .state_sync - .as_ref() - .map(|s| s.backfilled_blocks.to_string()) - .unwrap_or_else(|| "0".to_string()), - backfill_blocks_total: v0_response - .state_sync - .as_ref() - .map(|s| s.backfill_blocks_total.to_string()) - .unwrap_or_else(|| "0".to_string()), - }, - time: StatusTime { - local: v0_response - .time - .as_ref() - .map(|t| t.local.to_string()) - .unwrap_or_else(|| "0".to_string()), - block: v0_response - .time - .as_ref() - .and_then(|t| t.block) - .map(|b| b.to_string()), - genesis: v0_response - .time - .as_ref() - .and_then(|t| t.genesis) - .map(|g| g.to_string()), - epoch: v0_response.time.as_ref().and_then(|t| t.epoch), - }, - }; - - serde_wasm_bindgen::to_value(&status).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + let software = StatusSoftwareWasm::new( + v0_response + .version + .as_ref() + .and_then(|v| v.software.as_ref()) + .map(|s| s.dapi.clone()) + .unwrap_or_else(|| "unknown".to_string()), + v0_response + .version + .as_ref() + .and_then(|v| v.software.as_ref()) + .and_then(|s| s.drive.clone()), + v0_response + .version + .as_ref() + .and_then(|v| v.software.as_ref()) + .and_then(|s| s.tenderdash.clone()), + ); + + let tenderdash_protocol = StatusTenderdashProtocolWasm::new( + v0_response + .version + .as_ref() + .and_then(|v| v.protocol.as_ref()) + .and_then(|p| p.tenderdash.as_ref()) + .map(|t| t.p2p) + .unwrap_or(0), + v0_response + .version + .as_ref() + .and_then(|v| v.protocol.as_ref()) + .and_then(|p| p.tenderdash.as_ref()) + .map(|t| t.block) + .unwrap_or(0), + ); + + let drive_protocol = StatusDriveProtocolWasm::new( + v0_response + .version + .as_ref() + .and_then(|v| v.protocol.as_ref()) + .and_then(|p| p.drive.as_ref()) + .map(|d| d.latest) + .unwrap_or(0), + v0_response + .version + .as_ref() + .and_then(|v| v.protocol.as_ref()) + .and_then(|p| p.drive.as_ref()) + .map(|d| d.current) + .unwrap_or(0), + ); + + let protocol = StatusProtocolWasm::new(tenderdash_protocol, drive_protocol); + let version = StatusVersionWasm::new(software, protocol); + + let node = StatusNodeWasm::new( + v0_response + .node + .as_ref() + .map(|n| hex::encode(&n.id)) + .unwrap_or_else(|| "unknown".to_string()), + v0_response + .node + .as_ref() + .and_then(|n| n.pro_tx_hash.as_ref()) + .map(hex::encode), + ); + + let chain = StatusChainWasm::new( + v0_response + .chain + .as_ref() + .map(|c| c.catching_up) + .unwrap_or(false), + v0_response + .chain + .as_ref() + .map(|c| hex::encode(&c.latest_block_hash)) + .unwrap_or_else(|| "unknown".to_string()), + v0_response + .chain + .as_ref() + .map(|c| hex::encode(&c.latest_app_hash)) + .unwrap_or_else(|| "unknown".to_string()), + v0_response + .chain + .as_ref() + .map(|c| c.latest_block_height.to_string()) + .unwrap_or_else(|| "0".to_string()), + v0_response + .chain + .as_ref() + .map(|c| hex::encode(&c.earliest_block_hash)) + .unwrap_or_else(|| "unknown".to_string()), + v0_response + .chain + .as_ref() + .map(|c| hex::encode(&c.earliest_app_hash)) + .unwrap_or_else(|| "unknown".to_string()), + v0_response + .chain + .as_ref() + .map(|c| c.earliest_block_height.to_string()) + .unwrap_or_else(|| "0".to_string()), + v0_response + .chain + .as_ref() + .map(|c| c.max_peer_block_height.to_string()) + .unwrap_or_else(|| "0".to_string()), + v0_response + .chain + .as_ref() + .and_then(|c| c.core_chain_locked_height), + ); + + let network = StatusNetworkWasm::new( + v0_response + .network + .as_ref() + .map(|n| n.chain_id.clone()) + .unwrap_or_else(|| "unknown".to_string()), + v0_response + .network + .as_ref() + .map(|n| n.peers_count) + .unwrap_or(0), + v0_response + .network + .as_ref() + .map(|n| n.listening) + .unwrap_or(false), + ); + + let state_sync = StatusStateSyncWasm::new( + v0_response + .state_sync + .as_ref() + .map(|s| s.total_synced_time.to_string()) + .unwrap_or_else(|| "0".to_string()), + v0_response + .state_sync + .as_ref() + .map(|s| s.remaining_time.to_string()) + .unwrap_or_else(|| "0".to_string()), + v0_response + .state_sync + .as_ref() + .map(|s| s.total_snapshots) + .unwrap_or(0), + v0_response + .state_sync + .as_ref() + .map(|s| s.chunk_process_avg_time.to_string()) + .unwrap_or_else(|| "0".to_string()), + v0_response + .state_sync + .as_ref() + .map(|s| s.snapshot_height.to_string()) + .unwrap_or_else(|| "0".to_string()), + v0_response + .state_sync + .as_ref() + .map(|s| s.snapshot_chunks_count.to_string()) + .unwrap_or_else(|| "0".to_string()), + v0_response + .state_sync + .as_ref() + .map(|s| s.backfilled_blocks.to_string()) + .unwrap_or_else(|| "0".to_string()), + v0_response + .state_sync + .as_ref() + .map(|s| s.backfill_blocks_total.to_string()) + .unwrap_or_else(|| "0".to_string()), + ); + + let time = StatusTimeWasm::new( + v0_response + .time + .as_ref() + .map(|t| t.local.to_string()) + .unwrap_or_else(|| "0".to_string()), + v0_response + .time + .as_ref() + .and_then(|t| t.block) + .map(|b| b.to_string()), + v0_response + .time + .as_ref() + .and_then(|t| t.genesis) + .map(|g| g.to_string()), + v0_response.time.as_ref().and_then(|t| t.epoch), + ); + + Ok(StatusResponseWasm::new( + version, node, chain, network, state_sync, time, + )) } #[wasm_bindgen(js_name = "getCurrentQuorumsInfo")] - pub async fn get_current_quorums_info(&self) -> Result { + pub async fn get_current_quorums_info(&self) -> Result { use dash_sdk::platform::FetchUnproved; use drive_proof_verifier::types::{ CurrentQuorumsInfo as SdkCurrentQuorumsInfo, NoParamQuery, @@ -390,7 +691,7 @@ impl WasmSdk { if let Some(quorum_info) = quorums_result { // Convert the SDK response to our structure // Match quorum hashes with validator sets to get detailed information - let quorums: Vec = quorum_info + let quorums: Vec = quorum_info .quorum_hashes .into_iter() .map(|quorum_hash| { @@ -422,51 +723,40 @@ impl WasmSdk { ), }; - QuorumInfo { - quorum_hash: hex::encode(quorum_hash), + QuorumInfoWasm::new( + hex::encode(quorum_hash), quorum_type, member_count, threshold, - is_verified: true, // We have the validator set, so it's verified - } + true, + ) } else { // No validator set found for this quorum hash // TODO: This should not happen in normal circumstances. When the SDK // provides complete quorum information, this fallback can be removed. - QuorumInfo { - quorum_hash: hex::encode(quorum_hash), - quorum_type: "LLMQ_TYPE_UNKNOWN".to_string(), - member_count: 0, - threshold: 0, - is_verified: false, - } + QuorumInfoWasm::new( + hex::encode(quorum_hash), + "LLMQ_TYPE_UNKNOWN".to_string(), + 0, + 0, + false, + ) } }) .collect(); - let info = CurrentQuorumsInfo { + Ok(CurrentQuorumsInfoWasm::new( quorums, - height: quorum_info.last_platform_block_height, - }; - - serde_wasm_bindgen::to_value(&info).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + quorum_info.last_platform_block_height, + )) } else { // No quorum info available - let info = CurrentQuorumsInfo { - quorums: vec![], - height: 0, - }; - - serde_wasm_bindgen::to_value(&info).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(CurrentQuorumsInfoWasm::new(vec![], 0)) } } #[wasm_bindgen(js_name = "getTotalCreditsInPlatform")] - pub async fn get_total_credits_in_platform(&self) -> Result { + pub async fn get_total_credits_in_platform(&self) -> Result { use dash_sdk::platform::Fetch; use drive_proof_verifier::types::{ NoParamQuery, TotalCreditsInPlatform as TotalCreditsQuery, @@ -483,22 +773,14 @@ impl WasmSdk { 0 }; - let response = TotalCreditsResponse { - total_credits_in_platform: credits_value.to_string(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(BigInt::from(credits_value as u64)) } #[wasm_bindgen(js_name = "getPrefundedSpecializedBalance")] pub async fn get_prefunded_specialized_balance( &self, identity_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::{Fetch, Identifier}; use drive_proof_verifier::types::PrefundedSpecializedBalance as PrefundedBalance; @@ -512,37 +794,19 @@ impl WasmSdk { // Fetch prefunded specialized balance let balance_result = PrefundedBalance::fetch(self.as_ref(), identity_identifier).await?; - if let Some(balance) = balance_result { - let response = PrefundedSpecializedBalance { - identity_id: identity_id.to_string(), - balance: balance.0, // PrefundedSpecializedBalance is a newtype wrapper around u64 - }; + let balance_value = balance_result.map(|b| b.0).unwrap_or(0); - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } else { - // Return zero balance if not found - let response = PrefundedSpecializedBalance { - identity_id: identity_id.to_string(), - balance: 0, - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } + Ok(PrefundedSpecializedBalanceWasm::new( + identity_id.to_string(), + balance_value, + )) } #[wasm_bindgen(js_name = "waitForStateTransitionResult")] pub async fn wait_for_state_transition_result( &self, state_transition_hash: &str, - ) -> Result { + ) -> Result { use dapi_grpc::platform::v0::wait_for_state_transition_result_request::{ Version, WaitForStateTransitionResultRequestV0, }; @@ -600,15 +864,11 @@ impl WasmSdk { ), }; - let result = StateTransitionResult { - state_transition_hash: state_transition_hash.to_string(), + Ok(StateTransitionResultWasm::new( + state_transition_hash.to_string(), status, error, - }; - - serde_wasm_bindgen::to_value(&result).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + )) } #[wasm_bindgen(js_name = "getPathElements")] @@ -616,7 +876,7 @@ impl WasmSdk { &self, path: Vec, keys: Vec, - ) -> Result { + ) -> Result { use dash_sdk::drive::grovedb::Element; use dash_sdk::platform::FetchMany; use drive_proof_verifier::types::{Elements, KeysInPath}; @@ -649,31 +909,22 @@ impl WasmSdk { let path_elements_result: Elements = Element::fetch_many(self.as_ref(), query).await?; // Convert the result to our response format - let elements: Vec = keys - .into_iter() - .map(|key| { - // Check if this key exists in the result - let value = path_elements_result - .get(key.as_bytes()) - .and_then(|element_opt| element_opt.as_ref()) - .and_then(|element| { - // Element can contain different types, we'll serialize it as base64 - element.as_item_bytes().ok().map(|bytes| { - use base64::Engine; - base64::engine::general_purpose::STANDARD.encode(bytes) - }) - }); - - PathElement { - path: vec![key], - value, - } - }) - .collect(); + let elements_array = Array::new(); + for key in keys { + let value = path_elements_result + .get(key.as_bytes()) + .and_then(|element_opt| element_opt.as_ref()) + .and_then(|element| { + element.as_item_bytes().ok().map(|bytes| { + use base64::Engine; + base64::engine::general_purpose::STANDARD.encode(bytes) + }) + }); + + elements_array.push(&JsValue::from(PathElementWasm::new(vec![key], value))); + } - serde_wasm_bindgen::to_value(&elements).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(elements_array) } // Proof versions for system queries @@ -681,8 +932,7 @@ impl WasmSdk { #[wasm_bindgen(js_name = "getTotalCreditsInPlatformWithProofInfo")] pub async fn get_total_credits_in_platform_with_proof_info( &self, - ) -> Result { - use crate::queries::ProofMetadataResponse; + ) -> Result { use dash_sdk::platform::Fetch; use drive_proof_verifier::types::{ NoParamQuery, TotalCreditsInPlatform as TotalCreditsQuery, @@ -692,29 +942,20 @@ impl WasmSdk { TotalCreditsQuery::fetch_with_metadata_and_proof(self.as_ref(), NoParamQuery {}, None) .await?; - let data = total_credits_result.map(|credits| TotalCreditsResponse { - total_credits_in_platform: credits.0.to_string(), - }); - - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; + let data = total_credits_result + .map(|credits| JsValue::from(BigInt::from(credits.0 as u64))) + .unwrap_or(JsValue::UNDEFINED); - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + data, metadata, proof, + )) } #[wasm_bindgen(js_name = "getPrefundedSpecializedBalanceWithProofInfo")] pub async fn get_prefunded_specialized_balance_with_proof_info( &self, identity_id: &str, - ) -> Result { - use crate::queries::ProofMetadataResponse; + ) -> Result { use dash_sdk::platform::{Fetch, Identifier}; use drive_proof_verifier::types::PrefundedSpecializedBalance as PrefundedBalance; @@ -733,22 +974,18 @@ impl WasmSdk { ) .await?; - let data = PrefundedSpecializedBalance { - identity_id: identity_id.to_string(), - balance: balance_result.map(|b| b.0).unwrap_or(0), - }; - - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; + let data = balance_result + .map(|balance| { + JsValue::from(PrefundedSpecializedBalanceWasm::new( + identity_id.to_string(), + balance.0, + )) + }) + .unwrap_or(JsValue::UNDEFINED); - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + data, metadata, proof, + )) } #[wasm_bindgen(js_name = "getPathElementsWithProofInfo")] @@ -756,8 +993,7 @@ impl WasmSdk { &self, path: Vec, keys: Vec, - ) -> Result { - use crate::queries::ProofMetadataResponse; + ) -> Result { use dash_sdk::drive::grovedb::Element; use dash_sdk::platform::FetchMany; use drive_proof_verifier::types::KeysInPath; @@ -790,37 +1026,25 @@ impl WasmSdk { let (path_elements_result, metadata, proof) = Element::fetch_many_with_metadata_and_proof(self.as_ref(), query, None).await?; - // Convert the result to our response format - let elements: Vec = keys - .into_iter() - .map(|key| { - let value = path_elements_result - .get(key.as_bytes()) - .and_then(|element_opt| element_opt.as_ref()) - .and_then(|element| { - element.as_item_bytes().ok().map(|bytes| { - use base64::Engine; - base64::engine::general_purpose::STANDARD.encode(bytes) - }) - }); - - PathElement { - path: vec![key], - value, - } - }) - .collect(); - - let response = ProofMetadataResponse { - data: elements, - metadata: metadata.into(), - proof: proof.into(), - }; + let elements_array = Array::new(); + for key in keys { + let value = path_elements_result + .get(key.as_bytes()) + .and_then(|element_opt| element_opt.as_ref()) + .and_then(|element| { + element.as_item_bytes().ok().map(|bytes| { + use base64::Engine; + base64::engine::general_purpose::STANDARD.encode(bytes) + }) + }); + + elements_array.push(&JsValue::from(PathElementWasm::new(vec![key], value))); + } - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + elements_array, + metadata, + proof, + )) } } From 03abb9611f60b5c8ba9b86730fb8a6b9c8920777 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 10 Oct 2025 18:28:48 +0700 Subject: [PATCH 23/44] refactor: add tokens --- .../wasm-dpp2/src/tokens/contract_info.rs | 38 + packages/wasm-dpp2/src/tokens/info.rs | 29 + packages/wasm-dpp2/src/tokens/mod.rs | 6 + packages/wasm-dpp2/src/tokens/status.rs | 29 + packages/wasm-sdk/src/queries/token.rs | 764 ++++++------------ 5 files changed, 370 insertions(+), 496 deletions(-) create mode 100644 packages/wasm-dpp2/src/tokens/contract_info.rs create mode 100644 packages/wasm-dpp2/src/tokens/info.rs create mode 100644 packages/wasm-dpp2/src/tokens/status.rs diff --git a/packages/wasm-dpp2/src/tokens/contract_info.rs b/packages/wasm-dpp2/src/tokens/contract_info.rs new file mode 100644 index 00000000000..ed1db08f2f5 --- /dev/null +++ b/packages/wasm-dpp2/src/tokens/contract_info.rs @@ -0,0 +1,38 @@ +use crate::identifier::IdentifierWasm; +use dpp::data_contract::TokenContractPosition; +use dpp::tokens::contract_info::v0::TokenContractInfoV0Accessors; +use dpp::tokens::contract_info::TokenContractInfo; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "TokenContractInfo")] +#[derive(Clone, Debug, PartialEq)] +pub struct TokenContractInfoWasm(TokenContractInfo); + +impl From for TokenContractInfoWasm { + fn from(info: TokenContractInfo) -> Self { + Self(info) + } +} + +impl From for TokenContractInfo { + fn from(info: TokenContractInfoWasm) -> Self { + info.0 + } +} + +#[wasm_bindgen(js_class = TokenContractInfo)] +impl TokenContractInfoWasm { + #[wasm_bindgen(getter = "contractId")] + pub fn contract_id(&self) -> IdentifierWasm { + match &self.0 { + TokenContractInfo::V0(v0) => v0.contract_id().into(), + } + } + + #[wasm_bindgen(getter = "tokenContractPosition")] + pub fn token_contract_position(&self) -> TokenContractPosition { + match &self.0 { + TokenContractInfo::V0(v0) => v0.token_contract_position(), + } + } +} diff --git a/packages/wasm-dpp2/src/tokens/info.rs b/packages/wasm-dpp2/src/tokens/info.rs new file mode 100644 index 00000000000..6be57016aae --- /dev/null +++ b/packages/wasm-dpp2/src/tokens/info.rs @@ -0,0 +1,29 @@ +use dpp::tokens::info::v0::IdentityTokenInfoV0Accessors; +use dpp::tokens::info::IdentityTokenInfo; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "IdentityTokenInfo")] +#[derive(Clone, Debug, PartialEq)] +pub struct IdentityTokenInfoWasm(IdentityTokenInfo); + +impl From for IdentityTokenInfoWasm { + fn from(info: IdentityTokenInfo) -> Self { + Self(info) + } +} + +impl From for IdentityTokenInfo { + fn from(info: IdentityTokenInfoWasm) -> Self { + info.0 + } +} + +#[wasm_bindgen(js_class = IdentityTokenInfo)] +impl IdentityTokenInfoWasm { + #[wasm_bindgen(getter = "frozen")] + pub fn frozen(&self) -> bool { + match &self.0 { + IdentityTokenInfo::V0(v0) => v0.frozen(), + } + } +} diff --git a/packages/wasm-dpp2/src/tokens/mod.rs b/packages/wasm-dpp2/src/tokens/mod.rs index 8f47f59a11c..6621fac0595 100644 --- a/packages/wasm-dpp2/src/tokens/mod.rs +++ b/packages/wasm-dpp2/src/tokens/mod.rs @@ -1,11 +1,17 @@ pub mod configuration; pub mod configuration_change_item; +pub mod contract_info; pub mod encrypted_note; +pub mod info; +pub mod status; pub use configuration::TokenConfigurationWasm; pub use configuration::authorized_action_takers::AuthorizedActionTakersWasm; pub use configuration::group::GroupWasm; pub use configuration::localization::TokenConfigurationLocalizationWasm; pub use configuration_change_item::TokenConfigurationChangeItemWasm; +pub use contract_info::TokenContractInfoWasm; pub use encrypted_note::private_encrypted_note::PrivateEncryptedNoteWasm; pub use encrypted_note::shared_encrypted_note::SharedEncryptedNoteWasm; +pub use info::IdentityTokenInfoWasm; +pub use status::TokenStatusWasm; diff --git a/packages/wasm-dpp2/src/tokens/status.rs b/packages/wasm-dpp2/src/tokens/status.rs new file mode 100644 index 00000000000..77398f6656f --- /dev/null +++ b/packages/wasm-dpp2/src/tokens/status.rs @@ -0,0 +1,29 @@ +use dpp::tokens::status::v0::TokenStatusV0Accessors; +use dpp::tokens::status::TokenStatus; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "TokenStatus")] +#[derive(Clone, Debug, PartialEq)] +pub struct TokenStatusWasm(TokenStatus); + +impl From for TokenStatusWasm { + fn from(status: TokenStatus) -> Self { + Self(status) + } +} + +impl From for TokenStatus { + fn from(status: TokenStatusWasm) -> Self { + status.0 + } +} + +#[wasm_bindgen(js_class = TokenStatus)] +impl TokenStatusWasm { + #[wasm_bindgen(getter = "paused")] + pub fn paused(&self) -> bool { + match &self.0 { + TokenStatus::V0(v0) => v0.paused(), + } + } +} diff --git a/packages/wasm-sdk/src/queries/token.rs b/packages/wasm-sdk/src/queries/token.rs index eda077f9c88..2133aec3631 100644 --- a/packages/wasm-sdk/src/queries/token.rs +++ b/packages/wasm-sdk/src/queries/token.rs @@ -1,71 +1,101 @@ use crate::error::WasmSdkError; -use crate::queries::ProofMetadataResponse; +use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; use dash_sdk::dpp::balances::credits::TokenAmount; use dash_sdk::dpp::tokens::calculate_token_id; use dash_sdk::dpp::tokens::info::IdentityTokenInfo; -use dash_sdk::dpp::tokens::status::v0::TokenStatusV0Accessors; use dash_sdk::dpp::tokens::status::TokenStatus; use dash_sdk::dpp::tokens::token_pricing_schedule::TokenPricingSchedule; use dash_sdk::platform::{FetchMany, Identifier}; -use serde::{Deserialize, Serialize}; +use js_sys::{BigInt, Map}; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; +use wasm_dpp2::identifier::IdentifierWasm; +use wasm_dpp2::tokens::{IdentityTokenInfoWasm, TokenContractInfoWasm, TokenStatusWasm}; -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct IdentityTokenBalanceResponse { - identity_id: String, - balance: String, // String to handle large numbers +#[wasm_bindgen(js_name = "TokenPriceInfo")] +#[derive(Clone)] +pub struct TokenPriceInfoWasm { + token_id: IdentifierWasm, + current_price: String, + base_price: String, } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct TokenInfoResponse { - token_id: String, - is_frozen: bool, +impl TokenPriceInfoWasm { + fn new(token_id: IdentifierWasm, current_price: String, base_price: String) -> Self { + Self { + token_id, + current_price, + base_price, + } + } } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct IdentityTokenInfoResponse { - identity_id: String, - is_frozen: bool, +#[wasm_bindgen(js_class = TokenPriceInfo)] +impl TokenPriceInfoWasm { + #[wasm_bindgen(getter = "tokenId")] + pub fn token_id(&self) -> IdentifierWasm { + self.token_id + } + + #[wasm_bindgen(getter = "currentPrice")] + pub fn current_price(&self) -> String { + self.current_price.clone() + } + + #[wasm_bindgen(getter = "basePrice")] + pub fn base_price(&self) -> String { + self.base_price.clone() + } } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct TokenStatusResponse { - token_id: String, - is_paused: bool, +#[wasm_bindgen(js_name = "TokenLastClaim")] +#[derive(Clone)] +pub struct TokenLastClaimWasm { + last_claim_timestamp_ms: u64, + last_claim_block_height: u64, } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct TokenPriceResponse { - token_id: String, - current_price: String, - base_price: String, +impl TokenLastClaimWasm { + fn new(last_claim_timestamp_ms: u64, last_claim_block_height: u64) -> Self { + Self { + last_claim_timestamp_ms, + last_claim_block_height, + } + } } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct TokenContractInfoResponse { - contract_id: String, - token_contract_position: u16, +#[wasm_bindgen(js_class = TokenLastClaim)] +impl TokenLastClaimWasm { + #[wasm_bindgen(getter = "lastClaimTimestampMs")] + pub fn last_claim_timestamp_ms(&self) -> u64 { + self.last_claim_timestamp_ms + } + + #[wasm_bindgen(getter = "lastClaimBlockHeight")] + pub fn last_claim_block_height(&self) -> u64 { + self.last_claim_block_height + } } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct LastClaimResponse { - last_claim_timestamp_ms: u64, - last_claim_block_height: u64, +#[wasm_bindgen(js_name = "TokenTotalSupply")] +#[derive(Clone)] +pub struct TokenTotalSupplyWasm { + total_supply: u64, } -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct TokenTotalSupplyResponse { - total_supply: String, +impl TokenTotalSupplyWasm { + fn new(total_supply: u64) -> Self { + Self { total_supply } + } +} + +#[wasm_bindgen(js_class = TokenTotalSupply)] +impl TokenTotalSupplyWasm { + #[wasm_bindgen(getter = "totalSupply")] + pub fn total_supply(&self) -> BigInt { + BigInt::from(self.total_supply) + } } #[wasm_bindgen] @@ -131,14 +161,14 @@ impl WasmSdk { /// "Hqyu8WcRwXCTwbNxdga4CN5gsVEGc67wng4TFzceyLUv", /// 0 /// ); - /// console.log(`Token ${priceInfo.tokenId} current price: ${priceInfo.currentPrice}`); + /// console.log(`Token ${priceInfo.tokenId.base58()} current price: ${priceInfo.currentPrice}`); /// ``` #[wasm_bindgen(js_name = "getTokenPriceByContract")] pub async fn get_token_price_by_contract( &self, contract_id: &str, token_position: u16, - ) -> Result { + ) -> Result { // Calculate token ID let token_id_string = Self::calculate_token_id_from_contract(contract_id, token_position)?; @@ -148,6 +178,7 @@ impl WasmSdk { dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, ) .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid token ID: {}", e)))?; + let token_identifier_wasm = IdentifierWasm::from(token_identifier.clone()); // Fetch token prices let prices_result: drive_proof_verifier::types::TokenDirectPurchasePrices = @@ -172,15 +203,7 @@ impl WasmSdk { }, }; - let response = TokenPriceResponse { - token_id: token_id_string, - current_price, - base_price, - }; - - serde_wasm_bindgen::to_value(&response).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(TokenPriceInfoWasm::new(token_identifier_wasm, current_price, base_price)) } else { Err(WasmSdkError::not_found(format!( "No pricing schedule found for token at contract {} position {}", @@ -200,7 +223,7 @@ impl WasmSdk { &self, identity_ids: Vec, token_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::tokens::identity_token_balances::IdentitiesTokenBalancesQuery; use drive_proof_verifier::types::identity_token_balance::IdentitiesTokenBalances; @@ -234,28 +257,16 @@ impl WasmSdk { let balances_result: IdentitiesTokenBalances = TokenAmount::fetch_many(self.as_ref(), query).await?; - // Convert to response format - let responses: Vec = identity_ids - .into_iter() - .filter_map(|id_str| { - let id = Identifier::from_string( - &id_str, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .ok()?; - - balances_result.get(&id).and_then(|balance_opt| { - balance_opt.map(|balance| IdentityTokenBalanceResponse { - identity_id: id_str, - balance: balance.to_string(), - }) - }) - }) - .collect(); + let balances_map = Map::new(); + for identifier in &identities { + if let Some(Some(balance)) = balances_result.get(identifier) { + let key = JsValue::from(IdentifierWasm::from((*identifier).clone())); + let value = JsValue::from(BigInt::from(*balance as u64)); + balances_map.set(&key, &value); + } + } - serde_wasm_bindgen::to_value(&responses).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(balances_map) } #[wasm_bindgen(js_name = "getIdentityTokenInfos")] @@ -263,7 +274,7 @@ impl WasmSdk { &self, identity_id: &str, token_ids: Vec, - ) -> Result { + ) -> Result { use dash_sdk::platform::tokens::token_info::IdentityTokenInfosQuery; use drive_proof_verifier::types::token_info::IdentityTokenInfos; @@ -297,37 +308,17 @@ impl WasmSdk { let infos_result: IdentityTokenInfos = IdentityTokenInfo::fetch_many(self.as_ref(), query).await?; - // Convert to response format - let responses: Vec = token_ids - .into_iter() - .filter_map(|id_str| { - let id = Identifier::from_string( - &id_str, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .ok()?; - - infos_result.get(&id).and_then(|info_opt| { - info_opt.as_ref().map(|info| { - use dash_sdk::dpp::tokens::info::v0::IdentityTokenInfoV0Accessors; - - // IdentityTokenInfo only contains frozen status - let is_frozen = match &info { - dash_sdk::dpp::tokens::info::IdentityTokenInfo::V0(v0) => v0.frozen(), - }; - - TokenInfoResponse { - token_id: id_str, - is_frozen, - } - }) - }) - }) - .collect(); + let infos_map = Map::new(); + for token in tokens { + if let Some(Some(info)) = infos_result.get(&token) { + let info_wasm = IdentityTokenInfoWasm::from(info.clone()); + let key = JsValue::from(IdentifierWasm::from(token)); + let value = JsValue::from(info_wasm); + infos_map.set(&key, &value); + } + } - serde_wasm_bindgen::to_value(&responses).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(infos_map) } #[wasm_bindgen(js_name = "getIdentitiesTokenInfos")] @@ -335,7 +326,7 @@ impl WasmSdk { &self, identity_ids: Vec, token_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::tokens::token_info::IdentitiesTokenInfosQuery; use drive_proof_verifier::types::token_info::IdentitiesTokenInfos; @@ -369,44 +360,24 @@ impl WasmSdk { let infos_result: IdentitiesTokenInfos = IdentityTokenInfo::fetch_many(self.as_ref(), query).await?; - // Convert to response format - let responses: Vec = identity_ids - .into_iter() - .filter_map(|id_str| { - let id = Identifier::from_string( - &id_str, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .ok()?; - - infos_result.get(&id).and_then(|info_opt| { - info_opt.as_ref().map(|info| { - use dash_sdk::dpp::tokens::info::v0::IdentityTokenInfoV0Accessors; - - // IdentityTokenInfo only contains frozen status - let is_frozen = match &info { - dash_sdk::dpp::tokens::info::IdentityTokenInfo::V0(v0) => v0.frozen(), - }; - - IdentityTokenInfoResponse { - identity_id: id_str, - is_frozen, - } - }) - }) - }) - .collect(); + let infos_map = Map::new(); + for identity in identities { + if let Some(Some(info)) = infos_result.get(&identity) { + let info_wasm = IdentityTokenInfoWasm::from(info.clone()); + let key = JsValue::from(IdentifierWasm::from(identity)); + let value = JsValue::from(info_wasm); + infos_map.set(&key, &value); + } + } - serde_wasm_bindgen::to_value(&responses).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(infos_map) } #[wasm_bindgen(js_name = "getTokenStatuses")] pub async fn get_token_statuses( &self, token_ids: Vec, - ) -> Result { + ) -> Result { use drive_proof_verifier::types::token_status::TokenStatuses; // Parse token IDs @@ -426,35 +397,23 @@ impl WasmSdk { let statuses_result: TokenStatuses = TokenStatus::fetch_many(self.as_ref(), tokens.clone()).await?; - // Convert to response format - let responses: Vec = token_ids - .into_iter() - .filter_map(|id_str| { - let id = Identifier::from_string( - &id_str, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .ok()?; - - statuses_result.get(&id).and_then(|status_opt| { - status_opt.as_ref().map(|status| TokenStatusResponse { - token_id: id_str, - is_paused: status.paused(), - }) - }) - }) - .collect(); + let statuses_map = Map::new(); + for token in tokens { + if let Some(Some(status)) = statuses_result.get(&token) { + let key = JsValue::from(IdentifierWasm::from(token)); + let value = JsValue::from(TokenStatusWasm::from(status.clone())); + statuses_map.set(&key, &value); + } + } - serde_wasm_bindgen::to_value(&responses).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(statuses_map) } #[wasm_bindgen(js_name = "getTokenDirectPurchasePrices")] pub async fn get_token_direct_purchase_prices( &self, token_ids: Vec, - ) -> Result { + ) -> Result { use drive_proof_verifier::types::TokenDirectPurchasePrices; // Parse token IDs @@ -475,53 +434,44 @@ impl WasmSdk { TokenPricingSchedule::fetch_many(self.as_ref(), &tokens[..]).await?; // Convert to response format - let responses: Vec = token_ids - .into_iter() - .filter_map(|id_str| { - let id = Identifier::from_string( - &id_str, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ).ok()?; - - prices_result.get(&id).and_then(|price_opt| { - price_opt.as_ref().map(|schedule| { - // Get prices based on the schedule type - let (base_price, current_price) = match &schedule { - dash_sdk::dpp::tokens::token_pricing_schedule::TokenPricingSchedule::SinglePrice(price) => { - (price.to_string(), price.to_string()) - }, - dash_sdk::dpp::tokens::token_pricing_schedule::TokenPricingSchedule::SetPrices(prices) => { - // Use first price as base, last as current - let base = prices.first_key_value() - .map(|(_, p)| p.to_string()) - .unwrap_or_else(|| "0".to_string()); - let current = prices.last_key_value() - .map(|(_, p)| p.to_string()) - .unwrap_or_else(|| "0".to_string()); - (base, current) - }, - }; + let prices_map = Map::new(); + for token in tokens { + if let Some(Some(schedule)) = prices_result.get(&token) { + let token_id_wasm = IdentifierWasm::from(token.clone()); + let (base_price, current_price) = match schedule { + dash_sdk::dpp::tokens::token_pricing_schedule::TokenPricingSchedule::SinglePrice(price) => { + (price.to_string(), price.to_string()) + } + dash_sdk::dpp::tokens::token_pricing_schedule::TokenPricingSchedule::SetPrices(prices) => { + let base = prices + .first_key_value() + .map(|(_, p)| p.to_string()) + .unwrap_or_else(|| "0".to_string()); + let current = prices + .last_key_value() + .map(|(_, p)| p.to_string()) + .unwrap_or_else(|| "0".to_string()); + (base, current) + } + }; - TokenPriceResponse { - token_id: id_str, - current_price, - base_price, - } - }) - }) - }) - .collect(); + let price_info = + TokenPriceInfoWasm::new(token_id_wasm, current_price, base_price); + + let key = JsValue::from(token_id_wasm); + let value = JsValue::from(price_info); + prices_map.set(&key, &value); + } + } - serde_wasm_bindgen::to_value(&responses).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(prices_map) } #[wasm_bindgen(js_name = "getTokenContractInfo")] pub async fn get_token_contract_info( &self, data_contract_id: &str, - ) -> Result { + ) -> Result, WasmSdkError> { use dash_sdk::dpp::tokens::contract_info::TokenContractInfo; use dash_sdk::platform::Fetch; @@ -535,30 +485,7 @@ impl WasmSdk { // Fetch token contract info let info_result = TokenContractInfo::fetch(self.as_ref(), contract_id).await?; - if let Some(info) = info_result { - use dash_sdk::dpp::tokens::contract_info::v0::TokenContractInfoV0Accessors; - - // Extract fields based on the enum variant - let (contract_id, position) = match &info { - dash_sdk::dpp::tokens::contract_info::TokenContractInfo::V0(v0) => { - (v0.contract_id(), v0.token_contract_position()) - } - }; - - let response = TokenContractInfoResponse { - contract_id: contract_id - .to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), - token_contract_position: position, - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } else { - Ok(JsValue::NULL) - } + Ok(info_result.map(TokenContractInfoWasm::from)) } #[wasm_bindgen(js_name = "getTokenPerpetualDistributionLastClaim")] @@ -566,7 +493,7 @@ impl WasmSdk { &self, identity_id: &str, token_id: &str, - ) -> Result { + ) -> Result, WasmSdkError> { // Parse IDs let identity_identifier = Identifier::from_string( identity_id, @@ -696,24 +623,16 @@ impl WasmSdk { } }; - if let Some((timestamp_ms, block_height)) = claim_result { - let response = LastClaimResponse { - last_claim_timestamp_ms: timestamp_ms, - last_claim_block_height: block_height, - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } else { - Ok(JsValue::NULL) - } + Ok(claim_result.map(|(timestamp_ms, block_height)| { + TokenLastClaimWasm::new(timestamp_ms, block_height) + })) } #[wasm_bindgen(js_name = "getTokenTotalSupply")] - pub async fn get_token_total_supply(&self, token_id: &str) -> Result { + pub async fn get_token_total_supply( + &self, + token_id: &str, + ) -> Result, WasmSdkError> { use dash_sdk::dpp::balances::total_single_token_balance::TotalSingleTokenBalance; use dash_sdk::platform::Fetch; @@ -727,19 +646,9 @@ impl WasmSdk { // Fetch total supply let supply_result = TotalSingleTokenBalance::fetch(self.as_ref(), token_identifier).await?; - if let Some(supply) = supply_result { - let response = TokenTotalSupplyResponse { - total_supply: supply.token_supply.to_string(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } else { - Ok(JsValue::NULL) - } + Ok(supply_result.map(|supply| { + TokenTotalSupplyWasm::new(supply.token_supply as u64) + })) } // Proof versions for token queries @@ -749,7 +658,7 @@ impl WasmSdk { &self, identity_ids: Vec, token_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::tokens::identity_token_balances::IdentitiesTokenBalancesQuery; // Parse token ID @@ -785,43 +694,25 @@ impl WasmSdk { _, ) = TokenAmount::fetch_many_with_metadata_and_proof(self.as_ref(), query, None).await?; - // Convert to response format - let responses: Vec = identity_ids - .into_iter() - .filter_map(|id_str| { - let id = Identifier::from_string( - &id_str, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .ok()?; - - balances_result.get(&id).and_then(|balance_opt| { - balance_opt.map(|balance| IdentityTokenBalanceResponse { - identity_id: id_str, - balance: balance.to_string(), - }) - }) - }) - .collect(); - - let response = ProofMetadataResponse { - data: responses, - metadata: metadata.into(), - proof: proof.into(), - }; + let balances_map = Map::new(); + for identifier in &identities { + if let Some(Some(balance)) = balances_result.get(identifier) { + let key = JsValue::from(IdentifierWasm::from((*identifier).clone())); + let value = JsValue::from(BigInt::from(*balance as u64)); + balances_map.set(&key, &value); + } + } - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + balances_map, metadata, proof, + )) } #[wasm_bindgen(js_name = "getTokenStatusesWithProofInfo")] pub async fn get_token_statuses_with_proof_info( &self, token_ids: Vec, - ) -> Result { + ) -> Result { // Parse token IDs let tokens: Result, _> = token_ids .iter() @@ -840,43 +731,27 @@ impl WasmSdk { TokenStatus::fetch_many_with_metadata_and_proof(self.as_ref(), tokens.clone(), None) .await?; - // Convert to response format - let responses: Vec = token_ids - .into_iter() - .filter_map(|id_str| { - let id = Identifier::from_string( - &id_str, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .ok()?; - - statuses_result.get(&id).and_then(|status_opt| { - status_opt.as_ref().map(|status| TokenStatusResponse { - token_id: id_str, - is_paused: status.paused(), - }) - }) - }) - .collect(); - - let response = ProofMetadataResponse { - data: responses, - metadata: metadata.into(), - proof: proof.into(), - }; + let statuses_map = Map::new(); + for token in tokens { + if let Some(Some(status)) = statuses_result.get(&token) { + let key = JsValue::from(IdentifierWasm::from(token)); + let value = JsValue::from(TokenStatusWasm::from(status.clone())); + statuses_map.set(&key, &value); + } + } - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + statuses_map, + metadata, + proof, + )) } #[wasm_bindgen(js_name = "getTokenTotalSupplyWithProofInfo")] pub async fn get_token_total_supply_with_proof_info( &self, token_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::dpp::balances::total_single_token_balance::TotalSingleTokenBalance; use dash_sdk::platform::Fetch; @@ -896,21 +771,13 @@ impl WasmSdk { ) .await?; - let data = supply_result.map(|supply| TokenTotalSupplyResponse { - total_supply: supply.token_supply.to_string(), - }); - - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; + let data = supply_result + .map(|supply| JsValue::from(TokenTotalSupplyWasm::new(supply.token_supply as u64))) + .unwrap_or(JsValue::NULL); - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + data, metadata, proof, + )) } // Additional proof info versions for remaining token queries @@ -920,7 +787,7 @@ impl WasmSdk { &self, identity_id: &str, token_ids: Vec, - ) -> Result { + ) -> Result { use dash_sdk::platform::tokens::token_info::IdentityTokenInfosQuery; use drive_proof_verifier::types::token_info::IdentityTokenInfos; @@ -955,45 +822,19 @@ impl WasmSdk { IdentityTokenInfo::fetch_many_with_metadata_and_proof(self.as_ref(), query, None) .await?; - // Convert to response format - let responses: Vec = token_ids - .into_iter() - .filter_map(|id_str| { - let id = Identifier::from_string( - &id_str, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .ok()?; - - infos_result.get(&id).and_then(|info_opt| { - info_opt.as_ref().map(|info| { - use dash_sdk::dpp::tokens::info::v0::IdentityTokenInfoV0Accessors; - - // IdentityTokenInfo only contains frozen status - let is_frozen = match &info { - dash_sdk::dpp::tokens::info::IdentityTokenInfo::V0(v0) => v0.frozen(), - }; - - TokenInfoResponse { - token_id: id_str, - is_frozen, - } - }) - }) - }) - .collect(); - - let response = ProofMetadataResponse { - data: responses, - metadata: metadata.into(), - proof: proof.into(), - }; + let infos_map = Map::new(); + for token in tokens { + if let Some(Some(info)) = infos_result.get(&token) { + let info_wasm = IdentityTokenInfoWasm::from(info.clone()); + let key = JsValue::from(IdentifierWasm::from(token)); + let value = JsValue::from(info_wasm); + infos_map.set(&key, &value); + } + } - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + infos_map, metadata, proof, + )) } #[wasm_bindgen(js_name = "getIdentitiesTokenInfosWithProofInfo")] @@ -1001,7 +842,7 @@ impl WasmSdk { &self, identity_ids: Vec, token_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::tokens::token_info::IdentitiesTokenInfosQuery; use drive_proof_verifier::types::token_info::IdentitiesTokenInfos; @@ -1036,52 +877,26 @@ impl WasmSdk { IdentityTokenInfo::fetch_many_with_metadata_and_proof(self.as_ref(), query, None) .await?; - // Convert to response format - let responses: Vec = identity_ids - .into_iter() - .filter_map(|id_str| { - let id = Identifier::from_string( - &id_str, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .ok()?; - - infos_result.get(&id).and_then(|info_opt| { - info_opt.as_ref().map(|info| { - use dash_sdk::dpp::tokens::info::v0::IdentityTokenInfoV0Accessors; - - // IdentityTokenInfo only contains frozen status - let is_frozen = match &info { - dash_sdk::dpp::tokens::info::IdentityTokenInfo::V0(v0) => v0.frozen(), - }; - - IdentityTokenInfoResponse { - identity_id: id_str, - is_frozen, - } - }) - }) - }) - .collect(); - - let response = ProofMetadataResponse { - data: responses, - metadata: metadata.into(), - proof: proof.into(), - }; + let infos_map = Map::new(); + for identity in identities { + if let Some(Some(info)) = infos_result.get(&identity) { + let info_wasm = IdentityTokenInfoWasm::from(info.clone()); + let key = JsValue::from(IdentifierWasm::from(identity)); + let value = JsValue::from(info_wasm); + infos_map.set(&key, &value); + } + } - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + infos_map, metadata, proof, + )) } #[wasm_bindgen(js_name = "getTokenDirectPurchasePricesWithProofInfo")] pub async fn get_token_direct_purchase_prices_with_proof_info( &self, token_ids: Vec, - ) -> Result { + ) -> Result { use drive_proof_verifier::types::TokenDirectPurchasePrices; // Parse token IDs @@ -1106,62 +921,48 @@ impl WasmSdk { ) .await?; - // Convert to response format - let responses: Vec = token_ids - .into_iter() - .filter_map(|id_str| { - let id = Identifier::from_string( - &id_str, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ).ok()?; - - prices_result.get(&id).and_then(|price_opt| { - price_opt.as_ref().map(|schedule| { - // Get prices based on the schedule type - let (base_price, current_price) = match &schedule { - dash_sdk::dpp::tokens::token_pricing_schedule::TokenPricingSchedule::SinglePrice(price) => { - (price.to_string(), price.to_string()) - }, - dash_sdk::dpp::tokens::token_pricing_schedule::TokenPricingSchedule::SetPrices(prices) => { - // Use first price as base, last as current - let base = prices.first_key_value() - .map(|(_, p)| p.to_string()) - .unwrap_or_else(|| "0".to_string()); - let current = prices.last_key_value() - .map(|(_, p)| p.to_string()) - .unwrap_or_else(|| "0".to_string()); - (base, current) - }, - }; + let prices_map = Map::new(); + for token in tokens { + if let Some(Some(schedule)) = prices_result.get(&token) { + let token_id_wasm = IdentifierWasm::from(token.clone()); + let (base_price, current_price) = match schedule { + dash_sdk::dpp::tokens::token_pricing_schedule::TokenPricingSchedule::SinglePrice(price) => { + (price.to_string(), price.to_string()) + } + dash_sdk::dpp::tokens::token_pricing_schedule::TokenPricingSchedule::SetPrices(prices) => { + let base = prices + .first_key_value() + .map(|(_, p)| p.to_string()) + .unwrap_or_else(|| "0".to_string()); + let current = prices + .last_key_value() + .map(|(_, p)| p.to_string()) + .unwrap_or_else(|| "0".to_string()); + (base, current) + } + }; - TokenPriceResponse { - token_id: id_str, - current_price, - base_price, - } - }) - }) - }) - .collect(); + let price_info = + TokenPriceInfoWasm::new(token_id_wasm, current_price, base_price); - let response = ProofMetadataResponse { - data: responses, - metadata: metadata.into(), - proof: proof.into(), - }; + let key = JsValue::from(token_id_wasm); + let value = JsValue::from(price_info); + prices_map.set(&key, &value); + } + } - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + prices_map, + metadata, + proof, + )) } #[wasm_bindgen(js_name = "getTokenContractInfoWithProofInfo")] pub async fn get_token_contract_info_with_proof_info( &self, data_contract_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::dpp::tokens::contract_info::TokenContractInfo; use dash_sdk::platform::Fetch; @@ -1177,36 +978,13 @@ impl WasmSdk { TokenContractInfo::fetch_with_metadata_and_proof(self.as_ref(), contract_id, None) .await?; - let data = if let Some(info) = info_result { - use dash_sdk::dpp::tokens::contract_info::v0::TokenContractInfoV0Accessors; - - // Extract fields based on the enum variant - let (contract_id, position) = match &info { - dash_sdk::dpp::tokens::contract_info::TokenContractInfo::V0(v0) => { - (v0.contract_id(), v0.token_contract_position()) - } - }; + let data = info_result + .map(|info| JsValue::from(TokenContractInfoWasm::from(info))) + .unwrap_or(JsValue::UNDEFINED); - Some(TokenContractInfoResponse { - contract_id: contract_id - .to_string(dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58), - token_contract_position: position, - }) - } else { - None - }; - - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + data, metadata, proof, + )) } #[wasm_bindgen(js_name = "getTokenPerpetualDistributionLastClaimWithProofInfo")] @@ -1214,7 +992,7 @@ impl WasmSdk { &self, identity_id: &str, token_id: &str, - ) -> Result { + ) -> Result { use dash_sdk::platform::query::TokenLastClaimQuery; use dash_sdk::dpp::data_contract::associated_token::token_perpetual_distribution::reward_distribution_moment::RewardDistributionMoment; use dash_sdk::platform::Fetch; @@ -1259,24 +1037,18 @@ impl WasmSdk { }, }; - Some(LastClaimResponse { + Some(TokenLastClaimWasm::new( last_claim_timestamp_ms, last_claim_block_height, - }) + )) } else { None }; - let response = ProofMetadataResponse { - data, - metadata: metadata.into(), - proof: proof.into(), - }; + let data = data.map(JsValue::from).unwrap_or(JsValue::UNDEFINED); - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + data, metadata, proof, + )) } } From e9f6f2eefcdf8c59bfd9189b6b5890f4a4ce7b1b Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Wed, 15 Oct 2025 10:00:04 +0700 Subject: [PATCH 24/44] refactor: add typing to vote queries --- packages/js-evo-sdk/src/voting/facade.ts | 68 +- .../tests/unit/facades/voting.spec.mjs | 14 +- packages/rs-drive-proof-verifier/src/types.rs | 1 + packages/wasm-dpp2/src/block.rs | 26 + .../governance/masternode_vote/mod.rs | 6 - .../wasm-dpp2/src/identity/governance/mod.rs | 6 - packages/wasm-dpp2/src/identity/mod.rs | 5 +- .../masternode_vote_transition.rs | 2 +- .../wasm-dpp2/src/identity/transitions/mod.rs | 1 + packages/wasm-dpp2/src/lib.rs | 28 +- .../wasm-dpp2/src/tokens/contract_info.rs | 2 +- packages/wasm-dpp2/src/tokens/info.rs | 2 +- packages/wasm-dpp2/src/tokens/status.rs | 2 +- packages/wasm-dpp2/src/utils.rs | 12 + packages/wasm-dpp2/src/voting/mod.rs | 11 + .../resource_vote_choice.rs | 0 .../masternode_vote => voting}/vote.rs | 4 +- .../masternode_vote => voting}/vote_poll.rs | 0 packages/wasm-sdk/src/dpns.rs | 18 +- packages/wasm-sdk/src/lib.rs | 1 + .../wasm-sdk/src/queries/data_contract.rs | 2 - packages/wasm-sdk/src/queries/mod.rs | 104 +- packages/wasm-sdk/src/queries/token.rs | 29 +- packages/wasm-sdk/src/queries/voting.rs | 981 ------------------ packages/wasm-sdk/src/queries/voting/mod.rs | 5 + packages/wasm-sdk/src/queries/voting/polls.rs | 374 +++++++ .../wasm-sdk/src/queries/voting/resources.rs | 202 ++++ packages/wasm-sdk/src/queries/voting/state.rs | 357 +++++++ .../wasm-sdk/src/queries/voting/voters.rs | 192 ++++ packages/wasm-sdk/src/queries/voting/votes.rs | 235 +++++ 30 files changed, 1530 insertions(+), 1160 deletions(-) create mode 100644 packages/wasm-dpp2/src/block.rs delete mode 100644 packages/wasm-dpp2/src/identity/governance/masternode_vote/mod.rs delete mode 100644 packages/wasm-dpp2/src/identity/governance/mod.rs rename packages/wasm-dpp2/src/identity/{governance/masternode_vote => transitions}/masternode_vote_transition.rs (99%) create mode 100644 packages/wasm-dpp2/src/voting/mod.rs rename packages/wasm-dpp2/src/{identity/governance/masternode_vote => voting}/resource_vote_choice.rs (100%) rename packages/wasm-dpp2/src/{identity/governance/masternode_vote => voting}/vote.rs (93%) rename packages/wasm-dpp2/src/{identity/governance/masternode_vote => voting}/vote_poll.rs (100%) delete mode 100644 packages/wasm-sdk/src/queries/voting.rs create mode 100644 packages/wasm-sdk/src/queries/voting/mod.rs create mode 100644 packages/wasm-sdk/src/queries/voting/polls.rs create mode 100644 packages/wasm-sdk/src/queries/voting/resources.rs create mode 100644 packages/wasm-sdk/src/queries/voting/state.rs create mode 100644 packages/wasm-sdk/src/queries/voting/voters.rs create mode 100644 packages/wasm-sdk/src/queries/voting/votes.rs diff --git a/packages/js-evo-sdk/src/voting/facade.ts b/packages/js-evo-sdk/src/voting/facade.ts index dcc9e615a8e..9f2b12a6dee 100644 --- a/packages/js-evo-sdk/src/voting/facade.ts +++ b/packages/js-evo-sdk/src/voting/facade.ts @@ -29,18 +29,74 @@ export class VotingFacade { return w.getContestedResourceIdentityVotesWithProofInfo(identityId, limit ?? null, offset ?? null, orderAscending ?? null); } - async votePollsByEndDate(opts: { startTimeInfo?: string; endTimeInfo?: string; limit?: number; orderAscending?: boolean } = {}): Promise { - const { startTimeInfo, endTimeInfo, limit, orderAscending } = opts; + async votePollsByEndDate(opts: { startTimeMs?: number | string | bigint | null; startTimeIncluded?: boolean; endTimeMs?: number | string | bigint | null; endTimeIncluded?: boolean; limit?: number; offset?: number; orderAscending?: boolean } = {}): Promise { + const { startTimeMs, startTimeIncluded, endTimeMs, endTimeIncluded, limit, offset, orderAscending } = opts; const w = await this.sdk.getWasmSdkConnected(); - return w.getVotePollsByEndDate(startTimeInfo ?? null, endTimeInfo ?? null, limit ?? null, orderAscending ?? null); + + const normalizeTime = (value?: number | string | bigint | null) => { + if (value === null || value === undefined) { + return undefined; + } + + if (typeof value === 'number') { + return Number.isFinite(value) ? value : undefined; + } + + if (typeof value === 'bigint') { + return Number(value); + } + + const trimmed = value.trim(); + if (!trimmed) { + return undefined; + } + + const parsed = Number(trimmed); + return Number.isFinite(parsed) ? parsed : undefined; + }; + + const options: Record = {}; + const start = normalizeTime(startTimeMs); + if (start !== undefined) options.startTimeMs = start; + if (startTimeIncluded !== undefined) options.startTimeIncluded = startTimeIncluded; + + const end = normalizeTime(endTimeMs); + if (end !== undefined) options.endTimeMs = end; + if (endTimeIncluded !== undefined) options.endTimeIncluded = endTimeIncluded; + + if (limit !== undefined) options.limit = limit; + if (offset !== undefined) options.offset = offset; + if (orderAscending !== undefined) options.orderAscending = orderAscending; + + return w.getVotePollsByEndDate(options); } async votePollsByEndDateWithProof(opts: { startTimeMs?: number | bigint | null; endTimeMs?: number | bigint | null; limit?: number; offset?: number; orderAscending?: boolean } = {}): Promise { const { startTimeMs, endTimeMs, limit, offset, orderAscending } = opts; - const start = startTimeMs != null ? BigInt(startTimeMs) : null; - const end = endTimeMs != null ? BigInt(endTimeMs) : null; const w = await this.sdk.getWasmSdkConnected(); - return w.getVotePollsByEndDateWithProofInfo(start ?? null, end ?? null, limit ?? null, offset ?? null, orderAscending ?? null); + + const normalizeTime = (value?: number | bigint | null) => { + if (value === null || value === undefined) { + return undefined; + } + + if (typeof value === 'number') { + return Number.isFinite(value) ? value : undefined; + } + + return Number(value); + }; + + const options: Record = {}; + const start = normalizeTime(startTimeMs); + if (start !== undefined) options.startTimeMs = start; + const end = normalizeTime(endTimeMs); + if (end !== undefined) options.endTimeMs = end; + if (limit !== undefined) options.limit = limit; + if (offset !== undefined) options.offset = offset; + if (orderAscending !== undefined) options.orderAscending = orderAscending; + + return w.getVotePollsByEndDateWithProofInfo(options); } async masternodeVote(args: { masternodeProTxHash: string; contractId: string; documentTypeName: string; indexName: string; indexValues: string | any[]; voteChoice: string; votingKeyWif: string }): Promise { diff --git a/packages/js-evo-sdk/tests/unit/facades/voting.spec.mjs b/packages/js-evo-sdk/tests/unit/facades/voting.spec.mjs index e0d7af74e55..796b191fdf8 100644 --- a/packages/js-evo-sdk/tests/unit/facades/voting.spec.mjs +++ b/packages/js-evo-sdk/tests/unit/facades/voting.spec.mjs @@ -30,10 +30,20 @@ describe('VotingFacade', () => { await client.voting.contestedResourceIdentityVotes('id', { limit: 3, startAtVotePollIdInfo: 's', orderAscending: true }); await client.voting.contestedResourceIdentityVotesWithProof('id', { limit: 4, offset: 1, orderAscending: false }); await client.voting.votePollsByEndDate({ - startTimeInfo: 'a', endTimeInfo: 'b', limit: 2, orderAscending: true, + startTimeMs: 1000, + startTimeIncluded: true, + endTimeMs: 2000, + endTimeIncluded: false, + limit: 2, + offset: 1, + orderAscending: true, }); await client.voting.votePollsByEndDateWithProof({ - startTimeMs: 10, endTimeMs: 20, limit: 1, offset: 0, orderAscending: false, + startTimeMs: 10, + endTimeMs: 20, + limit: 1, + offset: 0, + orderAscending: false, }); expect(wasmSdk.getContestedResourceVoteState).to.be.calledOnce(); expect(wasmSdk.getContestedResourceVoteStateWithProofInfo).to.be.calledOnce(); diff --git a/packages/rs-drive-proof-verifier/src/types.rs b/packages/rs-drive-proof-verifier/src/types.rs index 4938ae2ad47..8ea63626acc 100644 --- a/packages/rs-drive-proof-verifier/src/types.rs +++ b/packages/rs-drive-proof-verifier/src/types.rs @@ -52,6 +52,7 @@ pub use indexmap::IndexMap; use std::collections::{BTreeMap, BTreeSet}; use dpp::dashcore::hashes::Hash; +use drive::query::vote_poll_contestant_votes_query::ContestedDocumentVotePollVotesDriveQuery; #[cfg(feature = "mocks")] use { bincode::{Decode, Encode}, diff --git a/packages/wasm-dpp2/src/block.rs b/packages/wasm-dpp2/src/block.rs new file mode 100644 index 00000000000..a9606596ff4 --- /dev/null +++ b/packages/wasm-dpp2/src/block.rs @@ -0,0 +1,26 @@ +use dpp::block::block_info::BlockInfo; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen(js_name = "BlockInfo")] +#[derive(Clone)] +pub struct BlockInfoWasm { + #[wasm_bindgen(getter = "timeMs")] + pub time_ms: u64, + #[wasm_bindgen(getter)] + pub height: u64, + #[wasm_bindgen(getter = "coreHeight")] + pub core_height: u64, + #[wasm_bindgen(getter = "epochIndex")] + pub epoch_index: u16, +} + +impl From for BlockInfoWasm { + fn from(block: BlockInfo) -> Self { + Self { + time_ms: block.time_ms, + height: block.height as u64, + core_height: block.core_height as u64, + epoch_index: block.epoch.index, + } + } +} diff --git a/packages/wasm-dpp2/src/identity/governance/masternode_vote/mod.rs b/packages/wasm-dpp2/src/identity/governance/masternode_vote/mod.rs deleted file mode 100644 index 53e3c4f1926..00000000000 --- a/packages/wasm-dpp2/src/identity/governance/masternode_vote/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -mod masternode_vote_transition; -pub mod resource_vote_choice; -pub mod vote; -pub mod vote_poll; - -pub use masternode_vote_transition::MasternodeVoteTransitionWasm; diff --git a/packages/wasm-dpp2/src/identity/governance/mod.rs b/packages/wasm-dpp2/src/identity/governance/mod.rs deleted file mode 100644 index 391735c6b93..00000000000 --- a/packages/wasm-dpp2/src/identity/governance/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod masternode_vote; - -pub use masternode_vote::MasternodeVoteTransitionWasm; -pub use masternode_vote::resource_vote_choice::ResourceVoteChoiceWasm; -pub use masternode_vote::vote::VoteWasm; -pub use masternode_vote::vote_poll::VotePollWasm; diff --git a/packages/wasm-dpp2/src/identity/mod.rs b/packages/wasm-dpp2/src/identity/mod.rs index 80974248901..4f32fef888a 100644 --- a/packages/wasm-dpp2/src/identity/mod.rs +++ b/packages/wasm-dpp2/src/identity/mod.rs @@ -1,18 +1,15 @@ -pub mod governance; pub mod model; pub mod partial_identity; pub mod public_key; pub mod transitions; -pub use governance::{ - MasternodeVoteTransitionWasm, ResourceVoteChoiceWasm, VotePollWasm, VoteWasm, -}; pub use model::IdentityWasm; pub use partial_identity::PartialIdentityWasm; pub use public_key::IdentityPublicKeyWasm; pub use transitions::create_transition::IdentityCreateTransitionWasm; pub use transitions::credit_withdrawal_transition::IdentityCreditWithdrawalTransitionWasm; pub use transitions::identity_credit_transfer_transition::IdentityCreditTransferWasm; +pub use transitions::masternode_vote_transition::MasternodeVoteTransitionWasm; pub use transitions::public_key_in_creation::IdentityPublicKeyInCreationWasm; pub use transitions::top_up_transition::IdentityTopUpTransitionWasm; pub use transitions::update_transition::IdentityUpdateTransitionWasm; diff --git a/packages/wasm-dpp2/src/identity/governance/masternode_vote/masternode_vote_transition.rs b/packages/wasm-dpp2/src/identity/transitions/masternode_vote_transition.rs similarity index 99% rename from packages/wasm-dpp2/src/identity/governance/masternode_vote/masternode_vote_transition.rs rename to packages/wasm-dpp2/src/identity/transitions/masternode_vote_transition.rs index 4b0da1907d6..5ae9c503c2b 100644 --- a/packages/wasm-dpp2/src/identity/governance/masternode_vote/masternode_vote_transition.rs +++ b/packages/wasm-dpp2/src/identity/transitions/masternode_vote_transition.rs @@ -1,7 +1,7 @@ +use crate::VoteWasm; use crate::asset_lock_proof::AssetLockProofWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::identifier::IdentifierWasm; -use crate::identity::governance::masternode_vote::vote::VoteWasm; use crate::state_transitions::StateTransitionWasm; use dpp::identity::KeyID; use dpp::identity::state_transition::OptionallyAssetLockProved; diff --git a/packages/wasm-dpp2/src/identity/transitions/mod.rs b/packages/wasm-dpp2/src/identity/transitions/mod.rs index 5e1c857d817..a7119f74ccf 100644 --- a/packages/wasm-dpp2/src/identity/transitions/mod.rs +++ b/packages/wasm-dpp2/src/identity/transitions/mod.rs @@ -1,6 +1,7 @@ pub mod create_transition; pub mod credit_withdrawal_transition; pub mod identity_credit_transfer_transition; +pub mod masternode_vote_transition; pub mod public_key_in_creation; pub mod top_up_transition; pub mod update_transition; diff --git a/packages/wasm-dpp2/src/lib.rs b/packages/wasm-dpp2/src/lib.rs index ec2b0eb42f2..e807a504d39 100644 --- a/packages/wasm-dpp2/src/lib.rs +++ b/packages/wasm-dpp2/src/lib.rs @@ -10,6 +10,7 @@ // }; pub mod asset_lock_proof; +pub mod block; pub mod consensus_error; pub mod core_script; pub mod data_contract; @@ -25,24 +26,15 @@ pub mod public_key; pub mod state_transitions; pub mod tokens; pub mod utils; +pub mod voting; -pub use data_contract::{ - ContractBoundsWasm, DataContractCreateTransitionWasm, DataContractUpdateTransitionWasm, - DataContractWasm, DocumentWasm, -}; -pub use epoch::{ExtendedEpochInfoWasm, FinalizedEpochInfoWasm}; -pub use group::{GroupActionEventWasm, GroupActionWasm, TokenEventWasm}; - -pub use identity::{ - IdentityCreateTransitionWasm, IdentityCreditTransferWasm, - IdentityCreditWithdrawalTransitionWasm, IdentityPublicKeyInCreationWasm, IdentityPublicKeyWasm, - IdentityTopUpTransitionWasm, IdentityUpdateTransitionWasm, MasternodeVoteTransitionWasm, - PartialIdentityWasm, ResourceVoteChoiceWasm, VotePollWasm, VoteWasm, -}; - +pub use data_contract::*; +pub use epoch::*; +pub use group::*; +pub use identity::*; pub use state_transitions::base::{GroupStateTransitionInfoWasm, StateTransitionWasm}; - -pub use tokens::{ - AuthorizedActionTakersWasm, GroupWasm, PrivateEncryptedNoteWasm, SharedEncryptedNoteWasm, - TokenConfigurationChangeItemWasm, TokenConfigurationLocalizationWasm, TokenConfigurationWasm, +pub use tokens::*; +pub use voting::{ + ContenderWithSerializedDocumentWasm, ContestedDocumentVotePollWinnerInfoWasm, + ResourceVoteChoiceWasm, VotePollWasm, VoteWasm, }; diff --git a/packages/wasm-dpp2/src/tokens/contract_info.rs b/packages/wasm-dpp2/src/tokens/contract_info.rs index ed1db08f2f5..3053b3a073a 100644 --- a/packages/wasm-dpp2/src/tokens/contract_info.rs +++ b/packages/wasm-dpp2/src/tokens/contract_info.rs @@ -1,7 +1,7 @@ use crate::identifier::IdentifierWasm; use dpp::data_contract::TokenContractPosition; -use dpp::tokens::contract_info::v0::TokenContractInfoV0Accessors; use dpp::tokens::contract_info::TokenContractInfo; +use dpp::tokens::contract_info::v0::TokenContractInfoV0Accessors; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "TokenContractInfo")] diff --git a/packages/wasm-dpp2/src/tokens/info.rs b/packages/wasm-dpp2/src/tokens/info.rs index 6be57016aae..b6365408772 100644 --- a/packages/wasm-dpp2/src/tokens/info.rs +++ b/packages/wasm-dpp2/src/tokens/info.rs @@ -1,5 +1,5 @@ -use dpp::tokens::info::v0::IdentityTokenInfoV0Accessors; use dpp::tokens::info::IdentityTokenInfo; +use dpp::tokens::info::v0::IdentityTokenInfoV0Accessors; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "IdentityTokenInfo")] diff --git a/packages/wasm-dpp2/src/tokens/status.rs b/packages/wasm-dpp2/src/tokens/status.rs index 77398f6656f..d63f4bee074 100644 --- a/packages/wasm-dpp2/src/tokens/status.rs +++ b/packages/wasm-dpp2/src/tokens/status.rs @@ -1,5 +1,5 @@ -use dpp::tokens::status::v0::TokenStatusV0Accessors; use dpp::tokens::status::TokenStatus; +use dpp::tokens::status::v0::TokenStatusV0Accessors; use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "TokenStatus")] diff --git a/packages/wasm-dpp2/src/utils.rs b/packages/wasm-dpp2/src/utils.rs index eb93cbda01e..146a6deb052 100644 --- a/packages/wasm-dpp2/src/utils.rs +++ b/packages/wasm-dpp2/src/utils.rs @@ -261,6 +261,18 @@ pub fn generate_document_id_v0( .map_err(|err| WasmDppError::invalid_argument(err.to_string())) } +// TODO: Refactor, code bellow + +// if let Ok(obj) = input.dyn_into::() { +// // received wasm object +// web_sys::console::log_1(&format!("MyClass: {}", obj.value()).into()); +// } else if let Some(s) = input.as_string() { +// // received string +// web_sys::console::log_1(&format!("String: {}", s).into()); +// } else { +// web_sys::console::error_1(&"Expected string | MyClass".into()); +// } + // Try to extract Identifier from **stringified** identifier_utils. // The `js_value` can be a stringified instance of: `Identifier`, `Buffer` or `Array` pub fn identifier_from_js_value(js_value: &JsValue) -> WasmDppResult { diff --git a/packages/wasm-dpp2/src/voting/mod.rs b/packages/wasm-dpp2/src/voting/mod.rs new file mode 100644 index 00000000000..f872805d4d0 --- /dev/null +++ b/packages/wasm-dpp2/src/voting/mod.rs @@ -0,0 +1,11 @@ +pub mod contender; +pub mod resource_vote_choice; +pub mod vote; +pub mod vote_poll; +pub mod winner_info; + +pub use contender::ContenderWithSerializedDocumentWasm; +pub use resource_vote_choice::ResourceVoteChoiceWasm; +pub use vote::VoteWasm; +pub use vote_poll::VotePollWasm; +pub use winner_info::ContestedDocumentVotePollWinnerInfoWasm; diff --git a/packages/wasm-dpp2/src/identity/governance/masternode_vote/resource_vote_choice.rs b/packages/wasm-dpp2/src/voting/resource_vote_choice.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/governance/masternode_vote/resource_vote_choice.rs rename to packages/wasm-dpp2/src/voting/resource_vote_choice.rs diff --git a/packages/wasm-dpp2/src/identity/governance/masternode_vote/vote.rs b/packages/wasm-dpp2/src/voting/vote.rs similarity index 93% rename from packages/wasm-dpp2/src/identity/governance/masternode_vote/vote.rs rename to packages/wasm-dpp2/src/voting/vote.rs index 8e793102f31..c5b288c97ef 100644 --- a/packages/wasm-dpp2/src/identity/governance/masternode_vote/vote.rs +++ b/packages/wasm-dpp2/src/voting/vote.rs @@ -1,5 +1,5 @@ -use crate::identity::governance::masternode_vote::resource_vote_choice::ResourceVoteChoiceWasm; -use crate::identity::governance::masternode_vote::vote_poll::VotePollWasm; +use crate::voting::resource_vote_choice::ResourceVoteChoiceWasm; +use crate::voting::vote_poll::VotePollWasm; use dpp::voting::votes::Vote; use dpp::voting::votes::resource_vote::ResourceVote; use dpp::voting::votes::resource_vote::accessors::v0::ResourceVoteGettersV0; diff --git a/packages/wasm-dpp2/src/identity/governance/masternode_vote/vote_poll.rs b/packages/wasm-dpp2/src/voting/vote_poll.rs similarity index 100% rename from packages/wasm-dpp2/src/identity/governance/masternode_vote/vote_poll.rs rename to packages/wasm-dpp2/src/voting/vote_poll.rs diff --git a/packages/wasm-sdk/src/dpns.rs b/packages/wasm-sdk/src/dpns.rs index dc98f46a90f..5e542309cab 100644 --- a/packages/wasm-sdk/src/dpns.rs +++ b/packages/wasm-sdk/src/dpns.rs @@ -1,5 +1,5 @@ use crate::error::WasmSdkError; -use crate::queries::{ProofInfoWasm, ProofMetadataResponse, ResponseMetadataWasm}; +use crate::queries::{ProofInfoWasm, ProofMetadataResponseWasm, ResponseMetadataWasm}; use crate::sdk::WasmSdk; use dash_sdk::dpp::document::{Document, DocumentV0Getters}; use dash_sdk::dpp::identity::accessors::IdentityGettersV0; @@ -287,16 +287,14 @@ impl WasmSdk { document_id: document.id().to_string(Encoding::Base58), }; - let response = ProofMetadataResponse { - data: result, - metadata: metadata.into(), - proof: proof.into(), - }; + let data = serde_wasm_bindgen::to_value(&result).map_err(|e| { + WasmSdkError::serialization(format!("Failed to serialize username info: {}", e)) + })?; - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) + let response = + ProofMetadataResponseWasm::from_parts(data, metadata.into(), proof.into()); + + Ok(JsValue::from(response)) } else { Err(WasmSdkError::not_found(format!( "Username '{}' not found", diff --git a/packages/wasm-sdk/src/lib.rs b/packages/wasm-sdk/src/lib.rs index e34c2116360..92a3edb0b06 100644 --- a/packages/wasm-sdk/src/lib.rs +++ b/packages/wasm-sdk/src/lib.rs @@ -7,6 +7,7 @@ pub mod logging; pub mod queries; pub mod sdk; pub mod state_transitions; +pub mod utils; pub mod wallet; // Re-export commonly used items diff --git a/packages/wasm-sdk/src/queries/data_contract.rs b/packages/wasm-sdk/src/queries/data_contract.rs index e84a74093bb..10cf1a94b54 100644 --- a/packages/wasm-sdk/src/queries/data_contract.rs +++ b/packages/wasm-sdk/src/queries/data_contract.rs @@ -92,7 +92,6 @@ impl WasmSdk { &self, id: &str, limit: Option, - _offset: Option, start_at_ms: Option, ) -> Result { // Parse contract ID @@ -165,7 +164,6 @@ impl WasmSdk { &self, id: &str, limit: Option, - _offset: Option, start_at_ms: Option, ) -> Result { // Parse contract ID diff --git a/packages/wasm-sdk/src/queries/mod.rs b/packages/wasm-sdk/src/queries/mod.rs index fb252f80224..a63cbe4a1eb 100644 --- a/packages/wasm-sdk/src/queries/mod.rs +++ b/packages/wasm-sdk/src/queries/mod.rs @@ -11,71 +11,10 @@ pub mod voting; // Re-export all query functions for easy access pub use group::*; -use crate::WasmSdkError; -use js_sys::{Object, Uint8Array}; -use serde::{Deserialize, Serialize}; +use js_sys::Uint8Array; use wasm_bindgen::prelude::*; use wasm_bindgen::JsValue; -// Legacy JSON-friendly response structures kept for compatibility with existing code paths -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct ProofMetadataResponse { - pub data: T, - pub metadata: ResponseMetadata, - pub proof: ProofInfo, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct ResponseMetadata { - pub height: u64, - pub core_chain_locked_height: u32, - pub epoch: u32, - pub time_ms: u64, - pub protocol_version: u32, - pub chain_id: String, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct ProofInfo { - pub grovedb_proof: String, - pub quorum_hash: String, - pub signature: String, - pub round: u32, - pub block_id_hash: String, - pub quorum_type: u32, -} - -impl From for ResponseMetadata { - fn from(metadata: dash_sdk::platform::proto::ResponseMetadata) -> Self { - ResponseMetadata { - height: metadata.height, - core_chain_locked_height: metadata.core_chain_locked_height, - epoch: metadata.epoch, - time_ms: metadata.time_ms, - protocol_version: metadata.protocol_version, - chain_id: metadata.chain_id, - } - } -} - -impl From for ProofInfo { - fn from(proof: dash_sdk::platform::proto::Proof) -> Self { - use base64::{engine::general_purpose, Engine as _}; - - ProofInfo { - grovedb_proof: general_purpose::STANDARD.encode(&proof.grovedb_proof), - quorum_hash: hex::encode(&proof.quorum_hash), - signature: general_purpose::STANDARD.encode(&proof.signature), - round: proof.round, - block_id_hash: hex::encode(&proof.block_id_hash), - quorum_type: proof.quorum_type, - } - } -} - #[wasm_bindgen(js_name = "ResponseMetadata")] #[derive(Clone, Debug)] pub struct ResponseMetadataWasm { @@ -334,44 +273,3 @@ impl ProofMetadataResponseWasm { (self.data, self.metadata, self.proof) } } - -pub(crate) fn proof_response_from_js_value( - data: JsValue, - metadata: ResponseMetadata, - proof: ProofInfo, -) -> Result { - let metadata_js = serialize_to_js(&metadata)?; - let proof_js = serialize_to_js(&proof)?; - - let response = Object::new(); - set_property(&response, "data", &data)?; - set_property(&response, "metadata", &metadata_js)?; - set_property(&response, "proof", &proof_js)?; - - Ok(response.into()) -} - -pub(crate) fn proof_response_from_serializable( - data: T, - metadata: ResponseMetadata, - proof: ProofInfo, -) -> Result { - proof_response_from_js_value(serialize_to_js(&data)?, metadata, proof) -} - -fn serialize_to_js(value: &T) -> Result { - serde_wasm_bindgen::to_value(value).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response component: {}", e)) - }) -} - -fn set_property(object: &Object, key: &str, value: &JsValue) -> Result<(), WasmSdkError> { - js_sys::Reflect::set(object, &JsValue::from_str(key), value).map_err(|err| { - WasmSdkError::serialization(format!( - "Failed to set '{}' on proof response: {:?}", - key, err - )) - })?; - - Ok(()) -} diff --git a/packages/wasm-sdk/src/queries/token.rs b/packages/wasm-sdk/src/queries/token.rs index 2133aec3631..af28a7492a2 100644 --- a/packages/wasm-sdk/src/queries/token.rs +++ b/packages/wasm-sdk/src/queries/token.rs @@ -203,7 +203,11 @@ impl WasmSdk { }, }; - Ok(TokenPriceInfoWasm::new(token_identifier_wasm, current_price, base_price)) + Ok(TokenPriceInfoWasm::new( + token_identifier_wasm, + current_price, + base_price, + )) } else { Err(WasmSdkError::not_found(format!( "No pricing schedule found for token at contract {} position {}", @@ -374,10 +378,7 @@ impl WasmSdk { } #[wasm_bindgen(js_name = "getTokenStatuses")] - pub async fn get_token_statuses( - &self, - token_ids: Vec, - ) -> Result { + pub async fn get_token_statuses(&self, token_ids: Vec) -> Result { use drive_proof_verifier::types::token_status::TokenStatuses; // Parse token IDs @@ -455,8 +456,7 @@ impl WasmSdk { } }; - let price_info = - TokenPriceInfoWasm::new(token_id_wasm, current_price, base_price); + let price_info = TokenPriceInfoWasm::new(token_id_wasm, current_price, base_price); let key = JsValue::from(token_id_wasm); let value = JsValue::from(price_info); @@ -646,9 +646,7 @@ impl WasmSdk { // Fetch total supply let supply_result = TotalSingleTokenBalance::fetch(self.as_ref(), token_identifier).await?; - Ok(supply_result.map(|supply| { - TokenTotalSupplyWasm::new(supply.token_supply as u64) - })) + Ok(supply_result.map(|supply| TokenTotalSupplyWasm::new(supply.token_supply as u64))) } // Proof versions for token queries @@ -704,7 +702,9 @@ impl WasmSdk { } Ok(ProofMetadataResponseWasm::from_sdk_parts( - balances_map, metadata, proof, + balances_map, + metadata, + proof, )) } @@ -942,8 +942,7 @@ impl WasmSdk { } }; - let price_info = - TokenPriceInfoWasm::new(token_id_wasm, current_price, base_price); + let price_info = TokenPriceInfoWasm::new(token_id_wasm, current_price, base_price); let key = JsValue::from(token_id_wasm); let value = JsValue::from(price_info); @@ -952,9 +951,7 @@ impl WasmSdk { } Ok(ProofMetadataResponseWasm::from_sdk_parts( - prices_map, - metadata, - proof, + prices_map, metadata, proof, )) } diff --git a/packages/wasm-sdk/src/queries/voting.rs b/packages/wasm-sdk/src/queries/voting.rs deleted file mode 100644 index 229b147d175..00000000000 --- a/packages/wasm-sdk/src/queries/voting.rs +++ /dev/null @@ -1,981 +0,0 @@ -use crate::error::WasmSdkError; -use crate::sdk::WasmSdk; -use dapi_grpc::platform::v0::{ - get_contested_resource_identity_votes_request::{ - self, GetContestedResourceIdentityVotesRequestV0, - }, - get_contested_resource_vote_state_request::{self, GetContestedResourceVoteStateRequestV0}, - get_contested_resource_voters_for_identity_request::{ - self, GetContestedResourceVotersForIdentityRequestV0, - }, - get_contested_resources_request::{self, GetContestedResourcesRequestV0}, - get_vote_polls_by_end_date_request::{self, GetVotePollsByEndDateRequestV0}, - GetContestedResourceIdentityVotesRequest, GetContestedResourceVoteStateRequest, - GetContestedResourceVotersForIdentityRequest, GetContestedResourcesRequest, - GetVotePollsByEndDateRequest, -}; -use dapi_grpc::platform::VersionedGrpcResponse; -use dash_sdk::dpp::platform_value::Value; -use dash_sdk::platform::Identifier; -use dash_sdk::RequestSettings; -use rs_dapi_client::DapiRequestExecutor; -use serde::Serialize; -use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::JsValue; - -// Standard bincode configuration used by Platform -use dash_sdk::dpp::bincode; -const BINCODE_CONFIG: bincode::config::Configuration = bincode::config::standard(); - -#[wasm_bindgen] -impl WasmSdk { - #[allow(clippy::too_many_arguments)] - #[wasm_bindgen(js_name = "getContestedResources")] - pub async fn get_contested_resources( - &self, - document_type_name: &str, - data_contract_id: &str, - index_name: &str, - start_at_value: Option>, - limit: Option, - _offset: Option, - order_ascending: Option, - ) -> Result { - // Parse contract ID - let contract_id = Identifier::from_string( - data_contract_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; - - // Parse result_type to get start_index_values - // The result_type parameter actually specifies what we want to query - // For contested domain names in DPNS, we query at the "dash" parent domain level - let start_index_values = - if index_name == "parentNameAndLabel" && document_type_name == "domain" { - // For DPNS domains, start at the parent domain level (e.g., "dash") - vec![] // Empty to get all contested resources at any parent domain - } else { - // For other types, may need different index values - vec![] - }; - - // Create start_at_value_info if provided - let start_at_value_info = start_at_value.map(|bytes| { - get_contested_resources_request::get_contested_resources_request_v0::StartAtValueInfo { - start_value: bytes, - start_value_included: true, - } - }); - - // Create the gRPC request directly - let request = GetContestedResourcesRequest { - version: Some(get_contested_resources_request::Version::V0( - GetContestedResourcesRequestV0 { - contract_id: contract_id.to_vec(), - document_type_name: document_type_name.to_string(), - index_name: index_name.to_string(), - start_index_values, - end_index_values: vec![], - start_at_value_info, - count: limit, - order_ascending: order_ascending.unwrap_or(true), - prove: self.prove(), - }, - )), - }; - - // Execute the request - let response = self - .as_ref() - .execute(request, RequestSettings::default()) - .await - .map_err(|e| { - WasmSdkError::generic(format!("Failed to get contested resources: {}", e)) - })?; - - // For now, return a simple response structure - // The actual response parsing would require the ContestedResource type - let result = serde_json::json!({ - "contestedResources": [], - "metadata": { - "height": response.inner.metadata().ok().map(|m| m.height), - "coreChainLockedHeight": response.inner.metadata().ok().map(|m| m.core_chain_locked_height), - "timeMs": response.inner.metadata().ok().map(|m| m.time_ms), - "protocolVersion": response.inner.metadata().ok().map(|m| m.protocol_version), - } - }); - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - result.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } - - #[allow(clippy::too_many_arguments)] - #[wasm_bindgen(js_name = "getContestedResourceVotersForIdentity")] - pub async fn get_contested_resource_voters_for_identity( - &self, - contract_id: &str, - document_type_name: &str, - index_name: &str, - index_values: Vec, - contestant_id: &str, - start_at_voter_info: Option, - limit: Option, - order_ascending: Option, - ) -> Result { - // Parse contract ID - let contract_id = Identifier::from_string( - contract_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; - - // Parse contestant ID - let contestant_id = Identifier::from_string( - contestant_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contestant ID: {}", e)))?; - - // Convert JsValue index values to Vec> using bincode serialization - let mut index_values_bytes: Vec> = Vec::new(); - for value in index_values { - if let Some(s) = value.as_string() { - // Create a platform Value from the string - let platform_value = Value::Text(s); - // Serialize using bincode - let serialized = - bincode::encode_to_vec(&platform_value, BINCODE_CONFIG).map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to serialize index value: {}", - e - )) - })?; - index_values_bytes.push(serialized); - } else { - return Err(WasmSdkError::invalid_argument( - "Index values must be strings", - )); - } - } - - // Parse start_at_voter_info if provided - let start_at_identifier_info = if let Some(info_str) = start_at_voter_info { - let info: serde_json::Value = serde_json::from_str(&info_str).map_err(|e| { - WasmSdkError::invalid_argument(format!("Invalid start_at_voter_info JSON: {}", e)) - })?; - - if let (Some(start_id), Some(included)) = ( - info.get("startIdentifier"), - info.get("startIdentifierIncluded"), - ) { - let start_identifier = start_id - .as_str() - .ok_or_else(|| { - WasmSdkError::invalid_argument("startIdentifier must be a string") - })? - .as_bytes() - .to_vec(); - let start_identifier_included = included.as_bool().unwrap_or(true); - - Some(get_contested_resource_voters_for_identity_request::get_contested_resource_voters_for_identity_request_v0::StartAtIdentifierInfo { - start_identifier, - start_identifier_included, - }) - } else { - None - } - } else { - None - }; - - // Create the gRPC request - let request = GetContestedResourceVotersForIdentityRequest { - version: Some( - get_contested_resource_voters_for_identity_request::Version::V0( - GetContestedResourceVotersForIdentityRequestV0 { - contract_id: contract_id.to_vec(), - document_type_name: document_type_name.to_string(), - index_name: index_name.to_string(), - index_values: index_values_bytes, - contestant_id: contestant_id.to_vec(), - start_at_identifier_info, - count: limit, - order_ascending: order_ascending.unwrap_or(true), - prove: self.prove(), - }, - ), - ), - }; - - // Execute the request - let response = self - .as_ref() - .execute(request, RequestSettings::default()) - .await - .map_err(|e| { - WasmSdkError::generic(format!("Failed to get contested resource voters: {}", e)) - })?; - - // For now, return a simple response structure - let result = serde_json::json!({ - "voters": [], - "metadata": { - "height": response.inner.metadata().ok().map(|m| m.height), - "coreChainLockedHeight": response.inner.metadata().ok().map(|m| m.core_chain_locked_height), - "timeMs": response.inner.metadata().ok().map(|m| m.time_ms), - "protocolVersion": response.inner.metadata().ok().map(|m| m.protocol_version), - } - }); - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - result.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } - - #[wasm_bindgen(js_name = "getContestedResourceIdentityVotes")] - pub async fn get_contested_resource_identity_votes( - &self, - identity_id: &str, - limit: Option, - start_at_vote_poll_id_info: Option, - order_ascending: Option, - ) -> Result { - // TODO: Implement get_contested_resource_identity_votes - // This function should return all votes made by a specific identity - let _ = ( - self, - identity_id, - limit, - start_at_vote_poll_id_info, - order_ascending, - ); - - // Return empty result for now - let result = serde_json::json!({ - "votes": [], - "metadata": {} - }); - - serde_wasm_bindgen::to_value(&result).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } - - #[wasm_bindgen(js_name = "getVotePollsByEndDate")] - pub async fn get_vote_polls_by_end_date( - &self, - start_time_info: Option, - end_time_info: Option, - limit: Option, - order_ascending: Option, - ) -> Result { - // TODO: Implement get_vote_polls_by_end_date - // This function should return vote polls filtered by end date - let _ = (self, start_time_info, end_time_info, limit, order_ascending); - - // Return empty result for now - let result = serde_json::json!({ - "votePolls": [], - "metadata": {} - }); - - serde_wasm_bindgen::to_value(&result).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } - - // Proof info versions for voting queries - #[allow(clippy::too_many_arguments)] - #[wasm_bindgen(js_name = "getContestedResourcesWithProofInfo")] - pub async fn get_contested_resources_with_proof_info( - &self, - document_type_name: &str, - data_contract_id: &str, - index_name: &str, - start_at_value: Option>, - limit: Option, - _offset: Option, - order_ascending: Option, - ) -> Result { - use crate::queries::ProofMetadataResponse; - - // Parse contract ID - let contract_id = Identifier::from_string( - data_contract_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; - - // Parse result_type to get start_index_values - // The result_type parameter actually specifies what we want to query - // For contested domain names in DPNS, we query at the "dash" parent domain level - let start_index_values = - if index_name == "parentNameAndLabel" && document_type_name == "domain" { - // For DPNS domains, start at the parent domain level (e.g., "dash") - vec![] // Empty to get all contested resources at any parent domain - } else { - // For other types, may need different index values - vec![] - }; - - // Create start_at_value_info if provided - let start_at_value_info = start_at_value.map(|bytes| { - get_contested_resources_request::get_contested_resources_request_v0::StartAtValueInfo { - start_value: bytes, - start_value_included: true, - } - }); - - // Create the gRPC request directly - force prove=true for proof info - let request = GetContestedResourcesRequest { - version: Some(get_contested_resources_request::Version::V0( - GetContestedResourcesRequestV0 { - contract_id: contract_id.to_vec(), - document_type_name: document_type_name.to_string(), - index_name: index_name.to_string(), - start_index_values, - end_index_values: vec![], - start_at_value_info, - count: limit, - order_ascending: order_ascending.unwrap_or(true), - prove: true, // Always true for proof info version - }, - )), - }; - - // Execute the request - let response = self - .as_ref() - .execute(request, RequestSettings::default()) - .await - .map_err(|e| { - WasmSdkError::generic(format!( - "Failed to get contested resources with proof: {}", - e - )) - })?; - - // Extract metadata and proof from response - let metadata = response - .inner - .metadata() - .map_err(|e| WasmSdkError::generic(format!("Failed to get metadata: {:?}", e)))?; - - let proof = response - .inner - .proof() - .map_err(|e| WasmSdkError::generic(format!("Failed to get proof: {:?}", e)))?; - - // For now, return a simple response structure - let data = serde_json::json!({ - "contestedResources": [] - }); - - let response = ProofMetadataResponse { - data, - metadata: metadata.clone().into(), - proof: proof.clone().into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } - - #[allow(clippy::too_many_arguments)] - #[wasm_bindgen(js_name = "getContestedResourceVoteStateWithProofInfo")] - pub async fn get_contested_resource_vote_state_with_proof_info( - &self, - data_contract_id: &str, - document_type_name: &str, - index_name: &str, - index_values: Vec, - // TODO: Implement result_type parameter properly - // Currently unused - should map to protobuf ResultType enum: - // - "documents" -> 0 (DOCUMENTS) - // - "vote_tally" -> 1 (VOTE_TALLY) - // - "documents_and_vote_tally" -> 2 (DOCUMENTS_AND_VOTE_TALLY) - // See: https://github.com/dashpay/platform/issues/2760 - _result_type: &str, - allow_include_locked_and_abstaining_vote_tally: Option, - start_at_identifier_info: Option, - count: Option, - _order_ascending: Option, - ) -> Result { - use crate::queries::ProofMetadataResponse; - - // Parse contract ID - let contract_id = Identifier::from_string( - data_contract_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; - - // Parse start_at_identifier_info if provided - let start_at_identifier_info = if let Some(info_str) = start_at_identifier_info { - let info: serde_json::Value = serde_json::from_str(&info_str).map_err(|e| { - WasmSdkError::invalid_argument(format!( - "Invalid start_at_identifier_info JSON: {}", - e - )) - })?; - - if let (Some(start_id), Some(included)) = ( - info.get("startIdentifier"), - info.get("startIdentifierIncluded"), - ) { - let start_identifier = start_id - .as_str() - .ok_or_else(|| { - WasmSdkError::invalid_argument("startIdentifier must be a string") - })? - .as_bytes() - .to_vec(); - let start_identifier_included = included.as_bool().unwrap_or(true); - - Some(get_contested_resource_vote_state_request::get_contested_resource_vote_state_request_v0::StartAtIdentifierInfo { - start_identifier, - start_identifier_included, - }) - } else { - None - } - } else { - None - }; - - // Convert JsValue index values to Vec> using bincode serialization - let mut index_values_bytes: Vec> = Vec::new(); - for value in index_values { - if let Some(s) = value.as_string() { - // Create a platform Value from the string - let platform_value = Value::Text(s); - // Serialize using bincode - let serialized = - bincode::encode_to_vec(&platform_value, BINCODE_CONFIG).map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to serialize index value: {}", - e - )) - })?; - index_values_bytes.push(serialized); - } else { - return Err(WasmSdkError::invalid_argument( - "Index values must be strings", - )); - } - } - - // Create the gRPC request directly - force prove=true - let request = GetContestedResourceVoteStateRequest { - version: Some(get_contested_resource_vote_state_request::Version::V0( - GetContestedResourceVoteStateRequestV0 { - contract_id: contract_id.to_vec(), - document_type_name: document_type_name.to_string(), - index_name: index_name.to_string(), - index_values: index_values_bytes, - // TODO: This should use the _result_type parameter instead of allow_include_locked_and_abstaining_vote_tally - // Current logic is incorrect - these are independent concerns - result_type: if allow_include_locked_and_abstaining_vote_tally.unwrap_or(false) - { - 0 - } else { - 1 - }, - allow_include_locked_and_abstaining_vote_tally: - allow_include_locked_and_abstaining_vote_tally.unwrap_or(false), - start_at_identifier_info, - count, - prove: true, // Always true for proof info version - }, - )), - }; - - // Execute the request - let response = self - .as_ref() - .execute(request, RequestSettings::default()) - .await - .map_err(|e| { - WasmSdkError::generic(format!( - "Failed to get contested resource vote state with proof: {}", - e - )) - })?; - - // Extract metadata and proof from response - let metadata = response - .inner - .metadata() - .map_err(|e| WasmSdkError::generic(format!("Failed to get metadata: {:?}", e)))?; - - let proof = response - .inner - .proof() - .map_err(|e| WasmSdkError::generic(format!("Failed to get proof: {:?}", e)))?; - - // Return a simple response structure - let data = serde_json::json!({ - "contenders": [], - "abstainVoteTally": null, - "lockVoteTally": null, - "finishedVoteInfo": null - }); - - let response = ProofMetadataResponse { - data, - metadata: metadata.clone().into(), - proof: proof.clone().into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } - - #[allow(clippy::too_many_arguments)] - #[wasm_bindgen(js_name = "getContestedResourceVotersForIdentityWithProofInfo")] - pub async fn get_contested_resource_voters_for_identity_with_proof_info( - &self, - data_contract_id: &str, - document_type_name: &str, - index_name: &str, - index_values: Vec, - contestant_id: &str, - start_at_identifier_info: Option, - count: Option, - order_ascending: Option, - ) -> Result { - use crate::queries::ProofMetadataResponse; - - // Parse IDs - let contract_id = Identifier::from_string( - data_contract_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; - - let contestant_identifier = Identifier::from_string( - contestant_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contestant ID: {}", e)))?; - - // Convert JsValue index values to Vec> using bincode serialization - let mut index_values_bytes: Vec> = Vec::new(); - for value in index_values { - if let Some(s) = value.as_string() { - // Create a platform Value from the string - let platform_value = Value::Text(s); - // Serialize using bincode - let serialized = - bincode::encode_to_vec(&platform_value, BINCODE_CONFIG).map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to serialize index value: {}", - e - )) - })?; - index_values_bytes.push(serialized); - } else { - return Err(WasmSdkError::invalid_argument( - "Index values must be strings", - )); - } - } - - // Parse start_at_identifier_info if provided - let start_at_identifier_info = if let Some(info_str) = start_at_identifier_info { - let info: serde_json::Value = serde_json::from_str(&info_str).map_err(|e| { - WasmSdkError::invalid_argument(format!( - "Invalid start_at_identifier_info JSON: {}", - e - )) - })?; - - if let (Some(start_id), Some(included)) = ( - info.get("startIdentifier"), - info.get("startIdentifierIncluded"), - ) { - let start_identifier = start_id - .as_str() - .ok_or_else(|| { - WasmSdkError::invalid_argument("startIdentifier must be a string") - })? - .as_bytes() - .to_vec(); - let start_identifier_included = included.as_bool().unwrap_or(true); - - Some(get_contested_resource_voters_for_identity_request::get_contested_resource_voters_for_identity_request_v0::StartAtIdentifierInfo { - start_identifier, - start_identifier_included, - }) - } else { - None - } - } else { - None - }; - - // Create the gRPC request directly - force prove=true - let request = GetContestedResourceVotersForIdentityRequest { - version: Some( - get_contested_resource_voters_for_identity_request::Version::V0( - GetContestedResourceVotersForIdentityRequestV0 { - contract_id: contract_id.to_vec(), - document_type_name: document_type_name.to_string(), - index_name: index_name.to_string(), - index_values: index_values_bytes, - contestant_id: contestant_identifier.to_vec(), - start_at_identifier_info, - count, - order_ascending: order_ascending.unwrap_or(true), - prove: true, // Always true for proof info version - }, - ), - ), - }; - - // Execute the request - let response = self - .as_ref() - .execute(request, RequestSettings::default()) - .await - .map_err(|e| { - WasmSdkError::generic(format!( - "Failed to get contested resource voters with proof: {}", - e - )) - })?; - - // Extract metadata and proof from response - let metadata = response - .inner - .metadata() - .map_err(|e| WasmSdkError::generic(format!("Failed to get metadata: {:?}", e)))?; - - let proof = response - .inner - .proof() - .map_err(|e| WasmSdkError::generic(format!("Failed to get proof: {:?}", e)))?; - - // Return a simple response structure - let data = serde_json::json!({ - "voters": [], - "finishedResults": false - }); - - let response = ProofMetadataResponse { - data, - metadata: metadata.clone().into(), - proof: proof.clone().into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } - - #[wasm_bindgen(js_name = "getContestedResourceIdentityVotesWithProofInfo")] - pub async fn get_contested_resource_identity_votes_with_proof_info( - &self, - identity_id: &str, - limit: Option, - offset: Option, - order_ascending: Option, - ) -> Result { - use crate::queries::ProofMetadataResponse; - - // Parse identity ID - let identity_identifier = Identifier::from_string( - identity_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; - - // Create the gRPC request directly - force prove=true - let request = GetContestedResourceIdentityVotesRequest { - version: Some(get_contested_resource_identity_votes_request::Version::V0( - GetContestedResourceIdentityVotesRequestV0 { - identity_id: identity_identifier.to_vec(), - limit, - offset, - order_ascending: order_ascending.unwrap_or(true), - start_at_vote_poll_id_info: None, - prove: true, // Always true for proof info version - }, - )), - }; - - // Execute the request - let response = self - .as_ref() - .execute(request, RequestSettings::default()) - .await - .map_err(|e| { - WasmSdkError::generic(format!( - "Failed to get contested resource identity votes with proof: {}", - e - )) - })?; - - // Extract metadata and proof from response - let metadata = response - .inner - .metadata() - .map_err(|e| WasmSdkError::generic(format!("Failed to get metadata: {:?}", e)))?; - - let proof = response - .inner - .proof() - .map_err(|e| WasmSdkError::generic(format!("Failed to get proof: {:?}", e)))?; - - // Return a simple response structure - let data = serde_json::json!({ - "votes": [], - "finishedResults": false - }); - - let response = ProofMetadataResponse { - data, - metadata: metadata.clone().into(), - proof: proof.clone().into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } - - #[wasm_bindgen(js_name = "getVotePollsByEndDateWithProofInfo")] - pub async fn get_vote_polls_by_end_date_with_proof_info( - &self, - start_time_ms: Option, - end_time_ms: Option, - limit: Option, - offset: Option, - order_ascending: Option, - ) -> Result { - use crate::queries::ProofMetadataResponse; - - // Note: GetVotePollsByEndDateRequestV0 doesn't have start_at_poll_info, only offset - - // Create the gRPC request directly - force prove=true - let request = GetVotePollsByEndDateRequest { - version: Some(get_vote_polls_by_end_date_request::Version::V0( - GetVotePollsByEndDateRequestV0 { - start_time_info: start_time_ms.map(|ms| { - get_vote_polls_by_end_date_request::get_vote_polls_by_end_date_request_v0::StartAtTimeInfo { - start_time_ms: ms, - start_time_included: true, - } - }), - end_time_info: end_time_ms.map(|ms| { - get_vote_polls_by_end_date_request::get_vote_polls_by_end_date_request_v0::EndAtTimeInfo { - end_time_ms: ms, - end_time_included: true, - } - }), - limit, - offset, - ascending: order_ascending.unwrap_or(true), - prove: true, // Always true for proof info version - }, - )), - }; - - // Execute the request - let response = self - .as_ref() - .execute(request, RequestSettings::default()) - .await - .map_err(|e| { - WasmSdkError::generic(format!( - "Failed to get vote polls by end date with proof: {}", - e - )) - })?; - - // Extract metadata and proof from response - let metadata = response - .inner - .metadata() - .map_err(|e| WasmSdkError::generic(format!("Failed to get metadata: {:?}", e)))?; - - let proof = response - .inner - .proof() - .map_err(|e| WasmSdkError::generic(format!("Failed to get proof: {:?}", e)))?; - - // Return a simple response structure - let data = serde_json::json!({ - "votePollsByTimestamps": {}, - "finishedResults": false - }); - - let response = ProofMetadataResponse { - data, - metadata: metadata.clone().into(), - proof: proof.clone().into(), - }; - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - response.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } - - #[allow(clippy::too_many_arguments)] - #[wasm_bindgen(js_name = "getContestedResourceVoteState")] - pub async fn get_contested_resource_vote_state( - &self, - data_contract_id: &str, - document_type_name: &str, - index_name: &str, - index_values: Vec, - // TODO: Implement result_type parameter properly - // Currently unused - should map to protobuf ResultType enum: - // - "documents" -> 0 (DOCUMENTS) - // - "vote_tally" -> 1 (VOTE_TALLY) - // - "documents_and_vote_tally" -> 2 (DOCUMENTS_AND_VOTE_TALLY) - // See: https://github.com/dashpay/platform/issues/2760 - _result_type: &str, - allow_include_locked_and_abstaining_vote_tally: Option, - start_at_identifier_info: Option, - count: Option, - _order_ascending: Option, - ) -> Result { - // Parse contract ID - let contract_id = Identifier::from_string( - data_contract_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; - - // Parse start_at_identifier_info if provided - let start_at_identifier_info = if let Some(info_str) = start_at_identifier_info { - let info: serde_json::Value = serde_json::from_str(&info_str).map_err(|e| { - WasmSdkError::invalid_argument(format!( - "Invalid start_at_identifier_info JSON: {}", - e - )) - })?; - - if let (Some(start_id), Some(included)) = ( - info.get("startIdentifier"), - info.get("startIdentifierIncluded"), - ) { - let start_identifier = start_id - .as_str() - .ok_or_else(|| { - WasmSdkError::invalid_argument("startIdentifier must be a string") - })? - .as_bytes() - .to_vec(); - let start_identifier_included = included.as_bool().unwrap_or(true); - - Some(get_contested_resource_vote_state_request::get_contested_resource_vote_state_request_v0::StartAtIdentifierInfo { - start_identifier, - start_identifier_included, - }) - } else { - None - } - } else { - None - }; - - // Convert JsValue index values to Vec> using bincode serialization - let mut index_values_bytes: Vec> = Vec::new(); - for value in index_values { - if let Some(s) = value.as_string() { - // Create a platform Value from the string - let platform_value = Value::Text(s); - // Serialize using bincode - let serialized = - bincode::encode_to_vec(&platform_value, BINCODE_CONFIG).map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to serialize index value: {}", - e - )) - })?; - index_values_bytes.push(serialized); - } else { - return Err(WasmSdkError::invalid_argument( - "Index values must be strings", - )); - } - } - - // Create the gRPC request directly - let request = GetContestedResourceVoteStateRequest { - version: Some(get_contested_resource_vote_state_request::Version::V0( - GetContestedResourceVoteStateRequestV0 { - contract_id: contract_id.to_vec(), - document_type_name: document_type_name.to_string(), - index_name: index_name.to_string(), - index_values: index_values_bytes, - // TODO: This should use the _result_type parameter instead of allow_include_locked_and_abstaining_vote_tally - // Current logic is incorrect - these are independent concerns - result_type: if allow_include_locked_and_abstaining_vote_tally.unwrap_or(false) - { - 0 - } else { - 1 - }, - allow_include_locked_and_abstaining_vote_tally: - allow_include_locked_and_abstaining_vote_tally.unwrap_or(false), - start_at_identifier_info, - count, - prove: self.prove(), - }, - )), - }; - - // Execute the request - let response = self - .as_ref() - .execute(request, RequestSettings::default()) - .await - .map_err(|e| { - WasmSdkError::generic(format!( - "Failed to get contested resource vote state: {}", - e - )) - })?; - - // Return a simple response structure - let result = serde_json::json!({ - "contenders": [], - "abstainVoteTally": null, - "lockVoteTally": null, - "finishedVoteInfo": null, - "metadata": { - "height": response.inner.metadata().ok().map(|m| m.height), - "coreChainLockedHeight": response.inner.metadata().ok().map(|m| m.core_chain_locked_height), - "timeMs": response.inner.metadata().ok().map(|m| m.time_ms), - "protocolVersion": response.inner.metadata().ok().map(|m| m.protocol_version), - } - }); - - // Use json_compatible serializer - let serializer = serde_wasm_bindgen::Serializer::json_compatible(); - result.serialize(&serializer).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize response: {}", e)) - }) - } -} diff --git a/packages/wasm-sdk/src/queries/voting/mod.rs b/packages/wasm-sdk/src/queries/voting/mod.rs new file mode 100644 index 00000000000..5122dd2e20f --- /dev/null +++ b/packages/wasm-sdk/src/queries/voting/mod.rs @@ -0,0 +1,5 @@ +mod polls; +mod resources; +mod state; +mod voters; +mod votes; diff --git a/packages/wasm-sdk/src/queries/voting/polls.rs b/packages/wasm-sdk/src/queries/voting/polls.rs new file mode 100644 index 00000000000..0964444d74a --- /dev/null +++ b/packages/wasm-sdk/src/queries/voting/polls.rs @@ -0,0 +1,374 @@ +use crate::sdk::WasmSdk; +use crate::{ProofMetadataResponseWasm, WasmSdkError}; +use dash_sdk::dpp::prelude::{TimestampIncluded, TimestampMillis}; +use dash_sdk::dpp::voting::vote_polls::VotePoll; +use dash_sdk::platform::FetchMany; +use drive::query::VotePollsByEndDateDriveQuery; +use drive_proof_verifier::types::VotePollsGroupedByTimestamp; +use js_sys::{Array, BigInt}; +use serde::Deserialize; +use std::rc::Rc; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::JsValue; +use wasm_dpp2::VotePollWasm; + +fn timestamp_from_option( + value: Option, + field: &str, +) -> Result, WasmSdkError> { + match value { + Some(raw) => { + if !raw.is_finite() || raw < 0.0 { + return Err(WasmSdkError::invalid_argument(format!( + "{} must be a non-negative finite number", + field + ))); + } + + if raw.fract() != 0.0 { + return Err(WasmSdkError::invalid_argument(format!( + "{} must be an integer value", + field + ))); + } + + let timestamp = raw as u64; + Ok(Some(timestamp)) + } + None => Ok(None), + } +} + +fn convert_limit(limit: Option, field: &str) -> Result, WasmSdkError> { + match limit { + Some(0) => Ok(None), + Some(value) => { + if value > u16::MAX as u32 { + return Err(WasmSdkError::invalid_argument(format!( + "{} {} exceeds maximum of {}", + field, + value, + u16::MAX + ))); + } + + Ok(Some(value as u16)) + } + None => Ok(None), + } +} + +#[derive(Default, Deserialize)] +#[serde(rename_all = "camelCase")] +struct VotePollsByEndDateQueryOptions { + start_time_ms: Option, + start_time_included: Option, + end_time_ms: Option, + end_time_included: Option, + limit: Option, + offset: Option, + order_ascending: Option, +} + +#[wasm_bindgen(js_name = "VotePollsByEndDateQuery")] +pub struct VotePollsByEndDateQueryWasm(VotePollsByEndDateDriveQuery); + +impl VotePollsByEndDateQueryWasm { + pub(crate) fn into_inner(self) -> VotePollsByEndDateDriveQuery { + self.0 + } +} + +#[wasm_bindgen(js_name = "VotePollsByEndDateQueryBuilder")] +pub struct VotePollsByEndDateQueryBuilder { + start_time: Option<(TimestampMillis, TimestampIncluded)>, + end_time: Option<(TimestampMillis, TimestampIncluded)>, + limit: Option, + offset: Option, + order_ascending: bool, +} + +#[wasm_bindgen(js_class = VotePollsByEndDateQueryBuilder)] +impl VotePollsByEndDateQueryBuilder { + #[wasm_bindgen(constructor)] + pub fn new() -> VotePollsByEndDateQueryBuilder { + Self { + start_time: None, + end_time: None, + limit: None, + offset: None, + order_ascending: true, + } + } + + #[wasm_bindgen(js_name = "withStartTime")] + pub fn with_start_time( + mut self, + timestamp_ms: Option, + included: bool, + ) -> Result { + self.start_time = timestamp_from_option(timestamp_ms, "startTimeMs")? + .map(|timestamp| (timestamp, included)); + Ok(self) + } + + #[wasm_bindgen(js_name = "withEndTime")] + pub fn with_end_time( + mut self, + timestamp_ms: Option, + included: bool, + ) -> Result { + self.end_time = timestamp_from_option(timestamp_ms, "endTimeMs")? + .map(|timestamp| (timestamp, included)); + Ok(self) + } + + #[wasm_bindgen(js_name = "withLimit")] + pub fn with_limit( + mut self, + limit: Option, + ) -> Result { + self.limit = convert_limit(limit, "limit")?; + Ok(self) + } + + #[wasm_bindgen(js_name = "withOffset")] + pub fn with_offset( + mut self, + offset: Option, + ) -> Result { + self.offset = convert_limit(offset, "offset")?; + Ok(self) + } + + #[wasm_bindgen(js_name = "withOrderAscending")] + pub fn with_order_ascending(mut self, ascending: bool) -> VotePollsByEndDateQueryBuilder { + self.order_ascending = ascending; + self + } + + #[wasm_bindgen(js_name = "build")] + pub fn build(self) -> VotePollsByEndDateQueryWasm { + let VotePollsByEndDateQueryBuilder { + start_time, + end_time, + limit, + offset, + order_ascending, + } = self; + + VotePollsByEndDateQueryWasm(VotePollsByEndDateDriveQuery { + start_time, + end_time, + limit, + offset, + order_ascending, + }) + } +} + +fn build_query_from_options( + opts: VotePollsByEndDateQueryOptions, +) -> Result { + let VotePollsByEndDateQueryOptions { + start_time_ms, + start_time_included, + end_time_ms, + end_time_included, + limit, + offset, + order_ascending, + } = opts; + + if start_time_ms.is_none() && start_time_included.is_some() { + return Err(WasmSdkError::invalid_argument( + "startTimeIncluded provided without startTimeMs", + )); + } + + if end_time_ms.is_none() && end_time_included.is_some() { + return Err(WasmSdkError::invalid_argument( + "endTimeIncluded provided without endTimeMs", + )); + } + + let mut builder = VotePollsByEndDateQueryBuilder::new(); + + if start_time_ms.is_some() || start_time_included.is_some() { + builder = builder.with_start_time(start_time_ms, start_time_included.unwrap_or(true))?; + } + + if end_time_ms.is_some() || end_time_included.is_some() { + builder = builder.with_end_time(end_time_ms, end_time_included.unwrap_or(true))?; + } + + if limit.is_some() { + builder = builder.with_limit(limit)?; + } + + if offset.is_some() { + builder = builder.with_offset(offset)?; + } + + if let Some(order) = order_ascending { + builder = builder.with_order_ascending(order); + } + + Ok(builder.build()) +} + +#[wasm_bindgen(js_name = "buildVotePollsByEndDateQuery")] +pub fn build_vote_polls_by_end_date_query( + options: JsValue, +) -> Result { + let opts = if options.is_null() || options.is_undefined() { + VotePollsByEndDateQueryOptions::default() + } else { + serde_wasm_bindgen::from_value(options).map_err(|err| { + WasmSdkError::invalid_argument(format!( + "Invalid vote polls by end date options: {}", + err + )) + })? + }; + + build_query_from_options(opts) +} + +#[derive(Clone)] +#[wasm_bindgen(js_name = "VotePollsByEndDateEntry")] +pub struct VotePollsByEndDateEntryWasm { + timestamp_ms: TimestampMillis, + polls_js: Rc, +} + +impl VotePollsByEndDateEntryWasm { + fn new(timestamp_ms: TimestampMillis, polls: Vec) -> Self { + let array = Array::new(); + for poll in polls { + array.push(&JsValue::from(poll)); + } + + Self { + timestamp_ms, + polls_js: Rc::new(array), + } + } +} + +#[wasm_bindgen(js_class = VotePollsByEndDateEntry)] +impl VotePollsByEndDateEntryWasm { + #[wasm_bindgen(getter = timestampMs)] + pub fn timestamp_ms(&self) -> BigInt { + BigInt::from(self.timestamp_ms) + } + + #[wasm_bindgen(getter = votePolls)] + pub fn vote_polls(&self) -> Array { + self.polls_js.as_ref().clone() + } +} + +#[derive(Clone)] +#[wasm_bindgen(js_name = "VotePollsByEndDateResult")] +pub struct VotePollsByEndDateResultWasm { + entries: Vec, + entries_js: Rc, +} + +impl VotePollsByEndDateResultWasm { + fn new(entries: Vec) -> Self { + let array = Array::new(); + for entry in &entries { + array.push(&JsValue::from(entry.clone())); + } + + Self { + entries, + entries_js: Rc::new(array), + } + } +} + +#[wasm_bindgen(js_class = VotePollsByEndDateResult)] +impl VotePollsByEndDateResultWasm { + #[wasm_bindgen(getter = entries)] + pub fn entries(&self) -> Array { + self.entries_js.as_ref().clone() + } + + #[wasm_bindgen(js_name = "isEmpty")] + pub fn is_empty(&self) -> bool { + self.entries.is_empty() + } +} + +impl From for VotePollsByEndDateResultWasm { + fn from(grouped: VotePollsGroupedByTimestamp) -> Self { + let entries = grouped + .into_iter() + .map(|(timestamp, polls)| { + let poll_wrappers = polls.into_iter().map(VotePollWasm::from).collect(); + VotePollsByEndDateEntryWasm::new(timestamp, poll_wrappers) + }) + .collect(); + + VotePollsByEndDateResultWasm::new(entries) + } +} + +#[wasm_bindgen] +impl WasmSdk { + async fn fetch_vote_polls_by_end_date( + &self, + query: VotePollsByEndDateQueryWasm, + ) -> Result { + let polls = VotePoll::fetch_many(self.as_ref(), query.into_inner()).await?; + Ok(polls.into()) + } + + #[wasm_bindgen(js_name = "getVotePollsByEndDate")] + pub async fn get_vote_polls_by_end_date( + &self, + options: JsValue, + ) -> Result { + let query = build_vote_polls_by_end_date_query(options)?; + self.fetch_vote_polls_by_end_date(query).await + } + + #[wasm_bindgen(js_name = "getVotePollsByEndDateWithQuery")] + pub async fn get_vote_polls_by_end_date_with_query( + &self, + query: VotePollsByEndDateQueryWasm, + ) -> Result { + self.fetch_vote_polls_by_end_date(query).await + } + + #[wasm_bindgen(js_name = "getVotePollsByEndDateWithProofInfo")] + pub async fn get_vote_polls_by_end_date_with_proof_info( + &self, + options: JsValue, + ) -> Result { + let query = build_vote_polls_by_end_date_query(options)?; + self.get_vote_polls_by_end_date_with_proof_info_query(query) + .await + } + + #[wasm_bindgen(js_name = "getVotePollsByEndDateWithProofInfoQuery")] + pub async fn get_vote_polls_by_end_date_with_proof_info_query( + &self, + query: VotePollsByEndDateQueryWasm, + ) -> Result { + let (polls, metadata, proof) = + VotePoll::fetch_many_with_metadata_and_proof(self.as_ref(), query.into_inner(), None) + .await?; + + let result = VotePollsByEndDateResultWasm::from(polls); + + Ok(ProofMetadataResponseWasm::from_parts( + JsValue::from(result), + metadata.into(), + proof.into(), + )) + } +} diff --git a/packages/wasm-sdk/src/queries/voting/resources.rs b/packages/wasm-sdk/src/queries/voting/resources.rs new file mode 100644 index 00000000000..0d554500a1a --- /dev/null +++ b/packages/wasm-sdk/src/queries/voting/resources.rs @@ -0,0 +1,202 @@ +use crate::queries::ProofMetadataResponseWasm; +use crate::sdk::WasmSdk; +use crate::utils::{js_value_to_platform_value, js_values_to_platform_values}; +use crate::WasmSdkError; +use dash_sdk::platform::FetchMany; +use drive::query::vote_polls_by_document_type_query::VotePollsByDocumentTypeQuery; +use drive_proof_verifier::types::ContestedResource; +use js_sys::Array; +use platform_value::{Identifier, Value}; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::JsValue; + +#[wasm_bindgen(js_name = "VotePollsByDocumentTypeQuery")] +pub struct VotePollsByDocumentTypeQueryWasm(VotePollsByDocumentTypeQuery); + +impl VotePollsByDocumentTypeQueryWasm { + pub(crate) fn into_inner(self) -> VotePollsByDocumentTypeQuery { + self.0 + } +} + +#[wasm_bindgen(js_name = "VotePollsByDocumentTypeQueryBuilder")] +pub struct VotePollsByDocumentTypeQueryBuilder { + contract_id: Identifier, + document_type_name: String, + index_name: String, + start_index_values: Vec, + end_index_values: Vec, + start_at_value: Option<(Value, bool)>, + limit: Option, + order_ascending: bool, +} + +#[wasm_bindgen(js_class = VotePollsByDocumentTypeQueryBuilder)] +impl VotePollsByDocumentTypeQueryBuilder { + #[wasm_bindgen(constructor)] + pub fn new( + data_contract_id: &str, + document_type_name: &str, + index_name: &str, + ) -> Result { + let contract_id = Identifier::from_string( + data_contract_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; + + Ok(Self { + contract_id, + document_type_name: document_type_name.to_string(), + index_name: index_name.to_string(), + start_index_values: Vec::new(), + end_index_values: Vec::new(), + start_at_value: None, + limit: None, + order_ascending: true, + }) + } + + #[wasm_bindgen(js_name = "withStartIndexValues")] + pub fn with_start_index_values( + mut self, + values: Vec, + ) -> Result { + self.start_index_values = js_values_to_platform_values(values)?; + Ok(self) + } + + #[wasm_bindgen(js_name = "withEndIndexValues")] + pub fn with_end_index_values( + mut self, + values: Vec, + ) -> Result { + self.end_index_values = js_values_to_platform_values(values)?; + Ok(self) + } + + #[wasm_bindgen(js_name = "withStartAtValue")] + pub fn with_start_at_value( + mut self, + value: JsValue, + included: bool, + ) -> Result { + if value.is_null() || value.is_undefined() { + self.start_at_value = None; + } else { + let platform_value = js_value_to_platform_value(value)?; + self.start_at_value = Some((platform_value, included)); + } + Ok(self) + } + + #[wasm_bindgen(js_name = "withLimit")] + pub fn with_limit( + mut self, + limit: Option, + ) -> Result { + self.limit = match limit { + Some(0) => None, + Some(count) => { + if count > u16::MAX as u32 { + return Err(WasmSdkError::invalid_argument(format!( + "limit {} exceeds maximum of {}", + count, + u16::MAX + ))); + } + Some(count as u16) + } + None => None, + }; + Ok(self) + } + + #[wasm_bindgen(js_name = "withOrderAscending")] + pub fn with_order_ascending( + mut self, + order_ascending: bool, + ) -> VotePollsByDocumentTypeQueryBuilder { + self.order_ascending = order_ascending; + self + } + + #[wasm_bindgen(js_name = "build")] + pub fn build(self) -> VotePollsByDocumentTypeQueryWasm { + let VotePollsByDocumentTypeQueryBuilder { + contract_id, + document_type_name, + index_name, + start_index_values, + end_index_values, + start_at_value, + limit, + order_ascending, + } = self; + + VotePollsByDocumentTypeQueryWasm(VotePollsByDocumentTypeQuery { + contract_id, + document_type_name, + index_name, + start_index_values, + end_index_values, + start_at_value, + limit, + order_ascending, + }) + } +} + +#[wasm_bindgen] +impl WasmSdk { + #[wasm_bindgen(js_name = "getContestedResources")] + pub async fn get_contested_resources( + &self, + query: VotePollsByDocumentTypeQueryWasm, + ) -> Result { + let contested_resources = + ContestedResource::fetch_many(self.as_ref(), query.into_inner()).await?; + + let array = Array::new(); + for resource in contested_resources.0 { + let js_value = serde_wasm_bindgen::to_value(&resource.0).map_err(|e| { + WasmSdkError::serialization(format!( + "Failed to serialize contested resource value: {}", + e + )) + })?; + array.push(&js_value); + } + + Ok(array) + } + + // Proof info versions for voting queries + #[wasm_bindgen(js_name = "getContestedResourcesWithProofInfo")] + pub async fn get_contested_resources_with_proof_info( + &self, + query: VotePollsByDocumentTypeQueryWasm, + ) -> Result { + let (contested_resources, metadata, proof) = + ContestedResource::fetch_many_with_metadata_and_proof( + self.as_ref(), + query.into_inner(), + None, + ) + .await?; + + let resources: Vec = contested_resources + .0 + .into_iter() + .map(|resource| resource.0) + .collect(); + + let data = serde_wasm_bindgen::to_value(&resources).map_err(|e| { + WasmSdkError::serialization(format!("Failed to serialize contested resources: {}", e)) + })?; + + let response = ProofMetadataResponseWasm::from_parts(data, metadata.into(), proof.into()); + + Ok(JsValue::from(response)) + } +} diff --git a/packages/wasm-sdk/src/queries/voting/state.rs b/packages/wasm-sdk/src/queries/voting/state.rs new file mode 100644 index 00000000000..1ad8b39b85e --- /dev/null +++ b/packages/wasm-sdk/src/queries/voting/state.rs @@ -0,0 +1,357 @@ +use dash_sdk::dpp::voting::contender_structs::ContenderWithSerializedDocument; +use dash_sdk::dpp::voting::vote_info_storage::contested_document_vote_poll_winner_info::ContestedDocumentVotePollWinnerInfo; +use dash_sdk::dpp::voting::vote_polls::contested_document_resource_vote_poll::ContestedDocumentResourceVotePoll; +use dash_sdk::platform::FetchMany; +use drive::query::vote_poll_vote_state_query::{ + ContestedDocumentVotePollDriveQuery, ContestedDocumentVotePollDriveQueryResultType, +}; +use drive_proof_verifier::types::Contenders; +use js_sys::Array; +use platform_value::Identifier; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::JsValue; +use wasm_dpp2::block::BlockInfoWasm; +use wasm_dpp2::identifier::IdentifierWasm; +use wasm_dpp2::{ContenderWithSerializedDocumentWasm, ContestedDocumentVotePollWinnerInfoWasm}; + +type ContestedResourceVoteWinnerBlockWasm = BlockInfoWasm; +use crate::sdk::WasmSdk; +use crate::utils::js_values_to_platform_values; +use crate::{ProofMetadataResponseWasm, WasmSdkError}; + +#[wasm_bindgen(js_name = "ContestedResourceVoteWinner")] +#[derive(Clone)] +pub struct ContestedResourceVoteWinnerWasm { + info: ContestedDocumentVotePollWinnerInfoWasm, + block: ContestedResourceVoteWinnerBlockWasm, +} + +impl ContestedResourceVoteWinnerWasm { + fn from_parts( + info: ContestedDocumentVotePollWinnerInfo, + block: ContestedResourceVoteWinnerBlockWasm, + ) -> Self { + Self { + info: info.into(), + block, + } + } +} + +#[wasm_bindgen(js_class = ContestedResourceVoteWinner)] +impl ContestedResourceVoteWinnerWasm { + #[wasm_bindgen(getter = kind)] + pub fn kind(&self) -> String { + self.info.kind() + } + + #[wasm_bindgen(getter = identityId)] + pub fn identity_id(&self) -> Option { + self.info.identity_id() + } + + #[wasm_bindgen(getter = block)] + pub fn block(&self) -> ContestedResourceVoteWinnerBlockWasm { + self.block.clone() + } + + #[wasm_bindgen(getter = info)] + pub fn info(&self) -> ContestedDocumentVotePollWinnerInfoWasm { + self.info + } +} + +#[wasm_bindgen(js_name = "ContestedResourceContender")] +#[derive(Clone)] +pub struct ContestedResourceContenderWasm { + identity_id: Identifier, + contender: ContenderWithSerializedDocumentWasm, +} + +impl ContestedResourceContenderWasm { + fn from_parts(identity: Identifier, contender: ContenderWithSerializedDocument) -> Self { + Self { + identity_id: identity, + contender: contender.into(), + } + } +} + +#[wasm_bindgen(js_class = ContestedResourceContender)] +impl ContestedResourceContenderWasm { + #[wasm_bindgen(getter = identityId)] + pub fn identity_id(&self) -> IdentifierWasm { + IdentifierWasm::from(self.identity_id.clone()) + } + + #[wasm_bindgen(getter = serializedDocument)] + pub fn serialized_document(&self) -> JsValue { + self.contender.serialized_document() + } + + #[wasm_bindgen(getter = voteTally)] + pub fn vote_tally(&self) -> Option { + self.contender.vote_tally() + } + + #[wasm_bindgen(getter = contender)] + pub fn contender(&self) -> ContenderWithSerializedDocumentWasm { + self.contender.clone() + } +} + +#[wasm_bindgen(js_name = "ContestedResourceVoteState")] +#[derive(Clone)] +pub struct ContestedResourceVoteStateWasm { + contenders: Vec, + lock_vote_tally: Option, + abstain_vote_tally: Option, + winner: Option, +} + +impl ContestedResourceVoteStateWasm { + fn new( + contenders: Vec, + lock_vote_tally: Option, + abstain_vote_tally: Option, + winner: Option, + ) -> Self { + Self { + contenders, + lock_vote_tally, + abstain_vote_tally, + winner, + } + } +} + +#[wasm_bindgen(js_class = ContestedResourceVoteState)] +impl ContestedResourceVoteStateWasm { + #[wasm_bindgen(getter = contenders)] + pub fn contenders(&self) -> Array { + let array = Array::new(); + for contender in &self.contenders { + array.push(&JsValue::from(contender.clone())); + } + array + } + + #[wasm_bindgen(getter = lockVoteTally)] + pub fn lock_vote_tally(&self) -> Option { + self.lock_vote_tally + } + + #[wasm_bindgen(getter = abstainVoteTally)] + pub fn abstain_vote_tally(&self) -> Option { + self.abstain_vote_tally + } + + #[wasm_bindgen(getter = winner)] + pub fn winner(&self) -> Option { + self.winner.clone() + } +} + +#[wasm_bindgen(js_name = "ContestedResourceVoteStateQuery")] +pub struct ContestedResourceVoteStateQueryWasm(ContestedDocumentVotePollDriveQuery); + +impl ContestedResourceVoteStateQueryWasm { + pub(crate) fn into_inner(self) -> ContestedDocumentVotePollDriveQuery { + self.0 + } +} + +#[wasm_bindgen(js_name = "ContestedResourceVoteStateQueryBuilder")] +pub struct ContestedResourceVoteStateQueryBuilder { + vote_poll: ContestedDocumentResourceVotePoll, + result_type: ContestedDocumentVotePollDriveQueryResultType, + limit: Option, + start_at: Option<([u8; 32], bool)>, + allow_include_locked_and_abstaining_vote_tally: bool, +} + +#[wasm_bindgen(js_class = ContestedResourceVoteStateQueryBuilder)] +impl ContestedResourceVoteStateQueryBuilder { + #[wasm_bindgen(constructor)] + pub fn new( + data_contract_id: &str, + document_type_name: &str, + index_name: &str, + ) -> Result { + let contract_id = Identifier::from_string( + data_contract_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; + + Ok(Self { + vote_poll: ContestedDocumentResourceVotePoll { + contract_id, + document_type_name: document_type_name.to_string(), + index_name: index_name.to_string(), + index_values: Vec::new(), + }, + result_type: ContestedDocumentVotePollDriveQueryResultType::DocumentsAndVoteTally, + limit: None, + start_at: None, + allow_include_locked_and_abstaining_vote_tally: false, + }) + } + + #[wasm_bindgen(js_name = "withIndexValues")] + pub fn with_index_values( + mut self, + values: Vec, + ) -> Result { + self.vote_poll.index_values = js_values_to_platform_values(values)?; + Ok(self) + } + + #[wasm_bindgen(js_name = "withResultType")] + pub fn with_result_type( + mut self, + result_type: &str, + ) -> Result { + self.result_type = match result_type { + "documents" | "DOCUMENTS" => ContestedDocumentVotePollDriveQueryResultType::Documents, + "voteTally" | "VOTE_TALLY" => ContestedDocumentVotePollDriveQueryResultType::VoteTally, + "documentsAndVoteTally" | "DOCUMENTS_AND_VOTE_TALLY" => { + ContestedDocumentVotePollDriveQueryResultType::DocumentsAndVoteTally + } + other => { + return Err(WasmSdkError::invalid_argument(format!( + "Unsupported result type '{}'", + other + ))) + } + }; + Ok(self) + } + + #[wasm_bindgen(js_name = "withLimit")] + pub fn with_limit( + mut self, + limit: Option, + ) -> Result { + self.limit = match limit { + Some(0) => None, + Some(count) => { + if count > u16::MAX as u32 { + return Err(WasmSdkError::invalid_argument(format!( + "limit {} exceeds maximum of {}", + count, + u16::MAX + ))); + } + Some(count as u16) + } + None => None, + }; + Ok(self) + } + + #[wasm_bindgen(js_name = "withStartAtContender")] + pub fn with_start_at_contender( + mut self, + contender_id: &str, + included: bool, + ) -> Result { + let identifier = Identifier::from_string( + contender_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contender ID: {}", e)))?; + + self.start_at = Some((identifier.to_buffer(), included)); + Ok(self) + } + + #[wasm_bindgen(js_name = "withIncludeLockedAndAbstaining")] + pub fn with_include_locked_and_abstaining( + mut self, + include: bool, + ) -> ContestedResourceVoteStateQueryBuilder { + self.allow_include_locked_and_abstaining_vote_tally = include; + self + } + + #[wasm_bindgen(js_name = "build")] + pub fn build(self) -> ContestedResourceVoteStateQueryWasm { + let ContestedResourceVoteStateQueryBuilder { + vote_poll, + result_type, + limit, + start_at, + allow_include_locked_and_abstaining_vote_tally, + } = self; + + ContestedResourceVoteStateQueryWasm(ContestedDocumentVotePollDriveQuery { + vote_poll, + result_type, + offset: None, + limit, + start_at, + allow_include_locked_and_abstaining_vote_tally, + }) + } +} + +fn convert_contenders(contenders: Contenders) -> ContestedResourceVoteStateWasm { + let Contenders { + winner, + contenders: inner_contenders, + abstain_vote_tally, + lock_vote_tally, + } = contenders; + + let wrappers = inner_contenders + .into_iter() + .map(|(identity, contender)| { + ContestedResourceContenderWasm::from_parts(identity, contender) + }) + .collect(); + + let winner = winner.map(|(info, block)| { + ContestedResourceVoteWinnerWasm::from_parts(info, BlockInfoWasm::from(block)) + }); + + ContestedResourceVoteStateWasm::new(wrappers, lock_vote_tally, abstain_vote_tally, winner) +} + +#[wasm_bindgen] +impl WasmSdk { + #[wasm_bindgen(js_name = "getContestedResourceVoteState")] + pub async fn get_contested_resource_vote_state( + &self, + query: ContestedResourceVoteStateQueryWasm, + ) -> Result { + let contenders = + ContenderWithSerializedDocument::fetch_many(self.as_ref(), query.into_inner()).await?; + + let state = convert_contenders(contenders); + + Ok(state) + } + + #[wasm_bindgen(js_name = "getContestedResourceVoteStateWithProofInfo")] + pub async fn get_contested_resource_vote_state_with_proof_info( + &self, + query: ContestedResourceVoteStateQueryWasm, + ) -> Result { + let (contenders, metadata, proof) = + ContenderWithSerializedDocument::fetch_many_with_metadata_and_proof( + self.as_ref(), + query.into_inner(), + None, + ) + .await?; + + let state = convert_contenders(contenders); + + Ok(ProofMetadataResponseWasm::from_parts( + JsValue::from(state), + metadata.into(), + proof.into(), + )) + } +} diff --git a/packages/wasm-sdk/src/queries/voting/voters.rs b/packages/wasm-sdk/src/queries/voting/voters.rs new file mode 100644 index 00000000000..011dd36e072 --- /dev/null +++ b/packages/wasm-sdk/src/queries/voting/voters.rs @@ -0,0 +1,192 @@ +use crate::queries::ProofMetadataResponseWasm; +use crate::sdk::WasmSdk; +use crate::utils::js_values_to_platform_values; +use crate::WasmSdkError; +use dash_sdk::dpp::voting::vote_polls::contested_document_resource_vote_poll::ContestedDocumentResourceVotePoll; +use dash_sdk::platform::FetchMany; +use drive::query::vote_poll_contestant_votes_query::ContestedDocumentVotePollVotesDriveQuery; +use drive_proof_verifier::types::Voter; +use js_sys::Array; +use platform_value::string_encoding::Encoding; +use platform_value::Identifier; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::JsValue; +use wasm_dpp2::identifier::IdentifierWasm; + +#[wasm_bindgen(js_name = "ContestedResourceVotersQuery")] +pub struct ContestedResourceVotersQueryWasm(ContestedDocumentVotePollVotesDriveQuery); + +impl ContestedResourceVotersQueryWasm { + pub(crate) fn into_inner(self) -> ContestedDocumentVotePollVotesDriveQuery { + self.0 + } +} + +#[wasm_bindgen(js_name = "ContestedResourceVotersQueryBuilder")] +pub struct ContestedResourceVotersQueryBuilder { + vote_poll: ContestedDocumentResourceVotePoll, + contestant_id: Identifier, + limit: Option, + start_at: Option<([u8; 32], bool)>, + order_ascending: bool, +} + +#[wasm_bindgen(js_class = ContestedResourceVotersQueryBuilder)] +impl ContestedResourceVotersQueryBuilder { + #[wasm_bindgen(constructor)] + pub fn new( + data_contract_id: &str, + document_type_name: &str, + index_name: &str, + contestant_id: &str, + ) -> Result { + let contract_id = Identifier::from_string( + data_contract_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; + + let contestant_id = Identifier::from_string( + contestant_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contestant ID: {}", e)))?; + + Ok(Self { + vote_poll: ContestedDocumentResourceVotePoll { + contract_id, + document_type_name: document_type_name.to_string(), + index_name: index_name.to_string(), + index_values: Vec::new(), + }, + contestant_id, + limit: None, + start_at: None, + order_ascending: true, + }) + } + + #[wasm_bindgen(js_name = "withIndexValues")] + pub fn with_index_values( + mut self, + values: Vec, + ) -> Result { + self.vote_poll.index_values = js_values_to_platform_values(values)?; + Ok(self) + } + + #[wasm_bindgen(js_name = "withLimit")] + pub fn with_limit( + mut self, + limit: Option, + ) -> Result { + self.limit = match limit { + Some(0) => None, + Some(count) => { + if count > u16::MAX as u32 { + return Err(WasmSdkError::invalid_argument(format!( + "limit {} exceeds maximum of {}", + count, + u16::MAX + ))); + } + Some(count as u16) + } + None => None, + }; + Ok(self) + } + + #[wasm_bindgen(js_name = "withOrderAscending")] + pub fn with_order_ascending( + mut self, + order_ascending: bool, + ) -> ContestedResourceVotersQueryBuilder { + self.order_ascending = order_ascending; + self + } + + #[wasm_bindgen(js_name = "withStartAtVoter")] + pub fn with_start_at_voter( + mut self, + voter_id: &str, + included: bool, + ) -> Result { + let identifier = Identifier::from_string( + voter_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid voter ID: {}", e)))?; + + self.start_at = Some((identifier.to_buffer(), included)); + Ok(self) + } + + #[wasm_bindgen(js_name = "build")] + pub fn build(self) -> ContestedResourceVotersQueryWasm { + let ContestedResourceVotersQueryBuilder { + vote_poll, + contestant_id, + limit, + start_at, + order_ascending, + } = self; + + ContestedResourceVotersQueryWasm(ContestedDocumentVotePollVotesDriveQuery { + vote_poll, + contestant_id, + offset: None, + limit, + start_at, + order_ascending, + }) + } +} + +#[wasm_bindgen] +impl WasmSdk { + #[wasm_bindgen(js_name = "getContestedResourceVotersForIdentity")] + pub async fn get_contested_resource_voters_for_identity( + &self, + query: ContestedResourceVotersQueryWasm, + ) -> Result { + let voters = Voter::fetch_many(self.as_ref(), query.into_inner()) + .await + .map_err(WasmSdkError::from)?; + + let array = Array::new(); + for voter in voters.0.into_iter() { + let identifier_js = IdentifierWasm::from(voter.0); + array.push(&JsValue::from(identifier_js)); + } + + Ok(array) + } + + #[wasm_bindgen(js_name = "getContestedResourceVotersForIdentityWithProofInfo")] + pub async fn get_contested_resource_voters_for_identity_with_proof_info( + &self, + query: ContestedResourceVotersQueryWasm, + ) -> Result { + let (voters, metadata, proof) = + Voter::fetch_many_with_metadata_and_proof(self.as_ref(), query.into_inner(), None) + .await?; + + let voters_list: Vec = voters + .0 + .into_iter() + .map(|voter| voter.0.to_string(Encoding::Base58)) + .collect(); + + let data = serde_wasm_bindgen::to_value(&voters_list).map_err(|e| { + WasmSdkError::serialization(format!( + "Failed to serialize contested resource voters: {}", + e + )) + })?; + + let response = ProofMetadataResponseWasm::from_parts(data, metadata.into(), proof.into()); + + Ok(JsValue::from(response)) + } +} diff --git a/packages/wasm-sdk/src/queries/voting/votes.rs b/packages/wasm-sdk/src/queries/voting/votes.rs new file mode 100644 index 00000000000..ca68cf70e40 --- /dev/null +++ b/packages/wasm-sdk/src/queries/voting/votes.rs @@ -0,0 +1,235 @@ +use crate::queries::ProofMetadataResponseWasm; +use crate::sdk::WasmSdk; +use crate::WasmSdkError; +use dash_sdk::dpp::voting::vote_choices::resource_vote_choice::ResourceVoteChoice; +use dash_sdk::dpp::voting::vote_polls::VotePoll; +use dash_sdk::dpp::voting::votes::resource_vote::ResourceVote; +use dash_sdk::platform::FetchMany; +use drive::query::contested_resource_votes_given_by_identity_query::ContestedResourceVotesGivenByIdentityQuery; +use drive_proof_verifier::types::ResourceVotesByIdentity; +use js_sys::Array; +use platform_value::string_encoding::Encoding; +use platform_value::Identifier; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::JsValue; + +#[wasm_bindgen(js_name = "ContestedResourceIdentityVotesQuery")] +pub struct ContestedResourceIdentityVotesQueryWasm(ContestedResourceVotesGivenByIdentityQuery); + +impl ContestedResourceIdentityVotesQueryWasm { + pub(crate) fn into_inner(self) -> ContestedResourceVotesGivenByIdentityQuery { + self.0 + } +} + +#[wasm_bindgen(js_name = "ContestedResourceIdentityVotesQueryBuilder")] +pub struct ContestedResourceIdentityVotesQueryBuilder { + identity_id: Identifier, + limit: Option, + start_at_vote: Option<([u8; 32], bool)>, + order_ascending: bool, +} + +#[wasm_bindgen(js_class = ContestedResourceIdentityVotesQueryBuilder)] +impl ContestedResourceIdentityVotesQueryBuilder { + #[wasm_bindgen(constructor)] + pub fn new( + identity_id: &str, + ) -> Result { + let identity_id = Identifier::from_string( + identity_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; + + Ok(Self { + identity_id, + limit: None, + start_at_vote: None, + order_ascending: true, + }) + } + + #[wasm_bindgen(js_name = "withLimit")] + pub fn with_limit( + mut self, + limit: Option, + ) -> Result { + self.limit = match limit { + Some(0) => None, + Some(count) => { + if count > u16::MAX as u32 { + return Err(WasmSdkError::invalid_argument(format!( + "limit {} exceeds maximum of {}", + count, + u16::MAX + ))); + } + Some(count as u16) + } + None => None, + }; + Ok(self) + } + + #[wasm_bindgen(js_name = "withOrderAscending")] + pub fn with_order_ascending( + mut self, + ascending: bool, + ) -> ContestedResourceIdentityVotesQueryBuilder { + self.order_ascending = ascending; + self + } + + #[wasm_bindgen(js_name = "withStartAtVote")] + pub fn with_start_at_vote( + mut self, + vote_id: &str, + included: bool, + ) -> Result { + let identifier = Identifier::from_string( + vote_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid vote ID: {}", e)))?; + + self.start_at_vote = Some((identifier.to_buffer(), included)); + Ok(self) + } + + #[wasm_bindgen(js_name = "build")] + pub fn build(self) -> ContestedResourceIdentityVotesQueryWasm { + let ContestedResourceIdentityVotesQueryBuilder { + identity_id, + limit, + start_at_vote, + order_ascending, + } = self; + + ContestedResourceIdentityVotesQueryWasm(ContestedResourceVotesGivenByIdentityQuery { + identity_id, + offset: None, + limit, + start_at: start_at_vote, + order_ascending, + }) + } +} + +fn resource_votes_to_json( + votes: ResourceVotesByIdentity, +) -> Result, WasmSdkError> { + let mut results = Vec::new(); + + for (vote_id, vote_opt) in votes.into_iter() { + let vote = match vote_opt { + Some(vote) => vote, + None => continue, + }; + + let inner = match vote { + ResourceVote::V0(inner) => inner, + }; + + let vote_poll = match inner.vote_poll { + VotePoll::ContestedDocumentResourceVotePoll(poll) => poll, + }; + + let poll_unique_id = vote_poll.unique_id().map_err(|e| { + WasmSdkError::serialization(format!("Failed to derive vote poll unique id: {}", e)) + })?; + + let index_values_json = vote_poll + .index_values + .into_iter() + .map(|value| { + serde_json::to_value(value).map_err(|e| { + WasmSdkError::serialization(format!( + "Failed to serialize vote poll index value: {}", + e + )) + }) + }) + .collect::, WasmSdkError>>()?; + + let poll_json = serde_json::json!({ + "type": "contestedDocumentResource", + "uniqueId": poll_unique_id.to_string(Encoding::Base58), + "contractId": vote_poll.contract_id.to_string(Encoding::Base58), + "documentTypeName": vote_poll.document_type_name, + "indexName": vote_poll.index_name, + "indexValues": index_values_json, + }); + + let choice_json = match inner.resource_vote_choice { + ResourceVoteChoice::TowardsIdentity(identifier) => serde_json::json!({ + "type": "towardsIdentity", + "identityId": identifier.to_string(Encoding::Base58), + }), + ResourceVoteChoice::Abstain => serde_json::json!({ "type": "abstain" }), + ResourceVoteChoice::Lock => serde_json::json!({ "type": "lock" }), + }; + + results.push(serde_json::json!({ + "voteId": vote_id.to_string(Encoding::Base58), + "votePoll": poll_json, + "choice": choice_json, + })); + } + + Ok(results) +} + +#[wasm_bindgen] +impl WasmSdk { + #[wasm_bindgen(js_name = "getContestedResourceIdentityVotes")] + pub async fn get_contested_resource_identity_votes( + &self, + query: ContestedResourceIdentityVotesQueryWasm, + ) -> Result { + let votes = ResourceVote::fetch_many(self.as_ref(), query.into_inner()).await?; + + let votes_json = resource_votes_to_json(votes)?; + let array = Array::new(); + for vote in votes_json { + let js_value = serde_wasm_bindgen::to_value(&vote).map_err(|e| { + WasmSdkError::serialization(format!( + "Failed to serialize contested resource identity vote: {}", + e + )) + })?; + array.push(&js_value); + } + + Ok(array) + } + + #[wasm_bindgen(js_name = "getContestedResourceIdentityVotesWithProofInfo")] + pub async fn get_contested_resource_identity_votes_with_proof_info( + &self, + query: ContestedResourceIdentityVotesQueryWasm, + ) -> Result { + let (votes, metadata, proof) = ResourceVote::fetch_many_with_metadata_and_proof( + self.as_ref(), + query.into_inner(), + None, + ) + .await?; + + let votes_json = resource_votes_to_json(votes)?; + + let data = serde_wasm_bindgen::to_value(&serde_json::json!({ + "votes": votes_json + })) + .map_err(|e| { + WasmSdkError::serialization(format!( + "Failed to serialize contested resource identity votes response: {}", + e + )) + })?; + + let response = ProofMetadataResponseWasm::from_parts(data, metadata.into(), proof.into()); + + Ok(JsValue::from(response)) + } +} From 7717fedec47c34f720f28e325ed0fcebec147dda Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Tue, 28 Oct 2025 13:58:14 +0700 Subject: [PATCH 25/44] refactor: plain object query params --- packages/js-evo-sdk/src/group/facade.ts | 68 ++- packages/js-evo-sdk/src/voting/facade.ts | 116 +++-- .../tests/unit/facades/group.spec.mjs | 34 +- .../tests/unit/facades/voting.spec.mjs | 56 ++- packages/wasm-dpp2/Cargo.toml | 2 +- packages/wasm-dpp2/src/voting/contender.rs | 69 +++ packages/wasm-dpp2/src/voting/winner_info.rs | 96 ++++ packages/wasm-sdk/src/queries/voting/polls.rs | 250 +++++----- .../wasm-sdk/src/queries/voting/resources.rs | 376 +++++++++------ packages/wasm-sdk/src/queries/voting/state.rs | 437 +++++++++++------- .../wasm-sdk/src/queries/voting/voters.rs | 312 ++++++++----- packages/wasm-sdk/src/queries/voting/votes.rs | 227 +++++---- packages/wasm-sdk/src/utils.rs | 21 + .../wasm-sdk/tests/functional/voting.spec.mjs | 35 +- 14 files changed, 1372 insertions(+), 727 deletions(-) create mode 100644 packages/wasm-dpp2/src/voting/contender.rs create mode 100644 packages/wasm-dpp2/src/voting/winner_info.rs create mode 100644 packages/wasm-sdk/src/utils.rs diff --git a/packages/js-evo-sdk/src/group/facade.ts b/packages/js-evo-sdk/src/group/facade.ts index 7024fc509fd..81223130d8f 100644 --- a/packages/js-evo-sdk/src/group/facade.ts +++ b/packages/js-evo-sdk/src/group/facade.ts @@ -1,5 +1,29 @@ import type { EvoSDK } from '../sdk.js'; +interface VotePollsByDocumentTypeQueryInput { + dataContractId: string; + documentTypeName: string; + indexName: string; + startIndexValues?: unknown[]; + endIndexValues?: unknown[]; + startAtValue?: unknown; + startAtValueIncluded?: boolean; + limit?: number; + orderAscending?: boolean; +} + +interface ContestedResourceVotersForIdentityQueryInput { + dataContractId: string; + documentTypeName: string; + indexName: string; + indexValues?: unknown[]; + contestantId: string; + limit?: number; + startAtVoterId?: string; + startAtIncluded?: boolean; + orderAscending?: boolean; +} + export class GroupFacade { private sdk: EvoSDK; constructor(sdk: EvoSDK) { this.sdk = sdk; } @@ -93,24 +117,60 @@ export class GroupFacade { async contestedResources(params: { documentTypeName: string; contractId: string; indexName: string; startAtValue?: Uint8Array; limit?: number; orderAscending?: boolean }): Promise { const { documentTypeName, contractId, indexName, startAtValue, limit, orderAscending } = params; const w = await this.sdk.getWasmSdkConnected(); - return w.getContestedResources(documentTypeName, contractId, indexName, startAtValue ?? null, limit ?? null, null, orderAscending ?? null); + const query: VotePollsByDocumentTypeQueryInput = { + dataContractId: contractId, + documentTypeName, + indexName, + }; + if (startAtValue !== undefined) query.startAtValue = startAtValue; + if (limit !== undefined) query.limit = limit; + if (orderAscending !== undefined) query.orderAscending = orderAscending; + return w.getContestedResources(query); } async contestedResourcesWithProof(params: { documentTypeName: string; contractId: string; indexName: string; startAtValue?: Uint8Array; limit?: number; orderAscending?: boolean }): Promise { const { documentTypeName, contractId, indexName, startAtValue, limit, orderAscending } = params; const w = await this.sdk.getWasmSdkConnected(); - return w.getContestedResourcesWithProofInfo(documentTypeName, contractId, indexName, startAtValue ?? null, limit ?? null, null, orderAscending ?? null); + const query: VotePollsByDocumentTypeQueryInput = { + dataContractId: contractId, + documentTypeName, + indexName, + }; + if (startAtValue !== undefined) query.startAtValue = startAtValue; + if (limit !== undefined) query.limit = limit; + if (orderAscending !== undefined) query.orderAscending = orderAscending; + return w.getContestedResourcesWithProofInfo(query); } async contestedResourceVotersForIdentity(params: { contractId: string; documentTypeName: string; indexName: string; indexValues: any[]; contestantId: string; startAtVoterInfo?: string; limit?: number; orderAscending?: boolean }): Promise { const { contractId, documentTypeName, indexName, indexValues, contestantId, startAtVoterInfo, limit, orderAscending } = params; const w = await this.sdk.getWasmSdkConnected(); - return w.getContestedResourceVotersForIdentity(contractId, documentTypeName, indexName, indexValues, contestantId, startAtVoterInfo ?? null, limit ?? null, orderAscending ?? null); + const query: ContestedResourceVotersForIdentityQueryInput = { + dataContractId: contractId, + documentTypeName, + indexName, + indexValues, + contestantId, + }; + if (startAtVoterInfo !== undefined) query.startAtVoterId = startAtVoterInfo; + if (limit !== undefined) query.limit = limit; + if (orderAscending !== undefined) query.orderAscending = orderAscending; + return w.getContestedResourceVotersForIdentity(query); } async contestedResourceVotersForIdentityWithProof(params: { contractId: string; documentTypeName: string; indexName: string; indexValues: any[]; contestantId: string; startAtIdentifierInfo?: string; count?: number; orderAscending?: boolean }): Promise { const { contractId, documentTypeName, indexName, indexValues, contestantId, startAtIdentifierInfo, count, orderAscending } = params; const w = await this.sdk.getWasmSdkConnected(); - return w.getContestedResourceVotersForIdentityWithProofInfo(contractId, documentTypeName, indexName, indexValues, contestantId, startAtIdentifierInfo ?? null, count ?? null, orderAscending ?? null); + const query: ContestedResourceVotersForIdentityQueryInput = { + dataContractId: contractId, + documentTypeName, + indexName, + indexValues, + contestantId, + }; + if (startAtIdentifierInfo !== undefined) query.startAtVoterId = startAtIdentifierInfo; + if (count !== undefined) query.limit = count; + if (orderAscending !== undefined) query.orderAscending = orderAscending; + return w.getContestedResourceVotersForIdentityWithProofInfo(query); } } diff --git a/packages/js-evo-sdk/src/voting/facade.ts b/packages/js-evo-sdk/src/voting/facade.ts index 9f2b12a6dee..8414da6e237 100644 --- a/packages/js-evo-sdk/src/voting/facade.ts +++ b/packages/js-evo-sdk/src/voting/facade.ts @@ -1,32 +1,96 @@ import { asJsonString } from '../util.js'; import type { EvoSDK } from '../sdk.js'; +interface ContestedResourceVoteStateQueryInput { + dataContractId: string; + documentTypeName: string; + indexName: string; + indexValues?: unknown[]; + resultType?: 'documents' | 'voteTally' | 'documentsAndVoteTally'; + limit?: number; + startAtContenderId?: string; + startAtIncluded?: boolean; + includeLockedAndAbstaining?: boolean; +} + +interface ContestedResourceIdentityVotesQueryInput { + identityId: string; + limit?: number; + startAtVoteId?: string; + startAtIncluded?: boolean; + orderAscending?: boolean; +} + +interface VotePollsByEndDateQueryInput { + startTimeMs?: number; + startTimeIncluded?: boolean; + endTimeMs?: number; + endTimeIncluded?: boolean; + limit?: number; + offset?: number; + orderAscending?: boolean; +} + export class VotingFacade { private sdk: EvoSDK; constructor(sdk: EvoSDK) { this.sdk = sdk; } - async contestedResourceVoteState(params: { contractId: string; documentTypeName: string; indexName: string; indexValues: any[]; resultType: string; allowIncludeLockedAndAbstainingVoteTally?: boolean; startAtIdentifierInfo?: string; count?: number; orderAscending?: boolean }): Promise { - const { contractId, documentTypeName, indexName, indexValues, resultType, allowIncludeLockedAndAbstainingVoteTally, startAtIdentifierInfo, count, orderAscending } = params; + async contestedResourceVoteState(params: { contractId: string; documentTypeName: string; indexName: string; indexValues: any[]; resultType?: string; allowIncludeLockedAndAbstainingVoteTally?: boolean; startAtIdentifierInfo?: string; startAtIncluded?: boolean; count?: number }): Promise { + const { contractId, documentTypeName, indexName, indexValues, resultType, allowIncludeLockedAndAbstainingVoteTally, startAtIdentifierInfo, startAtIncluded, count } = params; const w = await this.sdk.getWasmSdkConnected(); - return w.getContestedResourceVoteState(contractId, documentTypeName, indexName, indexValues, resultType, allowIncludeLockedAndAbstainingVoteTally ?? null, startAtIdentifierInfo ?? null, count ?? null, orderAscending ?? null); + const query: ContestedResourceVoteStateQueryInput = { + dataContractId: contractId, + documentTypeName, + indexName, + indexValues, + }; + if (resultType !== undefined) query.resultType = resultType as ContestedResourceVoteStateQueryInput['resultType']; + if (allowIncludeLockedAndAbstainingVoteTally !== undefined) { + query.includeLockedAndAbstaining = allowIncludeLockedAndAbstainingVoteTally; + } + if (startAtIdentifierInfo !== undefined) query.startAtContenderId = startAtIdentifierInfo; + if (startAtIncluded !== undefined) query.startAtIncluded = startAtIncluded; + if (count !== undefined) query.limit = count; + return w.getContestedResourceVoteState(query); } - async contestedResourceVoteStateWithProof(params: { contractId: string; documentTypeName: string; indexName: string; indexValues: any[]; resultType: string; allowIncludeLockedAndAbstainingVoteTally?: boolean; startAtIdentifierInfo?: string; count?: number; orderAscending?: boolean }): Promise { - const { contractId, documentTypeName, indexName, indexValues, resultType, allowIncludeLockedAndAbstainingVoteTally, startAtIdentifierInfo, count, orderAscending } = params; + async contestedResourceVoteStateWithProof(params: { contractId: string; documentTypeName: string; indexName: string; indexValues: any[]; resultType?: string; allowIncludeLockedAndAbstainingVoteTally?: boolean; startAtIdentifierInfo?: string; startAtIncluded?: boolean; count?: number }): Promise { + const { contractId, documentTypeName, indexName, indexValues, resultType, allowIncludeLockedAndAbstainingVoteTally, startAtIdentifierInfo, startAtIncluded, count } = params; const w = await this.sdk.getWasmSdkConnected(); - return w.getContestedResourceVoteStateWithProofInfo(contractId, documentTypeName, indexName, indexValues, resultType, allowIncludeLockedAndAbstainingVoteTally ?? null, startAtIdentifierInfo ?? null, count ?? null, orderAscending ?? null); + const query: ContestedResourceVoteStateQueryInput = { + dataContractId: contractId, + documentTypeName, + indexName, + indexValues, + }; + if (resultType !== undefined) query.resultType = resultType as ContestedResourceVoteStateQueryInput['resultType']; + if (allowIncludeLockedAndAbstainingVoteTally !== undefined) { + query.includeLockedAndAbstaining = allowIncludeLockedAndAbstainingVoteTally; + } + if (startAtIdentifierInfo !== undefined) query.startAtContenderId = startAtIdentifierInfo; + if (startAtIncluded !== undefined) query.startAtIncluded = startAtIncluded; + if (count !== undefined) query.limit = count; + return w.getContestedResourceVoteStateWithProofInfo(query); } async contestedResourceIdentityVotes(identityId: string, opts: { limit?: number; startAtVotePollIdInfo?: string; orderAscending?: boolean } = {}): Promise { const { limit, startAtVotePollIdInfo, orderAscending } = opts; const w = await this.sdk.getWasmSdkConnected(); - return w.getContestedResourceIdentityVotes(identityId, limit ?? null, startAtVotePollIdInfo ?? null, orderAscending ?? null); + const query: ContestedResourceIdentityVotesQueryInput = { identityId }; + if (limit !== undefined) query.limit = limit; + if (startAtVotePollIdInfo !== undefined) query.startAtVoteId = startAtVotePollIdInfo; + if (orderAscending !== undefined) query.orderAscending = orderAscending; + return w.getContestedResourceIdentityVotes(query); } - async contestedResourceIdentityVotesWithProof(identityId: string, opts: { limit?: number; offset?: number; orderAscending?: boolean } = {}): Promise { - const { limit, offset, orderAscending } = opts; + async contestedResourceIdentityVotesWithProof(identityId: string, opts: { limit?: number; startAtVotePollIdInfo?: string; orderAscending?: boolean } = {}): Promise { + const { limit, startAtVotePollIdInfo, orderAscending } = opts; const w = await this.sdk.getWasmSdkConnected(); - return w.getContestedResourceIdentityVotesWithProofInfo(identityId, limit ?? null, offset ?? null, orderAscending ?? null); + const query: ContestedResourceIdentityVotesQueryInput = { identityId }; + if (limit !== undefined) query.limit = limit; + if (startAtVotePollIdInfo !== undefined) query.startAtVoteId = startAtVotePollIdInfo; + if (orderAscending !== undefined) query.orderAscending = orderAscending; + return w.getContestedResourceIdentityVotesWithProofInfo(query); } async votePollsByEndDate(opts: { startTimeMs?: number | string | bigint | null; startTimeIncluded?: boolean; endTimeMs?: number | string | bigint | null; endTimeIncluded?: boolean; limit?: number; offset?: number; orderAscending?: boolean } = {}): Promise { @@ -55,20 +119,20 @@ export class VotingFacade { return Number.isFinite(parsed) ? parsed : undefined; }; - const options: Record = {}; + const query: VotePollsByEndDateQueryInput = {}; const start = normalizeTime(startTimeMs); - if (start !== undefined) options.startTimeMs = start; - if (startTimeIncluded !== undefined) options.startTimeIncluded = startTimeIncluded; + if (start !== undefined) query.startTimeMs = start; + if (startTimeIncluded !== undefined) query.startTimeIncluded = startTimeIncluded; const end = normalizeTime(endTimeMs); - if (end !== undefined) options.endTimeMs = end; - if (endTimeIncluded !== undefined) options.endTimeIncluded = endTimeIncluded; + if (end !== undefined) query.endTimeMs = end; + if (endTimeIncluded !== undefined) query.endTimeIncluded = endTimeIncluded; - if (limit !== undefined) options.limit = limit; - if (offset !== undefined) options.offset = offset; - if (orderAscending !== undefined) options.orderAscending = orderAscending; + if (limit !== undefined) query.limit = limit; + if (offset !== undefined) query.offset = offset; + if (orderAscending !== undefined) query.orderAscending = orderAscending; - return w.getVotePollsByEndDate(options); + return w.getVotePollsByEndDate(query); } async votePollsByEndDateWithProof(opts: { startTimeMs?: number | bigint | null; endTimeMs?: number | bigint | null; limit?: number; offset?: number; orderAscending?: boolean } = {}): Promise { @@ -87,16 +151,16 @@ export class VotingFacade { return Number(value); }; - const options: Record = {}; + const query: VotePollsByEndDateQueryInput = {}; const start = normalizeTime(startTimeMs); - if (start !== undefined) options.startTimeMs = start; + if (start !== undefined) query.startTimeMs = start; const end = normalizeTime(endTimeMs); - if (end !== undefined) options.endTimeMs = end; - if (limit !== undefined) options.limit = limit; - if (offset !== undefined) options.offset = offset; - if (orderAscending !== undefined) options.orderAscending = orderAscending; + if (end !== undefined) query.endTimeMs = end; + if (limit !== undefined) query.limit = limit; + if (offset !== undefined) query.offset = offset; + if (orderAscending !== undefined) query.orderAscending = orderAscending; - return w.getVotePollsByEndDateWithProofInfo(options); + return w.getVotePollsByEndDateWithProofInfo(query); } async masternodeVote(args: { masternodeProTxHash: string; contractId: string; documentTypeName: string; indexName: string; indexValues: string | any[]; voteChoice: string; votingKeyWif: string }): Promise { diff --git a/packages/js-evo-sdk/tests/unit/facades/group.spec.mjs b/packages/js-evo-sdk/tests/unit/facades/group.spec.mjs index 905d78e0702..39ecc33475c 100644 --- a/packages/js-evo-sdk/tests/unit/facades/group.spec.mjs +++ b/packages/js-evo-sdk/tests/unit/facades/group.spec.mjs @@ -90,9 +90,35 @@ describe('GroupFacade', () => { await client.group.contestedResourceVotersForIdentityWithProof({ contractId: 'c', documentTypeName: 'dt', indexName: 'i', indexValues: ['v2'], contestantId: 'id', }); - expect(wasmSdk.getContestedResources).to.be.calledOnce(); - expect(wasmSdk.getContestedResourcesWithProofInfo).to.be.calledOnce(); - expect(wasmSdk.getContestedResourceVotersForIdentity).to.be.calledOnce(); - expect(wasmSdk.getContestedResourceVotersForIdentityWithProofInfo).to.be.calledOnce(); + expect(wasmSdk.getContestedResources).to.be.calledOnceWithExactly({ + dataContractId: 'c', + documentTypeName: 'dt', + indexName: 'i', + startAtValue: new Uint8Array([1]), + limit: 2, + orderAscending: false, + }); + expect(wasmSdk.getContestedResourcesWithProofInfo).to.be.calledOnceWithExactly({ + dataContractId: 'c', + documentTypeName: 'dt', + indexName: 'i', + }); + expect(wasmSdk.getContestedResourceVotersForIdentity).to.be.calledOnceWithExactly({ + dataContractId: 'c', + documentTypeName: 'dt', + indexName: 'i', + indexValues: ['v1'], + contestantId: 'id', + startAtVoterId: 's', + limit: 3, + orderAscending: true, + }); + expect(wasmSdk.getContestedResourceVotersForIdentityWithProofInfo).to.be.calledOnceWithExactly({ + dataContractId: 'c', + documentTypeName: 'dt', + indexName: 'i', + indexValues: ['v2'], + contestantId: 'id', + }); }); }); diff --git a/packages/js-evo-sdk/tests/unit/facades/voting.spec.mjs b/packages/js-evo-sdk/tests/unit/facades/voting.spec.mjs index 796b191fdf8..acbffe35c49 100644 --- a/packages/js-evo-sdk/tests/unit/facades/voting.spec.mjs +++ b/packages/js-evo-sdk/tests/unit/facades/voting.spec.mjs @@ -25,10 +25,10 @@ describe('VotingFacade', () => { contractId: 'c', documentTypeName: 'dt', indexName: 'i', indexValues: ['v1'], resultType: 'rt', }); await client.voting.contestedResourceVoteStateWithProof({ - contractId: 'c', documentTypeName: 'dt', indexName: 'i', indexValues: ['v1'], resultType: 'rt', allowIncludeLockedAndAbstainingVoteTally: true, startAtIdentifierInfo: 's', count: 2, orderAscending: false, + contractId: 'c', documentTypeName: 'dt', indexName: 'i', indexValues: ['v1'], resultType: 'rt', allowIncludeLockedAndAbstainingVoteTally: true, startAtIdentifierInfo: 's', startAtIncluded: true, count: 2, }); await client.voting.contestedResourceIdentityVotes('id', { limit: 3, startAtVotePollIdInfo: 's', orderAscending: true }); - await client.voting.contestedResourceIdentityVotesWithProof('id', { limit: 4, offset: 1, orderAscending: false }); + await client.voting.contestedResourceIdentityVotesWithProof('id', { limit: 4, startAtVotePollIdInfo: 'p', orderAscending: false }); await client.voting.votePollsByEndDate({ startTimeMs: 1000, startTimeIncluded: true, @@ -45,12 +45,52 @@ describe('VotingFacade', () => { offset: 0, orderAscending: false, }); - expect(wasmSdk.getContestedResourceVoteState).to.be.calledOnce(); - expect(wasmSdk.getContestedResourceVoteStateWithProofInfo).to.be.calledOnce(); - expect(wasmSdk.getContestedResourceIdentityVotes).to.be.calledOnce(); - expect(wasmSdk.getContestedResourceIdentityVotesWithProofInfo).to.be.calledOnce(); - expect(wasmSdk.getVotePollsByEndDate).to.be.calledOnce(); - expect(wasmSdk.getVotePollsByEndDateWithProofInfo).to.be.calledOnce(); + expect(wasmSdk.getContestedResourceVoteState).to.be.calledOnceWithExactly({ + dataContractId: 'c', + documentTypeName: 'dt', + indexName: 'i', + indexValues: ['v1'], + resultType: 'rt', + }); + expect(wasmSdk.getContestedResourceVoteStateWithProofInfo).to.be.calledOnceWithExactly({ + dataContractId: 'c', + documentTypeName: 'dt', + indexName: 'i', + indexValues: ['v1'], + resultType: 'rt', + includeLockedAndAbstaining: true, + startAtContenderId: 's', + startAtIncluded: true, + limit: 2, + }); + expect(wasmSdk.getContestedResourceIdentityVotes).to.be.calledOnceWithExactly({ + identityId: 'id', + limit: 3, + startAtVoteId: 's', + orderAscending: true, + }); + expect(wasmSdk.getContestedResourceIdentityVotesWithProofInfo).to.be.calledOnceWithExactly({ + identityId: 'id', + limit: 4, + startAtVoteId: 'p', + orderAscending: false, + }); + expect(wasmSdk.getVotePollsByEndDate).to.be.calledOnceWithExactly({ + startTimeMs: 1000, + startTimeIncluded: true, + endTimeMs: 2000, + endTimeIncluded: false, + limit: 2, + offset: 1, + orderAscending: true, + }); + expect(wasmSdk.getVotePollsByEndDateWithProofInfo).to.be.calledOnceWithExactly({ + startTimeMs: 10, + endTimeMs: 20, + limit: 1, + offset: 0, + orderAscending: false, + }); }); it('masternodeVote() stringifies array indexValues and forwards', async () => { diff --git a/packages/wasm-dpp2/Cargo.toml b/packages/wasm-dpp2/Cargo.toml index 8472da2ae9d..efe3816efef 100644 --- a/packages/wasm-dpp2/Cargo.toml +++ b/packages/wasm-dpp2/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["cdylib", "lib"] talc = { version = "=4.4.2", default-features = false, features = ["lock_api"] } bincode = "=2.0.0-rc.3" bincode_derive = "=2.0.0-rc.3" -wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] } +wasm-bindgen = { version = "=0.2.103", default-features = false, features = ["serde-serialize"] } dpp = { path = "../rs-dpp", default-features = false, features = [ "state-transition-signing", "document-json-conversion", diff --git a/packages/wasm-dpp2/src/voting/contender.rs b/packages/wasm-dpp2/src/voting/contender.rs new file mode 100644 index 00000000000..a4d3826ffe3 --- /dev/null +++ b/packages/wasm-dpp2/src/voting/contender.rs @@ -0,0 +1,69 @@ +use crate::identifier::IdentifierWasm; +use dpp::voting::contender_structs::{ + ContenderWithSerializedDocument, ContenderWithSerializedDocumentV0, +}; +use js_sys::Uint8Array; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone)] +#[wasm_bindgen(js_name = "ContenderWithSerializedDocument")] +pub struct ContenderWithSerializedDocumentWasm(ContenderWithSerializedDocument); + +impl From for ContenderWithSerializedDocumentWasm { + fn from(contender: ContenderWithSerializedDocument) -> Self { + Self(contender) + } +} + +impl From for ContenderWithSerializedDocument { + fn from(contender: ContenderWithSerializedDocumentWasm) -> Self { + contender.0 + } +} + +#[wasm_bindgen(js_class = ContenderWithSerializedDocument)] +impl ContenderWithSerializedDocumentWasm { + #[wasm_bindgen(constructor)] + pub fn new( + identity_id: &IdentifierWasm, + serialized_document: Option>, + vote_tally: Option, + ) -> Self { + let inner = ContenderWithSerializedDocument::V0(ContenderWithSerializedDocumentV0 { + identity_id: (*identity_id).into(), + serialized_document, + vote_tally, + }); + + Self(inner) + } + + #[wasm_bindgen(getter = identityId)] + pub fn identity_id(&self) -> IdentifierWasm { + self.0.identity_id().into() + } + + #[wasm_bindgen(getter = serializedDocument)] + pub fn serialized_document(&self) -> JsValue { + match self.0.serialized_document() { + Some(bytes) => Uint8Array::from(bytes.as_slice()).into(), + None => JsValue::NULL, + } + } + + #[wasm_bindgen(getter = voteTally)] + pub fn vote_tally(&self) -> Option { + self.0.vote_tally() + } +} + +impl ContenderWithSerializedDocumentWasm { + pub fn into_inner(self) -> ContenderWithSerializedDocument { + self.0 + } + + pub fn as_inner(&self) -> &ContenderWithSerializedDocument { + &self.0 + } +} diff --git a/packages/wasm-dpp2/src/voting/winner_info.rs b/packages/wasm-dpp2/src/voting/winner_info.rs new file mode 100644 index 00000000000..645e678a36f --- /dev/null +++ b/packages/wasm-dpp2/src/voting/winner_info.rs @@ -0,0 +1,96 @@ +use crate::identifier::IdentifierWasm; +use dpp::voting::vote_info_storage::contested_document_vote_poll_winner_info::ContestedDocumentVotePollWinnerInfo; +use wasm_bindgen::JsValue; +use wasm_bindgen::prelude::wasm_bindgen; + +#[derive(Clone, Copy)] +#[wasm_bindgen(js_name = "ContestedDocumentVotePollWinnerInfo")] +pub struct ContestedDocumentVotePollWinnerInfoWasm(ContestedDocumentVotePollWinnerInfo); + +impl From for ContestedDocumentVotePollWinnerInfoWasm { + fn from(info: ContestedDocumentVotePollWinnerInfo) -> Self { + Self(info) + } +} + +impl From for ContestedDocumentVotePollWinnerInfo { + fn from(info: ContestedDocumentVotePollWinnerInfoWasm) -> Self { + info.0 + } +} + +#[wasm_bindgen(js_class = ContestedDocumentVotePollWinnerInfo)] +impl ContestedDocumentVotePollWinnerInfoWasm { + #[wasm_bindgen(constructor)] + pub fn new( + kind: &str, + identity_id: Option, + ) -> Result { + match kind { + "none" | "NoWinner" | "NO_WINNER" => { + Ok(ContestedDocumentVotePollWinnerInfo::NoWinner.into()) + } + "identity" | "Identity" | "IDENTITY" => { + let identity = identity_id.ok_or_else(|| { + JsValue::from_str("identityId is required when kind is 'identity'") + })?; + + Ok(ContestedDocumentVotePollWinnerInfo::WonByIdentity(identity.into()).into()) + } + "locked" | "Locked" | "LOCKED" => { + Ok(ContestedDocumentVotePollWinnerInfo::Locked.into()) + } + other => Err(JsValue::from_str(&format!( + "Unsupported winner info kind '{}'", + other + ))), + } + } + + #[wasm_bindgen(getter = kind)] + pub fn kind(&self) -> String { + match self.0 { + ContestedDocumentVotePollWinnerInfo::NoWinner => "none".to_string(), + ContestedDocumentVotePollWinnerInfo::WonByIdentity(_) => "identity".to_string(), + ContestedDocumentVotePollWinnerInfo::Locked => "locked".to_string(), + } + } + + #[wasm_bindgen(getter = identityId)] + pub fn identity_id(&self) -> Option { + match self.0 { + ContestedDocumentVotePollWinnerInfo::WonByIdentity(identifier) => { + Some(identifier.into()) + } + _ => None, + } + } + + #[wasm_bindgen(js_name = "isLocked")] + pub fn is_locked(&self) -> bool { + matches!(self.0, ContestedDocumentVotePollWinnerInfo::Locked) + } + + #[wasm_bindgen(js_name = "isWonByIdentity")] + pub fn is_won_by_identity(&self) -> bool { + matches!( + self.0, + ContestedDocumentVotePollWinnerInfo::WonByIdentity(_) + ) + } + + #[wasm_bindgen(js_name = "isNoWinner")] + pub fn is_no_winner(&self) -> bool { + matches!(self.0, ContestedDocumentVotePollWinnerInfo::NoWinner) + } +} + +impl ContestedDocumentVotePollWinnerInfoWasm { + pub fn into_inner(self) -> ContestedDocumentVotePollWinnerInfo { + self.0 + } + + pub fn as_inner(&self) -> ContestedDocumentVotePollWinnerInfo { + self.0 + } +} diff --git a/packages/wasm-sdk/src/queries/voting/polls.rs b/packages/wasm-sdk/src/queries/voting/polls.rs index 0964444d74a..8d08b4c90fb 100644 --- a/packages/wasm-sdk/src/queries/voting/polls.rs +++ b/packages/wasm-sdk/src/queries/voting/polls.rs @@ -12,6 +12,62 @@ use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; use wasm_dpp2::VotePollWasm; +#[wasm_bindgen(typescript_custom_section)] +const VOTE_POLLS_BY_END_DATE_QUERY_TS: &'static str = r#" +/** + * Query parameters for retrieving vote polls grouped by end date. + */ +export interface VotePollsByEndDateQuery { + /** + * Starting timestamp (milliseconds) to filter polls. + * @default undefined + */ + startTimeMs?: number; + + /** + * Include the `startTimeMs` boundary when true. + * @default true + */ + startTimeIncluded?: boolean; + + /** + * Ending timestamp (milliseconds) to filter polls. + * @default undefined + */ + endTimeMs?: number; + + /** + * Include the `endTimeMs` boundary when true. + * @default true + */ + endTimeIncluded?: boolean; + + /** + * Maximum number of buckets to return. + * @default undefined (no explicit limit) + */ + limit?: number; + + /** + * Offset into the paginated result set. + * @default undefined + */ + offset?: number; + + /** + * Sort order for timestamps; ascending by default. + * @default true + */ + orderAscending?: boolean; +} +"#; + +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(typescript_type = "VotePollsByEndDateQuery")] + pub type VotePollsByEndDateQueryJs; +} + fn timestamp_from_option( value: Option, field: &str, @@ -58,18 +114,6 @@ fn convert_limit(limit: Option, field: &str) -> Result, WasmSdk } } -#[derive(Default, Deserialize)] -#[serde(rename_all = "camelCase")] -struct VotePollsByEndDateQueryOptions { - start_time_ms: Option, - start_time_included: Option, - end_time_ms: Option, - end_time_included: Option, - limit: Option, - offset: Option, - order_ascending: Option, -} - #[wasm_bindgen(js_name = "VotePollsByEndDateQuery")] pub struct VotePollsByEndDateQueryWasm(VotePollsByEndDateDriveQuery); @@ -79,98 +123,29 @@ impl VotePollsByEndDateQueryWasm { } } -#[wasm_bindgen(js_name = "VotePollsByEndDateQueryBuilder")] -pub struct VotePollsByEndDateQueryBuilder { - start_time: Option<(TimestampMillis, TimestampIncluded)>, - end_time: Option<(TimestampMillis, TimestampIncluded)>, - limit: Option, - offset: Option, - order_ascending: bool, -} - -#[wasm_bindgen(js_class = VotePollsByEndDateQueryBuilder)] -impl VotePollsByEndDateQueryBuilder { - #[wasm_bindgen(constructor)] - pub fn new() -> VotePollsByEndDateQueryBuilder { - Self { - start_time: None, - end_time: None, - limit: None, - offset: None, - order_ascending: true, - } - } - - #[wasm_bindgen(js_name = "withStartTime")] - pub fn with_start_time( - mut self, - timestamp_ms: Option, - included: bool, - ) -> Result { - self.start_time = timestamp_from_option(timestamp_ms, "startTimeMs")? - .map(|timestamp| (timestamp, included)); - Ok(self) - } - - #[wasm_bindgen(js_name = "withEndTime")] - pub fn with_end_time( - mut self, - timestamp_ms: Option, - included: bool, - ) -> Result { - self.end_time = timestamp_from_option(timestamp_ms, "endTimeMs")? - .map(|timestamp| (timestamp, included)); - Ok(self) - } - - #[wasm_bindgen(js_name = "withLimit")] - pub fn with_limit( - mut self, - limit: Option, - ) -> Result { - self.limit = convert_limit(limit, "limit")?; - Ok(self) - } - - #[wasm_bindgen(js_name = "withOffset")] - pub fn with_offset( - mut self, - offset: Option, - ) -> Result { - self.offset = convert_limit(offset, "offset")?; - Ok(self) - } - - #[wasm_bindgen(js_name = "withOrderAscending")] - pub fn with_order_ascending(mut self, ascending: bool) -> VotePollsByEndDateQueryBuilder { - self.order_ascending = ascending; - self - } - - #[wasm_bindgen(js_name = "build")] - pub fn build(self) -> VotePollsByEndDateQueryWasm { - let VotePollsByEndDateQueryBuilder { - start_time, - end_time, - limit, - offset, - order_ascending, - } = self; - - VotePollsByEndDateQueryWasm(VotePollsByEndDateDriveQuery { - start_time, - end_time, - limit, - offset, - order_ascending, - }) - } +#[derive(Default, Deserialize)] +#[serde(rename_all = "camelCase")] +struct VotePollsByEndDateQueryInput { + #[serde(default)] + start_time_ms: Option, + #[serde(default)] + start_time_included: Option, + #[serde(default)] + end_time_ms: Option, + #[serde(default)] + end_time_included: Option, + #[serde(default)] + limit: Option, + #[serde(default)] + offset: Option, + #[serde(default)] + order_ascending: Option, } -fn build_query_from_options( - opts: VotePollsByEndDateQueryOptions, +fn build_vote_polls_by_end_date_drive_query( + input: VotePollsByEndDateQueryInput, ) -> Result { - let VotePollsByEndDateQueryOptions { + let VotePollsByEndDateQueryInput { start_time_ms, start_time_included, end_time_ms, @@ -178,7 +153,7 @@ fn build_query_from_options( limit, offset, order_ascending, - } = opts; + } = input; if start_time_ms.is_none() && start_time_included.is_some() { return Err(WasmSdkError::invalid_argument( @@ -192,47 +167,50 @@ fn build_query_from_options( )); } - let mut builder = VotePollsByEndDateQueryBuilder::new(); - - if start_time_ms.is_some() || start_time_included.is_some() { - builder = builder.with_start_time(start_time_ms, start_time_included.unwrap_or(true))?; - } - - if end_time_ms.is_some() || end_time_included.is_some() { - builder = builder.with_end_time(end_time_ms, end_time_included.unwrap_or(true))?; - } - - if limit.is_some() { - builder = builder.with_limit(limit)?; - } + let start_time = timestamp_from_option(start_time_ms, "startTimeMs")? + .map(|timestamp| (timestamp, start_time_included.unwrap_or(true))); - if offset.is_some() { - builder = builder.with_offset(offset)?; - } + let end_time = timestamp_from_option(end_time_ms, "endTimeMs")? + .map(|timestamp| (timestamp, end_time_included.unwrap_or(true))); - if let Some(order) = order_ascending { - builder = builder.with_order_ascending(order); - } + let limit = convert_limit(limit, "limit")?; + let offset = convert_limit(offset, "offset")?; - Ok(builder.build()) + Ok(VotePollsByEndDateQueryWasm(VotePollsByEndDateDriveQuery { + start_time, + end_time, + limit, + offset, + order_ascending: order_ascending.unwrap_or(true), + })) } -#[wasm_bindgen(js_name = "buildVotePollsByEndDateQuery")] -pub fn build_vote_polls_by_end_date_query( - options: JsValue, +fn parse_vote_polls_by_end_date_query( + query: Option, ) -> Result { - let opts = if options.is_null() || options.is_undefined() { - VotePollsByEndDateQueryOptions::default() + let value: JsValue = query + .map(Into::into) + .unwrap_or(JsValue::UNDEFINED); + + let input: VotePollsByEndDateQueryInput = if value.is_null() || value.is_undefined() { + VotePollsByEndDateQueryInput::default() } else { - serde_wasm_bindgen::from_value(options).map_err(|err| { + serde_wasm_bindgen::from_value(value).map_err(|err| { WasmSdkError::invalid_argument(format!( - "Invalid vote polls by end date options: {}", + "Invalid vote polls by end date query: {}", err )) })? }; - build_query_from_options(opts) + build_vote_polls_by_end_date_drive_query(input) +} + +#[wasm_bindgen(js_name = "buildVotePollsByEndDateQuery")] +pub fn build_vote_polls_by_end_date_query( + query: Option, +) -> Result { + parse_vote_polls_by_end_date_query(query) } #[derive(Clone)] @@ -330,10 +308,10 @@ impl WasmSdk { #[wasm_bindgen(js_name = "getVotePollsByEndDate")] pub async fn get_vote_polls_by_end_date( &self, - options: JsValue, + query: Option, ) -> Result { - let query = build_vote_polls_by_end_date_query(options)?; - self.fetch_vote_polls_by_end_date(query).await + let drive_query = parse_vote_polls_by_end_date_query(query)?; + self.fetch_vote_polls_by_end_date(drive_query).await } #[wasm_bindgen(js_name = "getVotePollsByEndDateWithQuery")] @@ -347,10 +325,10 @@ impl WasmSdk { #[wasm_bindgen(js_name = "getVotePollsByEndDateWithProofInfo")] pub async fn get_vote_polls_by_end_date_with_proof_info( &self, - options: JsValue, + query: Option, ) -> Result { - let query = build_vote_polls_by_end_date_query(options)?; - self.get_vote_polls_by_end_date_with_proof_info_query(query) + let drive_query = parse_vote_polls_by_end_date_query(query)?; + self.get_vote_polls_by_end_date_with_proof_info_query(drive_query) .await } diff --git a/packages/wasm-sdk/src/queries/voting/resources.rs b/packages/wasm-sdk/src/queries/voting/resources.rs index 0d554500a1a..b763d705010 100644 --- a/packages/wasm-sdk/src/queries/voting/resources.rs +++ b/packages/wasm-sdk/src/queries/voting/resources.rs @@ -2,147 +2,233 @@ use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; use crate::utils::{js_value_to_platform_value, js_values_to_platform_values}; use crate::WasmSdkError; +use dash_sdk::dpp::platform_value::{string_encoding::Encoding, Identifier}; use dash_sdk::platform::FetchMany; use drive::query::vote_polls_by_document_type_query::VotePollsByDocumentTypeQuery; -use drive_proof_verifier::types::ContestedResource; +use drive_proof_verifier::types::{ContestedResource, ContestedResources}; use js_sys::Array; -use platform_value::{Identifier, Value}; +use serde::Deserialize; +use serde_json::Value as JsonValue; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; -#[wasm_bindgen(js_name = "VotePollsByDocumentTypeQuery")] -pub struct VotePollsByDocumentTypeQueryWasm(VotePollsByDocumentTypeQuery); +#[wasm_bindgen(typescript_custom_section)] +const VOTE_POLLS_BY_DOCUMENT_TYPE_QUERY_TS: &'static str = r#" +/** + * Query configuration for contested resource listings. + */ +export interface VotePollsByDocumentTypeQuery { + /** + * Data contract identifier (base58 string). + */ + dataContractId: string; -impl VotePollsByDocumentTypeQueryWasm { - pub(crate) fn into_inner(self) -> VotePollsByDocumentTypeQuery { - self.0 - } + /** + * Document type to query. + */ + documentTypeName: string; + + /** + * Index name to query. + */ + indexName: string; + + /** + * Optional lower bound for index range, commonly an array of composite values. + * @default undefined + */ + startIndexValues?: unknown[]; + + /** + * Optional upper bound for index range, commonly an array of composite values. + * @default undefined + */ + endIndexValues?: unknown[]; + + /** + * Cursor value to resume iteration from. + * Provide a JS value matching the index schema (e.g., string, number, array). + * @default undefined + */ + startAtValue?: unknown; + + /** + * Whether to include `startAtValue` in the result set. + * @default true + */ + startAtValueIncluded?: boolean; + + /** + * Maximum number of records to return. + * @default undefined (no explicit limit) + */ + limit?: number; + + /** + * Sort order. When omitted, the query defaults to ascending order. + * @default true + */ + orderAscending?: boolean; +} +"#; + +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(typescript_type = "VotePollsByDocumentTypeQuery")] + pub type VotePollsByDocumentTypeQueryJs; } -#[wasm_bindgen(js_name = "VotePollsByDocumentTypeQueryBuilder")] -pub struct VotePollsByDocumentTypeQueryBuilder { - contract_id: Identifier, +#[derive(Default, Deserialize)] +#[serde(rename_all = "camelCase")] +struct VotePollsByDocumentTypeFilters { + #[serde(default)] + start_index_values: Option>, + #[serde(default)] + end_index_values: Option>, + #[serde(default)] + start_at_value: Option, + #[serde(default)] + start_at_value_included: Option, + #[serde(default)] + limit: Option, + #[serde(default)] + order_ascending: Option, +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +struct VotePollsByDocumentTypeQueryInput { + data_contract_id: String, document_type_name: String, index_name: String, - start_index_values: Vec, - end_index_values: Vec, - start_at_value: Option<(Value, bool)>, - limit: Option, - order_ascending: bool, + #[serde(flatten)] + filters: VotePollsByDocumentTypeFilters, } -#[wasm_bindgen(js_class = VotePollsByDocumentTypeQueryBuilder)] -impl VotePollsByDocumentTypeQueryBuilder { - #[wasm_bindgen(constructor)] - pub fn new( - data_contract_id: &str, - document_type_name: &str, - index_name: &str, - ) -> Result { - let contract_id = Identifier::from_string( - data_contract_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; - - Ok(Self { - contract_id, - document_type_name: document_type_name.to_string(), - index_name: index_name.to_string(), - start_index_values: Vec::new(), - end_index_values: Vec::new(), - start_at_value: None, - limit: None, - order_ascending: true, - }) - } +fn create_vote_polls_by_document_type_query( + query: VotePollsByDocumentTypeQueryInput, +) -> Result { + let VotePollsByDocumentTypeQueryInput { + data_contract_id, + document_type_name, + index_name, + filters: + VotePollsByDocumentTypeFilters { + start_index_values, + end_index_values, + start_at_value, + start_at_value_included, + limit, + order_ascending, + }, + } = query; - #[wasm_bindgen(js_name = "withStartIndexValues")] - pub fn with_start_index_values( - mut self, - values: Vec, - ) -> Result { - self.start_index_values = js_values_to_platform_values(values)?; - Ok(self) - } + let start_index_values_js: Vec = start_index_values + .unwrap_or_default() + .into_iter() + .map(|value| { + serde_wasm_bindgen::to_value(&value).map_err(|err| { + WasmSdkError::invalid_argument(format!( + "Invalid startIndexValues entry: {}", + err + )) + }) + }) + .collect::, _>>()?; + let start_index_values = js_values_to_platform_values(start_index_values_js)?; - #[wasm_bindgen(js_name = "withEndIndexValues")] - pub fn with_end_index_values( - mut self, - values: Vec, - ) -> Result { - self.end_index_values = js_values_to_platform_values(values)?; - Ok(self) - } + let end_index_values_js: Vec = end_index_values + .unwrap_or_default() + .into_iter() + .map(|value| { + serde_wasm_bindgen::to_value(&value).map_err(|err| { + WasmSdkError::invalid_argument(format!( + "Invalid endIndexValues entry: {}", + err + )) + }) + }) + .collect::, _>>()?; + let end_index_values = js_values_to_platform_values(end_index_values_js)?; - #[wasm_bindgen(js_name = "withStartAtValue")] - pub fn with_start_at_value( - mut self, - value: JsValue, - included: bool, - ) -> Result { - if value.is_null() || value.is_undefined() { - self.start_at_value = None; - } else { + let start_at_value = match start_at_value { + Some(value) => { + let value = serde_wasm_bindgen::to_value(&value).map_err(|err| { + WasmSdkError::invalid_argument(format!( + "Invalid startAtValue entry: {}", + err + )) + })?; let platform_value = js_value_to_platform_value(value)?; - self.start_at_value = Some((platform_value, included)); + Some((platform_value, start_at_value_included.unwrap_or(true))) } - Ok(self) - } + None => None, + }; - #[wasm_bindgen(js_name = "withLimit")] - pub fn with_limit( - mut self, - limit: Option, - ) -> Result { - self.limit = match limit { - Some(0) => None, - Some(count) => { - if count > u16::MAX as u32 { - return Err(WasmSdkError::invalid_argument(format!( - "limit {} exceeds maximum of {}", - count, - u16::MAX - ))); - } - Some(count as u16) + let limit = match limit { + Some(0) => None, + Some(value) => { + if value > u16::MAX as u32 { + return Err(WasmSdkError::invalid_argument(format!( + "limit {} exceeds maximum of {}", + value, + u16::MAX + ))); } - None => None, - }; - Ok(self) - } + Some(value as u16) + } + None => None, + }; - #[wasm_bindgen(js_name = "withOrderAscending")] - pub fn with_order_ascending( - mut self, - order_ascending: bool, - ) -> VotePollsByDocumentTypeQueryBuilder { - self.order_ascending = order_ascending; - self + let contract_id = Identifier::from_string( + &data_contract_id, + Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; + + Ok(VotePollsByDocumentTypeQuery { + contract_id, + document_type_name, + index_name, + start_index_values, + end_index_values, + start_at_value, + limit, + order_ascending: order_ascending.unwrap_or(true), + }) +} + +fn contested_resources_into_wasm( + contested_resources: ContestedResources, +) -> Result { + let array = Array::new(); + + for resource in contested_resources.0 { + let js_value = serde_wasm_bindgen::to_value(&resource.0).map_err(|e| { + WasmSdkError::serialization(format!( + "Failed to serialize contested resource value: {}", + e + )) + })?; + array.push(&js_value); } - #[wasm_bindgen(js_name = "build")] - pub fn build(self) -> VotePollsByDocumentTypeQueryWasm { - let VotePollsByDocumentTypeQueryBuilder { - contract_id, - document_type_name, - index_name, - start_index_values, - end_index_values, - start_at_value, - limit, - order_ascending, - } = self; - - VotePollsByDocumentTypeQueryWasm(VotePollsByDocumentTypeQuery { - contract_id, - document_type_name, - index_name, - start_index_values, - end_index_values, - start_at_value, - limit, - order_ascending, + Ok(array) +} + +fn parse_vote_polls_by_document_type_query( + query: JsValue, +) -> Result { + if query.is_null() || query.is_undefined() { + return Err(WasmSdkError::invalid_argument( + "Query object is required".to_string(), + )); + } else { + serde_wasm_bindgen::from_value(query).map_err(|err| { + WasmSdkError::invalid_argument(format!( + "Invalid vote polls by document type options: {}", + err + )) }) } } @@ -152,21 +238,15 @@ impl WasmSdk { #[wasm_bindgen(js_name = "getContestedResources")] pub async fn get_contested_resources( &self, - query: VotePollsByDocumentTypeQueryWasm, + query: VotePollsByDocumentTypeQueryJs, ) -> Result { - let contested_resources = - ContestedResource::fetch_many(self.as_ref(), query.into_inner()).await?; - - let array = Array::new(); - for resource in contested_resources.0 { - let js_value = serde_wasm_bindgen::to_value(&resource.0).map_err(|e| { - WasmSdkError::serialization(format!( - "Failed to serialize contested resource value: {}", - e - )) - })?; - array.push(&js_value); - } + let query_value: JsValue = query.into(); + let query = parse_vote_polls_by_document_type_query(query_value) + .and_then(create_vote_polls_by_document_type_query)?; + + let contested_resources = ContestedResource::fetch_many(self.as_ref(), query).await?; + + let array = contested_resources_into_wasm(contested_resources)?; Ok(array) } @@ -175,28 +255,20 @@ impl WasmSdk { #[wasm_bindgen(js_name = "getContestedResourcesWithProofInfo")] pub async fn get_contested_resources_with_proof_info( &self, - query: VotePollsByDocumentTypeQueryWasm, - ) -> Result { + query: VotePollsByDocumentTypeQueryJs, + ) -> Result { + let query_value: JsValue = query.into(); + let query = parse_vote_polls_by_document_type_query(query_value) + .and_then(create_vote_polls_by_document_type_query)?; + let (contested_resources, metadata, proof) = - ContestedResource::fetch_many_with_metadata_and_proof( - self.as_ref(), - query.into_inner(), - None, - ) - .await?; - - let resources: Vec = contested_resources - .0 - .into_iter() - .map(|resource| resource.0) - .collect(); - - let data = serde_wasm_bindgen::to_value(&resources).map_err(|e| { - WasmSdkError::serialization(format!("Failed to serialize contested resources: {}", e)) - })?; + ContestedResource::fetch_many_with_metadata_and_proof(self.as_ref(), query, None) + .await?; + + let array = contested_resources_into_wasm(contested_resources)?; - let response = ProofMetadataResponseWasm::from_parts(data, metadata.into(), proof.into()); + let response = ProofMetadataResponseWasm::from_sdk_parts(array, metadata, proof); - Ok(JsValue::from(response)) + Ok(response) } } diff --git a/packages/wasm-sdk/src/queries/voting/state.rs b/packages/wasm-sdk/src/queries/voting/state.rs index 1ad8b39b85e..0175cb96b5e 100644 --- a/packages/wasm-sdk/src/queries/voting/state.rs +++ b/packages/wasm-sdk/src/queries/voting/state.rs @@ -8,28 +8,94 @@ use drive::query::vote_poll_vote_state_query::{ use drive_proof_verifier::types::Contenders; use js_sys::Array; use platform_value::Identifier; +use serde::Deserialize; +use serde_json::Value as JsonValue; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; use wasm_dpp2::block::BlockInfoWasm; use wasm_dpp2::identifier::IdentifierWasm; use wasm_dpp2::{ContenderWithSerializedDocumentWasm, ContestedDocumentVotePollWinnerInfoWasm}; -type ContestedResourceVoteWinnerBlockWasm = BlockInfoWasm; use crate::sdk::WasmSdk; use crate::utils::js_values_to_platform_values; use crate::{ProofMetadataResponseWasm, WasmSdkError}; +#[wasm_bindgen(typescript_custom_section)] +const CONTESTED_RESOURCE_VOTE_STATE_QUERY_TS: &'static str = r#" +/** + * Query configuration for contested resource vote state. + */ +export interface ContestedResourceVoteStateQuery { + /** + * Data contract identifier (base58 string). + */ + dataContractId: string; + + /** + * Contested document type name. + */ + documentTypeName: string; + + /** + * Index name to query. + */ + indexName: string; + + /** + * Optional index values used as query parameters. + * @default undefined + */ + indexValues?: unknown[]; + + /** + * Result projection type. + * @default 'documentsAndVoteTally' + */ + resultType?: 'documents' | 'voteTally' | 'documentsAndVoteTally'; + + /** + * Maximum number of records to return. + * @default undefined (no explicit limit) + */ + limit?: number; + + /** + * Contender identifier to resume from (exclusive by default). + * @default undefined + */ + startAtContenderId?: string; + + /** + * Include the start contender when true. + * @default true + */ + startAtIncluded?: boolean; + + /** + * Include locked and abstaining tallies when true. + * @default false + */ + includeLockedAndAbstaining?: boolean; +} +"#; + +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(typescript_type = "ContestedResourceVoteStateQuery")] + pub type ContestedResourceVoteStateQueryJs; +} + #[wasm_bindgen(js_name = "ContestedResourceVoteWinner")] #[derive(Clone)] pub struct ContestedResourceVoteWinnerWasm { info: ContestedDocumentVotePollWinnerInfoWasm, - block: ContestedResourceVoteWinnerBlockWasm, + block: BlockInfoWasm, } impl ContestedResourceVoteWinnerWasm { fn from_parts( info: ContestedDocumentVotePollWinnerInfo, - block: ContestedResourceVoteWinnerBlockWasm, + block: BlockInfoWasm, ) -> Self { Self { info: info.into(), @@ -51,7 +117,7 @@ impl ContestedResourceVoteWinnerWasm { } #[wasm_bindgen(getter = block)] - pub fn block(&self) -> ContestedResourceVoteWinnerBlockWasm { + pub fn block(&self) -> BlockInfoWasm { self.block.clone() } @@ -103,10 +169,14 @@ impl ContestedResourceContenderWasm { #[wasm_bindgen(js_name = "ContestedResourceVoteState")] #[derive(Clone)] pub struct ContestedResourceVoteStateWasm { - contenders: Vec, - lock_vote_tally: Option, - abstain_vote_tally: Option, - winner: Option, + #[wasm_bindgen(getter_with_clone)] + pub contenders: Array, + #[wasm_bindgen(getter_with_clone, js_name = "lockVoteTally")] + pub lock_vote_tally: Option, + #[wasm_bindgen(getter_with_clone, js_name = "abstainVoteTally")] + pub abstain_vote_tally: Option, + #[wasm_bindgen(getter_with_clone)] + pub winner: Option, } impl ContestedResourceVoteStateWasm { @@ -116,8 +186,13 @@ impl ContestedResourceVoteStateWasm { abstain_vote_tally: Option, winner: Option, ) -> Self { + let array = Array::new(); + for contender in contenders { + array.push(&JsValue::from(contender)); + } + Self { - contenders, + contenders: array, lock_vote_tally, abstain_vote_tally, winner, @@ -125,33 +200,6 @@ impl ContestedResourceVoteStateWasm { } } -#[wasm_bindgen(js_class = ContestedResourceVoteState)] -impl ContestedResourceVoteStateWasm { - #[wasm_bindgen(getter = contenders)] - pub fn contenders(&self) -> Array { - let array = Array::new(); - for contender in &self.contenders { - array.push(&JsValue::from(contender.clone())); - } - array - } - - #[wasm_bindgen(getter = lockVoteTally)] - pub fn lock_vote_tally(&self) -> Option { - self.lock_vote_tally - } - - #[wasm_bindgen(getter = abstainVoteTally)] - pub fn abstain_vote_tally(&self) -> Option { - self.abstain_vote_tally - } - - #[wasm_bindgen(getter = winner)] - pub fn winner(&self) -> Option { - self.winner.clone() - } -} - #[wasm_bindgen(js_name = "ContestedResourceVoteStateQuery")] pub struct ContestedResourceVoteStateQueryWasm(ContestedDocumentVotePollDriveQuery); @@ -159,143 +207,176 @@ impl ContestedResourceVoteStateQueryWasm { pub(crate) fn into_inner(self) -> ContestedDocumentVotePollDriveQuery { self.0 } -} -#[wasm_bindgen(js_name = "ContestedResourceVoteStateQueryBuilder")] -pub struct ContestedResourceVoteStateQueryBuilder { - vote_poll: ContestedDocumentResourceVotePoll, - result_type: ContestedDocumentVotePollDriveQueryResultType, - limit: Option, - start_at: Option<([u8; 32], bool)>, - allow_include_locked_and_abstaining_vote_tally: bool, + pub(crate) fn from_query(query: ContestedDocumentVotePollDriveQuery) -> Self { + Self(query) + } } -#[wasm_bindgen(js_class = ContestedResourceVoteStateQueryBuilder)] -impl ContestedResourceVoteStateQueryBuilder { - #[wasm_bindgen(constructor)] - pub fn new( - data_contract_id: &str, - document_type_name: &str, - index_name: &str, - ) -> Result { - let contract_id = Identifier::from_string( - data_contract_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; - - Ok(Self { - vote_poll: ContestedDocumentResourceVotePoll { - contract_id, - document_type_name: document_type_name.to_string(), - index_name: index_name.to_string(), - index_values: Vec::new(), - }, - result_type: ContestedDocumentVotePollDriveQueryResultType::DocumentsAndVoteTally, - limit: None, - start_at: None, - allow_include_locked_and_abstaining_vote_tally: false, - }) - } +#[derive(Default, Deserialize)] +#[serde(rename_all = "camelCase")] +struct ContestedResourceVoteStateQueryFields { + #[serde(default)] + index_values: Option>, + #[serde(default)] + result_type: Option, + #[serde(default)] + limit: Option, + #[serde(default)] + start_at_contender_id: Option, + #[serde(default)] + start_at_included: Option, + #[serde(default)] + include_locked_and_abstaining: Option, +} - #[wasm_bindgen(js_name = "withIndexValues")] - pub fn with_index_values( - mut self, - values: Vec, - ) -> Result { - self.vote_poll.index_values = js_values_to_platform_values(values)?; - Ok(self) - } +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +struct ContestedResourceVoteStateQueryInput { + data_contract_id: String, + document_type_name: String, + index_name: String, + #[serde(flatten)] + fields: ContestedResourceVoteStateQueryFields, +} - #[wasm_bindgen(js_name = "withResultType")] - pub fn with_result_type( - mut self, - result_type: &str, - ) -> Result { - self.result_type = match result_type { - "documents" | "DOCUMENTS" => ContestedDocumentVotePollDriveQueryResultType::Documents, - "voteTally" | "VOTE_TALLY" => ContestedDocumentVotePollDriveQueryResultType::VoteTally, +fn parse_vote_state_result_type( + result_type: Option, +) -> Result { + match result_type { + None => Ok(ContestedDocumentVotePollDriveQueryResultType::DocumentsAndVoteTally), + Some(value) => match value.as_str() { + "documents" | "DOCUMENTS" => Ok(ContestedDocumentVotePollDriveQueryResultType::Documents), + "voteTally" | "VOTE_TALLY" => Ok(ContestedDocumentVotePollDriveQueryResultType::VoteTally), "documentsAndVoteTally" | "DOCUMENTS_AND_VOTE_TALLY" => { - ContestedDocumentVotePollDriveQueryResultType::DocumentsAndVoteTally - } - other => { - return Err(WasmSdkError::invalid_argument(format!( - "Unsupported result type '{}'", - other - ))) + Ok(ContestedDocumentVotePollDriveQueryResultType::DocumentsAndVoteTally) } - }; - Ok(self) + other => Err(WasmSdkError::invalid_argument(format!( + "Unsupported result type '{}'", + other + ))), + }, } +} - #[wasm_bindgen(js_name = "withLimit")] - pub fn with_limit( - mut self, - limit: Option, - ) -> Result { - self.limit = match limit { - Some(0) => None, - Some(count) => { - if count > u16::MAX as u32 { - return Err(WasmSdkError::invalid_argument(format!( - "limit {} exceeds maximum of {}", - count, - u16::MAX - ))); - } - Some(count as u16) +fn convert_limit(limit: Option) -> Result, WasmSdkError> { + match limit { + Some(0) => Ok(None), + Some(value) => { + if value > u16::MAX as u32 { + return Err(WasmSdkError::invalid_argument(format!( + "limit {} exceeds maximum of {}", + value, + u16::MAX + ))); } - None => None, - }; - Ok(self) - } - #[wasm_bindgen(js_name = "withStartAtContender")] - pub fn with_start_at_contender( - mut self, - contender_id: &str, - included: bool, - ) -> Result { - let identifier = Identifier::from_string( - contender_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contender ID: {}", e)))?; - - self.start_at = Some((identifier.to_buffer(), included)); - Ok(self) + Ok(Some(value as u16)) + } + None => Ok(None), } +} - #[wasm_bindgen(js_name = "withIncludeLockedAndAbstaining")] - pub fn with_include_locked_and_abstaining( - mut self, - include: bool, - ) -> ContestedResourceVoteStateQueryBuilder { - self.allow_include_locked_and_abstaining_vote_tally = include; - self - } +fn create_contested_resource_vote_state_query( + query: ContestedResourceVoteStateQueryInput, +) -> Result { + let ContestedResourceVoteStateQueryInput { + data_contract_id, + document_type_name, + index_name, + fields: + ContestedResourceVoteStateQueryFields { + index_values, + result_type, + limit, + start_at_contender_id, + start_at_included, + include_locked_and_abstaining, + }, + } = query; + + let index_values: Vec = index_values + .unwrap_or_default() + .into_iter() + .map(|value| { + serde_wasm_bindgen::to_value(&value).map_err(|err| { + WasmSdkError::invalid_argument(format!( + "Invalid indexValues entry: {}", + err + )) + }) + }) + .collect::, _>>()?; + let index_values = js_values_to_platform_values(index_values)?; + + let contract_id = Identifier::from_string( + &data_contract_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; + + let result_type = parse_vote_state_result_type(result_type)?; + let limit = convert_limit(limit)?; + + let start_at = match start_at_contender_id { + Some(contender_id) => { + let identifier = Identifier::from_string( + &contender_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contender ID: {}", e)))?; - #[wasm_bindgen(js_name = "build")] - pub fn build(self) -> ContestedResourceVoteStateQueryWasm { - let ContestedResourceVoteStateQueryBuilder { - vote_poll, - result_type, - limit, - start_at, - allow_include_locked_and_abstaining_vote_tally, - } = self; - - ContestedResourceVoteStateQueryWasm(ContestedDocumentVotePollDriveQuery { - vote_poll, - result_type, - offset: None, - limit, - start_at, - allow_include_locked_and_abstaining_vote_tally, + Some((identifier.to_buffer(), start_at_included.unwrap_or(true))) + } + None => None, + }; + + let allow_include_locked_and_abstaining_vote_tally = + include_locked_and_abstaining.unwrap_or(false); + + Ok(ContestedDocumentVotePollDriveQuery { + vote_poll: ContestedDocumentResourceVotePoll { + contract_id, + document_type_name, + index_name, + index_values, + }, + result_type, + offset: None, + limit, + start_at, + allow_include_locked_and_abstaining_vote_tally, + }) +} + +fn parse_contested_resource_vote_state_query( + query: JsValue, +) -> Result { + if query.is_null() || query.is_undefined() { + return Err(WasmSdkError::invalid_argument( + "Query object is required".to_string(), + )); + } else { + serde_wasm_bindgen::from_value(query).map_err(|err| { + WasmSdkError::invalid_argument(format!( + "Invalid contested resource vote state query: {}", + err + )) }) } } +#[wasm_bindgen(js_name = "buildContestedResourceVoteStateQuery")] +pub fn build_contested_resource_vote_state_query( + query: ContestedResourceVoteStateQueryJs, +) -> Result { + let query_value: JsValue = query.into(); + let query = parse_contested_resource_vote_state_query(query_value) + .and_then(create_contested_resource_vote_state_query)?; + + Ok(ContestedResourceVoteStateQueryWasm::from_query(query)) +} + fn convert_contenders(contenders: Contenders) -> ContestedResourceVoteStateWasm { let Contenders { winner, @@ -320,21 +401,51 @@ fn convert_contenders(contenders: Contenders) -> ContestedResourceVoteStateWasm #[wasm_bindgen] impl WasmSdk { + async fn fetch_contested_resource_vote_state( + &self, + query: ContestedDocumentVotePollDriveQuery, + ) -> Result { + let contenders = + ContenderWithSerializedDocument::fetch_many(self.as_ref(), query).await?; + + Ok(convert_contenders(contenders)) + } + #[wasm_bindgen(js_name = "getContestedResourceVoteState")] pub async fn get_contested_resource_vote_state( &self, - query: ContestedResourceVoteStateQueryWasm, + query: ContestedResourceVoteStateQueryJs, ) -> Result { - let contenders = - ContenderWithSerializedDocument::fetch_many(self.as_ref(), query.into_inner()).await?; + let query_value: JsValue = query.into(); + let query = parse_contested_resource_vote_state_query(query_value) + .and_then(create_contested_resource_vote_state_query)?; - let state = convert_contenders(contenders); + self.fetch_contested_resource_vote_state(query).await + } - Ok(state) + #[wasm_bindgen(js_name = "getContestedResourceVoteStateWithQuery")] + pub async fn get_contested_resource_vote_state_with_query( + &self, + query: ContestedResourceVoteStateQueryWasm, + ) -> Result { + self.fetch_contested_resource_vote_state(query.into_inner()).await } #[wasm_bindgen(js_name = "getContestedResourceVoteStateWithProofInfo")] pub async fn get_contested_resource_vote_state_with_proof_info( + &self, + query: ContestedResourceVoteStateQueryJs, + ) -> Result { + let query_value: JsValue = query.into(); + let query = parse_contested_resource_vote_state_query(query_value) + .and_then(create_contested_resource_vote_state_query)?; + + self.get_contested_resource_vote_state_with_proof_info_query(ContestedResourceVoteStateQueryWasm::from_query(query)) + .await + } + + #[wasm_bindgen(js_name = "getContestedResourceVoteStateWithProofInfoQuery")] + pub async fn get_contested_resource_vote_state_with_proof_info_query( &self, query: ContestedResourceVoteStateQueryWasm, ) -> Result { @@ -348,10 +459,10 @@ impl WasmSdk { let state = convert_contenders(contenders); - Ok(ProofMetadataResponseWasm::from_parts( + Ok(ProofMetadataResponseWasm::from_sdk_parts( JsValue::from(state), - metadata.into(), - proof.into(), + metadata, + proof, )) } } diff --git a/packages/wasm-sdk/src/queries/voting/voters.rs b/packages/wasm-sdk/src/queries/voting/voters.rs index 011dd36e072..af9918eeeb9 100644 --- a/packages/wasm-sdk/src/queries/voting/voters.rs +++ b/packages/wasm-sdk/src/queries/voting/voters.rs @@ -9,138 +9,207 @@ use drive_proof_verifier::types::Voter; use js_sys::Array; use platform_value::string_encoding::Encoding; use platform_value::Identifier; +use serde::Deserialize; +use serde_json::Value as JsonValue; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; use wasm_dpp2::identifier::IdentifierWasm; -#[wasm_bindgen(js_name = "ContestedResourceVotersQuery")] -pub struct ContestedResourceVotersQueryWasm(ContestedDocumentVotePollVotesDriveQuery); +#[wasm_bindgen(typescript_custom_section)] +const CONTESTED_RESOURCE_VOTERS_QUERY_TS: &'static str = r#" +/** + * Query parameters for fetching voters of a contested resource. + */ +export interface ContestedResourceVotersForIdentityQuery { + /** + * Data contract identifier (base58 string). + */ + dataContractId: string; -impl ContestedResourceVotersQueryWasm { - pub(crate) fn into_inner(self) -> ContestedDocumentVotePollVotesDriveQuery { - self.0 - } + /** + * Contested document type name. + */ + documentTypeName: string; + + /** + * Index name used to locate the contested resource. + */ + indexName: string; + + /** + * Optional index values used as query arguments. + * @default undefined + */ + indexValues?: unknown[]; + + /** + * Contested identity identifier (base58 string). + */ + contestantId: string; + + /** + * Maximum number of voters to return. + * @default undefined (no explicit limit) + */ + limit?: number; + + /** + * Voter identifier to resume from (exclusive by default). + * @default undefined + */ + startAtVoterId?: string; + + /** + * Include the `startAtVoterId` when true. + * @default true + */ + startAtIncluded?: boolean; + + /** + * Sort order. When omitted, defaults to ascending. + * @default true + */ + orderAscending?: boolean; } +"#; -#[wasm_bindgen(js_name = "ContestedResourceVotersQueryBuilder")] -pub struct ContestedResourceVotersQueryBuilder { - vote_poll: ContestedDocumentResourceVotePoll, - contestant_id: Identifier, - limit: Option, - start_at: Option<([u8; 32], bool)>, - order_ascending: bool, +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(typescript_type = "ContestedResourceVotersForIdentityQuery")] + pub type ContestedResourceVotersQueryJs; } -#[wasm_bindgen(js_class = ContestedResourceVotersQueryBuilder)] -impl ContestedResourceVotersQueryBuilder { - #[wasm_bindgen(constructor)] - pub fn new( - data_contract_id: &str, - document_type_name: &str, - index_name: &str, - contestant_id: &str, - ) -> Result { - let contract_id = Identifier::from_string( - data_contract_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; - - let contestant_id = Identifier::from_string( - contestant_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contestant ID: {}", e)))?; - - Ok(Self { - vote_poll: ContestedDocumentResourceVotePoll { - contract_id, - document_type_name: document_type_name.to_string(), - index_name: index_name.to_string(), - index_values: Vec::new(), - }, - contestant_id, - limit: None, - start_at: None, - order_ascending: true, - }) - } +#[derive(Default, Deserialize)] +#[serde(rename_all = "camelCase")] +struct ContestedResourceVotersQueryFields { + #[serde(default)] + index_values: Option>, + #[serde(default)] + limit: Option, + #[serde(default)] + start_at_voter_id: Option, + #[serde(default)] + start_at_included: Option, + #[serde(default)] + order_ascending: Option, +} - #[wasm_bindgen(js_name = "withIndexValues")] - pub fn with_index_values( - mut self, - values: Vec, - ) -> Result { - self.vote_poll.index_values = js_values_to_platform_values(values)?; - Ok(self) - } +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +struct ContestedResourceVotersQueryInput { + data_contract_id: String, + document_type_name: String, + index_name: String, + contestant_id: String, + #[serde(flatten)] + fields: ContestedResourceVotersQueryFields, +} - #[wasm_bindgen(js_name = "withLimit")] - pub fn with_limit( - mut self, - limit: Option, - ) -> Result { - self.limit = match limit { - Some(0) => None, - Some(count) => { - if count > u16::MAX as u32 { - return Err(WasmSdkError::invalid_argument(format!( - "limit {} exceeds maximum of {}", - count, - u16::MAX - ))); - } - Some(count as u16) +fn convert_limit(limit: Option) -> Result, WasmSdkError> { + match limit { + Some(0) => Ok(None), + Some(value) => { + if value > u16::MAX as u32 { + return Err(WasmSdkError::invalid_argument(format!( + "limit {} exceeds maximum of {}", + value, + u16::MAX + ))); } - None => None, - }; - Ok(self) + Ok(Some(value as u16)) + } + None => Ok(None), } +} - #[wasm_bindgen(js_name = "withOrderAscending")] - pub fn with_order_ascending( - mut self, - order_ascending: bool, - ) -> ContestedResourceVotersQueryBuilder { - self.order_ascending = order_ascending; - self - } +fn build_contested_resource_voters_query( + query: ContestedResourceVotersQueryInput, +) -> Result { + let ContestedResourceVotersQueryInput { + data_contract_id, + document_type_name, + index_name, + contestant_id, + fields: + ContestedResourceVotersQueryFields { + index_values, + limit, + start_at_voter_id, + start_at_included, + order_ascending, + }, + } = query; - #[wasm_bindgen(js_name = "withStartAtVoter")] - pub fn with_start_at_voter( - mut self, - voter_id: &str, - included: bool, - ) -> Result { - let identifier = Identifier::from_string( - voter_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid voter ID: {}", e)))?; - - self.start_at = Some((identifier.to_buffer(), included)); - Ok(self) - } + let contract_id = Identifier::from_string( + &data_contract_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; - #[wasm_bindgen(js_name = "build")] - pub fn build(self) -> ContestedResourceVotersQueryWasm { - let ContestedResourceVotersQueryBuilder { - vote_poll, - contestant_id, - limit, - start_at, - order_ascending, - } = self; - - ContestedResourceVotersQueryWasm(ContestedDocumentVotePollVotesDriveQuery { - vote_poll, - contestant_id, - offset: None, - limit, - start_at, - order_ascending, + let contestant_id = Identifier::from_string( + &contestant_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contestant ID: {}", e)))?; + + let index_values_js: Vec = index_values + .unwrap_or_default() + .into_iter() + .map(|value| { + serde_wasm_bindgen::to_value(&value).map_err(|err| { + WasmSdkError::invalid_argument(format!( + "Invalid indexValues entry: {}", + err + )) + }) }) - } + .collect::, _>>()?; + let index_values = js_values_to_platform_values(index_values_js)?; + + let start_at = match start_at_voter_id { + Some(voter_id) => { + let identifier = Identifier::from_string( + &voter_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid voter ID: {}", e)))?; + + Some((identifier.to_buffer(), start_at_included.unwrap_or(true))) + } + None => None, + }; + + let limit = convert_limit(limit)?; + let order_ascending = order_ascending.unwrap_or(true); + + Ok(ContestedDocumentVotePollVotesDriveQuery { + vote_poll: ContestedDocumentResourceVotePoll { + contract_id, + document_type_name, + index_name, + index_values, + }, + contestant_id, + offset: None, + limit, + start_at, + order_ascending, + }) +} + +fn parse_contested_resource_voters_query( + query: ContestedResourceVotersQueryJs, +) -> Result { + let query_value: JsValue = query.into(); + let input: ContestedResourceVotersQueryInput = serde_wasm_bindgen::from_value(query_value) + .map_err(|err| { + WasmSdkError::invalid_argument(format!( + "Invalid contested resource voters query: {}", + err + )) + })?; + + build_contested_resource_voters_query(input) } #[wasm_bindgen] @@ -148,9 +217,11 @@ impl WasmSdk { #[wasm_bindgen(js_name = "getContestedResourceVotersForIdentity")] pub async fn get_contested_resource_voters_for_identity( &self, - query: ContestedResourceVotersQueryWasm, + query: ContestedResourceVotersQueryJs, ) -> Result { - let voters = Voter::fetch_many(self.as_ref(), query.into_inner()) + let drive_query = parse_contested_resource_voters_query(query)?; + + let voters = Voter::fetch_many(self.as_ref(), drive_query) .await .map_err(WasmSdkError::from)?; @@ -166,11 +237,12 @@ impl WasmSdk { #[wasm_bindgen(js_name = "getContestedResourceVotersForIdentityWithProofInfo")] pub async fn get_contested_resource_voters_for_identity_with_proof_info( &self, - query: ContestedResourceVotersQueryWasm, + query: ContestedResourceVotersQueryJs, ) -> Result { + let drive_query = parse_contested_resource_voters_query(query)?; + let (voters, metadata, proof) = - Voter::fetch_many_with_metadata_and_proof(self.as_ref(), query.into_inner(), None) - .await?; + Voter::fetch_many_with_metadata_and_proof(self.as_ref(), drive_query, None).await?; let voters_list: Vec = voters .0 diff --git a/packages/wasm-sdk/src/queries/voting/votes.rs b/packages/wasm-sdk/src/queries/voting/votes.rs index ca68cf70e40..6240a3943e5 100644 --- a/packages/wasm-sdk/src/queries/voting/votes.rs +++ b/packages/wasm-sdk/src/queries/voting/votes.rs @@ -10,110 +10,148 @@ use drive_proof_verifier::types::ResourceVotesByIdentity; use js_sys::Array; use platform_value::string_encoding::Encoding; use platform_value::Identifier; +use serde::Deserialize; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsValue; -#[wasm_bindgen(js_name = "ContestedResourceIdentityVotesQuery")] -pub struct ContestedResourceIdentityVotesQueryWasm(ContestedResourceVotesGivenByIdentityQuery); +#[wasm_bindgen(typescript_custom_section)] +const CONTESTED_RESOURCE_IDENTITY_VOTES_QUERY_TS: &'static str = r#" +/** + * Query parameters for fetching contested resource votes cast by an identity. + */ +export interface ContestedResourceIdentityVotesQuery { + /** + * Identity identifier (base58 string). + */ + identityId: string; -impl ContestedResourceIdentityVotesQueryWasm { - pub(crate) fn into_inner(self) -> ContestedResourceVotesGivenByIdentityQuery { - self.0 - } + /** + * Maximum number of votes to return. + * @default undefined (no explicit limit) + */ + limit?: number; + + /** + * Vote identifier to resume from (exclusive by default). + * @default undefined + */ + startAtVoteId?: string; + + /** + * Include the `startAtVoteId` when true. + * @default true + */ + startAtIncluded?: boolean; + + /** + * Sort order. When omitted, defaults to ascending. + * @default true + */ + orderAscending?: boolean; } +"#; -#[wasm_bindgen(js_name = "ContestedResourceIdentityVotesQueryBuilder")] -pub struct ContestedResourceIdentityVotesQueryBuilder { - identity_id: Identifier, - limit: Option, - start_at_vote: Option<([u8; 32], bool)>, - order_ascending: bool, +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(typescript_type = "ContestedResourceIdentityVotesQuery")] + pub type ContestedResourceIdentityVotesQueryJs; } -#[wasm_bindgen(js_class = ContestedResourceIdentityVotesQueryBuilder)] -impl ContestedResourceIdentityVotesQueryBuilder { - #[wasm_bindgen(constructor)] - pub fn new( - identity_id: &str, - ) -> Result { - let identity_id = Identifier::from_string( - identity_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; - - Ok(Self { - identity_id, - limit: None, - start_at_vote: None, - order_ascending: true, - }) - } +#[derive(Default, Deserialize)] +#[serde(rename_all = "camelCase")] +struct ContestedResourceIdentityVotesQueryFields { + #[serde(default)] + limit: Option, + #[serde(default)] + start_at_vote_id: Option, + #[serde(default)] + start_at_included: Option, + #[serde(default)] + order_ascending: Option, +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +struct ContestedResourceIdentityVotesQueryInput { + identity_id: String, + #[serde(flatten)] + fields: ContestedResourceIdentityVotesQueryFields, +} - #[wasm_bindgen(js_name = "withLimit")] - pub fn with_limit( - mut self, - limit: Option, - ) -> Result { - self.limit = match limit { - Some(0) => None, - Some(count) => { - if count > u16::MAX as u32 { - return Err(WasmSdkError::invalid_argument(format!( - "limit {} exceeds maximum of {}", - count, - u16::MAX - ))); - } - Some(count as u16) +fn convert_limit(limit: Option) -> Result, WasmSdkError> { + match limit { + Some(0) => Ok(None), + Some(value) => { + if value > u16::MAX as u32 { + return Err(WasmSdkError::invalid_argument(format!( + "limit {} exceeds maximum of {}", + value, + u16::MAX + ))); } - None => None, - }; - Ok(self) + Ok(Some(value as u16)) + } + None => Ok(None), } +} - #[wasm_bindgen(js_name = "withOrderAscending")] - pub fn with_order_ascending( - mut self, - ascending: bool, - ) -> ContestedResourceIdentityVotesQueryBuilder { - self.order_ascending = ascending; - self - } +fn build_contested_resource_identity_votes_query( + input: ContestedResourceIdentityVotesQueryInput, +) -> Result { + let ContestedResourceIdentityVotesQueryInput { + identity_id, + fields: + ContestedResourceIdentityVotesQueryFields { + limit, + start_at_vote_id, + start_at_included, + order_ascending, + }, + } = input; - #[wasm_bindgen(js_name = "withStartAtVote")] - pub fn with_start_at_vote( - mut self, - vote_id: &str, - included: bool, - ) -> Result { - let identifier = Identifier::from_string( - vote_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid vote ID: {}", e)))?; + let identity_id = Identifier::from_string( + &identity_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; - self.start_at_vote = Some((identifier.to_buffer(), included)); - Ok(self) - } + let limit = convert_limit(limit)?; - #[wasm_bindgen(js_name = "build")] - pub fn build(self) -> ContestedResourceIdentityVotesQueryWasm { - let ContestedResourceIdentityVotesQueryBuilder { - identity_id, - limit, - start_at_vote, - order_ascending, - } = self; - - ContestedResourceIdentityVotesQueryWasm(ContestedResourceVotesGivenByIdentityQuery { - identity_id, - offset: None, - limit, - start_at: start_at_vote, - order_ascending, - }) - } + let start_at = match start_at_vote_id { + Some(vote_id) => { + let identifier = Identifier::from_string( + &vote_id, + dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, + ) + .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid vote ID: {}", e)))?; + + Some((identifier.to_buffer(), start_at_included.unwrap_or(true))) + } + None => None, + }; + + Ok(ContestedResourceVotesGivenByIdentityQuery { + identity_id, + offset: None, + limit, + start_at, + order_ascending: order_ascending.unwrap_or(true), + }) +} + +fn parse_contested_resource_identity_votes_query( + query: ContestedResourceIdentityVotesQueryJs, +) -> Result { + let value: JsValue = query.into(); + let input: ContestedResourceIdentityVotesQueryInput = + serde_wasm_bindgen::from_value(value).map_err(|err| { + WasmSdkError::invalid_argument(format!( + "Invalid contested resource identity votes query: {}", + err + )) + })?; + + build_contested_resource_identity_votes_query(input) } fn resource_votes_to_json( @@ -185,9 +223,11 @@ impl WasmSdk { #[wasm_bindgen(js_name = "getContestedResourceIdentityVotes")] pub async fn get_contested_resource_identity_votes( &self, - query: ContestedResourceIdentityVotesQueryWasm, + query: ContestedResourceIdentityVotesQueryJs, ) -> Result { - let votes = ResourceVote::fetch_many(self.as_ref(), query.into_inner()).await?; + let drive_query = parse_contested_resource_identity_votes_query(query)?; + + let votes = ResourceVote::fetch_many(self.as_ref(), drive_query).await?; let votes_json = resource_votes_to_json(votes)?; let array = Array::new(); @@ -207,11 +247,12 @@ impl WasmSdk { #[wasm_bindgen(js_name = "getContestedResourceIdentityVotesWithProofInfo")] pub async fn get_contested_resource_identity_votes_with_proof_info( &self, - query: ContestedResourceIdentityVotesQueryWasm, + query: ContestedResourceIdentityVotesQueryJs, ) -> Result { + let drive_query = parse_contested_resource_identity_votes_query(query)?; let (votes, metadata, proof) = ResourceVote::fetch_many_with_metadata_and_proof( self.as_ref(), - query.into_inner(), + drive_query, None, ) .await?; diff --git a/packages/wasm-sdk/src/utils.rs b/packages/wasm-sdk/src/utils.rs new file mode 100644 index 00000000000..4d00b930c26 --- /dev/null +++ b/packages/wasm-sdk/src/utils.rs @@ -0,0 +1,21 @@ +use crate::WasmSdkError; +use platform_value::Value; +use wasm_bindgen::JsValue; +use wasm_dpp2::utils::ToSerdeJSONExt; + +/// Convert a `JsValue` coming from JavaScript into a Platform `Value`. +pub fn js_value_to_platform_value(value: JsValue) -> Result { + value.with_serde_to_platform_value().map_err(|err| { + WasmSdkError::invalid_argument(format!( + "Failed to convert JS value to platform value: {err}" + )) + }) +} + +/// Convert an iterable collection of `JsValue` into Platform `Value`s. +pub fn js_values_to_platform_values(values: I) -> Result, WasmSdkError> +where + I: IntoIterator, +{ + values.into_iter().map(js_value_to_platform_value).collect() +} diff --git a/packages/wasm-sdk/tests/functional/voting.spec.mjs b/packages/wasm-sdk/tests/functional/voting.spec.mjs index 0e969158511..7bd80f3f8af 100644 --- a/packages/wasm-sdk/tests/functional/voting.spec.mjs +++ b/packages/wasm-sdk/tests/functional/voting.spec.mjs @@ -24,26 +24,21 @@ describe('Contested resources & voting', function describeContestedResources() { const PARENT = 'dash'; const LABEL = 'therealslimshaddy5'; - await client.getContestedResources( - 'domain', - DPNS_CONTRACT, - 'parentNameAndLabel', - null, - 50, - null, - true, - ); + await client.getContestedResources({ + dataContractId: DPNS_CONTRACT, + documentTypeName: 'domain', + indexName: 'parentNameAndLabel', + orderAscending: true, + }); - await client.getContestedResourceVoteState( - DPNS_CONTRACT, - 'domain', - 'parentNameAndLabel', - [PARENT, LABEL], - 'documents', - null, - null, - 50, - true, - ); + await client.getContestedResourceVoteState({ + dataContractId: DPNS_CONTRACT, + documentTypeName: 'domain', + indexName: 'parentNameAndLabel', + indexValues: [PARENT, LABEL], + resultType: 'documents', + limit: 50, + includeLockedAndAbstaining: true, + }); }); }); From 252e4e62f08d0f5deb2e2f7ce34410befa725160 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 28 Oct 2025 21:56:17 +0700 Subject: [PATCH 26/44] refactor: cleanup voting interface --- .../clients/core/v0/nodejs/core_protoc.js | 76 +- .../dapi-grpc/clients/core/v0/web/core_pb.js | 76 +- .../clients/drive/v0/nodejs/drive_protoc.js | 8 +- .../clients/drive/v0/web/drive_pb.js | 8 +- .../platform/v0/nodejs/platform_protoc.js | 908 +++++++++--------- .../platform/v0/objective-c/Platform.pbobjc.h | 10 +- .../clients/platform/v0/web/platform_pb.js | 908 +++++++++--------- packages/js-evo-sdk/src/voting/facade.ts | 147 +-- .../tests/functional/voting.spec.mjs | 7 +- .../tests/unit/facades/voting.spec.mjs | 30 +- packages/wasm-sdk/src/queries/mod.rs | 1 + packages/wasm-sdk/src/queries/utils.rs | 101 ++ packages/wasm-sdk/src/queries/voting/polls.rs | 165 +--- .../wasm-sdk/src/queries/voting/resources.rs | 117 +-- packages/wasm-sdk/src/queries/voting/state.rs | 181 +--- .../wasm-sdk/src/queries/voting/voters.rs | 110 +-- packages/wasm-sdk/src/queries/voting/votes.rs | 66 +- 17 files changed, 1285 insertions(+), 1634 deletions(-) create mode 100644 packages/wasm-sdk/src/queries/utils.rs diff --git a/packages/dapi-grpc/clients/core/v0/nodejs/core_protoc.js b/packages/dapi-grpc/clients/core/v0/nodejs/core_protoc.js index 5d91bb2c010..5bf2a3edaeb 100644 --- a/packages/dapi-grpc/clients/core/v0/nodejs/core_protoc.js +++ b/packages/dapi-grpc/clients/core/v0/nodejs/core_protoc.js @@ -13,44 +13,44 @@ var jspb = require('google-protobuf'); var goog = jspb; -var global = Function('return this')(); - -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest.FromBlockCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse.ResponsesCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BloomFilter', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest.BlockCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Chain', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Network', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.NetworkFee', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Status', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Time', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Version', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse.Status', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.InstantSendLockMessages', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.RawTransactions', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest.FromBlockCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse.ResponsesCase', null, global); +const proto = {}; + +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest.FromBlockCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse.ResponsesCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BloomFilter', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest.BlockCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Chain', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Network', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.NetworkFee', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Status', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Time', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Version', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse.Status', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.InstantSendLockMessages', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.RawTransactions', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest.FromBlockCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse.ResponsesCase', null, { proto }); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a diff --git a/packages/dapi-grpc/clients/core/v0/web/core_pb.js b/packages/dapi-grpc/clients/core/v0/web/core_pb.js index 5d91bb2c010..5bf2a3edaeb 100644 --- a/packages/dapi-grpc/clients/core/v0/web/core_pb.js +++ b/packages/dapi-grpc/clients/core/v0/web/core_pb.js @@ -13,44 +13,44 @@ var jspb = require('google-protobuf'); var goog = jspb; -var global = Function('return this')(); - -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest.FromBlockCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse.ResponsesCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BloomFilter', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest.BlockCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Chain', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Network', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.NetworkFee', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Status', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Time', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Version', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse.Status', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.InstantSendLockMessages', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.RawTransactions', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest.FromBlockCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse.ResponsesCase', null, global); +const proto = {}; + +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest.FromBlockCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse.ResponsesCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BloomFilter', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBestBlockHeightResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest.BlockCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Chain', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Network', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.NetworkFee', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Status', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Time', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockchainStatusResponse.Version', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetMasternodeStatusResponse.Status', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.InstantSendLockMessages', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.MasternodeListResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.RawTransactions', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest.FromBlockCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse.ResponsesCase', null, { proto }); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a diff --git a/packages/dapi-grpc/clients/drive/v0/nodejs/drive_protoc.js b/packages/dapi-grpc/clients/drive/v0/nodejs/drive_protoc.js index 1373c867d42..d43136990a8 100644 --- a/packages/dapi-grpc/clients/drive/v0/nodejs/drive_protoc.js +++ b/packages/dapi-grpc/clients/drive/v0/nodejs/drive_protoc.js @@ -13,12 +13,12 @@ var jspb = require('google-protobuf'); var goog = jspb; -var global = Function('return this')(); +const proto = {}; -var platform_v0_platform_pb = require('./platform/v0/platform_pb.js'); +var platform_v0_platform_pb = require('../../../platform/v0/web/platform_pb.js'); goog.object.extend(proto, platform_v0_platform_pb); -goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsResponse', null, { proto }); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a diff --git a/packages/dapi-grpc/clients/drive/v0/web/drive_pb.js b/packages/dapi-grpc/clients/drive/v0/web/drive_pb.js index 1373c867d42..d43136990a8 100644 --- a/packages/dapi-grpc/clients/drive/v0/web/drive_pb.js +++ b/packages/dapi-grpc/clients/drive/v0/web/drive_pb.js @@ -13,12 +13,12 @@ var jspb = require('google-protobuf'); var goog = jspb; -var global = Function('return this')(); +const proto = {}; -var platform_v0_platform_pb = require('./platform/v0/platform_pb.js'); +var platform_v0_platform_pb = require('../../../platform/v0/web/platform_pb.js'); goog.object.extend(proto, platform_v0_platform_pb); -goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsResponse', null, global); +goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.drive.v0.GetProofsResponse', null, { proto }); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a diff --git a/packages/dapi-grpc/clients/platform/v0/nodejs/platform_protoc.js b/packages/dapi-grpc/clients/platform/v0/nodejs/platform_protoc.js index 96cbdb47698..59e21a649c9 100644 --- a/packages/dapi-grpc/clients/platform/v0/nodejs/platform_protoc.js +++ b/packages/dapi-grpc/clients/platform/v0/nodejs/platform_protoc.js @@ -13,7 +13,7 @@ var jspb = require('google-protobuf'); var goog = jspb; -var global = Function('return this')(); +const proto = {}; var google_protobuf_wrappers_pb = require('google-protobuf/google/protobuf/wrappers_pb.js'); goog.object.extend(proto, google_protobuf_wrappers_pb); @@ -21,459 +21,459 @@ var google_protobuf_struct_pb = require('google-protobuf/google/protobuf/struct_ goog.object.extend(proto, google_protobuf_struct_pb); var google_protobuf_timestamp_pb = require('google-protobuf/google/protobuf/timestamp_pb.js'); goog.object.extend(proto, google_protobuf_timestamp_pb); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.AllKeys', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.GetConsensusParamsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsBlock', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsEvidence', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.GetConsensusParamsResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0.StartAtVotePollIdInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVote', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVotes', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice.VoteChoiceType', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.ResultType', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.StartAtIdentifierInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.Contender', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ContestedResourceContenders', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo.FinishedVoteOutcome', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0.StartAtIdentifierInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ContestedResourceVoters', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0.StartAtValueInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ContestedResourceValues', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.GetCurrentQuorumsInfoRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.GetCurrentQuorumsInfoResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorSetV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.GetDataContractHistoryRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistory', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistoryEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.GetDataContractRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.GetDataContractsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContractEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContracts', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0.StartCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.Documents', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.GetEpochsInfoRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfos', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.GetEvonodesProposedEpochBlocksByIdsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0.StartCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodeProposedBlocks', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodesProposedBlocks', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.GetFinalizedEpochInfosRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.BlockProposer', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfos', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.ActionStatus', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.GetGroupActionSignersRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigner', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigners', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.ActionStatus', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.GetGroupActionsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.StartAtActionId', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.BurnEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent.TypeCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractUpdateEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DestroyFrozenFundsEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentCreateEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent.TypeCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent.ActionType', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.FreezeEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent.EventTypeCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActions', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.MintEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.PersonalEncryptedNote', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.SharedEncryptedNote', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenConfigUpdateEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent.TypeCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UnfreezeEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceForQuantity', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PricingSchedule', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.GetGroupInfoRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfoEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupMemberEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.GetGroupInfosRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.StartAtGroupContractPosition', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupInfos', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupMemberEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupPositionInfoEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.GetIdentitiesBalancesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentitiesBalances', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentityBalance', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.GetIdentitiesContractKeysRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentitiesKeys', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentityKeys', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.PurposeKeys', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.GetIdentitiesTokenBalancesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalanceEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalances', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.GetIdentitiesTokenInfosRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.IdentityTokenInfos', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenIdentityInfoEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenInfoEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.GetIdentityBalanceAndRevisionRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.BalanceAndRevision', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.GetIdentityBalanceRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.GetIdentityByNonUniquePublicKeyHashRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityProvedResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.GetIdentityByPublicKeyHashRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.GetIdentityContractNonceRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.GetIdentityKeysRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.Keys', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.GetIdentityNonceRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.GetIdentityRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.GetIdentityTokenBalancesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalanceEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalances', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.GetIdentityTokenInfosRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenIdentityInfoEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfoEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfos', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.GetPathElementsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.Elements', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.GetPrefundedSpecializedBalanceRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.GetProtocolVersionUpgradeStateRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.VersionEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.Versions', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.GetProtocolVersionUpgradeVoteStatusRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignal', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignals', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.GetStatusRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Chain', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Network', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Node', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.StateSync', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Time', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Drive', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Tenderdash', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Software', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.GetTokenContractInfoRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.TokenContractInfoData', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.GetTokenDirectPurchasePricesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PriceForQuantity', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PricingSchedule', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry.PriceCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePrices', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.ContractTokenInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.GetTokenPerpetualDistributionLastClaimRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo.PaidAtCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0.StartAtInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributionEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributions', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenTimedDistributionEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.GetTokenStatusesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatusEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatuses', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.GetTokenTotalSupplyRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.TokenTotalSupplyEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.GetTotalCreditsInPlatformRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.EndAtTimeInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.StartAtTimeInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamp', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamps', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyPurpose', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType.RequestCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.Proof', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.ResponseMetadata', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SearchKey', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap.KeyKindRequestType', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SpecificKeys', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.StateTransitionBroadcastError', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.WaitForStateTransitionResultRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.AllKeys', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.GetConsensusParamsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsBlock', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsEvidence', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.GetConsensusParamsResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0.StartAtVotePollIdInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVote', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVotes', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice.VoteChoiceType', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.ResultType', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.StartAtIdentifierInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.Contender', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ContestedResourceContenders', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo.FinishedVoteOutcome', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0.StartAtIdentifierInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ContestedResourceVoters', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0.StartAtValueInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ContestedResourceValues', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.GetCurrentQuorumsInfoRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.GetCurrentQuorumsInfoResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorSetV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.GetDataContractHistoryRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistory', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistoryEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.GetDataContractRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.GetDataContractsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContractEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContracts', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0.StartCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.Documents', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.GetEpochsInfoRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfos', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.GetEvonodesProposedEpochBlocksByIdsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0.StartCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodeProposedBlocks', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodesProposedBlocks', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.GetFinalizedEpochInfosRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.BlockProposer', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfos', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.ActionStatus', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.GetGroupActionSignersRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigner', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigners', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.ActionStatus', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.GetGroupActionsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.StartAtActionId', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.BurnEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent.TypeCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractUpdateEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DestroyFrozenFundsEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentCreateEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent.TypeCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent.ActionType', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.FreezeEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent.EventTypeCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActions', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.MintEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.PersonalEncryptedNote', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.SharedEncryptedNote', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenConfigUpdateEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent.TypeCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UnfreezeEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceForQuantity', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PricingSchedule', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.GetGroupInfoRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfoEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupMemberEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.GetGroupInfosRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.StartAtGroupContractPosition', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupInfos', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupMemberEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupPositionInfoEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.GetIdentitiesBalancesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentitiesBalances', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentityBalance', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.GetIdentitiesContractKeysRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentitiesKeys', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentityKeys', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.PurposeKeys', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.GetIdentitiesTokenBalancesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalanceEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalances', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.GetIdentitiesTokenInfosRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.IdentityTokenInfos', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenIdentityInfoEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenInfoEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.GetIdentityBalanceAndRevisionRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.BalanceAndRevision', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.GetIdentityBalanceRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.GetIdentityByNonUniquePublicKeyHashRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityProvedResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.GetIdentityByPublicKeyHashRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.GetIdentityContractNonceRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.GetIdentityKeysRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.Keys', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.GetIdentityNonceRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.GetIdentityRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.GetIdentityTokenBalancesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalanceEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalances', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.GetIdentityTokenInfosRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenIdentityInfoEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfoEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfos', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.GetPathElementsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.Elements', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.GetPrefundedSpecializedBalanceRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.GetProtocolVersionUpgradeStateRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.VersionEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.Versions', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.GetProtocolVersionUpgradeVoteStatusRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignal', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignals', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.GetStatusRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Chain', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Network', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Node', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.StateSync', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Time', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Drive', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Tenderdash', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Software', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.GetTokenContractInfoRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.TokenContractInfoData', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.GetTokenDirectPurchasePricesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PriceForQuantity', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PricingSchedule', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry.PriceCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePrices', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.ContractTokenInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.GetTokenPerpetualDistributionLastClaimRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo.PaidAtCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0.StartAtInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributionEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributions', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenTimedDistributionEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.GetTokenStatusesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatusEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatuses', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.GetTokenTotalSupplyRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.TokenTotalSupplyEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.GetTotalCreditsInPlatformRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.EndAtTimeInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.StartAtTimeInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamp', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamps', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyPurpose', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType.RequestCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.Proof', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.ResponseMetadata', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SearchKey', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap.KeyKindRequestType', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SpecificKeys', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.StateTransitionBroadcastError', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.WaitForStateTransitionResultRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0.ResultCase', null, { proto }); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a diff --git a/packages/dapi-grpc/clients/platform/v0/objective-c/Platform.pbobjc.h b/packages/dapi-grpc/clients/platform/v0/objective-c/Platform.pbobjc.h index 261fab62628..7f6df1c7aa4 100644 --- a/packages/dapi-grpc/clients/platform/v0/objective-c/Platform.pbobjc.h +++ b/packages/dapi-grpc/clients/platform/v0/objective-c/Platform.pbobjc.h @@ -3362,7 +3362,7 @@ GPB_FINAL @interface GetFinalizedEpochInfosResponse_GetFinalizedEpochInfosRespon /** The actual finalized information about the requested epochs */ @property(nonatomic, readwrite, strong, null_resettable) GetFinalizedEpochInfosResponse_GetFinalizedEpochInfosResponseV0_FinalizedEpochInfos *epochs; -/** Cryptographic proof of the finalized epoch information, if requested */ +/** Cryptographic proof of the finalized epoch */ @property(nonatomic, readwrite, strong, null_resettable) Proof *proof; /** Metadata about the blockchain state */ @@ -3384,7 +3384,8 @@ typedef GPB_ENUM(GetFinalizedEpochInfosResponse_GetFinalizedEpochInfosResponseV0 }; /** - * FinalizedEpochInfos holds a collection of finalized epoch information entries + * FinalizedEpochInfos holds a collection of finalized epoch information + * entries **/ GPB_FINAL @interface GetFinalizedEpochInfosResponse_GetFinalizedEpochInfosResponseV0_FinalizedEpochInfos : GPBMessage @@ -6438,7 +6439,10 @@ GPB_FINAL @interface GetTokenPerpetualDistributionLastClaimRequest_GetTokenPerpe /** 32‑byte token identifier */ @property(nonatomic, readwrite, copy, null_resettable) NSData *tokenId; -/** This should be set if you wish to get back the last claim info as a specific type */ +/** + * This should be set if you wish to get back the last claim info as a + * specific type + **/ @property(nonatomic, readwrite, strong, null_resettable) GetTokenPerpetualDistributionLastClaimRequest_ContractTokenInfo *contractInfo; /** Test to see if @c contractInfo has been set. */ @property(nonatomic, readwrite) BOOL hasContractInfo; diff --git a/packages/dapi-grpc/clients/platform/v0/web/platform_pb.js b/packages/dapi-grpc/clients/platform/v0/web/platform_pb.js index 96cbdb47698..59e21a649c9 100644 --- a/packages/dapi-grpc/clients/platform/v0/web/platform_pb.js +++ b/packages/dapi-grpc/clients/platform/v0/web/platform_pb.js @@ -13,7 +13,7 @@ var jspb = require('google-protobuf'); var goog = jspb; -var global = Function('return this')(); +const proto = {}; var google_protobuf_wrappers_pb = require('google-protobuf/google/protobuf/wrappers_pb.js'); goog.object.extend(proto, google_protobuf_wrappers_pb); @@ -21,459 +21,459 @@ var google_protobuf_struct_pb = require('google-protobuf/google/protobuf/struct_ goog.object.extend(proto, google_protobuf_struct_pb); var google_protobuf_timestamp_pb = require('google-protobuf/google/protobuf/timestamp_pb.js'); goog.object.extend(proto, google_protobuf_timestamp_pb); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.AllKeys', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.GetConsensusParamsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsBlock', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsEvidence', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.GetConsensusParamsResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0.StartAtVotePollIdInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVote', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVotes', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice.VoteChoiceType', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.ResultType', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.StartAtIdentifierInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.Contender', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ContestedResourceContenders', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo.FinishedVoteOutcome', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0.StartAtIdentifierInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ContestedResourceVoters', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0.StartAtValueInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ContestedResourceValues', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.GetCurrentQuorumsInfoRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.GetCurrentQuorumsInfoResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorSetV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.GetDataContractHistoryRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistory', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistoryEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.GetDataContractRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.GetDataContractsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContractEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContracts', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0.StartCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.Documents', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.GetEpochsInfoRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfos', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.GetEvonodesProposedEpochBlocksByIdsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0.StartCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodeProposedBlocks', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodesProposedBlocks', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.GetFinalizedEpochInfosRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.BlockProposer', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfos', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.ActionStatus', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.GetGroupActionSignersRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigner', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigners', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.ActionStatus', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.GetGroupActionsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.StartAtActionId', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.BurnEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent.TypeCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractUpdateEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DestroyFrozenFundsEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentCreateEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent.TypeCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent.ActionType', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.FreezeEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent.EventTypeCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActions', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.MintEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.PersonalEncryptedNote', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.SharedEncryptedNote', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenConfigUpdateEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent.TypeCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UnfreezeEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceForQuantity', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PricingSchedule', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.GetGroupInfoRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfoEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupMemberEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.GetGroupInfosRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.StartAtGroupContractPosition', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupInfos', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupMemberEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupPositionInfoEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.GetIdentitiesBalancesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentitiesBalances', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentityBalance', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.GetIdentitiesContractKeysRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentitiesKeys', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentityKeys', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.PurposeKeys', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.GetIdentitiesTokenBalancesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalanceEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalances', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.GetIdentitiesTokenInfosRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.IdentityTokenInfos', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenIdentityInfoEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenInfoEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.GetIdentityBalanceAndRevisionRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.BalanceAndRevision', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.GetIdentityBalanceRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.GetIdentityByNonUniquePublicKeyHashRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityProvedResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.GetIdentityByPublicKeyHashRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.GetIdentityContractNonceRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.GetIdentityKeysRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.Keys', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.GetIdentityNonceRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.GetIdentityRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.GetIdentityTokenBalancesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalanceEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalances', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.GetIdentityTokenInfosRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenIdentityInfoEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfoEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfos', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.GetPathElementsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.Elements', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.GetPrefundedSpecializedBalanceRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.GetProtocolVersionUpgradeStateRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.VersionEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.Versions', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.GetProtocolVersionUpgradeVoteStatusRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignal', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignals', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.GetStatusRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Chain', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Network', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Node', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.StateSync', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Time', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Drive', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Tenderdash', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Software', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.GetTokenContractInfoRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.TokenContractInfoData', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.GetTokenDirectPurchasePricesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PriceForQuantity', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PricingSchedule', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry.PriceCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePrices', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.ContractTokenInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.GetTokenPerpetualDistributionLastClaimRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo.PaidAtCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0.StartAtInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributionEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributions', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenTimedDistributionEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.GetTokenStatusesRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatusEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatuses', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.GetTokenTotalSupplyRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.TokenTotalSupplyEntry', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.GetTotalCreditsInPlatformRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.EndAtTimeInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.StartAtTimeInfo', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.ResultCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamp', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamps', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyPurpose', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType.RequestCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.Proof', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.ResponseMetadata', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SearchKey', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap.KeyKindRequestType', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.SpecificKeys', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.StateTransitionBroadcastError', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.WaitForStateTransitionResultRequestV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.VersionCase', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0', null, global); -goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0.ResultCase', null, global); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.AllKeys', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastStateTransitionResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.GetConsensusParamsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsBlock', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.ConsensusParamsEvidence', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.GetConsensusParamsResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetConsensusParamsResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.GetContestedResourceIdentityVotesRequestV0.StartAtVotePollIdInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVote', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ContestedResourceIdentityVotes', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResourceVoteChoice.VoteChoiceType', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.GetContestedResourceIdentityVotesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceIdentityVotesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.ResultType', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.GetContestedResourceVoteStateRequestV0.StartAtIdentifierInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.Contender', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ContestedResourceContenders', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.FinishedVoteInfo.FinishedVoteOutcome', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.GetContestedResourceVoteStateResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVoteStateResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.GetContestedResourceVotersForIdentityRequestV0.StartAtIdentifierInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ContestedResourceVoters', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.GetContestedResourceVotersForIdentityResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourceVotersForIdentityResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.GetContestedResourcesRequestV0.StartAtValueInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ContestedResourceValues', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.GetContestedResourcesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetContestedResourcesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.GetCurrentQuorumsInfoRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.GetCurrentQuorumsInfoResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorSetV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.ValidatorV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetCurrentQuorumsInfoResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.GetDataContractHistoryRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistory', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.DataContractHistoryEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.GetDataContractHistoryResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractHistoryResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.GetDataContractRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.GetDataContractResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.GetDataContractsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContractEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.DataContracts', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.GetDataContractsResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDataContractsResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.GetDocumentsRequestV0.StartCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.Documents', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.GetDocumentsResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetDocumentsResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.GetEpochsInfoRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.EpochInfos', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.GetEpochsInfoResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEpochsInfoResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.GetEvonodesProposedEpochBlocksByIdsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByIdsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.GetEvonodesProposedEpochBlocksByRangeRequestV0.StartCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksByRangeRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodeProposedBlocks', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.EvonodesProposedBlocks', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.GetEvonodesProposedEpochBlocksResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEvonodesProposedEpochBlocksResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.GetFinalizedEpochInfosRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.BlockProposer', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.FinalizedEpochInfos', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.GetFinalizedEpochInfosResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetFinalizedEpochInfosResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.ActionStatus', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.GetGroupActionSignersRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigner', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.GroupActionSigners', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.GetGroupActionSignersResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionSignersResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.ActionStatus', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.GetGroupActionsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.StartAtActionId', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.BurnEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractEvent.TypeCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ContractUpdateEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DestroyFrozenFundsEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentCreateEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.DocumentEvent.TypeCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.EmergencyActionEvent.ActionType', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.FreezeEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActionEvent.EventTypeCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.GroupActions', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.MintEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.PersonalEncryptedNote', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.SharedEncryptedNote', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenConfigUpdateEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.TokenEvent.TypeCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UnfreezeEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PriceForQuantity', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.GetGroupActionsResponseV0.UpdateDirectPurchasePriceEvent.PricingSchedule', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupActionsResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.GetGroupInfoRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupInfoEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.GroupMemberEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.GetGroupInfoResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfoResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.GetGroupInfosRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.StartAtGroupContractPosition', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupInfos', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupMemberEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.GroupPositionInfoEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.GetGroupInfosResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetGroupInfosResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.GetIdentitiesBalancesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentitiesBalances', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.IdentityBalance', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.GetIdentitiesBalancesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesBalancesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.GetIdentitiesContractKeysRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentitiesKeys', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.IdentityKeys', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.PurposeKeys', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.GetIdentitiesContractKeysResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesContractKeysResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.GetIdentitiesTokenBalancesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalanceEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.IdentityTokenBalances', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.GetIdentitiesTokenBalancesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenBalancesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.GetIdentitiesTokenInfosRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.IdentityTokenInfos', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenIdentityInfoEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.GetIdentitiesTokenInfosResponseV0.TokenInfoEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentitiesTokenInfosResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.GetIdentityBalanceAndRevisionRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.BalanceAndRevision', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.GetIdentityBalanceAndRevisionResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceAndRevisionResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.GetIdentityBalanceRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.GetIdentityBalanceResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityBalanceResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.GetIdentityByNonUniquePublicKeyHashRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityProvedResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.IdentityResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.GetIdentityByNonUniquePublicKeyHashResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByNonUniquePublicKeyHashResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.GetIdentityByPublicKeyHashRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.GetIdentityByPublicKeyHashResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityByPublicKeyHashResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.GetIdentityContractNonceRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.GetIdentityContractNonceResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityContractNonceResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.GetIdentityKeysRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.Keys', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.GetIdentityKeysResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityKeysResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.GetIdentityNonceRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.GetIdentityNonceResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityNonceResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.GetIdentityRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.GetIdentityResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.GetIdentityTokenBalancesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalanceEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.GetIdentityTokenBalancesResponseV0.TokenBalances', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenBalancesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.GetIdentityTokenInfosRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenIdentityInfoEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfoEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.GetIdentityTokenInfosResponseV0.TokenInfos', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetIdentityTokenInfosResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.GetPathElementsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.Elements', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.GetPathElementsResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPathElementsResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.GetPrefundedSpecializedBalanceRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.GetPrefundedSpecializedBalanceResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetPrefundedSpecializedBalanceResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.GetProtocolVersionUpgradeStateRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.VersionEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.GetProtocolVersionUpgradeStateResponseV0.Versions', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeStateResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.GetProtocolVersionUpgradeVoteStatusRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignal', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.GetProtocolVersionUpgradeVoteStatusResponseV0.VersionSignals', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetProtocolVersionUpgradeVoteStatusResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.GetStatusRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Chain', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Network', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Node', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.StateSync', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Time', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Drive', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Protocol.Tenderdash', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.GetStatusResponseV0.Version.Software', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.GetTokenContractInfoRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.GetTokenContractInfoResponseV0.TokenContractInfoData', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenContractInfoResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.GetTokenDirectPurchasePricesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PriceForQuantity', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.PricingSchedule', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePriceEntry.PriceCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.GetTokenDirectPurchasePricesResponseV0.TokenDirectPurchasePrices', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenDirectPurchasePricesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.ContractTokenInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.GetTokenPerpetualDistributionLastClaimRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.LastClaimInfo.PaidAtCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.GetTokenPerpetualDistributionLastClaimResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPerpetualDistributionLastClaimResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.GetTokenPreProgrammedDistributionsRequestV0.StartAtInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributionEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenDistributions', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.GetTokenPreProgrammedDistributionsResponseV0.TokenTimedDistributionEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenPreProgrammedDistributionsResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.GetTokenStatusesRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatusEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.GetTokenStatusesResponseV0.TokenStatuses', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenStatusesResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.GetTokenTotalSupplyRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.GetTokenTotalSupplyResponseV0.TokenTotalSupplyEntry', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTokenTotalSupplyResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.GetTotalCreditsInPlatformRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.GetTotalCreditsInPlatformResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTotalCreditsInPlatformResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.EndAtTimeInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.GetVotePollsByEndDateRequestV0.StartAtTimeInfo', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.ResultCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamp', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.GetVotePollsByEndDateResponseV0.SerializedVotePollsByTimestamps', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetVotePollsByEndDateResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyPurpose', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.KeyRequestType.RequestCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.Proof', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.ResponseMetadata', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SearchKey', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SecurityLevelMap.KeyKindRequestType', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.SpecificKeys', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.StateTransitionBroadcastError', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultRequest.WaitForStateTransitionResultRequestV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.VersionCase', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0', null, { proto }); +goog.exportSymbol('proto.org.dash.platform.dapi.v0.WaitForStateTransitionResultResponse.WaitForStateTransitionResultResponseV0.ResultCase', null, { proto }); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a diff --git a/packages/js-evo-sdk/src/voting/facade.ts b/packages/js-evo-sdk/src/voting/facade.ts index 8414da6e237..1ce9825dc31 100644 --- a/packages/js-evo-sdk/src/voting/facade.ts +++ b/packages/js-evo-sdk/src/voting/facade.ts @@ -1,166 +1,45 @@ +import type { + ContestedResourceIdentityVotesQuery, + ContestedResourceVoteStateQuery, + VotePollsByEndDateQuery, +} from '@dashevo/wasm-sdk'; import { asJsonString } from '../util.js'; import type { EvoSDK } from '../sdk.js'; -interface ContestedResourceVoteStateQueryInput { - dataContractId: string; - documentTypeName: string; - indexName: string; - indexValues?: unknown[]; - resultType?: 'documents' | 'voteTally' | 'documentsAndVoteTally'; - limit?: number; - startAtContenderId?: string; - startAtIncluded?: boolean; - includeLockedAndAbstaining?: boolean; -} - -interface ContestedResourceIdentityVotesQueryInput { - identityId: string; - limit?: number; - startAtVoteId?: string; - startAtIncluded?: boolean; - orderAscending?: boolean; -} - -interface VotePollsByEndDateQueryInput { - startTimeMs?: number; - startTimeIncluded?: boolean; - endTimeMs?: number; - endTimeIncluded?: boolean; - limit?: number; - offset?: number; - orderAscending?: boolean; -} - export class VotingFacade { private sdk: EvoSDK; constructor(sdk: EvoSDK) { this.sdk = sdk; } - async contestedResourceVoteState(params: { contractId: string; documentTypeName: string; indexName: string; indexValues: any[]; resultType?: string; allowIncludeLockedAndAbstainingVoteTally?: boolean; startAtIdentifierInfo?: string; startAtIncluded?: boolean; count?: number }): Promise { - const { contractId, documentTypeName, indexName, indexValues, resultType, allowIncludeLockedAndAbstainingVoteTally, startAtIdentifierInfo, startAtIncluded, count } = params; + async contestedResourceVoteState(query: ContestedResourceVoteStateQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); - const query: ContestedResourceVoteStateQueryInput = { - dataContractId: contractId, - documentTypeName, - indexName, - indexValues, - }; - if (resultType !== undefined) query.resultType = resultType as ContestedResourceVoteStateQueryInput['resultType']; - if (allowIncludeLockedAndAbstainingVoteTally !== undefined) { - query.includeLockedAndAbstaining = allowIncludeLockedAndAbstainingVoteTally; - } - if (startAtIdentifierInfo !== undefined) query.startAtContenderId = startAtIdentifierInfo; - if (startAtIncluded !== undefined) query.startAtIncluded = startAtIncluded; - if (count !== undefined) query.limit = count; return w.getContestedResourceVoteState(query); } - async contestedResourceVoteStateWithProof(params: { contractId: string; documentTypeName: string; indexName: string; indexValues: any[]; resultType?: string; allowIncludeLockedAndAbstainingVoteTally?: boolean; startAtIdentifierInfo?: string; startAtIncluded?: boolean; count?: number }): Promise { - const { contractId, documentTypeName, indexName, indexValues, resultType, allowIncludeLockedAndAbstainingVoteTally, startAtIdentifierInfo, startAtIncluded, count } = params; + async contestedResourceVoteStateWithProof(query: ContestedResourceVoteStateQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); - const query: ContestedResourceVoteStateQueryInput = { - dataContractId: contractId, - documentTypeName, - indexName, - indexValues, - }; - if (resultType !== undefined) query.resultType = resultType as ContestedResourceVoteStateQueryInput['resultType']; - if (allowIncludeLockedAndAbstainingVoteTally !== undefined) { - query.includeLockedAndAbstaining = allowIncludeLockedAndAbstainingVoteTally; - } - if (startAtIdentifierInfo !== undefined) query.startAtContenderId = startAtIdentifierInfo; - if (startAtIncluded !== undefined) query.startAtIncluded = startAtIncluded; - if (count !== undefined) query.limit = count; return w.getContestedResourceVoteStateWithProofInfo(query); } - async contestedResourceIdentityVotes(identityId: string, opts: { limit?: number; startAtVotePollIdInfo?: string; orderAscending?: boolean } = {}): Promise { - const { limit, startAtVotePollIdInfo, orderAscending } = opts; + async contestedResourceIdentityVotes(query: ContestedResourceIdentityVotesQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); - const query: ContestedResourceIdentityVotesQueryInput = { identityId }; - if (limit !== undefined) query.limit = limit; - if (startAtVotePollIdInfo !== undefined) query.startAtVoteId = startAtVotePollIdInfo; - if (orderAscending !== undefined) query.orderAscending = orderAscending; return w.getContestedResourceIdentityVotes(query); } - async contestedResourceIdentityVotesWithProof(identityId: string, opts: { limit?: number; startAtVotePollIdInfo?: string; orderAscending?: boolean } = {}): Promise { - const { limit, startAtVotePollIdInfo, orderAscending } = opts; + async contestedResourceIdentityVotesWithProof(query: ContestedResourceIdentityVotesQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); - const query: ContestedResourceIdentityVotesQueryInput = { identityId }; - if (limit !== undefined) query.limit = limit; - if (startAtVotePollIdInfo !== undefined) query.startAtVoteId = startAtVotePollIdInfo; - if (orderAscending !== undefined) query.orderAscending = orderAscending; return w.getContestedResourceIdentityVotesWithProofInfo(query); } - async votePollsByEndDate(opts: { startTimeMs?: number | string | bigint | null; startTimeIncluded?: boolean; endTimeMs?: number | string | bigint | null; endTimeIncluded?: boolean; limit?: number; offset?: number; orderAscending?: boolean } = {}): Promise { - const { startTimeMs, startTimeIncluded, endTimeMs, endTimeIncluded, limit, offset, orderAscending } = opts; + async votePollsByEndDate(query?: VotePollsByEndDateQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); - const normalizeTime = (value?: number | string | bigint | null) => { - if (value === null || value === undefined) { - return undefined; - } - - if (typeof value === 'number') { - return Number.isFinite(value) ? value : undefined; - } - - if (typeof value === 'bigint') { - return Number(value); - } - - const trimmed = value.trim(); - if (!trimmed) { - return undefined; - } - - const parsed = Number(trimmed); - return Number.isFinite(parsed) ? parsed : undefined; - }; - - const query: VotePollsByEndDateQueryInput = {}; - const start = normalizeTime(startTimeMs); - if (start !== undefined) query.startTimeMs = start; - if (startTimeIncluded !== undefined) query.startTimeIncluded = startTimeIncluded; - - const end = normalizeTime(endTimeMs); - if (end !== undefined) query.endTimeMs = end; - if (endTimeIncluded !== undefined) query.endTimeIncluded = endTimeIncluded; - - if (limit !== undefined) query.limit = limit; - if (offset !== undefined) query.offset = offset; - if (orderAscending !== undefined) query.orderAscending = orderAscending; - - return w.getVotePollsByEndDate(query); + return w.getVotePollsByEndDate(query ?? null); } - async votePollsByEndDateWithProof(opts: { startTimeMs?: number | bigint | null; endTimeMs?: number | bigint | null; limit?: number; offset?: number; orderAscending?: boolean } = {}): Promise { - const { startTimeMs, endTimeMs, limit, offset, orderAscending } = opts; + async votePollsByEndDateWithProof(query?: VotePollsByEndDateQuery): Promise { const w = await this.sdk.getWasmSdkConnected(); - const normalizeTime = (value?: number | bigint | null) => { - if (value === null || value === undefined) { - return undefined; - } - - if (typeof value === 'number') { - return Number.isFinite(value) ? value : undefined; - } - - return Number(value); - }; - - const query: VotePollsByEndDateQueryInput = {}; - const start = normalizeTime(startTimeMs); - if (start !== undefined) query.startTimeMs = start; - const end = normalizeTime(endTimeMs); - if (end !== undefined) query.endTimeMs = end; - if (limit !== undefined) query.limit = limit; - if (offset !== undefined) query.offset = offset; - if (orderAscending !== undefined) query.orderAscending = orderAscending; - - return w.getVotePollsByEndDateWithProofInfo(query); + return w.getVotePollsByEndDateWithProofInfo(query ?? null); } async masternodeVote(args: { masternodeProTxHash: string; contractId: string; documentTypeName: string; indexName: string; indexValues: string | any[]; voteChoice: string; votingKeyWif: string }): Promise { diff --git a/packages/js-evo-sdk/tests/functional/voting.spec.mjs b/packages/js-evo-sdk/tests/functional/voting.spec.mjs index a5c0f260af7..64ab23be624 100644 --- a/packages/js-evo-sdk/tests/functional/voting.spec.mjs +++ b/packages/js-evo-sdk/tests/functional/voting.spec.mjs @@ -12,7 +12,7 @@ describe('Voting', function votingSuite() { it('contestedResourceVoteState() returns a vote state (may be empty)', async () => { const res = await sdk.voting.contestedResourceVoteState({ - contractId: TEST_IDS.dataContractId, + dataContractId: TEST_IDS.dataContractId, documentTypeName: 'domain', indexName: 'parentNameAndLabel', indexValues: ['dash', TEST_IDS.username], @@ -22,7 +22,10 @@ describe('Voting', function votingSuite() { }); it('contestedResourceIdentityVotes() returns votes for identity (may be empty)', async () => { - const res = await sdk.voting.contestedResourceIdentityVotes(TEST_IDS.identityId, { limit: 5 }); + const res = await sdk.voting.contestedResourceIdentityVotes({ + identityId: TEST_IDS.identityId, + limit: 5, + }); expect(res).to.exist(); }); }); diff --git a/packages/js-evo-sdk/tests/unit/facades/voting.spec.mjs b/packages/js-evo-sdk/tests/unit/facades/voting.spec.mjs index acbffe35c49..02ddbb748d2 100644 --- a/packages/js-evo-sdk/tests/unit/facades/voting.spec.mjs +++ b/packages/js-evo-sdk/tests/unit/facades/voting.spec.mjs @@ -22,13 +22,35 @@ describe('VotingFacade', () => { it('contestedResourceVoteState and related queries forward correctly', async () => { await client.voting.contestedResourceVoteState({ - contractId: 'c', documentTypeName: 'dt', indexName: 'i', indexValues: ['v1'], resultType: 'rt', + dataContractId: 'c', + documentTypeName: 'dt', + indexName: 'i', + indexValues: ['v1'], + resultType: 'rt', }); await client.voting.contestedResourceVoteStateWithProof({ - contractId: 'c', documentTypeName: 'dt', indexName: 'i', indexValues: ['v1'], resultType: 'rt', allowIncludeLockedAndAbstainingVoteTally: true, startAtIdentifierInfo: 's', startAtIncluded: true, count: 2, + dataContractId: 'c', + documentTypeName: 'dt', + indexName: 'i', + indexValues: ['v1'], + resultType: 'rt', + includeLockedAndAbstaining: true, + startAtContenderId: 's', + startAtIncluded: true, + limit: 2, + }); + await client.voting.contestedResourceIdentityVotes({ + identityId: 'id', + limit: 3, + startAtVoteId: 's', + orderAscending: true, + }); + await client.voting.contestedResourceIdentityVotesWithProof({ + identityId: 'id', + limit: 4, + startAtVoteId: 'p', + orderAscending: false, }); - await client.voting.contestedResourceIdentityVotes('id', { limit: 3, startAtVotePollIdInfo: 's', orderAscending: true }); - await client.voting.contestedResourceIdentityVotesWithProof('id', { limit: 4, startAtVotePollIdInfo: 'p', orderAscending: false }); await client.voting.votePollsByEndDate({ startTimeMs: 1000, startTimeIncluded: true, diff --git a/packages/wasm-sdk/src/queries/mod.rs b/packages/wasm-sdk/src/queries/mod.rs index a63cbe4a1eb..a90c7f28134 100644 --- a/packages/wasm-sdk/src/queries/mod.rs +++ b/packages/wasm-sdk/src/queries/mod.rs @@ -6,6 +6,7 @@ pub mod identity; pub mod protocol; pub mod system; pub mod token; +pub(crate) mod utils; pub mod voting; // Re-export all query functions for easy access diff --git a/packages/wasm-sdk/src/queries/utils.rs b/packages/wasm-sdk/src/queries/utils.rs new file mode 100644 index 00000000000..af92807020d --- /dev/null +++ b/packages/wasm-sdk/src/queries/utils.rs @@ -0,0 +1,101 @@ +use dash_sdk::dpp::platform_value::{ + string_encoding::Encoding, Identifier, Value as PlatformValue, +}; +use serde::de::DeserializeOwned; +use serde_json::Value as JsonValue; +use wasm_bindgen::JsValue; + +use crate::utils::{js_value_to_platform_value, js_values_to_platform_values}; +use crate::WasmSdkError; + +pub(crate) fn deserialize_required_query( + query: Q, + missing_error: &str, + context: &str, +) -> Result +where + T: DeserializeOwned, + Q: Into, +{ + let value = query.into(); + + if value.is_null() || value.is_undefined() { + return Err(WasmSdkError::invalid_argument(missing_error.to_string())); + } + + serde_wasm_bindgen::from_value(value) + .map_err(|err| WasmSdkError::invalid_argument(format!("Invalid {}: {}", context, err))) +} + +pub(crate) fn deserialize_query_with_default( + query: Option, + context: &str, +) -> Result +where + T: Default + DeserializeOwned, + Q: Into, +{ + let value = query.map(Into::into).unwrap_or_else(|| JsValue::UNDEFINED); + + if value.is_null() || value.is_undefined() { + return Ok(T::default()); + } + + serde_wasm_bindgen::from_value(value) + .map_err(|err| WasmSdkError::invalid_argument(format!("Invalid {}: {}", context, err))) +} + +pub(crate) fn convert_optional_limit( + limit: Option, + field: &str, +) -> Result, WasmSdkError> { + match limit { + Some(0) => Ok(None), + Some(value) => { + if value > u16::MAX as u32 { + Err(WasmSdkError::invalid_argument(format!( + "{} {} exceeds maximum of {}", + field, + value, + u16::MAX + ))) + } else { + Ok(Some(value as u16)) + } + } + None => Ok(None), + } +} + +pub(crate) fn convert_json_values_to_platform_values( + values: Option>, + field_name: &str, +) -> Result, WasmSdkError> { + let js_values = values + .unwrap_or_default() + .into_iter() + .map(|value| { + serde_wasm_bindgen::to_value(&value).map_err(|err| { + WasmSdkError::invalid_argument(format!("Invalid {} entry: {}", field_name, err)) + }) + }) + .collect::, _>>()?; + + js_values_to_platform_values(js_values) +} + +pub(crate) fn convert_json_value_to_platform_value( + value: JsonValue, + field_name: &str, +) -> Result { + let js_value = serde_wasm_bindgen::to_value(&value).map_err(|err| { + WasmSdkError::invalid_argument(format!("Invalid {} entry: {}", field_name, err)) + })?; + + js_value_to_platform_value(js_value) +} + +pub(crate) fn identifier_from_base58(value: &str, field: &str) -> Result { + Identifier::from_string(value, Encoding::Base58) + .map_err(|err| WasmSdkError::invalid_argument(format!("Invalid {}: {}", field, err))) +} diff --git a/packages/wasm-sdk/src/queries/voting/polls.rs b/packages/wasm-sdk/src/queries/voting/polls.rs index 8d08b4c90fb..b3485447f82 100644 --- a/packages/wasm-sdk/src/queries/voting/polls.rs +++ b/packages/wasm-sdk/src/queries/voting/polls.rs @@ -1,6 +1,7 @@ +use crate::queries::utils::{convert_optional_limit, deserialize_query_with_default}; use crate::sdk::WasmSdk; use crate::{ProofMetadataResponseWasm, WasmSdkError}; -use dash_sdk::dpp::prelude::{TimestampIncluded, TimestampMillis}; +use dash_sdk::dpp::prelude::TimestampMillis; use dash_sdk::dpp::voting::vote_polls::VotePoll; use dash_sdk::platform::FetchMany; use drive::query::VotePollsByEndDateDriveQuery; @@ -95,34 +96,6 @@ fn timestamp_from_option( } } -fn convert_limit(limit: Option, field: &str) -> Result, WasmSdkError> { - match limit { - Some(0) => Ok(None), - Some(value) => { - if value > u16::MAX as u32 { - return Err(WasmSdkError::invalid_argument(format!( - "{} {} exceeds maximum of {}", - field, - value, - u16::MAX - ))); - } - - Ok(Some(value as u16)) - } - None => Ok(None), - } -} - -#[wasm_bindgen(js_name = "VotePollsByEndDateQuery")] -pub struct VotePollsByEndDateQueryWasm(VotePollsByEndDateDriveQuery); - -impl VotePollsByEndDateQueryWasm { - pub(crate) fn into_inner(self) -> VotePollsByEndDateDriveQuery { - self.0 - } -} - #[derive(Default, Deserialize)] #[serde(rename_all = "camelCase")] struct VotePollsByEndDateQueryInput { @@ -144,7 +117,7 @@ struct VotePollsByEndDateQueryInput { fn build_vote_polls_by_end_date_drive_query( input: VotePollsByEndDateQueryInput, -) -> Result { +) -> Result { let VotePollsByEndDateQueryInput { start_time_ms, start_time_included, @@ -173,51 +146,32 @@ fn build_vote_polls_by_end_date_drive_query( let end_time = timestamp_from_option(end_time_ms, "endTimeMs")? .map(|timestamp| (timestamp, end_time_included.unwrap_or(true))); - let limit = convert_limit(limit, "limit")?; - let offset = convert_limit(offset, "offset")?; + let limit = convert_optional_limit(limit, "limit")?; + let offset = convert_optional_limit(offset, "offset")?; - Ok(VotePollsByEndDateQueryWasm(VotePollsByEndDateDriveQuery { + Ok(VotePollsByEndDateDriveQuery { start_time, end_time, limit, offset, order_ascending: order_ascending.unwrap_or(true), - })) + }) } fn parse_vote_polls_by_end_date_query( query: Option, -) -> Result { - let value: JsValue = query - .map(Into::into) - .unwrap_or(JsValue::UNDEFINED); - - let input: VotePollsByEndDateQueryInput = if value.is_null() || value.is_undefined() { - VotePollsByEndDateQueryInput::default() - } else { - serde_wasm_bindgen::from_value(value).map_err(|err| { - WasmSdkError::invalid_argument(format!( - "Invalid vote polls by end date query: {}", - err - )) - })? - }; +) -> Result { + let input: VotePollsByEndDateQueryInput = + deserialize_query_with_default(query, "vote polls by end date query")?; build_vote_polls_by_end_date_drive_query(input) } -#[wasm_bindgen(js_name = "buildVotePollsByEndDateQuery")] -pub fn build_vote_polls_by_end_date_query( - query: Option, -) -> Result { - parse_vote_polls_by_end_date_query(query) -} - #[derive(Clone)] #[wasm_bindgen(js_name = "VotePollsByEndDateEntry")] pub struct VotePollsByEndDateEntryWasm { timestamp_ms: TimestampMillis, - polls_js: Rc, + polls: Rc, } impl VotePollsByEndDateEntryWasm { @@ -229,7 +183,7 @@ impl VotePollsByEndDateEntryWasm { Self { timestamp_ms, - polls_js: Rc::new(array), + polls: Rc::new(array), } } } @@ -243,83 +197,30 @@ impl VotePollsByEndDateEntryWasm { #[wasm_bindgen(getter = votePolls)] pub fn vote_polls(&self) -> Array { - self.polls_js.as_ref().clone() - } -} - -#[derive(Clone)] -#[wasm_bindgen(js_name = "VotePollsByEndDateResult")] -pub struct VotePollsByEndDateResultWasm { - entries: Vec, - entries_js: Rc, -} - -impl VotePollsByEndDateResultWasm { - fn new(entries: Vec) -> Self { - let array = Array::new(); - for entry in &entries { - array.push(&JsValue::from(entry.clone())); - } - - Self { - entries, - entries_js: Rc::new(array), - } - } -} - -#[wasm_bindgen(js_class = VotePollsByEndDateResult)] -impl VotePollsByEndDateResultWasm { - #[wasm_bindgen(getter = entries)] - pub fn entries(&self) -> Array { - self.entries_js.as_ref().clone() - } - - #[wasm_bindgen(js_name = "isEmpty")] - pub fn is_empty(&self) -> bool { - self.entries.is_empty() + self.polls.as_ref().clone() } } -impl From for VotePollsByEndDateResultWasm { - fn from(grouped: VotePollsGroupedByTimestamp) -> Self { - let entries = grouped - .into_iter() - .map(|(timestamp, polls)| { - let poll_wrappers = polls.into_iter().map(VotePollWasm::from).collect(); - VotePollsByEndDateEntryWasm::new(timestamp, poll_wrappers) - }) - .collect(); - - VotePollsByEndDateResultWasm::new(entries) +fn vote_polls_grouped_to_entries(grouped: VotePollsGroupedByTimestamp) -> Array { + let entries = Array::new(); + for (timestamp, polls) in grouped { + let poll_wrappers = polls.into_iter().map(VotePollWasm::from).collect(); + let entry = VotePollsByEndDateEntryWasm::new(timestamp, poll_wrappers); + entries.push(&JsValue::from(entry)); } + entries } #[wasm_bindgen] impl WasmSdk { - async fn fetch_vote_polls_by_end_date( - &self, - query: VotePollsByEndDateQueryWasm, - ) -> Result { - let polls = VotePoll::fetch_many(self.as_ref(), query.into_inner()).await?; - Ok(polls.into()) - } - #[wasm_bindgen(js_name = "getVotePollsByEndDate")] pub async fn get_vote_polls_by_end_date( &self, query: Option, - ) -> Result { + ) -> Result { let drive_query = parse_vote_polls_by_end_date_query(query)?; - self.fetch_vote_polls_by_end_date(drive_query).await - } - - #[wasm_bindgen(js_name = "getVotePollsByEndDateWithQuery")] - pub async fn get_vote_polls_by_end_date_with_query( - &self, - query: VotePollsByEndDateQueryWasm, - ) -> Result { - self.fetch_vote_polls_by_end_date(query).await + let polls = VotePoll::fetch_many(self.as_ref(), drive_query).await?; + Ok(vote_polls_grouped_to_entries(polls)) } #[wasm_bindgen(js_name = "getVotePollsByEndDateWithProofInfo")] @@ -328,25 +229,13 @@ impl WasmSdk { query: Option, ) -> Result { let drive_query = parse_vote_polls_by_end_date_query(query)?; - self.get_vote_polls_by_end_date_with_proof_info_query(drive_query) - .await - } - - #[wasm_bindgen(js_name = "getVotePollsByEndDateWithProofInfoQuery")] - pub async fn get_vote_polls_by_end_date_with_proof_info_query( - &self, - query: VotePollsByEndDateQueryWasm, - ) -> Result { let (polls, metadata, proof) = - VotePoll::fetch_many_with_metadata_and_proof(self.as_ref(), query.into_inner(), None) - .await?; + VotePoll::fetch_many_with_metadata_and_proof(self.as_ref(), drive_query, None).await?; - let result = VotePollsByEndDateResultWasm::from(polls); + let entries = vote_polls_grouped_to_entries(polls); - Ok(ProofMetadataResponseWasm::from_parts( - JsValue::from(result), - metadata.into(), - proof.into(), + Ok(ProofMetadataResponseWasm::from_sdk_parts( + entries, metadata, proof, )) } } diff --git a/packages/wasm-sdk/src/queries/voting/resources.rs b/packages/wasm-sdk/src/queries/voting/resources.rs index b763d705010..26d4c7ccf8b 100644 --- a/packages/wasm-sdk/src/queries/voting/resources.rs +++ b/packages/wasm-sdk/src/queries/voting/resources.rs @@ -1,8 +1,10 @@ +use crate::queries::utils::{ + convert_json_value_to_platform_value, convert_json_values_to_platform_values, + convert_optional_limit, deserialize_required_query, identifier_from_base58, +}; use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; -use crate::utils::{js_value_to_platform_value, js_values_to_platform_values}; use crate::WasmSdkError; -use dash_sdk::dpp::platform_value::{string_encoding::Encoding, Identifier}; use dash_sdk::platform::FetchMany; use drive::query::vote_polls_by_document_type_query::VotePollsByDocumentTypeQuery; use drive_proof_verifier::types::{ContestedResource, ContestedResources}; @@ -10,7 +12,6 @@ use js_sys::Array; use serde::Deserialize; use serde_json::Value as JsonValue; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::JsValue; #[wasm_bindgen(typescript_custom_section)] const VOTE_POLLS_BY_DOCUMENT_TYPE_QUERY_TS: &'static str = r#" @@ -78,9 +79,12 @@ extern "C" { pub type VotePollsByDocumentTypeQueryJs; } -#[derive(Default, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] -struct VotePollsByDocumentTypeFilters { +struct VotePollsByDocumentTypeQueryInput { + data_contract_id: String, + document_type_name: String, + index_name: String, #[serde(default)] start_index_values: Option>, #[serde(default)] @@ -95,16 +99,6 @@ struct VotePollsByDocumentTypeFilters { order_ascending: Option, } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -struct VotePollsByDocumentTypeQueryInput { - data_contract_id: String, - document_type_name: String, - index_name: String, - #[serde(flatten)] - filters: VotePollsByDocumentTypeFilters, -} - fn create_vote_polls_by_document_type_query( query: VotePollsByDocumentTypeQueryInput, ) -> Result { @@ -112,79 +106,31 @@ fn create_vote_polls_by_document_type_query( data_contract_id, document_type_name, index_name, - filters: - VotePollsByDocumentTypeFilters { start_index_values, end_index_values, start_at_value, start_at_value_included, limit, - order_ascending, - }, + order_ascending, } = query; - let start_index_values_js: Vec = start_index_values - .unwrap_or_default() - .into_iter() - .map(|value| { - serde_wasm_bindgen::to_value(&value).map_err(|err| { - WasmSdkError::invalid_argument(format!( - "Invalid startIndexValues entry: {}", - err - )) - }) - }) - .collect::, _>>()?; - let start_index_values = js_values_to_platform_values(start_index_values_js)?; + let start_index_values = + convert_json_values_to_platform_values(start_index_values, "startIndexValues")?; - let end_index_values_js: Vec = end_index_values - .unwrap_or_default() - .into_iter() - .map(|value| { - serde_wasm_bindgen::to_value(&value).map_err(|err| { - WasmSdkError::invalid_argument(format!( - "Invalid endIndexValues entry: {}", - err - )) - }) - }) - .collect::, _>>()?; - let end_index_values = js_values_to_platform_values(end_index_values_js)?; + let end_index_values = + convert_json_values_to_platform_values(end_index_values, "endIndexValues")?; let start_at_value = match start_at_value { Some(value) => { - let value = serde_wasm_bindgen::to_value(&value).map_err(|err| { - WasmSdkError::invalid_argument(format!( - "Invalid startAtValue entry: {}", - err - )) - })?; - let platform_value = js_value_to_platform_value(value)?; + let platform_value = convert_json_value_to_platform_value(value, "startAtValue")?; Some((platform_value, start_at_value_included.unwrap_or(true))) } None => None, }; - let limit = match limit { - Some(0) => None, - Some(value) => { - if value > u16::MAX as u32 { - return Err(WasmSdkError::invalid_argument(format!( - "limit {} exceeds maximum of {}", - value, - u16::MAX - ))); - } - Some(value as u16) - } - None => None, - }; + let limit = convert_optional_limit(limit, "limit")?; - let contract_id = Identifier::from_string( - &data_contract_id, - Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; + let contract_id = identifier_from_base58(&data_contract_id, "contract ID")?; Ok(VotePollsByDocumentTypeQuery { contract_id, @@ -217,20 +163,13 @@ fn contested_resources_into_wasm( } fn parse_vote_polls_by_document_type_query( - query: JsValue, + query: VotePollsByDocumentTypeQueryJs, ) -> Result { - if query.is_null() || query.is_undefined() { - return Err(WasmSdkError::invalid_argument( - "Query object is required".to_string(), - )); - } else { - serde_wasm_bindgen::from_value(query).map_err(|err| { - WasmSdkError::invalid_argument(format!( - "Invalid vote polls by document type options: {}", - err - )) - }) - } + deserialize_required_query( + query, + "Query object is required", + "vote polls by document type options", + ) } #[wasm_bindgen] @@ -240,11 +179,10 @@ impl WasmSdk { &self, query: VotePollsByDocumentTypeQueryJs, ) -> Result { - let query_value: JsValue = query.into(); - let query = parse_vote_polls_by_document_type_query(query_value) + let drive_query = parse_vote_polls_by_document_type_query(query) .and_then(create_vote_polls_by_document_type_query)?; - let contested_resources = ContestedResource::fetch_many(self.as_ref(), query).await?; + let contested_resources = ContestedResource::fetch_many(self.as_ref(), drive_query).await?; let array = contested_resources_into_wasm(contested_resources)?; @@ -257,12 +195,11 @@ impl WasmSdk { &self, query: VotePollsByDocumentTypeQueryJs, ) -> Result { - let query_value: JsValue = query.into(); - let query = parse_vote_polls_by_document_type_query(query_value) + let drive_query = parse_vote_polls_by_document_type_query(query) .and_then(create_vote_polls_by_document_type_query)?; let (contested_resources, metadata, proof) = - ContestedResource::fetch_many_with_metadata_and_proof(self.as_ref(), query, None) + ContestedResource::fetch_many_with_metadata_and_proof(self.as_ref(), drive_query, None) .await?; let array = contested_resources_into_wasm(contested_resources)?; diff --git a/packages/wasm-sdk/src/queries/voting/state.rs b/packages/wasm-sdk/src/queries/voting/state.rs index 0175cb96b5e..ec62879bfbf 100644 --- a/packages/wasm-sdk/src/queries/voting/state.rs +++ b/packages/wasm-sdk/src/queries/voting/state.rs @@ -16,8 +16,11 @@ use wasm_dpp2::block::BlockInfoWasm; use wasm_dpp2::identifier::IdentifierWasm; use wasm_dpp2::{ContenderWithSerializedDocumentWasm, ContestedDocumentVotePollWinnerInfoWasm}; +use crate::queries::utils::{ + convert_json_values_to_platform_values, convert_optional_limit, deserialize_required_query, + identifier_from_base58, +}; use crate::sdk::WasmSdk; -use crate::utils::js_values_to_platform_values; use crate::{ProofMetadataResponseWasm, WasmSdkError}; #[wasm_bindgen(typescript_custom_section)] @@ -93,10 +96,7 @@ pub struct ContestedResourceVoteWinnerWasm { } impl ContestedResourceVoteWinnerWasm { - fn from_parts( - info: ContestedDocumentVotePollWinnerInfo, - block: BlockInfoWasm, - ) -> Self { + fn from_parts(info: ContestedDocumentVotePollWinnerInfo, block: BlockInfoWasm) -> Self { Self { info: info.into(), block, @@ -200,22 +200,12 @@ impl ContestedResourceVoteStateWasm { } } -#[wasm_bindgen(js_name = "ContestedResourceVoteStateQuery")] -pub struct ContestedResourceVoteStateQueryWasm(ContestedDocumentVotePollDriveQuery); - -impl ContestedResourceVoteStateQueryWasm { - pub(crate) fn into_inner(self) -> ContestedDocumentVotePollDriveQuery { - self.0 - } - - pub(crate) fn from_query(query: ContestedDocumentVotePollDriveQuery) -> Self { - Self(query) - } -} - -#[derive(Default, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] -struct ContestedResourceVoteStateQueryFields { +struct ContestedResourceVoteStateQueryInput { + data_contract_id: String, + document_type_name: String, + index_name: String, #[serde(default)] index_values: Option>, #[serde(default)] @@ -230,24 +220,18 @@ struct ContestedResourceVoteStateQueryFields { include_locked_and_abstaining: Option, } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -struct ContestedResourceVoteStateQueryInput { - data_contract_id: String, - document_type_name: String, - index_name: String, - #[serde(flatten)] - fields: ContestedResourceVoteStateQueryFields, -} - fn parse_vote_state_result_type( result_type: Option, ) -> Result { match result_type { None => Ok(ContestedDocumentVotePollDriveQueryResultType::DocumentsAndVoteTally), Some(value) => match value.as_str() { - "documents" | "DOCUMENTS" => Ok(ContestedDocumentVotePollDriveQueryResultType::Documents), - "voteTally" | "VOTE_TALLY" => Ok(ContestedDocumentVotePollDriveQueryResultType::VoteTally), + "documents" | "DOCUMENTS" => { + Ok(ContestedDocumentVotePollDriveQueryResultType::Documents) + } + "voteTally" | "VOTE_TALLY" => { + Ok(ContestedDocumentVotePollDriveQueryResultType::VoteTally) + } "documentsAndVoteTally" | "DOCUMENTS_AND_VOTE_TALLY" => { Ok(ContestedDocumentVotePollDriveQueryResultType::DocumentsAndVoteTally) } @@ -259,24 +243,6 @@ fn parse_vote_state_result_type( } } -fn convert_limit(limit: Option) -> Result, WasmSdkError> { - match limit { - Some(0) => Ok(None), - Some(value) => { - if value > u16::MAX as u32 { - return Err(WasmSdkError::invalid_argument(format!( - "limit {} exceeds maximum of {}", - value, - u16::MAX - ))); - } - - Ok(Some(value as u16)) - } - None => Ok(None), - } -} - fn create_contested_resource_vote_state_query( query: ContestedResourceVoteStateQueryInput, ) -> Result { @@ -284,47 +250,24 @@ fn create_contested_resource_vote_state_query( data_contract_id, document_type_name, index_name, - fields: - ContestedResourceVoteStateQueryFields { - index_values, - result_type, - limit, - start_at_contender_id, - start_at_included, - include_locked_and_abstaining, - }, + index_values, + result_type, + limit, + start_at_contender_id, + start_at_included, + include_locked_and_abstaining, } = query; - let index_values: Vec = index_values - .unwrap_or_default() - .into_iter() - .map(|value| { - serde_wasm_bindgen::to_value(&value).map_err(|err| { - WasmSdkError::invalid_argument(format!( - "Invalid indexValues entry: {}", - err - )) - }) - }) - .collect::, _>>()?; - let index_values = js_values_to_platform_values(index_values)?; + let index_values = convert_json_values_to_platform_values(index_values, "indexValues")?; - let contract_id = Identifier::from_string( - &data_contract_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; + let contract_id = identifier_from_base58(&data_contract_id, "contract ID")?; let result_type = parse_vote_state_result_type(result_type)?; - let limit = convert_limit(limit)?; + let limit = convert_optional_limit(limit, "limit")?; let start_at = match start_at_contender_id { Some(contender_id) => { - let identifier = Identifier::from_string( - &contender_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contender ID: {}", e)))?; + let identifier = identifier_from_base58(&contender_id, "contender ID")?; Some((identifier.to_buffer(), start_at_included.unwrap_or(true))) } @@ -350,31 +293,13 @@ fn create_contested_resource_vote_state_query( } fn parse_contested_resource_vote_state_query( - query: JsValue, -) -> Result { - if query.is_null() || query.is_undefined() { - return Err(WasmSdkError::invalid_argument( - "Query object is required".to_string(), - )); - } else { - serde_wasm_bindgen::from_value(query).map_err(|err| { - WasmSdkError::invalid_argument(format!( - "Invalid contested resource vote state query: {}", - err - )) - }) - } -} - -#[wasm_bindgen(js_name = "buildContestedResourceVoteStateQuery")] -pub fn build_contested_resource_vote_state_query( query: ContestedResourceVoteStateQueryJs, -) -> Result { - let query_value: JsValue = query.into(); - let query = parse_contested_resource_vote_state_query(query_value) - .and_then(create_contested_resource_vote_state_query)?; - - Ok(ContestedResourceVoteStateQueryWasm::from_query(query)) +) -> Result { + deserialize_required_query( + query, + "Query object is required", + "contested resource vote state query", + ) } fn convert_contenders(contenders: Contenders) -> ContestedResourceVoteStateWasm { @@ -401,34 +326,18 @@ fn convert_contenders(contenders: Contenders) -> ContestedResourceVoteStateWasm #[wasm_bindgen] impl WasmSdk { - async fn fetch_contested_resource_vote_state( - &self, - query: ContestedDocumentVotePollDriveQuery, - ) -> Result { - let contenders = - ContenderWithSerializedDocument::fetch_many(self.as_ref(), query).await?; - - Ok(convert_contenders(contenders)) - } - #[wasm_bindgen(js_name = "getContestedResourceVoteState")] pub async fn get_contested_resource_vote_state( &self, query: ContestedResourceVoteStateQueryJs, ) -> Result { - let query_value: JsValue = query.into(); - let query = parse_contested_resource_vote_state_query(query_value) + let drive_query = parse_contested_resource_vote_state_query(query) .and_then(create_contested_resource_vote_state_query)?; - self.fetch_contested_resource_vote_state(query).await - } + let contenders = + ContenderWithSerializedDocument::fetch_many(self.as_ref(), drive_query).await?; - #[wasm_bindgen(js_name = "getContestedResourceVoteStateWithQuery")] - pub async fn get_contested_resource_vote_state_with_query( - &self, - query: ContestedResourceVoteStateQueryWasm, - ) -> Result { - self.fetch_contested_resource_vote_state(query.into_inner()).await + Ok(convert_contenders(contenders)) } #[wasm_bindgen(js_name = "getContestedResourceVoteStateWithProofInfo")] @@ -436,23 +345,13 @@ impl WasmSdk { &self, query: ContestedResourceVoteStateQueryJs, ) -> Result { - let query_value: JsValue = query.into(); - let query = parse_contested_resource_vote_state_query(query_value) + let drive_query = parse_contested_resource_vote_state_query(query) .and_then(create_contested_resource_vote_state_query)?; - self.get_contested_resource_vote_state_with_proof_info_query(ContestedResourceVoteStateQueryWasm::from_query(query)) - .await - } - - #[wasm_bindgen(js_name = "getContestedResourceVoteStateWithProofInfoQuery")] - pub async fn get_contested_resource_vote_state_with_proof_info_query( - &self, - query: ContestedResourceVoteStateQueryWasm, - ) -> Result { let (contenders, metadata, proof) = ContenderWithSerializedDocument::fetch_many_with_metadata_and_proof( self.as_ref(), - query.into_inner(), + drive_query, None, ) .await?; @@ -460,9 +359,7 @@ impl WasmSdk { let state = convert_contenders(contenders); Ok(ProofMetadataResponseWasm::from_sdk_parts( - JsValue::from(state), - metadata, - proof, + state, metadata, proof, )) } } diff --git a/packages/wasm-sdk/src/queries/voting/voters.rs b/packages/wasm-sdk/src/queries/voting/voters.rs index af9918eeeb9..9717fea88dd 100644 --- a/packages/wasm-sdk/src/queries/voting/voters.rs +++ b/packages/wasm-sdk/src/queries/voting/voters.rs @@ -1,6 +1,9 @@ +use crate::queries::utils::{ + convert_json_values_to_platform_values, convert_optional_limit, deserialize_required_query, + identifier_from_base58, +}; use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; -use crate::utils::js_values_to_platform_values; use crate::WasmSdkError; use dash_sdk::dpp::voting::vote_polls::contested_document_resource_vote_poll::ContestedDocumentResourceVotePoll; use dash_sdk::platform::FetchMany; @@ -8,7 +11,6 @@ use drive::query::vote_poll_contestant_votes_query::ContestedDocumentVotePollVot use drive_proof_verifier::types::Voter; use js_sys::Array; use platform_value::string_encoding::Encoding; -use platform_value::Identifier; use serde::Deserialize; use serde_json::Value as JsonValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -79,9 +81,13 @@ extern "C" { pub type ContestedResourceVotersQueryJs; } -#[derive(Default, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] -struct ContestedResourceVotersQueryFields { +struct ContestedResourceVotersQueryInput { + data_contract_id: String, + document_type_name: String, + index_name: String, + contestant_id: String, #[serde(default)] index_values: Option>, #[serde(default)] @@ -94,34 +100,6 @@ struct ContestedResourceVotersQueryFields { order_ascending: Option, } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -struct ContestedResourceVotersQueryInput { - data_contract_id: String, - document_type_name: String, - index_name: String, - contestant_id: String, - #[serde(flatten)] - fields: ContestedResourceVotersQueryFields, -} - -fn convert_limit(limit: Option) -> Result, WasmSdkError> { - match limit { - Some(0) => Ok(None), - Some(value) => { - if value > u16::MAX as u32 { - return Err(WasmSdkError::invalid_argument(format!( - "limit {} exceeds maximum of {}", - value, - u16::MAX - ))); - } - Ok(Some(value as u16)) - } - None => Ok(None), - } -} - fn build_contested_resource_voters_query( query: ContestedResourceVotersQueryInput, ) -> Result { @@ -130,56 +108,29 @@ fn build_contested_resource_voters_query( document_type_name, index_name, contestant_id, - fields: - ContestedResourceVotersQueryFields { - index_values, - limit, - start_at_voter_id, - start_at_included, - order_ascending, - }, + index_values, + limit, + start_at_voter_id, + start_at_included, + order_ascending, } = query; - let contract_id = Identifier::from_string( - &data_contract_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contract ID: {}", e)))?; + let contract_id = identifier_from_base58(&data_contract_id, "contract ID")?; - let contestant_id = Identifier::from_string( - &contestant_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid contestant ID: {}", e)))?; + let contestant_id = identifier_from_base58(&contestant_id, "contestant ID")?; - let index_values_js: Vec = index_values - .unwrap_or_default() - .into_iter() - .map(|value| { - serde_wasm_bindgen::to_value(&value).map_err(|err| { - WasmSdkError::invalid_argument(format!( - "Invalid indexValues entry: {}", - err - )) - }) - }) - .collect::, _>>()?; - let index_values = js_values_to_platform_values(index_values_js)?; + let index_values = convert_json_values_to_platform_values(index_values, "indexValues")?; let start_at = match start_at_voter_id { Some(voter_id) => { - let identifier = Identifier::from_string( - &voter_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid voter ID: {}", e)))?; + let identifier = identifier_from_base58(&voter_id, "voter ID")?; Some((identifier.to_buffer(), start_at_included.unwrap_or(true))) } None => None, }; - let limit = convert_limit(limit)?; + let limit = convert_optional_limit(limit, "limit")?; let order_ascending = order_ascending.unwrap_or(true); Ok(ContestedDocumentVotePollVotesDriveQuery { @@ -200,14 +151,11 @@ fn build_contested_resource_voters_query( fn parse_contested_resource_voters_query( query: ContestedResourceVotersQueryJs, ) -> Result { - let query_value: JsValue = query.into(); - let input: ContestedResourceVotersQueryInput = serde_wasm_bindgen::from_value(query_value) - .map_err(|err| { - WasmSdkError::invalid_argument(format!( - "Invalid contested resource voters query: {}", - err - )) - })?; + let input: ContestedResourceVotersQueryInput = deserialize_required_query( + query, + "Query object is required", + "contested resource voters query", + )?; build_contested_resource_voters_query(input) } @@ -238,7 +186,7 @@ impl WasmSdk { pub async fn get_contested_resource_voters_for_identity_with_proof_info( &self, query: ContestedResourceVotersQueryJs, - ) -> Result { + ) -> Result { let drive_query = parse_contested_resource_voters_query(query)?; let (voters, metadata, proof) = @@ -257,8 +205,8 @@ impl WasmSdk { )) })?; - let response = ProofMetadataResponseWasm::from_parts(data, metadata.into(), proof.into()); - - Ok(JsValue::from(response)) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + data, metadata, proof, + )) } } diff --git a/packages/wasm-sdk/src/queries/voting/votes.rs b/packages/wasm-sdk/src/queries/voting/votes.rs index 6240a3943e5..c34a91a615a 100644 --- a/packages/wasm-sdk/src/queries/voting/votes.rs +++ b/packages/wasm-sdk/src/queries/voting/votes.rs @@ -1,3 +1,6 @@ +use crate::queries::utils::{ + convert_optional_limit, deserialize_required_query, identifier_from_base58, +}; use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; use crate::WasmSdkError; @@ -9,10 +12,8 @@ use drive::query::contested_resource_votes_given_by_identity_query::ContestedRes use drive_proof_verifier::types::ResourceVotesByIdentity; use js_sys::Array; use platform_value::string_encoding::Encoding; -use platform_value::Identifier; use serde::Deserialize; use wasm_bindgen::prelude::wasm_bindgen; -use wasm_bindgen::JsValue; #[wasm_bindgen(typescript_custom_section)] const CONTESTED_RESOURCE_IDENTITY_VOTES_QUERY_TS: &'static str = r#" @@ -78,23 +79,6 @@ struct ContestedResourceIdentityVotesQueryInput { fields: ContestedResourceIdentityVotesQueryFields, } -fn convert_limit(limit: Option) -> Result, WasmSdkError> { - match limit { - Some(0) => Ok(None), - Some(value) => { - if value > u16::MAX as u32 { - return Err(WasmSdkError::invalid_argument(format!( - "limit {} exceeds maximum of {}", - value, - u16::MAX - ))); - } - Ok(Some(value as u16)) - } - None => Ok(None), - } -} - fn build_contested_resource_identity_votes_query( input: ContestedResourceIdentityVotesQueryInput, ) -> Result { @@ -109,21 +93,13 @@ fn build_contested_resource_identity_votes_query( }, } = input; - let identity_id = Identifier::from_string( - &identity_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?; + let identity_id = identifier_from_base58(&identity_id, "identity ID")?; - let limit = convert_limit(limit)?; + let limit = convert_optional_limit(limit, "limit")?; let start_at = match start_at_vote_id { Some(vote_id) => { - let identifier = Identifier::from_string( - &vote_id, - dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, - ) - .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid vote ID: {}", e)))?; + let identifier = identifier_from_base58(&vote_id, "vote ID")?; Some((identifier.to_buffer(), start_at_included.unwrap_or(true))) } @@ -142,14 +118,11 @@ fn build_contested_resource_identity_votes_query( fn parse_contested_resource_identity_votes_query( query: ContestedResourceIdentityVotesQueryJs, ) -> Result { - let value: JsValue = query.into(); - let input: ContestedResourceIdentityVotesQueryInput = - serde_wasm_bindgen::from_value(value).map_err(|err| { - WasmSdkError::invalid_argument(format!( - "Invalid contested resource identity votes query: {}", - err - )) - })?; + let input: ContestedResourceIdentityVotesQueryInput = deserialize_required_query( + query, + "Query object is required", + "contested resource identity votes query", + )?; build_contested_resource_identity_votes_query(input) } @@ -248,14 +221,11 @@ impl WasmSdk { pub async fn get_contested_resource_identity_votes_with_proof_info( &self, query: ContestedResourceIdentityVotesQueryJs, - ) -> Result { + ) -> Result { let drive_query = parse_contested_resource_identity_votes_query(query)?; - let (votes, metadata, proof) = ResourceVote::fetch_many_with_metadata_and_proof( - self.as_ref(), - drive_query, - None, - ) - .await?; + let (votes, metadata, proof) = + ResourceVote::fetch_many_with_metadata_and_proof(self.as_ref(), drive_query, None) + .await?; let votes_json = resource_votes_to_json(votes)?; @@ -269,8 +239,8 @@ impl WasmSdk { )) })?; - let response = ProofMetadataResponseWasm::from_parts(data, metadata.into(), proof.into()); - - Ok(JsValue::from(response)) + Ok(ProofMetadataResponseWasm::from_sdk_parts( + data, metadata, proof, + )) } } From 7af57a7edd13264126dbd344c012919bea28ec50 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 29 Oct 2025 14:12:24 +0700 Subject: [PATCH 27/44] chore: update SDK interfaces --- packages/js-evo-sdk/src/contracts/facade.ts | 16 +++------------- packages/js-evo-sdk/src/identities/facade.ts | 6 +++--- packages/wasm-sdk/tests/functional/dpns.spec.mjs | 10 +++++----- .../tests/functional/epochs-blocks.spec.mjs | 4 ++-- .../wasm-sdk/tests/functional/protocol.spec.mjs | 2 +- .../wasm-sdk/tests/functional/system.spec.mjs | 4 ++-- 6 files changed, 16 insertions(+), 26 deletions(-) diff --git a/packages/js-evo-sdk/src/contracts/facade.ts b/packages/js-evo-sdk/src/contracts/facade.ts index 3d093d356ce..a0c43e9f951 100644 --- a/packages/js-evo-sdk/src/contracts/facade.ts +++ b/packages/js-evo-sdk/src/contracts/facade.ts @@ -9,7 +9,7 @@ export class ContractsFacade { this.sdk = sdk; } - async fetch(contractId: string): Promise { + async fetch(contractId: string): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getDataContract(contractId); } @@ -22,23 +22,13 @@ export class ContractsFacade { async getHistory(args: { contractId: string; limit?: number; startAtMs?: number | bigint }): Promise { const { contractId, limit, startAtMs } = args; const w = await this.sdk.getWasmSdkConnected(); - return w.getDataContractHistory( - contractId, - limit ?? null, - null, - startAtMs != null ? BigInt(startAtMs) : null, - ); + return w.getDataContractHistory(contractId, limit ?? null, startAtMs != null ? BigInt(startAtMs) : null); } async getHistoryWithProof(args: { contractId: string; limit?: number; startAtMs?: number | bigint }): Promise { const { contractId, limit, startAtMs } = args; const w = await this.sdk.getWasmSdkConnected(); - return w.getDataContractHistoryWithProofInfo( - contractId, - limit ?? null, - null, - startAtMs != null ? BigInt(startAtMs) : null, - ); + return w.getDataContractHistoryWithProofInfo(contractId, limit ?? null, startAtMs != null ? BigInt(startAtMs) : null); } async getMany(contractIds: string[]): Promise { diff --git a/packages/js-evo-sdk/src/identities/facade.ts b/packages/js-evo-sdk/src/identities/facade.ts index c7331b132fc..1b2c1c41960 100644 --- a/packages/js-evo-sdk/src/identities/facade.ts +++ b/packages/js-evo-sdk/src/identities/facade.ts @@ -9,7 +9,7 @@ export class IdentitiesFacade { this.sdk = sdk; } - async fetch(identityId: string): Promise { + async fetch(identityId: string): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentity(identityId); } @@ -19,7 +19,7 @@ export class IdentitiesFacade { return w.getIdentityWithProofInfo(identityId); } - async fetchUnproved(identityId: string): Promise { + async fetchUnproved(identityId: string): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityUnproved(identityId); } @@ -100,7 +100,7 @@ export class IdentitiesFacade { return w.getIdentityBalanceAndRevisionWithProofInfo(identityId); } - async byPublicKeyHash(publicKeyHash: string): Promise { + async byPublicKeyHash(publicKeyHash: string): Promise { const w = await this.sdk.getWasmSdkConnected(); return w.getIdentityByPublicKeyHash(publicKeyHash); } diff --git a/packages/wasm-sdk/tests/functional/dpns.spec.mjs b/packages/wasm-sdk/tests/functional/dpns.spec.mjs index 62800917ab8..c5c1724ca9f 100644 --- a/packages/wasm-sdk/tests/functional/dpns.spec.mjs +++ b/packages/wasm-sdk/tests/functional/dpns.spec.mjs @@ -21,26 +21,26 @@ describe('Document queries', function describeDocumentQueries() { it('lists DPNS documents (no filters)', async () => { const docs = await client.getDocuments(DPNS_CONTRACT, 'domain', null, null, 5, null, null); - expect(docs instanceof Map).to.be(true); + expect(docs).to.be.instanceOf(Map); }); it('queries with where clause', async () => { const where = JSON.stringify([['normalizedParentDomainName', '==', 'dash']]); const docs = await client.getDocuments(DPNS_CONTRACT, 'domain', where, null, 5, null, null); - expect(docs instanceof Map).to.be(true); + expect(docs).to.be.instanceOf(Map); }); it('queries with orderBy', async () => { const orderBy = JSON.stringify([['normalizedParentDomainName', 'asc']]); const docs = await client.getDocuments(DPNS_CONTRACT, 'domain', null, orderBy, 5, null, null); - expect(docs instanceof Map).to.be(true); + expect(docs).to.be.instanceOf(Map); }); it('complex where + orderBy', async () => { const where = JSON.stringify([['normalizedLabel', 'startsWith', 'test'], ['normalizedParentDomainName', '==', 'dash']]); const orderBy = JSON.stringify([['normalizedParentDomainName', 'asc'], ['normalizedLabel', 'asc']]); const docs = await client.getDocuments(DPNS_CONTRACT, 'domain', where, orderBy, 5, null, null); - expect(docs instanceof Map).to.be(true); + expect(docs).to.be.instanceOf(Map); }); it('getDocument by id (should handle invalid id gracefully)', async () => { @@ -52,6 +52,6 @@ describe('Document queries', function describeDocumentQueries() { it('fetches usernames for a known identity and verifies fields', async () => { const TEST_IDENTITY = '5DbLwAxGBzUzo81VewMUwn4b5P4bpv9FNFybi25XB5Bk'; const list = await client.getDpnsUsernames(TEST_IDENTITY, 10); - expect(Array.isArray(list)).to.be(true); + expect(list).to.be.an('array'); }); }); diff --git a/packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs b/packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs index 34e472ffece..17703fb4447 100644 --- a/packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs +++ b/packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs @@ -23,10 +23,10 @@ describe('Epochs and evonode blocks', function describeEpochs() { const start = Math.max(0, currentIndex - 5); const infos = await client.getEpochsInfo(start, 5, true); - expect(infos instanceof Map).to.be(true); + expect(infos).to.be.instanceOf(Map); const finalized = await client.getFinalizedEpochInfos(start, 5); - expect(finalized instanceof Map).to.be(true); + expect(finalized).to.be.instanceOf(Map); }); it('queries evonode proposed blocks by id/range', async () => { diff --git a/packages/wasm-sdk/tests/functional/protocol.spec.mjs b/packages/wasm-sdk/tests/functional/protocol.spec.mjs index 997e7494f98..ba9e3b35f4c 100644 --- a/packages/wasm-sdk/tests/functional/protocol.spec.mjs +++ b/packages/wasm-sdk/tests/functional/protocol.spec.mjs @@ -25,6 +25,6 @@ describe('Protocol versions', function describeProtocolVersions() { it('lists protocol upgrade vote statuses', async () => { const START_PROTX = '143dcd6a6b7684fde01e88a10e5d65de9a29244c5ecd586d14a342657025f113'; const res = await client.getProtocolVersionUpgradeVoteStatus(START_PROTX, 50); - expect(res).to.be.an('array'); + expect(res).to.be.instanceOf(Map); }); }); diff --git a/packages/wasm-sdk/tests/functional/system.spec.mjs b/packages/wasm-sdk/tests/functional/system.spec.mjs index 30f3e0b9f06..a1407a994d6 100644 --- a/packages/wasm-sdk/tests/functional/system.spec.mjs +++ b/packages/wasm-sdk/tests/functional/system.spec.mjs @@ -24,7 +24,7 @@ describe('System info', function describeSystemInfo() { it('getTotalCreditsInPlatform', async () => { const r = await client.getTotalCreditsInPlatform(); - expect(r).to.be.an('object'); - expect(String(r.totalCreditsInPlatform)).to.match(/^\d+$/); + expect(typeof r).to.equal('bigint'); + expect(String(r)).to.match(/^\d+$/); }); }); From fc83930d7f8af4200acb3907b798d7802ab48978 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 30 Oct 2025 12:42:11 +0700 Subject: [PATCH 28/44] build: fix docker image --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index d08c0d28cb9..f469d6dfaad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -393,6 +393,7 @@ COPY --parents \ packages/rs-sdk-trusted-context-provider \ packages/rs-platform-wallet \ packages/wasm-dpp \ + packages/wasm-dpp2 \ packages/wasm-drive-verify \ packages/rs-dapi-client \ packages/rs-sdk \ @@ -484,6 +485,7 @@ COPY --parents \ packages/rs-sdk-trusted-context-provider \ packages/rs-platform-wallet \ packages/wasm-dpp \ + packages/wasm-dpp2 \ packages/wasm-drive-verify \ packages/rs-dapi-client \ packages/rs-sdk \ @@ -569,6 +571,7 @@ COPY --parents \ packages/rs-json-schema-compatibility-validator \ # Common packages/wasm-dpp \ + packages/wasm-dpp2 \ packages/dashpay-contract \ packages/withdrawals-contract \ packages/wallet-utils-contract \ @@ -844,6 +847,7 @@ COPY --parents \ packages/rs-context-provider \ packages/rs-sdk-trusted-context-provider \ packages/wasm-dpp \ + packages/wasm-dpp2 \ packages/wasm-drive-verify \ packages/rs-dapi-client \ packages/rs-sdk \ From 3dbeddc7d47b74aa66a1a8188521abf17b303b87 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 30 Oct 2025 13:17:54 +0700 Subject: [PATCH 29/44] build: do not build wasm-dpp2 by default --- packages/wasm-dpp2/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wasm-dpp2/package.json b/packages/wasm-dpp2/package.json index 882d9cc1224..518cab2a407 100644 --- a/packages/wasm-dpp2/package.json +++ b/packages/wasm-dpp2/package.json @@ -28,7 +28,7 @@ "node": ">=18.18" }, "scripts": { - "build": "./scripts/build.sh && node ./scripts/bundle.cjs", + "build:dev": "./scripts/build.sh && node ./scripts/bundle.cjs", "build:release": "./scripts/build-optimized.sh && node ./scripts/bundle.cjs", "test": "yarn run test:unit", "test:unit": "mocha tests/unit/**/*.spec.mjs && karma start ./tests/karma/karma.conf.cjs --single-run", From c24080d9f9b42359a112ed40c7a40e3670216dd7 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 30 Oct 2025 15:43:37 +0700 Subject: [PATCH 30/44] build: build wasm-dpp2 by default but not for docker image --- Dockerfile | 3 ++- packages/wasm-dpp2/package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f469d6dfaad..4858c45b7c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -607,7 +607,8 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM yarn install --inline-builds && \ cp -R /platform/.yarn/unplugged /tmp/ && \ export SKIP_GRPC_PROTO_BUILD=1 && \ - yarn build && \ + # Build JS Dash SDK and dependencies + yarn run ultra -r --filter '+dash' --build && \ if [[ -x /usr/bin/sccache ]]; then sccache --show-stats; fi && \ # Remove target directory and rust packages to save space rm -rf target packages/rs-* diff --git a/packages/wasm-dpp2/package.json b/packages/wasm-dpp2/package.json index 518cab2a407..882d9cc1224 100644 --- a/packages/wasm-dpp2/package.json +++ b/packages/wasm-dpp2/package.json @@ -28,7 +28,7 @@ "node": ">=18.18" }, "scripts": { - "build:dev": "./scripts/build.sh && node ./scripts/bundle.cjs", + "build": "./scripts/build.sh && node ./scripts/bundle.cjs", "build:release": "./scripts/build-optimized.sh && node ./scripts/bundle.cjs", "test": "yarn run test:unit", "test:unit": "mocha tests/unit/**/*.spec.mjs && karma start ./tests/karma/karma.conf.cjs --single-run", From fadde6d50d0524d201d38721a9bb845fd925550d Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 30 Oct 2025 15:54:21 +0700 Subject: [PATCH 31/44] chore: remove unused deps --- Cargo.lock | 11 ----------- packages/wasm-dpp2/Cargo.toml | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d5c64f4929..65e78c0d273 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6414,15 +6414,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" -[[package]] -name = "talc" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fcad3be1cfe36eb7d716a04791eba36a197da9d9b6ea1e28e64ac569da3701d" -dependencies = [ - "lock_api", -] - [[package]] name = "tap" version = "1.0.1" @@ -7547,7 +7538,6 @@ version = "1.0.5" dependencies = [ "anyhow", "bincode 2.0.0-rc.3", - "bincode_derive", "dpp", "hex", "js-sys", @@ -7555,7 +7545,6 @@ dependencies = [ "serde-wasm-bindgen 0.5.0", "serde_json", "sha2", - "talc", "thiserror 1.0.69", "wasm-bindgen", ] diff --git a/packages/wasm-dpp2/Cargo.toml b/packages/wasm-dpp2/Cargo.toml index efe3816efef..f77791f02ff 100644 --- a/packages/wasm-dpp2/Cargo.toml +++ b/packages/wasm-dpp2/Cargo.toml @@ -7,9 +7,9 @@ edition = "2024" crate-type = ["cdylib", "lib"] [dependencies] -talc = { version = "=4.4.2", default-features = false, features = ["lock_api"] } +# TODO: Consider to use talc allocator +#talc = { version = "=4.4.2", default-features = false, features = ["lock_api"] } bincode = "=2.0.0-rc.3" -bincode_derive = "=2.0.0-rc.3" wasm-bindgen = { version = "=0.2.103", default-features = false, features = ["serde-serialize"] } dpp = { path = "../rs-dpp", default-features = false, features = [ "state-transition-signing", From 7572cff1422ef132afca92ae1647ab35b99bfdfc Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 30 Oct 2025 15:56:22 +0700 Subject: [PATCH 32/44] chore: remove web-sys deps --- Cargo.lock | 1 - packages/wasm-sdk/Cargo.toml | 9 --------- 2 files changed, 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 65e78c0d273..7ca753a52f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7618,7 +7618,6 @@ dependencies = [ "wasm-bindgen-futures", "wasm-dpp2", "wasm-sdk", - "web-sys", "wee_alloc", ] diff --git a/packages/wasm-sdk/Cargo.toml b/packages/wasm-sdk/Cargo.toml index 3863fe8a062..cc1b034d37a 100644 --- a/packages/wasm-sdk/Cargo.toml +++ b/packages/wasm-sdk/Cargo.toml @@ -65,15 +65,6 @@ drive = { path = "../rs-drive", default-features = false, features = [ ] } console_error_panic_hook = { version = "0.1.6" } thiserror = { version = "2.0.12" } -web-sys = { version = "0.3.64", features = [ - 'console', - 'Document', - 'Element', - 'HtmlElement', - 'Node', - 'Window', - 'Crypto', -] } wasm-bindgen = { version = "=0.2.103" } wasm-bindgen-futures = { version = "0.4.49" } drive-proof-verifier = { path = "../rs-drive-proof-verifier", default-features = false } # TODO: I think it's not needed (LKl) From 6b636a1351cc79872b62c8c67a36ef6e33d77ba9 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 30 Oct 2025 17:48:00 +0700 Subject: [PATCH 33/44] refactor: fix clippy warnings --- .../instant/instant_asset_lock_proof.rs | 10 +-- .../asset_lock_proof/instant/instant_lock.rs | 2 +- .../wasm-dpp2/src/asset_lock_proof/proof.rs | 5 +- packages/wasm-dpp2/src/block.rs | 35 ++++++-- packages/wasm-dpp2/src/core_script.rs | 2 +- .../src/data_contract/contract_bounds.rs | 7 +- .../src/data_contract/document/methods.rs | 11 +-- packages/wasm-dpp2/src/data_contract/model.rs | 6 +- packages/wasm-dpp2/src/error.rs | 2 - packages/wasm-dpp2/src/identifier.rs | 6 +- packages/wasm-dpp2/src/identity/model.rs | 12 ++- .../src/identity/partial_identity.rs | 2 +- packages/wasm-dpp2/src/identity/public_key.rs | 1 + .../identity/transitions/create_transition.rs | 2 +- .../credit_withdrawal_transition.rs | 9 +-- .../transitions/masternode_vote_transition.rs | 9 +-- .../transitions/public_key_in_creation.rs | 17 ++-- .../identity/transitions/top_up_transition.rs | 6 +- .../identity/transitions/update_transition.rs | 6 +- packages/wasm-dpp2/src/lib.rs | 12 ++- packages/wasm-dpp2/src/private_key.rs | 14 +++- .../base/state_transition.rs | 25 +++--- .../batch/batch_transition.rs | 2 +- .../batch/document_base_transition.rs | 5 +- .../batch/document_transitions/create.rs | 5 +- .../batch/prefunded_voting_balance.rs | 2 +- .../batch/token_base_transition.rs | 5 +- .../batch/token_pricing_schedule.rs | 2 +- .../batch/token_transitions/token_mint.rs | 5 +- .../batch/token_transitions/token_transfer.rs | 10 +-- .../src/tokens/configuration/action_taker.rs | 4 +- .../configuration/change_control_rules.rs | 9 +-- .../configuration/distribution_function.rs | 5 ++ .../configuration/distribution_recipient.rs | 4 +- .../configuration/distribution_rules.rs | 81 ++++++++++--------- .../src/tokens/configuration/group.rs | 2 +- .../configuration/perpetual_distribution.rs | 2 +- .../pre_programmed_distribution.rs | 4 +- .../configuration/token_configuration.rs | 13 +-- packages/wasm-dpp2/src/utils.rs | 2 +- .../src/voting/resource_vote_choice.rs | 4 +- packages/wasm-dpp2/src/voting/vote.rs | 6 +- packages/wasm-dpp2/src/voting/vote_poll.rs | 16 ++-- packages/wasm-sdk/src/lib.rs | 2 +- packages/wasm-sdk/src/queries/epoch.rs | 2 +- packages/wasm-sdk/src/queries/group.rs | 4 +- packages/wasm-sdk/src/queries/identity.rs | 4 +- packages/wasm-sdk/src/queries/mod.rs | 4 - packages/wasm-sdk/src/queries/system.rs | 50 +++--------- packages/wasm-sdk/src/queries/token.rs | 14 ++-- packages/wasm-sdk/src/queries/voting/state.rs | 2 +- packages/wasm-sdk/src/queries/voting/votes.rs | 19 +++-- 52 files changed, 222 insertions(+), 268 deletions(-) diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_asset_lock_proof.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_asset_lock_proof.rs index 075d7031eba..2ca5f4fe8b2 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_asset_lock_proof.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_asset_lock_proof.rs @@ -88,18 +88,12 @@ impl InstantAssetLockProofWasm { #[wasm_bindgen(js_name = "getOutput")] pub fn get_output(&self) -> Option { - match self.0.output() { - Some(output) => Some(output.clone().into()), - None => None, - } + self.0.output().map(|output| output.clone().into()) } #[wasm_bindgen(js_name = "getOutPoint")] pub fn get_out_point(&self) -> Option { - match self.0.out_point() { - Some(output) => Some(output.clone().into()), - None => None, - } + self.0.out_point().map(|output| output.into()) } #[wasm_bindgen(getter = "outputIndex")] diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs index 86d771ebe9e..caa1444c80b 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs @@ -69,7 +69,7 @@ impl InstantLockWasm { self.0 .inputs .iter() - .map(|input| input.clone().into()) + .map(|input| (*input).into()) .collect() } diff --git a/packages/wasm-dpp2/src/asset_lock_proof/proof.rs b/packages/wasm-dpp2/src/asset_lock_proof/proof.rs index 08fdb45e774..2dcd377e73a 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/proof.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/proof.rs @@ -129,10 +129,7 @@ impl AssetLockProofWasm { #[wasm_bindgen(js_name = "getOutPoint")] pub fn get_out_point(&self) -> Option { - match self.0.out_point() { - Some(out_point) => Some(OutPointWasm::from(out_point)), - None => None, - } + self.0.out_point().map(OutPointWasm::from) } #[wasm_bindgen(js_name = "createIdentityId")] diff --git a/packages/wasm-dpp2/src/block.rs b/packages/wasm-dpp2/src/block.rs index a9606596ff4..576ee7fac33 100644 --- a/packages/wasm-dpp2/src/block.rs +++ b/packages/wasm-dpp2/src/block.rs @@ -4,21 +4,40 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen(js_name = "BlockInfo")] #[derive(Clone)] pub struct BlockInfoWasm { - #[wasm_bindgen(getter = "timeMs")] - pub time_ms: u64, + time_ms: u64, + height: u64, + core_height: u64, + epoch_index: u16, +} + +#[wasm_bindgen(js_class = BlockInfo)] +impl BlockInfoWasm { + #[wasm_bindgen(getter = timeMs)] + pub fn time_ms(&self) -> u64 { + self.time_ms + } + #[wasm_bindgen(getter)] - pub height: u64, - #[wasm_bindgen(getter = "coreHeight")] - pub core_height: u64, - #[wasm_bindgen(getter = "epochIndex")] - pub epoch_index: u16, + pub fn height(&self) -> u64 { + self.height + } + + #[wasm_bindgen(getter = coreHeight)] + pub fn core_height(&self) -> u64 { + self.core_height + } + + #[wasm_bindgen(getter = epochIndex)] + pub fn epoch_index(&self) -> u16 { + self.epoch_index + } } impl From for BlockInfoWasm { fn from(block: BlockInfo) -> Self { Self { time_ms: block.time_ms, - height: block.height as u64, + height: block.height, core_height: block.core_height as u64, epoch_index: block.epoch.index, } diff --git a/packages/wasm-dpp2/src/core_script.rs b/packages/wasm-dpp2/src/core_script.rs index 35b703e5778..0df47fca743 100644 --- a/packages/wasm-dpp2/src/core_script.rs +++ b/packages/wasm-dpp2/src/core_script.rs @@ -80,7 +80,7 @@ impl CoreScriptWasm { } #[wasm_bindgen(js_name = "toString")] - pub fn to_string(&self) -> String { + pub fn to_string_js(&self) -> String { self.0.to_string(Base64) } diff --git a/packages/wasm-dpp2/src/data_contract/contract_bounds.rs b/packages/wasm-dpp2/src/data_contract/contract_bounds.rs index 14fc0694d43..f86c5936679 100644 --- a/packages/wasm-dpp2/src/data_contract/contract_bounds.rs +++ b/packages/wasm-dpp2/src/data_contract/contract_bounds.rs @@ -76,15 +76,12 @@ impl ContractBoundsWasm { #[wasm_bindgen(getter = "identifier")] pub fn id(&self) -> IdentifierWasm { - self.0.identifier().clone().into() + (*self.0.identifier()).into() } #[wasm_bindgen(getter = "documentTypeName")] pub fn document_type_name(&self) -> Option { - match self.0.document_type() { - Some(name) => Some(name.clone()), - None => None, - } + self.0.document_type().cloned() } #[wasm_bindgen(getter = "contractBoundsType")] diff --git a/packages/wasm-dpp2/src/data_contract/document/methods.rs b/packages/wasm-dpp2/src/data_contract/document/methods.rs index 29247a01d12..e9ac54ad6bd 100644 --- a/packages/wasm-dpp2/src/data_contract/document/methods.rs +++ b/packages/wasm-dpp2/src/data_contract/document/methods.rs @@ -93,10 +93,7 @@ impl DocumentWasm { #[wasm_bindgen(getter=entropy)] pub fn get_entropy(&self) -> Option> { - match self.entropy { - Some(entropy) => Some(entropy.to_vec()), - None => None, - } + self.entropy.map(|entropy| entropy.to_vec()) } #[wasm_bindgen(getter=dataContractId)] @@ -180,7 +177,7 @@ impl DocumentWasm { #[wasm_bindgen(setter=id)] pub fn set_id(&mut self, id: &JsValue) -> WasmDppResult<()> { - self.id = IdentifierWasm::try_from(id)?.clone(); + self.id = IdentifierWasm::try_from(id)?; Ok(()) } @@ -214,7 +211,7 @@ impl DocumentWasm { #[wasm_bindgen(setter=ownerId)] pub fn set_owner_id(&mut self, id: &JsValue) -> WasmDppResult<()> { - self.owner_id = IdentifierWasm::try_from(id)?.clone(); + self.owner_id = IdentifierWasm::try_from(id)?; Ok(()) } @@ -454,6 +451,6 @@ impl DocumentWasm { } fn set_data_contract_id(&mut self, data_contract_id: &IdentifierWasm) { - self.data_contract_id = data_contract_id.clone(); + self.data_contract_id = *data_contract_id; } } diff --git a/packages/wasm-dpp2/src/data_contract/model.rs b/packages/wasm-dpp2/src/data_contract/model.rs index 69f3d768a3d..518d4d49859 100644 --- a/packages/wasm-dpp2/src/data_contract/model.rs +++ b/packages/wasm-dpp2/src/data_contract/model.rs @@ -226,7 +226,7 @@ impl DataContractWasm { }; let rs_data_contract = DataContract::versioned_deserialize( - &bytes.as_slice(), + bytes.as_slice(), full_validation, &platform_version.into(), )?; @@ -339,7 +339,7 @@ impl DataContractWasm { for (key, value) in self.0.tokens().iter() { Reflect::set( &tokens_object, - &JsValue::from(key.clone()), + &JsValue::from(*key), &JsValue::from(TokenConfigurationWasm::from(value.clone())), ) .map_err(|err| { @@ -361,7 +361,7 @@ impl DataContractWasm { for (key, value) in self.0.groups().iter() { Reflect::set( &groups_object, - &JsValue::from(key.clone()), + &JsValue::from(*key), &JsValue::from(GroupWasm::from(value.clone())), ) .map_err(|err| { diff --git a/packages/wasm-dpp2/src/error.rs b/packages/wasm-dpp2/src/error.rs index a884609742c..8371f77e691 100644 --- a/packages/wasm-dpp2/src/error.rs +++ b/packages/wasm-dpp2/src/error.rs @@ -1,9 +1,7 @@ use anyhow::Error as AnyhowError; use dpp::ProtocolError; -use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; -use crate::utils::JsValueExt; /// Structured error returned by wasm-dpp2 APIs. #[wasm_bindgen] diff --git a/packages/wasm-dpp2/src/identifier.rs b/packages/wasm-dpp2/src/identifier.rs index 2b827f08db7..3642aa0faef 100644 --- a/packages/wasm-dpp2/src/identifier.rs +++ b/packages/wasm-dpp2/src/identifier.rs @@ -29,7 +29,7 @@ impl From<[u8; 32]> for IdentifierWasm { impl From<&IdentifierWasm> for Identifier { fn from(identifier: &IdentifierWasm) -> Self { - identifier.clone().into() + (*identifier).into() } } @@ -56,7 +56,7 @@ impl TryFrom for IdentifierWasm { match value.is_object() { true => match get_class_type(&value) { Ok(class_type) => match class_type.as_str() { - "Identifier" => Ok(value.to_wasm::("Identifier")?.clone()), + "Identifier" => Ok(*value.to_wasm::("Identifier")?), "" => Ok(identifier_from_js_value(&value)?.into()), _ => Err(WasmDppError::invalid_argument(format!( "Invalid type of data for identifier (passed {})", @@ -163,6 +163,6 @@ impl IdentifierWasm { impl IdentifierWasm { pub fn to_slice(&self) -> [u8; 32] { - self.0.as_bytes().clone() + *self.0.as_bytes() } } diff --git a/packages/wasm-dpp2/src/identity/model.rs b/packages/wasm-dpp2/src/identity/model.rs index 6020210f173..edb3e705f72 100644 --- a/packages/wasm-dpp2/src/identity/model.rs +++ b/packages/wasm-dpp2/src/identity/model.rs @@ -94,14 +94,12 @@ impl IdentityWasm { #[wasm_bindgen(js_name = "getPublicKeys")] pub fn get_public_keys(&self) -> Vec { - let keys = self - .0 - .public_keys() - .iter() - .map(|(_index, key)| IdentityPublicKeyWasm::from(key.clone())) - .collect(); + - keys + self + .0 + .public_keys().values().map(|key| IdentityPublicKeyWasm::from(key.clone())) + .collect() } #[wasm_bindgen(js_name = "fromHex")] diff --git a/packages/wasm-dpp2/src/identity/partial_identity.rs b/packages/wasm-dpp2/src/identity/partial_identity.rs index 3b9bdb3fd81..5e8010212e0 100644 --- a/packages/wasm-dpp2/src/identity/partial_identity.rs +++ b/packages/wasm-dpp2/src/identity/partial_identity.rs @@ -90,7 +90,7 @@ impl PartialIdentityWasm { arr.push(&v.into()); } - arr.into() + arr } #[wasm_bindgen(setter = "id")] diff --git a/packages/wasm-dpp2/src/identity/public_key.rs b/packages/wasm-dpp2/src/identity/public_key.rs index dfa8ec8d058..cced3ab35fe 100644 --- a/packages/wasm-dpp2/src/identity/public_key.rs +++ b/packages/wasm-dpp2/src/identity/public_key.rs @@ -50,6 +50,7 @@ impl IdentityPublicKeyWasm { } #[wasm_bindgen(constructor)] + #[allow(clippy::too_many_arguments)] pub fn new( id: u32, js_purpose: JsValue, diff --git a/packages/wasm-dpp2/src/identity/transitions/create_transition.rs b/packages/wasm-dpp2/src/identity/transitions/create_transition.rs index 57a68060814..63bb9708a83 100644 --- a/packages/wasm-dpp2/src/identity/transitions/create_transition.rs +++ b/packages/wasm-dpp2/src/identity/transitions/create_transition.rs @@ -61,7 +61,7 @@ impl IdentityCreateTransitionWasm { public_keys: public_keys.iter().map(|key| key.clone().into()).collect(), asset_lock_proof: asset_lock.clone().into(), user_fee_increase: user_fee_increase.unwrap_or(0), - signature: BinaryData::from(signature.unwrap_or(vec![])), + signature: BinaryData::from(signature.unwrap_or_default()), identity_id: asset_lock.create_identifier()?.into(), }, ))) diff --git a/packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs b/packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs index 7527e66c32f..50781d00268 100644 --- a/packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs +++ b/packages/wasm-dpp2/src/identity/transitions/credit_withdrawal_transition.rs @@ -76,10 +76,7 @@ impl IdentityCreditWithdrawalTransitionWasm { #[wasm_bindgen(getter = "outputScript")] pub fn get_output_script(&self) -> Option { - match self.0.output_script() { - None => None, - Some(script) => Some(script.into()), - } + self.0.output_script().map(|script| script.into()) } #[wasm_bindgen(getter = "pooling")] @@ -112,7 +109,7 @@ impl IdentityCreditWithdrawalTransitionWasm { self.0 .purpose_requirement() .iter() - .map(|purpose| PurposeWasm::from(purpose.clone()).into()) + .map(|purpose| PurposeWasm::from(*purpose).into()) .collect() } @@ -121,7 +118,7 @@ impl IdentityCreditWithdrawalTransitionWasm { self.0 .modified_data_ids() .iter() - .map(|id| id.clone().into()) + .map(|id| (*id).into()) .collect() } diff --git a/packages/wasm-dpp2/src/identity/transitions/masternode_vote_transition.rs b/packages/wasm-dpp2/src/identity/transitions/masternode_vote_transition.rs index 5ae9c503c2b..fa8d6c75fa6 100644 --- a/packages/wasm-dpp2/src/identity/transitions/masternode_vote_transition.rs +++ b/packages/wasm-dpp2/src/identity/transitions/masternode_vote_transition.rs @@ -64,7 +64,7 @@ impl MasternodeVoteTransitionWasm { vote: vote.clone().into(), nonce, signature_public_key_id: signature_public_key.unwrap_or(0), - signature: BinaryData::from(signature.unwrap_or(vec![])), + signature: BinaryData::from(signature.unwrap_or_default()), }, ))) } @@ -183,10 +183,7 @@ impl MasternodeVoteTransitionWasm { #[wasm_bindgen(getter = "assetLock")] pub fn get_asset_lock_proof(&self) -> Option { - match self.0.optional_asset_lock_proof().clone() { - None => None, - Some(asset_lock_proof) => Some(AssetLockProofWasm::from(asset_lock_proof.clone())), - } + self.0.optional_asset_lock_proof().map(|asset_lock_proof| AssetLockProofWasm::from(asset_lock_proof.clone())) } #[wasm_bindgen(setter = "userFeeIncrease")] @@ -199,7 +196,7 @@ impl MasternodeVoteTransitionWasm { self.0 .modified_data_ids() .iter() - .map(|id| id.clone().into()) + .map(|id| (*id).into()) .collect() } diff --git a/packages/wasm-dpp2/src/identity/transitions/public_key_in_creation.rs b/packages/wasm-dpp2/src/identity/transitions/public_key_in_creation.rs index a5073584dfe..d3463bfefb8 100644 --- a/packages/wasm-dpp2/src/identity/transitions/public_key_in_creation.rs +++ b/packages/wasm-dpp2/src/identity/transitions/public_key_in_creation.rs @@ -46,10 +46,7 @@ impl TryFrom for IdentityPublicKeyInCreationWasm { impl From for IdentityPublicKey { fn from(value: IdentityPublicKeyInCreationWasm) -> Self { - let contract_bounds = match value.0.contract_bounds() { - None => None, - Some(bounds) => Some(bounds.clone()), - }; + let contract_bounds = value.0.contract_bounds().cloned(); IdentityPublicKey::V0(IdentityPublicKeyV0 { id: value.0.id(), @@ -77,6 +74,7 @@ impl IdentityPublicKeyInCreationWasm { } #[wasm_bindgen(constructor)] + #[allow(clippy::too_many_arguments)] pub fn new( id: u32, js_purpose: JsValue, @@ -110,14 +108,14 @@ impl IdentityPublicKeyInCreationWasm { contract_bounds, read_only, data: BinaryData::from(binary_data), - signature: BinaryData::from(signature.unwrap_or(Vec::new())), + signature: BinaryData::from(signature.unwrap_or_default()), }), )) } #[wasm_bindgen(js_name = toIdentityPublicKey)] pub fn to_identity_public_key(&self) -> WasmDppResult { - Ok(IdentityPublicKeyWasm::new( + IdentityPublicKeyWasm::new( self.0.id(), JsValue::from(PurposeWasm::from(self.0.purpose())), JsValue::from(SecurityLevelWasm::from(self.0.security_level())), @@ -126,7 +124,7 @@ impl IdentityPublicKeyInCreationWasm { self.0.data().to_string(Hex).as_str(), None, &JsValue::from(self.get_contract_bounds().clone()), - )?) + ) } #[wasm_bindgen(js_name = "getHash")] @@ -137,10 +135,7 @@ impl IdentityPublicKeyInCreationWasm { #[wasm_bindgen(getter = "contractBounds")] pub fn get_contract_bounds(&self) -> Option { - match self.0.contract_bounds() { - Some(bounds) => Some(ContractBoundsWasm::from(bounds.clone())), - None => None, - } + self.0.contract_bounds().map(|bounds| ContractBoundsWasm::from(bounds.clone())) } #[wasm_bindgen(getter = keyId)] diff --git a/packages/wasm-dpp2/src/identity/transitions/top_up_transition.rs b/packages/wasm-dpp2/src/identity/transitions/top_up_transition.rs index 7faab098e3b..60d790ea234 100644 --- a/packages/wasm-dpp2/src/identity/transitions/top_up_transition.rs +++ b/packages/wasm-dpp2/src/identity/transitions/top_up_transition.rs @@ -54,7 +54,7 @@ impl IdentityTopUpTransitionWasm { self.0 .modified_data_ids() .iter() - .map(|id| id.clone().into()) + .map(|id| (*id).into()) .collect() } @@ -73,7 +73,7 @@ impl IdentityTopUpTransitionWasm { #[wasm_bindgen(getter = "identityIdentifier")] pub fn get_identity_identifier(&self) -> IdentifierWasm { - self.0.identity_id().clone().into() + (*self.0.identity_id()).into() } #[wasm_bindgen(getter = "assetLockProof")] @@ -93,7 +93,7 @@ impl IdentityTopUpTransitionWasm { ) -> WasmDppResult<()> { let identity_identifier: Identifier = IdentifierWasm::try_from(js_identity_identifier)?.into(); - self.0.set_identity_id(identity_identifier.clone().into()); + self.0.set_identity_id(identity_identifier); Ok(()) } diff --git a/packages/wasm-dpp2/src/identity/transitions/update_transition.rs b/packages/wasm-dpp2/src/identity/transitions/update_transition.rs index cfdfb48d763..198278f0133 100644 --- a/packages/wasm-dpp2/src/identity/transitions/update_transition.rs +++ b/packages/wasm-dpp2/src/identity/transitions/update_transition.rs @@ -86,7 +86,7 @@ impl IdentityUpdateTransitionWasm { self.0 .purpose_requirement() .iter() - .map(|purpose| PurposeWasm::from(purpose.clone()).into()) + .map(|purpose| PurposeWasm::from(*purpose).into()) .collect() } @@ -95,7 +95,7 @@ impl IdentityUpdateTransitionWasm { self.0 .modified_data_ids() .iter() - .map(|id| id.clone().into()) + .map(|id| (*id).into()) .collect() } @@ -140,7 +140,7 @@ impl IdentityUpdateTransitionWasm { #[wasm_bindgen(setter = "identityIdentifier")] pub fn set_identity_identifier(&mut self, js_identity_id: &JsValue) -> WasmDppResult<()> { let identity_id = IdentifierWasm::try_from(js_identity_id)?; - self.0.set_identity_id(identity_id.clone().into()); + self.0.set_identity_id(identity_id.into()); Ok(()) } diff --git a/packages/wasm-dpp2/src/lib.rs b/packages/wasm-dpp2/src/lib.rs index e807a504d39..34b16d66150 100644 --- a/packages/wasm-dpp2/src/lib.rs +++ b/packages/wasm-dpp2/src/lib.rs @@ -28,10 +28,18 @@ pub mod tokens; pub mod utils; pub mod voting; -pub use data_contract::*; +pub use data_contract::{ + ContractBoundsWasm, DataContractCreateTransitionWasm, DataContractUpdateTransitionWasm, + DataContractWasm, DocumentWasm, tokens_configuration_from_js_value, +}; pub use epoch::*; pub use group::*; -pub use identity::*; +pub use identity::{ + IdentityCreateTransitionWasm, IdentityCreditTransferWasm, + IdentityCreditWithdrawalTransitionWasm, IdentityPublicKeyInCreationWasm, + IdentityPublicKeyWasm, IdentityTopUpTransitionWasm, IdentityUpdateTransitionWasm, + IdentityWasm, MasternodeVoteTransitionWasm, PartialIdentityWasm, +}; pub use state_transitions::base::{GroupStateTransitionInfoWasm, StateTransitionWasm}; pub use tokens::*; pub use voting::{ diff --git a/packages/wasm-dpp2/src/private_key.rs b/packages/wasm-dpp2/src/private_key.rs index 1df7a1d7d37..f1368448460 100644 --- a/packages/wasm-dpp2/src/private_key.rs +++ b/packages/wasm-dpp2/src/private_key.rs @@ -1,3 +1,5 @@ +use std::convert::TryInto; + use crate::enums::network::NetworkWasm; use crate::error::{WasmDppError, WasmDppResult}; use crate::public_key::PublicKeyWasm; @@ -35,7 +37,11 @@ impl PrivateKeyWasm { pub fn from_bytes(bytes: Vec, js_network: JsValue) -> WasmDppResult { let network = NetworkWasm::try_from(js_network)?; - let pk = PrivateKey::from_slice(bytes.as_slice(), network.into()) + let key_bytes: [u8; 32] = bytes.try_into().map_err(|_| { + WasmDppError::invalid_argument("Private key bytes must be exactly 32 bytes".to_string()) + })?; + + let pk = PrivateKey::from_byte_array(&key_bytes, network.into()) .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; Ok(PrivateKeyWasm(pk)) @@ -48,7 +54,11 @@ impl PrivateKeyWasm { let bytes = Vec::from_hex(hex_key) .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; - let pk = PrivateKey::from_slice(bytes.as_slice(), network.into()) + let key_bytes: [u8; 32] = bytes.try_into().map_err(|_| { + WasmDppError::invalid_argument("Private key hex must decode to 32 bytes".to_string()) + })?; + + let pk = PrivateKey::from_byte_array(&key_bytes, network.into()) .map_err(|err| WasmDppError::invalid_argument(err.to_string()))?; Ok(PrivateKeyWasm(pk)) diff --git a/packages/wasm-dpp2/src/state_transitions/base/state_transition.rs b/packages/wasm-dpp2/src/state_transitions/base/state_transition.rs index af2ebf2479b..42cb39a101d 100644 --- a/packages/wasm-dpp2/src/state_transitions/base/state_transition.rs +++ b/packages/wasm-dpp2/src/state_transitions/base/state_transition.rs @@ -101,7 +101,7 @@ impl StateTransitionWasm { }; self.0.sign_by_private_key( - &private_key.to_bytes().as_slice(), + private_key.to_bytes().as_slice(), KeyType::from(key_type), &MockBLS {}, )?; @@ -258,13 +258,11 @@ impl StateTransitionWasm { #[wasm_bindgen(js_name = "hash")] pub fn get_hash(&self, skip_signature: bool) -> WasmDppResult { - let payload: Vec; - - if skip_signature { - payload = self.0.signable_bytes()?; + let payload = if skip_signature { + self.0.signable_bytes()? } else { - payload = dpp::serialization::PlatformSerializable::serialize_to_bytes(&self.0)?; - } + dpp::serialization::PlatformSerializable::serialize_to_bytes(&self.0)? + }; Ok(Sha256::digest(payload).to_hex_string(Lower)) } @@ -313,15 +311,10 @@ impl StateTransitionWasm { pub fn get_purpose_requirement(&self) -> Option> { let requirements = self.0.purpose_requirement(); - match requirements { - None => None, - Some(req) => Some( - req.iter() - .map(|purpose| PurposeWasm::from(purpose.clone())) + requirements.map(|req| req.iter() + .map(|purpose| PurposeWasm::from(*purpose)) .map(String::from) - .collect(), - ), - } + .collect()) } #[wasm_bindgen(js_name = "getKeyLevelRequirement")] @@ -337,7 +330,7 @@ impl StateTransitionWasm { None => Ok(None), Some(req) => Ok(Some( req.iter() - .map(|security_level| SecurityLevelWasm::from(security_level.clone())) + .map(|security_level| SecurityLevelWasm::from(*security_level)) .map(String::from) .collect(), )), diff --git a/packages/wasm-dpp2/src/state_transitions/batch/batch_transition.rs b/packages/wasm-dpp2/src/state_transitions/batch/batch_transition.rs index e1600cb94da..a473600d70f 100644 --- a/packages/wasm-dpp2/src/state_transitions/batch/batch_transition.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/batch_transition.rs @@ -159,7 +159,7 @@ impl BatchTransitionWasm { self.0 .modified_data_ids() .iter() - .map(|id| id.clone().into()) + .map(|id| (*id).into()) .collect() } diff --git a/packages/wasm-dpp2/src/state_transitions/batch/document_base_transition.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_base_transition.rs index a66bb0294e2..ba0a1cf3115 100644 --- a/packages/wasm-dpp2/src/state_transitions/batch/document_base_transition.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/document_base_transition.rs @@ -93,10 +93,7 @@ impl DocumentBaseTransitionWasm { #[wasm_bindgen(getter = "tokenPaymentInfo")] pub fn get_token_payment_info(&self) -> Option { - match self.0.token_payment_info() { - None => None, - Some(info) => Some(info.into()), - } + self.0.token_payment_info().map(|info| info.into()) } #[wasm_bindgen(setter = "id")] diff --git a/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/create.rs b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/create.rs index ec785ce76fe..a4eb1c473a3 100644 --- a/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/create.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/document_transitions/create.rs @@ -130,10 +130,7 @@ impl DocumentCreateTransitionWasm { pub fn get_prefunded_voting_balance(&self) -> Option { let rs_balance = self.0.prefunded_voting_balance(); - match rs_balance { - Some(balance) => Some(balance.clone().into()), - None => None, - } + rs_balance.as_ref().map(|balance| balance.clone().into()) } #[wasm_bindgen(setter = "prefundedVotingBalance")] diff --git a/packages/wasm-dpp2/src/state_transitions/batch/prefunded_voting_balance.rs b/packages/wasm-dpp2/src/state_transitions/batch/prefunded_voting_balance.rs index fdeda7e1cf8..4369ec2b4c9 100644 --- a/packages/wasm-dpp2/src/state_transitions/batch/prefunded_voting_balance.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/prefunded_voting_balance.rs @@ -50,6 +50,6 @@ impl PrefundedVotingBalanceWasm { #[wasm_bindgen(getter)] pub fn credits(&self) -> Credits { - self.credits.clone() + self.credits } } diff --git a/packages/wasm-dpp2/src/state_transitions/batch/token_base_transition.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_base_transition.rs index 736f63aa1d2..be34e7efc39 100644 --- a/packages/wasm-dpp2/src/state_transitions/batch/token_base_transition.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_base_transition.rs @@ -90,10 +90,7 @@ impl TokenBaseTransitionWasm { #[wasm_bindgen(getter = usingGroupInfo)] pub fn get_using_group_info(&self) -> Option { - match self.0.using_group_info() { - Some(using_group_info) => Some(using_group_info.clone().into()), - None => None, - } + self.0.using_group_info().map(|using_group_info| using_group_info.into()) } #[wasm_bindgen(setter = identityContractNonce)] diff --git a/packages/wasm-dpp2/src/state_transitions/batch/token_pricing_schedule.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_pricing_schedule.rs index 239ac4b87ab..16b52fa3213 100644 --- a/packages/wasm-dpp2/src/state_transitions/batch/token_pricing_schedule.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_pricing_schedule.rs @@ -89,7 +89,7 @@ impl TokenPricingScheduleWasm { Reflect::set( &price_object, &JsValue::from(key.to_string()), - &value.clone().into(), + &(*value).into(), ) .map_err(|err| { let message = err.error_message(); diff --git a/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_mint.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_mint.rs index 522bd661f95..bcbe2891c50 100644 --- a/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_mint.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_mint.rs @@ -63,10 +63,7 @@ impl TokenMintTransitionWasm { #[wasm_bindgen(getter = issuedToIdentityId)] pub fn issued_to_identity_id(&self) -> Option { - match self.0.issued_to_identity_id() { - None => None, - Some(id) => Some(id.into()), - } + self.0.issued_to_identity_id().map(|id| id.into()) } #[wasm_bindgen(getter = amount)] diff --git a/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_transfer.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_transfer.rs index 0fc5e974e09..65bb6d2f307 100644 --- a/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_transfer.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_transfer.rs @@ -103,18 +103,12 @@ impl TokenTransferTransitionWasm { #[wasm_bindgen(getter = "sharedEncryptedNote")] pub fn get_shared_encrypted_note(&self) -> Option { - match self.clone().0.shared_encrypted_note_owned() { - Some(shared_encrypted_note) => Some(shared_encrypted_note.into()), - None => None, - } + self.clone().0.shared_encrypted_note_owned().map(|shared_encrypted_note| shared_encrypted_note.into()) } #[wasm_bindgen(getter = "privateEncryptedNote")] pub fn get_private_encrypted_note(&self) -> Option { - match self.clone().0.private_encrypted_note_owned() { - Some(private_encrypted_note) => Some(private_encrypted_note.into()), - None => None, - } + self.clone().0.private_encrypted_note_owned().map(|private_encrypted_note| private_encrypted_note.into()) } #[wasm_bindgen(getter = recipientId)] diff --git a/packages/wasm-dpp2/src/tokens/configuration/action_taker.rs b/packages/wasm-dpp2/src/tokens/configuration/action_taker.rs index f7dbae79b17..3b214e2437a 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/action_taker.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/action_taker.rs @@ -80,12 +80,12 @@ impl ActionTakerWasm { pub fn get_value(&self) -> JsValue { match &self.0 { ActionTaker::SingleIdentity(value) => { - JsValue::from(IdentifierWasm::from(value.clone())) + JsValue::from(IdentifierWasm::from(*value)) } ActionTaker::SpecifiedIdentities(value) => { let array = Array::new(); for identifier in value.iter() { - array.push(&IdentifierWasm::from(identifier.clone()).into()); + array.push(&IdentifierWasm::from(*identifier).into()); } array.into() } diff --git a/packages/wasm-dpp2/src/tokens/configuration/change_control_rules.rs b/packages/wasm-dpp2/src/tokens/configuration/change_control_rules.rs index 35923acd97c..2bcec6420f0 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/change_control_rules.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/change_control_rules.rs @@ -61,15 +61,14 @@ impl ChangeControlRulesWasm { #[wasm_bindgen(getter = "authorizedToMakeChange")] pub fn get_authorized_to_make_change(&self) -> AuthorizedActionTakersWasm { - self.0 - .authorized_to_make_change_action_takers() - .clone() + (*self.0 + .authorized_to_make_change_action_takers()) .into() } #[wasm_bindgen(getter = "adminActionTakers")] pub fn get_admin_action_takers(&self) -> AuthorizedActionTakersWasm { - self.0.admin_action_takers().clone().into() + (*self.0.admin_action_takers()).into() } #[wasm_bindgen(getter = "changingAuthorizedActionTakersToNoOneAllowed")] @@ -201,7 +200,7 @@ impl ChangeControlRulesWasm { Ok(self.0.can_change_admin_action_takers( &admin_action_takers.clone().into(), - &contract_owner_id.clone().into(), + &contract_owner_id.into(), main_group, &groups, &action_taker.clone().into(), diff --git a/packages/wasm-dpp2/src/tokens/configuration/distribution_function.rs b/packages/wasm-dpp2/src/tokens/configuration/distribution_function.rs index e5c137912b6..30ea9824daf 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/distribution_function.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/distribution_function.rs @@ -51,6 +51,7 @@ impl DistributionFunctionWasm { } #[wasm_bindgen(js_name = "StepDecreasingAmount")] + #[allow(clippy::too_many_arguments)] pub fn step_decreasing_amount( step_count: u32, decrease_per_interval_numerator: u16, @@ -127,6 +128,7 @@ impl DistributionFunctionWasm { } #[wasm_bindgen(js_name = "Polynomial")] + #[allow(clippy::too_many_arguments)] pub fn polynomial( a: i64, d: u64, @@ -152,6 +154,7 @@ impl DistributionFunctionWasm { } #[wasm_bindgen(js_name = "Exponential")] + #[allow(clippy::too_many_arguments)] pub fn exponential( a: u64, d: u64, @@ -177,6 +180,7 @@ impl DistributionFunctionWasm { } #[wasm_bindgen(js_name = "Logarithmic")] + #[allow(clippy::too_many_arguments)] pub fn logarithmic( a: i64, d: u64, @@ -202,6 +206,7 @@ impl DistributionFunctionWasm { } #[wasm_bindgen(js_name = "InvertedLogarithmic")] + #[allow(clippy::too_many_arguments)] pub fn inverted_logarithmic( a: i64, d: u64, diff --git a/packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs b/packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs index 44c0febef10..1b10e5b8a21 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs @@ -58,10 +58,10 @@ impl TokenDistributionRecipientWasm { String::from("EvonodesByParticipation") } TokenDistributionRecipient::ContractOwner => String::from("ContractOwner"), - TokenDistributionRecipient::Identity(identity) => String::from(format!( + TokenDistributionRecipient::Identity(identity) => format!( "Identity({})", IdentifierWasm::from(identity).get_base58() - )), + ), } } diff --git a/packages/wasm-dpp2/src/tokens/configuration/distribution_rules.rs b/packages/wasm-dpp2/src/tokens/configuration/distribution_rules.rs index 83b8521fe66..f8ccdc03e2e 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/distribution_rules.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/distribution_rules.rs @@ -9,8 +9,6 @@ use dpp::data_contract::associated_token::token_distribution_rules::accessors::v TokenDistributionRulesV0Getters, TokenDistributionRulesV0Setters, }; use dpp::data_contract::associated_token::token_distribution_rules::v0::TokenDistributionRulesV0; -use dpp::data_contract::associated_token::token_perpetual_distribution::TokenPerpetualDistribution; -use dpp::data_contract::associated_token::token_pre_programmed_distribution::TokenPreProgrammedDistribution; use dpp::prelude::Identifier; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -44,6 +42,7 @@ impl TokenDistributionRulesWasm { } #[wasm_bindgen(constructor)] + #[allow(clippy::too_many_arguments)] pub fn new( js_perpetual_distribution: &JsValue, perpetual_distribution_rules: &ChangeControlRulesWasm, @@ -54,33 +53,38 @@ impl TokenDistributionRulesWasm { minting_allow_choosing_destination_rules: &ChangeControlRulesWasm, change_direct_purchase_pricing_rules: &ChangeControlRulesWasm, ) -> WasmDppResult { - let perpetual_distribution = match js_perpetual_distribution.is_undefined() { - true => None, - false => Some(TokenPerpetualDistribution::from( + let perpetual_distribution = if js_perpetual_distribution.is_undefined() { + None + } else { + Some( js_perpetual_distribution .to_wasm::("TokenPerpetualDistribution")? - .clone(), - )), + .clone() + .into(), + ) }; - let pre_programmed_distribution = match js_pre_programmed_distribution.is_undefined() { - true => None, - false => Some(TokenPreProgrammedDistribution::from( + let pre_programmed_distribution = if js_pre_programmed_distribution.is_undefined() { + None + } else { + Some( js_pre_programmed_distribution .to_wasm::( "TokenPreProgrammedDistribution", )? - .clone(), - )), + .clone() + .into(), + ) }; - let new_tokens_destination_identity = - match js_new_tokens_destination_identity.is_undefined() { - true => None, - false => Some(Identifier::from(IdentifierWasm::try_from( - js_new_tokens_destination_identity, - )?)), - }; + let new_tokens_destination_identity = if js_new_tokens_destination_identity.is_undefined() + { + None + } else { + Some(Identifier::from(IdentifierWasm::try_from( + js_new_tokens_destination_identity, + )?)) + }; Ok(TokenDistributionRulesWasm(TokenDistributionRules::V0( TokenDistributionRulesV0 { @@ -104,10 +108,9 @@ impl TokenDistributionRulesWasm { #[wasm_bindgen(getter = "perpetualDistribution")] pub fn get_perpetual_distribution(&self) -> Option { - match self.0.perpetual_distribution() { - Some(perp) => Some(perp.clone().into()), - None => None, - } + self.0 + .perpetual_distribution() + .map(|perp| perp.clone().into()) } #[wasm_bindgen(getter = "perpetualDistributionRules")] @@ -117,18 +120,16 @@ impl TokenDistributionRulesWasm { #[wasm_bindgen(getter = "preProgrammedDistribution")] pub fn get_pre_programmed_distribution(&self) -> Option { - match self.0.pre_programmed_distribution() { - Some(pre) => Some(pre.clone().into()), - None => None, - } + self.0 + .pre_programmed_distribution() + .map(|pre| pre.clone().into()) } #[wasm_bindgen(getter = "newTokenDestinationIdentity")] pub fn get_new_tokens_destination_identity(&self) -> Option { - match self.0.new_tokens_destination_identity().clone() { - Some(id) => Some(id.clone().into()), - None => None, - } + self.0 + .new_tokens_destination_identity() + .map(|id| IdentifierWasm::from(*id)) } #[wasm_bindgen(getter = "newTokenDestinationIdentityRules")] @@ -164,11 +165,12 @@ impl TokenDistributionRulesWasm { ) -> WasmDppResult<()> { let perpetual_distribution = match js_perpetual_distribution.is_undefined() { true => None, - false => Some(TokenPerpetualDistribution::from( + false => Some( js_perpetual_distribution .to_wasm::("TokenPerpetualDistribution")? - .clone(), - )), + .clone() + .into(), + ), }; self.0.set_perpetual_distribution(perpetual_distribution); @@ -188,13 +190,14 @@ impl TokenDistributionRulesWasm { ) -> WasmDppResult<()> { let distribution = match js_distribution.is_undefined() { true => None, - false => Some(TokenPreProgrammedDistribution::from( + false => Some( js_distribution .to_wasm::( "TokenPreProgrammedDistribution", )? - .clone(), - )), + .clone() + .into(), + ), }; self.0.set_pre_programmed_distribution(distribution); @@ -208,9 +211,7 @@ impl TokenDistributionRulesWasm { ) -> WasmDppResult<()> { let identifier = match js_identifier.is_undefined() { true => None, - false => Some(Identifier::from( - IdentifierWasm::try_from(js_identifier)?.clone(), - )), + false => Some(Identifier::from(IdentifierWasm::try_from(js_identifier)?)), }; self.0.set_new_tokens_destination_identity(identifier); diff --git a/packages/wasm-dpp2/src/tokens/configuration/group.rs b/packages/wasm-dpp2/src/tokens/configuration/group.rs index b642d28dc08..05161b80361 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/group.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/group.rs @@ -93,7 +93,7 @@ impl GroupWasm { Reflect::set( &js_members, &JsValue::from(k.to_string(Encoding::Base58)), - &JsValue::from(v.clone()), + &JsValue::from(*v), ) .map_err(|err| { let message = err.error_message(); diff --git a/packages/wasm-dpp2/src/tokens/configuration/perpetual_distribution.rs b/packages/wasm-dpp2/src/tokens/configuration/perpetual_distribution.rs index f76f992b233..e983b024c68 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/perpetual_distribution.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/perpetual_distribution.rs @@ -53,7 +53,7 @@ impl TokenPerpetualDistributionWasm { #[wasm_bindgen(getter = distributionRecipient)] pub fn recipient(&self) -> TokenDistributionRecipientWasm { - self.0.distribution_recipient().clone().into() + self.0.distribution_recipient().into() } #[wasm_bindgen(setter = distributionType)] diff --git a/packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs b/packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs index 5e3d49dd333..795fa1ab324 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs @@ -114,10 +114,10 @@ impl TokenPreProgrammedDistributionWasm { for (identifiers_key, identifiers_value) in value { Reflect::set( &identifiers_obj, - &IdentifierWasm::from(identifiers_key.clone()) + &IdentifierWasm::from(*identifiers_key) .get_base58() .into(), - &BigInt::from(identifiers_value.clone()).into(), + &BigInt::from(*identifiers_value).into(), ) .map_err(|err| { let message = err.error_message(); diff --git a/packages/wasm-dpp2/src/tokens/configuration/token_configuration.rs b/packages/wasm-dpp2/src/tokens/configuration/token_configuration.rs index 8f6d14bb4bd..aca9edb5f15 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/token_configuration.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/token_configuration.rs @@ -44,6 +44,7 @@ impl TokenConfigurationWasm { } #[wasm_bindgen(constructor)] + #[allow(clippy::too_many_arguments)] pub fn new( conventions: &TokenConfigurationConventionWasm, conventions_change_rules: &ChangeControlRulesWasm, @@ -105,7 +106,7 @@ impl TokenConfigurationWasm { #[wasm_bindgen(getter = "keepsHistory")] pub fn get_keeps_history(&self) -> TokenKeepsHistoryRulesWasm { - self.0.keeps_history().clone().into() + (*self.0.keeps_history()).into() } #[wasm_bindgen(getter = "startAsPaused")] @@ -177,7 +178,7 @@ impl TokenConfigurationWasm { #[wasm_bindgen(getter = "mainControlGroupCanBeModified")] pub fn get_main_control_group_can_be_modified(&self) -> AuthorizedActionTakersWasm { - self.0.main_control_group_can_be_modified().clone().into() + (*self.0.main_control_group_can_be_modified()).into() } #[wasm_bindgen(getter = "description")] @@ -202,13 +203,7 @@ impl TokenConfigurationWasm { #[wasm_bindgen(setter = "keepsHistory")] pub fn set_keeps_history(&mut self, keeps_history: &TokenKeepsHistoryRulesWasm) { - self.0 = match self.0.clone() { - TokenConfiguration::V0(mut v0) => { - v0.keeps_history = keeps_history.clone().into(); - - TokenConfiguration::V0(v0) - } - }; + *self.0.keeps_history_mut() = keeps_history.clone().into(); } #[wasm_bindgen(setter = "startAsPaused")] diff --git a/packages/wasm-dpp2/src/utils.rs b/packages/wasm-dpp2/src/utils.rs index 146a6deb052..dd1d37402a5 100644 --- a/packages/wasm-dpp2/src/utils.rs +++ b/packages/wasm-dpp2/src/utils.rs @@ -199,7 +199,7 @@ pub fn generic_of_js_val>( } pub fn get_class_type(value: &JsValue) -> WasmDppResult { - let class_type = js_sys::Reflect::get(&value, &JsValue::from_str("__type")).map_err(|err| { + let class_type = js_sys::Reflect::get(value, &JsValue::from_str("__type")).map_err(|err| { let message = err.error_message(); WasmDppError::generic(format!( "failed to read '__type' property from JS value: {}", diff --git a/packages/wasm-dpp2/src/voting/resource_vote_choice.rs b/packages/wasm-dpp2/src/voting/resource_vote_choice.rs index 95680b39275..d9fbb74cb67 100644 --- a/packages/wasm-dpp2/src/voting/resource_vote_choice.rs +++ b/packages/wasm-dpp2/src/voting/resource_vote_choice.rs @@ -53,7 +53,7 @@ impl ResourceVoteChoiceWasm { #[wasm_bindgen(js_name = "getValue")] pub fn get_value(&self) -> JsValue { - match self.0.clone() { + match self.0 { ResourceVoteChoice::TowardsIdentity(id) => JsValue::from(IdentifierWasm::from(id)), ResourceVoteChoice::Abstain => JsValue::undefined(), ResourceVoteChoice::Lock => JsValue::undefined(), @@ -62,7 +62,7 @@ impl ResourceVoteChoiceWasm { #[wasm_bindgen(js_name = "getType")] pub fn get_type(&self) -> String { - match self.0.clone() { + match self.0 { ResourceVoteChoice::TowardsIdentity(_) => "TowardsIdentity".to_string(), ResourceVoteChoice::Abstain => "Abstain".to_string(), ResourceVoteChoice::Lock => "Lock".to_string(), diff --git a/packages/wasm-dpp2/src/voting/vote.rs b/packages/wasm-dpp2/src/voting/vote.rs index c5b288c97ef..0edf9ac25ed 100644 --- a/packages/wasm-dpp2/src/voting/vote.rs +++ b/packages/wasm-dpp2/src/voting/vote.rs @@ -44,15 +44,15 @@ impl VoteWasm { #[wasm_bindgen(getter = votePoll)] pub fn vote_poll(&self) -> VotePollWasm { - match self.0.clone() { + match &self.0 { Vote::ResourceVote(vote) => vote.vote_poll().clone().into(), } } #[wasm_bindgen(getter = resourceVoteChoice)] pub fn resource_vote_choice(&self) -> ResourceVoteChoiceWasm { - match self.0.clone() { - Vote::ResourceVote(vote) => vote.resource_vote_choice().clone().into(), + match &self.0 { + Vote::ResourceVote(vote) => vote.resource_vote_choice().into(), } } diff --git a/packages/wasm-dpp2/src/voting/vote_poll.rs b/packages/wasm-dpp2/src/voting/vote_poll.rs index 458a870a665..d9e537fb65d 100644 --- a/packages/wasm-dpp2/src/voting/vote_poll.rs +++ b/packages/wasm-dpp2/src/voting/vote_poll.rs @@ -61,28 +61,28 @@ impl VotePollWasm { } #[wasm_bindgen(js_name = "toString")] - pub fn to_string(&self) -> String { + pub fn to_string_js(&self) -> String { self.0.to_string() } #[wasm_bindgen(getter = "contractId")] pub fn contract_id(&self) -> IdentifierWasm { - match self.0.clone() { - VotePoll::ContestedDocumentResourceVotePoll(poll) => poll.contract_id.into(), + match &self.0 { + VotePoll::ContestedDocumentResourceVotePoll(poll) => IdentifierWasm::from(poll.contract_id), } } #[wasm_bindgen(getter = "documentTypeName")] pub fn document_type_name(&self) -> String { - match self.0.clone() { - VotePoll::ContestedDocumentResourceVotePoll(poll) => poll.document_type_name.into(), + match &self.0 { + VotePoll::ContestedDocumentResourceVotePoll(poll) => poll.document_type_name.clone(), } } #[wasm_bindgen(getter = "indexName")] pub fn index_name(&self) -> String { - match self.0.clone() { - VotePoll::ContestedDocumentResourceVotePoll(poll) => poll.index_name.into(), + match &self.0 { + VotePoll::ContestedDocumentResourceVotePoll(poll) => poll.index_name.clone(), } } @@ -92,7 +92,7 @@ impl VotePollWasm { .with_big_endian() .with_no_limit(); - match self.0.clone() { + match &self.0 { VotePoll::ContestedDocumentResourceVotePoll(poll) => { let encoded: WasmDppResult>> = poll .index_values diff --git a/packages/wasm-sdk/src/lib.rs b/packages/wasm-sdk/src/lib.rs index 92a3edb0b06..bc0e6b207cc 100644 --- a/packages/wasm-sdk/src/lib.rs +++ b/packages/wasm-sdk/src/lib.rs @@ -13,7 +13,7 @@ pub mod wallet; // Re-export commonly used items pub use dpns::*; pub use error::{WasmSdkError, WasmSdkErrorKind}; -pub use queries::*; +pub use queries::{ProofInfoWasm, ProofMetadataResponseWasm, ResponseMetadataWasm}; pub use state_transitions::identity as state_transition_identity; pub use wallet::*; pub use wasm_dpp2::*; diff --git a/packages/wasm-sdk/src/queries/epoch.rs b/packages/wasm-sdk/src/queries/epoch.rs index 30dbf0b8796..aaf41795d5a 100644 --- a/packages/wasm-sdk/src/queries/epoch.rs +++ b/packages/wasm-sdk/src/queries/epoch.rs @@ -184,7 +184,7 @@ impl WasmSdk { epoch: u16, limit: Option, start_after: Option, - order_ascending: Option, + _order_ascending: Option, ) -> Result { use dash_sdk::platform::QueryStartInfo; use drive_proof_verifier::types::ProposerBlockCounts; diff --git a/packages/wasm-sdk/src/queries/group.rs b/packages/wasm-sdk/src/queries/group.rs index ad3264ce50d..99741644cba 100644 --- a/packages/wasm-sdk/src/queries/group.rs +++ b/packages/wasm-sdk/src/queries/group.rs @@ -400,7 +400,7 @@ impl WasmSdk { )) })?; - let contract_key = JsValue::from(IdentifierWasm::from(contract_id.clone())); + let contract_key = JsValue::from(IdentifierWasm::from(contract_id)); // Fetch all groups for this contract let query = GroupInfosQuery { @@ -792,7 +792,7 @@ impl WasmSdk { contract_id_str, e )) })?; - let contract_key = JsValue::from(IdentifierWasm::from(contract_id.clone())); + let contract_key = JsValue::from(IdentifierWasm::from(contract_id)); // Fetch all groups for this contract with proof let query = GroupInfosQuery { diff --git a/packages/wasm-sdk/src/queries/identity.rs b/packages/wasm-sdk/src/queries/identity.rs index e7351e64682..d6c7c0c5042 100644 --- a/packages/wasm-sdk/src/queries/identity.rs +++ b/packages/wasm-sdk/src/queries/identity.rs @@ -1034,7 +1034,7 @@ impl WasmSdk { for token_id in token_identifiers { if let Some(Some(balance)) = balances.get(&token_id) { let key = JsValue::from(IdentifierWasm::from(token_id)); - let value = JsValue::from(BigInt::from(*balance as u64)); + let value = JsValue::from(BigInt::from(*balance)); balances_map.set(&key, &value); } } @@ -1566,7 +1566,7 @@ impl WasmSdk { for token_id in token_identifiers { if let Some(Some(balance)) = balances.get(&token_id) { let key = JsValue::from(IdentifierWasm::from(token_id)); - let value = JsValue::from(BigInt::from(*balance as u64)); + let value = JsValue::from(BigInt::from(*balance)); balances_map.set(&key, &value); } } diff --git a/packages/wasm-sdk/src/queries/mod.rs b/packages/wasm-sdk/src/queries/mod.rs index a90c7f28134..0c4c462807b 100644 --- a/packages/wasm-sdk/src/queries/mod.rs +++ b/packages/wasm-sdk/src/queries/mod.rs @@ -269,8 +269,4 @@ impl ProofMetadataResponseWasm { proof: proof.into(), } } - - pub(crate) fn into_parts(self) -> (JsValue, ResponseMetadataWasm, ProofInfoWasm) { - (self.data, self.metadata, self.proof) - } } diff --git a/packages/wasm-sdk/src/queries/system.rs b/packages/wasm-sdk/src/queries/system.rs index 2df8344c6f7..c2a1c683a22 100644 --- a/packages/wasm-sdk/src/queries/system.rs +++ b/packages/wasm-sdk/src/queries/system.rs @@ -194,30 +194,6 @@ pub struct StatusStateSyncWasm { pub backfill_blocks_total: String, } -impl StatusStateSyncWasm { - fn new( - total_synced_time: String, - remaining_time: String, - total_snapshots: u32, - chunk_process_avg_time: String, - snapshot_height: String, - snapshot_chunks_count: String, - backfilled_blocks: String, - backfill_blocks_total: String, - ) -> Self { - Self { - total_synced_time, - remaining_time, - total_snapshots, - chunk_process_avg_time, - snapshot_height, - snapshot_chunks_count, - backfilled_blocks, - backfill_blocks_total, - } - } -} - #[wasm_bindgen(js_name = "StatusTime")] #[derive(Clone)] pub struct StatusTimeWasm { @@ -391,7 +367,7 @@ impl PrefundedSpecializedBalanceWasm { impl PrefundedSpecializedBalanceWasm { #[wasm_bindgen(getter = "balance")] pub fn balance(&self) -> BigInt { - BigInt::from(self.balance as u64) + BigInt::from(self.balance) } } @@ -610,48 +586,48 @@ impl WasmSdk { .unwrap_or(false), ); - let state_sync = StatusStateSyncWasm::new( - v0_response + let state_sync = StatusStateSyncWasm { + total_synced_time: v0_response .state_sync .as_ref() .map(|s| s.total_synced_time.to_string()) .unwrap_or_else(|| "0".to_string()), - v0_response + remaining_time: v0_response .state_sync .as_ref() .map(|s| s.remaining_time.to_string()) .unwrap_or_else(|| "0".to_string()), - v0_response + total_snapshots: v0_response .state_sync .as_ref() .map(|s| s.total_snapshots) .unwrap_or(0), - v0_response + chunk_process_avg_time: v0_response .state_sync .as_ref() .map(|s| s.chunk_process_avg_time.to_string()) .unwrap_or_else(|| "0".to_string()), - v0_response + snapshot_height: v0_response .state_sync .as_ref() .map(|s| s.snapshot_height.to_string()) .unwrap_or_else(|| "0".to_string()), - v0_response + snapshot_chunks_count: v0_response .state_sync .as_ref() .map(|s| s.snapshot_chunks_count.to_string()) .unwrap_or_else(|| "0".to_string()), - v0_response + backfilled_blocks: v0_response .state_sync .as_ref() .map(|s| s.backfilled_blocks.to_string()) .unwrap_or_else(|| "0".to_string()), - v0_response + backfill_blocks_total: v0_response .state_sync .as_ref() .map(|s| s.backfill_blocks_total.to_string()) .unwrap_or_else(|| "0".to_string()), - ); + }; let time = StatusTimeWasm::new( v0_response @@ -773,7 +749,7 @@ impl WasmSdk { 0 }; - Ok(BigInt::from(credits_value as u64)) + Ok(BigInt::from(credits_value)) } #[wasm_bindgen(js_name = "getPrefundedSpecializedBalance")] @@ -943,7 +919,7 @@ impl WasmSdk { .await?; let data = total_credits_result - .map(|credits| JsValue::from(BigInt::from(credits.0 as u64))) + .map(|credits| JsValue::from(BigInt::from(credits.0))) .unwrap_or(JsValue::UNDEFINED); Ok(ProofMetadataResponseWasm::from_sdk_parts( diff --git a/packages/wasm-sdk/src/queries/token.rs b/packages/wasm-sdk/src/queries/token.rs index af28a7492a2..0bfc7536c06 100644 --- a/packages/wasm-sdk/src/queries/token.rs +++ b/packages/wasm-sdk/src/queries/token.rs @@ -178,7 +178,7 @@ impl WasmSdk { dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, ) .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid token ID: {}", e)))?; - let token_identifier_wasm = IdentifierWasm::from(token_identifier.clone()); + let token_identifier_wasm = IdentifierWasm::from(token_identifier); // Fetch token prices let prices_result: drive_proof_verifier::types::TokenDirectPurchasePrices = @@ -264,8 +264,8 @@ impl WasmSdk { let balances_map = Map::new(); for identifier in &identities { if let Some(Some(balance)) = balances_result.get(identifier) { - let key = JsValue::from(IdentifierWasm::from((*identifier).clone())); - let value = JsValue::from(BigInt::from(*balance as u64)); + let key = JsValue::from(IdentifierWasm::from(*identifier)); + let value = JsValue::from(BigInt::from(*balance)); balances_map.set(&key, &value); } } @@ -438,7 +438,7 @@ impl WasmSdk { let prices_map = Map::new(); for token in tokens { if let Some(Some(schedule)) = prices_result.get(&token) { - let token_id_wasm = IdentifierWasm::from(token.clone()); + let token_id_wasm = IdentifierWasm::from(token); let (base_price, current_price) = match schedule { dash_sdk::dpp::tokens::token_pricing_schedule::TokenPricingSchedule::SinglePrice(price) => { (price.to_string(), price.to_string()) @@ -695,8 +695,8 @@ impl WasmSdk { let balances_map = Map::new(); for identifier in &identities { if let Some(Some(balance)) = balances_result.get(identifier) { - let key = JsValue::from(IdentifierWasm::from((*identifier).clone())); - let value = JsValue::from(BigInt::from(*balance as u64)); + let key = JsValue::from(IdentifierWasm::from(*identifier)); + let value = JsValue::from(BigInt::from(*balance)); balances_map.set(&key, &value); } } @@ -924,7 +924,7 @@ impl WasmSdk { let prices_map = Map::new(); for token in tokens { if let Some(Some(schedule)) = prices_result.get(&token) { - let token_id_wasm = IdentifierWasm::from(token.clone()); + let token_id_wasm = IdentifierWasm::from(token); let (base_price, current_price) = match schedule { dash_sdk::dpp::tokens::token_pricing_schedule::TokenPricingSchedule::SinglePrice(price) => { (price.to_string(), price.to_string()) diff --git a/packages/wasm-sdk/src/queries/voting/state.rs b/packages/wasm-sdk/src/queries/voting/state.rs index ec62879bfbf..df8d497a4c8 100644 --- a/packages/wasm-sdk/src/queries/voting/state.rs +++ b/packages/wasm-sdk/src/queries/voting/state.rs @@ -147,7 +147,7 @@ impl ContestedResourceContenderWasm { impl ContestedResourceContenderWasm { #[wasm_bindgen(getter = identityId)] pub fn identity_id(&self) -> IdentifierWasm { - IdentifierWasm::from(self.identity_id.clone()) + IdentifierWasm::from(self.identity_id) } #[wasm_bindgen(getter = serializedDocument)] diff --git a/packages/wasm-sdk/src/queries/voting/votes.rs b/packages/wasm-sdk/src/queries/voting/votes.rs index c34a91a615a..989473991de 100644 --- a/packages/wasm-sdk/src/queries/voting/votes.rs +++ b/packages/wasm-sdk/src/queries/voting/votes.rs @@ -6,6 +6,7 @@ use crate::sdk::WasmSdk; use crate::WasmSdkError; use dash_sdk::dpp::voting::vote_choices::resource_vote_choice::ResourceVoteChoice; use dash_sdk::dpp::voting::vote_polls::VotePoll; +use dash_sdk::dpp::voting::votes::resource_vote::v0::ResourceVoteV0; use dash_sdk::dpp::voting::votes::resource_vote::ResourceVote; use dash_sdk::platform::FetchMany; use drive::query::contested_resource_votes_given_by_identity_query::ContestedResourceVotesGivenByIdentityQuery; @@ -133,18 +134,16 @@ fn resource_votes_to_json( let mut results = Vec::new(); for (vote_id, vote_opt) in votes.into_iter() { - let vote = match vote_opt { - Some(vote) => vote, - None => continue, + let Some(vote) = vote_opt else { + continue; }; - let inner = match vote { - ResourceVote::V0(inner) => inner, - }; + let ResourceVote::V0(ResourceVoteV0 { + vote_poll, + resource_vote_choice, + }) = vote; - let vote_poll = match inner.vote_poll { - VotePoll::ContestedDocumentResourceVotePoll(poll) => poll, - }; + let VotePoll::ContestedDocumentResourceVotePoll(vote_poll) = vote_poll; let poll_unique_id = vote_poll.unique_id().map_err(|e| { WasmSdkError::serialization(format!("Failed to derive vote poll unique id: {}", e)) @@ -172,7 +171,7 @@ fn resource_votes_to_json( "indexValues": index_values_json, }); - let choice_json = match inner.resource_vote_choice { + let choice_json = match resource_vote_choice { ResourceVoteChoice::TowardsIdentity(identifier) => serde_json::json!({ "type": "towardsIdentity", "identityId": identifier.to_string(Encoding::Base58), From e9f77e2ccc774071c075f45db2c2f0056f3a5173 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 30 Oct 2025 18:02:54 +0700 Subject: [PATCH 34/44] test: fix contracts test --- packages/js-evo-sdk/tests/unit/facades/contracts.spec.mjs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/js-evo-sdk/tests/unit/facades/contracts.spec.mjs b/packages/js-evo-sdk/tests/unit/facades/contracts.spec.mjs index 6a304e860e9..ea9e6c2ebeb 100644 --- a/packages/js-evo-sdk/tests/unit/facades/contracts.spec.mjs +++ b/packages/js-evo-sdk/tests/unit/facades/contracts.spec.mjs @@ -46,14 +46,13 @@ describe('ContractsFacade', () => { const { args } = wasmSdk.getDataContractHistory.firstCall; expect(args[0]).to.equal('c'); expect(args[1]).to.equal(3); - expect(args[2]).to.equal(null); - expect(typeof args[3]).to.equal('bigint'); - expect(args[3]).to.equal(BigInt(5)); + expect(args[2]).to.be.a('bigint'); + expect(args[2]).to.equal(BigInt(5)); }); it('getHistoryWithProof() forwards similarly', async () => { await client.contracts.getHistoryWithProof({ contractId: 'c' }); - expect(wasmSdk.getDataContractHistoryWithProofInfo).to.be.calledOnceWithExactly('c', null, null, null); + expect(wasmSdk.getDataContractHistoryWithProofInfo).to.be.calledOnceWithExactly('c', null, null); }); it('getMany() and getManyWithProof() forward arrays', async () => { From c1559b622dc14b6f44b2a9db44b59b1a187a2e59 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 30 Oct 2025 18:16:23 +0700 Subject: [PATCH 35/44] style: formatting --- .../src/asset_lock_proof/instant/instant_lock.rs | 6 +----- packages/wasm-dpp2/src/error.rs | 1 - packages/wasm-dpp2/src/identity/model.rs | 9 ++++----- .../identity/transitions/masternode_vote_transition.rs | 4 +++- .../src/identity/transitions/public_key_in_creation.rs | 4 +++- packages/wasm-dpp2/src/lib.rs | 6 +++--- .../src/state_transitions/base/state_transition.rs | 10 ++++++---- .../state_transitions/batch/token_base_transition.rs | 4 +++- .../batch/token_transitions/token_transfer.rs | 10 ++++++++-- .../wasm-dpp2/src/tokens/configuration/action_taker.rs | 4 +--- .../src/tokens/configuration/change_control_rules.rs | 4 +--- .../src/tokens/configuration/distribution_recipient.rs | 7 +++---- .../src/tokens/configuration/distribution_rules.rs | 3 +-- .../configuration/pre_programmed_distribution.rs | 4 +--- packages/wasm-dpp2/src/voting/vote_poll.rs | 4 +++- 15 files changed, 41 insertions(+), 39 deletions(-) diff --git a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs index caa1444c80b..1d25633b32d 100644 --- a/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs +++ b/packages/wasm-dpp2/src/asset_lock_proof/instant/instant_lock.rs @@ -66,11 +66,7 @@ impl InstantLockWasm { #[wasm_bindgen(getter = "inputs")] pub fn get_inputs(&self) -> Vec { - self.0 - .inputs - .iter() - .map(|input| (*input).into()) - .collect() + self.0.inputs.iter().map(|input| (*input).into()).collect() } #[wasm_bindgen(getter = "txid")] diff --git a/packages/wasm-dpp2/src/error.rs b/packages/wasm-dpp2/src/error.rs index 8371f77e691..b4fa897c0fb 100644 --- a/packages/wasm-dpp2/src/error.rs +++ b/packages/wasm-dpp2/src/error.rs @@ -2,7 +2,6 @@ use anyhow::Error as AnyhowError; use dpp::ProtocolError; use wasm_bindgen::prelude::wasm_bindgen; - /// Structured error returned by wasm-dpp2 APIs. #[wasm_bindgen] #[derive(Copy, Clone, Debug, Eq, PartialEq)] diff --git a/packages/wasm-dpp2/src/identity/model.rs b/packages/wasm-dpp2/src/identity/model.rs index edb3e705f72..e6daed96793 100644 --- a/packages/wasm-dpp2/src/identity/model.rs +++ b/packages/wasm-dpp2/src/identity/model.rs @@ -94,11 +94,10 @@ impl IdentityWasm { #[wasm_bindgen(js_name = "getPublicKeys")] pub fn get_public_keys(&self) -> Vec { - - - self - .0 - .public_keys().values().map(|key| IdentityPublicKeyWasm::from(key.clone())) + self.0 + .public_keys() + .values() + .map(|key| IdentityPublicKeyWasm::from(key.clone())) .collect() } diff --git a/packages/wasm-dpp2/src/identity/transitions/masternode_vote_transition.rs b/packages/wasm-dpp2/src/identity/transitions/masternode_vote_transition.rs index fa8d6c75fa6..05ea86eb3cd 100644 --- a/packages/wasm-dpp2/src/identity/transitions/masternode_vote_transition.rs +++ b/packages/wasm-dpp2/src/identity/transitions/masternode_vote_transition.rs @@ -183,7 +183,9 @@ impl MasternodeVoteTransitionWasm { #[wasm_bindgen(getter = "assetLock")] pub fn get_asset_lock_proof(&self) -> Option { - self.0.optional_asset_lock_proof().map(|asset_lock_proof| AssetLockProofWasm::from(asset_lock_proof.clone())) + self.0 + .optional_asset_lock_proof() + .map(|asset_lock_proof| AssetLockProofWasm::from(asset_lock_proof.clone())) } #[wasm_bindgen(setter = "userFeeIncrease")] diff --git a/packages/wasm-dpp2/src/identity/transitions/public_key_in_creation.rs b/packages/wasm-dpp2/src/identity/transitions/public_key_in_creation.rs index d3463bfefb8..7f68f31a36e 100644 --- a/packages/wasm-dpp2/src/identity/transitions/public_key_in_creation.rs +++ b/packages/wasm-dpp2/src/identity/transitions/public_key_in_creation.rs @@ -135,7 +135,9 @@ impl IdentityPublicKeyInCreationWasm { #[wasm_bindgen(getter = "contractBounds")] pub fn get_contract_bounds(&self) -> Option { - self.0.contract_bounds().map(|bounds| ContractBoundsWasm::from(bounds.clone())) + self.0 + .contract_bounds() + .map(|bounds| ContractBoundsWasm::from(bounds.clone())) } #[wasm_bindgen(getter = keyId)] diff --git a/packages/wasm-dpp2/src/lib.rs b/packages/wasm-dpp2/src/lib.rs index 34b16d66150..9610a67545a 100644 --- a/packages/wasm-dpp2/src/lib.rs +++ b/packages/wasm-dpp2/src/lib.rs @@ -36,9 +36,9 @@ pub use epoch::*; pub use group::*; pub use identity::{ IdentityCreateTransitionWasm, IdentityCreditTransferWasm, - IdentityCreditWithdrawalTransitionWasm, IdentityPublicKeyInCreationWasm, - IdentityPublicKeyWasm, IdentityTopUpTransitionWasm, IdentityUpdateTransitionWasm, - IdentityWasm, MasternodeVoteTransitionWasm, PartialIdentityWasm, + IdentityCreditWithdrawalTransitionWasm, IdentityPublicKeyInCreationWasm, IdentityPublicKeyWasm, + IdentityTopUpTransitionWasm, IdentityUpdateTransitionWasm, IdentityWasm, + MasternodeVoteTransitionWasm, PartialIdentityWasm, }; pub use state_transitions::base::{GroupStateTransitionInfoWasm, StateTransitionWasm}; pub use tokens::*; diff --git a/packages/wasm-dpp2/src/state_transitions/base/state_transition.rs b/packages/wasm-dpp2/src/state_transitions/base/state_transition.rs index 42cb39a101d..709463ee4d2 100644 --- a/packages/wasm-dpp2/src/state_transitions/base/state_transition.rs +++ b/packages/wasm-dpp2/src/state_transitions/base/state_transition.rs @@ -311,10 +311,12 @@ impl StateTransitionWasm { pub fn get_purpose_requirement(&self) -> Option> { let requirements = self.0.purpose_requirement(); - requirements.map(|req| req.iter() - .map(|purpose| PurposeWasm::from(*purpose)) - .map(String::from) - .collect()) + requirements.map(|req| { + req.iter() + .map(|purpose| PurposeWasm::from(*purpose)) + .map(String::from) + .collect() + }) } #[wasm_bindgen(js_name = "getKeyLevelRequirement")] diff --git a/packages/wasm-dpp2/src/state_transitions/batch/token_base_transition.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_base_transition.rs index be34e7efc39..ae52167667c 100644 --- a/packages/wasm-dpp2/src/state_transitions/batch/token_base_transition.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_base_transition.rs @@ -90,7 +90,9 @@ impl TokenBaseTransitionWasm { #[wasm_bindgen(getter = usingGroupInfo)] pub fn get_using_group_info(&self) -> Option { - self.0.using_group_info().map(|using_group_info| using_group_info.into()) + self.0 + .using_group_info() + .map(|using_group_info| using_group_info.into()) } #[wasm_bindgen(setter = identityContractNonce)] diff --git a/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_transfer.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_transfer.rs index 65bb6d2f307..2a9732d1b19 100644 --- a/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_transfer.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_transfer.rs @@ -103,12 +103,18 @@ impl TokenTransferTransitionWasm { #[wasm_bindgen(getter = "sharedEncryptedNote")] pub fn get_shared_encrypted_note(&self) -> Option { - self.clone().0.shared_encrypted_note_owned().map(|shared_encrypted_note| shared_encrypted_note.into()) + self.clone() + .0 + .shared_encrypted_note_owned() + .map(|shared_encrypted_note| shared_encrypted_note.into()) } #[wasm_bindgen(getter = "privateEncryptedNote")] pub fn get_private_encrypted_note(&self) -> Option { - self.clone().0.private_encrypted_note_owned().map(|private_encrypted_note| private_encrypted_note.into()) + self.clone() + .0 + .private_encrypted_note_owned() + .map(|private_encrypted_note| private_encrypted_note.into()) } #[wasm_bindgen(getter = recipientId)] diff --git a/packages/wasm-dpp2/src/tokens/configuration/action_taker.rs b/packages/wasm-dpp2/src/tokens/configuration/action_taker.rs index 3b214e2437a..f67b798de78 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/action_taker.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/action_taker.rs @@ -79,9 +79,7 @@ impl ActionTakerWasm { #[wasm_bindgen(getter = "value")] pub fn get_value(&self) -> JsValue { match &self.0 { - ActionTaker::SingleIdentity(value) => { - JsValue::from(IdentifierWasm::from(*value)) - } + ActionTaker::SingleIdentity(value) => JsValue::from(IdentifierWasm::from(*value)), ActionTaker::SpecifiedIdentities(value) => { let array = Array::new(); for identifier in value.iter() { diff --git a/packages/wasm-dpp2/src/tokens/configuration/change_control_rules.rs b/packages/wasm-dpp2/src/tokens/configuration/change_control_rules.rs index 2bcec6420f0..88932f7e4da 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/change_control_rules.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/change_control_rules.rs @@ -61,9 +61,7 @@ impl ChangeControlRulesWasm { #[wasm_bindgen(getter = "authorizedToMakeChange")] pub fn get_authorized_to_make_change(&self) -> AuthorizedActionTakersWasm { - (*self.0 - .authorized_to_make_change_action_takers()) - .into() + (*self.0.authorized_to_make_change_action_takers()).into() } #[wasm_bindgen(getter = "adminActionTakers")] diff --git a/packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs b/packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs index 1b10e5b8a21..5743fe06952 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/distribution_recipient.rs @@ -58,10 +58,9 @@ impl TokenDistributionRecipientWasm { String::from("EvonodesByParticipation") } TokenDistributionRecipient::ContractOwner => String::from("ContractOwner"), - TokenDistributionRecipient::Identity(identity) => format!( - "Identity({})", - IdentifierWasm::from(identity).get_base58() - ), + TokenDistributionRecipient::Identity(identity) => { + format!("Identity({})", IdentifierWasm::from(identity).get_base58()) + } } } diff --git a/packages/wasm-dpp2/src/tokens/configuration/distribution_rules.rs b/packages/wasm-dpp2/src/tokens/configuration/distribution_rules.rs index f8ccdc03e2e..2a282e49aa0 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/distribution_rules.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/distribution_rules.rs @@ -77,8 +77,7 @@ impl TokenDistributionRulesWasm { ) }; - let new_tokens_destination_identity = if js_new_tokens_destination_identity.is_undefined() - { + let new_tokens_destination_identity = if js_new_tokens_destination_identity.is_undefined() { None } else { Some(Identifier::from(IdentifierWasm::try_from( diff --git a/packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs b/packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs index 795fa1ab324..a957c0cc2da 100644 --- a/packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs +++ b/packages/wasm-dpp2/src/tokens/configuration/pre_programmed_distribution.rs @@ -114,9 +114,7 @@ impl TokenPreProgrammedDistributionWasm { for (identifiers_key, identifiers_value) in value { Reflect::set( &identifiers_obj, - &IdentifierWasm::from(*identifiers_key) - .get_base58() - .into(), + &IdentifierWasm::from(*identifiers_key).get_base58().into(), &BigInt::from(*identifiers_value).into(), ) .map_err(|err| { diff --git a/packages/wasm-dpp2/src/voting/vote_poll.rs b/packages/wasm-dpp2/src/voting/vote_poll.rs index d9e537fb65d..767ed77978c 100644 --- a/packages/wasm-dpp2/src/voting/vote_poll.rs +++ b/packages/wasm-dpp2/src/voting/vote_poll.rs @@ -68,7 +68,9 @@ impl VotePollWasm { #[wasm_bindgen(getter = "contractId")] pub fn contract_id(&self) -> IdentifierWasm { match &self.0 { - VotePoll::ContestedDocumentResourceVotePoll(poll) => IdentifierWasm::from(poll.contract_id), + VotePoll::ContestedDocumentResourceVotePoll(poll) => { + IdentifierWasm::from(poll.contract_id) + } } } From de92ae7bb09b405a43547b9acc429f081a03df82 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 30 Oct 2025 18:25:06 +0700 Subject: [PATCH 36/44] chore: remove commented code --- packages/wasm-sdk/src/lib.rs | 46 ------------------------------------ 1 file changed, 46 deletions(-) diff --git a/packages/wasm-sdk/src/lib.rs b/packages/wasm-sdk/src/lib.rs index bc0e6b207cc..1bec583b6e5 100644 --- a/packages/wasm-sdk/src/lib.rs +++ b/packages/wasm-sdk/src/lib.rs @@ -18,52 +18,6 @@ pub use state_transitions::identity as state_transition_identity; pub use wallet::*; pub use wasm_dpp2::*; -// pub use wasm_dpp2::asset_lock_proof::{ -// chain::ChainAssetLockProofWasm, instant::InstantAssetLockProofWasm, outpoint::OutPointWasm, -// AssetLockProofWasm, -// }; -// pub use wasm_dpp2::consensus_error::ConsensusErrorWasm; -// pub use wasm_dpp2::core_script::CoreScriptWasm; -// pub use wasm_dpp2::data_contract::{ -// ContractBoundsWasm, DataContractCreateTransitionWasm, DataContractUpdateTransitionWasm, -// DataContractWasm, DocumentWasm, -// }; -// pub use wasm_dpp2::enums::{ -// batch::batch_enum::BatchTypeWasm, -// batch::gas_fees_paid_by::GasFeesPaidByWasm, -// contested::vote_state_result_type::VoteStateResultTypeWasm, -// keys::{key_type::KeyTypeWasm, purpose::PurposeWasm, security_level::SecurityLevelWasm}, -// lock_types::AssetLockProofTypeWasm, -// network::NetworkWasm, -// platform::PlatformVersionWasm, -// token::{ -// action_goal::ActionGoalWasm, distribution_type::TokenDistributionTypeWasm, -// emergency_action::TokenEmergencyActionWasm, -// }, -// withdrawal::PoolingWasm, -// }; -// pub use wasm_dpp2::error::{WasmDppError, WasmDppErrorKind}; -// pub use wasm_dpp2::identifier::IdentifierWasm; -// pub use wasm_dpp2::identity::{ -// IdentityCreateTransitionWasm, IdentityCreditTransferWasm, -// IdentityCreditWithdrawalTransitionWasm, IdentityPublicKeyInCreationWasm, IdentityPublicKeyWasm, -// IdentityTopUpTransitionWasm, IdentityUpdateTransitionWasm, IdentityWasm, -// MasternodeVoteTransitionWasm, PartialIdentityWasm, ResourceVoteChoiceWasm, VotePollWasm, -// VoteWasm, -// }; -// pub use wasm_dpp2::private_key::PrivateKeyWasm; -// pub use wasm_dpp2::public_key::PublicKeyWasm; -// pub use wasm_dpp2::state_transitions::{ -// base::{GroupStateTransitionInfoWasm, StateTransitionWasm}, -// batch::{batched_transition::BatchedTransitionWasm, BatchTransitionWasm}, -// }; -// pub use wasm_dpp2::tokens::configuration::action_taker::ActionTakerWasm; -// pub use wasm_dpp2::tokens::configuration::change_control_rules::ChangeControlRulesWasm; -// pub use wasm_dpp2::tokens::{ -// AuthorizedActionTakersWasm, GroupWasm, PrivateEncryptedNoteWasm, SharedEncryptedNoteWasm, -// TokenConfigurationChangeItemWasm, TokenConfigurationLocalizationWasm, TokenConfigurationWasm, -// }; - #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; From e346dfa82c7611bfd56074a6d16909a4bf044c83 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 30 Oct 2025 21:30:09 +0700 Subject: [PATCH 37/44] fix: invalid contested resource value --- packages/wasm-sdk/src/queries/utils.rs | 13 +--- .../wasm-sdk/src/queries/voting/resources.rs | 61 ++++++++++++++----- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/packages/wasm-sdk/src/queries/utils.rs b/packages/wasm-sdk/src/queries/utils.rs index af92807020d..6068adafe1a 100644 --- a/packages/wasm-sdk/src/queries/utils.rs +++ b/packages/wasm-sdk/src/queries/utils.rs @@ -5,7 +5,7 @@ use serde::de::DeserializeOwned; use serde_json::Value as JsonValue; use wasm_bindgen::JsValue; -use crate::utils::{js_value_to_platform_value, js_values_to_platform_values}; +use crate::utils::js_values_to_platform_values; use crate::WasmSdkError; pub(crate) fn deserialize_required_query( @@ -84,17 +84,6 @@ pub(crate) fn convert_json_values_to_platform_values( js_values_to_platform_values(js_values) } -pub(crate) fn convert_json_value_to_platform_value( - value: JsonValue, - field_name: &str, -) -> Result { - let js_value = serde_wasm_bindgen::to_value(&value).map_err(|err| { - WasmSdkError::invalid_argument(format!("Invalid {} entry: {}", field_name, err)) - })?; - - js_value_to_platform_value(js_value) -} - pub(crate) fn identifier_from_base58(value: &str, field: &str) -> Result { Identifier::from_string(value, Encoding::Base58) .map_err(|err| WasmSdkError::invalid_argument(format!("Invalid {}: {}", field, err))) diff --git a/packages/wasm-sdk/src/queries/voting/resources.rs b/packages/wasm-sdk/src/queries/voting/resources.rs index 26d4c7ccf8b..14f1edcf6fa 100644 --- a/packages/wasm-sdk/src/queries/voting/resources.rs +++ b/packages/wasm-sdk/src/queries/voting/resources.rs @@ -1,17 +1,18 @@ use crate::queries::utils::{ - convert_json_value_to_platform_value, convert_json_values_to_platform_values, - convert_optional_limit, deserialize_required_query, identifier_from_base58, + convert_json_values_to_platform_values, convert_optional_limit, deserialize_required_query, + identifier_from_base58, }; use crate::queries::ProofMetadataResponseWasm; use crate::sdk::WasmSdk; +use crate::utils::js_value_to_platform_value; use crate::WasmSdkError; use dash_sdk::platform::FetchMany; use drive::query::vote_polls_by_document_type_query::VotePollsByDocumentTypeQuery; use drive_proof_verifier::types::{ContestedResource, ContestedResources}; -use js_sys::Array; +use js_sys::{Array, Reflect}; use serde::Deserialize; use serde_json::Value as JsonValue; -use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::{prelude::wasm_bindgen, JsValue}; #[wasm_bindgen(typescript_custom_section)] const VOTE_POLLS_BY_DOCUMENT_TYPE_QUERY_TS: &'static str = r#" @@ -90,8 +91,6 @@ struct VotePollsByDocumentTypeQueryInput { #[serde(default)] end_index_values: Option>, #[serde(default)] - start_at_value: Option, - #[serde(default)] start_at_value_included: Option, #[serde(default)] limit: Option, @@ -101,6 +100,7 @@ struct VotePollsByDocumentTypeQueryInput { fn create_vote_polls_by_document_type_query( query: VotePollsByDocumentTypeQueryInput, + start_at_value: Option, ) -> Result { let VotePollsByDocumentTypeQueryInput { data_contract_id, @@ -108,7 +108,6 @@ fn create_vote_polls_by_document_type_query( index_name, start_index_values, end_index_values, - start_at_value, start_at_value_included, limit, order_ascending, @@ -122,7 +121,9 @@ fn create_vote_polls_by_document_type_query( let start_at_value = match start_at_value { Some(value) => { - let platform_value = convert_json_value_to_platform_value(value, "startAtValue")?; + let platform_value = js_value_to_platform_value(value).map_err(|err| { + WasmSdkError::invalid_argument(format!("Invalid startAtValue: {}", err)) + })?; Some((platform_value, start_at_value_included.unwrap_or(true))) } None => None, @@ -164,12 +165,40 @@ fn contested_resources_into_wasm( fn parse_vote_polls_by_document_type_query( query: VotePollsByDocumentTypeQueryJs, -) -> Result { - deserialize_required_query( - query, +) -> Result<(VotePollsByDocumentTypeQueryInput, Option), WasmSdkError> { + let value: JsValue = query.into(); + + if value.is_null() || value.is_undefined() { + return Err(WasmSdkError::invalid_argument( + "Query object is required".to_string(), + )); + } + + let start_at_value = + Reflect::get(&value, &JsValue::from_str("startAtValue")).map_err(|err| { + let message = err + .as_string() + .unwrap_or_else(|| "unable to access property".to_string()); + + WasmSdkError::invalid_argument(format!( + "Invalid vote polls by document type options: {}", + message + )) + })?; + + let start_at_value = if start_at_value.is_null() || start_at_value.is_undefined() { + None + } else { + Some(start_at_value) + }; + + let query_input = deserialize_required_query( + value, "Query object is required", "vote polls by document type options", - ) + )?; + + Ok((query_input, start_at_value)) } #[wasm_bindgen] @@ -179,8 +208,8 @@ impl WasmSdk { &self, query: VotePollsByDocumentTypeQueryJs, ) -> Result { - let drive_query = parse_vote_polls_by_document_type_query(query) - .and_then(create_vote_polls_by_document_type_query)?; + let (query, start_at_value) = parse_vote_polls_by_document_type_query(query)?; + let drive_query = create_vote_polls_by_document_type_query(query, start_at_value)?; let contested_resources = ContestedResource::fetch_many(self.as_ref(), drive_query).await?; @@ -195,8 +224,8 @@ impl WasmSdk { &self, query: VotePollsByDocumentTypeQueryJs, ) -> Result { - let drive_query = parse_vote_polls_by_document_type_query(query) - .and_then(create_vote_polls_by_document_type_query)?; + let (query, start_at_value) = parse_vote_polls_by_document_type_query(query)?; + let drive_query = create_vote_polls_by_document_type_query(query, start_at_value)?; let (contested_resources, metadata, proof) = ContestedResource::fetch_many_with_metadata_and_proof(self.as_ref(), drive_query, None) From 41685807c8c08e52f175f188ae949b9f1978b8ee Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 31 Oct 2025 11:39:54 +0700 Subject: [PATCH 38/44] fix: missing version 10 --- packages/wasm-dpp2/src/enums/platform.rs | 6 ++++++ packages/wasm-sdk/tests/unit/data-contract.spec.mjs | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/wasm-dpp2/src/enums/platform.rs b/packages/wasm-dpp2/src/enums/platform.rs index 63b1f69c8d7..259ee590c32 100644 --- a/packages/wasm-dpp2/src/enums/platform.rs +++ b/packages/wasm-dpp2/src/enums/platform.rs @@ -9,6 +9,7 @@ use dpp::version::v6::PLATFORM_V6; use dpp::version::v7::PLATFORM_V7; use dpp::version::v8::PLATFORM_V8; use dpp::version::v9::PLATFORM_V9; +use dpp::version::v10::PLATFORM_V10; use wasm_bindgen::JsValue; use wasm_bindgen::prelude::wasm_bindgen; @@ -26,6 +27,7 @@ pub enum PlatformVersionWasm { PLATFORM_V7 = 7, PLATFORM_V8 = 8, PLATFORM_V9 = 9, + PLATFORM_V10 = 10, } impl TryFrom for PlatformVersionWasm { @@ -46,6 +48,7 @@ impl TryFrom for PlatformVersionWasm { "platform_v7" => Ok(PlatformVersionWasm::PLATFORM_V7), "platform_v8" => Ok(PlatformVersionWasm::PLATFORM_V8), "platform_v9" => Ok(PlatformVersionWasm::PLATFORM_V9), + "platform_v10" => Ok(PlatformVersionWasm::PLATFORM_V10), _ => Err(WasmDppError::invalid_argument(format!( "unknown platform version value: {}", enum_val @@ -66,6 +69,7 @@ impl TryFrom for PlatformVersionWasm { 7 => Ok(PlatformVersionWasm::PLATFORM_V7), 8 => Ok(PlatformVersionWasm::PLATFORM_V8), 9 => Ok(PlatformVersionWasm::PLATFORM_V9), + 10 => Ok(PlatformVersionWasm::PLATFORM_V10), _ => Err(WasmDppError::invalid_argument(format!( "unknown platform version value: {}", enum_val @@ -88,6 +92,7 @@ impl From for String { PlatformVersionWasm::PLATFORM_V7 => String::from("PLATFORM_V7"), PlatformVersionWasm::PLATFORM_V8 => String::from("PLATFORM_V8"), PlatformVersionWasm::PLATFORM_V9 => String::from("PLATFORM_V9"), + PlatformVersionWasm::PLATFORM_V10 => String::from("PLATFORM_V10"), } } } @@ -104,6 +109,7 @@ impl From for PlatformVersion { PlatformVersionWasm::PLATFORM_V7 => PLATFORM_V7, PlatformVersionWasm::PLATFORM_V8 => PLATFORM_V8, PlatformVersionWasm::PLATFORM_V9 => PLATFORM_V9, + PlatformVersionWasm::PLATFORM_V10 => PLATFORM_V10, } } } diff --git a/packages/wasm-sdk/tests/unit/data-contract.spec.mjs b/packages/wasm-sdk/tests/unit/data-contract.spec.mjs index 33a1b48ce0b..98421b9ff19 100644 --- a/packages/wasm-sdk/tests/unit/data-contract.spec.mjs +++ b/packages/wasm-sdk/tests/unit/data-contract.spec.mjs @@ -7,8 +7,8 @@ const PLATFORM_VERSION_CONTRACT_V0 = 1; const PLATFORM_VERSION_CONTRACT_V1 = 9; // V1 contracts introduced in Platform v9 // Platform version compatibility ranges -const V0_COMPATIBLE_VERSIONS = [1, 2, 3, 4, 5, 6, 7, 8, 9]; // V0 supported versions -const V1_COMPATIBLE_VERSIONS = [9]; // V1 starts at platform version 9 +const V0_COMPATIBLE_VERSIONS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // V0 supported versions +const V1_COMPATIBLE_VERSIONS = [9, 10]; // V1 starts at platform version 9 const V0_ONLY_VERSIONS = [1, 2, 3, 4, 5, 6, 7, 8]; // Versions that only support V0 const LATEST_KNOWN_VERSION = Math.max(...V0_COMPATIBLE_VERSIONS); From 236a680a2044770faa7b5000c84ece2731d63d7a Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 31 Oct 2025 20:12:37 +0700 Subject: [PATCH 39/44] Update packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../tests/unit/DataContractUpdateStateTransition.spec.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs b/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs index ab3124862d5..bdca18946fd 100644 --- a/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DataContractUpdateStateTransition.spec.mjs @@ -10,7 +10,7 @@ before(async () => { ({ PlatformVersion } = wasm); }); -describe('DataContract Updatet Transition', () => { +describe('DataContract Update Transition', () => { describe('serialization / deserialization', () => { it('should allow to create document_transitions from data contract', () => { const dataContract = wasm.DataContract.fromValue(value, false, PlatformVersion.PLATFORM_V1); From dc34f751d14cccd4a2eacd17469765af75b359e4 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 31 Oct 2025 20:13:02 +0700 Subject: [PATCH 40/44] fix: typo --- .../tests/unit/DistributionFunction.spec.mjs | 18 +++++++++--------- .../tests/unit/RewardDistributionType.spec.mjs | 12 ++++++------ .../tests/unit/TokenDistributionRules.spec.mjs | 6 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/wasm-dpp2/tests/unit/DistributionFunction.spec.mjs b/packages/wasm-dpp2/tests/unit/DistributionFunction.spec.mjs index dfb269c8237..65168b43b4e 100644 --- a/packages/wasm-dpp2/tests/unit/DistributionFunction.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/DistributionFunction.spec.mjs @@ -8,7 +8,7 @@ before(async () => { describe('DistributionFunction', function () { describe('serialization / deserialization', function () { - it('shoulda allow to create FixedAmountDistribution', () => { + it('should allow to create FixedAmountDistribution', () => { const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111) ) @@ -16,7 +16,7 @@ describe('DistributionFunction', function () { expect(distributionFunction.__wbg_ptr).to.not.equal(0) }) - it('shoulda allow to create Random', () => { + it('should allow to create Random', () => { const distributionFunction = wasm.DistributionFunction.Random( BigInt(111), BigInt(113) @@ -25,7 +25,7 @@ describe('DistributionFunction', function () { expect(distributionFunction.__wbg_ptr).to.not.equal(0) }) - it('shoulda allow to create StepDecreasingAmount', () => { + it('should allow to create StepDecreasingAmount', () => { const distributionFunction = wasm.DistributionFunction.StepDecreasingAmount( 11, 11, @@ -40,7 +40,7 @@ describe('DistributionFunction', function () { expect(distributionFunction.__wbg_ptr).to.not.equal(0) }) - it('shoulda allow to create Stepwise', () => { + it('should allow to create Stepwise', () => { const distributionFunction = wasm.DistributionFunction.Stepwise( { 11111111121: BigInt(111) @@ -50,7 +50,7 @@ describe('DistributionFunction', function () { expect(distributionFunction.__wbg_ptr).to.not.equal(0) }) - it('shoulda allow to create Linear', () => { + it('should allow to create Linear', () => { const distributionFunction = wasm.DistributionFunction.Linear( BigInt(111), BigInt(113), @@ -63,7 +63,7 @@ describe('DistributionFunction', function () { expect(distributionFunction.__wbg_ptr).to.not.equal(0) }) - it('shoulda allow to create Polynomial', () => { + it('should allow to create Polynomial', () => { const distributionFunction = wasm.DistributionFunction.Polynomial( BigInt(111), BigInt(113), @@ -79,7 +79,7 @@ describe('DistributionFunction', function () { expect(distributionFunction.__wbg_ptr).to.not.equal(0) }) - it('shoulda allow to create Exponential', () => { + it('should allow to create Exponential', () => { const distributionFunction = wasm.DistributionFunction.Exponential( BigInt(111), BigInt(113), @@ -95,7 +95,7 @@ describe('DistributionFunction', function () { expect(distributionFunction.__wbg_ptr).to.not.equal(0) }) - it('shoulda allow to create Logarithmic', () => { + it('should allow to create Logarithmic', () => { const distributionFunction = wasm.DistributionFunction.Logarithmic( BigInt(111), BigInt(113), @@ -111,7 +111,7 @@ describe('DistributionFunction', function () { expect(distributionFunction.__wbg_ptr).to.not.equal(0) }) - it('shoulda allow to create InvertedLogarithmic', () => { + it('should allow to create InvertedLogarithmic', () => { const distributionFunction = wasm.DistributionFunction.InvertedLogarithmic( BigInt(111), BigInt(113), diff --git a/packages/wasm-dpp2/tests/unit/RewardDistributionType.spec.mjs b/packages/wasm-dpp2/tests/unit/RewardDistributionType.spec.mjs index c3882b245d3..b481e9e6efd 100644 --- a/packages/wasm-dpp2/tests/unit/RewardDistributionType.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/RewardDistributionType.spec.mjs @@ -8,7 +8,7 @@ before(async () => { describe('RewardDistributionType', () => { describe('serialization / deserialization', () => { - it('shoulda allow to create BlockBasedDistribution', () => { + it('should allow to create BlockBasedDistribution', () => { const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); @@ -22,7 +22,7 @@ describe('RewardDistributionType', () => { expect(distributionType.__wbg_ptr).to.not.equal(0); }); - it('shoulda allow to create TimeBasedDistribution', () => { + it('should allow to create TimeBasedDistribution', () => { const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); @@ -36,7 +36,7 @@ describe('RewardDistributionType', () => { expect(distributionType.__wbg_ptr).to.not.equal(0); }); - it('shoulda allow to create EpochBasedDistribution', () => { + it('should allow to create EpochBasedDistribution', () => { const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); @@ -52,7 +52,7 @@ describe('RewardDistributionType', () => { }); describe('getters', () => { - it('shoulda allow return value BlockBasedDistribution', () => { + it('should allow return value BlockBasedDistribution', () => { const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); @@ -65,7 +65,7 @@ describe('RewardDistributionType', () => { expect(distributionType.getDistribution().constructor.name).to.equal('BlockBasedDistribution'); }); - it('shoulda allow return value TimeBasedDistribution', () => { + it('should allow return value TimeBasedDistribution', () => { const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); @@ -78,7 +78,7 @@ describe('RewardDistributionType', () => { expect(distributionType.getDistribution().constructor.name).to.equal('TimeBasedDistribution'); }); - it('shoulda allow return value EpochBasedDistribution', () => { + it('should allow return value EpochBasedDistribution', () => { const distributionFunction = wasm.DistributionFunction.FixedAmountDistribution( BigInt(111), ); diff --git a/packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs b/packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs index c48033c646b..6dee286c9ff 100644 --- a/packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs +++ b/packages/wasm-dpp2/tests/unit/TokenDistributionRules.spec.mjs @@ -9,7 +9,7 @@ before(async () => { describe('TokenDistributionRules', () => { describe('serialization / deserialization', () => { - it('shoulda allow to create with undefined values', () => { + it('should allow to create with undefined values', () => { const noOne = wasm.AuthorizedActionTakers.NoOne(); const changeRules = new wasm.ChangeControlRules( @@ -35,7 +35,7 @@ describe('TokenDistributionRules', () => { expect(changeRules.__wbg_ptr).to.not.equal(0); }); - it('shoulda allow to create without undefined values', () => { + it('should allow to create without undefined values', () => { const noOne = wasm.AuthorizedActionTakers.NoOne(); const changeRules = new wasm.ChangeControlRules( @@ -89,7 +89,7 @@ describe('TokenDistributionRules', () => { }); describe('getters', () => { - it('shoulda allow to get values', () => { + it('should allow to get values', () => { const noOne = wasm.AuthorizedActionTakers.NoOne(); const changeRules = new wasm.ChangeControlRules( From 175cc08e730d6982ec1fb5bf71fd0a62a36725a6 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 31 Oct 2025 20:13:14 +0700 Subject: [PATCH 41/44] Update packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_mint.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../src/state_transitions/batch/token_transitions/token_mint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_mint.rs b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_mint.rs index bcbe2891c50..695bcfebd13 100644 --- a/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_mint.rs +++ b/packages/wasm-dpp2/src/state_transitions/batch/token_transitions/token_mint.rs @@ -81,7 +81,7 @@ impl TokenMintTransitionWasm { self.clone().0.public_note_owned() } - #[wasm_bindgen(js_name = getRecipitnId)] + #[wasm_bindgen(js_name = getRecipientId)] pub fn recipient_id(&self, config: &TokenConfigurationWasm) -> WasmDppResult { Ok(self.0.recipient_id(&config.clone().into())?.into()) } From 2afb5f387299e7cfea4b89485b5787bd1fb03e3f Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 31 Oct 2025 20:20:30 +0700 Subject: [PATCH 42/44] chore: update lock file --- Cargo.lock | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b67a74c341f..62c3985dd9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7606,8 +7606,6 @@ dependencies = [ "wasm-bindgen-futures", "wasm-dpp2", "wasm-sdk", - "wee_alloc", - "web-sys", ] [[package]] From b100690f38f25802da53b6ea692ac992e37a6c4e Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Sat, 1 Nov 2025 12:41:33 +0700 Subject: [PATCH 43/44] refactor: fix clippy warnings --- packages/rs-drive-proof-verifier/src/types.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/rs-drive-proof-verifier/src/types.rs b/packages/rs-drive-proof-verifier/src/types.rs index 8ea63626acc..93b1148431a 100644 --- a/packages/rs-drive-proof-verifier/src/types.rs +++ b/packages/rs-drive-proof-verifier/src/types.rs @@ -43,7 +43,6 @@ use dpp::{ identity::KeyID, prelude::{DataContract, Identifier, IdentityPublicKey, Revision}, util::deserializer::ProtocolVersion, - ProtocolError, }; use drive::grovedb::query_result_type::Path; use drive::grovedb::Element; @@ -52,7 +51,6 @@ pub use indexmap::IndexMap; use std::collections::{BTreeMap, BTreeSet}; use dpp::dashcore::hashes::Hash; -use drive::query::vote_poll_contestant_votes_query::ContestedDocumentVotePollVotesDriveQuery; #[cfg(feature = "mocks")] use { bincode::{Decode, Encode}, From 85ab1d5abc7d9aee7fd8c837a3d16d4c6f6c801a Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Sat, 1 Nov 2025 18:20:40 +0700 Subject: [PATCH 44/44] fix: missing import --- packages/rs-drive-proof-verifier/src/types.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/rs-drive-proof-verifier/src/types.rs b/packages/rs-drive-proof-verifier/src/types.rs index 93b1148431a..4938ae2ad47 100644 --- a/packages/rs-drive-proof-verifier/src/types.rs +++ b/packages/rs-drive-proof-verifier/src/types.rs @@ -43,6 +43,7 @@ use dpp::{ identity::KeyID, prelude::{DataContract, Identifier, IdentityPublicKey, Revision}, util::deserializer::ProtocolVersion, + ProtocolError, }; use drive::grovedb::query_result_type::Path; use drive::grovedb::Element;