-
Notifications
You must be signed in to change notification settings - Fork 91
Refactor function signatures where appropriate #481
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
Changes from all commits
e187ebf
6d02133
6cb2cd4
f0f47a1
ee2ddfb
97b0bc4
2599eb1
85aaf0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,7 +183,7 @@ impl<'a> SenderBuilder<'a> { | |
| fn build(self) -> Result<Sender, BuildSenderError> { | ||
| let mut psbt = | ||
| self.psbt.validate().map_err(InternalBuildSenderError::InconsistentOriginalPsbt)?; | ||
| psbt.validate_input_utxos(true).map_err(InternalBuildSenderError::InvalidOriginalInput)?; | ||
| psbt.validate_input_utxos().map_err(InternalBuildSenderError::InvalidOriginalInput)?; | ||
| let endpoint = self.uri.extras.endpoint.clone(); | ||
| let disable_output_substitution = | ||
| self.uri.extras.disable_output_substitution || self.disable_output_substitution; | ||
|
|
@@ -229,15 +229,15 @@ impl Sender { | |
| /// Extract serialized V1 Request and Context from a Payjoin Proposal | ||
| pub fn extract_v1(&self) -> Result<(Request, V1Context), url::ParseError> { | ||
| let url = serialize_url( | ||
| self.endpoint.clone(), | ||
| &self.endpoint, | ||
| self.disable_output_substitution, | ||
| self.fee_contribution, | ||
| self.min_fee_rate, | ||
| "1", // payjoin version | ||
| )?; | ||
| let body = self.psbt.to_string().as_bytes().to_vec(); | ||
| Ok(( | ||
| Request::new_v1(url, body), | ||
| Request::new_v1(&url, &body), | ||
| V1Context { | ||
| psbt_context: PsbtContext { | ||
| original_psbt: self.psbt.clone(), | ||
|
|
@@ -269,13 +269,8 @@ impl V1Context { | |
| /// Call this method with response from receiver to continue BIP78 flow. If the response is | ||
| /// valid you will get appropriate PSBT that you should sign and broadcast. | ||
| #[inline] | ||
| pub fn process_response( | ||
| self, | ||
| response: &mut impl std::io::Read, | ||
| ) -> Result<Psbt, ResponseError> { | ||
| let mut res_str = String::new(); | ||
| response.read_to_string(&mut res_str).map_err(InternalValidationError::Io)?; | ||
| let proposal = Psbt::from_str(&res_str).map_err(|_| ResponseError::parse(&res_str))?; | ||
| pub fn process_response(self, response: &str) -> Result<Psbt, ResponseError> { | ||
|
Collaborator
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. The note in #405 says response could be a @DanGould is there a reason we should use bytes instead of a string?
Collaborator
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. Seems @nothingmuch addressed this same question in his review and I missed it when writing this. |
||
| let proposal = Psbt::from_str(response).map_err(|_| ResponseError::parse(response))?; | ||
| self.psbt_context.process_proposal(proposal).map_err(Into::into) | ||
| } | ||
| } | ||
|
|
@@ -296,7 +291,7 @@ mod test { | |
| "message": "This version of payjoin is not supported." | ||
| }) | ||
| .to_string(); | ||
| match ctx.process_response(&mut known_json_error.as_bytes()) { | ||
| match ctx.process_response(&known_json_error) { | ||
| Err(ResponseError::WellKnown(WellKnownError::VersionUnsupported { .. })) => (), | ||
| _ => panic!("Expected WellKnownError"), | ||
| } | ||
|
|
@@ -307,7 +302,7 @@ mod test { | |
| "message": "This version of payjoin is not supported." | ||
| }) | ||
| .to_string(); | ||
| match ctx.process_response(&mut invalid_json_error.as_bytes()) { | ||
| match ctx.process_response(&invalid_json_error) { | ||
| Err(ResponseError::Validation(_)) => (), | ||
| _ => panic!("Expected unrecognized JSON error"), | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.