+ let client = Self {
+ bitcoind_rpc_client: Mutex::new(bitcoind_rpc_client),
+ host,
+ port,
+ rpc_user,
+ rpc_password,
+ runtime: Mutex::new(Runtime::new().unwrap()),
+ // runtime: Mutex::new(runtime),
+ };
+ Ok(client)
+ }
+
+ pub fn get_new_rpc_client(&self) -> std::io::Result<RpcClient> {
+ let http_endpoint = HttpEndpoint::for_host(self.host.clone()).with_port(self.port);
+ let rpc_credentials = base64::encode(format!("{}:{}",
+ self.rpc_user.clone(),
+ self.rpc_password.clone()));
+ RpcClient::new(&rpc_credentials, http_endpoint)
+ }
+
+ pub fn create_raw_transaction(&self, outputs: Vec<HashMap<String, f64>>) -> RawTx {
+ let runtime = self.runtime.lock().unwrap();
+ let mut rpc = self.bitcoind_rpc_client.lock().unwrap();
+
+ let outputs_json = serde_json::json!(outputs);
+ runtime.block_on(rpc.call_method::<RawTx>("createrawtransaction", &vec![serde_json::json!([]), outputs_json])).unwrap()
+ }
+
+ pub fn fund_raw_transaction(&self, raw_tx: RawTx) -> FundedTx {
+ let runtime = self.runtime.lock().unwrap();
+ let mut rpc = self.bitcoind_rpc_client.lock().unwrap();
+
+ let raw_tx_json = serde_json::json!(raw_tx.0);
+ runtime.block_on(rpc.call_method("fundrawtransaction", &[raw_tx_json])).unwrap()
+ }
+
+ pub fn sign_raw_transaction_with_wallet(&self, tx_hex: String) -> SignedTx {
+ let runtime = self.runtime.lock().unwrap();
+ let mut rpc = self.bitcoind_rpc_client.lock().unwrap();
+
+ let tx_hex_json = serde_json::json!(tx_hex);
+ runtime.block_on(rpc.call_method("signrawtransactionwithwallet",
+ &vec![tx_hex_json])).unwrap()
+ }
+
+ pub fn get_new_address(&self) -> Address {
+ let runtime = self.runtime.lock().unwrap();
+ let mut rpc = self.bitcoind_rpc_client.lock().unwrap();
+
+ let addr_args = vec![serde_json::json!("LDK output address")];
+ let addr = runtime.block_on(rpc.call_method::<NewAddress>("getnewaddress", &addr_args)).unwrap();
+ Address::from_str(addr.0.as_str()).unwrap()
+ }
+
+ pub fn get_blockchain_info(&self) -> BlockchainInfo {
+ let runtime = self.runtime.lock().unwrap();
+ let mut rpc = self.bitcoind_rpc_client.lock().unwrap();
+
+ runtime.block_on(rpc.call_method::<BlockchainInfo>("getblockchaininfo",
+ &vec![])).unwrap()