-
Notifications
You must be signed in to change notification settings - Fork 0
/
MemorialStore.sol
162 lines (144 loc) · 3.99 KB
/
MemorialStore.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
pragma solidity ^0.5.4;
pragma experimental ABIEncoderV2;
import "./ID.sol";
import "./IERC20.sol";
import "./ISacrifice.sol";
contract MemorialStore {
struct Memorial {
string name;
string nationality;
string birthTime;
string sleepTime;
string epitaph;
string phyAddress;
string introduction;
string picture;
bool exist;
}
mapping(string => Memorial) MemorialPark;
mapping(address => string[]) MemorialOwner;
mapping(address => string) OwnerName;
mapping(string => uint) _kv;
address public _MemorialContract;
address public _owner;
uint256 public currentNumber;
constructor() public {
_kv["name"] = 1;
_kv["nationality"] = 2;
_kv["birthTime"] = 3;
_kv["sleepTime"] = 4;
_kv["epitaph"] = 5;
_kv["phyAddress"] = 6;
_kv["introduction"] = 7;
_kv["picture"] = 8;
_owner = msg.sender;
}
function setContract(address addr) public {
require(msg.sender == _owner);
_MemorialContract = addr;
}
function createMemorial(
string memory _id,
string memory _name,
string memory _nationality,
string memory bt,
string memory st,
string memory epitaph,
string memory pha,
string memory introduction,
string memory pic,
address _addr
) public {
require(msg.sender == _MemorialContract);
MemorialPark[_id] = Memorial(_name, _nationality, bt, st, epitaph, pha, introduction, pic, true);
currentNumber++;
string[] storage _owned = MemorialOwner[_addr];
string[] memory _tmp = new string[](_owned.length+1);
for (uint i=0; i<_owned.length; i++) {
_tmp[i] = _owned[i];
}
_tmp[_owned.length] = _id;
MemorialOwner[_addr] = _tmp;
}
function exists(string memory _id) public view returns (bool) {
return MemorialPark[_id].exist;
}
function isOwner(address _addr, string memory _id) public view returns (bool) {
bool flag = false;
string[] memory _tmp = MemorialOwner[_addr];
for (uint i=0; i<_tmp.length; i++){
if (keccak256(abi.encodePacked(_id)) == keccak256(abi.encodePacked(_tmp[i]))) {
flag = true;
}
}
return flag;
}
function updateMemorial(
string memory _id,
string[] memory _key,
string[] memory _value
) public {
require(msg.sender == _MemorialContract);
Memorial memory _t = MemorialPark[_id];
for (uint i=0; i<_key.length; i++) {
if (_kv[_key[i]] == 1) {
_t.name = _value[i];
}
if (_kv[_key[i]] == 2) {
_t.nationality = _value[i];
}
if (_kv[_key[i]] == 3) {
_t.birthTime = _value[i];
}
if (_kv[_key[i]] == 4) {
_t.sleepTime = _value[i];
}
if (_kv[_key[i]] == 5) {
_t.epitaph = _value[i];
}
if (_kv[_key[i]] == 6) {
_t.phyAddress = _value[i];
}
if (_kv[_key[i]] == 7) {
_t.introduction = _value[i];
}
if (_kv[_key[i]] == 8) {
_t.picture = _value[i];
}
}
MemorialPark[_id] = _t;
}
function getMemorial(string memory _id) public view returns (
string memory, string memory, string memory , string memory, string memory, string memory, string memory, string memory) {
Memorial memory _t = MemorialPark[_id];
return (_t.name, _t.nationality, _t.birthTime, _t.sleepTime, _t.epitaph, _t.phyAddress, _t.introduction, _t.picture);
}
function getOwnedMemorial(address _addr) view public returns(string[] memory){
return MemorialOwner[_addr];
}
//function deleteMemorial(string _id) {
//}
function addManager(string memory _id, string memory _name, address _addr) public {
require(msg.sender == _MemorialContract);
string[] storage _owned = MemorialOwner[_addr];
string[] memory _tmp = new string[](_owned.length+1);
for (uint i=0; i<_owned.length; i++) {
require(keccak256(abi.encodePacked(_id)) != keccak256(abi.encodePacked(_owned[i])));
_tmp[i] = _owned[i];
}
_tmp[_owned.length] = _id;
MemorialOwner[_addr] = _tmp;
OwnerName[_addr] = _name;
}
function addManagerMulti(
string memory _id,
string[] memory _name,
address[] memory _addr
) public {
require(msg.sender == _MemorialContract);
require(_name.length == _addr.length);
for (uint i=0; i<_name.length; i++) {
addManager(_id, _name[i], _addr[i]);
}
}
}