start rewrite based on ticket #2
keys go migrated to solana_sdk in a 01b889d
This commit is contained in:
		
							parent
							
								
									01b889d273
								
							
						
					
					
						commit
						d7b0c3fd2c
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,4 +1,4 @@
 | 
				
			|||||||
/target
 | 
					target
 | 
				
			||||||
build
 | 
					build
 | 
				
			||||||
detee_challenge_nodes
 | 
					detee_challenge_nodes
 | 
				
			||||||
.cargo
 | 
					.cargo
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										0
									
								
								Cargo.lock → legacy_challenge/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										0
									
								
								Cargo.lock → legacy_challenge/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
								
								
									
										1297
									
								
								rewrite/Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										1297
									
								
								rewrite/Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										10
									
								
								rewrite/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										10
									
								
								rewrite/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					[package]
 | 
				
			||||||
 | 
					name = "rewrite"
 | 
				
			||||||
 | 
					version = "0.1.0"
 | 
				
			||||||
 | 
					edition = "2021"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[dependencies]
 | 
				
			||||||
 | 
					actix-web = "4.9.0"
 | 
				
			||||||
 | 
					rand = "0.8.5"
 | 
				
			||||||
 | 
					serde = { version = "1.0.210", features = ["derive"] }
 | 
				
			||||||
 | 
					tokio = { version = "1.40.0", features = ["macros", "rt-multi-thread", "fs"] }
 | 
				
			||||||
							
								
								
									
										110
									
								
								rewrite/src/http_server.rs
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										110
									
								
								rewrite/src/http_server.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,110 @@
 | 
				
			|||||||
 | 
					use actix_web::{
 | 
				
			||||||
 | 
					    error::ResponseError, get, http::StatusCode, post, web, App, HttpResponse, HttpServer,
 | 
				
			||||||
 | 
					    Responder, Result,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					use rand::Rng;
 | 
				
			||||||
 | 
					use serde::{Deserialize, Serialize};
 | 
				
			||||||
 | 
					use std::{fmt, sync::Arc};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const HOMEPAGE: &str = r#"Welcome, beloved hacker!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This node is part of the DeTEE hacker-challenge network. This network allows you
 | 
				
			||||||
 | 
					to mint the token {token_address},
 | 
				
			||||||
 | 
					and owns the mint address {mint_address}.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To be able to mint, you will need to send SOL to {mint_address}, however:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					BE AWARE THAT THE ONLY WAY TO GET THE SOL OUT IS BY HACKING THIS NETWORK!
 | 
				
			||||||
 | 
					DeTEE REPRESENTATIVES DON'T KNOW HOW TO HACK IT! THAT'S ACTUALLY WHY THIS GOT CREATED...
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Allowed operations:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/nodes <- information about nodes and counters of network activity
 | 
				
			||||||
 | 
					/mint (address) <- mint DHCT tokens to the address; the wallet needs sol for this operation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Feel free to use this as a faucet for HCKT tokens, that you can use for testing in any dApp.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The objective of the hacker challenge is to get the SOL out of {mint_address}.
 | 
				
			||||||
 | 
					If you hack it, contact us at https://detee.cloud cause we have lots of rewards.
 | 
				
			||||||
 | 
					"#;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[get("/")]
 | 
				
			||||||
 | 
					async fn homepage() -> impl Responder {
 | 
				
			||||||
 | 
					    HttpResponse::Ok().body(HOMEPAGE)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Serialize)]
 | 
				
			||||||
 | 
					struct NodesResp {
 | 
				
			||||||
 | 
					    ip: String,
 | 
				
			||||||
 | 
					    last_keepalive: u64,
 | 
				
			||||||
 | 
					    online: bool,
 | 
				
			||||||
 | 
					    public: bool,
 | 
				
			||||||
 | 
					    mints: u64,
 | 
				
			||||||
 | 
					    mint_requests: u64,
 | 
				
			||||||
 | 
					    ratls_attacks: u64,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[get("/nodes")]
 | 
				
			||||||
 | 
					async fn get_nodes() -> HttpResponse {
 | 
				
			||||||
 | 
					    let mock_nodes = generate_mock_data();
 | 
				
			||||||
 | 
					    HttpResponse::Ok().json(mock_nodes)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Deserialize)]
 | 
				
			||||||
 | 
					struct MintReq {
 | 
				
			||||||
 | 
					    wallet: String,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[post("/mint")]
 | 
				
			||||||
 | 
					async fn mint(req: web::Json<MintReq>) -> impl Responder {
 | 
				
			||||||
 | 
					    HttpResponse::Ok().json({})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TODO: init(ds: Arc<Store>)
 | 
				
			||||||
 | 
					pub async fn init() {
 | 
				
			||||||
 | 
					    HttpServer::new(move || {
 | 
				
			||||||
 | 
					        App::new()
 | 
				
			||||||
 | 
					            // .app_data(web::Data::new(ds.clone()))
 | 
				
			||||||
 | 
					            .service(homepage)
 | 
				
			||||||
 | 
					            .service(get_nodes)
 | 
				
			||||||
 | 
					            .service(mint)
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .bind("0.0.0.0:31372")
 | 
				
			||||||
 | 
					    .unwrap()
 | 
				
			||||||
 | 
					    .run()
 | 
				
			||||||
 | 
					    .await
 | 
				
			||||||
 | 
					    .unwrap();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn generate_mock_data() -> Vec<NodesResp> {
 | 
				
			||||||
 | 
					    let mut rng = rand::thread_rng();
 | 
				
			||||||
 | 
					    let mut nodes = Vec::new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for _ in 0..15 {
 | 
				
			||||||
 | 
					        let ip = format!(
 | 
				
			||||||
 | 
					            "{}.{}.{}.{}",
 | 
				
			||||||
 | 
					            rng.gen_range(1..=255),
 | 
				
			||||||
 | 
					            rng.gen_range(1..=255),
 | 
				
			||||||
 | 
					            rng.gen_range(1..=255),
 | 
				
			||||||
 | 
					            rng.gen_range(1..=255)
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        let last_keepalive = rng.gen_range(1_000_000..10_000_000);
 | 
				
			||||||
 | 
					        let online = rng.gen_bool(0.5);
 | 
				
			||||||
 | 
					        let public = rng.gen_bool(0.5);
 | 
				
			||||||
 | 
					        let mints = rng.gen_range(0..500);
 | 
				
			||||||
 | 
					        let mint_requests = rng.gen_range(0..1000);
 | 
				
			||||||
 | 
					        let ratls_attacks = rng.gen_range(0..10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        nodes.push(NodesResp {
 | 
				
			||||||
 | 
					            ip,
 | 
				
			||||||
 | 
					            last_keepalive,
 | 
				
			||||||
 | 
					            online,
 | 
				
			||||||
 | 
					            public,
 | 
				
			||||||
 | 
					            mints,
 | 
				
			||||||
 | 
					            mint_requests,
 | 
				
			||||||
 | 
					            ratls_attacks,
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    nodes
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										14
									
								
								rewrite/src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										14
									
								
								rewrite/src/main.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					mod http_server;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use tokio::task::JoinSet;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[tokio::main]
 | 
				
			||||||
 | 
					async fn main() {
 | 
				
			||||||
 | 
					    let mut long_term_tasks = JoinSet::new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    long_term_tasks.spawn(http_server::init());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    long_term_tasks.join_next().await;
 | 
				
			||||||
 | 
					    println!("Shutting down...");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user