-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharging_ledger_contract.sol
62 lines (49 loc) · 1.7 KB
/
charging_ledger_contract.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
pragma solidity ^0.4.0;
contract charge_database {
struct Charge {
address user_id;
uint32 charger_id;
uint32 start;
uint32 duration;
uint8 mode;
uint256 bonus;
}
address[] usersByAddress;
mapping (bytes32 => Charge) Charges;
bytes32[] chargesList;
uint32[] contractsList;
function addNewCustomer(address user_id) public returns (bool success) {
usersByAddress.push(user_id);
return true;
}
function addNewCharge( address user_id,
uint32 charger_id,
uint32 start,
uint32 duration,
uint8 mode,
uint256 bonus
) public returns (bytes32) {
bytes32 chargeId = keccak256(user_id, charger_id, start);
Charges[chargeId] = Charge(user_id, charger_id, start, duration, mode, bonus);
chargesList.push(chargeId);
return chargeId;
}
function getUsersList() public constant returns (address[]) {
return usersByAddress;
}
function getChargesList() public constant returns (bytes32[]) {
return chargesList;
}
function getChargeData(bytes32 chargeId) public constant returns (
uint32,
uint32,
uint32,
uint8,
uint256) {
return (Charges[chargeId].charger_id,
Charges[chargeId].start,
Charges[chargeId].duration,
Charges[chargeId].mode,
Charges[chargeId].bonus);
}
}