-
지갑 주소로 화이트리스 구현 #2프로그래밍/강좌 2022. 6. 27. 12:44728x90반응형
화이트리스트 구현 #1 : https://serverdown.tistory.com/537
영상링크: https://youtu.be/jEpKPYbctlg
mapping 과 배열을 이용한 자료구조를 설명하려고 예를 든것일뿐
이렇게 복잡하게 구현할 필요는 굳이 없을것 같습니다.소스코드 입니다.
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; contract Storage { uint public count = 0; mapping(address => uint) private map_addr; address[] list_addr; bool use_whitelist = true; constructor() { address a = 0x1e0A33d97f7793035704F5B0d896c631fb47BbE4; // map_addr[a] = 1; add_whitelist(a); } function is_whitelist(address addr) public view returns(uint) { return map_addr[addr]; } function get_whitelist_by_no(uint no) public view returns(address) { return list_addr[no-1]; } function get_whitelist_by_addr(address a) public view returns(uint) { return map_addr[a]; } function is_whitelist_2() public view returns(uint) { return map_addr[msg.sender]; } function add_whitelist(address a) public { require(map_addr[a] == 0); list_addr.push(a); uint no = list_addr.length; map_addr[a] = no; } function del_whitelist(address a) public { require(map_addr[a] != 0); uint no = map_addr[a]; uint index = no - 1; uint last_no = list_addr.length; uint last_index = last_no - 1; address last_a = list_addr[last_index]; list_addr[index] = last_a; list_addr.pop(); delete map_addr[a]; // map_addr[a] = 0; if(index == last_index) { return; } map_addr[last_a] = no; } function set_use_whitelist(bool b) public { use_whitelist = b; } function mint_a() public { if(use_whitelist) { require(is_whitelist_2() != 0); } count++; // _mint(no, link); } }화이트리스트를 추가 / 삭제할때마다 이벤트를 남기면 스마트컨트랙트를 굳지 조회할 필요없이
이벤트로그를 모아 보면 현재 화이트리스트에 무엇이 저장되어있는지 알 수 있습니다.
이벤트 구현은 이 부분을 참고해주세요이벤트 구현 참고자료: https://serverdown.tistory.com/498
코딩자습서/019 스마트컨트렉트 이벤트 모니터 만들어봅시다. / caver-js
이 기능은 이벤트 모니터 라고도 부르고 이벤트 감시기 라고도 부릅니다. 영어로는 watch 나 monitor 라고 부르더군요. 영상주소: https://www.youtube.com/watch?v=HxGpjz9LCc8 소스코드: https://github.com/Go..
serverdown.tistory.com
반응형