65 lines
No EOL
1.7 KiB
C++
65 lines
No EOL
1.7 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 <openssl/ripemd.h>
|
|
|
|
#include "config.h"
|
|
|
|
class Transaction{
|
|
char sender[RIPEMD160_DIGEST_LENGTH];
|
|
char reciver[RIPEMD160_DIGEST_LENGTH];
|
|
char hash[SHA256_CBLOCK+1];
|
|
int amount;
|
|
public:
|
|
Transaction(){
|
|
amount = 0;
|
|
memset(sender,0,RIPEMD160_DIGEST_LENGTH);
|
|
memset(reciver,0,RIPEMD160_DIGEST_LENGTH);
|
|
memset(hash,0,SHA256_CBLOCK+1);
|
|
}
|
|
|
|
Transaction(const char* sender,const char* to,int amount):amount(amount){
|
|
memset(this->reciver,0,RIPEMD160_DIGEST_LENGTH);
|
|
memset(this->sender,0,RIPEMD160_DIGEST_LENGTH);
|
|
strncpy(this->sender,sender,RIPEMD160_DIGEST_LENGTH);
|
|
strncpy(this->reciver,to,RIPEMD160_DIGEST_LENGTH);
|
|
calculateHash();
|
|
}
|
|
char* getSender() const { return (char*)sender; }
|
|
char* getReciever() const { return (char*)reciver; }
|
|
char* getHash() const { return (char*)hash; }
|
|
int getAmount() const { return amount; }
|
|
Transaction& operator=(Transaction& tr);
|
|
|
|
private:
|
|
void calculateHash();
|
|
};
|
|
|
|
class Block {
|
|
char hash[SHA256_CBLOCK+1];
|
|
char prev_hash[SHA256_CBLOCK+1];
|
|
Transaction transactions[MAX_BLOCK_TRANSACTION];
|
|
size_t difficulty;
|
|
int nonce = 0;
|
|
public:
|
|
char* getHash() const { return (char*)hash;}
|
|
char* getPerviousHash() const { return (char*)prev_hash;}
|
|
size_t getDifficulty() const;
|
|
Block(Transaction tr[],size_t count, const char *prev_hash = "");
|
|
void mine(size_t diff);
|
|
private:
|
|
void calculateHash();
|
|
};
|
|
|
|
|
|
#endif //BLOCKCHAIN_BLOCK_H
|