화이트리스트 구현 #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

 


WRITTEN BY
SIDNFT
게임개발자에서 WEBGL 웹개발자로 전환중

,




영상링크: https://www.youtube.com/watch?v=cWM3704pUns

mapping 을 사용했습니다.

단순한 형태로 작성한거구요

솔리디티 코드:

// SPDX-License-Identifier: GPL-3.0
// 0x281725fc1AD9AEDeFb8ADb1f4572E97CA918ED00

pragma solidity >=0.7.0 <0.9.0;

contract Storage {

    mapping(address => uint) private map_addr;
    bool use_whitelist = true;
    uint count = 0;
    
    constructor() {
        address a = 0x1e0A33d97f7793035704F5B0d896c631fb47BbE4;
        add_whitelist(a);
    }

    function is_whitelist(address addr) public view returns(uint) {
        return map_addr[addr];
    }

    function is_whitelist_2() public view returns(uint) {
        return map_addr[msg.sender];
    }

    function add_whitelist(address a) public {
        require(map_addr[a] == 0);

        map_addr[a] = 1;
    }
    
    function del_whitelist(address a) public {
        require(map_addr[a] != 0);

        // map_data[a] = 0;
        delete map_addr[a];
    }

    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);
    }
}

WRITTEN BY
SIDNFT
게임개발자에서 WEBGL 웹개발자로 전환중

,




이 기능은 이벤트 모니터 라고도 부르고 이벤트 감시기 라고도 부릅니다.
영어로는 watch 나 monitor 라고 부르더군요.

영상주소: https://www.youtube.com/watch?v=HxGpjz9LCc8
소스코드: 
https://github.com/GoToTheMetaverse/klay-tutorial-v2/tree/main klaytn-08-event-monitor 폴더입니다.

이벤트 모니터가 있어야 좀더 괜찮은 서비스를 만들수 있습니다.
스마트컨트렉트는 수정이 안되기 때문에 어려운 기능을 구현하다가 버그라도 생기면 리스크가 크기 때문에 적당히 쉬운 기능을 구현하고 이벤트를 이용해서 외부에서 어려운 기능을 구현하는 편이 수정이 용이 합니다.

이 소스는contract.getPastEvents() 를 활용합니다.
 
contract.events.allEvents() 를 이용하는 코드는 제대로 동작이 안되서 생략했습니다.
참고해주세요

 

디스코드봇과 연동했습니다. 디스코트로와서 구경해보세요

가위바위보 게임 페이지: https://klaytngame-1.gunillee.repl.co/
디스코드 초대링크: https://discord.gg/7REtkPHHJX

 

Join the SIDNFT Discord Server!

Check out the SIDNFT community on Discord - hang out with 10 other members and enjoy free voice and text chat.

discord.com

결과 스샷:

 

추후 개발 예정:
1. 전적관리
2. 웹페이지에 실시간 내역 추가
3. 차트나 그래프 추가

의견있으시면 디스코드로와서 이야기해주세요


WRITTEN BY
SIDNFT
게임개발자에서 WEBGL 웹개발자로 전환중

,