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
|
@@ -3,20 +3,17 @@ import {generateMnemonic, mnemonicToSeed} from 'bip39-mnemonic';
|
|
|
3
3
|
import b4a from 'b4a'
|
|
4
4
|
import PeerWallet from "trac-wallet"
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import CompleteStateMessageOperations from '../../src/messages/completeStateMessages/CompleteStateMessageOperations.js'
|
|
7
|
-
import PartialStateMessageOperations from '../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
|
|
8
6
|
import {MainSettlementBus} from '../../src/index.js'
|
|
7
|
+
import { createConfig, ENV } from '../../src/config/env.js'
|
|
9
8
|
import fileUtils from '../../src/utils/fileUtils.js'
|
|
10
9
|
import {EntryType} from '../../src/utils/constants.js';
|
|
11
10
|
import {sleep} from '../../src/utils/helpers.js'
|
|
12
11
|
import {formatIndexersEntry} from '../../src/utils/helpers.js';
|
|
13
|
-
import {
|
|
14
|
-
import CompleteStateMessageBuilder from '../../src/messages/completeStateMessages/CompleteStateMessageBuilder.js'
|
|
15
|
-
import CompleteStateMessageDirector from '../../src/messages/completeStateMessages/CompleteStateMessageDirector.js'
|
|
12
|
+
import { applyStateMessageFactory } from "../../src/messages/state/applyStateMessageFactory.js";
|
|
16
13
|
import { safeEncodeApplyOperation } from "../../src/utils/protobuf/operationHelpers.js"
|
|
17
14
|
import { $TNK } from '../../src/core/state/utils/balance.js';
|
|
18
|
-
import { operation } from 'trac-crypto-api'
|
|
19
15
|
import { EventType } from '../../src/utils/constants.js';
|
|
16
|
+
import { Config } from '../../src/config/config.js';
|
|
20
17
|
let os, fsp;
|
|
21
18
|
|
|
22
19
|
/**
|
|
@@ -69,14 +66,13 @@ export const tick = () => new Promise(resolve => setImmediate(resolve));
|
|
|
69
66
|
|
|
70
67
|
export async function fundPeer(admin, toFund, amount) {
|
|
71
68
|
const txValidity = await admin.msb.state.getIndexerSequenceState()
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
);
|
|
69
|
+
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
70
|
+
.buildCompleteBalanceInitializationMessage(
|
|
71
|
+
admin.wallet.address,
|
|
72
|
+
toFund.wallet.address,
|
|
73
|
+
amount,
|
|
74
|
+
txValidity
|
|
75
|
+
);
|
|
80
76
|
|
|
81
77
|
await admin.msb.state.append(safeEncodeApplyOperation(payload));
|
|
82
78
|
await tick()
|
|
@@ -88,9 +84,10 @@ export async function fundPeer(admin, toFund, amount) {
|
|
|
88
84
|
export async function initMsbPeer(peerName, peerKeyPair, temporaryDirectory, options = {}) {
|
|
89
85
|
const peer = await initDirectoryStructure(peerName, peerKeyPair, temporaryDirectory);
|
|
90
86
|
peer.options = options
|
|
91
|
-
peer.options.
|
|
92
|
-
peer.options.
|
|
93
|
-
|
|
87
|
+
peer.options.storesDirectory = peer.storesDirectory;
|
|
88
|
+
peer.options.storeName = peer.storeName;
|
|
89
|
+
peer.config = createConfig(ENV.DEVELOPMENT, peer.options)
|
|
90
|
+
const msb = new MainSettlementBus(peer.config);
|
|
94
91
|
|
|
95
92
|
peer.msb = msb;
|
|
96
93
|
peer.wallet = msb.wallet;
|
|
@@ -110,10 +107,11 @@ export async function initMsbAdmin(keyPair, temporaryDirectory, options = {}) {
|
|
|
110
107
|
const admin = await initMsbPeer(peerName, keyPair, temporaryDirectory, { ...options, bootstrap: randomBytes(32).toString('hex') });
|
|
111
108
|
|
|
112
109
|
await admin.msb.ready();
|
|
113
|
-
admin.options.bootstrap = admin.msb.state.writingKey;
|
|
110
|
+
admin.options.bootstrap = admin.msb.state.writingKey.toString('hex');
|
|
111
|
+
admin.config = new Config(admin.options, admin.config)
|
|
114
112
|
await admin.msb.close();
|
|
115
113
|
|
|
116
|
-
admin.msb = new MainSettlementBus(admin.
|
|
114
|
+
admin.msb = new MainSettlementBus(admin.config);
|
|
117
115
|
await admin.msb.ready();
|
|
118
116
|
await admin.msb.state.append(null); // before initialization system.indexers is empty, we need to initialize first block to create system.indexers array
|
|
119
117
|
return admin;
|
|
@@ -122,8 +120,10 @@ export async function initMsbAdmin(keyPair, temporaryDirectory, options = {}) {
|
|
|
122
120
|
export async function setupMsbAdmin(keyPair, temporaryDirectory, options = {}) {
|
|
123
121
|
const admin = await initMsbAdmin(keyPair, temporaryDirectory, options);
|
|
124
122
|
const txValidity = await admin.msb.state.getIndexerSequenceState();
|
|
125
|
-
const
|
|
126
|
-
|
|
123
|
+
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
124
|
+
.buildCompleteAddAdminMessage(admin.wallet.address, admin.msb.state.writingKey, txValidity);
|
|
125
|
+
|
|
126
|
+
await admin.msb.state.append(safeEncodeApplyOperation(payload));
|
|
127
127
|
await tick();
|
|
128
128
|
return admin;
|
|
129
129
|
}
|
|
@@ -133,22 +133,25 @@ export async function setupNodeAsWriter(admin, writerCandidate) {
|
|
|
133
133
|
await setupWhitelist(admin, [writerCandidate.wallet.address]); // ensure if is whitelisted
|
|
134
134
|
|
|
135
135
|
const validity = await admin.msb.getIndexerSequenceState()
|
|
136
|
-
const req = await
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
const req = await applyStateMessageFactory(writerCandidate.wallet, admin.config)
|
|
137
|
+
.buildPartialAddWriterMessage(
|
|
138
|
+
writerCandidate.wallet.address,
|
|
139
|
+
b4a.toString(writerCandidate.msb.state.writingKey, 'hex'),
|
|
140
|
+
b4a.toString(validity, 'hex'),
|
|
141
|
+
'json'
|
|
142
|
+
);
|
|
140
143
|
|
|
141
144
|
await waitWritable(admin, writerCandidate, async () => {
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
await admin.msb.state.append(
|
|
145
|
+
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
146
|
+
.buildCompleteAddWriterMessage(
|
|
147
|
+
admin.wallet.address,
|
|
148
|
+
b4a.from(req.rao.tx, 'hex'),
|
|
149
|
+
b4a.from(req.rao.txv, 'hex'),
|
|
150
|
+
b4a.from(req.rao.iw, 'hex'),
|
|
151
|
+
b4a.from(req.rao.in, 'hex'),
|
|
152
|
+
b4a.from(req.rao.is, 'hex')
|
|
153
|
+
);
|
|
154
|
+
await admin.msb.state.append(safeEncodeApplyOperation(payload))
|
|
152
155
|
})
|
|
153
156
|
|
|
154
157
|
return writerCandidate;
|
|
@@ -168,22 +171,25 @@ export async function promoteToWriter(admin, writerCandidate) {
|
|
|
168
171
|
isIndexer: false,
|
|
169
172
|
})
|
|
170
173
|
const validity = await admin.msb.state.getIndexerSequenceState()
|
|
171
|
-
const req = await
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
const req = await applyStateMessageFactory(writerCandidate.wallet, writerCandidate.config)
|
|
175
|
+
.buildPartialAddWriterMessage(
|
|
176
|
+
writerCandidate.wallet.address,
|
|
177
|
+
b4a.toString(writerCandidate.msb.state.writingKey, 'hex'),
|
|
178
|
+
b4a.toString(validity, 'hex'),
|
|
179
|
+
'json'
|
|
180
|
+
);
|
|
175
181
|
|
|
176
182
|
await waitWritable(writerCandidate, writerCandidate, async () => {
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
await admin.msb.state.append(
|
|
183
|
+
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
184
|
+
.buildCompleteAddWriterMessage(
|
|
185
|
+
req.address,
|
|
186
|
+
b4a.from(req.rao.tx, 'hex'),
|
|
187
|
+
b4a.from(req.rao.txv, 'hex'),
|
|
188
|
+
b4a.from(req.rao.iw, 'hex'),
|
|
189
|
+
b4a.from(req.rao.in, 'hex'),
|
|
190
|
+
b4a.from(req.rao.is, 'hex')
|
|
191
|
+
);
|
|
192
|
+
await admin.msb.state.append(safeEncodeApplyOperation(payload))
|
|
187
193
|
})
|
|
188
194
|
|
|
189
195
|
return writerCandidate;
|
|
@@ -201,9 +207,11 @@ export async function setupMsbWriter(admin, peerName, peerKeyPair, temporaryDire
|
|
|
201
207
|
|
|
202
208
|
export async function setupMsbIndexer(indexerCandidate, admin) {
|
|
203
209
|
try {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
210
|
+
const validity = await admin.msb.state.getIndexerSequenceState()
|
|
211
|
+
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
212
|
+
.buildCompleteAddIndexerMessage(admin.wallet.address, indexerCandidate.wallet.address, validity);
|
|
213
|
+
|
|
214
|
+
await admin.msb.state.append(safeEncodeApplyOperation(payload));
|
|
207
215
|
await tick(); // wait for the request to be processed
|
|
208
216
|
|
|
209
217
|
const isIndexer = async () => {
|
|
@@ -211,7 +219,7 @@ export async function setupMsbIndexer(indexerCandidate, admin) {
|
|
|
211
219
|
if (!indexersEntry) {
|
|
212
220
|
return false;
|
|
213
221
|
}
|
|
214
|
-
const formatted = formatIndexersEntry(indexersEntry);
|
|
222
|
+
const formatted = formatIndexersEntry(indexersEntry, admin.config.addressLength);
|
|
215
223
|
if (!formatted || !formatted.addresses) return false;
|
|
216
224
|
return formatted.addresses.includes(indexerCandidate.wallet.address);
|
|
217
225
|
}
|
|
@@ -254,11 +262,13 @@ export async function setupWhitelist(admin, whitelistAddresses) {
|
|
|
254
262
|
fileUtils.readAddressesFromWhitelistFile = async () => whitelistAddresses;
|
|
255
263
|
const validity = await admin.msb.state.getIndexerSequenceState()
|
|
256
264
|
for (const address of whitelistAddresses) {
|
|
257
|
-
const
|
|
258
|
-
|
|
265
|
+
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
266
|
+
.buildCompleteAppendWhitelistMessage(admin.wallet.address, address, validity);
|
|
267
|
+
|
|
268
|
+
await admin.msb.state.append(safeEncodeApplyOperation(payload));
|
|
259
269
|
await sleep(100)
|
|
260
270
|
}
|
|
261
|
-
|
|
271
|
+
|
|
262
272
|
fileUtils.readAddressesFromWhitelistFile = originalReadAddressesFromWhitelistFile;
|
|
263
273
|
}
|
|
264
274
|
|
|
@@ -306,24 +316,26 @@ export async function initDirectoryStructure(peerName, keyPair, temporaryDirecto
|
|
|
306
316
|
export const deployExternalBootstrap = async (writer, externalNode) => {
|
|
307
317
|
const externalBootstrap = randomBytes(32).toString('hex');
|
|
308
318
|
const txValidity = await writer.msb.state.getIndexerSequenceState();
|
|
309
|
-
const payload = await
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
319
|
+
const payload = await applyStateMessageFactory(externalNode.msb.wallet, admin.config)
|
|
320
|
+
.buildPartialBootstrapDeploymentMessage(
|
|
321
|
+
externalNode.msb.wallet.address,
|
|
322
|
+
externalBootstrap,
|
|
323
|
+
randomBytes(32).toString('hex'),
|
|
324
|
+
txValidity.toString('hex'),
|
|
325
|
+
'json'
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
const rawPayload = await applyStateMessageFactory(writer.msb.wallet, admin.config)
|
|
329
|
+
.buildCompleteBootstrapDeploymentMessage(
|
|
330
|
+
payload.address,
|
|
331
|
+
b4a.from(payload.bdo.tx, 'hex'),
|
|
332
|
+
b4a.from(payload.bdo.txv, 'hex'),
|
|
333
|
+
b4a.from(payload.bdo.bs, 'hex'),
|
|
334
|
+
b4a.from(payload.bdo.ic, 'hex'),
|
|
335
|
+
b4a.from(payload.bdo.in, 'hex'),
|
|
336
|
+
b4a.from(payload.bdo.is, 'hex'),
|
|
337
|
+
)
|
|
338
|
+
await writer.msb.state.base.append(safeEncodeApplyOperation(rawPayload))
|
|
327
339
|
await tick()
|
|
328
340
|
await waitForHash(writer, payload.bdo.tx)
|
|
329
341
|
return externalBootstrap
|
|
@@ -343,30 +355,33 @@ export const generatePostTx = async (writer, externalNode, externalContractBoots
|
|
|
343
355
|
}
|
|
344
356
|
};
|
|
345
357
|
|
|
346
|
-
const contentHash = await
|
|
358
|
+
const contentHash = await PeerWallet.blake3(JSON.stringify(testObj));
|
|
347
359
|
const validity = await writer.msb.state.getIndexerSequenceState()
|
|
348
|
-
const tx = await
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
writer.wallet,
|
|
359
|
-
tx.address,
|
|
360
|
-
b4a.from(tx.txo.tx, 'hex'),
|
|
361
|
-
b4a.from(tx.txo.txv, 'hex'),
|
|
362
|
-
b4a.from(tx.txo.iw, 'hex'),
|
|
363
|
-
b4a.from(tx.txo.in, 'hex'),
|
|
364
|
-
b4a.from(tx.txo.ch, 'hex'),
|
|
365
|
-
b4a.from(tx.txo.is, 'hex'),
|
|
366
|
-
b4a.from(tx.txo.bs, 'hex'),
|
|
367
|
-
b4a.from(tx.txo.mbs, 'hex')
|
|
368
|
-
);
|
|
360
|
+
const tx = await applyStateMessageFactory(externalNode.wallet, admin.config)
|
|
361
|
+
.buildPartialTransactionOperationMessage(
|
|
362
|
+
externalNode.wallet.address,
|
|
363
|
+
peerWriterKey,
|
|
364
|
+
b4a.toString(validity, 'hex'),
|
|
365
|
+
b4a.toString(contentHash, 'hex'),
|
|
366
|
+
externalContractBootstrap,
|
|
367
|
+
b4a.toString(writer.msb.bootstrap, 'hex'),
|
|
368
|
+
'json'
|
|
369
|
+
)
|
|
369
370
|
|
|
371
|
+
const postTxPayload = await applyStateMessageFactory(writer.wallet, admin.config)
|
|
372
|
+
.buildCompleteTransactionOperationMessage(
|
|
373
|
+
tx.address,
|
|
374
|
+
b4a.from(tx.txo.tx, 'hex'),
|
|
375
|
+
b4a.from(tx.txo.txv, 'hex'),
|
|
376
|
+
b4a.from(tx.txo.iw, 'hex'),
|
|
377
|
+
b4a.from(tx.txo.in, 'hex'),
|
|
378
|
+
b4a.from(tx.txo.ch, 'hex'),
|
|
379
|
+
b4a.from(tx.txo.is, 'hex'),
|
|
380
|
+
b4a.from(tx.txo.bs, 'hex'),
|
|
381
|
+
b4a.from(tx.txo.mbs, 'hex')
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
const postTx = safeEncodeApplyOperation(postTxPayload);
|
|
370
385
|
return { postTx, txHash: tx.txo.tx };
|
|
371
386
|
}
|
|
372
387
|
|
|
@@ -404,7 +419,6 @@ export const tryToSyncWriters = async (...args) => {
|
|
|
404
419
|
}
|
|
405
420
|
}
|
|
406
421
|
|
|
407
|
-
|
|
408
422
|
export async function waitForNotIndexer(indexer) {
|
|
409
423
|
try {
|
|
410
424
|
let attempts = 0;
|
|
@@ -417,7 +431,7 @@ export async function waitForNotIndexer(indexer) {
|
|
|
417
431
|
if (!indexersEntry) {
|
|
418
432
|
notIndexer = true;
|
|
419
433
|
} else {
|
|
420
|
-
const formatted = formatIndexersEntry(indexersEntry);
|
|
434
|
+
const formatted = formatIndexersEntry(indexersEntry, admin.config.addressLength);
|
|
421
435
|
if (!formatted || !formatted.addresses) {
|
|
422
436
|
notIndexer = true;
|
|
423
437
|
} else if (!formatted.addresses.includes(indexer.wallet.address)) {
|
|
@@ -564,7 +578,7 @@ export async function waitForIndexersEntry(node, expected) {
|
|
|
564
578
|
await sleep(250);
|
|
565
579
|
continue;
|
|
566
580
|
}
|
|
567
|
-
const formatted = formatIndexersEntry(indexersEntry);
|
|
581
|
+
const formatted = formatIndexersEntry(indexersEntry, admin.config.addressLength);
|
|
568
582
|
if (formatted && formatted.addresses && formatted.addresses.includes(expected.address)) {
|
|
569
583
|
break;
|
|
570
584
|
}
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import b4a from "b4a";
|
|
2
2
|
import tracCrypto from "trac-crypto-api";
|
|
3
|
-
|
|
3
|
+
import PeerWallet from "trac-wallet";
|
|
4
4
|
import { $TNK } from "../../src/core/state/utils/balance.js";
|
|
5
5
|
import { createMessage } from "../../src/utils/buffer.js";
|
|
6
|
-
import {
|
|
7
|
-
import { OperationType, NETWORK_ID } from "../../src/utils/constants.js";
|
|
6
|
+
import { OperationType } from "../../src/utils/constants.js";
|
|
8
7
|
import { addressToBuffer } from "../../src/core/state/utils/address.js";
|
|
8
|
+
import { config } from '../helpers/config.js'
|
|
9
|
+
import { sleep } from "../../src/utils/helpers.js";
|
|
10
|
+
|
|
11
|
+
export const waitForConnection = async node => {
|
|
12
|
+
let attempts = 0
|
|
13
|
+
while (attempts < 60) {
|
|
14
|
+
const count = node.network.validatorConnectionManager.connectionCount()
|
|
15
|
+
if (count > 0) {
|
|
16
|
+
break
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
await sleep(300);
|
|
20
|
+
attempts++;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
9
23
|
|
|
10
24
|
/**
|
|
11
25
|
* Build a base64-encoded transfer payload and matching tx hash
|
|
@@ -15,18 +29,18 @@ import { addressToBuffer } from "../../src/core/state/utils/address.js";
|
|
|
15
29
|
* PartialOperation.validateSignature, so that tests broadcast
|
|
16
30
|
* transactions the node will accept without touching consensus code.
|
|
17
31
|
*
|
|
18
|
-
* @param {
|
|
32
|
+
* @param {object} context - General context
|
|
19
33
|
* @param {import("../../src/core/state/State.js").default} state - MSB state instance.
|
|
20
34
|
* @param {bigint} [amountTnk=1n] - Transfer amount in TNK units.
|
|
21
35
|
* @returns {Promise<{ payload: string, txHashHex: string }>}
|
|
22
36
|
*/
|
|
23
|
-
export async function buildRpcSelfTransferPayload(
|
|
37
|
+
export async function buildRpcSelfTransferPayload(context, state, amountTnk = 1n) {
|
|
24
38
|
const txvBuffer = await state.getIndexerSequenceState();
|
|
25
39
|
const txvHex = b4a.toString(txvBuffer, "hex");
|
|
26
40
|
|
|
27
41
|
const txData = await tracCrypto.transaction.preBuild(
|
|
28
|
-
wallet.address,
|
|
29
|
-
wallet.address,
|
|
42
|
+
context.wallet.address,
|
|
43
|
+
context.wallet.address,
|
|
30
44
|
b4a.toString($TNK(amountTnk), "hex"),
|
|
31
45
|
txvHex
|
|
32
46
|
);
|
|
@@ -38,10 +52,10 @@ export async function buildRpcSelfTransferPayload(wallet, state, amountTnk = 1n)
|
|
|
38
52
|
const txvBuf = b4a.from(txData.validity, "hex");
|
|
39
53
|
const nonceBuf = b4a.from(nonceHex, "hex");
|
|
40
54
|
const amountBuf = b4a.from(amountHex, "hex");
|
|
41
|
-
const toBuf = addressToBuffer(toAddress);
|
|
55
|
+
const toBuf = addressToBuffer(toAddress, config.addressPrefix);
|
|
42
56
|
|
|
43
57
|
const message = createMessage(
|
|
44
|
-
|
|
58
|
+
config.networkId,
|
|
45
59
|
txvBuf,
|
|
46
60
|
toBuf,
|
|
47
61
|
amountBuf,
|
|
@@ -49,12 +63,12 @@ export async function buildRpcSelfTransferPayload(wallet, state, amountTnk = 1n)
|
|
|
49
63
|
OperationType.TRANSFER
|
|
50
64
|
);
|
|
51
65
|
|
|
52
|
-
const messageHash = await
|
|
53
|
-
const signature = wallet.sign(messageHash);
|
|
66
|
+
const messageHash = await PeerWallet.blake3(message);
|
|
67
|
+
const signature = context.wallet.sign(messageHash);
|
|
54
68
|
|
|
55
69
|
const payloadObject = {
|
|
56
70
|
type: OperationType.TRANSFER,
|
|
57
|
-
address: wallet.address,
|
|
71
|
+
address: context.wallet.address,
|
|
58
72
|
tro: {
|
|
59
73
|
tx: b4a.toString(messageHash, "hex"),
|
|
60
74
|
txv: txData.validity,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { default as test } from 'brittle';
|
|
2
|
+
|
|
3
|
+
async function runMsgUtilsTests() {
|
|
4
|
+
test.pause();
|
|
5
|
+
await import('./network/NetworkMessageBuilder.test.js');
|
|
6
|
+
await import('./network/NetworkMessageDirector.test.js');
|
|
7
|
+
await import('./state/applyStateMessageBuilder.complete.test.js');
|
|
8
|
+
await import('./state/applyStateMessageBuilder.partial.test.js');
|
|
9
|
+
test.resume();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
await runMsgUtilsTests();
|