diff --git a/client/src/pubsub_client.rs b/client/src/pubsub_client.rs index ad82aa45ad..79b33b6e94 100644 --- a/client/src/pubsub_client.rs +++ b/client/src/pubsub_client.rs @@ -7,7 +7,7 @@ use { }, rpc_response::{ Response as RpcResponse, RpcBlockUpdate, RpcKeyedAccount, RpcLogsResponse, - RpcSignatureResult, SlotInfo, SlotUpdate, + RpcSignatureResult, RpcVote, SlotInfo, SlotUpdate, }, }, log::*, @@ -192,6 +192,9 @@ pub type AccountSubscription = ( Receiver>, ); +pub type PubsubVoteClientSubscription = PubsubClientSubscription; +pub type VoteSubscription = (PubsubVoteClientSubscription, Receiver); + pub type PubsubRootClientSubscription = PubsubClientSubscription; pub type RootSubscription = (PubsubRootClientSubscription, Receiver); @@ -392,6 +395,39 @@ impl PubsubClient { Ok((result, receiver)) } + pub fn vote_subscribe(url: &str) -> Result { + let url = Url::parse(url)?; + let socket = connect_with_retry(url)?; + let (sender, receiver) = channel(); + + let socket = Arc::new(RwLock::new(socket)); + let socket_clone = socket.clone(); + let exit = Arc::new(AtomicBool::new(false)); + let exit_clone = exit.clone(); + let body = json!({ + "jsonrpc":"2.0", + "id":1, + "method":"voteSubscribe", + }) + .to_string(); + let subscription_id = PubsubVoteClientSubscription::send_subscribe(&socket_clone, body)?; + + let t_cleanup = std::thread::spawn(move || { + Self::cleanup_with_sender(exit_clone, &socket_clone, sender) + }); + + let result = PubsubClientSubscription { + message_type: PhantomData, + operation: "vote", + socket, + subscription_id, + t_cleanup: Some(t_cleanup), + exit, + }; + + Ok((result, receiver)) + } + pub fn root_subscribe(url: &str) -> Result { let url = Url::parse(url)?; let socket = connect_with_retry(url)?;