4#include <openssl/sha.h>
14#define BLOCK_HASH_SIZE SHA256_DIGEST_LENGTH
Block * init_block(const Key *auth, const CellProtected *votes, const uint8 *prev_hash)
init block object, copies all parameters.
Definition: blockchain.c:474
CellTree * create_node(Block *b)
Create a node object. Takes ownership of Block b!
Definition: blockchain.c:515
char * block_head_to_str(const Block *b)
convert block head to string and leave extra space for nonce to be appended
Definition: blockchain.c:269
void delete_tree(CellTree *node)
fonction de l'enonce
Definition: blockchain.c:631
void compute_proof_of_work(Block *B, int d)
compute proof of work of block B with d zeros in hexadecimal representation
Definition: blockchain.c:367
bool update_height(CellTree *father, CellTree *child)
Update height of a node.
Definition: blockchain.c:540
char * hash_to_str(const uint8 *hash)
convert sha256 hash to string representation
Definition: blockchain.c:196
bool compare_hash(const uint8 *A, const uint8 *B)
checks if A and B are the same hash
Definition: blockchain.c:402
char * block_to_str(const Block *b)
convert block to string
Definition: blockchain.c:324
Block * read_block(const char *filename)
read a file and save it's content in a Block object
Definition: blockchain.c:72
CellTree * highest_child(const CellTree *cell)
returns the child with max height of cell
Definition: blockchain.c:660
void add_block(int d, const char *name)
Read the last created Block. If it is valid, add it to BLOCKCHAIN_DIR. In any case,...
Definition: blockchain.c:764
void free_node(CellTree *node)
free everything the node contains
Definition: blockchain.c:620
Block * init_block_raw(Key *auth, CellProtected *votes, uint8 *prev_hash)
init a block object. Takes ownership of all auth, votes and prev_hash
Definition: blockchain.c:452
void submit_vote(Protected *p)
print a Protected object (declaration) to the Pending_vote file.
Definition: blockchain.c:714
uint8 * hash_string(const char *s)
hashes string s using sha256
Definition: blockchain.c:336
uint8 * copy_hash(const uint8 *hash)
copy hash
Definition: blockchain.c:417
void create_block(CellTree **tree, Key *author, int d)
Create a Block object using PENDING_VOTES_FILE declarations. Write the block in PENDING_BLOCK_FILE on...
Definition: blockchain.c:739
void print_tree(CellTree *tr)
print a tree.
Definition: blockchain.c:600
bool write_block(const char *filename, const Block *b)
print the content of a Block struct in a file
Definition: blockchain.c:24
struct block_tree_cell CellTree
Tree structure for Block objects.
bool verify_block(const Block *B, int d)
verifies if the block is valid with d zeros in hexadecimal representation
Definition: blockchain.c:435
void free_tree(CellTree *node)
fonction qui free la totalite de memoire dans l'arbre
Definition: blockchain.c:645
void delete_block(Block *b)
cette fonction ne free pas le champ author ni le contenu des votes
Definition: blockchain.c:497
void free_block(Block *b)
frees block (ce n'est pas delete_block)
Definition: blockchain.c:483
struct block Block
Block structure to store declarations.
void print_sha256_hash(const uint8 *hash)
print sha256 hash
Definition: blockchain.c:387
void block_nonce_to_str(char *headstr, const Block *b)
append nonce to the block head string. If nonce is already appended, the function will delete the old...
Definition: blockchain.c:305
CellTree * last_node(CellTree *tree)
Question 8.7 descpription is false. ~Returns the last node of a tree.
Definition: blockchain.c:679
bool str_to_hash(const char *str, uint8 **ret)
convert string sha256 hash representation to sha256 hash
Definition: blockchain.c:232
CellProtected * get_trusted_declarations(const CellTree *tree)
Get all the trusted declarations from the longest chain.
Definition: blockchain.c:696
void delete_node(CellTree *node)
Delete a node. See question 8.5 for more information.
Definition: blockchain.c:609
Tree structure for Block objects.
Definition: blockchain.h:57
Block structure to store declarations.
Definition: blockchain.h:21
a file with comfy aliases for long type signatures
#define uint8
alias for unsigned char
Definition: types.h:32