Last active
January 12, 2018 06:53
-
-
Save alecchampaign/2b2c0bedb81b724f884eb6bafc5a6ee2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.8; | |
contract FunBucks { | |
struct accounts { | |
string name; | |
uint balance; | |
bool active; | |
bool funOfficer; | |
} | |
mapping (address => accounts) people; | |
event fundsGenerated(uint _balance, address _receiver); | |
event fundsTransfered(uint _amount, address _receiver); | |
event accountActivated(string _name); | |
event accountClosed(address _address); | |
address owner; | |
modifier funAuthority { | |
require(people[msg.sender].funOfficer == true); | |
_; | |
} | |
modifier ownerOnly { | |
require(msg.sender == owner); | |
_; | |
} | |
function FunBucks(uint _balance, string _name) public { | |
// Establish owner of contract, credit him a balance, give him a name, and activate his account | |
owner = msg.sender; | |
people[owner].balance = _balance; | |
people[owner].name = _name; | |
people[owner].active = true; | |
people[owner].funOfficer = true; | |
} | |
function generateFunds(uint _balance, address receiver) public ownerOnly { | |
// Upon owner's request, generate funds for a user | |
people[receiver].balance += _balance; | |
fundsGenerated(_balance, receiver); | |
} | |
function transferFunds(uint amount, address receiver) public { | |
// Send funds from your account to another user's account | |
require(people[msg.sender].balance >= amount && people[msg.sender].active == true); | |
people[msg.sender].balance -= amount; | |
people[receiver].balance += amount; | |
fundsTransfered(amount, receiver); | |
} | |
function activateAccount(string _name) public payable { | |
// Activate your account to enable use of FunBucks; cost 10 finney | |
require(msg.value == 10 finney); | |
people[msg.sender].name = _name; | |
accountActivated(_name); | |
owner.transfer(10 finney); | |
} | |
function closeAccount(address _address) public payable { | |
if(_address > 0) { | |
// Fun Officer forcefully closes another user's account | |
require(people[msg.sender].funOfficer == true); | |
people[_address].name = ""; | |
people[_address].balance = 0; | |
people[_address].active = false; | |
accountClosed(_address); | |
} | |
else { | |
// Close your account; cost 10 finney | |
require(people[msg.sender].active == true && msg.value == 10 finney); | |
people[msg.sender].name = ""; | |
people[msg.sender].balance = 0; | |
people[msg.sender].active = false; | |
accountClosed(msg.sender); | |
} | |
} | |
function freezeAccount(address _address) public funAuthority { | |
// Fun Officer forcefully freezes the funds of a user's account | |
people[_address].active = false; | |
} | |
// Owner heightens the permissions of a user to officer status, generates officer's reward | |
function initiateOfficerOfTheFun(address _address) public ownerOnly { | |
people[_address].funOfficer = true; | |
people[_address].balance += 50; | |
} | |
function getBalance(address _address) public constant returns(uint) { | |
// Specify the address to query the funds of another user | |
if(_address > 0) { | |
return(people[_address].balance); | |
} | |
// If the user doesn't specify an address, they wish to query their own funds | |
else { | |
return(people[msg.sender].balance); | |
} | |
} | |
function killContract() public ownerOnly { | |
// Kills the contract and sends funds to the owner | |
selfdestruct(owner); | |
} | |
// Fallback function | |
function() public payable { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment