@xyo-network/xl1-protocol-sdk 1.26.12 → 1.26.14
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/config/Actors.d.ts +1 -1
- package/dist/neutral/config/Base.d.ts +1 -1
- package/dist/neutral/config/Config.d.ts +4 -4
- package/dist/neutral/payloads/AddressPairPayload.d.ts +1 -1
- package/dist/neutral/payloads/AddressPairPayload.d.ts.map +1 -1
- package/dist/neutral/primitives/uncle/findBestUncle.d.ts +13 -13
- package/dist/neutral/primitives/uncle/findUncles.d.ts +2 -2
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +2 -2
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +2 -2
- package/dist/neutral/simple/chainContractViewer/SimpleChainContractViewer.d.ts +1 -1
- 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 -21
- 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,94 +0,0 @@
|
|
|
1
|
-
import { type Address, spanRootAsync } from '@xylabs/sdk-js'
|
|
2
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
3
|
-
import { isAnyPayload } from '@xyo-network/sdk-js'
|
|
4
|
-
import type {
|
|
5
|
-
BlockViewer, CachingContext, MapType, XL1BlockRange,
|
|
6
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
7
|
-
import { asXL1BlockNumber, StepSizes } from '@xyo-network/xl1-protocol-lib'
|
|
8
|
-
import type { Semaphore } from 'async-mutex'
|
|
9
|
-
|
|
10
|
-
import { deepCalculateFramesFromRange } from '../../../block/index.ts'
|
|
11
|
-
import { withContextCacheResponse } from '../../../ChainContextHelpers.ts'
|
|
12
|
-
import { netBalancesForPayloads } from '../../../payloads/index.ts'
|
|
13
|
-
import {
|
|
14
|
-
parseSignedBigInt, type SignedBigInt, toSignedBigInt,
|
|
15
|
-
} from '../../../SignedBigInt.ts'
|
|
16
|
-
import type { BalancesStepSummary } from '../../model/index.ts'
|
|
17
|
-
import { BalancesStepSummarySchema } from '../../model/index.ts'
|
|
18
|
-
|
|
19
|
-
/** BalancesStepSummaryFromRange helper function. */
|
|
20
|
-
export async function balancesStepSummaryFromRange(
|
|
21
|
-
context: CachingContext,
|
|
22
|
-
semaphores: Semaphore[],
|
|
23
|
-
blockViewer: BlockViewer,
|
|
24
|
-
summaryMap: MapType<string, BalancesStepSummary>,
|
|
25
|
-
range: XL1BlockRange,
|
|
26
|
-
): Promise<BalancesStepSummary> {
|
|
27
|
-
const cacheKey = `${range[0]}|${range[1]}`
|
|
28
|
-
return await withContextCacheResponse(context, 'balancesStepSummaryFromRange', cacheKey, async () => {
|
|
29
|
-
return await spanRootAsync('balancesStepSummaryFromRange', async () => {
|
|
30
|
-
// console.log(`balanceStepSummaryFromRange: head=${head}, range=${range[0]}-${range[1]}`)
|
|
31
|
-
const [frameHead] = assertEx(await blockViewer.blockByNumber(range[1]), () => `Block not found for number: ${range[1]}`)
|
|
32
|
-
const frameSize = range[1] - range[0] + 1
|
|
33
|
-
|
|
34
|
-
const key = `${frameHead._hash}|${frameSize}`
|
|
35
|
-
|
|
36
|
-
return (frameSize === 1)
|
|
37
|
-
? await spanRootAsync(`balancesStepSummaryFromRange.frameSize=1[${key}]`, async () => {
|
|
38
|
-
const [,payloads] = assertEx(await blockViewer.blockByNumber(range[0]), () => `Block not found for number: ${range[0]}`)
|
|
39
|
-
const balances: Record<Address, SignedBigInt> = {}
|
|
40
|
-
for (const [address, balance] of Object.entries(netBalancesForPayloads(context, payloads))) {
|
|
41
|
-
balances[address as Address] = toSignedBigInt(balance)
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
schema: BalancesStepSummarySchema, hash: frameHead._hash, stepSize: -1, balances,
|
|
45
|
-
}
|
|
46
|
-
}, { ...context, timeBudgetLimit: 500 })
|
|
47
|
-
: await spanRootAsync(`balancesStepSummaryFromRange.frameSize>1[${key}]`, async () => {
|
|
48
|
-
const step = StepSizes.indexOf(asXL1BlockNumber(frameSize, true))
|
|
49
|
-
assertEx(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes.join(', ')}`)
|
|
50
|
-
|
|
51
|
-
const summaryResult = await summaryMap.get(`${frameHead._hash}|${frameSize}`)
|
|
52
|
-
if (isAnyPayload(summaryResult)) {
|
|
53
|
-
return summaryResult as BalancesStepSummary
|
|
54
|
-
} else {
|
|
55
|
-
// We do not have it, so lets build it
|
|
56
|
-
await semaphores[step].acquire()
|
|
57
|
-
try {
|
|
58
|
-
const subRanges = deepCalculateFramesFromRange(range, step - 1)
|
|
59
|
-
const promises = subRanges.map(subRange => balancesStepSummaryFromRange(
|
|
60
|
-
context,
|
|
61
|
-
semaphores,
|
|
62
|
-
blockViewer,
|
|
63
|
-
summaryMap,
|
|
64
|
-
subRange,
|
|
65
|
-
))
|
|
66
|
-
const subResults = await Promise.all(promises)
|
|
67
|
-
|
|
68
|
-
// add them all up
|
|
69
|
-
const bigIntBalances: Record<Address, bigint> = {}
|
|
70
|
-
for (const subResult of subResults) {
|
|
71
|
-
for (const [address, balance] of Object.entries(subResult.balances)) {
|
|
72
|
-
bigIntBalances[address as Address] = (bigIntBalances[address as Address] ?? 0n) + parseSignedBigInt(balance)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const balances: Record<Address, SignedBigInt> = {}
|
|
77
|
-
for (const [address, balance] of Object.entries(bigIntBalances)) {
|
|
78
|
-
balances[address as Address] = toSignedBigInt(balance)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const result = {
|
|
82
|
-
schema: BalancesStepSummarySchema, hash: frameHead._hash, stepSize: frameSize, balances,
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
await summaryMap.set(key, result)
|
|
86
|
-
return result
|
|
87
|
-
} finally {
|
|
88
|
-
semaphores[step].release()
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}, { ...context, timeBudgetLimit: 500 })
|
|
92
|
-
}, { ...context, timeBudgetLimit: 500 })
|
|
93
|
-
}, { max: 100_000 })
|
|
94
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
asAddress, assertEx, spanRootAsync,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import type {
|
|
6
|
-
BlockViewer,
|
|
7
|
-
CachingContext, ChainQualified, ChainQualifiedConfig,
|
|
8
|
-
MapType,
|
|
9
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
10
|
-
import {
|
|
11
|
-
asBlockBoundWitnessWithStorageMeta, asXL1BlockRange, isChainQualifiedHeadConfig,
|
|
12
|
-
isChainQualifiedRangeConfig,
|
|
13
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
14
|
-
import type { Semaphore } from 'async-mutex'
|
|
15
|
-
|
|
16
|
-
import { deepCalculateFramesFromRange } from '../../../block/index.ts'
|
|
17
|
-
import { parseSignedBigInt } from '../../../SignedBigInt.ts'
|
|
18
|
-
import type { BalancesStepSummary } from '../../model/index.ts'
|
|
19
|
-
import { balancesStepSummaryFromRange } from './balancesStepSummaryFromRange.ts'
|
|
20
|
-
|
|
21
|
-
/** BalancesSummary helper function. */
|
|
22
|
-
export async function balancesSummary(
|
|
23
|
-
context: CachingContext,
|
|
24
|
-
semaphores: Semaphore[],
|
|
25
|
-
blockViewer: BlockViewer,
|
|
26
|
-
summaryMap: MapType<string, BalancesStepSummary>,
|
|
27
|
-
config?: ChainQualifiedConfig,
|
|
28
|
-
): Promise<ChainQualified<Record<Address, bigint>>> {
|
|
29
|
-
return await spanRootAsync('balancesSummary', async () => {
|
|
30
|
-
const headHash = isChainQualifiedHeadConfig(config) ? config.head : await blockViewer.currentBlockHash()
|
|
31
|
-
const [head] = assertEx(await blockViewer.blockByHash(headHash), () => `Block not found for hash: ${headHash}`)
|
|
32
|
-
const headBoundWitness = asBlockBoundWitnessWithStorageMeta(head, () => `Found Block not a BlockWithHashMeta: ${headHash}`)
|
|
33
|
-
const range = isChainQualifiedRangeConfig(config) ? config.range : asXL1BlockRange([0, headBoundWitness.block], true)
|
|
34
|
-
const ranges = deepCalculateFramesFromRange(asXL1BlockRange(
|
|
35
|
-
range,
|
|
36
|
-
{ name: 'balancesSummary' },
|
|
37
|
-
))
|
|
38
|
-
const summaries = await Promise.all(ranges.map(range => balancesStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range)))
|
|
39
|
-
const balances: Record<Address, bigint> = {}
|
|
40
|
-
for (let summary of summaries) {
|
|
41
|
-
for (const [address, balance] of Object.entries(summary.balances)) {
|
|
42
|
-
const validAddress = asAddress(address, () => `Invalid address: ${address}`)
|
|
43
|
-
balances[validAddress] = (balances[validAddress] ?? 0n) + parseSignedBigInt(balance)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return [balances, { range, head: headHash }]
|
|
47
|
-
}, { ...context, timeBudgetLimit: 500 })
|
|
48
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Schema, WithHashMeta } from '@xyo-network/sdk-js'
|
|
3
|
-
import {
|
|
4
|
-
isAnyPayload, isBoundWitness,
|
|
5
|
-
isHashMeta, PayloadBuilder,
|
|
6
|
-
} from '@xyo-network/sdk-js'
|
|
7
|
-
import type {
|
|
8
|
-
BlockViewer, CachingContext, MapType, XL1BlockRange,
|
|
9
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
10
|
-
import { StepSizes } from '@xyo-network/xl1-protocol-lib'
|
|
11
|
-
import type { Semaphore } from 'async-mutex'
|
|
12
|
-
|
|
13
|
-
import { deepCalculateFramesFromRange } from '../../../block/index.ts'
|
|
14
|
-
import { type SchemasStepSummary, SchemasStepSummarySchema } from '../../model/index.ts'
|
|
15
|
-
|
|
16
|
-
/** SchemasStepSummaryFromRange helper function. */
|
|
17
|
-
export async function schemasStepSummaryFromRange(
|
|
18
|
-
context: CachingContext,
|
|
19
|
-
semaphores: Semaphore[],
|
|
20
|
-
blockViewer: BlockViewer,
|
|
21
|
-
summaryMap: MapType<string, WithHashMeta<SchemasStepSummary>>,
|
|
22
|
-
range: XL1BlockRange,
|
|
23
|
-
): Promise<WithHashMeta<SchemasStepSummary>> {
|
|
24
|
-
// console.log(`balanceStepSummaryFromRange: head=${head}, range=${range[0]}-${range[1]}`)
|
|
25
|
-
const [frameHead] = assertEx(await blockViewer.blockByNumber(range[1]), () => `Block not found for number: ${range[1]}`)
|
|
26
|
-
const frameSize = range[1] - range[0] + 1
|
|
27
|
-
|
|
28
|
-
let result: WithHashMeta<SchemasStepSummary> | undefined = undefined
|
|
29
|
-
|
|
30
|
-
if (frameSize === 1) {
|
|
31
|
-
const [block, payloads] = assertEx(await blockViewer.blockByNumber(range[0]), () => `Block not found for number: ${range[0]}`)
|
|
32
|
-
const boundWitnesses = [block, ...payloads.filter(x => isBoundWitness(x) && isHashMeta(x))]
|
|
33
|
-
const schemas: Record<Schema, number> = {}
|
|
34
|
-
for (const bw of boundWitnesses) {
|
|
35
|
-
schemas[bw.schema] = (schemas[bw.schema] ?? 0) + 1
|
|
36
|
-
for (const schema of bw.payload_schemas) {
|
|
37
|
-
schemas[schema] = (schemas[schema] ?? 0) + 1
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
result = await PayloadBuilder.addHashMeta({
|
|
41
|
-
schema: SchemasStepSummarySchema, hash: frameHead._hash, stepSize: -1, schemas,
|
|
42
|
-
})
|
|
43
|
-
} else {
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
-
const step = (StepSizes as any).indexOf(frameSize)
|
|
46
|
-
assertEx(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes.join(', ')}`)
|
|
47
|
-
|
|
48
|
-
const summaryResult = await summaryMap.get(`${frameHead._hash}|${frameSize}`)
|
|
49
|
-
if (isAnyPayload(summaryResult)) {
|
|
50
|
-
result = summaryResult as WithHashMeta<SchemasStepSummary>
|
|
51
|
-
} else {
|
|
52
|
-
// We do not have it, so lets build it
|
|
53
|
-
await semaphores[step].acquire()
|
|
54
|
-
try {
|
|
55
|
-
const subRanges = deepCalculateFramesFromRange(range, step - 1)
|
|
56
|
-
const promises = subRanges.map(subRange => schemasStepSummaryFromRange(
|
|
57
|
-
context,
|
|
58
|
-
semaphores,
|
|
59
|
-
blockViewer,
|
|
60
|
-
summaryMap,
|
|
61
|
-
subRange,
|
|
62
|
-
))
|
|
63
|
-
const subResults = await Promise.all(promises)
|
|
64
|
-
|
|
65
|
-
// add them all up
|
|
66
|
-
const schemas: Record<Schema, number> = {}
|
|
67
|
-
for (const subResult of subResults) {
|
|
68
|
-
for (const [schema, count] of Object.entries(subResult.schemas)) {
|
|
69
|
-
const typedSchema = schema as Schema
|
|
70
|
-
schemas[typedSchema] = (schemas[typedSchema] ?? 0) + count
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
result = await PayloadBuilder.addHashMeta({
|
|
75
|
-
schema: SchemasStepSummarySchema, hash: frameHead._hash, stepSize: frameSize, schemas: schemas,
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
await summaryMap.set(`${frameHead._hash}|${frameSize}`, result)
|
|
79
|
-
} finally {
|
|
80
|
-
semaphores[step].release()
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
// console.log(`balanceStepSummaryFromRange-result: head=${head}, range=${range[0]}-${range[1]}: ${toSafeJsonString(result, 10)}`)
|
|
85
|
-
return await PayloadBuilder.addHashMeta(result)
|
|
86
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { assertEx, spanRootAsync } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Schema, WithHashMeta } from '@xyo-network/sdk-js'
|
|
3
|
-
import type {
|
|
4
|
-
BlockViewer, CachingContext, ChainQualified, ChainQualifiedConfig,
|
|
5
|
-
MapType,
|
|
6
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
7
|
-
import {
|
|
8
|
-
asBlockBoundWitnessWithStorageMeta, asXL1BlockRange, isChainQualifiedHeadConfig,
|
|
9
|
-
isChainQualifiedRangeConfig,
|
|
10
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
11
|
-
import type { Semaphore } from 'async-mutex'
|
|
12
|
-
|
|
13
|
-
import { deepCalculateFramesFromRange } from '../../../block/index.ts'
|
|
14
|
-
import type { SchemasStepSummary } from '../../model/index.ts'
|
|
15
|
-
import { schemasStepSummaryFromRange } from './schemasStepSummaryFromRange.ts'
|
|
16
|
-
|
|
17
|
-
/** SchemasSummary helper function. */
|
|
18
|
-
export async function schemasSummary(
|
|
19
|
-
context: CachingContext,
|
|
20
|
-
semaphores: Semaphore[],
|
|
21
|
-
blockViewer: BlockViewer,
|
|
22
|
-
summaryMap: MapType<string, WithHashMeta<SchemasStepSummary>>,
|
|
23
|
-
config?: ChainQualifiedConfig,
|
|
24
|
-
): Promise<ChainQualified<Record<Schema, number>>> {
|
|
25
|
-
return await spanRootAsync('schemasSummary', async () => {
|
|
26
|
-
const headHash = isChainQualifiedHeadConfig(config) ? config.head : await blockViewer.currentBlockHash()
|
|
27
|
-
const [head] = assertEx(await blockViewer.blockByHash(headHash), () => `Block not found for hash: ${headHash}`)
|
|
28
|
-
const headBoundWitness = asBlockBoundWitnessWithStorageMeta(head, () => `Found Block not a BlockWithHashMeta: ${headHash}`)
|
|
29
|
-
const range = isChainQualifiedRangeConfig(config) ? config.range : asXL1BlockRange([0, headBoundWitness.block], true)
|
|
30
|
-
const ranges = deepCalculateFramesFromRange(asXL1BlockRange(
|
|
31
|
-
range,
|
|
32
|
-
{ name: 'schemasSummary' },
|
|
33
|
-
))
|
|
34
|
-
const summaries = await Promise.all(ranges.map(range => schemasStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range)))
|
|
35
|
-
const results: Record<Schema, number> = {}
|
|
36
|
-
for (let summary of summaries) {
|
|
37
|
-
for (const [schema, count] of Object.entries(summary.schemas)) {
|
|
38
|
-
const typedSchema = schema as Schema
|
|
39
|
-
results[typedSchema] = (results[typedSchema] ?? 0) + count
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return [results, { range, head: headHash }]
|
|
43
|
-
}, context)
|
|
44
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
|
-
import type { Address, Hash } from '@xylabs/sdk-js'
|
|
3
|
-
import { assertEx, spanRootAsync } from '@xylabs/sdk-js'
|
|
4
|
-
import { isAnyPayload } from '@xyo-network/sdk-js'
|
|
5
|
-
import type {
|
|
6
|
-
BlockViewer, CachingContext, MapType, XL1BlockRange,
|
|
7
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
8
|
-
import { asXL1BlockNumber, StepSizes } from '@xyo-network/xl1-protocol-lib'
|
|
9
|
-
import type { Semaphore } from 'async-mutex'
|
|
10
|
-
|
|
11
|
-
import { deepCalculateFramesFromRange } from '../../../block/index.ts'
|
|
12
|
-
import { withContextCacheResponse } from '../../../ChainContextHelpers.ts'
|
|
13
|
-
import { netTransfersForPayloads } from '../../../payloads/index.ts'
|
|
14
|
-
import {
|
|
15
|
-
parseSignedBigInt, type SignedBigInt, toSignedBigInt,
|
|
16
|
-
} from '../../../SignedBigInt.ts'
|
|
17
|
-
import {
|
|
18
|
-
asTransfersStepSummary, type TransfersStepSummary, TransfersStepSummarySchema,
|
|
19
|
-
} from '../../model/index.ts'
|
|
20
|
-
|
|
21
|
-
/** TransfersSummaryKey helper function. */
|
|
22
|
-
export function transfersSummaryKey(frameHeadHash: Hash, frameSize: number) {
|
|
23
|
-
return `${frameHeadHash}|${frameSize}`
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** TransfersStepSummaryFromRange helper function. */
|
|
27
|
-
export async function transfersStepSummaryFromRange(
|
|
28
|
-
context: CachingContext,
|
|
29
|
-
semaphores: Semaphore[],
|
|
30
|
-
blockViewer: BlockViewer,
|
|
31
|
-
summaryMap: MapType<string, TransfersStepSummary>,
|
|
32
|
-
range: XL1BlockRange,
|
|
33
|
-
): Promise<TransfersStepSummary> {
|
|
34
|
-
const cacheKey = `${range[0]}|${range[1]}`
|
|
35
|
-
return await withContextCacheResponse(context, 'transfersStepSummaryFromRange', cacheKey, async () => {
|
|
36
|
-
return await spanRootAsync('transfersStepSummaryFromRange', async () => {
|
|
37
|
-
const [frameHead] = assertEx(await blockViewer.blockByNumber(range[1]), () => `Block not found for number: ${range[1]}`)
|
|
38
|
-
const frameSize = range[1] - range[0] + 1
|
|
39
|
-
|
|
40
|
-
let result: TransfersStepSummary | undefined
|
|
41
|
-
|
|
42
|
-
if (frameSize === 1) {
|
|
43
|
-
const [, payloads] = assertEx(await blockViewer.blockByNumber(range[0]), () => `Block not found for number: ${range[0]}`)
|
|
44
|
-
const transfers: Record<Address, Record<Address, SignedBigInt>> = {}
|
|
45
|
-
for (const [from, toMap] of Object.entries(netTransfersForPayloads(context, payloads))) {
|
|
46
|
-
transfers[from as Address] = transfers[from as Address] ?? {}
|
|
47
|
-
for (const [to, amount] of Object.entries(toMap)) {
|
|
48
|
-
transfers[from as Address][to as Address] = toSignedBigInt(amount)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
result = {
|
|
52
|
-
schema: TransfersStepSummarySchema, hash: frameHead._hash, stepSize: -1, transfers,
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
const step = (StepSizes).indexOf(asXL1BlockNumber(frameSize, true))
|
|
56
|
-
assertEx(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes.join(', ')}`)
|
|
57
|
-
|
|
58
|
-
const key = transfersSummaryKey(frameHead._hash, frameSize)
|
|
59
|
-
|
|
60
|
-
const summaryResult = await summaryMap.get(key)
|
|
61
|
-
if (isAnyPayload(summaryResult)) {
|
|
62
|
-
result = asTransfersStepSummary(summaryResult, { required: true })
|
|
63
|
-
} else {
|
|
64
|
-
await semaphores[step].acquire()
|
|
65
|
-
// We do not have it, so lets build it
|
|
66
|
-
try {
|
|
67
|
-
const subRanges = deepCalculateFramesFromRange(range, step - 1)
|
|
68
|
-
const promises = subRanges.map(subRange => transfersStepSummaryFromRange(
|
|
69
|
-
context,
|
|
70
|
-
semaphores,
|
|
71
|
-
blockViewer,
|
|
72
|
-
summaryMap,
|
|
73
|
-
subRange,
|
|
74
|
-
))
|
|
75
|
-
const subResults = await Promise.all(promises)
|
|
76
|
-
|
|
77
|
-
// add them all up
|
|
78
|
-
const bigIntBalances: Record<Address, Record<Address, bigint>> = {}
|
|
79
|
-
for (const subResult of subResults) {
|
|
80
|
-
for (const [from, toMap] of Object.entries(subResult.transfers)) {
|
|
81
|
-
bigIntBalances[from as Address] = bigIntBalances[from as Address] ?? {}
|
|
82
|
-
for (const [to, transfer] of Object.entries(toMap)) {
|
|
83
|
-
bigIntBalances[from as Address][to as Address] = (bigIntBalances[from as Address][to as Address] ?? 0n) + parseSignedBigInt(transfer)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const transfers: Record<Address, Record<Address, SignedBigInt>> = {}
|
|
89
|
-
for (const [from, toMap] of Object.entries(bigIntBalances)) {
|
|
90
|
-
transfers[from as Address] = transfers[from as Address] ?? {}
|
|
91
|
-
for (const [to, transfer] of Object.entries(toMap)) {
|
|
92
|
-
transfers[from as Address][to as Address] = toSignedBigInt(transfer)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
result = {
|
|
97
|
-
schema: TransfersStepSummarySchema, hash: frameHead._hash, stepSize: frameSize, transfers,
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
await summaryMap.set(key, result)
|
|
101
|
-
} finally {
|
|
102
|
-
semaphores[step].release()
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return result
|
|
107
|
-
}, { ...context, timeBudgetLimit: 500 })
|
|
108
|
-
}, { max: 100_000 })
|
|
109
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
asAddress, assertEx, spanRootAsync,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import type {
|
|
6
|
-
BlockViewer, CachingContext, ChainQualified, ChainQualifiedConfig,
|
|
7
|
-
MapType,
|
|
8
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
9
|
-
import {
|
|
10
|
-
asBlockBoundWitnessWithStorageMeta, asXL1BlockRange, isChainQualifiedHeadConfig,
|
|
11
|
-
isChainQualifiedRangeConfig,
|
|
12
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
13
|
-
import type { Semaphore } from 'async-mutex'
|
|
14
|
-
|
|
15
|
-
import { deepCalculateFramesFromRange } from '../../../block/index.ts'
|
|
16
|
-
import { parseSignedBigInt } from '../../../SignedBigInt.ts'
|
|
17
|
-
import type { TransfersStepSummary } from '../../model/index.ts'
|
|
18
|
-
import { transfersStepSummaryFromRange } from './transfersStepSummaryFromRange.ts'
|
|
19
|
-
|
|
20
|
-
// the summary of amount of rewards claimed from the step reward pool by addresses
|
|
21
|
-
/** TransfersSummary helper function. */
|
|
22
|
-
export async function transfersSummary(
|
|
23
|
-
context: CachingContext,
|
|
24
|
-
semaphores: Semaphore[],
|
|
25
|
-
blockViewer: BlockViewer,
|
|
26
|
-
summaryMap: MapType<string, TransfersStepSummary>,
|
|
27
|
-
config?: ChainQualifiedConfig,
|
|
28
|
-
): Promise<ChainQualified<Record<Address, Record<Address, bigint>>>> {
|
|
29
|
-
return await spanRootAsync('transferSummary', async () => {
|
|
30
|
-
const headHash = isChainQualifiedHeadConfig(config) ? config.head : await blockViewer.currentBlockHash()
|
|
31
|
-
const [head] = assertEx(await blockViewer.blockByHash(headHash), () => `Block not found for hash: ${headHash}`)
|
|
32
|
-
const headBoundWitness = asBlockBoundWitnessWithStorageMeta(head, () => `Found Block not a BlockWithHashMeta: ${headHash}`)
|
|
33
|
-
const range = isChainQualifiedRangeConfig(config) ? config.range : asXL1BlockRange([0, headBoundWitness.block], true)
|
|
34
|
-
const ranges = deepCalculateFramesFromRange(asXL1BlockRange(
|
|
35
|
-
range,
|
|
36
|
-
{ name: 'transfersSummary' },
|
|
37
|
-
))
|
|
38
|
-
const summaries = await Promise.all(ranges.map(range => transfersStepSummaryFromRange(context, semaphores, blockViewer, summaryMap, range)))
|
|
39
|
-
const transfers: Record<Address, Record<Address, bigint>> = {}
|
|
40
|
-
for (let summary of summaries) {
|
|
41
|
-
for (const [from, toMap] of Object.entries(summary.transfers)) {
|
|
42
|
-
const validFrom = asAddress(from, () => `Invalid address: ${from}`)
|
|
43
|
-
transfers[validFrom] = transfers[validFrom] ?? {}
|
|
44
|
-
for (const [to, transfer] of Object.entries(toMap)) {
|
|
45
|
-
const validTo = asAddress(to, () => `Invalid address: ${to}`)
|
|
46
|
-
transfers[validFrom][validTo] = (transfers[validFrom][validTo] ?? 0n) + parseSignedBigInt(transfer)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return [transfers, { range, head: headHash }]
|
|
51
|
-
}, { ...context, timeBudgetLimit: 500 })
|
|
52
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { Address, Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
isAddress, isArray, isHash,
|
|
4
|
-
isNumber, isObject,
|
|
5
|
-
} from '@xylabs/sdk-js'
|
|
6
|
-
import type { AccountInstance } from '@xyo-network/sdk-js'
|
|
7
|
-
import type {
|
|
8
|
-
AllowedBlockPayload, AttoXL1, ChainId, SignedHydratedTransaction, XL1BlockNumber,
|
|
9
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
10
|
-
|
|
11
|
-
/** Options for BaseBuildBlock. */
|
|
12
|
-
export interface BaseBuildBlockOptions {
|
|
13
|
-
blockPayloads: AllowedBlockPayload[]
|
|
14
|
-
chainId: ChainId
|
|
15
|
-
chainStepRewardAddress?: Address
|
|
16
|
-
previousBlockNumber?: XL1BlockNumber
|
|
17
|
-
protocol?: number
|
|
18
|
-
signers: AccountInstance[]
|
|
19
|
-
txs: SignedHydratedTransaction[]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Type guard that checks if a value is a valid BaseBuildBlockOptions. */
|
|
23
|
-
export const isBaseBuildBlockOptions = (value: unknown): value is BaseBuildBlockOptions => {
|
|
24
|
-
if (!isObject(value)) {
|
|
25
|
-
return false
|
|
26
|
-
}
|
|
27
|
-
const typedValue = value as BaseBuildBlockOptions
|
|
28
|
-
if (!isArray(typedValue.blockPayloads) || !isAddress(typedValue.chainId) || !isArray(typedValue.signers) || !isArray(typedValue.txs)) {
|
|
29
|
-
return false
|
|
30
|
-
}
|
|
31
|
-
return true
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Options for BuildGenesisBlock. */
|
|
35
|
-
export interface BuildGenesisBlockOptions extends BaseBuildBlockOptions {
|
|
36
|
-
previousBlockHash: null
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Type guard that checks if a value is a valid BuildGenesisBlockOptions. */
|
|
40
|
-
export const isBuildGenesisBlockOptions = (value: unknown): value is BuildGenesisBlockOptions => {
|
|
41
|
-
if (!isBaseBuildBlockOptions(value)) {
|
|
42
|
-
return false
|
|
43
|
-
}
|
|
44
|
-
const typedValue = value as BuildGenesisBlockOptions
|
|
45
|
-
if (typedValue.previousBlockHash !== null) {
|
|
46
|
-
return false
|
|
47
|
-
}
|
|
48
|
-
if (typedValue.previousBlockNumber !== undefined) {
|
|
49
|
-
return false
|
|
50
|
-
}
|
|
51
|
-
return true
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** Options for BuildNextBlock. */
|
|
55
|
-
export interface BuildNextBlockOptions extends BaseBuildBlockOptions {
|
|
56
|
-
previousBlockHash: Hash
|
|
57
|
-
previousBlockNumber: XL1BlockNumber
|
|
58
|
-
previousStepHashes: Hash[]
|
|
59
|
-
stepRewardPoolBalance: AttoXL1
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Type guard that checks if a value is a valid BuildNextBlockOptions. */
|
|
63
|
-
export const isBuildNextBlockOptions = (value: unknown): value is BuildNextBlockOptions => {
|
|
64
|
-
if (!isBaseBuildBlockOptions(value)) {
|
|
65
|
-
return false
|
|
66
|
-
}
|
|
67
|
-
const typedValue = value as BuildNextBlockOptions
|
|
68
|
-
if (!isHash(typedValue.previousBlockHash)) {
|
|
69
|
-
return false
|
|
70
|
-
}
|
|
71
|
-
if (!isNumber(typedValue.previousBlockNumber)) {
|
|
72
|
-
return false
|
|
73
|
-
}
|
|
74
|
-
if (!isArray(typedValue.previousStepHashes)) {
|
|
75
|
-
return false
|
|
76
|
-
}
|
|
77
|
-
return true
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** BuildBlockOptions type. */
|
|
81
|
-
export type BuildBlockOptions = BuildGenesisBlockOptions | BuildNextBlockOptions
|
package/src/test/buildBlock.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import type { Hex } from '@xylabs/sdk-js'
|
|
2
|
-
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import type { Payload, WithStorageMeta } from '@xyo-network/sdk-js'
|
|
4
|
-
import {
|
|
5
|
-
asAnyPayload, BoundWitnessBuilder, PayloadBuilder,
|
|
6
|
-
} from '@xyo-network/sdk-js'
|
|
7
|
-
import type {
|
|
8
|
-
BlockBoundWitness, SignedHydratedBlockWithHashMeta, Transfer,
|
|
9
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
10
|
-
import {
|
|
11
|
-
asXL1BlockNumber, AttoXL1, isBlockBoundWitness, StepRewardFractions,
|
|
12
|
-
StepSizes,
|
|
13
|
-
XL1_PROTOCOL_VERSION,
|
|
14
|
-
XYO_STEP_REWARD_ADDRESS,
|
|
15
|
-
XYO_ZERO_ADDRESS,
|
|
16
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
17
|
-
|
|
18
|
-
import { validateTransactionsOpcodes } from '../block/index.ts'
|
|
19
|
-
import { createTransferPayload } from '../createTransferPayload.ts'
|
|
20
|
-
import { completedStepRewardAddress } from '../primitives/index.ts'
|
|
21
|
-
import {
|
|
22
|
-
type BuildBlockOptions, isBuildGenesisBlockOptions, isBuildNextBlockOptions,
|
|
23
|
-
} from './BuildBlockOptions.ts'
|
|
24
|
-
|
|
25
|
-
/*
|
|
26
|
-
//this is for testing only to speed up the pace
|
|
27
|
-
export const StepRewardFractions = [
|
|
28
|
-
[0n, 1n], // 0%
|
|
29
|
-
[1n, 10_000n], // 0.01%
|
|
30
|
-
[2n, 1000n], // 0.2%
|
|
31
|
-
[3n, 100n], // 3%
|
|
32
|
-
[45n, 100n], // 45%
|
|
33
|
-
] as const
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
function calculateCompletedStepReward(step: number, balance: AttoXL1): AttoXL1 {
|
|
37
|
-
return AttoXL1(StepRewardFractions[step][0] * balance / StepRewardFractions[step][1])
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Builds a Block instance. */
|
|
41
|
-
export async function buildBlock(options: BuildBlockOptions): Promise<SignedHydratedBlockWithHashMeta> {
|
|
42
|
-
const previousBlockNumber = isBuildGenesisBlockOptions(options) ? -1 : options.previousBlockNumber
|
|
43
|
-
const blockNumber = asXL1BlockNumber(previousBlockNumber + 1, true)
|
|
44
|
-
const inStepHashes = isBuildNextBlockOptions(options) ? options.previousStepHashes : []
|
|
45
|
-
const previousBlockHash = isBuildNextBlockOptions(options) ? options.previousBlockHash : undefined
|
|
46
|
-
const stepRewardPoolBalance = isBuildNextBlockOptions(options) ? options.stepRewardPoolBalance : AttoXL1(0n)
|
|
47
|
-
const {
|
|
48
|
-
chainId, txs,
|
|
49
|
-
chainStepRewardAddress = XYO_STEP_REWARD_ADDRESS,
|
|
50
|
-
blockPayloads, protocol = XL1_PROTOCOL_VERSION, signers,
|
|
51
|
-
} = options
|
|
52
|
-
const step_hashes: Hex[] = []
|
|
53
|
-
|
|
54
|
-
for (const [tx] of txs) {
|
|
55
|
-
if (tx.nbf > blockNumber) {
|
|
56
|
-
throw new Error(`Transaction ${await PayloadBuilder.hash(tx)} not valid for block ${blockNumber} - NBF is ${tx.nbf}`)
|
|
57
|
-
}
|
|
58
|
-
if (tx.exp < blockNumber) {
|
|
59
|
-
throw new Error(`Transaction ${await PayloadBuilder.hash(tx)} not valid for block ${blockNumber} - EXP is ${tx.exp}`)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const completedStepRewardTransfers: Transfer[] = []
|
|
64
|
-
|
|
65
|
-
// update the step hashes
|
|
66
|
-
for (const [i, step] of StepSizes.entries()) {
|
|
67
|
-
if (blockNumber < step) {
|
|
68
|
-
break
|
|
69
|
-
}
|
|
70
|
-
if (blockNumber % step === 0) {
|
|
71
|
-
if (StepRewardFractions[i][0] > 0 && chainStepRewardAddress !== XYO_ZERO_ADDRESS) {
|
|
72
|
-
const completedStepRewardHolderAddress = completedStepRewardAddress({ block: blockNumber, step })
|
|
73
|
-
const completedStepReward = calculateCompletedStepReward(i, stepRewardPoolBalance)
|
|
74
|
-
completedStepRewardTransfers.push(createTransferPayload(chainStepRewardAddress, { [completedStepRewardHolderAddress]: completedStepReward }))
|
|
75
|
-
}
|
|
76
|
-
step_hashes.push(assertEx(previousBlockHash, () => `Previous block hash is required for step ${step} at block ${blockNumber}`))
|
|
77
|
-
} else {
|
|
78
|
-
if (isDefined(inStepHashes.at(i))) {
|
|
79
|
-
step_hashes.push(inStepHashes[i])
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const previous = previousBlockHash ?? null
|
|
85
|
-
const block = blockNumber
|
|
86
|
-
const txElevatedPayloads = await validateTransactionsOpcodes(txs)
|
|
87
|
-
|
|
88
|
-
const payloads: Payload[] = [
|
|
89
|
-
...txs.map(([tx]) => tx),
|
|
90
|
-
...blockPayloads,
|
|
91
|
-
...txElevatedPayloads,
|
|
92
|
-
...completedStepRewardTransfers,
|
|
93
|
-
]
|
|
94
|
-
|
|
95
|
-
const [bw, txPayloads] = await new BoundWitnessBuilder<BlockBoundWitness, WithStorageMeta<Payload>>()
|
|
96
|
-
.fields({
|
|
97
|
-
block, chain: chainId, previous, step_hashes, protocol,
|
|
98
|
-
})
|
|
99
|
-
.meta({ $epoch: Date.now(), $signatures: [] })
|
|
100
|
-
.signers(signers)
|
|
101
|
-
.payloads(await PayloadBuilder.addStorageMeta(payloads))
|
|
102
|
-
.build()
|
|
103
|
-
assertEx(isBlockBoundWitness(bw), () => 'Build of BlockBoundWitness failed')
|
|
104
|
-
return [await PayloadBuilder.addStorageMeta(bw), txPayloads.map(p => asAnyPayload(p, true))]
|
|
105
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { AccountInstance } from '@xyo-network/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
AllowedBlockPayload, ChainId,
|
|
4
|
-
SignedHydratedBlockWithHashMeta,
|
|
5
|
-
SignedHydratedTransactionWithHashMeta,
|
|
6
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
7
|
-
import { XYO_ZERO_ADDRESS } from '@xyo-network/xl1-protocol-lib'
|
|
8
|
-
|
|
9
|
-
import { buildBlock } from './buildBlock.ts'
|
|
10
|
-
|
|
11
|
-
/** Builds a GenesisBlock instance. */
|
|
12
|
-
export async function buildGenesisBlock(
|
|
13
|
-
chainId: ChainId,
|
|
14
|
-
txs: SignedHydratedTransactionWithHashMeta[],
|
|
15
|
-
blockPayloads: AllowedBlockPayload[],
|
|
16
|
-
signers: AccountInstance[],
|
|
17
|
-
chainStepRewardAddress = XYO_ZERO_ADDRESS,
|
|
18
|
-
protocol?: number,
|
|
19
|
-
): Promise<SignedHydratedBlockWithHashMeta> {
|
|
20
|
-
return await buildBlock({
|
|
21
|
-
previousBlockHash: null,
|
|
22
|
-
chainId,
|
|
23
|
-
txs,
|
|
24
|
-
blockPayloads,
|
|
25
|
-
signers,
|
|
26
|
-
chainStepRewardAddress,
|
|
27
|
-
protocol,
|
|
28
|
-
})
|
|
29
|
-
}
|