Skip to content

Commit c3420ab

Browse files
committed
add sync wrapper
1 parent 0bfacff commit c3420ab

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lightning/src/sign/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,24 @@ pub trait ChangeDestinationSource {
996996
fn get_change_destination_script<'a>(&self) -> AsyncGetChangeDestinationScriptResult<'a, ScriptBuf>;
997997
}
998998

999+
1000+
/// A synchronous helper trait that describes an on-chain wallet capable of returning a (change) destination script.
1001+
pub trait ChangeDestinationSourceSync {
1002+
/// This method should return a different value each time it is called, to avoid linking
1003+
/// on-chain funds controlled to the same user.
1004+
fn get_change_destination_script(&self) -> Result<ScriptBuf, ()>;
1005+
}
1006+
1007+
/// A wrapper around [`ChangeDestinationSource`] to allow for async calls.
1008+
pub struct ChangeDestinationSourceSyncWrapper<T>(T) where T: ChangeDestinationSourceSync;
1009+
1010+
impl<T: ChangeDestinationSourceSync> ChangeDestinationSource for ChangeDestinationSourceSyncWrapper<T> {
1011+
fn get_change_destination_script<'a>(&self) -> AsyncGetChangeDestinationScriptResult<'a, ScriptBuf> {
1012+
let script = self.0.get_change_destination_script();
1013+
Box::pin(async move { script })
1014+
}
1015+
}
1016+
9991017
mod sealed {
10001018
use bitcoin::secp256k1::{Scalar, SecretKey};
10011019

0 commit comments

Comments
 (0)