簡體   English   中英

如何獲取彩票智能合約的中獎者地址

[英]How can get winner address of lottery smart contract

你好 Solidity 開發人員,我是這種語言的新手。 我想在抽獎獲勝者 function 之后獲得獲勝者地址。 這是繪制 function


function draw_daily(uint256 _randomness) public payable onlyOwner returns(address){
        require(Daily.time_end < block.timestamp, 'Draw period not over');
        uint256 index = generate_random(_randomness, (Daily.participants.length));
        uint256 prize = Daily.total_amount - ((Daily.total_amount * Daily.owner_share)/100);
        address lucky_winner = Daily.participants[index];
        Daily.total_amount = 0;
        delete Daily.participants;
        return lucky_winner;
    }
    

這里lucky_winner 是獲勝者地址,如果我想得到lucky_winner 的地址,我該怎么辦? 我需要先聲明全局變量luck_winner 嗎? 接着

function get_daily_winner() public view returns(address[] memory){
        return Daily.lucky_winner;
    }

它可以工作嗎?

這是全局變量


 address owner;
    
    struct lottery_draw{
        uint256 price;
        uint256 time_start;
        uint256 time_end;
        address[] participants;
       
        uint256 total_amount;
        uint256 owner_share;

         address lucky_winner 

    }
    
    lottery_draw Daily; 
    lottery_draw Weekly; 
    lottery_draw Monthly; 

請有人指導我。 如何正確地做到這一點。

是的,您應該使用全局變量 go 並將其存儲在“draw_daily”中

所以在方法中而不是

address lucky_winner = Daily.participants[index];

你應該只使用全局變量:

lucky_winner = Daily.participants[index];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM