From 82aadaf46fc8eea566db31a9ae4858dd0a5229b1 Mon Sep 17 00:00:00 2001 From: Robert Martin-Legene <robert@nic.ar> Date: Tue, 31 Jul 2018 11:06:54 -0300 Subject: [PATCH] bytes32 would have worked if we sent a binary string, but uint256 seems much more friendly. We also now accept an array of uint256s for put'ing. --- src/contract.TimeStampAuthority.sol | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/contract.TimeStampAuthority.sol b/src/contract.TimeStampAuthority.sol index 8b4c4e6..2282493 100644 --- a/src/contract.TimeStampAuthority.sol +++ b/src/contract.TimeStampAuthority.sol @@ -5,17 +5,22 @@ pragma solidity ^0.4.24; contract TimeStampAuthority { // This mapping is almost an "associative array" - mapping (bytes32 => uint) private hashes; + mapping (uint256 => uint) private hashstore; - // Stores the hash of the document in the mapping - function put( bytes32 hash ) public { - require( hashes[hash] == 0, "That checksum has already been stored." ); - hashes[hash] = block.number; + // Stores hashes (256 bit uint) of a document in the mapping + function put( uint256[] hasharray ) public { + uint256 i = hasharray.length; + while (i>0) { + i--; + uint256 h = hasharray[i]; + if (hashstore[h] == 0) { + hashstore[h] = block.number; + } + } } // Returns the block number in which the hash was first seen - function get( bytes32 hash ) public view returns (uint) { - require( hashes[hash] != 0, "That checksum has never been stored." ); - return hashes[hash]; + function get( uint256 hash ) public view returns (uint) { + return hashstore[hash]; } } -- GitLab