mirror of
https://github.com/smolgrrr/TAO.git
synced 2024-09-20 09:21:25 +00:00
basic server
This commit is contained in:
parent
b447a3a0a3
commit
01f3e3ab89
2
pow_server/.gitignore
vendored
Normal file
2
pow_server/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Ignore all build artifacts
|
||||||
|
target/
|
1863
pow_server/Cargo.lock
generated
Normal file
1863
pow_server/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
pow_server/Cargo.toml
Normal file
13
pow_server/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name = "pow_server"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
actix-web = "4.0"
|
||||||
|
actix-rt = "2.0"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
nostr = "0.25"
|
47
pow_server/src/main.rs
Normal file
47
pow_server/src/main.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
use actix_web::{web, App, HttpResponse, HttpServer, Responder, post};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use nostr::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct EventContent {
|
||||||
|
// tags: Vec<Vec<String>>,
|
||||||
|
content: String,
|
||||||
|
pubkey: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct PowRequest {
|
||||||
|
req_event: EventContent,
|
||||||
|
difficulty: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/powgen")]
|
||||||
|
async fn pow_handler(pow_request: web::Json<PowRequest>) -> impl Responder {
|
||||||
|
let pubkey = match XOnlyPublicKey::from_str(&pow_request.req_event.pubkey) {
|
||||||
|
Ok(pubkey) => pubkey,
|
||||||
|
Err(_) => return HttpResponse::BadRequest().finish(),
|
||||||
|
};
|
||||||
|
let difficulty = match u8::from_str(&pow_request.difficulty) {
|
||||||
|
Ok(difficulty) => difficulty,
|
||||||
|
Err(_) => return HttpResponse::BadRequest().finish(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let builder = EventBuilder::new_text_note(&pow_request.req_event.content, &[]);
|
||||||
|
let event = builder.to_unsigned_pow_event(pubkey, difficulty);
|
||||||
|
|
||||||
|
HttpResponse::Ok().json(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
HttpServer::new(|| {
|
||||||
|
App::new()
|
||||||
|
.service(pow_handler)
|
||||||
|
})
|
||||||
|
.bind("127.0.0.1:8080")?
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user