-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDaisee.sol
110 lines (87 loc) · 2.97 KB
/
Daisee.sol
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
contract Daisee {
Usager[] public usagers;
uint public currentTime;
uint prixKwh;
/* Usagers */
struct Usager {
address addr;
uint[] conso;
uint[] prod;
uint[] disponible;
string nom;
uint credit;
}
Usager anusager;
/* Initialisation */
function Daisee() {
currentTime = 0;
}
function () {
bool trouve=false;
for (uint i = 0; i < usagers.length; ++i) {
if(usagers[i].addr == msg.sender){
usagers[i].credit = usagers[i].credit + msg.value;
trouve=true;
}
}
if(trouve){
}else {
throw;
}
}
function sajouterUsager(
string name
) {
Usager nouvelUsager = anusager;
nouvelUsager.nom = name;
nouvelUsager.credit = msg.value;
nouvelUsager.addr = msg.sender;
usagers[usagers.length++] = nouvelUsager;
// {addr: msg.sender, credit: msg.value, nom: name, conso:[0], prod: [0], disponible:[0]}
for (uint i = 0; i < currentTime; ++i) {
usagers[usagers.length].conso[i]=0;
usagers[usagers.length].prod[i]=0;
usagers[usagers.length].disponible[i]=0;
}
}
function publier(uint consoActuelle, uint prodActuelle) {
uint prodDiff = prodActuelle - consoActuelle;
// address vendeur;
bool termine;
for (uint i = 0; i < usagers.length; ++i) {
if(usagers[i].addr == msg.sender){
usagers[i].conso[currentTime] = consoActuelle;
usagers[i].prod[currentTime] = prodActuelle;
if(prodDiff>0){
usagers[i].disponible[currentTime] = prodDiff;
} else {
for (uint j = 0; j < usagers.length; ++j) {
if(usagers[j].disponible[currentTime-1]> 0){
// vendeur = usagers[j].addr;
uint dispo;
if (prodDiff > dispo){
usagers[j].disponible[currentTime-1] = 0;
usagers[j].credit += dispo * prixKwh;
usagers[i].credit -= dispo * prixKwh;
prodDiff -= dispo;
}else {
usagers[j].disponible[currentTime-1] -= prodDiff;
usagers[j].credit += prodDiff * prixKwh;
usagers[i].credit -= prodDiff * prixKwh;
termine = true;
return;
}
}
}
if(termine){
}else{
/*Acheter hors reseau */
}
}
}
}
}
function nextTime() {
currentTime++;
}
}