Skip to content

Commit

Permalink
Merge pull request #828 from golemfactory/wiezzel/compute-cost
Browse files Browse the repository at this point in the history
Payment service panic fixed
  • Loading branch information
Wiezzel authored Nov 25, 2020
2 parents f7151f5 + e025b99 commit 6ffec0f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion agent/provider/src/payments/agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pub async fn compute_cost(

let cost = payment_model.compute_cost(&usage)?;

Ok(CostInfo { cost, usage })
Ok(CostInfo::new(usage, cost))
}

impl ActivitiesWaiter {
Expand Down
6 changes: 4 additions & 2 deletions core/payment/src/dao/agreement.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::dao::{invoice, invoice_event};
use crate::error::DbResult;
use crate::error::{DbError, DbResult};
use crate::models::agreement::{ReadObj, WriteObj};
use crate::schema::pay_activity::dsl as activity_dsl;
use crate::schema::pay_agreement::dsl;
Expand Down Expand Up @@ -41,7 +41,9 @@ pub fn set_amount_due(
let agreement: ReadObj = dsl::pay_agreement
.find((agreement_id, owner_id))
.first(conn)?;
assert!(total_amount_due >= &agreement.total_amount_due); // TODO: Remove when payment service is production-ready.
if total_amount_due < &agreement.total_amount_due {
return Err(DbError::Query(format!("Requested amount for agreement cannot be lowered. Current amount requested: {} Amount on invoice: {}", agreement.total_amount_due, total_amount_due)));
}
diesel::update(&agreement)
.set(dsl::total_amount_due.eq(total_amount_due))
.execute(conn)?;
Expand Down

0 comments on commit 6ffec0f

Please sign in to comment.