use anyhow::Result;
use serde_json::Value;
use crate::bitcoin::adapters::BitcoinRpcPort;
pub struct BitcoinRpcAdapter {
url: String,
username: String,
password: String,
}
impl BitcoinRpcAdapter {
pub fn new(url: &str, username: &str, password: &str) -> Self {
Self {
url: url.to_string(),
username: username.to_string(),
password: password.to_string(),
}
}
}
impl BitcoinRpcPort for BitcoinRpcAdapter {
fn execute_command(&self, command: &str, params: &[Value]) -> Result<Value> {
Ok(serde_json::json!({
"result": "Success",
"command": command,
"params": params,
}))
}
fn get_transaction_rpc(&self, txid: &str) -> Result<Value> {
self.execute_command("getrawtransaction", &[serde_json::json!(txid), serde_json::json!(true)])
}
fn send_raw_transaction(&self, hex: &str) -> Result<String> {
let result = self.execute_command("sendrawtransaction", &[serde_json::json!(hex)])?;
Ok(result["result"].as_str().unwrap_or("").to_string())
}
}