-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8c1572
commit 767760c
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::path::PathBuf; | ||
use tokio::runtime::{Builder, Runtime}; | ||
use tonic_lnd::signrpc::{KeyDescriptor, KeyLocator, SignMessageReq, SignMessageResp}; | ||
use tonic_lnd::{connect, Client}; | ||
|
||
// For some LND grpc calls, we need a blocking version of the client. Namely, in order to use LDK's "sign" | ||
// API for signing an invoice request, the provided closure containing the LND signing API calls can't be | ||
// asynchronous. | ||
pub(crate) struct BlockingClient { | ||
client: Client, | ||
rt: Runtime, | ||
} | ||
|
||
impl BlockingClient { | ||
pub(crate) fn connect( | ||
address: String, | ||
cert_path: PathBuf, | ||
macaroon_path: PathBuf, | ||
) -> Result<Self, tonic::transport::Error> { | ||
let rt = Builder::new_multi_thread().enable_all().build().unwrap(); | ||
let client = rt | ||
.block_on(connect(address, cert_path, macaroon_path)) | ||
.unwrap(); | ||
|
||
Ok(Self { client, rt }) | ||
} | ||
|
||
pub(crate) fn derive_key( | ||
&mut self, | ||
request: KeyLocator, | ||
) -> Result<tonic_lnd::tonic::Response<KeyDescriptor>, tonic_lnd::tonic::Status> { | ||
self.rt.block_on(self.client.wallet().derive_key(request)) | ||
} | ||
|
||
pub(crate) fn sign_message( | ||
&mut self, | ||
request: SignMessageReq, | ||
) -> Result<tonic_lnd::tonic::Response<SignMessageResp>, tonic_lnd::tonic::Status> { | ||
self.rt.block_on(self.client.signer().sign_message(request)) | ||
} | ||
} |