@xyo-network/chain-orchestration 1.20.14 → 1.20.16
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/README.md +9 -177
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/shared/config/actors/Api.d.ts +9 -539
- package/dist/browser/shared/config/actors/Api.d.ts.map +1 -1
- package/dist/browser/shared/config/actors/Bridge.d.ts +9 -689
- package/dist/browser/shared/config/actors/Bridge.d.ts.map +1 -1
- package/dist/browser/shared/config/actors/Mempool.d.ts +9 -539
- package/dist/browser/shared/config/actors/Mempool.d.ts.map +1 -1
- package/dist/browser/shared/config/actors/Producer.d.ts +9 -575
- package/dist/browser/shared/config/actors/Producer.d.ts.map +1 -1
- package/dist/browser/shared/config/actors/RewardRedemption.d.ts +9 -533
- package/dist/browser/shared/config/actors/RewardRedemption.d.ts.map +1 -1
- package/dist/browser/shared/config/actors/Validator.d.ts +9 -563
- package/dist/browser/shared/config/actors/Validator.d.ts.map +1 -1
- package/dist/browser/shared/createDeclarationIntentBlock.d.ts +11 -11
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/shared/config/actors/Api.d.ts +9 -539
- package/dist/neutral/shared/config/actors/Api.d.ts.map +1 -1
- package/dist/neutral/shared/config/actors/Bridge.d.ts +9 -689
- package/dist/neutral/shared/config/actors/Bridge.d.ts.map +1 -1
- package/dist/neutral/shared/config/actors/Mempool.d.ts +9 -539
- package/dist/neutral/shared/config/actors/Mempool.d.ts.map +1 -1
- package/dist/neutral/shared/config/actors/Producer.d.ts +9 -575
- package/dist/neutral/shared/config/actors/Producer.d.ts.map +1 -1
- package/dist/neutral/shared/config/actors/RewardRedemption.d.ts +9 -533
- package/dist/neutral/shared/config/actors/RewardRedemption.d.ts.map +1 -1
- package/dist/neutral/shared/config/actors/Validator.d.ts +9 -563
- package/dist/neutral/shared/config/actors/Validator.d.ts.map +1 -1
- package/dist/neutral/shared/createDeclarationIntentBlock.d.ts +11 -11
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/shared/config/actors/Api.d.ts +9 -539
- package/dist/node/shared/config/actors/Api.d.ts.map +1 -1
- package/dist/node/shared/config/actors/Bridge.d.ts +9 -689
- package/dist/node/shared/config/actors/Bridge.d.ts.map +1 -1
- package/dist/node/shared/config/actors/Mempool.d.ts +9 -539
- package/dist/node/shared/config/actors/Mempool.d.ts.map +1 -1
- package/dist/node/shared/config/actors/Producer.d.ts +9 -575
- package/dist/node/shared/config/actors/Producer.d.ts.map +1 -1
- package/dist/node/shared/config/actors/RewardRedemption.d.ts +9 -533
- package/dist/node/shared/config/actors/RewardRedemption.d.ts.map +1 -1
- package/dist/node/shared/config/actors/Validator.d.ts +9 -563
- package/dist/node/shared/config/actors/Validator.d.ts.map +1 -1
- package/dist/node/shared/createDeclarationIntentBlock.d.ts +11 -11
- package/package.json +136 -52
- package/src/neutral/config/index.ts +0 -1
- package/src/neutral/config/locators/basicRemoteRunnerLocator.ts +0 -14
- package/src/neutral/config/locators/basicRemoteViewerLocator.ts +0 -11
- package/src/neutral/config/locators/index.ts +0 -3
- package/src/neutral/config/locators/rootLocatorFromConfig.ts +0 -19
- package/src/neutral/index.ts +0 -2
- package/src/node/archivists/ChainFinalized/archivist.ts +0 -21
- package/src/node/archivists/ChainFinalized/index.ts +0 -1
- package/src/node/archivists/ChainFinalized/local.ts +0 -17
- package/src/node/archivists/PendingBlocks/archivist.ts +0 -21
- package/src/node/archivists/PendingBlocks/index.ts +0 -1
- package/src/node/archivists/PendingBlocks/local.ts +0 -17
- package/src/node/archivists/RejectedTransactions/archivist.ts +0 -21
- package/src/node/archivists/RejectedTransactions/index.ts +0 -1
- package/src/node/archivists/RejectedTransactions/local.ts +0 -19
- package/src/node/archivists/StakeIntentState/archivist.ts +0 -21
- package/src/node/archivists/StakeIntentState/index.ts +0 -1
- package/src/node/archivists/StakeIntentState/local.ts +0 -18
- package/src/node/archivists/index.ts +0 -4
- package/src/node/archivists/lib/index.ts +0 -1
- package/src/node/archivists/lib/localPersistentArchivist.ts +0 -63
- package/src/node/config/index.ts +0 -2
- package/src/node/config/locators/actors/apiLocatorFromConfig.ts +0 -25
- package/src/node/config/locators/actors/bridgeLocatorFromConfig.ts +0 -83
- package/src/node/config/locators/actors/index.ts +0 -6
- package/src/node/config/locators/actors/mempoolLocatorFromConfig.ts +0 -17
- package/src/node/config/locators/actors/producerLocatorFromConfig.ts +0 -29
- package/src/node/config/locators/actors/rewardRedemptionLocatorFromConfig.ts +0 -56
- package/src/node/config/locators/actors/validatorLocatorFromConfig.ts +0 -15
- package/src/node/config/locators/basicRemoteRunnerLocator.ts +0 -38
- package/src/node/config/locators/basicRemoteViewerLocator.ts +0 -19
- package/src/node/config/locators/contextFromConfigWithoutLocator.ts +0 -25
- package/src/node/config/locators/index.ts +0 -7
- package/src/node/config/locators/localLocatorFromConfig.ts +0 -75
- package/src/node/config/locators/localViewerFromConfig.ts +0 -14
- package/src/node/config/locators/locatorsFromConfig.ts +0 -75
- package/src/node/config/locators/remoteViewerFromConfig.ts +0 -13
- package/src/node/config/locators/rootLocatorFromConfig.ts +0 -22
- package/src/node/config/locators/telemetryContextFromConfig.ts +0 -15
- package/src/node/config/tryParseConfig.ts +0 -42
- package/src/node/evm/index.ts +0 -4
- package/src/node/evm/initChainId.ts +0 -20
- package/src/node/evm/initEvmProvider.ts +0 -22
- package/src/node/evm/initInfuraProvider.ts +0 -29
- package/src/node/evm/initJsonRpcProvider.ts +0 -22
- package/src/node/health/index.ts +0 -1
- package/src/node/health/initHealthEndpoints.ts +0 -67
- package/src/node/index.ts +0 -8
- package/src/node/init/index.ts +0 -6
- package/src/node/init/initBalanceSummaryMap.ts +0 -33
- package/src/node/init/initEvmProvidersIfAvailable.ts +0 -93
- package/src/node/init/initFinalizationArchivistIfNeeded.ts +0 -44
- package/src/node/init/initFinalizedArchivist.ts +0 -16
- package/src/node/init/initServerNode.ts +0 -51
- package/src/node/init/initTransferSummaryMap.ts +0 -33
- package/src/node/manifest/getLocator.ts +0 -65
- package/src/node/manifest/index.ts +0 -5
- package/src/node/manifest/loadNode.ts +0 -26
- package/src/node/manifest/node.json +0 -17
- package/src/node/manifest/nodeManifest.ts +0 -8
- package/src/node/manifest/private/index.ts +0 -4
- package/src/node/manifest/public/Chain.json +0 -49
- package/src/node/manifest/public/Pending.json +0 -54
- package/src/node/manifest/public/index.ts +0 -20
- package/src/node/sharedMiddleware.ts +0 -24
- package/src/shared/ChainInitializableParams.ts +0 -4
- package/src/shared/actor/ValidatorActor.ts +0 -75
- package/src/shared/actor/index.ts +0 -1
- package/src/shared/buildTelemetryConfig.ts +0 -10
- package/src/shared/config/actors/Api.ts +0 -29
- package/src/shared/config/actors/Bridge.ts +0 -131
- package/src/shared/config/actors/Mempool.ts +0 -39
- package/src/shared/config/actors/Producer.ts +0 -56
- package/src/shared/config/actors/RewardRedemption.ts +0 -21
- package/src/shared/config/actors/Validator.ts +0 -22
- package/src/shared/config/actors/index.ts +0 -7
- package/src/shared/config/index.ts +0 -3
- package/src/shared/config/locators/basicRemoteRunnerLocator.ts +0 -63
- package/src/shared/config/locators/basicRemoteViewerLocator.ts +0 -44
- package/src/shared/config/locators/commonLocatorFromConfig.ts +0 -40
- package/src/shared/config/locators/index.ts +0 -4
- package/src/shared/config/locators/remoteLocatorFromConfig.ts +0 -56
- package/src/shared/config/mergeConfig.ts +0 -11
- package/src/shared/createDeclarationIntentBlock.ts +0 -19
- package/src/shared/host/implementation/DefaultHost.ts +0 -25
- package/src/shared/host/implementation/DefaultServiceCollection.ts +0 -60
- package/src/shared/host/implementation/DefaultServiceProvider.ts +0 -12
- package/src/shared/host/implementation/index.ts +0 -2
- package/src/shared/host/index.ts +0 -2
- package/src/shared/host/model/Host.ts +0 -21
- package/src/shared/host/model/ServiceCollection.ts +0 -22
- package/src/shared/host/model/ServiceProvider.ts +0 -3
- package/src/shared/host/model/index.ts +0 -3
- package/src/shared/index.ts +0 -8
- package/src/shared/init/index.ts +0 -5
- package/src/shared/init/initActorAccount.ts +0 -28
- package/src/shared/init/initActorSeedPhrase.ts +0 -29
- package/src/shared/init/initBridgedModule.ts +0 -40
- package/src/shared/init/initStatusReporter.ts +0 -15
- package/src/shared/init/initWallet.ts +0 -44
- package/src/shared/orchestrator/Orchestrator.ts +0 -66
- package/src/shared/orchestrator/index.ts +0 -1
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
2
|
-
import type { BaseConfigContext } from '@xyo-network/xl1-sdk'
|
|
3
|
-
import { JsonRpcProvider } from 'ethers/providers'
|
|
4
|
-
|
|
5
|
-
import { canUseChainId, getChainId } from './initChainId.ts'
|
|
6
|
-
|
|
7
|
-
export const initJsonRpcProvider = (context: BaseConfigContext) => {
|
|
8
|
-
const providerConfig = getJsonRpcProviderConfig(context)
|
|
9
|
-
return Promise.resolve(new JsonRpcProvider(...providerConfig))
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const canUseJsonRpcProvider = (context: BaseConfigContext) => {
|
|
13
|
-
const { config } = context
|
|
14
|
-
return canUseChainId(context)
|
|
15
|
-
&& isDefined(config.evm.jsonRpc?.url)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const getJsonRpcProviderConfig = (context: BaseConfigContext) => {
|
|
19
|
-
const { config } = context
|
|
20
|
-
const jsonRpcUrl = assertEx(config.evm.jsonRpc?.url, () => 'Missing config.evm.jsonRpc.url')
|
|
21
|
-
return [jsonRpcUrl, getChainId(context)] as const
|
|
22
|
-
}
|
package/src/node/health/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './initHealthEndpoints.ts'
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
2
|
-
import http from 'node:http'
|
|
3
|
-
|
|
4
|
-
import type { CreatableStatus } from '@xylabs/sdk-js'
|
|
5
|
-
import { isDefined } from '@xylabs/sdk-js'
|
|
6
|
-
import type { ActorConfigContext, RuntimeStatusMonitor } from '@xyo-network/xl1-sdk'
|
|
7
|
-
|
|
8
|
-
const sendStatus = (res: ServerResponse, status: CreatableStatus, errorCode: number) => {
|
|
9
|
-
const statusCode = status === 'started' ? 200 : errorCode
|
|
10
|
-
res.writeHead(statusCode, { 'Content-Type': 'application/json' })
|
|
11
|
-
res.end(JSON.stringify({ status }))
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const notFound = (res: ServerResponse) => {
|
|
15
|
-
res.writeHead(404, { 'Content-Type': 'application/json' })
|
|
16
|
-
res.end(JSON.stringify({ status: 'not found' }))
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Starts an HTTP server with Kubernetes health endpoints:
|
|
21
|
-
* - /healthz
|
|
22
|
-
* - /livez
|
|
23
|
-
* - /readyz
|
|
24
|
-
* @param context The actor configuration context
|
|
25
|
-
* @param port The port to listen on (default: 8080)
|
|
26
|
-
* @param statusMonitor The runtime status monitor to determine the health status
|
|
27
|
-
*/
|
|
28
|
-
const createHealthServer = (context: ActorConfigContext, port: number, statusMonitor: RuntimeStatusMonitor) => {
|
|
29
|
-
const { logger } = context
|
|
30
|
-
const server = http.createServer((req: IncomingMessage, res: ServerResponse) => {
|
|
31
|
-
const url = req.url ?? ''
|
|
32
|
-
|
|
33
|
-
const status = statusMonitor.getGlobalStatus()
|
|
34
|
-
|
|
35
|
-
switch (url) {
|
|
36
|
-
case '/healthz': {
|
|
37
|
-
sendStatus(res, status, 500)
|
|
38
|
-
break
|
|
39
|
-
}
|
|
40
|
-
case '/livez': {
|
|
41
|
-
sendStatus(res, status, 503)
|
|
42
|
-
break
|
|
43
|
-
}
|
|
44
|
-
case '/readyz': {
|
|
45
|
-
sendStatus(res, status, 503)
|
|
46
|
-
break
|
|
47
|
-
}
|
|
48
|
-
default: {
|
|
49
|
-
notFound(res)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
server.listen(port, () => {
|
|
55
|
-
logger?.log(`Health server running on http://localhost:${port}`)
|
|
56
|
-
logger?.log(' - /healthz')
|
|
57
|
-
logger?.log(' - /livez')
|
|
58
|
-
logger?.log(' - /readyz')
|
|
59
|
-
})
|
|
60
|
-
return server
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function initHealthEndpoints(context: ActorConfigContext, statusMonitor: RuntimeStatusMonitor) {
|
|
64
|
-
const { config } = context
|
|
65
|
-
const { healthCheckPort } = config
|
|
66
|
-
return isDefined(healthCheckPort) ? createHealthServer(context, healthCheckPort, statusMonitor) : undefined
|
|
67
|
-
}
|
package/src/node/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from '../shared/index.ts'
|
|
2
|
-
export * from './archivists/index.ts'
|
|
3
|
-
export * from './config/index.ts'
|
|
4
|
-
export * from './evm/index.ts'
|
|
5
|
-
export * from './health/index.ts'
|
|
6
|
-
export * from './init/index.ts'
|
|
7
|
-
export * from './manifest/index.ts'
|
|
8
|
-
export * from './sharedMiddleware.ts'
|
package/src/node/init/index.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export * from './initBalanceSummaryMap.ts'
|
|
2
|
-
export * from './initEvmProvidersIfAvailable.ts'
|
|
3
|
-
export * from './initFinalizationArchivistIfNeeded.ts'
|
|
4
|
-
export * from './initFinalizedArchivist.ts'
|
|
5
|
-
export * from './initServerNode.ts'
|
|
6
|
-
export * from './initTransferSummaryMap.ts'
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { BaseMongoSdk, type BaseMongoSdkPrivateConfig } from '@xylabs/mongo'
|
|
2
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
3
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
4
|
-
import { MongoMap } from '@xyo-network/chain-protocol'
|
|
5
|
-
import type { WithStorageMeta } from '@xyo-network/sdk-js'
|
|
6
|
-
import type {
|
|
7
|
-
BalancesStepSummary, BaseConfigContext, MapType,
|
|
8
|
-
} from '@xyo-network/xl1-sdk'
|
|
9
|
-
import { hasMongoConfig, MemoryMap } from '@xyo-network/xl1-sdk'
|
|
10
|
-
|
|
11
|
-
export async function initBalanceSummaryMap({ logger, config }: BaseConfigContext): Promise<MapType<string, WithStorageMeta<BalancesStepSummary>>> {
|
|
12
|
-
const mongoConfig = config.storage?.mongo
|
|
13
|
-
if (hasMongoConfig(mongoConfig)) {
|
|
14
|
-
// Create the MongoDB SDK from the configuration
|
|
15
|
-
const {
|
|
16
|
-
connectionString: dbConnectionString, database: dbName, domain: dbDomain, password: dbPassword, username: dbUserName,
|
|
17
|
-
} = mongoConfig
|
|
18
|
-
const payloadSdkConfig: BaseMongoSdkPrivateConfig = {
|
|
19
|
-
dbConnectionString, dbDomain, dbName, dbPassword, dbUserName,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const sdkBalanceSummaryMap = new BaseMongoSdk<WithStorageMeta<BalancesStepSummary>>({ ...payloadSdkConfig, collection: 'balance_summary_map' })
|
|
23
|
-
const result = await MongoMap.create<MongoMap<Hash, WithStorageMeta<BalancesStepSummary>>>({
|
|
24
|
-
sdk: sdkBalanceSummaryMap,
|
|
25
|
-
getCache: { enabled: true, maxEntries: 5000 },
|
|
26
|
-
})
|
|
27
|
-
assertEx(await result.start(), () => 'Failed to start transfer summary map')
|
|
28
|
-
return result
|
|
29
|
-
} else {
|
|
30
|
-
logger?.warn('[API] Mongo configuration not found. Using MemoryMap for BalanceSummaryMap.')
|
|
31
|
-
return new MemoryMap<string, WithStorageMeta<BalancesStepSummary>>()
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { asEthAddress, assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
EvmChainContractViewer, EvmStakeEventsViewer, EvmStakeTotalsViewer, EvmStakeViewer,
|
|
4
|
-
} from '@xyo-network/chain-ethereum'
|
|
5
|
-
import type {
|
|
6
|
-
ChainId,
|
|
7
|
-
Position,
|
|
8
|
-
ProviderFactoryLocatorInstance,
|
|
9
|
-
} from '@xyo-network/xl1-sdk'
|
|
10
|
-
import {
|
|
11
|
-
SimpleChainContractViewer,
|
|
12
|
-
SimpleStakeEventsViewer, SimpleStakeTotalsViewer, SimpleStakeViewer, SimpleTimeSyncViewer,
|
|
13
|
-
XYO_ZERO_ADDRESS,
|
|
14
|
-
} from '@xyo-network/xl1-sdk'
|
|
15
|
-
|
|
16
|
-
import { canUseEvmProvider, initEvmProvider } from '../evm/index.ts'
|
|
17
|
-
|
|
18
|
-
/* TODO: Rename function since it initializes both EVM and non-EVM providers */
|
|
19
|
-
export async function initEvmProvidersIfAvailable(
|
|
20
|
-
locator: ProviderFactoryLocatorInstance,
|
|
21
|
-
): Promise<ProviderFactoryLocatorInstance> {
|
|
22
|
-
const context = locator.context
|
|
23
|
-
const { logger } = context
|
|
24
|
-
if (canUseEvmProvider(context)) {
|
|
25
|
-
const chainId = assertEx(context.config.chain.id as ChainId, () => 'Missing config.chain.id (required for EVM providers)')
|
|
26
|
-
const provider = await initEvmProvider(context)
|
|
27
|
-
const address = asEthAddress(chainId, true)
|
|
28
|
-
|
|
29
|
-
// Register the contract events viewer
|
|
30
|
-
locator.register(EvmStakeEventsViewer.factory<EvmStakeEventsViewer>(
|
|
31
|
-
EvmStakeEventsViewer.dependencies,
|
|
32
|
-
{ address, provider },
|
|
33
|
-
))
|
|
34
|
-
|
|
35
|
-
// Register the stake viewer
|
|
36
|
-
locator.register(EvmStakeViewer.factory<EvmStakeViewer>(
|
|
37
|
-
EvmStakeViewer.dependencies,
|
|
38
|
-
{ address, provider },
|
|
39
|
-
))
|
|
40
|
-
|
|
41
|
-
// Register the stake totals viewer
|
|
42
|
-
locator.register(EvmStakeTotalsViewer.factory<EvmStakeTotalsViewer>(
|
|
43
|
-
EvmStakeTotalsViewer.dependencies,
|
|
44
|
-
{ address, provider },
|
|
45
|
-
))
|
|
46
|
-
|
|
47
|
-
// Register the contract viewer
|
|
48
|
-
locator.register(EvmChainContractViewer.factory<EvmChainContractViewer>(
|
|
49
|
-
EvmChainContractViewer.dependencies,
|
|
50
|
-
{ address, provider },
|
|
51
|
-
))
|
|
52
|
-
|
|
53
|
-
locator.register(SimpleTimeSyncViewer.factory<SimpleTimeSyncViewer>(
|
|
54
|
-
SimpleTimeSyncViewer.dependencies,
|
|
55
|
-
{ ethProvider: provider },
|
|
56
|
-
))
|
|
57
|
-
} else {
|
|
58
|
-
logger?.warn('EVM provider not available - running with memory based contract/stake viewers')
|
|
59
|
-
const positions: Position[] = []
|
|
60
|
-
|
|
61
|
-
// Register the contract events viewer
|
|
62
|
-
locator.register(SimpleStakeEventsViewer.factory<SimpleStakeEventsViewer>(
|
|
63
|
-
SimpleStakeEventsViewer.dependencies,
|
|
64
|
-
{ positions },
|
|
65
|
-
))
|
|
66
|
-
|
|
67
|
-
// Register the stake viewer
|
|
68
|
-
locator.register(SimpleStakeViewer.factory<SimpleStakeViewer>(
|
|
69
|
-
SimpleStakeViewer.dependencies,
|
|
70
|
-
{ positions },
|
|
71
|
-
))
|
|
72
|
-
|
|
73
|
-
// Register the stake totals viewer
|
|
74
|
-
locator.register(SimpleStakeTotalsViewer.factory<SimpleStakeTotalsViewer>(
|
|
75
|
-
SimpleStakeTotalsViewer.dependencies,
|
|
76
|
-
{},
|
|
77
|
-
))
|
|
78
|
-
|
|
79
|
-
// Register the contract viewer
|
|
80
|
-
locator.register(SimpleChainContractViewer.factory<SimpleChainContractViewer>(
|
|
81
|
-
SimpleChainContractViewer.dependencies,
|
|
82
|
-
{
|
|
83
|
-
minWithdrawalBlocks: 10, stakingTokenAddress: XYO_ZERO_ADDRESS, rewardsContract: XYO_ZERO_ADDRESS,
|
|
84
|
-
},
|
|
85
|
-
))
|
|
86
|
-
|
|
87
|
-
locator.register(SimpleTimeSyncViewer.factory<SimpleTimeSyncViewer>(
|
|
88
|
-
SimpleTimeSyncViewer.dependencies,
|
|
89
|
-
{},
|
|
90
|
-
))
|
|
91
|
-
}
|
|
92
|
-
return locator
|
|
93
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import { createBootstrapHead } from '@xyo-network/chain-sdk'
|
|
3
|
-
import type { AccountInstance, ArchivistInstance } from '@xyo-network/sdk-js'
|
|
4
|
-
import { Account } from '@xyo-network/sdk-js'
|
|
5
|
-
import type {
|
|
6
|
-
ActorConfig,
|
|
7
|
-
ChainId,
|
|
8
|
-
SignedBlockBoundWitnessWithHashMeta,
|
|
9
|
-
} from '@xyo-network/xl1-sdk'
|
|
10
|
-
import {
|
|
11
|
-
asAttoXL1, findMostRecentBlock,
|
|
12
|
-
flattenHydratedBlock,
|
|
13
|
-
} from '@xyo-network/xl1-sdk'
|
|
14
|
-
|
|
15
|
-
export async function initFinalizationArchivistIfNeeded(
|
|
16
|
-
archivist: ArchivistInstance,
|
|
17
|
-
config: ActorConfig,
|
|
18
|
-
account: AccountInstance,
|
|
19
|
-
): Promise<[SignedBlockBoundWitnessWithHashMeta, ChainId]> {
|
|
20
|
-
const configuredChainId = config.chain.id
|
|
21
|
-
const possibleHead = await findMostRecentBlock(archivist)
|
|
22
|
-
if (configuredChainId && possibleHead && possibleHead.chain !== configuredChainId) {
|
|
23
|
-
throw new Error(`Configured chain ID (${configuredChainId}) does not match the existing chain ID (${possibleHead.chain})`)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let possibleChainId: ChainId | undefined = configuredChainId
|
|
27
|
-
|
|
28
|
-
// if there is no configured chain ID and no head, create a new chain
|
|
29
|
-
if (!possibleHead) {
|
|
30
|
-
possibleChainId = possibleChainId ?? (await Account.random()).address
|
|
31
|
-
// If there is no head, create one
|
|
32
|
-
const chain = await createBootstrapHead(
|
|
33
|
-
account,
|
|
34
|
-
possibleChainId,
|
|
35
|
-
asAttoXL1(20_000_000_000_000_000_000_000n),
|
|
36
|
-
config.chain.genesisRewardAddress ?? account.address,
|
|
37
|
-
)
|
|
38
|
-
const payloads = chain.flatMap(block => flattenHydratedBlock(block))
|
|
39
|
-
await archivist.insert(payloads)
|
|
40
|
-
}
|
|
41
|
-
const head = possibleHead ?? assertEx(await findMostRecentBlock(archivist), () => 'No blocks found in chain archivist')
|
|
42
|
-
const chainId = assertEx(possibleChainId, () => 'Chain ID could not be determined')
|
|
43
|
-
return [head, chainId]
|
|
44
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { MongoDBArchivistV2 } from '@xyo-network/archivist-mongodb'
|
|
2
|
-
import type { MongoDBModuleParamsV2 } from '@xyo-network/module-model-mongodb'
|
|
3
|
-
import type { Config } from '@xyo-network/xl1-sdk'
|
|
4
|
-
|
|
5
|
-
async function initMongoFinalizedArchivist(config: Config) {
|
|
6
|
-
const payloadSdkConfig = {
|
|
7
|
-
...config.storage.mongo,
|
|
8
|
-
collection: 'chain_validated',
|
|
9
|
-
} satisfies MongoDBModuleParamsV2['payloadSdkConfig']
|
|
10
|
-
return await MongoDBArchivistV2.create({ payloadSdkConfig })
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function initFinalizedArchivist(config: Config) {
|
|
14
|
-
const finalizedArchivist = await initMongoFinalizedArchivist(config)
|
|
15
|
-
return finalizedArchivist
|
|
16
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import type { NodeInstance } from '@xyo-network/sdk-js'
|
|
3
|
-
import { asArchivistInstance } from '@xyo-network/sdk-js'
|
|
4
|
-
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
5
|
-
import type { BaseConfigContext } from '@xyo-network/xl1-sdk'
|
|
6
|
-
|
|
7
|
-
import { loadNode } from '../manifest/index.ts'
|
|
8
|
-
|
|
9
|
-
async function writableChainArchivistFromNode(node: NodeInstance) {
|
|
10
|
-
return asArchivistInstance(
|
|
11
|
-
await node.resolve('Chain:Validated'),
|
|
12
|
-
{ required: true },
|
|
13
|
-
)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async function readonlyChainArchivistFromNode(node: NodeInstance) {
|
|
17
|
-
return assertEx(asArchivistInstance(
|
|
18
|
-
await node.resolve('Chain:Validated'),
|
|
19
|
-
{ required: true },
|
|
20
|
-
))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function pendingTransactionsArchivistFromNode(node: NodeInstance) {
|
|
24
|
-
return asArchivistInstance(
|
|
25
|
-
await node.resolve('XYOChain:Pending:Transactions'),
|
|
26
|
-
{ required: true },
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function pendingBlocksArchivistFromNode(node: NodeInstance) {
|
|
31
|
-
return asArchivistInstance(
|
|
32
|
-
await node.resolve('XYOChain:Pending:Blocks'),
|
|
33
|
-
{ required: true },
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export async function initServerNode(
|
|
38
|
-
context: BaseConfigContext,
|
|
39
|
-
wallet: WalletInstance,
|
|
40
|
-
providedNode?: NodeInstance,
|
|
41
|
-
) {
|
|
42
|
-
const node: NodeInstance = providedNode ?? await loadNode(context, wallet)
|
|
43
|
-
assertEx(await node.start(), () => 'Failed to start node')
|
|
44
|
-
const writableChainArchivist = await writableChainArchivistFromNode(node)
|
|
45
|
-
const readonlyChainArchivist = await readonlyChainArchivistFromNode(node)
|
|
46
|
-
const pendingTransactionsArchivist = await pendingTransactionsArchivistFromNode(node)
|
|
47
|
-
const pendingBlocksArchivist = await pendingBlocksArchivistFromNode(node)
|
|
48
|
-
return {
|
|
49
|
-
node, writableChainArchivist, readonlyChainArchivist, pendingTransactionsArchivist, pendingBlocksArchivist,
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { BaseMongoSdk, type BaseMongoSdkPrivateConfig } from '@xylabs/mongo'
|
|
2
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
3
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
4
|
-
import { MongoMap } from '@xyo-network/chain-protocol'
|
|
5
|
-
import type { WithStorageMeta } from '@xyo-network/sdk-js'
|
|
6
|
-
import type {
|
|
7
|
-
BaseConfigContext, MapType, TransfersStepSummary,
|
|
8
|
-
} from '@xyo-network/xl1-sdk'
|
|
9
|
-
import { hasMongoConfig, MemoryMap } from '@xyo-network/xl1-sdk'
|
|
10
|
-
|
|
11
|
-
export async function initTransferSummaryMap({ logger, config }: BaseConfigContext): Promise<MapType<string, WithStorageMeta<TransfersStepSummary>>> {
|
|
12
|
-
const mongoConfig = config.storage?.mongo
|
|
13
|
-
if (hasMongoConfig(mongoConfig)) {
|
|
14
|
-
// Create the MongoDB SDK from the configuration
|
|
15
|
-
const {
|
|
16
|
-
connectionString: dbConnectionString, database: dbName, domain: dbDomain, password: dbPassword, username: dbUserName,
|
|
17
|
-
} = mongoConfig
|
|
18
|
-
const payloadSdkConfig: BaseMongoSdkPrivateConfig = {
|
|
19
|
-
dbConnectionString, dbDomain, dbName, dbPassword, dbUserName,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const sdkTransferSummaryMap = new BaseMongoSdk<WithStorageMeta<TransfersStepSummary>>({ ...payloadSdkConfig, collection: 'transfer_summary_map' })
|
|
23
|
-
const result = await MongoMap.create<MongoMap<Hash, WithStorageMeta<TransfersStepSummary>>>({
|
|
24
|
-
sdk: sdkTransferSummaryMap,
|
|
25
|
-
getCache: { enabled: true, maxEntries: 5000 },
|
|
26
|
-
})
|
|
27
|
-
assertEx(await result.start(), () => 'Failed to start transfer summary map')
|
|
28
|
-
return result
|
|
29
|
-
} else {
|
|
30
|
-
logger?.warn('[API] Mongo configuration not found. Using MemoryMap for TransferSummaryMap.')
|
|
31
|
-
return new MemoryMap<string, WithStorageMeta<TransfersStepSummary>>()
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { type BaseMongoSdkPrivateConfig } from '@xylabs/mongo'
|
|
2
|
-
import { isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import { MongoDBArchivistV2, MongoDBArchivistV2Deletable } from '@xyo-network/archivist-mongodb'
|
|
4
|
-
import { ViewArchivist } from '@xyo-network/archivist-view'
|
|
5
|
-
import { initTelemetry } from '@xyo-network/chain-telemetry'
|
|
6
|
-
import type { MongoDBModuleParamsV2 } from '@xyo-network/module-model-mongodb'
|
|
7
|
-
import {
|
|
8
|
-
AbstractModule, LoggerModuleStatusReporter,
|
|
9
|
-
MemoryArchivist, MemorySentinel, ModuleFactoryLocator,
|
|
10
|
-
} from '@xyo-network/sdk-js'
|
|
11
|
-
import type { BaseConfigContext } from '@xyo-network/xl1-sdk'
|
|
12
|
-
import { hasMongoConfig } from '@xyo-network/xl1-sdk'
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Used for retrieving a locator with the necessary modules registered for testing
|
|
16
|
-
* operation of the node (entirely in memory)
|
|
17
|
-
* @returns A locator with the necessary modules registered
|
|
18
|
-
*/
|
|
19
|
-
export const getLocator = async (
|
|
20
|
-
{ logger, config }: BaseConfigContext,
|
|
21
|
-
) => {
|
|
22
|
-
const { otlpEndpoint } = config.telemetry?.otel ?? {}
|
|
23
|
-
const { path: endpoint = '/metrics', port: port = 9465 } = config.telemetry?.metrics?.scrape ?? {}
|
|
24
|
-
const { traceProvider, meterProvider } = await initTelemetry({
|
|
25
|
-
attributes: {
|
|
26
|
-
serviceName: 'xl1-api',
|
|
27
|
-
serviceVersion: '1.0.0',
|
|
28
|
-
},
|
|
29
|
-
otlpEndpoint,
|
|
30
|
-
metricsConfig: { endpoint, port },
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
if (isDefined(logger)) AbstractModule.defaultLogger = logger
|
|
34
|
-
const statusReporter = logger ? new LoggerModuleStatusReporter(logger) : undefined
|
|
35
|
-
|
|
36
|
-
const locator = new ModuleFactoryLocator()
|
|
37
|
-
// If there's a MongoDB configuration
|
|
38
|
-
const mongoConfig = config.storage?.mongo
|
|
39
|
-
if (hasMongoConfig(mongoConfig)) {
|
|
40
|
-
// Create the MongoDB SDK from the configuration
|
|
41
|
-
const {
|
|
42
|
-
connectionString: dbConnectionString, database: dbName, domain: dbDomain, password: dbPassword, username: dbUserName,
|
|
43
|
-
} = mongoConfig
|
|
44
|
-
const payloadSdkConfig: BaseMongoSdkPrivateConfig = {
|
|
45
|
-
dbConnectionString, dbDomain, dbName, dbPassword, dbUserName,
|
|
46
|
-
}
|
|
47
|
-
const params: Partial<MongoDBModuleParamsV2> = {
|
|
48
|
-
meterProvider, payloadSdkConfig, statusReporter, traceProvider,
|
|
49
|
-
}
|
|
50
|
-
// Register the MongoDB Archivist as the default
|
|
51
|
-
locator.register(MongoDBArchivistV2.factory(params), undefined, true)
|
|
52
|
-
locator.register(MongoDBArchivistV2Deletable.factory(params), { 'network.xyo.storage.capabilities.delete': 'enabled' }, false)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
locator.register(MemoryArchivist.factory({
|
|
56
|
-
traceProvider, meterProvider, statusReporter,
|
|
57
|
-
}))
|
|
58
|
-
locator.register(MemorySentinel.factory({
|
|
59
|
-
traceProvider, meterProvider, statusReporter,
|
|
60
|
-
}))
|
|
61
|
-
locator.register(ViewArchivist.factory({
|
|
62
|
-
traceProvider, meterProvider, statusReporter,
|
|
63
|
-
}))
|
|
64
|
-
return locator
|
|
65
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ManifestWrapper } from '@xyo-network/sdk-js'
|
|
2
|
-
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
3
|
-
import type { BaseConfigContext } from '@xyo-network/xl1-sdk'
|
|
4
|
-
|
|
5
|
-
import { getLocator } from './getLocator.ts'
|
|
6
|
-
import { NodeManifest } from './nodeManifest.ts'
|
|
7
|
-
import { PrivateChildManifests } from './private/index.ts'
|
|
8
|
-
import { PublicChildManifests } from './public/index.ts'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Creates a node with the xyo-chain modules registered
|
|
12
|
-
* @returns A node with the xyo-chain modules registered
|
|
13
|
-
*/
|
|
14
|
-
export const loadNode = async (
|
|
15
|
-
context: BaseConfigContext,
|
|
16
|
-
wallet: WalletInstance,
|
|
17
|
-
) => {
|
|
18
|
-
const locator = await getLocator(context)
|
|
19
|
-
const wrapper = new ManifestWrapper(NodeManifest, wallet, locator, PublicChildManifests, PrivateChildManifests)
|
|
20
|
-
const [node, ...childNodes] = await wrapper.loadNodes()
|
|
21
|
-
if (childNodes?.length > 0) {
|
|
22
|
-
await Promise.all(childNodes.map(childNode => node.register(childNode)))
|
|
23
|
-
await Promise.all(childNodes.map(childNode => node.attach(childNode.address, true)))
|
|
24
|
-
}
|
|
25
|
-
return node
|
|
26
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/schema.json",
|
|
3
|
-
"nodes": [
|
|
4
|
-
{
|
|
5
|
-
"config": {
|
|
6
|
-
"accountPath": "44'/60'/1",
|
|
7
|
-
"name": "XYOChain",
|
|
8
|
-
"schema": "network.xyo.node.config"
|
|
9
|
-
},
|
|
10
|
-
"modules": {
|
|
11
|
-
"private": [],
|
|
12
|
-
"public": []
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
],
|
|
16
|
-
"schema": "network.xyo.manifest"
|
|
17
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/schema.json",
|
|
3
|
-
"nodes": [
|
|
4
|
-
{
|
|
5
|
-
"config": {
|
|
6
|
-
"accountPath": "1",
|
|
7
|
-
"name": "Chain",
|
|
8
|
-
"schema": "network.xyo.node.config"
|
|
9
|
-
},
|
|
10
|
-
"modules": {
|
|
11
|
-
"private": [
|
|
12
|
-
{
|
|
13
|
-
"config": {
|
|
14
|
-
"accountPath": "1/1'/1'",
|
|
15
|
-
"name": "Validated",
|
|
16
|
-
"getCache": {
|
|
17
|
-
"enabled": true,
|
|
18
|
-
"maxEntries": 5000
|
|
19
|
-
},
|
|
20
|
-
"payloadSdkConfig": {
|
|
21
|
-
"collection": "chain_validated"
|
|
22
|
-
},
|
|
23
|
-
"schema": "network.xyo.archivist.config"
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
|
-
"public": [
|
|
28
|
-
{
|
|
29
|
-
"config": {
|
|
30
|
-
"accountPath": "1/1/1",
|
|
31
|
-
"name": "Finalized",
|
|
32
|
-
"allowedQueries": [
|
|
33
|
-
"network.xyo.query.archivist.get",
|
|
34
|
-
"network.xyo.query.archivist.next"
|
|
35
|
-
],
|
|
36
|
-
"getCache": {
|
|
37
|
-
"enabled": true,
|
|
38
|
-
"maxEntries": 50000
|
|
39
|
-
},
|
|
40
|
-
"originArchivist": "Validated",
|
|
41
|
-
"schema": "network.xyo.archivist.view.config"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
],
|
|
48
|
-
"schema": "network.xyo.manifest"
|
|
49
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/schema.json",
|
|
3
|
-
"nodes": [
|
|
4
|
-
{
|
|
5
|
-
"config": {
|
|
6
|
-
"accountPath": "2",
|
|
7
|
-
"name": "Pending",
|
|
8
|
-
"schema": "network.xyo.node.config"
|
|
9
|
-
},
|
|
10
|
-
"modules": {
|
|
11
|
-
"private": [],
|
|
12
|
-
"public": [
|
|
13
|
-
{
|
|
14
|
-
"config": {
|
|
15
|
-
"accountPath": "2/1/1",
|
|
16
|
-
"name": "Transactions",
|
|
17
|
-
"getCache": {
|
|
18
|
-
"enabled": true,
|
|
19
|
-
"maxEntries": 5000
|
|
20
|
-
},
|
|
21
|
-
"labels": {
|
|
22
|
-
"network.xyo.storage.capabilities.delete": "enabled",
|
|
23
|
-
"network.xyo.storage.class": "mongodb"
|
|
24
|
-
},
|
|
25
|
-
"payloadSdkConfig": {
|
|
26
|
-
"collection": "pending_transaction_bundles"
|
|
27
|
-
},
|
|
28
|
-
"schema": "network.xyo.archivist.config"
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"config": {
|
|
33
|
-
"accountPath": "2/1/2",
|
|
34
|
-
"name": "Blocks",
|
|
35
|
-
"getCache": {
|
|
36
|
-
"enabled": true,
|
|
37
|
-
"maxEntries": 5000
|
|
38
|
-
},
|
|
39
|
-
"labels": {
|
|
40
|
-
"network.xyo.storage.capabilities.delete": "enabled",
|
|
41
|
-
"network.xyo.storage.class": "mongodb"
|
|
42
|
-
},
|
|
43
|
-
"payloadSdkConfig": {
|
|
44
|
-
"collection": "pending_block_bundles"
|
|
45
|
-
},
|
|
46
|
-
"schema": "network.xyo.archivist.config"
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
],
|
|
53
|
-
"schema": "network.xyo.manifest"
|
|
54
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ModuleManifest, PackageManifestPayload } from '@xyo-network/sdk-js'
|
|
2
|
-
|
|
3
|
-
import Chain from './Chain.json' with { type: 'json' }
|
|
4
|
-
import Pending from './Pending.json' with { type: 'json' }
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Chain Node Manifest
|
|
8
|
-
*/
|
|
9
|
-
const ChainNodeManifest = Chain as unknown as PackageManifestPayload
|
|
10
|
-
/**
|
|
11
|
-
* Pending Node Manifest
|
|
12
|
-
*/
|
|
13
|
-
const PendingNodeManifest = Pending as unknown as PackageManifestPayload
|
|
14
|
-
/**
|
|
15
|
-
* Public Child Manifests
|
|
16
|
-
*/
|
|
17
|
-
export const PublicChildManifests: ModuleManifest[] = [
|
|
18
|
-
...ChainNodeManifest.nodes,
|
|
19
|
-
...PendingNodeManifest.nodes,
|
|
20
|
-
]
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
customPoweredByHeader,
|
|
3
|
-
disableCaseSensitiveRouting,
|
|
4
|
-
disableExpressDefaultPoweredByHeader,
|
|
5
|
-
getJsonBodyParser,
|
|
6
|
-
getJsonBodyParserOptions,
|
|
7
|
-
responseProfiler,
|
|
8
|
-
standardResponses,
|
|
9
|
-
} from '@xylabs/express'
|
|
10
|
-
import compression from 'compression'
|
|
11
|
-
import cors from 'cors'
|
|
12
|
-
import type { Express } from 'express'
|
|
13
|
-
|
|
14
|
-
export function sharedMiddleware(app: Express): void {
|
|
15
|
-
app.set('etag', false)
|
|
16
|
-
app.use(cors())
|
|
17
|
-
app.use(compression())
|
|
18
|
-
app.use(responseProfiler)
|
|
19
|
-
app.use(getJsonBodyParser(getJsonBodyParserOptions({ limit: '1mb' })))
|
|
20
|
-
app.use(standardResponses)
|
|
21
|
-
disableExpressDefaultPoweredByHeader(app)
|
|
22
|
-
app.use(customPoweredByHeader)
|
|
23
|
-
disableCaseSensitiveRouting(app)
|
|
24
|
-
}
|