└── Block.cpp /Block.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | class Block { 6 | public: 7 | int index; 8 | std::string previousHash; 9 | std::time_t timestamp; 10 | std::string data; 11 | std::string hash; 12 | 13 | Block(int idx, const std::string& prevHash, const std::string& data) 14 | : index(idx), previousHash(prevHash), data(data) { 15 | timestamp = std::time(nullptr); 16 | hash = generateHash(); 17 | } 18 | 19 | std::string generateHash() { 20 | // Тут можна використати більш складні алгоритми для хешування 21 | return std::to_string(index) + previousHash + std::to_string(timestamp) + data; 22 | } 23 | 24 | void displayBlock() { 25 | std::cout << "Index: " << index << "\n" 26 | << "Timestamp: " << timestamp << "\n" 27 | << "Data: " << data << "\n" 28 | << "Hash: " << hash << "\n" 29 | << "Previous Hash: " << previousHash << "\n"; 30 | } 31 | }; 32 | 33 | int main() { 34 | Block genesisBlock(0, "0", "First Block"); 35 | genesisBlock.displayBlock(); 36 | 37 | Block secondBlock(1, genesisBlock.hash, "Second Block"); 38 | secondBlock.displayBlock(); 39 | 40 | return 0; 41 | } 42 | --------------------------------------------------------------------------------