mainnet mixing, improve pools selection, other fixes

This commit is contained in:
Craig Raw 2021-09-23 10:59:40 +02:00
parent c55b19af0f
commit 427a6925ee
6 changed files with 32 additions and 15 deletions

2
drongo

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

View file

@ -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"));

View file

@ -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) {

View file

@ -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);
}
};
}

View file

@ -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();
}

View file

@ -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;