spark_sdk/
lib.rs

1use core::fmt;
2
3pub(crate) mod constants;
4pub mod error;
5pub(crate) mod wallet;
6
7pub mod signer;
8
9// pub use wallet::utils;
10pub use wallet::SparkSdk;
11
12pub(crate) mod common_types;
13
14#[cfg(any(test, feature = "integration-tests"))]
15pub mod spark_test_utils;
16
17pub mod rpc;
18
19/// Spark Network. This is the network of the Spark Operators that the user choose to connect to. Mainnet is the Bitcoin network, and all operations involve real money. Regtest is Ligthspark's Regtest network.
20#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Debug)]
21#[non_exhaustive]
22pub enum SparkNetwork {
23    /// Mainnet Bitcoin.
24    Mainnet,
25
26    /// Lightspark's Regtest network.
27    Regtest,
28}
29
30impl SparkNetwork {
31    pub fn from_str(s: &str) -> Result<Self, String> {
32        match s {
33            "mainnet" => Ok(SparkNetwork::Mainnet),
34            "regtest" => Ok(SparkNetwork::Regtest),
35            _ => Err(format!("Invalid network: {}", s)),
36        }
37    }
38
39    pub fn to_bitcoin_network(&self) -> ::bitcoin::Network {
40        match self {
41            SparkNetwork::Mainnet => ::bitcoin::Network::Bitcoin,
42            SparkNetwork::Regtest => ::bitcoin::Network::Regtest,
43        }
44    }
45
46    pub fn marshal_proto(&self) -> i32 {
47        match self {
48            SparkNetwork::Mainnet => spark_protos::spark::Network::Mainnet as i32,
49            SparkNetwork::Regtest => spark_protos::spark::Network::Regtest as i32,
50        }
51    }
52}
53
54impl fmt::Display for SparkNetwork {
55    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56        write!(f, "{}", self.to_string())
57    }
58}