-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsustainergy.sol
93 lines (38 loc) · 1.74 KB
/
sustainergy.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
pragma solidity ^0.4.25;
/* This contract should manage a CO2-token and have four functions:
1. It should award Tokens to a user if an expert tells it to do so;
2. It should make it possible to send and
3. Also receive Tokens
4. It would be nice if it was possible to buy tokens with ether
*/
contract sustainergy {
event Transfer(address sender, address receiver, uint amount);
//Associate addresses with balances
mapping(address => uint) public balance;
function createTokens(address _receiver, uint _amount, uint _credential) {
//Does the function caller have the necessary credentials to create tokens (unfinished)
//bytes32 hasch = 6e91ec6b618bb462a4a6ee5aa2cb0e9cf30f7a052bb467b0ba58b8748c00d2e5;
//require(keccak256(abi.encodePacked(_credential)) == hasch);
//Checks for an overflow
require(balance[_receiver] + _amount > balance[_receiver]);
//Adds the created tokens to the sender's account
balance[_receiver] = balance[_receiver] + _amount;
}
//Function to transfer tokens
function transferTokens(address _receiver, uint _amount) public returns (bool success){
//Checks whether sender has more tokens than he wants to send
require(balance[msg.sender] >= _amount);
//Checks for overflow
require(balance[_receiver] + _amount > balance[_receiver]);
//Subtracts sent tokens from sender's balance
balance[msg.sender] = balance[msg.sender] - _amount;
//Adds sent tokens to receiver's balance
balance[_receiver] = balance[_receiver] + _amount;
emit Transfer(msg.sender, _receiver, _amount);
return true;
}
//Checks the user's account balance
function checkBalance() public view returns (uint) {
return balance[msg.sender];
}
}