Guest User

Untitled

a guest
Nov 12th, 2012
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. Index: src/com/bitsofproof/supernode/core/Script.java
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- src/com/bitsofproof/supernode/core/Script.java (revision dcf8d41552a06f436fac915a260734d8c4335e03)
  7. +++ src/com/bitsofproof/supernode/core/Script.java (revision )
  8. @@ -37,7 +37,7 @@
  9. {
  10. private Stack<byte[]> stack = new Stack<byte[]> ();
  11. private final Stack<byte[]> alt = new Stack<byte[]> ();
  12. - private Set<String> validSignatureCache = new HashSet<String> ();
  13. + private final Set<SigCacheKey> validSignatureCache;
  14. private final Tx tx;
  15. private int inr;
  16.  
  17. @@ -447,7 +447,7 @@
  18. System.arraycopy (b, 0, tmp, 0, b.length);
  19. b = tmp;
  20. }
  21. - return Arrays.equals (a, b);
  22. + return Arrays.equals(a, b);
  23. }
  24.  
  25. private boolean isFalse (byte[] b)
  26. @@ -473,15 +473,17 @@
  27. public Script ()
  28. {
  29. this.tx = null;
  30. + validSignatureCache = new HashSet<SigCacheKey> ();
  31. - }
  32. + }
  33.  
  34. public Script (Tx tx, int inr)
  35. {
  36. this.tx = tx;
  37. this.inr = inr;
  38. + validSignatureCache = new HashSet<SigCacheKey> ();
  39. - }
  40. + }
  41.  
  42. - public Script (Tx tx, int inr, Set<String> sigCache)
  43. + public Script (Tx tx, int inr, Set<SigCacheKey> sigCache)
  44. {
  45. this.tx = tx;
  46. this.inr = inr;
  47. @@ -1562,14 +1564,45 @@
  48. {
  49. return false;
  50. }
  51. - StringBuffer c = new StringBuffer ();
  52. - c.append (ByteUtils.toHex (sig));
  53. - c.append (ByteUtils.toHex (pubkey));
  54. - c.append (ByteUtils.toHex (hash));
  55. - String cacheKey = c.toString ();
  56. + SigCacheKey cacheKey = new SigCacheKey(sig, pubkey, hash);
  57. synchronized ( validSignatureCache )
  58. {
  59. return validSignatureCache.contains (cacheKey) || ECKeyPair.verify (hash, sig, pubkey) && validSignatureCache.add (cacheKey);
  60. + }
  61. + }
  62. +
  63. + public final static class SigCacheKey{
  64. + final byte[] sig;
  65. + final byte[] pubkey;
  66. + final byte[] hash;
  67. +
  68. + private SigCacheKey(byte[] sig, byte[] pubkey, byte[] hash) {
  69. + //eventually check for non-nullness of params
  70. + this.sig = sig;
  71. + this.pubkey = pubkey;
  72. + this.hash = hash;
  73. + }
  74. +
  75. + @Override
  76. + public boolean equals(Object o) {
  77. + if (this == o) return true;
  78. + if (o == null || getClass() != o.getClass()) return false;
  79. +
  80. + SigCacheKey that = (SigCacheKey) o;
  81. +
  82. + if (!Arrays.equals(hash, that.hash)) return false;
  83. + if (!Arrays.equals(pubkey, that.pubkey)) return false;
  84. + if (!Arrays.equals(sig, that.sig)) return false;
  85. +
  86. + return true;
  87. + }
  88. +
  89. + @Override
  90. + public int hashCode() {
  91. + int result = Arrays.hashCode(sig);
  92. + result = 31 * result + Arrays.hashCode(pubkey);
  93. + result = 31 * result + Arrays.hashCode(hash);
  94. + return result;
  95. - }
  96. - }
  97. + }
  98. + }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment