From 426e83ec6fba028692bed334803ae9d3a645cb18 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Mon, 11 Apr 2022 19:01:42 +0300 Subject: [WIP] Spring cleaning --- src/main.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main.rs (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..f0027f2 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,52 @@ +//! # Gradecoin +//! +//! ## Services +//! ### /register +//! - Student creates their own 2048 bit RSA `keypair` +//! - Downloads `Gradecoin`'s Public Key from Moodle +//! - Encrypts their JSON wrapped `Public Key` and `Student ID` using Gradecoin's Public Key +//! - Their public key is now in our Db under [`block::User::public_key`] and can be used to sign their JWT's during requests +//! +//! ### /transaction +//! - offer a [`block::Transaction`] - POST request +//! - The request should have `Authorization` +//! - The request header should be signed by the Public Key of the `by` field in the transaction +//! - fetch the list of `Transaction`s - GET request +//! +//! ### /block +//! - offer a [`block::Block`] - POST request +//! - The request should have `Authorization` +//! - The [`block::Block::transaction_list`] of the block should be a subset of [`block::Db::pending_transactions`] +//! - fetch the last accepted [`block::Block`] - GET request +//! +//! `Authorization`: The request header should have Bearer JWT.Token signed with Student Public Key +#![warn(clippy::all, clippy::pedantic)] +#![allow(clippy::unused_async)] + +mod custom_filters; +mod db; +mod handlers; +mod routes; +mod block; +mod student; + +pub use block::{Fingerprint, Id}; +use db::Db; +use lazy_static::lazy_static; +use std::fs; + +#[tokio::main] +async fn main() { + log4rs::init_file("log.conf.yml", log4rs::config::Deserializers::default()).unwrap(); + + let api = routes::application(Db::new()); + + // Start the server + let point = ([127, 0, 0, 1], 8080); + warp::serve(api).run(point).await; +} + +lazy_static! { + static ref PRIVATE_KEY: String = + fs::read_to_string("secrets/gradecoin.pem").expect("error reading 'secrets/gradecoin.pem'"); +} -- cgit v1.2.3-70-g09d2