gun-eth 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- package/SHINE.json +19 -57
- package/SHINE.sol +9 -22
- package/index.js +60 -42
- package/package.json +1 -1
package/SHINE.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
{
|
2
|
-
"address": "
|
2
|
+
"address": "0x43D838b683F772F08f321E5FA265ad3e333BE9C2",
|
3
3
|
"abi": [
|
4
4
|
{
|
5
5
|
"anonymous": false,
|
@@ -10,12 +10,6 @@
|
|
10
10
|
"name": "nodeId",
|
11
11
|
"type": "bytes"
|
12
12
|
},
|
13
|
-
{
|
14
|
-
"indexed": true,
|
15
|
-
"internalType": "bytes32",
|
16
|
-
"name": "key",
|
17
|
-
"type": "bytes32"
|
18
|
-
},
|
19
13
|
{
|
20
14
|
"indexed": false,
|
21
15
|
"internalType": "bytes32",
|
@@ -39,11 +33,6 @@
|
|
39
33
|
"name": "nodeIds",
|
40
34
|
"type": "bytes[]"
|
41
35
|
},
|
42
|
-
{
|
43
|
-
"internalType": "bytes32[]",
|
44
|
-
"name": "keys",
|
45
|
-
"type": "bytes32[]"
|
46
|
-
},
|
47
36
|
{
|
48
37
|
"internalType": "bytes32[]",
|
49
38
|
"name": "contentHashes",
|
@@ -61,11 +50,6 @@
|
|
61
50
|
"internalType": "bytes",
|
62
51
|
"name": "nodeId",
|
63
52
|
"type": "bytes"
|
64
|
-
},
|
65
|
-
{
|
66
|
-
"internalType": "bytes32",
|
67
|
-
"name": "key",
|
68
|
-
"type": "bytes32"
|
69
53
|
}
|
70
54
|
],
|
71
55
|
"name": "getLatestRecord",
|
@@ -95,11 +79,6 @@
|
|
95
79
|
"internalType": "bytes",
|
96
80
|
"name": "",
|
97
81
|
"type": "bytes"
|
98
|
-
},
|
99
|
-
{
|
100
|
-
"internalType": "bytes32",
|
101
|
-
"name": "",
|
102
|
-
"type": "bytes32"
|
103
82
|
}
|
104
83
|
],
|
105
84
|
"name": "nodeData",
|
@@ -130,11 +109,6 @@
|
|
130
109
|
"name": "nodeId",
|
131
110
|
"type": "bytes"
|
132
111
|
},
|
133
|
-
{
|
134
|
-
"internalType": "bytes32",
|
135
|
-
"name": "key",
|
136
|
-
"type": "bytes32"
|
137
|
-
},
|
138
112
|
{
|
139
113
|
"internalType": "bytes32",
|
140
114
|
"name": "contentHash",
|
@@ -153,11 +127,6 @@
|
|
153
127
|
"name": "nodeId",
|
154
128
|
"type": "bytes"
|
155
129
|
},
|
156
|
-
{
|
157
|
-
"internalType": "bytes32",
|
158
|
-
"name": "key",
|
159
|
-
"type": "bytes32"
|
160
|
-
},
|
161
130
|
{
|
162
131
|
"internalType": "bytes32",
|
163
132
|
"name": "contentHash",
|
@@ -186,28 +155,28 @@
|
|
186
155
|
"type": "function"
|
187
156
|
}
|
188
157
|
],
|
189
|
-
"transactionHash": "
|
158
|
+
"transactionHash": "0xc00b134812b2cb32d6a412fd1d1a4c9661777b0ee29ed0ff05b09c7c0b1f6f0d",
|
190
159
|
"receipt": {
|
191
160
|
"to": null,
|
192
161
|
"from": "0x8aA5F726d9F868a21a8bd748E2f1E43bA31eb670",
|
193
|
-
"contractAddress": "
|
194
|
-
"transactionIndex":
|
195
|
-
"gasUsed": "
|
162
|
+
"contractAddress": "0x43D838b683F772F08f321E5FA265ad3e333BE9C2",
|
163
|
+
"transactionIndex": 2,
|
164
|
+
"gasUsed": "419514",
|
196
165
|
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
197
|
-
"blockHash": "
|
198
|
-
"transactionHash": "
|
166
|
+
"blockHash": "0xc8bd27a2f9bf4ec35e2c61c2c2e62b47b70aa10f587ea48d4802611c36116dd6",
|
167
|
+
"transactionHash": "0xc00b134812b2cb32d6a412fd1d1a4c9661777b0ee29ed0ff05b09c7c0b1f6f0d",
|
199
168
|
"logs": [],
|
200
|
-
"blockNumber":
|
201
|
-
"cumulativeGasUsed": "
|
169
|
+
"blockNumber": 17723163,
|
170
|
+
"cumulativeGasUsed": "551282",
|
202
171
|
"status": 1,
|
203
172
|
"byzantium": true
|
204
173
|
},
|
205
174
|
"args": [],
|
206
|
-
"numDeployments":
|
207
|
-
"solcInputHash": "
|
208
|
-
"metadata": "{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"indexed\":
|
209
|
-
"bytecode": "
|
210
|
-
"deployedBytecode": "
|
175
|
+
"numDeployments": 4,
|
176
|
+
"solcInputHash": "40cece70198a47ff2f958bd8d77d352d",
|
177
|
+
"metadata": "{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"contentHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"updater\",\"type\":\"address\"}],\"name\":\"DataUpdated\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"bytes[]\",\"name\":\"nodeIds\",\"type\":\"bytes[]\"},{\"internalType\":\"bytes32[]\",\"name\":\"contentHashes\",\"type\":\"bytes32[]\"}],\"name\":\"batchUpdateData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"}],\"name\":\"getLatestRecord\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"name\":\"nodeData\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"contentHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"timestamp\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"updater\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"contentHash\",\"type\":\"bytes32\"}],\"name\":\"updateData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"contentHash\",\"type\":\"bytes32\"}],\"name\":\"verifyData\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/SHINE.sol\":\"SHINE\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"contracts/SHINE.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\r\\npragma solidity ^0.8.0;\\r\\n\\r\\ncontract SHINE {\\r\\n\\tstruct DataRecord {\\r\\n\\t\\tbytes32 contentHash;\\r\\n\\t\\tuint256 timestamp;\\r\\n\\t\\taddress updater;\\r\\n\\t}\\r\\n\\r\\n\\tmapping(bytes => DataRecord) public nodeData;\\r\\n\\r\\n\\tevent DataUpdated(\\r\\n\\t\\tbytes indexed nodeId,\\r\\n\\t\\tbytes32 contentHash,\\r\\n\\t\\taddress updater\\r\\n\\t);\\r\\n\\r\\n\\tfunction updateData(bytes memory nodeId, bytes32 contentHash) public {\\r\\n\\t\\tnodeData[nodeId] = DataRecord(contentHash, block.timestamp, msg.sender);\\r\\n\\t\\temit DataUpdated(nodeId, contentHash, msg.sender);\\r\\n\\t}\\r\\n\\r\\n\\tfunction verifyData(\\r\\n\\t\\tbytes memory nodeId,\\r\\n\\t\\tbytes32 contentHash\\r\\n\\t) public view returns (bool, uint256, address) {\\r\\n\\t\\tDataRecord memory record = nodeData[nodeId];\\r\\n\\t\\tbool isValid = record.contentHash == contentHash;\\r\\n\\t\\treturn (isValid, record.timestamp, record.updater);\\r\\n\\t}\\r\\n\\r\\n\\tfunction getLatestRecord(\\r\\n\\t\\tbytes memory nodeId\\r\\n\\t) public view returns (bytes32, uint256, address) {\\r\\n\\t\\tDataRecord memory record = nodeData[nodeId];\\r\\n\\t\\treturn (record.contentHash, record.timestamp, record.updater);\\r\\n\\t}\\r\\n\\r\\n\\tfunction batchUpdateData(\\r\\n\\t\\tbytes[] memory nodeIds,\\r\\n\\t\\tbytes32[] memory contentHashes\\r\\n\\t) public {\\r\\n\\t\\trequire(\\r\\n\\t\\t\\tnodeIds.length == contentHashes.length,\\r\\n\\t\\t\\t\\\"Arrays length mismatch\\\"\\r\\n\\t\\t);\\r\\n\\t\\tfor (uint i = 0; i < nodeIds.length; i++) {\\r\\n\\t\\t\\tupdateData(nodeIds[i], contentHashes[i]);\\r\\n\\t\\t}\\r\\n\\t}\\r\\n}\\r\\n\",\"keccak256\":\"0x1ed77b1882586a77f3e6d5bf176009c5f00b9d91f71cfd6153ca2d57ef30831d\",\"license\":\"MIT\"}},\"version\":1}",
|
178
|
+
"bytecode": "0x608060405234801561001057600080fd5b506106a0806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80630d36830e1461005c5780630f07e48514610071578063d236feda14610084578063d54193d7146100c2578063d58a3de3146100f9575b600080fd5b61006f61006a3660046104a8565b61013c565b005b61006f61007f36600461057c565b6101e9565b61009761009236600461057c565b6102a2565b60408051931515845260208401929092526001600160a01b0316908201526060015b60405180910390f35b6100d56100d03660046105c1565b610302565b6040805193845260208401929092526001600160a01b0316908201526060016100b9565b6100d56101073660046105c1565b80516020818301810180516000825292820191909301209152805460018201546002909201549091906001600160a01b031683565b805182511461018a5760405162461bcd60e51b8152602060048201526016602482015275082e4e4c2f2e640d8cadccee8d040dad2e6dac2e8c6d60531b604482015260640160405180910390fd5b60005b82518110156101e4576101d28382815181106101ab576101ab6105fe565b60200260200101518383815181106101c5576101c56105fe565b60200260200101516101e9565b806101dc81610614565b91505061018d565b505050565b604080516060810182528281524260208201523381830152905160009061021190859061063b565b908152604080516020928190038301812084518155928401516001840155920151600290910180546001600160a01b0319166001600160a01b0390921691909117905561025f90839061063b565b60408051918290038220838352336020840152917fac3d4f3cbf6818c9329b6b8c61e41d9dc52fc1cc580fff6af273be3ebc1d423f910160405180910390a25050565b6000806000806000866040516102b8919061063b565b9081526040805160209281900383018120606082018352805480835260018201549483018590526002909101546001600160a01b0316919092018190529614979096509350505050565b600080600080600085604051610318919061063b565b9081526040805160209281900383018120606082018352805480835260018201549483018590526002909101546001600160a01b0316919092018190529097919650945092505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156103a1576103a1610362565b604052919050565b600067ffffffffffffffff8211156103c3576103c3610362565b5060051b60200190565b600082601f8301126103de57600080fd5b813567ffffffffffffffff8111156103f8576103f8610362565b61040b601f8201601f1916602001610378565b81815284602083860101111561042057600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261044e57600080fd5b8135602061046361045e836103a9565b610378565b82815260059290921b8401810191818101908684111561048257600080fd5b8286015b8481101561049d5780358352918301918301610486565b509695505050505050565b600080604083850312156104bb57600080fd5b823567ffffffffffffffff808211156104d357600080fd5b818501915085601f8301126104e757600080fd5b813560206104f761045e836103a9565b82815260059290921b8401810191818101908984111561051657600080fd5b8286015b8481101561054e578035868111156105325760008081fd5b6105408c86838b01016103cd565b84525091830191830161051a565b509650508601359250508082111561056557600080fd5b506105728582860161043d565b9150509250929050565b6000806040838503121561058f57600080fd5b823567ffffffffffffffff8111156105a657600080fd5b6105b2858286016103cd565b95602094909401359450505050565b6000602082840312156105d357600080fd5b813567ffffffffffffffff8111156105ea57600080fd5b6105f6848285016103cd565b949350505050565b634e487b7160e01b600052603260045260246000fd5b60006001820161063457634e487b7160e01b600052601160045260246000fd5b5060010190565b6000825160005b8181101561065c5760208186018101518583015201610642565b50600092019182525091905056fea2646970667358221220c3ea212644c861f0e892deb0129df945a7fa2af5971e51e4b97810c73fc547f764736f6c63430008110033",
|
179
|
+
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100575760003560e01c80630d36830e1461005c5780630f07e48514610071578063d236feda14610084578063d54193d7146100c2578063d58a3de3146100f9575b600080fd5b61006f61006a3660046104a8565b61013c565b005b61006f61007f36600461057c565b6101e9565b61009761009236600461057c565b6102a2565b60408051931515845260208401929092526001600160a01b0316908201526060015b60405180910390f35b6100d56100d03660046105c1565b610302565b6040805193845260208401929092526001600160a01b0316908201526060016100b9565b6100d56101073660046105c1565b80516020818301810180516000825292820191909301209152805460018201546002909201549091906001600160a01b031683565b805182511461018a5760405162461bcd60e51b8152602060048201526016602482015275082e4e4c2f2e640d8cadccee8d040dad2e6dac2e8c6d60531b604482015260640160405180910390fd5b60005b82518110156101e4576101d28382815181106101ab576101ab6105fe565b60200260200101518383815181106101c5576101c56105fe565b60200260200101516101e9565b806101dc81610614565b91505061018d565b505050565b604080516060810182528281524260208201523381830152905160009061021190859061063b565b908152604080516020928190038301812084518155928401516001840155920151600290910180546001600160a01b0319166001600160a01b0390921691909117905561025f90839061063b565b60408051918290038220838352336020840152917fac3d4f3cbf6818c9329b6b8c61e41d9dc52fc1cc580fff6af273be3ebc1d423f910160405180910390a25050565b6000806000806000866040516102b8919061063b565b9081526040805160209281900383018120606082018352805480835260018201549483018590526002909101546001600160a01b0316919092018190529614979096509350505050565b600080600080600085604051610318919061063b565b9081526040805160209281900383018120606082018352805480835260018201549483018590526002909101546001600160a01b0316919092018190529097919650945092505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156103a1576103a1610362565b604052919050565b600067ffffffffffffffff8211156103c3576103c3610362565b5060051b60200190565b600082601f8301126103de57600080fd5b813567ffffffffffffffff8111156103f8576103f8610362565b61040b601f8201601f1916602001610378565b81815284602083860101111561042057600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261044e57600080fd5b8135602061046361045e836103a9565b610378565b82815260059290921b8401810191818101908684111561048257600080fd5b8286015b8481101561049d5780358352918301918301610486565b509695505050505050565b600080604083850312156104bb57600080fd5b823567ffffffffffffffff808211156104d357600080fd5b818501915085601f8301126104e757600080fd5b813560206104f761045e836103a9565b82815260059290921b8401810191818101908984111561051657600080fd5b8286015b8481101561054e578035868111156105325760008081fd5b6105408c86838b01016103cd565b84525091830191830161051a565b509650508601359250508082111561056557600080fd5b506105728582860161043d565b9150509250929050565b6000806040838503121561058f57600080fd5b823567ffffffffffffffff8111156105a657600080fd5b6105b2858286016103cd565b95602094909401359450505050565b6000602082840312156105d357600080fd5b813567ffffffffffffffff8111156105ea57600080fd5b6105f6848285016103cd565b949350505050565b634e487b7160e01b600052603260045260246000fd5b60006001820161063457634e487b7160e01b600052601160045260246000fd5b5060010190565b6000825160005b8181101561065c5760208186018101518583015201610642565b50600092019182525091905056fea2646970667358221220c3ea212644c861f0e892deb0129df945a7fa2af5971e51e4b97810c73fc547f764736f6c63430008110033",
|
211
180
|
"devdoc": {
|
212
181
|
"kind": "dev",
|
213
182
|
"methods": {},
|
@@ -221,12 +190,12 @@
|
|
221
190
|
"storageLayout": {
|
222
191
|
"storage": [
|
223
192
|
{
|
224
|
-
"astId":
|
193
|
+
"astId": 13,
|
225
194
|
"contract": "contracts/SHINE.sol:SHINE",
|
226
195
|
"label": "nodeData",
|
227
196
|
"offset": 0,
|
228
197
|
"slot": "0",
|
229
|
-
"type": "t_mapping(t_bytes_memory_ptr,
|
198
|
+
"type": "t_mapping(t_bytes_memory_ptr,t_struct(DataRecord)8_storage)"
|
230
199
|
}
|
231
200
|
],
|
232
201
|
"types": {
|
@@ -245,19 +214,12 @@
|
|
245
214
|
"label": "bytes",
|
246
215
|
"numberOfBytes": "32"
|
247
216
|
},
|
248
|
-
"t_mapping(
|
249
|
-
"encoding": "mapping",
|
250
|
-
"key": "t_bytes32",
|
251
|
-
"label": "mapping(bytes32 => struct SHINE.DataRecord)",
|
252
|
-
"numberOfBytes": "32",
|
253
|
-
"value": "t_struct(DataRecord)8_storage"
|
254
|
-
},
|
255
|
-
"t_mapping(t_bytes_memory_ptr,t_mapping(t_bytes32,t_struct(DataRecord)8_storage))": {
|
217
|
+
"t_mapping(t_bytes_memory_ptr,t_struct(DataRecord)8_storage)": {
|
256
218
|
"encoding": "mapping",
|
257
219
|
"key": "t_bytes_memory_ptr",
|
258
|
-
"label": "mapping(bytes =>
|
220
|
+
"label": "mapping(bytes => struct SHINE.DataRecord)",
|
259
221
|
"numberOfBytes": "32",
|
260
|
-
"value": "
|
222
|
+
"value": "t_struct(DataRecord)8_storage"
|
261
223
|
},
|
262
224
|
"t_struct(DataRecord)8_storage": {
|
263
225
|
"encoding": "inplace",
|
package/SHINE.sol
CHANGED
@@ -8,58 +8,45 @@ contract SHINE {
|
|
8
8
|
address updater;
|
9
9
|
}
|
10
10
|
|
11
|
-
mapping(bytes =>
|
11
|
+
mapping(bytes => DataRecord) public nodeData;
|
12
12
|
|
13
13
|
event DataUpdated(
|
14
14
|
bytes indexed nodeId,
|
15
|
-
bytes32 indexed key,
|
16
15
|
bytes32 contentHash,
|
17
16
|
address updater
|
18
17
|
);
|
19
18
|
|
20
|
-
function updateData(
|
21
|
-
|
22
|
-
|
23
|
-
bytes32 contentHash
|
24
|
-
) public {
|
25
|
-
nodeData[nodeId][key] = DataRecord(
|
26
|
-
contentHash,
|
27
|
-
block.timestamp,
|
28
|
-
msg.sender
|
29
|
-
);
|
30
|
-
emit DataUpdated(nodeId, key, contentHash, msg.sender);
|
19
|
+
function updateData(bytes memory nodeId, bytes32 contentHash) public {
|
20
|
+
nodeData[nodeId] = DataRecord(contentHash, block.timestamp, msg.sender);
|
21
|
+
emit DataUpdated(nodeId, contentHash, msg.sender);
|
31
22
|
}
|
32
23
|
|
33
24
|
function verifyData(
|
34
25
|
bytes memory nodeId,
|
35
|
-
bytes32 key,
|
36
26
|
bytes32 contentHash
|
37
27
|
) public view returns (bool, uint256, address) {
|
38
|
-
DataRecord memory record = nodeData[nodeId]
|
28
|
+
DataRecord memory record = nodeData[nodeId];
|
39
29
|
bool isValid = record.contentHash == contentHash;
|
40
30
|
return (isValid, record.timestamp, record.updater);
|
41
31
|
}
|
42
32
|
|
43
33
|
function getLatestRecord(
|
44
|
-
bytes memory nodeId
|
45
|
-
bytes32 key
|
34
|
+
bytes memory nodeId
|
46
35
|
) public view returns (bytes32, uint256, address) {
|
47
|
-
DataRecord memory record = nodeData[nodeId]
|
36
|
+
DataRecord memory record = nodeData[nodeId];
|
48
37
|
return (record.contentHash, record.timestamp, record.updater);
|
49
38
|
}
|
50
39
|
|
51
40
|
function batchUpdateData(
|
52
41
|
bytes[] memory nodeIds,
|
53
|
-
bytes32[] memory keys,
|
54
42
|
bytes32[] memory contentHashes
|
55
43
|
) public {
|
56
44
|
require(
|
57
|
-
nodeIds.length ==
|
58
|
-
keys.length == contentHashes.length,
|
45
|
+
nodeIds.length == contentHashes.length,
|
59
46
|
"Arrays length mismatch"
|
60
47
|
);
|
61
48
|
for (uint i = 0; i < nodeIds.length; i++) {
|
62
|
-
updateData(nodeIds[i],
|
49
|
+
updateData(nodeIds[i], contentHashes[i]);
|
63
50
|
}
|
64
51
|
}
|
65
52
|
}
|
package/index.js
CHANGED
@@ -93,7 +93,7 @@ Gun.chain.getAndDecryptPair = async function (address, signature) {
|
|
93
93
|
}
|
94
94
|
};
|
95
95
|
|
96
|
-
Gun.chain.shine = function (chain, data, callback) {
|
96
|
+
Gun.chain.shine = function (chain, nodeId, data, callback) {
|
97
97
|
const gun = this;
|
98
98
|
|
99
99
|
// select address based on chain
|
@@ -115,7 +115,7 @@ Gun.chain.shine = function (chain, data, callback) {
|
|
115
115
|
};
|
116
116
|
|
117
117
|
// Funzione per scrivere on-chain
|
118
|
-
const writeOnChain = async (nodeId,
|
118
|
+
const writeOnChain = async (nodeId, contentHash) => {
|
119
119
|
const signer = await getSigner();
|
120
120
|
const contract = new ethers.Contract(
|
121
121
|
SHINE_CONTRACT_ADDRESS,
|
@@ -124,7 +124,6 @@ Gun.chain.shine = function (chain, data, callback) {
|
|
124
124
|
);
|
125
125
|
const tx = await contract.updateData(
|
126
126
|
ethers.toUtf8Bytes(nodeId),
|
127
|
-
key,
|
128
127
|
contentHash
|
129
128
|
);
|
130
129
|
await tx.wait();
|
@@ -132,59 +131,78 @@ Gun.chain.shine = function (chain, data, callback) {
|
|
132
131
|
};
|
133
132
|
|
134
133
|
// Funzione per verificare on-chain
|
135
|
-
const verifyOnChain = async (nodeId,
|
134
|
+
const verifyOnChain = async (nodeId, contentHash) => {
|
136
135
|
const signer = await getSigner();
|
137
136
|
const contract = new ethers.Contract(
|
138
137
|
SHINE_CONTRACT_ADDRESS,
|
139
138
|
SHINE_ABI,
|
140
139
|
signer
|
141
140
|
);
|
142
|
-
return await contract.verifyData(
|
143
|
-
|
144
|
-
|
145
|
-
|
141
|
+
return await contract.verifyData(ethers.toUtf8Bytes(nodeId), contentHash);
|
142
|
+
};
|
143
|
+
|
144
|
+
// Funzione per ottenere l'ultimo record on-chain
|
145
|
+
const getLatestRecord = async (nodeId) => {
|
146
|
+
const signer = await getSigner();
|
147
|
+
const contract = new ethers.Contract(
|
148
|
+
SHINE_CONTRACT_ADDRESS,
|
149
|
+
SHINE_ABI,
|
150
|
+
signer
|
146
151
|
);
|
152
|
+
return await contract.getLatestRecord(ethers.toUtf8Bytes(nodeId));
|
147
153
|
};
|
148
154
|
|
149
155
|
// Processo SHINE
|
150
|
-
gun.
|
151
|
-
if (ack.err) {
|
152
|
-
if (callback) callback({ err: ack.err });
|
153
|
-
return;
|
154
|
-
}
|
155
|
-
|
156
|
+
gun.get(nodeId).once(async (existingData) => {
|
156
157
|
try {
|
157
|
-
|
158
|
-
const dataString = JSON.stringify(
|
158
|
+
const dataToVerify = existingData || data;
|
159
|
+
const dataString = JSON.stringify(dataToVerify);
|
159
160
|
const contentHash = ethers.keccak256(ethers.toUtf8Bytes(dataString));
|
160
161
|
|
161
|
-
// Ottieni l'
|
162
|
-
const
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
ok: true,
|
182
|
-
message: "Data verified on GunDB and blockchain",
|
183
|
-
updater: updater,
|
184
|
-
timestamp: timestamp.toString(),
|
185
|
-
});
|
162
|
+
// Ottieni l'ultimo record on-chain
|
163
|
+
const [lastContentHash, lastTimestamp, lastUpdater] =
|
164
|
+
await getLatestRecord(nodeId);
|
165
|
+
|
166
|
+
if (lastContentHash !== ethers.ZeroHash) {
|
167
|
+
// Il dato esiste on-chain
|
168
|
+
if (lastContentHash === contentHash) {
|
169
|
+
// Il dato on-chain corrisponde al dato in GunDB
|
170
|
+
if (callback)
|
171
|
+
callback({
|
172
|
+
ok: true,
|
173
|
+
message: "Data verified on GunDB and blockchain",
|
174
|
+
updater: lastUpdater,
|
175
|
+
timestamp: lastTimestamp.toString(),
|
176
|
+
});
|
177
|
+
} else {
|
178
|
+
// Il dato on-chain è diverso dal dato in GunDB
|
179
|
+
if (callback)
|
180
|
+
callback({ err: "Data mismatch between GunDB and blockchain" });
|
181
|
+
}
|
186
182
|
} else {
|
187
|
-
|
183
|
+
// Il dato non esiste on-chain, procedi alla scrittura
|
184
|
+
if (!existingData) {
|
185
|
+
gun.get(nodeId).put(dataToVerify);
|
186
|
+
}
|
187
|
+
|
188
|
+
await writeOnChain(nodeId, contentHash);
|
189
|
+
|
190
|
+
// Verifica dopo la scrittura
|
191
|
+
const [newContentHash, newTimestamp, newUpdater] =
|
192
|
+
await getLatestRecord(nodeId);
|
193
|
+
|
194
|
+
if (newContentHash === contentHash) {
|
195
|
+
if (callback)
|
196
|
+
callback({
|
197
|
+
ok: true,
|
198
|
+
message: "Data written and verified on GunDB and blockchain",
|
199
|
+
updater: newUpdater,
|
200
|
+
timestamp: newTimestamp.toString(),
|
201
|
+
});
|
202
|
+
} else {
|
203
|
+
if (callback)
|
204
|
+
callback({ err: "Data verification failed after writing" });
|
205
|
+
}
|
188
206
|
}
|
189
207
|
} catch (error) {
|
190
208
|
if (callback) callback({ err: error.message });
|