gun-eth 1.1.1 → 1.1.3
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 +72 -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,19 @@ 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
|
+
console.log("SHINE plugin called with:", { chain, nodeId, data });
|
98
|
+
|
99
|
+
if (typeof callback !== "function") {
|
100
|
+
console.error("Callback must be a function");
|
101
|
+
return this;
|
102
|
+
}
|
103
|
+
|
104
|
+
if (typeof data !== "object" || data === null) {
|
105
|
+
callback({ err: "Data must be a non-null object" });
|
106
|
+
return this;
|
107
|
+
}
|
108
|
+
|
97
109
|
const gun = this;
|
98
110
|
|
99
111
|
// select address based on chain
|
@@ -115,7 +127,7 @@ Gun.chain.shine = function (chain, data, callback) {
|
|
115
127
|
};
|
116
128
|
|
117
129
|
// Funzione per scrivere on-chain
|
118
|
-
const writeOnChain = async (nodeId,
|
130
|
+
const writeOnChain = async (nodeId, contentHash) => {
|
119
131
|
const signer = await getSigner();
|
120
132
|
const contract = new ethers.Contract(
|
121
133
|
SHINE_CONTRACT_ADDRESS,
|
@@ -124,7 +136,6 @@ Gun.chain.shine = function (chain, data, callback) {
|
|
124
136
|
);
|
125
137
|
const tx = await contract.updateData(
|
126
138
|
ethers.toUtf8Bytes(nodeId),
|
127
|
-
key,
|
128
139
|
contentHash
|
129
140
|
);
|
130
141
|
await tx.wait();
|
@@ -132,59 +143,78 @@ Gun.chain.shine = function (chain, data, callback) {
|
|
132
143
|
};
|
133
144
|
|
134
145
|
// Funzione per verificare on-chain
|
135
|
-
const verifyOnChain = async (nodeId,
|
146
|
+
const verifyOnChain = async (nodeId, contentHash) => {
|
136
147
|
const signer = await getSigner();
|
137
148
|
const contract = new ethers.Contract(
|
138
149
|
SHINE_CONTRACT_ADDRESS,
|
139
150
|
SHINE_ABI,
|
140
151
|
signer
|
141
152
|
);
|
142
|
-
return await contract.verifyData(
|
143
|
-
|
144
|
-
|
145
|
-
|
153
|
+
return await contract.verifyData(ethers.toUtf8Bytes(nodeId), contentHash);
|
154
|
+
};
|
155
|
+
|
156
|
+
// Funzione per ottenere l'ultimo record on-chain
|
157
|
+
const getLatestRecord = async (nodeId) => {
|
158
|
+
const signer = await getSigner();
|
159
|
+
const contract = new ethers.Contract(
|
160
|
+
SHINE_CONTRACT_ADDRESS,
|
161
|
+
SHINE_ABI,
|
162
|
+
signer
|
146
163
|
);
|
164
|
+
return await contract.getLatestRecord(ethers.toUtf8Bytes(nodeId));
|
147
165
|
};
|
148
166
|
|
149
167
|
// Processo SHINE
|
150
|
-
gun.
|
151
|
-
if (ack.err) {
|
152
|
-
if (callback) callback({ err: ack.err });
|
153
|
-
return;
|
154
|
-
}
|
155
|
-
|
168
|
+
gun.get(nodeId).once(async (existingData) => {
|
156
169
|
try {
|
157
|
-
|
158
|
-
const dataString = JSON.stringify(
|
170
|
+
const dataToVerify = existingData || data;
|
171
|
+
const dataString = JSON.stringify(dataToVerify);
|
159
172
|
const contentHash = ethers.keccak256(ethers.toUtf8Bytes(dataString));
|
160
173
|
|
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
|
-
});
|
174
|
+
// Ottieni l'ultimo record on-chain
|
175
|
+
const [lastContentHash, lastTimestamp, lastUpdater] =
|
176
|
+
await getLatestRecord(nodeId);
|
177
|
+
|
178
|
+
if (lastContentHash !== ethers.ZeroHash) {
|
179
|
+
// Il dato esiste on-chain
|
180
|
+
if (lastContentHash === contentHash) {
|
181
|
+
// Il dato on-chain corrisponde al dato in GunDB
|
182
|
+
if (callback)
|
183
|
+
callback({
|
184
|
+
ok: true,
|
185
|
+
message: "Data verified on GunDB and blockchain",
|
186
|
+
updater: lastUpdater,
|
187
|
+
timestamp: lastTimestamp.toString(),
|
188
|
+
});
|
189
|
+
} else {
|
190
|
+
// Il dato on-chain è diverso dal dato in GunDB
|
191
|
+
if (callback)
|
192
|
+
callback({ err: "Data mismatch between GunDB and blockchain" });
|
193
|
+
}
|
186
194
|
} else {
|
187
|
-
|
195
|
+
// Il dato non esiste on-chain, procedi alla scrittura
|
196
|
+
if (!existingData) {
|
197
|
+
gun.get(nodeId).put(dataToVerify);
|
198
|
+
}
|
199
|
+
|
200
|
+
await writeOnChain(nodeId, contentHash);
|
201
|
+
|
202
|
+
// Verifica dopo la scrittura
|
203
|
+
const [newContentHash, newTimestamp, newUpdater] =
|
204
|
+
await getLatestRecord(nodeId);
|
205
|
+
|
206
|
+
if (newContentHash === contentHash) {
|
207
|
+
if (callback)
|
208
|
+
callback({
|
209
|
+
ok: true,
|
210
|
+
message: "Data written and verified on GunDB and blockchain",
|
211
|
+
updater: newUpdater,
|
212
|
+
timestamp: newTimestamp.toString(),
|
213
|
+
});
|
214
|
+
} else {
|
215
|
+
if (callback)
|
216
|
+
callback({ err: "Data verification failed after writing" });
|
217
|
+
}
|
188
218
|
}
|
189
219
|
} catch (error) {
|
190
220
|
if (callback) callback({ err: error.message });
|