-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssetTransfer.sol
More file actions
executable file
·208 lines (178 loc) · 4.56 KB
/
AssetTransfer.sol
File metadata and controls
executable file
·208 lines (178 loc) · 4.56 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
pragma solidity ^0.4.10;
contract AppBuilderBase {
event AppBuilderContractCreated(string contractType, address originatingAddress);
event AppBuilderContractUpdated(string contractType, string action, address originatingAddress);
string internal ContractType;
function AppBuilderBase(string contractType) internal {
ContractType = contractType;
}
function ContractCreated() internal {
AppBuilderContractCreated(ContractType, msg.sender);
}
function ContractUpdated(string action) internal {
AppBuilderContractUpdated(ContractType, action, msg.sender);
}
}
contract AssetTransfer is AppBuilderBase('AssetTransfer')
{
enum AssetState { Created, Active, OfferPlaced, PendingInspection, Inspected, Appraised, NotionalAcceptance, BuyerAccepted, SellerAccepted, Accepted, Complete, Terminated }
address public Owner;
string public Description;
uint public AskingPrice;
AssetState public State;
address public Buyer;
uint public OfferPrice;
address public Inspector;
address public Appraiser;
function AssetTransfer(string description, uint256 price)
{
Owner = msg.sender;
AskingPrice = price;
Description = description;
State = AssetState.Active;
ContractCreated();
}
function Terminate()
{
if (Owner != msg.sender)
{
revert();
}
State = AssetState.Terminated;
ContractUpdated('Terminate');
}
function Modify(string description, uint256 price)
{
if (Owner != msg.sender)
{
revert();
}
Description = description;
AskingPrice = price;
ContractUpdated('Modify');
}
function MakeOffer(address inspector, address appraiser, uint256 offerPrice)
{
if (inspector == 0x0 || appraiser == 0x0 || offerPrice == 0)
{
revert();
}
if (Buyer != 0x0 || Owner == msg.sender)
{
revert();
}
Buyer = msg.sender;
Inspector = inspector;
Appraiser = appraiser;
OfferPrice = offerPrice;
State = AssetState.OfferPlaced;
ContractUpdated('MakeOffer');
}
function AcceptOffer()
{
if (Owner != msg.sender || State != AssetState.OfferPlaced)
{
revert();
}
State = AssetState.PendingInspection;
ContractUpdated('AcceptOffer');
}
function Reject()
{
if (Owner != msg.sender)
{
revert();
}
Buyer = 0x0;
State = AssetState.Active;
ContractUpdated('Reject');
}
function Accept()
{
if (msg.sender != Buyer && msg.sender != Owner)
{
revert();
}
if (State != AssetState.NotionalAcceptance &&
State != AssetState.BuyerAccepted &&
State != AssetState.SellerAccepted)
{
revert();
}
if (msg.sender == Buyer)
{
if (State == AssetState.NotionalAcceptance)
{
State = AssetState.BuyerAccepted;
}
else if (State == AssetState.SellerAccepted)
{
State = AssetState.Accepted;
}
}
else
{
if (State == AssetState.NotionalAcceptance)
{
State = AssetState.SellerAccepted;
}
else if (State == AssetState.BuyerAccepted)
{
State = AssetState.Accepted;
}
}
ContractUpdated('Accept');
}
function ModifyOffer(uint256 offerPrice)
{
if (Buyer != msg.sender || offerPrice == 0)
{
revert();
}
OfferPrice = offerPrice;
ContractUpdated('ModifyOffer');
}
function RescindOffer()
{
if (Buyer != msg.sender)
{
revert();
}
Buyer = 0x0;
OfferPrice = 0;
State = AssetState.Active;
ContractUpdated('RescindOffer');
}
function MarkAppraised()
{
if (Appraiser != msg.sender)
{
revert();
}
if (State == AssetState.PendingInspection)
{
State = AssetState.Appraised;
}
else if (State == AssetState.Inspected)
{
State = AssetState.NotionalAcceptance;
}
ContractUpdated('MarkAppraised');
}
function MarkInspected()
{
if (Inspector != msg.sender)
{
revert();
}
if (State == AssetState.PendingInspection)
{
State = AssetState.Inspected;
}
else if (State == AssetState.Appraised)
{
State = AssetState.NotionalAcceptance;
}
ContractUpdated('MarkInspected');
}
}