Solidity를 공부 할 때 제가 참고하는 것은 크게 [공식 Document](https://solidity.readthedocs.io/en/develop/) 와 [State of the DAPPs](https://dapps.ethercasts.com/), ICO들의 소스 입니다. 공식문서는 Solidity의 기본부터 심화까지 모든 것을 담고 있고, State of the dapps 의 경우 현재 진행되고 있는 거의 모든 dapp들을 볼수 있고, 해당 소스도 참고하면서 공부도 해볼수 있습니다. ICO 들의 소스의 경우 ERC20 토큰의 제일 충분한 예시입니다. 그리고 해당 소스들을 보면 특이한 점들이 있습니다. ``` pragma solidity 0.4.11; import "TokenFactory.sol" contract CrowdSaleSample { TokenFactory public token; mapping (address => uint256) balances; address public owner; modifier onlyOwner { require(msg.sender == owner); _; } function FLToken(){ owner = msg.sender; } function() payable { if (now > endBlock) throw; token.distribute(msg.sender); } function distribute(address depositor) onlyOwner { balances[depositor] += 100; } ``` 매우 간단한 소스이고, `function` 이라는 것은 어느 언어에서든지 있는 개념입니다. 하지만 `modifier` 라는 것은 조금 생소했고, function 뒤에 리턴값이 아닌 것이 위치해있습니다. 그래서 Document 에서 해당 사항을 찾아봤습니다. ``` Function Modifiers Modifiers can be used to easily change the behaviour of functions. For example, they can automatically check a condition prior to executing the function. Modifiers are inheritable properties of contracts and may be overridden by derived contracts. -> modifier 는 function의 실행(행동)을 쉽게 변경가능하도록하며, function 실행의 조건을 체크 할수 있다 ``` 위에 예제에서 modifier 는 한번은 정의, 그리고 또 한번은 function 뒤에 두번 적혀있습니다. 간단하게 본다면 `distribute` function 을 실행하기 전에 `onlyOwner` 라는 것을 미리 체크를 해보다는 겁니다. ``` modifier onlyOwner { // msg.sender(실행하려는 Address)와 owner(Contract 를 생성한 Address) 같아야 합니다. require(msg.sender == owner); _; } ``` `Rails` 에서는 [BeforeFilter](https://apidock.com/rails/ActionController/Filters/ClassMethods/before_filter) 라는 개념이 있습니다. 저는 이것과 비슷한 개념이라고 이해를 했습니다. 함수를 실행하기 전에 미리 필터링을 시켜준다는 개념(?)(저만의 정의입니다.) 그러면 다양하게 적용을 할수 있을 겁니다. ``` modifier startCheck { require(block.number >= startBlock); _; } modifier onlyOwner { require(msg.sender == owner); _; } modifier crowdEndingCheck { require(!isCrwoldEnding); _; } ``` 등등등 중복적으로 실행이 필요하지만 간단하다면 modifier 로 정의해서 사용해보면 될겁니다. # 그리고 `payable` [Reddit](https://www.reddit.com/r/ethereum/comments/4yciyz/upcoming_changes_in_solidity_040/) 과[ 공식 문서](http://solidity.readthedocs.io/en/develop/contracts.html)에서 보면 payable 에 대한 설명이 나옵니다. ``` // Reddit functions reject ether by default and require the new "payable" modifier if they want to accept it // Solidity Document It is important to also provide the "payable" keyword here, otherwise the function will automatically reject all Ether sent to it. ``` Default 로 모든 function 에서는 이더 전송에 관한 모든 것을 Reject 시키며, `payable(아마도 내장 modifier 인 것 같네요)` 가 붙지 않으면 모든 전송을 자동으로 Reject 시킨다. 이더 전송에 관련된 function 이라면 무조건 붙여야지만 전송이 가능하도록 해놓은 거 같네요. modifier 와 payable.. 둘 다 생소했지만 Solidity에서는 매우 필요한 요소 인듯 싶네요. --- 잘못된 부분은 댓글로 남겨주시면 수정하도록 하겠습니다. --- # Donation 기부는 사랑입니다. - Ƀ BTC : 16MdVNJgvGYbVuaC6KrjGNy2RCrNsaPaZz - Ξ ETH : 0x5debb97a6Cc1Fdf686a3C6aA804a623a21deD73c 개발자에게 [Starize](https://github.com/ggomagundan/coinone) 도 사랑입니다.
author | kaipark |
---|---|
permlink | solidity-modifier-payable |
category | kr |
json_metadata | {"tags":["kr","coinkorea","solidity","ethereum","kr-dev"],"links":["https://solidity.readthedocs.io/en/develop/","https://dapps.ethercasts.com/","https://apidock.com/rails/ActionController/Filters/ClassMethods/before_filter","https://www.reddit.com/r/ethereum/comments/4yciyz/upcoming_changes_in_solidity_040/","http://solidity.readthedocs.io/en/develop/contracts.html","https://github.com/ggomagundan/coinone"],"app":"steemit/0.1","format":"markdown"} |
created | 2017-06-28 07:50:42 |
last_update | 2017-06-28 15:47:54 |
depth | 0 |
children | 6 |
last_payout | 2017-07-05 07:50:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 8.110 HBD |
curator_payout_value | 2.282 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 3,186 |
author_reputation | 848,534,820,110 |
root_title | "Solidity의 modifier 와 payable" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,446,043 |
net_rshares | 1,203,442,992,060 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
kdj | 0 | 426,502,574,329 | 50% | ||
ksc | 0 | 50,129,335,079 | 15% | ||
agile | 0 | 3,318,319,817 | 100% | ||
coinkorea | 0 | 650,199,755,585 | 5% | ||
jaiken | 0 | 20,890,552,222 | 56% | ||
kaipark | 0 | 7,911,859,602 | 100% | ||
leomichael | 0 | 29,192,359,356 | 13% | ||
digital-entrep | 0 | 5,442,603,942 | 100% | ||
bilalrahim | 0 | 142,908,200 | 100% | ||
virus707 | 0 | 9,712,723,928 | 1% |
개발 관련태그로 #kr-dev 를 추가해주시면 더 많은 분들이 보실 수 있을것 같습니다 :)
author | coinkorea |
---|---|
permlink | re-kaipark-solidity-modifier-payable-20170628t084459061z |
category | kr |
json_metadata | {"tags":["kr-dev","kr"],"app":"steemit/0.1"} |
created | 2017-06-28 08:44:57 |
last_update | 2017-06-28 08:44:57 |
depth | 1 |
children | 1 |
last_payout | 2017-07-05 08:44:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 51 |
author_reputation | 34,890,178,701,093 |
root_title | "Solidity의 modifier 와 payable" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,450,228 |
net_rshares | 0 |
새로운 태그 알려주셔서 감사합니다 ㅋㅋ
author | kaipark |
---|---|
permlink | re-coinkorea-re-kaipark-solidity-modifier-payable-20170628t155045809z |
category | kr |
json_metadata | {"tags":["kr"],"app":"steemit/0.1"} |
created | 2017-06-28 15:50:45 |
last_update | 2017-06-28 15:50:45 |
depth | 2 |
children | 0 |
last_payout | 2017-07-05 15:50:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 21 |
author_reputation | 848,534,820,110 |
root_title | "Solidity의 modifier 와 payable" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,493,956 |
net_rshares | 0 |
안녕하세요, 한국에서 일하시는 분인가요?? 저는 현재 뉴욕에서 블락체인 연구/컨설팅을 막 시작한 1인입니다. Solidity도 최근에 배워서 기본적인 건 어느 정도 마스터를 한 상태인데요, 한국 내에서는 Solidity나 블락체인에 대한 전반적인 관심이 어느 정도 있는 지 궁금하네요. 더 전반적으로는 가상화폐 모임이나 동호회 같은 구조들이 있나요??
author | ih5kevin |
---|---|
permlink | re-kaipark-solidity-modifier-payable-20171121t074048926z |
category | kr |
json_metadata | {"tags":["kr"],"app":"steemit/0.1"} |
created | 2017-11-21 07:41:03 |
last_update | 2017-11-21 07:41:03 |
depth | 1 |
children | 0 |
last_payout | 2017-11-28 07:41:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 196 |
author_reputation | 17,311,213,551 |
root_title | "Solidity의 modifier 와 payable" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 21,062,194 |
net_rshares | 0 |
환영합니다. 반갑습니다.
author | kdj |
---|---|
permlink | re-kaipark-solidity-modifier-payable-20170628t161357613z |
category | kr |
json_metadata | {"tags":["kr"],"app":"steemit/0.1"} |
created | 2017-06-28 16:14:00 |
last_update | 2017-06-28 16:14:00 |
depth | 1 |
children | 1 |
last_payout | 2017-07-05 16:14:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 13 |
author_reputation | 4,188,781,313,300 |
root_title | "Solidity의 modifier 와 payable" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,496,986 |
net_rshares | 0 |
@kdj 간간히 써내려가보게습니다 ^^
author | kaipark |
---|---|
permlink | re-kdj-re-kaipark-solidity-modifier-payable-20170629t015828269z |
category | kr |
json_metadata | {"tags":["kr"],"users":["kdj"],"app":"steemit/0.1"} |
created | 2017-06-29 01:58:27 |
last_update | 2017-06-29 01:58:27 |
depth | 2 |
children | 0 |
last_payout | 2017-07-06 01:58:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 21 |
author_reputation | 848,534,820,110 |
root_title | "Solidity의 modifier 와 payable" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 6,560,695 |
net_rshares | 0 |
Congratulations @kaipark! You have completed some achievement on Steemit and have been rewarded with new badge(s) : [](http://steemitboard.com/@kaipark) Award for the number of upvotes Click on any badge to view your own Board of Honor on SteemitBoard. For more information about SteemitBoard, click [here](https://steemit.com/@steemitboard) If you no longer want to receive notifications, reply to this comment with the word `STOP` > By upvoting this notification, you can help all Steemit users. Learn how [here](https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png)!
author | steemitboard |
---|---|
permlink | steemitboard-notify-kaipark-20171201t031402000z |
category | kr |
json_metadata | {"image":["https://steemitboard.com/img/notifications.png"]} |
created | 2017-12-01 03:14:00 |
last_update | 2017-12-01 03:14:00 |
depth | 1 |
children | 0 |
last_payout | 2017-12-08 03:14:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 684 |
author_reputation | 38,975,615,169,260 |
root_title | "Solidity의 modifier 와 payable" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 22,052,803 |
net_rshares | 0 |