commiting missing files

This commit is contained in:
Godmode Galactus 2023-06-11 16:11:04 +02:00
parent 3995d6ee39
commit bd59eeb7fd
No known key found for this signature in database
GPG Key ID: A04142C71ABB0DEA
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,8 @@
use async_trait::async_trait;
use solana_sdk::slot_history::Slot;
#[async_trait]
pub trait SubscriptionSink {
async fn send(&self, slot: Slot, message: serde_json::Value);
fn is_closed(&self) -> bool;
}

View File

@ -0,0 +1,41 @@
use async_trait::async_trait;
use jsonrpsee::{SubscriptionSink, SubscriptionMessage};
use solana_rpc_client_api::response::{RpcResponseContext, Response as RpcResponse};
pub struct JsonRpseeSubscriptionHandlerSink {
jsonrpsee_sink : SubscriptionSink,
}
impl JsonRpseeSubscriptionHandlerSink {
pub fn new(jsonrpsee_sink : SubscriptionSink) -> Self {
Self { jsonrpsee_sink }
}
}
#[async_trait]
impl solana_lite_rpc_core::subscription_sink::SubscriptionSink for JsonRpseeSubscriptionHandlerSink {
async fn send(&self, slot: solana_sdk::slot_history::Slot, message: serde_json::Value) {
let _ = self.jsonrpsee_sink.send(
SubscriptionMessage::from_json(&RpcResponse {
context: RpcResponseContext {
slot,
api_version: None,
},
value: message,
})
.unwrap(),
)
.await;
}
fn is_closed(&self) -> bool {
self.jsonrpsee_sink.is_closed()
}
}
unsafe impl Send for JsonRpseeSubscriptionHandlerSink {
}
unsafe impl Sync for JsonRpseeSubscriptionHandlerSink {
}