Skip to main content

ConfigurableClientHost

Struct ConfigurableClientHost 

Source
pub struct ConfigurableClientHost<S: ClientStorage> { /* private fields */ }
Expand description

A configurable client host that holds raw secret keys and uses pluggable storage.

This provides a batteries-included implementation of SpilmanClientHost for applications that want to manage keys directly. For hardware wallet integration or external signers, implement SpilmanClientHost directly instead.

§Key Management

Keys are stored in a HashMap indexed by their public key (hex-encoded). When signing operations are requested, the host looks up the corresponding secret key by the provided public key.

§Storage

Channel data is stored via a ClientStorage implementation. The default MemoryClientStorage keeps everything in memory. For persistence, implement ClientStorage for your preferred backend.

§Thread Safety

The storage is wrapped in RefCell for interior mutability, allowing the trait methods (which take &self) to modify storage. This means ConfigurableClientHost is not Sync and cannot be shared across threads. For multi-threaded use, wrap in Mutex or use a thread-safe storage backend.

Implementations§

Source§

impl<S: ClientStorage> ConfigurableClientHost<S>

Source

pub fn new(storage: S) -> Self

Create a new configurable client host with the given storage.

Source

pub fn add_key(&mut self, secret: SecretKey)

Add a keypair to the host.

The key is indexed by its public key (hex-encoded). If a key with the same public key already exists, it is replaced.

Source

pub fn add_key_from_hex(&mut self, secret_hex: &str) -> Result<String, String>

Add a keypair from hex-encoded secret key.

Returns an error if the hex string is invalid.

Source

pub fn get_pubkeys(&self) -> Vec<String>

Get the public keys of all stored keys.

Source

pub fn has_key(&self, pubkey_hex: &str) -> bool

Check if a key exists for the given public key.

Source

pub fn remove_key(&mut self, pubkey_hex: &str) -> bool

Remove a key by public key.

Returns true if a key was removed, false if no key existed.

Source

pub fn storage_mut(&mut self) -> &mut S

Get mutable access to the underlying storage.

Use with caution - this bypasses the normal host interface.

Source

pub fn channel_count(&self) -> usize

Get the number of stored channels.

Source§

impl ConfigurableClientHost<MemoryClientStorage>

Source

pub fn new_in_memory() -> Self

Create a new configurable client host with in-memory storage.

This is a convenience constructor for the common case of using MemoryClientStorage.

Trait Implementations§

Source§

impl<S: Debug + ClientStorage> Debug for ConfigurableClientHost<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: ClientStorage> SpilmanClientHost for ConfigurableClientHost<S>

Source§

fn save_channel_funding(&self, channel_id: &str, funding: ClientChannelFunding)

Save funding data for a newly created channel. Read more
Source§

fn get_channel_funding(&self, channel_id: &str) -> Option<ClientChannelFunding>

Get funding data for a channel. Read more
Source§

fn get_payment_state(&self, channel_id: &str) -> Option<ClientPaymentState>

Get the current payment state for a channel. Read more
Source§

fn record_payment(&self, channel_id: &str, state: ClientPaymentState)

Record a new payment state. Read more
Source§

fn get_channel_state(&self, channel_id: &str) -> ClientChannelState

Get the lifecycle state of a channel.
Source§

fn mark_channel_closed(&self, channel_id: &str)

Mark a channel as closed. Read more
Source§

fn list_channel_ids(&self) -> Vec<String>

List all stored channel IDs.
Source§

fn delete_channel(&self, channel_id: &str)

Delete a channel and all its data.
Source§

fn now_seconds(&self) -> u64

Get the current time in seconds since Unix epoch.
Source§

fn compute_channel_secret( &self, sender_pubkey_hex: &str, receiver_pubkey_hex: &str, ) -> Result<String, String>

Compute the hashed ECDH channel secret for a channel. Read more
Source§

fn sign_with_tweaked_key( &self, signer_pubkey_hex: &str, message_hex: &str, tweak_scalar_hex: &str, ) -> Result<String, String>

Sign a message with a tweaked key (BIP-340 Schnorr). Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more