Removed selfdestruct from BreakInvariantBounty (#1385)

* signing prefix added

* Minor improvement

* Tests changed

* Successfully tested

* Minor improvements

* Minor improvements

* Revert "Dangling commas are now required. (#1359)"

This reverts commit a6889776f4.

* updates

* fixes #1384

* introduced claimable and cancelBounty

* cancelBounty tests

* Update BreakInvariantBounty.test.js
This commit is contained in:
Aniket
2018-10-08 19:21:06 +05:30
committed by Nicolás Venturo
parent b17de011dc
commit 41f84f8b40
2 changed files with 58 additions and 31 deletions

View File

@ -8,24 +8,25 @@ import "../ownership/Ownable.sol";
* @dev This bounty will pay out to a researcher if they break invariant logic of the contract.
*/
contract BreakInvariantBounty is PullPayment, Ownable {
bool private _claimed;
bool private _claimable = true;
mapping(address => address) private _researchers;
event TargetCreated(address createdAddress);
event BountyCanceled();
/**
* @dev Fallback function allowing the contract to receive funds, if they haven't already been claimed.
*/
function() external payable {
require(!_claimed);
require(_claimable);
}
/**
* @dev Determine if the bounty was claimed.
* @return true if the bounty was claimed, false otherwise.
* @dev Determine if the bounty is claimable.
* @return false if the bounty was claimed, true otherwise.
*/
function claimed() public view returns(bool) {
return _claimed;
function claimable() public view returns(bool) {
return _claimable;
}
/**
@ -45,20 +46,23 @@ contract BreakInvariantBounty is PullPayment, Ownable {
* @param target contract
*/
function claim(Target target) public {
require(!_claimed);
require(_claimable);
address researcher = _researchers[target];
require(researcher != address(0));
// Check Target contract invariants
require(!target.checkInvariant());
_asyncTransfer(researcher, address(this).balance);
_claimed = true;
_claimable = false;
}
/**
* @dev Transfers the current balance to the owner and terminates the contract.
* @dev Cancels the bounty and transfers all funds to the owner
*/
function destroy() public onlyOwner {
selfdestruct(owner());
function cancelBounty() public onlyOwner{
require(_claimable);
_asyncTransfer(owner(), address(this).balance);
_claimable = false;
emit BountyCanceled();
}
/**