-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(p2p): reorganise reqresp handlers (#11327)
- Loading branch information
Showing
11 changed files
with
134 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Request Response protocol handlers | ||
*/ | ||
export * from './ping.js'; | ||
export * from './status.js'; | ||
export * from './tx.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Handles the ping request. | ||
* @param _msg - The ping request message. | ||
* @returns A resolved promise with the pong response. | ||
*/ | ||
export function pingHandler(_msg: any): Promise<Buffer> { | ||
return Promise.resolve(Buffer.from('pong')); | ||
} |
9 changes: 0 additions & 9 deletions
9
...ject/p2p/src/services/reqresp/handlers.ts → .../src/services/reqresp/protocols/status.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { type P2PClientType } from '@aztec/circuit-types'; | ||
import { TxHash } from '@aztec/circuit-types/tx_hash'; | ||
|
||
import { type MemPools } from '../../../mem_pools/interface.js'; | ||
|
||
/** | ||
* We want to keep the logic of the req resp handler in this file, but we do not have a reference to the mempools here | ||
* so we need to pass it in as a parameter. | ||
* | ||
* Handler for tx requests | ||
* @param mempools - the mempools | ||
* @returns the tx response message | ||
*/ | ||
export function reqRespTxHandler<T extends P2PClientType>(mempools: MemPools<T>): (msg: Buffer) => Promise<Buffer> { | ||
/** | ||
* Handler for tx requests | ||
* @param msg - the tx request message | ||
* @returns the tx response message | ||
*/ | ||
return (msg: Buffer) => { | ||
const txHash = TxHash.fromBuffer(msg); | ||
const foundTx = mempools.txPool.getTxByHash(txHash); | ||
const buf = foundTx ? foundTx.toBuffer() : Buffer.alloc(0); | ||
return Promise.resolve(buf); | ||
}; | ||
} |
Oops, something went wrong.