From d76d39a9de57e44f187ebdda678ee0d7645f1757 Mon Sep 17 00:00:00 2001 From: lvaccaro Date: Wed, 8 Mar 2017 15:12:44 +0100 Subject: [PATCH] Fix upgrade timestamp on pending --- src/main/java/com/eternitywall/Calendar.java | 8 +--- .../java/com/eternitywall/OpenTimestamps.java | 37 +++++++++++-------- src/main/java/com/eternitywall/OtsCli.java | 2 +- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/eternitywall/Calendar.java b/src/main/java/com/eternitywall/Calendar.java index dba1abb..fec9e6f 100644 --- a/src/main/java/com/eternitywall/Calendar.java +++ b/src/main/java/com/eternitywall/Calendar.java @@ -97,14 +97,8 @@ public Timestamp getTimestamp(byte[] commitment) { Timestamp timestamp = Timestamp.deserialize(ctx, commitment); return timestamp; - } catch (ProtocolException e) { - e.printStackTrace(); - return null; - } catch (IOException e) { - e.printStackTrace(); - return null; } catch (Exception e) { - e.printStackTrace(); + //e.printStackTrace(); return null; } } diff --git a/src/main/java/com/eternitywall/OpenTimestamps.java b/src/main/java/com/eternitywall/OpenTimestamps.java index 3308bac..4b0ea1d 100644 --- a/src/main/java/com/eternitywall/OpenTimestamps.java +++ b/src/main/java/com/eternitywall/OpenTimestamps.java @@ -426,9 +426,11 @@ private static boolean upgradeTimestamp(Timestamp timestamp) { Calendar calendar = new Calendar(calendarUrl); Timestamp upgradedStamp = OpenTimestamps.upgradeStamp(subStamp, calendar, commitment, existingAttestations); - subStamp.merge(upgradedStamp); - upgraded = true; - return upgraded; + if(upgradedStamp != null) { + subStamp.merge(upgradedStamp); + upgraded = true; + return upgraded; + } } } } @@ -437,6 +439,10 @@ private static boolean upgradeTimestamp(Timestamp timestamp) { private static Timestamp upgradeStamp(Timestamp subStamp, Calendar calendar, byte[] commitment, Set existingAttestations) { Timestamp upgradedStamp = calendar.getTimestamp(commitment); + if (upgradedStamp == null) { + return null; + } + Set attsFromRemote = upgradedStamp.getAttestations(); if (attsFromRemote.size() > 0) { // log.info(attsFromRemote.size + ' attestation(s) from ' + calendar.url); @@ -446,20 +452,19 @@ private static Timestamp upgradeStamp(Timestamp subStamp, Calendar calendar, byt Set newAttestations = attsFromRemote; newAttestations.removeAll(existingAttestations); - if (newAttestations.size() > 0) { - // changed & found_new_attestations - // foundNewAttestations = true; - // log.info(attsFromRemote.size + ' attestation(s) from ' + calendar.url); - - // Set union of existingAttestations & newAttestations - existingAttestations.addAll(newAttestations); - - return upgradedStamp; - // subStamp.merge(upgradedStamp); - // args.cache.merge(upgraded_stamp) - // sub_stamp.merge(upgraded_stamp) - } else { + if (newAttestations.size() == 0) { return null; } + // changed & found_new_attestations + // foundNewAttestations = true; + // log.info(attsFromRemote.size + ' attestation(s) from ' + calendar.url); + + // Set union of existingAttestations & newAttestations + existingAttestations.addAll(newAttestations); + + return upgradedStamp; + // subStamp.merge(upgradedStamp); + // args.cache.merge(upgraded_stamp) + // sub_stamp.merge(upgraded_stamp) } } \ No newline at end of file diff --git a/src/main/java/com/eternitywall/OtsCli.java b/src/main/java/com/eternitywall/OtsCli.java index 12ef1fc..71d1f61 100644 --- a/src/main/java/com/eternitywall/OtsCli.java +++ b/src/main/java/com/eternitywall/OtsCli.java @@ -151,8 +151,8 @@ public static void upgrade (String argsOts) { //System.out.println(Utils.bytesToHex(upgradeResult)); // Copy Bak File + byte[] byteBak = Files.readAllBytes(pathOts); Path pathBak = Paths.get(argsOts+".bak"); - byte[] byteBak = Files.readAllBytes(pathBak); Files.write(pathBak, byteBak); // Write new Upgrade Result