Jim's
Tutorials

Spring 2019
course
site

This is a more complicated contract utilizing structs and mappings. Mappings are an interestingly limited version of a dictionary that doesn't store keys, but efficiently lets you look up values for a given key.

pragma solidity ^0.4.17;

contract Campaign {
    struct Request {
        string description;
        uint value;
        address recipient;
        bool complete;
        uint approvalCount;
        mapping(address => bool) approvals;
    }

    Request[] public requests;
    address public manager;
    uint public minimumContribution;
    mapping(address => bool) public approvers;

    modifier restricted (){
        require(msg.sender == manager);
        _;
    }

    function Campaign(uint minimum) public {
        manager = msg.sender;
        minimumContribution = minimum;
    }

    function contribute() public payable {
        require(msg.value > minimumContribution);

        approvers[msg.sender] = true;
    }

    function createRequest(string description, uint value, address recipient)
        public restricted{
        Request memory newRequest = Request({
            description: description,
            value: value,
            recipient: recipient,
            complete: false
        });
        requests.push(newRequest);
    }
}
https://cs.marlboro.college /cours /spring2019 /jims_tutorials /nweeks /mock-kickstarter
last modified Mon November 25 2024 10:26 am