pub struct OfflineClient<B, W, S, K> {
pub name: String,
/* private fields */
}Expand description
A client to interact with Ark Server
§Example
struct MyBlockchain {}
struct MyWallet {}
struct InMemoryDb {}
// Initialize the client with a static keypair
async fn init_client_with_keypair() -> Result<Client<MyBlockchain, MyWallet, InMemorySwapStorage, ark_client::StaticKeyProvider>, 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 timeout = Duration::from_secs(30);
// Create the offline client (backward compatible method)
let offline_client = OfflineClient::<MyBlockchain, MyWallet, InMemorySwapStorage, StaticKeyProvider>::new_with_keypair(
"my-ark-client".to_string(),
keypair,
blockchain,
wallet,
"https://ark-server.example.com".to_string(),
Arc::new(InMemorySwapStorage::default()),
"http://boltz.example.com".to_string(),
None,
timeout,
None,
vec![],
);
// 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::Bip32KeyProvider>, 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();
let key_provider = Arc::new(ark_client::Bip32KeyProvider::new(master_key, derivation_path));
// Initialize blockchain and wallet implementations
let blockchain = Arc::new(MyBlockchain::new("https://esplora.example.com"));
let wallet = Arc::new(MyWallet {});
let timeout = Duration::from_secs(30);
// Create the offline client with BIP32 key provider
let offline_client = OfflineClient::new(
"my-ark-client".to_string(),
key_provider,
blockchain,
wallet,
"https://ark-server.example.com".to_string(),
Arc::new(InMemorySwapStorage::default()),
"http://boltz.example.com".to_string(),
None,
timeout,
None,
vec![],
);
// Connect to the Ark server and get server info
let client = offline_client.connect().await?;
Ok(client)
}Fields§
§name: StringImplementations§
Source§impl<B, W, S, K> OfflineClient<B, W, S, K>
impl<B, W, S, K> OfflineClient<B, W, S, K>
Sourcepub fn new(
name: String,
key_provider: Arc<K>,
blockchain: Arc<B>,
wallet: Arc<W>,
ark_server_url: String,
swap_storage: Arc<S>,
boltz_url: String,
boltz_referral_id: Option<String>,
timeout: Duration,
delegator_pk: Option<XOnlyPublicKey>,
historical_delegator_pks: Vec<XOnlyPublicKey>,
) -> Self
pub fn new( name: String, key_provider: Arc<K>, blockchain: Arc<B>, wallet: Arc<W>, ark_server_url: String, swap_storage: Arc<S>, boltz_url: String, boltz_referral_id: Option<String>, timeout: Duration, delegator_pk: Option<XOnlyPublicKey>, historical_delegator_pks: Vec<XOnlyPublicKey>, ) -> Self
Create a new offline client with a generic key provider
§Arguments
name- Client identifierkey_provider- Implementation of KeyProvider trait (StaticKeyProvider, Bip32KeyProvider, etc.)blockchain- Blockchain interface implementationwallet- Wallet implementationark_server_url- URL of the Ark serverswap_storage- Storage implementation for swap databoltz_url- URL of the Boltz serverboltz_referral_id- Boltz referral ID to be included in all swap creation requests as thereferralIdfield. WhenNone, defaults toDEFAULT_BOLTZ_REFERRAL_ID. To send no referral ID at all, callOfflineClient::with_boltz_referral_idwithNoneafter construction.timeout- Timeout duration for network operations
Sourcepub fn with_boltz_referral_id(self, boltz_referral_id: Option<String>) -> Self
pub fn with_boltz_referral_id(self, boltz_referral_id: Option<String>) -> Self
Override the Boltz referral ID after construction.
Pass Some(...) to set a custom value, or None to send no referralId field with
swap creation requests (this opts out of the SDK default).
Sourcepub fn new_with_keypair(
name: String,
kp: Keypair,
blockchain: Arc<B>,
wallet: Arc<W>,
ark_server_url: String,
swap_storage: Arc<S>,
boltz_url: String,
boltz_referral_id: Option<String>,
timeout: Duration,
delegator_pk: Option<XOnlyPublicKey>,
historical_delegator_pks: Vec<XOnlyPublicKey>,
) -> OfflineClient<B, W, S, StaticKeyProvider>
pub fn new_with_keypair( name: String, kp: Keypair, blockchain: Arc<B>, wallet: Arc<W>, ark_server_url: String, swap_storage: Arc<S>, boltz_url: String, boltz_referral_id: Option<String>, timeout: Duration, delegator_pk: Option<XOnlyPublicKey>, historical_delegator_pks: Vec<XOnlyPublicKey>, ) -> OfflineClient<B, W, S, StaticKeyProvider>
Create a new offline client with a static keypair (backward compatible)
This is a convenience method that wraps a single keypair in a StaticKeyProvider.
§Arguments
name- Client identifierkp- Static keypair for signingblockchain- Blockchain interface implementationwallet- Wallet implementationark_server_url- URL of the Ark serverswap_storage- Storage implementation for swap databoltz_url- URL of the Boltz servertimeout- Timeout duration for network operations
Sourcepub fn new_with_bip32(
name: String,
xpriv: Xpriv,
path: Option<DerivationPath>,
blockchain: Arc<B>,
wallet: Arc<W>,
ark_server_url: String,
swap_storage: Arc<S>,
boltz_url: String,
boltz_referral_id: Option<String>,
timeout: Duration,
delegator_pk: Option<XOnlyPublicKey>,
historical_delegator_pks: Vec<XOnlyPublicKey>,
) -> OfflineClient<B, W, S, Bip32KeyProvider>
pub fn new_with_bip32( name: String, xpriv: Xpriv, path: Option<DerivationPath>, blockchain: Arc<B>, wallet: Arc<W>, ark_server_url: String, swap_storage: Arc<S>, boltz_url: String, boltz_referral_id: Option<String>, timeout: Duration, delegator_pk: Option<XOnlyPublicKey>, historical_delegator_pks: Vec<XOnlyPublicKey>, ) -> OfflineClient<B, W, S, Bip32KeyProvider>
Create a new offline client with an Xpriv
§Arguments
name- Client identifierxpriv- BIP32 Xprivblockchain- Blockchain interface implementationwallet- Wallet implementationark_server_url- URL of the Ark serverswap_storage- Storage implementation for swap databoltz_url- URL of the Boltz servertimeout- Timeout duration for network operations
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§
Source§impl<B: Clone, W: Clone, S: Clone, K: Clone> Clone for OfflineClient<B, W, S, K>
impl<B: Clone, W: Clone, S: Clone, K: Clone> Clone for OfflineClient<B, W, S, K>
Source§fn clone(&self) -> OfflineClient<B, W, S, K>
fn clone(&self) -> OfflineClient<B, W, S, K>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<B, W, S, K> !Freeze for OfflineClient<B, W, S, K>
impl<B, W, S, K> !RefUnwindSafe for OfflineClient<B, W, S, K>
impl<B, W, S, K> !UnwindSafe for OfflineClient<B, W, S, K>
impl<B, W, S, K> Send for OfflineClient<B, W, S, K>
impl<B, W, S, K> Sync for OfflineClient<B, W, S, K>
impl<B, W, S, K> Unpin for OfflineClient<B, W, S, K>
impl<B, W, S, K> UnsafeUnpin for OfflineClient<B, W, S, K>
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