pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
contract Market {
struct Fruit {
uint amount;
}
uint256[] public fruitId;
mapping (uint256 => Fruit) private _fruits;
function gettotal() public view returns (uint) {
return fruitId.length;
}
function getFruit(uint256 _fruitId) public view returns (Fruit memory) {
return _fruits[_fruitId];
}
function addFruit(uint256 _fruitId) public {
//require(_fruits[_fruitId]== Market.Fruit(0),"added"); 好像不能用0判断
_fruits[_fruitId] = Fruit( 0);
fruitId.push(_fruitId) ;
}
}
添加一个新id的时候要判断一下这个fruit是否已经添加过,怎么判断这个id对应的结构体是不是空呢?