@xyo-network/chain-services 1.17.7 → 1.18.0
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 +3 -3
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
- package/dist/neutral/BaseService.d.ts +2 -2
- package/dist/neutral/BaseService.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 +4 -2
- package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts +0 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts.map +1 -1
- package/dist/neutral/Schemas/BaseSchemasService.d.ts +1 -1
- package/dist/neutral/Schemas/BaseSchemasService.d.ts.map +1 -1
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts +5 -3
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/neutral/blockViewerFromChainIteratorAndArchivist.d.ts.map +1 -1
- package/dist/neutral/implementation/chain/evm.d.ts +2 -2
- package/dist/neutral/implementation/chain/evm.d.ts.map +1 -1
- package/dist/neutral/implementation/chain/index.d.ts +2 -3
- package/dist/neutral/implementation/chain/index.d.ts.map +1 -1
- package/dist/neutral/implementation/head/createBootstrapHead.d.ts +3 -3
- package/dist/neutral/implementation/head/createBootstrapHead.d.ts.map +1 -1
- package/dist/neutral/implementation/head/index.d.ts +1 -1
- package/dist/neutral/implementation/head/index.d.ts.map +1 -1
- package/dist/neutral/implementation/index.d.ts +0 -9
- package/dist/neutral/implementation/index.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +0 -2
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +378 -997
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/model/Params.d.ts +3 -4
- package/dist/neutral/model/Params.d.ts.map +1 -1
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts +25 -33
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts.map +1 -1
- package/package.json +15 -17
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +10 -16
- package/src/BaseService.ts +3 -2
- package/src/ChainService/Evm/Evm.ts +24 -37
- package/src/ChainService/Memory/Memory.ts +6 -12
- package/src/ChainValidator/XyoValidator.ts +11 -4
- package/src/PendingTransactions/BasePendingTransactions.ts +2 -6
- package/src/Schemas/BaseSchemasService.ts +2 -2
- package/src/StakeIntent/XyoStakeIntentService.ts +12 -8
- package/src/blockViewerFromChainIteratorAndArchivist.ts +9 -0
- package/src/implementation/chain/evm.ts +5 -5
- package/src/implementation/chain/index.ts +12 -14
- package/src/implementation/head/createBootstrapHead.ts +13 -8
- package/src/implementation/head/index.ts +1 -1
- package/src/implementation/index.ts +0 -9
- package/src/index.ts +0 -2
- package/src/model/Params.ts +4 -4
- package/src/simple/block/runner/SimpleBlockRunner.ts +122 -122
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts +0 -50
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts.map +0 -1
- package/dist/neutral/ChainBlockNumberIteration/index.d.ts +0 -3
- package/dist/neutral/ChainBlockNumberIteration/index.d.ts.map +0 -1
- package/dist/neutral/ChainBlockNumberIteration/model/BlockNumberIteration.d.ts +0 -7
- package/dist/neutral/ChainBlockNumberIteration/model/BlockNumberIteration.d.ts.map +0 -1
- package/dist/neutral/ChainBlockNumberIteration/model/Params.d.ts +0 -9
- package/dist/neutral/ChainBlockNumberIteration/model/Params.d.ts.map +0 -1
- package/dist/neutral/ChainBlockNumberIteration/model/index.d.ts +0 -3
- package/dist/neutral/ChainBlockNumberIteration/model/index.d.ts.map +0 -1
- package/dist/neutral/Time/BaseTimeSyncService.d.ts +0 -24
- package/dist/neutral/Time/BaseTimeSyncService.d.ts.map +0 -1
- package/dist/neutral/Time/index.d.ts +0 -2
- package/dist/neutral/Time/index.d.ts.map +0 -1
- package/dist/neutral/implementation/accountBalance.d.ts +0 -7
- package/dist/neutral/implementation/accountBalance.d.ts.map +0 -1
- package/dist/neutral/implementation/blockViewer.d.ts +0 -7
- package/dist/neutral/implementation/blockViewer.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/config/getBridgeDestinationDetails.d.ts +0 -8
- package/dist/neutral/implementation/head/createForkedHead/config/getBridgeDestinationDetails.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/config/getBridgeSourceDetails.d.ts +0 -9
- package/dist/neutral/implementation/head/createForkedHead/config/getBridgeSourceDetails.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/config/getForkDetails.d.ts +0 -4
- package/dist/neutral/implementation/head/createForkedHead/config/getForkDetails.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/config/index.d.ts +0 -4
- package/dist/neutral/implementation/head/createForkedHead/config/index.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/createForkedHead.d.ts +0 -5
- package/dist/neutral/implementation/head/createForkedHead/createForkedHead.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/getBridgeDestinationObservation.d.ts +0 -11
- package/dist/neutral/implementation/head/createForkedHead/getBridgeDestinationObservation.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/getBridgeIntent.d.ts +0 -11
- package/dist/neutral/implementation/head/createForkedHead/getBridgeIntent.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/getBridgeSourceObservation.d.ts +0 -11
- package/dist/neutral/implementation/head/createForkedHead/getBridgeSourceObservation.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/getFirstBlockForNewChain.d.ts +0 -13
- package/dist/neutral/implementation/head/createForkedHead/getFirstBlockForNewChain.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/index.d.ts +0 -2
- package/dist/neutral/implementation/head/createForkedHead/index.d.ts.map +0 -1
- package/dist/neutral/implementation/head/getForkFromBlock.d.ts +0 -12
- package/dist/neutral/implementation/head/getForkFromBlock.d.ts.map +0 -1
- package/dist/neutral/implementation/head/head.d.ts +0 -11
- package/dist/neutral/implementation/head/head.d.ts.map +0 -1
- package/dist/neutral/implementation/head/submitNewChain.d.ts +0 -10
- package/dist/neutral/implementation/head/submitNewChain.d.ts.map +0 -1
- package/dist/neutral/implementation/mempoolRunner.d.ts +0 -7
- package/dist/neutral/implementation/mempoolRunner.d.ts.map +0 -1
- package/dist/neutral/implementation/mempoolViewer.d.ts +0 -7
- package/dist/neutral/implementation/mempoolViewer.d.ts.map +0 -1
- package/dist/neutral/implementation/pendingTransactions.d.ts +0 -9
- package/dist/neutral/implementation/pendingTransactions.d.ts.map +0 -1
- package/dist/neutral/implementation/producer.d.ts +0 -5
- package/dist/neutral/implementation/producer.d.ts.map +0 -1
- package/dist/neutral/implementation/reward.d.ts +0 -14
- package/dist/neutral/implementation/reward.d.ts.map +0 -1
- package/dist/neutral/implementation/time.d.ts +0 -6
- package/dist/neutral/implementation/time.d.ts.map +0 -1
- package/dist/neutral/implementation/validator.d.ts +0 -5
- package/dist/neutral/implementation/validator.d.ts.map +0 -1
- package/dist/neutral/simple/block/runner/spec/SimpleBlockRunner.d.ts +0 -2
- package/dist/neutral/simple/block/runner/spec/SimpleBlockRunner.d.ts.map +0 -1
- package/src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts +0 -176
- package/src/ChainBlockNumberIteration/index.ts +0 -2
- package/src/ChainBlockNumberIteration/model/BlockNumberIteration.ts +0 -7
- package/src/ChainBlockNumberIteration/model/Params.ts +0 -10
- package/src/ChainBlockNumberIteration/model/index.ts +0 -2
- package/src/Time/BaseTimeSyncService.ts +0 -54
- package/src/Time/index.ts +0 -1
- package/src/implementation/accountBalance.ts +0 -29
- package/src/implementation/blockViewer.ts +0 -29
- package/src/implementation/head/createForkedHead/config/getBridgeDestinationDetails.ts +0 -27
- package/src/implementation/head/createForkedHead/config/getBridgeSourceDetails.ts +0 -19
- package/src/implementation/head/createForkedHead/config/getForkDetails.ts +0 -10
- package/src/implementation/head/createForkedHead/config/index.ts +0 -3
- package/src/implementation/head/createForkedHead/createForkedHead.ts +0 -29
- package/src/implementation/head/createForkedHead/getBridgeDestinationObservation.ts +0 -42
- package/src/implementation/head/createForkedHead/getBridgeIntent.ts +0 -51
- package/src/implementation/head/createForkedHead/getBridgeSourceObservation.ts +0 -46
- package/src/implementation/head/createForkedHead/getFirstBlockForNewChain.ts +0 -41
- package/src/implementation/head/createForkedHead/index.ts +0 -1
- package/src/implementation/head/getForkFromBlock.ts +0 -43
- package/src/implementation/head/head.ts +0 -49
- package/src/implementation/head/submitNewChain.ts +0 -27
- package/src/implementation/mempoolRunner.ts +0 -29
- package/src/implementation/mempoolViewer.ts +0 -29
- package/src/implementation/pendingTransactions.ts +0 -36
- package/src/implementation/producer.ts +0 -16
- package/src/implementation/reward.ts +0 -53
- package/src/implementation/time.ts +0 -26
- package/src/implementation/validator.ts +0 -15
- package/src/simple/block/runner/spec/SimpleBlockRunner.ts +0 -418
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { creatable, EmptyObject } from '@xylabs/sdk-js'
|
|
2
|
-
import { TimeDomain, TimePayload } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import {
|
|
4
|
-
BlockViewer,
|
|
5
|
-
SimpleTimeSyncViewer, TimeSyncViewer,
|
|
6
|
-
TimeSyncViewerMoniker,
|
|
7
|
-
} from '@xyo-network/xl1-protocol-sdk'
|
|
8
|
-
import { Provider } from 'ethers'
|
|
9
|
-
|
|
10
|
-
import { BaseService } from '../BaseService.ts'
|
|
11
|
-
import { BaseServiceParams } from '../model/index.ts'
|
|
12
|
-
|
|
13
|
-
export interface BaseTimeServiceParams<TConfig extends EmptyObject = EmptyObject> extends BaseServiceParams<TConfig> {
|
|
14
|
-
blockViewer: BlockViewer
|
|
15
|
-
ethProvider?: Provider
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@creatable()
|
|
19
|
-
export class BaseTimeSyncService extends BaseService<BaseTimeServiceParams> implements TimeSyncViewer {
|
|
20
|
-
static readonly defaultMoniker = TimeSyncViewerMoniker
|
|
21
|
-
static readonly monikers = [TimeSyncViewerMoniker]
|
|
22
|
-
moniker = BaseTimeSyncService.defaultMoniker
|
|
23
|
-
|
|
24
|
-
protected timeSyncViewer!: TimeSyncViewer
|
|
25
|
-
|
|
26
|
-
protected get blockViewer() {
|
|
27
|
-
return this.params.blockViewer
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
protected get ethProvider() {
|
|
31
|
-
return this.params.ethProvider
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async convertTime(fromDomain: TimeDomain, toDomain: TimeDomain, from: number): Promise<number> {
|
|
35
|
-
return await this.timeSyncViewer.convertTime(fromDomain, toDomain, from)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
override async createHandler(): Promise<void> {
|
|
39
|
-
await super.createHandler()
|
|
40
|
-
this.timeSyncViewer = await SimpleTimeSyncViewer.create({ blockViewer: this.blockViewer, ethProvider: this.ethProvider })
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async currentTime(domain: TimeDomain): Promise<[string, number]> {
|
|
44
|
-
return await this.timeSyncViewer.currentTime(domain)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async currentTimeAndHash(domain: TimeDomain): Promise<[number, string | null]> {
|
|
48
|
-
return await this.timeSyncViewer.currentTimeAndHash(domain)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async currentTimePayload(): Promise<TimePayload> {
|
|
52
|
-
return await this.timeSyncViewer.currentTimePayload()
|
|
53
|
-
}
|
|
54
|
-
}
|
package/src/Time/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './BaseTimeSyncService.ts'
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { isDefined, type Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Initializable, InitializableParams } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type { AccountBalanceViewer, Config } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
import {
|
|
5
|
-
AccountBalanceViewerRpcSchemas,
|
|
6
|
-
HttpRpcTransport,
|
|
7
|
-
JsonRpcAccountBalanceViewer,
|
|
8
|
-
} from '@xyo-network/xl1-rpc'
|
|
9
|
-
|
|
10
|
-
let balanceServiceSingleton: Promisable<AccountBalanceViewer> | undefined
|
|
11
|
-
|
|
12
|
-
export type InitAccountBalanceServiceParams = InitializableParams<{
|
|
13
|
-
config: Config
|
|
14
|
-
}>
|
|
15
|
-
|
|
16
|
-
export const initAccountBalanceService: Initializable<InitAccountBalanceServiceParams, AccountBalanceViewer>
|
|
17
|
-
= (params): Promisable<AccountBalanceViewer> => {
|
|
18
|
-
const { config, logger } = params
|
|
19
|
-
if (balanceServiceSingleton) return balanceServiceSingleton
|
|
20
|
-
const endpoint = config.services?.accountBalanceViewerEndpoint ?? config.services?.apiEndpoint
|
|
21
|
-
if (isDefined(endpoint)) {
|
|
22
|
-
const transport = new HttpRpcTransport(endpoint, { ...AccountBalanceViewerRpcSchemas })
|
|
23
|
-
const viewer = new JsonRpcAccountBalanceViewer(transport)
|
|
24
|
-
logger?.log('Using AccountBalanceViewer RPC service at', endpoint)
|
|
25
|
-
return viewer
|
|
26
|
-
} else {
|
|
27
|
-
throw new Error('No AccountBalanceViewer endpoint configured')
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { isDefined, type Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Initializable, InitializableParams } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type { BlockViewer, Config } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
import {
|
|
5
|
-
BlockViewerRpcSchemas,
|
|
6
|
-
HttpRpcTransport,
|
|
7
|
-
JsonRpcBlockViewer,
|
|
8
|
-
} from '@xyo-network/xl1-rpc'
|
|
9
|
-
|
|
10
|
-
let blockViewerSingleton: Promisable<BlockViewer> | undefined
|
|
11
|
-
|
|
12
|
-
export type InitBlockViewerParams = InitializableParams<{
|
|
13
|
-
config: Config
|
|
14
|
-
}>
|
|
15
|
-
|
|
16
|
-
export const initBlockViewer: Initializable<InitBlockViewerParams, BlockViewer>
|
|
17
|
-
= (params): Promisable<BlockViewer> => {
|
|
18
|
-
const { config, logger } = params
|
|
19
|
-
if (blockViewerSingleton) return blockViewerSingleton
|
|
20
|
-
const endpoint = config.services?.apiEndpoint
|
|
21
|
-
if (isDefined(endpoint)) {
|
|
22
|
-
const transport = new HttpRpcTransport(endpoint, { ...BlockViewerRpcSchemas })
|
|
23
|
-
const viewer = new JsonRpcBlockViewer(transport)
|
|
24
|
-
logger?.log('Using BlockViewer RPC service at', endpoint)
|
|
25
|
-
return viewer
|
|
26
|
-
} else {
|
|
27
|
-
throw new Error('No BlockViewer endpoint configured')
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { toHex } from '@xylabs/sdk-js'
|
|
2
|
-
import type { BridgeDetailsDestinationFields } from '@xyo-network/xl1-protocol'
|
|
3
|
-
|
|
4
|
-
import { getForkBlockRewardHex } from './getForkDetails.ts'
|
|
5
|
-
|
|
6
|
-
// const bridgeableTokenContract = toHex('0x4865Cb10d55cfB0E60DD2B4F9b888f6a49B76733')
|
|
7
|
-
// const bridgeDestAddress = toHex('0xe53218d47913b5f9E58bb74F0a0eD790bbF21972')
|
|
8
|
-
// const destConfirmation = toHex('0x4fa05d7e799f36f1d45c441a4866eb4570a00a753a39377f404a8d113c01a657') // Eth TX for mint
|
|
9
|
-
const ethChainId = toHex('0x1')
|
|
10
|
-
const bridgeableTokenContract = toHex('0xf72aE3E0DA743033AbD7A407557D684c1aE66aed')
|
|
11
|
-
const bridgeDestAddress = toHex('0x0e65b65B10C791942665030402c35023d88B14dA')
|
|
12
|
-
const destConfirmation = toHex('0x950861b10523b52cdbb4a9ee52ed26601db555d2652bfec21c709e5e70d5b7d3') // Eth TX for mint
|
|
13
|
-
|
|
14
|
-
export const getBridgeDestChainId = () => ethChainId
|
|
15
|
-
export const getBridgeDestToken = () => bridgeableTokenContract
|
|
16
|
-
export const getBridgeDestAddress = () => bridgeDestAddress
|
|
17
|
-
export const getBridgeDestAmount = () => getForkBlockRewardHex()
|
|
18
|
-
export const getBridgeDestConfirmation = () => destConfirmation
|
|
19
|
-
|
|
20
|
-
export const getBridgeDestinationDetails = (): BridgeDetailsDestinationFields => {
|
|
21
|
-
return {
|
|
22
|
-
dest: getBridgeDestChainId(),
|
|
23
|
-
destToken: getBridgeDestToken(),
|
|
24
|
-
destAddress: getBridgeDestAddress(),
|
|
25
|
-
destAmount: getBridgeDestAmount(),
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { AccountInstance } from '@xyo-network/account-model'
|
|
2
|
-
import type { BridgeDetailsSourceFields } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type { ChainService } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
|
|
5
|
-
import { getForkBlockRewardHex } from './getForkDetails.ts'
|
|
6
|
-
|
|
7
|
-
export const getBridgeSrcChainId = (chainService: ChainService) => chainService.chainId()
|
|
8
|
-
export const getBridgeSrcAddress = (account: AccountInstance) => account.address
|
|
9
|
-
export const getBridgeSrcToken = (chainService: ChainService) => chainService.chainId()
|
|
10
|
-
export const getBridgeSrcAmount = () => getForkBlockRewardHex()
|
|
11
|
-
|
|
12
|
-
export const getBridgeSourceDetails = async (account: AccountInstance, chainService: ChainService): Promise<BridgeDetailsSourceFields> => {
|
|
13
|
-
return {
|
|
14
|
-
src: await getBridgeSrcChainId(chainService),
|
|
15
|
-
srcAddress: getBridgeSrcAddress(account),
|
|
16
|
-
srcToken: await getBridgeSrcToken(chainService),
|
|
17
|
-
srcAmount: getBridgeSrcAmount(),
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type Hex, toHex } from '@xylabs/sdk-js'
|
|
2
|
-
import { AttoXL1ConvertFactor } from '@xyo-network/xl1-protocol'
|
|
3
|
-
|
|
4
|
-
export const getForkBlockReward = (): bigint => {
|
|
5
|
-
return 18_000_000_000n * AttoXL1ConvertFactor.xl1 // 18b XL1 in AttoXL1
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const getForkBlockRewardHex = (): Hex => {
|
|
9
|
-
return toHex(getForkBlockReward())
|
|
10
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
2
|
-
import type { SignedBlockBoundWitnessWithHashMeta, SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type { ChainService } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
|
|
5
|
-
import { getBridgeDestinationObservation } from './getBridgeDestinationObservation.ts'
|
|
6
|
-
import { getBridgeIntent } from './getBridgeIntent.ts'
|
|
7
|
-
import { getBridgeSourceObservation } from './getBridgeSourceObservation.ts'
|
|
8
|
-
import { getFirstBlockForNewChain } from './getFirstBlockForNewChain.ts'
|
|
9
|
-
|
|
10
|
-
export const createForkedHead = async (
|
|
11
|
-
forkFromBlock: SignedBlockBoundWitnessWithHashMeta,
|
|
12
|
-
account: WalletInstance,
|
|
13
|
-
chainService: ChainService,
|
|
14
|
-
): Promise<SignedHydratedBlockWithHashMeta[]> => {
|
|
15
|
-
const chain: SignedHydratedBlockWithHashMeta[] = []
|
|
16
|
-
// Build the first block for the new chain
|
|
17
|
-
const firstBlockForNewChain = await getFirstBlockForNewChain(forkFromBlock, account, chainService)
|
|
18
|
-
chain.push(firstBlockForNewChain)
|
|
19
|
-
// Build the bridge intent
|
|
20
|
-
const bridgeIntent = await getBridgeIntent(firstBlockForNewChain, account, chainService)
|
|
21
|
-
chain.push(bridgeIntent)
|
|
22
|
-
// Build the bridge source observation
|
|
23
|
-
const bridgeSourceObservation = await getBridgeSourceObservation(bridgeIntent, account, chainService)
|
|
24
|
-
chain.push(bridgeSourceObservation)
|
|
25
|
-
// Build the bridge destination observation
|
|
26
|
-
const bridgeDestinationObservation = await getBridgeDestinationObservation(bridgeSourceObservation, account, chainService)
|
|
27
|
-
chain.push(bridgeDestinationObservation)
|
|
28
|
-
return chain
|
|
29
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { buildNextBlock } from '@xyo-network/chain-protocol'
|
|
2
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
3
|
-
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
4
|
-
import type {
|
|
5
|
-
BridgeDestinationObservation, BridgeDestinationObservationFields,
|
|
6
|
-
HydratedBlockWithHashMeta,
|
|
7
|
-
SignedHydratedBlockWithHashMeta,
|
|
8
|
-
} from '@xyo-network/xl1-protocol'
|
|
9
|
-
import { BridgeDestinationObservationSchema } from '@xyo-network/xl1-protocol'
|
|
10
|
-
import type { ChainService } from '@xyo-network/xl1-protocol-sdk'
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
getBridgeDestConfirmation, getBridgeDestinationDetails, getBridgeSourceDetails,
|
|
14
|
-
} from './config/index.ts'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Get the bridge destination observation for a given block.
|
|
18
|
-
* @param previousBlock The previous block to base the observation on.
|
|
19
|
-
* @param account The wallet account to use for the observation.
|
|
20
|
-
* @param chainService The chain service to use for the observation.
|
|
21
|
-
*/
|
|
22
|
-
export const getBridgeDestinationObservation = async (
|
|
23
|
-
previousBlock: HydratedBlockWithHashMeta,
|
|
24
|
-
account: WalletInstance,
|
|
25
|
-
chainService: ChainService,
|
|
26
|
-
): Promise<SignedHydratedBlockWithHashMeta> => {
|
|
27
|
-
const bridgeDestinationObservationFields: BridgeDestinationObservationFields = {
|
|
28
|
-
...await getBridgeSourceDetails(account, chainService),
|
|
29
|
-
...getBridgeDestinationDetails(),
|
|
30
|
-
destConfirmation: getBridgeDestConfirmation(),
|
|
31
|
-
}
|
|
32
|
-
const bridgeDestinationObservation = new PayloadBuilder<BridgeDestinationObservation>({ schema: BridgeDestinationObservationSchema })
|
|
33
|
-
.fields(bridgeDestinationObservationFields)
|
|
34
|
-
.build()
|
|
35
|
-
|
|
36
|
-
return await buildNextBlock(
|
|
37
|
-
previousBlock[0],
|
|
38
|
-
[],
|
|
39
|
-
[bridgeDestinationObservation],
|
|
40
|
-
[account],
|
|
41
|
-
)
|
|
42
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { buildNextBlock, createTransferPayload } from '@xyo-network/chain-protocol'
|
|
2
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
3
|
-
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
4
|
-
import type {
|
|
5
|
-
BridgeIntent, BridgeIntentFields,
|
|
6
|
-
SignedHydratedBlockWithHashMeta,
|
|
7
|
-
} from '@xyo-network/xl1-protocol'
|
|
8
|
-
import { BridgeIntentSchema, XYO_BRIDGE_ADDRESS } from '@xyo-network/xl1-protocol'
|
|
9
|
-
import type { ChainService } from '@xyo-network/xl1-protocol-sdk'
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
getBridgeDestinationDetails, getBridgeSourceDetails, getForkBlockReward,
|
|
13
|
-
} from './config/index.ts'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Get the bridge intent for a given block.
|
|
17
|
-
* @param previousBlock The previous block to base the intent on.
|
|
18
|
-
* @param account The wallet account to use for the intent.
|
|
19
|
-
* @param chainService The chain service to use for the intent.
|
|
20
|
-
*/
|
|
21
|
-
export const getBridgeIntent = async (
|
|
22
|
-
previousBlock: SignedHydratedBlockWithHashMeta,
|
|
23
|
-
account: WalletInstance,
|
|
24
|
-
chainService: ChainService,
|
|
25
|
-
): Promise<SignedHydratedBlockWithHashMeta> => {
|
|
26
|
-
// Create transfer to bridge address
|
|
27
|
-
const transferPayload = createTransferPayload(
|
|
28
|
-
account.address,
|
|
29
|
-
{ [XYO_BRIDGE_ADDRESS]: getForkBlockReward() },
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
// Use timestamp as nonce
|
|
33
|
-
const nonce = `${Date.now()}`
|
|
34
|
-
|
|
35
|
-
// Create Bridge Intent
|
|
36
|
-
const bridgeIntentFields: BridgeIntentFields = {
|
|
37
|
-
...await getBridgeSourceDetails(account, chainService),
|
|
38
|
-
...getBridgeDestinationDetails(),
|
|
39
|
-
nonce,
|
|
40
|
-
}
|
|
41
|
-
const bridgeIntent = new PayloadBuilder<BridgeIntent>({ schema: BridgeIntentSchema })
|
|
42
|
-
.fields(bridgeIntentFields)
|
|
43
|
-
.build()
|
|
44
|
-
|
|
45
|
-
return await buildNextBlock(
|
|
46
|
-
previousBlock[0],
|
|
47
|
-
[],
|
|
48
|
-
[bridgeIntent, transferPayload],
|
|
49
|
-
[account],
|
|
50
|
-
)
|
|
51
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { buildNextBlock } from '@xyo-network/chain-protocol'
|
|
2
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
3
|
-
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
4
|
-
import type {
|
|
5
|
-
BridgeSourceObservation, BridgeSourceObservationFields,
|
|
6
|
-
SignedHydratedBlockWithHashMeta,
|
|
7
|
-
} from '@xyo-network/xl1-protocol'
|
|
8
|
-
import { BridgeSourceObservationSchema } from '@xyo-network/xl1-protocol'
|
|
9
|
-
import type { ChainService } from '@xyo-network/xl1-protocol-sdk'
|
|
10
|
-
|
|
11
|
-
import { getBridgeDestinationDetails, getBridgeSourceDetails } from './config/index.ts'
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Get the bridge source observation for a given block.
|
|
15
|
-
* @param previousBlock The previous block to base the observation on.
|
|
16
|
-
* @param account The wallet account to use for the observation.
|
|
17
|
-
* @param chainService The chain service to use for the observation.
|
|
18
|
-
*/
|
|
19
|
-
export const getBridgeSourceObservation = async (
|
|
20
|
-
previousBlock: SignedHydratedBlockWithHashMeta,
|
|
21
|
-
account: WalletInstance,
|
|
22
|
-
chainService: ChainService,
|
|
23
|
-
): Promise<SignedHydratedBlockWithHashMeta> => {
|
|
24
|
-
// TODO: Find actual transfer TX from previous block/source intent?
|
|
25
|
-
// This hash should contain both the source intent and the transfer to the bridge address
|
|
26
|
-
// As the block is itself both a block and a transaction, we can use its hash for now
|
|
27
|
-
const srcTxHash = previousBlock[0]._hash
|
|
28
|
-
|
|
29
|
-
const bridgeSourceObservationFields: BridgeSourceObservationFields = {
|
|
30
|
-
...await getBridgeSourceDetails(account, chainService),
|
|
31
|
-
...getBridgeDestinationDetails(),
|
|
32
|
-
// Observation
|
|
33
|
-
srcConfirmation: srcTxHash,
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const bridgeSourceObservation = new PayloadBuilder<BridgeSourceObservation>({ schema: BridgeSourceObservationSchema })
|
|
37
|
-
.fields(bridgeSourceObservationFields)
|
|
38
|
-
.build()
|
|
39
|
-
|
|
40
|
-
return await buildNextBlock(
|
|
41
|
-
previousBlock[0],
|
|
42
|
-
[],
|
|
43
|
-
[bridgeSourceObservation],
|
|
44
|
-
[account],
|
|
45
|
-
)
|
|
46
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { buildBlock, type BuildNextBlockOptions } from '@xyo-network/chain-protocol'
|
|
2
|
-
import type { WithHashMeta } from '@xyo-network/payload-model'
|
|
3
|
-
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
4
|
-
import type {
|
|
5
|
-
BlockBoundWitness,
|
|
6
|
-
SignedHydratedBlockWithHashMeta,
|
|
7
|
-
} from '@xyo-network/xl1-protocol'
|
|
8
|
-
import { AttoXL1, XYO_STEP_REWARD_ADDRESS } from '@xyo-network/xl1-protocol'
|
|
9
|
-
import type { ChainService } from '@xyo-network/xl1-protocol-sdk'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Get the first block for the new forked chain.
|
|
13
|
-
* @param forkBlock The block to fork from
|
|
14
|
-
* @param account The wallet account to sign the block
|
|
15
|
-
* @param chainService The chain service instance
|
|
16
|
-
* @returns The first block for the new forked chain
|
|
17
|
-
*/
|
|
18
|
-
export const getFirstBlockForNewChain = async (
|
|
19
|
-
forkBlock: WithHashMeta<BlockBoundWitness>,
|
|
20
|
-
account: WalletInstance,
|
|
21
|
-
chainService: ChainService,
|
|
22
|
-
): Promise<SignedHydratedBlockWithHashMeta> => {
|
|
23
|
-
const {
|
|
24
|
-
_hash: previousBlockHash, block: previousBlockNumber, step_hashes: previousStepHashes = [], protocol,
|
|
25
|
-
} = forkBlock
|
|
26
|
-
const chainId = await chainService.chainId()
|
|
27
|
-
const options: BuildNextBlockOptions = {
|
|
28
|
-
blockPayloads: [],
|
|
29
|
-
chainId,
|
|
30
|
-
previousBlockHash,
|
|
31
|
-
previousBlockNumber,
|
|
32
|
-
previousStepHashes,
|
|
33
|
-
signers: [account],
|
|
34
|
-
txs: [],
|
|
35
|
-
protocol,
|
|
36
|
-
chainStepRewardAddress: XYO_STEP_REWARD_ADDRESS,
|
|
37
|
-
stepRewardPoolBalance: AttoXL1(0n),
|
|
38
|
-
}
|
|
39
|
-
// Can not use buildNextBlock because we need to control the chain id change here
|
|
40
|
-
return await buildBlock(options)
|
|
41
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './createForkedHead.ts'
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { Address, Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
asHash, hexFromBigInt, isDefined,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
6
|
-
import type { SignedBlockBoundWitnessWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
7
|
-
import { isSignedBlockBoundWitnessWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
8
|
-
import type { ChainService } from '@xyo-network/xl1-protocol-sdk'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Determine if the chain should fork based on the current head and chain configuration.
|
|
12
|
-
* @param head The current head block
|
|
13
|
-
* @param chainService The chain service instance
|
|
14
|
-
* @param chainArchivist The chain archivist instance
|
|
15
|
-
* @returns The block to fork from if the chain should fork, undefined otherwise
|
|
16
|
-
*/
|
|
17
|
-
export const getForkFromBlock = async (
|
|
18
|
-
head: SignedBlockBoundWitnessWithHashMeta,
|
|
19
|
-
chainService: ChainService,
|
|
20
|
-
chainArchivist: ArchivistInstance,
|
|
21
|
-
): Promise<SignedBlockBoundWitnessWithHashMeta | undefined> => {
|
|
22
|
-
// If the head's chain doesn't match our chainId, we may need to fork
|
|
23
|
-
if (head.chain !== await chainService.chainId()) {
|
|
24
|
-
// Get the forked at hash from the chain service
|
|
25
|
-
const forkedAtBigInt = await chainService.forkedAtHash()
|
|
26
|
-
const forkedAtHex = hexFromBigInt(forkedAtBigInt) // Validate it's a proper hex string
|
|
27
|
-
const forkedAtHash: Hash | undefined = asHash(forkedAtHex)
|
|
28
|
-
if (isDefined(forkedAtHash)) {
|
|
29
|
-
// If we have a forkedAtHash, we need to check if the correct block exists
|
|
30
|
-
const [forkedAtBlock] = await chainArchivist.get([forkedAtHash])
|
|
31
|
-
const forkedChainId: Address = await chainService.forkedChainId()
|
|
32
|
-
const forkedAtBlockNumber: number = Number(await chainService.forkedAtBlockNumber())
|
|
33
|
-
// If we found the block hash we should fork at, check if it's a valid BlockBoundWitness
|
|
34
|
-
if (isSignedBlockBoundWitnessWithHashMeta(forkedAtBlock)
|
|
35
|
-
// And it is on the correct forked from chain
|
|
36
|
-
&& forkedAtBlock.chain === forkedChainId
|
|
37
|
-
// And it is the correct forked at block number
|
|
38
|
-
&& forkedAtBlock.block === forkedAtBlockNumber) {
|
|
39
|
-
return forkedAtBlock
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
4
|
-
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
5
|
-
import type { Initializable, SignedBlockBoundWitnessWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
6
|
-
import { type ChainService, findMostRecentBlock } from '@xyo-network/xl1-protocol-sdk'
|
|
7
|
-
|
|
8
|
-
import { createBootstrapHead } from './createBootstrapHead.ts'
|
|
9
|
-
import { createForkedHead } from './createForkedHead/index.ts'
|
|
10
|
-
import { getForkFromBlock } from './getForkFromBlock.ts'
|
|
11
|
-
import { submitNewChain } from './submitNewChain.ts'
|
|
12
|
-
|
|
13
|
-
let headSingleton: Promisable<SignedBlockBoundWitnessWithHashMeta> | undefined
|
|
14
|
-
|
|
15
|
-
export const initHead: Initializable<{
|
|
16
|
-
account: WalletInstance
|
|
17
|
-
chainArchivist: ArchivistInstance
|
|
18
|
-
chainService: ChainService
|
|
19
|
-
chainSubmissionsArchivistWrite: ArchivistInstance
|
|
20
|
-
}, SignedBlockBoundWitnessWithHashMeta>
|
|
21
|
-
= async (params): Promise<SignedBlockBoundWitnessWithHashMeta> => {
|
|
22
|
-
const {
|
|
23
|
-
account, chainArchivist, chainSubmissionsArchivistWrite, chainService,
|
|
24
|
-
} = params
|
|
25
|
-
if (headSingleton) return headSingleton
|
|
26
|
-
let head = await findMostRecentBlock(chainArchivist)
|
|
27
|
-
|
|
28
|
-
// If there is a head
|
|
29
|
-
if (head) {
|
|
30
|
-
// If there is a head but check if it matches our chainId or we should fork from it
|
|
31
|
-
const forkFromBlock = await getForkFromBlock(head, chainService, chainArchivist)
|
|
32
|
-
// If we should fork form a block in the current chain
|
|
33
|
-
if (isDefined(forkFromBlock)) {
|
|
34
|
-
// Create a new chain from the fork from block
|
|
35
|
-
const chain = await createForkedHead(forkFromBlock, account, chainService)
|
|
36
|
-
await submitNewChain(chain, chainArchivist, chainSubmissionsArchivistWrite)
|
|
37
|
-
const newBlock = assertEx(chain.at(-1), () => new Error('Failed to get new head after forking'))
|
|
38
|
-
head = newBlock[0]
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
// If there is no head, create one
|
|
42
|
-
const chain = await createBootstrapHead(account, chainService)
|
|
43
|
-
await submitNewChain(chain, chainArchivist, chainSubmissionsArchivistWrite)
|
|
44
|
-
const newBlock = assertEx(chain.at(-1), () => new Error('Failed to get new head after genesis'))
|
|
45
|
-
head = newBlock[0]
|
|
46
|
-
}
|
|
47
|
-
headSingleton = head
|
|
48
|
-
return headSingleton
|
|
49
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { delay } from '@xylabs/sdk-js'
|
|
2
|
-
import type { ArchivistInstance, WriteArchivist } from '@xyo-network/archivist-model'
|
|
3
|
-
import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
4
|
-
import { flattenHydratedBlock } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Submit a new chain to the archivist.
|
|
8
|
-
* @param chain The new chain to submit
|
|
9
|
-
* @param chainArchivist The chain archivist instance
|
|
10
|
-
* @param chainSubmissionsArchivistWrite The chain submissions archivist instance
|
|
11
|
-
*/
|
|
12
|
-
export const submitNewChain = async (
|
|
13
|
-
chain: SignedHydratedBlockWithHashMeta[],
|
|
14
|
-
chainArchivist: ArchivistInstance,
|
|
15
|
-
chainSubmissionsArchivistWrite: WriteArchivist,
|
|
16
|
-
): Promise<void> => {
|
|
17
|
-
for (const block of chain) {
|
|
18
|
-
const [bw] = block
|
|
19
|
-
await chainSubmissionsArchivistWrite.insert(flattenHydratedBlock(block))
|
|
20
|
-
// Wait for block to show up in finalized archivist
|
|
21
|
-
while (true) {
|
|
22
|
-
const result = await chainArchivist.get([bw._hash])
|
|
23
|
-
if (result.length > 0) break
|
|
24
|
-
await delay(1000) // Wait 1 second before retrying
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { isDefined, type Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Initializable, InitializableParams } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type { Config, MempoolRunner } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
import {
|
|
5
|
-
HttpRpcTransport,
|
|
6
|
-
JsonRpcMempoolRunner,
|
|
7
|
-
MempoolRunnerRpcSchemas,
|
|
8
|
-
} from '@xyo-network/xl1-rpc'
|
|
9
|
-
|
|
10
|
-
let mempoolRunnerSingleton: Promisable<MempoolRunner> | undefined
|
|
11
|
-
|
|
12
|
-
export type InitMempoolRunnerParams = InitializableParams<{
|
|
13
|
-
config: Config
|
|
14
|
-
}>
|
|
15
|
-
|
|
16
|
-
export const initMempoolRunner: Initializable<InitMempoolRunnerParams, MempoolRunner>
|
|
17
|
-
= (params): Promisable<MempoolRunner> => {
|
|
18
|
-
const { config, logger } = params
|
|
19
|
-
if (mempoolRunnerSingleton) return mempoolRunnerSingleton
|
|
20
|
-
const endpoint = config.services?.apiEndpoint
|
|
21
|
-
if (isDefined(endpoint)) {
|
|
22
|
-
const transport = new HttpRpcTransport(endpoint, { ...MempoolRunnerRpcSchemas })
|
|
23
|
-
const runner = new JsonRpcMempoolRunner(transport)
|
|
24
|
-
logger?.log('Using mempoolRunner RPC service at', endpoint)
|
|
25
|
-
return runner
|
|
26
|
-
} else {
|
|
27
|
-
throw new Error('No MempoolRunner endpoint configured')
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { isDefined, type Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Initializable, InitializableParams } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type { Config, MempoolViewer } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
import {
|
|
5
|
-
HttpRpcTransport,
|
|
6
|
-
JsonRpcMempoolViewer,
|
|
7
|
-
MempoolViewerRpcSchemas,
|
|
8
|
-
} from '@xyo-network/xl1-rpc'
|
|
9
|
-
|
|
10
|
-
let mempoolViewerSingleton: Promisable<MempoolViewer> | undefined
|
|
11
|
-
|
|
12
|
-
export type InitMempoolViewerParams = InitializableParams<{
|
|
13
|
-
config: Config
|
|
14
|
-
}>
|
|
15
|
-
|
|
16
|
-
export const initMempoolViewer: Initializable<InitMempoolViewerParams, MempoolViewer>
|
|
17
|
-
= (params): Promisable<MempoolViewer> => {
|
|
18
|
-
const { config, logger } = params
|
|
19
|
-
if (mempoolViewerSingleton) return mempoolViewerSingleton
|
|
20
|
-
const endpoint = config.services?.apiEndpoint
|
|
21
|
-
if (isDefined(endpoint)) {
|
|
22
|
-
const transport = new HttpRpcTransport(endpoint, { ...MempoolViewerRpcSchemas })
|
|
23
|
-
const viewer = new JsonRpcMempoolViewer(transport)
|
|
24
|
-
logger?.log('Using MempoolViewer RPC service at', endpoint)
|
|
25
|
-
return viewer
|
|
26
|
-
} else {
|
|
27
|
-
throw new Error('No MempoolViewer endpoint configured')
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { isDefined, type Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Initializable, InitializableParams } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type { Config, MempoolViewer } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
import { timeBudget } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
-
import {
|
|
6
|
-
HttpRpcTransport, JsonRpcMempoolViewer, MempoolViewerRpcSchemas,
|
|
7
|
-
} from '@xyo-network/xl1-rpc'
|
|
8
|
-
|
|
9
|
-
import { BasePendingTransactionsService, type BasePendingTransactionsServiceParams } from '../PendingTransactions/index.ts'
|
|
10
|
-
|
|
11
|
-
let serviceSingleton: Promisable<MempoolViewer> | undefined
|
|
12
|
-
|
|
13
|
-
export type InitPendingTransactionsServiceParams = InitializableParams<{
|
|
14
|
-
config: Config
|
|
15
|
-
params?: BasePendingTransactionsServiceParams
|
|
16
|
-
}>
|
|
17
|
-
|
|
18
|
-
export const initPendingTransactions: Initializable<InitPendingTransactionsServiceParams, MempoolViewer> = async (
|
|
19
|
-
{
|
|
20
|
-
config, params, logger,
|
|
21
|
-
}: InitPendingTransactionsServiceParams,
|
|
22
|
-
): Promise<MempoolViewer> => {
|
|
23
|
-
if (serviceSingleton) return serviceSingleton
|
|
24
|
-
return await timeBudget('initPendingTransactions', logger, async () => {
|
|
25
|
-
const endpoint = config.services?.apiEndpoint
|
|
26
|
-
if (isDefined(endpoint)) {
|
|
27
|
-
const transport = new HttpRpcTransport(endpoint, { ...MempoolViewerRpcSchemas })
|
|
28
|
-
const viewer = new JsonRpcMempoolViewer(transport)
|
|
29
|
-
logger?.log('Using MempoolViewer RPC service at', endpoint)
|
|
30
|
-
return viewer
|
|
31
|
-
} else {
|
|
32
|
-
serviceSingleton = await BasePendingTransactionsService.create(params)
|
|
33
|
-
}
|
|
34
|
-
return serviceSingleton
|
|
35
|
-
}, 2000, true)
|
|
36
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import { type BlockProducerService, timeBudget } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
|
|
5
|
-
import { SimpleBlockRunner, type SimpleBlockRunnerParams } from '../simple/index.ts'
|
|
6
|
-
|
|
7
|
-
let serviceSingleton: Promisable<BlockProducerService> | undefined
|
|
8
|
-
|
|
9
|
-
export const initBlockProducer: Initializable<SimpleBlockRunnerParams, BlockProducerService>
|
|
10
|
-
= async (params: SimpleBlockRunnerParams): Promise<BlockProducerService> => {
|
|
11
|
-
if (serviceSingleton) return serviceSingleton
|
|
12
|
-
return await timeBudget('initBlockProducer', params.logger, async () => {
|
|
13
|
-
serviceSingleton = await SimpleBlockRunner.create(params)
|
|
14
|
-
return serviceSingleton
|
|
15
|
-
}, 2000, true)
|
|
16
|
-
}
|