Skip to content

Commit

Permalink
Merge pull request #11 from MutinyWallet/update-deps
Browse files Browse the repository at this point in the history
Update deps
  • Loading branch information
benthecarman authored Jan 9, 2024
2 parents aee80a5 + e41b832 commit 0769fba
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 48 deletions.
4 changes: 2 additions & 2 deletions waila-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
bitcoin-waila = { path = "../waila", version = "0.2.6" }
bitcoin = "0.29.2"
nostr = { version = "=0.23.0-bitcoin-v0.29", default-features = false, features = ["nip19"] }
bitcoin = "0.30.2"
nostr = { version = "0.26.0", default-features = false, features = ["std"] }
wasm-bindgen = "0.2.84"
16 changes: 8 additions & 8 deletions waila/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
bech32 = "0.9.1"
bitcoin = { version = "0.29.2", default-features = false, features = ["serde"] }
bip21 = "0.2.0"
bitcoin = { version = "0.30.2", default-features = false, features = ["serde"] }
bip21 = "0.3.1"
itertools = "0.12.0"
nostr = { version = "=0.23.0-bitcoin-v0.29", default-features = false, features = ["nip19", "nip47"] }
lnurl-rs = { version = "0.3", default-features = false }
lightning-invoice = { version = "0.26.0", default-features = false }
lightning = { version = "0.0.118", default-features = false }
nostr = { version = "0.26.0", default-features = false, features = ["nip47"] }
lnurl-rs = { version = "0.4.0", default-features = false }
lightning-invoice = { version = "0.27.0", default-features = false }
lightning = { version = "0.0.119", default-features = false }
rgb-std = { version = "0.10.9", optional = true }
rgb-wallet = { version = "0.10.9", optional = true }
url = "2.4.1"

[features]
default = ["std"]
std = ["bitcoin/std", "lightning-invoice/std", "lightning/std"]
no-std = ["bitcoin/no-std", "lightning-invoice/no-std", "lightning/no-std"]
std = ["bitcoin/std", "lightning-invoice/std", "lightning/std", "nostr/std"]
no-std = ["bitcoin/no-std", "lightning-invoice/no-std", "lightning/no-std", "nostr/alloc"]
rgb = ["rgb-std", "rgb-wallet"]

[package.metadata.wasm-pack.profile.release]
Expand Down
7 changes: 3 additions & 4 deletions waila/src/bip21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use std::convert::TryFrom;

use ::bip21::de::*;
use ::bip21::*;
use bitcoin::address::NetworkUnchecked;
use lightning_invoice::{Bolt11Invoice, ParseOrSemanticError};
use url::Url;

/// This lets us parse `lightning` and payjoin parameters from a BIP21 URI.
pub type UnifiedUri<'a> = Uri<'a, WailaExtras>;
pub type UnifiedUri<'a> = Uri<'a, NetworkUnchecked, WailaExtras>;

#[derive(Debug, Default, Eq, PartialEq, Clone, Hash)]
pub struct WailaExtras {
Expand Down Expand Up @@ -116,9 +117,7 @@ mod test {

use lightning_invoice::Bolt11Invoice;

use crate::bip21::WailaExtras;

type UnifiedUri<'a> = bip21::Uri<'a, WailaExtras>;
use crate::bip21::UnifiedUri;

#[test]
fn test_ln_uri() {
Expand Down
46 changes: 36 additions & 10 deletions waila/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use bech32::Variant;
use std::convert::TryInto;
use std::str::FromStr;

use bitcoin::blockdata::constants::ChainHash;
use bitcoin::key::XOnlyPublicKey;
use bitcoin::secp256k1::PublicKey;
use bitcoin::{Address, Amount, Network};
use lightning::offers::offer;
Expand All @@ -10,11 +12,12 @@ use lightning::offers::refund::Refund;
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription};
use lnurl::lightning_address::LightningAddress;
use lnurl::lnurl::LnUrl;
use nostr::prelude::*;
use nostr::FromBech32;
#[cfg(feature = "rgb")]
use rgbstd::Chain;
#[cfg(feature = "rgb")]
use rgbwallet::RgbInvoice;
use url::Url;

use crate::bip21::UnifiedUri;
use crate::nwa::NIP49URI;
Expand Down Expand Up @@ -92,7 +95,7 @@ impl PaymentParams<'_> {
/// Returns None if the network is unknown
pub fn valid_for_network(&self, network: Network) -> Option<bool> {
match self {
PaymentParams::OnChain(address) => Some(address.is_valid_for_network(network)),
PaymentParams::OnChain(address) => Some(address.network == network),
PaymentParams::Bip21(uri) => Some(uri.address.is_valid_for_network(network)),
PaymentParams::Bolt11(invoice) => Some(Network::from(invoice.currency()) == network),
PaymentParams::Bolt12(offer) => {
Expand Down Expand Up @@ -144,7 +147,7 @@ impl PaymentParams<'_> {
pub fn address(&self) -> Option<Address> {
match self {
PaymentParams::OnChain(address) => Some(address.clone()),
PaymentParams::Bip21(uri) => Some(uri.address.clone()),
PaymentParams::Bip21(uri) => Some(uri.address.clone().assume_checked()),
PaymentParams::Bolt11(invoice) => invoice.fallback_addresses().first().cloned(),
PaymentParams::Bolt12(_) => None,
PaymentParams::Bolt12Refund(_) => None,
Expand Down Expand Up @@ -410,7 +413,7 @@ impl FromStr for PaymentParams<'_> {
}

Address::from_str(str)
.map(PaymentParams::OnChain)
.map(|a| PaymentParams::OnChain(a.assume_checked()))
.or_else(|_| Bolt11Invoice::from_str(str).map(PaymentParams::Bolt11))
.or_else(|_| UnifiedUri::from_str(str).map(PaymentParams::Bip21))
.or_else(|_| LightningAddress::from_str(str).map(PaymentParams::LightningAddress))
Expand Down Expand Up @@ -463,7 +466,9 @@ mod tests {

#[test]
fn parse_address() {
let address = Address::from_str("1andreas3batLhQa2FawWjeyjCqyBzypd").unwrap();
let address = Address::from_str("1andreas3batLhQa2FawWjeyjCqyBzypd")
.unwrap()
.assume_checked();
let parsed = PaymentParams::from_str(&address.to_string()).unwrap();

assert_eq!(parsed.address(), Some(address));
Expand All @@ -486,7 +491,11 @@ mod tests {
assert_eq!(parsed.network(), Some(Network::Bitcoin));
assert_eq!(
parsed.address(),
Some(Address::from_str("1RustyRX2oai4EYYDpQGWvEL62BBGqN9T").unwrap())
Some(
Address::from_str("1RustyRX2oai4EYYDpQGWvEL62BBGqN9T")
.unwrap()
.assume_checked()
)
);
assert_eq!(parsed.memo(), None);
assert_eq!(parsed.lnurl(), None);
Expand Down Expand Up @@ -527,7 +536,11 @@ mod tests {
assert_eq!(parsed.network(), Some(Network::Bitcoin));
assert_eq!(
parsed.address(),
Some(Address::from_str("1RustyRX2oai4EYYDpQGWvEL62BBGqN9T").unwrap())
Some(
Address::from_str("1RustyRX2oai4EYYDpQGWvEL62BBGqN9T")
.unwrap()
.assume_checked()
)
);
assert_eq!(parsed.memo(), None);
assert_eq!(parsed.lnurl(), None);
Expand All @@ -546,7 +559,11 @@ mod tests {
assert_eq!(parsed.network(), Some(Network::Bitcoin));
assert_eq!(
parsed.address(),
Some(Address::from_str("1RustyRX2oai4EYYDpQGWvEL62BBGqN9T").unwrap())
Some(
Address::from_str("1RustyRX2oai4EYYDpQGWvEL62BBGqN9T")
.unwrap()
.assume_checked()
)
);
assert_eq!(parsed.memo(), None);
assert_eq!(parsed.lnurl(), None);
Expand All @@ -559,7 +576,11 @@ mod tests {
assert_eq!(parsed.amount(), Some(Amount::from_btc(50_f64).unwrap()));
assert_eq!(
parsed.address(),
Some(Address::from_str("1andreas3batLhQa2FawWjeyjCqyBzypd").unwrap())
Some(
Address::from_str("1andreas3batLhQa2FawWjeyjCqyBzypd")
.unwrap()
.assume_checked()
)
);
assert_eq!(parsed.memo(), Some("Donation for project xyz".to_string()));
assert_eq!(parsed.network(), Some(Network::Bitcoin));
Expand All @@ -575,7 +596,11 @@ mod tests {
assert_eq!(parsed.amount(), Some(Amount::from_btc(0.00001).unwrap()));
assert_eq!(
parsed.address(),
Some(Address::from_str("BC1QYLH3U67J673H6Y6ALV70M0PL2YZ53TZHVXGG7U").unwrap())
Some(
Address::from_str("BC1QYLH3U67J673H6Y6ALV70M0PL2YZ53TZHVXGG7U")
.unwrap()
.assume_checked()
)
);
assert_eq!(parsed.memo(), Some("For lunch Tuesday".to_string()));
assert_eq!(parsed.network(), Some(Network::Bitcoin));
Expand All @@ -602,6 +627,7 @@ mod tests {
Some(
Address::from_str("tb1p0vztr8q25czuka5u4ta5pqu0h8dxkf72mam89cpg4tg40fm8wgmqp3gv99")
.unwrap()
.assume_checked()
)
);
assert_eq!(parsed.memo(), Some("yooo".to_string()));
Expand Down
28 changes: 4 additions & 24 deletions waila/src/nwa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,6 @@ pub struct NIP49URI {
pub identity: Option<XOnlyPublicKey>,
}

fn method_from_str(s: &str) -> Result<Method, Error> {
match s {
"pay_invoice" => Ok(Method::PayInvoice),
"make_invoice" => Ok(Method::MakeInvoice),
"lookup_invoice" => Ok(Method::LookupInvoice),
"get_balance" => Ok(Method::GetBalance),
_ => Err(Error::InvalidURI),
}
}

fn method_to_string(method: &Method) -> String {
match method {
Method::PayInvoice => "pay_invoice",
Method::MakeInvoice => "make_invoice",
Method::LookupInvoice => "lookup_invoice",
Method::GetBalance => "get_balance",
}
.to_string()
}

impl FromStr for NIP49URI {
type Err = Error;
fn from_str(uri: &str) -> Result<Self, Self::Err> {
Expand Down Expand Up @@ -162,13 +142,13 @@ impl FromStr for NIP49URI {
Cow::Borrowed("required_commands") => {
required_commands = value
.split(' ')
.map(method_from_str)
.map(Method::from_str)
.collect::<Result<Vec<Method>, Error>>()?;
}
Cow::Borrowed("optional_commands") => {
optional_commands = value
.split(' ')
.map(method_from_str)
.map(Method::from_str)
.collect::<Result<Vec<Method>, Error>>()?;
}
Cow::Borrowed("budget") => {
Expand Down Expand Up @@ -213,7 +193,7 @@ impl fmt::Display for NIP49URI {
url_encode(
self.required_commands
.iter()
.map(method_to_string)
.map(|x| x.to_string())
.join(" ")
),
)?;
Expand All @@ -224,7 +204,7 @@ impl fmt::Display for NIP49URI {
url_encode(
self.optional_commands
.iter()
.map(method_to_string)
.map(|x| x.to_string())
.join(" ")
)
)?;
Expand Down

0 comments on commit 0769fba

Please sign in to comment.