Solidity

之前是否從特定地址呼叫了該函式?

  • June 13, 2020

考慮如下函式定義 -

function checkForUpvote() external returns(bool){

在這裡,我首先想檢查一下,呼叫此函式的外部帳戶是否:以前呼叫過此函式?. 如果是,退出。否則繼續。

// ......
// ......<function definition follows>
}

**問題:**如何檢查 checkForUpvote() 僅由一個帳戶呼叫一次。?

mapping (address => bool) private hasUpvoted;

function checkForUpvote() external returns(bool) {
   require(!hasUpvoted[msg.sender], 'You already upvoted');

   [... do stuff]

   hasUpvoted[msg.sender] = true;
}

引用自:https://ethereum.stackexchange.com/questions/84122