Skip to content

Commit

Permalink
wip on changing the server to support different manifest structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Caspar Oostendorp committed Apr 27, 2024
1 parent 64c72c6 commit 53c93be
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
1 change: 1 addition & 0 deletions server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion server/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ starknet = "=0.9.0"
cairo-lang-sierra-to-casm = "=2.5.4"
cairo-lang-sierra-type-size = "=2.5.4"
cairo-lang-sierra-gas = "=2.5.4"
cairo-lang-sierra = "=2.5.4"
cairo-lang-sierra = "=2.5.4"
anyhow = "1.0.82"
65 changes: 37 additions & 28 deletions server/api/src/handlers/keiko/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
use serde_json::json;
use axum::extract::Path;
use axum::http::StatusCode;
use axum::{Extension, Json};
use axum::response::IntoResponse;
use dojo_world::manifest::Manifest;
use dojo_world::manifest::{AbstractManifestError, DeploymentManifest};
use crate::server_state::ServerState;
use std::fs;
use std::io::ErrorKind;
use starknet::core::types::FieldElement;
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::JsonRpcClient;

// pub async fn store_manifest(Path(app_name): Path<String>, Extension(server_state): Extension<ServerState>, Json(manifest): Json<Manifest<T>>) -> impl IntoResponse {
// let path = &server_state.manifest_base_dir;
// if !std::path::Path::new(path).exists() {
// if let Err(_) = fs::create_dir_all(path) {
// return (StatusCode::INTERNAL_SERVER_ERROR, "Server Error");
// }
// }
// let path = format!("{}/{}.json", &server_state.manifest_base_dir, app_name);
// match fs::metadata(&path) {
// Ok(_) => (StatusCode::IM_USED, "Already uploaded"),
// Err(ref e) if e.kind() == ErrorKind::NotFound => {
// let json = serde_json::to_string(&manifest).unwrap();
// match fs::write(path, json) {
// Ok(_) => (StatusCode::CREATED, "Stored manifest"),
// Err(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Server error")
// }
// }
// Err(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Server error"),
// }
// }

pub async fn get_manifest(Path(app_name): Path<String>, Extension(server_state): Extension<ServerState>) -> impl IntoResponse {
let path = format!("{}/{}.json", &server_state.manifest_base_dir, app_name);
println!("{}", path);
match fs::read_to_string(&path) {
Ok(content) => (StatusCode::OK, content),
Err(ref e) if e.kind() == ErrorKind::NotFound => (StatusCode::NOT_FOUND, "Not Found".into()),
Err(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Server error".into()),
pub async fn get_manifest(
Path(app_name): Path<String>,
Extension(server_state): Extension<ServerState>,
)
-> impl IntoResponse
{
let provider = JsonRpcClient::new(HttpTransport::new(
server_state.rpc_url
));

// let manifest = DeploymentManifest::load_from_remote(provider, FieldElement::from(server_state.world_address)).await?;
let world_address = FieldElement::from_hex_be(server_state.world_address.as_str()).unwrap();


match DeploymentManifest::load_from_remote(provider, world_address).await {
Ok(manifest) => {
let world_json = serde_json::to_value(&manifest.base).unwrap();
(StatusCode::OK, Json(world_json))
}

_ => (StatusCode::NOT_FOUND, Json(serde_json::json!("Not found")))
}

//
// if remote_manifest.is_none() {
// ui.print_sub("No remote World found");
// }
//
// match fs::read_to_string(&path) {
// Ok(content) => (StatusCode::OK, manifest),
// Err(ref e) if e.kind() == ErrorKind::NotFound => (StatusCode::NOT_FOUND, "Not Found".into()),
// Err(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Server error".into()),
// }
}
1 change: 1 addition & 0 deletions server/api/src/server_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ pub struct ServerState {
pub json_rpc_client: HttpClient,
pub rpc_url: Url,
pub manifest_base_dir: String,
pub world_address: String,
pub torii_url: Url,
}
1 change: 1 addition & 0 deletions server/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ impl Config {
rpc_url: self.rpc_url(),
manifest_base_dir,
torii_url: self.torii_url(),
world_address: self.katana.world_address.clone(),
}
}
}

0 comments on commit 53c93be

Please sign in to comment.