-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInteraction.sol
More file actions
45 lines (37 loc) · 1.68 KB
/
Copy pathUserInteraction.sol
File metadata and controls
45 lines (37 loc) · 1.68 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract UserInteraction {
// Estructura de interacción
struct Interaction {
string action; // Acción realizada por el usuario
string element; // Elemento sobre el cual se interactuó
uint256 timestamp; // Marca de tiempo de la interacción
address user; // Dirección del usuario que realizó la interacción
}
// Arreglo dinámico de interacciones
Interaction[] public interactions;
// Evento para cuando se registra una nueva interacción
event InteractionLogged(address indexed user, string action, string element, uint256 timestamp);
// Función para registrar una nueva interacción
function logInteraction(string memory action, string memory element) public {
require(bytes(action).length > 0, "La accion no puede estar vacia");
require(bytes(element).length > 0, "El elemento no puede estar vacio");
// Crear una nueva interacción y almacenarla
interactions.push(Interaction({
action: action,
element: element,
timestamp: block.timestamp,
user: msg.sender // Registra la dirección del usuario que interactúa
}));
// Emitir un evento para que las dApps puedan escuchar
emit InteractionLogged(msg.sender, action, element, block.timestamp);
}
// Obtener todas las interacciones
function getInteractions() public view returns (Interaction[] memory) {
return interactions;
}
// Obtener la cantidad de interacciones registradas
function getInteractionsCount() public view returns (uint256) {
return interactions.length;
}
}