Skip to content

Commit

Permalink
Implement equals/hashCode on TransactionInput.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehearn committed Apr 22, 2014
1 parent c43362e commit dd7973c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions core/src/main/java/com/google/bitcoin/core/TransactionInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.OutputStream;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Map;

import static com.google.common.base.Preconditions.checkElementIndex;
Expand Down Expand Up @@ -422,4 +423,34 @@ public void verify(TransactionOutput output) throws VerificationException {
public TransactionOutput getConnectedOutput() {
return getOutpoint().getConnectedOutput();
}

/** Returns a copy of the input detached from its containing transaction, if need be. */
public TransactionInput duplicateDetached() {
return new TransactionInput(params, null, bitcoinSerialize(), 0);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

TransactionInput input = (TransactionInput) o;

if (sequence != input.sequence) return false;
if (!outpoint.equals(input.outpoint)) return false;
if (!Arrays.equals(scriptBytes, input.scriptBytes)) return false;
if (scriptSig != null ? !scriptSig.equals(input.scriptSig) : input.scriptSig != null) return false;
if (parentTransaction != input.parentTransaction) return false;

return true;
}

@Override
public int hashCode() {
int result = (int) (sequence ^ (sequence >>> 32));
result = 31 * result + outpoint.hashCode();
result = 31 * result + (scriptBytes != null ? Arrays.hashCode(scriptBytes) : 0);
result = 31 * result + (scriptSig != null ? scriptSig.hashCode() : 0);
return result;
}
}

0 comments on commit dd7973c

Please sign in to comment.