-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from okjodom/node-nfo
feat: get node info
- Loading branch information
Showing
5 changed files
with
118 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
@@ -1,26 +1,66 @@ | ||
use crate::{LightningNode, PaymentError}; | ||
use std::str::FromStr; | ||
|
||
use crate::{LightningError, LightningNode, NodeInfo}; | ||
use async_trait::async_trait; | ||
use bitcoin::secp256k1::PublicKey; | ||
use lightning::ln::PaymentHash; | ||
use tonic_lnd::Client; | ||
use tonic_lnd::{ | ||
lnrpc::{GetInfoRequest, GetInfoResponse}, | ||
Client, | ||
}; | ||
|
||
#[allow(dead_code)] | ||
pub struct LndNode { | ||
client: Client, | ||
} | ||
|
||
impl LndNode { | ||
pub async fn new(address: String, macaroon: String, cert: String) -> anyhow::Result<Self> { | ||
let client = tonic_lnd::connect(address, cert, macaroon).await?; | ||
pub async fn new( | ||
address: String, | ||
macaroon: String, | ||
cert: String, | ||
) -> Result<Self, LightningError> { | ||
let client = tonic_lnd::connect(address, cert, macaroon) | ||
.await | ||
.map_err(|err| LightningError::ConnectionError(err.to_string()))?; | ||
Ok(Self { client }) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl LightningNode for LndNode { | ||
fn send_payment(&self, _dest: PublicKey, _amt_msat: u64) -> anyhow::Result<PaymentHash> { | ||
async fn get_info(&self) -> Result<NodeInfo, LightningError> { | ||
let mut client = self.client.clone(); | ||
let ln_client = client.lightning(); | ||
|
||
let GetInfoResponse { | ||
identity_pubkey, | ||
features, | ||
alias, | ||
.. | ||
} = ln_client | ||
.get_info(GetInfoRequest {}) | ||
.await | ||
.map_err(|err| LightningError::GetInfoError(err.to_string()))? | ||
.into_inner(); | ||
|
||
Ok(NodeInfo { | ||
pubkey: PublicKey::from_str(&identity_pubkey) | ||
.map_err(|err| LightningError::GetInfoError(err.to_string()))?, | ||
features: features.keys().copied().collect(), | ||
alias, | ||
}) | ||
} | ||
|
||
async fn send_payment( | ||
&self, | ||
_dest: PublicKey, | ||
_amount_msat: u64, | ||
) -> Result<PaymentHash, LightningError> { | ||
unimplemented!() | ||
} | ||
|
||
fn track_payment(&self, _hash: PaymentHash) -> Result<(), PaymentError> { | ||
async fn track_payment(&self, _hash: PaymentHash) -> Result<(), LightningError> { | ||
unimplemented!() | ||
} | ||
} |