I have this smart contract:
contract Truerec {
struct Certificate {
address issuerAddress;
string identityType;
string identityHash;
string dataHash;
bool revoked;
}
mapping(bytes32 => Certificate) certificates;
function issue(string _key,
string _identityType,
string _identityHash,
string _dataHash) {
certificates[sha3(_key)] = Certificate(
msg.sender,
_identityType,
_identityHash,
_dataHash,
false
);
}
...
}
How can I check whether a mapping already exists and by using that make sure that if the key already exists, that the existing mapping will not be overwritten?
I need something like:
function issue(string _key,
string _identityType,
string _identityHash,
string _dataHash) {
require(!key_exists(sha3(_key, certificates)]
certificates[sha3(_key)] = Certificate(
msg.sender,
_identityType,
_identityHash,
_dataHash,
false
);
}