aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/handlers.rs2
-rw-r--r--src/schema.rs6
-rw-r--r--src/validators.rs6
3 files changed, 9 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