parity-clib: async C bindings to RPC requests + subscribe/unsubscribe to websocket events (#9920)
* feat(parity-clib asynchronous rpc queries) * feat(seperate bindings for ws and rpc) * Subscribing to websockets for the full-client works * feat(c binding unsubscribe_from_websocket) * fix(tests): tweak CMake build config * Enforce C+11 * refactor(parity-cpp-example) : `cpp:ify` * fix(typedefs) : revert typedefs parity-clib * docs(nits) * fix(simplify websocket_unsubscribe) * refactor(cpp example) : more subscriptions * fix(callback type) : address grumbles on callback * Use it the example to avoid using global variables * docs(nits) - don't mention `arc` * fix(jni bindings): fix compile errors * feat(java example and updated java bindings) * fix(java example) : run both full and light client * fix(Java shutdown) : unsubscribe to sessions Forgot to pass the JNIEnv environment since it is an instance method * feat(return valid JString) * Remove Java dependency by constructing a valid Java String in the callback * fix(logger) : remove `rpc` trace log * fix(format) * fix(parity-clib): remove needless callback `type` * fix(parity-clib-examples) : update examples * `cpp` example pass in a struct instead to determines `callback kind` * `java` add a instance variable the class `Callback` to determine `callback kind` * fix(review comments): docs and format * Update parity-clib/src/java.rs Co-Authored-By: niklasad1 <niklasadolfsson1@gmail.com> * fix(bad merge + spelling) * fix(move examples to parity-clib/examples)
This commit is contained in:
committed by
Afri Schoedon
parent
2bb79614f6
commit
b4f8bba843
@@ -121,6 +121,7 @@ use std::alloc::System;
|
||||
|
||||
pub use self::configuration::Configuration;
|
||||
pub use self::run::RunningClient;
|
||||
pub use parity_rpc::PubSubSession;
|
||||
|
||||
#[cfg(feature = "memory_profiling")]
|
||||
#[global_allocator]
|
||||
|
||||
@@ -41,7 +41,8 @@ use light::Cache as LightDataCache;
|
||||
use miner::external::ExternalMiner;
|
||||
use node_filter::NodeFilter;
|
||||
use parity_runtime::Runtime;
|
||||
use parity_rpc::{Origin, Metadata, NetworkSettings, informant, is_major_importing};
|
||||
use parity_rpc::{Origin, Metadata, NetworkSettings, informant, is_major_importing, PubSubSession, FutureResult,
|
||||
FutureResponse, FutureOutput};
|
||||
use updater::{UpdatePolicy, Updater};
|
||||
use parity_version::version;
|
||||
use ethcore_private_tx::{ProviderConfig, EncryptorConfig, SecretStoreEncryptor};
|
||||
@@ -875,21 +876,19 @@ enum RunningClientInner {
|
||||
}
|
||||
|
||||
impl RunningClient {
|
||||
/// Performs a synchronous RPC query.
|
||||
/// Blocks execution until the result is ready.
|
||||
pub fn rpc_query_sync(&self, request: &str) -> Option<String> {
|
||||
/// Performs an asynchronous RPC query.
|
||||
// FIXME: [tomaka] This API should be better, with for example a Future
|
||||
pub fn rpc_query(&self, request: &str, session: Option<Arc<PubSubSession>>)
|
||||
-> FutureResult<FutureResponse, FutureOutput>
|
||||
{
|
||||
let metadata = Metadata {
|
||||
origin: Origin::CApi,
|
||||
session: None,
|
||||
session,
|
||||
};
|
||||
|
||||
match self.inner {
|
||||
RunningClientInner::Light { ref rpc, .. } => {
|
||||
rpc.handle_request_sync(request, metadata)
|
||||
},
|
||||
RunningClientInner::Full { ref rpc, .. } => {
|
||||
rpc.handle_request_sync(request, metadata)
|
||||
},
|
||||
RunningClientInner::Light { ref rpc, .. } => rpc.handle_request(request, metadata),
|
||||
RunningClientInner::Full { ref rpc, .. } => rpc.handle_request(request, metadata),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user