Changed serialization of block to binary format.

This commit is contained in:
Revertron
2021-05-03 08:42:21 +02:00
parent c3576d62d8
commit fab62bdfc8
4 changed files with 17 additions and 10 deletions
+5 -2
View File
@@ -6,6 +6,7 @@ use serde::{Serialize, Deserialize};
use crate::bytes::Bytes;
use crate::Transaction;
use crate::blockchain::hash_utils::{hash_difficulty, key_hash_difficulty};
use crate::blockchain::transaction::TransactionType;
#[derive(Clone, Serialize, Deserialize, PartialEq, Debug)]
pub struct Block {
@@ -61,11 +62,13 @@ impl Block {
}
pub fn is_genesis(&self) -> bool {
self.index == 1 && self.transaction.is_none() && self.prev_block_hash == Bytes::default()
self.index == 1 &&
matches!(Transaction::get_type(&self.transaction), TransactionType::Origin) &&
self.prev_block_hash == Bytes::default()
}
pub fn as_bytes(&self) -> Vec<u8> {
Vec::from(serde_json::to_string(&self).unwrap().as_bytes())
bincode::serialize(&self).unwrap()
}
/// Checks if this block is superior than the other