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/migration/.gitkeep
DELETED
|
File without changes
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
syntax = "proto3";
|
|
2
|
-
|
|
3
|
-
package apply.operations;
|
|
4
|
-
|
|
5
|
-
//DO NOT CHANGE THE ORDER AFTER RELEASE - ONLY APPEND NEW ONES
|
|
6
|
-
enum OperationType {
|
|
7
|
-
UNKNOWN = 0;
|
|
8
|
-
ADD_ADMIN = 1; // complete
|
|
9
|
-
DISABLE_INITIALIZATION = 2; // complete
|
|
10
|
-
BALANCE_INITIALIZATION = 3; // complete
|
|
11
|
-
APPEND_WHITELIST = 4; // complete
|
|
12
|
-
ADD_WRITER = 5; // partial
|
|
13
|
-
REMOVE_WRITER = 6; // partial
|
|
14
|
-
ADMIN_RECOVERY = 7; // partial
|
|
15
|
-
ADD_INDEXER = 8; // complete
|
|
16
|
-
REMOVE_INDEXER = 9; // complete
|
|
17
|
-
BAN_VALIDATOR = 10; // complete
|
|
18
|
-
BOOTSTRAP_DEPLOYMENT = 11; // partial
|
|
19
|
-
TX = 12; // partial
|
|
20
|
-
TRANSFER = 13; // partial
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// add admin operation, disable_initialization (complete by default)
|
|
24
|
-
message CoreAdminOperation {
|
|
25
|
-
bytes tx = 1; // Transaction hash (unique identifier for the transaction)
|
|
26
|
-
bytes txv = 2; // Transaction expiration
|
|
27
|
-
bytes iw = 3; // incoming writer key (admin)
|
|
28
|
-
bytes in = 4; // Nonce of the invoker (admin)
|
|
29
|
-
bytes is = 5; // Signature of the invoker (admin)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// append_whitelist, add_indexer, remove_indexer, ban_writer (complete by default)
|
|
33
|
-
message AdminControlOperation {
|
|
34
|
-
bytes tx = 1; // Transaction hash (unique identifier for the transaction)
|
|
35
|
-
bytes txv = 2; // Transaction expiration
|
|
36
|
-
bytes ia = 3; // selected address to specific operation.
|
|
37
|
-
bytes in = 4; // Nonce of the invoker (admin)
|
|
38
|
-
bytes is = 5; // Signature of the invoker (admin)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// balance_initialization (complete by default)
|
|
42
|
-
message BalanceInitializationOperation {
|
|
43
|
-
bytes tx = 1; // Transaction hash (unique identifier for the transaction)
|
|
44
|
-
bytes txv = 2; // Transaction expiration
|
|
45
|
-
bytes ia = 3; // selected address to specific operation.
|
|
46
|
-
bytes am = 4; // Initial balance to be set for the address
|
|
47
|
-
bytes in = 5; // Nonce of the contract invoker (admin)
|
|
48
|
-
bytes is = 6; // Signature of the contract invoker (admin)
|
|
49
|
-
}
|
|
50
|
-
// token_transfer (partial - need to be signed by another writer to be complete)
|
|
51
|
-
message TransferOperation {
|
|
52
|
-
bytes tx = 1; // Transaction hash (unique identifier for the transaction)
|
|
53
|
-
bytes txv = 2; // Transaction expiration
|
|
54
|
-
bytes to = 3; // Address of the recipient (any account)
|
|
55
|
-
bytes am = 4; // Amount of tokens to transfer
|
|
56
|
-
bytes in = 5; // Nonce of the invoker (any account)
|
|
57
|
-
bytes is = 6; // Signature of the invoker (any account)
|
|
58
|
-
bytes va = 7; // Validator's address (optional)
|
|
59
|
-
bytes vn = 8; // Validator's nonce (optional)
|
|
60
|
-
bytes vs = 9; // Validator's signature (optional)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// add_writer, remove_writer, admin_recovery (partial - need to be signed by another writer to be complete)
|
|
64
|
-
message RoleAccessOperation {
|
|
65
|
-
bytes tx = 1; // Transaction hash (unique identifier for the transaction)
|
|
66
|
-
bytes txv = 2; // Transaction expiration
|
|
67
|
-
bytes iw = 3; // Writing key of the invoker (whitelisted node, admin to be recovered, Trac Network)
|
|
68
|
-
bytes in = 4; // Nonce of the invoker (whitelisted node, admin to be recovered, Trac Network)
|
|
69
|
-
bytes is = 5; // Signature of the invoker (whitelisted node, admin to be recovered)
|
|
70
|
-
bytes va = 6; // Validator's address (optional)
|
|
71
|
-
bytes vn = 7; // Validator's nonce (optional)
|
|
72
|
-
bytes vs = 8; // Validator's signature (optional)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// transaction - (partial - need to be signed by another writer to be complete)
|
|
76
|
-
message TxOperation {
|
|
77
|
-
bytes tx = 1; // Transaction hash (unique identifier for the transaction)
|
|
78
|
-
bytes txv = 2; // Transaction expiration
|
|
79
|
-
bytes iw = 3; // Writing key of the requesting node (external subnetwork)
|
|
80
|
-
bytes ch = 4; // Content hash (hash of the transaction's data)
|
|
81
|
-
bytes bs = 5; // External bootstrap contract
|
|
82
|
-
bytes mbs = 6; // MSB bootstrap key
|
|
83
|
-
bytes in = 7; // Nonce of the requesting node
|
|
84
|
-
bytes is = 8; // Requester's signature
|
|
85
|
-
bytes va = 9; // Validator's address (optional)
|
|
86
|
-
bytes vn = 10; // Validator's nonce (optional)
|
|
87
|
-
bytes vs = 11; // Validator's signature (optional)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// bootstrap deployment - (partial - need to be signed by another writer to be complete)
|
|
91
|
-
message BootstrapDeploymentOperation {
|
|
92
|
-
bytes tx = 1; // Transaction hash (unique identifier for the transaction)
|
|
93
|
-
bytes txv = 2; // Transaction expiration
|
|
94
|
-
bytes bs = 3; // Bootstrap contract address
|
|
95
|
-
bytes ic = 4; // Channel on which the contract will operate
|
|
96
|
-
bytes in = 5; // Nonce of the contract invoker
|
|
97
|
-
bytes is = 6; // Signature of the contract invoker
|
|
98
|
-
bytes va = 7; // Validator's address (optional)
|
|
99
|
-
bytes vn = 8; // Validator's nonce (optional)
|
|
100
|
-
bytes vs = 9; // Validator's signature (optional)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Main structure for the operations where messages are
|
|
104
|
-
message Operation {
|
|
105
|
-
OperationType type = 1;
|
|
106
|
-
bytes address = 2; // address of the invoker
|
|
107
|
-
|
|
108
|
-
oneof value {
|
|
109
|
-
CoreAdminOperation cao = 3;
|
|
110
|
-
AdminControlOperation aco = 4;
|
|
111
|
-
BalanceInitializationOperation bio = 5;
|
|
112
|
-
TransferOperation tro = 6;
|
|
113
|
-
RoleAccessOperation rao = 7;
|
|
114
|
-
BootstrapDeploymentOperation bdo = 8;
|
|
115
|
-
TxOperation txo = 9;
|
|
116
|
-
}
|
|
117
|
-
}
|
package/proto/network.proto
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
syntax = "proto3";
|
|
2
|
-
|
|
3
|
-
package network.v1;
|
|
4
|
-
|
|
5
|
-
enum MessageType {
|
|
6
|
-
MESSAGE_TYPE_UNSPECIFIED = 0;
|
|
7
|
-
MESSAGE_TYPE_VALIDATOR_CONNECTION_REQUEST = 1;
|
|
8
|
-
MESSAGE_TYPE_VALIDATOR_CONNECTION_RESPONSE = 2;
|
|
9
|
-
MESSAGE_TYPE_LIVENESS_REQUEST = 3;
|
|
10
|
-
MESSAGE_TYPE_LIVENESS_RESPONSE = 4;
|
|
11
|
-
MESSAGE_TYPE_BROADCAST_TRANSACTION_REQUEST = 5;
|
|
12
|
-
MESSAGE_TYPE_BROADCAST_TRANSACTION_RESPONSE = 6;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
enum ResultCode {
|
|
16
|
-
RESULT_CODE_UNSPECIFIED = 0;
|
|
17
|
-
RESULT_CODE_OK = 1;
|
|
18
|
-
RESULT_CODE_INVALID_PAYLOAD = 2;
|
|
19
|
-
RESULT_CODE_UNSUPPORTED_VERSION = 3;
|
|
20
|
-
RESULT_CODE_RATE_LIMITED = 4;
|
|
21
|
-
RESULT_CODE_TIMEOUT = 5;
|
|
22
|
-
RESULT_CODE_SIGNATURE_INVALID = 6;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
message ValidatorConnectionRequest {
|
|
26
|
-
string issuer_address = 1;
|
|
27
|
-
bytes nonce = 2;
|
|
28
|
-
bytes signature = 3;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
message ValidatorConnectionResponse {
|
|
32
|
-
string issuer_address = 1;
|
|
33
|
-
bytes nonce = 2;
|
|
34
|
-
bytes signature = 3;
|
|
35
|
-
ResultCode result = 4;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
message LivenessRequest {
|
|
39
|
-
bytes nonce = 1;
|
|
40
|
-
bytes signature = 2;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
message LivenessResponse {
|
|
44
|
-
bytes nonce = 1;
|
|
45
|
-
bytes signature = 2;
|
|
46
|
-
ResultCode result = 3;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
message BroadcastTransactionRequest {
|
|
50
|
-
bytes data = 1; // binary encoded payload
|
|
51
|
-
bytes nonce = 2;
|
|
52
|
-
bytes signature = 3;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
message BroadcastTransactionResponse {
|
|
56
|
-
bytes nonce = 1;
|
|
57
|
-
bytes signature = 2;
|
|
58
|
-
ResultCode result = 3;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
message MessageHeader {
|
|
62
|
-
MessageType type = 1;
|
|
63
|
-
string id = 2;
|
|
64
|
-
uint64 timestamp = 3;
|
|
65
|
-
oneof field {
|
|
66
|
-
ValidatorConnectionRequest validator_connection_request = 4;
|
|
67
|
-
ValidatorConnectionResponse validator_connection_response = 5;
|
|
68
|
-
LivenessRequest liveness_request = 6;
|
|
69
|
-
LivenessResponse liveness_response = 7;
|
|
70
|
-
BroadcastTransactionRequest broadcast_transaction_request = 8;
|
|
71
|
-
BroadcastTransactionResponse broadcast_transaction_response = 9;
|
|
72
|
-
}
|
|
73
|
-
repeated string capabilities = 10;
|
|
74
|
-
}
|
package/rpc/rpc_services.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { bufferToBigInt } from "../src/utils/amountSerialization.js";
|
|
2
|
-
import {
|
|
3
|
-
normalizeDecodedPayloadForJson,
|
|
4
|
-
normalizeTransactionOperation,
|
|
5
|
-
normalizeTransferOperation
|
|
6
|
-
} from "../src/utils/normalizers.js";
|
|
7
|
-
import { get_confirmed_tx_info, get_unconfirmed_tx_info } from "../src/utils/cli.js";
|
|
8
|
-
import { OperationType } from "../src/utils/constants.js";
|
|
9
|
-
import b4a from "b4a";
|
|
10
|
-
import PartialTransaction from "../src/core/network/protocols/shared/validators/PartialTransaction.js";
|
|
11
|
-
import PartialTransfer from "../src/core/network/protocols/shared/validators/PartialTransfer.js";
|
|
12
|
-
import { ValidationError, BroadcastError, NotFoundError } from "./utils/helpers.js";
|
|
13
|
-
|
|
14
|
-
export async function getBalance(msbInstance, address, confirmed) {
|
|
15
|
-
const state = msbInstance.state;
|
|
16
|
-
const useUnconfirmed = confirmed === false;
|
|
17
|
-
|
|
18
|
-
const nodeEntry = useUnconfirmed
|
|
19
|
-
? await state.getNodeEntryUnsigned(address)
|
|
20
|
-
: await state.getNodeEntry(address);
|
|
21
|
-
|
|
22
|
-
if (!nodeEntry) return undefined;
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
address,
|
|
26
|
-
balance: bufferToBigInt(nodeEntry.balance).toString(),
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function getTxv(msbInstance) {
|
|
31
|
-
const txv = await msbInstance.state.getIndexerSequenceState();
|
|
32
|
-
return txv.toString("hex");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function getFee(msbInstance) {
|
|
36
|
-
const feeBuffer = msbInstance.state.getFee();
|
|
37
|
-
return bufferToBigInt(feeBuffer).toString();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function getConfirmedLength(msbInstance) {
|
|
41
|
-
return msbInstance.state.getSignedLength();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function getUnconfirmedLength(msbInstance) {
|
|
45
|
-
return msbInstance.state.getUnsignedLength();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function broadcastTransaction(msbInstance, config, payload) {
|
|
49
|
-
if (!payload) {
|
|
50
|
-
throw new ValidationError("Transaction payload is required for broadcasting.");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let normalizedPayload;
|
|
54
|
-
let isValid = false;
|
|
55
|
-
let hash;
|
|
56
|
-
|
|
57
|
-
const partialTransferValidator = new PartialTransfer(msbInstance.state, null, config);
|
|
58
|
-
const partialTransactionValidator = new PartialTransaction(msbInstance.state, null, config);
|
|
59
|
-
|
|
60
|
-
if (payload.type === OperationType.TRANSFER) {
|
|
61
|
-
normalizedPayload = normalizeTransferOperation(payload, config);
|
|
62
|
-
isValid = await partialTransferValidator.validate(normalizedPayload);
|
|
63
|
-
hash = b4a.toString(normalizedPayload.tro.tx, "hex");
|
|
64
|
-
} else if (payload.type === OperationType.TX) {
|
|
65
|
-
normalizedPayload = normalizeTransactionOperation(payload, config);
|
|
66
|
-
isValid = await partialTransactionValidator.validate(normalizedPayload);
|
|
67
|
-
hash = b4a.toString(normalizedPayload.txo.tx, "hex");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (!isValid) {
|
|
71
|
-
throw new ValidationError("Invalid transaction payload.");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const success = await msbInstance.broadcastPartialTransaction(payload);
|
|
75
|
-
|
|
76
|
-
if (!success) {
|
|
77
|
-
throw new BroadcastError("Failed to broadcast transaction after multiple attempts.");
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const signedLength = msbInstance.state.getSignedLength();
|
|
81
|
-
const unsignedLength = msbInstance.state.getUnsignedLength();
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
message: "Transaction broadcasted successfully.",
|
|
85
|
-
signedLength,
|
|
86
|
-
unsignedLength,
|
|
87
|
-
tx: hash
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export async function getTxHashes(msbInstance, start, end) {
|
|
92
|
-
const hashes = await msbInstance.state.confirmedTransactionsBetween(start, end);
|
|
93
|
-
return { hashes };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export async function getTxDetails(msbInstance, hash) {
|
|
97
|
-
const rawPayload = await get_confirmed_tx_info(msbInstance.state, hash);
|
|
98
|
-
if (!rawPayload) {
|
|
99
|
-
throw new NotFoundError(`Transaction ${hash} not found.`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return normalizeDecodedPayloadForJson(rawPayload.decoded, msbInstance.config);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export async function fetchBulkTxPayloads(msbInstance, hashes) {
|
|
106
|
-
if (!Array.isArray(hashes) || hashes.length === 0) {
|
|
107
|
-
throw new ValidationError("Missing hash list.");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (hashes.length > 1500) {
|
|
111
|
-
throw new ValidationError("Length of input tx hashes exceeded.");
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const res = { results: [], missing: [] };
|
|
115
|
-
|
|
116
|
-
const promises = hashes.map((hash) => get_confirmed_tx_info(msbInstance.state, hash));
|
|
117
|
-
const results = await Promise.all(promises);
|
|
118
|
-
|
|
119
|
-
results.forEach((result, index) => {
|
|
120
|
-
const hash = hashes[index];
|
|
121
|
-
if (!result) {
|
|
122
|
-
res.missing.push(hash);
|
|
123
|
-
} else {
|
|
124
|
-
const decodedResult = normalizeDecodedPayloadForJson(result.decoded, msbInstance.config);
|
|
125
|
-
res.results.push({ hash, payload: decodedResult });
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
return res;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export async function getExtendedTxDetails(msbInstance, hash, confirmed) {
|
|
133
|
-
const state = msbInstance.state;
|
|
134
|
-
let rawPayload;
|
|
135
|
-
|
|
136
|
-
if (confirmed) {
|
|
137
|
-
rawPayload = await get_confirmed_tx_info(state, hash);
|
|
138
|
-
} else {
|
|
139
|
-
rawPayload = await get_unconfirmed_tx_info(state, hash);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!rawPayload) {
|
|
143
|
-
throw new NotFoundError(`No payload found for tx hash: ${hash}`);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const normalizedPayload = normalizeDecodedPayloadForJson(rawPayload.decoded, msbInstance.config);
|
|
147
|
-
const length = await state.getTransactionConfirmedLength(hash);
|
|
148
|
-
|
|
149
|
-
if (length === null) {
|
|
150
|
-
return {
|
|
151
|
-
txDetails: normalizedPayload,
|
|
152
|
-
confirmed_length: 0,
|
|
153
|
-
fee: "0",
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const feeBuffer = state.getFee();
|
|
158
|
-
return {
|
|
159
|
-
txDetails: normalizedPayload,
|
|
160
|
-
confirmed_length: length,
|
|
161
|
-
fee: bufferToBigInt(feeBuffer).toString(),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
import { execSync } from 'child_process';
|
|
6
|
-
|
|
7
|
-
function generateCJSFromProto(inputPath, outputPath) {
|
|
8
|
-
execSync(`protocol-buffers "${inputPath}" -o "${outputPath}"`);
|
|
9
|
-
console.log(`${outputPath} has been generated.`);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function transformToUseB4a(outputPath) {
|
|
13
|
-
let content = fs.readFileSync(outputPath, 'utf-8');
|
|
14
|
-
content = content.replace(/\bBuffer\.([a-zA-Z]+)/g, 'b4a.$1');
|
|
15
|
-
content = `var b4a = require('b4a');\n` + content;
|
|
16
|
-
fs.writeFileSync(outputPath, content, 'utf-8');
|
|
17
|
-
console.log(`${outputPath} has been modified to use b4a.`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
function main() {
|
|
22
|
-
const directoryName = path.dirname(fileURLToPath(import.meta.url));
|
|
23
|
-
|
|
24
|
-
const inputDir = path.join(directoryName, '../proto');
|
|
25
|
-
const outputDir = path.join(directoryName, '../src/utils/protobuf');
|
|
26
|
-
|
|
27
|
-
fs.mkdirSync(outputDir, { recursive: true });
|
|
28
|
-
|
|
29
|
-
const files = fs.readdirSync(inputDir).filter(f => f.endsWith('.proto'));
|
|
30
|
-
|
|
31
|
-
for (const file of files) {
|
|
32
|
-
const name = path.basename(file, '.proto');
|
|
33
|
-
const inputPath = path.join(inputDir, file);
|
|
34
|
-
const outputPath = path.join(outputDir, `${name}.cjs`);
|
|
35
|
-
|
|
36
|
-
generateCJSFromProto(inputPath, outputPath);
|
|
37
|
-
transformToUseB4a(outputPath);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
main();
|
|
42
|
-
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import PeerWallet from 'trac-wallet';
|
|
2
|
-
import b4a from 'b4a';
|
|
3
|
-
|
|
4
|
-
class NetworkWalletFactory {
|
|
5
|
-
static provide(options = {}) {
|
|
6
|
-
const {
|
|
7
|
-
enableWallet,
|
|
8
|
-
wallet,
|
|
9
|
-
keyPair,
|
|
10
|
-
networkPrefix
|
|
11
|
-
} = options;
|
|
12
|
-
|
|
13
|
-
if (enableWallet) {
|
|
14
|
-
if (!wallet) {
|
|
15
|
-
throw new Error('NetworkingWalletFactory: wallet instance is required when wallet is enabled');
|
|
16
|
-
}
|
|
17
|
-
return wallet;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (!keyPair) {
|
|
21
|
-
throw new Error('NetworkingWalletFactory: keyPair must be provided when wallet is disabled');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return new EphemeralWallet(keyPair, networkPrefix);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// TODO: Once Wallet class in trac-wallet exposes a constructor/factory that accepts an existing keyPair
|
|
29
|
-
// (e.g. Wallet.fromKeyPair({ publicKey, secretKey }, networkPrefix)), replace EphemeralWallet
|
|
30
|
-
// with a thin wrapper around that functionality instead of duplicating signing/verification logic.
|
|
31
|
-
export class EphemeralWallet {
|
|
32
|
-
#publicKey;
|
|
33
|
-
#secretKey;
|
|
34
|
-
#address;
|
|
35
|
-
|
|
36
|
-
constructor(keyPair, networkPrefix) {
|
|
37
|
-
|
|
38
|
-
if (!keyPair?.publicKey || !keyPair?.secretKey) {
|
|
39
|
-
throw new Error('NetworkIdentityProvider: keyPair with publicKey and secretKey is required');
|
|
40
|
-
}
|
|
41
|
-
this.#assertBuffer(keyPair.publicKey);
|
|
42
|
-
this.#assertBuffer(keyPair.secretKey);
|
|
43
|
-
|
|
44
|
-
const address = PeerWallet.encodeBech32m(networkPrefix, keyPair.publicKey);
|
|
45
|
-
if (!address) {
|
|
46
|
-
throw new Error('NetworkIdentityProvider: failed to derive address from networking key pair');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.#publicKey = keyPair.publicKey;
|
|
50
|
-
this.#secretKey = keyPair.secretKey;
|
|
51
|
-
this.#address = address;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get publicKey() {
|
|
55
|
-
return this.#publicKey;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get address() {
|
|
59
|
-
return this.#address;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
sign(message) {
|
|
63
|
-
return PeerWallet.sign(message, this.#secretKey);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
verify(signature, message, publicKey = this.#publicKey) {
|
|
67
|
-
return PeerWallet.verify(signature, message, publicKey);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
#assertBuffer(value) {
|
|
71
|
-
if (!b4a.isBuffer(value)) {
|
|
72
|
-
throw new Error(`NetworkIdentityProvider: value must be a Buffer`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export default NetworkWalletFactory;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import ValidatorResponse from '../validators/ValidatorResponse.js';
|
|
2
|
-
import PeerWallet from 'trac-wallet';
|
|
3
|
-
|
|
4
|
-
class ResponseHandler {
|
|
5
|
-
#responseValidator;
|
|
6
|
-
#connectionManager;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(state, wallet, connectionManager ,config) {
|
|
10
|
-
this.#responseValidator = new ValidatorResponse(state, wallet, config);
|
|
11
|
-
this.#connectionManager = connectionManager;
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async handle(message, connection, channelString) {
|
|
16
|
-
await this.#handleValidatorResponse(message, connection, channelString);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async #handleValidatorResponse(message, connection, channelString) {
|
|
20
|
-
const isValid = await this.#responseValidator.validate(message, channelString);
|
|
21
|
-
if (isValid) {
|
|
22
|
-
const validatorAddressString = message.address;
|
|
23
|
-
const validatorPublicKey = PeerWallet.decodeBech32m(validatorAddressString);
|
|
24
|
-
|
|
25
|
-
if (this.#connectionManager.connected(validatorPublicKey)) {
|
|
26
|
-
return;
|
|
27
|
-
// TODO: What we should return? Or maybe we should throw?
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
this.#connectionManager.addValidator(validatorPublicKey, connection)
|
|
31
|
-
} else {
|
|
32
|
-
throw new Error("Validator response verification failed");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default ResponseHandler;
|
package/src/utils/cli.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import b4a from 'b4a';
|
|
2
|
-
import { safeDecodeApplyOperation } from "./protobuf/operationHelpers.js";
|
|
3
|
-
import { bigIntToDecimalString, bufferToBigInt } from "./amountSerialization.js";
|
|
4
|
-
|
|
5
|
-
export async function verifyDag(state, network, wallet, writerKey) {
|
|
6
|
-
try {
|
|
7
|
-
console.log('---------- node & network stats ----------');
|
|
8
|
-
let dagView, lengthdagView, dagSystem, lengthdagSystem;
|
|
9
|
-
|
|
10
|
-
if (state?.base?.view?.core && state?.base?.system?.core) {
|
|
11
|
-
try {
|
|
12
|
-
dagView = await state.base.view.core.treeHash();
|
|
13
|
-
lengthdagView = state.base.view.core.length;
|
|
14
|
-
dagSystem = await state.base.system.core.treeHash();
|
|
15
|
-
lengthdagSystem = state.base.system.core.length;
|
|
16
|
-
} catch (e) {
|
|
17
|
-
console.log('Error getting DAG info:', e.message);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
console.log('wallet.publicKey:', wallet?.publicKey?.toString('hex') ?? 'unset');
|
|
22
|
-
console.log('wallet.address:', (wallet && wallet.address) ? wallet.address : 'unset');
|
|
23
|
-
console.log('msb.writerKey:', writerKey ? writerKey.toString('hex') : 'unset');
|
|
24
|
-
console.log('swarm.connections.size:', network?.swarm?.connections?.size || 0);
|
|
25
|
-
if (state?.base?.view?.core) {
|
|
26
|
-
console.log('base.view.core.signedLength:', state.base.view.core.signedLength ?? 'unset');
|
|
27
|
-
console.log('base.view.core.length:', state.base.view.core.length ?? 'unset');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (state?.base) {
|
|
31
|
-
console.log("base.signedLength", state.base.signedLength ?? 'unset');
|
|
32
|
-
console.log("base.indexedLength", state.base.indexedLength ?? 'unset');
|
|
33
|
-
console.log("base.linearizer.indexers.length", state.base.linearizer?.indexers?.length ?? 'unset');
|
|
34
|
-
console.log(`base.key: ${state.base.key ? state.base.key.toString('hex') : 'unset'}`);
|
|
35
|
-
console.log('discoveryKey:', state.base.discoveryKey ? b4a.toString(state.base.discoveryKey, 'hex') : 'unset');
|
|
36
|
-
}
|
|
37
|
-
console.log(`VIEW Dag: ${dagView ? dagView.toString('hex') : 'unset'} (length: ${lengthdagView || 0})`);
|
|
38
|
-
console.log(`SYSTEM Dag: ${dagSystem ? dagSystem.toString('hex') : 'unset'} (length: ${lengthdagSystem || 0})`);
|
|
39
|
-
const wl = await state.getWriterLength();
|
|
40
|
-
console.log('Total Registered Writers:', wl !== null ? wl : 0);
|
|
41
|
-
|
|
42
|
-
console.log("---------- flags ----------");
|
|
43
|
-
try {
|
|
44
|
-
console.log(`isIndexer: ${state?.isIndexer?.() ?? 'unset'}`);
|
|
45
|
-
console.log(`isWriter: ${state?.isWritable?.() ?? 'unset'}`);
|
|
46
|
-
} catch (e) {
|
|
47
|
-
console.log('Error getting flags:', e.message);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
} catch (error) {
|
|
51
|
-
console.error('Error during DAG monitoring:', error.message);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function printHelp(isAdminMode = false) {
|
|
56
|
-
if (isAdminMode) {
|
|
57
|
-
console.log('🚨 WARNING: IF YOU ARE NOT AN ADMIN, DO NOT USE THE COMMANDS BELOW! YOU RISK LOSING YOUR FUNDS! 🚨');
|
|
58
|
-
console.log('\nAdmin commands:');
|
|
59
|
-
console.log('- /add_admin: Register admin entry with bootstrap key (initial setup), or use --recovery flag to recover admin role');
|
|
60
|
-
console.log('- /balance_migration: Perform balance migration with the given initial balances CSV file');
|
|
61
|
-
console.log('- /add_whitelist: Add all specified whitelist addresses. If initialization is enabled, no fee is required.');
|
|
62
|
-
console.log('- /disable_initialization: Disable further balance initializations and whitelisting');
|
|
63
|
-
console.log('- /add_indexer <address>: Change a role of the selected writer node to indexer role. Charges a fee.');
|
|
64
|
-
console.log('- /remove_indexer <address>: Change a role of the selected indexer node to default role. Charges a fee.');
|
|
65
|
-
console.log('- /ban_writer <address>: Demote a whitelisted writer to default role and remove it from the whitelist. Charges a fee.');
|
|
66
|
-
}
|
|
67
|
-
console.log('Available commands:');
|
|
68
|
-
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.');
|
|
69
|
-
console.log('- /remove_writer: Remove yourself from this MSB. Requires a fee, and the stake will be refunded.');
|
|
70
|
-
console.log('- /node_status <address>: Get network information about a node with the given address.');
|
|
71
|
-
console.log('- /stats: Check system stats such as writing key, DAG, etc.');
|
|
72
|
-
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.');
|
|
73
|
-
console.log('- /get_deployment <subnetwork_bootstrap>: Get information about a subnetwork deployment with the given bootstrap.');
|
|
74
|
-
console.log('- /transfer <to_address> <amount>: Transfer the specified amount to the given address. Requires a fee.');
|
|
75
|
-
console.log('- /get_tx_info <tx_hash>: Get information about a transaction with the given hash.');
|
|
76
|
-
console.log('- /get_validator_addr <writing_key>: Get the validator address mapped to the given writing key.');
|
|
77
|
-
console.log('- /get_balance <address> <confirmed>: Get the balance of the node with specified address (confirmed = true is default)');
|
|
78
|
-
console.log('- /exit: Exit the program.');
|
|
79
|
-
console.log('- /help: Display this help.');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export const printWalletInfo = (address, writingKey) => {
|
|
83
|
-
console.log('');
|
|
84
|
-
console.log('#####################################################################################');
|
|
85
|
-
console.log('# MSB Address: ', address, ' #');
|
|
86
|
-
console.log('# MSB Writer: ', writingKey.toString('hex'), '#');
|
|
87
|
-
console.log('#####################################################################################');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export const printBalance = async (address, state, wallet_enabled) => {
|
|
91
|
-
if (wallet_enabled && state) {
|
|
92
|
-
const nodeEntry = await state.getNodeEntry(address);
|
|
93
|
-
const balance = nodeEntry ? bigIntToDecimalString(bufferToBigInt(nodeEntry.balance)) : '0';
|
|
94
|
-
console.log(`Balance: ${balance}`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export const get_confirmed_tx_info = async (state_instance, txHash) => {
|
|
99
|
-
const payload = await state_instance.getSigned(txHash);
|
|
100
|
-
if (!payload) {
|
|
101
|
-
return null
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const decoded = safeDecodeApplyOperation(payload);
|
|
105
|
-
if (!decoded) {
|
|
106
|
-
throw new Error(`Failed to decode payload for transaction hash: ${txHash}`);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
payload,
|
|
111
|
-
decoded
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export const get_unconfirmed_tx_info = async (state_instance, txHash) => {
|
|
116
|
-
const payload = await state_instance.get(txHash);
|
|
117
|
-
if (!payload) {
|
|
118
|
-
return null
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const decoded = safeDecodeApplyOperation(payload);
|
|
122
|
-
if (!decoded) {
|
|
123
|
-
throw new Error(`Failed to decode payload for transaction hash: ${txHash}`);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
payload,
|
|
128
|
-
decoded
|
|
129
|
-
}
|
|
130
|
-
}
|