@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,271 +0,0 @@
|
|
|
1
|
-
import type { Address, Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
asHash,
|
|
4
|
-
assertEx, exists, isDefined,
|
|
5
|
-
ZERO_ADDRESS,
|
|
6
|
-
} from '@xylabs/sdk-js'
|
|
7
|
-
import type { WithHashMeta, WithStorageMeta } from '@xyo-network/sdk-js'
|
|
8
|
-
import type {
|
|
9
|
-
AccountBalanceConfig,
|
|
10
|
-
AccountBalanceHistoryItem,
|
|
11
|
-
AccountBalanceViewer,
|
|
12
|
-
BlockViewer,
|
|
13
|
-
ChainQualification,
|
|
14
|
-
ChainQualified,
|
|
15
|
-
MapType,
|
|
16
|
-
SignedBlockBoundWitnessWithHashMeta, Transfer, XL1BlockNumber, XL1BlockRange,
|
|
17
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
18
|
-
import {
|
|
19
|
-
AccountBalanceViewerMoniker,
|
|
20
|
-
asRange, asXL1BlockNumber, asXL1BlockRange, AttoXL1,
|
|
21
|
-
BlockViewerMoniker,
|
|
22
|
-
isChainQualifiedHeadConfig,
|
|
23
|
-
isChainQualifiedRangeConfig,
|
|
24
|
-
StepSizes,
|
|
25
|
-
TransferSchema,
|
|
26
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
27
|
-
import { Semaphore } from 'async-mutex'
|
|
28
|
-
|
|
29
|
-
import { deepCalculateFramesFromRange } from '../../block/index.ts'
|
|
30
|
-
import type { CreatableProviderParams } from '../../CreatableProvider/index.ts'
|
|
31
|
-
import { AbstractCreatableProvider, creatableProvider } from '../../CreatableProvider/index.ts'
|
|
32
|
-
import type { BalancesStepSummary, TransfersStepSummary } from '../../summary/index.ts'
|
|
33
|
-
import {
|
|
34
|
-
balancesSummary,
|
|
35
|
-
transfersStepSummaryFromRange,
|
|
36
|
-
} from '../../summary/index.ts'
|
|
37
|
-
|
|
38
|
-
/** Parameters for SimpleAccountBalanceViewer. */
|
|
39
|
-
export interface SimpleAccountBalanceViewerParams extends CreatableProviderParams {
|
|
40
|
-
balancesSummaryMap: MapType<string, WithHashMeta<BalancesStepSummary>>
|
|
41
|
-
transfersSummaryMap: MapType<string, WithHashMeta<TransfersStepSummary>>
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** SimpleAccountBalanceViewer implementation. */
|
|
45
|
-
@creatableProvider()
|
|
46
|
-
export class SimpleAccountBalanceViewer extends AbstractCreatableProvider<SimpleAccountBalanceViewerParams> implements AccountBalanceViewer {
|
|
47
|
-
static readonly defaultMoniker = AccountBalanceViewerMoniker
|
|
48
|
-
static readonly dependencies = [BlockViewerMoniker]
|
|
49
|
-
static readonly monikers = [AccountBalanceViewerMoniker]
|
|
50
|
-
moniker = SimpleAccountBalanceViewer.defaultMoniker
|
|
51
|
-
|
|
52
|
-
private _balanceStepSemaphores = StepSizes.map(() => new Semaphore(20))
|
|
53
|
-
private _blockViewer!: BlockViewer
|
|
54
|
-
private _transferStepSemaphores = StepSizes.map(() => new Semaphore(20))
|
|
55
|
-
|
|
56
|
-
get balancesSummaryMap() {
|
|
57
|
-
return this.params.balancesSummaryMap
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get blockViewer() {
|
|
61
|
-
return this._blockViewer
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
get transfersSummaryMap() {
|
|
65
|
-
return this.params.transfersSummaryMap
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
static override async paramsHandler(params: Partial<SimpleAccountBalanceViewerParams> = {}) {
|
|
69
|
-
return {
|
|
70
|
-
...await super.paramsHandler(params),
|
|
71
|
-
balancesSummaryMap: assertEx(params.balancesSummaryMap, () => 'balancesSummaryMap is required'),
|
|
72
|
-
transfersSummaryMap: assertEx(params.transfersSummaryMap, () => 'transfersSummaryMap is required'),
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async accountBalance(address: Address, config?: AccountBalanceConfig) {
|
|
77
|
-
const balances = await this.accountBalances([address], config)
|
|
78
|
-
return balances[address] ?? AttoXL1(0n)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async accountBalanceHistories(addresses: Address[], config: AccountBalanceConfig = {}) {
|
|
82
|
-
return (await this.qualifiedAccountBalanceHistories(addresses, config))[0]
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async accountBalanceHistory(address: Address, config?: AccountBalanceConfig) {
|
|
86
|
-
return await this.spanAsync('accountBalanceHistory', async () => {
|
|
87
|
-
const range = isChainQualifiedRangeConfig(config) ? config.range : undefined
|
|
88
|
-
const startingRange = asXL1BlockRange(range ?? [0, await this.blockViewer.currentBlockNumber()], true)
|
|
89
|
-
const blockNumbers = await this.distillTransferHistory(address, startingRange)
|
|
90
|
-
const blocks = (await Promise.all(blockNumbers.map(async bn => await this.blockViewer.blockByNumber(bn)))).filter(exists)
|
|
91
|
-
const result: AccountBalanceHistoryItem[] = []
|
|
92
|
-
for (const block of blocks) {
|
|
93
|
-
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema ? index : undefined).filter(exists)
|
|
94
|
-
const transfers = transferIndexes.map((index) => {
|
|
95
|
-
const hash = block[0].payload_hashes[index]
|
|
96
|
-
return assertEx(
|
|
97
|
-
block[1].find(p => p._hash === hash) as WithStorageMeta<Transfer>,
|
|
98
|
-
() => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`,
|
|
99
|
-
)
|
|
100
|
-
}).filter(exists).filter(t => ((t.from === address) || (isDefined(t.transfers[address]))))
|
|
101
|
-
if (transfers.length === 0) {
|
|
102
|
-
continue
|
|
103
|
-
}
|
|
104
|
-
const pairs: [SignedBlockBoundWitnessWithHashMeta, WithHashMeta<Transfer>][] = (transfers.map((transfer) => {
|
|
105
|
-
return [block[0], transfer]
|
|
106
|
-
}))
|
|
107
|
-
result.push(...pairs.map(([block, transfer]) => [block,
|
|
108
|
-
null,
|
|
109
|
-
transfer] satisfies AccountBalanceHistoryItem))
|
|
110
|
-
}
|
|
111
|
-
return result
|
|
112
|
-
}, this.context)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async accountBalances(address: Address[], config?: AccountBalanceConfig) {
|
|
116
|
-
const [result] = (await this.qualifiedAccountBalances(address, config ?? {}))
|
|
117
|
-
return result
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
override async createHandler() {
|
|
121
|
-
await super.createHandler()
|
|
122
|
-
this._blockViewer = await this.locator.getInstance<BlockViewer>(BlockViewerMoniker)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async qualifiedAccountBalanceHistories(
|
|
126
|
-
addresses: Address[],
|
|
127
|
-
config: AccountBalanceConfig,
|
|
128
|
-
) {
|
|
129
|
-
return await this.spanAsync('qualifiedAccountBalanceHistories', async () => {
|
|
130
|
-
const head = isChainQualifiedHeadConfig(config) ? config.head : await this.blockViewer.currentBlockHash()
|
|
131
|
-
const range = isChainQualifiedRangeConfig(config)
|
|
132
|
-
? config.range
|
|
133
|
-
: asXL1BlockRange([0,
|
|
134
|
-
assertEx(
|
|
135
|
-
await this.blockViewer.blockByHash(head),
|
|
136
|
-
() => `Error: Could not find block with hash ${head}`,
|
|
137
|
-
)[0].block])
|
|
138
|
-
const qualifiedEntries = await Promise.all(addresses.map(async address => ([
|
|
139
|
-
address,
|
|
140
|
-
await this.qualifiedAccountBalanceHistory(address, range),
|
|
141
|
-
]))) satisfies [Address, ChainQualified<AccountBalanceHistoryItem[]>][]
|
|
142
|
-
|
|
143
|
-
const entries = qualifiedEntries.map(([address, [history]]) => {
|
|
144
|
-
return [address, history]
|
|
145
|
-
})
|
|
146
|
-
const qualifiedRange = qualifiedEntries[0][1][1].range
|
|
147
|
-
const qualifiedHeadHash = qualifiedEntries[0][1][1].head
|
|
148
|
-
|
|
149
|
-
// check for drift
|
|
150
|
-
for (const [_, [__, { range, head }]] of qualifiedEntries) {
|
|
151
|
-
assertEx(
|
|
152
|
-
range[0] === qualifiedRange[0] && range[1] === qualifiedRange[1],
|
|
153
|
-
() => 'Inconsistent ranges in qualifiedAccountBalanceHistories',
|
|
154
|
-
)
|
|
155
|
-
assertEx(
|
|
156
|
-
head === qualifiedHeadHash,
|
|
157
|
-
() => 'Inconsistent head hashes in qualifiedAccountBalanceHistories',
|
|
158
|
-
)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return [Object.fromEntries(entries), { range: qualifiedRange, head: qualifiedHeadHash }] satisfies
|
|
162
|
-
[Record<Address, AccountBalanceHistoryItem[]>, ChainQualification]
|
|
163
|
-
}, this.context)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async qualifiedAccountBalances(
|
|
167
|
-
address: Address[],
|
|
168
|
-
config: AccountBalanceConfig,
|
|
169
|
-
): Promise<ChainQualified<Record<Address, AttoXL1>>> {
|
|
170
|
-
return await this.spanAsync('qualifiedAccountsBalances', async () => {
|
|
171
|
-
const qualifiedSummary = await balancesSummary(
|
|
172
|
-
this.context,
|
|
173
|
-
this._balanceStepSemaphores,
|
|
174
|
-
this.blockViewer,
|
|
175
|
-
this.balancesSummaryMap,
|
|
176
|
-
config,
|
|
177
|
-
)
|
|
178
|
-
const result: Record<Address, AttoXL1> = {}
|
|
179
|
-
for (const addr of address) {
|
|
180
|
-
const summaryBalance = qualifiedSummary[0][addr] ?? 0n
|
|
181
|
-
result[addr] = AttoXL1(summaryBalance < 0n ? 0n : summaryBalance)
|
|
182
|
-
}
|
|
183
|
-
return [result, qualifiedSummary[1]]
|
|
184
|
-
}, this.context)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
override async startHandler() {
|
|
188
|
-
await super.startHandler()
|
|
189
|
-
await Promise.all([
|
|
190
|
-
this.accountBalance(ZERO_ADDRESS),
|
|
191
|
-
this.accountBalanceHistory(ZERO_ADDRESS),
|
|
192
|
-
])
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
private async distillTransferHistory(address: Address, range: XL1BlockRange, max: number = 50): Promise<XL1BlockNumber[]> {
|
|
196
|
-
return await this.spanAsync('distillTransferHistory', async () => {
|
|
197
|
-
if ((range[1] - range[0]) <= StepSizes[0] || max <= 1) {
|
|
198
|
-
return Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[1] - i).slice(0, max).map(n => asXL1BlockNumber(n, true))
|
|
199
|
-
}
|
|
200
|
-
const frames = deepCalculateFramesFromRange(asXL1BlockRange(range, true))
|
|
201
|
-
const transferSummaryPairs = await Promise.all(frames.map(
|
|
202
|
-
async (frame) => {
|
|
203
|
-
return [frame, await transfersStepSummaryFromRange(this.context, this._transferStepSemaphores, this.blockViewer, this.transfersSummaryMap, frame)]
|
|
204
|
-
},
|
|
205
|
-
)) as [XL1BlockRange, WithStorageMeta<TransfersStepSummary>][]
|
|
206
|
-
|
|
207
|
-
const filteredTransferSummaryPairs = transferSummaryPairs.filter(([_, summary]) => Object.keys(summary.transfers).includes(address))
|
|
208
|
-
|
|
209
|
-
// sort it latest to earliest
|
|
210
|
-
const sortedTransferSummaryPairs = filteredTransferSummaryPairs.toSorted((a, b) => {
|
|
211
|
-
return b[0][1] - a[0][1]
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
const resultBlockNumbers: Set<XL1BlockNumber> = new Set()
|
|
215
|
-
for (const [frame] of sortedTransferSummaryPairs) {
|
|
216
|
-
if ((frame[1] - frame[0] + 1) > StepSizes[0]) {
|
|
217
|
-
const values = await this.distillTransferHistory(address, asXL1BlockRange([frame[0], frame[1] - 1], true), max - resultBlockNumbers.size)
|
|
218
|
-
for (const value of values) {
|
|
219
|
-
resultBlockNumbers.add(value)
|
|
220
|
-
}
|
|
221
|
-
resultBlockNumbers.add(frame[1])
|
|
222
|
-
} else {
|
|
223
|
-
for (let i = frame[0]; i <= frame[1]; i++) {
|
|
224
|
-
resultBlockNumbers.add(i)
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (resultBlockNumbers.size >= max) {
|
|
228
|
-
break
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return [...resultBlockNumbers].toSorted((a, b) => b - a).slice(0, max)
|
|
232
|
-
}, this.context)
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
private async qualifiedAccountBalanceHistory(
|
|
236
|
-
address: Address,
|
|
237
|
-
headOrRange?: Hash | XL1BlockRange,
|
|
238
|
-
): Promise<ChainQualified<AccountBalanceHistoryItem[]>> {
|
|
239
|
-
return await this.spanAsync('qualifiedAccountBalanceHistory', async () => {
|
|
240
|
-
const range = asRange(headOrRange)
|
|
241
|
-
const headHash = asHash(headOrRange)
|
|
242
|
-
const [head] = assertEx(isDefined(headHash)
|
|
243
|
-
? (await this.blockViewer.blockByHash(headHash))
|
|
244
|
-
: (await this.blockViewer.currentBlock()), () => 'Could not resolve head block')
|
|
245
|
-
const startingRange = asXL1BlockRange(range ?? [0, head.block], true)
|
|
246
|
-
const blockNumbers = await this.distillTransferHistory(address, startingRange)
|
|
247
|
-
const blocks = (await Promise.all(blockNumbers.map(async bn => await this.blockViewer.blockByNumber(bn)))).filter(exists)
|
|
248
|
-
const result: AccountBalanceHistoryItem[] = []
|
|
249
|
-
for (const block of blocks) {
|
|
250
|
-
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema ? index : undefined).filter(exists)
|
|
251
|
-
const transfers = transferIndexes.map((index) => {
|
|
252
|
-
const hash = block[0].payload_hashes[index]
|
|
253
|
-
return assertEx(
|
|
254
|
-
block[1].find(p => p._hash === hash) as WithStorageMeta<Transfer>,
|
|
255
|
-
() => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`,
|
|
256
|
-
)
|
|
257
|
-
}).filter(exists).filter(t => ((t.from === address) || (isDefined(t.transfers[address]))))
|
|
258
|
-
if (transfers.length === 0) {
|
|
259
|
-
continue
|
|
260
|
-
}
|
|
261
|
-
const pairs: [SignedBlockBoundWitnessWithHashMeta, WithHashMeta<Transfer>][] = (transfers.map((transfer) => {
|
|
262
|
-
return [block[0], transfer]
|
|
263
|
-
}))
|
|
264
|
-
result.push(...pairs.map(([block, transfer]) => [block,
|
|
265
|
-
null,
|
|
266
|
-
transfer] satisfies AccountBalanceHistoryItem))
|
|
267
|
-
}
|
|
268
|
-
return [result, { range: startingRange, head: head._hash }]
|
|
269
|
-
}, this.context)
|
|
270
|
-
}
|
|
271
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SimpleAccountBalanceViewer.ts'
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
assertEx, exists, isUndefined,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import type {
|
|
6
|
-
Payload, ReadArchivist, WithHashMeta,
|
|
7
|
-
} from '@xyo-network/sdk-js'
|
|
8
|
-
import {
|
|
9
|
-
asSignedHydratedBlockWithHashMeta, asSignedHydratedBlockWithStorageMeta, asXL1BlockNumber,
|
|
10
|
-
BlockContextRead,
|
|
11
|
-
BlockRate, BlockViewer, BlockViewerMoniker, ChainContextRead,
|
|
12
|
-
ChainId, DataLakeViewer, DataLakeViewerMoniker, FinalizationViewer, FinalizationViewerMoniker, type SignedHydratedBlockWithHashMeta,
|
|
13
|
-
SignedHydratedBlockWithStorageMeta, SingleTimeConfig, TimeDurations, type XL1BlockNumber, XL1BlockRange,
|
|
14
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
15
|
-
|
|
16
|
-
import { hydrateBlock } from '../../block/index.ts'
|
|
17
|
-
import type { CreatableProviderParams } from '../../CreatableProvider/index.ts'
|
|
18
|
-
import { AbstractCreatableProvider, creatableProvider } from '../../CreatableProvider/index.ts'
|
|
19
|
-
import { LruCacheMap } from '../../driver/index.ts'
|
|
20
|
-
import { ChainStoreRead } from '../../model/index.ts'
|
|
21
|
-
import {
|
|
22
|
-
addDataLakePayloads,
|
|
23
|
-
addDataLakePayloadsToPayloads,
|
|
24
|
-
calculateBlockRate, calculateStepSizeRate, calculateTimeRate, hydratedBlockByNumber,
|
|
25
|
-
} from '../../primitives/index.ts'
|
|
26
|
-
import { HydratedCache } from '../../utils/index.ts'
|
|
27
|
-
|
|
28
|
-
/** Parameters for SimpleBlockViewer. */
|
|
29
|
-
export interface SimpleBlockViewerParams extends CreatableProviderParams {
|
|
30
|
-
finalizedArchivist: ReadArchivist
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** SimpleBlockViewer implementation. */
|
|
34
|
-
@creatableProvider()
|
|
35
|
-
export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockViewerParams> implements BlockViewer {
|
|
36
|
-
static readonly defaultMoniker = BlockViewerMoniker
|
|
37
|
-
static readonly dependencies = [FinalizationViewerMoniker]
|
|
38
|
-
static readonly monikers = [BlockViewerMoniker]
|
|
39
|
-
moniker = SimpleBlockViewer.defaultMoniker
|
|
40
|
-
|
|
41
|
-
protected _store?: ChainStoreRead
|
|
42
|
-
protected dataLakeViewer?: DataLakeViewer
|
|
43
|
-
protected finalizationViewer!: FinalizationViewer
|
|
44
|
-
protected payloadCache = new LruCacheMap<Hash, WithHashMeta<Payload>>({ max: 10_000 })
|
|
45
|
-
protected signedHydratedBlockWithDataLakePayloadsCache = new LruCacheMap<Hash, SignedHydratedBlockWithHashMeta>({ max: 2000, ttl: 1000 * 60 * 60 })
|
|
46
|
-
|
|
47
|
-
private _signedHydratedBlockCache: HydratedCache<SignedHydratedBlockWithStorageMeta> | undefined
|
|
48
|
-
|
|
49
|
-
get finalizedArchivist(): ReadArchivist {
|
|
50
|
-
return this.params.finalizedArchivist
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
protected get hydratedBlockCache(): HydratedCache<SignedHydratedBlockWithStorageMeta> {
|
|
54
|
-
if (this._signedHydratedBlockCache) return this._signedHydratedBlockCache
|
|
55
|
-
const context = this.getBlockContextRead()
|
|
56
|
-
this._signedHydratedBlockCache = new HydratedCache<SignedHydratedBlockWithStorageMeta>(context, async (
|
|
57
|
-
context,
|
|
58
|
-
hash: Hash,
|
|
59
|
-
maxDepth?: number,
|
|
60
|
-
minDepth?: number,
|
|
61
|
-
) => {
|
|
62
|
-
const result = await hydrateBlock(context, hash, maxDepth, minDepth)
|
|
63
|
-
return asSignedHydratedBlockWithStorageMeta(result, true)
|
|
64
|
-
}, 20_000)
|
|
65
|
-
return this._signedHydratedBlockCache
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
protected get store() {
|
|
69
|
-
return this._store!
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
static override async paramsHandler(params: Partial<SimpleBlockViewerParams>) {
|
|
73
|
-
return {
|
|
74
|
-
...await super.paramsHandler(params),
|
|
75
|
-
finalizedArchivist: assertEx(params.finalizedArchivist, () => 'finalizedArchivist is required'),
|
|
76
|
-
} satisfies SimpleBlockViewerParams
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async blockByHash(hash: Hash): Promise<SignedHydratedBlockWithHashMeta | null> {
|
|
80
|
-
return await this.spanAsync('blockByHash', async () => {
|
|
81
|
-
const cachedBlock = this.signedHydratedBlockWithDataLakePayloadsCache.get(hash)
|
|
82
|
-
if (cachedBlock) {
|
|
83
|
-
return cachedBlock
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const cache = this.hydratedBlockCache
|
|
87
|
-
const block = await cache.get(hash)
|
|
88
|
-
const [result] = block ? await addDataLakePayloads(block, this.dataLakeViewer) : [null, []]
|
|
89
|
-
if (result) {
|
|
90
|
-
this.signedHydratedBlockWithDataLakePayloadsCache.set(hash, result)
|
|
91
|
-
}
|
|
92
|
-
return result
|
|
93
|
-
}, { ...this.context, timeBudgetLimit: 100 })
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async blockByNumber(blockNumber: XL1BlockNumber): Promise<SignedHydratedBlockWithHashMeta | null> {
|
|
97
|
-
return await this.spanAsync('blockByNumber', async () => {
|
|
98
|
-
const chainContext = await this.getChainContextRead()
|
|
99
|
-
if (isUndefined(chainContext.head)) {
|
|
100
|
-
return null
|
|
101
|
-
}
|
|
102
|
-
return await this.blockByNumberWithContext(chainContext, blockNumber)
|
|
103
|
-
}, { ...this.context, timeBudgetLimit: 100 })
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async blocksByHash(hash: Hash, limit = 50): Promise<SignedHydratedBlockWithHashMeta[]> {
|
|
107
|
-
return await this.spanAsync('blocksByHash', async () => {
|
|
108
|
-
assertEx(limit > 0, () => 'limit must be greater than 0')
|
|
109
|
-
assertEx(limit <= 100, () => 'limit must be less than 100')
|
|
110
|
-
const blocks: SignedHydratedBlockWithHashMeta[] = []
|
|
111
|
-
let current = await this.blockByHash(hash)
|
|
112
|
-
while (current && blocks.length < limit) {
|
|
113
|
-
blocks.push(current)
|
|
114
|
-
const previousHash = current[0].previous
|
|
115
|
-
if (previousHash === null) break
|
|
116
|
-
current = await this.blockByHash(previousHash)
|
|
117
|
-
}
|
|
118
|
-
return blocks.map(b => asSignedHydratedBlockWithHashMeta(b, true))
|
|
119
|
-
}, { ...this.context, timeBudgetLimit: 300 })
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async blocksByNumber(blockNumber: XL1BlockNumber, limit = 50): Promise<SignedHydratedBlockWithHashMeta[]> {
|
|
123
|
-
return await this.spanAsync('blocksByNumber', async () => {
|
|
124
|
-
assertEx(limit > 0, () => 'limit must be greater than 0')
|
|
125
|
-
assertEx(limit <= 100, () => 'limit must be less than 100')
|
|
126
|
-
const chainContext = await this.getChainContextRead()
|
|
127
|
-
if (isUndefined(chainContext.head)) {
|
|
128
|
-
return []
|
|
129
|
-
}
|
|
130
|
-
const blocks: SignedHydratedBlockWithHashMeta[] = []
|
|
131
|
-
let current = await this.blockByNumberWithContext(chainContext, blockNumber)
|
|
132
|
-
while (current && blocks.length < limit) {
|
|
133
|
-
blocks.push(current)
|
|
134
|
-
if (current[0].block === 0) break
|
|
135
|
-
const previousNumber = asXL1BlockNumber(current[0].block - 1, true)
|
|
136
|
-
current = await this.blockByNumberWithContext(chainContext, previousNumber)
|
|
137
|
-
}
|
|
138
|
-
return blocks.map(b => asSignedHydratedBlockWithHashMeta(b, true))
|
|
139
|
-
}, this.context)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
chainId(): Promise<ChainId>
|
|
143
|
-
chainId(blockNumber: XL1BlockNumber): Promise<ChainId>
|
|
144
|
-
chainId(blockNumber: 'latest'): Promise<ChainId>
|
|
145
|
-
async chainId(blockNumber: XL1BlockNumber | 'latest' = 'latest'): Promise<ChainId> {
|
|
146
|
-
return await this.spanAsync('chainId', async () => {
|
|
147
|
-
return blockNumber === 'latest' ? (await this.finalizationViewer.headBlock()).chain : assertEx((await this.blockByNumber(blockNumber)), () => `Block not found [${blockNumber}]`)[0].chain
|
|
148
|
-
}, this.context)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
override async createHandler() {
|
|
152
|
-
await super.createHandler()
|
|
153
|
-
this.dataLakeViewer = await this.locator.tryGetInstance<DataLakeViewer>(DataLakeViewerMoniker)
|
|
154
|
-
this.finalizationViewer = await this.locator.getInstance<FinalizationViewer>(FinalizationViewerMoniker)
|
|
155
|
-
this._store = { chainMap: this.params.finalizedArchivist }
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async currentBlock(): Promise<SignedHydratedBlockWithHashMeta> {
|
|
159
|
-
const [result] = await addDataLakePayloads(await this.finalizationViewer.head(), this.dataLakeViewer)
|
|
160
|
-
return result
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
async currentBlockHash(): Promise<Hash> {
|
|
164
|
-
return await this.finalizationViewer.headHash()
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async currentBlockNumber(): Promise<XL1BlockNumber> {
|
|
168
|
-
return await this.finalizationViewer.headNumber()
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async payloadByHash(hash: Hash): Promise<WithHashMeta<Payload> | null> {
|
|
172
|
-
const [payload] = await this.payloadsByHash([hash])
|
|
173
|
-
return payload ?? null
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async payloadsByHash(hashes: Hash[]): Promise<WithHashMeta<Payload>[]> {
|
|
177
|
-
let remainingHashes = [...hashes]
|
|
178
|
-
const cachedPayloads = this.payloadCache.getMany(remainingHashes)
|
|
179
|
-
const cachedHashes = new Set(cachedPayloads.map(p => p._hash))
|
|
180
|
-
remainingHashes = remainingHashes.filter(h => !cachedHashes.has(h))
|
|
181
|
-
const finalizedPayloads = remainingHashes.length > 0
|
|
182
|
-
? await this.finalizedArchivist.get(remainingHashes)
|
|
183
|
-
: []
|
|
184
|
-
const [resultPayloads] = await addDataLakePayloadsToPayloads(hashes, [...cachedPayloads, ...finalizedPayloads.filter(exists)], this.dataLakeViewer)
|
|
185
|
-
resultPayloads.map((payload) => {
|
|
186
|
-
this.payloadCache.set(payload._hash, payload)
|
|
187
|
-
})
|
|
188
|
-
return resultPayloads
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
async rate(range: XL1BlockRange, timeUnit?: keyof TimeDurations): Promise<BlockRate> {
|
|
192
|
-
return await calculateBlockRate(this, range, timeUnit)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
async stepSizeRate(start: XL1BlockNumber, stepIndex: number, count = 1, timeUnit?: keyof TimeDurations): Promise<BlockRate> {
|
|
196
|
-
return await calculateStepSizeRate(this, start, stepIndex, count, timeUnit)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
async timeDurationRate(
|
|
200
|
-
timeConfig: SingleTimeConfig,
|
|
201
|
-
startBlockNumber?: XL1BlockNumber,
|
|
202
|
-
timeUnit?: keyof TimeDurations,
|
|
203
|
-
toleranceMs?: number,
|
|
204
|
-
maxAttempts?: number,
|
|
205
|
-
): Promise<BlockRate> {
|
|
206
|
-
return await calculateTimeRate(this, timeConfig, startBlockNumber, timeUnit, toleranceMs, maxAttempts)
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
protected getBlockContextRead(): BlockContextRead {
|
|
210
|
-
return {
|
|
211
|
-
...this.context,
|
|
212
|
-
chainMap: this.store.chainMap,
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
protected async getChainContextRead(): Promise<ChainContextRead> {
|
|
217
|
-
return {
|
|
218
|
-
...this.getBlockContextRead(),
|
|
219
|
-
head: (await this.finalizationViewer.head())[0],
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
private async blockByNumberWithContext(
|
|
224
|
-
chainContext: ChainContextRead,
|
|
225
|
-
blockNumber: XL1BlockNumber,
|
|
226
|
-
): Promise<SignedHydratedBlockWithHashMeta | null> {
|
|
227
|
-
const block = asSignedHydratedBlockWithHashMeta(await hydratedBlockByNumber(chainContext, blockNumber)) ?? null
|
|
228
|
-
const [result] = block ? await addDataLakePayloads(block, this.dataLakeViewer) : [null, []]
|
|
229
|
-
return result
|
|
230
|
-
}
|
|
231
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SimpleBlockViewer.ts'
|