title | author | theme | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Dlc Dev Kit - Application SDK for DLCs |
benny b |
|
Creating a DLC application is complex. Existing libraries provided excellent core functionality but were fragmented.
- Contract creation and management
- Contract storage
- Message handling
- Wallet integration
- No unified solution for quick prototyping
- Contract Management
- Contract Execution
- Contract Storage
- DLC Messaging
- Wallet
cargo install ddk-node
# or latest
cargo install --git https://github.com/bennyhodl/dlcdevkit.git ddk-node
cargo add ddk
# or latest
cargo add --git https://github.com/bennyhodl/dlcdevkit.git ddk
- Transport
- Storage
- Oracle Client
cargo add ddk --features lightning
use std::sync::Arc;
use ddk::builder::Builder;
use ddk::storage::SledStorage;
use ddk::transport::lightning::LightningTransport;
use ddk::oracle::KormirOracleClient;
use bitcoin::Network;
type ApplicationDdk = ddk::DlcDevKit<LightningTransport, SledStorage, KormirOracleClient>;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let transport = Arc::new(LightningTransport::new([0u8;32], 9735, Network::Regtest)?);
let storage = Arc::new(SledStorage::new("/tmp/ddk")?);
let oracle = Arc::new(KormirOracleClient::new("http://127.0.0.1:8080").await?);
let ddk: ApplicationDdk = Builder::new()
.set_seed_bytes([0u8;32])
.set_network(Network::Regtest)
.set_storage_path("/tmp/ddk")
.set_esplora_path("http://127.0.0.1:3000")
.set_transport(transport.clone())
.set_storage(storage.clone())
.set_oracle(oracle_client.clone())
.finish()?;
ddk.start()?;
}
/// Allows ddk to open a listening connection and send/receive dlc messages functionality.
pub trait Transport {
/// Name for the transport service.
fn name(&self) -> String;
/// Open an incoming listener for DLC messages from peers.
async fn listen(&self);
/// Get messages that have not been processed yet.
async fn receive_messages<S: Storage, O: Oracle>(
&self,
manager: Arc<DlcDevKitDlcManager<S, O>>,
);
/// Send a message to a specific counterparty.
fn send_message(&self, counterparty: PublicKey, message: Message);
/// Connect to another peer
async fn connect_outbound(&self, pubkey: PublicKey, host: &str);
}
https://github.com/bennyhodl/dlcdevkit/blob/master/ddk/src/transport/lightning/mod.rs
/// Storage for DLC contracts.
pub trait Storage: dlc_manager::Storage + DeriveSigner {
/// Instantiate the storage for the BDK wallet.
fn initialize_bdk(&self) -> Result<ChangeSet, WalletError>;
/// Save changeset to the wallet storage.
fn persist_bdk(&self, changeset: &ChangeSet) -> Result<(), WalletError>;
/// Connected counterparties.
fn list_peers(&self) -> Result<Vec<PeerInformation>, Error>;
/// Persist counterparty.
fn save_peer(&self, peer: PeerInformation) -> Result<(), Error>;
/// Marketplace methods
#[cfg(feature = "marketplace")]
fn save_announcement(&self, announcement: OracleAnnouncement) -> Result<(), Error>;
#[cfg(feature = "marketplace")]
fn get_marketplace_announcements(&self) -> Result<Vec<OracleAnnouncement>, Error>;
}
https://github.com/bennyhodl/dlcdevkit/tree/master/ddk/src/storage/sled
/// Oracle client
pub trait Oracle: dlc_manager::Oracle {
fn name(&self) -> String;
}
/// Oracle trait provides access to oracle information.
pub trait Oracle {
/// Returns the public key of the oracle.
fn get_public_key(&self) -> XOnlyPublicKey;
/// Returns the announcement for the event with the given id if found.
fn get_announcement(&self, event_id: &str) -> Result<OracleAnnouncement, Error>;
/// Returns the attestation for the event with the given id if found.
fn get_attestation(&self, event_id: &str) -> Result<OracleAttestation, Error>;
}
https://github.com/bennyhodl/dlcdevkit/blob/master/ddk/src/oracle/kormir.rs
- gRPC servers
- REST API services
- P2P networking
- Client/Server model
- Document or relational database
- Nostr communication
- Matrix communication
- IndexedDB storage
- Browser based
- Mobile applications
Written in 🦀. Ability for library consumers to use DDK in the language and platform they are comfortable with.
Finalize and comply to NIP-88.
- Nostr transport module
- IndexedDB storage module
- Oracle Announcement marketplace
- Finalize async support
- Taproot support
- Covenant research (https://github.com/bennyhodl/dlcat)
There is an example node that is available via crates.io. But I would like to have a desktop application for beginners. Ideally, installable to node-in-a-box solutions.