@xyo-network/chain-services 1.16.7 → 1.16.9
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.map +1 -1
- package/dist/neutral/BaseService.d.ts +2 -5
- package/dist/neutral/BaseService.d.ts.map +1 -1
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts +2 -2
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts.map +1 -1
- package/dist/neutral/BlockReward/BaseBlockRewardService.d.ts +2 -1
- package/dist/neutral/BlockReward/BaseBlockRewardService.d.ts.map +1 -1
- package/dist/neutral/BlockReward/EvmBlockRewardService.d.ts +2 -2
- package/dist/neutral/BlockReward/EvmBlockRewardService.d.ts.map +1 -1
- package/dist/neutral/ChainService/Memory/Memory.d.ts +2 -2
- package/dist/neutral/ChainService/Memory/Memory.d.ts.map +1 -1
- package/dist/neutral/ChainValidator/XyoValidator.d.ts +2 -1
- package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts +2 -2
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts +2 -2
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts.map +1 -1
- package/dist/neutral/Time/BaseTimeSyncService.d.ts +4 -3
- package/dist/neutral/Time/BaseTimeSyncService.d.ts.map +1 -1
- package/dist/neutral/index.mjs +0 -3
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/model/Params.d.ts +4 -4
- package/dist/neutral/model/Params.d.ts.map +1 -1
- package/package.json +10 -9
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +1 -0
- package/src/BaseService.ts +2 -8
- package/src/BlockProducer/BaseBlockProducerService.ts +2 -2
- package/src/BlockReward/BaseBlockRewardService.ts +2 -1
- package/src/BlockReward/EvmBlockRewardService.ts +4 -2
- package/src/ChainService/Memory/Memory.ts +2 -2
- package/src/ChainValidator/XyoValidator.ts +2 -1
- package/src/StakeIntent/XyoStakeIntentService.ts +2 -1
- package/src/StepStake/BaseStepStakeService.ts +2 -2
- package/src/Time/BaseTimeSyncService.ts +4 -3
- package/src/model/Params.ts +4 -4
- package/dist/neutral/ChainBlockIteration/ChainBlockNumberIterationService.d.ts +0 -21
- package/dist/neutral/ChainBlockIteration/ChainBlockNumberIterationService.d.ts.map +0 -1
- package/dist/neutral/ChainBlockIteration/index.d.ts +0 -3
- package/dist/neutral/ChainBlockIteration/index.d.ts.map +0 -1
- package/dist/neutral/ChainBlockIteration/model/BlockNumberIteration.d.ts +0 -7
- package/dist/neutral/ChainBlockIteration/model/BlockNumberIteration.d.ts.map +0 -1
- package/dist/neutral/ChainBlockIteration/model/Params.d.ts +0 -8
- package/dist/neutral/ChainBlockIteration/model/Params.d.ts.map +0 -1
- package/dist/neutral/ChainBlockIteration/model/index.d.ts +0 -3
- package/dist/neutral/ChainBlockIteration/model/index.d.ts.map +0 -1
- package/src/ChainBlockIteration/ChainBlockNumberIterationService.ts +0 -105
- package/src/ChainBlockIteration/index.ts +0 -2
- package/src/ChainBlockIteration/model/BlockNumberIteration.ts +0 -7
- package/src/ChainBlockIteration/model/Params.ts +0 -9
- package/src/ChainBlockIteration/model/index.ts +0 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { CreatableParams } from '@xylabs/creatable';
|
|
2
|
+
import type { EmptyObject } from '@xylabs/object';
|
|
2
3
|
import type { AccountInstance } from '@xyo-network/account-model';
|
|
3
4
|
import type { OpenTelemetryProviders } from '@xyo-network/xl1-protocol';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
config: Config;
|
|
5
|
+
export interface BaseServiceParams<TConfig extends EmptyObject = EmptyObject> extends CreatableParams, OpenTelemetryProviders {
|
|
6
|
+
config: TConfig;
|
|
7
7
|
}
|
|
8
|
-
export interface BaseAccountableServiceParams extends BaseServiceParams {
|
|
8
|
+
export interface BaseAccountableServiceParams<TConfig extends EmptyObject = EmptyObject> extends BaseServiceParams<TConfig> {
|
|
9
9
|
account: AccountInstance;
|
|
10
10
|
}
|
|
11
11
|
//# sourceMappingURL=Params.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../../src/model/Params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../../src/model/Params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAEvE,MAAM,WAAW,iBAAiB,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,CAAE,SAAQ,eAAe,EAAE,sBAAsB;IAC3H,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,MAAM,WAAW,4BAA4B,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,CAAE,SAAQ,iBAAiB,CAAC,OAAO,CAAC;IACzH,OAAO,EAAE,eAAe,CAAA;CACzB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/chain-services",
|
|
4
|
-
"version": "1.16.
|
|
4
|
+
"version": "1.16.9",
|
|
5
5
|
"description": "XYO Layer One SDK Services",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"@xylabs/exists": "~5.0.24",
|
|
46
46
|
"@xylabs/forget": "~5.0.24",
|
|
47
47
|
"@xylabs/hex": "~5.0.24",
|
|
48
|
+
"@xylabs/object": "~5.0.24",
|
|
48
49
|
"@xylabs/promise": "~5.0.24",
|
|
49
50
|
"@xylabs/telemetry": "~5.0.24",
|
|
50
51
|
"@xylabs/typeof": "~5.0.24",
|
|
@@ -54,17 +55,17 @@
|
|
|
54
55
|
"@xyo-network/boundwitness-model": "~5.1.21",
|
|
55
56
|
"@xyo-network/boundwitness-validator": "~5.1.21",
|
|
56
57
|
"@xyo-network/boundwitness-wrapper": "~5.1.21",
|
|
57
|
-
"@xyo-network/chain-analyze": "~1.16.
|
|
58
|
-
"@xyo-network/chain-modules": "~1.16.
|
|
59
|
-
"@xyo-network/chain-protocol": "~1.16.
|
|
60
|
-
"@xyo-network/chain-utils": "~1.16.
|
|
58
|
+
"@xyo-network/chain-analyze": "~1.16.9",
|
|
59
|
+
"@xyo-network/chain-modules": "~1.16.9",
|
|
60
|
+
"@xyo-network/chain-protocol": "~1.16.9",
|
|
61
|
+
"@xyo-network/chain-utils": "~1.16.9",
|
|
61
62
|
"@xyo-network/payload-builder": "~5.1.21",
|
|
62
63
|
"@xyo-network/payload-model": "~5.1.21",
|
|
63
64
|
"@xyo-network/typechain": "~4.0.10",
|
|
64
65
|
"@xyo-network/xl1-protocol": "~1.13.6",
|
|
65
|
-
"@xyo-network/xl1-protocol-sdk": "~1.16.
|
|
66
|
-
"@xyo-network/xl1-validation": "~1.16.
|
|
67
|
-
"@xyo-network/xl1-wrappers": "~1.16.
|
|
66
|
+
"@xyo-network/xl1-protocol-sdk": "~1.16.9",
|
|
67
|
+
"@xyo-network/xl1-validation": "~1.16.9",
|
|
68
|
+
"@xyo-network/xl1-wrappers": "~1.16.9",
|
|
68
69
|
"async-mutex": "~0.5.0",
|
|
69
70
|
"ethers": "6.15.0",
|
|
70
71
|
"lru-cache": "~11.2.2"
|
|
@@ -77,7 +78,7 @@
|
|
|
77
78
|
"@xylabs/vitest-extended": "~5.0.24",
|
|
78
79
|
"@xyo-network/account": "~5.1.21",
|
|
79
80
|
"@xyo-network/account-model": "~5.1.21",
|
|
80
|
-
"@xyo-network/chain-validation": "~1.16.
|
|
81
|
+
"@xyo-network/chain-validation": "~1.16.9",
|
|
81
82
|
"@xyo-network/wallet": "~5.1.21",
|
|
82
83
|
"eslint": "^9.39.1",
|
|
83
84
|
"tslib": "~2.8.1",
|
|
@@ -11,6 +11,7 @@ import { Semaphore } from 'async-mutex'
|
|
|
11
11
|
|
|
12
12
|
import { BaseAccountBalanceService } from './BaseAccountBalanceService.ts'
|
|
13
13
|
|
|
14
|
+
// this is intended to only be used for testing
|
|
14
15
|
export const accountBalancesServiceFromArchivist = async (
|
|
15
16
|
chainId: ChainId,
|
|
16
17
|
archivist: ReadArchivist<WithStorageMeta<Payload>>,
|
package/src/BaseService.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { AbstractCreatable, creatable } from '@xylabs/creatable'
|
|
2
2
|
import type { EventData } from '@xylabs/events'
|
|
3
|
-
import { Hash } from '@xylabs/hex'
|
|
4
3
|
import type { Promisable } from '@xylabs/promise'
|
|
5
4
|
import { spanRoot, spanRootAsync } from '@xylabs/telemetry'
|
|
6
|
-
import type { ServiceInterface } from '@xyo-network/xl1-protocol-sdk'
|
|
7
5
|
import { Mutex } from 'async-mutex'
|
|
8
6
|
|
|
9
7
|
import type { BaseAccountableServiceParams, BaseServiceParams } from './model/index.ts'
|
|
@@ -14,7 +12,7 @@ declare global {
|
|
|
14
12
|
|
|
15
13
|
@creatable()
|
|
16
14
|
export class BaseService<TParams extends BaseServiceParams = BaseServiceParams, TEventData extends EventData = EventData>
|
|
17
|
-
extends AbstractCreatable<TParams, TEventData>
|
|
15
|
+
extends AbstractCreatable<TParams, TEventData> {
|
|
18
16
|
private static singletonInitMutex = new Mutex()
|
|
19
17
|
|
|
20
18
|
static get singletons() {
|
|
@@ -39,10 +37,6 @@ export class BaseService<TParams extends BaseServiceParams = BaseServiceParams,
|
|
|
39
37
|
async spanAsync<T>(name: string, fn: () => Promise<T>): Promise<T> {
|
|
40
38
|
return await spanRootAsync(name, fn, this.tracer)
|
|
41
39
|
}
|
|
42
|
-
|
|
43
|
-
sync(_head: Hash): Promise<void> {
|
|
44
|
-
throw new Error('Method not implemented.')
|
|
45
|
-
}
|
|
46
40
|
}
|
|
47
41
|
|
|
48
42
|
export abstract class BaseAccountableService<
|
|
@@ -51,7 +45,7 @@ export abstract class BaseAccountableService<
|
|
|
51
45
|
// Base class for services that have an account
|
|
52
46
|
}
|
|
53
47
|
|
|
54
|
-
export interface CreatableService<T extends BaseService = BaseService>
|
|
48
|
+
export interface CreatableService<T extends BaseService = BaseService> {
|
|
55
49
|
new(params: T['params']): T
|
|
56
50
|
create<T extends BaseService>(this: CreatableService<T>, params?: Partial<T['params']>): Promisable<T>
|
|
57
51
|
}
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
Transfer, XYO_STEP_REWARD_ADDRESS,
|
|
21
21
|
} from '@xyo-network/xl1-protocol'
|
|
22
22
|
import {
|
|
23
|
-
AccountBalanceService, BlockProducerService, PendingTransactionsService, StakeIntentService, TimeSyncViewer,
|
|
23
|
+
AccountBalanceService, BlockProducerService, Config, PendingTransactionsService, StakeIntentService, TimeSyncViewer,
|
|
24
24
|
} from '@xyo-network/xl1-protocol-sdk'
|
|
25
25
|
|
|
26
26
|
import { BaseService } from '../BaseService.ts'
|
|
@@ -43,7 +43,7 @@ export const XYO_PRODUCER_REDECLARATION_DURATION = 10_000
|
|
|
43
43
|
*/
|
|
44
44
|
export const XYO_PRODUCER_REDECLARATION_WINDOW = 500
|
|
45
45
|
|
|
46
|
-
export interface BaseBlockProducerServiceParams extends XyoValidatorParams {
|
|
46
|
+
export interface BaseBlockProducerServiceParams extends XyoValidatorParams<Pick<Config, 'producer'>> {
|
|
47
47
|
balanceService: AccountBalanceService
|
|
48
48
|
pendingTransactionsService: PendingTransactionsService
|
|
49
49
|
rejectedTransactionsArchivist: ArchivistInstance
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { creatable } from '@xylabs/creatable'
|
|
2
|
+
import { EmptyObject } from '@xylabs/object'
|
|
2
3
|
import { Promisable } from '@xylabs/promise'
|
|
3
4
|
import { BlockRewardService } from '@xyo-network/xl1-protocol-sdk'
|
|
4
5
|
|
|
5
6
|
import { BaseService } from '../BaseService.ts'
|
|
6
7
|
import { BaseServiceParams } from '../model/index.ts'
|
|
7
8
|
|
|
8
|
-
export interface BaseBlockRewardServiceParams extends BaseServiceParams {}
|
|
9
|
+
export interface BaseBlockRewardServiceParams<TConfig extends EmptyObject = EmptyObject> extends BaseServiceParams<TConfig> {}
|
|
9
10
|
|
|
10
11
|
@creatable()
|
|
11
12
|
export class BaseBlockRewardService<TParams extends BaseBlockRewardServiceParams = BaseBlockRewardServiceParams>
|
|
@@ -3,12 +3,14 @@ import { creatable } from '@xylabs/creatable'
|
|
|
3
3
|
import { toEthAddress } from '@xylabs/hex'
|
|
4
4
|
import { AccountInstance } from '@xyo-network/account-model'
|
|
5
5
|
import { XyoChainRewards__factory as XyoChainRewardsFactory } from '@xyo-network/typechain'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
BlockRewardService, ChainService, Config,
|
|
8
|
+
} from '@xyo-network/xl1-protocol-sdk'
|
|
7
9
|
import { Provider } from 'ethers/providers'
|
|
8
10
|
|
|
9
11
|
import { BaseBlockRewardService, BaseBlockRewardServiceParams } from './BaseBlockRewardService.ts'
|
|
10
12
|
|
|
11
|
-
export interface EvmBlockRewardServiceParams extends BaseBlockRewardServiceParams {
|
|
13
|
+
export interface EvmBlockRewardServiceParams extends BaseBlockRewardServiceParams<Pick<Config, 'evm'>> {
|
|
12
14
|
account: AccountInstance
|
|
13
15
|
chainService?: ChainService
|
|
14
16
|
provider?: Provider
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Address } from '@xylabs/hex'
|
|
2
2
|
import { ZERO_ADDRESS } from '@xylabs/hex'
|
|
3
|
-
import type { ChainService } from '@xyo-network/xl1-protocol-sdk'
|
|
3
|
+
import type { ChainService, Config } from '@xyo-network/xl1-protocol-sdk'
|
|
4
4
|
|
|
5
5
|
import { BaseService } from '../../BaseService.ts'
|
|
6
6
|
import type { BaseServiceParams } from '../../model/index.ts'
|
|
7
7
|
|
|
8
|
-
export interface MemoryChainServiceParams extends BaseServiceParams {}
|
|
8
|
+
export interface MemoryChainServiceParams extends BaseServiceParams<Pick<Config, 'producer'>> {}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* A class that represents a chain stake as backed in memory
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { creatable } from '@xylabs/creatable'
|
|
3
|
+
import { EmptyObject } from '@xylabs/object'
|
|
3
4
|
import { Promisable } from '@xylabs/promise'
|
|
4
5
|
import { AccountInstance } from '@xyo-network/account-model'
|
|
5
6
|
import { ArchivistInstance, ReadArchivist } from '@xyo-network/archivist-model'
|
|
@@ -16,7 +17,7 @@ import { BaseService } from '../BaseService.ts'
|
|
|
16
17
|
import { BaseServiceParams } from '../model/index.ts'
|
|
17
18
|
import { Validator } from './model/index.ts'
|
|
18
19
|
|
|
19
|
-
export interface XyoValidatorParams extends BaseServiceParams {
|
|
20
|
+
export interface XyoValidatorParams<TConfig extends EmptyObject = EmptyObject> extends BaseServiceParams<TConfig> {
|
|
20
21
|
account: AccountInstance
|
|
21
22
|
chainArchivist: ReadArchivist
|
|
22
23
|
chainId: ChainId
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
asChainIndexingServiceStateWithStorageMeta,
|
|
25
25
|
ChainIndexingServiceState, ChainIndexingServiceStateSchema, ChainStakeViewer,
|
|
26
|
+
Config,
|
|
26
27
|
EventingChainBlockNumberIteratorService,
|
|
27
28
|
isChainIndexingServiceState,
|
|
28
29
|
readPayloadMapFromStore,
|
|
@@ -34,7 +35,7 @@ import { LRUCache } from 'lru-cache'
|
|
|
34
35
|
import { BaseService } from '../BaseService.ts'
|
|
35
36
|
import { BaseServiceParams } from '../model/index.ts'
|
|
36
37
|
|
|
37
|
-
export interface XyoStakeIntentServiceParams extends BaseServiceParams {
|
|
38
|
+
export interface XyoStakeIntentServiceParams extends BaseServiceParams<Pick<Config, 'producer'>> {
|
|
38
39
|
chainArchivist?: ArchivistInstance
|
|
39
40
|
chainIterator?: EventingChainBlockNumberIteratorService
|
|
40
41
|
chainStakeViewer?: ChainStakeViewer
|
|
@@ -3,7 +3,7 @@ import { Address } from '@xylabs/hex'
|
|
|
3
3
|
import { Promisable } from '@xylabs/promise'
|
|
4
4
|
import { ReadArchivist } from '@xyo-network/archivist-model'
|
|
5
5
|
import { StepIdentity } from '@xyo-network/xl1-protocol'
|
|
6
|
-
import {
|
|
6
|
+
import { StepStakeViewer } from '@xyo-network/xl1-protocol-sdk'
|
|
7
7
|
|
|
8
8
|
import { BaseService } from '../BaseService.ts'
|
|
9
9
|
import { BaseServiceParams } from '../model/index.ts'
|
|
@@ -13,7 +13,7 @@ export interface BaseStepStakeServiceParams extends BaseServiceParams {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
@creatable()
|
|
16
|
-
export class BaseStepStakeService extends BaseService<BaseStepStakeServiceParams> implements
|
|
16
|
+
export class BaseStepStakeService extends BaseService<BaseStepStakeServiceParams> implements StepStakeViewer {
|
|
17
17
|
stepStake(_step: StepIdentity): Promisable<Record<Address, bigint>> {
|
|
18
18
|
throw new Error('Method not implemented.')
|
|
19
19
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { creatable } from '@xylabs/creatable'
|
|
3
3
|
import { asHash, Hash } from '@xylabs/hex'
|
|
4
|
+
import { EmptyObject } from '@xylabs/object'
|
|
4
5
|
import { Promisable } from '@xylabs/promise'
|
|
5
6
|
import { ReadArchivist } from '@xyo-network/archivist-model'
|
|
6
7
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
@@ -8,7 +9,7 @@ import {
|
|
|
8
9
|
asTimePayload,
|
|
9
10
|
TimeDomain, TimePayload, TimeSchema,
|
|
10
11
|
} from '@xyo-network/xl1-protocol'
|
|
11
|
-
import { EventingChainBlockNumberIteratorService,
|
|
12
|
+
import { EventingChainBlockNumberIteratorService, TimeSyncViewer } from '@xyo-network/xl1-protocol-sdk'
|
|
12
13
|
import { Provider } from 'ethers'
|
|
13
14
|
|
|
14
15
|
import { BaseService } from '../BaseService.ts'
|
|
@@ -18,14 +19,14 @@ export interface TimeProvider {
|
|
|
18
19
|
currentTime(): Promise<[string, number]>
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export interface BaseTimeServiceParams extends BaseServiceParams {
|
|
22
|
+
export interface BaseTimeServiceParams<TConfig extends EmptyObject = EmptyObject> extends BaseServiceParams<TConfig> {
|
|
22
23
|
chainArchivist: ReadArchivist
|
|
23
24
|
chainIterator: EventingChainBlockNumberIteratorService
|
|
24
25
|
ethProvider?: Provider
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
@creatable()
|
|
28
|
-
export class BaseTimeSyncService extends BaseService<BaseTimeServiceParams> implements
|
|
29
|
+
export class BaseTimeSyncService extends BaseService<BaseTimeServiceParams> implements TimeSyncViewer {
|
|
29
30
|
get chainArchivist() {
|
|
30
31
|
return this.params.chainArchivist
|
|
31
32
|
}
|
package/src/model/Params.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { CreatableParams } from '@xylabs/creatable'
|
|
2
|
+
import type { EmptyObject } from '@xylabs/object'
|
|
2
3
|
import type { AccountInstance } from '@xyo-network/account-model'
|
|
3
4
|
import type { OpenTelemetryProviders } from '@xyo-network/xl1-protocol'
|
|
4
|
-
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
5
5
|
|
|
6
|
-
export interface BaseServiceParams extends CreatableParams, OpenTelemetryProviders {
|
|
7
|
-
config:
|
|
6
|
+
export interface BaseServiceParams<TConfig extends EmptyObject = EmptyObject> extends CreatableParams, OpenTelemetryProviders {
|
|
7
|
+
config: TConfig
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export interface BaseAccountableServiceParams extends BaseServiceParams {
|
|
10
|
+
export interface BaseAccountableServiceParams<TConfig extends EmptyObject = EmptyObject> extends BaseServiceParams<TConfig> {
|
|
11
11
|
account: AccountInstance
|
|
12
12
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Hex } from '@xylabs/hex';
|
|
2
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model';
|
|
3
|
-
import type { WithStorageMeta } from '@xyo-network/payload-model';
|
|
4
|
-
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol';
|
|
5
|
-
import type { ChainIteratorServiceEventData, EventingChainBlockNumberIteratorService } from '@xyo-network/xl1-protocol-sdk';
|
|
6
|
-
import { LRUCache } from 'lru-cache';
|
|
7
|
-
import { BaseService } from '../BaseService.ts';
|
|
8
|
-
import type { XyoChainIteratorParams } from './model/index.ts';
|
|
9
|
-
export declare class ChainBlockNumberIterationService extends BaseService<XyoChainIteratorParams, ChainIteratorServiceEventData> implements EventingChainBlockNumberIteratorService {
|
|
10
|
-
protected _blocksByBlockNumber: LRUCache<number, WithStorageMeta<BlockBoundWitness>, unknown>;
|
|
11
|
-
protected _currentHead: WithStorageMeta<BlockBoundWitness> | undefined;
|
|
12
|
-
get chainArchivist(): ArchivistInstance;
|
|
13
|
-
get chainId(): Hex;
|
|
14
|
-
get(block: number): Promise<WithStorageMeta<BlockBoundWitness>>;
|
|
15
|
-
head(): Promise<WithStorageMeta<BlockBoundWitness>>;
|
|
16
|
-
next(block: number): Promise<WithStorageMeta<BlockBoundWitness> | undefined>;
|
|
17
|
-
previous(block?: number | undefined, count?: number): Promise<WithStorageMeta<BlockBoundWitness>[]>;
|
|
18
|
-
updateHead(head: BlockBoundWitness): Promise<void>;
|
|
19
|
-
private getBoundWitnessAsBlockBoundWitnessWithStorageMeta;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=ChainBlockNumberIterationService.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChainBlockNumberIterationService.d.ts","sourceRoot":"","sources":["../../../src/ChainBlockIteration/ChainBlockNumberIterationService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAItC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAMlE,OAAO,KAAK,EAAE,6BAA6B,EAAE,uCAAuC,EAAE,MAAM,+BAA+B,CAAA;AAC3H,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAE9D,qBAAa,gCAAiC,SAAQ,WAAW,CAAC,sBAAsB,EAAE,6BAA6B,CACrH,YAAW,uCAAuC;IAClD,SAAS,CAAC,oBAAoB,gEAA4E;IAC1G,SAAS,CAAC,YAAY,EAAE,eAAe,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAA;IAEtE,IAAI,cAAc,IAAI,iBAAiB,CAAgD;IAEvF,IAAI,OAAO,IAAI,GAAG,CAA2G;IAEvH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;IA0B/D,IAAI,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;IAUnD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC;IAQ5E,QAAQ,CAAC,KAAK,GAAE,MAAM,GAAG,SAAqB,EAAE,KAAK,GAAE,MAAU,GAAG,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,EAAE,CAAC;IAkBjH,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;YAM1C,iDAAiD;CAOhE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ChainBlockIteration/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AACrD,cAAc,kBAAkB,CAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@xylabs/promise';
|
|
2
|
-
import type { BlockBoundWitness, SignedHydratedTransactionWithStorageMeta } from '@xyo-network/xl1-protocol';
|
|
3
|
-
export interface BlockNumberIteration {
|
|
4
|
-
validatePendingBlock(block: BlockBoundWitness): Promisable<Error[]>;
|
|
5
|
-
validatePendingTransaction(tx: SignedHydratedTransactionWithStorageMeta): Promise<boolean>;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=BlockNumberIteration.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BlockNumberIteration.d.ts","sourceRoot":"","sources":["../../../../src/ChainBlockIteration/model/BlockNumberIteration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,wCAAwC,EAAE,MAAM,2BAA2B,CAAA;AAE5G,MAAM,WAAW,oBAAoB;IACnC,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;IACnE,0BAA0B,CAAC,EAAE,EAAE,wCAAwC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAC3F"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model';
|
|
2
|
-
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol';
|
|
3
|
-
import type { BaseServiceParams } from '../../model/index.ts';
|
|
4
|
-
export interface XyoChainIteratorParams extends BaseServiceParams {
|
|
5
|
-
chainArchivist: ArchivistInstance;
|
|
6
|
-
head: BlockBoundWitness;
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=Params.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../../../src/ChainBlockIteration/model/Params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,MAAM,WAAW,sBAAuB,SAAQ,iBAAiB;IAC/D,cAAc,EAAE,iBAAiB,CAAA;IACjC,IAAI,EAAE,iBAAiB,CAAA;CACxB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ChainBlockIteration/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,aAAa,CAAA"}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import type { Hex } from '@xylabs/hex'
|
|
3
|
-
import {
|
|
4
|
-
isDefined, isNull, isUndefined,
|
|
5
|
-
} from '@xylabs/typeof'
|
|
6
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
7
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
8
|
-
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
9
|
-
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
10
|
-
import {
|
|
11
|
-
asBlockBoundWitness,
|
|
12
|
-
asBlockBoundWitnessWithStorageMeta,
|
|
13
|
-
isBlockBoundWitness,
|
|
14
|
-
} from '@xyo-network/xl1-protocol'
|
|
15
|
-
import type { ChainIteratorServiceEventData, EventingChainBlockNumberIteratorService } from '@xyo-network/xl1-protocol-sdk'
|
|
16
|
-
import { LRUCache } from 'lru-cache'
|
|
17
|
-
|
|
18
|
-
import { BaseService } from '../BaseService.ts'
|
|
19
|
-
import type { XyoChainIteratorParams } from './model/index.ts'
|
|
20
|
-
|
|
21
|
-
export class ChainBlockNumberIterationService extends BaseService<XyoChainIteratorParams, ChainIteratorServiceEventData>
|
|
22
|
-
implements EventingChainBlockNumberIteratorService {
|
|
23
|
-
protected _blocksByBlockNumber = new LRUCache<number, WithStorageMeta<BlockBoundWitness>>({ max: 10_000 })
|
|
24
|
-
protected _currentHead: WithStorageMeta<BlockBoundWitness> | undefined
|
|
25
|
-
|
|
26
|
-
get chainArchivist(): ArchivistInstance { return assertEx(this.params.chainArchivist) }
|
|
27
|
-
|
|
28
|
-
get chainId(): Hex { return assertEx(this._currentHead?.chain ?? this.params?.head?.chain, () => 'Current head is not set') }
|
|
29
|
-
|
|
30
|
-
async get(block: number): Promise<WithStorageMeta<BlockBoundWitness>> {
|
|
31
|
-
const head = await this.head()
|
|
32
|
-
// if(isUndefined(head)) return undefined
|
|
33
|
-
// Bail early if the block requested is newer than the current head
|
|
34
|
-
assertEx(head.block >= block, () => `Block requested is newer than the current head [${block}]`)
|
|
35
|
-
const cached = this._blocksByBlockNumber.get(block)
|
|
36
|
-
if (cached) return cached
|
|
37
|
-
// Start at the current head and traverse backwards until the requested block is found
|
|
38
|
-
const startingBlock = head
|
|
39
|
-
const currentBlockHash = await PayloadBuilder.hash(startingBlock)
|
|
40
|
-
let currentBlock = (await this.chainArchivist.get([currentBlockHash])).at(0)
|
|
41
|
-
while (isDefined(currentBlock)) {
|
|
42
|
-
assertEx(asBlockBoundWitness(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`)
|
|
43
|
-
if (isBlockBoundWitness(currentBlock)) {
|
|
44
|
-
this._blocksByBlockNumber.set(currentBlock.block, currentBlock)
|
|
45
|
-
if (currentBlock.block === block) {
|
|
46
|
-
return currentBlock
|
|
47
|
-
}
|
|
48
|
-
const { previous } = currentBlock
|
|
49
|
-
if (isNull(previous)) break
|
|
50
|
-
currentBlock = (await this.chainArchivist.get([previous])).at(0)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
throw new Error(`Block not found: ${block}`)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async head(): Promise<WithStorageMeta<BlockBoundWitness>> {
|
|
57
|
-
if (isDefined(this._currentHead)) return this._currentHead
|
|
58
|
-
if (isDefined(this.params.head)) {
|
|
59
|
-
const newHead = await this.getBoundWitnessAsBlockBoundWitnessWithStorageMeta(this.params.head)
|
|
60
|
-
this._currentHead = newHead
|
|
61
|
-
return newHead
|
|
62
|
-
}
|
|
63
|
-
throw new Error('Head is not set')
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async next(block: number): Promise<WithStorageMeta<BlockBoundWitness> | undefined> {
|
|
67
|
-
const currentBlock = block
|
|
68
|
-
const nextBlockNumber = currentBlock + 1
|
|
69
|
-
return await this.get(nextBlockNumber)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// TODO: Decide on inclusive/exclusive (probably need inclusive to account for chain head)
|
|
73
|
-
// and then communicate via method name and documentation
|
|
74
|
-
async previous(block: number | undefined = undefined, count: number = 1): Promise<WithStorageMeta<BlockBoundWitness>[]> {
|
|
75
|
-
const results: WithStorageMeta<BlockBoundWitness>[] = []
|
|
76
|
-
let currentBlock: WithStorageMeta<BlockBoundWitness> | undefined = isDefined(block) ? (await this.get(block)) : await this.head()
|
|
77
|
-
while (currentBlock && results.length < count) {
|
|
78
|
-
if (isBlockBoundWitness(currentBlock)) {
|
|
79
|
-
results.push(currentBlock)
|
|
80
|
-
const { previous } = currentBlock
|
|
81
|
-
if (isNull(previous)) break
|
|
82
|
-
const nextBlock = await this.chainArchivist.get([previous])
|
|
83
|
-
currentBlock = asBlockBoundWitnessWithStorageMeta(nextBlock[0])
|
|
84
|
-
} else {
|
|
85
|
-
const hash = PayloadBuilder.hash(currentBlock)
|
|
86
|
-
assertEx(asBlockBoundWitnessWithStorageMeta(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return results
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async updateHead(head: BlockBoundWitness): Promise<void> {
|
|
93
|
-
const newHead = await this.getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head)
|
|
94
|
-
this._currentHead = newHead
|
|
95
|
-
void this.emit('headUpdated', { blocks: [newHead] })
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private async getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head: BlockBoundWitness): Promise<WithStorageMeta<BlockBoundWitness>> {
|
|
99
|
-
const hash = await PayloadBuilder.hash(head)
|
|
100
|
-
const stored = (await this.chainArchivist.get([hash])).at(-1)
|
|
101
|
-
const newHead = asBlockBoundWitnessWithStorageMeta(stored)
|
|
102
|
-
if (isUndefined(newHead)) throw new Error(`Head block not found in archivist [${hash}]`)
|
|
103
|
-
return newHead
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@xylabs/promise'
|
|
2
|
-
import type { BlockBoundWitness, SignedHydratedTransactionWithStorageMeta } from '@xyo-network/xl1-protocol'
|
|
3
|
-
|
|
4
|
-
export interface BlockNumberIteration {
|
|
5
|
-
validatePendingBlock(block: BlockBoundWitness): Promisable<Error[]>
|
|
6
|
-
validatePendingTransaction(tx: SignedHydratedTransactionWithStorageMeta): Promise<boolean>
|
|
7
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
-
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
3
|
-
|
|
4
|
-
import type { BaseServiceParams } from '../../model/index.ts'
|
|
5
|
-
|
|
6
|
-
export interface XyoChainIteratorParams extends BaseServiceParams {
|
|
7
|
-
chainArchivist: ArchivistInstance
|
|
8
|
-
head: BlockBoundWitness
|
|
9
|
-
}
|