trac-msb 0.2.12 → 0.2.13
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/package.json +9 -4
- package/proto/network/v1/enums/message_type.proto +16 -0
- package/proto/network/v1/enums/result_code.proto +84 -0
- package/proto/network/v1/messages/broadcast_transaction_request.proto +9 -0
- package/proto/network/v1/messages/broadcast_transaction_response.proto +13 -0
- package/proto/network/v1/messages/liveness_request.proto +8 -0
- package/proto/network/v1/messages/liveness_response.proto +11 -0
- package/proto/network/v1/network_message.proto +22 -0
- package/rpc/rpc_services.js +22 -4
- package/scripts/generate-protobufs.js +37 -12
- package/src/config/config.js +26 -5
- package/src/config/env.js +25 -11
- package/src/core/network/Network.js +73 -36
- 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 +14 -2
- 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 +88 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +25 -19
- package/src/core/network/protocols/{shared/handlers/base/BaseOperationHandler.js → legacy/handlers/BaseStateOperationHandler.js} +23 -12
- package/src/core/network/protocols/legacy/handlers/{GetRequestHandler.js → LegacyGetRequestHandler.js} +6 -6
- package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +23 -0
- package/src/core/network/protocols/{shared/handlers/RoleOperationHandler.js → legacy/handlers/LegacyRoleOperationHandler.js} +18 -11
- package/src/core/network/protocols/{shared/handlers/SubnetworkOperationHandler.js → legacy/handlers/LegacySubnetworkOperationHandler.js} +28 -17
- package/src/core/network/protocols/{shared/handlers/TransferOperationHandler.js → legacy/handlers/LegacyTransferOperationHandler.js} +17 -11
- package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +27 -0
- 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} +47 -25
- 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} +26 -9
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +91 -7
- package/src/core/network/protocols/v1/V1ProtocolError.js +91 -0
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +65 -0
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +389 -0
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +87 -0
- package/src/core/network/protocols/v1/validators/V1BaseOperation.js +211 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +26 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +276 -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 +146 -94
- package/src/core/network/services/MessageOrchestrator.js +151 -27
- package/src/core/network/services/PendingRequestService.js +172 -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 +52 -34
- package/src/core/network/services/ValidatorHealthCheckService.js +127 -0
- package/src/core/network/services/ValidatorObserverService.js +18 -26
- package/src/core/state/State.js +70 -19
- package/src/index.js +5 -4
- package/src/messages/network/v1/NetworkMessageBuilder.js +59 -79
- package/src/messages/network/v1/NetworkMessageDirector.js +16 -50
- package/src/utils/Scheduler.js +0 -8
- package/src/utils/constants.js +71 -5
- package/src/utils/deepEqualApplyPayload.js +40 -0
- package/src/utils/helpers.js +10 -1
- package/src/utils/logger.js +25 -0
- 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/tests/acceptance/v1/account/account.test.mjs +8 -2
- package/tests/acceptance/v1/tx/tx.test.mjs +23 -1
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +34 -6
- package/tests/fixtures/networkV1.fixtures.js +2 -28
- package/tests/helpers/transactionPayloads.mjs +2 -2
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +239 -79
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +223 -77
- package/tests/unit/network/LegacyNetworkMessageRouter.test.js +54 -0
- package/tests/unit/network/ProtocolSession.test.js +127 -0
- package/tests/unit/network/networkModule.test.js +4 -1
- package/tests/unit/network/services/ConnectionManager.test.js +450 -0
- package/tests/unit/network/services/MessageOrchestrator.test.js +445 -0
- package/tests/unit/network/services/PendingRequestService.test.js +431 -0
- package/tests/unit/network/services/TransactionCommitService.test.js +246 -0
- package/tests/unit/network/services/TransactionPoolService.test.js +489 -0
- package/tests/unit/network/services/TransactionRateLimiterService.test.js +139 -0
- package/tests/unit/network/services/ValidatorHealthCheckService.test.js +115 -0
- package/tests/unit/network/services/services.test.js +17 -0
- package/tests/unit/network/utils/v1TestUtils.js +153 -0
- package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +151 -0
- package/tests/unit/network/v1/V1BaseOperation.test.js +356 -0
- package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +129 -0
- package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +53 -0
- package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +512 -0
- package/tests/unit/network/v1/V1LivenessRequest.test.js +32 -0
- package/tests/unit/network/v1/V1LivenessResponse.test.js +45 -0
- package/tests/unit/network/v1/V1ResultCode.test.js +84 -0
- package/tests/unit/network/v1/V1ValidationSchema.test.js +13 -0
- package/tests/unit/network/v1/connectionPolicies.test.js +49 -0
- package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +284 -0
- package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +794 -0
- package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +193 -0
- package/tests/unit/network/v1/v1.handlers.test.js +15 -0
- package/tests/unit/network/v1/v1.test.js +19 -0
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +119 -0
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +136 -0
- package/tests/unit/network/v1/v1ValidationSchema/common.test.js +308 -0
- package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +90 -0
- package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +133 -0
- package/tests/unit/unit.test.js +2 -2
- package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +102 -0
- package/tests/unit/utils/protobuf/operationHelpers.test.js +2 -4
- package/tests/unit/utils/utils.test.js +1 -0
- 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/proto/network.proto +0 -74
- package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +0 -37
- package/src/utils/protobuf/network.cjs +0 -840
- package/tests/unit/network/ConnectionManager.test.js +0 -191
package/src/utils/helpers.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import b4a from "b4a";
|
|
2
|
+
import PeerWallet from "trac-wallet";
|
|
2
3
|
import {bufferToAddress} from "../core/state/utils/address.js";
|
|
3
4
|
import { EntryType } from "./constants.js";
|
|
4
|
-
|
|
5
|
+
import { v7 as uuidv7 } from 'uuid';
|
|
5
6
|
//TODO: change file name or split functions below into multiple files (Remember to update imports and tests accordingly)
|
|
6
7
|
|
|
7
8
|
export function isHexString(string) {
|
|
@@ -95,3 +96,11 @@ export function isTransactionRecordPut(entry) {
|
|
|
95
96
|
const is64 = entry.key.length === 64;
|
|
96
97
|
return isPut && isHex && is64;
|
|
97
98
|
}
|
|
99
|
+
|
|
100
|
+
export function generateUUID() {
|
|
101
|
+
return uuidv7();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function publicKeyToAddress(publicKey, config) {
|
|
105
|
+
return PeerWallet.encodeBech32m(config.addressPrefix, b4a.isBuffer(publicKey) ? publicKey : b4a.from(publicKey, typeof publicKey === 'string' ? 'hex' : undefined));
|
|
106
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class Logger {
|
|
2
|
+
#config
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.#config = config;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
info(message) {
|
|
8
|
+
console.log("i: " + message);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
debug(message) {
|
|
12
|
+
if (this.#config.debug) {
|
|
13
|
+
console.debug("d: " + message);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
error(message) {
|
|
18
|
+
console.error("e: " + message);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
warn(message) {
|
|
22
|
+
console.warn("w: " + message);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
package/src/utils/normalizers.js
CHANGED
|
@@ -3,6 +3,7 @@ import { normalizeHex } from './helpers.js';
|
|
|
3
3
|
import { addressToBuffer, bufferToAddress } from '../core/state/utils/address.js';
|
|
4
4
|
import b4a from 'b4a';
|
|
5
5
|
import { bufferToBigInt } from './amountSerialization.js'
|
|
6
|
+
import {isBootstrapDeployment, isRoleAccess, isTransaction, isTransfer} from './applyOperations.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Normalizes the payload for a transfer operation.
|
|
@@ -199,3 +200,40 @@ export function normalizeBootstrapDeploymentOperation(payload, config) {
|
|
|
199
200
|
bdo: normalizedBdo
|
|
200
201
|
};
|
|
201
202
|
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Normalizes an incoming partial operation message based on its operation type.
|
|
206
|
+
*
|
|
207
|
+
* @param {Object} message The raw incoming message.
|
|
208
|
+
* @param {object} config The environment configuration object.
|
|
209
|
+
* @returns {Object} Normalized payload.
|
|
210
|
+
* @throws {Error} If message is invalid or operation type is unsupported.
|
|
211
|
+
*/
|
|
212
|
+
export function normalizeMessageByOperationType(message, config) {
|
|
213
|
+
if (!message || typeof message !== 'object') {
|
|
214
|
+
throw new Error('Invalid message for normalization.');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const { type } = message;
|
|
218
|
+
if (!Number.isInteger(type) || type <= 0) {
|
|
219
|
+
throw new Error('Message type is missing or invalid.');
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (isRoleAccess(type)) {
|
|
223
|
+
return normalizeRoleAccessOperation(message, config);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (isTransaction(type)) {
|
|
227
|
+
return normalizeTransactionOperation(message, config);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (isBootstrapDeployment(type)) {
|
|
231
|
+
return normalizeBootstrapDeploymentOperation(message, config);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (isTransfer(type)) {
|
|
235
|
+
return normalizeTransferOperation(message, config);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
throw new Error(`Unsupported operation type for normalization: ${type}`);
|
|
239
|
+
}
|