diff --git a/contrib/jni/src/main/java/dev/bwt/daemon/NativeBwtDaemon.java b/contrib/jni/src/main/java/dev/bwt/daemon/NativeBwtDaemon.java index 5c9f0af..a164424 100644 --- a/contrib/jni/src/main/java/dev/bwt/daemon/NativeBwtDaemon.java +++ b/contrib/jni/src/main/java/dev/bwt/daemon/NativeBwtDaemon.java @@ -6,10 +6,14 @@ public class NativeBwtDaemon { } // Start the bwt daemon with the configured server(s) - // Blocks until the initial indexing is completed and the servers are ready. + // Blocks the current thread until the daemon is stopped. // Returns a pointer to be used with shutdown(). public static native long start(String jsonConfig, CallbackNotifier callback); // Shutdown thw bwt daemon public static native void shutdown(long shutdownPtr); -} \ No newline at end of file + + // Test the Bitcoin Core RPC connection details + // Throws an exception on failures. + public static native void testRpc(String jsonConfig); +} diff --git a/src/app.rs b/src/app.rs index 35bc698..342caa1 100644 --- a/src/app.rs +++ b/src/app.rs @@ -166,6 +166,12 @@ impl App { Some(self.http.as_ref()?.addr()) } + pub fn test_rpc(config: &Config) -> Result<()> { + let rpc = RpcClient::new(config.bitcoind_url(), config.bitcoind_auth()?)?; + rpc.get_wallet_info()?; + Ok(()) + } + // Pipe the shutdown receiver `rx` to trigger `sync_tx`. This is needed to start the next // sync loop run immediately, which will then process the shutdown signal itself. Without // this, the shutdown signal will only be noticed after a delay. diff --git a/src/interface.rs b/src/interface.rs index 3c09798..fc56efb 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -201,6 +201,23 @@ mod jni { Box::from_raw(shutdown_ptr as *mut ShutdownHandler); } + #[no_mangle] + pub extern "system" fn Java_dev_bwt_daemon_NativeBwtDaemon_testRpc( + env: JNIEnv, + _: JClass, + json_config: JString, + ) { + let json_config: String = env.get_string(json_config).unwrap().into(); + + let test = || App::test_rpc(&serde_json::from_str(&json_config)?); + + if let Err(e) = test() { + warn!("test rpc failed: {:?}", e); + env.throw_new("dev/bwt/daemon/BwtException", &e.to_string()) + .unwrap(); + } + } + fn spawn_recv_progress_thread( progress_rx: mpsc::Receiver, jvm: JavaVM,