This repository was archived by the owner on Nov 6, 2020. It is now read-only.
  
  
  - 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.7k
 
Allow making direct RPC queries from the C API #8588
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -41,7 +41,7 @@ use miner::external::ExternalMiner; | |
| use node_filter::NodeFilter; | ||
| use node_health; | ||
| use parity_reactor::EventLoop; | ||
| use parity_rpc::{NetworkSettings, informant, is_major_importing}; | ||
| use parity_rpc::{Origin, Metadata, NetworkSettings, informant, is_major_importing}; | ||
| use updater::{UpdatePolicy, Updater}; | ||
| use parity_version::version; | ||
| use ethcore_private_tx::{ProviderConfig, EncryptorConfig, SecretStoreEncryptor}; | ||
| 
        
          
        
         | 
    @@ -56,6 +56,7 @@ use cache::CacheConfig; | |
| use user_defaults::UserDefaults; | ||
| use dapps; | ||
| use ipfs; | ||
| use jsonrpc_core; | ||
| use modules; | ||
| use rpc; | ||
| use rpc_apis; | ||
| 
          
            
          
           | 
    @@ -369,6 +370,7 @@ fn execute_light_impl(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<Runnin | |
| }; | ||
| 
     | 
||
| // start rpc servers | ||
| let rpc_direct = rpc::setup_apis(rpc_apis::ApiSet::All, &dependencies); | ||
| let ws_server = rpc::new_ws(cmd.ws_conf, &dependencies)?; | ||
| let http_server = rpc::new_http("HTTP JSON-RPC", "jsonrpc", cmd.http_conf.clone(), &dependencies, dapps_middleware)?; | ||
| let ipc_server = rpc::new_ipc(cmd.ipc_conf, &dependencies)?; | ||
| 
        
          
        
         | 
    @@ -390,6 +392,7 @@ fn execute_light_impl(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<Runnin | |
| 
     | 
||
| Ok(RunningClient { | ||
| inner: RunningClientInner::Light { | ||
| rpc: rpc_direct, | ||
| informant, | ||
| client, | ||
| keep_alive: Box::new((event_loop, service, ws_server, http_server, ipc_server, ui_server)), | ||
| 
          
            
          
           | 
    @@ -805,6 +808,7 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq: | |
| }; | ||
| 
     | 
||
| // start rpc servers | ||
| let rpc_direct = rpc::setup_apis(rpc_apis::ApiSet::All, &dependencies); | ||
| let ws_server = rpc::new_ws(cmd.ws_conf.clone(), &dependencies)?; | ||
| let ipc_server = rpc::new_ipc(cmd.ipc_conf, &dependencies)?; | ||
| let http_server = rpc::new_http("HTTP JSON-RPC", "jsonrpc", cmd.http_conf.clone(), &dependencies, dapps_middleware)?; | ||
| 
          
            
          
           | 
    @@ -878,6 +882,7 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq: | |
| 
     | 
||
| Ok(RunningClient { | ||
| inner: RunningClientInner::Full { | ||
| rpc: rpc_direct, | ||
| informant, | ||
| client, | ||
| keep_alive: Box::new((watcher, service, updater, ws_server, http_server, ipc_server, ui_server, secretstore_key_server, ipfs_server, event_loop)), | ||
| 
        
          
        
         | 
    @@ -890,42 +895,64 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq: | |
| /// Should be destroyed by calling `shutdown()`, otherwise execution will continue in the | ||
| /// background. | ||
| pub struct RunningClient { | ||
| inner: RunningClientInner | ||
| inner: RunningClientInner, | ||
| } | ||
| 
     | 
||
| enum RunningClientInner { | ||
| Light { | ||
| rpc: jsonrpc_core::MetaIoHandler<Metadata, informant::Middleware<rpc_apis::LightClientNotifier>>, | ||
| informant: Arc<Informant<LightNodeInformantData>>, | ||
| client: Arc<LightClient>, | ||
| keep_alive: Box<Any>, | ||
| }, | ||
| Full { | ||
| rpc: jsonrpc_core::MetaIoHandler<Metadata, informant::Middleware<informant::ClientNotifier>>, | ||
| informant: Arc<Informant<FullNodeInformantData>>, | ||
| client: Arc<Client>, | ||
| keep_alive: Box<Any>, | ||
| }, | ||
| } | ||
| 
     | 
||
| impl RunningClient { | ||
| /// Performs a synchronous RPC query. | ||
| /// Blocks execution until the result is ready. | ||
| pub fn rpc_query_sync(&self, request: &str) -> Option<String> { | ||
| let metadata = Metadata { | ||
| origin: Origin::CApi, | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a question are these origins being used somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used in the transaction confirmations, and also I think for logging.  | 
||
| session: None, | ||
| }; | ||
| 
     | 
||
| match self.inner { | ||
| RunningClientInner::Light { ref rpc, .. } => { | ||
| rpc.handle_request_sync(request, metadata) | ||
| }, | ||
| RunningClientInner::Full { ref rpc, .. } => { | ||
| rpc.handle_request_sync(request, metadata) | ||
| }, | ||
| } | ||
| } | ||
| 
     | 
||
| /// Shuts down the client. | ||
| pub fn shutdown(self) { | ||
| match self.inner { | ||
| RunningClientInner::Light { informant, client, keep_alive } => { | ||
| RunningClientInner::Light { rpc, informant, client, keep_alive } => { | ||
| // Create a weak reference to the client so that we can wait on shutdown | ||
| // until it is dropped | ||
| let weak_client = Arc::downgrade(&client); | ||
| drop(rpc); | ||
| drop(keep_alive); | ||
| informant.shutdown(); | ||
| drop(informant); | ||
| drop(client); | ||
| wait_for_drop(weak_client); | ||
| }, | ||
| RunningClientInner::Full { informant, client, keep_alive } => { | ||
| RunningClientInner::Full { rpc, informant, client, keep_alive } => { | ||
| info!("Finishing work, please wait..."); | ||
| // Create a weak reference to the client so that we can wait on shutdown | ||
| // until it is dropped | ||
| let weak_client = Arc::downgrade(&client); | ||
| // drop this stuff as soon as exit detected. | ||
| drop(rpc); | ||
| drop(keep_alive); | ||
| // to make sure timer does not spawn requests while shutdown is in progress | ||
| informant.shutdown(); | ||
| 
          
            
          
           | 
    ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed
--lightbecauseparity_versionInfoisn't available for the light client (don't really know why).The
--no-ipcis here just to give an example usage for the arguments.