Add PubsubClient::vote_subscribe (#22114)
(cherry picked from commit 0a0fc85282
)
Co-authored-by: Kirill Fomichev <fanatid@ya.ru>
This commit is contained in:
@ -7,7 +7,7 @@ use {
|
|||||||
},
|
},
|
||||||
rpc_response::{
|
rpc_response::{
|
||||||
Response as RpcResponse, RpcBlockUpdate, RpcKeyedAccount, RpcLogsResponse,
|
Response as RpcResponse, RpcBlockUpdate, RpcKeyedAccount, RpcLogsResponse,
|
||||||
RpcSignatureResult, SlotInfo, SlotUpdate,
|
RpcSignatureResult, RpcVote, SlotInfo, SlotUpdate,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
log::*,
|
log::*,
|
||||||
@ -192,6 +192,9 @@ pub type AccountSubscription = (
|
|||||||
Receiver<RpcResponse<UiAccount>>,
|
Receiver<RpcResponse<UiAccount>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
pub type PubsubVoteClientSubscription = PubsubClientSubscription<RpcVote>;
|
||||||
|
pub type VoteSubscription = (PubsubVoteClientSubscription, Receiver<RpcVote>);
|
||||||
|
|
||||||
pub type PubsubRootClientSubscription = PubsubClientSubscription<Slot>;
|
pub type PubsubRootClientSubscription = PubsubClientSubscription<Slot>;
|
||||||
pub type RootSubscription = (PubsubRootClientSubscription, Receiver<Slot>);
|
pub type RootSubscription = (PubsubRootClientSubscription, Receiver<Slot>);
|
||||||
|
|
||||||
@ -392,6 +395,39 @@ impl PubsubClient {
|
|||||||
Ok((result, receiver))
|
Ok((result, receiver))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn vote_subscribe(url: &str) -> Result<VoteSubscription, PubsubClientError> {
|
||||||
|
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<RootSubscription, PubsubClientError> {
|
pub fn root_subscribe(url: &str) -> Result<RootSubscription, PubsubClientError> {
|
||||||
let url = Url::parse(url)?;
|
let url = Url::parse(url)?;
|
||||||
let socket = connect_with_retry(url)?;
|
let socket = connect_with_retry(url)?;
|
||||||
|
Reference in New Issue
Block a user