use {
super::*,
bitcoin::{
secp256k1::{rand, KeyPair, Secp256k1, XOnlyPublicKey},
Witness,
},
bitcoincore_rpc::RawTx,
};
pub(crate) struct Server {
pub(crate) state: Arc<Mutex<State>>,
pub(crate) network: Network,
}
impl Server {
pub(crate) fn new(state: Arc<Mutex<State>>) -> Self {
let network = state.lock().unwrap().network;
Self { network, state }
}
fn state(&self) -> MutexGuard<State> {
self.state.lock().unwrap()
}
fn not_found() -> jsonrpc_core::Error {
jsonrpc_core::Error::new(jsonrpc_core::types::error::ErrorCode::ServerError(-8))
}
}
impl Api for Server {
fn get_balances(&self) -> Result<GetBalancesResult, jsonrpc_core::Error> {
Ok(GetBalancesResult {
mine: GetBalancesResultEntry {
immature: Amount::from_sat(0),
trusted: self
.list_unspent(None, None, None, None, None)?
.iter()
.map(|entry| entry.amount)
.sum(),
untrusted_pending: Amount::from_sat(0),
},
watchonly: None,