trac-msb 0.2.7 → 0.2.9
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/.github/workflows/publish.yml +8 -16
- package/msb.mjs +13 -25
- package/package.json +8 -4
- package/proto/network.proto +74 -0
- package/rpc/{create_server.mjs → create_server.js} +4 -4
- package/rpc/{handlers.mjs → handlers.js} +7 -7
- package/rpc/routes/{index.mjs → index.js} +1 -1
- package/rpc/routes/{v1.mjs → v1.js} +1 -1
- package/rpc/rpc_server.js +10 -0
- package/rpc/rpc_services.js +48 -7
- package/rpc/utils/{helpers.mjs → helpers.js} +1 -1
- package/src/config/config.js +137 -0
- package/src/config/env.js +63 -0
- package/src/core/network/Network.js +133 -119
- package/src/core/network/identity/NetworkWalletFactory.js +5 -6
- package/src/core/network/protocols/LegacyProtocol.js +67 -0
- package/src/core/network/protocols/NetworkMessages.js +48 -0
- package/src/core/network/protocols/ProtocolInterface.js +31 -0
- package/src/core/network/protocols/ProtocolSession.js +59 -0
- package/src/core/network/protocols/V1Protocol.js +64 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +84 -0
- package/src/core/network/protocols/legacy/handlers/GetRequestHandler.js +53 -0
- package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +37 -0
- package/src/core/network/{messaging → protocols/legacy}/validators/ValidatorResponse.js +2 -2
- package/src/core/network/{messaging → protocols/legacy}/validators/base/BaseResponse.js +13 -6
- package/src/core/network/protocols/shared/handlers/RoleOperationHandler.js +88 -0
- package/src/core/network/protocols/shared/handlers/SubnetworkOperationHandler.js +93 -0
- package/src/core/network/protocols/shared/handlers/TransferOperationHandler.js +57 -0
- package/src/core/network/{messaging → protocols/shared}/handlers/base/BaseOperationHandler.js +21 -26
- package/src/core/network/{messaging → protocols/shared}/validators/PartialBootstrapDeployment.js +3 -3
- package/src/core/network/{messaging → protocols/shared}/validators/PartialRoleAccess.js +15 -12
- package/src/core/network/{messaging → protocols/shared}/validators/PartialTransaction.js +10 -11
- package/src/core/network/{messaging → protocols/shared}/validators/PartialTransfer.js +10 -7
- package/src/core/network/{messaging → protocols/shared}/validators/base/PartialOperation.js +40 -22
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +15 -0
- package/src/core/network/services/ConnectionManager.js +13 -19
- package/src/core/network/services/MessageOrchestrator.js +10 -22
- package/src/core/network/services/TransactionPoolService.js +10 -10
- package/src/core/network/services/TransactionRateLimiterService.js +5 -3
- package/src/core/network/services/ValidatorObserverService.js +46 -21
- package/src/core/state/State.js +137 -141
- package/src/core/state/utils/address.js +18 -16
- package/src/core/state/utils/adminEntry.js +17 -16
- package/src/core/state/utils/deploymentEntry.js +15 -15
- package/src/core/state/utils/transaction.js +3 -95
- package/src/index.js +250 -325
- package/src/messages/network/v1/NetworkMessageBuilder.js +325 -0
- package/src/messages/network/v1/NetworkMessageDirector.js +137 -0
- package/src/messages/network/v1/networkMessageFactory.js +12 -0
- package/src/messages/state/ApplyStateMessageBuilder.js +661 -0
- package/src/messages/state/ApplyStateMessageDirector.js +516 -0
- package/src/messages/state/applyStateMessageFactory.js +12 -0
- package/src/utils/buffer.js +53 -1
- package/src/utils/check.js +21 -17
- package/src/utils/cli.js +0 -8
- package/src/utils/cliCommands.js +11 -11
- package/src/utils/constants.js +36 -24
- package/src/utils/fileUtils.js +1 -4
- package/src/utils/helpers.js +9 -20
- package/src/utils/migrationUtils.js +2 -2
- package/src/utils/normalizers.js +94 -11
- package/src/utils/protobuf/network.cjs +840 -0
- package/src/utils/protobuf/operationHelpers.js +10 -0
- package/tests/acceptance/v1/account/account.test.mjs +2 -2
- package/tests/acceptance/v1/balance/balance.test.mjs +1 -1
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +11 -2
- package/tests/acceptance/v1/rpc.test.mjs +10 -10
- package/tests/acceptance/v1/tx/tx.test.mjs +4 -2
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +7 -3
- package/tests/fixtures/check.fixtures.js +42 -42
- package/tests/fixtures/networkV1.fixtures.js +84 -0
- package/tests/fixtures/protobuf.fixtures.js +110 -26
- package/tests/helpers/StateNetworkFactory.js +3 -5
- package/tests/helpers/autobaseTestHelpers.js +1 -2
- package/tests/helpers/config.js +3 -0
- package/tests/helpers/setupApplyTests.js +113 -99
- package/tests/helpers/transactionPayloads.mjs +26 -12
- package/tests/unit/messages/messages.test.js +12 -0
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +276 -0
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +203 -0
- package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +521 -0
- package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +233 -0
- package/tests/unit/network/ConnectionManager.test.js +10 -7
- package/tests/unit/network/NetworkWalletFactory.test.js +14 -14
- package/tests/unit/network/networkModule.test.js +3 -2
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +10 -6
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +11 -8
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +11 -7
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +18 -20
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +57 -48
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +2 -1
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +72 -57
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +3 -7
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +12 -14
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +18 -13
- package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +2 -1
- package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +2 -1
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +27 -30
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +2 -1
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +24 -21
- package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +5 -4
- package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +4 -3
- package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +2 -1
- package/tests/unit/state/apply/common/commonScenarioHelper.js +16 -16
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +10 -5
- package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +2 -2
- package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +2 -1
- package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +2 -1
- package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +2 -1
- package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +2 -1
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +16 -9
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +6 -5
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +23 -19
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +45 -36
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +48 -45
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +32 -29
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +2 -1
- package/tests/unit/state/stateModule.test.js +0 -1
- package/tests/unit/state/stateTestUtils.js +7 -3
- package/tests/unit/state/utils/address.test.js +3 -3
- package/tests/unit/state/utils/adminEntry.test.js +10 -9
- package/tests/unit/unit.test.js +1 -1
- package/tests/unit/utils/buffer/buffer.test.js +62 -1
- package/tests/unit/utils/check/adminControlOperation.test.js +3 -3
- package/tests/unit/utils/check/balanceInitializationOperation.test.js +2 -2
- package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +2 -3
- package/tests/unit/utils/check/common.test.js +7 -6
- package/tests/unit/utils/check/coreAdminOperation.test.js +3 -3
- package/tests/unit/utils/check/roleAccessOperation.test.js +3 -2
- package/tests/unit/utils/check/transactionOperation.test.js +3 -3
- package/tests/unit/utils/check/transferOperation.test.js +3 -3
- package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +2 -1
- package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +2 -1
- package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +7 -0
- package/tests/unit/utils/normalizers/normalizers.test.js +469 -0
- package/tests/unit/utils/protobuf/operationHelpers.test.js +120 -2
- package/tests/unit/utils/utils.test.js +0 -1
- package/rpc/rpc_server.mjs +0 -10
- package/src/core/network/messaging/NetworkMessages.js +0 -63
- package/src/core/network/messaging/handlers/GetRequestHandler.js +0 -112
- package/src/core/network/messaging/handlers/ResponseHandler.js +0 -108
- package/src/core/network/messaging/handlers/RoleOperationHandler.js +0 -116
- package/src/core/network/messaging/handlers/SubnetworkOperationHandler.js +0 -143
- package/src/core/network/messaging/handlers/TransferOperationHandler.js +0 -52
- package/src/core/network/messaging/routes/NetworkMessageRouter.js +0 -94
- package/src/core/network/messaging/validators/AdminResponse.js +0 -58
- package/src/core/network/messaging/validators/CustomNodeResponse.js +0 -46
- package/src/core/state/utils/indexerEntry.js +0 -105
- package/src/messages/base/StateBuilder.js +0 -25
- package/src/messages/completeStateMessages/CompleteStateMessageBuilder.js +0 -421
- package/src/messages/completeStateMessages/CompleteStateMessageDirector.js +0 -252
- package/src/messages/completeStateMessages/CompleteStateMessageOperations.js +0 -299
- package/src/messages/partialStateMessages/PartialStateMessageBuilder.js +0 -272
- package/src/messages/partialStateMessages/PartialStateMessageDirector.js +0 -137
- package/src/messages/partialStateMessages/PartialStateMessageOperations.js +0 -131
- package/src/utils/crypto.js +0 -11
- package/tests/integration/apply/addAdmin/addAdminBasic.test.js +0 -68
- package/tests/integration/apply/addAdmin/addAdminRecovery.test.js +0 -125
- package/tests/integration/apply/addIndexer.test.js +0 -237
- package/tests/integration/apply/addWhitelist.test.js +0 -53
- package/tests/integration/apply/addWriter.test.js +0 -244
- package/tests/integration/apply/apply.test.js +0 -19
- package/tests/integration/apply/banValidator.test.js +0 -109
- package/tests/integration/apply/postTx/invalidSubValues.test.js +0 -103
- package/tests/integration/apply/postTx/postTx.test.js +0 -222
- package/tests/integration/apply/removeIndexer.test.js +0 -128
- package/tests/integration/apply/removeWriter.test.js +0 -167
- package/tests/integration/apply/transfer.test.js +0 -81
- package/tests/integration/integration.test.js +0 -9
- package/tests/unit/messageOperations/assembleAddIndexerMessage.test.js +0 -21
- package/tests/unit/messageOperations/assembleAddWriterMessage.test.js +0 -16
- package/tests/unit/messageOperations/assembleAdminMessage.test.js +0 -69
- package/tests/unit/messageOperations/assembleBanWriterMessage.test.js +0 -16
- package/tests/unit/messageOperations/assemblePostTransaction.test.js +0 -442
- package/tests/unit/messageOperations/assembleRemoveIndexerMessage.test.js +0 -19
- package/tests/unit/messageOperations/assembleRemoveWriterMessage.test.js +0 -17
- package/tests/unit/messageOperations/assembleWhitelistMessages.test.js +0 -58
- package/tests/unit/messageOperations/commonsStateMessageOperationsTest.js +0 -277
- package/tests/unit/messageOperations/stateMessageOperations.test.js +0 -19
- package/tests/unit/state/utils/indexerEntry.test.js +0 -83
- package/tests/unit/state/utils/transaction.test.js +0 -97
- package/tests/unit/utils/crypto/createHash.test.js +0 -15
- /package/rpc/{constants.mjs → constants.js} +0 -0
- /package/rpc/{cors.mjs → cors.js} +0 -0
- /package/rpc/utils/{confirmedParameter.mjs → confirmedParameter.js} +0 -0
- /package/rpc/utils/{url.mjs → url.js} +0 -0
- /package/src/utils/{operations.js → applyOperations.js} +0 -0
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import StateBuilder from '../base/StateBuilder.js'
|
|
2
|
-
import { OperationType } from '../../utils/protobuf/applyOperations.cjs'
|
|
3
|
-
|
|
4
|
-
class CompleteStateMessageDirector {
|
|
5
|
-
#builder;
|
|
6
|
-
|
|
7
|
-
set builder(builderInstance) {
|
|
8
|
-
if (!(builderInstance instanceof StateBuilder)) {
|
|
9
|
-
throw new Error('Director requires a Builder instance.');
|
|
10
|
-
}
|
|
11
|
-
this.#builder = builderInstance;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async buildAddAdminMessage(invokerAddress, writingKey, txValidity) {
|
|
15
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
16
|
-
|
|
17
|
-
await this.#builder
|
|
18
|
-
.forOperationType(OperationType.ADD_ADMIN)
|
|
19
|
-
.withAddress(invokerAddress)
|
|
20
|
-
.withWriterKey(writingKey)
|
|
21
|
-
.withTxValidity(txValidity)
|
|
22
|
-
.buildValueAndSign();
|
|
23
|
-
|
|
24
|
-
return this.#builder.getPayload();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async buildDisableInitializationMessage(invokerAddress, writingKey, txValidity) {
|
|
28
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
29
|
-
|
|
30
|
-
await this.#builder
|
|
31
|
-
.forOperationType(OperationType.DISABLE_INITIALIZATION)
|
|
32
|
-
.withAddress(invokerAddress)
|
|
33
|
-
.withWriterKey(writingKey)
|
|
34
|
-
.withTxValidity(txValidity)
|
|
35
|
-
.buildValueAndSign();
|
|
36
|
-
|
|
37
|
-
return this.#builder.getPayload();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async buildBalanceInitializationMessage(invokerAddress, recipientAddress, amount, txValidity) {
|
|
41
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
42
|
-
await this.#builder
|
|
43
|
-
.forOperationType(OperationType.BALANCE_INITIALIZATION)
|
|
44
|
-
.withAddress(invokerAddress)
|
|
45
|
-
.withIncomingAddress(recipientAddress)
|
|
46
|
-
.withAmount(amount)
|
|
47
|
-
.withTxValidity(txValidity)
|
|
48
|
-
.buildValueAndSign();
|
|
49
|
-
|
|
50
|
-
return this.#builder.getPayload();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async buildAppendWhitelistMessage(invokerAddress, incomingAddress, txValidity) {
|
|
54
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
55
|
-
|
|
56
|
-
await this.#builder
|
|
57
|
-
.forOperationType(OperationType.APPEND_WHITELIST)
|
|
58
|
-
.withAddress(invokerAddress)
|
|
59
|
-
.withTxValidity(txValidity)
|
|
60
|
-
.withIncomingAddress(incomingAddress)
|
|
61
|
-
.buildValueAndSign();
|
|
62
|
-
|
|
63
|
-
return this.#builder.getPayload();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async buildAddWriterMessage(
|
|
67
|
-
invokerAddress,
|
|
68
|
-
txHash,
|
|
69
|
-
txValidity,
|
|
70
|
-
incomingWritingKey,
|
|
71
|
-
incomingNonce,
|
|
72
|
-
incomingSignature
|
|
73
|
-
) {
|
|
74
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
75
|
-
|
|
76
|
-
await this.#builder
|
|
77
|
-
.forOperationType(OperationType.ADD_WRITER)
|
|
78
|
-
.withAddress(invokerAddress)
|
|
79
|
-
.withTxHash(txHash)
|
|
80
|
-
.withTxValidity(txValidity)
|
|
81
|
-
.withIncomingWriterKey(incomingWritingKey)
|
|
82
|
-
.withIncomingNonce(incomingNonce)
|
|
83
|
-
.withIncomingSignature(incomingSignature)
|
|
84
|
-
.buildValueAndSign();
|
|
85
|
-
|
|
86
|
-
return this.#builder.getPayload();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async buildRemoveWriterMessage(
|
|
90
|
-
invokerAddress,
|
|
91
|
-
txHash,
|
|
92
|
-
txValidity,
|
|
93
|
-
incomingWritingKey,
|
|
94
|
-
incomingNonce,
|
|
95
|
-
incomingSignature
|
|
96
|
-
) {
|
|
97
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
98
|
-
|
|
99
|
-
await this.#builder
|
|
100
|
-
.forOperationType(OperationType.REMOVE_WRITER)
|
|
101
|
-
.withAddress(invokerAddress)
|
|
102
|
-
.withTxHash(txHash)
|
|
103
|
-
.withTxValidity(txValidity)
|
|
104
|
-
.withIncomingWriterKey(incomingWritingKey)
|
|
105
|
-
.withIncomingNonce(incomingNonce)
|
|
106
|
-
.withIncomingSignature(incomingSignature)
|
|
107
|
-
.buildValueAndSign();
|
|
108
|
-
|
|
109
|
-
return this.#builder.getPayload();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async buildAdminRecoveryMessage(
|
|
113
|
-
invokerAddress,
|
|
114
|
-
txHash,
|
|
115
|
-
txValidity,
|
|
116
|
-
incomingWritingKey,
|
|
117
|
-
incomingNonce,
|
|
118
|
-
incomingSignature
|
|
119
|
-
) {
|
|
120
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
121
|
-
|
|
122
|
-
await this.#builder
|
|
123
|
-
.forOperationType(OperationType.ADMIN_RECOVERY)
|
|
124
|
-
.withAddress(invokerAddress)
|
|
125
|
-
.withTxHash(txHash)
|
|
126
|
-
.withTxValidity(txValidity)
|
|
127
|
-
.withIncomingWriterKey(incomingWritingKey)
|
|
128
|
-
.withIncomingNonce(incomingNonce)
|
|
129
|
-
.withIncomingSignature(incomingSignature)
|
|
130
|
-
.buildValueAndSign();
|
|
131
|
-
|
|
132
|
-
return this.#builder.getPayload();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async buildAddIndexerMessage(invokerAddress, incomingAddress, txValidity) {
|
|
136
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
137
|
-
|
|
138
|
-
await this.#builder
|
|
139
|
-
.forOperationType(OperationType.ADD_INDEXER)
|
|
140
|
-
.withAddress(invokerAddress)
|
|
141
|
-
.withTxValidity(txValidity)
|
|
142
|
-
.withIncomingAddress(incomingAddress)
|
|
143
|
-
.buildValueAndSign();
|
|
144
|
-
|
|
145
|
-
return this.#builder.getPayload();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async buildRemoveIndexerMessage(invokerAddress, incomingAddress, txValidity) {
|
|
149
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
150
|
-
await this.#builder
|
|
151
|
-
.forOperationType(OperationType.REMOVE_INDEXER)
|
|
152
|
-
.withAddress(invokerAddress)
|
|
153
|
-
.withTxValidity(txValidity)
|
|
154
|
-
.withIncomingAddress(incomingAddress)
|
|
155
|
-
.buildValueAndSign();
|
|
156
|
-
|
|
157
|
-
return this.#builder.getPayload();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async buildBanWriterMessage(invokerAddress, incomingAddress, txValidity) {
|
|
161
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
162
|
-
|
|
163
|
-
await this.#builder
|
|
164
|
-
.forOperationType(OperationType.BAN_VALIDATOR)
|
|
165
|
-
.withAddress(invokerAddress)
|
|
166
|
-
.withTxValidity(txValidity)
|
|
167
|
-
.withIncomingAddress(incomingAddress)
|
|
168
|
-
.buildValueAndSign();
|
|
169
|
-
|
|
170
|
-
return this.#builder.getPayload();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async buildTransactionOperationMessage(
|
|
174
|
-
invokerAddress,
|
|
175
|
-
txHash,
|
|
176
|
-
txValidity,
|
|
177
|
-
incomingWriterKey,
|
|
178
|
-
incomingNonce,
|
|
179
|
-
contentHash,
|
|
180
|
-
incomingSignature,
|
|
181
|
-
externalBootstrap,
|
|
182
|
-
msbBootstrap,
|
|
183
|
-
) {
|
|
184
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
185
|
-
await this.#builder
|
|
186
|
-
.forOperationType(OperationType.TX)
|
|
187
|
-
.withAddress(invokerAddress)
|
|
188
|
-
.withTxHash(txHash)
|
|
189
|
-
.withTxValidity(txValidity)
|
|
190
|
-
.withIncomingWriterKey(incomingWriterKey)
|
|
191
|
-
.withIncomingNonce(incomingNonce)
|
|
192
|
-
.withContentHash(contentHash)
|
|
193
|
-
.withIncomingSignature(incomingSignature)
|
|
194
|
-
.withExternalBootstrap(externalBootstrap)
|
|
195
|
-
.withMsbBootstrap(msbBootstrap)
|
|
196
|
-
.buildValueAndSign();
|
|
197
|
-
|
|
198
|
-
return this.#builder.getPayload();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
async buildBootstrapDeploymentMessage(
|
|
202
|
-
invokerAddress,
|
|
203
|
-
transactionHash,
|
|
204
|
-
txValidity,
|
|
205
|
-
externalBootstrap,
|
|
206
|
-
channel,
|
|
207
|
-
incomingNonce,
|
|
208
|
-
incomingSignature
|
|
209
|
-
) {
|
|
210
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
211
|
-
|
|
212
|
-
await this.#builder
|
|
213
|
-
.forOperationType(OperationType.BOOTSTRAP_DEPLOYMENT)
|
|
214
|
-
.withAddress(invokerAddress)
|
|
215
|
-
.withTxHash(transactionHash)
|
|
216
|
-
.withTxValidity(txValidity)
|
|
217
|
-
.withExternalBootstrap(externalBootstrap)
|
|
218
|
-
.withChannel(channel)
|
|
219
|
-
.withIncomingNonce(incomingNonce)
|
|
220
|
-
.withIncomingSignature(incomingSignature)
|
|
221
|
-
.buildValueAndSign();
|
|
222
|
-
|
|
223
|
-
return this.#builder.getPayload();
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
async buildTransferOperationMessage(
|
|
227
|
-
invokerAddress,
|
|
228
|
-
transactionHash,
|
|
229
|
-
txValidity,
|
|
230
|
-
incomingNonce,
|
|
231
|
-
recipientAddress,
|
|
232
|
-
amount,
|
|
233
|
-
incomingSignature
|
|
234
|
-
) {
|
|
235
|
-
if (!this.#builder) throw new Error('Builder has not been set.');
|
|
236
|
-
await this.#builder
|
|
237
|
-
.forOperationType(OperationType.TRANSFER)
|
|
238
|
-
.withAddress(invokerAddress)
|
|
239
|
-
.withTxHash(transactionHash)
|
|
240
|
-
.withTxValidity(txValidity)
|
|
241
|
-
.withIncomingNonce(incomingNonce)
|
|
242
|
-
.withIncomingAddress(recipientAddress)
|
|
243
|
-
.withAmount(amount)
|
|
244
|
-
.withIncomingSignature(incomingSignature)
|
|
245
|
-
.buildValueAndSign();
|
|
246
|
-
|
|
247
|
-
return this.#builder.getPayload();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export default CompleteStateMessageDirector;
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import CompleteStateMessageDirector from './CompleteStateMessageDirector.js';
|
|
2
|
-
import CompleteStateMessageBuilder from './CompleteStateMessageBuilder.js';
|
|
3
|
-
import { safeEncodeApplyOperation } from '../../utils/protobuf/operationHelpers.js';
|
|
4
|
-
import fileUtils from '../../../src/utils/fileUtils.js';
|
|
5
|
-
|
|
6
|
-
class CompleteStateMessageOperations {
|
|
7
|
-
|
|
8
|
-
static async assembleAddAdminMessage(wallet, writingKey, txValidity) {
|
|
9
|
-
try {
|
|
10
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
11
|
-
const director = new CompleteStateMessageDirector();
|
|
12
|
-
director.builder = builder;
|
|
13
|
-
|
|
14
|
-
const payload = await director.buildAddAdminMessage(wallet.address, writingKey, txValidity);
|
|
15
|
-
return safeEncodeApplyOperation(payload);
|
|
16
|
-
|
|
17
|
-
} catch (error) {
|
|
18
|
-
throw new Error(`Failed to assemble admin message: ${error.message}`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static async assembleDisableInitializationMessage(wallet, writingKey, txValidity) {
|
|
23
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
24
|
-
const director = new CompleteStateMessageDirector();
|
|
25
|
-
director.builder = builder;
|
|
26
|
-
|
|
27
|
-
const payload = await director.buildDisableInitializationMessage(wallet.address, writingKey, txValidity);
|
|
28
|
-
return safeEncodeApplyOperation(payload);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
static async assembleAddWriterMessage(
|
|
32
|
-
wallet,
|
|
33
|
-
invokerAddress,
|
|
34
|
-
transactionHash,
|
|
35
|
-
txValidity,
|
|
36
|
-
incomingWritingKey,
|
|
37
|
-
incomingNonce,
|
|
38
|
-
incomingSignature
|
|
39
|
-
) {
|
|
40
|
-
try {
|
|
41
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
42
|
-
const director = new CompleteStateMessageDirector();
|
|
43
|
-
director.builder = builder;
|
|
44
|
-
|
|
45
|
-
const payload = await director.buildAddWriterMessage(
|
|
46
|
-
invokerAddress,
|
|
47
|
-
transactionHash,
|
|
48
|
-
txValidity,
|
|
49
|
-
incomingWritingKey,
|
|
50
|
-
incomingNonce,
|
|
51
|
-
incomingSignature
|
|
52
|
-
);
|
|
53
|
-
return safeEncodeApplyOperation(payload);
|
|
54
|
-
|
|
55
|
-
} catch (error) {
|
|
56
|
-
throw new Error(`Failed to assemble add writer message: ${error.message}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static async assembleRemoveWriterMessage(
|
|
61
|
-
wallet,
|
|
62
|
-
invokerAddress,
|
|
63
|
-
transactionHash,
|
|
64
|
-
txValidity,
|
|
65
|
-
incomingWritingKey,
|
|
66
|
-
incomingNonce,
|
|
67
|
-
incomingSignature
|
|
68
|
-
) {
|
|
69
|
-
try {
|
|
70
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
71
|
-
const director = new CompleteStateMessageDirector();
|
|
72
|
-
director.builder = builder;
|
|
73
|
-
|
|
74
|
-
const payload = await director.buildRemoveWriterMessage(
|
|
75
|
-
invokerAddress,
|
|
76
|
-
transactionHash,
|
|
77
|
-
txValidity,
|
|
78
|
-
incomingWritingKey,
|
|
79
|
-
incomingNonce,
|
|
80
|
-
incomingSignature
|
|
81
|
-
);
|
|
82
|
-
return safeEncodeApplyOperation(payload);
|
|
83
|
-
|
|
84
|
-
} catch (error) {
|
|
85
|
-
throw new Error(`Failed to assemble remove writer message: ${error.message}`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
static async assembleAdminRecoveryMessage(
|
|
90
|
-
wallet,
|
|
91
|
-
invokerAddress,
|
|
92
|
-
transactionHash,
|
|
93
|
-
txValidity,
|
|
94
|
-
incomingWritingKey,
|
|
95
|
-
incomingNonce,
|
|
96
|
-
incomingSignature
|
|
97
|
-
) {
|
|
98
|
-
try {
|
|
99
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
100
|
-
const director = new CompleteStateMessageDirector();
|
|
101
|
-
director.builder = builder;
|
|
102
|
-
|
|
103
|
-
const payload = await director.buildAdminRecoveryMessage(
|
|
104
|
-
invokerAddress,
|
|
105
|
-
transactionHash,
|
|
106
|
-
txValidity,
|
|
107
|
-
incomingWritingKey,
|
|
108
|
-
incomingNonce,
|
|
109
|
-
incomingSignature
|
|
110
|
-
);
|
|
111
|
-
return safeEncodeApplyOperation(payload);
|
|
112
|
-
|
|
113
|
-
} catch (error) {
|
|
114
|
-
throw new Error(`Failed to assemble remove writer message: ${error.message}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
static async assembleAddIndexerMessage(wallet, incomingAddress, txValidity) {
|
|
119
|
-
try {
|
|
120
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
121
|
-
const director = new CompleteStateMessageDirector();
|
|
122
|
-
director.builder = builder;
|
|
123
|
-
|
|
124
|
-
const payload = await director.buildAddIndexerMessage(wallet.address, incomingAddress, txValidity);
|
|
125
|
-
return safeEncodeApplyOperation(payload);
|
|
126
|
-
|
|
127
|
-
} catch (error) {
|
|
128
|
-
throw new Error(`Failed to assemble addIndexerMessage: ${error.message}`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
static async assembleRemoveIndexerMessage(wallet, incomingAddress, txValidity) {
|
|
135
|
-
try {
|
|
136
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
137
|
-
const director = new CompleteStateMessageDirector();
|
|
138
|
-
director.builder = builder;
|
|
139
|
-
|
|
140
|
-
const payload = await director.buildRemoveIndexerMessage(wallet.address, incomingAddress, txValidity);
|
|
141
|
-
return safeEncodeApplyOperation(payload);
|
|
142
|
-
|
|
143
|
-
} catch (error) {
|
|
144
|
-
throw new Error(`Failed to assemble removeIndexerMessage: ${error.message}`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
static async assembleAppendWhitelistMessages(wallet, txValidity, addressToWhitelist) {
|
|
149
|
-
try {
|
|
150
|
-
|
|
151
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
152
|
-
const director = new CompleteStateMessageDirector();
|
|
153
|
-
director.builder = builder;
|
|
154
|
-
|
|
155
|
-
const payload = await director.buildAppendWhitelistMessage(wallet.address, addressToWhitelist, txValidity);
|
|
156
|
-
|
|
157
|
-
return safeEncodeApplyOperation(payload);;
|
|
158
|
-
} catch (error) {
|
|
159
|
-
throw new Error(`Failed to assemble appendWhitelistMessages: ${error.message}`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
static async assembleBalanceInitializationMessages(wallet, txValidity, addressBalancePair) {
|
|
164
|
-
try {
|
|
165
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
166
|
-
const director = new CompleteStateMessageDirector();
|
|
167
|
-
director.builder = builder;
|
|
168
|
-
|
|
169
|
-
const messages = [];
|
|
170
|
-
|
|
171
|
-
for (const [recipientAddress, balanceBuffer] of addressBalancePair) {
|
|
172
|
-
const payload = await director.buildBalanceInitializationMessage(
|
|
173
|
-
wallet.address,
|
|
174
|
-
recipientAddress,
|
|
175
|
-
balanceBuffer,
|
|
176
|
-
txValidity
|
|
177
|
-
);
|
|
178
|
-
messages.push(safeEncodeApplyOperation(payload));
|
|
179
|
-
}
|
|
180
|
-
return messages;
|
|
181
|
-
|
|
182
|
-
} catch (error) {
|
|
183
|
-
throw new Error(`Failed to assemble balance initialization messages: ${error.message}`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
static async assembleBanWriterMessage(wallet, incomingAddress, txValidity) {
|
|
188
|
-
try {
|
|
189
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
190
|
-
const director = new CompleteStateMessageDirector();
|
|
191
|
-
director.builder = builder;
|
|
192
|
-
|
|
193
|
-
const payload = await director.buildBanWriterMessage(wallet.address, incomingAddress, txValidity);
|
|
194
|
-
return safeEncodeApplyOperation(payload);
|
|
195
|
-
|
|
196
|
-
} catch (error) {
|
|
197
|
-
throw new Error(`Failed to assemble ban writer message: ${error.message}`);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
static async assembleCompleteTransactionOperationMessage(
|
|
202
|
-
wallet,
|
|
203
|
-
invokerAddress,
|
|
204
|
-
txHash,
|
|
205
|
-
txValidity,
|
|
206
|
-
incomingWriterKey,
|
|
207
|
-
incomingNonce,
|
|
208
|
-
contentHash,
|
|
209
|
-
incomingSignature,
|
|
210
|
-
externalBootstrap,
|
|
211
|
-
msbBootstrap
|
|
212
|
-
) {
|
|
213
|
-
try {
|
|
214
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
215
|
-
const director = new CompleteStateMessageDirector();
|
|
216
|
-
director.builder = builder;
|
|
217
|
-
const payload = await director.buildTransactionOperationMessage(
|
|
218
|
-
invokerAddress,
|
|
219
|
-
txHash,
|
|
220
|
-
txValidity,
|
|
221
|
-
incomingWriterKey,
|
|
222
|
-
incomingNonce,
|
|
223
|
-
contentHash,
|
|
224
|
-
incomingSignature,
|
|
225
|
-
externalBootstrap,
|
|
226
|
-
msbBootstrap,
|
|
227
|
-
);
|
|
228
|
-
return safeEncodeApplyOperation(payload);
|
|
229
|
-
|
|
230
|
-
} catch (error) {
|
|
231
|
-
throw new Error(`Failed to assemble transaction Operation: ${error.message}`);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
static async assembleCompleteBootstrapDeployment(
|
|
236
|
-
wallet,
|
|
237
|
-
invokerAddress,
|
|
238
|
-
transactionHash,
|
|
239
|
-
txValidity,
|
|
240
|
-
externalBootstrap,
|
|
241
|
-
channel,
|
|
242
|
-
incomingNonce,
|
|
243
|
-
incomingSignature
|
|
244
|
-
) {
|
|
245
|
-
try {
|
|
246
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
247
|
-
const director = new CompleteStateMessageDirector();
|
|
248
|
-
director.builder = builder;
|
|
249
|
-
|
|
250
|
-
const payload = await director.buildBootstrapDeploymentMessage(
|
|
251
|
-
invokerAddress,
|
|
252
|
-
transactionHash,
|
|
253
|
-
txValidity,
|
|
254
|
-
externalBootstrap,
|
|
255
|
-
channel,
|
|
256
|
-
incomingNonce,
|
|
257
|
-
incomingSignature,
|
|
258
|
-
);
|
|
259
|
-
return safeEncodeApplyOperation(payload);
|
|
260
|
-
|
|
261
|
-
} catch (error) {
|
|
262
|
-
throw new Error(`Failed to assemble bootstrap deployment message: ${error.message}`);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
static async assembleCompleteTransferOperationMessage(
|
|
267
|
-
wallet,
|
|
268
|
-
invokerAddress,
|
|
269
|
-
transactionHash,
|
|
270
|
-
txValidity,
|
|
271
|
-
incomingNonce,
|
|
272
|
-
recipientAddress,
|
|
273
|
-
amount,
|
|
274
|
-
incomingSignature
|
|
275
|
-
) {
|
|
276
|
-
try {
|
|
277
|
-
const builder = new CompleteStateMessageBuilder(wallet);
|
|
278
|
-
const director = new CompleteStateMessageDirector();
|
|
279
|
-
director.builder = builder;
|
|
280
|
-
|
|
281
|
-
const payload = await director.buildTransferOperationMessage(
|
|
282
|
-
invokerAddress,
|
|
283
|
-
transactionHash,
|
|
284
|
-
txValidity,
|
|
285
|
-
incomingNonce,
|
|
286
|
-
recipientAddress,
|
|
287
|
-
amount,
|
|
288
|
-
incomingSignature
|
|
289
|
-
);
|
|
290
|
-
return safeEncodeApplyOperation(payload);
|
|
291
|
-
|
|
292
|
-
} catch (error) {
|
|
293
|
-
throw new Error(`Failed to assemble transfer operation message: ${error.message}`);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export default CompleteStateMessageOperations;
|