Browse Source

mainnet mixing, improve pools selection, other fixes

terminal
Craig Raw 3 years ago
parent
commit
427a6925ee
  1. 2
      drongo
  2. 1
      src/main/java/com/sparrowwallet/sparrow/control/TorStatusLabel.java
  3. 2
      src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java
  4. 14
      src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java
  5. 23
      src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolController.java
  6. 5
      src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java

2
drongo

@ -1 +1 @@
Subproject commit 38783d68a49ecf5d8c8640edb299d693f455b2a9
Subproject commit c9e57fad018750a150a563cd17c8872d7cda48f0

1
src/main/java/com/sparrowwallet/sparrow/control/TorStatusLabel.java

@ -43,6 +43,7 @@ public class TorStatusLabel extends Label {
}
} else if(!torConnectionTest.isRunning()) {
torConnectionTest.setPeriod(Duration.seconds(20.0));
torConnectionTest.setBackoffStrategy(null);
torConnectionTest.setOnSucceeded(workerStateEvent -> {
getStyleClass().remove("failure");
setTooltip(new Tooltip("External Tor proxy enabled"));

2
src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java

@ -133,7 +133,7 @@ public class UtxosController extends WalletFormController implements Initializab
}
private boolean canWalletMix() {
return Network.get() == Network.TESTNET && getWalletForm().getWallet().getKeystores().size() == 1 && getWalletForm().getWallet().getKeystores().get(0).hasSeed() && !getWalletForm().getWallet().isWhirlpoolMixWallet();
return getWalletForm().getWallet().getKeystores().size() == 1 && getWalletForm().getWallet().getKeystores().get(0).hasSeed() && !getWalletForm().getWallet().isWhirlpoolMixWallet();
}
private void updateButtons(BitcoinUnit unit) {

14
src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java

@ -107,9 +107,13 @@ public class Whirlpool {
return whirlpoolWalletConfig;
}
public Collection<Pool> getPools() throws Exception {
public Collection<Pool> getPools(Long totalUtxoValue) throws Exception {
this.poolSupplier.load();
return poolSupplier.getPools();
if(totalUtxoValue == null) {
return poolSupplier.getPools();
}
return tx0ParamService.findPools(poolSupplier.getPools(), totalUtxoValue);
}
public Tx0Previews getTx0Previews(Collection<UnspentOutput> utxos) throws Exception {
@ -458,16 +462,18 @@ public class Whirlpool {
public static class PoolsService extends Service<Collection<Pool>> {
private final Whirlpool whirlpool;
private final Long totalUtxoValue;
public PoolsService(Whirlpool whirlpool) {
public PoolsService(Whirlpool whirlpool, Long totalUtxoValue) {
this.whirlpool = whirlpool;
this.totalUtxoValue = totalUtxoValue;
}
@Override
protected Task<Collection<Pool>> createTask() {
return new Task<>() {
protected Collection<Pool> call() throws Exception {
return whirlpool.getPools();
return whirlpool.getPools(totalUtxoValue);
}
};
}

23
src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolController.java

@ -217,17 +217,22 @@ public class WhirlpoolController {
private void fetchPools() {
long totalUtxoValue = utxoEntries.stream().mapToLong(Entry::getValue).sum();
Whirlpool.PoolsService poolsService = new Whirlpool.PoolsService(AppServices.getWhirlpoolServices().getWhirlpool(walletId));
Whirlpool.PoolsService poolsService = new Whirlpool.PoolsService(AppServices.getWhirlpoolServices().getWhirlpool(walletId), totalUtxoValue);
poolsService.setOnSucceeded(workerStateEvent -> {
List<Pool> availablePools = poolsService.getValue().stream().filter(pool1 -> totalUtxoValue >= (pool1.getPremixValueMin() + pool1.getFeeValue())).toList();
List<Pool> availablePools = poolsService.getValue().stream().toList();
if(availablePools.isEmpty()) {
pool.setVisible(false);
OptionalLong optMinValue = poolsService.getValue().stream().mapToLong(pool1 -> pool1.getPremixValueMin() + pool1.getFeeValue()).min();
if(optMinValue.isPresent()) {
String satsValue = String.format(Locale.ENGLISH, "%,d", optMinValue.getAsLong()) + " sats";
String btcValue = CoinLabel.BTC_FORMAT.format((double)optMinValue.getAsLong() / Transaction.SATOSHIS_PER_BITCOIN) + " BTC";
poolInsufficient.setText("No available pools. Select a value over " + (Config.get().getBitcoinUnit() == BitcoinUnit.BTC ? btcValue : satsValue) + ".");
}
Whirlpool.PoolsService allPoolsService = new Whirlpool.PoolsService(AppServices.getWhirlpoolServices().getWhirlpool(walletId), null);
allPoolsService.setOnSucceeded(poolsStateEvent -> {
OptionalLong optMinValue = allPoolsService.getValue().stream().mapToLong(pool1 -> pool1.getPremixValueMin() + pool1.getFeeValue()).min();
if(optMinValue.isPresent() && totalUtxoValue < optMinValue.getAsLong()) {
String satsValue = String.format(Locale.ENGLISH, "%,d", optMinValue.getAsLong()) + " sats";
String btcValue = CoinLabel.BTC_FORMAT.format((double)optMinValue.getAsLong() / Transaction.SATOSHIS_PER_BITCOIN) + " BTC";
poolInsufficient.setText("No available pools. Select a value over " + (Config.get().getBitcoinUnit() == BitcoinUnit.BTC ? btcValue : satsValue) + ".");
}
});
allPoolsService.start();
} else {
pool.setDisable(false);
pool.setItems(FXCollections.observableList(availablePools));
@ -285,7 +290,7 @@ public class WhirlpoolController {
exception = exception.getCause();
}
nbOutputsLoading.setText("Error fetching fee: " + exception.getMessage());
nbOutputsLoading.setText("Error fetching Tx0: " + exception.getMessage());
});
tx0PreviewsService.start();
}

5
src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java

@ -43,6 +43,11 @@ public class WhirlpoolServices {
HostAndPort torProxy = getTorProxy();
whirlpool = new Whirlpool(Network.get(), torProxy);
whirlpoolMap.put(walletId, whirlpool);
} else if(!whirlpool.isStarted()) {
HostAndPort torProxy = getTorProxy();
if(!Objects.equals(whirlpool.getTorProxy(), torProxy)) {
whirlpool.setTorProxy(getTorProxy());
}
}
return whirlpool;

Loading…
Cancel
Save