Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: src/com/bitsofproof/supernode/core/Script.java
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- --- src/com/bitsofproof/supernode/core/Script.java (revision dcf8d41552a06f436fac915a260734d8c4335e03)
- +++ src/com/bitsofproof/supernode/core/Script.java (revision )
- @@ -37,7 +37,7 @@
- {
- private Stack<byte[]> stack = new Stack<byte[]> ();
- private final Stack<byte[]> alt = new Stack<byte[]> ();
- - private Set<String> validSignatureCache = new HashSet<String> ();
- + private final Set<SigCacheKey> validSignatureCache;
- private final Tx tx;
- private int inr;
- @@ -447,7 +447,7 @@
- System.arraycopy (b, 0, tmp, 0, b.length);
- b = tmp;
- }
- - return Arrays.equals (a, b);
- + return Arrays.equals(a, b);
- }
- private boolean isFalse (byte[] b)
- @@ -473,15 +473,17 @@
- public Script ()
- {
- this.tx = null;
- + validSignatureCache = new HashSet<SigCacheKey> ();
- - }
- + }
- public Script (Tx tx, int inr)
- {
- this.tx = tx;
- this.inr = inr;
- + validSignatureCache = new HashSet<SigCacheKey> ();
- - }
- + }
- - public Script (Tx tx, int inr, Set<String> sigCache)
- + public Script (Tx tx, int inr, Set<SigCacheKey> sigCache)
- {
- this.tx = tx;
- this.inr = inr;
- @@ -1562,14 +1564,45 @@
- {
- return false;
- }
- - StringBuffer c = new StringBuffer ();
- - c.append (ByteUtils.toHex (sig));
- - c.append (ByteUtils.toHex (pubkey));
- - c.append (ByteUtils.toHex (hash));
- - String cacheKey = c.toString ();
- + SigCacheKey cacheKey = new SigCacheKey(sig, pubkey, hash);
- synchronized ( validSignatureCache )
- {
- return validSignatureCache.contains (cacheKey) || ECKeyPair.verify (hash, sig, pubkey) && validSignatureCache.add (cacheKey);
- + }
- + }
- +
- + public final static class SigCacheKey{
- + final byte[] sig;
- + final byte[] pubkey;
- + final byte[] hash;
- +
- + private SigCacheKey(byte[] sig, byte[] pubkey, byte[] hash) {
- + //eventually check for non-nullness of params
- + this.sig = sig;
- + this.pubkey = pubkey;
- + this.hash = hash;
- + }
- +
- + @Override
- + public boolean equals(Object o) {
- + if (this == o) return true;
- + if (o == null || getClass() != o.getClass()) return false;
- +
- + SigCacheKey that = (SigCacheKey) o;
- +
- + if (!Arrays.equals(hash, that.hash)) return false;
- + if (!Arrays.equals(pubkey, that.pubkey)) return false;
- + if (!Arrays.equals(sig, that.sig)) return false;
- +
- + return true;
- + }
- +
- + @Override
- + public int hashCode() {
- + int result = Arrays.hashCode(sig);
- + result = 31 * result + Arrays.hashCode(pubkey);
- + result = 31 * result + Arrays.hashCode(hash);
- + return result;
- - }
- - }
- + }
- + }
- }
Advertisement
Add Comment
Please, Sign In to add comment