-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.c
More file actions
86 lines (67 loc) · 2.88 KB
/
function.c
File metadata and controls
86 lines (67 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "blockChain.h"
/*
Description :
*/
char* subString(char *hash, int pos, int len){
int i;
char *sub = (char*)malloc((len+1)*sizeof(char));
for (i = 0 ; i < len; i++){
*(sub+i) = *(hash+pos);
hash++;
}
*(sub+i) = '\0';
return sub;
}
/*
Description :
*/
char* afficheTimestamp(time_t tim){
struct tm ts;
char* buf = (char*)malloc(100*sizeof(char));
ts = *localtime(&tim);
strftime(buf, 100*sizeof(buf), "%Y/%m/%d %H:%M:%S", &ts);
return buf;
}
/*
Description :
*/
void afficherBC(Blockchain* G) {
char* tim = (char*)malloc(100*sizeof(char));
Block* s = G->first;
tim = afficheTimestamp(s->timestamp);
while(s != NULL) {
printf("________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________\n");
for(int i = 0; i < s->nb_trans; i++){
printf("____________________________________________________________________________________________________________________________________________________________________________________________________________\n");
printf("|index : %d |author : %s |timestamp : %s |Nom de la transaction : %s |hash : %s |previousHash : %s |nonce : %ld |transaction : %d |destinataire : %s |expéditeur : %s |montant : %d |\n",s->index, s->author, tim, s->data, s->hash, s->previousHash, s->nonce, i + 1, s->trans[i].dest, s->trans[i].rep, s->trans[i].montant);
printf("____________________________________________________________________________________________________________________________________________________________________________________________________________\n");
}
printf("________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________\n");
printf("\n");
s = s->successor;
}
printf("\n");
}
/*
Description :
*/
void afficherNom(Blockchain* G){
int j = 0;
char** noms = (char**)malloc(100*sizeof(char*));
Block* s = G->first;
s = s->successor;
while(s != NULL) {
for(int i = 0; i < s->nb_trans; i++){
noms[j] = s->trans[i].dest;
j++;
noms[j] = s->trans[i].rep;
j++;
noms[j] = s->author;
j++;
}
s = s->successor;
}
for(int k = 0; k < j; k++){
printf("%s\n", noms[k]);
}
}