forked from magonicolas/Ethereum-Solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSalesContractPro.sol
More file actions
63 lines (54 loc) · 1.91 KB
/
SalesContractPro.sol
File metadata and controls
63 lines (54 loc) · 1.91 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
pragma solidity ^0.4.0;
contract SalesContract {
address public owner;
uint256 public updatedTime;
string public salesDescription;
uint public price;
bool public onSale = true;
event UserStatus(string _msg, address user, uint amount, uint256 time);
function SalesContract(string description, uint _price) payable {
owner = msg.sender;
salesDescription = description;
price = _price;
updatedTime = block.timestamp;
UserStatus(description, msg.sender, msg.value, block.timestamp);
UserStatus('Item on Sale:', msg.sender, msg.value, block.timestamp);
}
function buy() payable {
if(msg.value >= price && onSale == true) {
owner.transfer(this.balance);
owner = msg.sender;
onSale = false;
UserStatus('Item Bought', msg.sender, msg.value, block.timestamp);
UserStatus('Item No Longer on Sale', msg.sender, msg.value, block.timestamp);
} else {
revert();
}
updatedTime = block.timestamp;
}
function updatePrice(uint _price) onlyOwner {
price = _price;
UserStatus('Price Updated', msg.sender, price, block.timestamp);
}
function modifyDescription(string description) onlyOwner {
salesDescription = description;
UserStatus(description, msg.sender, 0, block.timestamp);
UserStatus('Description Modified', msg.sender, 0, block.timestamp);
}
function putOnSale() onlyOwner {
onSale = true;
UserStatus('Item Now is On Sale', msg.sender, 0, block.timestamp);
}
function removeFromSale() onlyOwner {
onSale = false;
UserStatus('Item No Longer on Sale', msg.sender, 0, block.timestamp);
}
modifier onlyOwner {
updatedTime = block.timestamp;
if (msg.sender != owner) {
revert();
} else {
_;
}
}
}