# A Cloud Microservices Architecture for Data Integrity Verifiability Based on Blockchain
## 5 The Smart Contracts
### Objectcontract, Log, Bitacora and Root  
The base model of the contracts _Objectcontract_, _Log_, _Bitacora_ and _Root_ were taken from [36], here were used to engage with smart contracts _Admor_, _TUser_ and _Resource_ as illustrated in Figure 4.  
The explanation is as follows:  
_ObjectContract_ denotes the parent of all contracts. It contains two attributes: contract address \(A_{sc}\) and transaction address \(A_{tr}\). When a contract is created, these attributes are generated and can be accessed publicly by methods \(\mathit{getContractAddress}()\) and \(\mathit{getTransactionAddress}()\), respectively. Method \(\mathit{getReceipt}()\) is used to obtain the receipt of a transaction. Contract address is used to identify the contract in the blockchain and the transaction address to identify the event. _Log_ inherits from _ObjectContract_, you can see a description of the attributes in Table 4. All of such attributes are stored in the blockchain when method \(\mathit{Emit}(Ev)\) is called. Attributes marked with \(*\) are auto-generated within the smart contract; the rest are obtained from \(Ev\). \(\mathit{Emit}(Ev)\) is an abstract method, which must be implemented in a specialized smart contract, such as _Bitacora_. A particular log event can be obtained using \(\mathit{getEvent}(\mathit{Attr})\). \begin{table}
\begin{tabular}{l l} \hline \hline
**Abbreviation** & **Description** \\ \hline \(*\)_Albock_ & Abbreviates Address Block of the blockchain. \\ \hline \(*\)_idEvent_ & Identifier of the current event. This attribute is formed by auto-incrementing. \\ \hline \(*\)_Asig_ & This is a signature hash of the log. \\ \hline \(*\)_when_ & A timestamp \(T\), denoting when the event has happened and \\ submitted to the blockchain. \\ \hline _Op_ & HTTP methods (GET, POST, PUT or DELETE). \\ \hline _where_ & The source of the event \\ \hline _target_ & The target of the event \\ \hline _To_ & Token identifier to know who has carried out the event. \\ \hline _Hd_ & Hashed message that describes more details about the event. \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Attributes (\(Atr\)) and description of Smart Contract Log. Figure 4: The smart contracts illustrated as class diagrams. Bitacora inherits all attributes and methods of smart contract _Log_. Events are registered in this smart contract. The constructor \(Bitacora(M)\) is created when it is called the first time, from \(M\), data are extracted to form \(Ev\), and it calls \(Emit(Ev)\), which is a private method, inherited from _Log_. This method stores \(Ev\) in the _Log_. \(setEvent(Ev)\) is another method, which can add events with information \(Ev\) by calling \(Emit(Ev)\) to be stored in the _Log_. All log events can be obtained using method \(getEvents()\). Root smart contract is created executing constructor \(Root(A,AS,m,To)\).The constructor creates its _Bitacora_ and the first _Log_. Let \(A\) be a user wanting to become a root; AS be a receiver user or target; _To_ be a token identifier to identify the transaction; and \(m\) is composed of two set of messages \(m_{1}\) and \(m_{2}\). \(m_{1}\) is formed by \(\{K^{+}_{p},Gas,credentials\}\), where \(K^{+}_{p}\) is the user public key, which will be the owner of the contract, and the key address will be used to execute the next transactions; _Gas_ represents the cost necessary to perform transactions; _credentials_ is related with root's secret information, such as _username_, _email_, and a hashed _password_. With \(m_{2}\) is possible to store extra information of the root. As a result of executing constructor \(Root\), it is generated a blockchain transaction answer \(R\), see Formula (5) for more details about \(R\). Smart contract \(Root\) can add events, using method \(addEvent(Ev)\). This method calls \(setEvent(Ev)\) of smart contract _Bitacora_. This transaction generates another transaction, \(R\); however, the smart contract address \(A_{sc}\) is still the same since this method does not create a new smart contract.