diff --git a/lnvps_db/migrations/20250305215123_amount-float.sql b/lnvps_db/migrations/20250305215123_amount-float.sql new file mode 100644 index 0000000..66e8249 --- /dev/null +++ b/lnvps_db/migrations/20250305215123_amount-float.sql @@ -0,0 +1,2 @@ +-- Add migration script here +ALTER TABLE vm_cost_plan MODIFY COLUMN amount float NOT NULL; diff --git a/lnvps_db/src/model.rs b/lnvps_db/src/model.rs index ed14d03..b2642a7 100644 --- a/lnvps_db/src/model.rs +++ b/lnvps_db/src/model.rs @@ -179,7 +179,7 @@ pub struct VmCostPlan { pub id: u64, pub name: String, pub created: DateTime, - pub amount: u64, + pub amount: f32, pub currency: String, pub interval_amount: u64, pub interval_type: VmCostPlanIntervalType, diff --git a/src/api/model.rs b/src/api/model.rs index 6fd2f94..f9706ae 100644 --- a/src/api/model.rs +++ b/src/api/model.rs @@ -175,7 +175,7 @@ impl From for ApiVmCostPlanIntervalType { pub struct ApiVmCostPlan { pub id: u64, pub name: String, - pub amount: u64, + pub amount: f32, pub currency: String, pub interval_amount: u64, pub interval_type: ApiVmCostPlanIntervalType, diff --git a/src/mocks.rs b/src/mocks.rs index dc2f851..ab795a9 100644 --- a/src/mocks.rs +++ b/src/mocks.rs @@ -102,7 +102,7 @@ impl Default for MockDb { id: 1, name: "mock".to_string(), created: Utc::now(), - amount: 1, + amount: 1f32, currency: "EUR".to_string(), interval_amount: 1, interval_type: VmCostPlanIntervalType::Month, diff --git a/src/provisioner/lnvps.rs b/src/provisioner/lnvps.rs index 28d3fd4..054f1ce 100644 --- a/src/provisioner/lnvps.rs +++ b/src/provisioner/lnvps.rs @@ -321,7 +321,7 @@ impl LNVpsProvisioner { bail!("No exchange rate found") }; - let cost_btc = cost_plan.amount as f32 / rate; + let cost_btc = cost_plan.amount / rate; let cost_msat = (cost_btc as f64 * BTC_SATS) as u64 * 1000; info!("Creating invoice for {vm_id} for {} sats", cost_msat / 1000); let invoice = self