-
Notifications
You must be signed in to change notification settings - Fork 36
/
provider.sol
79 lines (65 loc) · 1.7 KB
/
provider.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
contract mortal {
address public owner;
function mortal() {
owner = msg.sender;
}
modifier onlyOwner {
if (msg.sender != owner) {
throw;
} else {
_;
}
}
function kill() onlyOwner {
suicide(owner);
}
}
contract User is mortal {
string public userName;
mapping(address=>Service) public services;
struct Service {
bool active;
uint lastUpdate;
uint256 debt;
}
function User(string _name) {
userName = _name;
}
function registerToProvider(address _providerContract) onlyOwner {
services[_providerContract] = Service({
active: true,
lastUpdate: now,
debt: 0
});
}
function setDebt(uint256 _debt) {
if (services[msg.sender].active) {
services[msg.sender].lastUpdate = now;
services[msg.sender].debt = _debt;
} else {
throw;
}
}
function payToProvider(address _providerContract) {
_providerContract.send(services[_providerContract].debt);
}
function unsubscribeFromProvider(address _providerContract) {
if (services[_providerContract].debt == 0) {
services[_providerContract].active = false;
} else {
throw;
}
}
}
contract Provider is mortal {
string public providerName;
string public description;
function Provider(string _name, string _description) {
providerName = _name;
description = _description;
}
function setDebt(uint256 _debt, address _userContract) {
User person = User(_userContract);
person.setDebt(_debt);
}
}