@xyo-network/xl1-protocol-sdk 1.26.12 → 1.26.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/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +2 -2
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +2 -2
- package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts +1 -1
- package/dist/neutral/simple/finalization/SimpleFinalizationViewer.d.ts +1 -1
- package/dist/neutral/simple/windowedBlock/SimpleWindowedBlockViewer.d.ts +10 -10
- package/dist/neutral/transaction/TransactionBuilder.d.ts +4 -4
- package/dist/neutral/transaction/signTransaction.d.ts +1 -1
- package/package.json +24 -14
- package/src/ChainContextHelpers.ts +0 -50
- package/src/CreatableProvider/AbstractCreatableProvider.ts +0 -97
- package/src/CreatableProvider/CreatableProvider.ts +0 -102
- package/src/CreatableProvider/CreatableProviderRegistry.ts +0 -94
- package/src/CreatableProvider/GetInstanceOptions.ts +0 -11
- package/src/CreatableProvider/LabeledCreatableProviderFactory.ts +0 -24
- package/src/CreatableProvider/ProviderFactory.ts +0 -138
- package/src/CreatableProvider/ProviderFactoryLocator.ts +0 -170
- package/src/CreatableProvider/ProviderFactoryLocatorInstance.ts +0 -70
- package/src/CreatableProvider/index.ts +0 -8
- package/src/SignedBigInt.ts +0 -59
- package/src/_internal/context/getTestProviderContext.ts +0 -13
- package/src/_internal/context/index.ts +0 -1
- package/src/_internal/index.ts +0 -2
- package/src/actor/ActorV3.ts +0 -177
- package/src/actor/index.ts +0 -1
- package/src/amount/ShiftedBigInt.ts +0 -73
- package/src/amount/XL1Amount.ts +0 -103
- package/src/amount/index.ts +0 -4
- package/src/amount/splitOnDecimal.ts +0 -6
- package/src/amount/splitOnDecimalToString.ts +0 -40
- package/src/block/hydrate/allHashesPresent.ts +0 -8
- package/src/block/hydrate/blockPayloadsFromHydratedBlock.ts +0 -12
- package/src/block/hydrate/flattenHydratedBlock.ts +0 -28
- package/src/block/hydrate/flattenHydratedBlocks.ts +0 -7
- package/src/block/hydrate/hydrateBlock.ts +0 -43
- package/src/block/hydrate/index.ts +0 -7
- package/src/block/hydrate/transactionsFromHydratedBlock.ts +0 -7
- package/src/block/hydrate/tryHydrateBlock.ts +0 -26
- package/src/block/index.ts +0 -2
- package/src/block/primitives/blockFromBlockNumber.ts +0 -69
- package/src/block/primitives/frames/calculateFramesFromRange.ts +0 -30
- package/src/block/primitives/frames/deepCalculateFramesFromRange.ts +0 -28
- package/src/block/primitives/frames/index.ts +0 -2
- package/src/block/primitives/hashFromBlockNumber.ts +0 -9
- package/src/block/primitives/index.ts +0 -7
- package/src/block/primitives/model.ts +0 -18
- package/src/block/primitives/payloads/ChainWindow.ts +0 -7
- package/src/block/primitives/payloads/index.ts +0 -1
- package/src/block/primitives/toStepIdentityString.ts +0 -6
- package/src/block/primitives/validateTransactionOpcodes.ts +0 -45
- package/src/config/Actor.ts +0 -32
- package/src/config/Actors.ts +0 -9
- package/src/config/Base.ts +0 -27
- package/src/config/Chain.ts +0 -23
- package/src/config/Config.ts +0 -24
- package/src/config/DataLake/DataLake.ts +0 -12
- package/src/config/DataLake/DataLakeRemoteConfig.ts +0 -11
- package/src/config/DataLake/RestDataLakeConfig.ts +0 -18
- package/src/config/DataLake/RouterDataLakeConfig.ts +0 -22
- package/src/config/DataLake/index.ts +0 -4
- package/src/config/DeepPartial.ts +0 -4
- package/src/config/Evm.ts +0 -38
- package/src/config/HostActor.ts +0 -32
- package/src/config/Log.ts +0 -25
- package/src/config/Provider.ts +0 -20
- package/src/config/Providers.ts +0 -9
- package/src/config/Remote.ts +0 -59
- package/src/config/Telemetry.ts +0 -49
- package/src/config/UsageMeta.ts +0 -46
- package/src/config/Validation.ts +0 -29
- package/src/config/index.ts +0 -12
- package/src/config/storage/Storage.ts +0 -16
- package/src/config/storage/driver/Mongo.ts +0 -53
- package/src/config/storage/driver/index.ts +0 -1
- package/src/config/storage/index.ts +0 -2
- package/src/constants.ts +0 -4
- package/src/context/Actor.ts +0 -20
- package/src/context/HostActor.ts +0 -20
- package/src/context/getEmptyProviderContext.ts +0 -19
- package/src/context/index.ts +0 -3
- package/src/createDeclarationPayload.ts +0 -15
- package/src/createTransferPayload.ts +0 -16
- package/src/driver/cache/LruCacheMap.ts +0 -48
- package/src/driver/cache/index.ts +0 -1
- package/src/driver/index.ts +0 -2
- package/src/driver/memory/MemoryMap.ts +0 -48
- package/src/driver/memory/index.ts +0 -1
- package/src/eip-712/Payloads/EIP712Data.ts +0 -35
- package/src/eip-712/Payloads/EIP712Signature.ts +0 -32
- package/src/eip-712/Payloads/index.ts +0 -2
- package/src/eip-712/Types.ts +0 -41
- package/src/eip-712/index.ts +0 -4
- package/src/eip-712/sign.ts +0 -19
- package/src/eip-712/spec/fixtures.ts +0 -27
- package/src/eip-712/verify.ts +0 -20
- package/src/getFileConfig.ts +0 -36
- package/src/index.ts +0 -27
- package/src/instances/Address.ts +0 -16
- package/src/instances/BoundWitness.ts +0 -13
- package/src/instances/Data.ts +0 -4
- package/src/instances/Fees.ts +0 -9
- package/src/instances/HydratedBoundWitness.ts +0 -16
- package/src/instances/Object.ts +0 -6
- package/src/instances/Payload.ts +0 -7
- package/src/instances/Signature.ts +0 -12
- package/src/instances/block/BlockFields.ts +0 -18
- package/src/instances/block/HydratedBlock.ts +0 -10
- package/src/instances/block/index.ts +0 -1
- package/src/instances/index.ts +0 -10
- package/src/instances/modifiers/BlockWindowInstance.ts +0 -8
- package/src/instances/modifiers/BlockWindowState.ts +0 -6
- package/src/instances/modifiers/Signed.ts +0 -9
- package/src/instances/modifiers/Validatable.ts +0 -6
- package/src/instances/modifiers/index.ts +0 -4
- package/src/instances/transaction/HydratedTransaction.ts +0 -9
- package/src/instances/transaction/TransactionFields.ts +0 -22
- package/src/instances/transaction/index.ts +0 -1
- package/src/isInternetAvailable.ts +0 -11
- package/src/model/ChainFork/ChainForkStatic.ts +0 -9
- package/src/model/ChainFork/index.ts +0 -1
- package/src/model/ChainIdentity.ts +0 -6
- package/src/model/ChainStore.ts +0 -16
- package/src/model/CreatableProviderContext.ts +0 -6
- package/src/model/CreatableProviderContext.zod.ts +0 -55
- package/src/model/PayloadBundle/bundledPayloadToHydratedBlock.ts +0 -15
- package/src/model/PayloadBundle/bundledPayloadToHydratedTransaction.ts +0 -15
- package/src/model/PayloadBundle/hydratedBlockToPayloadBundle.ts +0 -19
- package/src/model/PayloadBundle/hydratedTransactionToPayloadBundle.ts +0 -19
- package/src/model/PayloadBundle/index.ts +0 -4
- package/src/model/index.ts +0 -6
- package/src/multipliers.ts +0 -18
- package/src/payloads/AddressPairPayload.ts +0 -27
- package/src/payloads/index.ts +0 -4
- package/src/payloads/netBalancesForPayloads.ts +0 -24
- package/src/payloads/netSchemasForPayloads.ts +0 -24
- package/src/payloads/netTransfersForPayloads.ts +0 -27
- package/src/primitives/block/index.ts +0 -2
- package/src/primitives/block/range/blockRangeSteps.ts +0 -23
- package/src/primitives/block/range/index.ts +0 -1
- package/src/primitives/block/rate/blockRate.ts +0 -77
- package/src/primitives/block/rate/index.ts +0 -4
- package/src/primitives/block/rate/stepRate.ts +0 -37
- package/src/primitives/block/rate/timeHelpers.ts +0 -61
- package/src/primitives/block/rate/timeRate.ts +0 -121
- package/src/primitives/chain/getWindowedChain.ts +0 -50
- package/src/primitives/chain/index.ts +0 -3
- package/src/primitives/chain/step/chainStepRewardAddress.ts +0 -30
- package/src/primitives/chain/step/index.ts +0 -4
- package/src/primitives/chain/step/stepRewardBlock.ts +0 -13
- package/src/primitives/chain/step/stepRewardTotal.ts +0 -46
- package/src/primitives/chain/step/stepsRewardTotal.ts +0 -37
- package/src/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.ts +0 -32
- package/src/primitives/chain/time/externalBlockRangeFromStep.ts +0 -21
- package/src/primitives/chain/time/externalBlockRangeFromXL1BlockRange.ts +0 -17
- package/src/primitives/chain/time/index.ts +0 -3
- package/src/primitives/datalake/addDataLakePayloads.ts +0 -18
- package/src/primitives/datalake/addDataLakePayloadsToPayloads.ts +0 -24
- package/src/primitives/datalake/index.ts +0 -2
- package/src/primitives/index.ts +0 -13
- package/src/primitives/mapToMapType.ts +0 -35
- package/src/primitives/payload/index.ts +0 -1
- package/src/primitives/payload/mergeTransfers.ts +0 -16
- package/src/primitives/readPayloadMapFromStore.ts +0 -58
- package/src/primitives/rewardFromBlockNumber.ts +0 -19
- package/src/primitives/rewards/index.ts +0 -1
- package/src/primitives/rewards/networkStakeStepRewardPositionWeight.ts +0 -26
- package/src/primitives/stake/activeStakeAtTimeByAddress.ts +0 -27
- package/src/primitives/stake/activeStakeAtTimeByPosition.ts +0 -25
- package/src/primitives/stake/allStakersForRange.ts +0 -32
- package/src/primitives/stake/allStakersForStep.ts +0 -24
- package/src/primitives/stake/index.ts +0 -6
- package/src/primitives/stake/mergedAddRemoveStakeEventsByPosition.ts +0 -15
- package/src/primitives/stake/mergedAddRemoveStakeEventsByStaker.ts +0 -17
- package/src/primitives/stake/weightedStakeForRangeByPosition.ts +0 -69
- package/src/primitives/state/findMostRecentBlock.ts +0 -44
- package/src/primitives/state/hydratedBlockByNumber.ts +0 -25
- package/src/primitives/state/index.ts +0 -2
- package/src/primitives/step/completedStepRewardAddress.ts +0 -10
- package/src/primitives/step/derivedReceiveAddress.ts +0 -9
- package/src/primitives/step/index.ts +0 -4
- package/src/primitives/step/stepBlockRange.ts +0 -9
- package/src/primitives/step/stepTransferIndex.ts +0 -19
- package/src/primitives/transaction/elevatedPayloads.ts +0 -24
- package/src/primitives/transaction/index.ts +0 -1
- package/src/primitives/uncle/findBestUncle.ts +0 -9
- package/src/primitives/uncle/findUncles.ts +0 -75
- package/src/primitives/uncle/index.ts +0 -3
- package/src/primitives/uncle/scoreUncle.ts +0 -7
- package/src/services/AccountTransfersService.ts +0 -13
- package/src/services/BlockProducerService.ts +0 -11
- package/src/services/Chain/BaseChainService.ts +0 -4
- package/src/services/Chain/ChainHeadService.ts +0 -8
- package/src/services/Chain/ChainService.ts +0 -6
- package/src/services/Chain/index.ts +0 -3
- package/src/services/Election.ts +0 -14
- package/src/services/NetworkStakeService.ts +0 -4
- package/src/services/Params.ts +0 -13
- package/src/services/PendingTransactionsService.ts +0 -7
- package/src/services/SchemasService.ts +0 -11
- package/src/services/StakeIntentService/ChainIndexingServiceStateSchema.ts +0 -50
- package/src/services/StakeIntentService/StakeIntentService.ts +0 -35
- package/src/services/StakeIntentService/index.ts +0 -2
- package/src/services/index.ts +0 -8
- package/src/simple/StakeEventsViewer/SimpleStakeEventsViewer.ts +0 -93
- package/src/simple/StakeEventsViewer/index.ts +0 -1
- package/src/simple/StakeTotalsViewer/SimpleStakeTotalsViewer.ts +0 -116
- package/src/simple/StakeTotalsViewer/index.ts +0 -1
- package/src/simple/StakeViewer/SimpleStakeViewer.ts +0 -164
- package/src/simple/StakeViewer/index.ts +0 -1
- package/src/simple/TransactionViewer/SimpleTransactionViewer.ts +0 -100
- package/src/simple/TransactionViewer/index.ts +0 -1
- package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +0 -271
- package/src/simple/accountBalance/index.ts +0 -1
- package/src/simple/block/SimpleBlockViewer.ts +0 -231
- package/src/simple/block/index.ts +0 -1
- package/src/simple/blockInvalidation/SimpleBlockInvalidationViewer.ts +0 -197
- package/src/simple/blockInvalidation/index.ts +0 -1
- package/src/simple/blockReward/SimpleBlockRewardViewer.ts +0 -27
- package/src/simple/blockReward/index.ts +0 -1
- package/src/simple/blockValidation/SimpleBlockValidationViewer.ts +0 -194
- package/src/simple/blockValidation/index.ts +0 -1
- package/src/simple/chainContractViewer/SimpleChainContractViewer.ts +0 -92
- package/src/simple/chainContractViewer/index.ts +0 -1
- package/src/simple/client/SimpleXyoClient.ts +0 -14
- package/src/simple/client/index.ts +0 -1
- package/src/simple/datalake/AbstractRestDataLake.ts +0 -70
- package/src/simple/datalake/AbstractSimpleDataLake.ts +0 -62
- package/src/simple/datalake/RestDataLakeRunner.ts +0 -54
- package/src/simple/datalake/RestDataLakeViewer.ts +0 -22
- package/src/simple/datalake/SimpleDataLakeRunner.ts +0 -44
- package/src/simple/datalake/SimpleDataLakeViewer.ts +0 -24
- package/src/simple/datalake/index.ts +0 -4
- package/src/simple/finalization/SimpleFinalizationRunner.ts +0 -45
- package/src/simple/finalization/SimpleFinalizationViewer.ts +0 -123
- package/src/simple/finalization/index.ts +0 -2
- package/src/simple/gateway/SimpleXyoGateway.ts +0 -30
- package/src/simple/gateway/SimpleXyoGatewayRunner.ts +0 -137
- package/src/simple/gateway/index.ts +0 -2
- package/src/simple/index.ts +0 -22
- package/src/simple/mempool/SimpleMempoolRunner.ts +0 -390
- package/src/simple/mempool/SimpleMempoolViewer.ts +0 -215
- package/src/simple/mempool/index.ts +0 -2
- package/src/simple/network/SimpleXyoNetwork.ts +0 -48
- package/src/simple/network/index.ts +0 -1
- package/src/simple/network/lib/FailedNetworkStatusPayloads.ts +0 -16
- package/src/simple/network/lib/StatusNetworks.ts +0 -32
- package/src/simple/network/lib/index.ts +0 -2
- package/src/simple/permissions/SimpleXyoPermissions.ts +0 -82
- package/src/simple/permissions/index.ts +0 -2
- package/src/simple/permissions/store/MemoryPermissions.ts +0 -32
- package/src/simple/permissions/store/PermissionsStore.ts +0 -17
- package/src/simple/permissions/store/index.ts +0 -2
- package/src/simple/runner/SimpleXyoRunner.ts +0 -41
- package/src/simple/runner/index.ts +0 -1
- package/src/simple/signer/SimpleXyoSigner.ts +0 -78
- package/src/simple/signer/index.ts +0 -1
- package/src/simple/timeSync2/SimpleTimeSyncViewer.ts +0 -132
- package/src/simple/timeSync2/index.ts +0 -1
- package/src/simple/transactionInvalidation/SimpleTransactionInvalidationViewer.ts +0 -197
- package/src/simple/transactionInvalidation/index.ts +0 -1
- package/src/simple/transactionValidation/SimpleTransactionValidationViewer.ts +0 -173
- package/src/simple/transactionValidation/index.ts +0 -1
- package/src/simple/windowedBlock/SimpleWindowedBlockViewer.ts +0 -207
- package/src/simple/windowedBlock/index.ts +0 -1
- package/src/status/RuntimeStatusMonitor.ts +0 -120
- package/src/status/ServiceStatus.ts +0 -21
- package/src/status/index.ts +0 -2
- package/src/summary/index.ts +0 -2
- package/src/summary/model/BalancesStepSummary.ts +0 -35
- package/src/summary/model/SchemasStepSummary.ts +0 -33
- package/src/summary/model/StepSummary.ts +0 -20
- package/src/summary/model/TransfersSummary.ts +0 -36
- package/src/summary/model/index.ts +0 -4
- package/src/summary/primitives/balances/balancesStepSummaryFromRange.ts +0 -94
- package/src/summary/primitives/balances/balancesSummary.ts +0 -48
- package/src/summary/primitives/balances/index.ts +0 -2
- package/src/summary/primitives/index.ts +0 -3
- package/src/summary/primitives/schemas/index.ts +0 -2
- package/src/summary/primitives/schemas/schemasStepSummaryFromRange.ts +0 -86
- package/src/summary/primitives/schemas/schemasSummary.ts +0 -44
- package/src/summary/primitives/transfers/index.ts +0 -2
- package/src/summary/primitives/transfers/transfersStepSummaryFromRange.ts +0 -109
- package/src/summary/primitives/transfers/transfersSummary.ts +0 -52
- package/src/test/BuildBlockOptions.ts +0 -81
- package/src/test/buildBlock.ts +0 -105
- package/src/test/buildGenesisBlock.ts +0 -29
- package/src/test/buildNextBlock.ts +0 -37
- package/src/test/buildRandomChain.ts +0 -92
- package/src/test/buildRandomGenesisBlock.ts +0 -47
- package/src/test/createGenesisBlock.ts +0 -41
- package/src/test/createProducerChainStakeIntentTransaction.ts +0 -48
- package/src/test/getSimpleBlockViewerLocator.ts +0 -41
- package/src/test/getTestProviderContext.ts +0 -8
- package/src/test/index.ts +0 -2
- package/src/time/index.ts +0 -1
- package/src/time/primitives/index.ts +0 -1
- package/src/time/primitives/xl1BlockNumberToEthBlockNumber.ts +0 -13
- package/src/transaction/TransactionBuilder.ts +0 -164
- package/src/transaction/buildRandomTransaction.ts +0 -38
- package/src/transaction/buildTransaction.ts +0 -68
- package/src/transaction/buildUnsignedTransaction.ts +0 -56
- package/src/transaction/confirmSubmittedTransaction.ts +0 -42
- package/src/transaction/hydrateTransaction.ts +0 -117
- package/src/transaction/index.ts +0 -9
- package/src/transaction/primitives/index.ts +0 -4
- package/src/transaction/primitives/transactionBlockByteCount.ts +0 -10
- package/src/transaction/primitives/transactionElevatedPayloads.ts +0 -18
- package/src/transaction/primitives/transactionOperations.ts +0 -13
- package/src/transaction/primitives/transactionRequiredGas.ts +0 -22
- package/src/transaction/script.ts +0 -48
- package/src/transaction/signTransaction.ts +0 -32
- package/src/utils/HydratedCache.ts +0 -39
- package/src/utils/index.ts +0 -2
- package/src/utils/isZodError.ts +0 -11
- package/src/validation/index.ts +0 -2
- package/src/validation/lib/getUrl.ts +0 -7
- package/src/validation/lib/index.ts +0 -2
- package/src/validation/lib/isLocalhost.ts +0 -9
- package/src/validation/schema/Address.ts +0 -2
- package/src/validation/schema/Mnemonic.ts +0 -21
- package/src/validation/schema/index.ts +0 -2
- package/src/wallet/generateXyoBaseWalletFromPhrase.ts +0 -13
- package/src/wallet/index.ts +0 -2
- package/src/wallet/paths.ts +0 -17
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
3
|
-
import {
|
|
4
|
-
AccountBalanceViewer,
|
|
5
|
-
AccountBalanceViewerMoniker,
|
|
6
|
-
asXL1BlockRange,
|
|
7
|
-
BlockViewer,
|
|
8
|
-
BlockViewerMoniker,
|
|
9
|
-
ChainContractViewer,
|
|
10
|
-
ChainContractViewerMoniker,
|
|
11
|
-
ChainId,
|
|
12
|
-
HydratedTransactionStateValidationFunction,
|
|
13
|
-
HydratedTransactionValidationError,
|
|
14
|
-
HydratedTransactionValidationFunction,
|
|
15
|
-
isChainQualifiedHeadConfig,
|
|
16
|
-
isHydratedTransaction,
|
|
17
|
-
SignedHydratedTransaction,
|
|
18
|
-
type SignedHydratedTransactionWithHashMeta,
|
|
19
|
-
TransactionValidationConfig,
|
|
20
|
-
TransactionValidationQualification,
|
|
21
|
-
TransactionValidationViewer,
|
|
22
|
-
TransactionValidationViewerMoniker,
|
|
23
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
24
|
-
|
|
25
|
-
import type { CreatableProviderParams } from '../../CreatableProvider/index.ts'
|
|
26
|
-
import { AbstractCreatableProvider, creatableProvider } from '../../CreatableProvider/index.ts'
|
|
27
|
-
|
|
28
|
-
/** Parameters for SimpleTransactionValidationViewer. */
|
|
29
|
-
export interface SimpleTransactionValidationViewerParams extends CreatableProviderParams {
|
|
30
|
-
maxUncleWindowSize?: number
|
|
31
|
-
protocol?: HydratedTransactionValidationFunction
|
|
32
|
-
state?: HydratedTransactionStateValidationFunction
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** SimpleTransactionValidationViewer implementation. */
|
|
36
|
-
@creatableProvider()
|
|
37
|
-
export class SimpleTransactionValidationViewer extends
|
|
38
|
-
AbstractCreatableProvider<SimpleTransactionValidationViewerParams> implements TransactionValidationViewer {
|
|
39
|
-
static readonly defaultMoniker = TransactionValidationViewerMoniker
|
|
40
|
-
static readonly dependencies = [AccountBalanceViewerMoniker, ChainContractViewerMoniker, BlockViewerMoniker]
|
|
41
|
-
static readonly monikers = [TransactionValidationViewerMoniker]
|
|
42
|
-
moniker = SimpleTransactionValidationViewer.defaultMoniker
|
|
43
|
-
|
|
44
|
-
private _accountBalanceViewer!: AccountBalanceViewer
|
|
45
|
-
private _blockViewer!: BlockViewer
|
|
46
|
-
private _chainContractViewer!: ChainContractViewer
|
|
47
|
-
|
|
48
|
-
protected get blockViewer() {
|
|
49
|
-
return this._blockViewer
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
protected get chainContractViewer() {
|
|
53
|
-
return this._chainContractViewer
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
protected get maxUncleWindowSize() {
|
|
57
|
-
return this.params.maxUncleWindowSize!
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static override async paramsHandler(params: Partial<SimpleTransactionValidationViewerParams>): Promise<SimpleTransactionValidationViewerParams> {
|
|
61
|
-
return {
|
|
62
|
-
...await super.paramsHandler(params),
|
|
63
|
-
protocol: params.protocol,
|
|
64
|
-
state: params.state,
|
|
65
|
-
maxUncleWindowSize: params.maxUncleWindowSize ?? 100,
|
|
66
|
-
} satisfies SimpleTransactionValidationViewerParams
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
override async createHandler() {
|
|
70
|
-
await super.createHandler()
|
|
71
|
-
this._accountBalanceViewer = await this.locator.getInstance<AccountBalanceViewer>(AccountBalanceViewerMoniker)
|
|
72
|
-
this._chainContractViewer = await this.locator.getInstance<ChainContractViewer>(ChainContractViewerMoniker)
|
|
73
|
-
this._blockViewer = await this.locator.getInstance<BlockViewer>(BlockViewerMoniker)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async qualifiedValidateTransaction(
|
|
77
|
-
block: SignedHydratedTransactionWithHashMeta,
|
|
78
|
-
config?: TransactionValidationConfig,
|
|
79
|
-
): Promise<[HydratedTransactionValidationError[] | SignedHydratedTransactionWithHashMeta, TransactionValidationQualification]> {
|
|
80
|
-
const result = (await this.qualifiedValidateTransactions([block], config))
|
|
81
|
-
return [result[0][0], result[1]]
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async qualifiedValidateTransactions(
|
|
85
|
-
transactions: SignedHydratedTransaction[],
|
|
86
|
-
config?: TransactionValidationConfig,
|
|
87
|
-
): Promise<[(HydratedTransactionValidationError[] | SignedHydratedTransactionWithHashMeta)[], TransactionValidationQualification]> {
|
|
88
|
-
const { value, state } = config ?? {
|
|
89
|
-
shape: true, links: true, state: true, head: undefined,
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const transactionsWithMeta = await Promise.all(transactions.map(b => Promise.all([PayloadBuilder.addHashMeta(b[0]), PayloadBuilder.addHashMeta(b[1])])))
|
|
93
|
-
|
|
94
|
-
const head = isChainQualifiedHeadConfig(config)
|
|
95
|
-
? assertEx(
|
|
96
|
-
(await this.blockViewer.blockByHash(config.head))?.[0],
|
|
97
|
-
() => `Specified a head that is not in the chain [${config.head}]`,
|
|
98
|
-
)
|
|
99
|
-
: undefined
|
|
100
|
-
|
|
101
|
-
const headBlock = head ?? (await this.blockViewer.currentBlock())[0]
|
|
102
|
-
|
|
103
|
-
const validateProtocol = value ? this.doValidateProtocol.bind(this) : undefined
|
|
104
|
-
const validateState = state ? this.doValidateState.bind(this) : undefined
|
|
105
|
-
|
|
106
|
-
const chainId = headBlock.chain
|
|
107
|
-
|
|
108
|
-
const qualification = { head: headBlock._hash, range: asXL1BlockRange([0, headBlock.block], true) }
|
|
109
|
-
const [protocolResults, stateResults] = await Promise.all([
|
|
110
|
-
validateProtocol?.(transactionsWithMeta, chainId), validateState?.(transactionsWithMeta, chainId),
|
|
111
|
-
])
|
|
112
|
-
const blockResults = transactionsWithMeta.map((r, i) => {
|
|
113
|
-
const errors = []
|
|
114
|
-
if (protocolResults && !isHydratedTransaction(protocolResults[i])) {
|
|
115
|
-
errors.push(...(protocolResults[i]))
|
|
116
|
-
}
|
|
117
|
-
if (stateResults && !isHydratedTransaction(stateResults[i])) {
|
|
118
|
-
errors.push(...(stateResults[i]))
|
|
119
|
-
}
|
|
120
|
-
return errors.length === 0 ? r : errors
|
|
121
|
-
})
|
|
122
|
-
return [blockResults, qualification]
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
qualifiedValidateUncle(
|
|
126
|
-
_transactions: SignedHydratedTransaction[],
|
|
127
|
-
_config?: TransactionValidationConfig,
|
|
128
|
-
): Promise<[(HydratedTransactionValidationError[] | SignedHydratedTransactionWithHashMeta)[], TransactionValidationQualification]> {
|
|
129
|
-
throw new Error('Method not implemented.')
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async validateTransaction(
|
|
133
|
-
block: SignedHydratedTransaction,
|
|
134
|
-
config?: TransactionValidationConfig,
|
|
135
|
-
): Promise<HydratedTransactionValidationError[] | SignedHydratedTransactionWithHashMeta> {
|
|
136
|
-
return (await this.validateTransactions([block], config))[0]
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async validateTransactions(
|
|
140
|
-
transactions: SignedHydratedTransaction[],
|
|
141
|
-
config?: TransactionValidationConfig,
|
|
142
|
-
): Promise<(HydratedTransactionValidationError[] | SignedHydratedTransactionWithHashMeta)[]> {
|
|
143
|
-
return (await this.qualifiedValidateTransactions(transactions, config))[0]
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
private async doValidateProtocol(
|
|
147
|
-
transactions: SignedHydratedTransactionWithHashMeta[],
|
|
148
|
-
chainId: ChainId,
|
|
149
|
-
): Promise<(SignedHydratedTransactionWithHashMeta | HydratedTransactionValidationError[])[]> {
|
|
150
|
-
return (await Promise.all(transactions.map(async (tx) => {
|
|
151
|
-
const errors = await this.params.protocol!(
|
|
152
|
-
{ ...this.context, chainId },
|
|
153
|
-
tx,
|
|
154
|
-
)
|
|
155
|
-
return (errors.length === 0) ? tx : errors
|
|
156
|
-
})))
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
private async doValidateState(
|
|
160
|
-
transactions: SignedHydratedTransactionWithHashMeta[],
|
|
161
|
-
chainId: ChainId,
|
|
162
|
-
): Promise<(SignedHydratedTransactionWithHashMeta | HydratedTransactionValidationError[])[]> {
|
|
163
|
-
return (await Promise.all(transactions.map(async (tx) => {
|
|
164
|
-
const errors = await this.params.state!(
|
|
165
|
-
{
|
|
166
|
-
...this.context, chainId, accountBalanceViewer: this._accountBalanceViewer, blockViewer: this.blockViewer,
|
|
167
|
-
},
|
|
168
|
-
tx,
|
|
169
|
-
)
|
|
170
|
-
return (errors.length === 0) ? tx : errors
|
|
171
|
-
})))
|
|
172
|
-
}
|
|
173
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SimpleTransactionValidationViewer.ts'
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertEx, exists, type Hash, isNull, type Promisable,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import type { Payload, WithHashMeta } from '@xyo-network/sdk-js'
|
|
5
|
-
import type {
|
|
6
|
-
BlockViewer,
|
|
7
|
-
ChainId, HydratedBlockWithHashMeta, SignedHydratedBlockWithHashMeta, SyncMap, WindowedBlockViewer, XL1BlockNumber,
|
|
8
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
9
|
-
import {
|
|
10
|
-
asXL1BlockNumber, BlockViewerMoniker, WindowedBlockViewerMoniker,
|
|
11
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
12
|
-
import { Mutex } from 'async-mutex'
|
|
13
|
-
|
|
14
|
-
import { transactionsFromHydratedBlock } from '../../block/index.ts'
|
|
15
|
-
import {
|
|
16
|
-
AbstractCreatableProvider, creatableProvider, type CreatableProviderParams,
|
|
17
|
-
} from '../../CreatableProvider/index.ts'
|
|
18
|
-
import { MemoryMap } from '../../driver/index.ts'
|
|
19
|
-
|
|
20
|
-
/** Parameters for SimpleWindowedBlockViewer. */
|
|
21
|
-
export interface SimpleWindowedBlockViewerParams extends CreatableProviderParams {
|
|
22
|
-
blockViewer?: BlockViewer
|
|
23
|
-
maxWindowSize: number
|
|
24
|
-
syncInterval: number
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** SimpleWindowedBlockViewer implementation. */
|
|
28
|
-
@creatableProvider()
|
|
29
|
-
export class SimpleWindowedBlockViewer extends AbstractCreatableProvider<SimpleWindowedBlockViewerParams> implements WindowedBlockViewer {
|
|
30
|
-
static readonly defaultMoniker = WindowedBlockViewerMoniker
|
|
31
|
-
static readonly dependencies = [BlockViewerMoniker]
|
|
32
|
-
static readonly monikers = [WindowedBlockViewerMoniker]
|
|
33
|
-
moniker = WindowedBlockViewerMoniker
|
|
34
|
-
|
|
35
|
-
private _blockHashMap!: SyncMap<Hash, SignedHydratedBlockWithHashMeta>
|
|
36
|
-
private _blockNumberMap!: SyncMap<XL1BlockNumber, SignedHydratedBlockWithHashMeta>
|
|
37
|
-
// the external BlockViewer
|
|
38
|
-
private _blockViewer!: BlockViewer
|
|
39
|
-
private _chain: SignedHydratedBlockWithHashMeta[] = []
|
|
40
|
-
private _syncMutex = new Mutex()
|
|
41
|
-
private _timerId: ReturnType<typeof setInterval> | null = null
|
|
42
|
-
private _transactionHashMap!: SyncMap<Hash, SignedHydratedBlockWithHashMeta>
|
|
43
|
-
|
|
44
|
-
protected get maxWindowSize() {
|
|
45
|
-
return this.params.maxWindowSize
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
protected get syncInterval() {
|
|
49
|
-
return this.params.syncInterval
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
static override async paramsHandler(params?: Partial<SimpleWindowedBlockViewerParams>): Promise<SimpleWindowedBlockViewerParams> {
|
|
53
|
-
return {
|
|
54
|
-
...await super.paramsHandler(params),
|
|
55
|
-
maxWindowSize: params?.maxWindowSize ?? 1000,
|
|
56
|
-
syncInterval: params?.syncInterval ?? 10_000,
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
blockByHash(hash: Hash) {
|
|
61
|
-
return this._blockHashMap.get(hash) ?? null
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
blockByNumber(blockNumber: XL1BlockNumber) {
|
|
65
|
-
return this._blockNumberMap.get(blockNumber) ?? null
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async blockByTransactionHash(hash: Hash) {
|
|
69
|
-
const [block = null] = await this.blocksByTransactionHashes([hash])
|
|
70
|
-
return block
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
blocksByHash(hash: Hash, limit?: number) {
|
|
74
|
-
const result: SignedHydratedBlockWithHashMeta[] = []
|
|
75
|
-
let block = this._blockHashMap.get(hash)
|
|
76
|
-
while (block && (limit === undefined || result.length < limit)) {
|
|
77
|
-
result.unshift(block)
|
|
78
|
-
const previousHash = block[0].previous
|
|
79
|
-
block = previousHash ? this._blockHashMap.get(previousHash) : undefined
|
|
80
|
-
}
|
|
81
|
-
return result
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
blocksByNumber(blockNumber: XL1BlockNumber, limit?: number) {
|
|
85
|
-
const result: SignedHydratedBlockWithHashMeta[] = []
|
|
86
|
-
let block = this._blockNumberMap.get(blockNumber)
|
|
87
|
-
while (block && (limit === undefined || result.length < limit)) {
|
|
88
|
-
result.unshift(block)
|
|
89
|
-
const previousBlockNumber = asXL1BlockNumber(block[0].block - 1, true)
|
|
90
|
-
block = (previousBlockNumber >= 0) ? this._blockNumberMap.get(previousBlockNumber) : undefined
|
|
91
|
-
}
|
|
92
|
-
return result
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
blocksByTransactionHashes(hashes: Hash[]): Promisable<HydratedBlockWithHashMeta[]> {
|
|
96
|
-
return hashes.map(hash => this._transactionHashMap.get(hash)).filter(exists)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
chainId(_blockNumber?: unknown): Promisable<ChainId> {
|
|
100
|
-
throw new Error('Method not implemented.')
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
override async createHandler() {
|
|
104
|
-
await super.createHandler()
|
|
105
|
-
|
|
106
|
-
this._blockViewer = assertEx(
|
|
107
|
-
this.params.blockViewer ?? await this.locator.getInstance<BlockViewer>(BlockViewerMoniker),
|
|
108
|
-
() => 'BlockViewer instance is required',
|
|
109
|
-
)
|
|
110
|
-
this._blockHashMap = new MemoryMap<Hash, SignedHydratedBlockWithHashMeta>()
|
|
111
|
-
this._blockNumberMap = new MemoryMap<XL1BlockNumber, SignedHydratedBlockWithHashMeta>()
|
|
112
|
-
this._transactionHashMap = new MemoryMap<Hash, SignedHydratedBlockWithHashMeta>()
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
currentBlock(): Promisable<SignedHydratedBlockWithHashMeta> {
|
|
116
|
-
return assertEx(this._chain.at(-1))
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
currentBlockHash(): Promisable<Hash> {
|
|
120
|
-
return assertEx(this._chain.at(-1)?.[0]._hash)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
currentBlockNumber(): Promisable<XL1BlockNumber> {
|
|
124
|
-
return assertEx(this._chain.at(-1)?.[0].block)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async payloadByHash(hash: Hash): Promise<WithHashMeta<Payload> | null> {
|
|
128
|
-
const payloads = await this.payloadsByHash([hash])
|
|
129
|
-
return payloads.length > 0 ? payloads[0] : null
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
payloadsByHash(_hashes: Hash[]): Promisable<WithHashMeta<Payload>[]> {
|
|
133
|
-
throw new Error('Method not implemented.')
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
override async startHandler() {
|
|
137
|
-
await super.startHandler()
|
|
138
|
-
await this.sync()
|
|
139
|
-
this.stopPoll()
|
|
140
|
-
this.startPoll()
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
override async stopHandler() {
|
|
144
|
-
await super.stopHandler()
|
|
145
|
-
this.stopPoll()
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
private addBlock(block: SignedHydratedBlockWithHashMeta) {
|
|
149
|
-
// Add the new block to the end of the window
|
|
150
|
-
this._chain.push(block)
|
|
151
|
-
|
|
152
|
-
// Index the new block
|
|
153
|
-
this._blockHashMap.set(block[0]._hash, block)
|
|
154
|
-
this._blockNumberMap.set(block[0].block, block)
|
|
155
|
-
for (const tx of transactionsFromHydratedBlock(block)) {
|
|
156
|
-
this._transactionHashMap.set(tx._hash, block)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Purge only if the window size is exceeded
|
|
160
|
-
while (this._chain.length > this.maxWindowSize) {
|
|
161
|
-
const removedBlock = this._chain.shift()
|
|
162
|
-
if (!removedBlock) break
|
|
163
|
-
|
|
164
|
-
this._blockHashMap.delete(removedBlock[0]._hash)
|
|
165
|
-
this._blockNumberMap.delete(removedBlock[0].block)
|
|
166
|
-
for (const tx of transactionsFromHydratedBlock(removedBlock)) {
|
|
167
|
-
this._transactionHashMap.delete(tx._hash)
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private startPoll() {
|
|
173
|
-
this._timerId = setInterval(() => {
|
|
174
|
-
void this.sync()
|
|
175
|
-
}, this.syncInterval)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private stopPoll() {
|
|
179
|
-
if (this._timerId) {
|
|
180
|
-
clearInterval(this._timerId)
|
|
181
|
-
}
|
|
182
|
-
this._timerId = null
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
private async sync() {
|
|
186
|
-
if (this._syncMutex.isLocked()) {
|
|
187
|
-
return
|
|
188
|
-
}
|
|
189
|
-
return await this._syncMutex.runExclusive(async () => {
|
|
190
|
-
try {
|
|
191
|
-
let cursor: SignedHydratedBlockWithHashMeta | null = await this._blockViewer.currentBlock()
|
|
192
|
-
const previousHead = this._chain.length > 0 ? await this.currentBlockHash() : null
|
|
193
|
-
const newBlocks: SignedHydratedBlockWithHashMeta[] = []
|
|
194
|
-
while (!isNull(cursor) && cursor[0]._hash !== previousHead && newBlocks.length < this.maxWindowSize) {
|
|
195
|
-
newBlocks.unshift(cursor)
|
|
196
|
-
const previousHash = newBlocks[0][0].previous
|
|
197
|
-
cursor = isNull(previousHash) ? null : await this._blockViewer.blockByHash(previousHash)
|
|
198
|
-
}
|
|
199
|
-
for (const block of newBlocks) {
|
|
200
|
-
this.addBlock(block)
|
|
201
|
-
}
|
|
202
|
-
} catch (ex) {
|
|
203
|
-
console.error('Error during sync:', ex)
|
|
204
|
-
}
|
|
205
|
-
})
|
|
206
|
-
}
|
|
207
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SimpleWindowedBlockViewer.ts'
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import type { CreatableName, CreatableStatus } from '@xylabs/sdk-js'
|
|
2
|
-
|
|
3
|
-
import { LoggerStatusReporter } from './ServiceStatus.ts'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Enum-like record for statuses with priority allowing
|
|
7
|
-
* for determination of the aggregated status.
|
|
8
|
-
*/
|
|
9
|
-
const statusPriority: Record<CreatableStatus, number> = {
|
|
10
|
-
error: 0,
|
|
11
|
-
stopped: 1,
|
|
12
|
-
stopping: 2,
|
|
13
|
-
creating: 3,
|
|
14
|
-
created: 4,
|
|
15
|
-
starting: 5,
|
|
16
|
-
started: 6,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A sentinel status that represents the initial state
|
|
21
|
-
* before any statuses are reported.
|
|
22
|
-
* It is used to ensure that the monitor has a valid status
|
|
23
|
-
* even when no statuses have been reported yet and to
|
|
24
|
-
* prevent the system from showing an "error" state
|
|
25
|
-
* when no statuses are available.
|
|
26
|
-
*/
|
|
27
|
-
const SENTINEL_STATUS: CreatableStatus = 'starting'
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Given an array of statuses, this function reduces them
|
|
31
|
-
* to the minimum status based on the defined priority.
|
|
32
|
-
* @param statuses An array of statuses to reduce.
|
|
33
|
-
* @returns The minimum status based on priority.
|
|
34
|
-
*/
|
|
35
|
-
const reduceToMinimumStatus = (statuses: CreatableStatus[]): CreatableStatus => {
|
|
36
|
-
let minStatus: CreatableStatus = SENTINEL_STATUS
|
|
37
|
-
let minPriority = Infinity
|
|
38
|
-
|
|
39
|
-
for (const status of statuses) {
|
|
40
|
-
const priority = statusPriority[status]
|
|
41
|
-
if (priority < minPriority) {
|
|
42
|
-
minPriority = priority
|
|
43
|
-
minStatus = status
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return minStatus
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Handler for global status transitions with optional from/to filters */
|
|
50
|
-
export type GlobalTransitionHandler = {
|
|
51
|
-
from?: CreatableStatus
|
|
52
|
-
handler: (from: CreatableStatus, to: CreatableStatus) => void
|
|
53
|
-
to?: CreatableStatus
|
|
54
|
-
}
|
|
55
|
-
/** Handler for named service status transitions with optional from/to filters */
|
|
56
|
-
export type TransitionHandler = GlobalTransitionHandler & {
|
|
57
|
-
name?: string
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Monitors runtime service statuses and fires transition callbacks on status changes */
|
|
61
|
-
export class RuntimeStatusMonitor extends LoggerStatusReporter {
|
|
62
|
-
private globalTransitions: GlobalTransitionHandler[] = []
|
|
63
|
-
private transitions: TransitionHandler[] = []
|
|
64
|
-
|
|
65
|
-
getGlobalStatus(): CreatableStatus {
|
|
66
|
-
// If no statuses have been reported, return the sentinel status
|
|
67
|
-
if (Object.keys(this.statusMap).length === 0) return SENTINEL_STATUS
|
|
68
|
-
return reduceToMinimumStatus(Object.values(this.statusMap))
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
getStatus(name: CreatableName): CreatableStatus | undefined {
|
|
72
|
-
return this.statusMap[name]
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
onGlobalTransition(match: { from?: CreatableStatus; to?: CreatableStatus }, handler: (from: CreatableStatus, to: CreatableStatus) => void) {
|
|
76
|
-
this.globalTransitions.push({ ...match, handler })
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Register a callback to be called on a specific transition.
|
|
81
|
-
*/
|
|
82
|
-
onTransition(match: { from?: CreatableStatus; name: string; to?: CreatableStatus }, handler: (from: CreatableStatus, to: CreatableStatus) => void) {
|
|
83
|
-
this.transitions.push({ ...match, handler })
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
override report(name: CreatableName, status: CreatableStatus, progress?: number | Error): void {
|
|
87
|
-
// Capture the current status before updating
|
|
88
|
-
const previous = this.statusMap[name]
|
|
89
|
-
const previousGlobal = this.getGlobalStatus()
|
|
90
|
-
|
|
91
|
-
// Update the status map with the new status
|
|
92
|
-
super.report(name, status, progress)
|
|
93
|
-
|
|
94
|
-
// If the status hasn't changed, do not run handlers
|
|
95
|
-
if (previous === status) return
|
|
96
|
-
this.runTransitions(this.transitions, previous, status, name)
|
|
97
|
-
|
|
98
|
-
// If the global status hasn't changed, do not run handlers
|
|
99
|
-
const globalStatus = this.getGlobalStatus()
|
|
100
|
-
if (previousGlobal === globalStatus) return
|
|
101
|
-
this.runTransitions(this.globalTransitions, previousGlobal, globalStatus)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private runTransitions(
|
|
105
|
-
transitions: (TransitionHandler | GlobalTransitionHandler)[],
|
|
106
|
-
prev: CreatableStatus,
|
|
107
|
-
next: CreatableStatus,
|
|
108
|
-
name?: string,
|
|
109
|
-
) {
|
|
110
|
-
for (const {
|
|
111
|
-
from, to, name: matchName, handler,
|
|
112
|
-
} of transitions as TransitionHandler[]) {
|
|
113
|
-
if ((matchName === undefined || matchName === name)
|
|
114
|
-
&& (from === undefined || from === prev)
|
|
115
|
-
&& (to === undefined || to === next)) {
|
|
116
|
-
handler(prev, next)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CreatableName, CreatableStatus, CreatableStatusReporter, Logger,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
|
|
5
|
-
/** Status reporter that logs status changes and tracks service status counts */
|
|
6
|
-
export class LoggerStatusReporter implements CreatableStatusReporter {
|
|
7
|
-
protected logger: Logger
|
|
8
|
-
|
|
9
|
-
protected statusMap: Record<CreatableName, CreatableStatus> = {}
|
|
10
|
-
|
|
11
|
-
constructor(logger: Logger) {
|
|
12
|
-
this.logger = logger
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
report(name: CreatableName, status: CreatableStatus, progress?: number | Error): void {
|
|
16
|
-
this.statusMap[name] = status
|
|
17
|
-
const starting = (Object.entries(this.statusMap).map(([, value]): number => value === 'starting' ? 1 : 0)).reduce((a, b) => a + b, 0)
|
|
18
|
-
const started = (Object.entries(this.statusMap).map(([, value]): number => value === 'started' ? 1 : 0)).reduce((a, b) => a + b, 0)
|
|
19
|
-
this.logger.info(`${started}/${starting + started} ${name} status: ${status}`, { progress })
|
|
20
|
-
}
|
|
21
|
-
}
|
package/src/status/index.ts
DELETED
package/src/summary/index.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import { AsObjectFactory } from '@xylabs/sdk-js'
|
|
3
|
-
import type { WithStorageMeta } from '@xyo-network/sdk-js'
|
|
4
|
-
import {
|
|
5
|
-
asSchema, isPayloadOfSchemaType, isStorageMeta,
|
|
6
|
-
} from '@xyo-network/sdk-js'
|
|
7
|
-
|
|
8
|
-
import type { SignedBigInt } from '../../SignedBigInt.ts'
|
|
9
|
-
import type { StepSummary } from './StepSummary.ts'
|
|
10
|
-
|
|
11
|
-
/** Schema identifier for balances step summary payloads */
|
|
12
|
-
export const BalancesStepSummarySchema = asSchema('network.xyo.step.summary.balances', true)
|
|
13
|
-
/** Schema type for BalancesStepSummary payloads. */
|
|
14
|
-
export type BalancesStepSummarySchema = typeof BalancesStepSummarySchema
|
|
15
|
-
|
|
16
|
-
/** Step summary payload containing net balance changes per address */
|
|
17
|
-
export type BalancesStepSummary = StepSummary<{
|
|
18
|
-
balances: Record<Address, SignedBigInt>
|
|
19
|
-
}, BalancesStepSummarySchema>
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Identity function for determining if an object is an BalancesStepSummary
|
|
23
|
-
*/
|
|
24
|
-
export const isBalancesStepSummary = isPayloadOfSchemaType<BalancesStepSummary>(BalancesStepSummarySchema)
|
|
25
|
-
/** Type assertion factory for BalancesStepSummary payloads */
|
|
26
|
-
export const asBalancesStepSummary = AsObjectFactory.create<BalancesStepSummary>(isBalancesStepSummary)
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Identity function for determining if an object is an BalancesStepSummary with Storage Meta
|
|
30
|
-
*/
|
|
31
|
-
export const isBalancesStepSummaryWithStorageMeta = (value: unknown): value is WithStorageMeta<BalancesStepSummary> => {
|
|
32
|
-
return isBalancesStepSummary(value) && isStorageMeta(value)
|
|
33
|
-
}
|
|
34
|
-
/** Type assertion factory for BalancesStepSummary with storage metadata */
|
|
35
|
-
export const asBalancesStepSummaryWithStorageMeta = AsObjectFactory.create<WithStorageMeta<BalancesStepSummary>>(isBalancesStepSummaryWithStorageMeta)
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { AsObjectFactory } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Schema, WithStorageMeta } from '@xyo-network/sdk-js'
|
|
3
|
-
import {
|
|
4
|
-
asSchema, isPayloadOfSchemaType, isStorageMeta,
|
|
5
|
-
} from '@xyo-network/sdk-js'
|
|
6
|
-
|
|
7
|
-
import type { StepSummary } from './StepSummary.ts'
|
|
8
|
-
|
|
9
|
-
/** Schema identifier for schemas step summary payloads */
|
|
10
|
-
export const SchemasStepSummarySchema = asSchema('network.xyo.step.summary.schemas', true)
|
|
11
|
-
/** Schema type for sStepSummary payloads. */
|
|
12
|
-
export type SchemasStepSummarySchema = typeof SchemasStepSummarySchema
|
|
13
|
-
|
|
14
|
-
/** Step summary payload containing schema occurrence counts */
|
|
15
|
-
export type SchemasStepSummary = StepSummary<{
|
|
16
|
-
schemas: Record<Schema, number>
|
|
17
|
-
}, SchemasStepSummarySchema>
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Identity function for determining if an object is an SchemasStepSummary
|
|
21
|
-
*/
|
|
22
|
-
export const isSchemasStepSummary = isPayloadOfSchemaType<SchemasStepSummary>(SchemasStepSummarySchema)
|
|
23
|
-
/** Type assertion factory for SchemasStepSummary payloads */
|
|
24
|
-
export const asSchemasStepSummary = AsObjectFactory.create<SchemasStepSummary>(isSchemasStepSummary)
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Identity function for determining if an object is an SchemasStepSummary with Storage Meta
|
|
28
|
-
*/
|
|
29
|
-
export const isSchemasStepSummaryWithStorageMeta = (value: unknown): value is WithStorageMeta<SchemasStepSummary> => {
|
|
30
|
-
return isSchemasStepSummary(value) && isStorageMeta(value)
|
|
31
|
-
}
|
|
32
|
-
/** Type assertion factory for SchemasStepSummary with storage metadata */
|
|
33
|
-
export const asSchemasStepSummaryWithStorageMeta = AsObjectFactory.create<WithStorageMeta<SchemasStepSummary>>(isSchemasStepSummaryWithStorageMeta)
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { EmptyObject, Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
asSchema, type Payload, type Schema,
|
|
4
|
-
} from '@xyo-network/sdk-js'
|
|
5
|
-
|
|
6
|
-
/** Schema identifier for step summary payloads */
|
|
7
|
-
export const StepSummarySchema = asSchema('network.xyo.step.summary', true)
|
|
8
|
-
/** Schema type for StepSummary payloads. */
|
|
9
|
-
export type StepSummarySchema = typeof StepSummarySchema
|
|
10
|
-
|
|
11
|
-
/** Fields common to all step summary payloads */
|
|
12
|
-
export interface StepSummaryFields {
|
|
13
|
-
hash: Hash // the stepHash - the hash of the last block in the step frame
|
|
14
|
-
stepSize: number // the stepSize in blocks
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Payload type for a step summary with optional additional fields and schema */
|
|
18
|
-
export type StepSummary<TAdditionalFields extends EmptyObject | void = void,
|
|
19
|
-
TSchema extends Schema | void = void> = Payload<TAdditionalFields extends void ? StepSummaryFields : TAdditionalFields & StepSummaryFields,
|
|
20
|
-
TSchema extends void ? StepSummarySchema : TSchema>
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import { AsObjectFactory } from '@xylabs/sdk-js'
|
|
3
|
-
import type { WithStorageMeta } from '@xyo-network/sdk-js'
|
|
4
|
-
import {
|
|
5
|
-
asSchema, isPayloadOfSchemaType, isStorageMeta,
|
|
6
|
-
} from '@xyo-network/sdk-js'
|
|
7
|
-
|
|
8
|
-
import type { SignedBigInt } from '../../SignedBigInt.ts'
|
|
9
|
-
import type { StepSummary } from './StepSummary.ts'
|
|
10
|
-
|
|
11
|
-
/** Schema identifier for transfers step summary payloads */
|
|
12
|
-
export const TransfersStepSummarySchema = asSchema('network.xyo.step.summary.transfer', true)
|
|
13
|
-
/** Schema type for TransfersStepSummary payloads. */
|
|
14
|
-
export type TransfersStepSummarySchema = typeof TransfersStepSummarySchema
|
|
15
|
-
|
|
16
|
-
/** Step summary payload containing transfer amounts between address pairs */
|
|
17
|
-
export type TransfersStepSummary = StepSummary<{
|
|
18
|
-
transfers: Record<Address, Record<Address, SignedBigInt>>
|
|
19
|
-
}, TransfersStepSummarySchema>
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Identity function for determining if an object is an TransfersStepSummary
|
|
23
|
-
*/
|
|
24
|
-
export const isTransfersStepSummary = isPayloadOfSchemaType<TransfersStepSummary>(TransfersStepSummarySchema)
|
|
25
|
-
/** Type assertion factory for TransfersStepSummary payloads */
|
|
26
|
-
export const asTransfersStepSummary = AsObjectFactory.create<TransfersStepSummary>(isTransfersStepSummary)
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Identity function for determining if an object is an TransfersStepSummary with Storage Meta
|
|
30
|
-
*/
|
|
31
|
-
export const isTransfersStepSummaryWithStorageMeta = (value: unknown): value is WithStorageMeta<TransfersStepSummary> => {
|
|
32
|
-
return isTransfersStepSummary(value) && isStorageMeta(value)
|
|
33
|
-
}
|
|
34
|
-
/** Type assertion factory for TransfersStepSummary with storage metadata */
|
|
35
|
-
export const asTransfersStepSummaryWithStorageMeta
|
|
36
|
-
= AsObjectFactory.create<WithStorageMeta<TransfersStepSummary>>(isTransfersStepSummaryWithStorageMeta)
|