// // Keszitette: Toldi Balázs Ádám // Datum: 2020. 03. 15. // #include "Blockchain.h" int Blockchain::difficulty = 2; int Blockchain::blockReward = 50; int Blockchain::getBlockReward() { return blockReward; } int Blockchain::getDifficulty() { return difficulty; } const std::vector &Blockchain::getBlockList() const { return blockList; } bool Blockchain::verifyBlocks() const{ std::string prev_hash = blockList.rbegin()->getPerviousHash(); for (auto it = blockList.rbegin()+1;it < blockList.rend();++it) { if(it->getHash() != prev_hash) return false; } return true; } bool Blockchain::addBlock(Block &b) { blockList.push_back(b); return verifyBlocks(); } Block Blockchain::operator[](size_t id) { if(id >= blockList.size()) throw std::out_of_range("Out of range"); return blockList[id]; } bool Blockchain::operator<(Blockchain &b) { return blockList.size() < b.blockList.size(); } size_t Blockchain::getHeight() const { return blockList.size(); } bool Blockchain::operator>(Blockchain &b) { return blockList.size() > b.getHeight(); } Blockchain::Blockchain() { } Blockchain::Blockchain(const Blockchain &b) { for(Block bl : b.blockList) blockList.push_back(bl); }