|
| 1 | +use jsonrpsee::core::RpcResult; |
| 2 | +use jsonrpsee::proc_macros::rpc; |
| 3 | +use katana_primitives::ContractAddress; |
| 4 | +use katana_rpc_types::txpool::{TxPoolContent, TxPoolInspect, TxPoolStatus}; |
| 5 | + |
| 6 | +/// Inspection API for the node's local transaction pool. |
| 7 | +/// |
| 8 | +/// This exposes the node's own pending-transaction pool — not a network-wide mempool. |
| 9 | +/// Unlike Ethereum, Starknet does not yet have a shared peer-to-peer mempool; each sequencer |
| 10 | +/// maintains its own pool of transactions waiting to be included in a block. The |
| 11 | +/// transactions visible here are only those that have been submitted to *this* node. |
| 12 | +/// |
| 13 | +/// This API is primarily intended for debugging and diagnostics. |
| 14 | +/// |
| 15 | +/// Modeled after Ethereum's `txpool_*` namespace, adapted for Starknet transactions. |
| 16 | +/// |
| 17 | +/// All responses distinguish between `pending` (ready to execute) and `queued` (waiting on |
| 18 | +/// a nonce gap) transactions. Currently Katana has no queued pool — dependent transactions |
| 19 | +/// are rejected at submission — so the `queued` fields are always empty/zero. They exist |
| 20 | +/// for forward-compatibility. |
| 21 | +#[cfg_attr(not(feature = "client"), rpc(server, namespace = "txpool"))] |
| 22 | +#[cfg_attr(feature = "client", rpc(client, server, namespace = "txpool"))] |
| 23 | +pub trait TxPoolApi { |
| 24 | + /// Returns the number of pending and queued transactions in the pool. |
| 25 | + /// |
| 26 | + /// This is a cheap call that avoids snapshotting individual transactions. |
| 27 | + #[method(name = "status")] |
| 28 | + async fn txpool_status(&self) -> RpcResult<TxPoolStatus>; |
| 29 | + |
| 30 | + /// Returns the full content of the pool, grouped by sender address and nonce. |
| 31 | + /// |
| 32 | + /// Each transaction is represented as a lightweight [`TxPoolTransaction`] containing |
| 33 | + /// the hash, nonce, sender, max_fee, and tip. The full transaction can be retrieved |
| 34 | + /// via `starknet_getTransactionByHash`. |
| 35 | + #[method(name = "content")] |
| 36 | + async fn txpool_content(&self) -> RpcResult<TxPoolContent>; |
| 37 | + |
| 38 | + /// Same as `txpool_content` but filtered to a single sender address. |
| 39 | + /// |
| 40 | + /// Returns only the transactions from the given address. The `queued` map is always empty. |
| 41 | + #[method(name = "contentFrom")] |
| 42 | + async fn txpool_content_from(&self, address: ContractAddress) -> RpcResult<TxPoolContent>; |
| 43 | + |
| 44 | + /// Returns a textual summary of all pooled transactions, grouped by sender and nonce. |
| 45 | + /// |
| 46 | + /// Each transaction is represented as a human-readable string |
| 47 | + /// (`hash=0x… nonce=0x… max_fee=… tip=…`) rather than a structured object — |
| 48 | + /// useful for quick inspection or logging. |
| 49 | + #[method(name = "inspect")] |
| 50 | + async fn txpool_inspect(&self) -> RpcResult<TxPoolInspect>; |
| 51 | +} |
0 commit comments