use crate::bitcoin::error::BitcoinResult;
use bitcoin::Transaction;
pub mod rgb;
pub use rgb::{
AssetCreationParams, AssetTransfer, RGBAsset, RGBFactory, RGBManager, TransferStatus,
};
pub trait Layer2Protocol {
fn generate_address(&self, address_type: &str) -> BitcoinResult<String>;
fn create_transaction(&self, outputs: Vec<(String, u64)>) -> BitcoinResult<Transaction>;
fn verify_merkle_proof(&self, tx_hash: &[u8], block_header: &[u8]) -> BitcoinResult<bool>;
fn get_transaction(&self, txid: &str) -> BitcoinResult<Transaction>;
fn get_block(&self, hash: &str) -> BitcoinResult<Vec<u8>>;
fn broadcast_transaction(&self, tx: &Transaction) -> BitcoinResult<String>;
fn send_transaction(&self, tx: &Transaction) -> BitcoinResult<String>;
fn get_block_height(&self) -> BitcoinResult<u64>;
fn get_balance(&self, address: &str) -> BitcoinResult<u64>;
fn estimate_fee(&self) -> BitcoinResult<u64>;
}
pub struct Layer2Registry(Vec<(String, Box<dyn Layer2Protocol>)>);
impl Default for Layer2Registry {
fn default() -> Self {
Self::new()
}
}
impl Layer2Registry {
pub fn new() -> Self {
Self(Vec::new())
}
pub fn register(&mut self, name: String, protocol: Box<dyn Layer2Protocol>) {
self.0.push((name, protocol));
}
pub fn get(&self, name: &str) -> Option<&dyn Layer2Protocol> {
self.0
.iter()
.find(|(n, _)| n == name)
.map(|(_, p)| p.as_ref())
}
pub fn list_protocols(&self) -> Vec<&str> {
self.0.iter().map(|(name, _)| name.as_str()).collect()
}
}