diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 52 |
1 files changed, 52 insertions, 0 deletions
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 @@ | |||
1 | //! # Gradecoin | ||
2 | //! | ||
3 | //! ## Services | ||
4 | //! ### /register | ||
5 | //! - Student creates their own 2048 bit RSA `keypair` | ||
6 | //! - Downloads `Gradecoin`'s Public Key from Moodle | ||
7 | //! - Encrypts their JSON wrapped `Public Key` and `Student ID` using Gradecoin's Public Key | ||
8 | //! - Their public key is now in our Db under [`block::User::public_key`] and can be used to sign their JWT's during requests | ||
9 | //! | ||
10 | //! ### /transaction | ||
11 | //! - offer a [`block::Transaction`] - POST request | ||
12 | //! - The request should have `Authorization` | ||
13 | //! - The request header should be signed by the Public Key of the `by` field in the transaction | ||
14 | //! - fetch the list of `Transaction`s - GET request | ||
15 | //! | ||
16 | //! ### /block | ||
17 | //! - offer a [`block::Block`] - POST request | ||
18 | //! - The request should have `Authorization` | ||
19 | //! - The [`block::Block::transaction_list`] of the block should be a subset of [`block::Db::pending_transactions`] | ||
20 | //! - fetch the last accepted [`block::Block`] - GET request | ||
21 | //! | ||
22 | //! `Authorization`: The request header should have Bearer JWT.Token signed with Student Public Key | ||
23 | #![warn(clippy::all, clippy::pedantic)] | ||
24 | #![allow(clippy::unused_async)] | ||
25 | |||
26 | mod custom_filters; | ||
27 | mod db; | ||
28 | mod handlers; | ||
29 | mod routes; | ||
30 | mod block; | ||
31 | mod student; | ||
32 | |||
33 | pub use block::{Fingerprint, Id}; | ||
34 | use db::Db; | ||
35 | use lazy_static::lazy_static; | ||
36 | use std::fs; | ||
37 | |||
38 | #[tokio::main] | ||
39 | async fn main() { | ||
40 | log4rs::init_file("log.conf.yml", log4rs::config::Deserializers::default()).unwrap(); | ||
41 | |||
42 | let api = routes::application(Db::new()); | ||
43 | |||
44 | // Start the server | ||
45 | let point = ([127, 0, 0, 1], 8080); | ||
46 | warp::serve(api).run(point).await; | ||
47 | } | ||
48 | |||
49 | lazy_static! { | ||
50 | static ref PRIVATE_KEY: String = | ||
51 | fs::read_to_string("secrets/gradecoin.pem").expect("error reading 'secrets/gradecoin.pem'"); | ||
52 | } | ||