trac-msb 0.2.8 → 0.2.10

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.
Files changed (151) hide show
  1. package/.github/workflows/acceptance-tests.yml +7 -11
  2. package/.github/workflows/lint-pr-title.yml +26 -0
  3. package/.github/workflows/unit-tests.yml +2 -8
  4. package/CODE_OF_CONDUCT.md +128 -0
  5. package/README.md +33 -18
  6. package/docker-compose.yml +1 -0
  7. package/docs/trac_network_http_api.openapi.yaml +889 -0
  8. package/msb.mjs +5 -22
  9. package/package.json +14 -10
  10. package/proto/network.proto +74 -0
  11. package/rpc/create_server.js +2 -2
  12. package/rpc/handlers.js +165 -92
  13. package/rpc/routes/v1.js +3 -1
  14. package/rpc/rpc_server.js +4 -4
  15. package/rpc/rpc_services.js +62 -25
  16. package/rpc/utils/helpers.js +83 -52
  17. package/src/config/args.js +46 -0
  18. package/src/config/config.js +78 -5
  19. package/src/config/env.js +70 -3
  20. package/src/core/network/Network.js +34 -70
  21. package/src/core/network/identity/NetworkWalletFactory.js +2 -2
  22. package/src/core/network/protocols/LegacyProtocol.js +67 -0
  23. package/src/core/network/protocols/NetworkMessages.js +48 -0
  24. package/src/core/network/protocols/ProtocolInterface.js +31 -0
  25. package/src/core/network/protocols/ProtocolSession.js +59 -0
  26. package/src/core/network/protocols/V1Protocol.js +64 -0
  27. package/src/core/network/protocols/legacy/NetworkMessageRouter.js +84 -0
  28. package/src/core/network/protocols/legacy/handlers/GetRequestHandler.js +53 -0
  29. package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +37 -0
  30. package/src/core/network/{messaging → protocols/legacy}/validators/base/BaseResponse.js +2 -3
  31. package/src/core/network/protocols/shared/handlers/RoleOperationHandler.js +88 -0
  32. package/src/core/network/protocols/shared/handlers/SubnetworkOperationHandler.js +93 -0
  33. package/src/core/network/{messaging → protocols/shared}/handlers/TransferOperationHandler.js +17 -16
  34. package/src/core/network/{messaging → protocols/shared}/handlers/base/BaseOperationHandler.js +10 -15
  35. package/src/core/network/{messaging → protocols/shared}/validators/PartialBootstrapDeployment.js +2 -2
  36. package/src/core/network/{messaging → protocols/shared}/validators/PartialRoleAccess.js +5 -5
  37. package/src/core/network/{messaging → protocols/shared}/validators/PartialTransaction.js +4 -4
  38. package/src/core/network/{messaging → protocols/shared}/validators/PartialTransfer.js +4 -4
  39. package/src/core/network/{messaging → protocols/shared}/validators/base/PartialOperation.js +14 -12
  40. package/src/core/network/protocols/v1/NetworkMessageRouter.js +15 -0
  41. package/src/core/network/services/ConnectionManager.js +5 -5
  42. package/src/core/network/services/MessageOrchestrator.js +2 -2
  43. package/src/core/network/services/TransactionPoolService.js +5 -6
  44. package/src/core/network/services/TransactionRateLimiterService.js +12 -13
  45. package/src/core/network/services/ValidatorObserverService.js +5 -6
  46. package/src/core/state/State.js +3 -5
  47. package/src/index.js +156 -181
  48. package/src/messages/network/v1/NetworkMessageBuilder.js +325 -0
  49. package/src/messages/network/v1/NetworkMessageDirector.js +137 -0
  50. package/src/messages/network/v1/networkMessageFactory.js +12 -0
  51. package/src/messages/state/ApplyStateMessageBuilder.js +661 -0
  52. package/src/messages/state/ApplyStateMessageDirector.js +516 -0
  53. package/src/messages/state/applyStateMessageFactory.js +12 -0
  54. package/src/utils/buffer.js +53 -1
  55. package/src/utils/check.js +1 -1
  56. package/src/utils/cli.js +0 -8
  57. package/src/utils/constants.js +33 -30
  58. package/src/utils/fileUtils.js +13 -0
  59. package/src/utils/normalizers.js +84 -2
  60. package/src/utils/protobuf/network.cjs +840 -0
  61. package/src/utils/protobuf/operationHelpers.js +10 -0
  62. package/src/utils/type.js +26 -0
  63. package/tests/acceptance/v1/balance/balance.test.mjs +1 -2
  64. package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +26 -30
  65. package/tests/acceptance/v1/health/health.test.mjs +33 -0
  66. package/tests/acceptance/v1/rpc.test.mjs +4 -3
  67. package/tests/acceptance/v1/tx/tx.test.mjs +27 -16
  68. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +26 -12
  69. package/tests/fixtures/check.fixtures.js +33 -32
  70. package/tests/fixtures/networkV1.fixtures.js +85 -0
  71. package/tests/fixtures/protobuf.fixtures.js +109 -25
  72. package/tests/helpers/StateNetworkFactory.js +2 -2
  73. package/tests/helpers/address.js +6 -0
  74. package/tests/helpers/autobaseTestHelpers.js +2 -1
  75. package/tests/helpers/config.js +2 -1
  76. package/tests/helpers/setupApplyTests.js +59 -56
  77. package/tests/unit/messages/messages.test.js +12 -0
  78. package/tests/unit/messages/network/NetworkMessageBuilder.test.js +276 -0
  79. package/tests/unit/messages/network/NetworkMessageDirector.test.js +201 -0
  80. package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +521 -0
  81. package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +233 -0
  82. package/tests/unit/network/ConnectionManager.test.js +6 -5
  83. package/tests/unit/network/networkModule.test.js +3 -2
  84. package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +10 -6
  85. package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +9 -6
  86. package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +10 -7
  87. package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +18 -21
  88. package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +53 -38
  89. package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +46 -35
  90. package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +13 -16
  91. package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +17 -11
  92. package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +11 -12
  93. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +9 -7
  94. package/tests/unit/state/apply/common/commonScenarioHelper.js +15 -14
  95. package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +9 -4
  96. package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +17 -11
  97. package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +19 -14
  98. package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +37 -29
  99. package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +9 -7
  100. package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +11 -9
  101. package/tests/unit/unit.test.js +1 -1
  102. package/tests/unit/utils/buffer/buffer.test.js +62 -1
  103. package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +4 -3
  104. package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +3 -2
  105. package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +3 -2
  106. package/tests/unit/utils/normalizers/normalizers.test.js +469 -0
  107. package/tests/unit/utils/protobuf/operationHelpers.test.js +120 -2
  108. package/tests/unit/utils/type/type.test.js +25 -0
  109. package/tests/unit/utils/utils.test.js +1 -0
  110. package/docs/networking-dualstack-plan.md +0 -75
  111. package/docs/networking-layer-redesign.md +0 -155
  112. package/src/core/network/messaging/NetworkMessages.js +0 -64
  113. package/src/core/network/messaging/handlers/GetRequestHandler.js +0 -113
  114. package/src/core/network/messaging/handlers/ResponseHandler.js +0 -107
  115. package/src/core/network/messaging/handlers/RoleOperationHandler.js +0 -114
  116. package/src/core/network/messaging/handlers/SubnetworkOperationHandler.js +0 -149
  117. package/src/core/network/messaging/routes/NetworkMessageRouter.js +0 -98
  118. package/src/core/network/messaging/validators/AdminResponse.js +0 -58
  119. package/src/core/network/messaging/validators/CustomNodeResponse.js +0 -46
  120. package/src/messages/base/StateBuilder.js +0 -25
  121. package/src/messages/completeStateMessages/CompleteStateMessageBuilder.js +0 -425
  122. package/src/messages/completeStateMessages/CompleteStateMessageDirector.js +0 -252
  123. package/src/messages/completeStateMessages/CompleteStateMessageOperations.js +0 -296
  124. package/src/messages/partialStateMessages/PartialStateMessageBuilder.js +0 -272
  125. package/src/messages/partialStateMessages/PartialStateMessageDirector.js +0 -137
  126. package/src/messages/partialStateMessages/PartialStateMessageOperations.js +0 -138
  127. package/tests/integration/apply/addAdmin/addAdminBasic.test.js +0 -69
  128. package/tests/integration/apply/addAdmin/addAdminRecovery.test.js +0 -126
  129. package/tests/integration/apply/addIndexer.test.js +0 -239
  130. package/tests/integration/apply/addWhitelist.test.js +0 -53
  131. package/tests/integration/apply/addWriter.test.js +0 -245
  132. package/tests/integration/apply/apply.test.js +0 -19
  133. package/tests/integration/apply/banValidator.test.js +0 -116
  134. package/tests/integration/apply/postTx/invalidSubValues.test.js +0 -103
  135. package/tests/integration/apply/postTx/postTx.test.js +0 -196
  136. package/tests/integration/apply/removeIndexer.test.js +0 -132
  137. package/tests/integration/apply/removeWriter.test.js +0 -168
  138. package/tests/integration/apply/transfer.test.js +0 -83
  139. package/tests/integration/integration.test.js +0 -9
  140. package/tests/unit/messageOperations/assembleAddIndexerMessage.test.js +0 -21
  141. package/tests/unit/messageOperations/assembleAddWriterMessage.test.js +0 -17
  142. package/tests/unit/messageOperations/assembleAdminMessage.test.js +0 -68
  143. package/tests/unit/messageOperations/assembleBanWriterMessage.test.js +0 -17
  144. package/tests/unit/messageOperations/assemblePostTransaction.test.js +0 -424
  145. package/tests/unit/messageOperations/assembleRemoveIndexerMessage.test.js +0 -19
  146. package/tests/unit/messageOperations/assembleRemoveWriterMessage.test.js +0 -17
  147. package/tests/unit/messageOperations/assembleWhitelistMessages.test.js +0 -59
  148. package/tests/unit/messageOperations/commonsStateMessageOperationsTest.js +0 -278
  149. package/tests/unit/messageOperations/stateMessageOperations.test.js +0 -19
  150. /package/src/core/network/{messaging → protocols/legacy}/validators/ValidatorResponse.js +0 -0
  151. /package/src/utils/{operations.js → applyOperations.js} +0 -0
@@ -4,8 +4,8 @@ import nodeEntryUtils, { setWritingKey } from '../../../../../src/core/state/uti
4
4
  import { EntryType } from '../../../../../src/utils/constants.js';
5
5
  import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
6
6
  import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
7
- import PartialStateMessageOperations from '../../../../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
8
- import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
7
+ import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
8
+ import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
9
9
  import {
10
10
  setupAdminNetwork,
11
11
  initializeBalances,
@@ -90,21 +90,24 @@ export async function buildAdminRecoveryPayload(context) {
90
90
  const { adminPeer, validatorPeer1, newAdminWriterKey } = context.adminRecovery;
91
91
  const txValidity = await deriveIndexerSequenceState(validatorPeer1.base);
92
92
 
93
- const partial = await new PartialStateMessageOperations(adminPeer.wallet, config)
94
- .assembleAdminRecoveryMessage(
93
+ const partial = await applyStateMessageFactory(adminPeer.wallet, config)
94
+ .buildPartialAdminRecoveryMessage(
95
+ adminPeer.wallet.address,
95
96
  b4a.toString(newAdminWriterKey, 'hex'),
96
- b4a.toString(txValidity, 'hex')
97
+ b4a.toString(txValidity, 'hex'),
98
+ 'json'
97
99
  );
98
100
 
99
- return new CompleteStateMessageOperations(validatorPeer1.wallet, config)
100
- .assembleAdminRecoveryMessage(
101
- partial.address,
102
- b4a.from(partial.rao.tx, 'hex'),
103
- b4a.from(partial.rao.txv, 'hex'),
104
- b4a.from(partial.rao.iw, 'hex'),
105
- b4a.from(partial.rao.in, 'hex'),
106
- b4a.from(partial.rao.is, 'hex')
107
- );
101
+ const payload = await applyStateMessageFactory(validatorPeer1.wallet, config)
102
+ .buildCompleteAdminRecoveryMessage(
103
+ partial.address,
104
+ b4a.from(partial.rao.tx, 'hex'),
105
+ b4a.from(partial.rao.txv, 'hex'),
106
+ b4a.from(partial.rao.iw, 'hex'),
107
+ b4a.from(partial.rao.in, 'hex'),
108
+ b4a.from(partial.rao.is, 'hex')
109
+ );
110
+ return safeEncodeApplyOperation(payload);
108
111
  }
109
112
 
110
113
  export async function buildAdminRecoveryPayloadWithTxValidity(context, mutatedTxValidity) {
@@ -113,21 +116,24 @@ export async function buildAdminRecoveryPayloadWithTxValidity(context, mutatedTx
113
116
  }
114
117
 
115
118
  const { adminPeer, validatorPeer1, newAdminWriterKey } = context.adminRecovery;
116
- const partial = await new PartialStateMessageOperations(adminPeer.wallet, config)
117
- .assembleAdminRecoveryMessage(
119
+ const partial = await applyStateMessageFactory(adminPeer.wallet, config)
120
+ .buildPartialAdminRecoveryMessage(
121
+ adminPeer.wallet.address,
118
122
  b4a.toString(newAdminWriterKey, 'hex'),
119
- b4a.toString(mutatedTxValidity, 'hex')
123
+ b4a.toString(mutatedTxValidity, 'hex'),
124
+ 'json'
120
125
  );
121
126
 
122
- return new CompleteStateMessageOperations(validatorPeer1.wallet, config)
123
- .assembleAdminRecoveryMessage(
124
- partial.address,
127
+ const payload = await applyStateMessageFactory(validatorPeer1.wallet, config)
128
+ .buildCompleteAdminRecoveryMessage(
129
+ partial.address,
125
130
  b4a.from(partial.rao.tx, 'hex'),
126
131
  mutatedTxValidity,
127
132
  b4a.from(partial.rao.iw, 'hex'),
128
133
  b4a.from(partial.rao.in, 'hex'),
129
134
  b4a.from(partial.rao.is, 'hex')
130
135
  );
136
+ return safeEncodeApplyOperation(payload);
131
137
  }
132
138
 
133
139
  export async function applyAdminRecovery(context, payload) {
@@ -516,21 +522,26 @@ export async function applyTransferSeries(context, count = TRANSFER_COUNT) {
516
522
 
517
523
  async function buildSimpleTransferPayload({ requesterPeer, validatorPeer, recipientPeer, amount }) {
518
524
  const txValidity = await deriveIndexerSequenceState(validatorPeer.base);
519
- const partial = await new PartialStateMessageOperations(requesterPeer.wallet, config).assembleTransferOperationMessage(
520
- recipientPeer.wallet.address,
521
- b4a.toString(amount, 'hex'),
522
- b4a.toString(txValidity, 'hex')
523
- );
524
-
525
- return new CompleteStateMessageOperations(validatorPeer.wallet, config).assembleCompleteTransferOperationMessage(
526
- partial.address,
527
- b4a.from(partial.tro.tx, 'hex'),
528
- b4a.from(partial.tro.txv, 'hex'),
529
- b4a.from(partial.tro.in, 'hex'),
530
- partial.tro.to,
531
- b4a.from(partial.tro.am, 'hex'),
532
- b4a.from(partial.tro.is, 'hex')
533
- );
525
+ const partial = await applyStateMessageFactory(requesterPeer.wallet, config)
526
+ .buildPartialTransferOperationMessage(
527
+ requesterPeer.wallet.address,
528
+ recipientPeer.wallet.address,
529
+ b4a.toString(amount, 'hex'),
530
+ b4a.toString(txValidity, 'hex'),
531
+ 'json'
532
+ );
533
+
534
+ const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
535
+ .buildCompleteTransferOperationMessage(
536
+ partial.address,
537
+ b4a.from(partial.tro.tx, 'hex'),
538
+ b4a.from(partial.tro.txv, 'hex'),
539
+ b4a.from(partial.tro.in, 'hex'),
540
+ partial.tro.to,
541
+ b4a.from(partial.tro.am, 'hex'),
542
+ b4a.from(partial.tro.is, 'hex')
543
+ );
544
+ return safeEncodeApplyOperation(payload);
534
545
  }
535
546
 
536
547
  export async function assertAdminRecoverySuccessState(t, context, { viewBase } = {}) {
@@ -6,7 +6,7 @@ import {
6
6
  deriveIndexerSequenceState,
7
7
  eventFlush
8
8
  } from '../../../../helpers/autobaseTestHelpers.js';
9
- import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
9
+ import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
10
10
  import { AUTOBASE_VALUE_ENCODING, EntryType } from '../../../../../src/utils/constants.js';
11
11
  import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
12
12
  import nodeEntryUtils, { ZERO_LICENSE } from '../../../../../src/core/state/utils/nodeEntry.js';
@@ -45,11 +45,10 @@ export async function buildAppendWhitelistPayload(context, readerAddress = null)
45
45
  const adminNode = context.adminBootstrap;
46
46
  const targetAddress = readerAddress ?? selectReaderPeer(context).wallet.address;
47
47
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
48
- return new CompleteStateMessageOperations(adminNode.wallet, config)
49
- .assembleAppendWhitelistMessages(
50
- txValidity,
51
- targetAddress
52
- );
48
+ return safeEncodeApplyOperation(
49
+ await applyStateMessageFactory(adminNode.wallet, config)
50
+ .buildCompleteAppendWhitelistMessage(adminNode.wallet.address, targetAddress, txValidity)
51
+ );
53
52
  }
54
53
 
55
54
  export async function buildAppendWhitelistPayloadWithTxValidity(
@@ -59,21 +58,19 @@ export async function buildAppendWhitelistPayloadWithTxValidity(
59
58
  ) {
60
59
  const adminNode = context.adminBootstrap;
61
60
  const targetAddress = readerAddress ?? selectReaderPeer(context).wallet.address;
62
- return new CompleteStateMessageOperations(adminNode.wallet, config)
63
- .assembleAppendWhitelistMessages(
64
- txValidity,
65
- targetAddress
66
- );
61
+ return safeEncodeApplyOperation(
62
+ await applyStateMessageFactory(adminNode.wallet, config)
63
+ .buildCompleteAppendWhitelistMessage(adminNode.wallet.address, targetAddress, txValidity)
64
+ );
67
65
  }
68
66
 
69
67
  export async function buildBanWriterPayload(context, readerAddress) {
70
68
  const adminNode = context.adminBootstrap;
71
69
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
72
- return new CompleteStateMessageOperations(adminNode.wallet, config)
73
- .assembleBanWriterMessage(
74
- readerAddress,
75
- txValidity
76
- );
70
+ return safeEncodeApplyOperation(
71
+ await applyStateMessageFactory(adminNode.wallet, config)
72
+ .buildCompleteBanWriterMessage(adminNode.wallet.address, readerAddress, txValidity)
73
+ );
77
74
  }
78
75
 
79
76
  export function mutateAppendWhitelistPayloadForInvalidSchema(t, validPayload) {
@@ -6,7 +6,7 @@ import {
6
6
  deriveIndexerSequenceState,
7
7
  eventFlush
8
8
  } from '../../../../helpers/autobaseTestHelpers.js';
9
- import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
9
+ import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
10
10
  import { AUTOBASE_VALUE_ENCODING } from '../../../../../src/utils/constants.js';
11
11
  import { toTerm } from '../../../../../src/core/state/utils/balance.js';
12
12
  import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
@@ -42,11 +42,14 @@ async function bootstrapAdmin(context) {
42
42
  export async function buildBalanceInitializationPayload(context, recipientAddress, balanceBuffer) {
43
43
  const adminNode = context.adminBootstrap;
44
44
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
45
- const messages = await new CompleteStateMessageOperations(adminNode.wallet, config).assembleBalanceInitializationMessages(
46
- txValidity,
47
- [[recipientAddress, balanceBuffer]]
48
- );
49
- return messages[0];
45
+ const payload = await applyStateMessageFactory(adminNode.wallet, config)
46
+ .buildCompleteBalanceInitializationMessage(
47
+ adminNode.wallet.address,
48
+ recipientAddress,
49
+ balanceBuffer,
50
+ txValidity
51
+ );
52
+ return safeEncodeApplyOperation(payload);
50
53
  }
51
54
 
52
55
  export async function buildBalanceInitializationPayloadWithTxValidity({
@@ -60,11 +63,14 @@ export async function buildBalanceInitializationPayloadWithTxValidity({
60
63
  }
61
64
 
62
65
  const adminNode = context.adminBootstrap;
63
- const messages = await new CompleteStateMessageOperations(adminNode.wallet, config).assembleBalanceInitializationMessages(
64
- mutatedTxValidity,
65
- [[decoded.bio.ia, decoded.bio.am]]
66
- );
67
- return messages[0];
66
+ const payload = await applyStateMessageFactory(adminNode.wallet, config)
67
+ .buildCompleteBalanceInitializationMessage(
68
+ adminNode.wallet.address,
69
+ decoded.bio.ia,
70
+ decoded.bio.am,
71
+ mutatedTxValidity
72
+ );
73
+ return safeEncodeApplyOperation(payload);
68
74
  }
69
75
 
70
76
  export async function buildDefaultBalanceInitializationPayload(context) {
@@ -1,7 +1,7 @@
1
1
  import b4a from 'b4a';
2
2
  import PeerWallet from 'trac-wallet';
3
3
  import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
4
- import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
4
+ import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
5
5
  import nodeEntryUtils, { ZERO_LICENSE } from '../../../../../src/core/state/utils/nodeEntry.js';
6
6
  import addressUtils from '../../../../../src/core/state/utils/address.js';
7
7
  import lengthEntryUtils from '../../../../../src/core/state/utils/lengthEntry.js';
@@ -62,9 +62,9 @@ export async function buildBanValidatorPayload(
62
62
  /* cover tests */
63
63
  ) {
64
64
  const txValidity = await deriveIndexerSequenceState(adminPeer.base);
65
- return new CompleteStateMessageOperations(adminPeer.wallet, config).assembleBanWriterMessage(
66
- validatorPeer.wallet.address,
67
- txValidity
65
+ return safeEncodeApplyOperation(
66
+ await applyStateMessageFactory(adminPeer.wallet, config)
67
+ .buildCompleteBanWriterMessage(adminPeer.wallet.address, validatorPeer.wallet.address, txValidity)
68
68
  );
69
69
  }
70
70
 
@@ -73,9 +73,9 @@ export async function buildBanValidatorPayloadWithTxValidity(
73
73
  mutatedTxValidity,
74
74
  { adminPeer = context.adminBootstrap, validatorPeer = selectWriterPeer(context) } = {}
75
75
  ) {
76
- return new CompleteStateMessageOperations(adminPeer.wallet, config).assembleBanWriterMessage(
77
- validatorPeer.wallet.address,
78
- mutatedTxValidity
76
+ return safeEncodeApplyOperation(
77
+ await applyStateMessageFactory(adminPeer.wallet, config)
78
+ .buildCompleteBanWriterMessage(adminPeer.wallet.address, validatorPeer.wallet.address, mutatedTxValidity)
79
79
  );
80
80
  }
81
81
 
@@ -339,11 +339,10 @@ export async function promoteValidatorToIndexer(
339
339
  { adminPeer = context.adminBootstrap, validatorPeer = selectWriterPeer(context) } = {}
340
340
  ) {
341
341
  const txValidity = await deriveIndexerSequenceState(adminPeer.base);
342
- const payload = await new CompleteStateMessageOperations(adminPeer.wallet, config)
343
- .assembleAddIndexerMessage(
344
- validatorPeer.wallet.address,
345
- txValidity
346
- );
342
+ const payload = safeEncodeApplyOperation(
343
+ await applyStateMessageFactory(adminPeer.wallet, config)
344
+ .buildCompleteAddIndexerMessage(adminPeer.wallet.address, validatorPeer.wallet.address, txValidity)
345
+ );
347
346
 
348
347
  await adminPeer.base.append(payload);
349
348
  await adminPeer.base.update();
@@ -1,6 +1,5 @@
1
1
  import b4a from 'b4a';
2
- import PartialStateMessageOperations from '../../../../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
3
- import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
2
+ import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
4
3
  import { deriveIndexerSequenceState } from '../../../../helpers/autobaseTestHelpers.js';
5
4
  import {
6
5
  setupAdminNetwork,
@@ -109,15 +108,17 @@ export async function buildBootstrapDeploymentPayload(context, options = {}) {
109
108
  context.bootstrapDeployment?.txValidity ??
110
109
  (await deriveIndexerSequenceState(validatorPeer.base));
111
110
 
112
- const partial = await new PartialStateMessageOperations(deployerPeer.wallet, config)
113
- .assembleBootstrapDeploymentMessage(
111
+ const partial = await applyStateMessageFactory(deployerPeer.wallet, config)
112
+ .buildPartialBootstrapDeploymentMessage(
113
+ deployerPeer.wallet.address,
114
114
  externalBootstrap.toString('hex'),
115
115
  channel.toString('hex'),
116
- txValidity.toString('hex')
116
+ txValidity.toString('hex'),
117
+ 'json'
117
118
  );
118
119
 
119
- return new CompleteStateMessageOperations(validatorPeer.wallet, config)
120
- .assembleCompleteBootstrapDeployment(
120
+ const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
121
+ .buildCompleteBootstrapDeploymentMessage(
121
122
  partial.address,
122
123
  b4a.from(partial.bdo.tx, 'hex'),
123
124
  b4a.from(partial.bdo.txv, 'hex'),
@@ -126,6 +127,7 @@ export async function buildBootstrapDeploymentPayload(context, options = {}) {
126
127
  b4a.from(partial.bdo.in, 'hex'),
127
128
  b4a.from(partial.bdo.is, 'hex')
128
129
  );
130
+ return safeEncodeApplyOperation(payload);
129
131
  }
130
132
 
131
133
  export async function buildBootstrapDeploymentPayloadWithTxValidity(context, txValidity, options = {}) {
@@ -5,7 +5,8 @@ import {
5
5
  deriveIndexerSequenceState,
6
6
  eventFlush
7
7
  } from '../../../../helpers/autobaseTestHelpers.js';
8
- import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
8
+ import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
9
+ import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
9
10
  import { AUTOBASE_VALUE_ENCODING } from '../../../../../src/utils/constants.js';
10
11
  import { buildAddAdminRequesterPayload } from '../addAdmin/addAdminScenarioHelpers.js';
11
12
  import { config } from '../../../../helpers/config.js';
@@ -59,13 +60,16 @@ export async function initializeBalances(context, recipients) {
59
60
  if (!adminNode || !Array.isArray(recipients) || recipients.length === 0) return;
60
61
 
61
62
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
62
- const payloads = await new CompleteStateMessageOperations(adminNode.wallet, config).assembleBalanceInitializationMessages(
63
- txValidity,
64
- recipients
65
- );
66
-
67
- for (const payload of payloads) {
68
- await adminNode.base.append(payload);
63
+ for (const [recipientAddress, balanceBuffer] of recipients) {
64
+ const payload = await applyStateMessageFactory(adminNode.wallet, config)
65
+ .buildCompleteBalanceInitializationMessage(
66
+ adminNode.wallet.address,
67
+ recipientAddress,
68
+ balanceBuffer,
69
+ txValidity
70
+ );
71
+ const encoded = safeEncodeApplyOperation(payload);
72
+ await adminNode.base.append(encoded);
69
73
  await adminNode.base.update();
70
74
  await eventFlush();
71
75
  }
@@ -76,12 +80,9 @@ export async function whitelistAddress(context, address) {
76
80
  if (!adminNode || !address) return;
77
81
 
78
82
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
79
- const payload = await new CompleteStateMessageOperations(adminNode.wallet, config).assembleAppendWhitelistMessages(
80
- txValidity,
81
- address
82
- );
83
-
84
- await adminNode.base.append(payload);
83
+ const payload = await applyStateMessageFactory(adminNode.wallet, config)
84
+ .buildCompleteAppendWhitelistMessage(adminNode.wallet.address, address, txValidity);
85
+ await adminNode.base.append(safeEncodeApplyOperation(payload));
85
86
  await adminNode.base.update();
86
87
  await eventFlush();
87
88
  }
@@ -1,6 +1,7 @@
1
1
  import { eventFlush, deriveIndexerSequenceState } from '../../../../../helpers/autobaseTestHelpers.js';
2
2
  import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
3
- import CompleteStateMessageOperations from '../../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
3
+ import { applyStateMessageFactory } from '../../../../../../src/messages/state/applyStateMessageFactory.js';
4
+ import { safeEncodeApplyOperation } from '../../../../../../src/utils/protobuf/operationHelpers.js';
4
5
  import { config } from '../../../../../helpers/config.js';
5
6
 
6
7
  export default class InitializationDisabledScenario extends OperationValidationScenarioBase {
@@ -34,9 +35,13 @@ async function disableInitializationAndApply(context, invalidPayload) {
34
35
  }
35
36
 
36
37
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
37
- const disablePayload = await new CompleteStateMessageOperations(adminNode.wallet, config).assembleDisableInitializationMessage(
38
- adminNode.base.local.key,
39
- txValidity
38
+ const disablePayload = safeEncodeApplyOperation(
39
+ await applyStateMessageFactory(adminNode.wallet, config)
40
+ .buildCompleteDisableInitializationMessage(
41
+ adminNode.wallet.address,
42
+ adminNode.base.local.key,
43
+ txValidity
44
+ )
40
45
  );
41
46
 
42
47
  await adminNode.base.append(disablePayload);
@@ -6,7 +6,7 @@ import {
6
6
  deriveIndexerSequenceState,
7
7
  eventFlush
8
8
  } from '../../../../helpers/autobaseTestHelpers.js';
9
- import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
9
+ import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
10
10
  import { AUTOBASE_VALUE_ENCODING, EntryType } from '../../../../../src/utils/constants.js';
11
11
  import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
12
12
  import { safeWriteUInt32BE } from '../../../../../src/utils/buffer.js';
@@ -55,20 +55,26 @@ export async function buildDisableInitializationPayload(context) {
55
55
  const adminNode = context.adminBootstrap;
56
56
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
57
57
 
58
- return new CompleteStateMessageOperations(adminNode.wallet, config)
59
- .assembleDisableInitializationMessage(
60
- adminNode.base.local.key,
61
- txValidity
62
- );
58
+ return safeEncodeApplyOperation(
59
+ await applyStateMessageFactory(adminNode.wallet, config)
60
+ .buildCompleteDisableInitializationMessage(
61
+ adminNode.wallet.address,
62
+ adminNode.base.local.key,
63
+ txValidity
64
+ )
65
+ );
63
66
  }
64
67
 
65
68
  export async function buildDisableInitializationPayloadWithTxValidity(context, txValidity) {
66
69
  const adminNode = context.adminBootstrap;
67
- return new CompleteStateMessageOperations(adminNode.wallet, config)
68
- .assembleDisableInitializationMessage(
69
- adminNode.base.local.key,
70
- txValidity
71
- );
70
+ return safeEncodeApplyOperation(
71
+ await applyStateMessageFactory(adminNode.wallet, config)
72
+ .buildCompleteDisableInitializationMessage(
73
+ adminNode.wallet.address,
74
+ adminNode.base.local.key,
75
+ txValidity
76
+ )
77
+ );
72
78
  }
73
79
 
74
80
  export async function assertInitializationDisabledState(t, base, payload) {
@@ -7,8 +7,8 @@ import {
7
7
  assertValidatorReward,
8
8
  promotePeerToWriter
9
9
  } from '../addWriter/addWriterScenarioHelpers.js';
10
- import PartialStateMessageOperations from '../../../../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
11
- import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
10
+ import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
11
+ import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
12
12
  import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
13
13
  import addressUtils from '../../../../../src/core/state/utils/address.js';
14
14
  import { toBalance, BALANCE_FEE, BALANCE_TO_STAKE } from '../../../../../src/core/state/utils/balance.js';
@@ -180,18 +180,23 @@ export async function buildRemoveWriterPayloadWithTxValidity(context, mutatedTxV
180
180
  }
181
181
  const { readerPeer = selectWriterPeer(context), validatorPeer = context.adminBootstrap, writerKeyBuffer = null } = options;
182
182
  const writerKey = writerKeyBuffer ?? readerPeer.base.local.key;
183
- const partial = await new PartialStateMessageOperations(readerPeer.wallet, config).assembleRemoveWriterMessage(
184
- writerKey.toString('hex'),
185
- mutatedTxValidity.toString('hex')
186
- );
187
- return new CompleteStateMessageOperations(validatorPeer.wallet, config).assembleRemoveWriterMessage(
188
- partial.address,
189
- b4a.from(partial.rao.tx, 'hex'),
190
- mutatedTxValidity,
191
- b4a.from(partial.rao.iw, 'hex'),
192
- b4a.from(partial.rao.in, 'hex'),
193
- b4a.from(partial.rao.is, 'hex')
194
- );
183
+ const partial = await applyStateMessageFactory(readerPeer.wallet, config)
184
+ .buildPartialRemoveWriterMessage(
185
+ readerPeer.wallet.address,
186
+ writerKey.toString('hex'),
187
+ mutatedTxValidity.toString('hex'),
188
+ 'json'
189
+ );
190
+ const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
191
+ .buildCompleteRemoveWriterMessage(
192
+ partial.address,
193
+ b4a.from(partial.rao.tx, 'hex'),
194
+ mutatedTxValidity,
195
+ b4a.from(partial.rao.iw, 'hex'),
196
+ b4a.from(partial.rao.in, 'hex'),
197
+ b4a.from(partial.rao.is, 'hex')
198
+ );
199
+ return safeEncodeApplyOperation(payload);
195
200
  }
196
201
 
197
202
  export async function snapshotDowngradedWriterEntry(context) {
@@ -1,7 +1,7 @@
1
1
  import b4a from 'b4a';
2
2
  import { test } from 'brittle';
3
- import PartialStateMessageOperations from '../../../../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
4
- import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
3
+ import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
4
+ import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
5
5
  import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
6
6
  import {
7
7
  setupTransferScenario,
@@ -50,40 +50,48 @@ export default function transferDoubleSpendAcrossValidatorsScenario() {
50
50
  const txValidityA = await deriveIndexerSequenceState(primaryValidator.base);
51
51
  const txValidityB = await deriveIndexerSequenceState(secondaryValidator.base);
52
52
 
53
- const partialA = await new PartialStateMessageOperations(senderPeer.wallet, config)
54
- .assembleTransferOperationMessage(
53
+ const partialA = await applyStateMessageFactory(senderPeer.wallet, config)
54
+ .buildPartialTransferOperationMessage(
55
+ senderPeer.wallet.address,
55
56
  recipientA.wallet.address,
56
57
  b4a.toString(DEFAULT_TRANSFER_AMOUNT, 'hex'),
57
- b4a.toString(txValidityA, 'hex')
58
+ b4a.toString(txValidityA, 'hex'),
59
+ 'json'
58
60
  );
59
- const partialB = await new PartialStateMessageOperations(senderPeer.wallet, config)
60
- .assembleTransferOperationMessage(
61
+ const partialB = await applyStateMessageFactory(senderPeer.wallet, config)
62
+ .buildPartialTransferOperationMessage(
63
+ senderPeer.wallet.address,
61
64
  recipientB.wallet.address,
62
65
  b4a.toString(DEFAULT_TRANSFER_AMOUNT, 'hex'),
63
- b4a.toString(txValidityB, 'hex')
66
+ b4a.toString(txValidityB, 'hex'),
67
+ 'json'
64
68
  );
65
69
 
66
- const payloadA = await new CompleteStateMessageOperations(primaryValidator.wallet, config)
67
- .assembleCompleteTransferOperationMessage(
68
- partialA.address,
69
- b4a.from(partialA.tro.tx, 'hex'),
70
- b4a.from(partialA.tro.txv, 'hex'),
71
- b4a.from(partialA.tro.in, 'hex'),
72
- partialA.tro.to,
73
- b4a.from(partialA.tro.am, 'hex'),
74
- b4a.from(partialA.tro.is, 'hex')
75
- );
76
-
77
- const payloadB = await new CompleteStateMessageOperations(secondaryValidator.wallet, config)
78
- .assembleCompleteTransferOperationMessage(
79
- partialB.address,
80
- b4a.from(partialB.tro.tx, 'hex'),
81
- b4a.from(partialB.tro.txv, 'hex'),
82
- b4a.from(partialB.tro.in, 'hex'),
83
- partialB.tro.to,
84
- b4a.from(partialB.tro.am, 'hex'),
85
- b4a.from(partialB.tro.is, 'hex')
86
- );
70
+ const payloadA = safeEncodeApplyOperation(
71
+ await applyStateMessageFactory(primaryValidator.wallet, config)
72
+ .buildCompleteTransferOperationMessage(
73
+ partialA.address,
74
+ b4a.from(partialA.tro.tx, 'hex'),
75
+ b4a.from(partialA.tro.txv, 'hex'),
76
+ b4a.from(partialA.tro.in, 'hex'),
77
+ partialA.tro.to,
78
+ b4a.from(partialA.tro.am, 'hex'),
79
+ b4a.from(partialA.tro.is, 'hex')
80
+ )
81
+ );
82
+
83
+ const payloadB = safeEncodeApplyOperation(
84
+ await applyStateMessageFactory(secondaryValidator.wallet, config)
85
+ .buildCompleteTransferOperationMessage(
86
+ partialB.address,
87
+ b4a.from(partialB.tro.tx, 'hex'),
88
+ b4a.from(partialB.tro.txv, 'hex'),
89
+ b4a.from(partialB.tro.in, 'hex'),
90
+ partialB.tro.to,
91
+ b4a.from(partialB.tro.am, 'hex'),
92
+ b4a.from(partialB.tro.is, 'hex')
93
+ )
94
+ );
87
95
 
88
96
  // Apply first transfer successfully via primary validator.
89
97
  await primaryValidator.base.append(payloadA);
@@ -1,7 +1,6 @@
1
1
  import b4a from 'b4a';
2
2
  import PeerWallet from 'trac-wallet';
3
- import PartialStateMessageOperations from '../../../../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
4
- import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
3
+ import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
5
4
  import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
6
5
  import {
7
6
  setupAdminNetwork,
@@ -123,15 +122,17 @@ export async function buildTransferPayload(
123
122
  const resolvedTxValidity =
124
123
  txValidity ?? (await deriveIndexerSequenceState(validatorPeer.base));
125
124
 
126
- const partial = await new PartialStateMessageOperations(senderPeer.wallet, config)
127
- .assembleTransferOperationMessage(
125
+ const partial = await applyStateMessageFactory(senderPeer.wallet, config)
126
+ .buildPartialTransferOperationMessage(
127
+ senderPeer.wallet.address,
128
128
  recipientAddress,
129
129
  b4a.toString(amount, 'hex'),
130
- b4a.toString(resolvedTxValidity, 'hex')
130
+ b4a.toString(resolvedTxValidity, 'hex'),
131
+ 'json'
131
132
  );
132
133
 
133
- return new CompleteStateMessageOperations(validatorPeer.wallet, config)
134
- .assembleCompleteTransferOperationMessage(
134
+ const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
135
+ .buildCompleteTransferOperationMessage(
135
136
  partial.address,
136
137
  b4a.from(partial.tro.tx, 'hex'),
137
138
  b4a.from(partial.tro.txv, 'hex'),
@@ -140,6 +141,7 @@ export async function buildTransferPayload(
140
141
  b4a.from(partial.tro.am, 'hex'),
141
142
  b4a.from(partial.tro.is, 'hex')
142
143
  );
144
+ return safeEncodeApplyOperation(payload);
143
145
  }
144
146
 
145
147
  export async function buildTransferPayloadWithTxValidity(