gb1
9/7/2017 - 9:30 AM

Ethereum piggy bank

Ethereum piggy bank

pragma solidity ^0.4.0;

contract Piggy {
    
    uint target = 1000000000000000000;
    
    event Msg( string msg);
    
    mapping(address => uint) balances;
    
    function withdraw() {
        if (balances[msg.sender] >= target) {
            Msg("monies sent!");
            msg.sender.send(balances[msg.sender]);
            balances[msg.sender] = 0;
        }else{
            throw;
        }
    }
    
    function deposit( ) payable{
        
        if (msg.sender.balance >= msg.value) {
            balances[msg.sender] += msg.value;
        }else{
            throw;
        }
        
    }
    
    function getBalance() constant returns(uint balance) {
        return balances[msg.sender];
    }
    
    function getAccountBalance() constant returns(uint balance){
        Msg("cool!");
        return msg.sender.balance;
    }
    
}