-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShipment.obs
173 lines (142 loc) · 4.63 KB
/
Shipment.obs
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
import "IO.obs"
import "Transport.obs"
import "LinkedList.obs"
main contract ShippingDriver {
int totalShipments;
int nextID;
ShippingDriver@Owned() {
totalShipments = 0;
nextID = 1;
}
transaction createAgreement(string pseller, string pshipper, string pbuyer, string psource,
string pdest, int pload, string pdescription, string pplannedDate) returns Shipment@Contract {
Shipment s = new Shipment(nextID, pseller, pshipper, pbuyer, psource, pdest, pload, pdescription, pplannedDate);
totalShipments = totalShipments + 1;
nextID = nextID + 1;
return s;
}
}
contract Shipment {
int id;
string seller;
string shipper;
string buyer;
string source;
string dest;
int load;
string description;
string plannedDate;
LinkedList@Owned transportList;
state Contract;
state Release {
string releasedDate;
}
state Sailing;
state InTransit {
Transport@InTransport inTsp;
}
state Delivered;
Shipment@Contract(int nid, string pseller, string pshipper, string pbuyer, string psource, string pdest,
int pload, string pdescription, string pplannedDate) {
id = nid;
seller = pseller;
shipper = pshipper;
buyer = pbuyer;
seller = pseller;
source = psource;
dest = pdest;
load = pload;
description = pdescription;
plannedDate = pplannedDate;
transportList = new LinkedList[Transport]();
->Contract;
IO io = new IO();
io.println("");
io.print("* ");
io.print(pplannedDate);
io.print(" - shipment ");
io.printInt(id);
io.println(" [Contract]");
io.print(" seller: ");
io.println(seller);
io.print(" buyer: ");
io.println(buyer);
io.print(" shipper: ");
io.println(shipper);
io.print(" source port: ");
io.println(source);
io.print(" destination port: ");
io.println(dest);
io.print(" shipment description: ");
io.println(description);
io.println("");
}
transaction release(Shipment@Contract >> Release this, string date) {
->Release(releasedDate = date);
IO io = new IO();
io.println("");
io.print("* ");
io.print(date);
io.print(" - shipment ");
io.printInt(id);
io.println(" [Release]");
io.println("");
}
transaction setSail(Shipment@Release >> Sailing this, string date) {
->Sailing;
IO io = new IO();
io.println("");
io.print("* ");
io.print(date);
io.print(" - shipment ");
io.printInt(id);
io.println(" [InTransit]");
io.println("");
}
transaction depart(Shipment@Sailing >> InTransit this, string transportName, string transportType, string date, string port) {
Transport newTransport = new Transport(transportName, transportType, source, date);
[newTransport @ Load];
newTransport.depart(date, port);
[newTransport @ InTransport];
->InTransit(inTsp = newTransport);
}
transaction layover(Shipment@InTransit this, string date, string port) {
inTsp.stopOver(date, port);
}
transaction layoverDepart(Shipment@InTransit this, string date, string port) {
inTsp.layoverDepart(date, port);
}
transaction transfer(Shipment@InTransit this, string transportName, string transportType, string date, string port) {
inTsp.arrive(date, port);
transportList.append[Transport](inTsp);
Transport newTransport = new Transport(transportName, transportType, source, date);
[newTransport @ Load];
newTransport.depart(date, port);
[newTransport @ InTransport];
inTsp = newTransport;
IO io = new IO();
io.print("* ");
io.print(date);
io.print(" - transfer at port [");
io.print(port);
io.println("]");
io.println("");
}
transaction deliver(Shipment@InTransit >> Delivered this, string date, string port) {
inTsp.arrive(date, port);
transportList.append[Transport](inTsp);
->Delivered;
IO io = new IO();
io.print("* ");
io.print(date);
io.print(" - shipment ");
io.printInt(id);
io.print(" [Delivered] at port [");
io.print(port);
io.println("]");
io.println("");
}
transaction getID(Shipment this) returns int {
return id;
}
}