📜  检查映射中的值是否为solidity ethereum中的空结构 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:02:21.980000             🧑  作者: Mango

代码示例1
pragma solidity >=0.4.21 <0.6.0;

contract Test {

    struct Ticket {
       uint seatNumber;
    }

    mapping (string => Ticket) myMapping;

    function isExists(string memory key) public view returns (bool) {
        // check if non-zero value in struct is zero
        // if it is zero then you know that myMapping[key] doesn't yet exist
        if(myMapping[key].seatNumber != 0) {
            return true;
        } 
        return false;
    }

    function add(string memory key, uint seatNumber) public returns (bool){            
        myMapping[key].seatNumber = seatNumber;            
        return true;
    }
}