struct buyer{
uint amount;
Status status;
}
mapping(address=>buyer) public buyers;
mapping(uint=>address) buyerIndex;
uint publi
As Viktor said, default value for all possible values in mapping is zero. So if a buyer
has not already inserted in mapping, the amount
value for that address
will be zero. But this approach has a flaw, if a buyer
does exists but its balance became zero after some operations, you will treat it as it does not exist.
I think the best approach is to add a exists
member to the buyer
struct with bool
type. Default value for this member is false
and when the buyer get created, you initialize it with true
value. So you can check exactly if a buyer exist or not via this member.
Buyer struct:
struct buyer{
uint amount;
Status status;
bool exists;
}
Initialize buyer:
buyer memory b = buyer(0, status, true);
Check if buyer exists:
if(buyers[msg.sender].exists) {
//so can buy
}