Skip to content

Commit

Permalink
Fix upgrade timestamp on pending
Browse files Browse the repository at this point in the history
  • Loading branch information
lvaccaro committed Mar 8, 2017
1 parent 2fd6b44 commit d76d39a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
8 changes: 1 addition & 7 deletions src/main/java/com/eternitywall/Calendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
37 changes: 21 additions & 16 deletions src/main/java/com/eternitywall/OpenTimestamps.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand All @@ -437,6 +439,10 @@ private static boolean upgradeTimestamp(Timestamp timestamp) {

private static Timestamp upgradeStamp(Timestamp subStamp, Calendar calendar, byte[] commitment, Set<TimeAttestation> existingAttestations) {
Timestamp upgradedStamp = calendar.getTimestamp(commitment);
if (upgradedStamp == null) {
return null;
}

Set<TimeAttestation> attsFromRemote = upgradedStamp.getAttestations();
if (attsFromRemote.size() > 0) {
// log.info(attsFromRemote.size + ' attestation(s) from ' + calendar.url);
Expand All @@ -446,20 +452,19 @@ private static Timestamp upgradeStamp(Timestamp subStamp, Calendar calendar, byt
Set<TimeAttestation> 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)
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/eternitywall/OtsCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d76d39a

Please sign in to comment.