Skip to content

Instantly share code, notes, and snippets.

@bear2u
Created February 12, 2018 13:50
Show Gist options
  • Save bear2u/7d42151c1a1126309d73669e0e6547a7 to your computer and use it in GitHub Desktop.
Save bear2u/7d42151c1a1126309d73669e0e6547a7 to your computer and use it in GitHub Desktop.
QuickStart 솔리디티 예제 연습 코드 #1
pragma solidity ^0.4.17;
contract Compaign {
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;
uint public approversCount;
modifier restricted() {
require(msg.sender == manager);
_;
}
function Compaign(uint minimum) public {
manager = msg.sender;
minimumContribution = minimum;
}
function contribute() public payable {
require(msg.value > minimumContribution);
approvers[msg.sender] = true;
approversCount++;
}
function createRequest(string description, uint value, address recipient)
public restricted
{
require(approvers[msg.sender]);
Request memory newRequest = Request({
description: description,
value: value,
recipient: recipient,
complete: false,
approvalCount: 0
});
requests.push(newRequest);
}
function approveRequest(uint index) public {
Request storage request = requests[index];
require(approvers[msg.sender]);
require(!request.approvals[msg.sender]);
request.approvals[msg.sender] = true;
request.approvalCount++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment