aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/handlers.rs2
-rw-r--r--src/schema.rs6
-rw-r--r--src/validators.rs6
-rwxr-xr-xtester.sh11
4 files changed, 20 insertions, 5 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index 1189b35..362a341 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -122,6 +122,8 @@ pub async fn authorized_propose_block(
122 122
123 let users_store = db.users.read(); 123 let users_store = db.users.read();
124 124
125 println!("{:?}", &new_block);
126
125 let internal_user = match users_store.get(&new_block.transaction_list[0]) { 127 let internal_user = match users_store.get(&new_block.transaction_list[0]) {
126 Some(existing_user) => existing_user, 128 Some(existing_user) => existing_user,
127 None => { 129 None => {
diff --git a/src/schema.rs b/src/schema.rs
index b07744a..6719722 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -92,6 +92,7 @@ pub struct Transaction {
92/// 92///
93#[derive(Serialize, Deserialize, Debug)] 93#[derive(Serialize, Deserialize, Debug)]
94pub struct Block { 94pub struct Block {
95 #[serde(skip_serializing_if = "Vec::is_empty")]
95 pub transaction_list: Vec<PublicKeySignature>, 96 pub transaction_list: Vec<PublicKeySignature>,
96 pub nonce: u32, 97 pub nonce: u32,
97 pub timestamp: NaiveDateTime, 98 pub timestamp: NaiveDateTime,
@@ -101,6 +102,7 @@ pub struct Block {
101/// For prototyping and letting serde handle everything json 102/// For prototyping and letting serde handle everything json
102#[derive(Serialize, Deserialize, Debug)] 103#[derive(Serialize, Deserialize, Debug)]
103pub struct NakedBlock { 104pub struct NakedBlock {
105 #[serde(skip_serializing_if = "Vec::is_empty", default)]
104 pub transaction_list: Vec<PublicKeySignature>, 106 pub transaction_list: Vec<PublicKeySignature>,
105 pub nonce: u32, 107 pub nonce: u32,
106 pub timestamp: NaiveDateTime, 108 pub timestamp: NaiveDateTime,
@@ -110,10 +112,10 @@ impl Block {
110 /// Genesis block 112 /// Genesis block
111 pub fn new() -> Block { 113 pub fn new() -> Block {
112 Block { 114 Block {
113 transaction_list: vec![], 115 transaction_list: vec!["gradecoin_bank".to_owned()],
114 nonce: 0, 116 nonce: 0,
115 timestamp: NaiveDate::from_ymd(2021, 04, 11).and_hms(20, 45, 00), 117 timestamp: NaiveDate::from_ymd(2021, 04, 11).and_hms(20, 45, 00),
116 hash: String::from(""), 118 hash: String::from("not_actually_mined"),
117 } 119 }
118 } 120 }
119} 121}
diff --git a/src/validators.rs b/src/validators.rs
index dbebee8..31344d8 100644
--- a/src/validators.rs
+++ b/src/validators.rs
@@ -1,14 +1,14 @@
1// Custom validators incoming data 1/// Custom validators incoming data
2 2
3use log::error; 3use log::error;
4use serde::de::{Deserializer, Error as DeserializerError, Unexpected}; 4use serde::de::{Deserializer, Error as DeserializerError, Unexpected};
5use serde::ser::{Error as SerializerError, Serializer}; 5use serde::ser::{Error as SerializerError, Serializer};
6use serde::Deserialize; 6use serde::Deserialize;
7 7
8pub mod validate_game_rating { 8pub mod validate_block {
9 use super::*; 9 use super::*;
10 10
11 const ERROR_MESSAGE: &str = "rating must be a number between 0 and 100"; 11 const ERROR_MESSAGE: &str = "block cannot have an empty transaction list";
12 12
13 pub fn deserialize<'de, D>(deserializer: D) -> Result<u8, D::Error> 13 pub fn deserialize<'de, D>(deserializer: D) -> Result<u8, D::Error>
14 where 14 where
diff --git a/tester.sh b/tester.sh
index 0323dcb..19c1549 100755
--- a/tester.sh
+++ b/tester.sh
@@ -119,3 +119,14 @@ curl --request POST \
119 "hash": "000000a996ab57b3aff1ad1d009767278f819895b28ef860a8ec3b6560d6ed0e" 119 "hash": "000000a996ab57b3aff1ad1d009767278f819895b28ef860a8ec3b6560d6ed0e"
120}' \ 120}' \
121 http://localhost:8080/block 121 http://localhost:8080/block
122
123curl --request POST \
124 --header 'Content-Type: application/json' \
125 --header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aGEiOiIyYjY0OGZmYWI1ZDlhZjFkNWQ1ZmMwNTJmYzllNTFiODgyZmM0ZmIwYzk5ODYwOGM5OTIzMmY5MjgyMDAwMDAwIiwiaWF0IjoxNjE4MzYwNjQxLCJleHAiOjE3MTgyNjA2NDF9.P5L_uZ9lOhRZCbsG9GDXn_rmZat3dP9Y2lbk8GY4Kg4pOxJIklBUxot-TtJzB0vEJFcjnxVnT2lFLCgfdQLHTJvURiW0KRHi94e1Kj8aDXxJ0qjlq4-c1JCZnAIbDpvkFtHNKz04yfyeSR2htJ6kOjlqVpeUhLVokHhi1x-ZUZZSpeGnlIXgi-AcmkEoyOypZGSZgQ1hjID2f18zgfbshgPK4Dr0hiN36wYMB0y0YiikRbvDuGgDzRLN2nitih46-CXTGZMqIRz3eAfM2wuUSH1yhdKi5_vavz8L3EPVCGMO-CKlPUDkYA-duQZf_q3tG2fkdaFlTAcCik_kVMprdw' \
126 --data '{
127 "transaction_list": [],
128 "nonce": 2151653522,
129 "timestamp": "2021-04-13T23:38:00",
130 "hash": "000000a996ab57b3aff1ad1d009767278f819895b28ef860a8ec3b6560d6ed0e"
131}' \
132 http://localhost:8080/block