2018-10-10 13:51:43 -07:00
|
|
|
//! The `pubsub` module implements a threaded subscription service on client RPC request
|
|
|
|
|
2019-01-21 09:59:09 -08:00
|
|
|
use crate::bank;
|
|
|
|
use crate::bank::{Bank, BankError, BankSubscriptions};
|
2018-12-07 19:16:27 -08:00
|
|
|
use crate::jsonrpc_core::futures::Future;
|
|
|
|
use crate::jsonrpc_core::*;
|
|
|
|
use crate::jsonrpc_macros::pubsub;
|
2019-01-21 09:59:09 -08:00
|
|
|
use crate::jsonrpc_macros::pubsub::Sink;
|
2018-12-07 19:16:27 -08:00
|
|
|
use crate::jsonrpc_pubsub::{PubSubHandler, Session, SubscriptionId};
|
|
|
|
use crate::jsonrpc_ws_server::{RequestContext, Sender, ServerBuilder};
|
2019-01-14 11:51:28 -08:00
|
|
|
use crate::rpc::RpcSignatureStatus;
|
2018-12-07 19:16:27 -08:00
|
|
|
use crate::service::Service;
|
2018-12-17 07:55:56 -08:00
|
|
|
use crate::status_deque::Status;
|
2018-10-10 13:51:43 -07:00
|
|
|
use bs58;
|
2018-10-25 11:13:08 -07:00
|
|
|
use solana_sdk::account::Account;
|
|
|
|
use solana_sdk::pubkey::Pubkey;
|
2019-01-21 09:59:09 -08:00
|
|
|
use solana_sdk::signature::Signature;
|
2018-10-10 13:51:43 -07:00
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::mem;
|
|
|
|
use std::net::SocketAddr;
|
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
2018-10-12 11:04:14 -07:00
|
|
|
use std::sync::{atomic, Arc, RwLock};
|
|
|
|
use std::thread::{self, sleep, Builder, JoinHandle};
|
2018-10-10 13:51:43 -07:00
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
pub enum ClientState {
|
|
|
|
Uninitialized,
|
|
|
|
Init(Sender),
|
|
|
|
}
|
|
|
|
|
2018-10-12 11:04:14 -07:00
|
|
|
pub struct PubSubService {
|
|
|
|
thread_hdl: JoinHandle<()>,
|
2018-10-25 16:58:40 -07:00
|
|
|
exit: Arc<AtomicBool>,
|
2019-01-21 09:59:09 -08:00
|
|
|
rpc_bank: Arc<RwLock<RpcPubSubBank>>,
|
|
|
|
subscription: Arc<RpcSubscriptions>,
|
2018-10-10 13:51:43 -07:00
|
|
|
}
|
|
|
|
|
2018-10-12 11:04:14 -07:00
|
|
|
impl Service for PubSubService {
|
|
|
|
type JoinReturnType = ();
|
|
|
|
|
|
|
|
fn join(self) -> thread::Result<()> {
|
|
|
|
self.thread_hdl.join()
|
|
|
|
}
|
2018-10-10 13:51:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl PubSubService {
|
2018-10-25 16:58:40 -07:00
|
|
|
pub fn new(bank: &Arc<Bank>, pubsub_addr: SocketAddr) -> Self {
|
2019-01-15 12:20:07 -08:00
|
|
|
info!("rpc_pubsub bound to {:?}", pubsub_addr);
|
2019-01-21 09:59:09 -08:00
|
|
|
let rpc_bank = Arc::new(RwLock::new(RpcPubSubBank::new(bank.clone())));
|
|
|
|
let rpc = RpcSolPubSubImpl::new(rpc_bank.clone());
|
|
|
|
let subscription = rpc.subscription.clone();
|
|
|
|
bank.set_subscriptions(Box::new(subscription.clone()));
|
2018-10-25 16:58:40 -07:00
|
|
|
let exit = Arc::new(AtomicBool::new(false));
|
|
|
|
let exit_ = exit.clone();
|
2018-10-12 11:04:14 -07:00
|
|
|
let thread_hdl = Builder::new()
|
2018-10-10 13:51:43 -07:00
|
|
|
.name("solana-pubsub".to_string())
|
|
|
|
.spawn(move || {
|
|
|
|
let mut io = PubSubHandler::default();
|
|
|
|
io.extend_with(rpc.to_delegate());
|
|
|
|
|
2018-10-12 11:04:14 -07:00
|
|
|
let server = ServerBuilder::with_meta_extractor(io, |context: &RequestContext| {
|
|
|
|
info!("New pubsub connection");
|
|
|
|
let session = Arc::new(Session::new(context.sender().clone()));
|
2018-12-07 15:15:16 -08:00
|
|
|
session.on_drop(|| {
|
2018-10-12 11:04:14 -07:00
|
|
|
info!("Pubsub connection dropped");
|
2018-12-07 15:15:16 -08:00
|
|
|
});
|
2018-10-12 11:04:14 -07:00
|
|
|
session
|
|
|
|
})
|
|
|
|
.start(&pubsub_addr);
|
2018-10-10 13:51:43 -07:00
|
|
|
|
2018-11-29 10:51:07 -08:00
|
|
|
if let Err(e) = server {
|
|
|
|
warn!("Pubsub service unavailable error: {:?}. \nAlso, check that port {} is not already in use by another application", e, pubsub_addr.port());
|
2018-10-10 13:51:43 -07:00
|
|
|
return;
|
|
|
|
}
|
2018-10-25 16:58:40 -07:00
|
|
|
while !exit_.load(Ordering::Relaxed) {
|
2018-10-10 13:51:43 -07:00
|
|
|
sleep(Duration::from_millis(100));
|
|
|
|
}
|
|
|
|
server.unwrap().close();
|
|
|
|
})
|
|
|
|
.unwrap();
|
2019-01-21 09:59:09 -08:00
|
|
|
PubSubService {
|
|
|
|
thread_hdl,
|
|
|
|
exit,
|
|
|
|
rpc_bank,
|
|
|
|
subscription,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_bank(&self, bank: &Arc<Bank>) {
|
|
|
|
self.rpc_bank.write().unwrap().bank = bank.clone();
|
|
|
|
bank.set_subscriptions(Box::new(self.subscription.clone()));
|
2018-10-25 16:58:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn exit(&self) {
|
|
|
|
self.exit.store(true, Ordering::Relaxed);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn close(self) -> thread::Result<()> {
|
|
|
|
self.exit();
|
|
|
|
self.join()
|
2018-10-10 13:51:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
build_rpc_trait! {
|
|
|
|
pub trait RpcSolPubSub {
|
|
|
|
type Metadata;
|
|
|
|
|
|
|
|
#[pubsub(name = "accountNotification")] {
|
|
|
|
// Get notification every time account userdata is changed
|
|
|
|
// Accepts pubkey parameter as base-58 encoded string
|
|
|
|
#[rpc(name = "accountSubscribe")]
|
|
|
|
fn account_subscribe(&self, Self::Metadata, pubsub::Subscriber<Account>, String);
|
|
|
|
|
|
|
|
// Unsubscribe from account notification subscription.
|
|
|
|
#[rpc(name = "accountUnsubscribe")]
|
2018-10-15 12:58:46 -07:00
|
|
|
fn account_unsubscribe(&self, SubscriptionId) -> Result<bool>;
|
2018-10-10 13:51:43 -07:00
|
|
|
}
|
|
|
|
#[pubsub(name = "signatureNotification")] {
|
|
|
|
// Get notification when signature is verified
|
|
|
|
// Accepts signature parameter as base-58 encoded string
|
|
|
|
#[rpc(name = "signatureSubscribe")]
|
|
|
|
fn signature_subscribe(&self, Self::Metadata, pubsub::Subscriber<RpcSignatureStatus>, String);
|
|
|
|
|
|
|
|
// Unsubscribe from signature notification subscription.
|
|
|
|
#[rpc(name = "signatureUnsubscribe")]
|
2018-10-15 12:58:46 -07:00
|
|
|
fn signature_unsubscribe(&self, SubscriptionId) -> Result<bool>;
|
2018-10-10 13:51:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 09:59:09 -08:00
|
|
|
struct RpcPubSubBank {
|
|
|
|
bank: Arc<Bank>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RpcPubSubBank {
|
|
|
|
pub fn new(bank: Arc<Bank>) -> Self {
|
|
|
|
RpcPubSubBank { bank }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct RpcSubscriptions {
|
|
|
|
account_subscriptions: RwLock<HashMap<Pubkey, HashMap<SubscriptionId, Sink<Account>>>>,
|
|
|
|
signature_subscriptions:
|
|
|
|
RwLock<HashMap<Signature, HashMap<SubscriptionId, Sink<RpcSignatureStatus>>>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for RpcSubscriptions {
|
|
|
|
fn default() -> Self {
|
|
|
|
RpcSubscriptions {
|
|
|
|
account_subscriptions: Default::default(),
|
|
|
|
signature_subscriptions: Default::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BankSubscriptions for RpcSubscriptions {
|
|
|
|
fn check_account(&self, pubkey: &Pubkey, account: &Account) {
|
|
|
|
let subscriptions = self.account_subscriptions.read().unwrap();
|
|
|
|
if let Some(hashmap) = subscriptions.get(pubkey) {
|
|
|
|
for (_bank_sub_id, sink) in hashmap.iter() {
|
|
|
|
sink.notify(Ok(account.clone())).wait().unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_signature(&self, signature: &Signature, bank_error: &bank::Result<()>) {
|
|
|
|
let status = match bank_error {
|
|
|
|
Ok(_) => RpcSignatureStatus::Confirmed,
|
|
|
|
Err(BankError::AccountInUse) => RpcSignatureStatus::AccountInUse,
|
|
|
|
Err(BankError::ProgramError(_, _)) => RpcSignatureStatus::ProgramRuntimeError,
|
|
|
|
Err(_) => RpcSignatureStatus::GenericFailure,
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut subscriptions = self.signature_subscriptions.write().unwrap();
|
|
|
|
if let Some(hashmap) = subscriptions.get(signature) {
|
|
|
|
for (_bank_sub_id, sink) in hashmap.iter() {
|
|
|
|
sink.notify(Ok(status)).wait().unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
subscriptions.remove(&signature);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RpcSubscriptions {
|
|
|
|
pub fn add_account_subscription(
|
|
|
|
&self,
|
|
|
|
pubkey: &Pubkey,
|
|
|
|
sub_id: &SubscriptionId,
|
|
|
|
sink: &Sink<Account>,
|
|
|
|
) {
|
|
|
|
let mut subscriptions = self.account_subscriptions.write().unwrap();
|
|
|
|
if let Some(current_hashmap) = subscriptions.get_mut(pubkey) {
|
|
|
|
current_hashmap.insert(sub_id.clone(), sink.clone());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let mut hashmap = HashMap::new();
|
|
|
|
hashmap.insert(sub_id.clone(), sink.clone());
|
|
|
|
subscriptions.insert(*pubkey, hashmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn remove_account_subscription(&self, id: &SubscriptionId) -> bool {
|
|
|
|
let mut subscriptions = self.account_subscriptions.write().unwrap();
|
|
|
|
let mut found = false;
|
|
|
|
subscriptions.retain(|_, v| {
|
|
|
|
v.retain(|k, _| {
|
|
|
|
if *k == *id {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
!found
|
|
|
|
});
|
|
|
|
!v.is_empty()
|
|
|
|
});
|
|
|
|
found
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_signature_subscription(
|
|
|
|
&self,
|
|
|
|
signature: &Signature,
|
|
|
|
sub_id: &SubscriptionId,
|
|
|
|
sink: &Sink<RpcSignatureStatus>,
|
|
|
|
) {
|
|
|
|
let mut subscriptions = self.signature_subscriptions.write().unwrap();
|
|
|
|
if let Some(current_hashmap) = subscriptions.get_mut(signature) {
|
|
|
|
current_hashmap.insert(sub_id.clone(), sink.clone());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let mut hashmap = HashMap::new();
|
|
|
|
hashmap.insert(sub_id.clone(), sink.clone());
|
|
|
|
subscriptions.insert(*signature, hashmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn remove_signature_subscription(&self, id: &SubscriptionId) -> bool {
|
|
|
|
let mut subscriptions = self.signature_subscriptions.write().unwrap();
|
|
|
|
let mut found = false;
|
|
|
|
subscriptions.retain(|_, v| {
|
|
|
|
v.retain(|k, _| {
|
|
|
|
if *k == *id {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
!found
|
|
|
|
});
|
|
|
|
!v.is_empty()
|
|
|
|
});
|
|
|
|
found
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-10 13:51:43 -07:00
|
|
|
struct RpcSolPubSubImpl {
|
2018-10-12 11:04:14 -07:00
|
|
|
uid: Arc<atomic::AtomicUsize>,
|
2019-01-21 09:59:09 -08:00
|
|
|
bank: Arc<RwLock<RpcPubSubBank>>,
|
|
|
|
subscription: Arc<RpcSubscriptions>,
|
2018-10-10 13:51:43 -07:00
|
|
|
}
|
2018-10-12 11:04:14 -07:00
|
|
|
|
|
|
|
impl RpcSolPubSubImpl {
|
2019-01-21 09:59:09 -08:00
|
|
|
fn new(bank: Arc<RwLock<RpcPubSubBank>>) -> Self {
|
2018-10-12 11:04:14 -07:00
|
|
|
RpcSolPubSubImpl {
|
|
|
|
uid: Default::default(),
|
|
|
|
bank,
|
2019-01-21 09:59:09 -08:00
|
|
|
subscription: Arc::new(Default::default()),
|
2018-10-12 11:04:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-10 13:51:43 -07:00
|
|
|
impl RpcSolPubSub for RpcSolPubSubImpl {
|
2018-10-12 11:04:14 -07:00
|
|
|
type Metadata = Arc<Session>;
|
2018-10-10 13:51:43 -07:00
|
|
|
|
|
|
|
fn account_subscribe(
|
|
|
|
&self,
|
2018-10-12 11:04:14 -07:00
|
|
|
_meta: Self::Metadata,
|
2018-10-10 13:51:43 -07:00
|
|
|
subscriber: pubsub::Subscriber<Account>,
|
|
|
|
pubkey_str: String,
|
|
|
|
) {
|
|
|
|
let pubkey_vec = bs58::decode(pubkey_str).into_vec().unwrap();
|
|
|
|
if pubkey_vec.len() != mem::size_of::<Pubkey>() {
|
|
|
|
subscriber
|
|
|
|
.reject(Error {
|
|
|
|
code: ErrorCode::InvalidParams,
|
|
|
|
message: "Invalid Request: Invalid pubkey provided".into(),
|
|
|
|
data: None,
|
2018-12-07 19:01:28 -08:00
|
|
|
})
|
|
|
|
.unwrap();
|
2018-10-10 13:51:43 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
let pubkey = Pubkey::new(&pubkey_vec);
|
|
|
|
|
|
|
|
let id = self.uid.fetch_add(1, atomic::Ordering::SeqCst);
|
|
|
|
let sub_id = SubscriptionId::Number(id as u64);
|
2018-10-30 11:47:14 -07:00
|
|
|
info!("account_subscribe: account={:?} id={:?}", pubkey, sub_id);
|
2018-10-10 13:51:43 -07:00
|
|
|
let sink = subscriber.assign_id(sub_id.clone()).unwrap();
|
|
|
|
|
2019-01-21 09:59:09 -08:00
|
|
|
self.subscription
|
|
|
|
.add_account_subscription(&pubkey, &sub_id, &sink)
|
2018-10-10 13:51:43 -07:00
|
|
|
}
|
|
|
|
|
2018-10-15 12:58:46 -07:00
|
|
|
fn account_unsubscribe(&self, id: SubscriptionId) -> Result<bool> {
|
2018-10-30 11:47:14 -07:00
|
|
|
info!("account_unsubscribe: id={:?}", id);
|
2019-01-21 09:59:09 -08:00
|
|
|
if self.subscription.remove_account_subscription(&id) {
|
2018-10-10 13:51:43 -07:00
|
|
|
Ok(true)
|
|
|
|
} else {
|
|
|
|
Err(Error {
|
|
|
|
code: ErrorCode::InvalidParams,
|
|
|
|
message: "Invalid Request: Subscription id does not exist".into(),
|
|
|
|
data: None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signature_subscribe(
|
|
|
|
&self,
|
2018-10-12 11:04:14 -07:00
|
|
|
_meta: Self::Metadata,
|
2018-10-10 13:51:43 -07:00
|
|
|
subscriber: pubsub::Subscriber<RpcSignatureStatus>,
|
|
|
|
signature_str: String,
|
|
|
|
) {
|
2018-10-12 11:04:14 -07:00
|
|
|
info!("signature_subscribe");
|
2018-10-10 13:51:43 -07:00
|
|
|
let signature_vec = bs58::decode(signature_str).into_vec().unwrap();
|
|
|
|
if signature_vec.len() != mem::size_of::<Signature>() {
|
|
|
|
subscriber
|
|
|
|
.reject(Error {
|
|
|
|
code: ErrorCode::InvalidParams,
|
|
|
|
message: "Invalid Request: Invalid signature provided".into(),
|
|
|
|
data: None,
|
2018-12-07 19:01:28 -08:00
|
|
|
})
|
|
|
|
.unwrap();
|
2018-10-10 13:51:43 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
let signature = Signature::new(&signature_vec);
|
|
|
|
let id = self.uid.fetch_add(1, atomic::Ordering::SeqCst);
|
|
|
|
let sub_id = SubscriptionId::Number(id as u64);
|
|
|
|
let sink = subscriber.assign_id(sub_id.clone()).unwrap();
|
|
|
|
|
2019-01-21 09:59:09 -08:00
|
|
|
let status = self
|
|
|
|
.bank
|
|
|
|
.read()
|
|
|
|
.unwrap()
|
|
|
|
.bank
|
|
|
|
.get_signature_status(&signature);
|
2018-12-17 07:55:56 -08:00
|
|
|
if status.is_none() {
|
2019-01-21 09:59:09 -08:00
|
|
|
self.subscription
|
|
|
|
.add_signature_subscription(&signature, &sub_id, &sink);
|
2018-12-17 07:55:56 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
match status.unwrap() {
|
|
|
|
Status::Complete(Ok(_)) => {
|
2018-10-10 13:51:43 -07:00
|
|
|
sink.notify(Ok(RpcSignatureStatus::Confirmed))
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
}
|
2019-01-21 09:59:09 -08:00
|
|
|
_ => self
|
|
|
|
.subscription
|
|
|
|
.add_signature_subscription(&signature, &sub_id, &sink),
|
2018-10-10 13:51:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-15 12:58:46 -07:00
|
|
|
fn signature_unsubscribe(&self, id: SubscriptionId) -> Result<bool> {
|
2018-10-12 11:04:14 -07:00
|
|
|
info!("signature_unsubscribe");
|
2019-01-21 09:59:09 -08:00
|
|
|
if self.subscription.remove_signature_subscription(&id) {
|
2018-10-10 13:51:43 -07:00
|
|
|
Ok(true)
|
|
|
|
} else {
|
|
|
|
Err(Error {
|
|
|
|
code: ErrorCode::InvalidParams,
|
|
|
|
message: "Invalid Request: Subscription id does not exist".into(),
|
|
|
|
data: None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2018-12-07 19:16:27 -08:00
|
|
|
use crate::jsonrpc_core::futures::sync::mpsc;
|
2019-01-21 09:59:09 -08:00
|
|
|
use crate::jsonrpc_macros::pubsub::{Subscriber, SubscriptionId};
|
2018-12-07 19:16:27 -08:00
|
|
|
use crate::mint::Mint;
|
2018-12-04 14:38:19 -08:00
|
|
|
use solana_sdk::budget_program;
|
|
|
|
use solana_sdk::budget_transaction::BudgetTransaction;
|
2018-12-03 10:26:28 -08:00
|
|
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
2018-12-04 20:19:48 -08:00
|
|
|
use solana_sdk::system_transaction::SystemTransaction;
|
2018-11-29 16:18:47 -08:00
|
|
|
use solana_sdk::transaction::Transaction;
|
2018-10-10 13:51:43 -07:00
|
|
|
use std::net::{IpAddr, Ipv4Addr};
|
|
|
|
use tokio::prelude::{Async, Stream};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_pubsub_new() {
|
|
|
|
let alice = Mint::new(10_000);
|
|
|
|
let bank = Bank::new(&alice);
|
|
|
|
let pubsub_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0);
|
2018-10-25 16:58:40 -07:00
|
|
|
let pubsub_service = PubSubService::new(&Arc::new(bank), pubsub_addr);
|
2018-10-12 11:04:14 -07:00
|
|
|
let thread = pubsub_service.thread_hdl.thread();
|
2018-10-10 13:51:43 -07:00
|
|
|
assert_eq!(thread.name().unwrap(), "solana-pubsub");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2018-12-17 07:55:56 -08:00
|
|
|
#[ignore]
|
2018-10-10 13:51:43 -07:00
|
|
|
fn test_signature_subscribe() {
|
|
|
|
let alice = Mint::new(10_000);
|
|
|
|
let bob = Keypair::new();
|
|
|
|
let bob_pubkey = bob.pubkey();
|
|
|
|
let bank = Bank::new(&alice);
|
|
|
|
let arc_bank = Arc::new(bank);
|
|
|
|
let last_id = arc_bank.last_id();
|
|
|
|
|
|
|
|
let (sender, mut receiver) = mpsc::channel(1);
|
|
|
|
let session = Arc::new(Session::new(sender));
|
|
|
|
|
|
|
|
let mut io = PubSubHandler::default();
|
2019-01-21 09:59:09 -08:00
|
|
|
let rpc_bank = Arc::new(RwLock::new(RpcPubSubBank::new(arc_bank.clone())));
|
|
|
|
let rpc = RpcSolPubSubImpl::new(rpc_bank.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
io.extend_with(rpc.to_delegate());
|
|
|
|
|
|
|
|
// Test signature subscription
|
|
|
|
let tx = Transaction::system_move(&alice.keypair(), bob_pubkey, 20, last_id, 0);
|
|
|
|
|
|
|
|
let req = format!(
|
|
|
|
r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["{}"]}}"#,
|
2018-10-26 14:43:34 -07:00
|
|
|
tx.signatures[0].to_string()
|
2018-10-10 13:51:43 -07:00
|
|
|
);
|
2018-10-12 11:04:14 -07:00
|
|
|
let res = io.handle_request_sync(&req, session.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
let expected = format!(r#"{{"jsonrpc":"2.0","result":0,"id":1}}"#);
|
|
|
|
let expected: Response =
|
|
|
|
serde_json::from_str(&expected).expect("expected response deserialization");
|
|
|
|
|
|
|
|
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
|
|
|
.expect("actual response deserialization");
|
|
|
|
assert_eq!(expected, result);
|
|
|
|
|
|
|
|
// Test bad parameter
|
|
|
|
let req = format!(
|
|
|
|
r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["a1b2c3"]}}"#
|
|
|
|
);
|
2018-10-12 11:04:14 -07:00
|
|
|
let res = io.handle_request_sync(&req, session.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
let expected = format!(r#"{{"jsonrpc":"2.0","error":{{"code":-32602,"message":"Invalid Request: Invalid signature provided"}},"id":1}}"#);
|
|
|
|
let expected: Response =
|
|
|
|
serde_json::from_str(&expected).expect("expected response deserialization");
|
|
|
|
|
|
|
|
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
|
|
|
.expect("actual response deserialization");
|
|
|
|
assert_eq!(expected, result);
|
|
|
|
|
|
|
|
arc_bank
|
|
|
|
.process_transaction(&tx)
|
|
|
|
.expect("process transaction");
|
|
|
|
sleep(Duration::from_millis(200));
|
|
|
|
|
|
|
|
// Test signature confirmation notification
|
|
|
|
let string = receiver.poll();
|
|
|
|
assert!(string.is_ok());
|
|
|
|
if let Async::Ready(Some(response)) = string.unwrap() {
|
|
|
|
let expected = format!(r#"{{"jsonrpc":"2.0","method":"signatureNotification","params":{{"result":"Confirmed","subscription":0}}}}"#);
|
|
|
|
assert_eq!(expected, response);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test subscription id increment
|
|
|
|
let tx = Transaction::system_move(&alice.keypair(), bob_pubkey, 10, last_id, 0);
|
|
|
|
let req = format!(
|
|
|
|
r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["{}"]}}"#,
|
2018-10-26 14:43:34 -07:00
|
|
|
tx.signatures[0].to_string()
|
2018-10-10 13:51:43 -07:00
|
|
|
);
|
2018-10-12 11:04:14 -07:00
|
|
|
let res = io.handle_request_sync(&req, session.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
let expected = format!(r#"{{"jsonrpc":"2.0","result":1,"id":1}}"#);
|
|
|
|
let expected: Response =
|
|
|
|
serde_json::from_str(&expected).expect("expected response deserialization");
|
|
|
|
|
|
|
|
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
|
|
|
.expect("actual response deserialization");
|
|
|
|
assert_eq!(expected, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_signature_unsubscribe() {
|
|
|
|
let alice = Mint::new(10_000);
|
|
|
|
let bob_pubkey = Keypair::new().pubkey();
|
|
|
|
let bank = Bank::new(&alice);
|
|
|
|
let arc_bank = Arc::new(bank);
|
|
|
|
let last_id = arc_bank.last_id();
|
|
|
|
|
|
|
|
let (sender, _receiver) = mpsc::channel(1);
|
|
|
|
let session = Arc::new(Session::new(sender));
|
|
|
|
|
|
|
|
let mut io = PubSubHandler::default();
|
2019-01-21 09:59:09 -08:00
|
|
|
let rpc_bank = Arc::new(RwLock::new(RpcPubSubBank::new(arc_bank.clone())));
|
|
|
|
let rpc = RpcSolPubSubImpl::new(rpc_bank.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
io.extend_with(rpc.to_delegate());
|
|
|
|
|
|
|
|
let tx = Transaction::system_move(&alice.keypair(), bob_pubkey, 20, last_id, 0);
|
|
|
|
let req = format!(
|
|
|
|
r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["{}"]}}"#,
|
2018-10-26 14:43:34 -07:00
|
|
|
tx.signatures[0].to_string()
|
2018-10-10 13:51:43 -07:00
|
|
|
);
|
2018-10-12 11:04:14 -07:00
|
|
|
let _res = io.handle_request_sync(&req, session.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
|
|
|
|
let req =
|
|
|
|
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"signatureUnsubscribe","params":[0]}}"#);
|
2018-10-12 11:04:14 -07:00
|
|
|
let res = io.handle_request_sync(&req, session.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
|
|
|
|
let expected = format!(r#"{{"jsonrpc":"2.0","result":true,"id":1}}"#);
|
|
|
|
let expected: Response =
|
|
|
|
serde_json::from_str(&expected).expect("expected response deserialization");
|
|
|
|
|
|
|
|
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
|
|
|
.expect("actual response deserialization");
|
|
|
|
assert_eq!(expected, result);
|
|
|
|
|
|
|
|
// Test bad parameter
|
|
|
|
let req =
|
|
|
|
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"signatureUnsubscribe","params":[1]}}"#);
|
2018-10-12 11:04:14 -07:00
|
|
|
let res = io.handle_request_sync(&req, session.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
let expected = format!(r#"{{"jsonrpc":"2.0","error":{{"code":-32602,"message":"Invalid Request: Subscription id does not exist"}},"id":1}}"#);
|
|
|
|
let expected: Response =
|
|
|
|
serde_json::from_str(&expected).expect("expected response deserialization");
|
|
|
|
|
|
|
|
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
|
|
|
.expect("actual response deserialization");
|
|
|
|
assert_eq!(expected, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2018-12-17 07:55:56 -08:00
|
|
|
#[ignore]
|
2018-10-10 13:51:43 -07:00
|
|
|
fn test_account_subscribe() {
|
|
|
|
let alice = Mint::new(10_000);
|
|
|
|
let bob_pubkey = Keypair::new().pubkey();
|
|
|
|
let witness = Keypair::new();
|
|
|
|
let contract_funds = Keypair::new();
|
|
|
|
let contract_state = Keypair::new();
|
2018-11-23 12:45:34 -08:00
|
|
|
let budget_program_id = budget_program::id();
|
2018-11-12 09:11:24 -08:00
|
|
|
let loader = Pubkey::default(); // TODO
|
2018-10-16 09:43:49 -07:00
|
|
|
let executable = false; // TODO
|
2018-10-10 13:51:43 -07:00
|
|
|
let bank = Bank::new(&alice);
|
|
|
|
let arc_bank = Arc::new(bank);
|
|
|
|
let last_id = arc_bank.last_id();
|
|
|
|
|
|
|
|
let (sender, mut receiver) = mpsc::channel(1);
|
|
|
|
let session = Arc::new(Session::new(sender));
|
|
|
|
|
|
|
|
let mut io = PubSubHandler::default();
|
2019-01-21 09:59:09 -08:00
|
|
|
let rpc_bank = Arc::new(RwLock::new(RpcPubSubBank::new(arc_bank.clone())));
|
|
|
|
let rpc = RpcSolPubSubImpl::new(rpc_bank.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
io.extend_with(rpc.to_delegate());
|
|
|
|
|
|
|
|
let req = format!(
|
|
|
|
r#"{{"jsonrpc":"2.0","id":1,"method":"accountSubscribe","params":["{}"]}}"#,
|
|
|
|
contract_state.pubkey().to_string()
|
|
|
|
);
|
|
|
|
|
2018-10-12 11:04:14 -07:00
|
|
|
let res = io.handle_request_sync(&req, session.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
let expected = format!(r#"{{"jsonrpc":"2.0","result":0,"id":1}}"#);
|
|
|
|
let expected: Response =
|
|
|
|
serde_json::from_str(&expected).expect("expected response deserialization");
|
|
|
|
|
|
|
|
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
|
|
|
.expect("actual response deserialization");
|
|
|
|
assert_eq!(expected, result);
|
|
|
|
|
|
|
|
// Test bad parameter
|
|
|
|
let req = format!(
|
|
|
|
r#"{{"jsonrpc":"2.0","id":1,"method":"accountSubscribe","params":["a1b2c3"]}}"#
|
|
|
|
);
|
2018-10-12 11:04:14 -07:00
|
|
|
let res = io.handle_request_sync(&req, session.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
let expected = format!(r#"{{"jsonrpc":"2.0","error":{{"code":-32602,"message":"Invalid Request: Invalid pubkey provided"}},"id":1}}"#);
|
|
|
|
let expected: Response =
|
|
|
|
serde_json::from_str(&expected).expect("expected response deserialization");
|
|
|
|
|
|
|
|
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
|
|
|
.expect("actual response deserialization");
|
|
|
|
assert_eq!(expected, result);
|
|
|
|
|
|
|
|
let tx = Transaction::system_create(
|
|
|
|
&alice.keypair(),
|
|
|
|
contract_funds.pubkey(),
|
|
|
|
last_id,
|
|
|
|
50,
|
|
|
|
0,
|
|
|
|
budget_program_id,
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
arc_bank
|
|
|
|
.process_transaction(&tx)
|
|
|
|
.expect("process transaction");
|
|
|
|
|
|
|
|
let tx = Transaction::system_create(
|
|
|
|
&alice.keypair(),
|
|
|
|
contract_state.pubkey(),
|
|
|
|
last_id,
|
|
|
|
1,
|
|
|
|
196,
|
|
|
|
budget_program_id,
|
|
|
|
0,
|
|
|
|
);
|
2018-10-12 11:04:14 -07:00
|
|
|
|
2018-10-10 13:51:43 -07:00
|
|
|
arc_bank
|
|
|
|
.process_transaction(&tx)
|
|
|
|
.expect("process transaction");
|
|
|
|
|
|
|
|
// Test signature confirmation notification #1
|
|
|
|
let string = receiver.poll();
|
|
|
|
assert!(string.is_ok());
|
2018-10-12 11:04:14 -07:00
|
|
|
|
2018-10-10 13:51:43 -07:00
|
|
|
let expected_userdata = arc_bank
|
|
|
|
.get_account(&contract_state.pubkey())
|
|
|
|
.unwrap()
|
|
|
|
.userdata;
|
2018-10-12 11:04:14 -07:00
|
|
|
|
2018-10-10 13:51:43 -07:00
|
|
|
let expected = json!({
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"method": "accountNotification",
|
|
|
|
"params": {
|
|
|
|
"result": {
|
2018-11-12 09:29:17 -08:00
|
|
|
"owner": budget_program_id,
|
2018-10-10 13:51:43 -07:00
|
|
|
"tokens": 1,
|
2018-10-16 09:43:49 -07:00
|
|
|
"userdata": expected_userdata,
|
|
|
|
"executable": executable,
|
2018-11-12 09:11:24 -08:00
|
|
|
"loader": loader,
|
2018-10-16 09:43:49 -07:00
|
|
|
|
2018-10-10 13:51:43 -07:00
|
|
|
},
|
|
|
|
"subscription": 0,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if let Async::Ready(Some(response)) = string.unwrap() {
|
|
|
|
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
|
|
|
}
|
|
|
|
|
|
|
|
let tx = Transaction::budget_new_when_signed(
|
|
|
|
&contract_funds,
|
|
|
|
bob_pubkey,
|
|
|
|
contract_state.pubkey(),
|
|
|
|
witness.pubkey(),
|
|
|
|
None,
|
|
|
|
50,
|
|
|
|
last_id,
|
|
|
|
);
|
|
|
|
arc_bank
|
|
|
|
.process_transaction(&tx)
|
|
|
|
.expect("process transaction");
|
|
|
|
sleep(Duration::from_millis(200));
|
|
|
|
|
|
|
|
// Test signature confirmation notification #2
|
|
|
|
let string = receiver.poll();
|
|
|
|
assert!(string.is_ok());
|
|
|
|
let expected_userdata = arc_bank
|
|
|
|
.get_account(&contract_state.pubkey())
|
|
|
|
.unwrap()
|
|
|
|
.userdata;
|
|
|
|
let expected = json!({
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"method": "accountNotification",
|
|
|
|
"params": {
|
|
|
|
"result": {
|
2018-11-12 09:29:17 -08:00
|
|
|
"owner": budget_program_id,
|
2018-10-10 13:51:43 -07:00
|
|
|
"tokens": 51,
|
2018-10-16 09:43:49 -07:00
|
|
|
"userdata": expected_userdata,
|
|
|
|
"executable": executable,
|
2018-11-12 09:11:24 -08:00
|
|
|
"loader": loader,
|
2018-10-10 13:51:43 -07:00
|
|
|
},
|
|
|
|
"subscription": 0,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if let Async::Ready(Some(response)) = string.unwrap() {
|
|
|
|
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
|
|
|
}
|
|
|
|
|
|
|
|
let tx = Transaction::system_new(&alice.keypair(), witness.pubkey(), 1, last_id);
|
|
|
|
arc_bank
|
|
|
|
.process_transaction(&tx)
|
|
|
|
.expect("process transaction");
|
|
|
|
sleep(Duration::from_millis(200));
|
|
|
|
let tx = Transaction::budget_new_signature(
|
|
|
|
&witness,
|
|
|
|
contract_state.pubkey(),
|
|
|
|
bob_pubkey,
|
|
|
|
last_id,
|
|
|
|
);
|
|
|
|
arc_bank
|
|
|
|
.process_transaction(&tx)
|
|
|
|
.expect("process transaction");
|
|
|
|
sleep(Duration::from_millis(200));
|
|
|
|
|
|
|
|
let expected_userdata = arc_bank
|
|
|
|
.get_account(&contract_state.pubkey())
|
|
|
|
.unwrap()
|
|
|
|
.userdata;
|
|
|
|
let expected = json!({
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"method": "accountNotification",
|
|
|
|
"params": {
|
|
|
|
"result": {
|
2018-11-12 09:29:17 -08:00
|
|
|
"owner": budget_program_id,
|
2018-10-10 13:51:43 -07:00
|
|
|
"tokens": 1,
|
2018-10-16 09:43:49 -07:00
|
|
|
"userdata": expected_userdata,
|
|
|
|
"executable": executable,
|
2018-11-12 09:11:24 -08:00
|
|
|
"loader": loader,
|
2018-10-10 13:51:43 -07:00
|
|
|
},
|
|
|
|
"subscription": 0,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let string = receiver.poll();
|
|
|
|
assert!(string.is_ok());
|
|
|
|
if let Async::Ready(Some(response)) = string.unwrap() {
|
|
|
|
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_account_unsubscribe() {
|
|
|
|
let alice = Mint::new(10_000);
|
|
|
|
let bob_pubkey = Keypair::new().pubkey();
|
|
|
|
let bank = Bank::new(&alice);
|
|
|
|
let arc_bank = Arc::new(bank);
|
|
|
|
|
|
|
|
let (sender, _receiver) = mpsc::channel(1);
|
|
|
|
let session = Arc::new(Session::new(sender));
|
|
|
|
|
|
|
|
let mut io = PubSubHandler::default();
|
2019-01-21 09:59:09 -08:00
|
|
|
let rpc_bank = Arc::new(RwLock::new(RpcPubSubBank::new(arc_bank.clone())));
|
|
|
|
let rpc = RpcSolPubSubImpl::new(rpc_bank.clone());
|
2018-10-12 11:04:14 -07:00
|
|
|
|
2018-10-10 13:51:43 -07:00
|
|
|
io.extend_with(rpc.to_delegate());
|
|
|
|
|
|
|
|
let req = format!(
|
|
|
|
r#"{{"jsonrpc":"2.0","id":1,"method":"accountSubscribe","params":["{}"]}}"#,
|
|
|
|
bob_pubkey.to_string()
|
|
|
|
);
|
2018-10-12 11:04:14 -07:00
|
|
|
let _res = io.handle_request_sync(&req, session.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
|
|
|
|
let req =
|
|
|
|
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"accountUnsubscribe","params":[0]}}"#);
|
2018-10-12 11:04:14 -07:00
|
|
|
let res = io.handle_request_sync(&req, session.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
|
|
|
|
let expected = format!(r#"{{"jsonrpc":"2.0","result":true,"id":1}}"#);
|
|
|
|
let expected: Response =
|
|
|
|
serde_json::from_str(&expected).expect("expected response deserialization");
|
|
|
|
|
|
|
|
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
|
|
|
.expect("actual response deserialization");
|
|
|
|
assert_eq!(expected, result);
|
|
|
|
|
|
|
|
// Test bad parameter
|
|
|
|
let req =
|
|
|
|
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"accountUnsubscribe","params":[1]}}"#);
|
2018-10-12 11:04:14 -07:00
|
|
|
let res = io.handle_request_sync(&req, session.clone());
|
2018-10-10 13:51:43 -07:00
|
|
|
let expected = format!(r#"{{"jsonrpc":"2.0","error":{{"code":-32602,"message":"Invalid Request: Subscription id does not exist"}},"id":1}}"#);
|
|
|
|
let expected: Response =
|
|
|
|
serde_json::from_str(&expected).expect("expected response deserialization");
|
|
|
|
|
|
|
|
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
|
|
|
.expect("actual response deserialization");
|
|
|
|
assert_eq!(expected, result);
|
|
|
|
}
|
2019-01-21 09:59:09 -08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_check_account_subscribe() {
|
|
|
|
let mint = Mint::new(100);
|
|
|
|
let bank = Bank::new(&mint);
|
|
|
|
let alice = Keypair::new();
|
|
|
|
let last_id = bank.last_id();
|
|
|
|
let tx = Transaction::system_create(
|
|
|
|
&mint.keypair(),
|
|
|
|
alice.pubkey(),
|
|
|
|
last_id,
|
|
|
|
1,
|
|
|
|
16,
|
|
|
|
budget_program::id(),
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
bank.process_transaction(&tx).unwrap();
|
|
|
|
|
|
|
|
let (subscriber, _id_receiver, mut transport_receiver) =
|
|
|
|
Subscriber::new_test("accountNotification");
|
|
|
|
let sub_id = SubscriptionId::Number(0 as u64);
|
|
|
|
let sink = subscriber.assign_id(sub_id.clone()).unwrap();
|
|
|
|
let subscriptions = RpcSubscriptions::default();
|
|
|
|
subscriptions.add_account_subscription(&alice.pubkey(), &sub_id, &sink);
|
|
|
|
|
|
|
|
assert!(subscriptions
|
|
|
|
.account_subscriptions
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.contains_key(&alice.pubkey()));
|
|
|
|
|
|
|
|
let account = bank.get_account(&alice.pubkey()).unwrap();
|
|
|
|
subscriptions.check_account(&alice.pubkey(), &account);
|
|
|
|
let string = transport_receiver.poll();
|
|
|
|
assert!(string.is_ok());
|
|
|
|
if let Async::Ready(Some(response)) = string.unwrap() {
|
|
|
|
let expected = format!(r#"{{"jsonrpc":"2.0","method":"accountNotification","params":{{"result":{{"executable":false,"loader":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"owner":[129,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tokens":1,"userdata":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},"subscription":0}}}}"#);
|
|
|
|
assert_eq!(expected, response);
|
|
|
|
}
|
|
|
|
|
|
|
|
subscriptions.remove_account_subscription(&sub_id);
|
|
|
|
assert!(!subscriptions
|
|
|
|
.account_subscriptions
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.contains_key(&alice.pubkey()));
|
|
|
|
}
|
|
|
|
#[test]
|
|
|
|
fn test_check_signature_subscribe() {
|
|
|
|
let mint = Mint::new(100);
|
|
|
|
let bank = Bank::new(&mint);
|
|
|
|
let alice = Keypair::new();
|
|
|
|
let last_id = bank.last_id();
|
|
|
|
let tx = Transaction::system_move(&mint.keypair(), alice.pubkey(), 20, last_id, 0);
|
|
|
|
let signature = tx.signatures[0];
|
|
|
|
bank.process_transaction(&tx).unwrap();
|
|
|
|
|
|
|
|
let (subscriber, _id_receiver, mut transport_receiver) =
|
|
|
|
Subscriber::new_test("signatureNotification");
|
|
|
|
let sub_id = SubscriptionId::Number(0 as u64);
|
|
|
|
let sink = subscriber.assign_id(sub_id.clone()).unwrap();
|
|
|
|
let subscriptions = RpcSubscriptions::default();
|
|
|
|
subscriptions.add_signature_subscription(&signature, &sub_id, &sink);
|
|
|
|
|
|
|
|
assert!(subscriptions
|
|
|
|
.signature_subscriptions
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.contains_key(&signature));
|
|
|
|
|
|
|
|
subscriptions.check_signature(&signature, &Ok(()));
|
|
|
|
let string = transport_receiver.poll();
|
|
|
|
assert!(string.is_ok());
|
|
|
|
if let Async::Ready(Some(response)) = string.unwrap() {
|
|
|
|
let expected = format!(r#"{{"jsonrpc":"2.0","method":"signatureNotification","params":{{"result":"Confirmed","subscription":0}}}}"#);
|
|
|
|
assert_eq!(expected, response);
|
|
|
|
}
|
|
|
|
|
|
|
|
subscriptions.remove_signature_subscription(&sub_id);
|
|
|
|
assert!(!subscriptions
|
|
|
|
.signature_subscriptions
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.contains_key(&signature));
|
|
|
|
}
|
2018-10-10 13:51:43 -07:00
|
|
|
}
|