Browse Source

retrieve stored index from mixconfig on whirlpool wallet load

terminal
Craig Raw 3 years ago
parent
commit
813e0f3ab1
  1. 1
      src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java
  2. 6
      src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowDataSource.java
  3. 8
      src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowIndexHandler.java

1
src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java

@ -1145,6 +1145,7 @@ public class SendController extends WalletFormController implements Initializabl
AppServices.showErrorDialog("Error broadcasting premix transaction", exception.getMessage());
});
ServiceProgressDialog progressDialog = new ServiceProgressDialog("Whirlpool", "Broadcast Premix Transaction", "/image/whirlpool.png", tx0BroadcastService);
AppServices.moveToActiveWindowScreen(progressDialog);
tx0BroadcastService.start();
}

6
src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowDataSource.java

@ -89,8 +89,10 @@ public class SparrowDataSource extends WalletResponseDataSource {
List<ExtendedKey.Header> headers = ExtendedKey.Header.getHeaders(Network.get());
ExtendedKey.Header header = headers.stream().filter(head -> head.getDefaultScriptType().equals(wallet.getScriptType()) && !head.isPrivateKey()).findFirst().orElse(ExtendedKey.Header.xpub);
address.address = wallet.getKeystores().get(0).getExtendedPublicKey().toString(header);
address.account_index = wallet.getNode(KeyPurpose.RECEIVE).getHighestUsedIndex() == null ? 0 : wallet.getNode(KeyPurpose.RECEIVE).getHighestUsedIndex() + 1;
address.change_index = wallet.getNode(KeyPurpose.CHANGE).getHighestUsedIndex() == null ? 0 : wallet.getNode(KeyPurpose.CHANGE).getHighestUsedIndex() + 1;
int receiveIndex = wallet.getNode(KeyPurpose.RECEIVE).getHighestUsedIndex() == null ? 0 : wallet.getNode(KeyPurpose.RECEIVE).getHighestUsedIndex() + 1;
address.account_index = wallet.getMixConfig() != null ? Math.max(receiveIndex, wallet.getMixConfig().getReceiveIndex()) : receiveIndex;
int changeIndex = wallet.getNode(KeyPurpose.CHANGE).getHighestUsedIndex() == null ? 0 : wallet.getNode(KeyPurpose.CHANGE).getHighestUsedIndex() + 1;
address.change_index = wallet.getMixConfig() != null ? Math.max(changeIndex, wallet.getMixConfig().getChangeIndex()) : changeIndex;
address.n_tx = wallet.getTransactions().size();
addresses.add(address);

8
src/main/java/com/sparrowwallet/sparrow/whirlpool/dataSource/SparrowIndexHandler.java

@ -60,13 +60,13 @@ public class SparrowIndexHandler extends AbstractIndexHandler {
private void setStoredIndex(int index) {
if(wallet.getMixConfig() != null) {
if(walletNode.getKeyPurpose() == KeyPurpose.RECEIVE) {
if(walletNode.getKeyPurpose() == KeyPurpose.RECEIVE && wallet.getMixConfig().getReceiveIndex() != index) {
wallet.getMixConfig().setReceiveIndex(index);
} else if(walletNode.getKeyPurpose() == KeyPurpose.CHANGE) {
EventManager.get().post(new WalletMixConfigChangedEvent(wallet));
} else if(walletNode.getKeyPurpose() == KeyPurpose.CHANGE && wallet.getMixConfig().getChangeIndex() != index) {
wallet.getMixConfig().setChangeIndex(index);
EventManager.get().post(new WalletMixConfigChangedEvent(wallet));
}
EventManager.get().post(new WalletMixConfigChangedEvent(wallet));
}
}

Loading…
Cancel
Save