Solidity

誰能幫我解決投注問題,一旦我投注了一場比賽,我就無法投注其他比賽

  • August 23, 2021

這是完整的智能合約:https ://github.com/laronlineworld/betMatch/blob/main/betMatch.sol

這是投注合約,投注id_1時,同一地址不能投注id_2。我正在使用遊戲儲存

function bet(uint _gameId, uint8 _teamSelected) public payable {
 Game storage game = gameInfo[_gameId];
 require(game.state == State.Created,"Game has not been created");
 require(bettingActive);
 //The first require is used to check if the player already exist
 require(!checkPlayerExists(msg.sender));
 //The second one is used to see if the value sended by the player is
 //Higher than the minimum value
 require(msg.value >= minimumBet);

 //We set the player informations : amount of the bet and selected team
 playerInfo[msg.sender].amountBet = msg.value;
 playerInfo[msg.sender].teamSelected = _teamSelected;

 //then we add the address of the player to the players array
 players.push(msg.sender);

 //at the end, we increment the stakes of the team selected with the player bet
 if ( _teamSelected == 1){
     totalBetsOne += msg.value;
 }
 else{
     totalBetsTwo += msg.value;
 }
}

也許您應該嘗試選擇另一個帳戶來執行 id_2 的 bet()

我很難弄清楚你到底想做什麼,你是想用相同的地址在 2 個不同的遊戲上下注嗎?如果是這樣,您是契約的創建者嗎?因為程式碼中充滿了阻止你這樣做的東西,這對我來說似乎是故意的。

//The first require is used to check if the player already exist
 require(!checkPlayerExists(msg.sender));

這只是一個例子,可能是最明顯的一個

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