Oops I did it again...

Oops I did it again...

pragma solidity ^0.4.11;

import "MiniMeToken.sol";

contract ERC20Token {
    function transfer(address _to, uint256 _value) returns (bool success);
    function balanceOf(address _owner) constant returns (uint256 balance);
}

contract Owned {
    address public owner;

    function Owned() {
        owner = msg.sender;
    }

    function transferOwnership (address _newOwner) onlyOwner {
        owner = _newOwner;
    }

    modifier onlyOwner() {
        if(msg.sender != owner) throw;
        _;
    }
}

/*
    Copyright 2017, Joseph Reed

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/// @title MeDao Contract
/// @author Joseph Reed
/// @dev A MeDao aims to let anyone issue time shares for themselves. The issuer
///      should talk to shareholders for advice on how to maximize value for
///      themselves and for shareholders. Up to 40 hours worth of time are
///      auctioned off each week. The Owner of the MeDao is expected to burn
///      a certain amount of tokens each week negotiated between the Owner
///      and the Shareholders and thus will be diffrent for every MeDao. For
///      more info go to <github link here>.

contract Tokenized is Owned {

    MiniMeToken public Token;
    address public withdraw_address;

    function setupToken (
        address withdrawAddress,
        MiniMeToken CloneableToken,
        string _tokenName,
        uint8 _decimals,
        string _symbol,
        uint _snapshotBlock,
        bool _transfersEnabled
    ) onlyOwner {
        withdraw_address = withdrawAddress;
        address token = CloneableToken.createCloneToken(
            _tokenName,
            _decimals,
            _symbol,
            _snapshotBlock,
            _transfersEnabled
        );

        Token = MiniMeToken(token);
    }

    function withdrawEther () onlyOwner {
        var balance = this.balance;
        withdraw_address.transfer(balance);

        WithdrawEther_event(withdraw_address,balance);
    }

    function withdrawERC20Token (address Token) onlyOwner {
        uint tokenBalance = ERC20Token(Token).balanceOf(this);
        ERC20Token(Token).transfer(withdraw_address,tokenBalance);

        WithdrawToken_event(withdraw_address,Token,tokenBalance);
    }

    function updateDepositAddress (address _newDepositAddress) onlyOwner {
        withdraw_address = _newDepositAddress;

        NewWithdrawAddress_event(withdraw_address);
    }

    function () payable {
        withdraw_address.transfer(msg.value);

        Payable_event(msg.sender,msg.value);
    }

    modifier onlyTokenHolders (uint _minimum_needed) {
        uint tokens = Token.balanceOf(msg.sender);
        if(tokens < _minimum_needed) throw;
        _;
    }

    event Payable_event(address sender, uint amount);
    event WithdrawEther_event(address withdrawAddress, uint amount);
    event WithdrawToken_event(address withdrawAddress, address token, uint amount);
    event NewWithdrawAddress_event(address withdraw_address);
}

contract OngoingAuction is Owned {

    uint public current_bids_open;
    uint public total_bids_made;
    mapping (uint => Bid) public bids;
    mapping (address => Bidder) public bidders;

    uint public top_teir;
    uint public bottom_teir;
    uint public total_teirs;
    mapping (uint => Teir) public teirs; //DLL

////////////////
// Auction Functions
////////////////

    function placeBid (uint touchingTeir) payable {
        if(msg.value == 0) throw;

        if(teirs[msg.value].line_length == 0) {
            if(teirs[touchingTeir].line_length == 0 && top_teir != 0) throw;

            addNewTeir_internal(touchingTeir);
        }

        addNewBid_internal();
    }

    function removeBid (uint bid_id) {
        if (msg.sender != bids[bid_id].owner) throw;

        removeBid_internal(bid_id);
        bids[bid_id].cancelled = true;

        if (!bids[bid_id].owner.send(bids[bid_id].value)) throw;
    }

    function acceptHighestBid (address deposit_address) onlyOwner returns (uint) {
        if(top_teir == 0) throw;

        uint winning_bid_id = teirs[top_teir].front_of_line_id;
        removeBid_internal(winning_bid_id);
        bids[winning_bid_id].accepted = true;

        uint bidValue = bids[winning_bid_id].value;
        deposit_address.transfer(bidValue);

        return winning_bid_id;
    }

    function getBids (address bidder) constant returns (uint[]) {
        uint total_bids = bidders[bidder].total_bids_made;
        uint[] memory all_bids = new uint[](total_bids);

        for(uint i = 0; i < total_bids; i++)
            all_bids[i] = bidders[bidder].bids[i+1];

        return all_bids;
    }

    function getTeirs () constant returns (uint[]) {
        uint[] memory all_teirs = new uint[](total_teirs);
        uint current_teir = teirs[top_teir].value;
        for (uint i = 0; i < total_teirs; i++) {
            all_teirs[i] = current_teir;
            current_teir = teirs[current_teir].teir_below;
        }

        return all_teirs;
    }

    function getBidOwner (uint bid_id) constant returns (address) {
        return bids[bid_id].owner;
    }

    function getBidValue (uint bid_id) constant returns (uint) {
        return bids[bid_id].value;
    }

////////////////
// Internal Functions
////////////////

    function addNewTeir_internal (uint touching) internal {
        uint value = msg.value;

        if (top_teir == 0) {
            teirs[value] = Teir(0,value,0,0,0,0);
            top_teir = value;
            bottom_teir = value;
        } else if (value > top_teir && touching == top_teir) {
            teirs[value] = Teir(0,value,top_teir,0,0,0);
            teirs[top_teir].teir_above = value;
            top_teir = value;
        } else if (value < bottom_teir && touching == bottom_teir) {
            teirs[value] = Teir(bottom_teir,value,0,0,0,0);
            teirs[bottom_teir].teir_below = value;
            bottom_teir = value;
        } else {
            uint above;
            uint below;
            if(value > touching) {
                above = teirs[touching].teir_above;
                below = touching;
                if(value > above) throw;
            } else if(value < touching) {
                above = touching;
                below = teirs[touching].teir_below;
                if(value < below) throw;
            }

            teirs[value] = Teir(above,value,below,0,0,0);
            teirs[above].teir_below = value;
            teirs[below].teir_above = value;
        }

        total_teirs++;
    }

    function removeTeir_internal (uint value) internal {
        uint teir_below = teirs[value].teir_below;
        uint teir_above = teirs[value].teir_above;

        if (value == top_teir && value == bottom_teir) {
            top_teir = 0;
            bottom_teir = 0;
        } else if (value == top_teir) {
            teirs[teir_below].teir_above = 0;
            top_teir = teir_below;
        } else if (value == bottom_teir) {
            teirs[teir_above].teir_below = 0;
            bottom_teir = teir_above;
        } else {
            teirs[teir_above].teir_below = teir_below;
            teirs[teir_below].teir_above = teir_above;
        }

        delete teirs[value];
        total_teirs--;
    }

    function addNewBid_internal () internal {
        current_bids_open++;
        total_bids_made++;
        uint new_bid_id = total_bids_made;

        teirs[msg.value].line[new_bid_id] = SpotInLine(back_of_line_id,new_bid_id,0);

        if (teirs[msg.value].line_length == 0)
            teirs[msg.value].front_of_line_id = new_bid_id;

        uint back_of_line_id = teirs[msg.value].back_of_line_id;
        if (back_of_line_id != 0)
            teirs[msg.value].line[back_of_line_id].prev = new_bid_id;

        teirs[msg.value].back_of_line_id = new_bid_id;
        teirs[msg.value].line_length++;

        bids[new_bid_id] = Bid(new_bid_id,msg.sender,msg.value,false,false);
        bidders[msg.sender].current_bids_open++;
        bidders[msg.sender].total_bids_made++;
        uint total_bids = bidders[msg.sender].total_bids_made;
        bidders[msg.sender].bids[total_bids] = new_bid_id;

        NewBid_event(msg.sender,new_bid_id,msg.value);
    }

    function removeBid_internal (uint bid_id) internal {
        Bid bid = bids[bid_id];
        if(teirs[bid.value].line_length == 0) throw;
        if(bid.accepted || bid.cancelled) throw;

        uint front_of_line_id = teirs[bid.value].front_of_line_id;
        uint back_of_line_id = teirs[bid.value].back_of_line_id;
        if (bid.id == front_of_line_id) {
            uint prev = teirs[bid.value].line[bid.id].prev;
            teirs[bid.value].front_of_line_id = prev;
            teirs[bid.value].line[prev].prev = 0;
        } else if (bid.id == back_of_line_id) {
            uint next = teirs[bid.value].line[bid.id].next;
            teirs[bid.value].back_of_line_id = next;
            teirs[bid.value].line[next].prev = 0;
        } else {
            uint front_id = teirs[bid.value].line[bid.id].next;
            uint back_id = teirs[bid.value].line[bid.id].prev;
            teirs[bid.value].line[front_id].prev = back_id;
            teirs[bid.value].line[back_id].next = front_id;
        }

        delete teirs[bid.value].line[bid_id];
        teirs[bid.value].line_length--;

        bidders[msg.sender].current_bids_open--;
        current_bids_open--;

        if(teirs[bid.value].line_length == 0)
            removeTeir_internal(bid.value);
    }

////////////////
// Structs and Events
////////////////

    struct SpotInLine {
        uint next;
        uint bid_id;
        uint prev;
    }

    struct Bidder {
        uint current_bids_open;
        uint total_bids_made;
        mapping (uint => uint) bids;
    }

    struct Bid {
        uint id;
        address owner;
        uint value;
        bool cancelled;
        bool accepted;
    }

    struct Teir {
        uint teir_above;
        uint value;
        uint teir_below;

        uint front_of_line_id;
        uint back_of_line_id;
        uint line_length;
        mapping (uint => SpotInLine) line; //FIFO DLL
    }

    event NewBid_event(address bidder, uint bid_id, uint value);
}

contract MeDao is Tokenized {

    string public version = '0.0.2';

    address public Founder;

    OngoingAuction public Auction;

    uint public weekly_auction_reward;
    uint public scheduled_auction_timestamp;
    uint public auction_period;

    uint public total_proof_of_work;

    uint public cooldown_timestamp;
    uint burn_minimum = 1;

////////////////
// MeDao Functions
////////////////

    function MeDao (address founder, OngoingAuction auction) {
        Founder = founder;
        Auction = auction;
    }

    function startAuction () isScheduled {
        uint winning_bid_id = Auction.acceptHighestBid(withdraw_address);
        address winner = Auction.getBidOwner(winning_bid_id);
        uint winning_bid_value = Auction.getBidValue(winning_bid_id);

        Token.generateTokens(winner, 1 hours);

        AuctionWinner_event(winner,winning_bid_value);
    }

    function submitProofOfWork (uint burnAmount, string metadataHash)
    onlyTokenHolders(burn_minimum) {
        if(Token.balanceOf(msg.sender) < burnAmount) throw;

        Token.destroyTokens(msg.sender,burnAmount);
        total_proof_of_work += burnAmount;

        ProofOfWork_event(msg.sender,burnAmount,metadataHash);
    }

////////////////
// Owner Only
////////////////

    function setWeeklyAuctionReward (uint8 reward) onlyOwner
    hasCooldown(7 days) {
        if(reward > 40 hours || reward == 0) throw;

        weekly_auction_reward = reward;
        auction_period = 5 minutes; //set to 5 minutes for testing. Normally use
                                    //7 days / auction_reward;
        scheduled_auction_timestamp = now + auction_period;

        NewWeeklyAuctionReward_event(weekly_auction_reward);
    }

    function setBurnMinimum (uint burnMinimum) onlyOwner {
        burn_minimum = burnMinimum;
    }

////////////////
// Events and Modifiers
////////////////

    modifier isScheduled () {
        if (scheduled_auction_timestamp == 0) throw;
        if (now < scheduled_auction_timestamp) throw;

        if(now < scheduled_auction_timestamp + auction_period)
            scheduled_auction_timestamp += auction_period;
        else
            scheduled_auction_timestamp = now + auction_period;

        _;
    }

    modifier hasCooldown (uint cooldown) {
        if(now < cooldown_timestamp) throw;

        cooldown_timestamp = now + cooldown;
        _;
    }

    event AuctionWinner_event (address winner, uint ether_bid);
    event ProofOfWork_event(address sender, uint amount, string metadataHash);
    event NewDepositAddress_event(address deposit_address);
    event NewWeeklyAuctionReward_event(uint new_auction_reward);
}

contract MeDaoRegistry {

    MiniMeToken PrimeToken;

    uint public total_medaos;
    mapping (uint => address) public founders;
    mapping (address => MeDao ) public medaos;

    function MeDaoRegistry (MiniMeToken Token) {
        PrimeToken = Token;
    }

    function register (string name) {
        if(medaos[msg.sender] != address(0x0)) throw;

        uint next_id = total_medaos++;
        founders[next_id] = msg.sender;

        OngoingAuction Auction = new OngoingAuction();

        medaos[msg.sender] = new MeDao(msg.sender,Auction);
        medaos[msg.sender].setupToken(msg.sender,PrimeToken,name,0,'seconds',0,true);
        medaos[msg.sender].transferOwnership(msg.sender);
        Auction.transferOwnership(medaos[msg.sender]);

        NewMeDao_event(msg.sender, medaos[msg.sender]);
    }

    event NewMeDao_event(address founder, address medao);
}

pragma solidity ^0.4.11;

import "MiniMeToken.sol";

contract ERC20Token {
    function transfer(address _to, uint256 _value) returns (bool success);
    function balanceOf(address _owner) constant returns (uint256 balance);
}

contract Owned {
    address public owner;

    function Owned() {
        owner = msg.sender;
    }

    function transferOwnership (address _newOwner) onlyOwner {
        owner = _newOwner;
    }

    modifier onlyOwner() {
        if(msg.sender != owner) throw;
        _;
    }
}

/*
    Copyright 2017, Joseph Reed

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/// @title MeDao Contract
/// @author Joseph Reed
/// @dev A MeDao aims to let anyone issue time shares for themselves. The issuer
///      should talk to shareholders for advice on how to maximize value for
///      themselves and for shareholders. Up to 40 hours worth of time are
///      auctioned off each week. The Owner of the MeDao is expected to burn
///      a certain amount of tokens each week negotiated between the Owner
///      and the Shareholders and thus will be diffrent for every MeDao. For
///      more info go to <github link here>.

contract Tokenized is Owned {

    MiniMeToken public Token;
    address public withdraw_address;

    function setupToken (
        address withdrawAddress,
        MiniMeToken CloneableToken,
        string _tokenName,
        uint8 _decimals,
        string _symbol,
        uint _snapshotBlock,
        bool _transfersEnabled
    ) onlyOwner {
        withdraw_address = withdrawAddress;
        address token = CloneableToken.createCloneToken(
            _tokenName,
            _decimals,
            _symbol,
            _snapshotBlock,
            _transfersEnabled
        );

        Token = MiniMeToken(token);
    }

    function withdrawEther () onlyOwner {
        var balance = this.balance;
        withdraw_address.transfer(balance);

        WithdrawEther_event(withdraw_address,balance);
    }

    function withdrawERC20Token (address Token) onlyOwner {
        uint tokenBalance = ERC20Token(Token).balanceOf(this);
        ERC20Token(Token).transfer(withdraw_address,tokenBalance);

        WithdrawToken_event(withdraw_address,Token,tokenBalance);
    }

    function updateDepositAddress (address _newDepositAddress) onlyOwner {
        withdraw_address = _newDepositAddress;

        NewWithdrawAddress_event(withdraw_address);
    }

    function () payable {
        withdraw_address.transfer(msg.value);

        Payable_event(msg.sender,msg.value);
    }

    modifier onlyTokenHolders (uint _minimum_needed) {
        uint tokens = Token.balanceOf(msg.sender);
        if(tokens < _minimum_needed) throw;
        _;
    }

    event Payable_event(address sender, uint amount);
    event WithdrawEther_event(address withdrawAddress, uint amount);
    event WithdrawToken_event(address withdrawAddress, address token, uint amount);
    event NewWithdrawAddress_event(address withdraw_address);
}

contract OngoingAuction is Owned {

    uint public current_bids_open;
    uint public total_bids_made;
    mapping (uint => Bid) public bids;
    mapping (address => Bidder) public bidders;

    uint public top_teir;
    uint public bottom_teir;
    uint public total_teirs;
    mapping (uint => Teir) public teirs; //DLL

////////////////
// Auction Functions
////////////////

    function placeBid (uint touchingTeir) payable {
        if(msg.value == 0) throw;

        if(teirs[msg.value].line_length == 0) {
            if(teirs[touchingTeir].line_length == 0 && top_teir != 0) throw;

            addNewTeir_internal(touchingTeir);
        }

        addNewBid_internal();
    }

    function removeBid (uint bid_id) {
        if (msg.sender != bids[bid_id].owner) throw;

        removeBid_internal(bid_id);
        bids[bid_id].cancelled = true;

        if (!bids[bid_id].owner.send(bids[bid_id].value)) throw;
    }

    function acceptHighestBid (address deposit_address) onlyOwner returns (uint) {
        if(top_teir == 0) throw;

        uint winning_bid_id = teirs[top_teir].front_of_line_id;
        bids[winning_bid_id].accepted = true;
        removeBid_internal(winning_bid_id);

        uint bidValue = bids[winning_bid_id].value;
        deposit_address.transfer(bidValue);

        return winning_bid_id;
    }

    function getBids (address bidder) constant returns (uint[]) {
        uint total_bids = bidders[bidder].total_bids_made;
        uint[] memory all_bids = new uint[](total_bids);

        for(uint i = 0; i < total_bids; i++)
            all_bids[i] = bidders[bidder].bids[i+1];

        return all_bids;
    }

    function getTeirs () constant returns (uint[]) {
        uint[] memory all_teirs = new uint[](total_teirs);
        uint current_teir = teirs[top_teir].value;
        for (uint i = 0; i < total_teirs; i++) {
            all_teirs[i] = current_teir;
            current_teir = teirs[current_teir].teir_below;
        }

        return all_teirs;
    }

    function getBidOwner (uint bid_id) constant returns (address) {
        return bids[bid_id].owner;
    }

    function getBidValue (uint bid_id) constant returns (uint) {
        return bids[bid_id].value;
    }

////////////////
// Internal Functions
////////////////

    function addNewTeir_internal (uint touching) internal {
        uint value = msg.value;

        if (top_teir == 0) {
            teirs[value] = Teir(0,value,0,0,0,0);
            top_teir = value;
            bottom_teir = value;
        } else if (value > top_teir && touching == top_teir) {
            teirs[value] = Teir(0,value,top_teir,0,0,0);
            teirs[top_teir].teir_above = value;
            top_teir = value;
        } else if (value < bottom_teir && touching == bottom_teir) {
            teirs[value] = Teir(bottom_teir,value,0,0,0,0);
            teirs[bottom_teir].teir_below = value;
            bottom_teir = value;
        } else {
            uint above;
            uint below;
            if(value > touching) {
                above = teirs[touching].teir_above;
                below = touching;
                if(value > above) throw;
            } else if(value < touching) {
                above = touching;
                below = teirs[touching].teir_below;
                if(value < below) throw;
            }

            teirs[value] = Teir(above,value,below,0,0,0);
            teirs[above].teir_below = value;
            teirs[below].teir_above = value;
        }

        total_teirs++;
    }

    function removeTeir_internal (uint value) internal {
        uint teir_below = teirs[value].teir_below;
        uint teir_above = teirs[value].teir_above;

        if (value == top_teir && value == bottom_teir) {
            top_teir = 0;
            bottom_teir = 0;
        } else if (value == top_teir) {
            teirs[teir_below].teir_above = 0;
            top_teir = teir_below;
        } else if (value == bottom_teir) {
            teirs[teir_above].teir_below = 0;
            bottom_teir = teir_above;
        } else {
            teirs[teir_above].teir_below = teir_below;
            teirs[teir_below].teir_above = teir_above;
        }

        delete teirs[value];
        total_teirs--;
    }

    function addNewBid_internal () internal {
        current_bids_open++;
        total_bids_made++;
        uint new_bid_id = total_bids_made;

        teirs[msg.value].line[new_bid_id] = SpotInLine(back_of_line_id,new_bid_id,0);

        if (teirs[msg.value].line_length == 0)
            teirs[msg.value].front_of_line_id = new_bid_id;

        uint back_of_line_id = teirs[msg.value].back_of_line_id;
        if (back_of_line_id != 0)
            teirs[msg.value].line[back_of_line_id].prev = new_bid_id;

        teirs[msg.value].back_of_line_id = new_bid_id;
        teirs[msg.value].line_length++;

        bids[new_bid_id] = Bid(new_bid_id,msg.sender,msg.value,false,false);
        bidders[msg.sender].current_bids_open++;
        bidders[msg.sender].total_bids_made++;
        uint total_bids = bidders[msg.sender].total_bids_made;
        bidders[msg.sender].bids[total_bids] = new_bid_id;

        NewBid_event(msg.sender,new_bid_id,msg.value);
    }

    function removeBid_internal (uint bid_id) internal {
        Bid bid = bids[bid_id];
        if(teirs[bid.value].line_length == 0) throw;
        if(bid.accepted || bid.cancelled) throw;

        uint front_of_line_id = teirs[bid.value].front_of_line_id;
        uint back_of_line_id = teirs[bid.value].back_of_line_id;
        if (bid.id == front_of_line_id) {
            uint prev = teirs[bid.value].line[bid.id].prev;
            teirs[bid.value].front_of_line_id = prev;
            teirs[bid.value].line[prev].prev = 0;
        } else if (bid.id == back_of_line_id) {
            uint next = teirs[bid.value].line[bid.id].next;
            teirs[bid.value].back_of_line_id = next;
            teirs[bid.value].line[next].prev = 0;
        } else {
            uint front_id = teirs[bid.value].line[bid.id].next;
            uint back_id = teirs[bid.value].line[bid.id].prev;
            teirs[bid.value].line[front_id].prev = back_id;
            teirs[bid.value].line[back_id].next = front_id;
        }

        delete teirs[bid.value].line[bid_id];
        teirs[bid.value].line_length--;

        bidders[msg.sender].current_bids_open--;
        current_bids_open--;

        if(teirs[bid.value].line_length == 0)
            removeTeir_internal(bid.value);
    }

////////////////
// Structs and Events
////////////////

    struct SpotInLine {
        uint next;
        uint bid_id;
        uint prev;
    }

    struct Bidder {
        uint current_bids_open;
        uint total_bids_made;
        mapping (uint => uint) bids;
    }

    struct Bid {
        uint id;
        address owner;
        uint value;
        bool cancelled;
        bool accepted;
    }

    struct Teir {
        uint teir_above;
        uint value;
        uint teir_below;

        uint front_of_line_id;
        uint back_of_line_id;
        uint line_length;
        mapping (uint => SpotInLine) line; //FIFO DLL
    }

    event NewBid_event(address bidder, uint bid_id, uint value);
}

contract MeDao is Tokenized {

    string public version = '0.0.2';

    address public Founder;

    OngoingAuction public Auction;

    uint public weekly_auction_reward;
    uint public scheduled_auction_timestamp;
    uint public auction_period;

    uint public total_proof_of_work;

    uint public cooldown_timestamp;
    uint burn_minimum = 1;

////////////////
// MeDao Functions
////////////////

    function MeDao (address founder, OngoingAuction auction) {
        Founder = founder;
        Auction = auction;
    }

    function startAuction () isScheduled {
        uint winning_bid_id = Auction.acceptHighestBid(withdraw_address);
        address winner = Auction.getBidOwner(winning_bid_id);
        uint winning_bid_value = Auction.getBidValue(winning_bid_id);

        Token.generateTokens(winner, 1 hours);

        AuctionWinner_event(winner,winning_bid_value);
    }

    function submitProofOfWork (uint burnAmount, string metadataHash)
    onlyTokenHolders(burn_minimum) {
        if(Token.balanceOf(msg.sender) < burnAmount) throw;

        Token.destroyTokens(msg.sender,burnAmount);
        total_proof_of_work += burnAmount;

        ProofOfWork_event(msg.sender,burnAmount,metadataHash);
    }

////////////////
// Owner Only
////////////////

    function setWeeklyAuctionReward (uint8 reward) onlyOwner
    hasCooldown(7 days) {
        if(reward > 40 hours || reward == 0) throw;

        weekly_auction_reward = reward;
        auction_period = 5 minutes; //set to 5 minutes for testing normally use:
                                    //7 days / auction_reward;
        scheduled_auction_timestamp = now + auction_period;

        NewWeeklyAuctionReward_event(weekly_auction_reward);
    }

    function setBurnMinimum (uint burnMinimum) onlyOwner {
        burn_minimum = burnMinimum;
    }

////////////////
// Events and Modifiers
////////////////

    modifier isScheduled () {
        if (scheduled_auction_timestamp == 0) throw;
        if (now < scheduled_auction_timestamp) throw;

        if(now < scheduled_auction_timestamp + auction_period)
            scheduled_auction_timestamp += auction_period;
        else
            scheduled_auction_timestamp = now + auction_period;

        _;
    }

    modifier onlyAuction () {
        if (msg.sender != address(Auction)) throw;

        _;
    }

    modifier hasCooldown (uint cooldown) {
        if(now < cooldown_timestamp) throw;

        cooldown_timestamp = now + cooldown;
        _;
    }

    event AuctionWinner_event (address winner, uint ether_bid);
    event ProofOfWork_event(address sender, uint amount, string metadataHash);
    event NewDepositAddress_event(address deposit_address);
    event NewWeeklyAuctionReward_event(uint new_auction_reward);
}

contract MeDaoRegistry {

    MiniMeToken PrimeToken;

    uint public total_medaos;
    mapping (uint => address) public founders;
    mapping (address => MeDao ) public medaos;

    function MeDaoRegistry (MiniMeToken Token) {
        PrimeToken = Token;
    }

    function register (string name) {
        if(medaos[msg.sender] != address(0x0)) throw;

        uint next_id = total_medaos++;
        founders[next_id] = msg.sender;

        OngoingAuction Auction = new OngoingAuction();

        medaos[msg.sender] = new MeDao(msg.sender,Auction);
        medaos[msg.sender].setupToken(msg.sender,PrimeToken,name,0,'seconds',0,true);
        medaos[msg.sender].transferOwnership(msg.sender);
        Auction.transferOwnership(medaos[msg.sender]);

        NewMeDao_event(msg.sender, medaos[msg.sender]);
    }

    event NewMeDao_event(address founder, address medao);
}


catalogo: criar smart contract de catalogo de ouvidorias

pragma solidity ^0.4.4;

/// @title Catalogo de Ouvidorias para o Barramento de Ouvidorias
contract CatalogoOuvidorias {

}

error: pathspec 'catalogo-project/contracts/CatalogoOuvidorias.sol' did not match any file(s) known to git


remove comments; whitespace

remove comments; whitespace

contract TokenInterface {
    mapping (address => uint256) balances;
    mapping (address => mapping (address => uint256)) allowed;

    uint256 public totalSupply;

    function balanceOf(address _owner) constant returns (uint256 balance);
    function transfer(address _to, uint256 _amount) returns (bool success);

    /* TODO: THIS LATER!
    function transferFrom(address _from, address _to, uint256 _amount) returns (bool success);
    function approve(address _spender, uint256 _amount) returns (bool success);
    function allowance(address _owner, address _spender) constant returns (uint256 remaining);
    */

    event Transfer(address indexed _from, address indexed _to, uint256 _amount);
    /* event Approval(address indexed _owner,address indexed _spender,uint256 _amount);*/
}

/*string public version;   // eg comakery-token-v1.0 */

contract Token is TokenInterface {
  address public owner;

  /* public event on the blockchain that will notify clients */

  function Token() {
    owner = msg.sender; // contract owner is contract creator
    totalSupply = 10000000;
  }

  // owner functions ----------------------------
  modifier onlyOwner {
    if (msg.sender == owner) {
      _
    }
  }

  function setTotalSupply(uint256 _totalSupply) onlyOwner {
      totalSupply = _totalSupply;
  }

  function issue(address _to, uint256 _value) onlyOwner {
    if (_value <= totalSupply) {
      balances[_to] = _value;
    }
  }

  function setOwner(address _newOwner) onlyOwner {
    owner = _newOwner;
  }

  // user functions -------------------------------
  function transfer(address _to, uint256 _amount) returns (bool success) {
    if (balances[msg.sender] >= _amount) {           // Check if the sender has enough*/
      if (balances[_to] + _amount < balances[_to]) throw;  // Check for overflows

      balances[msg.sender] -= _amount;                     // Subtract from the sender
      balances[_to] += _amount;                            // Add the same to the recipient
      Transfer(msg.sender, _to, _amount);                   // Notify anyone listening that this transfer took place
      return true;
    } else {
      return false;
    }
  }

  function balanceOf(address _owner) constant returns(uint256 balance) {
    return balances[_owner];
  }

  /*TODO*/
  /*function destroy() onlyOwner {
    suicide(owner);
  }*/

  /* This unnamed function is called whenever someone tries to transfer ether to it */
  function () {
    throw;     // Prevents accidental sending of ether
  }
}

contract TokenInterface {
    mapping (address => uint256) balances;
    mapping (address => mapping (address => uint256)) allowed;

    /// Total amount of tokens
    uint256 public totalSupply;

    /// @param _owner The address from which the balance will be retrieved
    /// @return The balance
    function balanceOf(address _owner) constant returns (uint256 balance);

    /// @notice Send `_amount` tokens to `_to` from `msg.sender`
    /// @param _to The address of the recipient
    /// @param _amount The amount of tokens to be transferred
    /// @return Whether the transfer was successful or not
    function transfer(address _to, uint256 _amount) returns (bool success);

    /* TODO: THIS LATER!
    /// @notice Send `_amount` tokens to `_to` from `_from` on the condition it
    /// is approved by `_from`
    /// @param _from The address of the origin of the transfer
    /// @param _to The address of the recipient
    /// @param _amount The amount of tokens to be transferred
    /// @return Whether the transfer was successful or not
    function transferFrom(address _from, address _to, uint256 _amount) returns (bool success);
    */

    /*
    /// @notice `msg.sender` approves `_spender` to spend `_amount` tokens on
    /// its behalf
    /// @param _spender The address of the account able to transfer the tokens
    /// @param _amount The amount of tokens to be approved for transfer
    /// @return Whether the approval was successful or not
    function approve(address _spender, uint256 _amount) returns (bool success);

    /// @param _owner The address of the account owning tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @return Amount of remaining tokens of _owner that _spender is allowed
    /// to spend
    function allowance(
        address _owner,
        address _spender
    ) constant returns (uint256 remaining);
    */

    event Transfer(address indexed _from, address indexed _to, uint256 _amount);
    /*
    event Approval(
        address indexed _owner,
        address indexed _spender,
        uint256 _amount
    );*/
}

/*string public version;   // eg comakery-token-v1.0 */

contract Token is TokenInterface {
  address public owner;

  /* public event on the blockchain that will notify clients */

  function Token() {
    owner = msg.sender; // contract owner is contract creator
    totalSupply = 10000000;
  }

  // owner functions ----------------------------
  modifier onlyOwner {
    if (msg.sender == owner) {
      _
    }
  }

  function setTotalSupply(uint256 _totalSupply) onlyOwner {
      totalSupply = _totalSupply;
  }

  function issue(address _to, uint256 _value) onlyOwner {
    if (_value <= totalSupply) {
      balances[_to] = _value;
    }
  }

  function setOwner(address _newOwner) onlyOwner {
    owner = _newOwner;
  }

  // user functions -------------------------------
  function transfer(address _to, uint256 _amount) returns (bool success) {
    if (balances[msg.sender] >= _amount) {           // Check if the sender has enough*/
      if (balances[_to] + _amount < balances[_to]) throw;  // Check for overflows

      balances[msg.sender] -= _amount;                     // Subtract from the sender
      balances[_to] += _amount;                            // Add the same to the recipient
      Transfer(msg.sender, _to, _amount);                   // Notify anyone listening that this transfer took place
      return true;
    } else {
      return false;
    }
  }

  function balanceOf(address _owner) constant returns(uint256 balance) {
    return balances[_owner];
  }

  /*TODO*/
  /*function destroy() onlyOwner {
    suicide(owner);
  }*/

  /* This unnamed function is called whenever someone tries to transfer ether to it */
  function () {
    throw;     // Prevents accidental sending of ether
  }
}


Remove Cost struct

Remove Cost struct

pragma solidity >=0.8.4;

import "./BaseRegistrarImplementation.sol";
import "./StringUtils.sol";
import "../resolvers/Resolver.sol";
import "../registry/ReverseRegistrar.sol";
import "../dnssec-oracle/BytesUtils.sol";
import "./IETHRegistrarController.sol";

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "../wrapper/INameWrapper.sol";

/**
 * @dev A registrar controller for registering and renewing names at fixed cost.
 */
contract ETHRegistrarController is Ownable, IETHRegistrarController {
    using StringUtils for *;
    using BytesUtils for bytes;

    uint256 public constant MIN_REGISTRATION_DURATION = 28 days;
    bytes32 private constant ETH_NODE =
        0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae;

    BaseRegistrarImplementation immutable base;
    PriceOracle public prices;
    uint256 public immutable minCommitmentAge;
    uint256 public immutable maxCommitmentAge;
    ReverseRegistrar public immutable reverseRegistrar;
    INameWrapper public immutable nameWrapper;

    mapping(bytes32 => uint256) public commitments;

    event NameRegistered(
        string name,
        bytes32 indexed label,
        address indexed owner,
        uint256 baseCost,
        uint256 premium,
        uint256 expires
    );
    event NameRenewed(
        string name,
        bytes32 indexed label,
        uint256 cost,
        uint256 expires
    );
    event NewPriceOracle(address indexed oracle);

    constructor(
        BaseRegistrarImplementation _base,
        PriceOracle _prices,
        uint256 _minCommitmentAge,
        uint256 _maxCommitmentAge,
        ReverseRegistrar _reverseRegistrar,
        INameWrapper _nameWrapper
    ) {
        require(_maxCommitmentAge > _minCommitmentAge);

        base = _base;
        prices = _prices;
        minCommitmentAge = _minCommitmentAge;
        maxCommitmentAge = _maxCommitmentAge;
        reverseRegistrar = _reverseRegistrar;
        nameWrapper = _nameWrapper;
    }

    function rentPrice(string memory name, uint256 duration)
        public
        view
        override
        returns (uint256 basePrice, uint256 premiumPrice)
    {
        bytes32 hash = keccak256(bytes(name));
        (basePrice, premiumPrice) = prices.price(
            name,
            base.nameExpires(uint256(hash)),
            duration
        );
    }

    function valid(string memory name) public pure returns (bool) {
        return name.strlen() >= 3;
    }

    function available(string memory name) public view override returns (bool) {
        bytes32 label = keccak256(bytes(name));
        return valid(name) && base.available(uint256(label));
    }

    function makeCommitment(
        string memory name,
        address owner,
        bytes32 secret,
        address resolver,
        bytes[] calldata data,
        bool reverseRecord,
        uint96 fuses
    ) public pure override returns (bytes32) {
        bytes32 label = keccak256(bytes(name));
        return
            keccak256(
                abi.encode(
                    label,
                    owner,
                    resolver,
                    data,
                    secret,
                    reverseRecord,
                    fuses
                )
            );
    }

    function commit(bytes32 commitment) public override {
        require(commitments[commitment] + maxCommitmentAge < block.timestamp);
        commitments[commitment] = block.timestamp;
    }

    function register(
        string calldata name,
        address owner,
        bytes32 secret,
        address resolver,
        bytes[] calldata data,
        bool reverseRecord,
        uint96 fuses
    ) public payable override {
        bytes32 label = keccak256(bytes(name));
        (uint256 duration, uint256 premiumCost) = prices.duration(
            name,
            base.nameExpires(uint256(label)),
            msg.value
        );
        _consumeCommitment(
            name,
            duration,
            makeCommitment(
                name,
                owner,
                secret,
                resolver,
                data,
                reverseRecord,
                fuses
            )
        );

        uint256 expires = nameWrapper.registerAndWrapETH2LD(
            name,
            owner,
            duration,
            resolver,
            fuses
        );

        if (data.length > 0) {
            require(
                resolver != address(0),
                "ETHRegistrarController: resolver is required when data is supplied"
            );
            _setRecords(resolver, label, data);
        }

        if (reverseRecord) {
            _setReverseRecord(name, resolver, msg.sender);
        }

        emit NameRegistered(
            name,
            label,
            owner,
            msg.value - premiumCost,
            premiumCost,
            expires
        );
    }

    function renew(string calldata name) external payable override {
        bytes32 label = keccak256(bytes(name));
        (uint256 duration, ) = prices.duration(
            name,
            base.nameExpires(uint256(label)),
            msg.value
        );

        uint256 expires = base.renew(uint256(label), duration);

        emit NameRenewed(name, label, msg.value, expires);
    }

    function setPriceOracle(PriceOracle _prices) public onlyOwner {
        prices = _prices;
        emit NewPriceOracle(address(prices));
    }

    function withdraw() public {
        payable(owner()).transfer(address(this).balance);
    }

    function supportsInterface(bytes4 interfaceID)
        external
        pure
        returns (bool)
    {
        return
            interfaceID == type(IERC165).interfaceId ||
            interfaceID == type(IETHRegistrarController).interfaceId;
    }

    /* Internal functions */

    function _consumeCommitment(
        string memory name,
        uint256 duration,
        bytes32 commitment
    ) internal {
        // Require a valid commitment
        require(commitments[commitment] + minCommitmentAge <= block.timestamp);

        // If the commitment is too old, or the name is registered, stop
        require(commitments[commitment] + maxCommitmentAge > block.timestamp);
        require(available(name));

        delete (commitments[commitment]);

        require(duration >= MIN_REGISTRATION_DURATION);
    }

    function _setRecords(
        address resolver,
        bytes32 label,
        bytes[] calldata data
    ) internal {
        // use hardcoded .eth namehash
        bytes32 nodehash = keccak256(abi.encodePacked(ETH_NODE, label));
        for (uint256 i = 0; i < data.length; i++) {
            // check first few bytes are namehash
            bytes32 txNamehash = data[i].readBytes32(4);
            require(
                txNamehash == nodehash,
                "ETHRegistrarController: Namehash on record do not match the name being registered"
            );
            (bool success, ) = address(resolver).call(data[i]);
            require(success, "ETHRegistrarController: Failed to set Record");
        }
    }

    function _setReverseRecord(
        string calldata name,
        address resolver,
        address owner
    ) internal {
        reverseRegistrar.setNameForAddr(
            msg.sender,
            msg.sender,
            resolver,
            string(abi.encodePacked(name, ".eth"))
        );
    }
}

pragma solidity >=0.8.4;

import "./BaseRegistrarImplementation.sol";
import "./StringUtils.sol";
import "../resolvers/Resolver.sol";
import "../registry/ReverseRegistrar.sol";
import "../dnssec-oracle/BytesUtils.sol";
import "./IETHRegistrarController.sol";

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "../wrapper/INameWrapper.sol";

struct Cost {
    uint256 base;
    uint256 premium;
}

/**
 * @dev A registrar controller for registering and renewing names at fixed cost.
 */
contract ETHRegistrarController is Ownable, IETHRegistrarController {
    using StringUtils for *;
    using BytesUtils for bytes;

    uint256 public constant MIN_REGISTRATION_DURATION = 28 days;
    bytes32 private constant ETH_NODE =
        0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae;

    BaseRegistrarImplementation immutable base;
    PriceOracle public prices;
    uint256 public immutable minCommitmentAge;
    uint256 public immutable maxCommitmentAge;
    ReverseRegistrar public immutable reverseRegistrar;
    INameWrapper public immutable nameWrapper;

    mapping(bytes32 => uint256) public commitments;

    event NameRegistered(
        string name,
        bytes32 indexed label,
        address indexed owner,
        uint256 baseCost,
        uint256 premium,
        uint256 expires
    );
    event NameRenewed(
        string name,
        bytes32 indexed label,
        uint256 cost,
        uint256 expires
    );
    event NewPriceOracle(address indexed oracle);

    constructor(
        BaseRegistrarImplementation _base,
        PriceOracle _prices,
        uint256 _minCommitmentAge,
        uint256 _maxCommitmentAge,
        ReverseRegistrar _reverseRegistrar,
        INameWrapper _nameWrapper
    ) {
        require(_maxCommitmentAge > _minCommitmentAge);

        base = _base;
        prices = _prices;
        minCommitmentAge = _minCommitmentAge;
        maxCommitmentAge = _maxCommitmentAge;
        reverseRegistrar = _reverseRegistrar;
        nameWrapper = _nameWrapper;
    }

    function rentPrice(string memory name, uint256 duration)
        public
        view
        override
        returns (uint256 basePrice, uint256 premiumPrice)
    {
        bytes32 hash = keccak256(bytes(name));
        (basePrice, premiumPrice) = prices.price(
            name,
            base.nameExpires(uint256(hash)),
            duration
        );
    }

    function valid(string memory name) public pure returns (bool) {
        return name.strlen() >= 3;
    }

    function available(string memory name) public view override returns (bool) {
        bytes32 label = keccak256(bytes(name));
        return valid(name) && base.available(uint256(label));
    }

    function makeCommitment(
        string memory name,
        address owner,
        bytes32 secret,
        address resolver,
        bytes[] calldata data,
        bool reverseRecord,
        uint96 fuses
    ) public pure override returns (bytes32) {
        bytes32 label = keccak256(bytes(name));
        return
            keccak256(
                abi.encode(
                    label,
                    owner,
                    resolver,
                    data,
                    secret,
                    reverseRecord,
                    fuses
                )
            );
    }

    function commit(bytes32 commitment) public override {
        require(commitments[commitment] + maxCommitmentAge < block.timestamp);
        commitments[commitment] = block.timestamp;
    }

    function register(
        string calldata name,
        address owner,
        bytes32 secret,
        address resolver,
        bytes[] calldata data,
        bool reverseRecord,
        uint96 fuses
    ) public payable override {
        bytes32 label = keccak256(bytes(name));
        (uint256 duration, uint256 premiumCost) = prices.duration(
            name,
            base.nameExpires(uint256(label)),
            msg.value
        );
        _consumeCommitment(
            name,
            duration,
            makeCommitment(
                name,
                owner,
                secret,
                resolver,
                data,
                reverseRecord,
                fuses
            )
        );

        uint256 expires = nameWrapper.registerAndWrapETH2LD(
            name,
            owner,
            duration,
            resolver,
            fuses
        );

        if (data.length > 0) {
            require(
                resolver != address(0),
                "ETHRegistrarController: resolver is required when data is supplied"
            );
            _setRecords(resolver, label, data);
        }

        if (reverseRecord) {
            _setReverseRecord(name, resolver, msg.sender);
        }

        emit NameRegistered(
            name,
            label,
            owner,
            msg.value - premiumCost,
            premiumCost,
            expires
        );
    }

    function renew(string calldata name) external payable override {
        bytes32 label = keccak256(bytes(name));
        (uint256 duration, ) = prices.duration(
            name,
            base.nameExpires(uint256(label)),
            msg.value
        );

        uint256 expires = base.renew(uint256(label), duration);

        emit NameRenewed(name, label, msg.value, expires);
    }

    function setPriceOracle(PriceOracle _prices) public onlyOwner {
        prices = _prices;
        emit NewPriceOracle(address(prices));
    }

    function withdraw() public {
        payable(owner()).transfer(address(this).balance);
    }

    function supportsInterface(bytes4 interfaceID)
        external
        pure
        returns (bool)
    {
        return
            interfaceID == type(IERC165).interfaceId ||
            interfaceID == type(IETHRegistrarController).interfaceId;
    }

    /* Internal functions */

    function _consumeCommitment(
        string memory name,
        uint256 duration,
        bytes32 commitment
    ) internal {
        // Require a valid commitment
        require(commitments[commitment] + minCommitmentAge <= block.timestamp);

        // If the commitment is too old, or the name is registered, stop
        require(commitments[commitment] + maxCommitmentAge > block.timestamp);
        require(available(name));

        delete (commitments[commitment]);

        require(duration >= MIN_REGISTRATION_DURATION);
    }

    function _setRecords(
        address resolver,
        bytes32 label,
        bytes[] calldata data
    ) internal {
        // use hardcoded .eth namehash
        bytes32 nodehash = keccak256(abi.encodePacked(ETH_NODE, label));
        for (uint256 i = 0; i < data.length; i++) {
            // check first few bytes are namehash
            bytes32 txNamehash = data[i].readBytes32(4);
            require(
                txNamehash == nodehash,
                "ETHRegistrarController: Namehash on record do not match the name being registered"
            );
            (bool success, ) = address(resolver).call(data[i]);
            require(success, "ETHRegistrarController: Failed to set Record");
        }
    }

    function _setReverseRecord(
        string calldata name,
        address resolver,
        address owner
    ) internal {
        reverseRegistrar.setNameForAddr(
            msg.sender,
            msg.sender,
            resolver,
            string(abi.encodePacked(name, ".eth"))
        );
    }
}


Tiny indentation fix in MintedCrowdsale (#792)

Tiny indentation fix in MintedCrowdsale

pragma solidity ^0.4.18;

import "../Crowdsale.sol";
import "../../token/ERC20/MintableToken.sol";

/**
 * @title MintedCrowdsale
 * @dev Extension of Crowdsale contract whose tokens are minted in each purchase.
 * Token ownership should be transferred to MintedCrowdsale for minting.
 */
contract MintedCrowdsale is Crowdsale {

  /**
   * @dev Overrides delivery by minting tokens upon purchase.
   * @param _beneficiary Token purchaser
   * @param _tokenAmount Number of tokens to be minted
   */
  function _deliverTokens(address _beneficiary, uint256 _tokenAmount) internal {
    require(MintableToken(token).mint(_beneficiary, _tokenAmount));
  }
}


Adding a new StackExchange answer

Adding a new StackExchange answer

pragma solidity ^0.4.0;

// Contract used to answer https://ethereum.stackexchange.com/questions/42207/solidity-deleting-a-struct-from-a-storage-array
contract Lockers {
    struct Locker {
        uint creationTime;
        uint holdTime;
        uint balance;
    }

    mapping (address => Locker[]) lockersByAddress;

    event Withdrawal(address sender, uint balance);

    function store(uint holdTime) external payable {
        Locker memory locker = Locker(now, holdTime, msg.value);
        lockersByAddress[msg.sender].push(locker);
    }

    // Original function
    function withdrawAll() public {
        Locker[] storage lockers = lockersByAddress[msg.sender];
        for (uint i = 0; i < lockers.length; i++) {
            if (lockers[i].creationTime + lockers[i].holdTime < now) {
                msg.sender.transfer(lockers[i].balance);
                Withdrawal(msg.sender, lockers[i].balance);
                delete lockers[i];
            }
        }
    }

    // Modified function that demonstrates how to clear an array
    // Note: withdrawAll is a misnomer and no effort was made to deal with demonstrating how to deal with the edge case of a "locker" not being able to be deleted.
    function withdrawAll2() public {
        Locker[] memory memLockers = lockersByAddress[msg.sender];
        // Avoid any re-entrancy issues
        delete lockersByAddress[msg.sender];
        for (uint i = 0; i < memLockers.length; i++) {
            if (memLockers[i].creationTime + memLockers[i].holdTime < now) {
                msg.sender.transfer(memLockers[i].balance);
                Withdrawal(msg.sender, memLockers[i].balance);
            }
        }
    }

    function getNumLockers(address owner) external view returns(uint) {
        return lockersByAddress[owner].length;
    }

    function getLockerDetails(address owner, uint index) external view returns(uint creationTime, uint holdTime, uint balance) {
        Locker memory locker = lockersByAddress[owner][index];
        creationTime = locker.creationTime;
        holdTime = locker.holdTime;
        balance = locker.balance;
    }
}

error: pathspec 'contracts/stackexchange/Lockers.sol' did not match any file(s) known to git