mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-27 02:26:44 +00:00
blockchain to block rename for transaction in block
This commit is contained in:
parent
9820491cd5
commit
cb18f7c4c3
5 changed files with 28 additions and 28 deletions
|
@ -3,10 +3,10 @@ package com.sparrowwallet.drongo.wallet;
|
||||||
import com.sparrowwallet.drongo.protocol.Sha256Hash;
|
import com.sparrowwallet.drongo.protocol.Sha256Hash;
|
||||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
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;
|
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);
|
super(hash, height, fee);
|
||||||
this.transaction = transaction;
|
this.transaction = transaction;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public class BlockchainTransaction extends BlockchainTransactionHash implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(BlockchainTransaction blockchainTransaction) {
|
public int compareTo(BlockTransaction blockchainTransaction) {
|
||||||
return super.compareTo(blockchainTransaction);
|
return super.compareTo(blockchainTransaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,22 +4,22 @@ import com.sparrowwallet.drongo.protocol.Sha256Hash;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class BlockchainTransactionHash {
|
public abstract class BlockTransactionHash {
|
||||||
private final Sha256Hash hash;
|
private final Sha256Hash hash;
|
||||||
private final int height;
|
private final int height;
|
||||||
private final Long fee;
|
private final Long fee;
|
||||||
|
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
public BlockchainTransactionHash(Sha256Hash hash) {
|
public BlockTransactionHash(Sha256Hash hash) {
|
||||||
this(hash, 0, 0L);
|
this(hash, 0, 0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockchainTransactionHash(Sha256Hash hash, int height) {
|
public BlockTransactionHash(Sha256Hash hash, int height) {
|
||||||
this(hash, height, 0L);
|
this(hash, height, 0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockchainTransactionHash(Sha256Hash hash, int height, Long fee) {
|
public BlockTransactionHash(Sha256Hash hash, int height, Long fee) {
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.fee = fee;
|
this.fee = fee;
|
||||||
|
@ -58,7 +58,7 @@ public abstract class BlockchainTransactionHash {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
BlockchainTransactionHash that = (BlockchainTransactionHash) o;
|
BlockTransactionHash that = (BlockTransactionHash) o;
|
||||||
return hash.equals(that.hash) && height == that.height;
|
return hash.equals(that.hash) && height == that.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public abstract class BlockchainTransactionHash {
|
||||||
return Objects.hash(hash, height);
|
return Objects.hash(hash, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(BlockchainTransactionHash reference) {
|
public int compareTo(BlockTransactionHash reference) {
|
||||||
int heightDiff = height - reference.height;
|
int heightDiff = height - reference.height;
|
||||||
if(heightDiff != 0) {
|
if(heightDiff != 0) {
|
||||||
return heightDiff;
|
return heightDiff;
|
|
@ -4,16 +4,16 @@ import com.sparrowwallet.drongo.protocol.Sha256Hash;
|
||||||
|
|
||||||
import java.util.Objects;
|
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 index;
|
||||||
private final long value;
|
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);
|
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);
|
super(hash, height, fee);
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
@ -32,11 +32,11 @@ public class BlockchainTransactionHashIndex extends BlockchainTransactionHash im
|
||||||
return spentBy != null;
|
return spentBy != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockchainTransactionHashIndex getSpentBy() {
|
public BlockTransactionHashIndex getSpentBy() {
|
||||||
return spentBy;
|
return spentBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpentBy(BlockchainTransactionHashIndex spentBy) {
|
public void setSpentBy(BlockTransactionHashIndex spentBy) {
|
||||||
this.spentBy = spentBy;
|
this.spentBy = spentBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public class BlockchainTransactionHashIndex extends BlockchainTransactionHash im
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
if (!super.equals(o)) return false;
|
if (!super.equals(o)) return false;
|
||||||
BlockchainTransactionHashIndex that = (BlockchainTransactionHashIndex) o;
|
BlockTransactionHashIndex that = (BlockTransactionHashIndex) o;
|
||||||
return index == that.index;
|
return index == that.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class BlockchainTransactionHashIndex extends BlockchainTransactionHash im
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(BlockchainTransactionHashIndex reference) {
|
public int compareTo(BlockTransactionHashIndex reference) {
|
||||||
int diff = super.compareTo(reference);
|
int diff = super.compareTo(reference);
|
||||||
if(diff != 0) {
|
if(diff != 0) {
|
||||||
return diff;
|
return diff;
|
||||||
|
@ -69,7 +69,7 @@ public class BlockchainTransactionHashIndex extends BlockchainTransactionHash im
|
||||||
return (int)(index - reference.index);
|
return (int)(index - reference.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockchainTransactionHashIndex copy() {
|
public BlockTransactionHashIndex copy() {
|
||||||
return new BlockchainTransactionHashIndex(super.getHash(), super.getHeight(), super.getFee(), index, value, spentBy.copy());
|
return new BlockTransactionHashIndex(super.getHash(), super.getHeight(), super.getFee(), index, value, spentBy.copy());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ public class Wallet {
|
||||||
private Policy defaultPolicy;
|
private Policy defaultPolicy;
|
||||||
private List<Keystore> keystores = new ArrayList<>();
|
private List<Keystore> keystores = new ArrayList<>();
|
||||||
private final Set<WalletNode> purposeNodes = new TreeSet<>();
|
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() {
|
public Wallet() {
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public class Wallet {
|
||||||
return purposeNodes;
|
return purposeNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Sha256Hash, BlockchainTransaction> getTransactions() {
|
public Map<Sha256Hash, BlockTransaction> getTransactions() {
|
||||||
return transactions;
|
return transactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class WalletNode implements Comparable<WalletNode> {
|
||||||
private final String derivationPath;
|
private final String derivationPath;
|
||||||
private String label;
|
private String label;
|
||||||
private Set<WalletNode> children = new TreeSet<>();
|
private Set<WalletNode> children = new TreeSet<>();
|
||||||
private Set<BlockchainTransactionHashIndex> transactionOutputs = new TreeSet<>();
|
private Set<BlockTransactionHashIndex> transactionOutputs = new TreeSet<>();
|
||||||
|
|
||||||
private transient KeyPurpose keyPurpose;
|
private transient KeyPurpose keyPurpose;
|
||||||
private transient int index = -1;
|
private transient int index = -1;
|
||||||
|
@ -83,7 +83,7 @@ public class WalletNode implements Comparable<WalletNode> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getUnspentTransactionOutputs().stream().mapToLong(BlockchainTransactionHashIndex::getValue).sum();
|
return getUnspentTransactionOutputs().stream().mapToLong(BlockTransactionHashIndex::getValue).sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<WalletNode> getChildren() {
|
public Set<WalletNode> getChildren() {
|
||||||
|
@ -94,16 +94,16 @@ public class WalletNode implements Comparable<WalletNode> {
|
||||||
this.children = children;
|
this.children = children;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<BlockchainTransactionHashIndex> getTransactionOutputs() {
|
public Set<BlockTransactionHashIndex> getTransactionOutputs() {
|
||||||
return transactionOutputs;
|
return transactionOutputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransactionOutputs(Set<BlockchainTransactionHashIndex> transactionOutputs) {
|
public void setTransactionOutputs(Set<BlockTransactionHashIndex> transactionOutputs) {
|
||||||
this.transactionOutputs = transactionOutputs;
|
this.transactionOutputs = transactionOutputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<BlockchainTransactionHashIndex> getUnspentTransactionOutputs() {
|
public Set<BlockTransactionHashIndex> getUnspentTransactionOutputs() {
|
||||||
Set<BlockchainTransactionHashIndex> unspentTXOs = new TreeSet<>(transactionOutputs);
|
Set<BlockTransactionHashIndex> unspentTXOs = new TreeSet<>(transactionOutputs);
|
||||||
return unspentTXOs.stream().filter(txo -> !txo.isSpent()).collect(Collectors.toCollection(HashSet::new));
|
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());
|
copy.getChildren().add(child.copy());
|
||||||
}
|
}
|
||||||
|
|
||||||
for(BlockchainTransactionHashIndex txo : getTransactionOutputs()) {
|
for(BlockTransactionHashIndex txo : getTransactionOutputs()) {
|
||||||
copy.getTransactionOutputs().add(txo.copy());
|
copy.getTransactionOutputs().add(txo.copy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue