@xyo-network/chain-services 1.18.0 → 1.18.1
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/AccountBalance/accountBalanceServiceFromArchivist.d.ts +1 -2
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
- package/dist/neutral/BlockReward/EvmBlockRewardViewer.d.ts +1 -2
- package/dist/neutral/BlockReward/EvmBlockRewardViewer.d.ts.map +1 -1
- package/dist/neutral/ChainService/Evm/Evm.d.ts +3 -4
- package/dist/neutral/ChainService/Evm/Evm.d.ts.map +1 -1
- package/dist/neutral/ChainService/Memory/Memory.d.ts +3 -4
- package/dist/neutral/ChainService/Memory/Memory.d.ts.map +1 -1
- package/dist/neutral/ChainValidator/XyoValidator.d.ts +8 -8
- package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/neutral/ChainValidator/model/Validator.d.ts +1 -1
- package/dist/neutral/ChainValidator/model/Validator.d.ts.map +1 -1
- package/dist/neutral/Election/BaseElectionService.d.ts +8 -5
- package/dist/neutral/Election/BaseElectionService.d.ts.map +1 -1
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts +3 -4
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts +3 -4
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/bundledPayloadToHydratedTransaction.d.ts +1 -1
- package/dist/neutral/PendingTransactions/bundledPayloadToHydratedTransaction.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/hydratedTransactionToPayloadBundle.d.ts +1 -1
- package/dist/neutral/PendingTransactions/hydratedTransactionToPayloadBundle.d.ts.map +1 -1
- package/dist/neutral/Schemas/BaseSchemasService.d.ts +6 -3
- package/dist/neutral/Schemas/BaseSchemasService.d.ts.map +1 -1
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts +13 -6
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/neutral/StakeIntent/lib/getBlockSignedStakeDeclarations.d.ts +1 -1
- package/dist/neutral/StakeIntent/lib/getBlockSignedStakeDeclarations.d.ts.map +1 -1
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts +6 -7
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts.map +1 -1
- package/dist/neutral/blockViewerFromChainIteratorAndArchivist.d.ts +1 -1
- package/dist/neutral/blockViewerFromChainIteratorAndArchivist.d.ts.map +1 -1
- package/dist/neutral/implementation/chain/evm.d.ts +1 -2
- package/dist/neutral/implementation/chain/evm.d.ts.map +1 -1
- package/dist/neutral/implementation/chain/index.d.ts +1 -2
- package/dist/neutral/implementation/chain/index.d.ts.map +1 -1
- package/dist/neutral/implementation/evm/initChainId.d.ts +1 -1
- package/dist/neutral/implementation/evm/initChainId.d.ts.map +1 -1
- package/dist/neutral/implementation/evm/initEvmProvider.d.ts +1 -1
- package/dist/neutral/implementation/evm/initEvmProvider.d.ts.map +1 -1
- package/dist/neutral/implementation/evm/initInfuraProvider.d.ts +1 -1
- package/dist/neutral/implementation/evm/initInfuraProvider.d.ts.map +1 -1
- package/dist/neutral/implementation/evm/initJsonRpcProvider.d.ts +1 -1
- package/dist/neutral/implementation/evm/initJsonRpcProvider.d.ts.map +1 -1
- package/dist/neutral/implementation/head/createBootstrapHead.d.ts +1 -1
- package/dist/neutral/implementation/head/createBootstrapHead.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +0 -1
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +113 -149
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/model/Params.d.ts +1 -2
- package/dist/neutral/model/Params.d.ts.map +1 -1
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts +30 -18
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts.map +1 -1
- package/dist/neutral/simple/block/runner/generateTransactionFeeTransfers.d.ts +1 -1
- package/dist/neutral/simple/block/runner/generateTransactionFeeTransfers.d.ts.map +1 -1
- package/package.json +25 -28
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +5 -6
- package/src/BlockReward/EvmBlockRewardViewer.ts +3 -5
- package/src/ChainService/Evm/Evm.ts +6 -5
- package/src/ChainService/Memory/Memory.ts +7 -8
- package/src/ChainValidator/XyoValidator.ts +9 -14
- package/src/ChainValidator/model/Validator.ts +1 -1
- package/src/Election/BaseElectionService.ts +14 -9
- package/src/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.ts +10 -11
- package/src/PendingTransactions/BasePendingTransactions.ts +11 -11
- package/src/PendingTransactions/bundledPayloadToHydratedTransaction.ts +2 -2
- package/src/PendingTransactions/hydratedTransactionToPayloadBundle.ts +2 -2
- package/src/Schemas/BaseSchemasService.ts +10 -7
- package/src/StakeIntent/XyoStakeIntentService.ts +13 -8
- package/src/StakeIntent/lib/getBlockSignedStakeDeclarations.ts +2 -2
- package/src/StepStake/BaseStepStakeService.ts +7 -11
- package/src/blockViewerFromChainIteratorAndArchivist.ts +14 -4
- package/src/implementation/chain/evm.ts +1 -2
- package/src/implementation/chain/index.ts +1 -2
- package/src/implementation/evm/initChainId.ts +1 -1
- package/src/implementation/evm/initEvmProvider.ts +1 -1
- package/src/implementation/evm/initInfuraProvider.ts +1 -1
- package/src/implementation/evm/initJsonRpcProvider.ts +1 -1
- package/src/implementation/head/createBootstrapHead.ts +2 -2
- package/src/index.ts +0 -1
- package/src/model/Params.ts +1 -2
- package/src/simple/block/runner/SimpleBlockRunner.ts +20 -13
- package/src/simple/block/runner/generateTransactionFeeTransfers.ts +5 -4
- package/dist/neutral/BaseService.d.ts +0 -19
- package/dist/neutral/BaseService.d.ts.map +0 -1
- package/src/BaseService.ts +0 -45
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from '@
|
|
4
|
-
import {
|
|
5
|
-
import { StepIdentity } from '@xyo-network/xl1-protocol'
|
|
6
|
-
import { StepStakeViewer, StepStakeViewerMoniker } from '@xyo-network/xl1-protocol-sdk'
|
|
1
|
+
import type { Address, Promisable } from '@xylabs/sdk-js'
|
|
2
|
+
import type { ReadArchivist } from '@xyo-network/archivist-model'
|
|
3
|
+
import type { StepIdentity, StepStakeViewer } from '@xyo-network/xl1-sdk'
|
|
4
|
+
import { AbstractCreatableProvider, StepStakeViewerMoniker } from '@xyo-network/xl1-sdk'
|
|
7
5
|
|
|
8
|
-
import {
|
|
9
|
-
import { BaseServiceParams } from '../model/index.ts'
|
|
6
|
+
import type { BaseServiceParams } from '../model/index.ts'
|
|
10
7
|
|
|
11
8
|
export interface BaseStepStakeServiceParams extends BaseServiceParams {
|
|
12
9
|
chainArchivist: ReadArchivist
|
|
13
10
|
}
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
export class BaseStepStakeService extends BaseService<BaseStepStakeServiceParams> implements StepStakeViewer {
|
|
12
|
+
export abstract class AbstractStepStakeService extends AbstractCreatableProvider<BaseStepStakeServiceParams> implements StepStakeViewer {
|
|
17
13
|
static readonly defaultMoniker = StepStakeViewerMoniker
|
|
18
14
|
static readonly monikers = [StepStakeViewerMoniker]
|
|
19
|
-
moniker =
|
|
15
|
+
override moniker = AbstractStepStakeService.defaultMoniker
|
|
20
16
|
|
|
21
17
|
stepStake(_step: StepIdentity): Promisable<Record<Address, bigint>> {
|
|
22
18
|
throw new Error('Method [stepStake] not implemented.')
|
|
@@ -4,13 +4,14 @@ import type { ReadArchivist } from '@xyo-network/archivist-model'
|
|
|
4
4
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
5
5
|
import type { Payload, WithHashMeta } from '@xyo-network/payload-model'
|
|
6
6
|
import type {
|
|
7
|
+
BlockRate,
|
|
8
|
+
BlockViewer, EventingChainBlockNumberIteratorService,
|
|
7
9
|
SignedHydratedBlockWithHashMeta,
|
|
8
10
|
XL1BlockNumber,
|
|
9
|
-
} from '@xyo-network/xl1-
|
|
10
|
-
import { asSignedBlockBoundWitness, asSignedBlockBoundWitnessWithStorageMeta } from '@xyo-network/xl1-protocol'
|
|
11
|
+
} from '@xyo-network/xl1-sdk'
|
|
11
12
|
import {
|
|
12
|
-
|
|
13
|
-
} from '@xyo-network/xl1-
|
|
13
|
+
asSignedBlockBoundWitness, asSignedBlockBoundWitnessWithStorageMeta, BlockViewerMoniker,
|
|
14
|
+
} from '@xyo-network/xl1-sdk'
|
|
14
15
|
|
|
15
16
|
export function blockViewerFromChainIteratorAndArchivist(
|
|
16
17
|
chainIterator: EventingChainBlockNumberIteratorService,
|
|
@@ -87,6 +88,15 @@ export function blockViewerFromChainIteratorAndArchivist(
|
|
|
87
88
|
payloadsByHash: function (_hashes: Hash[]): Promisable<WithHashMeta<Payload>[]> {
|
|
88
89
|
throw new Error('Function not implemented.')
|
|
89
90
|
},
|
|
91
|
+
rate(..._args): Promisable<BlockRate> {
|
|
92
|
+
throw new Error('Function not implemented.')
|
|
93
|
+
},
|
|
94
|
+
stepSizeRate(..._args) {
|
|
95
|
+
throw new Error('Function not implemented.')
|
|
96
|
+
},
|
|
97
|
+
timeDurationRate(..._args) {
|
|
98
|
+
throw new Error('Function not implemented.')
|
|
99
|
+
},
|
|
90
100
|
} satisfies BlockViewer
|
|
91
101
|
return result
|
|
92
102
|
}
|
|
@@ -2,8 +2,7 @@ import type { Address, Promisable } from '@xylabs/sdk-js'
|
|
|
2
2
|
import {
|
|
3
3
|
asAddress, assertEx, isDefined, ZERO_ADDRESS,
|
|
4
4
|
} from '@xylabs/sdk-js'
|
|
5
|
-
import type { Initializable } from '@xyo-network/xl1-
|
|
6
|
-
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
+
import type { Config, Initializable } from '@xyo-network/xl1-sdk'
|
|
7
6
|
import type { ContractRunner } from 'ethers'
|
|
8
7
|
import { Wallet } from 'ethers/wallet'
|
|
9
8
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assertEx, type CreatableName, type Promisable,
|
|
3
3
|
} from '@xylabs/sdk-js'
|
|
4
|
-
import type { Initializable } from '@xyo-network/xl1-
|
|
5
|
-
import type { ChainService } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
+
import type { ChainService, Initializable } from '@xyo-network/xl1-sdk'
|
|
6
5
|
|
|
7
6
|
import { MemoryChainViewer } from '../../ChainService/index.ts'
|
|
8
7
|
import type { BaseAccountableServiceParams } from '../../model/index.ts'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assertEx, hexFrom, isDefined, isHex,
|
|
3
3
|
} from '@xylabs/sdk-js'
|
|
4
|
-
import type { Config } from '@xyo-network/xl1-
|
|
4
|
+
import type { Config } from '@xyo-network/xl1-sdk'
|
|
5
5
|
|
|
6
6
|
export const canUseChainId = (config: Pick<Config, 'evm'>): boolean => {
|
|
7
7
|
return isDefined(config.evm.chainId)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from '@xylabs/sdk-js'
|
|
2
2
|
import { assertEx } from '@xylabs/sdk-js'
|
|
3
|
-
import type { Config } from '@xyo-network/xl1-
|
|
3
|
+
import type { Config } from '@xyo-network/xl1-sdk'
|
|
4
4
|
import type { Provider } from 'ethers'
|
|
5
5
|
import type { JsonRpcProvider } from 'ethers/providers'
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Config } from '@xyo-network/xl1-
|
|
2
|
+
import type { Config } from '@xyo-network/xl1-sdk'
|
|
3
3
|
import { InfuraProvider } from 'ethers/providers'
|
|
4
4
|
|
|
5
5
|
import { canUseChainId, getChainId } from './initChainId.ts'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Config } from '@xyo-network/xl1-
|
|
2
|
+
import type { Config } from '@xyo-network/xl1-sdk'
|
|
3
3
|
import { JsonRpcProvider } from 'ethers/providers'
|
|
4
4
|
|
|
5
5
|
import { canUseChainId, getChainId } from './initChainId.ts'
|
|
@@ -3,8 +3,8 @@ import { buildNextBlock, createGenesisBlock } from '@xyo-network/chain-protocol'
|
|
|
3
3
|
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
4
4
|
import type {
|
|
5
5
|
AttoXL1, ChainId, SignedHydratedBlockWithHashMeta,
|
|
6
|
-
} from '@xyo-network/xl1-
|
|
7
|
-
import { createDeclarationIntent } from '@xyo-network/xl1-
|
|
6
|
+
} from '@xyo-network/xl1-sdk'
|
|
7
|
+
import { createDeclarationIntent } from '@xyo-network/xl1-sdk'
|
|
8
8
|
|
|
9
9
|
export const createBootstrapHead = async (
|
|
10
10
|
account: WalletInstance,
|
package/src/index.ts
CHANGED
package/src/model/Params.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { AccountInstance } from '@xyo-network/account-model'
|
|
2
|
-
import type { OpenTelemetryProviders } from '@xyo-network/xl1-
|
|
3
|
-
import type { CreatableProviderParams } from '@xyo-network/xl1-protocol-sdk'
|
|
2
|
+
import type { CreatableProviderParams, OpenTelemetryProviders } from '@xyo-network/xl1-sdk'
|
|
4
3
|
|
|
5
4
|
export interface BaseServiceParams extends CreatableProviderParams, OpenTelemetryProviders {
|
|
6
5
|
|
|
@@ -11,33 +11,31 @@ import {
|
|
|
11
11
|
import { buildNextBlock } from '@xyo-network/chain-protocol'
|
|
12
12
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
13
13
|
import { WithHashMeta } from '@xyo-network/payload-model'
|
|
14
|
-
import {
|
|
15
|
-
AllowedBlockPayload, asBlockBoundWitness, AttoXL1, BlockBoundWitness, BlockNumberPayload, BlockNumberSchema,
|
|
16
|
-
ChainStakeIntent, defaultRewardRatio, SignedBlockBoundWitnessWithHashMeta,
|
|
17
|
-
SignedHydratedBlockWithHashMeta, SignedHydratedTransaction,
|
|
18
|
-
Transfer, XYO_STEP_REWARD_ADDRESS,
|
|
19
|
-
} from '@xyo-network/xl1-protocol'
|
|
20
14
|
import {
|
|
21
15
|
AbstractCreatableProvider,
|
|
22
16
|
AccountBalanceViewer,
|
|
23
17
|
AccountBalanceViewerMoniker,
|
|
18
|
+
AllowedBlockPayload, asBlockBoundWitness, AttoXL1, BlockBoundWitness, BlockNumberPayload, BlockNumberSchema,
|
|
24
19
|
BlockRewardViewer,
|
|
25
20
|
BlockRewardViewerMoniker,
|
|
26
21
|
BlockRunner,
|
|
27
22
|
BlockRunnerMoniker,
|
|
28
23
|
BlockValidationViewer,
|
|
29
24
|
BlockValidationViewerMoniker,
|
|
30
|
-
creatableProvider,
|
|
25
|
+
ChainStakeIntent, creatableProvider,
|
|
31
26
|
CreatableProviderParams,
|
|
32
27
|
createDeclarationIntent,
|
|
33
|
-
HydratedBlockStateValidationFunction,
|
|
28
|
+
defaultRewardRatio, HydratedBlockStateValidationFunction,
|
|
34
29
|
MempoolRunner,
|
|
35
30
|
MempoolRunnerMoniker,
|
|
36
31
|
MempoolViewer,
|
|
37
32
|
MempoolViewerMoniker,
|
|
33
|
+
SignedBlockBoundWitnessWithHashMeta,
|
|
34
|
+
SignedHydratedBlockWithHashMeta, SignedHydratedTransaction,
|
|
38
35
|
TimeSyncViewer,
|
|
39
36
|
TimeSyncViewerMoniker,
|
|
40
|
-
|
|
37
|
+
Transfer, XYO_STEP_REWARD_ADDRESS,
|
|
38
|
+
} from '@xyo-network/xl1-sdk'
|
|
41
39
|
|
|
42
40
|
import { generateTransactionFeeTransfers } from './generateTransactionFeeTransfers.ts'
|
|
43
41
|
|
|
@@ -67,6 +65,15 @@ export type SimpleBlockRunnerParams = CreatableProviderParams & {
|
|
|
67
65
|
@creatableProvider()
|
|
68
66
|
export class SimpleBlockRunner extends AbstractCreatableProvider<SimpleBlockRunnerParams> implements BlockRunner {
|
|
69
67
|
static readonly defaultMoniker = BlockRunnerMoniker
|
|
68
|
+
static readonly dependencies = [
|
|
69
|
+
AccountBalanceViewerMoniker,
|
|
70
|
+
BlockRewardViewerMoniker,
|
|
71
|
+
BlockValidationViewerMoniker,
|
|
72
|
+
MempoolRunnerMoniker,
|
|
73
|
+
MempoolViewerMoniker,
|
|
74
|
+
TimeSyncViewerMoniker,
|
|
75
|
+
]
|
|
76
|
+
|
|
70
77
|
static readonly monikers = [BlockRunnerMoniker]
|
|
71
78
|
moniker = SimpleBlockRunner.defaultMoniker
|
|
72
79
|
|
|
@@ -148,7 +155,7 @@ export class SimpleBlockRunner extends AbstractCreatableProvider<SimpleBlockRunn
|
|
|
148
155
|
}
|
|
149
156
|
|
|
150
157
|
protected get rewardAddress(): Address {
|
|
151
|
-
return
|
|
158
|
+
return this._rewardAddress!
|
|
152
159
|
}
|
|
153
160
|
|
|
154
161
|
// protected get stakeIntentService(): StakeIntentService {
|
|
@@ -166,13 +173,13 @@ export class SimpleBlockRunner extends AbstractCreatableProvider<SimpleBlockRunn
|
|
|
166
173
|
override async createHandler() {
|
|
167
174
|
this._rejectedTransactionsArchivist = this.params.rejectedTransactionsArchivist ?? await MemoryArchivist.create()
|
|
168
175
|
this._account = assertEx(this.params.account, () => 'Account is required')
|
|
169
|
-
this._rewardAddress = assertEx(this.params.rewardAddress, () => 'No reward address provided')
|
|
170
176
|
this._address = this.account.address
|
|
171
177
|
this._accountBalanceViewer = await this.locateAndCreate<AccountBalanceViewer>(AccountBalanceViewerMoniker)
|
|
172
178
|
this._blockRewardViewer = await this.locateAndCreate<BlockRewardViewer>(BlockRewardViewerMoniker)
|
|
173
179
|
this._blockValidationViewer = await this.locator.getInstance<BlockValidationViewer>(BlockValidationViewerMoniker)
|
|
174
180
|
this._mempoolRunner = await this.locateAndCreate<MempoolRunner>(MempoolRunnerMoniker)
|
|
175
181
|
this._mempoolViewer = await this.locateAndCreate<MempoolViewer>(MempoolViewerMoniker)
|
|
182
|
+
this._rewardAddress = this.params.rewardAddress ?? this.context.config.producer.rewardAddress
|
|
176
183
|
this._timeSyncViewer = await this.locateAndCreate<TimeSyncViewer>(TimeSyncViewerMoniker)
|
|
177
184
|
}
|
|
178
185
|
|
|
@@ -268,7 +275,7 @@ export class SimpleBlockRunner extends AbstractCreatableProvider<SimpleBlockRunn
|
|
|
268
275
|
|
|
269
276
|
const transactionTransfers = await generateTransactionFeeTransfers(this.address, nextBlockTransactions)
|
|
270
277
|
const timeStart = Date.now()
|
|
271
|
-
const timePayload = await this.generateTimePayload(
|
|
278
|
+
const timePayload = await this.generateTimePayload()
|
|
272
279
|
const timeDuration = Date.now() - timeStart
|
|
273
280
|
if (timeDuration > 100) {
|
|
274
281
|
this.logger?.warn(`[Slow] Generated time payload in ${timeDuration}ms`)
|
|
@@ -334,7 +341,7 @@ export class SimpleBlockRunner extends AbstractCreatableProvider<SimpleBlockRunn
|
|
|
334
341
|
return [fundedTransactions, fundedTransfers]
|
|
335
342
|
}
|
|
336
343
|
|
|
337
|
-
private async generateTimePayload(
|
|
344
|
+
private async generateTimePayload() {
|
|
338
345
|
return await this.timeSyncViewer.currentTimePayload()
|
|
339
346
|
}
|
|
340
347
|
|
|
@@ -5,10 +5,11 @@ import type {
|
|
|
5
5
|
SignedHydratedTransaction,
|
|
6
6
|
Transfer,
|
|
7
7
|
XL1,
|
|
8
|
-
} from '@xyo-network/xl1-
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
} from '@xyo-network/xl1-sdk'
|
|
9
|
+
import {
|
|
10
|
+
HydratedTransactionWrapper,
|
|
11
|
+
transactionRequiredGas, TransferSchema, XYO_ZERO_ADDRESS,
|
|
12
|
+
} from '@xyo-network/xl1-sdk'
|
|
12
13
|
|
|
13
14
|
export async function generateTransactionFeeTransfers(address: Address, transactions: SignedHydratedTransaction[]): Promise<Transfer[]> {
|
|
14
15
|
const txs = await Promise.all(transactions.map(async (tx) => {
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { EventData, Promisable } from '@xylabs/sdk-js';
|
|
2
|
-
import { AbstractCreatableProvider } from '@xyo-network/xl1-protocol-sdk';
|
|
3
|
-
import type { BaseAccountableServiceParams, BaseServiceParams } from './model/index.ts';
|
|
4
|
-
declare global {
|
|
5
|
-
var xyoServiceSingletons: Record<string, unknown>;
|
|
6
|
-
}
|
|
7
|
-
export declare class BaseService<TParams extends BaseServiceParams = BaseServiceParams, TEventData extends EventData = EventData> extends AbstractCreatableProvider<TParams, TEventData> {
|
|
8
|
-
private static singletonInitMutex;
|
|
9
|
-
static get singletons(): Record<string, unknown>;
|
|
10
|
-
static initSingleton<TService extends BaseService<TParams>, TParams extends BaseServiceParams>(params: Partial<TParams>): Promise<TService>;
|
|
11
|
-
}
|
|
12
|
-
export declare abstract class BaseAccountableService<TParams extends BaseAccountableServiceParams = BaseAccountableServiceParams> extends BaseService<TParams> {
|
|
13
|
-
}
|
|
14
|
-
export interface CreatableService<T extends BaseService = BaseService> {
|
|
15
|
-
new (params: T['params']): T;
|
|
16
|
-
create<T extends BaseService>(this: CreatableService<T>, params?: Partial<T['params']>): Promisable<T>;
|
|
17
|
-
}
|
|
18
|
-
export declare function creatableService<T extends BaseService = BaseService>(): <U extends CreatableService<T>>(constructor: U) => void;
|
|
19
|
-
//# sourceMappingURL=BaseService.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseService.d.ts","sourceRoot":"","sources":["../../src/BaseService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAA;AAGzE,OAAO,KAAK,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEvF,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClD;AAED,qBACa,WAAW,CAAC,OAAO,SAAS,iBAAiB,GAAG,iBAAiB,EAAE,UAAU,SAAS,SAAS,GAAG,SAAS,CACtH,SAAQ,yBAAyB,CAAC,OAAO,EAAE,UAAU,CAAC;IACtD,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAc;IAE/C,MAAM,KAAK,UAAU,4BAEpB;IAED,MAAM,CAAC,aAAa,CAAC,QAAQ,SAAS,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,SAAS,iBAAiB,EAAE,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC;CAMxH;AAED,8BAAsB,sBAAsB,CAC1C,OAAO,SAAS,4BAA4B,GAAG,4BAA4B,CAC3E,SAAQ,WAAW,CAAC,OAAO,CAAC;CAE7B;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IACnE,KAAI,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC3B,MAAM,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;CACvG;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,MAC1D,CAAC,SAAS,gBAAgB,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,UAItD"}
|
package/src/BaseService.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { EventData, Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import { creatable } from '@xylabs/sdk-js'
|
|
3
|
-
import { AbstractCreatableProvider } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
import { Mutex } from 'async-mutex'
|
|
5
|
-
|
|
6
|
-
import type { BaseAccountableServiceParams, BaseServiceParams } from './model/index.ts'
|
|
7
|
-
|
|
8
|
-
declare global {
|
|
9
|
-
var xyoServiceSingletons: Record<string, unknown>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
@creatable()
|
|
13
|
-
export class BaseService<TParams extends BaseServiceParams = BaseServiceParams, TEventData extends EventData = EventData>
|
|
14
|
-
extends AbstractCreatableProvider<TParams, TEventData> {
|
|
15
|
-
private static singletonInitMutex = new Mutex()
|
|
16
|
-
|
|
17
|
-
static get singletons() {
|
|
18
|
-
return globalThis['xyoServiceSingletons'] ?? (globalThis['xyoServiceSingletons'] = {})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static initSingleton<TService extends BaseService<TParams>, TParams extends BaseServiceParams>(params: Partial<TParams>) {
|
|
22
|
-
if (this.singletons[this.name]) throw new Error(`Singleton already initialized for ${this.name}`)
|
|
23
|
-
return this.singletonInitMutex.runExclusive(async () => {
|
|
24
|
-
return await this.create(params) as TService
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export abstract class BaseAccountableService<
|
|
30
|
-
TParams extends BaseAccountableServiceParams = BaseAccountableServiceParams,
|
|
31
|
-
> extends BaseService<TParams> {
|
|
32
|
-
// Base class for services that have an account
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface CreatableService<T extends BaseService = BaseService> {
|
|
36
|
-
new(params: T['params']): T
|
|
37
|
-
create<T extends BaseService>(this: CreatableService<T>, params?: Partial<T['params']>): Promisable<T>
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function creatableService<T extends BaseService = BaseService>() {
|
|
41
|
-
return <U extends CreatableService<T>>(constructor: U) => {
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
43
|
-
constructor
|
|
44
|
-
}
|
|
45
|
-
}
|