@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,32 +0,0 @@
|
|
|
1
|
-
import type { GatewayName } from '@xyo-network/xl1-protocol-lib'
|
|
2
|
-
|
|
3
|
-
/** StatusNetwork type. */
|
|
4
|
-
export type StatusNetwork = {
|
|
5
|
-
id: GatewayName
|
|
6
|
-
statusUrl: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** MainNetworkStats constant. */
|
|
10
|
-
export const MainNetworkStats: StatusNetwork = {
|
|
11
|
-
id: 'mainnet' as GatewayName,
|
|
12
|
-
statusUrl: 'https://xyo.network/chain-network-status-mainnet.json',
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** SequenceNetworkStats constant. */
|
|
16
|
-
export const SequenceNetworkStats: StatusNetwork = {
|
|
17
|
-
id: 'sequence' as GatewayName,
|
|
18
|
-
statusUrl: 'https://beta.xyo.network/chain-network-status-sequence.json',
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** LocalNetworkStats constant. */
|
|
22
|
-
export const LocalNetworkStats: StatusNetwork = {
|
|
23
|
-
id: 'local' as GatewayName,
|
|
24
|
-
statusUrl: 'http://localhost:3002/chain-network-status-local.json',
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** StatusNetworks constant. */
|
|
28
|
-
export const StatusNetworks: Record<GatewayName, StatusNetwork> = {
|
|
29
|
-
['mainnet' as GatewayName]: MainNetworkStats,
|
|
30
|
-
['sequence' as GatewayName]: SequenceNetworkStats,
|
|
31
|
-
['local' as GatewayName]: LocalNetworkStats,
|
|
32
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
CaveatTypes,
|
|
4
|
-
InvokerPermission, PermissionRequest, RequestedPermission, XyoPermissions,
|
|
5
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
6
|
-
|
|
7
|
-
import type { Invoker, PermissionsStore } from './store/index.ts'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* In-memory implementation of XyoPermissions for testing or ephemeral use cases.
|
|
11
|
-
* Does not persist data beyond the lifetime of the instance.
|
|
12
|
-
* Assumes all permission requests are granted and revocations always succeed.
|
|
13
|
-
*/
|
|
14
|
-
export class SimpleXyoPermissions implements XyoPermissions {
|
|
15
|
-
invoker: Invoker
|
|
16
|
-
private _store: PermissionsStore
|
|
17
|
-
|
|
18
|
-
constructor(store: PermissionsStore) {
|
|
19
|
-
this._store = store
|
|
20
|
-
this.invoker = store.invoker
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
get store(): PermissionsStore {
|
|
24
|
-
return assertEx(this._store, () => 'Store must be defined to get permissions')
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async getPermissions(): Promise<InvokerPermission[]> {
|
|
28
|
-
return await this.store.getPermissions()
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// assumed the permissions are always granted
|
|
32
|
-
async requestPermissions(permissions: PermissionRequest[]): Promise<RequestedPermission[]> {
|
|
33
|
-
await Promise.resolve()
|
|
34
|
-
// Flatten PermissionRequest[] into InvokerPermission[]
|
|
35
|
-
const newPermissions: InvokerPermission[] = []
|
|
36
|
-
const now = Date.now()
|
|
37
|
-
for (const req of permissions) {
|
|
38
|
-
for (const parentCapability in req) {
|
|
39
|
-
newPermissions.push({
|
|
40
|
-
invoker: this.invoker,
|
|
41
|
-
parentCapability,
|
|
42
|
-
caveats: Object.entries(req[parentCapability]).map(([type, value]) => ({ type: type as CaveatTypes, value })),
|
|
43
|
-
date: now,
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Update or add permissions in the store
|
|
49
|
-
const existingPermissions = await this.getPermissions()
|
|
50
|
-
for (const perm of newPermissions) {
|
|
51
|
-
const idx = existingPermissions.findIndex(
|
|
52
|
-
p => p.invoker === perm.invoker && p.parentCapability === perm.parentCapability,
|
|
53
|
-
)
|
|
54
|
-
if (idx === -1) {
|
|
55
|
-
existingPermissions.push(perm)
|
|
56
|
-
} else {
|
|
57
|
-
existingPermissions[idx] = perm
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
await this.store.setPermissions(existingPermissions)
|
|
61
|
-
|
|
62
|
-
// Return the granted permissions in RequestedPermission shape
|
|
63
|
-
return newPermissions.map(({ parentCapability, date }) => ({ parentCapability, date }))
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Assumes the permissions are always revoked
|
|
67
|
-
async revokePermissions(permissions: PermissionRequest): Promise<RequestedPermission[]> {
|
|
68
|
-
const existingPermissions = await this.getPermissions()
|
|
69
|
-
const revoked: RequestedPermission[] = []
|
|
70
|
-
for (const parentCapability in permissions) {
|
|
71
|
-
const idx = existingPermissions.findIndex(
|
|
72
|
-
p => p.invoker === this.invoker && p.parentCapability === parentCapability,
|
|
73
|
-
)
|
|
74
|
-
if (idx !== -1) {
|
|
75
|
-
const removed = existingPermissions.splice(idx, 1)[0]
|
|
76
|
-
revoked.push({ parentCapability: removed.parentCapability, date: removed.date })
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
await this.store.setPermissions(existingPermissions)
|
|
80
|
-
return revoked
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import type { InvokerPermission } from '@xyo-network/xl1-protocol-lib'
|
|
3
|
-
|
|
4
|
-
import type { Invoker, PermissionsStore } from './PermissionsStore.ts'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* In-memory implementation of XyoPermissions for testing or ephemeral use cases.
|
|
8
|
-
* Does not persist data beyond the lifetime of the instance.
|
|
9
|
-
* Assumes all permission requests are granted and revocations always succeed.
|
|
10
|
-
*/
|
|
11
|
-
export class MemoryPermissionsStore implements PermissionsStore {
|
|
12
|
-
private _invoker: Invoker
|
|
13
|
-
private permissions: InvokerPermission[] = []
|
|
14
|
-
|
|
15
|
-
constructor(invoker: Invoker) {
|
|
16
|
-
this._invoker = invoker
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get invoker(): Invoker {
|
|
20
|
-
return assertEx(this._invoker, () => 'Invoker must be defined to get permissions')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async getPermissions(): Promise<InvokerPermission[]> {
|
|
24
|
-
await Promise.resolve()
|
|
25
|
-
return this.permissions
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async setPermissions(permissions: InvokerPermission[]): Promise<void> {
|
|
29
|
-
await Promise.resolve()
|
|
30
|
-
this.permissions = permissions
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { InvokerPermission, PermissionsGetHandler } from '@xyo-network/xl1-protocol-lib'
|
|
2
|
-
|
|
3
|
-
/** Invoker type. */
|
|
4
|
-
export type Invoker = string
|
|
5
|
-
/** ParentCapability type. */
|
|
6
|
-
export type ParentCapability = string
|
|
7
|
-
/**
|
|
8
|
-
* Interface for a permissions store that abstracts away the storage medium.
|
|
9
|
-
* (i.e. in-memory, browser storage, database, etc.)
|
|
10
|
-
*/
|
|
11
|
-
export interface PermissionsStore extends PermissionsGetHandler {
|
|
12
|
-
// The invoker associated with this permissions store
|
|
13
|
-
readonly invoker: Invoker
|
|
14
|
-
// Retrieve all permissions associated with the invoker.
|
|
15
|
-
// Store or update permissions for the invoker
|
|
16
|
-
setPermissions(permissions: InvokerPermission[]): Promise<void>
|
|
17
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
3
|
-
import {
|
|
4
|
-
MempoolRunner,
|
|
5
|
-
MempoolRunnerMoniker, SignedHydratedTransactionWithStorageMeta,
|
|
6
|
-
XyoRunner, XyoRunnerMoniker,
|
|
7
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
8
|
-
|
|
9
|
-
import type { CreatableProviderParams } from '../../CreatableProvider/index.ts'
|
|
10
|
-
import { AbstractCreatableProvider, creatableProvider } from '../../CreatableProvider/index.ts'
|
|
11
|
-
|
|
12
|
-
/** Parameters for SimpleXyoRunner. */
|
|
13
|
-
export interface SimpleXyoRunnerParams extends CreatableProviderParams {
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** SimpleXyoRunner implementation. */
|
|
17
|
-
@creatableProvider()
|
|
18
|
-
export class SimpleXyoRunner extends AbstractCreatableProvider<SimpleXyoRunnerParams> implements XyoRunner {
|
|
19
|
-
static readonly defaultMoniker = XyoRunnerMoniker
|
|
20
|
-
static readonly dependencies = [MempoolRunnerMoniker]
|
|
21
|
-
static readonly monikers = [XyoRunnerMoniker]
|
|
22
|
-
moniker = SimpleXyoRunner.defaultMoniker
|
|
23
|
-
|
|
24
|
-
private _mempoolRunner?: MempoolRunner
|
|
25
|
-
|
|
26
|
-
get mempool() {
|
|
27
|
-
return this._mempoolRunner!
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async broadcastTransaction(transaction: SignedHydratedTransactionWithStorageMeta): Promise<Hash> {
|
|
31
|
-
await this.mempool.submitTransactions([transaction])
|
|
32
|
-
const hash = await PayloadBuilder.hash(transaction[0])
|
|
33
|
-
this.logger?.info(`Broadcasted transaction with hash ${hash}`)
|
|
34
|
-
return hash
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
override async createHandler() {
|
|
38
|
-
await super.createHandler()
|
|
39
|
-
this._mempoolRunner = await this.locator.getInstance<MempoolRunner>(MempoolRunnerMoniker)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SimpleXyoRunner.ts'
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { Address, Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type { AccountInstance, Payload } from '@xyo-network/sdk-js'
|
|
3
|
-
import { Account, PayloadBuilder } from '@xyo-network/sdk-js'
|
|
4
|
-
import type {
|
|
5
|
-
AllowedBlockPayload, ChainId, SignedHydratedTransactionWithHashMeta,
|
|
6
|
-
SignedTransactionBoundWitness, TransactionFeesBigInt,
|
|
7
|
-
UnsignedTransactionBoundWitness,
|
|
8
|
-
XL1BlockNumber, XyoSigner,
|
|
9
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
10
|
-
import {
|
|
11
|
-
SignedHydratedTransactionWithHashMetaZod,
|
|
12
|
-
XyoSignerMoniker,
|
|
13
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
14
|
-
|
|
15
|
-
import type { CreatableProviderParams } from '../../CreatableProvider/index.ts'
|
|
16
|
-
import { AbstractCreatableProvider } from '../../CreatableProvider/index.ts'
|
|
17
|
-
import { buildTransaction, signTransaction } from '../../transaction/index.ts'
|
|
18
|
-
|
|
19
|
-
/** Parameters for SimpleXyoSigner. */
|
|
20
|
-
export interface SimpleXyoSignerParams extends CreatableProviderParams {
|
|
21
|
-
account: AccountInstance
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** SimpleXyoSigner implementation. */
|
|
25
|
-
export class SimpleXyoSigner extends AbstractCreatableProvider<SimpleXyoSignerParams> implements XyoSigner {
|
|
26
|
-
static readonly defaultMoniker = XyoSignerMoniker
|
|
27
|
-
static readonly dependencies = []
|
|
28
|
-
static readonly monikers = [XyoSignerMoniker]
|
|
29
|
-
moniker = SimpleXyoSigner.defaultMoniker
|
|
30
|
-
|
|
31
|
-
static override async paramsHandler(params?: Partial<SimpleXyoSignerParams>) {
|
|
32
|
-
let account: AccountInstance
|
|
33
|
-
if (params?.account) {
|
|
34
|
-
account = params.account
|
|
35
|
-
} else {
|
|
36
|
-
const localLogger = params?.logger ?? params?.context?.logger
|
|
37
|
-
localLogger?.warn(`No account provided to SimpleXyoSigner, generating a random account.
|
|
38
|
-
This account will not be persisted and any transactions signed with it may be lost.
|
|
39
|
-
`)
|
|
40
|
-
|
|
41
|
-
account = await Account.random()
|
|
42
|
-
}
|
|
43
|
-
return { ...await super.paramsHandler(params), account }
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
address(): Promisable<Address> {
|
|
47
|
-
return this.params.account.address
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** @deprecated - use signTransaction instead */
|
|
51
|
-
async createSignedTransaction(
|
|
52
|
-
chain: ChainId,
|
|
53
|
-
elevatedPayloads: AllowedBlockPayload[],
|
|
54
|
-
additionalPayloads: Payload[],
|
|
55
|
-
nbf: XL1BlockNumber,
|
|
56
|
-
exp: XL1BlockNumber,
|
|
57
|
-
fees: TransactionFeesBigInt,
|
|
58
|
-
from?: Address,
|
|
59
|
-
): Promise<SignedTransactionBoundWitness> {
|
|
60
|
-
const fromAddress = from ?? await this.address()
|
|
61
|
-
const transaction = await buildTransaction(
|
|
62
|
-
chain,
|
|
63
|
-
elevatedPayloads,
|
|
64
|
-
additionalPayloads,
|
|
65
|
-
this.params.account,
|
|
66
|
-
nbf,
|
|
67
|
-
exp,
|
|
68
|
-
fromAddress,
|
|
69
|
-
fees,
|
|
70
|
-
)
|
|
71
|
-
return transaction[0]
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async signTransaction(tx: [UnsignedTransactionBoundWitness, Payload[]]): Promise<SignedHydratedTransactionWithHashMeta> {
|
|
75
|
-
const txBW = await signTransaction(tx[0], this.params.account)
|
|
76
|
-
return SignedHydratedTransactionWithHashMetaZod.parse([await PayloadBuilder.addStorageMeta(txBW), await PayloadBuilder.addStorageMeta(tx[1])])
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SimpleXyoSigner.ts'
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
asHash, assertEx, isDefined,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import type {
|
|
6
|
-
BlockViewer,
|
|
7
|
-
TimeDomain, TimePayload, TimeSyncViewer,
|
|
8
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
9
|
-
import {
|
|
10
|
-
asTimePayload, asXL1BlockNumber, BlockViewerMoniker, TimeSchema,
|
|
11
|
-
TimeSyncViewerMoniker,
|
|
12
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
13
|
-
import type { Provider } from 'ethers'
|
|
14
|
-
|
|
15
|
-
import type { CreatableProviderParams } from '../../CreatableProvider/index.ts'
|
|
16
|
-
import { AbstractCreatableProvider, creatableProvider } from '../../CreatableProvider/index.ts'
|
|
17
|
-
|
|
18
|
-
/** Parameters for SimpleTimeSyncViewer. */
|
|
19
|
-
export interface SimpleTimeSyncViewerParams extends CreatableProviderParams {
|
|
20
|
-
ethProvider?: Provider
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** SimpleTimeSyncViewer implementation. */
|
|
24
|
-
@creatableProvider()
|
|
25
|
-
export class SimpleTimeSyncViewer extends AbstractCreatableProvider<SimpleTimeSyncViewerParams> implements TimeSyncViewer {
|
|
26
|
-
static readonly defaultMoniker = TimeSyncViewerMoniker
|
|
27
|
-
static readonly dependencies = [BlockViewerMoniker]
|
|
28
|
-
static readonly monikers = [TimeSyncViewerMoniker]
|
|
29
|
-
moniker = SimpleTimeSyncViewer.defaultMoniker
|
|
30
|
-
|
|
31
|
-
private _blockViewer?: BlockViewer
|
|
32
|
-
|
|
33
|
-
protected get blockViewer() {
|
|
34
|
-
return this._blockViewer!
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
protected get ethProvider() {
|
|
38
|
-
return this.params.ethProvider
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async convertTime(fromDomain: TimeDomain, toDomain: TimeDomain, from: number): Promise<number> {
|
|
42
|
-
switch (fromDomain) {
|
|
43
|
-
case 'xl1': {
|
|
44
|
-
const [block, payloads] = assertEx(await this.blockViewer.blockByNumber(asXL1BlockNumber(from, true)), () => 'Block not found')
|
|
45
|
-
const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema)
|
|
46
|
-
const hash = timeSchemaIndex === -1 ? undefined : block.payload_hashes[timeSchemaIndex]
|
|
47
|
-
const timePayload = asTimePayload(isDefined(hash) ? payloads.find(p => p._hash === hash) : undefined)
|
|
48
|
-
if (timePayload === undefined) return 0
|
|
49
|
-
switch (toDomain) {
|
|
50
|
-
case 'xl1': {
|
|
51
|
-
return timePayload.xl1 ?? 0
|
|
52
|
-
}
|
|
53
|
-
case 'epoch': {
|
|
54
|
-
return timePayload.epoch ?? 0
|
|
55
|
-
}
|
|
56
|
-
case 'ethereum': {
|
|
57
|
-
return timePayload.ethereum ?? 0
|
|
58
|
-
}
|
|
59
|
-
default: {
|
|
60
|
-
throw new Error(`Unsupported to toDomain: ${toDomain}`)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
default: {
|
|
65
|
-
throw new Error(`Unsupported from fromDomain: ${fromDomain}`)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
override async createHandler() {
|
|
71
|
-
await super.createHandler()
|
|
72
|
-
this._blockViewer = await this.locator.getInstance<BlockViewer>(BlockViewerMoniker)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async currentTime(domain: TimeDomain): Promise<[string, number]> {
|
|
76
|
-
switch (domain) {
|
|
77
|
-
case 'xl1': {
|
|
78
|
-
return ['xl1', (await this.blockViewer.currentBlock())?.[0].block ?? -1]
|
|
79
|
-
}
|
|
80
|
-
case 'epoch': {
|
|
81
|
-
return ['epoch', Date.now()]
|
|
82
|
-
}
|
|
83
|
-
case 'ethereum': {
|
|
84
|
-
return ['ethereum', (await this.ethProvider?.getBlockNumber()) ?? 0]
|
|
85
|
-
}
|
|
86
|
-
default: {
|
|
87
|
-
throw new Error(`Unknown time domain: ${domain}`)
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async currentTimeAndHash(domain: TimeDomain): Promise<[number, Hash | null]> {
|
|
93
|
-
switch (domain) {
|
|
94
|
-
case 'xl1': {
|
|
95
|
-
const [head] = await this.blockViewer.currentBlock()
|
|
96
|
-
return [head.block, head._hash]
|
|
97
|
-
}
|
|
98
|
-
case 'epoch': {
|
|
99
|
-
return [Date.now(), null]
|
|
100
|
-
}
|
|
101
|
-
case 'ethereum': {
|
|
102
|
-
const provider = assertEx(this.ethProvider, () => 'Ethereum provider not configured')
|
|
103
|
-
const blockNumber = (await provider.getBlockNumber()) ?? 0
|
|
104
|
-
const block = await provider.getBlock(blockNumber)
|
|
105
|
-
const blockHash = asHash(assertEx(block?.hash, () => 'Block hash not found'), true)
|
|
106
|
-
return [blockNumber, blockHash]
|
|
107
|
-
}
|
|
108
|
-
default: {
|
|
109
|
-
throw new Error(`Unknown time domain: ${domain}`)
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async currentTimePayload(): Promise<TimePayload> {
|
|
115
|
-
const [xl1, xl1Hash] = await this.currentTimeAndHash('xl1')
|
|
116
|
-
const timePayload: TimePayload = {
|
|
117
|
-
schema: TimeSchema,
|
|
118
|
-
// this is for the previous block
|
|
119
|
-
xl1,
|
|
120
|
-
// this is for the previous block
|
|
121
|
-
xl1Hash: assertEx(xl1Hash, () => 'No xl1 hash available from time sync service'),
|
|
122
|
-
epoch: Date.now(),
|
|
123
|
-
}
|
|
124
|
-
if (isDefined(this.ethProvider)) {
|
|
125
|
-
const [ethereum, ethHashOrNull] = await this.currentTimeAndHash('ethereum')
|
|
126
|
-
const ethereumHash = asHash(ethHashOrNull, () => 'No ethereum hash available from time sync service')
|
|
127
|
-
timePayload.ethereum = ethereum
|
|
128
|
-
timePayload.ethereumHash = ethereumHash
|
|
129
|
-
}
|
|
130
|
-
return timePayload
|
|
131
|
-
}
|
|
132
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SimpleTimeSyncViewer.ts'
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { assertEx, Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
3
|
-
import {
|
|
4
|
-
AccountBalanceViewer,
|
|
5
|
-
AccountBalanceViewerMoniker,
|
|
6
|
-
asXL1BlockRange,
|
|
7
|
-
BlockInvalidationConfig,
|
|
8
|
-
BlockInvalidationQualification,
|
|
9
|
-
BlockInvalidationViewer,
|
|
10
|
-
BlockInvalidationViewerMoniker,
|
|
11
|
-
BlockViewer,
|
|
12
|
-
BlockViewerMoniker,
|
|
13
|
-
ChainContractViewer,
|
|
14
|
-
ChainContractViewerMoniker,
|
|
15
|
-
ChainId,
|
|
16
|
-
HydratedBlockStateValidationFunction,
|
|
17
|
-
HydratedBlockValidationError,
|
|
18
|
-
HydratedBlockValidationFunction,
|
|
19
|
-
isChainQualifiedHeadConfig,
|
|
20
|
-
isHydratedBlock,
|
|
21
|
-
SignedHydratedBlock,
|
|
22
|
-
type SignedHydratedBlockWithHashMeta,
|
|
23
|
-
XL1BlockNumber,
|
|
24
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
25
|
-
|
|
26
|
-
import type { CreatableProviderParams } from '../../CreatableProvider/index.ts'
|
|
27
|
-
import { AbstractCreatableProvider, creatableProvider } from '../../CreatableProvider/index.ts'
|
|
28
|
-
import { findUncles, getWindowedChain } from '../../primitives/index.ts'
|
|
29
|
-
|
|
30
|
-
/** Parameters for SimpleBlockInvalidationViewer. */
|
|
31
|
-
export interface SimpleBlockInvalidationViewerParams extends CreatableProviderParams {
|
|
32
|
-
maxUncleWindowSize?: number
|
|
33
|
-
state?: HydratedBlockStateValidationFunction
|
|
34
|
-
value?: HydratedBlockValidationFunction
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** SimpleBlockInvalidationViewer implementation. */
|
|
38
|
-
@creatableProvider()
|
|
39
|
-
export class SimpleBlockInvalidationViewer extends AbstractCreatableProvider<SimpleBlockInvalidationViewerParams> implements BlockInvalidationViewer {
|
|
40
|
-
static readonly defaultMoniker = BlockInvalidationViewerMoniker
|
|
41
|
-
static readonly dependencies = [AccountBalanceViewerMoniker, BlockViewerMoniker, ChainContractViewerMoniker]
|
|
42
|
-
static readonly monikers = [BlockInvalidationViewerMoniker]
|
|
43
|
-
moniker = SimpleBlockInvalidationViewer.defaultMoniker
|
|
44
|
-
|
|
45
|
-
private _accountBalanceViewer!: AccountBalanceViewer
|
|
46
|
-
private _blockViewer!: BlockViewer
|
|
47
|
-
private _chainContractViewer!: ChainContractViewer
|
|
48
|
-
private _uncleWindowedChainCache: SignedHydratedBlockWithHashMeta[] | null = null
|
|
49
|
-
|
|
50
|
-
protected get blockViewer() {
|
|
51
|
-
return this._blockViewer
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
protected get chainContractViewer() {
|
|
55
|
-
return this._chainContractViewer
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
protected get maxUncleWindowSize() {
|
|
59
|
-
return this.params.maxUncleWindowSize!
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
static override async paramsHandler(params: Partial<SimpleBlockInvalidationViewerParams>): Promise<SimpleBlockInvalidationViewerParams> {
|
|
63
|
-
return {
|
|
64
|
-
...await super.paramsHandler(params),
|
|
65
|
-
value: params.value,
|
|
66
|
-
state: params.state,
|
|
67
|
-
maxUncleWindowSize: params.maxUncleWindowSize ?? 100,
|
|
68
|
-
} satisfies SimpleBlockInvalidationViewerParams
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
override async createHandler() {
|
|
72
|
-
await super.createHandler()
|
|
73
|
-
this._accountBalanceViewer = await this.locator.getInstance<AccountBalanceViewer>(AccountBalanceViewerMoniker)
|
|
74
|
-
this._blockViewer = await this.locator.getInstance<BlockViewer>(BlockViewerMoniker)
|
|
75
|
-
this._chainContractViewer = await this.locator.getInstance<ChainContractViewer>(ChainContractViewerMoniker)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async invalidateBlock(
|
|
79
|
-
block: SignedHydratedBlock,
|
|
80
|
-
config?: BlockInvalidationConfig,
|
|
81
|
-
): Promise<HydratedBlockValidationError[] | SignedHydratedBlockWithHashMeta> {
|
|
82
|
-
return (await this.invalidateBlocks([block], config))[0]
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async invalidateBlocks(
|
|
86
|
-
blocks: SignedHydratedBlock[],
|
|
87
|
-
config?: BlockInvalidationConfig,
|
|
88
|
-
): Promise<(HydratedBlockValidationError[] | SignedHydratedBlockWithHashMeta)[]> {
|
|
89
|
-
return (await this.qualifiedInvalidateBlocks(blocks, config))[0]
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async invalidateUncle(
|
|
93
|
-
blocks: SignedHydratedBlock[],
|
|
94
|
-
config?: BlockInvalidationConfig,
|
|
95
|
-
): Promise<(HydratedBlockValidationError[] | SignedHydratedBlockWithHashMeta)[]> {
|
|
96
|
-
return (await this.qualifiedInvalidateUncle(blocks, config))[0]
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async qualifiedInvalidateBlock(
|
|
100
|
-
block: SignedHydratedBlockWithHashMeta,
|
|
101
|
-
config?: BlockInvalidationConfig,
|
|
102
|
-
): Promise<[HydratedBlockValidationError[] | SignedHydratedBlockWithHashMeta, BlockInvalidationQualification]> {
|
|
103
|
-
const result = (await this.qualifiedInvalidateBlocks([block], config))
|
|
104
|
-
return [result[0][0], result[1]]
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async qualifiedInvalidateBlocks(
|
|
108
|
-
blocks: SignedHydratedBlock[],
|
|
109
|
-
config?: BlockInvalidationConfig,
|
|
110
|
-
): Promise<[(HydratedBlockValidationError[] | SignedHydratedBlockWithHashMeta)[], BlockInvalidationQualification]> {
|
|
111
|
-
const { value, state } = config ?? {
|
|
112
|
-
shape: true, links: true, state: true, head: undefined,
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const blocksWithMeta = await Promise.all(blocks.map(b => Promise.all([PayloadBuilder.addHashMeta(b[0]), PayloadBuilder.addHashMeta(b[1])])))
|
|
116
|
-
|
|
117
|
-
const head = isChainQualifiedHeadConfig(config)
|
|
118
|
-
? assertEx(
|
|
119
|
-
(await this.blockViewer.blockByHash(config.head))?.[0],
|
|
120
|
-
() => `Specified a head that is not in the chain [${config.head}]`,
|
|
121
|
-
)
|
|
122
|
-
: undefined
|
|
123
|
-
|
|
124
|
-
const headBlock = head ?? (await this.blockViewer.currentBlock())[0]
|
|
125
|
-
|
|
126
|
-
const validateProtocol = value ? this.doInvalidateProtocol.bind(this) : undefined
|
|
127
|
-
const validateState = state ? this.doInvalidateState.bind(this) : undefined
|
|
128
|
-
|
|
129
|
-
const chainIdAtBlockNumber = (blockNumber: XL1BlockNumber) => this.chainContractViewer.chainIdAtBlockNumber(blockNumber)
|
|
130
|
-
|
|
131
|
-
const qualification = { head: headBlock._hash, range: asXL1BlockRange([0, headBlock.block], true) }
|
|
132
|
-
const [protocolResults, stateResults] = await Promise.all([
|
|
133
|
-
validateProtocol?.(blocksWithMeta, chainIdAtBlockNumber), validateState?.(blocksWithMeta, chainIdAtBlockNumber),
|
|
134
|
-
])
|
|
135
|
-
const blockResults = blocksWithMeta.map((r, i) => {
|
|
136
|
-
const errors = []
|
|
137
|
-
if (protocolResults && !isHydratedBlock(protocolResults[i])) {
|
|
138
|
-
errors.push(...(protocolResults[i]))
|
|
139
|
-
}
|
|
140
|
-
if (stateResults && !isHydratedBlock(stateResults[i])) {
|
|
141
|
-
errors.push(...(stateResults[i]))
|
|
142
|
-
}
|
|
143
|
-
return errors.length === 0 ? r : errors
|
|
144
|
-
})
|
|
145
|
-
return [blockResults, qualification]
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
qualifiedInvalidateUncle(
|
|
149
|
-
_blocks: SignedHydratedBlock[],
|
|
150
|
-
_config?: BlockInvalidationConfig,
|
|
151
|
-
): Promise<[(HydratedBlockValidationError[] | SignedHydratedBlockWithHashMeta)[], BlockInvalidationQualification]> {
|
|
152
|
-
throw new Error('Method not implemented.')
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
private async doInvalidateProtocol(
|
|
156
|
-
blocks: SignedHydratedBlockWithHashMeta[],
|
|
157
|
-
chainIdAtBlockNumber: (blockNumber: XL1BlockNumber) => Promisable<ChainId>,
|
|
158
|
-
): Promise<(SignedHydratedBlockWithHashMeta | HydratedBlockValidationError[])[]> {
|
|
159
|
-
return (await Promise.all(blocks.map(async (block) => {
|
|
160
|
-
const errors = await this.params.value!(
|
|
161
|
-
this.context,
|
|
162
|
-
block,
|
|
163
|
-
chainIdAtBlockNumber,
|
|
164
|
-
)
|
|
165
|
-
return (errors.length === 0) ? block : errors
|
|
166
|
-
})))
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
private async doInvalidateState(
|
|
170
|
-
blocks: SignedHydratedBlockWithHashMeta[],
|
|
171
|
-
chainIdAtBlockNumber: (blockNumber: XL1BlockNumber) => Promisable<ChainId>,
|
|
172
|
-
): Promise<(SignedHydratedBlockWithHashMeta | HydratedBlockValidationError[])[]> {
|
|
173
|
-
const windowedUncleChain = await this.updateWindowedChainCache()
|
|
174
|
-
|
|
175
|
-
const uncles = findUncles(this.context, windowedUncleChain, blocks)
|
|
176
|
-
|
|
177
|
-
if (uncles.length !== 1) {
|
|
178
|
-
this.logger?.warn(JSON.stringify({ uncles, blocks }, null, 2))
|
|
179
|
-
this.logger?.warn(JSON.stringify(windowedUncleChain, null, 2))
|
|
180
|
-
throw new Error(`No uncles or greater than one uncle found in block validation, which is not supported [${uncles.length}, ${blocks.length}]`)
|
|
181
|
-
}
|
|
182
|
-
return (await Promise.all(uncles[0].map(async (block) => {
|
|
183
|
-
const errors = await this.params.state!(
|
|
184
|
-
{
|
|
185
|
-
...this.context, chainIdAtBlockNumber, accountBalance: this._accountBalanceViewer,
|
|
186
|
-
},
|
|
187
|
-
block,
|
|
188
|
-
)
|
|
189
|
-
return (errors.length === 0) ? block : errors
|
|
190
|
-
})))
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
private async updateWindowedChainCache() {
|
|
194
|
-
this._uncleWindowedChainCache = await getWindowedChain(this.context, this.blockViewer, this.maxUncleWindowSize, this._uncleWindowedChainCache ?? [])
|
|
195
|
-
return [...this._uncleWindowedChainCache]
|
|
196
|
-
}
|
|
197
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SimpleTransactionInvalidationViewer.ts'
|