Compare commits
1 Commits
249657d780
...
ae5d2f911b
Author | SHA1 | Date | |
---|---|---|---|
ae5d2f911b |
15
src/data.rs
15
src/data.rs
@ -286,6 +286,7 @@ impl BrainData {
|
||||
uuid: &str,
|
||||
reason: &str,
|
||||
) -> Result<u64, Error> {
|
||||
log::debug!("Operator {operator} requested a kick of {uuid} for reason: {reason}");
|
||||
let contract = self.find_contract_by_uuid(uuid)?;
|
||||
let mut operator_data = self
|
||||
.operators
|
||||
@ -305,14 +306,14 @@ impl BrainData {
|
||||
}
|
||||
|
||||
let mut refund_ammount = minutes_to_refund * contract.price_per_minute();
|
||||
let mut user = self
|
||||
let mut admin_account = self
|
||||
.accounts
|
||||
.get_mut(&contract.admin_pubkey)
|
||||
.ok_or(Error::ImpossibleError)?;
|
||||
|
||||
// check if he got kicked within the last day
|
||||
if !chrono::Utc::now()
|
||||
.signed_duration_since(user.last_kick)
|
||||
.signed_duration_since(admin_account.last_kick)
|
||||
.gt(&chrono::Duration::days(1))
|
||||
{
|
||||
refund_ammount = 0;
|
||||
@ -322,8 +323,13 @@ impl BrainData {
|
||||
refund_ammount = operator_data.escrow;
|
||||
}
|
||||
|
||||
user.balance += refund_ammount;
|
||||
user.kicked_for.push(reason.to_string());
|
||||
log::debug!(
|
||||
"Removing {refund_ammount} escrow from {} and giving it to {}",
|
||||
operator_data.key(),
|
||||
admin_account.key()
|
||||
);
|
||||
admin_account.balance += refund_ammount;
|
||||
admin_account.kicked_for.push(reason.to_string());
|
||||
operator_data.escrow -= refund_ammount;
|
||||
|
||||
self.delete_vm(grpc::DeleteVmReq {
|
||||
@ -448,6 +454,7 @@ impl BrainData {
|
||||
}
|
||||
|
||||
pub async fn delete_vm(&self, delete_vm: grpc::DeleteVmReq) -> Result<(), Error> {
|
||||
log::debug!("Starting deletion of VM {}", delete_vm.uuid);
|
||||
let contract = self.find_contract_by_uuid(&delete_vm.uuid)?;
|
||||
if contract.admin_pubkey != delete_vm.admin_pubkey {
|
||||
return Err(Error::AccessDenied);
|
||||
|
@ -206,7 +206,6 @@ impl BrainCli for BrainCliMock {
|
||||
|
||||
async fn delete_vm(&self, req: Request<DeleteVmReq>) -> Result<Response<Empty>, Status> {
|
||||
let req = check_sig_from_req(req)?;
|
||||
info!("Unknown CLI requested to delete vm {}", req.uuid);
|
||||
match self.data.delete_vm(req).await {
|
||||
Ok(()) => Ok(Response::new(Empty {})),
|
||||
Err(e) => Err(Status::not_found(e.to_string())),
|
||||
|
Loading…
Reference in New Issue
Block a user