diff --git a/core/src/rpc_pubsub.rs b/core/src/rpc_pubsub.rs index 6cc152f15f..072336b0e8 100644 --- a/core/src/rpc_pubsub.rs +++ b/core/src/rpc_pubsub.rs @@ -3,12 +3,9 @@ use crate::rpc_subscriptions::{Confirmations, RpcSubscriptions, SlotInfo}; use jsonrpc_core::{Error, ErrorCode, Result}; use jsonrpc_derive::rpc; -use jsonrpc_pubsub::typed::Subscriber; -use jsonrpc_pubsub::{Session, SubscriptionId}; -use solana_sdk::account::Account; -use solana_sdk::pubkey::Pubkey; -use solana_sdk::signature::Signature; -use solana_sdk::transaction; +use jsonrpc_pubsub::{typed::Subscriber, Session, SubscriptionId}; +use solana_client::rpc_response::RpcKeyedAccount; +use solana_sdk::{account::Account, pubkey::Pubkey, signature::Signature, transaction}; use std::sync::{atomic, Arc}; // Suppress needless_return due to @@ -28,10 +25,10 @@ pub trait RpcSolPubSub { )] fn account_subscribe( &self, - _: Self::Metadata, - _: Subscriber, - _: String, - _: Option, + meta: Self::Metadata, + subscriber: Subscriber, + pubkey_str: String, + confirmations: Option, ); // Unsubscribe from account notification subscription. @@ -40,7 +37,8 @@ pub trait RpcSolPubSub { unsubscribe, name = "accountUnsubscribe" )] - fn account_unsubscribe(&self, _: Option, _: SubscriptionId) -> Result; + fn account_unsubscribe(&self, meta: Option, id: SubscriptionId) + -> Result; // Get notification every time account data owned by a particular program is changed // Accepts pubkey parameter as base-58 encoded string @@ -51,10 +49,10 @@ pub trait RpcSolPubSub { )] fn program_subscribe( &self, - _: Self::Metadata, - _: Subscriber<(String, Account)>, - _: String, - _: Option, + meta: Self::Metadata, + subscriber: Subscriber, + pubkey_str: String, + confirmations: Option, ); // Unsubscribe from account notification subscription. @@ -63,7 +61,8 @@ pub trait RpcSolPubSub { unsubscribe, name = "programUnsubscribe" )] - fn program_unsubscribe(&self, _: Option, _: SubscriptionId) -> Result; + fn program_unsubscribe(&self, meta: Option, id: SubscriptionId) + -> Result; // Get notification when signature is verified // Accepts signature parameter as base-58 encoded string @@ -74,10 +73,10 @@ pub trait RpcSolPubSub { )] fn signature_subscribe( &self, - _: Self::Metadata, - _: Subscriber>, - _: String, - _: Option, + meta: Self::Metadata, + subscriber: Subscriber>, + signature_str: String, + confirmations: Option, ); // Unsubscribe from signature notification subscription. @@ -86,11 +85,15 @@ pub trait RpcSolPubSub { unsubscribe, name = "signatureUnsubscribe" )] - fn signature_unsubscribe(&self, _: Option, _: SubscriptionId) -> Result; + fn signature_unsubscribe( + &self, + meta: Option, + id: SubscriptionId, + ) -> Result; // Get notification when slot is encountered #[pubsub(subscription = "slotNotification", subscribe, name = "slotSubscribe")] - fn slot_subscribe(&self, _: Self::Metadata, _: Subscriber); + fn slot_subscribe(&self, meta: Self::Metadata, subscriber: Subscriber); // Unsubscribe from slot notification subscription. #[pubsub( @@ -98,7 +101,7 @@ pub trait RpcSolPubSub { unsubscribe, name = "slotUnsubscribe" )] - fn slot_unsubscribe(&self, _: Option, _: SubscriptionId) -> Result; + fn slot_unsubscribe(&self, meta: Option, id: SubscriptionId) -> Result; } #[derive(Default)] @@ -168,7 +171,7 @@ impl RpcSolPubSub for RpcSolPubSubImpl { fn program_subscribe( &self, _meta: Self::Metadata, - subscriber: Subscriber<(String, Account)>, + subscriber: Subscriber, pubkey_str: String, confirmations: Option, ) { @@ -277,21 +280,18 @@ impl RpcSolPubSub for RpcSolPubSubImpl { mod tests { use super::*; use crate::genesis_utils::{create_genesis_config, GenesisConfigInfo}; - use jsonrpc_core::futures::sync::mpsc; - use jsonrpc_core::Response; + use jsonrpc_core::{futures::sync::mpsc, Response}; use jsonrpc_pubsub::{PubSubHandler, Session}; - use solana_budget_program; - use solana_budget_program::budget_instruction; + use solana_budget_program::{self, budget_instruction}; use solana_ledger::bank_forks::BankForks; use solana_runtime::bank::Bank; - use solana_sdk::pubkey::Pubkey; - use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_program; - use solana_sdk::system_transaction; - use solana_sdk::transaction::{self, Transaction}; - use std::sync::RwLock; - use std::thread::sleep; - use std::time::Duration; + use solana_sdk::{ + pubkey::Pubkey, + signature::{Keypair, KeypairUtil}, + system_program, system_transaction, + transaction::{self, Transaction}, + }; + use std::{sync::RwLock, thread::sleep, time::Duration}; use tokio::prelude::{Async, Stream}; fn process_transaction_and_notify( diff --git a/core/src/rpc_subscriptions.rs b/core/src/rpc_subscriptions.rs index d2fcf2a0a4..0760528c8f 100644 --- a/core/src/rpc_subscriptions.rs +++ b/core/src/rpc_subscriptions.rs @@ -4,14 +4,17 @@ use core::hash::Hash; use jsonrpc_core::futures::Future; use jsonrpc_pubsub::{typed::Sink, SubscriptionId}; use serde::Serialize; +use solana_client::rpc_response::RpcKeyedAccount; use solana_ledger::bank_forks::BankForks; use solana_runtime::bank::Bank; use solana_sdk::{ account::Account, clock::Slot, pubkey::Pubkey, signature::Signature, transaction, }; use solana_vote_program::vote_state::MAX_LOCKOUT_HISTORY; -use std::collections::HashMap; -use std::sync::{Arc, RwLock}; +use std::{ + collections::HashMap, + sync::{Arc, RwLock}, +}; pub type Confirmations = usize; @@ -25,7 +28,7 @@ pub struct SlotInfo { type RpcAccountSubscriptions = RwLock, Confirmations)>>>; type RpcProgramSubscriptions = - RwLock, Confirmations)>>>; + RwLock, Confirmations)>>>; type RpcSignatureSubscriptions = RwLock< HashMap>, Confirmations)>>, >; @@ -147,11 +150,14 @@ where } } -fn notify_program(accounts: Vec<(Pubkey, Account)>, sink: &Sink<(String, Account)>, _root: Slot) { +fn notify_program(accounts: Vec<(Pubkey, Account)>, sink: &Sink, _root: Slot) { for (pubkey, account) in accounts.iter() { - sink.notify(Ok((pubkey.to_string(), account.clone()))) - .wait() - .unwrap(); + sink.notify(Ok(RpcKeyedAccount { + pubkey: pubkey.to_string(), + account: account.clone(), + })) + .wait() + .unwrap(); } } @@ -247,7 +253,7 @@ impl RpcSubscriptions { program_id: &Pubkey, confirmations: Option, sub_id: &SubscriptionId, - sink: &Sink<(String, Account)>, + sink: &Sink, ) { let mut subscriptions = self.program_subscriptions.write().unwrap(); add_subscription(&mut subscriptions, program_id, confirmations, sub_id, sink); @@ -328,8 +334,10 @@ mod tests { use crate::genesis_utils::{create_genesis_config, GenesisConfigInfo}; use jsonrpc_pubsub::typed::Subscriber; use solana_budget_program; - use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_transaction; + use solana_sdk::{ + signature::{Keypair, KeypairUtil}, + system_transaction, + }; use tokio::prelude::{Async, Stream}; #[test] @@ -433,7 +441,7 @@ mod tests { let string = transport_receiver.poll(); if let Async::Ready(Some(response)) = string.unwrap() { let expected = format!( - r#"{{"jsonrpc":"2.0","method":"programNotification","params":{{"result":["{:?}",{{"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"executable":false,"lamports":1,"owner":[2,203,81,223,225,24,34,35,203,214,138,130,144,208,35,77,63,16,87,51,47,198,115,123,98,188,19,160,0,0,0,0],"rentEpoch":1}}],"subscription":0}}}}"#, + r#"{{"jsonrpc":"2.0","method":"programNotification","params":{{"result":{{"account":{{"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"executable":false,"lamports":1,"owner":[2,203,81,223,225,24,34,35,203,214,138,130,144,208,35,77,63,16,87,51,47,198,115,123,98,188,19,160,0,0,0,0],"rentEpoch":1}},"pubkey":"{:?}"}},"subscription":0}}}}"#, alice.pubkey() ); assert_eq!(expected, response);