114. Solving Real Problems with Contract
new project
; why we care about etherium & smart contracts at all
; where to use in new project
-> what the problem is with the startup & how we can apply blockchain technology
kickstarter = help you raise some money (크라우드 펀딩 주관해주는 사이트)
-> 여기서 문제는 ?
-> 크라우드 펀딩 받았지만 실제로는 프로젝트를 생산해낼 능력이 없음
=> sorry we ran out of money and we can't give you your product = 악의적인,,,
: kickstarter failures
-> how we can use an ethereum contract to at least somewhat solve the issue at kickstarter
115. Fixing Kickstarter's Issue
what we want to happen

where this money(= 크라우드 펀딩 받은 돈) goes?

spending 요청을 보낼 때마다 펀딩해주는 모든 사람이 투표에 참여하면 어떨까?
-> contributors have the idea of where their money is being sent to and they have the ability to review these spending requests
116. Campaign Contract Design

118. Campaign Constructor

119. Contributing to the Campaign - 121. The Request Struct

122. More on Function Modifiers - 123. Creating Struct Instances
pragma solidity ^0.4.17;
contract Campaign{
struct Request { //creates the type
string description;
uint value;
address recipient;
bool complete;
}
Request[] public requests;
address public manager; //handling Manager
uint public minimumContribution;
address[] 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); //min보다 value 값이 작으면 에러
approvers.push(msg.sender);
}
function createRequest(string description, uint value, address recipient)
public restricted{
Request newRequset = Request({
description: description,
value: value,
recipient: recipient,
complete: false
}); //create new request
requests.push(newRequset);
}
}
124. Instance Creation Syntax

125. Storage and Memory

126. More on Storage vs Memory
how our solidity variables reference values
*storage keyword
127. Voting System Requirements
128. The Wrong Voting System
* wrong way -> 이렇게 하지 말라고 알려주는 것임
<implementing approval request>
1. 그 사람이 우리 캠페인에 돈을 냈는지 먼저 살펴보기
1-1. 돈 안냈으면 투표 못하게.
2. 이미 투표했으면 중복 투표 못하게.
-> poor way
129. Issues with Arrays
assume 1.



many thousands of people voting-> 1000 loop * thousands
=> total 100,015,000 gas
(-) spend a tremendous amount of money in order to call that approve request function
= 이게 poor approach 인 이유
130. Mapping vs Arrays
mapping = reference type that is availoable to us inside of solidity
= collection of key value pairs
어떻게 맵핑으로 위의 문제를 해결하는가

131. Basics of Mapping - 142. Testing the factory
* keys are not stored with mappings

someone's address - mapping
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,
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++;
}
}
require(approvers[msg.sender]);
-> one simple little block to do the entirely same exact thing : 문제 해결 방법!
* approvals = track whoever has voted on a given request
'PBL Ⅲ > Ethereum and Solidity' 카테고리의 다른 글
Section7 : Advanced Multi-Page Front-Ends (1) (0) | 2022.09.14 |
---|---|
Section6 : Ethereum Project Infrastructure (0) | 2022.09.09 |
Section4 : Building Interative Front-Ends (0) | 2022.08.28 |
Section3 : Advanced SmartContracts (0) | 2022.08.21 |
Section2 : Smartcontracts with solidity (0) | 2022.08.16 |