trac-msb 0.2.17 → 0.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -2
- package/SECURITY.md +9 -6
- package/cli/commandHandler.js +272 -0
- package/cli/handlers.js +210 -0
- package/cli/interactive.js +182 -0
- package/msb.mjs +7 -8
- package/package.json +33 -11
- package/rpc/create_server.js +44 -44
- package/rpc/handlers.js +43 -56
- package/rpc/routes/index.js +8 -8
- package/rpc/rpc_server.js +6 -2
- package/rpc/utils/helpers.js +46 -66
- package/scripts/pear-runner.js +170 -0
- package/src/config/args.js +60 -13
- package/src/config/config.js +163 -14
- package/src/config/env.js +57 -25
- package/src/core/network/Network.js +121 -56
- package/src/core/network/protocols/LegacyProtocol.js +21 -11
- package/src/core/network/protocols/NetworkMessages.js +38 -17
- package/src/core/network/protocols/ProtocolInterface.js +15 -3
- package/src/core/network/protocols/ProtocolSession.js +144 -17
- package/src/core/network/protocols/V1Protocol.js +37 -18
- package/src/core/network/protocols/connectionPolicies.js +174 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +26 -20
- package/src/core/network/protocols/{shared/handlers/base/BaseOperationHandler.js → legacy/handlers/BaseStateOperationHandler.js} +25 -14
- package/src/core/network/protocols/legacy/handlers/{GetRequestHandler.js → LegacyGetRequestHandler.js} +9 -9
- package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +23 -0
- package/src/core/network/protocols/{shared/handlers/RoleOperationHandler.js → legacy/handlers/LegacyRoleOperationHandler.js} +19 -12
- package/src/core/network/protocols/{shared/handlers/SubnetworkOperationHandler.js → legacy/handlers/LegacySubnetworkOperationHandler.js} +29 -18
- package/src/core/network/protocols/{shared/handlers/TransferOperationHandler.js → legacy/handlers/LegacyTransferOperationHandler.js} +18 -12
- package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
- package/src/core/network/protocols/shared/validators/{PartialBootstrapDeployment.js → PartialBootstrapDeploymentValidator.js} +9 -4
- package/src/core/network/protocols/shared/validators/{base/PartialOperation.js → PartialOperationValidator.js} +53 -31
- package/src/core/network/protocols/shared/validators/{PartialRoleAccess.js → PartialRoleAccessValidator.js} +51 -17
- package/src/core/network/protocols/shared/validators/{PartialTransaction.js → PartialTransactionValidator.js} +21 -7
- package/src/core/network/protocols/shared/validators/{PartialTransfer.js → PartialTransferValidator.js} +32 -14
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +91 -7
- package/src/core/network/protocols/v1/V1ProtocolError.js +27 -0
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +66 -0
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +272 -0
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +88 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +84 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +128 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +26 -0
- package/src/core/network/protocols/v1/validators/V1BaseOperation.js +212 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +28 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +260 -0
- package/src/core/network/protocols/v1/validators/V1LivenessRequest.js +15 -0
- package/src/core/network/protocols/v1/validators/V1LivenessResponse.js +17 -0
- package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +210 -0
- package/src/core/network/services/ConnectionManager.js +149 -96
- package/src/core/network/services/MessageOrchestrator.js +197 -37
- package/src/core/network/services/PendingRequestService.js +175 -0
- package/src/core/network/services/TransactionCommitService.js +149 -0
- package/src/core/network/services/TransactionPoolService.js +129 -18
- package/src/core/network/services/TransactionRateLimiterService.js +57 -35
- package/src/core/network/services/ValidatorHealthCheckService.js +127 -0
- package/src/core/network/services/ValidatorObserverService.js +400 -121
- package/src/core/state/State.js +259 -156
- package/src/core/state/utils/address.js +4 -9
- package/src/core/state/utils/balance.js +7 -7
- package/src/core/state/utils/roles.js +1 -1
- package/src/index.js +320 -278
- package/src/messages/network/v1/NetworkMessageBuilder.js +71 -100
- package/src/messages/network/v1/NetworkMessageDirector.js +16 -50
- package/src/messages/network/v1/networkMessageFactory.js +1 -1
- package/src/messages/state/ApplyStateMessageBuilder.js +6 -6
- package/src/messages/state/applyStateMessageFactory.js +1 -1
- package/src/utils/Scheduler.js +0 -8
- package/src/utils/buffer.js +1 -1
- package/src/utils/check.js +12 -13
- package/src/utils/constants.js +78 -5
- package/src/utils/deepEqualApplyPayload.js +40 -0
- package/src/utils/errors.js +20 -0
- package/src/utils/fileUtils.js +12 -3
- package/src/utils/helpers.js +10 -1
- package/src/utils/logger.js +25 -0
- package/src/utils/migrationUtils.js +3 -3
- package/src/utils/normalizers.js +38 -0
- package/src/utils/protobuf/networkV1.generated.cjs +2460 -0
- package/src/utils/protobuf/operationHelpers.js +24 -3
- package/.dockerignore +0 -16
- package/.github/workflows/acceptance-tests.yml +0 -38
- package/.github/workflows/lint-pr-title.yml +0 -26
- package/.github/workflows/publish.yml +0 -33
- package/.github/workflows/unit-tests.yml +0 -34
- package/CODE_OF_CONDUCT.md +0 -128
- package/docker-compose.yml +0 -17
- package/dockerfile +0 -41
- package/docs/fee_distribution.md +0 -89
- package/docs/trac_network_http_api.openapi.yaml +0 -889
- package/migration/.gitkeep +0 -0
- package/proto/applyOperations.proto +0 -117
- package/proto/network.proto +0 -74
- package/rpc/rpc_services.js +0 -163
- package/scripts/generate-protobufs.js +0 -42
- package/src/core/network/identity/NetworkWalletFactory.js +0 -77
- package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +0 -37
- package/src/utils/cli.js +0 -130
- package/src/utils/cliCommands.js +0 -280
- package/src/utils/protobuf/network.cjs +0 -840
- package/tests/acceptance/v1/account/account.test.mjs +0 -123
- package/tests/acceptance/v1/balance/balance.test.mjs +0 -54
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +0 -116
- package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +0 -19
- package/tests/acceptance/v1/fee/fee.test.mjs +0 -11
- package/tests/acceptance/v1/health/health.test.mjs +0 -33
- package/tests/acceptance/v1/rpc.test.mjs +0 -95
- package/tests/acceptance/v1/tx/tx.test.mjs +0 -111
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -213
- package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +0 -72
- package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +0 -27
- package/tests/acceptance/v1/txv/txv.test.mjs +0 -11
- package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +0 -11
- package/tests/fixtures/apply.fixtures.js +0 -77
- package/tests/fixtures/assembleMessage.fixtures.js +0 -41
- package/tests/fixtures/check.fixtures.js +0 -428
- package/tests/fixtures/networkV1.fixtures.js +0 -85
- package/tests/fixtures/protobuf.fixtures.js +0 -388
- package/tests/helpers/StateNetworkFactory.js +0 -155
- package/tests/helpers/address.js +0 -6
- package/tests/helpers/autobaseTestHelpers.js +0 -419
- package/tests/helpers/config.js +0 -4
- package/tests/helpers/createTestSignature.js +0 -13
- package/tests/helpers/regexHelper.js +0 -3
- package/tests/helpers/setupApplyTests.js +0 -587
- package/tests/helpers/transactionPayloads.mjs +0 -92
- package/tests/helpers/wrapper.js +0 -28
- package/tests/unit/messages/messages.test.js +0 -12
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +0 -276
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -201
- package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +0 -525
- package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +0 -237
- package/tests/unit/network/ConnectionManager.test.js +0 -191
- package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
- package/tests/unit/network/networkModule.test.js +0 -10
- package/tests/unit/state/State.test.js +0 -80
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +0 -42
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +0 -276
- package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +0 -78
- package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +0 -68
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +0 -159
- package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +0 -39
- package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +0 -167
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +0 -186
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +0 -443
- package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +0 -32
- package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +0 -297
- package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +0 -41
- package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +0 -149
- package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +0 -766
- package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +0 -50
- package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +0 -37
- package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +0 -42
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +0 -106
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +0 -309
- package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +0 -30
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +0 -881
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +0 -435
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +0 -78
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +0 -98
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +0 -66
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +0 -55
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +0 -103
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +0 -60
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +0 -189
- package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +0 -220
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +0 -111
- package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +0 -45
- package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +0 -189
- package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +0 -156
- package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +0 -36
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +0 -531
- package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +0 -74
- package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +0 -32
- package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +0 -38
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +0 -91
- package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +0 -266
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +0 -143
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +0 -26
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +0 -94
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +0 -37
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +0 -86
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +0 -347
- package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +0 -57
- package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +0 -429
- package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +0 -120
- package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +0 -130
- package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +0 -93
- package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +0 -108
- package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +0 -126
- package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +0 -121
- package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +0 -50
- package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +0 -56
- package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +0 -198
- package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +0 -40
- package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +0 -114
- package/tests/unit/state/apply/common/commonScenarioHelper.js +0 -103
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +0 -29
- package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +0 -66
- package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +0 -84
- package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +0 -47
- package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +0 -85
- package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +0 -52
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +0 -54
- package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +0 -73
- package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +0 -71
- package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +0 -31
- package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +0 -142
- package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +0 -87
- package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +0 -71
- package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +0 -73
- package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +0 -44
- package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +0 -25
- package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +0 -98
- package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +0 -202
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +0 -17
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +0 -44
- package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +0 -19
- package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +0 -18
- package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +0 -315
- package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +0 -18
- package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +0 -43
- package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +0 -53
- package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +0 -24
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +0 -204
- package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +0 -161
- package/tests/unit/state/apply/missing-tests.md +0 -18
- package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +0 -58
- package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +0 -98
- package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +0 -167
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +0 -429
- package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +0 -22
- package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +0 -20
- package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +0 -291
- package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +0 -87
- package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +0 -38
- package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +0 -348
- package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +0 -113
- package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +0 -33
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +0 -26
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +0 -22
- package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +0 -307
- package/tests/unit/state/apply/state.apply.test.js +0 -24
- package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +0 -819
- package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +0 -22
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +0 -146
- package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +0 -63
- package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +0 -67
- package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +0 -22
- package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +0 -8
- package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +0 -66
- package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +0 -1170
- package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +0 -318
- package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +0 -70
- package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +0 -23
- package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +0 -48
- package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +0 -39
- package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +0 -46
- package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +0 -432
- package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +0 -31
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +0 -49
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +0 -93
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +0 -29
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +0 -33
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/stateModule.test.js +0 -23
- package/tests/unit/state/stateTestUtils.js +0 -32
- package/tests/unit/state/utils/address.test.js +0 -63
- package/tests/unit/state/utils/adminEntry.test.js +0 -52
- package/tests/unit/state/utils/balance.test.js +0 -320
- package/tests/unit/state/utils/lengthEntry.test.js +0 -54
- package/tests/unit/state/utils/nodeEntry.test.js +0 -298
- package/tests/unit/state/utils/roles.test.js +0 -44
- package/tests/unit/unit.test.js +0 -14
- package/tests/unit/utils/amountSerialization/amountSerialization.test.js +0 -237
- package/tests/unit/utils/buffer/buffer.test.js +0 -251
- package/tests/unit/utils/check/adminControlOperation.test.js +0 -156
- package/tests/unit/utils/check/balanceInitializationOperation.test.js +0 -54
- package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +0 -104
- package/tests/unit/utils/check/check.test.js +0 -17
- package/tests/unit/utils/check/common.test.js +0 -419
- package/tests/unit/utils/check/coreAdminOperation.test.js +0 -95
- package/tests/unit/utils/check/roleAccessOperation.test.js +0 -255
- package/tests/unit/utils/check/transactionOperation.test.js +0 -107
- package/tests/unit/utils/check/transferOperation.test.js +0 -102
- package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +0 -95
- package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +0 -149
- package/tests/unit/utils/helpers/helpers.test.js +0 -11
- package/tests/unit/utils/helpers/isHexString.test.js +0 -12
- package/tests/unit/utils/helpers/normalizeHex.test.js +0 -82
- package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +0 -100
- package/tests/unit/utils/normalizers/normalizers.test.js +0 -469
- package/tests/unit/utils/protobuf/applyOperations.test.js +0 -91
- package/tests/unit/utils/protobuf/operationHelpers.test.js +0 -305
- package/tests/unit/utils/protobuf/protobuf.test.js +0 -12
- package/tests/unit/utils/type/type.test.js +0 -25
- package/tests/unit/utils/utils.test.js +0 -20
- package/whitelist/.gitkeep +0 -0
package/README.md
CHANGED
|
@@ -18,9 +18,9 @@ The MSB leverages the [Pear Runtime and Holepunch](https://pears.com/).
|
|
|
18
18
|
|
|
19
19
|
Node.js is required to run the application. Before installing Node.js, refer to the official [Node.js documentation](https://nodejs.org) for the latest recommended version and installation instructions. For this project, Node.js v22.22.0 (LTS) and npm 11.6.1 or newer are compatible.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
MSB supports both Pear v2 and Pear v3. Its Pear runner uses `pear run` with Pear v2 and the embedded [`pear-runtime`](https://docs.pears.com/reference/pear/runtime/) module with Pear v3.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
The Pear CLI is required for Pear v2 and for Pear deployment commands. Pear v3 can run MSB through the embedded module without a globally installed CLI. Install the CLI when it is needed:
|
|
24
24
|
|
|
25
25
|
```sh
|
|
26
26
|
npm install -g pear
|
|
@@ -53,6 +53,23 @@ npm install -g bare
|
|
|
53
53
|
|
|
54
54
|
Runtime entry points cover CLI-driven runs (`start`, `rpc`) and `.env`-aware runs (`env`, `env-rpc`). Each section below lists the accepted configuration inputs.
|
|
55
55
|
|
|
56
|
+
### Startup input validation
|
|
57
|
+
|
|
58
|
+
Startup input is validated before MSB finishes booting. This applies to direct CLI flags and to the `.env` / inline environment-variable entry points, because those scripts pass the same flags through the Pear v2/v3 runner.
|
|
59
|
+
|
|
60
|
+
- `--network` / `NETWORK` must be one of `mainnet`, `development`, `testnet1`, or `testnet` (`testnet` is treated as an alias for `testnet1`).
|
|
61
|
+
- `--stores-directory` / `STORES_DIRECTORY` must be a non-empty string.
|
|
62
|
+
- `--host` / `MSB_HOST` must be a non-empty string when RPC mode is enabled.
|
|
63
|
+
- `--port` / `MSB_PORT` must be an integer in range `1-65535` when RPC mode is enabled.
|
|
64
|
+
|
|
65
|
+
MSB also validates the high-risk overrideable config values that are normalized into shared runtime state before startup:
|
|
66
|
+
|
|
67
|
+
- `bootstrap` must be a 32-byte hex string or `Buffer`.
|
|
68
|
+
- `channel` must be a string or `Buffer` with length `1-32` bytes.
|
|
69
|
+
- `storesDirectory`, `host`, `port`, and `dhtBootstrap` overrides are validated before the node starts.
|
|
70
|
+
|
|
71
|
+
When one of these values is invalid, startup fails immediately with a field-specific error instead of silently falling back.
|
|
72
|
+
|
|
56
73
|
### Interactive regular node
|
|
57
74
|
|
|
58
75
|
#### Regular node with .env file
|
|
@@ -87,6 +104,8 @@ This run persists data under `${STORES_DIRECTORY}` (defaults to `stores` under t
|
|
|
87
104
|
npm run start -- --stores-directory <stores_directory> --network testnet
|
|
88
105
|
```
|
|
89
106
|
|
|
107
|
+
Supported network values are `mainnet`, `development`, `testnet1`, and `testnet` (`testnet` maps to `testnet1`).
|
|
108
|
+
|
|
90
109
|
### RPC-enabled node
|
|
91
110
|
|
|
92
111
|
#### RPC with .env file
|
|
@@ -119,6 +138,8 @@ Override any combination of `STORES_DIRECTORY`, `MSB_HOST`, `MSB_PORT`, or `NETW
|
|
|
119
138
|
npm run rpc --host=<host> --port=<port> -- --stores-directory <stores_directory> --network <network>
|
|
120
139
|
```
|
|
121
140
|
|
|
141
|
+
Supported network values are `mainnet`, `development`, `testnet1`, and `testnet` (`testnet` maps to `testnet1`). Invalid `--host`, `--port`, `--stores-directory`, or `--network` values fail before the RPC node starts.
|
|
142
|
+
|
|
122
143
|
## Docker usage
|
|
123
144
|
|
|
124
145
|
You can run the RPC node in a containerized environment using the provided `docker-compose.yml` file. The `msb-rpc` service is already wired up. You usually only need to tweak these variables:
|
|
@@ -216,3 +237,42 @@ Stop the service with `docker compose stop msb-rpc`, remove the stack entirely w
|
|
|
216
237
|
|
|
217
238
|
- **Dependency install failures** – confirm you are on Node.js v22.22.0 (LTS) and npm ≥ 11.6.1. If packages still fail to build, clear artifacts (`rm -rf node_modules package-lock.json && npm install`) and rerun `npm run test:unit:all`.
|
|
218
239
|
- **Unit tests fail only in one runtime** – run the targeted commands (`npm run test:unit:node` or `npm run test:unit:bare`) to isolate regressions, then inspect `tests/unit/unit.test.js` for the failing cases.
|
|
240
|
+
|
|
241
|
+
## Development
|
|
242
|
+
|
|
243
|
+
### VS Code
|
|
244
|
+
|
|
245
|
+
Open the repository root in VS Code so the editor can resolve the local `eslint` dependency, the root `eslint.config.js`, and the existing debugger launch configurations in `.vscode/launch.json`.
|
|
246
|
+
|
|
247
|
+
Install these extensions:
|
|
248
|
+
|
|
249
|
+
- `dbaeumer.vscode-eslint` (microsoft.com)
|
|
250
|
+
|
|
251
|
+
For linting, add the following to your workspace or user `.vscode/settings.json`:
|
|
252
|
+
|
|
253
|
+
```json
|
|
254
|
+
{
|
|
255
|
+
"editor.formatOnSave": false,
|
|
256
|
+
"editor.codeActionsOnSave": {
|
|
257
|
+
"source.fixAll.eslint": "explicit"
|
|
258
|
+
},
|
|
259
|
+
"eslint.useFlatConfig": true,
|
|
260
|
+
"eslint.workingDirectories": [
|
|
261
|
+
{
|
|
262
|
+
"mode": "auto"
|
|
263
|
+
}
|
|
264
|
+
],
|
|
265
|
+
"[javascript]": {
|
|
266
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Linting and tests
|
|
272
|
+
|
|
273
|
+
Use these commands during development:
|
|
274
|
+
|
|
275
|
+
- `npm run lint` checks the full repository with ESLint.
|
|
276
|
+
- `npm run lint:fix` applies ESLint autofixes where possible.
|
|
277
|
+
- `npm run test:unit:all` runs both unit suites and is the main pre-commit test command.
|
|
278
|
+
- `npm run test:acceptance` runs the RPC acceptance test suite.
|
package/SECURITY.md
CHANGED
|
@@ -4,12 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
The following table shows which versions of this project are currently receiving security updates.
|
|
6
6
|
|
|
7
|
-
| Version
|
|
8
|
-
| -------- | ------------------ |
|
|
9
|
-
| 0.2.
|
|
10
|
-
|
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
| Version | Supported | Pear compatibility |
|
|
8
|
+
| -------- | ------------------ | ------------------ |
|
|
9
|
+
| 0.2.19 | :white_check_mark: | Pear v2 and v3 |
|
|
10
|
+
| 0.2.18 | :white_check_mark: | Pear v2 only |
|
|
11
|
+
| 0.2.17 | :white_check_mark: | Pear v2 only |
|
|
12
|
+
| main | :warning: unstable | Pear v2 and v3 |
|
|
13
|
+
| < 0.2.17 | :x: | N/A |
|
|
14
|
+
|
|
15
|
+
Versions older than 0.2.17 are deprecated.
|
|
13
16
|
Please upgrade to the latest release to ensure you receive security fixes.
|
|
14
17
|
|
|
15
18
|
---
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { randomBytes } from "hypercore-crypto";
|
|
2
|
+
import { Handlers } from "./handlers.js";
|
|
3
|
+
import { isHexString } from "../src/utils/helpers.js";
|
|
4
|
+
import { bigIntToDecimalString } from "../src/utils/amountSerialization.js";
|
|
5
|
+
|
|
6
|
+
export const COMMANDS = {
|
|
7
|
+
HELP: "/help",
|
|
8
|
+
EXIT: "/exit",
|
|
9
|
+
ADD_ADMIN: "/add_admin",
|
|
10
|
+
ADD_ADMIN_RECOVERY: "/add_admin --recovery",
|
|
11
|
+
ADD_WHITELIST: "/add_whitelist",
|
|
12
|
+
ADD_WRITER: "/add_writer",
|
|
13
|
+
REMOVE_WRITER: "/remove_writer",
|
|
14
|
+
CORE: "/core",
|
|
15
|
+
INDEXERS_LIST: "/indexers_list",
|
|
16
|
+
VALIDATOR_POOL: "/validator_pool",
|
|
17
|
+
STATS: "/stats",
|
|
18
|
+
BALANCE_MIGRATION: "/balance_migration",
|
|
19
|
+
DISABLE_INITIALIZATION: "/disable_initialization",
|
|
20
|
+
NODE_STATUS: "/node_status",
|
|
21
|
+
ADD_INDEXER: "/add_indexer",
|
|
22
|
+
REMOVE_INDEXER: "/remove_indexer",
|
|
23
|
+
BAN_WRITER: "/ban_writer",
|
|
24
|
+
DEPLOYMENT: "/deployment",
|
|
25
|
+
GET_VALIDATOR_ADDR: "/get_validator_addr",
|
|
26
|
+
GET_DEPLOYMENT: "/get_deployment",
|
|
27
|
+
GET_TX_INFO: "/get_tx_info",
|
|
28
|
+
TRANSFER: "/transfer",
|
|
29
|
+
GET_BALANCE: "/get_balance",
|
|
30
|
+
GET_LICENSE_NUMBER: "/get_license_number",
|
|
31
|
+
GET_LICENSE_ADDRESS: "/get_license_address",
|
|
32
|
+
GET_LICENSE_COUNT: "/get_license_count",
|
|
33
|
+
GET_TXV: "/get_txv",
|
|
34
|
+
GET_FEE: "/get_fee",
|
|
35
|
+
CONFIRMED_LENGTH: "/confirmed_length",
|
|
36
|
+
UNCONFIRMED_LENGTH: "/unconfirmed_length",
|
|
37
|
+
GET_TXS_HASHES: "/get_txs_hashes",
|
|
38
|
+
GET_TX_DETAILS: "/get_tx_details",
|
|
39
|
+
GET_EXTENDED_TX_DETAILS: "/get_extended_tx_details"
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export class CommandHandler {
|
|
43
|
+
#msb;
|
|
44
|
+
#closeCli;
|
|
45
|
+
#wallet;
|
|
46
|
+
#handlers;
|
|
47
|
+
#pendingConfirmation = null;
|
|
48
|
+
|
|
49
|
+
constructor({ config, msb, handleClose, wallet }) {
|
|
50
|
+
this.#msb = msb;
|
|
51
|
+
this.#closeCli = handleClose;
|
|
52
|
+
this.#wallet = wallet;
|
|
53
|
+
this.#handlers = new Handlers(msb, config);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async handle(input) {
|
|
57
|
+
if (this.#pendingConfirmation !== null) {
|
|
58
|
+
return this.#handlePendingConfirmation(input);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const [command, ...parts] = input.split(" ");
|
|
62
|
+
const context = { command, input, parts };
|
|
63
|
+
const handlers = this.#getHandlers();
|
|
64
|
+
const handler = handlers.find(({ evaluate }) => evaluate(context));
|
|
65
|
+
|
|
66
|
+
if (handler) {
|
|
67
|
+
return handler.process(context);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#getHandlers() {
|
|
72
|
+
return [
|
|
73
|
+
{
|
|
74
|
+
evaluate: ({ command }) => command === COMMANDS.HELP,
|
|
75
|
+
process: async () => {
|
|
76
|
+
this.#msb.printHelp();
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
evaluate: ({ command }) => command === COMMANDS.EXIT,
|
|
81
|
+
process: async () => {
|
|
82
|
+
await this.#closeCli();
|
|
83
|
+
await this.#msb.close();
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
evaluate: ({ input }) => input === COMMANDS.ADD_ADMIN_RECOVERY,
|
|
88
|
+
process: async () => this.#msb.handleAdminRecovery()
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
evaluate: ({ command }) => command === COMMANDS.ADD_ADMIN,
|
|
92
|
+
process: async () => this.#msb.handleAdminCreation()
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
evaluate: ({ command }) => command === COMMANDS.ADD_WHITELIST,
|
|
96
|
+
process: async () => this.#msb.handleWhitelistOperations()
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
evaluate: ({ command }) => command === COMMANDS.ADD_WRITER,
|
|
100
|
+
process: async () => this.#msb.requestWriterRole(true)
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
evaluate: ({ command }) => command === COMMANDS.REMOVE_WRITER,
|
|
104
|
+
process: async () => this.#msb.requestWriterRole(false)
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
evaluate: ({ command }) => command === COMMANDS.CORE,
|
|
108
|
+
process: async () => this.#handlers.handleCoreInfo()
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
evaluate: ({ command }) => command === COMMANDS.INDEXERS_LIST,
|
|
112
|
+
process: async () => console.log(await this.#msb.state.getIndexersEntry())
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
evaluate: ({ command }) => command === COMMANDS.VALIDATOR_POOL,
|
|
116
|
+
process: async () => this.#msb.network.validatorConnectionManager.prettyPrint()
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
evaluate: ({ command }) => command === COMMANDS.STATS,
|
|
120
|
+
process: async () => this.#msb.verifyDag()
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
evaluate: ({ command }) => command === COMMANDS.BALANCE_MIGRATION,
|
|
124
|
+
process: async () => this.#msb.balanceMigrationOperation()
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
evaluate: ({ command }) => command === COMMANDS.DISABLE_INITIALIZATION,
|
|
128
|
+
process: async () => this.#msb.disableInitialization()
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.NODE_STATUS),
|
|
132
|
+
process: async ({ parts }) => this.#handlers.handleNodeStatus(parts[0])
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.ADD_INDEXER),
|
|
136
|
+
process: async ({ parts }) => this.#msb.updateWriterToIndexerRole(parts[0], true)
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.REMOVE_INDEXER),
|
|
140
|
+
process: async ({ parts }) => this.#msb.updateWriterToIndexerRole(parts[0], false)
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.BAN_WRITER),
|
|
144
|
+
process: async ({ parts }) => this.#msb.banValidator(parts[0])
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.DEPLOYMENT),
|
|
148
|
+
process: async ({ parts }) => {
|
|
149
|
+
const channel = parts[1] || randomBytes(32).toString("hex");
|
|
150
|
+
if (!isHexString(channel, 64)) {
|
|
151
|
+
throw new Error("Channel must be a 32-byte hex string");
|
|
152
|
+
}
|
|
153
|
+
return this.#msb.deployBootstrap(parts[0], channel);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.GET_VALIDATOR_ADDR),
|
|
158
|
+
process: async ({ parts }) => this.#handlers.handleValidatorAddress(parts[0])
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.GET_DEPLOYMENT),
|
|
162
|
+
process: async ({ parts }) => this.#handlers.handleDeployment(parts[0])
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.GET_TX_INFO),
|
|
166
|
+
process: async ({ parts }) => this.#handlers.handleTxInfo(parts[0])
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.TRANSFER),
|
|
170
|
+
process: async ({ parts }) => this.#queueTransferConfirmation(parts[0], parts[1])
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.GET_BALANCE),
|
|
174
|
+
process: async ({ parts }) => this.#handlers.handleBalance(parts[0] || this.#wallet?.address, parts[1])
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.GET_LICENSE_NUMBER),
|
|
178
|
+
process: async ({ parts }) => this.#handlers.handleLicenseNumber(parts[0])
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.GET_LICENSE_ADDRESS),
|
|
182
|
+
process: async ({ parts }) => this.#handlers.handleLicenseAddress(parseInt(parts[0]))
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.GET_LICENSE_COUNT),
|
|
186
|
+
process: async () => this.#handlers.handleLicenseCount()
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.GET_TXV),
|
|
190
|
+
process: async () => this.#handlers.handleTxv()
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.GET_FEE),
|
|
194
|
+
process: async () => this.#handlers.handleFee()
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.CONFIRMED_LENGTH),
|
|
198
|
+
process: async () => this.#handlers.handleConfirmedLength()
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.UNCONFIRMED_LENGTH),
|
|
202
|
+
process: async () => this.#handlers.handleUnconfirmedLength()
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.GET_TXS_HASHES),
|
|
206
|
+
process: async ({ parts }) => this.#handlers.handleTxHashes(
|
|
207
|
+
parseInt(parts[0]),
|
|
208
|
+
parseInt(parts[1])
|
|
209
|
+
)
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.GET_TX_DETAILS),
|
|
213
|
+
process: async ({ parts }) => this.#handlers.handleTxDetails(parts[0])
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
evaluate: ({ input }) => input.startsWith(COMMANDS.GET_EXTENDED_TX_DETAILS),
|
|
217
|
+
process: async ({ parts }) => this.#handlers.handleExtendedTxDetails(parts[0], parts[1] === "true")
|
|
218
|
+
}
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
async #handlePendingConfirmation(input) {
|
|
223
|
+
const normalizedInput = input.trim().toLowerCase();
|
|
224
|
+
const pendingConfirmation = this.#pendingConfirmation;
|
|
225
|
+
|
|
226
|
+
if (normalizedInput === "y" || normalizedInput === "yes") {
|
|
227
|
+
this.#pendingConfirmation = null;
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
return await pendingConfirmation.onConfirm();
|
|
231
|
+
} catch (error) {
|
|
232
|
+
const errorMessage = typeof error === "object" && error !== null && "message" in error
|
|
233
|
+
? error.message
|
|
234
|
+
: `${error}`;
|
|
235
|
+
console.error(`Transaction submission failed: ${errorMessage}`);
|
|
236
|
+
console.log("Try again or use /help.");
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (normalizedInput === "n" || normalizedInput === "no") {
|
|
243
|
+
this.#pendingConfirmation = null;
|
|
244
|
+
return pendingConfirmation.onDecline();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
console.log('Invalid input. Please answer "y" or "n".');
|
|
248
|
+
console.log(pendingConfirmation.prompt);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async #queueTransferConfirmation(recipientAddress, amount) {
|
|
252
|
+
const preparedTransfer = await this.#msb.prepareTransferOperation(recipientAddress, amount);
|
|
253
|
+
|
|
254
|
+
console.info("Transfer Details:");
|
|
255
|
+
if (preparedTransfer.isSelfTransfer) {
|
|
256
|
+
console.info("Self transfer - only fee will be deducted");
|
|
257
|
+
}
|
|
258
|
+
console.info(`Amount: ${bigIntToDecimalString(preparedTransfer.amountBigInt)}`);
|
|
259
|
+
console.info(`Estimated transaction fee: ${bigIntToDecimalString(preparedTransfer.feeBigInt)}`);
|
|
260
|
+
console.info(`Total transaction cost: ${bigIntToDecimalString(preparedTransfer.totalDeductedAmount)}`);
|
|
261
|
+
console.info(`Current balance: ${bigIntToDecimalString(preparedTransfer.senderBalance)}`);
|
|
262
|
+
console.info(`Balance after transaction: ${bigIntToDecimalString(preparedTransfer.expectedNewBalance)}`);
|
|
263
|
+
|
|
264
|
+
this.#pendingConfirmation = {
|
|
265
|
+
prompt: "Do you want to proceed? (y/n)",
|
|
266
|
+
onConfirm: async () => this.#msb.submitPreparedTransferOperation(preparedTransfer),
|
|
267
|
+
onDecline: async () => this.#msb.printHelp()
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
console.log(this.#pendingConfirmation.prompt);
|
|
271
|
+
}
|
|
272
|
+
}
|
package/cli/handlers.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { ZERO_WK } from "../src/utils/buffer.js";
|
|
2
|
+
import { bigIntToDecimalString, bufferToBigInt } from "../src/utils/amountSerialization.js";
|
|
3
|
+
import { EntryType } from "../src/utils/constants.js";
|
|
4
|
+
import { bufferToAddress } from "../src/core/state/utils/address.js";
|
|
5
|
+
import deploymentEntryUtils from "../src/core/state/utils/deploymentEntry.js";
|
|
6
|
+
import { safeDecodeApplyOperation } from "../src/utils/protobuf/operationHelpers.js";
|
|
7
|
+
|
|
8
|
+
export class Handlers {
|
|
9
|
+
#msb
|
|
10
|
+
#config
|
|
11
|
+
|
|
12
|
+
constructor(msb, config) {
|
|
13
|
+
this.#msb = msb
|
|
14
|
+
this.#config = config
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async handleNodeStatus(address) {
|
|
18
|
+
const nodeEntry = await this.#msb.state.getNodeEntry(address)
|
|
19
|
+
if (nodeEntry) {
|
|
20
|
+
const licenseValue = nodeEntry.license.readUInt32BE(0)
|
|
21
|
+
const licenseDisplay = licenseValue === 0 ? "N/A" : licenseValue.toString()
|
|
22
|
+
console.log("Node Status:", {
|
|
23
|
+
Address: address,
|
|
24
|
+
WritingKey: nodeEntry.wk.toString("hex"),
|
|
25
|
+
IsWhitelisted: nodeEntry.isWhitelisted,
|
|
26
|
+
IsWriter: nodeEntry.isWriter,
|
|
27
|
+
IsIndexer: nodeEntry.isIndexer,
|
|
28
|
+
License: licenseDisplay,
|
|
29
|
+
StakedBalance: bigIntToDecimalString(bufferToBigInt(nodeEntry.stakedBalance)),
|
|
30
|
+
Balance: bigIntToDecimalString(bufferToBigInt(nodeEntry.balance))
|
|
31
|
+
})
|
|
32
|
+
return {
|
|
33
|
+
address,
|
|
34
|
+
writingKey: nodeEntry.wk.toString("hex"),
|
|
35
|
+
isWhitelisted: nodeEntry.isWhitelisted,
|
|
36
|
+
isWriter: nodeEntry.isWriter,
|
|
37
|
+
isIndexer: nodeEntry.isIndexer,
|
|
38
|
+
license: licenseDisplay,
|
|
39
|
+
stakedBalance: bigIntToDecimalString(bufferToBigInt(nodeEntry.stakedBalance)),
|
|
40
|
+
balance: bigIntToDecimalString(bufferToBigInt(nodeEntry.balance))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
console.log("Node Status:", {
|
|
45
|
+
WritingKey: ZERO_WK.toString("hex"),
|
|
46
|
+
IsWhitelisted: false,
|
|
47
|
+
IsWriter: false,
|
|
48
|
+
IsIndexer: false,
|
|
49
|
+
license: "N/A",
|
|
50
|
+
stakedBalance: "0"
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async handleCoreInfo() {
|
|
55
|
+
const admin = await this.#msb.state.getAdminEntry()
|
|
56
|
+
console.log("Admin:", admin ? {
|
|
57
|
+
address: admin.address,
|
|
58
|
+
writingKey: admin.wk.toString("hex")
|
|
59
|
+
} : null)
|
|
60
|
+
|
|
61
|
+
const formattedIndexers = await this.#msb.state.getIndexersEntry().then(entry => entry ? entry : null)
|
|
62
|
+
if (!formattedIndexers || (Array.isArray(formattedIndexers) && formattedIndexers.length === 0)) {
|
|
63
|
+
console.log("Indexers: no indexers")
|
|
64
|
+
} else {
|
|
65
|
+
console.log("Indexers:", formattedIndexers)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async handleValidatorAddress(wkHexString) {
|
|
70
|
+
const payload = await this.#msb.state.getSigned(EntryType.WRITER_ADDRESS + wkHexString)
|
|
71
|
+
if (payload === null) {
|
|
72
|
+
console.log(`No address assigned to the writer key: ${wkHexString}`)
|
|
73
|
+
} else {
|
|
74
|
+
console.log(
|
|
75
|
+
`Address assigned to the writer key: ${wkHexString} - ${bufferToAddress(payload, this.#config.addressPrefix)}`
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async handleDeployment(bootstrapHex) {
|
|
81
|
+
const deploymentEntry = await this.#msb.state.getRegisteredBootstrapEntry(bootstrapHex)
|
|
82
|
+
if (deploymentEntry) {
|
|
83
|
+
const decodedDeploymentEntry = deploymentEntryUtils.decode(deploymentEntry, this.#config.addressLength)
|
|
84
|
+
const txhash = decodedDeploymentEntry.txHash.toString("hex")
|
|
85
|
+
console.log(`Bootstrap deployed under transaction hash: ${txhash}`)
|
|
86
|
+
const payload = await this.#msb.state.getSigned(txhash)
|
|
87
|
+
if (payload) {
|
|
88
|
+
const decoded = safeDecodeApplyOperation(payload)
|
|
89
|
+
console.log("Decoded Bootstrap Deployment Payload:", decoded)
|
|
90
|
+
} else {
|
|
91
|
+
console.log(`No payload found for transaction hash: ${txhash}`)
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
console.log(`No deployment found for bootstrap: ${bootstrapHex}`)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async handleTxInfo(txHash) {
|
|
99
|
+
const txInfo = await this.#msb.getConfirmedTxInfo(txHash)
|
|
100
|
+
if (txInfo) {
|
|
101
|
+
console.log(`Payload for transaction hash ${txHash}:`, txInfo.decoded)
|
|
102
|
+
} else {
|
|
103
|
+
console.log(`No information found for transaction hash: ${txHash}`)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async handleLicenseNumber(address) {
|
|
108
|
+
const nodeEntry = await this.#msb.state.getNodeEntry(address)
|
|
109
|
+
if (nodeEntry) {
|
|
110
|
+
console.log({
|
|
111
|
+
Address: address,
|
|
112
|
+
License: bufferToBigInt(nodeEntry.license).toString()
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async handleLicenseAddress(licenseId) {
|
|
118
|
+
if (isNaN(licenseId) || licenseId < 0) {
|
|
119
|
+
console.log("Invalid license ID. Please provide a valid non-negative number.")
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const address = await this.#msb.state.getAddressByLicenseId(licenseId)
|
|
124
|
+
if (address) {
|
|
125
|
+
console.log({
|
|
126
|
+
LicenseId: licenseId,
|
|
127
|
+
Address: address
|
|
128
|
+
})
|
|
129
|
+
} else {
|
|
130
|
+
console.log(`No address found for license ID: ${licenseId}`)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async handleLicenseCount() {
|
|
135
|
+
if (!await this.#msb.state.isAdmin()) {
|
|
136
|
+
throw new Error("Cannot perform this operation - you are not the admin!.")
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const licenseCount = await this.#msb.state.getLicenseCount()
|
|
140
|
+
console.log({
|
|
141
|
+
LicensesCount: licenseCount
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
handleFee() {
|
|
146
|
+
const fee = this.#msb.handleGetFee()
|
|
147
|
+
console.log("Current FEE:", bigIntToDecimalString(fee));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async handleBalance(address, confirmedFlag) {
|
|
151
|
+
const nodeInfo = await this.#msb.getBalance(address, confirmedFlag !== "false");
|
|
152
|
+
|
|
153
|
+
if (nodeInfo) {
|
|
154
|
+
console.log({
|
|
155
|
+
Address: address,
|
|
156
|
+
Balance: bigIntToDecimalString(BigInt(nodeInfo.balance))
|
|
157
|
+
});
|
|
158
|
+
return nodeInfo;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
console.log("Node Entry:", {
|
|
162
|
+
WritingKey: ZERO_WK.toString("hex"),
|
|
163
|
+
IsWhitelisted: false,
|
|
164
|
+
IsWriter: false,
|
|
165
|
+
IsIndexer: false,
|
|
166
|
+
balance: bigIntToDecimalString(0n)
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async handleTxv() {
|
|
171
|
+
const txv = await this.#msb.getTxv();
|
|
172
|
+
console.log("Current TXV:", txv);
|
|
173
|
+
return txv;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
handleConfirmedLength() {
|
|
177
|
+
const confirmedLength = this.#msb.getConfirmedLength();
|
|
178
|
+
console.log("Confirmed_length:", confirmedLength);
|
|
179
|
+
return confirmedLength;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
handleUnconfirmedLength() {
|
|
183
|
+
const unconfirmedLength = this.#msb.getUnconfirmedLength();
|
|
184
|
+
console.log("Unconfirmed_length:", unconfirmedLength);
|
|
185
|
+
return unconfirmedLength;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async handleTxHashes(start, end) {
|
|
189
|
+
return this.#msb.getTxHashes(start, end);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async handleTxDetails(hash) {
|
|
193
|
+
const txDetails = await this.#msb.getTxDetails(hash);
|
|
194
|
+
if (!txDetails) {
|
|
195
|
+
console.log(`No payload found for tx hash: ${hash}`);
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return txDetails;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async handleExtendedTxDetails(hash, confirmed) {
|
|
203
|
+
const txDetails = await this.#msb.getExtendedTxDetails(hash, confirmed);
|
|
204
|
+
if (!txDetails) {
|
|
205
|
+
throw new Error(`No payload found for tx hash: ${hash}`);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return txDetails;
|
|
209
|
+
}
|
|
210
|
+
}
|