-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get Quote and Pay for Inbound Channel #65
Merged
+255
−72
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
865d016
Make lsp client to request inbound capacity
nickfarrow 63cbd48
Move calculate_fees() to fees(&self)
DanGould ae9d62a
Rename wallet_amount to reserve_deposit
DanGould 5781fd5
Calculate PayJoin fees including inbound quote
DanGould e5deba6
Add inbound payment output to ScheduledPayJoin
DanGould 1bd8c2b
Create Inbound channel request interface
nickfarrow 648534b
Respond to POST /schedule with json
nickfarrow 2953eed
Show quote information if requested
nickfarrow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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={}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should really be a config string but it's viable for this PR |
||
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should really be strongly typed with
bitcoin::Amount
,bitcoin::Amount
,std::time::Duration
(I have NO clue this u32 duration is. ms? seconds? minutes? months? you get my point) andbitcoin::Address
but this PR works and we need to ship. It's not a regression to our codebase but I know we do cleaner work than this.