Skip to content

Commit

Permalink
deps: use ddk manager instead of blocking rust-dlc
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyhodl committed Nov 27, 2024
1 parent 11da8bd commit 0a1359a
Show file tree
Hide file tree
Showing 44 changed files with 378 additions and 272 deletions.
131 changes: 68 additions & 63 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions ddk-node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use crate::ddkrpc::{
};
use anyhow::anyhow;
use ddk::bitcoin::Transaction;
use ddk::dlc::{EnumerationPayout, Payout};
use ddk::dlc_manager::contract::contract_input::ContractInput;
use ddk::dlc_manager::contract::offered_contract::OfferedContract;
use ddk::dlc_manager::contract::Contract;
use ddk::dlc_messages::oracle_msgs::{EventDescriptor, OracleAnnouncement};
use ddk::dlc_messages::{AcceptDlc, OfferDlc};
use ddk::ddk_dlc::{EnumerationPayout, Payout};
use ddk::ddk_manager::contract::contract_input::ContractInput;
use ddk::ddk_manager::contract::offered_contract::OfferedContract;
use ddk::ddk_manager::contract::Contract;
use ddk::ddk_messages::oracle_msgs::{EventDescriptor, OracleAnnouncement};
use ddk::ddk_messages::{AcceptDlc, OfferDlc};
use ddk::util;
use ddk::wallet::LocalOutput;
use inquire::{Select, Text};
Expand Down Expand Up @@ -172,6 +172,8 @@ pub async fn cli_command(
})
.await?
.into_inner();
let offer_hex = hex::encode(&offer.offer_dlc);
println!("{}", offer_hex);
let offer_dlc: OfferDlc = serde_json::from_slice(&offer.offer_dlc)?;
let offer = serde_json::to_string_pretty(&offer_dlc)?;
print!("{}", offer);
Expand All @@ -193,6 +195,8 @@ pub async fn cli_command(
.await?
.into_inner();
let accept_dlc: AcceptDlc = serde_json::from_slice(&accept.accept_dlc)?;
let accept_hex = hex::encode(&accept.accept_dlc);
println!("{}", accept_hex);
let accept_dlc = serde_json::to_string_pretty(&accept_dlc)?;
print!("{}", accept_dlc)
}
Expand Down
2 changes: 1 addition & 1 deletion ddk-node/src/convert.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ddk::dlc_manager::contract::{
use ddk::ddk_manager::contract::{
accepted_contract::AcceptedContract, offered_contract::OfferedContract,
signed_contract::SignedContract, ClosedContract, Contract, FailedAcceptContract,
FailedSignContract, PreClosedContract,
Expand Down
8 changes: 4 additions & 4 deletions ddk-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ mod seed;
use ddk::bitcoin::secp256k1::PublicKey;
use ddk::bitcoin::{Address, Amount, FeeRate, Network};
use ddk::builder::Builder;
use ddk::dlc_manager::contract::contract_input::ContractInput;
use ddk::dlc_manager::Oracle as DlcOracle;
use ddk::dlc_manager::Storage as DlcStorage;
use ddk::ddk_manager::contract::contract_input::ContractInput;
use ddk::ddk_manager::Oracle as DlcOracle;
use ddk::ddk_manager::Storage as DlcStorage;
use ddk::oracle::kormir::KormirOracleClient;
use ddk::storage::sled::SledStorage;
use ddk::transport::lightning::LightningTransport;
Expand Down Expand Up @@ -87,7 +87,7 @@ impl DdkNode {
builder.set_storage(storage.clone());
builder.set_oracle(oracle.clone());

let ddk: Ddk = builder.finish()?;
let ddk: Ddk = builder.finish().await?;

ddk.start()?;

Expand Down
26 changes: 10 additions & 16 deletions ddk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ p2pderivatives = ["dep:reqwest"]
sled = ["dep:sled"]

[dependencies]
# dlc = { version = "0.7.0", features = ["use-serde"] }
# dlc-manager = { version = "0.7.0", features = ["use-serde"] }
# dlc-messages = { version = "0.7.0", features = [ "use-serde"] }
# dlc-trie = { version = "0.7.0", features = ["use-serde"] }
dlc = { version = "0.7.0", git = "https://github.com/bennyhodl/rust-dlc", branch = "async", features = ["use-serde"] }
dlc-manager = { version = "0.7.0", git = "https://github.com/bennyhodl/rust-dlc", branch = "async", features = ["use-serde", "async"] }
dlc-messages = { version = "0.7.0", git = "https://github.com/bennyhodl/rust-dlc", branch = "async", features = [ "use-serde"] }
dlc-trie = { version = "0.7.0", git = "https://github.com/bennyhodl/rust-dlc", branch = "async", features = ["use-serde"] }
# dlc = { version = "0.7.0", path = "../../rust-dlc/dlc", features = ["use-serde"] }
# dlc-manager = { version = "0.7.0", path = "../../rust-dlc/dlc-manager", features = ["use-serde", "async"] }
# dlc-messages = { version = "0.7.0", path = "../../rust-dlc/dlc-messages", features = [ "use-serde"] }
# dlc-trie = { version = "0.7.0", path = "../../rust-dlc/dlc-trie", features = ["use-serde"] }

ddk-dlc = { version = "0.7.0", features = ["use-serde"] }
ddk-manager = { version = "0.7.1", features = ["use-serde"] }
ddk-messages = { version = "0.7.0", features = [ "use-serde"] }
ddk-trie = { version = "0.7.0", features = ["use-serde"] }
# ddk-dlc = { version = "0.7.0", path = "../../rust-dlc/dlc", features = ["use-serde"] }
# ddk-manager = { version = "0.7.1", path = "../../rust-dlc/dlc-manager", features = ["use-serde", "async"] }
# ddk-messages = { version = "0.7.0", path = "../../rust-dlc/dlc-messages", features = [ "use-serde"] }
# ddk-trie = { version = "0.7.0", path = "../../rust-dlc/dlc-trie", features = ["use-serde"] }

bitcoin = { version = "0.32.2", features = ["rand", "serde"] }
bdk_esplora = { version = "0.19", features = ["blocking", "async"] }
Expand Down Expand Up @@ -70,9 +65,8 @@ lightning-net-tokio = { version = "0.0.125", optional = true }

# oracle feature
reqwest = { version = "0.12.9", features = ["blocking"], optional = true }
# kormir = "0.3.0"
kormir = { version = "0.3.0", git = "https://github.com/bennyhodl/kormir", branch = "rust-dlc-async", optional = true }
# kormir = { version = "0.3.0", path = "../../kormir/kormir" }
kormir = { version = "0.3.2", optional = true }
# kormir = { version = "0.3.2", path = "../../kormir/kormir", optional = true }

[dev-dependencies]
test-log = { version = "0.2.16", features = ["trace"] }
Expand Down
2 changes: 1 addition & 1 deletion ddk/examples/ddk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn main() -> Result<()> {
builder.set_storage(storage.clone());
builder.set_oracle(oracle_client.clone());

let ddk: ApplicationDdk = builder.finish()?;
let ddk: ApplicationDdk = builder.finish().await?;

ddk.start().expect("couldn't start ddk");

Expand Down
31 changes: 17 additions & 14 deletions ddk/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bitcoin::Network;
use crossbeam::channel::unbounded;
use dlc_manager::manager::Manager;
use dlc_manager::SystemTimeProvider;
use ddk_manager::manager::Manager;
use ddk_manager::SystemTimeProvider;
use std::collections::HashMap;
use std::sync::{Arc, RwLock};

Expand Down Expand Up @@ -78,14 +78,14 @@ impl<T: Transport, S: Storage, O: Oracle> Builder<T, S, O> {
self
}

/// DLC contract storage. Storage is used by the [dlc_manager::manager::Manager] to create, update, retrieve, and
/// DLC contract storage. Storage is used by the [ddk_manager::manager::Manager] to create, update, retrieve, and
/// delete contracts. MUST implement [crate::Storage]
pub fn set_storage(&mut self, storage: Arc<S>) -> &mut Self {
self.storage = Some(storage);
self
}

/// Oracle implementation for the [dlc_manager::manager::Manager] to retrieve oracle attestations and announcements.
/// Oracle implementation for the [ddk_manager::manager::Manager] to retrieve oracle attestations and announcements.
/// MUST implement [crate::Oracle].
pub fn set_oracle(&mut self, oracle: Arc<O>) -> &mut Self {
self.oracle = Some(oracle);
Expand All @@ -111,7 +111,7 @@ impl<T: Transport, S: Storage, O: Oracle> Builder<T, S, O> {
}

/// Builds the `DlcDevKit` instance. Fails if any components are missing.
pub fn finish(&self) -> anyhow::Result<DlcDevKit<T, S, O>> {
pub async fn finish(&self) -> anyhow::Result<DlcDevKit<T, S, O>> {
tracing::info!(
network = self.network.to_string(),
esplora = self.esplora_host,
Expand Down Expand Up @@ -153,15 +153,18 @@ impl<T: Transport, S: Storage, O: Oracle> Builder<T, S, O> {

let (sender, receiver) = unbounded::<DlcManagerMessage>();

let manager = Arc::new(Manager::new(
wallet.clone(),
wallet.clone(),
esplora_client.clone(),
storage.clone(),
oracles,
Arc::new(SystemTimeProvider {}),
wallet.clone(),
)?);
let manager = Arc::new(
Manager::new(
wallet.clone(),
wallet.clone(),
esplora_client.clone(),
storage.clone(),
oracles,
Arc::new(SystemTimeProvider {}),
wallet.clone(),
)
.await?,
);
tracing::info!("Created ddk dlc manager.");

Ok(DlcDevKit {
Expand Down
Loading

0 comments on commit 0a1359a

Please sign in to comment.