Skip to content

Commit

Permalink
feat: add more helper function to serviceQueue module and export it a…
Browse files Browse the repository at this point in the history
…s an object for clarity
  • Loading branch information
PudgyPug authored and mhanson-github committed Jan 27, 2025
1 parent 8ce1bab commit 64bdd8b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/p2p/ServiceQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,15 @@ export function sendRequests(): void {

/** Module Functions */

export function containsTx(txHash: string): boolean {
return txList.some((entry) => entry.hash === txHash)
}

export function containsTxData(txData: OpaqueTransaction): boolean {
const hash = crypto.hash(txData)
return containsTx(hash)
}

export function registerShutdownHandler(
type: string,
handler: (
Expand Down
32 changes: 19 additions & 13 deletions src/shardus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ interface Shardus {
registerExternalPut: RouteHandlerRegister
registerExternalDelete: RouteHandlerRegister
registerExternalPatch: RouteHandlerRegister
registerBeforeAddVerifier: (type: string, verifier: (tx: OpaqueTransaction) => Promise<boolean>) => void
registerApplyVerifier: (type: string, verifier: (tx: OpaqueTransaction) => Promise<boolean>) => void
registerShutdownHandler: (
type: string,
handler: (
activeNode: P2P.NodeListTypes.Node,
record: P2P.CycleCreatorTypes.CycleRecord
) => Omit<P2P.ServiceQueueTypes.AddNetworkTx, 'cycle' | 'hash'> | null | undefined
) => void
serviceQueue: {
registerBeforeAddVerifier: typeof ServiceQueue.registerBeforeAddVerifier
registerApplyVerifier: typeof ServiceQueue.registerApplyVerifier
registerShutdownHandler: typeof ServiceQueue.registerShutdownHandler
containsTxData: typeof ServiceQueue.containsTxData
containsTx: typeof ServiceQueue.containsTx
addNetworkTx: typeof ServiceQueue.addNetworkTx
getLatestNetworkTxEntryForSubqueueKey: typeof ServiceQueue.getLatestNetworkTxEntryForSubqueueKey
}
_listeners: any
appliedConfigChanges: Set<string>

Expand Down Expand Up @@ -265,10 +265,16 @@ class Shardus extends EventEmitter {
this.registerExternalPatch = (route, authHandler, handler) =>
this.network.registerExternalPatch(route, authHandler, handler)

this.registerBeforeAddVerifier = ServiceQueue.registerBeforeAddVerifier
this.registerApplyVerifier = ServiceQueue.registerApplyVerifier
this.registerApplyVerifier = ServiceQueue.registerApplyVerifier
this.registerShutdownHandler = ServiceQueue.registerShutdownHandler
// serviceQueue module
this.serviceQueue = {
registerBeforeAddVerifier: ServiceQueue.registerBeforeAddVerifier,
registerApplyVerifier: ServiceQueue.registerApplyVerifier,
registerShutdownHandler: ServiceQueue.registerShutdownHandler,
containsTxData: ServiceQueue.containsTxData,
containsTx: ServiceQueue.containsTx,
addNetworkTx: ServiceQueue.addNetworkTx,
getLatestNetworkTxEntryForSubqueueKey: ServiceQueue.getLatestNetworkTxEntryForSubqueueKey
}

this.exitHandler.addSigListeners()
this.exitHandler.registerSync('reporter', () => {
Expand Down

0 comments on commit 64bdd8b

Please sign in to comment.