<commit_before>// Crowdfunding System
// Start, donate, payout and refund crowdfunding campaigns
// @authors:
// <NAME> <<EMAIL>>
// If goal is not reached and campaign is expired, contributers can get their donation refunded individually
// If goal is reached by alloted time, contributions can still be made

// With config.

contract CrowdFundrrConfig { function onContribute(uint cid, address addr, uint amount){} }
contract CrowdFundrr
{
    struct User
    {
        uint numCampaigns;
        mapping(uint => uint) campaigns;
    }
    
    struct Funder 
    {
        address addr;
        uint amount;
    }
    
    struct Campaign 
    {
        bytes32 name;
        bytes32 website;
        address owner;
        address beneficiary;
        address config; // ADDRESS TO CONFIG
        uint timelimit;
        uint fundingGoal;
        uint amount;
        uint category;
        uint status;
        uint numFunders;
        mapping (uint => Funder) funders;
        mapping (address => uint) toFunder;
    }
  
    uint public numCampaigns;
    mapping (uint => Campaign) public campaigns;
    mapping (address => User) public users;
    
    modifier hasValue { if(msg.value > 0) _ }
    
    function newCampaign(bytes32 name, bytes32 website
    , address beneficiary, uint goal, uint timelimit, uint category, address config)
    {
        if(goal > 0 && timelimit > block.timestamp){
            uint cid = numCampaigns++; // campaignID is return variable
            Campaign c = campaigns[cid];  // assigns reference
            c.name = name;
            c.owner = msg.sender;
            c.website = website;
            c.beneficiary = beneficiary;
            c.fundingGoal = goal;
            c.timelimit = timelimit;
            c.category = category;
            c.config = config;
            
            User u = users[msg.sender];
            uint u_cid = u.numCampaigns++;
            u.campaigns[u_cid] = cid;
        }
    }
    
    function contribute(uint cid) hasValue
    {
        Campaign c = campaigns[cid]; // Cannot be expired.
        if(c.timelimit >= block.timestamp){
            uint fid = c.numFunders++;
            Funder f = c.funders[fid];
            f.addr = msg.sender;
            f.amount = msg.value;
            c.amount += f.amount;
            c.toFunder[msg.sender] = fid;
            
            if(c.config != 0){
                CrowdFundrrConfig(c.config).onContribute(cid, msg.sender, msg.value);
            }
        }
    }
    
    function refund(uint cid)
    {
        Campaign c = campaigns[cid];
        if (block.timestamp > c.timelimit 
        && c.amount < c.fundingGoal && c.amount > 0){
            Funder f = c.funders[c.toFunder[msg.sender]];
            if(f.amount > 0){
                f.addr.send(f.amount);
                c.amount -= f.amount;
                f.amount = 0;
            }
        }
    }
  
    function payout(uint cid)
    {
        Campaign c = campaigns[cid];
        if (c.amount >= c.fundingGoal){
            c.beneficiary.send(c.amount);
            c.amount = 0;
            c.status = 1;
        }
    }
    
    function userCampaigns(address addr, uint u_cid) returns (uint _cid)
    {
        User u = users[addr];
        _cid = u.campaigns[u_cid];
    }<commit_msg>Update CrowdFundrrConfig.sol<commit_after>// Crowdfunding System
// Start, donate, payout and refund crowdfunding campaigns
// @authors:
// <NAME> <<EMAIL>>
// If goal is not reached and campaign is expired, contributers can get their donation refunded individually
// If goal is reached by alloted time, contributions can still be made

// With config.
// The config will allow the CrowdFundrr contract to morph
// This allows the campaign owners to connect anything from token systems
// to shares or what ever contract they want.
contract CrowdFundrrConfig 
{ 
    function onContribute(uint cid, address addr, uint amount){} 
    function onRefund(uint cid, address addr, uint amount){} 
    function onPayout(uint cid, uint amount){}
}

contract CrowdFundrr
{
    struct User
    {
        uint numCampaigns;
        mapping(uint => uint) campaigns;
    }
    
    struct Funder 
    {
        address addr;
        uint amount;
    }
    
    struct Campaign 
    {
        bytes32 name;
        bytes32 website;
        address owner;
        address beneficiary;
        address config; // ADDRESS TO CONFIG
        uint timelimit;
        uint fundingGoal;
        uint amount;
        uint category;
        uint status;
        uint numFunders;
        mapping (uint => Funder) funders;
        mapping (address => uint) toFunder;
    }
  
    uint public numCampaigns;
    mapping (uint => Campaign) public campaigns;
    mapping (address => User) public users;
    
    modifier hasValue { if(msg.value > 0) _ }
    
    function newCampaign(bytes32 name, bytes32 website
    , address beneficiary, uint goal, uint timelimit, uint category, address config)
    {
        if(goal > 0 && timelimit > block.timestamp){
            uint cid = numCampaigns++; // campaignID is return variable
            Campaign c = campaigns[cid];  // assigns reference
            c.name = name;
            c.owner = msg.sender;
            c.website = website;
            c.beneficiary = beneficiary;
            c.fundingGoal = goal;
            c.timelimit = timelimit;
            c.category = category;
            c.config = config; // config address setting
            
            User u = users[msg.sender];
            uint u_cid = u.numCampaigns++;
            u.campaigns[u_cid] = cid;
        }
    }
    
    function contribute(uint cid) hasValue
    {
        Campaign c = campaigns[cid]; // Cannot be expired.
        if(c.timelimit >= block.timestamp){
            uint fid = c.numFunders++;
            Funder f = c.funders[fid];
            f.addr = msg.sender;
            f.amount = msg.value;
            c.amount += f.amount;
            c.toFunder[msg.sender] = fid;
            
            // A certain amount could be taken as a fee if config is set for
            // sending the transaction.
            // Call custom contract set by campaign owner
            if(c.config != 0) // if config address exists
                CrowdFundrrConfig(c.config).onContribute(cid, msg.sender, msg.value);
        }
    }
    
    function refund(uint cid)
    {
        Campaign c = campaigns[cid];
        if (block.timestamp > c.timelimit 
        && c.amount < c.fundingGoal && c.amount > 0){
            Funder f = c.funders[c.toFunder[msg.sender]];
            if(f.amount > 0){
                f.addr.send(f.amount);
                c.amount -= f.amount;
                f.amount = 0;
                if(c.config != 0) // if config address exists
                    CrowdFundrrConfig(c.config).onRefund(cid, f.addr, f.amount);
            }
        }
    }
  
    function payout(uint cid)
    {
        Campaign c = campaigns[cid];
        if (c.amount >= c.fundingGoal){
            c.beneficiary.send(c.amount);
            c.amount = 0;
            c.status = 1;
            if(c.config != 0) // if config address exists
                CrowdFundrrConfig(c.config).onPayout(cid, c.amount);
        }
    }
    
    function userCampaigns(address addr, uint u_cid) returns (uint _cid)
    {
        User u = users[addr];
        _cid = u.campaigns[u_cid];
    }
{'fraction_non_alphanumeric': 0.0969926849092387, 'fraction_numerical': 0.004605797886751558, 'mean_word_length': 1.7093577981651376, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '221642', 'n_tokens_mistral': 2202, 'n_tokens_neox': 2138, 'n_words': 601}