|
1 | 1 | use crate::Balances as OrangeBalances; |
2 | 2 |
|
| 3 | +use crate::SingleUseReceiveUri as OrangeSingleUseReceiveUri; |
3 | 4 | use crate::Wallet as OrangeWallet; |
4 | 5 | use crate::WalletConfig as OrangeWalletConfig; |
5 | 6 | use crate::ffi::bitcoin_payment_instructions::Amount; |
@@ -47,6 +48,35 @@ impl Balances { |
47 | 48 | impl_from_core_type!(OrangeBalances, Balances); |
48 | 49 | impl_into_core_type!(Balances, OrangeBalances); |
49 | 50 |
|
| 51 | +/// Represents a single-use Bitcoin URI for receiving payments. |
| 52 | +#[derive(Debug, Clone, PartialEq, Eq, uniffi::Object)] |
| 53 | +pub struct SingleUseReceiveUri(pub OrangeSingleUseReceiveUri); |
| 54 | + |
| 55 | +#[uniffi::export] |
| 56 | +impl SingleUseReceiveUri { |
| 57 | + pub fn address(&self) -> Option<String> { |
| 58 | + self.0.address.clone().map(|a| a.to_string()) |
| 59 | + } |
| 60 | + |
| 61 | + pub fn invoice(&self) -> String { |
| 62 | + self.0.invoice.to_string() |
| 63 | + } |
| 64 | + |
| 65 | + pub fn amount(&self) -> Option<Arc<Amount>> { |
| 66 | + self.0.amount.map(|a| Arc::new(a.into())) |
| 67 | + } |
| 68 | + |
| 69 | + pub fn from_trusted(&self) -> bool { |
| 70 | + self.0.from_trusted |
| 71 | + } |
| 72 | + |
| 73 | + pub fn bip21_uri(&self) -> String { |
| 74 | + self.0.to_string() |
| 75 | + } |
| 76 | +} |
| 77 | +impl_from_core_type!(OrangeSingleUseReceiveUri, SingleUseReceiveUri); |
| 78 | +impl_into_core_type!(SingleUseReceiveUri, OrangeSingleUseReceiveUri); |
| 79 | + |
50 | 80 | #[derive(Clone, uniffi::Object)] |
51 | 81 | pub struct Wallet { |
52 | 82 | inner: Arc<OrangeWallet>, |
@@ -100,4 +130,11 @@ impl Wallet { |
100 | 130 | pub async fn stop(&self) { |
101 | 131 | self.inner.stop().await |
102 | 132 | } |
| 133 | + |
| 134 | + pub async fn get_single_use_receive_uri( |
| 135 | + &self, amount: Option<Arc<Amount>>, |
| 136 | + ) -> Result<SingleUseReceiveUri, WalletError> { |
| 137 | + let uri = self.inner.get_single_use_receive_uri(amount.map(|a| a.0)).await?; |
| 138 | + Ok(uri.into()) |
| 139 | + } |
103 | 140 | } |
0 commit comments