use super::{Plugin, Account, Address, PaymentOption, Transaction, Payment, Confirmation, Price};
use anyhow::Result;
use bigdecimal::BigDecimal;
use std::str::FromStr;
pub struct BitcoinSVPlugin;
#[async_trait::async_trait]
impl Plugin for BitcoinSVPlugin {
fn currency(&self) -> &str { "BSV" }
fn chain(&self) -> &str { "BSV" }
fn decimals(&self) -> u8 { 8 }
async fn build_signed_payment(&self, payment_option: &PaymentOption, mnemonic: &str) -> Result<Transaction> {
Ok(Transaction {
txhex: "mock_bsv_tx".into(),
txid: Some("mock_bsv_txid".into()),
txkey: None,
})
}
async fn verify_payment(&self, payment_option: &PaymentOption, transaction: &Transaction) -> Result<bool> {
Ok(true)
}
async fn validate_address(&self, address: &str) -> Result<bool> {
Ok(address.starts_with("1") || address.starts_with("3") || address.starts_with("q"))
}
async fn get_transaction(&self, txid: &str) -> Result<Transaction> {
Ok(Transaction {
txhex: "mock_bsv_tx".into(),
txid: Some(txid.to_string()),
txkey: None,
})
}
async fn broadcast_tx(&self, txhex: &str, txid: Option<&str>, _txkey: Option<&str>) -> Result<Transaction> {
Ok(Transaction {
txhex: txhex.to_string(),
txid: txid.map(String::from),
txkey: None,
})
}
async fn get_new_address(&self, _account: &Account, address: &Address) -> Result<String> {
Ok(address.value.clone())
}
async fn transform_address(&self, address: &str) -> Result<String> {
Ok(address.split(':').last().unwrap_or(address).to_string())
}
async fn get_confirmation(&self, _txid: &str) -> Result<Option<Confirmation>> {
Ok(Some(Confirmation {
confirmations: 6,
confirmed: true,
}))
}
async fn get_payments(&self, txid: &str) -> Result<Vec<Payment>> {
Ok(vec![Payment {
chain: self.chain().to_string(),
currency: self.currency().to_string(),
address: "mock_bsv_address".to_string(),
amount: 100000000, txid: txid.to_string(),
}])
}
async fn parse_payments(&self, transaction: &Transaction) -> Result<Vec<Payment>> {
Ok(vec![])
}
async fn get_price(&self) -> Result<Price> {
Ok(Price {
currency: self.currency().to_string(),
price: BigDecimal::from_str("35.00")?,
timestamp: chrono::Utc::now().timestamp(),
})
}
}