-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockchain.hpp
More file actions
79 lines (55 loc) · 1.78 KB
/
Blockchain.hpp
File metadata and controls
79 lines (55 loc) · 1.78 KB
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
// Blockchain.hpp
#include "Transaction.hpp"
#include "Utils.hpp"
// Cryptolib
#include "Uint256.hpp"
#include "Sha256.hpp"
#include "CurvePoint.hpp" // should not be needed here - fix GAIA
#include <vector>
using std::vector;
const vector<uint8_t> BZ32(Sha256Hash::HASH_LEN, 0);
const static Sha256Hash NULL_HASH = Sha256Hash(&BZ32[0], BZ32.size());
class Block {
/* --- Instance Members ---*/
// Block header
private: Sha256Hash myHash;
private: Sha256Hash prevHash;
public: Uint256 nonce;
public: Uint256 soln; // POW Solution
//Uint256 timestamp;
// Transaction list
public: Transaction reward; // Block reward
vector<Transaction> txList;
/* --- Constructors --- */
Block();
Block(const vector<Transaction> txs, Uint256 a_nonce, Uint256 a_soln);
void addTransaction(Transaction &tx);
Sha256Hash calcHash();
void setHash(Sha256Hash previousBlockHash);
Sha256Hash getHash() const;
Sha256Hash getPrevHash() const;
// --- Static Constants
static const size_t MAX_TX = 10;
};
class Blockchain {
/* --- Members --- */
vector<Block> blocks; // Replace with DAG structure one P2P built
const PrivateKey GAIA_PRIV;
const PublicKey GAIA_PUB;
/* --- Constructors --- */
public: Blockchain();
public: Blockchain(vector<Block> blockList);
/* --- Public instance methods --- */
bool addBlock(Block &block);
bool isValidBlock(const Block &block) const;
bool chainIsEmpty() const;
int checkChainIntegrity(bool sigs) const;
Block getBlock(size_t depth) const;
void genesis(const PublicKey &whale, const int supply = TOTAL_SUPPLY);
// Blockchain State Accessors
int getAddressBalance(const PublicKey &address) const;
public: vector<Block>::const_iterator getTop() const;
/* --- Helper methods --- */
/* --- Class constants --- */
static const int TOTAL_SUPPLY = 10000;
};