Skip to content

Commit

Permalink
jni: Implement NativeBwtDaemon.testRpc()
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek committed Jan 6, 2021
1 parent 6650cbe commit a952827
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
8 changes: 6 additions & 2 deletions contrib/jni/src/main/java/dev/bwt/daemon/NativeBwtDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

// Test the Bitcoin Core RPC connection details
// Throws an exception on failures.
public static native void testRpc(String jsonConfig);
}
6 changes: 6 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Progress>,
jvm: JavaVM,
Expand Down

0 comments on commit a952827

Please sign in to comment.