-
Notifications
You must be signed in to change notification settings - Fork 12
/
BlockChain.h
159 lines (130 loc) · 3.86 KB
/
BlockChain.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#pragma once
#include <string>
#include <fstream>
#include "Transaction.h"
using std::string;
using std::ifstream;
using std::ofstream;
typedef unsigned int (*updateFunction)(unsigned int);
/**
*
* BlockChain - Defining the new BlockChain Type
*
*/
struct BlockChain {
// You may add any fields you believe are necessary
};
/**
* BlockChainGetSize - returns the number of Blocks in the BlockChain
*
* @param blockChain - BlockChain to measure
*
* @return Number of Blocks in the BlockChain
*/
int BlockChainGetSize(const BlockChain& blockChain);
/**
* BlockChainPersonalBalance - returns the balance of a given person, relative to a given BlockChain
*
* @param blockChain - BlockChain to calculate the balance from
* @param name - Name of the person to calculate the balance for
*
* @return Balance of the person
*/
int BlockChainPersonalBalance(const BlockChain& blockChain, const string& name);
/**
* BlockChainAppendTransaction - creates and appends a new transaction to the BlockChain
*
* @param blockChain BlockChain to append the transaction to
* @param value Value of the transaction
* @param sender Name of the sender
* @param receiver Name of the receiver
* @param timestamp String that holds the time the transaction was made
*/
void BlockChainAppendTransaction(
BlockChain& blockChain,
unsigned int value,
const string& sender,
const string& receiver,
const string& timestamp
);
/**
* BlockChainAppendTransaction - appends a copy of a given transaction to the BlockChain
*
* @param blockChain BlockChain to append the transaction to
* @param transaction Transaction we want to append
* @param timestamp String that holds the time the transaction was made
*/
void BlockChainAppendTransaction(
BlockChain& blockChain,
const Transaction& transaction,
const string& timestamp
);
/**
* BlockChainLoad - Reads data from a file and creates a new block chain
*
* @param file Data file to read from
*
* @return BlockChain created from the file
*
*/
BlockChain BlockChainLoad(ifstream& file);
/**
* BlockChainDump - Prints the data of all transactions in the BlockChain to a given file
*
* Data will be printed in the following format:
*
* BlockChain info:
* <n>.
* Sender Name: <name>
* Receiver Name: <name>
* Transaction Value: <value>
* Transaction Timestamp: <time>
*
* @param blockChain BlockChain to print
* @param file File to print to
*
*/
void BlockChainDump(const BlockChain& blockChain, ofstream& file);
/**
* BlockChainDumpHashed - Prints the *hashed data* of all transactions in the BlockChain to a given file
*
* Data will be printed in the following format:
* <hashed message>
* <hashed message>
* ...
* <hashed message>
*
* @param blockChain BlockChain to print
* @param file File to print to
*
*/
void BlockChainDumpHashed(const BlockChain& blockChain, ofstream& file);
/**
* BlockChainVerifyFile - verifies that the file contains correct hashed messages of the given BlockChain
*
* Input file is expected to contain data in the following format:
* <hashed message>
* <hashed message>
* ...
* <hashed message>
*
* @param blockChain BlockChain to verify
* @param file File to read from
*
* @return true if the file is valid, false otherwise
*/
bool BlockChainVerifyFile(const BlockChain& blockChain, std::ifstream& file);
/**
* BlockChainCompress - Compresses the given block chain based on the transaction's data.
* All consecutive blocks with the same sender and receiver will be compressed to one Block.
*
* @param blockChain BlockChain to compress
*/
void BlockChainCompress(BlockChain& blockChain);
/**
* BlockChainTransform - Update the values of each transaction in the BlockChain
*
* @param blockChain BlockChain to update
* @param function a pointer to a transform function
*/
void BlockChainTransform(BlockChain& blockChain, updateFunction function);