From 7871413573e67ed7539cf03d6deadd1a2c4abafa Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 26 May 2020 17:55:11 +0200 Subject: [PATCH] generate fresh address nodes --- .../sparrowwallet/drongo/wallet/Wallet.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index 80627a4..17b86d5 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -25,6 +25,8 @@ public class Wallet { private List keystores = new ArrayList<>(); private final List accountNodes = new ArrayList<>(); + private transient int lookAhead = DEFAULT_LOOKAHEAD; + public Wallet() { } @@ -80,7 +82,7 @@ public class Wallet { this.keystores = keystores; } - public Node getNodes(KeyPurpose keyPurpose) { + public Node getNode(KeyPurpose keyPurpose) { Node purposeNode; Optional optionalPurposeNode = accountNodes.stream().filter(node -> node.getKeyPurpose().equals(keyPurpose)).findFirst(); if(optionalPurposeNode.isEmpty()) { @@ -96,7 +98,28 @@ public class Wallet { public int getLookAhead() { //TODO: Calculate using seen transactions - return DEFAULT_LOOKAHEAD; + return lookAhead; + } + + public Node getFreshNode(KeyPurpose keyPurpose) { + //TODO: Calculate using seen transactions + return getFreshNode(keyPurpose, null); + } + + public Node getFreshNode(KeyPurpose keyPurpose, Node current) { + //TODO: Calculate using seen transactions + int index = 0; + if(current != null) { + index = current.getIndex() + 1; + } + + Node node = getNode(keyPurpose); + if(index >= node.getChildren().size()) { + lookAhead = index; + node.fillToLookAhead(lookAhead); + } + + return node.getChildren().get(index); } public Address getAddress(KeyPurpose keyPurpose, int index) { @@ -310,6 +333,10 @@ public class Wallet { this.index = index; } + public String getDerivationPath() { + return derivationPath; + } + public int getIndex() { return index; }