@@ -21,14 +21,14 @@ contract LiquidPledging is LiquidPledgingBase {
21
21
/// @param idReceiver To who it's transfered. Can ve the same donnor, another
22
22
/// donor, a delegate or a project
23
23
function donate (uint64 idDonor , uint64 idReceiver ) payable {
24
- NoteManager sender = findManager (idDonor);
24
+ NoteManager storage sender = findManager (idDonor);
25
25
26
- if (sender.managerType != NoteManagerType.Donor) throw ;
27
- if (sender.addr != msg .sender ) throw ;
26
+ require (sender.managerType == NoteManagerType.Donor);
27
+ require (sender.addr == msg .sender );
28
28
29
29
uint amount = msg .value ;
30
30
31
- if (amount == 0 ) throw ;
31
+ require (amount > 0 );
32
32
33
33
vault.transfer (amount);
34
34
uint64 idNote = findNote (
@@ -40,7 +40,7 @@ contract LiquidPledging is LiquidPledgingBase {
40
40
PaymentState.NotPaid);
41
41
42
42
43
- Note nTo = findNote (idNote);
43
+ Note storage nTo = findNote (idNote);
44
44
nTo.amount += amount;
45
45
46
46
Transfer (0 , idNote, amount);
@@ -60,12 +60,12 @@ contract LiquidPledging is LiquidPledgingBase {
60
60
61
61
idNote = normalizeNote (idNote);
62
62
63
- Note n = findNote (idNote);
64
- NoteManager receiver = findManager (idReceiver);
65
- NoteManager sender = findManager (idSender);
63
+ Note storage n = findNote (idNote);
64
+ NoteManager storage receiver = findManager (idReceiver);
65
+ NoteManager storage sender = findManager (idSender);
66
66
67
- if (sender.addr != msg .sender ) throw ;
68
- if (n.paymentState != PaymentState.NotPaid) throw ;
67
+ require (sender.addr == msg .sender );
68
+ require (n.paymentState == PaymentState.NotPaid);
69
69
70
70
// If the sender is the owner
71
71
if (n.owner == idSender) {
@@ -76,7 +76,7 @@ contract LiquidPledging is LiquidPledgingBase {
76
76
} else if (receiver.managerType == NoteManagerType.Delegate) {
77
77
appendDelegate (idNote, amount, idReceiver);
78
78
} else {
79
- throw ;
79
+ assert ( false ) ;
80
80
}
81
81
return ;
82
82
}
@@ -88,11 +88,8 @@ contract LiquidPledging is LiquidPledgingBase {
88
88
// If the receiver is another doner
89
89
if (receiver.managerType == NoteManagerType.Donor) {
90
90
// Only accept to change to the original donor to remove all delegates
91
- if (n.owner == idReceiver) {
92
- undelegate (idNote, amount, n.delegationChain.length );
93
- } else {
94
- throw ;
95
- }
91
+ assert (n.owner == idReceiver);
92
+ undelegate (idNote, amount, n.delegationChain.length );
96
93
return ;
97
94
}
98
95
@@ -122,7 +119,7 @@ contract LiquidPledging is LiquidPledgingBase {
122
119
return ;
123
120
}
124
121
}
125
- throw ; // It is not the owner nor any delegate.
122
+ assert ( false ) ; // It is not the owner nor any delegate.
126
123
}
127
124
128
125
@@ -135,13 +132,13 @@ contract LiquidPledging is LiquidPledgingBase {
135
132
136
133
idNote = normalizeNote (idNote);
137
134
138
- Note n = findNote (idNote);
135
+ Note storage n = findNote (idNote);
139
136
140
- if (n.paymentState != PaymentState.NotPaid) throw ;
137
+ require (n.paymentState == PaymentState.NotPaid);
141
138
142
- NoteManager owner = findManager (n.owner);
139
+ NoteManager storage owner = findManager (n.owner);
143
140
144
- if (owner.addr != msg .sender ) throw ;
141
+ require (owner.addr == msg .sender );
145
142
146
143
uint64 idNewNote = findNote (
147
144
n.owner,
@@ -161,12 +158,12 @@ contract LiquidPledging is LiquidPledgingBase {
161
158
/// @param idNote Id of the note that wants to be withdrawed.
162
159
/// @param amount Quantity of Ether that wants to be withdrawed.
163
160
function confirmPayment (uint64 idNote , uint amount ) onlyVault {
164
- Note n = findNote (idNote);
161
+ Note storage n = findNote (idNote);
165
162
166
- if (n.paymentState != PaymentState.Paying) throw ;
163
+ require (n.paymentState == PaymentState.Paying);
167
164
168
165
// Check the project is not canceled in the while.
169
- if (getOldestNoteNotCanceled (idNote) != idNote) throw ;
166
+ require (getOldestNoteNotCanceled (idNote) == idNote);
170
167
171
168
uint64 idNewNote = findNote (
172
169
n.owner,
@@ -184,9 +181,9 @@ contract LiquidPledging is LiquidPledgingBase {
184
181
/// @param idNote Id of the note that wants to be canceled for withdraw.
185
182
/// @param amount Quantity of Ether that wants to be rolled back.
186
183
function cancelPayment (uint64 idNote , uint amount ) onlyVault {
187
- Note n = findNote (idNote);
184
+ Note storage n = findNote (idNote);
188
185
189
- if (n.paymentState != PaymentState.Paying) throw ;
186
+ require (n.paymentState == PaymentState.Paying);
190
187
191
188
// When a payment is cacnceled, never is assigned to a project.
192
189
uint64 oldNote = findNote (
@@ -206,7 +203,7 @@ contract LiquidPledging is LiquidPledgingBase {
206
203
/// @notice Method called by the reviewer of a project to cancel this project.
207
204
/// @param idProject Id of the projct that wants to be canceled.
208
205
function cancelProject (uint64 idProject ) {
209
- NoteManager project = findManager (idProject);
206
+ NoteManager storage project = findManager (idProject);
210
207
require ((project.reviewer == msg .sender ) || (project.addr == msg .sender ));
211
208
project.canceled = true ;
212
209
}
@@ -258,9 +255,9 @@ contract LiquidPledging is LiquidPledgingBase {
258
255
259
256
260
257
function transferOwnershipToProject (uint64 idNote , uint amount , uint64 idReceiver ) internal {
261
- Note n = findNote (idNote);
258
+ Note storage n = findNote (idNote);
262
259
263
- if (getProjectLevel (n) >= MAX_SUBPROJECT_LEVEL) throw ;
260
+ require (getProjectLevel (n) < MAX_SUBPROJECT_LEVEL);
264
261
uint64 oldNote = findNote (
265
262
n.owner,
266
263
n.delegationChain,
@@ -283,7 +280,7 @@ contract LiquidPledging is LiquidPledgingBase {
283
280
284
281
function transferOwnershipToDonor (uint64 idNote , uint amount , uint64 idReceiver ) internal {
285
282
// If the owner does not change, then just let it this way.
286
- Note n = findNote (idNote);
283
+ Note storage n = findNote (idNote);
287
284
288
285
if (n.owner == idReceiver) return ;
289
286
uint64 toNote = findNote (
@@ -297,9 +294,9 @@ contract LiquidPledging is LiquidPledgingBase {
297
294
}
298
295
299
296
function appendDelegate (uint64 idNote , uint amount , uint64 idReceiver ) internal {
300
- Note n = findNote (idNote);
297
+ Note storage n = findNote (idNote);
301
298
302
- if (n.delegationChain.length >= MAX_DELEGATES) throw ;
299
+ require (n.delegationChain.length < MAX_DELEGATES);
303
300
uint64 [] memory newDelegationChain = new uint64 [](n.delegationChain.length + 1 );
304
301
for (uint i= 0 ; i< n.delegationChain.length ; i++ ) {
305
302
newDelegationChain[i] = n.delegationChain[i];
@@ -317,7 +314,7 @@ contract LiquidPledging is LiquidPledgingBase {
317
314
318
315
/// @param q Unmber of undelegations
319
316
function undelegate (uint64 idNote , uint amount , uint q ) internal {
320
- Note n = findNote (idNote);
317
+ Note storage n = findNote (idNote);
321
318
uint64 [] memory newDelegationChain = new uint64 [](n.delegationChain.length - q);
322
319
for (uint i= 0 ; i< n.delegationChain.length - q; i++ ) {
323
320
newDelegationChain[i] = n.delegationChain[i];
@@ -334,11 +331,11 @@ contract LiquidPledging is LiquidPledgingBase {
334
331
335
332
336
333
function proposeAssignProject (uint64 idNote , uint amount , uint64 idReceiver ) internal {
337
- Note n = findNote (idNote);
334
+ Note storage n = findNote (idNote);
338
335
339
- if (getProjectLevel (n) >= MAX_SUBPROJECT_LEVEL) throw ;
336
+ require (getProjectLevel (n) < MAX_SUBPROJECT_LEVEL);
340
337
341
- NoteManager owner = findManager (n.owner);
338
+ NoteManager storage owner = findManager (n.owner);
342
339
uint64 toNote = findNote (
343
340
n.owner,
344
341
n.delegationChain,
@@ -352,17 +349,17 @@ contract LiquidPledging is LiquidPledgingBase {
352
349
function doTransfer (uint64 from , uint64 to , uint amount ) internal {
353
350
if (from == to) return ;
354
351
if (amount == 0 ) return ;
355
- Note nFrom = findNote (from);
356
- Note nTo = findNote (to);
357
- if (nFrom.amount < amount) throw ;
352
+ Note storage nFrom = findNote (from);
353
+ Note storage nTo = findNote (to);
354
+ require (nFrom.amount >= amount);
358
355
nFrom.amount -= amount;
359
356
nTo.amount += amount;
360
357
361
358
Transfer (from, to, amount);
362
359
}
363
360
364
361
function normalizeNote (uint64 idNote ) internal returns (uint64 ) {
365
- Note n = findNote (idNote);
362
+ Note storage n = findNote (idNote);
366
363
if (n.paymentState != PaymentState.NotPaid) return idNote;
367
364
368
365
// First send to a project if it's proposed and commited
0 commit comments