@xyo-network/chain-api 1.15.27 → 1.16.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.
Files changed (37) hide show
  1. package/dist/node/index.mjs +258 -77
  2. package/dist/node/index.mjs.map +1 -1
  3. package/dist/node/manifest/getLocator.d.ts +3 -1
  4. package/dist/node/manifest/getLocator.d.ts.map +1 -1
  5. package/dist/node/manifest/getNode.d.ts.map +1 -1
  6. package/dist/node/manifest/public/WithMempool/index.d.ts +6 -0
  7. package/dist/node/manifest/public/WithMempool/index.d.ts.map +1 -0
  8. package/dist/node/manifest/public/WithoutMempool/index.d.ts +6 -0
  9. package/dist/node/manifest/public/WithoutMempool/index.d.ts.map +1 -0
  10. package/dist/node/manifest/public/index.d.ts +2 -13
  11. package/dist/node/manifest/public/index.d.ts.map +1 -1
  12. package/dist/node/server/app.d.ts +3 -2
  13. package/dist/node/server/app.d.ts.map +1 -1
  14. package/dist/node/server/routes/addRoutes.d.ts +3 -2
  15. package/dist/node/server/routes/addRoutes.d.ts.map +1 -1
  16. package/dist/node/server/routes/address/get/get.d.ts.map +1 -1
  17. package/dist/node/server/routes/rpc/routes/addRpcRoutes.d.ts +3 -2
  18. package/dist/node/server/routes/rpc/routes/addRpcRoutes.d.ts.map +1 -1
  19. package/dist/node/server/server.d.ts.map +1 -1
  20. package/package.json +52 -52
  21. package/src/manifest/getLocator.ts +20 -7
  22. package/src/manifest/getNode.ts +4 -2
  23. package/src/manifest/public/{Chain.json → WithMempool/Chain.json} +1 -1
  24. package/src/manifest/public/{Pending.json → WithMempool/Pending.json} +1 -1
  25. package/src/manifest/public/WithMempool/index.ts +20 -0
  26. package/src/manifest/public/WithoutMempool/Chain.json +97 -0
  27. package/src/manifest/public/WithoutMempool/Pending.json +35 -0
  28. package/src/manifest/public/WithoutMempool/index.ts +20 -0
  29. package/src/manifest/public/index.ts +2 -20
  30. package/src/server/app.ts +6 -3
  31. package/src/server/routes/addRoutes.ts +11 -3
  32. package/src/server/routes/address/get/get.ts +8 -10
  33. package/src/server/routes/rpc/routes/addRpcRoutes.ts +41 -7
  34. package/src/server/server.ts +10 -6
  35. package/dist/node/manifest/public/spec/Node.spec.d.ts +0 -2
  36. package/dist/node/manifest/public/spec/Node.spec.d.ts.map +0 -1
  37. package/src/manifest/public/spec/Node.spec.ts +0 -32
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/chain-api",
3
- "version": "1.15.27",
3
+ "version": "1.16.0",
4
4
  "description": "XYO Layer One API",
5
5
  "homepage": "https://xylabs.com",
6
6
  "bugs": {
@@ -46,42 +46,42 @@
46
46
  "types": "tsc --noEmit -p tsconfig.test.json"
47
47
  },
48
48
  "dependencies": {
49
- "@opentelemetry/instrumentation": "~0.207.0",
50
- "@opentelemetry/instrumentation-express": "~0.56.0",
51
- "@opentelemetry/instrumentation-http": "~0.207.0",
52
- "@xylabs/assert": "~5.0.17",
53
- "@xylabs/creatable": "~5.0.17",
54
- "@xylabs/express": "~5.0.17",
55
- "@xylabs/hex": "~5.0.17",
56
- "@xylabs/logger": "~5.0.17",
57
- "@xylabs/mongo": "~5.0.17",
58
- "@xylabs/typeof": "~5.0.17",
59
- "@xyo-network/archivist-memory": "~5.1.15",
60
- "@xyo-network/archivist-model": "~5.1.15",
61
- "@xyo-network/archivist-mongodb": "~5.1.15",
62
- "@xyo-network/archivist-view": "~5.1.15",
49
+ "@opentelemetry/instrumentation": "~0.208.0",
50
+ "@opentelemetry/instrumentation-express": "~0.57.0",
51
+ "@opentelemetry/instrumentation-http": "~0.208.0",
52
+ "@xylabs/assert": "~5.0.19",
53
+ "@xylabs/creatable": "~5.0.19",
54
+ "@xylabs/express": "~5.0.19",
55
+ "@xylabs/hex": "~5.0.19",
56
+ "@xylabs/logger": "~5.0.19",
57
+ "@xylabs/mongo": "~5.0.19",
58
+ "@xylabs/typeof": "~5.0.19",
59
+ "@xyo-network/archivist-memory": "~5.1.18",
60
+ "@xyo-network/archivist-model": "~5.1.18",
61
+ "@xyo-network/archivist-mongodb": "~5.1.18",
62
+ "@xyo-network/archivist-view": "~5.1.18",
63
63
  "@xyo-network/bios": "~7.1.1",
64
- "@xyo-network/boundwitness-model": "~5.1.15",
65
- "@xyo-network/chain-ethereum": "~1.15.27",
66
- "@xyo-network/chain-modules": "~1.15.27",
67
- "@xyo-network/chain-protocol": "~1.15.27",
68
- "@xyo-network/chain-rpc": "~1.15.27",
69
- "@xyo-network/chain-telemetry": "~1.15.27",
70
- "@xyo-network/manifest-model": "~5.1.15",
71
- "@xyo-network/manifest-wrapper": "~5.1.15",
72
- "@xyo-network/module-abstract": "~5.1.15",
73
- "@xyo-network/module-factory-locator": "~5.1.15",
74
- "@xyo-network/module-model": "~5.1.15",
75
- "@xyo-network/node-model": "~5.1.15",
76
- "@xyo-network/payload-builder": "~5.1.15",
77
- "@xyo-network/payload-model": "~5.1.15",
78
- "@xyo-network/sentinel-memory": "~5.1.15",
64
+ "@xyo-network/boundwitness-model": "~5.1.18",
65
+ "@xyo-network/chain-ethereum": "~1.16.0",
66
+ "@xyo-network/chain-modules": "~1.16.0",
67
+ "@xyo-network/chain-protocol": "~1.16.0",
68
+ "@xyo-network/chain-rpc": "~1.16.0",
69
+ "@xyo-network/chain-telemetry": "~1.16.0",
70
+ "@xyo-network/manifest-model": "~5.1.18",
71
+ "@xyo-network/manifest-wrapper": "~5.1.18",
72
+ "@xyo-network/module-abstract": "~5.1.18",
73
+ "@xyo-network/module-factory-locator": "~5.1.18",
74
+ "@xyo-network/module-model": "~5.1.18",
75
+ "@xyo-network/node-model": "~5.1.18",
76
+ "@xyo-network/payload-builder": "~5.1.18",
77
+ "@xyo-network/payload-model": "~5.1.18",
78
+ "@xyo-network/sentinel-memory": "~5.1.18",
79
79
  "@xyo-network/typechain": "~4.0.10",
80
- "@xyo-network/wallet": "~5.1.15",
81
- "@xyo-network/wallet-model": "~5.1.15",
82
- "@xyo-network/xl1-protocol": "~1.12.95",
83
- "@xyo-network/xl1-protocol-sdk": "~1.15.27",
84
- "@xyo-network/xl1-rpc": "~1.15.27",
80
+ "@xyo-network/wallet": "~5.1.18",
81
+ "@xyo-network/wallet-model": "~5.1.18",
82
+ "@xyo-network/xl1-protocol": "~1.13.0",
83
+ "@xyo-network/xl1-protocol-sdk": "~1.16.0",
84
+ "@xyo-network/xl1-rpc": "~1.16.0",
85
85
  "async-mutex": "~0.5.0",
86
86
  "compression": "~1.8.1",
87
87
  "cors": "~2.8.5",
@@ -89,34 +89,34 @@
89
89
  "express": "~5.1.0",
90
90
  "http-status-codes": "~2.3.0",
91
91
  "lru-cache": "~11.2.2",
92
- "mongodb": "~6.20.0"
92
+ "mongodb": "~7.0.0"
93
93
  },
94
94
  "devDependencies": {
95
95
  "@types/compression": "~1.8.1",
96
96
  "@types/cors": "~2.8.19",
97
97
  "@types/express": "5.0.5",
98
98
  "@types/express-serve-static-core": "~5.1.0",
99
- "@types/node": "~24.9.2",
100
- "@xylabs/base": "~5.0.17",
101
- "@xylabs/object": "~5.0.17",
102
- "@xylabs/promise": "~5.0.17",
103
- "@xylabs/ts-scripts-yarn3": "~7.1.8",
104
- "@xylabs/tsconfig": "~7.1.8",
105
- "@xyo-network/account": "~5.1.15",
106
- "@xyo-network/account-model": "~5.1.15",
107
- "@xyo-network/archivist-abstract": "~5.1.15",
99
+ "@types/node": "~24.10.0",
100
+ "@xylabs/base": "~5.0.19",
101
+ "@xylabs/object": "~5.0.19",
102
+ "@xylabs/promise": "~5.0.19",
103
+ "@xylabs/ts-scripts-yarn3": "~7.2.4",
104
+ "@xylabs/tsconfig": "~7.2.4",
105
+ "@xyo-network/account": "~5.1.18",
106
+ "@xyo-network/account-model": "~5.1.18",
107
+ "@xyo-network/archivist-abstract": "~5.1.18",
108
108
  "@xyo-network/bios-model": "~7.1.1",
109
- "@xyo-network/boundwitness-builder": "~5.1.15",
110
- "@xyo-network/module-abstract-mongodb": "~5.1.15",
111
- "@xyo-network/module-model-mongodb": "~5.1.15",
112
- "@xyo-network/node-memory": "~5.1.15",
113
- "@xyo-network/xl1-protocol": "~1.12.95",
109
+ "@xyo-network/boundwitness-builder": "~5.1.18",
110
+ "@xyo-network/module-abstract-mongodb": "~5.1.18",
111
+ "@xyo-network/module-model-mongodb": "~5.1.18",
112
+ "@xyo-network/node-memory": "~5.1.18",
113
+ "@xyo-network/xl1-protocol": "~1.13.0",
114
114
  "dotenv": "~17.2.3",
115
- "eslint": "^9.39.0",
115
+ "eslint": "^9.39.1",
116
116
  "nodemon": "~3.1.10",
117
117
  "tslib": "~2.8.1",
118
118
  "typescript": "~5.9.3",
119
- "vitest": "~3.2.4",
119
+ "vitest": "~4.0.8",
120
120
  "vitest-mock-extended": "~3.1.0"
121
121
  },
122
122
  "engines": {
@@ -30,6 +30,25 @@ export interface GetLocatorContext {
30
30
  logger?: Logger
31
31
  }
32
32
 
33
+ export async function getTransferSummaryMap(config: Config): Promise<Promise<MapType<string, WithStorageMeta<TransfersStepSummary>> | undefined>> {
34
+ const mongoConfig = config.storage?.mongo
35
+ if (hasMongoConfig(mongoConfig)) {
36
+ // Create the MongoDB SDK from the configuration
37
+ const {
38
+ connectionString: dbConnectionString, database: dbName, domain: dbDomain, password: dbPassword, username: dbUserName,
39
+ } = mongoConfig
40
+ const payloadSdkConfig: BaseMongoSdkPrivateConfig = {
41
+ dbConnectionString, dbDomain, dbName, dbPassword, dbUserName,
42
+ }
43
+
44
+ const sdkTransferSummaryMap = new BaseMongoSdk<WithStorageMeta<TransfersStepSummary>>({ ...payloadSdkConfig, collection: 'transfer_summary_map' })
45
+ return await MongoMap.create<MongoMap<Hash, WithStorageMeta<TransfersStepSummary>>>({
46
+ sdk: sdkTransferSummaryMap,
47
+ getCache: { enabled: true, maxEntries: 5000 },
48
+ })
49
+ }
50
+ }
51
+
33
52
  /**
34
53
  * Used for retrieving a locator with the necessary modules registered for testing
35
54
  * operation of the node (entirely in memory)
@@ -55,7 +74,7 @@ export const getLocator = async (context: GetLocatorContext) => {
55
74
 
56
75
  const locator = new ModuleFactoryLocator()
57
76
  let balanceSummaryMap: MapType<string, WithStorageMeta<BalancesStepSummary>> | undefined
58
- let transferSummaryMap: MapType<string, WithStorageMeta<TransfersStepSummary>> | undefined
77
+ let transferSummaryMap = await getTransferSummaryMap(config)
59
78
  // If there's a MongoDB configuration
60
79
  const mongoConfig = config.storage?.mongo
61
80
  if (hasMongoConfig(mongoConfig)) {
@@ -78,12 +97,6 @@ export const getLocator = async (context: GetLocatorContext) => {
78
97
  sdk: sdkBalanceSummaryMap,
79
98
  getCache: { enabled: true, maxEntries: 5000 },
80
99
  })
81
-
82
- const sdkTransferSummaryMap = new BaseMongoSdk<WithStorageMeta<TransfersStepSummary>>({ ...payloadSdkConfig, collection: 'transfer_summary_map' })
83
- transferSummaryMap = await MongoMap.create<MongoMap<Hash, WithStorageMeta<TransfersStepSummary>>>({
84
- sdk: sdkTransferSummaryMap,
85
- getCache: { enabled: true, maxEntries: 5000 },
86
- })
87
100
  }
88
101
 
89
102
  locator.register(AddressBalanceDivinerV2.factory<AddressBalanceDivinerV2>({
@@ -6,7 +6,7 @@ import type { Config } from '@xyo-network/xl1-protocol-sdk'
6
6
  import { getLocator } from './getLocator.ts'
7
7
  import { NodeManifest } from './nodeManifest.ts'
8
8
  import { PrivateChildManifests } from './private/index.ts'
9
- import { PublicChildManifests } from './public/index.ts'
9
+ import { PublicChildManifestsWithMempool, PublicChildManifestsWithoutMempool } from './public/index.ts'
10
10
 
11
11
  export interface GetNodeContext {
12
12
  config: Config
@@ -20,7 +20,9 @@ export interface GetNodeContext {
20
20
  * @returns A node with the xyo-chain modules registered
21
21
  */
22
22
  export const getNode = async (context: GetNodeContext) => {
23
- const { wallet } = context
23
+ const { wallet, config } = context
24
+ const { enabled: mempoolEnabled } = config.mempool
25
+ const PublicChildManifests = mempoolEnabled ? PublicChildManifestsWithoutMempool : PublicChildManifestsWithMempool
24
26
  const locator = await getLocator(context)
25
27
  const wrapper = new ManifestWrapper(NodeManifest, wallet, locator, PublicChildManifests, PrivateChildManifests)
26
28
  const [node, ...childNodes] = await wrapper.loadNodes()
@@ -172,4 +172,4 @@
172
172
  }
173
173
  ],
174
174
  "schema": "network.xyo.manifest"
175
- }
175
+ }
@@ -12,7 +12,7 @@
12
12
  "public": [
13
13
  {
14
14
  "config": {
15
- "accountPath": "2/1/2",
15
+ "accountPath": "2/1/1",
16
16
  "name": "PendingTransactions",
17
17
  "getCache": {
18
18
  "enabled": true,
@@ -0,0 +1,20 @@
1
+ import type { ModuleManifest, PackageManifestPayload } from '@xyo-network/manifest-model'
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 PackageManifestPayload
10
+ /**
11
+ * Pending Node Manifest
12
+ */
13
+ const PendingNodeManifest = Pending as PackageManifestPayload
14
+ /**
15
+ * Public Child Manifests
16
+ */
17
+ export const PublicChildManifestsWithMempool: ModuleManifest[] = [
18
+ ...ChainNodeManifest.nodes,
19
+ ...PendingNodeManifest.nodes,
20
+ ]
@@ -0,0 +1,97 @@
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
+ "allowedQueries": [
17
+ "network.xyo.query.archivist.get",
18
+ "network.xyo.query.archivist.next"
19
+ ],
20
+ "getCache": {
21
+ "enabled": true,
22
+ "maxEntries": 5000
23
+ },
24
+ "payloadSdkConfig": {
25
+ "collection": "chain_validated"
26
+ },
27
+ "schema": "network.xyo.archivist.config"
28
+ }
29
+ }
30
+ ],
31
+ "public": [
32
+ {
33
+ "config": {
34
+ "accountPath": "1/1/1",
35
+ "name": "Submissions",
36
+ "getCache": {
37
+ "enabled": true,
38
+ "maxEntries": 5000
39
+ },
40
+ "payloadSdkConfig": {
41
+ "collection": "chain_submissions"
42
+ },
43
+ "schema": "network.xyo.archivist.config"
44
+ }
45
+ },
46
+ {
47
+ "config": {
48
+ "accountPath": "1/1/2",
49
+ "name": "Finalized",
50
+ "allowedQueries": [
51
+ "network.xyo.query.archivist.get",
52
+ "network.xyo.query.archivist.next"
53
+ ],
54
+ "getCache": {
55
+ "enabled": true,
56
+ "maxEntries": 50000
57
+ },
58
+ "originArchivist": "Validated",
59
+ "schema": "network.xyo.archivist.view.config"
60
+ }
61
+ },
62
+ {
63
+ "config": {
64
+ "accountPath": "1/1/3'",
65
+ "name": "AddressBalanceDiviner",
66
+ "schema": "network.xyo.diviner.chain.address.balance.config",
67
+ "map": {
68
+ "lmdb": {
69
+ "dbName": "summaries",
70
+ "storeName": "address_balance",
71
+ "location": ".store"
72
+ }
73
+ },
74
+ "archivist": "Validated"
75
+ }
76
+ },
77
+ {
78
+ "config": {
79
+ "accountPath": "1/1/4'",
80
+ "name": "AddressTransferDiviner",
81
+ "schema": "network.xyo.diviner.chain.address.transfer.config",
82
+ "map": {
83
+ "lmdb": {
84
+ "dbName": "summaries",
85
+ "storeName": "address_transfer",
86
+ "location": ".store"
87
+ }
88
+ },
89
+ "archivist": "Validated"
90
+ }
91
+ }
92
+ ]
93
+ }
94
+ }
95
+ ],
96
+ "schema": "network.xyo.manifest"
97
+ }
@@ -0,0 +1,35 @@
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": "PendingTransactions",
17
+ "getCache": {
18
+ "enabled": true,
19
+ "maxEntries": 5000
20
+ },
21
+ "labels": {
22
+ "network.xyo.storage.class": "mongodb"
23
+ },
24
+ "payloadSdkConfig": {
25
+ "collection": "pending_bundles"
26
+ },
27
+ "schema": "network.xyo.archivist.config"
28
+ }
29
+ }
30
+ ]
31
+ }
32
+ }
33
+ ],
34
+ "schema": "network.xyo.manifest"
35
+ }
@@ -0,0 +1,20 @@
1
+ import type { ModuleManifest, PackageManifestPayload } from '@xyo-network/manifest-model'
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 PackageManifestPayload
10
+ /**
11
+ * Pending Node Manifest
12
+ */
13
+ const PendingNodeManifest = Pending as PackageManifestPayload
14
+ /**
15
+ * Public Child Manifests
16
+ */
17
+ export const PublicChildManifestsWithoutMempool: ModuleManifest[] = [
18
+ ...ChainNodeManifest.nodes,
19
+ ...PendingNodeManifest.nodes,
20
+ ]
@@ -1,20 +1,2 @@
1
- import type { ModuleManifest, PackageManifestPayload } from '@xyo-network/manifest-model'
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
- export const ChainNodeManifest = Chain as PackageManifestPayload
10
- /**
11
- * Pending Node Manifest
12
- */
13
- export const PendingNodeManifest = Pending as PackageManifestPayload
14
- /**
15
- * Public Child Manifests
16
- */
17
- export const PublicChildManifests: ModuleManifest[] = [
18
- ...ChainNodeManifest.nodes,
19
- ...PendingNodeManifest.nodes,
20
- ]
1
+ export * from './WithMempool/index.ts'
2
+ export * from './WithoutMempool/index.ts'
package/src/server/app.ts CHANGED
@@ -9,7 +9,10 @@ import {
9
9
  standardResponses,
10
10
  } from '@xylabs/express'
11
11
  import type { NodeInstance } from '@xyo-network/node-model'
12
- import type { StakedChainContextRead, StakeEventsRead } from '@xyo-network/xl1-protocol-sdk'
12
+ import type { WithStorageMeta } from '@xyo-network/payload-model'
13
+ import type {
14
+ MapType, StakedChainContextRead, TransfersStepSummary,
15
+ } from '@xyo-network/xl1-protocol-sdk'
13
16
  import compression from 'compression'
14
17
  import cors from 'cors'
15
18
  import type { Express } from 'express'
@@ -20,7 +23,7 @@ import { addRoutes } from './routes/index.ts'
20
23
 
21
24
  export const getApp = async (
22
25
  node: NodeInstance,
23
- eventsReader: StakeEventsRead,
26
+ transferSummaryMap: MapType<string, WithStorageMeta<TransfersStepSummary>>,
24
27
  stakedChainContext: StakedChainContextRead,
25
28
  initRewardsCache?: boolean,
26
29
  ): Promise<Express> => {
@@ -37,7 +40,7 @@ export const getApp = async (
37
40
  app.use(customPoweredByHeader)
38
41
  disableCaseSensitiveRouting(app)
39
42
  app.node = node
40
- await addRoutes(app, eventsReader, stakedChainContext, initRewardsCache)
43
+ await addRoutes(app, transferSummaryMap, stakedChainContext, initRewardsCache)
41
44
  app.use(standardErrors)
42
45
  return app
43
46
  }
@@ -1,12 +1,20 @@
1
- import type { StakedChainContextRead, StakeEventsRead } from '@xyo-network/xl1-protocol-sdk'
1
+ import type { WithStorageMeta } from '@xyo-network/payload-model'
2
+ import type {
3
+ MapType, StakedChainContextRead, TransfersStepSummary,
4
+ } from '@xyo-network/xl1-protocol-sdk'
2
5
  import type { Express } from 'express'
3
6
 
4
7
  import { addNodeRoutes } from './address/index.ts'
5
8
  import { addDataLakeRoutes } from './dataLake/index.ts'
6
9
  import { addRpcRoutes } from './rpc/index.ts'
7
10
 
8
- export const addRoutes = async (app: Express, eventsReader: StakeEventsRead, stakedChainContext: StakedChainContextRead, initRewardsCache?: boolean) => {
9
- await addRpcRoutes(app, eventsReader, stakedChainContext, initRewardsCache)
11
+ export const addRoutes = async (
12
+ app: Express,
13
+ transferSummaryMap: MapType<string, WithStorageMeta<TransfersStepSummary>>,
14
+ stakedChainContext: StakedChainContextRead,
15
+ initRewardsCache?: boolean,
16
+ ) => {
17
+ await addRpcRoutes(app, transferSummaryMap, stakedChainContext, initRewardsCache)
10
18
  addDataLakeRoutes(app)
11
19
  addNodeRoutes(app)
12
20
  }
@@ -1,7 +1,7 @@
1
- import { assertEx } from '@xylabs/assert'
2
1
  import { asyncHandler } from '@xylabs/express'
3
- import { asAddress, toAddress } from '@xylabs/hex'
4
- import { isModuleIdentifierPart } from '@xyo-network/module-model'
2
+ import { asAddress } from '@xylabs/hex'
3
+ import { isDefined } from '@xylabs/typeof'
4
+ import { isModuleName } from '@xyo-network/module-model'
5
5
  import type { Payload } from '@xyo-network/payload-model'
6
6
  import type { RequestHandler } from 'express'
7
7
  import { StatusCodes } from 'http-status-codes'
@@ -9,22 +9,20 @@ import { StatusCodes } from 'http-status-codes'
9
9
  import type { AddressPathParams } from '../AddressPathParams.ts'
10
10
 
11
11
  const handler: RequestHandler<AddressPathParams, Payload[]> = async (req, res, next) => {
12
- const { address: rawAddress } = req.params
12
+ const { address: moduleIdentifier } = req.params
13
13
  const { node } = req.app
14
- const address = asAddress(rawAddress)
15
- if (address !== undefined) {
14
+ const address = asAddress(moduleIdentifier)
15
+ if (isDefined(address)) {
16
16
  let mod = node.address === address ? node : (await node.resolve(address, { direction: 'down' }))
17
17
  if (mod) {
18
18
  res.json(await mod.state())
19
19
  return
20
20
  }
21
21
  }
22
- if (isModuleIdentifierPart(rawAddress)) {
23
- const moduleIdentifier = toAddress(rawAddress)
22
+ if (isModuleName(moduleIdentifier)) {
24
23
  const mod = await node.resolve(moduleIdentifier, { direction: 'down' })
25
24
  if (mod) {
26
- const moduleAddress = assertEx(mod?.address, () => 'Error redirecting to module by address')
27
- res.redirect(StatusCodes.MOVED_TEMPORARILY, `/${moduleAddress}`)
25
+ res.redirect(StatusCodes.MOVED_TEMPORARILY, `/${mod.address}`)
28
26
  return
29
27
  }
30
28
  }
@@ -1,25 +1,59 @@
1
1
  import { setRawResponseFormat } from '@xylabs/express'
2
- import { NodeXyoViewer } from '@xyo-network/chain-rpc'
3
2
  import {
4
- RewardMultipliers, type StakedChainContextRead, type StakeEventsRead,
3
+ NodeNetworkStakeViewer, NodeStepRewardsByPositionViewer, NodeXyoViewer,
4
+ } from '@xyo-network/chain-rpc'
5
+ import type { WithStorageMeta } from '@xyo-network/payload-model'
6
+ import { StepSizes } from '@xyo-network/xl1-protocol'
7
+ import type {
8
+ MapType, StakedChainContextRead, TransfersStepSummary,
5
9
  } from '@xyo-network/xl1-protocol-sdk'
10
+ import { RewardMultipliers } from '@xyo-network/xl1-protocol-sdk'
6
11
  import {
7
12
  NodeXyoRunner, rpcEngineFromConnection,
8
13
  XyoBaseConnection,
9
14
  } from '@xyo-network/xl1-rpc'
15
+ import { Semaphore } from 'async-mutex'
10
16
  import type { Express } from 'express'
11
17
 
12
- export const addRpcRoutes = async (app: Express, eventReader: StakeEventsRead, stakedChainContext: StakedChainContextRead, initRewardsCache?: boolean) => {
18
+ export const addRpcRoutes = async (
19
+ app: Express,
20
+ transferSummaryMap: MapType<string, WithStorageMeta<TransfersStepSummary>>,
21
+ stakedChainContext: StakedChainContextRead,
22
+ initRewardsCache?: boolean,
23
+ ) => {
13
24
  const { node } = app
14
25
  const runner = new NodeXyoRunner(node)
26
+ const networkStakeViewer = await NodeNetworkStakeViewer.create({ context: stakedChainContext })
27
+
28
+ console.log('Initializing NodeNetworkStakeViewer...')
29
+ await networkStakeViewer.start()
30
+ console.log('Initialized NodeNetworkStakeViewer.')
31
+
15
32
  const viewer = await NodeXyoViewer.create({
16
- node, eventReader, stakedChainContext, rewardMultipliers: RewardMultipliers, initRewardsCache,
33
+ node,
34
+ rewardMultipliers: RewardMultipliers,
35
+ initRewardsCache,
36
+ context: stakedChainContext,
37
+ transfersSummaryContext: {
38
+ ...stakedChainContext, stepSemaphores: StepSizes.map(() => new Semaphore(20)), summaryMap: transferSummaryMap,
39
+ },
17
40
  })
18
- console.log('Initializing Node viewer...')
41
+
42
+ console.log('Initializing NodeXyoViewer...')
19
43
  await viewer.start()
20
- console.log('Initialized Node viewer.')
44
+ console.log('Initialized NodeXyoViewer.')
45
+
46
+ const stepRewardsByPositionViewer = await NodeStepRewardsByPositionViewer.create({
47
+ context: stakedChainContext,
48
+ rewardMultipliers: RewardMultipliers,
49
+ })
50
+
51
+ console.log('Initializing NodeStepRewardsByPositionViewer...')
52
+ await stepRewardsByPositionViewer.start()
53
+ console.log('Initialized NodeStepRewardsByPositionViewer.')
54
+
21
55
  const connection = new XyoBaseConnection({ runner, viewer })
22
- const engine = rpcEngineFromConnection(connection)
56
+ const engine = rpcEngineFromConnection(connection, networkStakeViewer)
23
57
 
24
58
  app.post('/rpc', (req, res) => {
25
59
  setRawResponseFormat(res)
@@ -1,4 +1,5 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
+ import type { Hash } from '@xylabs/hex'
2
3
  import { toEthAddress } from '@xylabs/hex'
3
4
  import type { Logger } from '@xylabs/logger'
4
5
  import { isDefined, isString } from '@xylabs/typeof'
@@ -6,17 +7,19 @@ import { asArchivistInstance } from '@xyo-network/archivist-model'
6
7
  import { boot } from '@xyo-network/bios'
7
8
  import type { BiosExternalInterface } from '@xyo-network/bios-model'
8
9
  import { EthereumChainStake, EthereumChainStakeEvents } from '@xyo-network/chain-ethereum'
9
- import { findMostRecentBlock } from '@xyo-network/chain-protocol'
10
+ import { findMostRecentBlock, getLocalPersistentMap } from '@xyo-network/chain-protocol'
10
11
  import type { NodeInstance } from '@xyo-network/node-model'
11
12
  import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
12
13
  import { StakedXyoChainV2__factory } from '@xyo-network/typechain'
13
14
  import { HDWallet } from '@xyo-network/wallet'
14
15
  import type { ChainId } from '@xyo-network/xl1-protocol'
15
- import type { Config, StakedChainContextRead } from '@xyo-network/xl1-protocol-sdk'
16
+ import type {
17
+ Config, StakedChainContextRead, TransfersStepSummary,
18
+ } from '@xyo-network/xl1-protocol-sdk'
16
19
  import { readPayloadMapFromStore } from '@xyo-network/xl1-protocol-sdk'
17
20
 
18
21
  import { initInfuraProvider } from '../helpers/index.ts'
19
- import { getNode } from '../manifest/index.ts'
22
+ import { getNode, getTransferSummaryMap } from '../manifest/index.ts'
20
23
  import { getApp } from './app.ts'
21
24
 
22
25
  const hostname = '::'
@@ -83,16 +86,17 @@ export const getServer = async (context: GetServerContext) => {
83
86
  events: eventsReader,
84
87
  stake: stakeChainReader,
85
88
  store: { chainMap },
86
- head: async () => {
89
+ head: async (): Promise<[Hash, number]> => {
87
90
  const head = await findMostRecentBlock(chainArchivist)
88
- return assertEx(head?._hash, () => 'No head found in chainArchivist')
91
+ return [assertEx(head?._hash, () => 'No head found in chainArchivist'), assertEx(head?.block, () => 'No head found in chainArchivist')]
89
92
  },
90
93
  }
91
94
  const mods = await resolvedNode.resolve('*')
92
95
  await Promise.all(mods.map((mod) => {
93
96
  return mod.start?.() ?? (() => true)
94
97
  }))
95
- const app = await getApp(resolvedNode, eventsReader, stakedChainContext, config.api.initRewardsCache)
98
+ const transferSummaryMap = assertEx(await getTransferSummaryMap(config), () => 'Transfer Summary Map not initialized')
99
+ const app = await getApp(resolvedNode, transferSummaryMap, stakedChainContext, config.api.initRewardsCache)
96
100
  const server = app.listen(port, hostname, () => logger?.log(`[API] Server listening at http://${hostname}:${port}`))
97
101
  server.setTimeout(20_000)
98
102
  return server
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Node.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Node.spec.d.ts","sourceRoot":"","sources":["../../../../../src/manifest/public/spec/Node.spec.ts"],"names":[],"mappings":""}