-
Notifications
You must be signed in to change notification settings - Fork 0
/
Storage.sol
113 lines (95 loc) · 3.27 KB
/
Storage.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
// Import of the "AccessControl" contract from OpenZeppelin for role-based access control
import "@openzeppelin/contracts/access/AccessControl.sol";
contract Storage_01 is AccessControl {
// Declaration of struct
struct CidDataFormat {
string multibase;
string version;
string multicodec;
string multihashAlgorithm;
uint16 multihashLength;
string dataTemplateCid; //IPFS-CID des Templates
}
// Definition of roles
bytes32 public constant MERKLE_ROOT_UPDATER = keccak256("MERKLE_ROOT_UPDATER");
bytes32 public constant CHAINLINK_UPKEEPER = keccak256("CHAINLINK_UPKEEPER");
// Declaration of variables
string public merkleRoot;
address public sensor;
CidDataFormat public cidDataFormat;
// Declaration of events
event MerkleRootRequested(uint256 indexed blockNumber);
event MerkleRootUpdated(
uint256 indexed blockNumber,
string merkleRoot,
string leaf
);
event CidDataFormatUpdated(
uint256 indexed blockNumber,
string multibase,
string version,
string multicodec,
string multihashAlgorithm,
uint16 multihashLength,
string dataTemplateCid
);
event SensorAddressUpdated(
uint256 indexed blockNumber,
address sensorAddress
);
// Constructor
constructor(address defaultAdmin) {
_grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}
// Declaration and definition of functions
function requestMerkleRoot() public onlyRole(CHAINLINK_UPKEEPER) {
// Emitting the "MerkleRootRequested" event
emit MerkleRootRequested(block.number);
}
function setMerkleRoot(string memory merkleRoot_, string memory leaf_)
public
onlyRole(MERKLE_ROOT_UPDATER)
{
// Writing the new Merkle Root
merkleRoot = merkleRoot_;
// Emitting the "MerkleRootUpdated" event
emit MerkleRootUpdated(block.number, merkleRoot_, leaf_);
}
function setSensorAddress(address sensor_)
public
onlyRole(DEFAULT_ADMIN_ROLE)
{
// Writing the new sensor address
sensor = sensor_;
// Emitting the "SensorAddressUpdated" event
emit SensorAddressUpdated(block.number, sensor_);
}
function setCidDataFormat(
string memory multibase_,
string memory version_,
string memory multicodec_,
string memory multihashAlgorithm_,
uint16 multihashLength_,
string memory dataTemplateCid_
) public onlyRole(DEFAULT_ADMIN_ROLE) {
// Writing the information required to generate the IPFS CID
cidDataFormat.multibase = multibase_;
cidDataFormat.version = version_;
cidDataFormat.multicodec = multicodec_;
cidDataFormat.multihashAlgorithm = multihashAlgorithm_;
cidDataFormat.multihashLength = multihashLength_;
cidDataFormat.dataTemplateCid = dataTemplateCid_;
// Emitting the "CidDataFormatUpdated" event
emit CidDataFormatUpdated(
block.number,
multibase_,
version_,
multicodec_,
multihashAlgorithm_,
multihashLength_,
dataTemplateCid_
);
}
}