diff --git a/build.gradle b/build.gradle index af5a7b6..02c3c59 100644 --- a/build.gradle +++ b/build.gradle @@ -68,6 +68,8 @@ jar { attributes "Main-Class": "com.sparrowwallet.drongo.Main" } + exclude('logback.xml') + archiveBaseName = 'drongo' archiveVersion = '0.1' } diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/TransactionReference.java b/src/main/java/com/sparrowwallet/drongo/wallet/TransactionReference.java new file mode 100644 index 0000000..1b2cf15 --- /dev/null +++ b/src/main/java/com/sparrowwallet/drongo/wallet/TransactionReference.java @@ -0,0 +1,57 @@ +package com.sparrowwallet.drongo.wallet; + +import java.util.Objects; + +public class TransactionReference implements Comparable { + private final String transactionId; + private final Integer height; + private final Long fee; + + public TransactionReference(String transactionId) { + this(transactionId, 0, 0L); + } + + public TransactionReference(String transactionId, Integer height) { + this(transactionId, height, 0L); + } + + public TransactionReference(String transactionId, Integer height, Long fee) { + this.transactionId = transactionId; + this.height = height; + this.fee = fee; + } + + public String getTransactionId() { + return transactionId; + } + + public Integer getHeight() { + return height; + } + + public Long getFee() { + return fee; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TransactionReference that = (TransactionReference) o; + return transactionId.equals(that.transactionId); + } + + @Override + public int hashCode() { + return Objects.hash(transactionId); + } + + @Override + public int compareTo(TransactionReference reference) { + return height - reference.height; + } + + public TransactionReference copy() { + return new TransactionReference(transactionId, height, fee); + } +} diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index 6f989b2..600599b 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -11,6 +11,7 @@ import com.sparrowwallet.drongo.policy.Policy; import com.sparrowwallet.drongo.policy.PolicyType; import com.sparrowwallet.drongo.protocol.Script; import com.sparrowwallet.drongo.protocol.ScriptType; +import com.sparrowwallet.drongo.protocol.Transaction; import java.util.*; import java.util.stream.Collectors; @@ -23,7 +24,8 @@ public class Wallet { private ScriptType scriptType; private Policy defaultPolicy; private List keystores = new ArrayList<>(); - private final Set accountNodes = new TreeSet<>(); + private final Set purposeNodes = new TreeSet<>(); + private final Map transactions = new HashMap<>(); public Wallet() { } @@ -80,16 +82,20 @@ public class Wallet { this.keystores = keystores; } - private Set getAccountNodes() { - return accountNodes; + private Set getPurposeNodes() { + return purposeNodes; + } + + public Map getTransactions() { + return transactions; } public Node getNode(KeyPurpose keyPurpose) { Node purposeNode; - Optional optionalPurposeNode = accountNodes.stream().filter(node -> node.getKeyPurpose().equals(keyPurpose)).findFirst(); + Optional optionalPurposeNode = purposeNodes.stream().filter(node -> node.getKeyPurpose().equals(keyPurpose)).findFirst(); if(optionalPurposeNode.isEmpty()) { purposeNode = new Node(keyPurpose); - accountNodes.add(purposeNode); + purposeNodes.add(purposeNode); } else { purposeNode = optionalPurposeNode.get(); } @@ -272,9 +278,9 @@ public class Wallet { for(Keystore keystore : keystores) { copy.getKeystores().add(keystore.copy()); } - for(Wallet.Node node : accountNodes) { + for(Wallet.Node node : purposeNodes) { Node nodeCopy = copy.copyNode(node); - copy.getAccountNodes().add(nodeCopy); + copy.getPurposeNodes().add(nodeCopy); } return copy; } @@ -286,6 +292,9 @@ public class Wallet { for(Node child : node.getChildren()) { copy.getChildren().add(copyNode(child)); } + for(TransactionReference reference : node.getHistory()) { + copy.getHistory().add(reference.copy()); + } return copy; } @@ -349,6 +358,7 @@ public class Wallet { private String label; private Long amount; private Set children = new TreeSet<>(); + private Set history = new TreeSet<>(); private transient KeyPurpose keyPurpose; private transient int index = -1; @@ -431,6 +441,14 @@ public class Wallet { this.children = children; } + public Set getHistory() { + return history; + } + + public void setHistory(Set history) { + this.history = history; + } + public Address getAddress() { return Wallet.this.getAddress(keyPurpose, index); } diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 5e9c842..cbe6610 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -2,6 +2,8 @@ open module com.sparrowwallet.drongo { requires org.bouncycastle.provider; requires de.mkammerer.argon2; requires slf4j.api; + requires json.simple; + requires jeromq; exports com.sparrowwallet.drongo; exports com.sparrowwallet.drongo.psbt; exports com.sparrowwallet.drongo.protocol;