@xyo-network/xl1-cli-lib 1.17.0 → 1.17.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/node/commands/index.d.ts +0 -1
- package/dist/node/commands/index.d.ts.map +1 -1
- package/dist/node/commands/validator/runValidator.d.ts +2 -2
- package/dist/node/commands/validator/runValidator.d.ts.map +1 -1
- package/dist/node/index.mjs +190 -1356
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/orchestration/actor/implementation/BalanceActor.d.ts +2 -6
- package/dist/node/orchestration/actor/implementation/BalanceActor.d.ts.map +1 -1
- package/dist/node/orchestration/actor/implementation/ValidatorActor.d.ts +5 -10
- package/dist/node/orchestration/actor/implementation/ValidatorActor.d.ts.map +1 -1
- package/dist/node/orchestration/actor/implementation/index.d.ts +0 -1
- package/dist/node/orchestration/actor/implementation/index.d.ts.map +1 -1
- package/dist/node/orchestration/actor/index.d.ts +0 -1
- package/dist/node/orchestration/actor/index.d.ts.map +1 -1
- package/dist/node/orchestration/index.d.ts +0 -1
- package/dist/node/orchestration/index.d.ts.map +1 -1
- package/dist/node/orchestration/initServices.d.ts.map +1 -1
- package/dist/node/runCLI.d.ts.map +1 -1
- package/dist/node/xl1.mjs +24 -1386
- package/dist/node/xl1.mjs.map +1 -1
- package/package.json +30 -31
- package/src/commands/index.ts +0 -1
- package/src/commands/validator/runValidator.ts +6 -8
- package/src/orchestration/actor/implementation/BalanceActor.ts +4 -16
- package/src/orchestration/actor/implementation/ValidatorActor.ts +19 -27
- package/src/orchestration/actor/implementation/index.ts +0 -1
- package/src/orchestration/actor/index.ts +0 -1
- package/src/orchestration/index.ts +0 -1
- package/src/orchestration/initServices.ts +69 -112
- package/src/runCLI.ts +15 -14
- package/dist/node/commands/producer/index.d.ts +0 -2
- package/dist/node/commands/producer/index.d.ts.map +0 -1
- package/dist/node/commands/producer/runProducer.d.ts +0 -11
- package/dist/node/commands/producer/runProducer.d.ts.map +0 -1
- package/dist/node/orchestration/actor/implementation/ProducerActor.d.ts +0 -35
- package/dist/node/orchestration/actor/implementation/ProducerActor.d.ts.map +0 -1
- package/dist/node/orchestration/actor/model/Actor.d.ts +0 -41
- package/dist/node/orchestration/actor/model/Actor.d.ts.map +0 -1
- package/dist/node/orchestration/actor/model/Orchestrator.d.ts +0 -27
- package/dist/node/orchestration/actor/model/Orchestrator.d.ts.map +0 -1
- package/dist/node/orchestration/actor/model/index.d.ts +0 -3
- package/dist/node/orchestration/actor/model/index.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/accountBalance.d.ts +0 -7
- package/dist/node/orchestration/services/implementation/accountBalance.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/blockViewer.d.ts +0 -7
- package/dist/node/orchestration/services/implementation/blockViewer.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/chain/evm.d.ts +0 -7
- package/dist/node/orchestration/services/implementation/chain/evm.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/chain/index.d.ts +0 -7
- package/dist/node/orchestration/services/implementation/chain/index.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/evm/index.d.ts +0 -2
- package/dist/node/orchestration/services/implementation/evm/index.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/evm/initChainId.d.ts +0 -4
- package/dist/node/orchestration/services/implementation/evm/initChainId.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/evm/initEvmProvider.d.ts +0 -11
- package/dist/node/orchestration/services/implementation/evm/initEvmProvider.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/evm/initInfuraProvider.d.ts +0 -6
- package/dist/node/orchestration/services/implementation/evm/initInfuraProvider.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/evm/initJsonRpcProvider.d.ts +0 -6
- package/dist/node/orchestration/services/implementation/evm/initJsonRpcProvider.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/createBootstrapHead.d.ts +0 -5
- package/dist/node/orchestration/services/implementation/head/createBootstrapHead.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getBridgeDestinationDetails.d.ts +0 -8
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getBridgeDestinationDetails.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getBridgeSourceDetails.d.ts +0 -9
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getBridgeSourceDetails.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getForkDetails.d.ts +0 -4
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getForkDetails.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/index.d.ts +0 -4
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/index.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/createForkedHead/createForkedHead.d.ts +0 -5
- package/dist/node/orchestration/services/implementation/head/createForkedHead/createForkedHead.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getBridgeDestinationObservation.d.ts +0 -11
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getBridgeDestinationObservation.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getBridgeIntent.d.ts +0 -11
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getBridgeIntent.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getBridgeSourceObservation.d.ts +0 -11
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getBridgeSourceObservation.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getFirstBlockForNewChain.d.ts +0 -13
- package/dist/node/orchestration/services/implementation/head/createForkedHead/getFirstBlockForNewChain.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/createForkedHead/index.d.ts +0 -2
- package/dist/node/orchestration/services/implementation/head/createForkedHead/index.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/getForkFromBlock.d.ts +0 -12
- package/dist/node/orchestration/services/implementation/head/getForkFromBlock.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/head.d.ts +0 -11
- package/dist/node/orchestration/services/implementation/head/head.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/index.d.ts +0 -2
- package/dist/node/orchestration/services/implementation/head/index.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/head/submitNewChain.d.ts +0 -10
- package/dist/node/orchestration/services/implementation/head/submitNewChain.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/index.d.ts +0 -12
- package/dist/node/orchestration/services/implementation/index.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/pendingTransactions.d.ts +0 -9
- package/dist/node/orchestration/services/implementation/pendingTransactions.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/producer.d.ts +0 -5
- package/dist/node/orchestration/services/implementation/producer.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/reward.d.ts +0 -5
- package/dist/node/orchestration/services/implementation/reward.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/time.d.ts +0 -6
- package/dist/node/orchestration/services/implementation/time.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/transfer.d.ts +0 -5
- package/dist/node/orchestration/services/implementation/transfer.d.ts.map +0 -1
- package/dist/node/orchestration/services/implementation/validator.d.ts +0 -5
- package/dist/node/orchestration/services/implementation/validator.d.ts.map +0 -1
- package/dist/node/orchestration/services/index.d.ts +0 -2
- package/dist/node/orchestration/services/index.d.ts.map +0 -1
- package/src/commands/producer/index.ts +0 -1
- package/src/commands/producer/runProducer.ts +0 -40
- package/src/orchestration/actor/implementation/ProducerActor.ts +0 -302
- package/src/orchestration/actor/model/Actor.ts +0 -167
- package/src/orchestration/actor/model/Orchestrator.ts +0 -71
- package/src/orchestration/actor/model/index.ts +0 -2
- package/src/orchestration/services/implementation/accountBalance.ts +0 -29
- package/src/orchestration/services/implementation/blockViewer.ts +0 -29
- package/src/orchestration/services/implementation/chain/evm.ts +0 -39
- package/src/orchestration/services/implementation/chain/index.ts +0 -45
- package/src/orchestration/services/implementation/evm/index.ts +0 -1
- package/src/orchestration/services/implementation/evm/initChainId.ts +0 -20
- package/src/orchestration/services/implementation/evm/initEvmProvider.ts +0 -24
- package/src/orchestration/services/implementation/evm/initInfuraProvider.ts +0 -26
- package/src/orchestration/services/implementation/evm/initJsonRpcProvider.ts +0 -20
- package/src/orchestration/services/implementation/head/createBootstrapHead.ts +0 -31
- package/src/orchestration/services/implementation/head/createForkedHead/config/getBridgeDestinationDetails.ts +0 -27
- package/src/orchestration/services/implementation/head/createForkedHead/config/getBridgeSourceDetails.ts +0 -19
- package/src/orchestration/services/implementation/head/createForkedHead/config/getForkDetails.ts +0 -10
- package/src/orchestration/services/implementation/head/createForkedHead/config/index.ts +0 -3
- package/src/orchestration/services/implementation/head/createForkedHead/createForkedHead.ts +0 -29
- package/src/orchestration/services/implementation/head/createForkedHead/getBridgeDestinationObservation.ts +0 -42
- package/src/orchestration/services/implementation/head/createForkedHead/getBridgeIntent.ts +0 -51
- package/src/orchestration/services/implementation/head/createForkedHead/getBridgeSourceObservation.ts +0 -46
- package/src/orchestration/services/implementation/head/createForkedHead/getFirstBlockForNewChain.ts +0 -41
- package/src/orchestration/services/implementation/head/createForkedHead/index.ts +0 -1
- package/src/orchestration/services/implementation/head/getForkFromBlock.ts +0 -43
- package/src/orchestration/services/implementation/head/head.ts +0 -49
- package/src/orchestration/services/implementation/head/index.ts +0 -1
- package/src/orchestration/services/implementation/head/submitNewChain.ts +0 -27
- package/src/orchestration/services/implementation/index.ts +0 -11
- package/src/orchestration/services/implementation/pendingTransactions.ts +0 -35
- package/src/orchestration/services/implementation/producer.ts +0 -15
- package/src/orchestration/services/implementation/reward.ts +0 -50
- package/src/orchestration/services/implementation/time.ts +0 -26
- package/src/orchestration/services/implementation/transfer.ts +0 -15
- package/src/orchestration/services/implementation/validator.ts +0 -15
- package/src/orchestration/services/index.ts +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './initEvmProvider.ts'
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertEx, hexFrom, isDefined, isHex,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
-
|
|
6
|
-
export const canUseChainId = (config: Pick<Config, 'evm'>): boolean => {
|
|
7
|
-
return isDefined(config.evm.chainId)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const getChainId = (config: Pick<Config, 'evm'>) => {
|
|
11
|
-
const chainId = assertEx(config.evm.chainId, () => 'Missing config.evm.chainId')
|
|
12
|
-
if (isHex(chainId, { prefix: true })) {
|
|
13
|
-
const hex = hexFrom(chainId)
|
|
14
|
-
const parsed = Number.parseInt(hex, 16)
|
|
15
|
-
return parsed
|
|
16
|
-
} else {
|
|
17
|
-
const parsed = Number.parseInt(chainId, 10)
|
|
18
|
-
return parsed
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Logger } from '@xylabs/sdk-js'
|
|
2
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
3
|
-
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
import type { Provider } from 'ethers'
|
|
5
|
-
import type { JsonRpcProvider } from 'ethers/providers'
|
|
6
|
-
|
|
7
|
-
import { canUseInfuraProvider, initInfuraProvider } from './initInfuraProvider.ts'
|
|
8
|
-
import { canUseJsonRpcProvider, initJsonRpcProvider } from './initJsonRpcProvider.ts'
|
|
9
|
-
|
|
10
|
-
let provider: Promise<JsonRpcProvider> | undefined
|
|
11
|
-
|
|
12
|
-
export const initEvmProvider = async ({ config }: { config: Pick<Config, 'evm'>; logger?: Logger }): Promise<Provider> => {
|
|
13
|
-
if (provider) return provider
|
|
14
|
-
if (canUseInfuraProvider(config)) {
|
|
15
|
-
provider = initInfuraProvider(config)
|
|
16
|
-
} else if (canUseJsonRpcProvider(config)) {
|
|
17
|
-
provider = initJsonRpcProvider(config)
|
|
18
|
-
}
|
|
19
|
-
return assertEx(await provider, () => 'No provider available')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const canUseEvmProvider = ({ config }: { config: Pick<Config, 'evm'> }) => {
|
|
23
|
-
return canUseInfuraProvider(config) || canUseJsonRpcProvider(config)
|
|
24
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
3
|
-
import { InfuraProvider } from 'ethers/providers'
|
|
4
|
-
|
|
5
|
-
import { canUseChainId, getChainId } from './initChainId.ts'
|
|
6
|
-
|
|
7
|
-
let instance: Promise<InfuraProvider> | undefined
|
|
8
|
-
|
|
9
|
-
export const initInfuraProvider = (config: Pick<Config, 'evm'>) => {
|
|
10
|
-
if (instance) return instance
|
|
11
|
-
const providerConfig = getInfuraProviderConfig(config)
|
|
12
|
-
instance = Promise.resolve(new InfuraProvider(...providerConfig))
|
|
13
|
-
return instance
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const canUseInfuraProvider = (config: Pick<Config, 'evm'>): boolean => {
|
|
17
|
-
return canUseChainId(config)
|
|
18
|
-
&& isDefined(config.evm?.infura?.projectId)
|
|
19
|
-
&& isDefined(config.evm?.infura?.projectSecret)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const getInfuraProviderConfig = (config: Pick<Config, 'evm'>) => {
|
|
23
|
-
const projectId = assertEx(config.evm?.infura?.projectId, () => 'Missing config.evm.infura.projectId')
|
|
24
|
-
const projectSecret = assertEx(config.evm?.infura?.projectSecret, () => 'Missing config.evm.infura.projectSecret')
|
|
25
|
-
return [getChainId(config), projectId, projectSecret] as const
|
|
26
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
3
|
-
import { JsonRpcProvider } from 'ethers/providers'
|
|
4
|
-
|
|
5
|
-
import { canUseChainId, getChainId } from './initChainId.ts'
|
|
6
|
-
|
|
7
|
-
export const initJsonRpcProvider = (config: Pick<Config, 'evm'>) => {
|
|
8
|
-
const providerConfig = getJsonRpcProviderConfig(config)
|
|
9
|
-
return Promise.resolve(new JsonRpcProvider(...providerConfig))
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const canUseJsonRpcProvider = (config: Pick<Config, 'evm'>) => {
|
|
13
|
-
return canUseChainId(config)
|
|
14
|
-
&& isDefined(config.evm.jsonRpc?.url)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const getJsonRpcProviderConfig = (config: Pick<Config, 'evm'>) => {
|
|
18
|
-
const jsonRpcUrl = assertEx(config.evm.jsonRpc?.url, () => 'Missing config.evm.jsonRpc.url')
|
|
19
|
-
return [jsonRpcUrl, getChainId(config)] as const
|
|
20
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildNextBlock, createDeclarationIntent, createGenesisBlock,
|
|
3
|
-
} from '@xyo-network/chain-protocol'
|
|
4
|
-
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
5
|
-
import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
6
|
-
import type { ChainService } from '@xyo-network/xl1-protocol-sdk'
|
|
7
|
-
|
|
8
|
-
export const createBootstrapHead = async (account: WalletInstance, chainService: ChainService): Promise<SignedHydratedBlockWithHashMeta[]> => {
|
|
9
|
-
const chainId = await chainService.chainId()
|
|
10
|
-
const chain: SignedHydratedBlockWithHashMeta[] = []
|
|
11
|
-
|
|
12
|
-
// Create genesis block
|
|
13
|
-
const genesisBlock = await createGenesisBlock(account, chainId, 10_000_000n, account.address)
|
|
14
|
-
chain.push(genesisBlock)
|
|
15
|
-
|
|
16
|
-
// Create producer declaration block
|
|
17
|
-
const producerDeclarationPayload = createDeclarationIntent(
|
|
18
|
-
account.address,
|
|
19
|
-
'producer',
|
|
20
|
-
genesisBlock[0].block,
|
|
21
|
-
genesisBlock[0].block + 10_000,
|
|
22
|
-
)
|
|
23
|
-
const producerDeclarationBlock = await buildNextBlock(
|
|
24
|
-
genesisBlock[0],
|
|
25
|
-
[],
|
|
26
|
-
[producerDeclarationPayload],
|
|
27
|
-
[account],
|
|
28
|
-
)
|
|
29
|
-
chain.push(producerDeclarationBlock)
|
|
30
|
-
return chain
|
|
31
|
-
}
|
|
@@ -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
|
-
}
|
package/src/orchestration/services/implementation/head/createForkedHead/config/getForkDetails.ts
DELETED
|
@@ -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
|
-
}
|
package/src/orchestration/services/implementation/head/createForkedHead/getFirstBlockForNewChain.ts
DELETED
|
@@ -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 +0,0 @@
|
|
|
1
|
-
export * from './head.ts'
|
|
@@ -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,11 +0,0 @@
|
|
|
1
|
-
export * from './accountBalance.ts'
|
|
2
|
-
export * from './blockViewer.ts'
|
|
3
|
-
export * from './chain/index.ts'
|
|
4
|
-
export * from './evm/index.ts'
|
|
5
|
-
export * from './head/index.ts'
|
|
6
|
-
export * from './pendingTransactions.ts'
|
|
7
|
-
export * from './producer.ts'
|
|
8
|
-
export * from './reward.ts'
|
|
9
|
-
export * from './time.ts'
|
|
10
|
-
export * from './transfer.ts'
|
|
11
|
-
export * from './validator.ts'
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { isDefined, type Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import { BasePendingTransactionsService, type BasePendingTransactionsServiceParams } from '@xyo-network/chain-services'
|
|
3
|
-
import type { Initializable, InitializableParams } from '@xyo-network/xl1-protocol'
|
|
4
|
-
import type { Config, MempoolViewer } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
-
import { timeBudget } from '@xyo-network/xl1-protocol-sdk'
|
|
6
|
-
import {
|
|
7
|
-
HttpRpcTransport, JsonRpcMempoolViewer, MempoolViewerRpcSchemas,
|
|
8
|
-
} from '@xyo-network/xl1-rpc'
|
|
9
|
-
|
|
10
|
-
let serviceSingleton: Promisable<MempoolViewer> | undefined
|
|
11
|
-
|
|
12
|
-
export type InitPendingTransactionsServiceParams = InitializableParams<{
|
|
13
|
-
config: Config
|
|
14
|
-
params?: BasePendingTransactionsServiceParams
|
|
15
|
-
}>
|
|
16
|
-
|
|
17
|
-
export const initPendingTransactions: Initializable<InitPendingTransactionsServiceParams, MempoolViewer> = async (
|
|
18
|
-
{
|
|
19
|
-
config, params, logger,
|
|
20
|
-
}: InitPendingTransactionsServiceParams,
|
|
21
|
-
): Promise<MempoolViewer> => {
|
|
22
|
-
if (serviceSingleton) return serviceSingleton
|
|
23
|
-
return await timeBudget('initPendingTransactions', logger, async () => {
|
|
24
|
-
const endpoint = config.services?.apiEndpoint
|
|
25
|
-
if (isDefined(endpoint)) {
|
|
26
|
-
const transport = new HttpRpcTransport(endpoint, { ...MempoolViewerRpcSchemas })
|
|
27
|
-
const viewer = new JsonRpcMempoolViewer(transport)
|
|
28
|
-
logger?.log('Using MempoolViewer RPC service at', endpoint)
|
|
29
|
-
return viewer
|
|
30
|
-
} else {
|
|
31
|
-
serviceSingleton = await BasePendingTransactionsService.create(params)
|
|
32
|
-
}
|
|
33
|
-
return serviceSingleton
|
|
34
|
-
}, 2000, true)
|
|
35
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import { BaseBlockProducerService, type BaseBlockProducerServiceParams } from '@xyo-network/chain-services'
|
|
3
|
-
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
4
|
-
import { type BlockProducerService, timeBudget } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
-
|
|
6
|
-
let serviceSingleton: Promisable<BlockProducerService> | undefined
|
|
7
|
-
|
|
8
|
-
export const initBlockProducer: Initializable<BaseBlockProducerServiceParams, BlockProducerService>
|
|
9
|
-
= async (params: BaseBlockProducerServiceParams): Promise<BlockProducerService> => {
|
|
10
|
-
if (serviceSingleton) return serviceSingleton
|
|
11
|
-
return await timeBudget('initBlockProducer', params.logger, async () => {
|
|
12
|
-
serviceSingleton = await BaseBlockProducerService.create(params)
|
|
13
|
-
return serviceSingleton
|
|
14
|
-
}, 2000, true)
|
|
15
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
type BaseBlockRewardServiceParams, EvmBlockRewardService, type EvmBlockRewardServiceParams, MemoryBlockRewardService,
|
|
4
|
-
} from '@xyo-network/chain-services'
|
|
5
|
-
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
6
|
-
import {
|
|
7
|
-
type BlockRewardService, type Config, timeBudget,
|
|
8
|
-
} from '@xyo-network/xl1-protocol-sdk'
|
|
9
|
-
|
|
10
|
-
import { canUseEvmProvider, initEvmProvider } from './evm/index.ts'
|
|
11
|
-
|
|
12
|
-
let rewardServiceSingleton: Promise<BlockRewardService> | undefined
|
|
13
|
-
|
|
14
|
-
export const initBlockRewardService: Initializable<
|
|
15
|
-
BaseBlockRewardServiceParams<Pick<Config, 'evm'>> | EvmBlockRewardServiceParams,
|
|
16
|
-
BlockRewardService
|
|
17
|
-
> = (params): Promise<BlockRewardService> => {
|
|
18
|
-
if (rewardServiceSingleton) return rewardServiceSingleton
|
|
19
|
-
return timeBudget('initBlockRewardService', params.logger, () => {
|
|
20
|
-
const { config } = params
|
|
21
|
-
rewardServiceSingleton = canUseEvmBlockRewardService({ config })
|
|
22
|
-
? initEvmBlockRewardService(params as EvmBlockRewardServiceParams)
|
|
23
|
-
: initXyoBlockRewardService(params)
|
|
24
|
-
return rewardServiceSingleton
|
|
25
|
-
}, 2000, true)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const initXyoBlockRewardService = (params: BaseBlockRewardServiceParams): Promise<BlockRewardService> => {
|
|
29
|
-
if (rewardServiceSingleton) return rewardServiceSingleton
|
|
30
|
-
return timeBudget('initXyoBlockRewardService', params.logger, () => {
|
|
31
|
-
rewardServiceSingleton = MemoryBlockRewardService.create(params)
|
|
32
|
-
return rewardServiceSingleton
|
|
33
|
-
}, 2000, true)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const canUseEvmBlockRewardService = (params: { config: Pick<Config, 'evm'> }) => canUseEvmProvider({ config: params.config })
|
|
37
|
-
|
|
38
|
-
const initEvmBlockRewardService = async (params: EvmBlockRewardServiceParams): Promise<BlockRewardService> => {
|
|
39
|
-
if (rewardServiceSingleton) return rewardServiceSingleton
|
|
40
|
-
return await timeBudget('initEvmBlockRewardService', params.logger, async () => {
|
|
41
|
-
const { account: paramsAccount } = params
|
|
42
|
-
const account = assertEx(paramsAccount, () => 'Account is required')
|
|
43
|
-
const provider = assertEx(await initEvmProvider(params))
|
|
44
|
-
const evmBlockRewardServiceParams: EvmBlockRewardServiceParams = {
|
|
45
|
-
...params, provider, account,
|
|
46
|
-
}
|
|
47
|
-
rewardServiceSingleton = EvmBlockRewardService.create(evmBlockRewardServiceParams)
|
|
48
|
-
return rewardServiceSingleton
|
|
49
|
-
}, 2000, true)
|
|
50
|
-
}
|