-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadseller.sol
More file actions
84 lines (71 loc) · 2.16 KB
/
adseller.sol
File metadata and controls
84 lines (71 loc) · 2.16 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
pragma solidity ^0.4.15;
contract adseller {
address private owner;
uint256 public bidDueTime;
uint public marginRatio;
string public currentAdContent;
address private currentAdOwner;
uint256 private currentAdValue;
string private nextAdContent;
address private nextAdOwner;
uint256 public highestBid;
function adseller(){
owner=msg.sender;
bidDueTime=now+1 weeks;
marginRatio=5;
}
function gotoNext() returns(bool success){
if(bidDueTime>now){
return false;
}
else{
bidDueTime+= 1 weeks;
address redeemaddress = currentAdOwner;
uint256 redeemvalue = marginRatio*currentAdValue/(marginRatio+1);
currentAdValue = highestBid;
currentAdContent = nextAdContent;
currentAdOwner = nextAdOwner;
nextAdContent = "-";
nextAdOwner = 0x0;
highestBid = 0;
redeemaddress.transfer(redeemvalue);
return true;
}
}
function bid(string ad) payable returns(bool success){
if(bidDueTime<now){
gotoNext();
}
if(msg.value*105<=100*highestBid){
revert();
return false;
}
else{
address redeemaddress = nextAdOwner;
uint256 redeemvalue = highestBid;
nextAdContent = ad;
nextAdOwner = msg.sender;
highestBid = msg.value;
if(redeemaddress!=0x0)
redeemaddress.transfer(redeemvalue);
return true;
}
}
function judge() returns(bool success){
require(msg.sender==owner);
currentAdValue = 0;
currentAdContent = "-";
currentAdOwner = 0x0;
return true;
}
function collect() returns(bool success){
require(msg.sender==owner);
owner.transfer(this.balance-currentAdValue);
return true;
}
function setRatio(uint newRatio) returns(bool success){
require(msg.sender==owner);
marginRatio = newRatio;
return true;
}
}