mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-27 02:26:44 +00:00
look at used transactions for fresh nodes
This commit is contained in:
parent
fa30f37e23
commit
0d56692784
2 changed files with 23 additions and 8 deletions
|
@ -101,29 +101,32 @@ public class Wallet {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLookAhead(WalletNode node) {
|
public int getLookAhead(WalletNode node) {
|
||||||
//TODO: Calculate using seen transactions
|
|
||||||
int lookAhead = DEFAULT_LOOKAHEAD;
|
int lookAhead = DEFAULT_LOOKAHEAD;
|
||||||
Integer maxIndex = node.getHighestUsedIndex();
|
Integer highestUsed = node.getHighestUsedIndex();
|
||||||
if(maxIndex != null) {
|
if(highestUsed != null) {
|
||||||
lookAhead = Math.max(maxIndex + lookAhead/2, lookAhead);
|
lookAhead = Math.max(highestUsed + lookAhead/2, lookAhead);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lookAhead;
|
return lookAhead;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WalletNode getFreshNode(KeyPurpose keyPurpose) {
|
public WalletNode getFreshNode(KeyPurpose keyPurpose) {
|
||||||
//TODO: Calculate using seen transactions
|
|
||||||
return getFreshNode(keyPurpose, null);
|
return getFreshNode(keyPurpose, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WalletNode getFreshNode(KeyPurpose keyPurpose, WalletNode current) {
|
public WalletNode getFreshNode(KeyPurpose keyPurpose, WalletNode current) {
|
||||||
//TODO: Calculate using seen transactions
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
if(current != null) {
|
|
||||||
|
WalletNode node = getNode(keyPurpose);
|
||||||
|
Integer highestUsed = node.getHighestUsedIndex();
|
||||||
|
if(highestUsed != null) {
|
||||||
|
index = highestUsed + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(current != null && current.getIndex() >= index) {
|
||||||
index = current.getIndex() + 1;
|
index = current.getIndex() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
WalletNode node = getNode(keyPurpose);
|
|
||||||
if(index >= node.getChildren().size()) {
|
if(index >= node.getChildren().size()) {
|
||||||
node.fillToIndex(index);
|
node.fillToIndex(index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,15 @@ public class WalletNode implements Comparable<WalletNode> {
|
||||||
return unspentTXOs.stream().filter(txo -> !txo.isSpent()).collect(Collectors.toCollection(HashSet::new));
|
return unspentTXOs.stream().filter(txo -> !txo.isSpent()).collect(Collectors.toCollection(HashSet::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getUnspentValue() {
|
||||||
|
long value = 0L;
|
||||||
|
for(BlockTransactionHashIndex utxo : getUnspentTransactionOutputs()) {
|
||||||
|
value += utxo.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
public void fillToIndex(int index) {
|
public void fillToIndex(int index) {
|
||||||
for(int i = 0; i <= index; i++) {
|
for(int i = 0; i <= index; i++) {
|
||||||
WalletNode node = new WalletNode(getKeyPurpose(), i);
|
WalletNode node = new WalletNode(getKeyPurpose(), i);
|
||||||
|
@ -114,6 +123,9 @@ public class WalletNode implements Comparable<WalletNode> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The highest used index, or null if no addresses are used
|
||||||
|
*/
|
||||||
public Integer getHighestUsedIndex() {
|
public Integer getHighestUsedIndex() {
|
||||||
WalletNode highestNode = null;
|
WalletNode highestNode = null;
|
||||||
for(WalletNode childNode : getChildren()) {
|
for(WalletNode childNode : getChildren()) {
|
||||||
|
|
Loading…
Reference in a new issue