@xyo-network/chain-bridge 1.17.7 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node/config/getGateway.d.ts +1 -1
- package/dist/node/config/getGateway.d.ts.map +1 -1
- package/dist/node/index.mjs +534 -108
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/interface/service/Observer/ERC20TransferObserver/ERC20TransferObserver.d.ts.map +1 -1
- package/dist/node/interface/service/Observer/LiquidityPoolBridgeObserver/LiquidityPoolBridgeObserver.d.ts.map +1 -1
- package/dist/node/interface/service/Relay/LiquidityPoolBridgeRelay/LiquidityPoolBridgeRelay.d.ts.map +1 -1
- package/dist/node/manifest/getServices.d.ts +13 -0
- package/dist/node/manifest/getServices.d.ts.map +1 -0
- package/dist/node/manifest/index.d.ts +1 -0
- package/dist/node/manifest/index.d.ts.map +1 -1
- package/dist/node/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.d.ts.map +1 -1
- package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.d.ts.map +1 -1
- package/dist/node/queue/connection.d.ts +4 -0
- package/dist/node/queue/connection.d.ts.map +1 -0
- package/dist/node/queue/flowProducer.d.ts +4 -0
- package/dist/node/queue/flowProducer.d.ts.map +1 -0
- package/dist/node/queue/flows/createXl1ToEthBridgeJob.d.ts +4 -0
- package/dist/node/queue/flows/createXl1ToEthBridgeJob.d.ts.map +1 -0
- package/dist/node/queue/flows/index.d.ts +2 -0
- package/dist/node/queue/flows/index.d.ts.map +1 -0
- package/dist/node/queue/index.d.ts +5 -0
- package/dist/node/queue/index.d.ts.map +1 -0
- package/dist/node/queue/workers/WorkerDescription.d.ts +7 -0
- package/dist/node/queue/workers/WorkerDescription.d.ts.map +1 -0
- package/dist/node/queue/workers/createWorkers.d.ts +3 -0
- package/dist/node/queue/workers/createWorkers.d.ts.map +1 -0
- package/dist/node/queue/workers/ethTransactionMonitor.d.ts +3 -0
- package/dist/node/queue/workers/ethTransactionMonitor.d.ts.map +1 -0
- package/dist/node/queue/workers/ethTransactionPreparation.d.ts +5 -0
- package/dist/node/queue/workers/ethTransactionPreparation.d.ts.map +1 -0
- package/dist/node/queue/workers/ethTransactionSubmission.d.ts +3 -0
- package/dist/node/queue/workers/ethTransactionSubmission.d.ts.map +1 -0
- package/dist/node/queue/workers/index.d.ts +9 -0
- package/dist/node/queue/workers/index.d.ts.map +1 -0
- package/dist/node/queue/workers/xl1ToEthBridgeParent.d.ts +3 -0
- package/dist/node/queue/workers/xl1ToEthBridgeParent.d.ts.map +1 -0
- package/dist/node/queue/workers/xl1TransactionMonitor.d.ts +3 -0
- package/dist/node/queue/workers/xl1TransactionMonitor.d.ts.map +1 -0
- package/dist/node/queue/workers/xl1TransactionPreparation.d.ts +3 -0
- package/dist/node/queue/workers/xl1TransactionPreparation.d.ts.map +1 -0
- package/dist/node/queue/workers/xl1TransactionSubmission.d.ts +3 -0
- package/dist/node/queue/workers/xl1TransactionSubmission.d.ts.map +1 -0
- package/dist/node/server/app.d.ts.map +1 -1
- package/dist/node/server/flowProducer.d.ts +4 -0
- package/dist/node/server/flowProducer.d.ts.map +1 -0
- package/dist/node/server/index.d.ts +4 -0
- package/dist/node/server/index.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.d.ts.map +1 -1
- package/dist/node/server/server.d.ts.map +1 -1
- package/dist/node/services/EthTxState.d.ts +5 -0
- package/dist/node/services/EthTxState.d.ts.map +1 -0
- package/dist/node/services/IBridgeServiceCollection.d.ts +17 -0
- package/dist/node/services/IBridgeServiceCollection.d.ts.map +1 -0
- package/dist/node/services/TxState.d.ts +22 -0
- package/dist/node/services/TxState.d.ts.map +1 -0
- package/dist/node/services/Xl1TxState.d.ts +6 -0
- package/dist/node/services/Xl1TxState.d.ts.map +1 -0
- package/dist/node/services/index.d.ts +5 -0
- package/dist/node/services/index.d.ts.map +1 -0
- package/dist/node/util/generateBridgeEstimate.d.ts.map +1 -1
- package/dist/node/util/validateBridgeTransaction.d.ts.map +1 -1
- package/package.json +19 -18
- package/src/config/getGateway.ts +10 -3
- package/src/interface/service/Observer/ERC20TransferObserver/ERC20TransferObserver.ts +1 -1
- package/src/interface/service/Observer/LiquidityPoolBridgeObserver/LiquidityPoolBridgeObserver.ts +1 -2
- package/src/interface/service/Relay/LiquidityPoolBridgeRelay/LiquidityPoolBridgeRelay.ts +1 -1
- package/src/manifest/getLocator.ts +4 -4
- package/src/manifest/getServices.ts +102 -0
- package/src/manifest/index.ts +1 -0
- package/src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.ts +1 -1
- package/src/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.ts +1 -1
- package/src/queue/connection.ts +16 -0
- package/src/queue/flowProducer.ts +11 -0
- package/src/queue/flows/createXl1ToEthBridgeJob.ts +60 -0
- package/src/queue/flows/index.ts +1 -0
- package/src/queue/index.ts +4 -0
- package/src/queue/workers/WorkerDescription.ts +7 -0
- package/src/queue/workers/createWorkers.ts +15 -0
- package/src/queue/workers/ethTransactionMonitor.ts +42 -0
- package/src/queue/workers/ethTransactionPreparation.ts +47 -0
- package/src/queue/workers/ethTransactionSubmission.ts +77 -0
- package/src/queue/workers/index.ts +8 -0
- package/src/queue/workers/xl1ToEthBridgeParent.ts +25 -0
- package/src/queue/workers/xl1TransactionMonitor.ts +66 -0
- package/src/queue/workers/xl1TransactionPreparation.ts +36 -0
- package/src/queue/workers/xl1TransactionSubmission.ts +60 -0
- package/src/server/app.ts +2 -0
- package/src/server/flowProducer.ts +11 -0
- package/src/server/index.ts +5 -0
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.ts +6 -14
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts +1 -0
- package/src/server/server.ts +2 -1
- package/src/services/EthTxState.ts +5 -0
- package/src/services/IBridgeServiceCollection.ts +18 -0
- package/src/services/TxState.ts +32 -0
- package/src/services/Xl1TxState.ts +6 -0
- package/src/services/index.ts +4 -0
- package/src/util/generateBridgeEstimate.ts +1 -2
- package/src/util/validateBridgeTransaction.ts +5 -0
- package/dist/node/driver/index.d.ts +0 -2
- package/dist/node/driver/index.d.ts.map +0 -1
- package/dist/node/driver/indexer/ChainBlockIteration/ChainHashIterationService.d.ts +0 -24
- package/dist/node/driver/indexer/ChainBlockIteration/ChainHashIterationService.d.ts.map +0 -1
- package/dist/node/driver/indexer/ChainBlockIteration/index.d.ts +0 -2
- package/dist/node/driver/indexer/ChainBlockIteration/index.d.ts.map +0 -1
- package/dist/node/driver/indexer/ChainBlocksObservable.d.ts +0 -6
- package/dist/node/driver/indexer/ChainBlocksObservable.d.ts.map +0 -1
- package/dist/node/driver/indexer/ChainHydratedBlocksObservable.d.ts +0 -11
- package/dist/node/driver/indexer/ChainHydratedBlocksObservable.d.ts.map +0 -1
- package/dist/node/driver/indexer/index.d.ts +0 -2
- package/dist/node/driver/indexer/index.d.ts.map +0 -1
- package/src/driver/index.ts +0 -1
- package/src/driver/indexer/ChainBlockIteration/ChainHashIterationService.ts +0 -89
- package/src/driver/indexer/ChainBlockIteration/index.ts +0 -1
- package/src/driver/indexer/ChainBlocksObservable.ts +0 -46
- package/src/driver/indexer/ChainHydratedBlocksObservable.ts +0 -23
- package/src/driver/indexer/index.ts +0 -1
package/src/server/index.ts
CHANGED
|
@@ -2,12 +2,17 @@ export * from './app.ts'
|
|
|
2
2
|
export * from './server.ts'
|
|
3
3
|
|
|
4
4
|
import type { NodeInstance } from '@xyo-network/node-model'
|
|
5
|
+
import type { FlowProducer } from 'bullmq'
|
|
6
|
+
|
|
7
|
+
import type { IBridgeServiceCollection } from '../services/index.ts'
|
|
5
8
|
|
|
6
9
|
declare global {
|
|
7
10
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
8
11
|
namespace Express {
|
|
9
12
|
interface Application {
|
|
13
|
+
flowProducer: FlowProducer
|
|
10
14
|
node: NodeInstance
|
|
15
|
+
services: IBridgeServiceCollection
|
|
11
16
|
}
|
|
12
17
|
}
|
|
13
18
|
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import type { RouteDefinition } from '@xylabs/express'
|
|
2
2
|
import { requestHandlerValidator } from '@xylabs/express'
|
|
3
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
4
3
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
5
4
|
import { PayloadZodStrictOfSchema } from '@xyo-network/payload-model'
|
|
6
|
-
import { asSentinelInstance } from '@xyo-network/sentinel-model'
|
|
7
5
|
import type {
|
|
8
6
|
BridgeSourceObservation, BridgeSourceObservationFields, SignedHydratedTransaction,
|
|
9
7
|
} from '@xyo-network/xl1-protocol'
|
|
10
8
|
import {
|
|
11
9
|
BridgeIntentFieldsZod, BridgeIntentSchema, BridgeSourceObservationFieldsZod, BridgeSourceObservationSchema, SignedTransactionBoundWitnessZod, TransferZod,
|
|
12
10
|
} from '@xyo-network/xl1-protocol'
|
|
13
|
-
import { type Config
|
|
11
|
+
import { type Config } from '@xyo-network/xl1-protocol-sdk'
|
|
14
12
|
import { z } from 'zod'
|
|
15
13
|
|
|
14
|
+
import { createXl1ToEthBridgeJob } from '../../../../../queue/index.ts'
|
|
16
15
|
import { validateBridgeEstimateExact, validateBridgeTransaction } from '../../../../../util/index.ts'
|
|
17
16
|
import { getRemoteChainIdZod } from '../pathParams/index.ts'
|
|
18
17
|
|
|
@@ -33,7 +32,7 @@ export const makeBridgeToRemoteRoute = (config: Config): RouteDefinition => {
|
|
|
33
32
|
path: '/bridge/chains/:chainId/bridgeToRemote',
|
|
34
33
|
handlers: validateRequest(async (req, res) => {
|
|
35
34
|
const [signedTxBw, bridgeIntent, transfer] = req.body
|
|
36
|
-
const {
|
|
35
|
+
const { flowProducer } = req.app
|
|
37
36
|
|
|
38
37
|
// Validate request
|
|
39
38
|
const transactionValid = await validateBridgeTransaction(signedTxBw, bridgeIntent, transfer, config)
|
|
@@ -49,19 +48,12 @@ export const makeBridgeToRemoteRoute = (config: Config): RouteDefinition => {
|
|
|
49
48
|
return
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
// Submit to
|
|
53
|
-
const mod = await node.resolve('XL1BridgeIntentTransactionCompletionMonitorSentinel')
|
|
54
|
-
const sentinel = assertEx(asSentinelInstance(mod), () => 'Error resolving XL1BridgeIntentTransactionCompletionMonitorSentinel')
|
|
51
|
+
// Submit to job queue
|
|
55
52
|
const singedHydratedTransaction: SignedHydratedTransaction = [signedTxBw, [transfer, bridgeIntent]]
|
|
56
|
-
|
|
57
|
-
if (observation.length === 0) {
|
|
58
|
-
console.error('Error submitting bridge intent transaction to sentinel')
|
|
59
|
-
res.status(500).send()
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
const srcConfirmation = await PayloadBuilder.hash(signedTxBw)
|
|
53
|
+
await createXl1ToEthBridgeJob(flowProducer, singedHydratedTransaction)
|
|
63
54
|
|
|
64
55
|
// Create BridgeObservation
|
|
56
|
+
const srcConfirmation = await PayloadBuilder.hash(signedTxBw)
|
|
65
57
|
const bridgeCommonFieldsZod = z.object({}).extend(BridgeSourceObservationFieldsZod.shape)
|
|
66
58
|
const bridgeCommonFields = bridgeCommonFieldsZod.parse(bridgeIntent)
|
|
67
59
|
const bridgeObservationFields: BridgeSourceObservationFields = { ...bridgeCommonFields, srcConfirmation }
|
package/src/server/server.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { NodeInstance } from '@xyo-network/node-model'
|
|
|
7
7
|
import { HDWallet } from '@xyo-network/wallet'
|
|
8
8
|
import { type Config } from '@xyo-network/xl1-protocol-sdk'
|
|
9
9
|
|
|
10
|
-
import { getNode } from '../manifest/index.ts'
|
|
10
|
+
import { getNode, getServices } from '../manifest/index.ts'
|
|
11
11
|
import { getApp } from './app.ts'
|
|
12
12
|
|
|
13
13
|
const hostname = '::'
|
|
@@ -52,6 +52,7 @@ export const getServer = async (context: GetServerContext) => {
|
|
|
52
52
|
}
|
|
53
53
|
const node = context.node ?? await getNode(nodeContext)
|
|
54
54
|
const app = getApp(node, config)
|
|
55
|
+
app.services = await getServices({ config, logger })
|
|
55
56
|
const server = app.listen(port, hostname, () => logger?.log(`[Bridge] Server listening at http://${hostname}:${port}`))
|
|
56
57
|
server.setTimeout(20_000)
|
|
57
58
|
return server
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
+
import type { AccountInstance } from '@xyo-network/account-model'
|
|
3
|
+
import type { LiquidityPoolBridge } from '@xyo-network/typechain'
|
|
4
|
+
import type { IterableMap, XyoGatewayRunner } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
+
import type { Provider, Wallet } from 'ethers'
|
|
6
|
+
|
|
7
|
+
import type { EthTxState } from './EthTxState.ts'
|
|
8
|
+
import type { Xl1TxState } from './Xl1TxState.ts'
|
|
9
|
+
|
|
10
|
+
export interface IBridgeServiceCollection {
|
|
11
|
+
account: AccountInstance
|
|
12
|
+
bridge: LiquidityPoolBridge
|
|
13
|
+
ethTxStateMap: IterableMap<Hash, EthTxState>
|
|
14
|
+
gateway: XyoGatewayRunner
|
|
15
|
+
provider: Provider
|
|
16
|
+
wallet: Wallet
|
|
17
|
+
xl1TxStateMap: IterableMap<Hash, Xl1TxState>
|
|
18
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isDefined } from '@xylabs/sdk-js'
|
|
2
|
+
|
|
3
|
+
export interface TxState<TTx, TTxHash extends string = string, TConfHash extends string = string> {
|
|
4
|
+
/**
|
|
5
|
+
* The confirmation hash of the transaction
|
|
6
|
+
*/
|
|
7
|
+
confirmationHash?: TConfHash
|
|
8
|
+
/**
|
|
9
|
+
* The transaction that has been prepared for submission
|
|
10
|
+
*/
|
|
11
|
+
preparedTx?: TTx
|
|
12
|
+
/**
|
|
13
|
+
* The hash of the submitted transaction
|
|
14
|
+
*/
|
|
15
|
+
submissionHash?: TTxHash
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type TxCompletionStates = 'pendingSubmission' | 'submitted' | 'confirmed' | 'failed'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Determines the transaction state based on the TxState object
|
|
22
|
+
* @param state The transaction state
|
|
23
|
+
* @returns The state of the transaction
|
|
24
|
+
*/
|
|
25
|
+
export const getTransactionCompletionState = <T>(state: TxState<T>): TxCompletionStates => {
|
|
26
|
+
// Prepared, submitted, and confirmed
|
|
27
|
+
if (isDefined(state.preparedTx) && isDefined(state.submissionHash) && isDefined(state.confirmationHash)) return 'confirmed'
|
|
28
|
+
// Prepared and submitted
|
|
29
|
+
if (isDefined(state.preparedTx) && isDefined(state.submissionHash)) return 'submitted'
|
|
30
|
+
// Prepared
|
|
31
|
+
return 'pendingSubmission'
|
|
32
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { Hex } from '@xylabs/sdk-js'
|
|
2
2
|
import { hexToBigInt, toAddress } from '@xylabs/sdk-js'
|
|
3
|
-
import { createTransferPayload } from '@xyo-network/chain-protocol'
|
|
4
3
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
5
4
|
import type {
|
|
6
5
|
BridgeIntent, BridgeIntentFields, Transfer,
|
|
7
6
|
} from '@xyo-network/xl1-protocol'
|
|
8
7
|
import { BridgeIntentSchema } from '@xyo-network/xl1-protocol'
|
|
9
|
-
import { type Config } from '@xyo-network/xl1-protocol-sdk'
|
|
8
|
+
import { type Config, createTransferPayload } from '@xyo-network/xl1-protocol-sdk'
|
|
10
9
|
import { v4 } from 'uuid'
|
|
11
10
|
|
|
12
11
|
import { getBridgeSettings } from '../config/index.ts'
|
|
@@ -8,6 +8,8 @@ import type {
|
|
|
8
8
|
} from '@xyo-network/xl1-protocol'
|
|
9
9
|
import { type Config } from '@xyo-network/xl1-protocol-sdk'
|
|
10
10
|
|
|
11
|
+
import { getXl1ChainId } from '../config/index.ts'
|
|
12
|
+
|
|
11
13
|
/**
|
|
12
14
|
* Validates a bridge estimate by checking the intent and transfer against the provided configuration. This method
|
|
13
15
|
* exists to allow for "at least" validation of a bridge estimates in case we want to allow for some flexibility in
|
|
@@ -27,6 +29,9 @@ export const validateBridgeTransaction = async (
|
|
|
27
29
|
): Promise<boolean> => {
|
|
28
30
|
const { srcAddress } = intent
|
|
29
31
|
|
|
32
|
+
const chainId = getXl1ChainId(config)
|
|
33
|
+
if (signedTxBw.chain !== chainId) return false
|
|
34
|
+
|
|
30
35
|
const errors = await new BoundWitnessValidator(signedTxBw).validate()
|
|
31
36
|
if (isDefined(errors) && errors.length > 0) return false
|
|
32
37
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/driver/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Hash, Hex, Promisable } from '@xylabs/sdk-js';
|
|
2
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model';
|
|
3
|
-
import type { BaseServiceParams } from '@xyo-network/chain-services';
|
|
4
|
-
import { BaseService } from '@xyo-network/chain-services';
|
|
5
|
-
import type { WithStorageMeta } from '@xyo-network/payload-model';
|
|
6
|
-
import { type BlockBoundWitness } from '@xyo-network/xl1-protocol';
|
|
7
|
-
import type { ChainIteratorServiceEventData, EventingChainHashIteratorService } from '@xyo-network/xl1-protocol-sdk';
|
|
8
|
-
export interface ChainHashIterationServiceParams extends BaseServiceParams {
|
|
9
|
-
chainArchivist: ArchivistInstance;
|
|
10
|
-
head: BlockBoundWitness;
|
|
11
|
-
}
|
|
12
|
-
export declare class ChainHashIterationService extends BaseService<ChainHashIterationServiceParams, ChainIteratorServiceEventData> implements EventingChainHashIteratorService {
|
|
13
|
-
protected _currentHead: WithStorageMeta<BlockBoundWitness> | undefined;
|
|
14
|
-
get chainArchivist(): ArchivistInstance;
|
|
15
|
-
get chainId(): Hex;
|
|
16
|
-
get(id: Hash): Promisable<BlockBoundWitness | undefined>;
|
|
17
|
-
head(): Promise<WithStorageMeta<BlockBoundWitness>>;
|
|
18
|
-
next(_id: Hex): Promise<WithStorageMeta<BlockBoundWitness> | undefined>;
|
|
19
|
-
previous(block?: Hash | undefined, count?: number): Promise<WithStorageMeta<BlockBoundWitness>[]>;
|
|
20
|
-
updateHead(head: BlockBoundWitness): Promise<void>;
|
|
21
|
-
private getBoundWitnessAsBlockBoundWitnessWithStorageMeta;
|
|
22
|
-
private getHashAsBlockBoundWitnessWithStorageMeta;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=ChainHashIterationService.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChainHashIterationService.d.ts","sourceRoot":"","sources":["../../../../../src/driver/indexer/ChainBlockIteration/ChainHashIterationService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EAAE,GAAG,EAAE,UAAU,EACtB,MAAM,gBAAgB,CAAA;AAKvB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,EAC+B,KAAK,iBAAiB,EAE3D,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EAAE,6BAA6B,EAAE,gCAAgC,EAAE,MAAM,+BAA+B,CAAA;AAEpH,MAAM,WAAW,+BAAgC,SAAQ,iBAAiB;IACxE,cAAc,EAAE,iBAAiB,CAAA;IACjC,IAAI,EAAE,iBAAiB,CAAA;CACxB;AAED,qBAAa,yBAA0B,SAAQ,WAAW,CAAC,+BAA+B,EAAE,6BAA6B,CACvH,YAAW,gCAAgC;IAC3C,SAAS,CAAC,YAAY,EAAE,eAAe,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAA;IAEtE,IAAI,cAAc,IAAI,iBAAiB,CAAgD;IAEvF,IAAI,OAAO,IAAI,GAAG,CAA2G;IAE7H,GAAG,CAAC,EAAE,EAAE,IAAI,GAAG,UAAU,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAIlD,IAAI,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;IAUnD,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC;IAKvE,QAAQ,CAAC,KAAK,GAAE,IAAI,GAAG,SAAqB,EAAE,KAAK,GAAE,MAAU,GAAG,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,EAAE,CAAC;IAqB/G,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;YAM1C,iDAAiD;YAKjD,yCAAyC;CAMxD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/driver/indexer/ChainBlockIteration/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAA"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { WithStorageMeta } from '@xyo-network/payload-model';
|
|
2
|
-
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol';
|
|
3
|
-
import type { EventingChainBlockNumberIteratorService } from '@xyo-network/xl1-protocol-sdk';
|
|
4
|
-
import type { Observable } from 'rxjs';
|
|
5
|
-
export declare const chainBlocks$: (chainIterator: EventingChainBlockNumberIteratorService) => Observable<WithStorageMeta<BlockBoundWitness>>;
|
|
6
|
-
//# sourceMappingURL=ChainBlocksObservable.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChainBlocksObservable.d.ts","sourceRoot":"","sources":["../../../../src/driver/indexer/ChainBlocksObservable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAClE,OAAO,KAAK,EAAE,uCAAuC,EAAiB,MAAM,+BAA+B,CAAA;AAC3G,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAKtC,eAAO,MAAM,YAAY,GACvB,eAAe,uCAAuC,KACrD,UAAU,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAkC/C,CAAA"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { HydratedBlock } from '@xyo-network/xl1-protocol';
|
|
2
|
-
import type { ChainStoreRead } from '@xyo-network/xl1-protocol-sdk';
|
|
3
|
-
import type { Observable } from 'rxjs';
|
|
4
|
-
import { chainBlocks$ } from './ChainBlocksObservable.ts';
|
|
5
|
-
/**
|
|
6
|
-
* Creates an observable of HydratedBlocks from a chain iterator + context.
|
|
7
|
-
* @param chainIterator - EventingChainBlockNumberIteratorService that emits heads
|
|
8
|
-
* @param context - ChainStoreContextRead used to fetch payloads and hydrate blocks
|
|
9
|
-
*/
|
|
10
|
-
export declare const hydratedChainBlocks$: (chainIterator: Parameters<typeof chainBlocks$>[0], context: ChainStoreRead) => Observable<HydratedBlock>;
|
|
11
|
-
//# sourceMappingURL=ChainHydratedBlocksObservable.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChainHydratedBlocksObservable.d.ts","sourceRoot":"","sources":["../../../../src/driver/indexer/ChainHydratedBlocksObservable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqB,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAEnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAGtC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEzD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,eAAe,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,EACjD,SAAS,cAAc,KACtB,UAAU,CAAC,aAAa,CAK1B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/driver/indexer/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA"}
|
package/src/driver/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './indexer/index.ts'
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Hash, Hex, Promisable,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import {
|
|
5
|
-
assertEx,
|
|
6
|
-
isDefined, isNull, isUndefined,
|
|
7
|
-
} from '@xylabs/sdk-js'
|
|
8
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
9
|
-
import type { BaseServiceParams } from '@xyo-network/chain-services'
|
|
10
|
-
import { BaseService } from '@xyo-network/chain-services'
|
|
11
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
12
|
-
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
13
|
-
import {
|
|
14
|
-
asBlockBoundWitnessWithStorageMeta, type BlockBoundWitness,
|
|
15
|
-
isBlockBoundWitnessWithStorageMeta,
|
|
16
|
-
} from '@xyo-network/xl1-protocol'
|
|
17
|
-
import type { ChainIteratorServiceEventData, EventingChainHashIteratorService } from '@xyo-network/xl1-protocol-sdk'
|
|
18
|
-
|
|
19
|
-
export interface ChainHashIterationServiceParams extends BaseServiceParams {
|
|
20
|
-
chainArchivist: ArchivistInstance
|
|
21
|
-
head: BlockBoundWitness
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class ChainHashIterationService extends BaseService<ChainHashIterationServiceParams, ChainIteratorServiceEventData>
|
|
25
|
-
implements EventingChainHashIteratorService {
|
|
26
|
-
protected _currentHead: WithStorageMeta<BlockBoundWitness> | undefined
|
|
27
|
-
|
|
28
|
-
get chainArchivist(): ArchivistInstance { return assertEx(this.params.chainArchivist) }
|
|
29
|
-
|
|
30
|
-
get chainId(): Hex { return assertEx(this._currentHead?.chain ?? this.params?.head?.chain, () => 'Current head is not set') }
|
|
31
|
-
|
|
32
|
-
get(id: Hash): Promisable<BlockBoundWitness | undefined> {
|
|
33
|
-
return this.getHashAsBlockBoundWitnessWithStorageMeta(id)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async head(): Promise<WithStorageMeta<BlockBoundWitness>> {
|
|
37
|
-
if (isDefined(this._currentHead)) return this._currentHead
|
|
38
|
-
if (isDefined(this.params.head)) {
|
|
39
|
-
const newHead = await this.getBoundWitnessAsBlockBoundWitnessWithStorageMeta(this.params.head)
|
|
40
|
-
this._currentHead = newHead
|
|
41
|
-
return newHead
|
|
42
|
-
}
|
|
43
|
-
throw new Error('Head is not set')
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async next(_id: Hex): Promise<WithStorageMeta<BlockBoundWitness> | undefined> {
|
|
47
|
-
await Promise.resolve() // to make this function async
|
|
48
|
-
throw new Error('Next method not implemented for ChainHashIterationService.')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async previous(block: Hash | undefined = undefined, count: number = 1): Promise<WithStorageMeta<BlockBoundWitness>[]> {
|
|
52
|
-
const results: WithStorageMeta<BlockBoundWitness>[] = []
|
|
53
|
-
let currentBlock: WithStorageMeta<BlockBoundWitness> | undefined = await this.head()
|
|
54
|
-
if (isDefined(block)) {
|
|
55
|
-
currentBlock = await this.getHashAsBlockBoundWitnessWithStorageMeta(block)
|
|
56
|
-
}
|
|
57
|
-
while (currentBlock && results.length < count) {
|
|
58
|
-
if (isBlockBoundWitnessWithStorageMeta(currentBlock)) {
|
|
59
|
-
results.push(currentBlock)
|
|
60
|
-
const { previous } = currentBlock
|
|
61
|
-
if (isNull(previous)) break
|
|
62
|
-
const nextBlock = await this.chainArchivist.get([previous])
|
|
63
|
-
currentBlock = asBlockBoundWitnessWithStorageMeta(nextBlock[0])
|
|
64
|
-
} else {
|
|
65
|
-
const hash = await PayloadBuilder.hash(currentBlock)
|
|
66
|
-
assertEx(asBlockBoundWitnessWithStorageMeta(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return results
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async updateHead(head: BlockBoundWitness): Promise<void> {
|
|
73
|
-
const newHead = await this.getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head)
|
|
74
|
-
this._currentHead = newHead
|
|
75
|
-
void this.emit('headUpdated', { blocks: [newHead] })
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private async getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head: BlockBoundWitness): Promise<WithStorageMeta<BlockBoundWitness>> {
|
|
79
|
-
const hash = await PayloadBuilder.hash(head)
|
|
80
|
-
return this.getHashAsBlockBoundWitnessWithStorageMeta(hash)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private async getHashAsBlockBoundWitnessWithStorageMeta(hash: Hash): Promise<WithStorageMeta<BlockBoundWitness>> {
|
|
84
|
-
const stored = (await this.chainArchivist.get([hash])).at(-1)
|
|
85
|
-
const bw = asBlockBoundWitnessWithStorageMeta(stored)
|
|
86
|
-
if (isUndefined(bw)) throw new Error(`Block not found in archivist [${hash}]`)
|
|
87
|
-
return bw
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ChainHashIterationService.ts'
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { isDefined, isUndefined } from '@xylabs/sdk-js'
|
|
2
|
-
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
3
|
-
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
4
|
-
import type { EventingChainBlockNumberIteratorService, HeadEventArgs } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
-
import type { Observable } from 'rxjs'
|
|
6
|
-
import {
|
|
7
|
-
concatMap, defer, fromEvent, mergeMap,
|
|
8
|
-
} from 'rxjs'
|
|
9
|
-
|
|
10
|
-
export const chainBlocks$ = (
|
|
11
|
-
chainIterator: EventingChainBlockNumberIteratorService,
|
|
12
|
-
): Observable<WithStorageMeta<BlockBoundWitness>> => {
|
|
13
|
-
// Event source: head updated
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
const headUpdates$ = fromEvent<HeadEventArgs>(chainIterator as any, 'headUpdated')
|
|
16
|
-
|
|
17
|
-
return defer(async () => {
|
|
18
|
-
// seed with current head (optional)
|
|
19
|
-
const head = await chainIterator.head()
|
|
20
|
-
return head
|
|
21
|
-
}).pipe(
|
|
22
|
-
// merge initial head + updates into a single stream
|
|
23
|
-
mergeMap((firstHead) => {
|
|
24
|
-
let lastSeen: number | undefined = firstHead.block
|
|
25
|
-
|
|
26
|
-
return headUpdates$.pipe(
|
|
27
|
-
concatMap(async (blocks: HeadEventArgs) => {
|
|
28
|
-
// walk backwards from newHead until we reach lastSeen
|
|
29
|
-
const history: WithStorageMeta<BlockBoundWitness>[] = []
|
|
30
|
-
const newHead = blocks.blocks.at(-1)
|
|
31
|
-
let cursor: number | undefined = newHead?.block
|
|
32
|
-
while (isDefined(cursor) && (isUndefined(lastSeen) || cursor > lastSeen)) {
|
|
33
|
-
const blocks = await chainIterator.previous(cursor, 1)
|
|
34
|
-
if (blocks.length === 0) break
|
|
35
|
-
history.push(blocks[0])
|
|
36
|
-
cursor = blocks[0].block - 1
|
|
37
|
-
}
|
|
38
|
-
if (isDefined(newHead)) lastSeen = newHead.block
|
|
39
|
-
// emit in ascending order
|
|
40
|
-
return history.toReversed()
|
|
41
|
-
}),
|
|
42
|
-
mergeMap(blocks => blocks), // flatten
|
|
43
|
-
)
|
|
44
|
-
}),
|
|
45
|
-
)
|
|
46
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
2
|
-
import type { BlockBoundWitness, HydratedBlock } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type { ChainStoreRead } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
import { hydrateBlock } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
-
import type { Observable } from 'rxjs'
|
|
6
|
-
import { concatMap } from 'rxjs'
|
|
7
|
-
|
|
8
|
-
import { chainBlocks$ } from './ChainBlocksObservable.ts'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Creates an observable of HydratedBlocks from a chain iterator + context.
|
|
12
|
-
* @param chainIterator - EventingChainBlockNumberIteratorService that emits heads
|
|
13
|
-
* @param context - ChainStoreContextRead used to fetch payloads and hydrate blocks
|
|
14
|
-
*/
|
|
15
|
-
export const hydratedChainBlocks$ = (
|
|
16
|
-
chainIterator: Parameters<typeof chainBlocks$>[0],
|
|
17
|
-
context: ChainStoreRead,
|
|
18
|
-
): Observable<HydratedBlock> => {
|
|
19
|
-
return chainBlocks$(chainIterator).pipe(
|
|
20
|
-
concatMap((block: WithStorageMeta<BlockBoundWitness>) =>
|
|
21
|
-
hydrateBlock(context, block._hash)),
|
|
22
|
-
)
|
|
23
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ChainBlocksObservable.ts'
|