Skip to content

Commit

Permalink
UTXO: Make index, hash and value the identity.
Browse files Browse the repository at this point in the history
 Conflicts:
	core/src/main/java/org/bitcoinj/core/UTXO.java
  • Loading branch information
Andreas Schildbach authored and ripcurlx committed Aug 23, 2021
1 parent 0e0280f commit eb5851f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/src/main/java/org/bitcoinj/core/UTXO.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.math.*;
import java.util.Locale;

import static com.google.common.base.Preconditions.checkNotNull;

// TODO: Fix this class: should not talk about addresses, height should be optional/support mempool height etc

/**
Expand Down Expand Up @@ -75,9 +77,9 @@ public UTXO(Sha256Hash hash,
boolean coinbase,
Script script,
String address) {
this.hash = hash;
this.hash = checkNotNull(hash);
this.index = index;
this.value = value;
this.value = checkNotNull(value);
this.height = height;
this.script = script;
this.coinbase = coinbase;
Expand Down Expand Up @@ -126,15 +128,15 @@ public String toString() {

@Override
public int hashCode() {
return Objects.hashCode(getIndex(), getHash());
return Objects.hashCode(getIndex(), getHash(), getValue());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UTXO other = (UTXO) o;
return getIndex() == other.getIndex() && getHash().equals(other.getHash());
return getIndex() == other.getIndex() && getHash().equals(other.getHash()) && getValue().equals(((UTXO) o).getValue());
}

public void serializeToStream(OutputStream bos) throws IOException {
Expand Down

0 comments on commit eb5851f

Please sign in to comment.