diff --git a/Cargo.lock b/Cargo.lock index 9a7f1fb..7e0091e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -336,8 +336,10 @@ dependencies = [ "bdk 0.13.0", "bdk-macros 0.6.0", "dirs-next", + "percent-encoding", "rust-ini", "structopt", + "url", ] [[package]] @@ -1964,6 +1966,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde 1.0.193", ] [[package]] diff --git a/bitcoin/Cargo.toml b/bitcoin/Cargo.toml index 6d2b129..2de6ee5 100644 --- a/bitcoin/Cargo.toml +++ b/bitcoin/Cargo.toml @@ -6,8 +6,10 @@ version = "0.1.1-dev" bdk = { version = "0.13.0", default-features = false } bdk-macros = "^0.6" dirs-next = "2.0.0" -rust-ini = "0.16" structopt = "0.3" +rust-ini = "0.16" +url = { version = "2", features = ["serde"] } +percent-encoding = "2.1.0" [features] default = ["electrum", "bdk/key-value-db"] diff --git a/server/src/server.rs b/server/src/server.rs index c8b8e21..4abc23f 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -7,6 +7,8 @@ use crate::{html, wallet}; use crate::html::not_found; use wallet::{Wallet, Error, gen_err}; +use btctipserver_bitcoin::BTCWallet; + pub fn run_server(url: &str, wallet: Wallet) { let wallet_mutex = Arc::new(Mutex::new(wallet)); let server = Server::http(url).unwrap(); @@ -31,7 +33,6 @@ pub fn run_server(url: &str, wallet: Wallet) { }; drop(wallet_lock); Response::from_string(html).with_header(content_type_header) - } else { let html = match page(&mut wallet_lock, parsed.query().unwrap()) { Ok(txt) => txt, @@ -63,6 +64,22 @@ pub fn page( uri: &str, ) -> Result { let network = wallet.network()?; + let mut address = uri; + + BTCWallet::Bip21::parse(uri).unwrap(); + + + Bip21::parse("bitcoin:2NDxuABdg2uqk9MouV6f53acAwaY2GwKVHK") + let address = match parsed.query().unwrap() { + + }; + + + + if parsed.query().unwrap().starts_with(wallet.schema()) { + address = Bip21::parse("bitcoin:2NDxuABdg2uqk9MouV6f53acAwaY2GwKVHK").unwrap(); + } + let address = uri; let mine = wallet.is_my_address(address)?; if !mine { diff --git a/server/src/wallet.rs b/server/src/wallet.rs index cd3b7c9..e0c6f8c 100644 --- a/server/src/wallet.rs +++ b/server/src/wallet.rs @@ -55,4 +55,13 @@ impl Wallet { Wallet::ClightningWallet(w) => { w.balance_address(addr, _from_height).map_err(|_| gen_err()) } } } + + pub fn schema(&mut self) -> &str { + match self { + Wallet::BTCWallet(_) => "bitcoin", + Wallet::LiquidWallet(_) => "liquidnetwork", + Wallet::ClightningWallet(_) => "lightning", + } + } + } \ No newline at end of file