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/src/index.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
/** @typedef {import('pear-interface')} */ /* global Pear */
|
|
2
1
|
import ReadyResource from "ready-resource";
|
|
3
2
|
import Corestore from "corestore";
|
|
4
|
-
import
|
|
3
|
+
import tracCryptoApi from "trac-crypto-api";
|
|
5
4
|
import b4a from "b4a";
|
|
6
|
-
import readline from "readline";
|
|
7
|
-
import tty from "tty";
|
|
8
5
|
import { sleep, isHexString } from "./utils/helpers.js";
|
|
9
|
-
import { verifyDag, printHelp, printWalletInfo, printBalance } from "./utils/cli.js";
|
|
10
6
|
import { applyStateMessageFactory } from "./messages/state/applyStateMessageFactory.js";
|
|
11
7
|
import { isAddressValid } from "./core/state/utils/address.js";
|
|
12
8
|
import Network from "./core/network/Network.js";
|
|
@@ -18,64 +14,39 @@ import {
|
|
|
18
14
|
BOOTSTRAP_HEXSTRING_LENGTH,
|
|
19
15
|
CustomEventType,
|
|
20
16
|
BALANCE_MIGRATION_SLEEP_INTERVAL,
|
|
21
|
-
WHITELIST_MIGRATION_DIR
|
|
17
|
+
WHITELIST_MIGRATION_DIR,
|
|
18
|
+
OperationType
|
|
22
19
|
} from "./utils/constants.js";
|
|
23
|
-
import { randomBytes } from "hypercore-crypto";
|
|
24
20
|
import { decimalStringToBigInt, bigIntTo16ByteBuffer, bufferToBigInt, bigIntToDecimalString } from "./utils/amountSerialization.js"
|
|
21
|
+
import {
|
|
22
|
+
normalizeDecodedPayloadForJson,
|
|
23
|
+
normalizeTransactionOperation,
|
|
24
|
+
normalizeTransferOperation
|
|
25
|
+
} from "./utils/normalizers.js";
|
|
25
26
|
import fileUtils from './utils/fileUtils.js';
|
|
26
27
|
import migrationUtils from './utils/migrationUtils.js';
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
getConfirmedLengthCommand,
|
|
32
|
-
getUnconfirmedLengthCommand,
|
|
33
|
-
getTxPayloadsBulkCommand,
|
|
34
|
-
getTxHashesCommand,
|
|
35
|
-
getTxDetailsCommand,
|
|
36
|
-
getExtendedTxDetailsCommand,
|
|
37
|
-
nodeStatusCommand,
|
|
38
|
-
coreInfoCommand,
|
|
39
|
-
getValidatorAddressCommand,
|
|
40
|
-
getDeploymentCommand,
|
|
41
|
-
getTxInfoCommand,
|
|
42
|
-
getLicenseNumberCommand,
|
|
43
|
-
getLicenseAddressCommand,
|
|
44
|
-
getLicenseCountCommand
|
|
45
|
-
} from "./utils/cliCommands.js";
|
|
46
|
-
import {safeEncodeApplyOperation} from "./utils/protobuf/operationHelpers.js";
|
|
28
|
+
import {safeDecodeApplyOperation, safeEncodeApplyOperation} from "./utils/protobuf/operationHelpers.js";
|
|
29
|
+
import PartialTransactionValidator from "./core/network/protocols/shared/validators/PartialTransactionValidator.js";
|
|
30
|
+
import PartialTransferValidator from "./core/network/protocols/shared/validators/PartialTransferValidator.js";
|
|
31
|
+
import { BroadcastError, ValidationError } from "./utils/errors.js";
|
|
47
32
|
|
|
48
33
|
export class MainSettlementBus extends ReadyResource {
|
|
49
34
|
#store;
|
|
50
35
|
#wallet;
|
|
51
36
|
#network;
|
|
52
|
-
#readline_instance;
|
|
53
37
|
#state;
|
|
54
38
|
#isClosing = false;
|
|
55
39
|
#config
|
|
56
40
|
|
|
57
41
|
/**
|
|
58
|
-
* @param {Config} config
|
|
42
|
+
* @param {import("./config/config.js").Config} config
|
|
43
|
+
* @param {import("trac-wallet").Wallet | undefined} wallet
|
|
59
44
|
**/
|
|
60
|
-
constructor(config) {
|
|
45
|
+
constructor(config, wallet = undefined) {
|
|
61
46
|
super();
|
|
62
47
|
this.#config = config
|
|
48
|
+
this.#wallet = wallet;
|
|
63
49
|
this.#store = new Corestore(this.#config.storesFullPath);
|
|
64
|
-
this.#wallet = new PeerWallet({
|
|
65
|
-
networkPrefix: this.#config.addressPrefix,
|
|
66
|
-
derivationPath: this.#config.derivationPath
|
|
67
|
-
});
|
|
68
|
-
this.#readline_instance = null;
|
|
69
|
-
|
|
70
|
-
if (this.#config.enableInteractiveMode) {
|
|
71
|
-
try {
|
|
72
|
-
this.#readline_instance = readline.createInterface({
|
|
73
|
-
input: new tty.ReadStream(0),
|
|
74
|
-
output: new tty.WriteStream(1),
|
|
75
|
-
});
|
|
76
|
-
} catch (_ignored) {}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
50
|
this.check = new Check(this.#config);
|
|
80
51
|
}
|
|
81
52
|
|
|
@@ -99,23 +70,15 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
99
70
|
}
|
|
100
71
|
|
|
101
72
|
async _open() {
|
|
102
|
-
await fileUtils.ensureCoresStoreDir(this.#config);
|
|
103
|
-
|
|
104
|
-
if (this.#config.enableWallet) {
|
|
105
|
-
await this.#wallet.initKeyPair(
|
|
106
|
-
this.#config.keyPairPath,
|
|
107
|
-
this.#readline_instance
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
73
|
this.#state = new State(this.#store, this.#wallet, this.#config);
|
|
111
|
-
this.#network = new Network(this.#state, this.#config, this.#wallet
|
|
74
|
+
this.#network = new Network(this.#state, this.#config, this.#wallet?.address ?? null);
|
|
112
75
|
|
|
113
76
|
await this.#state.ready();
|
|
114
77
|
await this.#network.ready();
|
|
115
78
|
await this.#stateEventsListener();
|
|
116
79
|
|
|
117
|
-
if (this.#
|
|
118
|
-
printWalletInfo(
|
|
80
|
+
if (this.#wallet) {
|
|
81
|
+
this.#printWalletInfo();
|
|
119
82
|
}
|
|
120
83
|
|
|
121
84
|
await this.#network.replicate(
|
|
@@ -134,7 +97,9 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
134
97
|
console.log("MSB Unsigned Length:", this.#state.getUnsignedLength());
|
|
135
98
|
console.log("MSB Signed Length:", this.#state.getSignedLength());
|
|
136
99
|
|
|
137
|
-
|
|
100
|
+
if (this.#wallet) {
|
|
101
|
+
await this.#printBalance();
|
|
102
|
+
}
|
|
138
103
|
}
|
|
139
104
|
|
|
140
105
|
async _close() {
|
|
@@ -149,26 +114,6 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
149
114
|
|
|
150
115
|
await sleep(100);
|
|
151
116
|
|
|
152
|
-
if (this.#readline_instance) {
|
|
153
|
-
const inputClosed = new Promise((resolve) =>
|
|
154
|
-
this.#readline_instance.input.once("close", resolve)
|
|
155
|
-
);
|
|
156
|
-
const outputClosed = new Promise((resolve) =>
|
|
157
|
-
this.#readline_instance.output.once("close", resolve)
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
this.#readline_instance.close();
|
|
161
|
-
this.#readline_instance.input.destroy();
|
|
162
|
-
this.#readline_instance.output.destroy();
|
|
163
|
-
|
|
164
|
-
// Do not remove this. Without it, readline may close too quickly and still hang.
|
|
165
|
-
await Promise.all([inputClosed, outputClosed]).catch((e) =>
|
|
166
|
-
console.log("Error during closing readline stream:", e)
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
await sleep(100);
|
|
171
|
-
|
|
172
117
|
if (this.#store !== null) {
|
|
173
118
|
await this.#store.close();
|
|
174
119
|
}
|
|
@@ -176,42 +121,98 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
176
121
|
await sleep(100);
|
|
177
122
|
}
|
|
178
123
|
|
|
124
|
+
async destroy() {
|
|
125
|
+
return await this.close();
|
|
126
|
+
}
|
|
127
|
+
|
|
179
128
|
async broadcastPartialTransaction(partialTransactionPayload) {
|
|
180
129
|
return await this.#network.validatorMessageOrchestrator.send(partialTransactionPayload);
|
|
181
130
|
}
|
|
182
131
|
|
|
132
|
+
async validateTransfer(payload) {
|
|
133
|
+
const partialTransferValidator = new PartialTransferValidator(this.#state, null, this.#config);
|
|
134
|
+
return await partialTransferValidator.validate(payload);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Used by peer simulation
|
|
138
|
+
async validateTransaction(payload) {
|
|
139
|
+
const partialTransactionValidator = new PartialTransactionValidator(this.#state, null, this.#config);
|
|
140
|
+
return await partialTransactionValidator.validate(payload);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async broadcastTransaction(payload) {
|
|
144
|
+
if (!payload) {
|
|
145
|
+
throw new ValidationError("Transaction payload is required for broadcasting.");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let normalizedPayload;
|
|
149
|
+
let hash;
|
|
150
|
+
|
|
151
|
+
if (payload.type === OperationType.TRANSFER) {
|
|
152
|
+
normalizedPayload = normalizeTransferOperation(payload, this.#config);
|
|
153
|
+
await this.validateTransfer(normalizedPayload);
|
|
154
|
+
hash = b4a.toString(normalizedPayload.tro.tx, "hex");
|
|
155
|
+
} else if (payload.type === OperationType.TX) {
|
|
156
|
+
normalizedPayload = normalizeTransactionOperation(payload, this.#config);
|
|
157
|
+
try {
|
|
158
|
+
await this.validateTransaction(normalizedPayload);
|
|
159
|
+
} catch {
|
|
160
|
+
// We swap exceptions to keep compatibility
|
|
161
|
+
throw new ValidationError("Invalid transaction payload.");
|
|
162
|
+
}
|
|
163
|
+
hash = b4a.toString(normalizedPayload.txo.tx, "hex");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const success = await this.broadcastPartialTransaction(payload);
|
|
167
|
+
if (!success) {
|
|
168
|
+
throw new BroadcastError("Failed to broadcast transaction after multiple attempts.");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const isConfirmed = await this.#state.waitForUnsigned(
|
|
172
|
+
hash,
|
|
173
|
+
this.#config.messageValidatorResponseTimeout,
|
|
174
|
+
100
|
|
175
|
+
);
|
|
176
|
+
if (!isConfirmed) {
|
|
177
|
+
throw new BroadcastError("Failed to broadcast transaction after multiple attempts.");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
signedLength: this.#state.getSignedLength(),
|
|
182
|
+
unsignedLength: this.#state.getUnsignedLength(),
|
|
183
|
+
tx: hash
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
183
187
|
async #setUpRoleAutomatically() {
|
|
184
188
|
if (!this.#state.isWritable() && this.#config.enableRoleRequester) {
|
|
185
|
-
console.log("Requesting writer role... This may take a moment.");
|
|
186
|
-
await this.#requestWriterRole(false);
|
|
187
189
|
setTimeout(async () => {
|
|
188
|
-
await this
|
|
190
|
+
await this.requestWriterRole(true);
|
|
189
191
|
}, 5_000);
|
|
190
192
|
await sleep(5_000);
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
|
|
196
|
+
isAdmin(adminEntry) {
|
|
195
197
|
if (!adminEntry || !this.#config.enableWallet) return false;
|
|
196
198
|
return this.#wallet.address === adminEntry.address && b4a.equals(adminEntry.wk, this.#state.writingKey)
|
|
197
199
|
}
|
|
198
200
|
|
|
199
201
|
async #isAllowedToRequestRole(adminEntry, nodeEntry) {
|
|
200
|
-
return nodeEntry?.isWhitelisted && !this
|
|
202
|
+
return nodeEntry?.isWhitelisted && !this.isAdmin(adminEntry);
|
|
201
203
|
}
|
|
202
204
|
|
|
203
205
|
async #stateEventsListener() {
|
|
204
206
|
this.#state.on(CustomEventType.IS_INDEXER, (publicKey) => {
|
|
205
|
-
if (this.#
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
})
|
|
207
|
+
if (this.#isClosing) return;
|
|
208
|
+
this.#network.disconnectValidatorPeer(publicKey, 'peer promoted to indexer');
|
|
209
|
+
});
|
|
209
210
|
|
|
210
211
|
this.#state.on(CustomEventType.UNWRITABLE, (publicKey) => {
|
|
211
|
-
if (this.#
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
if (this.#isClosing) return;
|
|
213
|
+
this.#network.disconnectValidatorPeer(publicKey, 'peer became unwritable');
|
|
214
|
+
});
|
|
215
|
+
|
|
215
216
|
this.#state.base.on(EventType.IS_INDEXER, () => {
|
|
216
217
|
console.log("Current node is an indexer");
|
|
217
218
|
});
|
|
@@ -232,7 +233,195 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
232
233
|
});
|
|
233
234
|
}
|
|
234
235
|
|
|
235
|
-
async
|
|
236
|
+
async getConfirmedTxInfo(txHash) {
|
|
237
|
+
const payload = await this.#state.getSigned(txHash);
|
|
238
|
+
if (!payload) return null
|
|
239
|
+
|
|
240
|
+
const decoded = safeDecodeApplyOperation(payload);
|
|
241
|
+
if (!decoded) {
|
|
242
|
+
throw new Error(`Failed to decode payload for transaction hash: ${txHash}`);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return { payload, decoded }
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async getUnconfirmedTxInfo(txHash) {
|
|
249
|
+
const payload = await this.#state.get(txHash);
|
|
250
|
+
if (!payload) return null
|
|
251
|
+
|
|
252
|
+
const decoded = safeDecodeApplyOperation(payload);
|
|
253
|
+
if (!decoded) {
|
|
254
|
+
throw new Error(`Failed to decode payload for transaction hash: ${txHash}`);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return { payload, decoded }
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
handleGetFee() {
|
|
261
|
+
const fee = this.#state.getFee();
|
|
262
|
+
return bufferToBigInt(fee);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async getBalance(address, confirmed = true) {
|
|
266
|
+
const nodeEntry = confirmed
|
|
267
|
+
? await this.#state.getNodeEntry(address)
|
|
268
|
+
: await this.#state.getNodeEntryUnsigned(address);
|
|
269
|
+
|
|
270
|
+
if (!nodeEntry) {
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
address,
|
|
276
|
+
balance: bufferToBigInt(nodeEntry.balance).toString(),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async getTxv() {
|
|
281
|
+
const txv = await this.#state.getIndexerSequenceState();
|
|
282
|
+
return txv.toString("hex");
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
getConfirmedLength() {
|
|
286
|
+
return this.#state.getSignedLength();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
getUnconfirmedLength() {
|
|
290
|
+
return this.#state.getUnsignedLength();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async verifyDag() {
|
|
294
|
+
try {
|
|
295
|
+
let dagView = await this.#state.base.view.core.treeHash();
|
|
296
|
+
let lengthdagView = this.#state.base.view.core.length;
|
|
297
|
+
let dagSystem = await this.#state.base.system.core.treeHash();
|
|
298
|
+
let lengthdagSystem = this.#state.base.system.core.length;
|
|
299
|
+
const wl = await this.#state.getWriterLength();
|
|
300
|
+
|
|
301
|
+
console.log("---------- node & network stats ----------");
|
|
302
|
+
console.log("wallet.publicKey:", this.#wallet?.publicKey?.toString("hex") ?? "unset");
|
|
303
|
+
console.log("wallet.address:", this.#wallet?.address ?? "unset");
|
|
304
|
+
console.log("msb.writerKey:", this.#state?.writingKey ? this.#state.writingKey.toString("hex") : "unset");
|
|
305
|
+
console.log("swarm.connections.size:", this.#network?.swarm?.connections?.size || 0);
|
|
306
|
+
console.log("base.view.core.signedLength:", this.#state.base.view.core.signedLength ?? "unset");
|
|
307
|
+
console.log("base.view.core.length:", this.#state.base.view.core.length ?? "unset");
|
|
308
|
+
console.log("base.signedLength", this.#state.base.signedLength ?? "unset");
|
|
309
|
+
console.log("base.indexedLength", this.#state.base.indexedLength ?? "unset");
|
|
310
|
+
console.log("base.linearizer.indexers.length", this.#state.base.linearizer?.indexers?.length ?? "unset");
|
|
311
|
+
console.log(`base.key: ${this.#state.base.key ? this.#state.base.key.toString("hex") : "unset"}`);
|
|
312
|
+
console.log("discoveryKey:", this.#state.base.discoveryKey ? b4a.toString(this.#state.base.discoveryKey, "hex") : "unset");
|
|
313
|
+
console.log(`VIEW Dag: ${dagView ? dagView.toString("hex") : "unset"} (length: ${lengthdagView || 0})`);
|
|
314
|
+
console.log(`SYSTEM Dag: ${dagSystem ? dagSystem.toString("hex") : "unset"} (length: ${lengthdagSystem || 0})`);
|
|
315
|
+
console.log("Total Registered Writers:", wl !== null ? wl : 0);
|
|
316
|
+
console.log("---------- flags ----------");
|
|
317
|
+
console.log(`isIndexer: ${this.#state?.isIndexer?.() ?? "unset"}`);
|
|
318
|
+
console.log(`isWriter: ${this.#state?.isWritable?.() ?? "unset"}`);
|
|
319
|
+
} catch (error) {
|
|
320
|
+
console.error("Error during DAG monitoring:", error.message);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
printHelp() {
|
|
325
|
+
if (this.#config.isAdminMode) {
|
|
326
|
+
console.log("🚨 WARNING: IF YOU ARE NOT AN ADMIN, DO NOT USE THE COMMANDS BELOW! YOU RISK LOSING YOUR FUNDS! 🚨");
|
|
327
|
+
console.log("\nAdmin commands:");
|
|
328
|
+
console.log("- /add_admin: Register admin entry with bootstrap key (initial setup), or use --recovery flag to recover admin role");
|
|
329
|
+
console.log("- /balance_migration: Perform balance migration with the given initial balances CSV file");
|
|
330
|
+
console.log("- /add_whitelist: Add all specified whitelist addresses. If initialization is enabled, no fee is required.");
|
|
331
|
+
console.log("- /disable_initialization: Disable further balance initializations and whitelisting");
|
|
332
|
+
console.log("- /add_indexer <address>: Change a role of the selected writer node to indexer role. Charges a fee.");
|
|
333
|
+
console.log("- /remove_indexer <address>: Change a role of the selected indexer node to default role. Charges a fee.");
|
|
334
|
+
console.log("- /ban_writer <address>: Demote a whitelisted writer to default role and remove it from the whitelist. Charges a fee.");
|
|
335
|
+
}
|
|
336
|
+
console.log("Available commands:");
|
|
337
|
+
console.log("- /add_writer: Add yourself as a validator to this MSB once whitelisted. Requires a fee + 10x the fee as a stake in $TNK.");
|
|
338
|
+
console.log("- /remove_writer: Remove yourself from this MSB. Requires a fee, and the stake will be refunded.");
|
|
339
|
+
console.log("- /node_status <address>: Get network information about a node with the given address.");
|
|
340
|
+
console.log("- /stats: Check system stats such as writing key, DAG, etc.");
|
|
341
|
+
console.log("- /deployment <subnetwork_bootstrap> <channel>: Deploy a subnetwork with the given bootstrap. If channel is not provided, a random one will be generated. Requires a fee.");
|
|
342
|
+
console.log("- /get_deployment <subnetwork_bootstrap>: Get information about a subnetwork deployment with the given bootstrap.");
|
|
343
|
+
console.log("- /transfer <to_address> <amount>: Transfer the specified amount to the given address. Requires a fee.");
|
|
344
|
+
console.log("- /get_tx_info <tx_hash>: Get information about a transaction with the given hash.");
|
|
345
|
+
console.log("- /get_validator_addr <writing_key>: Get the validator address mapped to the given writing key.");
|
|
346
|
+
console.log("- /get_balance <address> <confirmed>: Get the balance of the node with specified address (confirmed = true is default)");
|
|
347
|
+
console.log("- /exit: Exit the program.");
|
|
348
|
+
console.log("- /help: Display this help.");
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
#printWalletInfo() {
|
|
352
|
+
console.log("");
|
|
353
|
+
console.log("#####################################################################################");
|
|
354
|
+
console.log("# MSB Address: ", this.#wallet.address, " #");
|
|
355
|
+
console.log("# MSB Writer: ", this.#state.writingKey.toString("hex"), "#");
|
|
356
|
+
console.log("#####################################################################################");
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
async #printBalance() {
|
|
360
|
+
const nodeEntry = await this.#state.getNodeEntry(this.#wallet.address);
|
|
361
|
+
const balance = nodeEntry ? bigIntToDecimalString(bufferToBigInt(nodeEntry.balance)) : "0";
|
|
362
|
+
console.log(`Balance: ${balance}`);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
async getTxHashes(start, end) {
|
|
366
|
+
const hashes = await this.#state.confirmedTransactionsBetween(start, end);
|
|
367
|
+
return { hashes };
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
async getTxDetails(hash) {
|
|
371
|
+
const rawPayload = await this.getConfirmedTxInfo(hash);
|
|
372
|
+
if (!rawPayload) {
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return normalizeDecodedPayloadForJson(rawPayload.decoded, this.#config);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async fetchBulkTxPayloads(hashes) {
|
|
380
|
+
const response = { results: [], missing: [] };
|
|
381
|
+
const results = await Promise.all(hashes.map((hash) => this.getConfirmedTxInfo(hash)));
|
|
382
|
+
|
|
383
|
+
results.forEach((result, index) => {
|
|
384
|
+
const hash = hashes[index];
|
|
385
|
+
if (!result) {
|
|
386
|
+
response.missing.push(hash);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const decodedResult = normalizeDecodedPayloadForJson(result.decoded, this.#config);
|
|
391
|
+
response.results.push({ hash, payload: decodedResult });
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
return response;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
async getExtendedTxDetails(hash, confirmed) {
|
|
398
|
+
const rawPayload = confirmed
|
|
399
|
+
? await this.getConfirmedTxInfo(hash)
|
|
400
|
+
: await this.getUnconfirmedTxInfo(hash);
|
|
401
|
+
|
|
402
|
+
if (!rawPayload) {
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const txDetails = normalizeDecodedPayloadForJson(rawPayload.decoded, this.#config);
|
|
407
|
+
const confirmedLength = await this.#state.getTransactionConfirmedLength(hash);
|
|
408
|
+
|
|
409
|
+
if (confirmedLength === null) {
|
|
410
|
+
return {
|
|
411
|
+
txDetails,
|
|
412
|
+
confirmed_length: 0,
|
|
413
|
+
fee: "0",
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return {
|
|
418
|
+
txDetails,
|
|
419
|
+
confirmed_length: confirmedLength,
|
|
420
|
+
fee: this.handleGetFee().toString(),
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
async handleAdminCreation() {
|
|
236
425
|
if (!this.#config.enableWallet) {
|
|
237
426
|
throw new Error("Can not initialize an admin - wallet is not enabled.");
|
|
238
427
|
}
|
|
@@ -258,7 +447,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
258
447
|
);
|
|
259
448
|
}
|
|
260
449
|
|
|
261
|
-
const txValidity = await
|
|
450
|
+
const txValidity = await tracCryptoApi.hash.blake3(this.#config.bootstrap);
|
|
262
451
|
const addAdminMessage = await applyStateMessageFactory(this.#wallet, this.#config)
|
|
263
452
|
.buildCompleteAddAdminMessage(
|
|
264
453
|
this.#wallet.address,
|
|
@@ -270,7 +459,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
270
459
|
await this.#state.append(encodedPayload);
|
|
271
460
|
}
|
|
272
461
|
|
|
273
|
-
async
|
|
462
|
+
async handleAdminRecovery() {
|
|
274
463
|
if (!this.#config.enableWallet) {
|
|
275
464
|
throw new Error("Can not initialize an admin - wallet is not enabled.");
|
|
276
465
|
}
|
|
@@ -306,20 +495,20 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
306
495
|
const success = await this.broadcastPartialTransaction(adminRecoveryMessage);
|
|
307
496
|
|
|
308
497
|
if (!success) {
|
|
309
|
-
throw new Error("Failed to broadcast transaction
|
|
498
|
+
throw new Error("Failed to broadcast transaction. Try again later.");
|
|
310
499
|
}
|
|
311
500
|
|
|
312
501
|
console.info(`Transaction hash: ${adminRecoveryMessage.rao.tx}`);
|
|
313
502
|
}
|
|
314
503
|
|
|
315
|
-
async
|
|
504
|
+
async handleWhitelistOperations() {
|
|
316
505
|
if (!this.#config.enableWallet) {
|
|
317
506
|
throw new Error("Cannot perform whitelisting - wallet is not enabled.");
|
|
318
507
|
}
|
|
319
508
|
|
|
320
509
|
const adminEntry = await this.#state.getAdminEntry();
|
|
321
510
|
|
|
322
|
-
if (!this
|
|
511
|
+
if (!this.isAdmin(adminEntry)) {
|
|
323
512
|
throw new Error('Cannot perform whitelisting - you are not the admin!.');
|
|
324
513
|
}
|
|
325
514
|
|
|
@@ -374,7 +563,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
374
563
|
}
|
|
375
564
|
}
|
|
376
565
|
|
|
377
|
-
async
|
|
566
|
+
async requestWriterRole(toAdd) {
|
|
378
567
|
if (!this.#config.enableWallet) {
|
|
379
568
|
throw new Error("Cannot request writer role - wallet is not enabled");
|
|
380
569
|
}
|
|
@@ -427,7 +616,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
427
616
|
const success = await this.broadcastPartialTransaction(assembledMessage);
|
|
428
617
|
|
|
429
618
|
if (!success) {
|
|
430
|
-
throw new Error("Failed to broadcast transaction
|
|
619
|
+
throw new Error("Failed to broadcast transaction. Try again later.");
|
|
431
620
|
}
|
|
432
621
|
|
|
433
622
|
console.info(`Transaction hash: ${assembledMessage.rao.tx}`);
|
|
@@ -461,13 +650,13 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
461
650
|
const success = await this.broadcastPartialTransaction(assembledMessage);
|
|
462
651
|
|
|
463
652
|
if (!success) {
|
|
464
|
-
throw new Error("Failed to broadcast transaction
|
|
653
|
+
throw new Error("Failed to broadcast transaction. Try again later.");
|
|
465
654
|
}
|
|
466
655
|
|
|
467
656
|
console.info(`Transaction hash: ${assembledMessage.rao.tx}`);
|
|
468
657
|
}
|
|
469
658
|
|
|
470
|
-
async
|
|
659
|
+
async updateWriterToIndexerRole(addressToUpdate, toAdd) {
|
|
471
660
|
if (!this.#config.enableWallet) {
|
|
472
661
|
throw new Error(
|
|
473
662
|
`Can not request indexer role for: ${addressToUpdate} - wallet is not enabled.`
|
|
@@ -488,7 +677,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
488
677
|
);
|
|
489
678
|
}
|
|
490
679
|
|
|
491
|
-
if (!this
|
|
680
|
+
if (!this.isAdmin(adminEntry) && !this.#state.isWritable()) {
|
|
492
681
|
throw new Error(
|
|
493
682
|
`Can not request indexer role for: ${addressToUpdate} - You are not an admin or writer.`
|
|
494
683
|
);
|
|
@@ -557,7 +746,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
557
746
|
}
|
|
558
747
|
}
|
|
559
748
|
|
|
560
|
-
async
|
|
749
|
+
async banValidator(addresstToBan) {
|
|
561
750
|
if (!this.#config.enableWallet) {
|
|
562
751
|
throw new Error(
|
|
563
752
|
`Can not ban writer with address: ${addresstToBan} - wallet is not enabled.`
|
|
@@ -577,7 +766,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
577
766
|
);
|
|
578
767
|
}
|
|
579
768
|
|
|
580
|
-
if (!this
|
|
769
|
+
if (!this.isAdmin(adminEntry)) {
|
|
581
770
|
throw new Error(
|
|
582
771
|
`Can not ban writer with address: ${addresstToBan} - You are not an admin.`
|
|
583
772
|
);
|
|
@@ -602,7 +791,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
602
791
|
await this.#state.append(encodedPayload);
|
|
603
792
|
}
|
|
604
793
|
|
|
605
|
-
async
|
|
794
|
+
async deployBootstrap(externalBootstrap, channel) {
|
|
606
795
|
if (!this.#config.enableWallet) {
|
|
607
796
|
throw new Error(
|
|
608
797
|
"Can not perform bootstrap deployment - wallet is not enabled."
|
|
@@ -685,7 +874,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
685
874
|
const success = await this.broadcastPartialTransaction(payload);
|
|
686
875
|
|
|
687
876
|
if (!success) {
|
|
688
|
-
throw new Error("Failed to broadcast transaction
|
|
877
|
+
throw new Error("Failed to broadcast transaction. Try again later.");
|
|
689
878
|
}
|
|
690
879
|
|
|
691
880
|
console.info(`Transaction hash: ${payload.bdo.tx}`);
|
|
@@ -696,7 +885,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
696
885
|
|
|
697
886
|
}
|
|
698
887
|
|
|
699
|
-
async
|
|
888
|
+
async prepareTransferOperation(recipientAddress, amount) {
|
|
700
889
|
if (!this.#config.enableWallet) {
|
|
701
890
|
throw new Error(
|
|
702
891
|
"Can not perform transfer - wallet is not enabled."
|
|
@@ -744,37 +933,37 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
744
933
|
const txValidity = await this.#state.getIndexerSequenceState();
|
|
745
934
|
const payload = await applyStateMessageFactory(this.#wallet, this.#config)
|
|
746
935
|
.buildPartialTransferOperationMessage(
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
936
|
+
this.#wallet.address,
|
|
937
|
+
recipientAddress,
|
|
938
|
+
amountBuffer,
|
|
939
|
+
txValidity,
|
|
940
|
+
"json"
|
|
941
|
+
)
|
|
753
942
|
|
|
754
943
|
const expectedNewBalance = senderBalance - totalDeductedAmount;
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
const success = await this.broadcastPartialTransaction(payload);
|
|
944
|
+
return {
|
|
945
|
+
payload,
|
|
946
|
+
amountBigInt,
|
|
947
|
+
feeBigInt,
|
|
948
|
+
senderBalance,
|
|
949
|
+
totalDeductedAmount,
|
|
950
|
+
expectedNewBalance,
|
|
951
|
+
isSelfTransfer
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
async submitPreparedTransferOperation(preparedTransfer) {
|
|
956
|
+
const success = await this.broadcastPartialTransaction(preparedTransfer.payload);
|
|
768
957
|
if (!success) {
|
|
769
958
|
throw new Error("Failed to broadcast transfer transaction after multiple attempts.");
|
|
770
959
|
} else {
|
|
771
|
-
console.log(`Transfer transaction broadcasted successfully. Tx hash: ${payload.tro.tx}`);
|
|
960
|
+
console.log(`Transfer transaction broadcasted successfully. Tx hash: ${preparedTransfer.payload.tro.tx}`);
|
|
772
961
|
}
|
|
773
962
|
|
|
963
|
+
return preparedTransfer.payload.tro.tx;
|
|
774
964
|
}
|
|
775
965
|
|
|
776
|
-
async
|
|
777
|
-
|
|
966
|
+
async balanceMigrationOperation() {
|
|
778
967
|
const isInitDisabled = await this.#state.isInitalizationDisabled()
|
|
779
968
|
|
|
780
969
|
if (isInitDisabled) {
|
|
@@ -791,7 +980,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
791
980
|
throw new Error("Can not initialize an admin - admin does not exist.");
|
|
792
981
|
}
|
|
793
982
|
|
|
794
|
-
if (!this
|
|
983
|
+
if (!this.isAdmin(adminEntry)) {
|
|
795
984
|
throw new Error('Cannot perform balance migration - you are not the admin!.');
|
|
796
985
|
}
|
|
797
986
|
|
|
@@ -875,7 +1064,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
875
1064
|
console.log(`${bigIntToDecimalString(totalBalance)} $TNK have been migrated across ${totalAddresses} addresses.`);
|
|
876
1065
|
}
|
|
877
1066
|
|
|
878
|
-
async
|
|
1067
|
+
async disableInitialization() {
|
|
879
1068
|
if (!this.#config.enableWallet) {
|
|
880
1069
|
throw new Error("Can not initialize an admin - wallet is not enabled.");
|
|
881
1070
|
}
|
|
@@ -889,7 +1078,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
889
1078
|
throw new Error("Can not initialize an admin - admin does not exist.");
|
|
890
1079
|
}
|
|
891
1080
|
|
|
892
|
-
if (!this
|
|
1081
|
+
if (!this.isAdmin(adminEntry)) {
|
|
893
1082
|
throw new Error('Cannot perform whitelisting - you are not the admin!.');
|
|
894
1083
|
}
|
|
895
1084
|
if (!this.#wallet) {
|
|
@@ -911,153 +1100,6 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
911
1100
|
const encodedPayload = safeEncodeApplyOperation(payload);
|
|
912
1101
|
await this.#state.append(encodedPayload);
|
|
913
1102
|
}
|
|
914
|
-
|
|
915
|
-
async interactiveMode() {
|
|
916
|
-
if (this.#readline_instance === null) return;
|
|
917
|
-
const rl = this.#readline_instance;
|
|
918
|
-
|
|
919
|
-
printHelp(this.#config.isAdminMode);
|
|
920
|
-
|
|
921
|
-
rl.on("line", async (input) => {
|
|
922
|
-
try {
|
|
923
|
-
await this.handleCommand(input.trim(), rl);
|
|
924
|
-
} catch (err) {
|
|
925
|
-
console.error(`${err}`);
|
|
926
|
-
}
|
|
927
|
-
rl.prompt();
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
rl.prompt();
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
async handleCommand(input, rl = null, payload = null) {
|
|
934
|
-
const [command, ...parts] = input.split(" ");
|
|
935
|
-
const exactHandlers = {
|
|
936
|
-
"/help": async () => {
|
|
937
|
-
printHelp(this.#config.isAdminMode);
|
|
938
|
-
},
|
|
939
|
-
"/exit": async () => {
|
|
940
|
-
if (rl) rl.close();
|
|
941
|
-
await this.close();
|
|
942
|
-
},
|
|
943
|
-
"/add_admin": async () => await this.#handleAdminCreation(),
|
|
944
|
-
"/add_admin --recovery": async () => await this.#handleAdminRecovery(),
|
|
945
|
-
"/add_whitelist": async () => await this.#handleWhitelistOperations(),
|
|
946
|
-
"/add_writer": async () => await this.#requestWriterRole(true),
|
|
947
|
-
"/remove_writer": async () => await this.#requestWriterRole(false),
|
|
948
|
-
"/core": async () => await coreInfoCommand(this.#state),
|
|
949
|
-
"/indexers_list": async () => console.log(await this.#state.getIndexersEntry()),
|
|
950
|
-
"/validator_pool": () => this.#network.validatorConnectionManager.prettyPrint(),
|
|
951
|
-
"/stats": async () => await verifyDag(
|
|
952
|
-
this.#state,
|
|
953
|
-
this.#network,
|
|
954
|
-
this.#wallet,
|
|
955
|
-
this.#state.writingKey
|
|
956
|
-
),
|
|
957
|
-
"/balance_migration": async () => await this.#balanceMigrationOperation(),
|
|
958
|
-
"/disable_initialization": async () => await this.#disableInitialization()
|
|
959
|
-
};
|
|
960
|
-
|
|
961
|
-
if (exactHandlers[command]) {
|
|
962
|
-
const result = await exactHandlers[command]();
|
|
963
|
-
if (rl) rl.prompt();
|
|
964
|
-
return result;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
if (input.startsWith("/node_status")) {
|
|
968
|
-
const address = parts[0];
|
|
969
|
-
const result = await nodeStatusCommand(this.#state, address);
|
|
970
|
-
if (rl) rl.prompt();
|
|
971
|
-
return result;
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
if (input.startsWith("/add_indexer")) {
|
|
975
|
-
const address = parts[0];
|
|
976
|
-
await this.#updateWriterToIndexerRole(address, true);
|
|
977
|
-
} else if (input.startsWith("/remove_indexer")) {
|
|
978
|
-
const address = parts[0];
|
|
979
|
-
await this.#updateWriterToIndexerRole(address, false);
|
|
980
|
-
} else if (input.startsWith("/ban_writer")) {
|
|
981
|
-
const address = parts[0];
|
|
982
|
-
await this.#banValidator(address);
|
|
983
|
-
} else if (input.startsWith("/deployment")) {
|
|
984
|
-
const bootstrapToDeploy = parts[0];
|
|
985
|
-
const channel = parts[1] || randomBytes(32).toString("hex");
|
|
986
|
-
if (channel.length !== 64 || !isHexString(channel)) {
|
|
987
|
-
throw new Error("Channel must be a 32-byte hex string");
|
|
988
|
-
}
|
|
989
|
-
await this.#deployBootstrap(bootstrapToDeploy, channel);
|
|
990
|
-
} else if (input.startsWith("/get_validator_addr")) {
|
|
991
|
-
const wkHexString = parts[0];
|
|
992
|
-
await getValidatorAddressCommand(this.#state, wkHexString, this.#config.addressPrefix);
|
|
993
|
-
} else if (input.startsWith("/get_deployment")) {
|
|
994
|
-
const bootstrapHex = parts[0];
|
|
995
|
-
await getDeploymentCommand(this.#state, bootstrapHex, this.#config.addressLength);
|
|
996
|
-
} else if (input.startsWith("/get_tx_info")) {
|
|
997
|
-
const txHash = parts[0];
|
|
998
|
-
await getTxInfoCommand(this.#state, txHash);
|
|
999
|
-
} else if (input.startsWith("/transfer")) {
|
|
1000
|
-
const address = parts[0];
|
|
1001
|
-
const amount = parts[1];
|
|
1002
|
-
await this.#handleTransferOperation(address, amount);
|
|
1003
|
-
} else if (input.startsWith("/get_balance")) {
|
|
1004
|
-
const address = parts[0];
|
|
1005
|
-
const confirmedFlag = parts[1];
|
|
1006
|
-
const result = await getBalanceCommand(this.#state, address, confirmedFlag);
|
|
1007
|
-
if (rl) rl.prompt();
|
|
1008
|
-
return result;
|
|
1009
|
-
} else if (input.startsWith("/get_license_number")) {
|
|
1010
|
-
const address = parts[0];
|
|
1011
|
-
await getLicenseNumberCommand(this.#state, address);
|
|
1012
|
-
} else if (input.startsWith("/get_license_address")) {
|
|
1013
|
-
const licenseId = parseInt(parts[0]);
|
|
1014
|
-
await getLicenseAddressCommand(this.#state, licenseId);
|
|
1015
|
-
} else if (input.startsWith("/get_license_count")) {
|
|
1016
|
-
await getLicenseCountCommand(this.#state, this.#isAdmin.bind(this));
|
|
1017
|
-
} else if (input.startsWith("/get_txv")) {
|
|
1018
|
-
const result = await getTxvCommand(this.#state);
|
|
1019
|
-
if (rl) rl.prompt();
|
|
1020
|
-
return result;
|
|
1021
|
-
} else if (input.startsWith("/get_fee")) {
|
|
1022
|
-
const result = getFeeCommand(this.#state);
|
|
1023
|
-
if (rl) rl.prompt();
|
|
1024
|
-
return result;
|
|
1025
|
-
} else if (input.startsWith("/confirmed_length")) {
|
|
1026
|
-
const result = getConfirmedLengthCommand(this.#state);
|
|
1027
|
-
if (rl) rl.prompt();
|
|
1028
|
-
return result;
|
|
1029
|
-
} else if (input.startsWith("/unconfirmed_length")) {
|
|
1030
|
-
const result = getUnconfirmedLengthCommand(this.#state);
|
|
1031
|
-
if (rl) rl.prompt();
|
|
1032
|
-
return result;
|
|
1033
|
-
} else if (input.startsWith("/get_tx_payloads_bulk")) {
|
|
1034
|
-
if (!payload) {
|
|
1035
|
-
throw new Error("Missing payload for fetching tx payloads.");
|
|
1036
|
-
}
|
|
1037
|
-
const result = await getTxPayloadsBulkCommand(this.#state, payload, this.#config);
|
|
1038
|
-
if (rl) rl.prompt();
|
|
1039
|
-
return result;
|
|
1040
|
-
} else if (input.startsWith("/get_txs_hashes")) {
|
|
1041
|
-
const start = parseInt(parts[0]);
|
|
1042
|
-
const end = parseInt(parts[1]);
|
|
1043
|
-
const result = await getTxHashesCommand(this.#state, start, end);
|
|
1044
|
-
if (rl) rl.prompt();
|
|
1045
|
-
return result;
|
|
1046
|
-
} else if (input.startsWith("/get_tx_details")) {
|
|
1047
|
-
const hash = parts[0];
|
|
1048
|
-
const result = await getTxDetailsCommand(this.#state, hash, this.#config);
|
|
1049
|
-
if (rl) rl.prompt();
|
|
1050
|
-
return result;
|
|
1051
|
-
} else if (input.startsWith("/get_extended_tx_details")) {
|
|
1052
|
-
const hash = parts[0];
|
|
1053
|
-
const confirmed = parts[1] === "true";
|
|
1054
|
-
const result = await getExtendedTxDetailsCommand(this.#state, hash, confirmed, this.#config);
|
|
1055
|
-
if (rl) rl.prompt();
|
|
1056
|
-
return result;
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
if (rl) rl.prompt();
|
|
1060
|
-
}
|
|
1061
1103
|
}
|
|
1062
1104
|
|
|
1063
1105
|
export default MainSettlementBus;
|