Skip to content

Commit 1dffe79

Browse files
committed
Update lightning-transaction-sync to use macros crate
1 parent 3bc10e9 commit 1dffe79

File tree

5 files changed

+9
-63
lines changed

5 files changed

+9
-63
lines changed

lightning-macros/src/lib.rs

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,7 @@
2121
use proc_macro::TokenStream;
2222
use quote::quote;
2323
use syn::spanned::Spanned;
24-
use syn::{parse, ImplItemFn, ItemImpl, ItemTrait, Token};
25-
26-
fn add_async_trait(mut parsed: ItemTrait) -> TokenStream {
27-
let output = quote! {
28-
#[cfg(not(feature = "async-interface"))]
29-
#parsed
30-
};
31-
32-
for mut item in &mut parsed.items {
33-
if let syn::TraitItem::Fn(f) = &mut item {
34-
f.sig.asyncness = Some(Token![async](f.span()));
35-
}
36-
}
37-
38-
let output = quote! {
39-
#output
40-
41-
#[cfg(feature = "async-interface")]
42-
#[async_trait(?Send)]
43-
#parsed
44-
};
45-
46-
output.into()
47-
}
24+
use syn::{parse, ImplItemFn, Token};
4825

4926
fn add_async_method(mut parsed: ImplItemFn) -> TokenStream {
5027
let output = quote! {
@@ -64,44 +41,14 @@ fn add_async_method(mut parsed: ImplItemFn) -> TokenStream {
6441
output.into()
6542
}
6643

67-
fn add_async_impl_trait(mut parsed: ItemImpl) -> TokenStream {
68-
let output = quote! {
69-
#[cfg(not(feature = "async-interface"))]
70-
#parsed
71-
};
72-
73-
for mut item in &mut parsed.items {
74-
if let syn::ImplItem::Fn(f) = &mut item {
75-
f.sig.asyncness = Some(Token![async](f.span()));
76-
}
77-
}
78-
79-
let output = quote! {
80-
#output
81-
82-
#[cfg(feature = "async-interface")]
83-
#[async_trait(?Send)]
84-
#parsed
85-
};
86-
87-
output.into()
88-
}
89-
90-
/// Makes a method or every method of a trait `async`, if the `async-interface` feature is enabled.
91-
///
92-
/// Requires the `async-trait` crate as a dependency whenever this attribute is used on a trait
93-
/// definition or trait implementation.
44+
/// Makes a method `async`, if the `async-interface` feature is enabled.
9445
#[proc_macro_attribute]
9546
pub fn maybe_async(_attr: TokenStream, item: TokenStream) -> TokenStream {
96-
if let Ok(parsed) = parse(item.clone()) {
97-
add_async_trait(parsed)
98-
} else if let Ok(parsed) = parse(item.clone()) {
47+
if let Ok(parsed) = parse(item) {
9948
add_async_method(parsed)
100-
} else if let Ok(parsed) = parse(item) {
101-
add_async_impl_trait(parsed)
10249
} else {
10350
(quote! {
104-
compile_error!("#[maybe_async] can only be used on methods, trait or trait impl blocks")
51+
compile_error!("#[maybe_async] can only be used on methods")
10552
})
10653
.into()
10754
}

lightning-transaction-sync/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ async-interface = []
2424

2525
[dependencies]
2626
lightning = { version = "0.0.124", path = "../lightning", default-features = false, features = ["std"] }
27+
lightning-macros = { version = "0.1", path = "../lightning-macros", default-features = false }
2728
bitcoin = { version = "0.32.2", default-features = false }
28-
bdk-macros = "0.6"
2929
futures = { version = "0.3", optional = true }
3030
esplora-client = { version = "0.9", default-features = false, optional = true }
3131
electrum-client = { version = "0.21.0", optional = true }

lightning-transaction-sync/src/esplora.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use lightning::chain::{Confirm, Filter};
1313
use lightning::util::logger::Logger;
1414
use lightning::{log_debug, log_error, log_trace};
1515

16+
use lightning_macros::{maybe_async, maybe_await};
17+
1618
use bitcoin::{BlockHash, Script, Txid};
1719

1820
#[cfg(not(feature = "async-interface"))]

lightning-transaction-sync/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@
7171
#![deny(unsafe_code)]
7272
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
7373

74-
#[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
75-
#[macro_use]
76-
extern crate bdk_macros;
77-
7874
#[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
7975
mod esplora;
8076

lightning-transaction-sync/tests/integration_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use lightning_transaction_sync::ElectrumSyncClient;
1111
#[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
1212
use lightning_transaction_sync::EsploraSyncClient;
1313

14-
use bdk_macros::maybe_await;
14+
use lightning_macros::maybe_await;
15+
1516
use bitcoin::block::Header;
1617
use bitcoin::constants::genesis_block;
1718
use bitcoin::network::Network;

0 commit comments

Comments
 (0)