-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add operator address support for Exits
While exits don't need to pay an operator fee they do need an operator address so we can categorize them per network / operator in operator tools or elsewhere. On the exit side this new setting actually has no real functionality, it's only a tag for remote management software. The operator fee has been removed becuase the fee is for operational upkeep of nodes and exits are expected to have bespoke operators.
- Loading branch information
Showing
10 changed files
with
157 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Operator fees are the fees that the operator charges for the service of running the network | ||
//! and providing internet access. This module contains the operator fee related endpoints. | ||
|
||
use crate::operator_fee_manager::get_operator_fee_debt; | ||
use actix_web_async::web::Path; | ||
use actix_web_async::{HttpRequest, HttpResponse}; | ||
use clarity::Uint256; | ||
|
||
pub async fn get_operator_fee(_req: HttpRequest) -> HttpResponse { | ||
debug!("get_operator_fee GET hit"); | ||
HttpResponse::Ok().json(settings::get_rita_client().operator.operator_fee) | ||
} | ||
|
||
pub async fn set_operator_fee(fee: Path<Uint256>) -> HttpResponse { | ||
let op_fee = fee.into_inner(); | ||
debug!("set_operator_fee POST hit {:?}", op_fee); | ||
|
||
let mut rita_client = settings::get_rita_client(); | ||
rita_client.operator.operator_fee = op_fee; | ||
|
||
rita_client.operator.use_operator_price = op_fee == 0_u8.into(); | ||
|
||
settings::set_rita_client(rita_client); | ||
|
||
// save immediately | ||
if let Err(_e) = settings::write_config() { | ||
return HttpResponse::InternalServerError().finish(); | ||
} | ||
|
||
HttpResponse::Ok().json(settings::get_rita_client().operator.operator_fee) | ||
} | ||
|
||
pub async fn get_operator_debt(_req: HttpRequest) -> HttpResponse { | ||
debug!("get operator debt hit"); | ||
HttpResponse::Ok().json(get_operator_fee_debt()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ pub mod usage; | |
pub mod wallet; | ||
pub mod wg_key; | ||
pub mod wifi; | ||
pub mod operator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//! This module contains the operator address related endpoints the operator address is used to organize | ||
//! what network a given device is a part of and for client devices the address to which operator fees are | ||
//! paid, exits only use operator addresses for organization and not for fee collection. | ||
use actix_web_async::web::Path; | ||
use actix_web_async::{HttpRequest, HttpResponse}; | ||
use clarity::Address; | ||
|
||
enum Mode { | ||
Client, | ||
Exit, | ||
} | ||
|
||
fn get_mode() -> Option<Mode> { | ||
if settings::check_if_client() { | ||
Some(Mode::Client) | ||
} else if settings::check_if_exit() { | ||
Some(Mode::Exit) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
fn get_operator_address(mode: Mode) -> Option<Address> { | ||
match mode { | ||
Mode::Client => settings::get_rita_client().operator.operator_address, | ||
Mode::Exit => settings::get_rita_exit().operator.operator_address, | ||
} | ||
} | ||
|
||
fn set_operator_address_and_save(mode: Mode, address: Option<Address>) { | ||
match mode { | ||
Mode::Client => { | ||
let mut rita_client = settings::get_rita_client(); | ||
rita_client.operator.operator_address = address; | ||
settings::set_rita_client(rita_client); | ||
} | ||
Mode::Exit => { | ||
let mut rita_exit = settings::get_rita_exit(); | ||
rita_exit.operator.operator_address = address; | ||
settings::set_rita_exit(rita_exit); | ||
} | ||
} | ||
|
||
// Save configuration immediately and log any error, but don't return it | ||
if let Err(e) = settings::write_config() { | ||
error!("Failed to write config: {:?}", e); | ||
} | ||
} | ||
|
||
pub async fn get_operator(_req: HttpRequest) -> HttpResponse { | ||
trace!("get operator address: Hit"); | ||
|
||
match get_mode() { | ||
Some(mode) => HttpResponse::Ok().json(get_operator_address(mode)), | ||
None => HttpResponse::InternalServerError().finish(), | ||
} | ||
} | ||
|
||
pub async fn change_operator(path: Path<Address>) -> HttpResponse { | ||
trace!("add operator address: Hit"); | ||
let provided_address = Some(path.into_inner()); | ||
|
||
match get_mode() { | ||
Some(mode) => { | ||
set_operator_address_and_save(mode, provided_address); | ||
HttpResponse::Ok().finish() | ||
} | ||
None => HttpResponse::InternalServerError().finish(), | ||
} | ||
} | ||
|
||
pub async fn remove_operator(_path: Path<Address>) -> HttpResponse { | ||
match get_mode() { | ||
Some(mode) => { | ||
set_operator_address_and_save(mode, None); | ||
HttpResponse::Ok().finish() | ||
} | ||
None => HttpResponse::InternalServerError().finish(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters