Skip to content

Instantly share code, notes, and snippets.

@ketankr9
Last active March 25, 2018 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ketankr9/b0f0f969b0a7f8871c5723f6a671965a to your computer and use it in GitHub Desktop.
Save ketankr9/b0f0f969b0a7f8871c5723f6a671965a to your computer and use it in GitHub Desktop.
Problem Statement 1 for CTF
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