-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathStandardBounties.sol
723 lines (640 loc) · 26 KB
/
StandardBounties.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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
/**
*Submitted for verification at Etherscan.io on 2018-01-22
*/
pragma solidity ^0.4.18;
contract Token {
/* This is a slight change to the ERC20 base standard.
function totalSupply() constant returns (uint256 supply);
is replaced with:
uint256 public totalSupply;
This automatically creates a getter function for the totalSupply.
This is moved to the base contract since public getter functions are not
currently recognised as an implementation of the matching abstract
function by the compiler.
*/
/// total amount of tokens
uint256 public totalSupply;
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance);
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success);
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
/// @notice `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of tokens to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success);
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract StandardToken is Token {
function transfer(address _to, uint256 _value) returns (bool success) {
//Default assumes totalSupply can't be over max (2^256 - 1).
//If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
//Replace the if with this one instead.
//if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
//same as above. Replace this line with the following if you want to protect against wrapping uints.
//if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
}
contract HumanStandardToken is StandardToken {
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; //fancy name: eg Simon Bucks
uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
string public symbol; //An identifier: eg SBX
string public version = 'H0.1'; //human 0.1 standard. Just an arbitrary versioning scheme.
function HumanStandardToken(
uint256 _initialAmount,
string _tokenName,
uint8 _decimalUnits,
string _tokenSymbol
) {
balances[msg.sender] = _initialAmount; // Give the creator all initial tokens
totalSupply = _initialAmount; // Update total supply
name = _tokenName; // Set the name for display purposes
decimals = _decimalUnits; // Amount of decimals for display purposes
symbol = _tokenSymbol; // Set the symbol for display purposes
}
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
require(_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData));
return true;
}
}
contract StandardBounties {
/*
* Events
*/
event BountyIssued(uint bountyId);
event BountyActivated(uint bountyId, address issuer);
event BountyFulfilled(uint bountyId, address indexed fulfiller, uint256 indexed _fulfillmentId);
event FulfillmentUpdated(uint _bountyId, uint _fulfillmentId);
event FulfillmentAccepted(uint bountyId, address indexed fulfiller, uint256 indexed _fulfillmentId);
event BountyKilled(uint bountyId, address indexed issuer);
event ContributionAdded(uint bountyId, address indexed contributor, uint256 value);
event DeadlineExtended(uint bountyId, uint newDeadline);
event BountyChanged(uint bountyId);
event IssuerTransferred(uint _bountyId, address indexed _newIssuer);
event PayoutIncreased(uint _bountyId, uint _newFulfillmentAmount);
/*
* Storage
*/
address public owner;
Bounty[] public bounties;
mapping(uint=>Fulfillment[]) fulfillments;
mapping(uint=>uint) numAccepted;
mapping(uint=>HumanStandardToken) tokenContracts;
/*
* Enums
*/
enum BountyStages {
Draft,
Active,
Dead
}
/*
* Structs
*/
struct Bounty {
address issuer;
uint deadline;
string data;
uint fulfillmentAmount;
address arbiter;
bool paysTokens;
BountyStages bountyStage;
uint balance;
}
struct Fulfillment {
bool accepted;
address fulfiller;
string data;
}
/*
* Modifiers
*/
modifier validateNotTooManyBounties(){
require((bounties.length + 1) > bounties.length);
_;
}
modifier validateNotTooManyFulfillments(uint _bountyId){
require((fulfillments[_bountyId].length + 1) > fulfillments[_bountyId].length);
_;
}
modifier validateBountyArrayIndex(uint _bountyId){
require(_bountyId < bounties.length);
_;
}
modifier onlyIssuer(uint _bountyId) {
require(msg.sender == bounties[_bountyId].issuer);
_;
}
modifier onlyFulfiller(uint _bountyId, uint _fulfillmentId) {
require(msg.sender == fulfillments[_bountyId][_fulfillmentId].fulfiller);
_;
}
modifier amountIsNotZero(uint _amount) {
require(_amount != 0);
_;
}
modifier transferredAmountEqualsValue(uint _bountyId, uint _amount) {
if (bounties[_bountyId].paysTokens){
require(msg.value == 0);
uint oldBalance = tokenContracts[_bountyId].balanceOf(this);
if (_amount != 0){
require(tokenContracts[_bountyId].transferFrom(msg.sender, this, _amount));
}
require((tokenContracts[_bountyId].balanceOf(this) - oldBalance) == _amount);
} else {
require((_amount * 1 wei) == msg.value);
}
_;
}
modifier isBeforeDeadline(uint _bountyId) {
require(now < bounties[_bountyId].deadline);
_;
}
modifier validateDeadline(uint _newDeadline) {
require(_newDeadline > now);
_;
}
modifier isAtStage(uint _bountyId, BountyStages _desiredStage) {
require(bounties[_bountyId].bountyStage == _desiredStage);
_;
}
modifier validateFulfillmentArrayIndex(uint _bountyId, uint _index) {
require(_index < fulfillments[_bountyId].length);
_;
}
modifier notYetAccepted(uint _bountyId, uint _fulfillmentId){
require(fulfillments[_bountyId][_fulfillmentId].accepted == false);
_;
}
/*
* Public functions
*/
/// @dev StandardBounties(): instantiates
/// @param _owner the issuer of the standardbounties contract, who has the
/// ability to remove bounties
function StandardBounties(address _owner)
public
{
owner = _owner;
}
/// @dev issueBounty(): instantiates a new draft bounty
/// @param _issuer the address of the intended issuer of the bounty
/// @param _deadline the unix timestamp after which fulfillments will no longer be accepted
/// @param _data the requirements of the bounty
/// @param _fulfillmentAmount the amount of wei to be paid out for each successful fulfillment
/// @param _arbiter the address of the arbiter who can mediate claims
/// @param _paysTokens whether the bounty pays in tokens or in ETH
/// @param _tokenContract the address of the contract if _paysTokens is true
function issueBounty(
address _issuer,
uint _deadline,
string _data,
uint256 _fulfillmentAmount,
address _arbiter,
bool _paysTokens,
address _tokenContract
)
public
validateDeadline(_deadline)
amountIsNotZero(_fulfillmentAmount)
validateNotTooManyBounties
returns (uint)
{
bounties.push(Bounty(_issuer, _deadline, _data, _fulfillmentAmount, _arbiter, _paysTokens, BountyStages.Draft, 0));
if (_paysTokens){
tokenContracts[bounties.length - 1] = HumanStandardToken(_tokenContract);
}
BountyIssued(bounties.length - 1);
return (bounties.length - 1);
}
/// @dev issueAndActivateBounty(): instantiates a new draft bounty
/// @param _issuer the address of the intended issuer of the bounty
/// @param _deadline the unix timestamp after which fulfillments will no longer be accepted
/// @param _data the requirements of the bounty
/// @param _fulfillmentAmount the amount of wei to be paid out for each successful fulfillment
/// @param _arbiter the address of the arbiter who can mediate claims
/// @param _paysTokens whether the bounty pays in tokens or in ETH
/// @param _tokenContract the address of the contract if _paysTokens is true
/// @param _value the total number of tokens being deposited upon activation
function issueAndActivateBounty(
address _issuer,
uint _deadline,
string _data,
uint256 _fulfillmentAmount,
address _arbiter,
bool _paysTokens,
address _tokenContract,
uint256 _value
)
public
payable
validateDeadline(_deadline)
amountIsNotZero(_fulfillmentAmount)
validateNotTooManyBounties
returns (uint)
{
require (_value >= _fulfillmentAmount);
if (_paysTokens){
require(msg.value == 0);
tokenContracts[bounties.length] = HumanStandardToken(_tokenContract);
require(tokenContracts[bounties.length].transferFrom(msg.sender, this, _value));
} else {
require((_value * 1 wei) == msg.value);
}
bounties.push(Bounty(_issuer,
_deadline,
_data,
_fulfillmentAmount,
_arbiter,
_paysTokens,
BountyStages.Active,
_value));
BountyIssued(bounties.length - 1);
ContributionAdded(bounties.length - 1, msg.sender, _value);
BountyActivated(bounties.length - 1, msg.sender);
return (bounties.length - 1);
}
modifier isNotDead(uint _bountyId) {
require(bounties[_bountyId].bountyStage != BountyStages.Dead);
_;
}
/// @dev contribute(): a function allowing anyone to contribute tokens to a
/// bounty, as long as it is still before its deadline. Shouldn't keep
/// them by accident (hence 'value').
/// @param _bountyId the index of the bounty
/// @param _value the amount being contributed in ether to prevent accidental deposits
/// @notice Please note you funds will be at the mercy of the issuer
/// and can be drained at any moment. Be careful!
function contribute (uint _bountyId, uint _value)
payable
public
validateBountyArrayIndex(_bountyId)
isBeforeDeadline(_bountyId)
isNotDead(_bountyId)
amountIsNotZero(_value)
transferredAmountEqualsValue(_bountyId, _value)
{
bounties[_bountyId].balance += _value;
ContributionAdded(_bountyId, msg.sender, _value);
}
/// @notice Send funds to activate the bug bounty
/// @dev activateBounty(): activate a bounty so it may pay out
/// @param _bountyId the index of the bounty
/// @param _value the amount being contributed in ether to prevent
/// accidental deposits
function activateBounty(uint _bountyId, uint _value)
payable
public
validateBountyArrayIndex(_bountyId)
isBeforeDeadline(_bountyId)
onlyIssuer(_bountyId)
transferredAmountEqualsValue(_bountyId, _value)
{
bounties[_bountyId].balance += _value;
require (bounties[_bountyId].balance >= bounties[_bountyId].fulfillmentAmount);
transitionToState(_bountyId, BountyStages.Active);
ContributionAdded(_bountyId, msg.sender, _value);
BountyActivated(_bountyId, msg.sender);
}
modifier notIssuerOrArbiter(uint _bountyId) {
require(msg.sender != bounties[_bountyId].issuer && msg.sender != bounties[_bountyId].arbiter);
_;
}
/// @dev fulfillBounty(): submit a fulfillment for the given bounty
/// @param _bountyId the index of the bounty
/// @param _data the data artifacts representing the fulfillment of the bounty
function fulfillBounty(uint _bountyId, string _data)
public
validateBountyArrayIndex(_bountyId)
validateNotTooManyFulfillments(_bountyId)
isAtStage(_bountyId, BountyStages.Active)
isBeforeDeadline(_bountyId)
notIssuerOrArbiter(_bountyId)
{
fulfillments[_bountyId].push(Fulfillment(false, msg.sender, _data));
BountyFulfilled(_bountyId, msg.sender, (fulfillments[_bountyId].length - 1));
}
/// @dev updateFulfillment(): Submit updated data for a given fulfillment
/// @param _bountyId the index of the bounty
/// @param _fulfillmentId the index of the fulfillment
/// @param _data the new data being submitted
function updateFulfillment(uint _bountyId, uint _fulfillmentId, string _data)
public
validateBountyArrayIndex(_bountyId)
validateFulfillmentArrayIndex(_bountyId, _fulfillmentId)
onlyFulfiller(_bountyId, _fulfillmentId)
notYetAccepted(_bountyId, _fulfillmentId)
{
fulfillments[_bountyId][_fulfillmentId].data = _data;
FulfillmentUpdated(_bountyId, _fulfillmentId);
}
modifier onlyIssuerOrArbiter(uint _bountyId) {
require(msg.sender == bounties[_bountyId].issuer ||
(msg.sender == bounties[_bountyId].arbiter && bounties[_bountyId].arbiter != address(0)));
_;
}
modifier fulfillmentNotYetAccepted(uint _bountyId, uint _fulfillmentId) {
require(fulfillments[_bountyId][_fulfillmentId].accepted == false);
_;
}
modifier enoughFundsToPay(uint _bountyId) {
require(bounties[_bountyId].balance >= bounties[_bountyId].fulfillmentAmount);
_;
}
/// @dev acceptFulfillment(): accept a given fulfillment
/// @param _bountyId the index of the bounty
/// @param _fulfillmentId the index of the fulfillment being accepted
function acceptFulfillment(uint _bountyId, uint _fulfillmentId)
public
validateBountyArrayIndex(_bountyId)
validateFulfillmentArrayIndex(_bountyId, _fulfillmentId)
onlyIssuerOrArbiter(_bountyId)
isAtStage(_bountyId, BountyStages.Active)
fulfillmentNotYetAccepted(_bountyId, _fulfillmentId)
enoughFundsToPay(_bountyId)
{
fulfillments[_bountyId][_fulfillmentId].accepted = true;
numAccepted[_bountyId]++;
bounties[_bountyId].balance -= bounties[_bountyId].fulfillmentAmount;
if (bounties[_bountyId].paysTokens){
require(tokenContracts[_bountyId].transfer(fulfillments[_bountyId][_fulfillmentId].fulfiller, bounties[_bountyId].fulfillmentAmount));
} else {
fulfillments[_bountyId][_fulfillmentId].fulfiller.transfer(bounties[_bountyId].fulfillmentAmount);
}
FulfillmentAccepted(_bountyId, msg.sender, _fulfillmentId);
}
/// @dev killBounty(): drains the contract of it's remaining
/// funds, and moves the bounty into stage 3 (dead) since it was
/// either killed in draft stage, or never accepted any fulfillments
/// @param _bountyId the index of the bounty
function killBounty(uint _bountyId)
public
validateBountyArrayIndex(_bountyId)
onlyIssuer(_bountyId)
{
transitionToState(_bountyId, BountyStages.Dead);
uint oldBalance = bounties[_bountyId].balance;
bounties[_bountyId].balance = 0;
if (oldBalance > 0){
if (bounties[_bountyId].paysTokens){
require(tokenContracts[_bountyId].transfer(bounties[_bountyId].issuer, oldBalance));
} else {
bounties[_bountyId].issuer.transfer(oldBalance);
}
}
BountyKilled(_bountyId, msg.sender);
}
modifier newDeadlineIsValid(uint _bountyId, uint _newDeadline) {
require(_newDeadline > bounties[_bountyId].deadline);
_;
}
/// @dev extendDeadline(): allows the issuer to add more time to the
/// bounty, allowing it to continue accepting fulfillments
/// @param _bountyId the index of the bounty
/// @param _newDeadline the new deadline in timestamp format
function extendDeadline(uint _bountyId, uint _newDeadline)
public
validateBountyArrayIndex(_bountyId)
onlyIssuer(_bountyId)
newDeadlineIsValid(_bountyId, _newDeadline)
{
bounties[_bountyId].deadline = _newDeadline;
DeadlineExtended(_bountyId, _newDeadline);
}
/// @dev transferIssuer(): allows the issuer to transfer ownership of the
/// bounty to some new address
/// @param _bountyId the index of the bounty
/// @param _newIssuer the address of the new issuer
function transferIssuer(uint _bountyId, address _newIssuer)
public
validateBountyArrayIndex(_bountyId)
onlyIssuer(_bountyId)
{
bounties[_bountyId].issuer = _newIssuer;
IssuerTransferred(_bountyId, _newIssuer);
}
/// @dev changeBountyDeadline(): allows the issuer to change a bounty's deadline
/// @param _bountyId the index of the bounty
/// @param _newDeadline the new deadline for the bounty
function changeBountyDeadline(uint _bountyId, uint _newDeadline)
public
validateBountyArrayIndex(_bountyId)
onlyIssuer(_bountyId)
validateDeadline(_newDeadline)
isAtStage(_bountyId, BountyStages.Draft)
{
bounties[_bountyId].deadline = _newDeadline;
BountyChanged(_bountyId);
}
/// @dev changeData(): allows the issuer to change a bounty's data
/// @param _bountyId the index of the bounty
/// @param _newData the new requirements of the bounty
function changeBountyData(uint _bountyId, string _newData)
public
validateBountyArrayIndex(_bountyId)
onlyIssuer(_bountyId)
isAtStage(_bountyId, BountyStages.Draft)
{
bounties[_bountyId].data = _newData;
BountyChanged(_bountyId);
}
/// @dev changeBountyfulfillmentAmount(): allows the issuer to change a bounty's fulfillment amount
/// @param _bountyId the index of the bounty
/// @param _newFulfillmentAmount the new fulfillment amount
function changeBountyFulfillmentAmount(uint _bountyId, uint _newFulfillmentAmount)
public
validateBountyArrayIndex(_bountyId)
onlyIssuer(_bountyId)
isAtStage(_bountyId, BountyStages.Draft)
{
bounties[_bountyId].fulfillmentAmount = _newFulfillmentAmount;
BountyChanged(_bountyId);
}
/// @dev changeBountyArbiter(): allows the issuer to change a bounty's arbiter
/// @param _bountyId the index of the bounty
/// @param _newArbiter the new address of the arbiter
function changeBountyArbiter(uint _bountyId, address _newArbiter)
public
validateBountyArrayIndex(_bountyId)
onlyIssuer(_bountyId)
isAtStage(_bountyId, BountyStages.Draft)
{
bounties[_bountyId].arbiter = _newArbiter;
BountyChanged(_bountyId);
}
modifier newFulfillmentAmountIsIncrease(uint _bountyId, uint _newFulfillmentAmount) {
require(bounties[_bountyId].fulfillmentAmount < _newFulfillmentAmount);
_;
}
/// @dev increasePayout(): allows the issuer to increase a given fulfillment
/// amount in the active stage
/// @param _bountyId the index of the bounty
/// @param _newFulfillmentAmount the new fulfillment amount
/// @param _value the value of the additional deposit being added
function increasePayout(uint _bountyId, uint _newFulfillmentAmount, uint _value)
public
payable
validateBountyArrayIndex(_bountyId)
onlyIssuer(_bountyId)
newFulfillmentAmountIsIncrease(_bountyId, _newFulfillmentAmount)
transferredAmountEqualsValue(_bountyId, _value)
{
bounties[_bountyId].balance += _value;
require(bounties[_bountyId].balance >= _newFulfillmentAmount);
bounties[_bountyId].fulfillmentAmount = _newFulfillmentAmount;
PayoutIncreased(_bountyId, _newFulfillmentAmount);
}
/// @dev getFulfillment(): Returns the fulfillment at a given index
/// @param _bountyId the index of the bounty
/// @param _fulfillmentId the index of the fulfillment to return
/// @return Returns a tuple for the fulfillment
function getFulfillment(uint _bountyId, uint _fulfillmentId)
public
constant
validateBountyArrayIndex(_bountyId)
validateFulfillmentArrayIndex(_bountyId, _fulfillmentId)
returns (bool, address, string)
{
return (fulfillments[_bountyId][_fulfillmentId].accepted,
fulfillments[_bountyId][_fulfillmentId].fulfiller,
fulfillments[_bountyId][_fulfillmentId].data);
}
/// @dev getBounty(): Returns the details of the bounty
/// @param _bountyId the index of the bounty
/// @return Returns a tuple for the bounty
function getBounty(uint _bountyId)
public
constant
validateBountyArrayIndex(_bountyId)
returns (address, uint, uint, bool, uint, uint)
{
return (bounties[_bountyId].issuer,
bounties[_bountyId].deadline,
bounties[_bountyId].fulfillmentAmount,
bounties[_bountyId].paysTokens,
uint(bounties[_bountyId].bountyStage),
bounties[_bountyId].balance);
}
/// @dev getBountyArbiter(): Returns the arbiter of the bounty
/// @param _bountyId the index of the bounty
/// @return Returns an address for the arbiter of the bounty
function getBountyArbiter(uint _bountyId)
public
constant
validateBountyArrayIndex(_bountyId)
returns (address)
{
return (bounties[_bountyId].arbiter);
}
/// @dev getBountyData(): Returns the data of the bounty
/// @param _bountyId the index of the bounty
/// @return Returns a string for the bounty data
function getBountyData(uint _bountyId)
public
constant
validateBountyArrayIndex(_bountyId)
returns (string)
{
return (bounties[_bountyId].data);
}
/// @dev getBountyToken(): Returns the token contract of the bounty
/// @param _bountyId the index of the bounty
/// @return Returns an address for the token that the bounty uses
function getBountyToken(uint _bountyId)
public
constant
validateBountyArrayIndex(_bountyId)
returns (address)
{
return (tokenContracts[_bountyId]);
}
/// @dev getNumBounties() returns the number of bounties in the registry
/// @return Returns the number of bounties
function getNumBounties()
public
constant
returns (uint)
{
return bounties.length;
}
/// @dev getNumFulfillments() returns the number of fulfillments for a given milestone
/// @param _bountyId the index of the bounty
/// @return Returns the number of fulfillments
function getNumFulfillments(uint _bountyId)
public
constant
validateBountyArrayIndex(_bountyId)
returns (uint)
{
return fulfillments[_bountyId].length;
}
/*
* Internal functions
*/
/// @dev transitionToState(): transitions the contract to the
/// state passed in the parameter `_newStage` given the
/// conditions stated in the body of the function
/// @param _bountyId the index of the bounty
/// @param _newStage the new stage to transition to
function transitionToState(uint _bountyId, BountyStages _newStage)
internal
{
bounties[_bountyId].bountyStage = _newStage;
}
}