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/rpc/rpc_server.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { createServer } from "./create_server.js";
|
|
2
|
+
import { MainSettlementBus } from "../src/index.js";
|
|
2
3
|
|
|
3
4
|
// Called by msb.mjs file
|
|
4
|
-
export function startRpcServer(
|
|
5
|
-
|
|
5
|
+
export async function startRpcServer(config) {
|
|
6
|
+
console.log('Starting RPC server...');
|
|
7
|
+
const msb = new MainSettlementBus(config);
|
|
8
|
+
await msb.ready()
|
|
9
|
+
const server = createServer(msb, config)
|
|
6
10
|
|
|
7
11
|
return server.listen(config.port, config.host, () => {
|
|
8
12
|
console.log(`Running RPC with http at http://${config.host}:${config.port}`);
|
package/rpc/utils/helpers.js
CHANGED
|
@@ -1,99 +1,79 @@
|
|
|
1
1
|
import b4a from "b4a"
|
|
2
2
|
import { operationToPayload } from "../../src/utils/applyOperations.js"
|
|
3
3
|
import { isHexString } from "../../src/utils/helpers.js";
|
|
4
|
-
|
|
5
|
-
export class ValidationError extends Error {
|
|
6
|
-
constructor(message) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = "ValidationError";
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class BroadcastError extends Error {
|
|
13
|
-
constructor(message) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.name = "BroadcastError";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class NotFoundError extends Error {
|
|
20
|
-
constructor(message) {
|
|
21
|
-
super(message);
|
|
22
|
-
this.name = "NotFoundError";
|
|
23
|
-
}
|
|
24
|
-
}
|
|
4
|
+
import { ValidationError } from "../../src/utils/errors.js";
|
|
25
5
|
|
|
26
6
|
export function decodeBase64Payload(base64) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
7
|
+
let decodedPayloadString
|
|
8
|
+
try {
|
|
9
|
+
decodedPayloadString = b4a.from(base64, "base64").toString("utf-8")
|
|
10
|
+
} catch {
|
|
11
|
+
throw new ValidationError("Failed to decode base64 payload.")
|
|
12
|
+
}
|
|
33
13
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(decodedPayloadString)
|
|
16
|
+
} catch {
|
|
17
|
+
throw new ValidationError("Decoded payload is not valid JSON.")
|
|
18
|
+
}
|
|
39
19
|
}
|
|
40
20
|
|
|
41
21
|
export function isBase64(str) {
|
|
42
|
-
|
|
22
|
+
const base64Regex =
|
|
43
23
|
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/
|
|
44
|
-
|
|
24
|
+
return base64Regex.test(str)
|
|
45
25
|
}
|
|
46
26
|
|
|
47
27
|
export function validatePayloadStructure(payload) {
|
|
48
|
-
|
|
49
|
-
|
|
28
|
+
if (
|
|
29
|
+
typeof payload !== "object" ||
|
|
50
30
|
payload === null ||
|
|
51
31
|
typeof payload.type !== "number" ||
|
|
52
32
|
typeof payload.address !== "string" ||
|
|
53
33
|
!["txo", "tro"].some((key) => key in payload && typeof payload[key] === "object")
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
34
|
+
) {
|
|
35
|
+
throw new ValidationError("Invalid payload structure.")
|
|
36
|
+
}
|
|
57
37
|
}
|
|
58
38
|
|
|
59
39
|
export function sanitizeTransferPayload(payload) {
|
|
60
|
-
|
|
40
|
+
const operationKey = operationToPayload(payload.type);
|
|
61
41
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
42
|
+
if (operationKey !== 'tro' && operationKey !== 'txo') {
|
|
43
|
+
throw new ValidationError('Payload is not a transfer/transaction operation.');
|
|
44
|
+
}
|
|
65
45
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
46
|
+
const operation = payload[operationKey];
|
|
47
|
+
if (payload.address && typeof payload.address === "string") {
|
|
48
|
+
payload.address = payload.address.trim()
|
|
49
|
+
}
|
|
70
50
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
51
|
+
if (operation && typeof operation === "object") {
|
|
52
|
+
for (const [key, value] of Object.entries(operation)) {
|
|
53
|
+
if (typeof value === "string") {
|
|
54
|
+
let sanitized = value.trim()
|
|
75
55
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
56
|
+
// normalize hex-like strings
|
|
57
|
+
if (/^[0-9A-F]+$/i.test(sanitized)) {
|
|
58
|
+
sanitized = sanitized.toLowerCase()
|
|
59
|
+
}
|
|
80
60
|
|
|
81
|
-
|
|
82
|
-
|
|
61
|
+
payload[operationKey][key] = sanitized
|
|
62
|
+
}
|
|
63
|
+
}
|
|
83
64
|
}
|
|
84
|
-
}
|
|
85
65
|
|
|
86
|
-
|
|
66
|
+
return payload
|
|
87
67
|
}
|
|
88
68
|
|
|
89
69
|
export function sanitizeBulkPayloadsRequestBody(body) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
70
|
+
const cleanBody = body
|
|
71
|
+
.replace(/^\uFEFF/, '')
|
|
72
|
+
.replace(/\r/g, '')
|
|
73
|
+
.replace(/\0/g, '')
|
|
74
|
+
.trim();
|
|
95
75
|
|
|
96
|
-
|
|
76
|
+
return JSON.parse(cleanBody);
|
|
97
77
|
}
|
|
98
78
|
|
|
99
79
|
export function isValidTxHash(hash) {
|
|
@@ -102,4 +82,4 @@ export function isValidTxHash(hash) {
|
|
|
102
82
|
|
|
103
83
|
export function hasSpacesInUrl(url) {
|
|
104
84
|
return url.includes('%20') || url.includes(' ');
|
|
105
|
-
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const SIGNAL_EXIT_CODES = new Map([
|
|
6
|
+
['SIGHUP', 129],
|
|
7
|
+
['SIGINT', 130],
|
|
8
|
+
['SIGQUIT', 131],
|
|
9
|
+
['SIGTERM', 143]
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const projectDirectory = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
13
|
+
const workerEntrypoint = path.join(projectDirectory, 'msb.mjs');
|
|
14
|
+
|
|
15
|
+
export const parsePearMajor = output => {
|
|
16
|
+
const semver = output.match(/\bSemVer\s*=\s*(\d+)\.\d+\.\d+\b/i);
|
|
17
|
+
if (semver) {
|
|
18
|
+
return Number(semver[1]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const summary = output.match(/\/\s*v(\d+)\.\d+\.\d+\b/i);
|
|
22
|
+
return summary ? Number(summary[1]) : null;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const detectPearMajor = (runCommand = spawnSync) => {
|
|
26
|
+
const result = runCommand('pear', ['-v'], {
|
|
27
|
+
encoding: 'utf8',
|
|
28
|
+
stdio: ['ignore', 'pipe', 'pipe']
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (result.error?.code === 'ENOENT') {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (result.error) {
|
|
36
|
+
throw new Error(`Could not check the installed Pear version: ${result.error.message}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const output = `${result.stdout ?? ''}\n${result.stderr ?? ''}`;
|
|
40
|
+
|
|
41
|
+
if (result.status !== 0) {
|
|
42
|
+
throw new Error('Could not determine the installed Pear major version from `pear -v`.');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return parsePearMajor(output);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const exitCodeFor = (code, signal) => {
|
|
49
|
+
if (Number.isInteger(code)) {
|
|
50
|
+
return code;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return SIGNAL_EXIT_CODES.get(signal) ?? 1;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const runWithPearV2 = (
|
|
57
|
+
args,
|
|
58
|
+
spawnProcess = spawn
|
|
59
|
+
) => new Promise((resolve, reject) => {
|
|
60
|
+
const child = spawnProcess('pear', ['run', '.', ...args], {
|
|
61
|
+
cwd: projectDirectory,
|
|
62
|
+
env: process.env,
|
|
63
|
+
stdio: 'inherit'
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
child.once('error', reject);
|
|
67
|
+
child.once('exit', (code, signal) => resolve(exitCodeFor(code, signal)));
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const pipeWorkerStdio = (worker, hostProcess) => {
|
|
71
|
+
if (worker.stdin && hostProcess.stdin?.pipe) {
|
|
72
|
+
hostProcess.stdin.pipe(worker.stdin);
|
|
73
|
+
}
|
|
74
|
+
if (worker.stdout?.pipe && hostProcess.stdout) {
|
|
75
|
+
worker.stdout.pipe(hostProcess.stdout);
|
|
76
|
+
}
|
|
77
|
+
if (worker.stderr?.pipe && hostProcess.stderr) {
|
|
78
|
+
worker.stderr.pipe(hostProcess.stderr);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const runWithPearV3 = async (
|
|
83
|
+
args,
|
|
84
|
+
{
|
|
85
|
+
loadPearRuntime = () => import('pear-runtime'),
|
|
86
|
+
hostProcess = process
|
|
87
|
+
} = {}
|
|
88
|
+
) => {
|
|
89
|
+
let PearRuntime;
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const pearRuntimeModule = await loadPearRuntime();
|
|
93
|
+
PearRuntime = pearRuntimeModule.default ?? pearRuntimeModule;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
'Pear v3 requires the pear-runtime dependency. Run npm install before starting MSB.',
|
|
97
|
+
{ cause: error }
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const worker = PearRuntime.run(workerEntrypoint, args);
|
|
102
|
+
pipeWorkerStdio(worker, hostProcess);
|
|
103
|
+
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
let requestedSignal = null;
|
|
106
|
+
const signalListeners = [];
|
|
107
|
+
|
|
108
|
+
const cleanup = () => {
|
|
109
|
+
for (const [signal, listener] of signalListeners) {
|
|
110
|
+
hostProcess.removeListener(signal, listener);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (worker.stdin && hostProcess.stdin?.unpipe) {
|
|
114
|
+
hostProcess.stdin.unpipe(worker.stdin);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
for (const signal of SIGNAL_EXIT_CODES.keys()) {
|
|
119
|
+
const listener = () => {
|
|
120
|
+
if (requestedSignal !== null) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
requestedSignal = signal;
|
|
125
|
+
worker.destroy();
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
signalListeners.push([signal, listener]);
|
|
129
|
+
hostProcess.once(signal, listener);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
worker.once('error', error => {
|
|
133
|
+
cleanup();
|
|
134
|
+
reject(error);
|
|
135
|
+
});
|
|
136
|
+
worker.once('exit', (code, signal) => {
|
|
137
|
+
cleanup();
|
|
138
|
+
resolve(exitCodeFor(code, requestedSignal ?? signal));
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export const run = async (
|
|
144
|
+
args = process.argv.slice(2),
|
|
145
|
+
{
|
|
146
|
+
detectVersion = detectPearMajor,
|
|
147
|
+
runPearV2 = runWithPearV2,
|
|
148
|
+
runPearV3 = runWithPearV3
|
|
149
|
+
} = {}
|
|
150
|
+
) => {
|
|
151
|
+
const major = detectVersion();
|
|
152
|
+
|
|
153
|
+
if (major !== null && major < 3) {
|
|
154
|
+
return runPearV2(args);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return runPearV3(args);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const isMainModule = process.argv[1] &&
|
|
161
|
+
path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
162
|
+
|
|
163
|
+
if (isMainModule) {
|
|
164
|
+
try {
|
|
165
|
+
process.exitCode = await run();
|
|
166
|
+
} catch (error) {
|
|
167
|
+
console.error(`MainSettlementBus Pear runner: ${error.message}`);
|
|
168
|
+
process.exitCode = 1;
|
|
169
|
+
}
|
|
170
|
+
}
|
package/src/config/args.js
CHANGED
|
@@ -1,19 +1,69 @@
|
|
|
1
1
|
import { createConfig, ENV } from './env.js';
|
|
2
2
|
|
|
3
|
-
const getArguments = () => {
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
3
|
+
export const getArguments = (runtime = globalThis) => {
|
|
4
|
+
const pearRuntime = runtime.Pear;
|
|
5
|
+
const pearApp = pearRuntime?.app ?? pearRuntime?.config;
|
|
6
|
+
const bareArgs = runtime.Bare?.argv?.slice(2);
|
|
7
|
+
const processArgs = runtime.process?.argv?.slice(2) ?? [];
|
|
8
|
+
return pearApp?.args ?? bareArgs ?? processArgs;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const getOptionValue = (args, flag) => {
|
|
12
|
+
const index = args.indexOf(flag);
|
|
13
|
+
if (index === -1) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const value = args[index + 1];
|
|
18
|
+
if (value === undefined || String(value).startsWith('--')) {
|
|
19
|
+
throw new Error(`MainSettlementBus CLI: ${flag} requires a value.`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const parseNonEmptyStringOption = (args, flag) => {
|
|
26
|
+
const value = getOptionValue(args, flag);
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
32
|
+
throw new Error(`MainSettlementBus CLI: ${flag} must be a non-empty string.`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return value;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const parsePortOption = (args) => {
|
|
39
|
+
const value = getOptionValue(args, '--port');
|
|
40
|
+
if (value === undefined) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!/^\d+$/.test(value)) {
|
|
45
|
+
throw new Error('MainSettlementBus CLI: --port must be an integer in range 1-65535.');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const port = Number(value);
|
|
49
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
50
|
+
throw new Error('MainSettlementBus CLI: --port must be an integer in range 1-65535.');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return port;
|
|
7
54
|
};
|
|
8
55
|
|
|
9
56
|
export const resolveEnvironment = (args = []) => {
|
|
10
|
-
const
|
|
11
|
-
|
|
57
|
+
const network = getOptionValue(args, '--network');
|
|
58
|
+
if (network === undefined) {
|
|
59
|
+
return ENV.MAINNET;
|
|
60
|
+
}
|
|
12
61
|
|
|
13
62
|
if (network === ENV.MAINNET) return ENV.MAINNET;
|
|
14
63
|
if (network === ENV.DEVELOPMENT) return ENV.DEVELOPMENT;
|
|
15
64
|
if (network === ENV.TESTNET1 || network === 'testnet') return ENV.TESTNET1;
|
|
16
|
-
|
|
65
|
+
|
|
66
|
+
throw new Error('MainSettlementBus CLI: --network must be one of: mainnet, development, testnet.');
|
|
17
67
|
};
|
|
18
68
|
|
|
19
69
|
export const isRpcEnabled = () => {
|
|
@@ -25,12 +75,9 @@ export const resolveConfig = () => {
|
|
|
25
75
|
const args = getArguments();
|
|
26
76
|
const runRpc = isRpcEnabled();
|
|
27
77
|
const selectedEnv = resolveEnvironment(args);
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const host = (hostIndex !== -1 && args[hostIndex + 1]) ? args[hostIndex + 1] : undefined;
|
|
32
|
-
const portIndex = args.indexOf('--port');
|
|
33
|
-
const port = (portIndex !== -1 && args[portIndex + 1]) ? parseInt(args[portIndex + 1], 10) : undefined;
|
|
78
|
+
const storesDirectory = parseNonEmptyStringOption(args, '--stores-directory');
|
|
79
|
+
const host = runRpc ? parseNonEmptyStringOption(args, '--host') : undefined;
|
|
80
|
+
const port = runRpc ? parsePortOption(args) : undefined;
|
|
34
81
|
|
|
35
82
|
const rpc = {
|
|
36
83
|
storesDirectory,
|
package/src/config/config.js
CHANGED
|
@@ -12,9 +12,12 @@ export class Config {
|
|
|
12
12
|
this.#validate(options, config)
|
|
13
13
|
this.#options = options
|
|
14
14
|
this.#config = config
|
|
15
|
-
this.#bootstrap =
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
this.#bootstrap = this.#normalizeBootstrap(
|
|
16
|
+
isDefined(options.bootstrap) ? options.bootstrap : config.bootstrap
|
|
17
|
+
)
|
|
18
|
+
this.#channel = this.#normalizeChannel(
|
|
19
|
+
isDefined(options.channel) ? options.channel : config.channel
|
|
20
|
+
)
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
get addressLength() {
|
|
@@ -46,10 +49,6 @@ export class Config {
|
|
|
46
49
|
return this.#config.dhtBootstrap
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
get derivationPath() {
|
|
50
|
-
return this.#config.derivationPath
|
|
51
|
-
}
|
|
52
|
-
|
|
53
52
|
get disableRateLimit() {
|
|
54
53
|
if (this.#isOverriden('disableRateLimit')) return !!this.#options.disableRateLimit
|
|
55
54
|
return !!this.#config.disableRateLimit
|
|
@@ -89,8 +88,12 @@ export class Config {
|
|
|
89
88
|
return _.endsWith(this.storesDirectory, '/admin')
|
|
90
89
|
}
|
|
91
90
|
|
|
91
|
+
get keyPairDirectoryPath() {
|
|
92
|
+
return `${this.storesFullPath}/db`
|
|
93
|
+
}
|
|
94
|
+
|
|
92
95
|
get keyPairPath() {
|
|
93
|
-
return `${this.
|
|
96
|
+
return `${this.keyPairDirectoryPath}/keypair.json`
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
get maxRetries() {
|
|
@@ -133,11 +136,6 @@ export class Config {
|
|
|
133
136
|
return this.#config.processIntervalMs
|
|
134
137
|
}
|
|
135
138
|
|
|
136
|
-
get maxPartialTxPayloadByteSize() {
|
|
137
|
-
if (this.#isOverriden('maxPartialTxPayloadByteSize')) return this.#options.maxPartialTxPayloadByteSize
|
|
138
|
-
return this.#config.maxPartialTxPayloadByteSize
|
|
139
|
-
}
|
|
140
|
-
|
|
141
139
|
get transactionPoolSize() {
|
|
142
140
|
if (this.#isOverriden('transactionPoolSize')) return this.#options.transactionPoolSize
|
|
143
141
|
return this.#config.transactionPoolSize
|
|
@@ -198,17 +196,168 @@ export class Config {
|
|
|
198
196
|
if (this.#isOverriden('rateLimitMaxTransactionsPerSecond')) return this.#options.rateLimitMaxTransactionsPerSecond
|
|
199
197
|
return this.#config.rateLimitMaxTransactionsPerSecond
|
|
200
198
|
}
|
|
199
|
+
|
|
200
|
+
get pendingRequestTimeout() {
|
|
201
|
+
return this.#config.pendingRequestTimeout
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
get txCommitTimeout() {
|
|
205
|
+
return this.#config.txCommitTimeout
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
get txPoolSize() {
|
|
209
|
+
return this.#config.txPoolSize
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
get validatorHealthCheckInterval() {
|
|
213
|
+
if (this.#isOverriden('validatorHealthCheckInterval')) return this.#options.validatorHealthCheckInterval
|
|
214
|
+
return this.#config.validatorHealthCheckInterval
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
get maxPendingRequestsInPendingRequestsService() {
|
|
218
|
+
return this.#config.maxPendingRequestsInPendingRequestsService
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
get debug() {
|
|
222
|
+
return this.#config.debug
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
get derivationPath() {
|
|
226
|
+
return this.#config.derivationPath
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
get pollInterval() {
|
|
230
|
+
if (this.#isOverriden('pollInterval')) return this.#options.pollInterval
|
|
231
|
+
return this.#config.pollInterval
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
get adminCacheTTL() {
|
|
235
|
+
if (this.#isOverriden('adminCacheTTL')) return this.#options.adminCacheTTL
|
|
236
|
+
return this.#config.adminCacheTTL
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
get bootstrapTimeout() {
|
|
240
|
+
if (this.#isOverriden('bootstrapTimeout')) return this.#options.bootstrapTimeout
|
|
241
|
+
return this.#config.bootstrapTimeout
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
get writersShortCacheTTL() {
|
|
245
|
+
if (this.#isOverriden('writersShortCacheTTL')) return this.#options.writersShortCacheTTL
|
|
246
|
+
return this.#config.writersShortCacheTTL
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
get writersLongCacheTTL() {
|
|
250
|
+
if (this.#isOverriden('writersLongCacheTTL')) return this.#options.writersLongCacheTTL
|
|
251
|
+
return this.#config.writersLongCacheTTL
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
get validatorConnectionAttemptDelay() {
|
|
255
|
+
if (this.#isOverriden('validatorConnectionAttemptDelay')) return this.#options.validatorConnectionAttemptDelay
|
|
256
|
+
return this.#config.validatorConnectionAttemptDelay
|
|
257
|
+
}
|
|
201
258
|
|
|
202
|
-
// Most of these properties are boolean
|
|
203
259
|
#isOverriden(prop) {
|
|
204
260
|
return this.#options.hasOwnProperty(prop) && isDefined(this.#options[prop])
|
|
205
261
|
}
|
|
206
262
|
|
|
263
|
+
#normalizeBootstrap(bootstrap) {
|
|
264
|
+
if (b4a.isBuffer(bootstrap)) {
|
|
265
|
+
return b4a.from(bootstrap)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return b4a.from(bootstrap, 'hex')
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
#normalizeChannel(channel) {
|
|
272
|
+
return b4a.alloc(32).fill(channel)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
#validateStringOverride(field, value) {
|
|
276
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
277
|
+
throw new Error(`MainSettlementBus Config: ${field} must be a non-empty string.`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
#validatePortOverride(port) {
|
|
282
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
283
|
+
throw new Error('MainSettlementBus Config: port must be an integer in range 1-65535.');
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
#validateBootstrapOverride(bootstrap) {
|
|
288
|
+
if (b4a.isBuffer(bootstrap)) {
|
|
289
|
+
if (bootstrap.length !== 32) {
|
|
290
|
+
throw new Error('MainSettlementBus Config: bootstrap must be a 32-byte hex string or Buffer.');
|
|
291
|
+
}
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (typeof bootstrap !== 'string' || !/^[0-9a-fA-F]{64}$/.test(bootstrap)) {
|
|
296
|
+
throw new Error('MainSettlementBus Config: bootstrap must be a 32-byte hex string or Buffer.');
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
#validateChannelOverride(channel) {
|
|
301
|
+
if (!(typeof channel === 'string' || b4a.isBuffer(channel))) {
|
|
302
|
+
throw new Error('MainSettlementBus Config: channel must be a string or Buffer.');
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const length = b4a.isBuffer(channel) ? channel.length : b4a.from(channel).length
|
|
306
|
+
|
|
307
|
+
if (length === 0 || length > 32) {
|
|
308
|
+
throw new Error('MainSettlementBus Config: channel must be 1-32 bytes long.');
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
#validateDhtBootstrapOverride(dhtBootstrap) {
|
|
313
|
+
if (!Array.isArray(dhtBootstrap) || dhtBootstrap.length === 0) {
|
|
314
|
+
throw new Error('MainSettlementBus Config: dhtBootstrap must be a non-empty array of strings.');
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
for (const entry of dhtBootstrap) {
|
|
318
|
+
if (typeof entry !== 'string' || entry.trim().length === 0) {
|
|
319
|
+
throw new Error('MainSettlementBus Config: dhtBootstrap entries must be non-empty strings.');
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
207
324
|
#validate(options, config) {
|
|
325
|
+
if (options === null || typeof options !== 'object') {
|
|
326
|
+
throw new Error('MainSettlementBus Config: options must be an object.');
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (config === null || typeof config !== 'object') {
|
|
330
|
+
throw new Error('MainSettlementBus Config: config must be an object.');
|
|
331
|
+
}
|
|
332
|
+
|
|
208
333
|
if (!options.channel && !config.channel) {
|
|
209
334
|
throw new Error(
|
|
210
335
|
"MainSettlementBus: Channel is required. Application cannot start without channel."
|
|
211
336
|
);
|
|
212
337
|
}
|
|
338
|
+
|
|
339
|
+
if (isDefined(options.bootstrap)) {
|
|
340
|
+
this.#validateBootstrapOverride(options.bootstrap);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (isDefined(options.channel)) {
|
|
344
|
+
this.#validateChannelOverride(options.channel);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (isDefined(options.storesDirectory)) {
|
|
348
|
+
this.#validateStringOverride('storesDirectory', options.storesDirectory);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (isDefined(options.host)) {
|
|
352
|
+
this.#validateStringOverride('host', options.host);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (isDefined(options.port)) {
|
|
356
|
+
this.#validatePortOverride(options.port);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (isDefined(options.dhtBootstrap)) {
|
|
360
|
+
this.#validateDhtBootstrapOverride(options.dhtBootstrap);
|
|
361
|
+
}
|
|
213
362
|
}
|
|
214
363
|
}
|