Skip to content

Commit

Permalink
chore: remove local connection info
Browse files Browse the repository at this point in the history
  • Loading branch information
yHSJ committed Nov 26, 2024
1 parent 31ffe0e commit e2e9dfa
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 41 deletions.
2 changes: 2 additions & 0 deletions crates/rpc/src/bin/metric_exporter/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct Args {

pub struct LocalState {
network: Network,
hydra: ConnectionInfo,
admin_key: SecretKey,
metrics: Arc<Metrics>,
}
Expand Down Expand Up @@ -93,6 +94,7 @@ async fn main() -> Result<()> {
let _ = rocket::build()
.manage(LocalState {
admin_key,
hydra: connection_info,
metrics,
network,
})
Expand Down
10 changes: 2 additions & 8 deletions crates/rpc/src/bin/metric_exporter/routes/game/add_player.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use hydra_control_plane_rpc::model::cluster::{
shared::AddPlayerLocalResponse, ConnectionInfo, NodeClient,
};
use hydra_control_plane_rpc::model::cluster::{shared::AddPlayerLocalResponse, NodeClient};
use pallas::ledger::addresses::Address;
use rocket::{get, http::Status, serde::json::Json, State};
use tracing::error;
Expand All @@ -17,11 +15,7 @@ pub async fn add_player(
_ => Err(Status::BadRequest),
}?;

let client = NodeClient::new(
ConnectionInfo::local(),
state.admin_key.clone(),
state.network,
);
let client = NodeClient::new(state.hydra.clone(), state.admin_key.clone(), state.network);

let tx_hash = client
.add_player(pkh.into())
Expand Down
8 changes: 2 additions & 6 deletions crates/rpc/src/bin/metric_exporter/routes/game/cleanup.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use hydra_control_plane_rpc::model::cluster::{ConnectionInfo, NodeClient};
use hydra_control_plane_rpc::model::cluster::NodeClient;
use rocket::{http::Status, post, State};
use tracing::error;

use crate::LocalState;

#[post("/game/cleanup")]
pub async fn cleanup(state: &State<LocalState>) -> Result<(), Status> {
let client = NodeClient::new(
ConnectionInfo::local(),
state.admin_key.clone(),
state.network,
);
let client = NodeClient::new(state.hydra.clone(), state.admin_key.clone(), state.network);

client
.cleanup_game()
Expand Down
8 changes: 2 additions & 6 deletions crates/rpc/src/bin/metric_exporter/routes/game/end_game.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use hydra_control_plane_rpc::model::cluster::{ConnectionInfo, NodeClient};
use hydra_control_plane_rpc::model::cluster::NodeClient;
use rocket::{http::Status, post, State};
use tracing::error;

use crate::LocalState;

#[post("/game/end_game")]
pub async fn end_game(state: &State<LocalState>) -> Result<(), Status> {
let client = NodeClient::new(
ConnectionInfo::local(),
state.admin_key.clone(),
state.network,
);
let client = NodeClient::new(state.hydra.clone(), state.admin_key.clone(), state.network);

// TODO: we need to take in the "end state" of the game. Currently, we are always aborting
client
Expand Down
10 changes: 2 additions & 8 deletions crates/rpc/src/bin/metric_exporter/routes/game/new_game.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use anyhow::{anyhow, Context};
use hydra_control_plane_rpc::model::cluster::{
shared::NewGameLocalResponse, ConnectionInfo, NodeClient,
};
use hydra_control_plane_rpc::model::cluster::{shared::NewGameLocalResponse, NodeClient};
use pallas::ledger::addresses::Address;
use rocket::{get, serde::json::Json, State};
use rocket_errors::anyhow::Result;
Expand All @@ -23,11 +21,7 @@ pub async fn new_game(
_ => return Result::Err(anyhow!("unsupported address type").into()),
};

let client = NodeClient::new(
ConnectionInfo::local(),
state.admin_key.clone(),
state.network,
);
let client = NodeClient::new(state.hydra.clone(), state.admin_key.clone(), state.network);

let tx_hash = client
.new_game(pkh.into(), player_count, bot_count)
Expand Down
8 changes: 2 additions & 6 deletions crates/rpc/src/bin/metric_exporter/routes/game/start_game.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hydra_control_plane_rpc::model::cluster::{ConnectionInfo, NodeClient};
use hydra_control_plane_rpc::model::cluster::NodeClient;
use rocket::{http::Status, post, State};
use rocket_errors::anyhow::Result;
use tracing::error;
Expand All @@ -7,11 +7,7 @@ use crate::LocalState;

#[post("/game/start_game")]
pub async fn start_game(state: &State<LocalState>) -> Result<(), Status> {
let client = NodeClient::new(
ConnectionInfo::local(),
state.admin_key.clone(),
state.network,
);
let client = NodeClient::new(state.hydra.clone(), state.admin_key.clone(), state.network);

client
.start_game()
Expand Down
7 changes: 0 additions & 7 deletions crates/rpc/src/model/cluster/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,6 @@ impl NodeClient {
}

impl ConnectionInfo {
pub fn local() -> Self {
Self {
host: "localhost".to_string(),
port: 4001,
secure: false,
}
}
pub fn from_resource(resource: &super::crd::HydraDoomNodeStatus) -> Result<(Self, Self)> {
Ok((
ConnectionInfo::from_url(&resource.local_url)?,
Expand Down

0 comments on commit e2e9dfa

Please sign in to comment.