mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-05 03:26:43 +00:00
generate fresh address nodes
This commit is contained in:
parent
eabcf4e8f4
commit
7871413573
1 changed files with 29 additions and 2 deletions
|
@ -25,6 +25,8 @@ public class Wallet {
|
||||||
private List<Keystore> keystores = new ArrayList<>();
|
private List<Keystore> keystores = new ArrayList<>();
|
||||||
private final List<Node> accountNodes = new ArrayList<>();
|
private final List<Node> accountNodes = new ArrayList<>();
|
||||||
|
|
||||||
|
private transient int lookAhead = DEFAULT_LOOKAHEAD;
|
||||||
|
|
||||||
public Wallet() {
|
public Wallet() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +82,7 @@ public class Wallet {
|
||||||
this.keystores = keystores;
|
this.keystores = keystores;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node getNodes(KeyPurpose keyPurpose) {
|
public Node getNode(KeyPurpose keyPurpose) {
|
||||||
Node purposeNode;
|
Node purposeNode;
|
||||||
Optional<Node> optionalPurposeNode = accountNodes.stream().filter(node -> node.getKeyPurpose().equals(keyPurpose)).findFirst();
|
Optional<Node> optionalPurposeNode = accountNodes.stream().filter(node -> node.getKeyPurpose().equals(keyPurpose)).findFirst();
|
||||||
if(optionalPurposeNode.isEmpty()) {
|
if(optionalPurposeNode.isEmpty()) {
|
||||||
|
@ -96,7 +98,28 @@ public class Wallet {
|
||||||
|
|
||||||
public int getLookAhead() {
|
public int getLookAhead() {
|
||||||
//TODO: Calculate using seen transactions
|
//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) {
|
public Address getAddress(KeyPurpose keyPurpose, int index) {
|
||||||
|
@ -310,6 +333,10 @@ public class Wallet {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDerivationPath() {
|
||||||
|
return derivationPath;
|
||||||
|
}
|
||||||
|
|
||||||
public int getIndex() {
|
public int getIndex() {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue