mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-23 20:36:44 +00:00
refactor wallet node to non inner class
This commit is contained in:
parent
5223fe8d8c
commit
7e8496915a
5 changed files with 27 additions and 23 deletions
2
drongo
2
drongo
|
@ -1 +1 @@
|
|||
Subproject commit cc4f70002f64bc38307401cfecc548e0ee9adbbe
|
||||
Subproject commit 60a0d450e0c35fe9e806cffb587fcb4edd603377
|
|
@ -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<Wallet.Node> nodes) throws ServerException {
|
||||
public void getHistory(Wallet wallet, Collection<WalletNode> nodes) throws ServerException {
|
||||
getReferences(wallet, "blockchain.scripthash.get_history", nodes);
|
||||
}
|
||||
|
||||
public void getMempool(Wallet wallet, Collection<Wallet.Node> nodes) throws ServerException {
|
||||
public void getMempool(Wallet wallet, Collection<WalletNode> nodes) throws ServerException {
|
||||
getReferences(wallet, "blockchain.scripthash.get_mempool", nodes);
|
||||
}
|
||||
|
||||
public void getReferences(Wallet wallet, String method, Collection<Wallet.Node> nodes) throws ServerException {
|
||||
public void getReferences(Wallet wallet, String method, Collection<WalletNode> nodes) throws ServerException {
|
||||
try {
|
||||
JsonRpcClient client = new JsonRpcClient(getTransport());
|
||||
BatchRequestBuilder<String, ScriptHashTx[]> 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<String, ScriptHashTx[]> result = batchRequest.execute();
|
||||
|
@ -97,9 +98,9 @@ public class ElectrumServer {
|
|||
for(String path : result.keySet()) {
|
||||
ScriptHashTx[] txes = result.get(path);
|
||||
|
||||
Optional<Wallet.Node> optionalNode = nodes.stream().filter(n -> n.getDerivationPath().equals(path)).findFirst();
|
||||
Optional<WalletNode> optionalNode = nodes.stream().filter(n -> n.getDerivationPath().equals(path)).findFirst();
|
||||
if(optionalNode.isPresent()) {
|
||||
Wallet.Node node = optionalNode.get();
|
||||
WalletNode node = optionalNode.get();
|
||||
Set<TransactionReference> 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<TransactionReference> 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);
|
||||
|
|
|
@ -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<Wallet.Node> {
|
||||
private static class NodeSerializer implements JsonSerializer<WalletNode> {
|
||||
@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<Wallet.Node> {
|
||||
private static class NodeDeserializer implements JsonDeserializer<WalletNode> {
|
||||
@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<>());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue