Skip to content

Commit

Permalink
Sort on attestations
Browse files Browse the repository at this point in the history
  • Loading branch information
lvaccaro committed Mar 4, 2017
1 parent 334549c commit 6718bc7
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
out/
.idea/
target/
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Created by luca on 25/02/2017.
*/

import java.util.Arrays;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -59,4 +60,11 @@ public void serializePayload(StreamSerializationContext ctx) {
public String toString() {
return "com.eternitywall.BitcoinBlockHeaderAttestation(" + this.height + ")";
}


@Override
public int compareTo(TimeAttestation o) {
BitcoinBlockHeaderAttestation ob = (BitcoinBlockHeaderAttestation) o;
return this.height - ob.height;
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/eternitywall/PendingAttestation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.eternitywall;

import org.bouncycastle.util.Arrays;

import java.nio.charset.StandardCharsets;
import java.util.logging.Logger;

Expand Down Expand Up @@ -78,4 +80,10 @@ public void serializePayload(StreamSerializationContext ctx) {
public String toString() {
return "PendingAttestation(\'" + new String(this.uri, StandardCharsets.UTF_8) + "\')";
}

@Override
public int compareTo(TimeAttestation o) {
PendingAttestation opa = (PendingAttestation) o;
return Arrays.compareUnsigned(this.uri, opa.uri) ;
}
}
14 changes: 13 additions & 1 deletion src/main/java/com/eternitywall/TimeAttestation.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
*/


import com.eternitywall.op.Op;

import java.util.Arrays;
import java.util.logging.Logger;

/** Class representing com.eternitywall.Timestamp signature verification */
class TimeAttestation {
class TimeAttestation implements Comparable<TimeAttestation> {


private static Logger log = Logger.getLogger(TimeAttestation.class.getName());
Expand Down Expand Up @@ -70,4 +72,14 @@ public void serialize(StreamSerializationContext ctx) {
public void serializePayload(StreamSerializationContext ctxPayload) {

}

@Override
public int compareTo(TimeAttestation o) {
int deltaTag = org.bouncycastle.util.Arrays.compareUnsigned(this._TAG(),o._TAG());
if( deltaTag == 0){
return this.compareTo(o);
} else {
return deltaTag;
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/eternitywall/Timestamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public void serialize(StreamSerializationContext ctx) {

// sort
List<TimeAttestation> sortedAttestations = this.attestations;
Collections.sort(sortedAttestations);

if (sortedAttestations.size() > 1) {
for (int i = 0; i < sortedAttestations.size(); i++) {
ctx.writeBytes(new byte[]{(byte) 0xff, (byte) 0x00});
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/eternitywall/UnknownAttestation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.eternitywall;

import org.bouncycastle.util.Arrays;

import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -39,4 +41,11 @@ public static UnknownAttestation deserialize(StreamDeserializationContext ctxPay
public String toString() {
return "com.eternitywall.UnknownAttestation " + this._TAG() + ' ' + this.payload;
}


@Override
public int compareTo(TimeAttestation o) {
UnknownAttestation ota = (UnknownAttestation) o;
return Arrays.compareUnsigned(this.payload, ota.payload) ;
}
}

0 comments on commit 6718bc7

Please sign in to comment.