-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDowtry3.sol
83 lines (71 loc) · 2.12 KB
/
Dowtry3.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
pragma solidity ^0.4.17;
contract Dowtry3{
address public owner;
uint public n=0;
mapping(address=>bool) public inspectors;
struct car{
uint carid;
address seller;
uint phno;
uint basePrice;
uint maxPrice;
bool inspected;
bool stop;
uint[] phnobidders;
uint[] bids;
}
car[] public cars;
function Dowtry3() public{
owner=msg.sender;
}
function inspectorAddRemove(address _address)public{
assert(msg.sender == owner);
inspectors[_address] ? inspectors[_address]=false : inspectors[_address]=true;
}
function postAd(uint _phno)public{
car memory newCar = car({
carid:n,
seller : msg.sender,
phno : _phno,
basePrice : 0,
maxPrice : 0,
inspected : false,
stop : false,
phnobidders : new uint[](0),
bids : new uint[](0)
});
cars.push(newCar);
n=n+1;
}
function inspect(uint i, uint _basePrice, uint _maxPrice)public{
car storage temp = cars[i];
assert(inspectors[msg.sender]);
assert(!temp.inspected);
temp.inspected=true;
temp.basePrice = _basePrice;
temp.maxPrice = _maxPrice;
}
function bid(uint i, uint _bidValue, uint _phno)public{
car storage temp = cars[i];
assert(_bidValue>temp.basePrice && _bidValue<=temp.maxPrice);
assert(temp.inspected);
assert(!temp.stop);
assert(msg.sender != temp.seller);
temp.bids.push(_bidValue);
temp.phnobidders.push(_phno);
}
function stopBid(uint i)public{
assert(msg.sender == cars[i].seller);
assert(!cars[i].stop);
cars[i].stop=true;
}
function getphnobidders(uint i)public view returns(uint[]){
return cars[i].phnobidders;
}
function getbids(uint i)public view returns(uint[]){
return cars[i].bids;
}
function getNoOfBids(uint i)public view returns(uint){
return cars[i].bids.length;
}
}