From 5d89af4286c6b2a13d3a79042815ad6801be3789 Mon Sep 17 00:00:00 2001
From: "Mariano Absatz (git)" <scm@baby.com.ar>
Date: Mon, 1 Apr 2019 16:19:05 -0300
Subject: [PATCH] =?UTF-8?q?'stamper'=20gen=C3=A9rico=20(basado=20en=20la?=
 =?UTF-8?q?=20tsa=20v3=20de=20Robert)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/Stamper.sol             | 69 +++++++++++++++++++++++++++++++++++++
 src/TimeStampAuthority3.sol | 60 --------------------------------
 2 files changed, 69 insertions(+), 60 deletions(-)
 create mode 100644 src/Stamper.sol
 delete mode 100644 src/TimeStampAuthority3.sol

diff --git a/src/Stamper.sol b/src/Stamper.sol
new file mode 100644
index 0000000..fa16369
--- /dev/null
+++ b/src/Stamper.sol
@@ -0,0 +1,69 @@
+// 20190401 Robert Martin-Legene <robert@nic.ar>
+// Stamper
+// vim:filetype=javascript
+
+pragma solidity ^0.5.2;
+      
+contract Stamper {
+    struct          stamp {
+        uint256         object;
+        address         stamper;
+        uint256         blockno;
+    }
+    stamp[]         stamplist;
+
+    // Mapping de objects stampeados a la stamplist
+    mapping ( uint256 => uint256[] )  hashobjects;
+
+    // Mapping de cuentas que stampean (stampers) a la stamplist
+    mapping ( address => uint256[] )  hashstampers;
+
+    constructor() public {
+        // No queremos que haya stamps asociados a la posicion 0 (== false)
+        // entonces guardamos ahi informacion de quien creo el SC y en que bloque
+        stamplist.push( stamp( 0, msg.sender, block.number) );
+    }
+
+    // Stampear una lista de objects (hashes)
+    function put( uint256[] memory objectlist ) public {
+        uint256     i           =   0;
+        uint256     max         =   objectlist.length;
+        while ( i<max )
+        {
+            uint256     h       =   objectlist[i];
+                    // stamplist.push devuelve la longitud, restamos 1 para usar como indice
+            uint256     idx     =   stamplist.push( stamp( h, msg.sender, block.number ) ) - 1;
+            hashobjects[h].push( idx );
+            hashstampers[msg.sender].push( idx );
+            i++;
+        }
+    }
+
+    // devuelve un stamp completo (object, stamper, blockno) de la lista
+    function getStamplistPos( uint256 pos ) public view returns ( uint256, address, uint256 )
+    {
+        return  (stamplist[pos].object, stamplist[pos].stamper, stamplist[pos].blockno );
+    }
+    
+    // devuelve la cantidad de stamps que hay de este object
+    function getObjectCount( uint256 object ) public view returns (uint256) {
+    return hashobjects[object].length;
+    }
+
+    // devuelve la ubicacion en la stamplist de un stamp especifico de este object
+    function getObjectPos( uint256 object, uint256 pos ) public view returns (uint256)
+    {
+        return hashobjects[object][pos];
+    }
+
+    // devuelve la cantidad de stamps que realizo este stamper
+    function getStamperCount( address stamper ) public view returns (uint256) {
+    return hashstampers[stamper].length;
+    }
+
+    // devuelve la ubicacion en la sstamplist de un stamp especifico de este stamper
+    function getObjectPos( address stamper, uint256 pos ) public view returns (uint256)
+    {
+        return hashstampers[stamper][pos];
+    }
+}
diff --git a/src/TimeStampAuthority3.sol b/src/TimeStampAuthority3.sol
deleted file mode 100644
index 542feeb..0000000
--- a/src/TimeStampAuthority3.sol
+++ /dev/null
@@ -1,60 +0,0 @@
-// 20180718 Robert Martin-Legene <robert@nic.ar>
-// Time stamp authority
-// vim:filetype=javascript
-
-pragma solidity ^0.5.2;
-      
-contract TimeStampAuthority {
-    struct          stamp {
-        uint256         stamped;
-        address         stamper;
-        uint256         blockno;
-    }
-    stamp[]         stamplist;
-    // Provide mappings from what is being stamped, back to the stamplist
-    mapping ( uint256 => uint256[] )  hashstamped;
-    // Provide mappings from who is stamping, back to the stamplist
-    mapping ( address => uint256[] )  hashstamper;
-    constructor() public {
-        // We don't like to assign anything to position 0, so we fill
-        // it with a dummy which just happens to also have information
-        // about the creator and the blocknumber it was created.
-        stamplist.push( stamp( 0, msg.sender, block.number) );
-    }
-    // Stores hashes (256 bit uint) in the mapping
-    function put( uint256[] memory hasharray ) public {
-        uint256     i           =   0;
-        uint256     max         =   hasharray.length;
-        while ( i<max )
-        {
-            uint256     h       =   hasharray[i];
-            uint256     idx     =   stamplist.push( stamp( h, msg.sender, block.number ) ) - 1;
-            hashstamped[h].push( idx );
-            hashstamper[msg.sender].push( idx );
-            i++;
-        }
-    }
-
-    function getStamplistPos( uint256 pos ) public view returns ( uint256, address, uint256 )
-    {
-        return  (stamplist[pos].stamped, stamplist[pos].stamper, stamplist[pos].blockno );
-    }
-    // returns the number of stamps stored with this hash
-    function getStampedCount( uint256 hash ) public view returns (uint256) {
-	return hashstamped[hash].length;
-    }
-    // returns the index position into the stamplist
-    function getStampedPos( uint256 hash, uint256 pos ) public view returns (uint256)
-    {
-        return hashstamped[hash][pos];
-    }
-    // returns the number of stamps stored from this sender
-    function getStamperCount( address sndr ) public view returns (uint256) {
-	return hashstamper[sndr].length;
-    }
-    // returns the index position into the stamplist
-    function getStampedPos( address sndr, uint256 pos ) public view returns (uint256)
-    {
-        return hashstamper[sndr][pos];
-    }
-}
-- 
GitLab