1#[cfg(all(any(target_os = "android", target_os = "ios"), feature = "tls-native-roots"))]
34compile_error!("feature `tls-native-roots` can't be used on Android or iOS, use `tls-webpki-roots` instead");
35
36pub extern crate tonic;
37
38#[cfg(feature = "server")]
40include!(concat!(env!("OUT_DIR"), "/grpc_methods.rs"));
41
42mod convert;
43pub use crate::convert::{ConvertError, TryFromBytes};
44
45mod error;
46pub use crate::error::StatusExt;
47
48pub mod pver;
49
50pub mod client;
51pub mod protos {
52 pub mod core {
53 tonic::include_proto!("core");
54 }
55 pub use self::core::*;
56 pub mod bark_server {
57 tonic::include_proto!("bark_server");
58 }
59 pub use self::bark_server::*;
60 pub mod intman {
61 tonic::include_proto!("intman");
62 }
63 pub mod mailbox_server {
64 tonic::include_proto!("mailbox_server");
65 }
66}
67
68pub use client::ServerConnection;
69pub use crate::protos::bark_server::ark_service_client::ArkServiceClient;
70
71pub mod admin {
72 pub use crate::protos::bark_server::wallet_admin_service_client::WalletAdminServiceClient;
73 pub use crate::protos::bark_server::round_admin_service_client::RoundAdminServiceClient;
74 pub use crate::protos::bark_server::lightning_admin_service_client::LightningAdminServiceClient;
75 pub use crate::protos::bark_server::sweep_admin_service_client::SweepAdminServiceClient;
76 pub use crate::protos::bark_server::ban_admin_service_client::BanAdminServiceClient;
77}
78
79#[cfg(feature = "intman")]
80pub mod intman {
81 pub use crate::protos::intman::integration_service_client::IntegrationServiceClient;
82}
83
84#[cfg(feature = "server")]
85pub mod server {
86 pub use crate::protos::bark_server::ark_service_server::{ArkService, ArkServiceServer};
87 pub use crate::protos::bark_server::wallet_admin_service_server::{WalletAdminService, WalletAdminServiceServer};
88 pub use crate::protos::bark_server::round_admin_service_server::{RoundAdminService, RoundAdminServiceServer};
89 pub use crate::protos::bark_server::lightning_admin_service_server::{LightningAdminService, LightningAdminServiceServer};
90 pub use crate::protos::bark_server::sweep_admin_service_server::{SweepAdminService, SweepAdminServiceServer};
91 pub use crate::protos::bark_server::ban_admin_service_server::{BanAdminService, BanAdminServiceServer};
92 pub use crate::protos::intman::integration_service_server::{IntegrationService, IntegrationServiceServer};
93 pub use crate::protos::mailbox_server::mailbox_service_server::{MailboxService, MailboxServiceServer};
94}
95
96pub mod mailbox {
97 pub use crate::protos::mailbox_server::mailbox_service_client::MailboxServiceClient;
98}
99
100
101use std::borrow::BorrowMut;
102use std::str::FromStr;
103use std::time::Duration;
104
105use bitcoin::{Address, Amount, OutPoint};
106use bitcoin::address::NetworkUnchecked;
107
108
109pub const MIN_PROTOCOL_VERSION: u64 = pver::PROTOCOL_VERSION_BASE;
113
114pub const MAX_PROTOCOL_VERSION: u64 = pver::PROTOCOL_VERSION_LN_RECEIVE_CHECKPOINT;
118
119pub const PROTOCOL_VERSION_HEADER: &str = "pver";
121
122
123#[derive(Debug, Clone)]
124pub struct WalletStatus {
125 pub address: Address<NetworkUnchecked>,
126 pub total_balance: Amount,
127 pub trusted_balance: Amount,
128 pub untrusted_balance: Amount,
129 pub confirmed_utxos: Vec<OutPoint>,
130 pub unconfirmed_utxos: Vec<OutPoint>,
131}
132
133pub trait RequestExt<T>: BorrowMut<tonic::Request<T>> {
135 fn try_pver(&self) -> Result<Option<u64>, tonic::Status> {
139 self.borrow().metadata().get(PROTOCOL_VERSION_HEADER).map(|v| {
140 v.to_str().ok().and_then(|s| u64::from_str(s).ok())
141 .ok_or_else(|| tonic::Status::invalid_argument("invalid protocol version header"))
142 }).transpose()
143 }
144
145 fn pver(&self) -> Result<u64, tonic::Status> {
149 self.try_pver()?.ok_or_else(|| tonic::Status::invalid_argument("missing pver header"))
150 }
151
152 fn set_pver(&mut self, pver: u64) {
154 self.borrow_mut().metadata_mut().insert(PROTOCOL_VERSION_HEADER, pver.into());
155 }
156
157 fn set_default_timeout(&mut self, timeout: Duration) {
159 const GRPC_TIMEOUT_HEADER: &str = "grpc-timeout";
160
161 let slf = self.borrow_mut();
162 if slf.metadata().get(GRPC_TIMEOUT_HEADER).is_none () {
163 slf.set_timeout(timeout);
164 }
165 }
166}
167impl<T> RequestExt<T> for tonic::Request<T> {}