56 lines
No EOL
1.5 KiB
C++
56 lines
No EOL
1.5 KiB
C++
//
|
|
// Keszitette: Toldi Balázs Ádám
|
|
// Datum: 2020. 03. 14.
|
|
//
|
|
|
|
#ifndef BLOCKCHAIN_BLOCK_H
|
|
#define BLOCKCHAIN_BLOCK_H
|
|
#include <string>
|
|
#include <cstring>
|
|
#include <sstream>
|
|
#include <iostream>
|
|
#include <vector>
|
|
#include <openssl/sha.h>
|
|
#include "config.h"
|
|
|
|
class Transaction{
|
|
char sender[KEY_LENGTH];
|
|
char reciver[KEY_LENGTH];
|
|
int amount;
|
|
public:
|
|
Transaction(){
|
|
amount = 0;
|
|
memset(sender,0,KEY_LENGTH);
|
|
memset(reciver,0,KEY_LENGTH);
|
|
}
|
|
|
|
Transaction(const char* sender,const char* to,int amount):amount(amount){
|
|
memset(this->reciver,0,KEY_LENGTH);
|
|
memset(this->sender,0,KEY_LENGTH);
|
|
strncpy(this->sender,sender,KEY_LENGTH);
|
|
strncpy(this->reciver,to,KEY_LENGTH);
|
|
}
|
|
char* getSender() const { return (char*)sender; }
|
|
char* getReciever() const { return (char*)reciver; }
|
|
int getAmount() const { return amount; }
|
|
Transaction& operator=(Transaction& tr);
|
|
};
|
|
|
|
class Block {
|
|
char hash[SHA256_DIGEST_LENGTH];
|
|
char prev_hash[SHA256_DIGEST_LENGTH];
|
|
Transaction transactions[MAX_BLOCK_TRANSACTION];
|
|
size_t height;
|
|
static size_t max_height;
|
|
public:
|
|
size_t getHeight() { return height; }
|
|
static size_t getMaxHeight() { return max_height; }
|
|
char* getHash() const { return (char*)hash;}
|
|
char* getPerviousHash() const { return (char*)prev_hash;}
|
|
Block(Transaction tr[],size_t count, const char *prev_hash = "");
|
|
private:
|
|
std::string calculateHash();
|
|
};
|
|
|
|
|
|
#endif //BLOCKCHAIN_BLOCK_H
|