Browse Source

identify and color code signatures in transaction hex witness data

terminal
Craig Raw 3 years ago
parent
commit
281fad5970
  1. 18
      src/main/java/com/sparrowwallet/sparrow/control/TransactionHexArea.java
  2. 1
      src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css
  3. 1
      src/main/resources/com/sparrowwallet/sparrow/transaction/input.css
  4. 1
      src/main/resources/com/sparrowwallet/sparrow/transaction/inputs.css
  5. 1
      src/main/resources/com/sparrowwallet/sparrow/transaction/output.css
  6. 1
      src/main/resources/com/sparrowwallet/sparrow/transaction/outputs.css

18
src/main/java/com/sparrowwallet/sparrow/control/TransactionHexArea.java

@ -165,8 +165,9 @@ public class TransactionHexArea extends CodeArea {
for(int j = 0; j < witness.getPushes().size(); j++) {
byte[] push = witness.getPushes().get(j);
VarInt witnessLen = new VarInt(push.length);
boolean isSignature = isSignature(push);
cursor = addSegment(segments, cursor, witnessLen.getSizeInBytes() * 2, i, j, "witness-" + getIndexedStyleClass(i, selectedInputIndex, "length"));
cursor = addSegment(segments, cursor, (int) witnessLen.value * 2, i, j, "witness-" + getIndexedStyleClass(i, selectedInputIndex, "data"));
cursor = addSegment(segments, cursor, (int) witnessLen.value * 2, i, j, "witness-" + getIndexedStyleClass(i, selectedInputIndex, "data" + (isSignature ? "-signature" : "")));
}
}
}
@ -204,6 +205,19 @@ public class TransactionHexArea extends CodeArea {
return "other";
}
private boolean isSignature(byte[] data) {
if(data.length >= 64) {
try {
TransactionSignature.decodeFromBitcoin(data, false);
return true;
} catch(Exception e) {
//ignore, not a signature
}
}
return false;
}
private String describeTransactionPart(Collection<String> styles) {
String style = "";
Integer index = null;
@ -238,7 +252,7 @@ public class TransactionHexArea extends CodeArea {
case "output-pubkeyscript" -> "Output #" + index + " scriptPubKey";
case "witness-count" -> "Input #" + index + " witness count";
case "witness-length" -> "Input #" + index + " witness #" + witnessIndex + " length";
case "witness-data" -> "Input #" + index + " witness #" + witnessIndex + " data";
case "witness-data", "witness-data-signature" -> "Input #" + index + " witness #" + witnessIndex + " data";
case "locktime" -> "Locktime";
default -> "";
};

1
src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css

@ -17,6 +17,7 @@
.witness-count { -fx-fill: color-0 }
.witness-length { -fx-fill: color-6 }
.witness-data { -fx-fill: color-6 }
.witness-data-signature { -fx-fill: color-3 }
.locktime { -fx-fill: color-7 }

1
src/main/resources/com/sparrowwallet/sparrow/transaction/input.css

@ -21,6 +21,7 @@
.witness-count { -fx-fill: color-0 }
.witness-length { -fx-fill: color-7 }
.witness-data { -fx-fill: color-6 }
.witness-data-signature { -fx-fill: color-3 }
.locktime { -fx-fill: color-grey }

1
src/main/resources/com/sparrowwallet/sparrow/transaction/inputs.css

@ -17,6 +17,7 @@
.witness-count { -fx-fill: color-0 }
.witness-length { -fx-fill: color-7 }
.witness-data { -fx-fill: color-6 }
.witness-data-signature { -fx-fill: color-3 }
.locktime { -fx-fill: color-grey }

1
src/main/resources/com/sparrowwallet/sparrow/transaction/output.css

@ -19,6 +19,7 @@
.witness-count { -fx-fill: color-grey }
.witness-length { -fx-fill: color-grey }
.witness-data { -fx-fill: color-grey }
.witness-data-signature { -fx-fill: color-grey }
.locktime { -fx-fill: color-grey }

1
src/main/resources/com/sparrowwallet/sparrow/transaction/outputs.css

@ -17,6 +17,7 @@
.witness-count { -fx-fill: color-grey }
.witness-length { -fx-fill: color-grey }
.witness-data { -fx-fill: color-grey }
.witness-data-signature { -fx-fill: color-grey }
.locktime { -fx-fill: color-grey }

Loading…
Cancel
Save