use std::env;
use anyhow::Context;
use fedimint_core::util::SafeUrl;
use fedimint_derive::{Decodable, Encodable};
use jsonrpsee_core::Serialize;
use serde::Deserialize;
pub const FM_BITCOIN_RPC_KIND: &str = "FM_BITCOIN_RPC_KIND";
pub const FM_BITCOIN_RPC_URL: &str = "FM_BITCOIN_RPC_URL";
pub const FM_BITCOIND_COOKIE_FILE_VAR_NAME: &str = "FM_BITCOIND_COOKIE_FILE";
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize, Encodable, Decodable)]
pub struct BitcoinRpcConfig {
pub kind: String,
pub url: SafeUrl,
}
impl BitcoinRpcConfig {
pub fn from_env_vars() -> anyhow::Result<Self> {
Ok(Self {
kind: env::var(FM_BITCOIN_RPC_KIND).with_context(|| {
anyhow::anyhow!("failure looking up env var {FM_BITCOIN_RPC_KIND}")
})?,
url: env::var(FM_BITCOIN_RPC_URL)
.with_context(|| {
anyhow::anyhow!("failure looking up env var {FM_BITCOIN_RPC_URL}")
})?
.parse()
.with_context(|| anyhow::anyhow!("failure parsing env var {FM_BITCOIN_RPC_URL}"))?,
})
}
}