Skip to main content

DlcDevKit

Struct DlcDevKit 

Source
pub struct DlcDevKit<T: Transport, S: Storage, O: Oracle> {
    pub runtime: Arc<RwLock<Option<Runtime>>>,
    pub wallet: Arc<DlcDevKitWallet>,
    pub manager: Arc<Manager<Arc<DlcDevKitWallet>, Arc<CachedContractSignerProvider<Arc<DlcDevKitWallet>, SimpleSigner>>, Arc<EsploraClient>, Arc<S>, Arc<O>, Arc<SystemTimeProvider>, Arc<DlcDevKitWallet>, SimpleSigner, Arc<Logger>>>,
    pub sender: Sender<DlcManagerMessage>,
    pub transport: Arc<T>,
    pub storage: Arc<S>,
    pub oracle: Arc<O>,
    pub network: Network,
    pub stop_signal: Receiver<bool>,
    pub stop_signal_sender: Sender<bool>,
    pub logger: Arc<Logger>,
}
Expand description

DDK object with all services Main DDK instance that encapsulates all DLC functionality.

This struct manages:

  1. Runtime Context:

    • Single tokio runtime for all async operations
    • Background task management
    • Graceful shutdown handling
  2. Core Components:

    • Wallet for Bitcoin operations
    • DLC manager for contract operations
    • Transport layer for peer communication
    • Storage backend for persistence
    • Oracle client for external data
  3. Communication:

    • Message channel to the DLC manager actor
    • Stop signal broadcasting for shutdown coordination

The struct is designed to be thread-safe and can be shared across multiple threads using Arc.

Fieldsยง

ยงruntime: Arc<RwLock<Option<Runtime>>>

Tokio runtime for async operations

ยงwallet: Arc<DlcDevKitWallet>

Bitcoin wallet instance

ยงmanager: Arc<Manager<Arc<DlcDevKitWallet>, Arc<CachedContractSignerProvider<Arc<DlcDevKitWallet>, SimpleSigner>>, Arc<EsploraClient>, Arc<S>, Arc<O>, Arc<SystemTimeProvider>, Arc<DlcDevKitWallet>, SimpleSigner, Arc<Logger>>>

DLC manager instance

ยงsender: Sender<DlcManagerMessage>

Channel for sending messages to the DLC manager

ยงtransport: Arc<T>

Transport layer implementation

ยงstorage: Arc<S>

Storage backend implementation

ยงoracle: Arc<O>

Oracle client implementation

ยงnetwork: Network

Bitcoin network (mainnet, testnet, regtest)

ยงstop_signal: Receiver<bool>

Receiver for stop signal

ยงstop_signal_sender: Sender<bool>

Sender for stop signal

ยงlogger: Arc<Logger>

Logger instance for structured logging

Implementationsยง

Sourceยง

impl<T, S, O> DlcDevKit<T, S, O>
where T: Transport, S: Storage, O: Oracle,

Source

pub fn start(&self) -> Result<(), Error>

Starts the DDK runtime with a new multi-threaded tokio runtime. This spawns all necessary background tasks:

  • Transport layer listeners
  • Wallet synchronization
  • Periodic contract checks
Source

pub fn start_with_runtime(&self, runtime: Runtime) -> Result<(), Error>

Starts the DDK runtime with a provided tokio runtime. Useful when integrating with existing async applications.

This method spawns three critical background tasks:

  1. Transport Listener Thread:
  • Handles incoming DLC messages
  • Manages peer connections
  • Routes messages to DLC manager
  • Gracefully shuts down on stop signal
  1. Wallet Sync Thread:
  • Runs every 60 seconds
  • Updates UTXO set
  • Syncs with blockchain
  • Maintains wallet state
  1. Contract Monitor Thread:
  • Runs every 30 seconds
  • Checks contract states
  • Triggers necessary updates
  • Maintains contract lifecycle
ยงArguments
  • runtime - A tokio runtime to use for async operations
ยงReturns
  • Ok(()) if runtime started successfully
  • Err(Error::RuntimeExists) if runtime is already running
Source

pub fn stop(&self) -> Result<(), Error>

Gracefully stops the DDK runtime and all background tasks. This ensures:

  • All listeners are closed
  • Background tasks are terminated
  • Resources are properly cleaned up
Source

pub fn network(&self) -> Network

Returns the configured Bitcoin network

Source

pub async fn send_dlc_offer( &self, contract_input: &ContractInput, counter_party: PublicKey, oracle_announcements: Vec<OracleAnnouncement>, ) -> Result<OfferDlc, Error>

Creates and sends a new DLC offer to a counterparty.

This method:

  1. Creates a DLC offer message
  2. Sends it through the transport layer
  3. Returns the created offer for further processing
Source

pub async fn accept_dlc_offer( &self, contract: [u8; 32], ) -> Result<(String, String, AcceptDlc), Error>

Accepts an existing DLC offer.

This method:

  1. Processes the acceptance
  2. Creates acceptance message
  3. Sends it to the counterparty
  4. Returns the acceptance details
Source

pub async fn refund_dlc( &self, contract_id: &[u8; 32], ) -> Result<Contract, Error>

Refunds a DLC contract.

This method checks if the refund locktime has passed and broadcasts the refund transaction if it has.

ยงArguments
  • contract_id - The ID of the contract to refund
ยงErrors if the contract maturity has not passed to broadcast refund
Source

pub async fn balance(&self) -> Result<Balance, Error>

Retrieves the current balance state, including:

  • Confirmed balance
  • Unconfirmed changes
  • Funds locked in contracts
  • Total profit/loss from closed contracts

Trait Implementationsยง

Sourceยง

impl<T: Debug + Transport, S: Debug + Storage, O: Debug + Oracle> Debug for DlcDevKit<T, S, O>

Sourceยง

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

Formats the value using the given formatter. Read more

Auto Trait Implementationsยง

ยง

impl<T, S, O> Freeze for DlcDevKit<T, S, O>

ยง

impl<T, S, O> !RefUnwindSafe for DlcDevKit<T, S, O>

ยง

impl<T, S, O> Send for DlcDevKit<T, S, O>

ยง

impl<T, S, O> Sync for DlcDevKit<T, S, O>

ยง

impl<T, S, O> Unpin for DlcDevKit<T, S, O>

ยง

impl<T, S, O> UnsafeUnpin for DlcDevKit<T, S, O>

ยง

impl<T, S, O> !UnwindSafe for DlcDevKit<T, S, O>

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> PolicyExt for T
where T: ?Sized,

Sourceยง

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Sourceยง

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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
Sourceยง

impl<T> ErasedDestructor for T
where T: 'static,