@xyo-network/chain-services 1.6.0 → 1.6.2
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/index.mjs +273 -361
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/types/AccountBalance/{ChainAccountBalanceServiceV2.d.ts → BaseAccountBalanceService.d.ts} +4 -4
- package/dist/types/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -0
- package/dist/types/AccountBalance/accountBalanceServiceFromArchivist.d.ts +4 -4
- package/dist/types/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
- package/dist/types/AccountBalance/index.d.ts +1 -2
- package/dist/types/AccountBalance/index.d.ts.map +1 -1
- package/dist/types/BaseService.d.ts +1 -1
- package/dist/types/BaseService.d.ts.map +1 -1
- package/dist/types/BlockProducer/{XyoBlockProducer.d.ts → BaseBlockProducerService.d.ts} +4 -4
- package/dist/types/BlockProducer/BaseBlockProducerService.d.ts.map +1 -0
- package/dist/types/BlockProducer/index.d.ts +1 -1
- package/dist/types/BlockProducer/index.d.ts.map +1 -1
- package/dist/types/BlockReward/BaseBlockRewardService.d.ts +10 -0
- package/dist/types/BlockReward/BaseBlockRewardService.d.ts.map +1 -0
- package/dist/types/BlockReward/EvmBlockRewardService.d.ts +5 -4
- package/dist/types/BlockReward/EvmBlockRewardService.d.ts.map +1 -1
- package/dist/types/BlockReward/{XyoBlockRewardService.d.ts → MemoryBlockRewardService.d.ts} +5 -6
- package/dist/types/BlockReward/MemoryBlockRewardService.d.ts.map +1 -0
- package/dist/types/BlockReward/index.d.ts +2 -1
- package/dist/types/BlockReward/index.d.ts.map +1 -1
- package/dist/types/ChainBlockNumberIteration/model/Params.d.ts +1 -1
- package/dist/types/ChainBlockNumberIteration/model/Params.d.ts.map +1 -1
- package/dist/types/{Staker → ChainService}/Evm/Evm.d.ts +1 -1
- package/dist/types/ChainService/Evm/Evm.d.ts.map +1 -0
- package/dist/types/ChainService/Evm/index.d.ts.map +1 -0
- package/dist/types/{Staker → ChainService}/Memory/Memory.d.ts +1 -1
- package/dist/types/ChainService/Memory/Memory.d.ts.map +1 -0
- package/dist/types/ChainService/Memory/index.d.ts.map +1 -0
- package/dist/types/ChainService/index.d.ts.map +1 -0
- package/dist/types/ChainValidator/XyoValidator.d.ts +1 -1
- package/dist/types/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/types/Election/{XyoElectionService.d.ts → BaseElectionService.d.ts} +4 -4
- package/dist/types/Election/BaseElectionService.d.ts.map +1 -0
- package/dist/types/Election/index.d.ts +1 -1
- package/dist/types/Election/index.d.ts.map +1 -1
- package/dist/types/PendingTransactions/{PendingTransactions.d.ts → BasePendingTransactions.d.ts} +4 -4
- package/dist/types/PendingTransactions/BasePendingTransactions.d.ts.map +1 -0
- package/dist/types/PendingTransactions/index.d.ts +1 -1
- package/dist/types/PendingTransactions/index.d.ts.map +1 -1
- package/dist/types/StakeIntent/XyoStakeIntentService.d.ts +1 -1
- package/dist/types/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/model/Params.d.ts.map +1 -0
- package/dist/types/model/index.d.ts +2 -0
- package/dist/types/model/index.d.ts.map +1 -0
- package/package.json +39 -40
- package/src/AccountBalance/{ChainAccountBalanceServiceV2.ts → BaseAccountBalanceService.ts} +3 -3
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +8 -50
- package/src/AccountBalance/index.ts +1 -2
- package/src/BaseService.ts +1 -1
- package/src/BlockProducer/{XyoBlockProducer.ts → BaseBlockProducerService.ts} +7 -7
- package/src/BlockProducer/index.ts +1 -1
- package/src/BlockReward/BaseBlockRewardService.ts +16 -0
- package/src/BlockReward/EvmBlockRewardService.ts +6 -5
- package/src/BlockReward/{XyoBlockRewardService.ts → MemoryBlockRewardService.ts} +6 -6
- package/src/BlockReward/index.ts +2 -1
- package/src/ChainBlockNumberIteration/model/Params.ts +1 -1
- package/src/{Staker → ChainService}/Evm/Evm.ts +1 -1
- package/src/{Staker → ChainService}/Memory/Memory.ts +1 -1
- package/src/ChainValidator/XyoValidator.ts +1 -1
- package/src/Election/{XyoElectionService.ts → BaseElectionService.ts} +3 -3
- package/src/Election/index.ts +1 -1
- package/src/PendingTransactions/{PendingTransactions.ts → BasePendingTransactions.ts} +8 -8
- package/src/PendingTransactions/index.ts +1 -1
- package/src/StakeIntent/XyoStakeIntentService.ts +1 -1
- package/src/index.ts +2 -2
- package/src/model/index.ts +1 -0
- package/dist/types/AccountBalance/ChainAccountBalanceServiceV2.d.ts.map +0 -1
- package/dist/types/AccountBalance/XyoChainAccountBalanceService.d.ts +0 -24
- package/dist/types/AccountBalance/XyoChainAccountBalanceService.d.ts.map +0 -1
- package/dist/types/BlockProducer/XyoBlockProducer.d.ts.map +0 -1
- package/dist/types/BlockReward/XyoBlockRewardService.d.ts.map +0 -1
- package/dist/types/ChainIndexService.d.ts +0 -23
- package/dist/types/ChainIndexService.d.ts.map +0 -1
- package/dist/types/Election/XyoElectionService.d.ts.map +0 -1
- package/dist/types/Params.d.ts.map +0 -1
- package/dist/types/PendingTransactions/PendingTransactions.d.ts.map +0 -1
- package/dist/types/Staker/Evm/Evm.d.ts.map +0 -1
- package/dist/types/Staker/Evm/index.d.ts.map +0 -1
- package/dist/types/Staker/Memory/Memory.d.ts.map +0 -1
- package/dist/types/Staker/Memory/index.d.ts.map +0 -1
- package/dist/types/Staker/index.d.ts.map +0 -1
- package/src/AccountBalance/XyoChainAccountBalanceService.ts +0 -86
- package/src/ChainIndexService.ts +0 -46
- /package/dist/types/{Staker → ChainService}/Evm/index.d.ts +0 -0
- /package/dist/types/{Staker → ChainService}/Memory/index.d.ts +0 -0
- /package/dist/types/{Staker → ChainService}/index.d.ts +0 -0
- /package/dist/types/{Params.d.ts → model/Params.d.ts} +0 -0
- /package/src/{Staker → ChainService}/Evm/index.ts +0 -0
- /package/src/{Staker → ChainService}/Memory/index.ts +0 -0
- /package/src/{Staker → ChainService}/index.ts +0 -0
- /package/src/{Params.ts → model/Params.ts} +0 -0
|
@@ -1,63 +1,18 @@
|
|
|
1
1
|
import { exists } from '@xylabs/exists'
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
asHash, type Hash,
|
|
4
4
|
isHash,
|
|
5
5
|
} from '@xylabs/hex'
|
|
6
|
-
import type {
|
|
7
|
-
import type { ChainSummaryBalances } from '@xyo-network/chain-analyze'
|
|
8
|
-
import {
|
|
9
|
-
analyzeChain, BalanceAnalyzer, ChainSummaryBalancesSchema, isChainSummaryBalances,
|
|
10
|
-
} from '@xyo-network/chain-analyze'
|
|
6
|
+
import type { ReadArchivist } from '@xyo-network/archivist-model'
|
|
11
7
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
12
8
|
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
13
9
|
import type { AccountBalanceServiceV2 } from '@xyo-network/xl1-protocol'
|
|
14
|
-
import { AttoXL1 } from '@xyo-network/xl1-protocol'
|
|
15
10
|
import type { BalancesStepSummary, StepSummary } from '@xyo-network/xl1-protocol-sdk'
|
|
16
|
-
import { parseSignedBigInt } from '@xyo-network/xl1-protocol-sdk'
|
|
17
11
|
import { LRUCache } from 'lru-cache'
|
|
18
12
|
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
export const accountBalanceServiceFromArchivist = async (archivist: ArchivistInstance, head?: Hash): Promise<AccountBalanceServiceV2> => {
|
|
22
|
-
let allAddressesBalances: ChainSummaryBalances = {
|
|
23
|
-
schema: ChainSummaryBalancesSchema, balances: {}, firstBlock: null, lastBlock: null,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const result: AccountBalanceServiceV2 = {
|
|
27
|
-
balances: async (head: Hash, addresses: Address[]): Promise<Partial<Record<Address, AttoXL1>>> => {
|
|
28
|
-
const sync = async (head: Hash): Promise<void> => {
|
|
29
|
-
const analysis = await analyzeChain(
|
|
30
|
-
archivist,
|
|
31
|
-
[new BalanceAnalyzer()],
|
|
32
|
-
head,
|
|
33
|
-
null,
|
|
34
|
-
-1n,
|
|
35
|
-
)
|
|
36
|
-
allAddressesBalances = analysis.find(isChainSummaryBalances) ?? {
|
|
37
|
-
schema: ChainSummaryBalancesSchema, balances: {}, firstBlock: null, lastBlock: null,
|
|
38
|
-
}
|
|
39
|
-
return await Promise.resolve()
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
await sync(head)
|
|
43
|
-
|
|
44
|
-
const result: Record<Address, AttoXL1> = {}
|
|
45
|
-
for (const addr of addresses) {
|
|
46
|
-
const signedValue = parseSignedBigInt(allAddressesBalances.balances[addr] ?? { positive: '00' })
|
|
47
|
-
result[addr] = AttoXL1(signedValue > 0n ? signedValue : 0n)
|
|
48
|
-
}
|
|
49
|
-
return result
|
|
50
|
-
},
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (isHash(head)) {
|
|
54
|
-
await result.balances(head, [])
|
|
55
|
-
}
|
|
13
|
+
import { BaseAccountBalanceService } from './BaseAccountBalanceService.ts'
|
|
56
14
|
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const accountBalanceServiceFromArchivistV2 = async (archivist: ArchivistInstance): Promise<AccountBalanceServiceV2> => {
|
|
15
|
+
export const accountBalanceServiceFromArchivist = async (archivist: ReadArchivist): Promise<AccountBalanceServiceV2> => {
|
|
61
16
|
const summaryArchivistCache = new LRUCache<Hash, WithStorageMeta<BalancesStepSummary>>({
|
|
62
17
|
max: 100_000,
|
|
63
18
|
allowStale: true,
|
|
@@ -85,6 +40,9 @@ export const accountBalanceServiceFromArchivistV2 = async (archivist: ArchivistI
|
|
|
85
40
|
throw new Error('Not implemented')
|
|
86
41
|
},
|
|
87
42
|
}
|
|
88
|
-
const service = await
|
|
43
|
+
const service = await BaseAccountBalanceService.create({ chainArchivist: archivist, summaryRepository })
|
|
89
44
|
return service
|
|
90
45
|
}
|
|
46
|
+
|
|
47
|
+
/** @deprecated use accountBalanceServiceFromArchivist */
|
|
48
|
+
export const accountBalanceServiceFromArchivistV2 = accountBalanceServiceFromArchivist
|
package/src/BaseService.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { span, spanAsync } from '@xylabs/telemetry'
|
|
|
5
5
|
import type { Service } from '@xyo-network/xl1-protocol'
|
|
6
6
|
import { Mutex } from 'async-mutex'
|
|
7
7
|
|
|
8
|
-
import type { BaseAccountableServiceParams, BaseServiceParams } from './Params.ts'
|
|
8
|
+
import type { BaseAccountableServiceParams, BaseServiceParams } from './model/Params.ts'
|
|
9
9
|
|
|
10
10
|
declare global {
|
|
11
11
|
var xyoServiceSingletons: Record<string, unknown>
|
|
@@ -39,7 +39,7 @@ export const XYO_PRODUCER_REDECLARATION_DURATION = 10_000
|
|
|
39
39
|
*/
|
|
40
40
|
export const XYO_PRODUCER_REDECLARATION_WINDOW = 500
|
|
41
41
|
|
|
42
|
-
export interface
|
|
42
|
+
export interface BaseBlockProducerServiceParams extends XyoValidatorParams {
|
|
43
43
|
balanceService: AccountBalanceServiceV2
|
|
44
44
|
pendingTransactionsService: PendingTransactionsService
|
|
45
45
|
rejectedTransactionsArchivist: ArchivistInstance
|
|
@@ -47,7 +47,7 @@ export interface XyoBlockProducerParams extends XyoValidatorParams {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
@creatable()
|
|
50
|
-
export class
|
|
50
|
+
export class BaseBlockProducerService extends BaseService<BaseBlockProducerServiceParams> implements BlockProducerService {
|
|
51
51
|
protected _blockRewardDiviner: BlockRewardDiviner | undefined
|
|
52
52
|
|
|
53
53
|
/**
|
|
@@ -163,11 +163,11 @@ export class XyoBlockProducer extends BaseService<XyoBlockProducerParams> implem
|
|
|
163
163
|
/**
|
|
164
164
|
* Handles the producer redeclaration logic
|
|
165
165
|
* @param head The current head block
|
|
166
|
-
* @returns
|
|
166
|
+
* @returns chain stake intent for the producer redeclaration, or undefined if no redeclaration is needed
|
|
167
167
|
*/
|
|
168
168
|
protected async getProducerRedeclaration(head: WithStorageMeta<BlockBoundWitness>): Promise<ChainStakeIntent | undefined> {
|
|
169
169
|
// Decide if we should redeclare intent
|
|
170
|
-
if (!
|
|
170
|
+
if (!BaseBlockProducerService.RedeclareIntent) return
|
|
171
171
|
// Decide if we need to redeclare intent
|
|
172
172
|
const ranges = await this.stakeIntentService.getDeclaredCandidateRanges(this.address, 'producer')
|
|
173
173
|
// TODO: This doesn't handle the case where the producer had declared a range for the future
|
|
@@ -178,8 +178,8 @@ export class XyoBlockProducer extends BaseService<XyoBlockProducerParams> implem
|
|
|
178
178
|
const [, currentDeclarationEnd] = lastRange
|
|
179
179
|
const currentBlock = head.block
|
|
180
180
|
const timeToProducerExpiration = currentDeclarationEnd - currentBlock
|
|
181
|
-
if (timeToProducerExpiration >
|
|
182
|
-
return createDeclarationIntent(this.address, 'producer', currentBlock, currentBlock +
|
|
181
|
+
if (timeToProducerExpiration > BaseBlockProducerService.RedeclarationWindow) return
|
|
182
|
+
return createDeclarationIntent(this.address, 'producer', currentBlock, currentBlock + BaseBlockProducerService.RedeclarationDuration)
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
protected async proposeNextValidBlock(head: WithStorageMeta<BlockBoundWitness>, validateBalances = false): Promise<HydratedBlock | undefined> {
|
|
@@ -187,7 +187,7 @@ export class XyoBlockProducer extends BaseService<XyoBlockProducerParams> implem
|
|
|
187
187
|
// Calculate the next block components
|
|
188
188
|
const { block: previousBlock } = assertEx(asBlockBoundWitness(head), () => 'Invalid head block')
|
|
189
189
|
const nextBlock = previousBlock + 1
|
|
190
|
-
const nextBlockTransactions = await this.pendingTransactionsService.getPendingTransactions(head._hash,
|
|
190
|
+
const nextBlockTransactions = await this.pendingTransactionsService.getPendingTransactions(head._hash, BaseBlockProducerService.DefaultBlockSize)
|
|
191
191
|
|
|
192
192
|
const blockPayloads: AllowedBlockPayload[] = []
|
|
193
193
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './BaseBlockProducerService.ts'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { creatable } from '@xylabs/creatable'
|
|
2
|
+
import { Promisable } from '@xylabs/promise'
|
|
3
|
+
import { BlockRewardService } from '@xyo-network/xl1-protocol'
|
|
4
|
+
|
|
5
|
+
import { BaseService } from '../BaseService.ts'
|
|
6
|
+
import { BaseServiceParams } from '../model/Params.ts'
|
|
7
|
+
|
|
8
|
+
export interface BaseBlockRewardServiceParams extends BaseServiceParams {}
|
|
9
|
+
|
|
10
|
+
@creatable()
|
|
11
|
+
export class BaseBlockRewardService<TParams extends BaseBlockRewardServiceParams = BaseBlockRewardServiceParams>
|
|
12
|
+
extends BaseService<TParams> implements BlockRewardService {
|
|
13
|
+
getRewardForBlock(_blockNumber: bigint): Promisable<bigint> {
|
|
14
|
+
throw new Error('getRewardForBlock method must be implemented in derived classes')
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { creatable } from '@xylabs/creatable'
|
|
3
|
+
import { AccountInstance } from '@xyo-network/account-model'
|
|
3
4
|
import { toEthAddress } from '@xyo-network/chain-ethereum'
|
|
4
5
|
import { XyoChainRewards__factory as XyoChainRewardsFactory } from '@xyo-network/typechain'
|
|
5
6
|
import { BlockRewardService, ChainService } from '@xyo-network/xl1-protocol'
|
|
6
7
|
import { Provider } from 'ethers/providers'
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
-
import { BaseAccountableServiceParams } from '../Params.ts'
|
|
9
|
+
import { BaseBlockRewardService, BaseBlockRewardServiceParams } from './BaseBlockRewardService.ts'
|
|
10
10
|
|
|
11
|
-
export interface EvmBlockRewardServiceParams extends
|
|
11
|
+
export interface EvmBlockRewardServiceParams extends BaseBlockRewardServiceParams {
|
|
12
|
+
account: AccountInstance
|
|
12
13
|
chainService?: ChainService
|
|
13
14
|
provider?: Provider
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
@creatable()
|
|
17
|
-
export class EvmBlockRewardService extends
|
|
18
|
+
export class EvmBlockRewardService extends BaseBlockRewardService<EvmBlockRewardServiceParams> implements BlockRewardService {
|
|
18
19
|
protected _contractAddress: string | undefined
|
|
19
20
|
|
|
20
21
|
protected get chainService() {
|
|
@@ -39,7 +40,7 @@ export class EvmBlockRewardService extends BaseService<EvmBlockRewardServicePara
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
async getRewardForBlock(blockNumber: bigint): Promise<bigint> {
|
|
43
|
+
override async getRewardForBlock(blockNumber: bigint): Promise<bigint> {
|
|
43
44
|
const contract = XyoChainRewardsFactory.connect(toEthAddress(this.contractAddress), this.provider)
|
|
44
45
|
return await contract.calcBlockReward(blockNumber)
|
|
45
46
|
}
|
|
@@ -5,10 +5,9 @@ import { Promisable } from '@xylabs/promise'
|
|
|
5
5
|
import { rewardFromBlockNumber } from '@xyo-network/chain-protocol'
|
|
6
6
|
import { BlockRewardService } from '@xyo-network/xl1-protocol'
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import { BaseServiceParams } from '../Params.ts'
|
|
8
|
+
import { BaseBlockRewardService, BaseBlockRewardServiceParams } from './BaseBlockRewardService.ts'
|
|
10
9
|
|
|
11
|
-
export interface
|
|
10
|
+
export interface MemoryBlockRewardServiceParams extends BaseBlockRewardServiceParams {
|
|
12
11
|
creatorReward?: bigint
|
|
13
12
|
initialStepReward?: bigint
|
|
14
13
|
minRewardPerBlock?: bigint
|
|
@@ -18,7 +17,8 @@ export interface XyoBlockRewardServiceParams extends BaseServiceParams {
|
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
@creatable()
|
|
21
|
-
export class
|
|
20
|
+
export class MemoryBlockRewardService<TParams extends MemoryBlockRewardServiceParams = MemoryBlockRewardServiceParams>
|
|
21
|
+
extends BaseBlockRewardService<TParams> implements BlockRewardService {
|
|
22
22
|
protected readonly rewardFromBlockNumber = rewardFromBlockNumber(18)
|
|
23
23
|
|
|
24
24
|
get creatorReward() {
|
|
@@ -45,7 +45,7 @@ export class XyoBlockRewardService extends BaseService<XyoBlockRewardServicePara
|
|
|
45
45
|
return assertEx(this.params.stepSize, () => 'stepSize is required')
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
static override async paramsHandler<T extends
|
|
48
|
+
static override async paramsHandler<T extends MemoryBlockRewardService['params']>(
|
|
49
49
|
inParams?: Partial<T>,
|
|
50
50
|
): Promise<T> {
|
|
51
51
|
return {
|
|
@@ -59,7 +59,7 @@ export class XyoBlockRewardService extends BaseService<XyoBlockRewardServicePara
|
|
|
59
59
|
} as T
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
getRewardForBlock(blockNumber: bigint): Promisable<bigint> {
|
|
62
|
+
override getRewardForBlock(blockNumber: bigint): Promisable<bigint> {
|
|
63
63
|
return this.rewardFromBlockNumber(
|
|
64
64
|
blockNumber,
|
|
65
65
|
this.initialReward,
|
package/src/BlockReward/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
2
|
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
3
3
|
|
|
4
|
-
import type { BaseServiceParams } from '../../Params.ts'
|
|
4
|
+
import type { BaseServiceParams } from '../../model/Params.ts'
|
|
5
5
|
|
|
6
6
|
export interface XyoChainIteratorParams extends BaseServiceParams {
|
|
7
7
|
chainArchivist: ArchivistInstance
|
|
@@ -9,7 +9,7 @@ import { getAddress } from 'ethers/address'
|
|
|
9
9
|
import type { ContractRunner } from 'ethers/providers'
|
|
10
10
|
|
|
11
11
|
import { BaseService } from '../../BaseService.ts'
|
|
12
|
-
import type { BaseServiceParams } from '../../Params.ts'
|
|
12
|
+
import type { BaseServiceParams } from '../../model/Params.ts'
|
|
13
13
|
|
|
14
14
|
export interface EvmChainServiceParams extends BaseServiceParams {
|
|
15
15
|
contract: StakedXyoChain
|
|
@@ -4,7 +4,7 @@ import { isDefined } from '@xylabs/typeof'
|
|
|
4
4
|
import type { ChainService } from '@xyo-network/xl1-protocol'
|
|
5
5
|
|
|
6
6
|
import { BaseService } from '../../BaseService.ts'
|
|
7
|
-
import type { BaseServiceParams } from '../../Params.ts'
|
|
7
|
+
import type { BaseServiceParams } from '../../model/Params.ts'
|
|
8
8
|
|
|
9
9
|
export interface MemoryChainServiceParams extends BaseServiceParams {}
|
|
10
10
|
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from '@xyo-network/xl1-protocol'
|
|
15
15
|
|
|
16
16
|
import { BaseService } from '../BaseService.ts'
|
|
17
|
-
import { BaseServiceParams } from '../Params.ts'
|
|
17
|
+
import { BaseServiceParams } from '../model/Params.ts'
|
|
18
18
|
import { Validator } from './model/index.ts'
|
|
19
19
|
|
|
20
20
|
export interface XyoValidatorParams extends BaseServiceParams {
|
|
@@ -9,16 +9,16 @@ import type {
|
|
|
9
9
|
import { BlockBoundWitness, ElectionService } from '@xyo-network/xl1-protocol'
|
|
10
10
|
|
|
11
11
|
import { BaseService } from '../BaseService.ts'
|
|
12
|
-
import { BaseServiceParams } from '../Params.ts'
|
|
12
|
+
import { BaseServiceParams } from '../model/Params.ts'
|
|
13
13
|
|
|
14
|
-
export interface
|
|
14
|
+
export interface BaseElectionServicesParams extends BaseServiceParams {
|
|
15
15
|
chainIterator?: ChainBlockNumberIterator
|
|
16
16
|
chainStakeViewer?: ChainStakeViewer
|
|
17
17
|
stakeIntentService?: StakeIntentService
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
@creatable()
|
|
21
|
-
export class
|
|
21
|
+
export class BaseElectionService extends BaseService<BaseElectionServicesParams> implements ElectionService {
|
|
22
22
|
get chainIterator() {
|
|
23
23
|
return assertEx(this.params.chainIterator, () => 'No chain iterator')
|
|
24
24
|
}
|
package/src/Election/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './BaseElectionService.ts'
|
|
@@ -20,21 +20,21 @@ import {
|
|
|
20
20
|
import { Mutex } from 'async-mutex'
|
|
21
21
|
|
|
22
22
|
import { BaseService } from '../BaseService.ts'
|
|
23
|
-
import { BaseServiceParams } from '../Params.ts'
|
|
23
|
+
import { BaseServiceParams } from '../model/Params.ts'
|
|
24
24
|
import { bundledPayloadToHydratedTransaction } from './bundledPayloadToHydratedTransaction.ts'
|
|
25
25
|
import { hydratedTransactionToPayloadBundle } from './hydratedTransactionToPayloadBundle.ts'
|
|
26
26
|
|
|
27
|
-
export interface
|
|
27
|
+
export interface BasePendingTransactionsServiceParams extends BaseServiceParams {
|
|
28
28
|
chainArchivist?: ArchivistInstance
|
|
29
29
|
chainId?: Address
|
|
30
30
|
pendingBundledTransactionsArchivist?: ArchivistInstance
|
|
31
31
|
rejectedTransactionsArchivist?: ArchivistInstance
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
globalAttributes.setAttribute('
|
|
34
|
+
globalAttributes.setAttribute('BasePendingTransactionsService:status', 'unknown')
|
|
35
35
|
|
|
36
36
|
@creatable()
|
|
37
|
-
export class
|
|
37
|
+
export class BasePendingTransactionsService extends BaseService<BasePendingTransactionsServiceParams> implements PendingTransactionsService {
|
|
38
38
|
private static readonly MutexPriority = {
|
|
39
39
|
/**
|
|
40
40
|
* Priority for inserting new transactions
|
|
@@ -135,7 +135,7 @@ export class XyoPendingTransactionsService extends BaseService<XyoPendingTransac
|
|
|
135
135
|
pendingTransactionsCounter?.addCallback((observer) => {
|
|
136
136
|
observer.observe(this.pendingTransactionsCount)
|
|
137
137
|
})
|
|
138
|
-
globalAttributes.setAttribute('
|
|
138
|
+
globalAttributes.setAttribute('BasePendingTransactionsService:status', 'created')
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
async getPendingTransactions(head: Hash, limit: number): Promise<HydratedTransaction[]> {
|
|
@@ -191,7 +191,7 @@ export class XyoPendingTransactionsService extends BaseService<XyoPendingTransac
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
return foundPendingTransactions
|
|
194
|
-
},
|
|
194
|
+
}, BasePendingTransactionsService.MutexPriority.ReadTransactions)
|
|
195
195
|
})
|
|
196
196
|
}
|
|
197
197
|
|
|
@@ -199,7 +199,7 @@ export class XyoPendingTransactionsService extends BaseService<XyoPendingTransac
|
|
|
199
199
|
return await this._updateCuratedPendingTransactionsArchivistMutex.runExclusive(async () => {
|
|
200
200
|
const lastHead = await findMostRecentBlock(this.chainArchivist)
|
|
201
201
|
if (isDefined(lastHead)) await this.pruneCuratedPendingTransactionsArchivist(lastHead._hash)
|
|
202
|
-
},
|
|
202
|
+
}, BasePendingTransactionsService.MutexPriority.PurgeTransactions)
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
private async countPendingTransactions() {
|
|
@@ -242,7 +242,7 @@ export class XyoPendingTransactionsService extends BaseService<XyoPendingTransac
|
|
|
242
242
|
const bundledTransactions = validTransactions.map(tx => hydratedTransactionToPayloadBundle(tx))
|
|
243
243
|
await this.pendingBundledTransactionsLocalArchivist.insert(bundledTransactions)
|
|
244
244
|
}
|
|
245
|
-
},
|
|
245
|
+
}, BasePendingTransactionsService.MutexPriority.InsertNewTransactions)
|
|
246
246
|
})
|
|
247
247
|
}
|
|
248
248
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './BasePendingTransactions.ts'
|
|
@@ -29,7 +29,7 @@ import { Mutex } from 'async-mutex'
|
|
|
29
29
|
import { LRUCache } from 'lru-cache'
|
|
30
30
|
|
|
31
31
|
import { BaseService } from '../BaseService.ts'
|
|
32
|
-
import { BaseServiceParams } from '../Params.ts'
|
|
32
|
+
import { BaseServiceParams } from '../model/Params.ts'
|
|
33
33
|
|
|
34
34
|
export interface XyoStakeIntentServiceParams extends BaseServiceParams {
|
|
35
35
|
chainArchivist?: ArchivistInstance
|
package/src/index.ts
CHANGED
|
@@ -3,9 +3,9 @@ export * from './BaseService.ts'
|
|
|
3
3
|
export * from './BlockProducer/index.ts'
|
|
4
4
|
export * from './BlockReward/index.ts'
|
|
5
5
|
export * from './ChainBlockNumberIteration/index.ts'
|
|
6
|
+
export * from './ChainService/index.ts'
|
|
6
7
|
export * from './ChainValidator/index.ts'
|
|
7
8
|
export * from './Election/index.ts'
|
|
8
|
-
export * from './
|
|
9
|
+
export * from './model/index.ts'
|
|
9
10
|
export * from './PendingTransactions/index.ts'
|
|
10
11
|
export * from './StakeIntent/index.ts'
|
|
11
|
-
export * from './Staker/index.ts'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Params.ts'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChainAccountBalanceServiceV2.d.ts","sourceRoot":"","sources":["../../../src/AccountBalance/ChainAccountBalanceServiceV2.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EACL,uBAAuB,EACvB,OAAO,EAAE,iBAAiB,EAC3B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,mBAAmB,EAEpB,MAAM,+BAA+B,CAAA;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,MAAM,WAAW,kCAAmC,SAAQ,iBAAiB;IAC3E,cAAc,EAAE,aAAa,CAAA;IAC7B,iBAAiB,EAAE,iBAAiB,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAA;CAChE;AAED,qBACa,4BAA6B,SAAQ,WAAW,CAAC,kCAAkC,CAAE,YAAW,uBAAuB;IAC5H,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;CAU3F"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Address, Hash } from '@xylabs/hex';
|
|
2
|
-
import { ArchivistInstance } from '@xyo-network/archivist-model';
|
|
3
|
-
import { AccountBalanceServiceV2, AttoXL1, ChainServiceCollection } from '@xyo-network/xl1-protocol';
|
|
4
|
-
import { BaseService } from '../BaseService.ts';
|
|
5
|
-
import { BaseServiceParams } from '../Params.ts';
|
|
6
|
-
export interface ChainAccountBalanceServiceParams extends BaseServiceParams, Partial<Pick<ChainServiceCollection, 'chainArchivist'>> {
|
|
7
|
-
head?: Hash;
|
|
8
|
-
}
|
|
9
|
-
export declare class XyoChainAccountBalanceService extends BaseService<ChainAccountBalanceServiceParams> implements AccountBalanceServiceV2 {
|
|
10
|
-
private _balances;
|
|
11
|
-
/**
|
|
12
|
-
* The most recent head that was indexed to
|
|
13
|
-
*/
|
|
14
|
-
private _firstBlock;
|
|
15
|
-
/**
|
|
16
|
-
* The oldest block that was indexed through
|
|
17
|
-
*/
|
|
18
|
-
private _lastBlock;
|
|
19
|
-
protected get chainArchivist(): ArchivistInstance;
|
|
20
|
-
balances(head: Hash, address: Address[]): Partial<Record<Address, AttoXL1>>;
|
|
21
|
-
startHandler(): Promise<void>;
|
|
22
|
-
sync(head: Hash): Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=XyoChainAccountBalanceService.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"XyoChainAccountBalanceService.d.ts","sourceRoot":"","sources":["../../../src/AccountBalance/XyoChainAccountBalanceService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAKhE,OAAO,EACL,uBAAuB,EAAE,OAAO,EAAE,sBAAsB,EACzD,MAAM,2BAA2B,CAAA;AAGlC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CA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AC,QAAQ,CAAC,EAC3E,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GACpB,OAAO,CAAC,CAAC,CAAC;IAYb,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;CAW3D"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Hash, Hex } from '@xylabs/hex';
|
|
2
|
-
import { Promisable } from '@xylabs/promise';
|
|
3
|
-
import { ArchivistInstance } from '@xyo-network/archivist-model';
|
|
4
|
-
import { HydratedBlock, Service } from '@xyo-network/xl1-protocol';
|
|
5
|
-
import { BaseService } from './BaseService.ts';
|
|
6
|
-
import { BaseServiceParams } from './Params.ts';
|
|
7
|
-
export interface ChainIndexServiceParams extends BaseServiceParams {
|
|
8
|
-
archivist?: ArchivistInstance;
|
|
9
|
-
}
|
|
10
|
-
export interface ChainIndexService extends Service {
|
|
11
|
-
get(index: bigint): Promisable<HydratedBlock | undefined>;
|
|
12
|
-
updateHead(head: Hash | null): Promisable<void>;
|
|
13
|
-
}
|
|
14
|
-
export declare class XyoChainIndexService extends BaseService<ChainIndexServiceParams> implements ChainIndexService {
|
|
15
|
-
private _head;
|
|
16
|
-
private _internalArchivist;
|
|
17
|
-
protected get externalArchivist(): ArchivistInstance<import("@xyo-network/archivist-model").ArchivistParams<import("@xyo-network/module-model").AnyConfigSchema<import("@xyo-network/archivist-model").ArchivistConfig>>, import("@xyo-network/archivist-model").ArchivistModuleEventData, import("@xyo-network/payload-model").Payload> | undefined;
|
|
18
|
-
protected get internalArchivist(): ArchivistInstance<import("@xyo-network/archivist-model").ArchivistParams<import("@xyo-network/module-model").AnyConfigSchema<import("@xyo-network/archivist-model").ArchivistConfig>>, import("@xyo-network/archivist-model").ArchivistModuleEventData, import("@xyo-network/payload-model").Payload>;
|
|
19
|
-
createHandler(): Promise<void>;
|
|
20
|
-
get(index: bigint | Hex): Promisable<HydratedBlock | undefined>;
|
|
21
|
-
updateHead(_head: Hash | null): Promisable<void>;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=ChainIndexService.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChainIndexService.d.ts","sourceRoot":"","sources":["../../src/ChainIndexService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,SAAS,CAAC,EAAE,iBAAiB,CAAA;CAC9B;AAED,MAAM,WAAW,iBAAkB,SAAQ,OAAO;IAChD,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,aAAa,GAAG,SAAS,CAAC,CAAA;IACzD,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;CAChD;AAED,qBACa,oBAAqB,SAAQ,WAAW,CAAC,uBAAuB,CAAE,YAAW,iBAAiB;IACzG,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,kBAAkB,CAA+B;IAEzD,SAAS,KAAK,iBAAiB,sTAE9B;IAED,SAAS,KAAK,iBAAiB,0SAE9B;IAEc,aAAa;IAI5B,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,UAAU,CAAC,aAAa,GAAG,SAAS,CAAC;IAK/D,UAAU,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;CAGjD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"XyoElectionService.d.ts","sourceRoot":"","sources":["../../../src/Election/XyoElectionService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAG3C,OAAO,KAAK,EACV,wBAAwB,EAAE,gBAAgB,EAAE,kBAAkB,EAC/D,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE9E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,aAAa,CAAC,EAAE,wBAAwB,CAAA;IACxC,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;CACxC;AAED,qBACa,kBAAmB,SAAQ,WAAW,CAAC,yBAAyB,CAAE,YAAW,eAAe;IACvG,IAAI,aAAa,6BAEhB;IAED,IAAI,gBAAgB,qBAEnB;IAED,IAAI,kBAAkB,uBAErB;IAEK,+BAA+B,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IASrF,SAAS,CAAC,wBAAwB,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,OAAO,SAAI,GAAG,OAAO,EAAE;CAM3G"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../src/Params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAEvE,MAAM,WAAW,iBAAkB,SA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CAAC;IAIhD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM1D,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAI/B,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAIjC,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1B,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM3C,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAIlC,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM7C,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAI5B,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAGzD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Staker/Evm/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Memory.d.ts","sourceRoot":"","sources":["../../../../src/Staker/Memory/Memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAExD,MAAM,WAAW,wBAAyB,SA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aAAa,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Staker/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import { creatable } from '@xylabs/creatable'
|
|
3
|
-
import { Address, Hash } from '@xylabs/hex'
|
|
4
|
-
import { isDefined } from '@xylabs/typeof'
|
|
5
|
-
import { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
6
|
-
import {
|
|
7
|
-
analyzeChain, BalanceAnalyzer, ChainSummaryBalances, ChainSummaryBalancesSchema, isChainSummaryBalances,
|
|
8
|
-
} from '@xyo-network/chain-analyze'
|
|
9
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
10
|
-
import {
|
|
11
|
-
AccountBalanceServiceV2, AttoXL1, ChainServiceCollection,
|
|
12
|
-
} from '@xyo-network/xl1-protocol'
|
|
13
|
-
import { parseSignedBigInt, SignedBigInt } from '@xyo-network/xl1-protocol-sdk'
|
|
14
|
-
|
|
15
|
-
import { BaseService } from '../BaseService.ts'
|
|
16
|
-
import { BaseServiceParams } from '../Params.ts'
|
|
17
|
-
|
|
18
|
-
export interface ChainAccountBalanceServiceParams extends BaseServiceParams, Partial<Pick<ChainServiceCollection, 'chainArchivist'>> { head?: Hash }
|
|
19
|
-
|
|
20
|
-
@creatable()
|
|
21
|
-
export class XyoChainAccountBalanceService extends BaseService<ChainAccountBalanceServiceParams> implements AccountBalanceServiceV2 {
|
|
22
|
-
private _balances: Partial<Record<Address, SignedBigInt>> = {}
|
|
23
|
-
/**
|
|
24
|
-
* The most recent head that was indexed to
|
|
25
|
-
*/
|
|
26
|
-
private _firstBlock: Hash | null = null
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* The oldest block that was indexed through
|
|
30
|
-
*/
|
|
31
|
-
private _lastBlock: Hash | null = null
|
|
32
|
-
|
|
33
|
-
protected get chainArchivist(): ArchivistInstance {
|
|
34
|
-
return assertEx(this.params.chainArchivist, () => 'chainArchivist is required')
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
balances(head: Hash, address: Address[]): Partial<Record<Address, AttoXL1>> {
|
|
38
|
-
const result: Record<Address, AttoXL1> = {}
|
|
39
|
-
for (const addr of address) {
|
|
40
|
-
const balance = this._balances[addr]
|
|
41
|
-
const signedBalance = balance ? parseSignedBigInt(balance) : 0n
|
|
42
|
-
result[addr] = AttoXL1(signedBalance >= 0n ? signedBalance : 0n)
|
|
43
|
-
}
|
|
44
|
-
return result
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
override async startHandler() {
|
|
48
|
-
// If we were passed in a head
|
|
49
|
-
if (isDefined(this.params.head)) {
|
|
50
|
-
// Sync from that
|
|
51
|
-
await this.sync(this.params.head)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async sync(head: Hash): Promise<void> {
|
|
56
|
-
// Create starting balances from the current balances
|
|
57
|
-
const startingBalances = new PayloadBuilder<ChainSummaryBalances>({ schema: ChainSummaryBalancesSchema })
|
|
58
|
-
.fields({
|
|
59
|
-
balances: this._balances,
|
|
60
|
-
firstBlock: this._firstBlock,
|
|
61
|
-
lastBlock: this._lastBlock,
|
|
62
|
-
})
|
|
63
|
-
.build()
|
|
64
|
-
|
|
65
|
-
// Calculate the balances for each address through the last indexed block based on the current balances
|
|
66
|
-
const analysis = await analyzeChain(
|
|
67
|
-
this.chainArchivist,
|
|
68
|
-
[new BalanceAnalyzer(undefined, undefined, startingBalances)],
|
|
69
|
-
head,
|
|
70
|
-
this._firstBlock,
|
|
71
|
-
)
|
|
72
|
-
// Find the balances for all addresses
|
|
73
|
-
const allAddressesBalances = analysis.find(isChainSummaryBalances)
|
|
74
|
-
|
|
75
|
-
// Return if no balances were found (nothing to index)
|
|
76
|
-
if (allAddressesBalances === undefined) return
|
|
77
|
-
|
|
78
|
-
// Merge to existing balances map
|
|
79
|
-
this._balances = { ...this._balances, ...allAddressesBalances.balances }
|
|
80
|
-
|
|
81
|
-
// Update first indexed block
|
|
82
|
-
this._firstBlock = allAddressesBalances.firstBlock
|
|
83
|
-
// Update last indexed block
|
|
84
|
-
if (this._lastBlock === null) this._lastBlock = allAddressesBalances.lastBlock
|
|
85
|
-
}
|
|
86
|
-
}
|