blockchain to block rename for transaction in block

This commit is contained in:
Craig Raw 2020-06-02 11:05:02 +02:00
parent 9820491cd5
commit cb18f7c4c3
5 changed files with 28 additions and 28 deletions

View file

@ -3,10 +3,10 @@ package com.sparrowwallet.drongo.wallet;
import com.sparrowwallet.drongo.protocol.Sha256Hash;
import com.sparrowwallet.drongo.protocol.Transaction;
public class BlockchainTransaction extends BlockchainTransactionHash implements Comparable<BlockchainTransaction> {
public class BlockTransaction extends BlockTransactionHash implements Comparable<BlockTransaction> {
private final Transaction transaction;
public BlockchainTransaction(Sha256Hash hash, int height, Long fee, Transaction transaction) {
public BlockTransaction(Sha256Hash hash, int height, Long fee, Transaction transaction) {
super(hash, height, fee);
this.transaction = transaction;
}
@ -16,7 +16,7 @@ public class BlockchainTransaction extends BlockchainTransactionHash implements
}
@Override
public int compareTo(BlockchainTransaction blockchainTransaction) {
public int compareTo(BlockTransaction blockchainTransaction) {
return super.compareTo(blockchainTransaction);
}
}

View file

@ -4,22 +4,22 @@ import com.sparrowwallet.drongo.protocol.Sha256Hash;
import java.util.Objects;
public abstract class BlockchainTransactionHash {
public abstract class BlockTransactionHash {
private final Sha256Hash hash;
private final int height;
private final Long fee;
private String label;
public BlockchainTransactionHash(Sha256Hash hash) {
public BlockTransactionHash(Sha256Hash hash) {
this(hash, 0, 0L);
}
public BlockchainTransactionHash(Sha256Hash hash, int height) {
public BlockTransactionHash(Sha256Hash hash, int height) {
this(hash, height, 0L);
}
public BlockchainTransactionHash(Sha256Hash hash, int height, Long fee) {
public BlockTransactionHash(Sha256Hash hash, int height, Long fee) {
this.hash = hash;
this.height = height;
this.fee = fee;
@ -58,7 +58,7 @@ public abstract class BlockchainTransactionHash {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BlockchainTransactionHash that = (BlockchainTransactionHash) o;
BlockTransactionHash that = (BlockTransactionHash) o;
return hash.equals(that.hash) && height == that.height;
}
@ -67,7 +67,7 @@ public abstract class BlockchainTransactionHash {
return Objects.hash(hash, height);
}
public int compareTo(BlockchainTransactionHash reference) {
public int compareTo(BlockTransactionHash reference) {
int heightDiff = height - reference.height;
if(heightDiff != 0) {
return heightDiff;

View file

@ -4,16 +4,16 @@ import com.sparrowwallet.drongo.protocol.Sha256Hash;
import java.util.Objects;
public class BlockchainTransactionHashIndex extends BlockchainTransactionHash implements Comparable<BlockchainTransactionHashIndex> {
public class BlockTransactionHashIndex extends BlockTransactionHash implements Comparable<BlockTransactionHashIndex> {
private final long index;
private final long value;
private BlockchainTransactionHashIndex spentBy;
private BlockTransactionHashIndex spentBy;
public BlockchainTransactionHashIndex(Sha256Hash hash, int height, Long fee, long index, long value) {
public BlockTransactionHashIndex(Sha256Hash hash, int height, Long fee, long index, long value) {
this(hash, height, fee, index, value, null);
}
public BlockchainTransactionHashIndex(Sha256Hash hash, int height, Long fee, long index, long value, BlockchainTransactionHashIndex spentBy) {
public BlockTransactionHashIndex(Sha256Hash hash, int height, Long fee, long index, long value, BlockTransactionHashIndex spentBy) {
super(hash, height, fee);
this.index = index;
this.value = value;
@ -32,11 +32,11 @@ public class BlockchainTransactionHashIndex extends BlockchainTransactionHash im
return spentBy != null;
}
public BlockchainTransactionHashIndex getSpentBy() {
public BlockTransactionHashIndex getSpentBy() {
return spentBy;
}
public void setSpentBy(BlockchainTransactionHashIndex spentBy) {
public void setSpentBy(BlockTransactionHashIndex spentBy) {
this.spentBy = spentBy;
}
@ -50,7 +50,7 @@ public class BlockchainTransactionHashIndex extends BlockchainTransactionHash im
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
BlockchainTransactionHashIndex that = (BlockchainTransactionHashIndex) o;
BlockTransactionHashIndex that = (BlockTransactionHashIndex) o;
return index == that.index;
}
@ -60,7 +60,7 @@ public class BlockchainTransactionHashIndex extends BlockchainTransactionHash im
}
@Override
public int compareTo(BlockchainTransactionHashIndex reference) {
public int compareTo(BlockTransactionHashIndex reference) {
int diff = super.compareTo(reference);
if(diff != 0) {
return diff;
@ -69,7 +69,7 @@ public class BlockchainTransactionHashIndex extends BlockchainTransactionHash im
return (int)(index - reference.index);
}
public BlockchainTransactionHashIndex copy() {
return new BlockchainTransactionHashIndex(super.getHash(), super.getHeight(), super.getFee(), index, value, spentBy.copy());
public BlockTransactionHashIndex copy() {
return new BlockTransactionHashIndex(super.getHash(), super.getHeight(), super.getFee(), index, value, spentBy.copy());
}
}

View file

@ -21,7 +21,7 @@ public class Wallet {
private Policy defaultPolicy;
private List<Keystore> keystores = new ArrayList<>();
private final Set<WalletNode> purposeNodes = new TreeSet<>();
private final Map<Sha256Hash, BlockchainTransaction> transactions = new HashMap<>();
private final Map<Sha256Hash, BlockTransaction> transactions = new HashMap<>();
public Wallet() {
}
@ -82,7 +82,7 @@ public class Wallet {
return purposeNodes;
}
public Map<Sha256Hash, BlockchainTransaction> getTransactions() {
public Map<Sha256Hash, BlockTransaction> getTransactions() {
return transactions;
}

View file

@ -11,7 +11,7 @@ public class WalletNode implements Comparable<WalletNode> {
private final String derivationPath;
private String label;
private Set<WalletNode> children = new TreeSet<>();
private Set<BlockchainTransactionHashIndex> transactionOutputs = new TreeSet<>();
private Set<BlockTransactionHashIndex> transactionOutputs = new TreeSet<>();
private transient KeyPurpose keyPurpose;
private transient int index = -1;
@ -83,7 +83,7 @@ public class WalletNode implements Comparable<WalletNode> {
return null;
}
return getUnspentTransactionOutputs().stream().mapToLong(BlockchainTransactionHashIndex::getValue).sum();
return getUnspentTransactionOutputs().stream().mapToLong(BlockTransactionHashIndex::getValue).sum();
}
public Set<WalletNode> getChildren() {
@ -94,16 +94,16 @@ public class WalletNode implements Comparable<WalletNode> {
this.children = children;
}
public Set<BlockchainTransactionHashIndex> getTransactionOutputs() {
public Set<BlockTransactionHashIndex> getTransactionOutputs() {
return transactionOutputs;
}
public void setTransactionOutputs(Set<BlockchainTransactionHashIndex> transactionOutputs) {
public void setTransactionOutputs(Set<BlockTransactionHashIndex> transactionOutputs) {
this.transactionOutputs = transactionOutputs;
}
public Set<BlockchainTransactionHashIndex> getUnspentTransactionOutputs() {
Set<BlockchainTransactionHashIndex> unspentTXOs = new TreeSet<>(transactionOutputs);
public Set<BlockTransactionHashIndex> getUnspentTransactionOutputs() {
Set<BlockTransactionHashIndex> unspentTXOs = new TreeSet<>(transactionOutputs);
return unspentTXOs.stream().filter(txo -> !txo.isSpent()).collect(Collectors.toCollection(HashSet::new));
}
@ -163,7 +163,7 @@ public class WalletNode implements Comparable<WalletNode> {
copy.getChildren().add(child.copy());
}
for(BlockchainTransactionHashIndex txo : getTransactionOutputs()) {
for(BlockTransactionHashIndex txo : getTransactionOutputs()) {
copy.getTransactionOutputs().add(txo.copy());
}