## 5 The Proposed Approach
### Setup Phase
```
1 pragmasolidity>=0.6.12<0.9.0;
2
3 contractRoot_IPFSAddress_Mapping{
4//Addressofthecontractowner,i.e.,\"thebroker
5 addresspublicowner;
6
7//Arraytostoretheaddressesofpublishers/subscribers
8 address[]publicclients;
9
10//MappingtostoretherootsandthecorrespondingIPFSaddress
11 mapping(bytes32=>bytes32)privaterootToIPFSAddress;
12
13//Eventomitedwhentnloekupmadebyapublisher/subscribersfails
14 eventClientafter(addressindexedrequester,bytes32 root);
15
16//Modifiertorestrictaccesstothecontractowner
17 modifieronlyDwner(){
18 require(msg.sender==over,\"Notauthorized\");
19-;
20}
21
22//Constructortosettheownerofthecontract
23 constructor(){
24 owner=msg.sender;
25}
26
27//Functiontoaddasnewroot-IPFSAddressmapping(onlycallablebytheowner)
28 functionaddRootIPFSAddress(bytes32 root,bytes32 IPFSAddress)publiconlyDwner{
29 rootToIPFSAddress[root]=IPFSAddress;
30}
31
32//Functiontoaddasnewpublisher/subscriberaddress(onlycallablebytheowner)
33 functionaddClient(addressclient)publiconlyDwner{
34 clients.push(client);
35}
36
37//ViewfunctiontoretrievetheIPFSAddressassociatedwithagivenroot
38 functiongetIPFSAddress(bytes32 root)publicviewreturns(bytes32){
39 bytes32 IPFSAddress=rootToIPFSAddress[root];
40 returnIPFSAddress;
41}
42
43//Functiontoentaneventsignalingtheintegrityviolation
44 functionpullTheAlarm(bytes32 root)public{
45 if(isClientAddress(msg.sender)){
46 emitClientAlert(msg.sender,root);
47}
48}
49
50//Internalfunctiontocheckifamaddressisintheclientsarray
51 functionisClientAddress(addressaddr)internalviewreturns(bool){
52 for(uint=0;i<clients.length;i++){
53 if(clients[i]==addr){
54 returntrue;
55}
56}
57 returnfalse;
58}
59}
```  
Listing 1: Solidity Smart Contract for handling the mapping between the root of the MHT and the IPFS address. ```
1 pragmasolidity>=0.6.12<0.9.0;
2
3 contractRoot_IPFSAddress_Mapping{
4//Addressofthecontractowner,i.e.,\"thebroker
5 addresspublicowner;
6
7//Arraytostoretheaddressesofpublishers/subscribers
8 address[]publicclients;
9
10//MappingtostoretherootsandthecorrespondingIPFSaddress
11 mapping(bytes32=>bytes32)privaterootToIPFSAddress;
12
13//Eventomitedwhentnloekupmadebyapublisher/subscribersfails
14 eventClientafter(addressindexedrequester,bytes32 root);
15
16//Modifiertorestrictaccesstothecontractowner
17 modifieronlyDwner(){
18 require(msg.sender==over,\"Notauthorized\");
19-;
20}
21
22//Constructortosettheownerofthecontract
23 constructor(){
24 owner=msg.sender;
25}
26
27//Functiontoaddasnewroot-IPFSAddressmapping(onlycallablebytheowner)
28 functionaddRootIPFSAddress(bytes32 root,bytes32 IPFSAddress)publiconlyDwner{
29 rootToIPFSAddress[root]=IPFSAddress;
30}
31
32//Functiontoaddasnewpublisher/subscriberaddress(onlycallablebytheowner)
33 functionaddClient(addressclient)publiconlyDwner{
34 clients.push(client);
35}
36
37//ViewfunctiontoretrievetheIPFSAddressassociatedwithagivenroot
38 functiongetIPFSAddress(bytes32 root)publicviewreturns(bytes32){
39 bytes32 IPFSAddress=rootToIPFSAddress[root];
40 returnIPFSAddress;
41}
42
43//Functiontoentaneventsignalingtheintegrityviolation
44 functionpullTheAlarm(bytes32 root)public{
45 if(isClientAddress(msg.sender)){
46 emitClientAlert(msg.sender,root);
47}
48}
49
50//Internalfunctiontocheckifamaddressisintheclientsarray
51 functionisClientAddress(addressaddr)internalviewreturns(bool){
52 for(uint=0;i<clients.length;i++){
53 if(clients[i]==addr){
54 returntrue;
55}
56}
57 returnfalse;
58}
59}
```  
**Listing 2**Solidity Smart Contract for handling the mapping between the root of the MHT and the IPFS address.