pub struct OfflineClient<B, W, S> { /* private fields */ }Expand description
A client to interact with Ark Server
§Example
struct MyBlockchain {}
struct MyWallet {}
// Initialize the client with a static keypair
async fn init_client_with_keypair() -> Result<Client<MyBlockchain, MyWallet, InMemorySwapStorage>, ark_client::Error> {
// Create a keypair for signing transactions
let secp = bitcoin::key::Secp256k1::new();
let secret_key = SecretKey::from_str("your_private_key_here").unwrap();
let keypair = Keypair::from_secret_key(&secp, &secret_key);
// Initialize blockchain and wallet implementations
let blockchain = Arc::new(MyBlockchain::new("https://esplora.example.com"));
let wallet = Arc::new(MyWallet {});
let config = OfflineClientConfig {
ark_server_url: "https://ark-server.example.com".to_string(),
boltz_url: "http://boltz.example.com".to_string(),
..Default::default()
};
let offline_client = OfflineClient::with_keypair(
config,
keypair,
blockchain,
wallet,
Arc::new(InMemorySwapStorage::default()),
);
// Connect to the Ark server and get server info
let client = offline_client.connect().await?;
Ok(client)
}
// Initialize the client with a BIP32 HD wallet
async fn init_client_with_bip32() -> Result<Client<MyBlockchain, MyWallet, InMemorySwapStorage>, ark_client::Error> {
// Create a BIP32 master key and derivation path
let master_key = Xpriv::from_str("xprv...").unwrap();
let derivation_path = DerivationPath::from_str("m/84'/0'/0'/0/0").unwrap();
// Initialize blockchain and wallet implementations
let blockchain = Arc::new(MyBlockchain::new("https://esplora.example.com"));
let wallet = Arc::new(MyWallet {});
let config = OfflineClientConfig {
ark_server_url: "https://ark-server.example.com".to_string(),
boltz_url: "http://boltz.example.com".to_string(),
..Default::default()
};
let offline_client = OfflineClient::with_bip32(
config,
master_key,
Some(derivation_path),
blockchain,
wallet,
Arc::new(InMemorySwapStorage::default()),
);
// Connect to the Ark server and get server info
let client = offline_client.connect().await?;
Ok(client)
}Implementations§
Source§impl<B, W, S> OfflineClient<B, W, S>
impl<B, W, S> OfflineClient<B, W, S>
Sourcepub fn with_key_provider(
config: OfflineClientConfig,
key_provider: Arc<dyn KeyProvider>,
blockchain: Arc<B>,
wallet: Arc<W>,
swap_storage: Arc<S>,
) -> Self
pub fn with_key_provider( config: OfflineClientConfig, key_provider: Arc<dyn KeyProvider>, blockchain: Arc<B>, wallet: Arc<W>, swap_storage: Arc<S>, ) -> Self
Create a new offline client with a generic key provider.
Sourcepub fn with_discoverable_key_provider<P>(
config: OfflineClientConfig,
key_provider: Arc<P>,
blockchain: Arc<B>,
wallet: Arc<W>,
swap_storage: Arc<S>,
) -> Selfwhere
P: DiscoverableKeyProvider + 'static,
pub fn with_discoverable_key_provider<P>(
config: OfflineClientConfig,
key_provider: Arc<P>,
blockchain: Arc<B>,
wallet: Arc<W>,
swap_storage: Arc<S>,
) -> Selfwhere
P: DiscoverableKeyProvider + 'static,
Create a new offline client with a discoverable key provider.
Sourcepub fn with_keypair(
config: OfflineClientConfig,
kp: Keypair,
blockchain: Arc<B>,
wallet: Arc<W>,
swap_storage: Arc<S>,
) -> Self
pub fn with_keypair( config: OfflineClientConfig, kp: Keypair, blockchain: Arc<B>, wallet: Arc<W>, swap_storage: Arc<S>, ) -> Self
Create a new offline client with a static keypair.
Sourcepub fn with_bip32(
config: OfflineClientConfig,
xpriv: Xpriv,
path: Option<DerivationPath>,
blockchain: Arc<B>,
wallet: Arc<W>,
swap_storage: Arc<S>,
) -> Self
pub fn with_bip32( config: OfflineClientConfig, xpriv: Xpriv, path: Option<DerivationPath>, blockchain: Arc<B>, wallet: Arc<W>, swap_storage: Arc<S>, ) -> Self
Create a new offline client with an Xpriv.
Sourcepub fn with_contract_store(self, store: Box<dyn ContractStore>) -> Self
pub fn with_contract_store(self, store: Box<dyn ContractStore>) -> Self
Use a custom contract store for the connected client.
If unset, the client uses an in-memory contract store.
Sourcepub fn delegator_pk(&self) -> Option<XOnlyPublicKey>
pub fn delegator_pk(&self) -> Option<XOnlyPublicKey>
Returns the currently configured delegator pubkey, if any.
Sourcepub fn boltz_referral_id(&self) -> Option<&str>
pub fn boltz_referral_id(&self) -> Option<&str>
Returns the Boltz referral ID sent with all swap creation requests, if any.
Trait Implementations§
Auto Trait Implementations§
impl<B, W, S> !Freeze for OfflineClient<B, W, S>
impl<B, W, S> !RefUnwindSafe for OfflineClient<B, W, S>
impl<B, W, S> !UnwindSafe for OfflineClient<B, W, S>
impl<B, W, S> Send for OfflineClient<B, W, S>
impl<B, W, S> Sync for OfflineClient<B, W, S>
impl<B, W, S> Unpin for OfflineClient<B, W, S>
impl<B, W, S> UnsafeUnpin for OfflineClient<B, W, S>
Blanket Implementations§
Source§impl<T> AnyExt for T
impl<T> AnyExt for T
Source§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
Attempts to downcast this to
T behind referenceSource§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
Attempts to downcast this to
T behind mutable referenceSource§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
Attempts to downcast this to
T behind Rc pointerSource§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
Attempts to downcast this to
T behind Arc pointerSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request