Last active
March 25, 2018 10:22
-
-
Save ketankr9/b0f0f969b0a7f8871c5723f6a671965a to your computer and use it in GitHub Desktop.
Problem Statement 1 for CTF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.6; | |
contract Question1 { | |
uint initialSupply = 100; | |
uint transactionCost = 1; | |
uint transactionCount = 0; | |
address owner; | |
mapping (address => uint) private balance; | |
mapping (address => bool) moneySpent; | |
function Question1() public { | |
balance[msg.sender] = initialSupply; | |
owner = msg.sender; | |
moneySpent[msg.sender] = false; | |
} | |
function tax() private returns (bool){ | |
if(balance[msg.sender] - 1 < 0) | |
return false; | |
balance[msg.sender] -= 1; | |
return true; | |
} | |
function checkEligiblity(uint _money) private returns (bool) { | |
if((balance[msg.sender] - _money < 0) || (tax() == false) || (_money < 0) || (transactionCount > 0)) | |
return false; | |
moneySpent[msg.sender] = true; | |
transactionCount++; | |
return true; | |
} | |
function transfer(address _to, uint _money) public returns (bool) { | |
require(checkEligiblity(_money) == true); | |
balance[msg.sender] -= _money; | |
balance[_to] += _money; | |
return true; | |
} | |
function myBalance() public view returns (uint) { | |
return balance[msg.sender]; | |
} | |
function spent() public view returns (bool){ | |
return moneySpent[msg.sender]; | |
} | |
function checkResult() public view returns (bool) { | |
if ( balance[msg.sender] == initialSupply && moneySpent[msg.sender] == true) | |
return true; | |
else | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment