Skip to content

Commit

Permalink
Add transaction sync crate
Browse files Browse the repository at this point in the history
This crate provides utilities for syncing LDK via the transaction-based
`Confirm` interface. The initial implementation facilitates
synchronization with an Esplora backend server.
  • Loading branch information
tnull committed Nov 24, 2022
1 parent af7c292 commit c0e0a9e
Show file tree
Hide file tree
Showing 6 changed files with 467 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ jobs:
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client,tokio
- name: Build Transaction Sync Clients on Rust ${{ matrix.toolchain }} with features
if: "!matrix.coverage"
run: |
cd lightning-transaction-sync
cargo build --verbose --color always --features esplora-blocking
cargo build --verbose --color always --features esplora-async
- name: Build Transaction Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
if: matrix.coverage
run: |
cd lightning-transaction-sync
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-blocking
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async
- name: Test backtrace-debug builds on Rust ${{ matrix.toolchain }}
if: "matrix.build-no-std"
run: |
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
members = [
"lightning",
"lightning-block-sync",
"lightning-transaction-sync",
"lightning-invoice",
"lightning-net-tokio",
"lightning-persister",
Expand Down
27 changes: 27 additions & 0 deletions lightning-transaction-sync/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "lightning-transaction-sync"
version = "0.0.112"
authors = ["Elias Rohrer"]
license = "MIT OR Apache-2.0"
repository = "http://github.com/lightningdevkit/rust-lightning"
description = """
Utilities for syncing LDK via the transaction-based `Confirm` interface.
"""
edition = "2018"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["esplora-blocking"]
esplora-async = ["async-interface", "esplora-client/async", "tokio"]
esplora-blocking = ["esplora-client/blocking"]
async-interface = []

[dependencies]
lightning = { version = "0.0.112", path = "../lightning" }
bitcoin = "0.29.0"
bdk-macros = "0.6"
tokio = { version = "1.0", default-features = false, features = [], optional = true }
esplora-client = { git = "https://github.com/tnull/rust-esplora-client", branch = "2022-10-get-merkle-block", default-features = false, optional = true }
30 changes: 30 additions & 0 deletions lightning-transaction-sync/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::fmt;
use esplora_client::Error as EsploraError;

#[derive(Debug)]
/// An error that possibly needs to be handled by the user.
pub enum TxSyncError {
/// A transaction sync failed.
Failed,
/// An inconsisteny was encounterd during transaction sync.
Inconsistency,
}

impl fmt::Display for TxSyncError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Failed => write!(f, "Failed to conduct transaction sync."),
Self::Inconsistency => {
write!(f, "Encountered an inconsisteny during transaction sync.")
}
}
}
}

impl std::error::Error for TxSyncError {}

impl From<EsploraError> for TxSyncError {
fn from(_e: EsploraError) -> Self {
Self::Failed
}
}
Loading

0 comments on commit c0e0a9e

Please sign in to comment.