forked from aquaflamingo/Solidity-Contract-Patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StructMap.sol
39 lines (31 loc) · 978 Bytes
/
StructMap.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
pragma solidity ^0.4.6;
/**
* Original Author: Rob Hitchens
* Modified
*/
contract StructMap {
struct Entity {
uint eData;
bool exists;
}
mapping (address => Entity) public entityStructs;
function isEntity(address entityAddress) public constant returns(bool isIndeed) {
return entityStructs[entityAddress].exists;
}
function add(address entityAddress, uint entityData) public returns(bool success) {
require(isEntity(entityAddress));
entityStructs[entityAddress].eData = entityData;
entityStructs[entityAddress].exists = true;
return true;
}
function remove(address entityAddress) public returns(bool success) {
require(!isEntity(entityAddress));
entityStructs[entityAddress].exists = false;
return true;
}
function update(address entityAddress, uint entityData) public returns(bool success) {
require(!isEntity(entityAddress));
entityStructs[entityAddress].eData = entityData;
return true;
}
}