diff --git a/drongo b/drongo index cc4f7000..60a0d450 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit cc4f70002f64bc38307401cfecc548e0ee9adbbe +Subproject commit 60a0d450e0c35fe9e806cffb587fcb4edd603377 diff --git a/src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java b/src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java index 6effb440..5c3fc1e4 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java @@ -13,6 +13,7 @@ import com.sparrowwallet.drongo.protocol.Sha256Hash; import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.wallet.TransactionReference; import com.sparrowwallet.drongo.wallet.Wallet; +import com.sparrowwallet.drongo.wallet.WalletNode; import javafx.concurrent.Service; import javafx.concurrent.Task; import org.jetbrains.annotations.NotNull; @@ -77,19 +78,19 @@ public class ElectrumServer { getMempool(wallet, wallet.getNode(keyPurpose).getChildren()); } - public void getHistory(Wallet wallet, Collection nodes) throws ServerException { + public void getHistory(Wallet wallet, Collection nodes) throws ServerException { getReferences(wallet, "blockchain.scripthash.get_history", nodes); } - public void getMempool(Wallet wallet, Collection nodes) throws ServerException { + public void getMempool(Wallet wallet, Collection nodes) throws ServerException { getReferences(wallet, "blockchain.scripthash.get_mempool", nodes); } - public void getReferences(Wallet wallet, String method, Collection nodes) throws ServerException { + public void getReferences(Wallet wallet, String method, Collection nodes) throws ServerException { try { JsonRpcClient client = new JsonRpcClient(getTransport()); BatchRequestBuilder batchRequest = client.createBatchRequest().keysType(String.class).returnType(ScriptHashTx[].class); - for(Wallet.Node node : nodes) { + for(WalletNode node : nodes) { batchRequest.add(node.getDerivationPath(), method, getScriptHash(wallet, node)); } Map result = batchRequest.execute(); @@ -97,9 +98,9 @@ public class ElectrumServer { for(String path : result.keySet()) { ScriptHashTx[] txes = result.get(path); - Optional optionalNode = nodes.stream().filter(n -> n.getDerivationPath().equals(path)).findFirst(); + Optional optionalNode = nodes.stream().filter(n -> n.getDerivationPath().equals(path)).findFirst(); if(optionalNode.isPresent()) { - Wallet.Node node = optionalNode.get(); + WalletNode node = optionalNode.get(); Set references = Arrays.stream(txes).map(ScriptHashTx::getTransactionReference).collect(Collectors.toSet()); for(TransactionReference reference : references) { @@ -129,9 +130,9 @@ public class ElectrumServer { } public void getReferencedTransactions(Wallet wallet, KeyPurpose keyPurpose) throws ServerException { - Wallet.Node purposeNode = wallet.getNode(keyPurpose); + WalletNode purposeNode = wallet.getNode(keyPurpose); Set references = new HashSet<>(); - for(Wallet.Node addressNode : purposeNode.getChildren()) { + for(WalletNode addressNode : purposeNode.getChildren()) { references.addAll(addressNode.getHistory()); } @@ -163,7 +164,7 @@ public class ElectrumServer { } } - private String getScriptHash(Wallet wallet, Wallet.Node node) { + private String getScriptHash(Wallet wallet, WalletNode node) { byte[] hash = Sha256Hash.hash(wallet.getOutputScript(node).getProgram()); byte[] reversed = Utils.reverseBytes(hash); return Utils.bytesToHex(reversed); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java index b3f19e06..54d23ef2 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java @@ -9,6 +9,7 @@ import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.wallet.Keystore; import com.sparrowwallet.drongo.wallet.MnemonicException; import com.sparrowwallet.drongo.wallet.Wallet; +import com.sparrowwallet.drongo.wallet.WalletNode; import javafx.concurrent.Service; import javafx.concurrent.Task; @@ -62,8 +63,8 @@ public class Storage { gsonBuilder.registerTypeAdapter(Transaction.class, new TransactionDeserializer()); if(includeWalletSerializers) { gsonBuilder.registerTypeAdapter(Keystore.class, new KeystoreSerializer()); - gsonBuilder.registerTypeAdapter(Wallet.Node.class, new NodeSerializer()); - gsonBuilder.registerTypeAdapter(Wallet.Node.class, new NodeDeserializer()); + gsonBuilder.registerTypeAdapter(WalletNode.class, new NodeSerializer()); + gsonBuilder.registerTypeAdapter(WalletNode.class, new NodeDeserializer()); } return gsonBuilder.setPrettyPrinting().disableHtmlEscaping().create(); @@ -304,9 +305,9 @@ public class Storage { } } - private static class NodeSerializer implements JsonSerializer { + private static class NodeSerializer implements JsonSerializer { @Override - public JsonElement serialize(Wallet.Node node, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(WalletNode node, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObject = (JsonObject)getGson(false).toJsonTree(node); JsonArray children = jsonObject.getAsJsonArray("children"); @@ -330,11 +331,11 @@ public class Storage { } } - private static class NodeDeserializer implements JsonDeserializer { + private static class NodeDeserializer implements JsonDeserializer { @Override - public Wallet.Node deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - Wallet.Node node = getGson(false).fromJson(json, typeOfT); - for(Wallet.Node childNode : node.getChildren()) { + public WalletNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + WalletNode node = getGson(false).fromJson(json, typeOfT); + for(WalletNode childNode : node.getChildren()) { if(childNode.getChildren() == null) { childNode.setChildren(new TreeSet<>()); } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/NodeEntry.java b/src/main/java/com/sparrowwallet/sparrow/wallet/NodeEntry.java index 7c2406e2..4fb969f1 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/NodeEntry.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/NodeEntry.java @@ -3,14 +3,15 @@ package com.sparrowwallet.sparrow.wallet; import com.sparrowwallet.drongo.address.Address; import com.sparrowwallet.drongo.protocol.Script; import com.sparrowwallet.drongo.wallet.Wallet; +import com.sparrowwallet.drongo.wallet.WalletNode; import java.util.stream.Collectors; public class NodeEntry extends Entry { private final Wallet wallet; - private final Wallet.Node node; + private final WalletNode node; - public NodeEntry(Wallet wallet, Wallet.Node node) { + public NodeEntry(Wallet wallet, WalletNode node) { super(node.getLabel(), node.getChildren().stream().map(childNode -> new NodeEntry(wallet, childNode)).collect(Collectors.toList())); this.wallet = wallet; this.node = node; @@ -37,7 +38,7 @@ public class NodeEntry extends Entry { return null; } - public Wallet.Node getNode() { + public WalletNode getNode() { return node; } } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java index 6ef64b24..18eca127 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java @@ -2,6 +2,7 @@ package com.sparrowwallet.sparrow.wallet; import com.sparrowwallet.drongo.KeyPurpose; import com.sparrowwallet.drongo.wallet.Wallet; +import com.sparrowwallet.drongo.wallet.WalletNode; import com.sparrowwallet.sparrow.io.Storage; import java.io.File; @@ -50,7 +51,7 @@ public class WalletForm { if(optionalPurposeEntry.isPresent()) { purposeEntry = optionalPurposeEntry.get(); } else { - Wallet.Node purposeNode = getWallet().getNode(keyPurpose); + WalletNode purposeNode = getWallet().getNode(keyPurpose); purposeEntry = new NodeEntry(getWallet(), purposeNode); accountEntries.add(purposeEntry); } @@ -60,7 +61,7 @@ public class WalletForm { public NodeEntry getFreshNodeEntry(KeyPurpose keyPurpose, NodeEntry currentEntry) { NodeEntry rootEntry = getNodeEntry(keyPurpose); - Wallet.Node freshNode = getWallet().getFreshNode(keyPurpose, currentEntry == null ? null : currentEntry.getNode()); + WalletNode freshNode = getWallet().getFreshNode(keyPurpose, currentEntry == null ? null : currentEntry.getNode()); for(Entry childEntry : rootEntry.getChildren()) { NodeEntry nodeEntry = (NodeEntry)childEntry;