lwk/blockdata/
address_result.rs

1//! Liquid address result
2
3use crate::Address;
4use std::sync::Arc;
5
6/// Value returned from asking an address to the wallet.
7/// Containing the confidential address and its
8/// derivation index (the last element in the derivation path)
9#[derive(uniffi::Object)]
10pub struct AddressResult {
11    inner: lwk_wollet::AddressResult,
12}
13
14impl From<lwk_wollet::AddressResult> for AddressResult {
15    fn from(inner: lwk_wollet::AddressResult) -> Self {
16        Self { inner }
17    }
18}
19
20#[uniffi::export]
21impl AddressResult {
22    /// Return the address.
23    pub fn address(&self) -> Arc<Address> {
24        Arc::new(self.inner.address().clone().into())
25    }
26
27    /// Return the derivation index of the address.
28    pub fn index(&self) -> u32 {
29        self.inner.index()
30    }
31}
32
33#[cfg(test)]
34mod tests {
35
36    use std::str::FromStr;
37
38    use super::AddressResult;
39
40    #[test]
41    fn address_result() {
42        let address_str = "tlq1qq2xvpcvfup5j8zscjq05u2wxxjcyewk7979f3mmz5l7uw5pqmx6xf5xy50hsn6vhkm5euwt72x878eq6zxx2z58hd7zrsg9qn";
43        let index = 0;
44        let wollet_address_result = lwk_wollet::AddressResult::new(
45            elements::Address::from_str(address_str).unwrap(),
46            index,
47        );
48
49        let address_result: AddressResult = wollet_address_result.into();
50
51        assert_eq!(address_result.address().to_string(), address_str);
52
53        assert_eq!(address_result.index(), index);
54    }
55}