improved AppContract pricing calculation precision
This commit is contained in:
parent
928a7d029b
commit
41352f2c33
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -420,7 +420,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "detee-shared"
|
name = "detee-shared"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#dc1e2dd0cd70f0915245fe3cae0863eab838fe5a"
|
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#a734b392b7dba31693337b5a806d30cc9b8cd967"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"prost",
|
"prost",
|
||||||
|
24
src/data.rs
24
src/data.rs
@ -195,20 +195,16 @@ pub struct AppContract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppContract {
|
impl AppContract {
|
||||||
fn total_units(&self) -> u64 {
|
fn total_units(&self) -> f64 {
|
||||||
// TODO: Optimize this based on price of hardware.
|
// TODO: Optimize this based on price of hardware.
|
||||||
(self.vcpus as u64 * 10)
|
(self.vcpus as f64 * 10f64)
|
||||||
+ (self.memory_mb as u64 / 200)
|
+ (self.memory_mb as f64 / 200f64)
|
||||||
+ (self.disk_size_mb as u64 / 10000)
|
+ (self.disk_size_mb as f64 / 10000f64)
|
||||||
}
|
|
||||||
|
|
||||||
pub fn price_estimate(vcpus: u32, memory_mb: u32, disk_size_mb: u32) -> u64 {
|
|
||||||
(vcpus as u64 * 10) + (memory_mb as u64 / 200) + (disk_size_mb as u64 / 10000)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns price per minute in nanoLP
|
/// Returns price per minute in nanoLP
|
||||||
fn price_per_minute(&self) -> u64 {
|
fn price_per_minute(&self) -> u64 {
|
||||||
self.total_units() * self.price_per_unit
|
(self.total_units() * self.price_per_unit as f64) as u64
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,6 +217,7 @@ impl From<AppContract> for AppContractPB {
|
|||||||
.map(MappedPort::from)
|
.map(MappedPort::from)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let nano_per_minute = value.price_per_minute();
|
||||||
let resource = Some(AppResourcePB {
|
let resource = Some(AppResourcePB {
|
||||||
memory_mb: value.memory_mb,
|
memory_mb: value.memory_mb,
|
||||||
disk_mb: value.disk_size_mb,
|
disk_mb: value.disk_size_mb,
|
||||||
@ -238,7 +235,7 @@ impl From<AppContract> for AppContractPB {
|
|||||||
created_at: value.created_at.to_rfc3339(),
|
created_at: value.created_at.to_rfc3339(),
|
||||||
updated_at: value.updated_at.to_rfc3339(),
|
updated_at: value.updated_at.to_rfc3339(),
|
||||||
// TODO: check while implementing pricing
|
// TODO: check while implementing pricing
|
||||||
nano_per_minute: value.price_per_unit,
|
nano_per_minute,
|
||||||
locked_nano: value.locked_nano,
|
locked_nano: value.locked_nano,
|
||||||
collected_at: value.collected_at.to_rfc3339(),
|
collected_at: value.collected_at.to_rfc3339(),
|
||||||
hratls_pubkey: value.hratls_pubkey,
|
hratls_pubkey: value.hratls_pubkey,
|
||||||
@ -1311,13 +1308,6 @@ impl BrainData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_new_container_req(&self, mut req: NewAppReq, tx: OneshotSender<NewAppRes>) {
|
pub async fn send_new_container_req(&self, mut req: NewAppReq, tx: OneshotSender<NewAppRes>) {
|
||||||
// TODO: make sure locked_nano in cli
|
|
||||||
if req.locked_nano == 0 {
|
|
||||||
let resource = req.resource.clone().unwrap_or_default();
|
|
||||||
req.locked_nano =
|
|
||||||
AppContract::price_estimate(resource.vcpu, resource.memory_mb, resource.disk_mb)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Err(e) = self.lock_nanotockens(&req.admin_pubkey, req.locked_nano) {
|
if let Err(e) = self.lock_nanotockens(&req.admin_pubkey, req.locked_nano) {
|
||||||
let _ = tx.send(NewAppRes {
|
let _ = tx.send(NewAppRes {
|
||||||
uuid: String::new(),
|
uuid: String::new(),
|
||||||
|
Loading…
Reference in New Issue
Block a user