Skip to content
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

Make signature optional to support 0.6.x requestors #1370

Merged
merged 1 commit into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/model/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,14 @@ pub mod public {
// *************************** PAYMENT ****************************
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct SendPayment {
#[serde(flatten)] // Flatten is required for backwards compatability with 0.6.x
pub payment: Payment,
pub signature: Vec<u8>,
#[serde(default)] // Optional is required for backwards compatability with 0.6.x
pub signature: Option<Vec<u8>>,
}

impl SendPayment {
pub fn new(payment: Payment, signature: Vec<u8>) -> Self {
pub fn new(payment: Payment, signature: Option<Vec<u8>>) -> Self {
Self { payment, signature }
}
}
Expand Down
16 changes: 9 additions & 7 deletions core/payment/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl PaymentProcessor {
.await??;

counter!("payment.amount.sent", ya_metrics::utils::cryptocurrency_to_u64(&msg.amount), "platform" => payment_platform);
let msg = SendPayment::new(payment, signature);
let msg = SendPayment::new(payment, Some(signature));

// Spawning to avoid deadlock in a case that payee is the same node as payer
Arbiter::spawn(
Expand Down Expand Up @@ -463,7 +463,7 @@ impl PaymentProcessor {
pub async fn verify_payment(
&self,
payment: Payment,
signature: Vec<u8>,
signature: Option<Vec<u8>>,
) -> Result<(), VerifyPaymentError> {
// TODO: Split this into smaller functions
let platform = payment.payment_platform.clone();
Expand All @@ -473,11 +473,13 @@ impl PaymentProcessor {
AccountMode::RECV,
)?;

if !driver_endpoint(&driver)
.send(driver::VerifySignature::new(payment.clone(), signature))
.await??
{
return Err(VerifyPaymentError::InvalidSignature);
if let Some(signature) = signature {
if !driver_endpoint(&driver)
.send(driver::VerifySignature::new(payment.clone(), signature))
.await??
{
return Err(VerifyPaymentError::InvalidSignature);
}
}

let confirmation = match base64::decode(&payment.details) {
Expand Down