📅  最后修改于: 2022-03-11 15:02:21.980000             🧑  作者: Mango
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;
}
}