-
Notifications
You must be signed in to change notification settings - Fork 8
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 #65 from nickfarrow/inbound
Lease inbound capacity as part of the PayJoin
- Loading branch information
Showing
12 changed files
with
255 additions
and
72 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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use bitcoin::Address; | ||
use hyper::{Body, Client, Uri}; | ||
use ln_types::P2PAddress; | ||
use serde_derive::{Deserialize, Serialize}; | ||
|
||
async fn body_to_string(body: Body) -> Result<String, LspError> { | ||
let body_bytes = hyper::body::to_bytes(body).await.map_err(InternalLspError::Hyper)?; | ||
Ok(String::from_utf8(body_bytes.to_vec()).map_err(InternalLspError::FromUtf8)?) | ||
} | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
pub struct Quote { | ||
pub price: u32, | ||
size: u32, | ||
duration: u32, | ||
pub address: String, | ||
} | ||
|
||
pub async fn request_quote( | ||
p2p_address: &P2PAddress, | ||
refund_address: &Address, | ||
) -> Result<Quote, LspError> { | ||
let https = hyper_tls::HttpsConnector::new(); | ||
let client = Client::builder().build::<_, hyper::Body>(https); | ||
// get address | ||
// suggest capacity | ||
let base_uri = format!( | ||
"https://nolooking.chaincase.app/api/request-inbound?nodeid={}&capacity={}&duration={}&refund_address={}", | ||
p2p_address, 1000000, 1, refund_address | ||
); // TODO confirm p2p_address is urlencoded | ||
let url: Uri = base_uri.parse().map_err(InternalLspError::Uri)?; | ||
let req = | ||
hyper::Request::post(url).body(hyper::Body::empty()).map_err(InternalLspError::Http)?; | ||
let res = client.request(req).await.map_err(InternalLspError::Hyper)?; | ||
let body_str = body_to_string(res.into_body()).await?; | ||
let quote: Quote = serde_json::from_str(&body_str).map_err(InternalLspError::SerdeJson)?; | ||
Ok(quote) | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct LspError(InternalLspError); | ||
|
||
#[derive(Debug)] | ||
pub(crate) enum InternalLspError { | ||
Uri(hyper::http::uri::InvalidUri), | ||
FromUtf8(std::string::FromUtf8Error), | ||
Hyper(hyper::Error), | ||
Http(hyper::http::Error), | ||
SerdeJson(serde_json::Error), | ||
} | ||
|
||
impl From<InternalLspError> for LspError { | ||
fn from(value: InternalLspError) -> Self { LspError(value) } | ||
} |
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
Oops, something went wrong.