mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-20 10:12:19 +01:00
TransactionOutput: add equals/hashcode/duplicateDetached methods.
This commit is contained in:
parent
af07acd1b6
commit
782edd8ea8
@ -28,6 +28,7 @@ import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
|
||||
@ -332,4 +333,30 @@ public class TransactionOutput extends ChildMessage implements Serializable {
|
||||
maybeParse();
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
|
||||
/** Returns a copy of the output detached from its containing transaction, if need be. */
|
||||
public TransactionOutput duplicateDetached() {
|
||||
return new TransactionOutput(params, null, value, org.spongycastle.util.Arrays.clone(scriptBytes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
TransactionOutput output = (TransactionOutput) o;
|
||||
|
||||
if (!Arrays.equals(scriptBytes, output.scriptBytes)) return false;
|
||||
if (value != null ? !value.equals(output.value) : output.value != null) return false;
|
||||
if (parentTransaction != null && parentTransaction != output.parentTransaction) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = value != null ? value.hashCode() : 0;
|
||||
result = 31 * result + (scriptBytes != null ? Arrays.hashCode(scriptBytes) : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user