-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.cpp
42 lines (35 loc) · 801 Bytes
/
block.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include "block.h"
#include "transaction_data.h"
block::block(int indx, transaction_data obj, size_t prev_hash)
{
index = indx;
data = obj;
previous_hash = prev_hash;
block_hash = generate_hash();
}
int block::get_index()
{
return index;
}
size_t block::generate_hash()
{
hash<std::string> hash1;
hash<size_t> hash2;
hash<size_t> final_hash;
std::string to_hash = std::to_string(data.amount) + data.receiver_key + data.sender_key + std::to_string(data.timestamp);
return final_hash(hash1(to_hash) + hash2(previous_hash));
}
size_t block::get_hash()
{
return block_hash;
}
size_t block::get_previous_hash()
{
return previous_hash;
}
bool block::is_hash_valid()
{
return generate_hash() == block_hash;
}