Skip to content
Snippets Groups Projects
Commit a7027dc8 authored by Mariano Absatz (git)'s avatar Mariano Absatz (git)
Browse files

Agrego comentarios y aclaraciones. El código del smart contract en sí es idéntico

parent d257f8b6
No related branches found
No related tags found
No related merge requests found
// 20190401 Robert Martin-Legene <robert@nic.ar> // 20190401 Robert Martin-Legene <robert@nic.ar>
// 20190507 Andres Blanco <ablanco@siu.edu.ar>
// Stamper // Stamper
// vim:filetype=javascript // vim:filetype=javascript
...@@ -10,6 +11,8 @@ contract Stamper { ...@@ -10,6 +11,8 @@ contract Stamper {
address stamper; address stamper;
uint256 blockNo; uint256 blockNo;
} }
// Lista de stamps (cada entrada tiene el hash del object, la cuenta que lo envio
// y el numero de bloque en que se guardo)
Stamp[] stampList; Stamp[] stampList;
// Mapping de objects stampeados a la stampList // Mapping de objects stampeados a la stampList
...@@ -35,19 +38,23 @@ contract Stamper { ...@@ -35,19 +38,23 @@ contract Stamper {
stampList.push(Stamp(0, msg.sender, block.number)); stampList.push(Stamp(0, msg.sender, block.number));
} }
// Stampear una lista de objects (hashes) // Stampear una lista de objects (hashes) recibido como array
function put( bytes32[] memory objectList ) public { function put( bytes32[] memory objectList ) public {
uint256 i = 0; uint256 i = 0;
uint256 max = objectList.length; uint256 max = objectList.length;
while ( i<max ) while ( i<max )
{ {
bytes32 h = objectList[i]; // este object
// stampList.push devuelve la longitud, restamos 1 para usar como indice bytes32 object = objectList[i];
uint256 idx = stampList.push(Stamp(h, msg.sender, block.number)) - 1; // lo agregamos a la stampList
hashObjects[h].push(idx); // stampList.push devuelve la longitud, restamos 1 para usar como indice de la nueva entrada
hashStampers[msg.sender].push(idx); uint256 newObjectIndex = stampList.push(Stamp(object, msg.sender, block.number)) - 1;
// lo mapeamos desde la lista de objects
emit Stamped(msg.sender, h, block.number); hashObjects[object].push(newObjectIndex);
// lo mapeamos desde la lista de stampers
hashStampers[msg.sender].push(newObjectIndex);
emit Stamped(msg.sender, object, block.number);
i++; i++;
} }
...@@ -71,7 +78,8 @@ contract Stamper { ...@@ -71,7 +78,8 @@ contract Stamper {
return hashObjects[object][pos]; return hashObjects[object][pos];
} }
// devuelve el nro de bloque en el que stamper registro object. Si no fue stampeado devuelve 0 // devuelve el nro de bloque en el que este stamper registro este object por primera vez
// Si no fue stampeado por este stamper devuelve 0
function getBlockNo( bytes32 object, address stamper ) public view returns (uint256) function getBlockNo( bytes32 object, address stamper ) public view returns (uint256)
{ {
uint length = hashObjects[object].length; uint length = hashObjects[object].length;
...@@ -91,7 +99,7 @@ contract Stamper { ...@@ -91,7 +99,7 @@ contract Stamper {
return hashStampers[stamper].length; return hashStampers[stamper].length;
} }
// devuelve la ubicacion en la sstamplist de un Stamp especifico de este stamper // devuelve la ubicacion en la stampList de un Stamp especifico de este stamper
function getStamperPos( address stamper, uint256 pos ) public view returns (uint256) function getStamperPos( address stamper, uint256 pos ) public view returns (uint256)
{ {
return hashStampers[stamper][pos]; return hashStampers[stamper][pos];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment