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