mod client;
pub use client::*;
use crate::connection::InteractionContext;
use crate::error::Result;
use crate::schema::{MempoolSizeAndCapacity, Slot, Transaction, TransactionId};
use serde::{Deserialize, Serialize};
pub async fn acquire_mempool(context: &InteractionContext) -> Result<Slot> {
#[derive(Deserialize)]
struct Response {
slot: Slot,
}
let response: Response = context.request("acquireMempool", None::<()>).await?;
Ok(response.slot)
}
pub async fn has_transaction(context: &InteractionContext, id: &str) -> Result<bool> {
#[derive(Serialize)]
struct Params<'a> {
id: &'a str,
}
#[derive(Deserialize)]
struct Response {
#[serde(rename = "hasTransaction")]
has_transaction: bool,
}
let response: Response = context
.request("hasTransaction", Some(Params { id }))
.await?;
Ok(response.has_transaction)
}
pub async fn next_transaction_id(context: &InteractionContext) -> Result<Option<TransactionId>> {
#[derive(Deserialize)]
struct Response {
transaction: Option<TransactionWrapper>,
}
#[derive(Deserialize)]
#[serde(untagged)]
enum TransactionWrapper {
Id { id: TransactionId },
Full(Transaction),
}
let response: Response = context.request("nextTransaction", None::<()>).await?;
Ok(response.transaction.map(|t| match t {
TransactionWrapper::Id { id } => id,
TransactionWrapper::Full(tx) => tx.id,
}))
}
pub async fn next_transaction(context: &InteractionContext) -> Result<Option<Transaction>> {
#[derive(Serialize)]
struct Params {
fields: &'static str,
}
#[derive(Deserialize)]
struct Response {
transaction: Option<Transaction>,
}
let response: Response = context
.request("nextTransaction", Some(Params { fields: "all" }))
.await?;
Ok(response.transaction)
}
pub async fn size_of_mempool(context: &InteractionContext) -> Result<MempoolSizeAndCapacity> {
context.request("sizeOfMempool", None::<()>).await
}
pub async fn release_mempool(context: &InteractionContext) -> Result<()> {
let _: serde_json::Value = context.request("releaseMempool", None::<()>).await?;
Ok(())
}
#[cfg(test)]
mod tests {
#[test]
fn test_module_compiles() {
}
}