-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlock.cpp
53 lines (36 loc) · 981 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
43
44
45
46
47
48
49
50
51
52
53
#include "Block.hpp"
Block::Block(std::istream & input) {
input.read((char *)(&magic), 4);
input.read((char *)(&blockSize), 4);
this->blockHeader.init(input);
this->txnCounter = varint(input);
for (uint32_t i = 0; i < txnCounter; i++) {
txs.push_back(Transaction(input));
}
}
uint32_t Block::getMagicNumber() const {
return this->magic;
}
uint32_t Block::getSize() const {
return this->blockSize;
}
BlockHeader Block::getHeader() const {
return this->blockHeader;
}
uint32_t Block::getTransactionCount() const {
return this->txnCounter;
}
uint64_t Block::getOutputsValue() const {
uint64_t sum = 0;
for (const auto & tx : this->txs) {
sum += tx.getOutputsValue();
}
return sum;
}
std::vector<Transaction>& Block::getTransactions() {
return txs;
}
std::vector<uint8_t> Block::calcMerkleRoot() {
std::vector<uint8_t> result;
return result;
}