Commit abda80ee authored by zeroleak's avatar zeroleak
Browse files

make WhirlpoolUtxo.mixsTarget nullable + add WhirlpoolUtxo.mixsTargetOrDefault

parent b45d6e07
......@@ -91,7 +91,8 @@ Response:
"progressLabel":"CONNECTING",
"poolId":"0.01btc",
"priority":5,
"mixsTarget":1,
"mixsTarget":null,
"mixsTargetOrDefault":1,
"mixsDone":0,
"message":" - [MIX 1/1] ▮▮▮▮▮▯▯▯▯▯ (5/10) CONFIRMED_INPUT : joined a mix!",
"error":null,
......
......@@ -4,14 +4,12 @@ import com.samourai.whirlpool.cli.services.CliConfigService;
import com.samourai.whirlpool.cli.services.CliService;
import com.samourai.whirlpool.cli.utils.CliUtils;
import com.samourai.whirlpool.client.exception.NotifiableException;
import com.samourai.whirlpool.client.utils.LogbackUtils;
import com.samourai.whirlpool.protocol.WhirlpoolProtocol;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import javax.annotation.PreDestroy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
......@@ -55,7 +53,7 @@ public class Application implements ApplicationRunner {
// enable debug logs with --debug
debug = ApplicationArgs.isMainDebug(args);
debugClient = ApplicationArgs.isMainDebugClient(args);
setDebug(debug, debugClient);
CliUtils.setLogLevel(debug, debugClient);
// run
WebApplicationType wat =
......@@ -97,7 +95,7 @@ public class Application implements ApplicationRunner {
restart = false;
Application.applicationArguments = applicationArguments;
setDebug(debug, debugClient); // run twice to fix incorrect log level
CliUtils.setLogLevel(debug, debugClient); // run twice to fix incorrect log level
if (log.isDebugEnabled()) {
log.debug("Run... " + Arrays.toString(applicationArguments.getSourceArgs()));
......@@ -133,34 +131,6 @@ public class Application implements ApplicationRunner {
}
}
private static void setDebug(boolean isDebug, boolean isDebugClient) {
if (isDebug) {
LogbackUtils.setLogLevel("com.samourai", Level.DEBUG.toString());
}
if (isDebugClient) {
LogbackUtils.setLogLevel("com.samourai.whirlpool.client", Level.DEBUG.toString());
LogbackUtils.setLogLevel("com.samourai.stomp.client", Level.DEBUG.toString());
} else {
LogbackUtils.setLogLevel("com.samourai.whirlpool.client", Level.INFO.toString());
LogbackUtils.setLogLevel("com.samourai.stomp.client", Level.INFO.toString());
}
if (isDebug) {
LogbackUtils.setLogLevel("com.samourai.whirlpool.client.wallet", Level.DEBUG.toString());
LogbackUtils.setLogLevel(
"com.samourai.whirlpool.client.wallet.orchestrator", Level.DEBUG.toString());
}
// skip noisy logs
LogbackUtils.setLogLevel("org.bitcoinj", Level.ERROR.toString());
LogbackUtils.setLogLevel("org.bitcoin", Level.WARN.toString()); // "no wallycore"
LogbackUtils.setLogLevel("com.msopentech.thali.toronionproxy", Level.WARN.toString());
LogbackUtils.setLogLevel("com.msopentech.thali.java.toronionproxy", Level.WARN.toString());
LogbackUtils.setLogLevel("org.springframework.web", Level.INFO.toString());
LogbackUtils.setLogLevel("org.apache.http.impl.conn", Level.INFO.toString());
}
public static void restart() {
long restartDelay = 1000;
if (log.isDebugEnabled()) {
......
......@@ -4,6 +4,7 @@ import com.samourai.whirlpool.cli.api.controllers.AbstractRestController;
import com.samourai.whirlpool.cli.api.protocol.CliApiEndpoint;
import com.samourai.whirlpool.cli.api.protocol.rest.ApiWalletStateResponse;
import com.samourai.whirlpool.cli.services.CliWalletService;
import com.samourai.whirlpool.client.wallet.WhirlpoolWallet;
import com.samourai.whirlpool.client.wallet.beans.MixingState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
......@@ -19,8 +20,9 @@ public class MixController extends AbstractRestController {
@RequestMapping(value = CliApiEndpoint.REST_MIX, method = RequestMethod.GET)
public ApiWalletStateResponse wallet(@RequestHeader HttpHeaders headers) throws Exception {
checkHeaders(headers);
MixingState mixingState = cliWalletService.getSessionWallet().getMixingState();
return new ApiWalletStateResponse(mixingState);
WhirlpoolWallet whirlpoolWallet = cliWalletService.getSessionWallet();
MixingState mixingState = whirlpoolWallet.getMixingState();
return new ApiWalletStateResponse(mixingState, whirlpoolWallet.getConfig().getMixsTarget());
}
@RequestMapping(value = CliApiEndpoint.REST_MIX_START, method = RequestMethod.POST)
......
......@@ -17,13 +17,14 @@ public class ApiUtxo {
private MixableStatus mixableStatus;
private Integer progressPercent;
private String poolId;
private int mixsTarget;
private Integer mixsTarget;
private Integer mixsTargetOrDefault;
private int mixsDone;
private String message;
private String error;
private Long lastActivityElapsed;
public ApiUtxo(WhirlpoolUtxo whirlpoolUtxo) {
public ApiUtxo(WhirlpoolUtxo whirlpoolUtxo, int mixsTargetMin) {
UnspentResponse.UnspentOutput utxo = whirlpoolUtxo.getUtxo();
this.hash = utxo.tx_hash;
this.index = utxo.tx_output_n;
......@@ -42,6 +43,7 @@ public class ApiUtxo {
utxoState.getMixProgress() != null ? utxoState.getMixProgress().getProgressPercent() : null;
this.poolId = utxoConfig.getPoolId();
this.mixsTarget = utxoConfig.getMixsTarget();
this.mixsTargetOrDefault = utxoConfig.getMixsTargetOrDefault(mixsTargetMin);
this.mixsDone = utxoConfig.getMixsDone();
this.message = utxoState.getMessage();
this.error = utxoState.getError();
......@@ -95,10 +97,14 @@ public class ApiUtxo {
return poolId;
}
public int getMixsTarget() {
public Integer getMixsTarget() {
return mixsTarget;
}
public Integer getMixsTargetOrDefault() {
return mixsTargetOrDefault;
}
public int getMixsDone() {
return mixsDone;
}
......
......@@ -11,12 +11,15 @@ public class ApiWallet {
private String zpub;
public ApiWallet(
Collection<WhirlpoolUtxo> whirlpoolUtxos, String zpub, Comparator<WhirlpoolUtxo> comparator) {
Collection<WhirlpoolUtxo> whirlpoolUtxos,
String zpub,
Comparator<WhirlpoolUtxo> comparator,
int mixsTargetMin) {
this.utxos =
whirlpoolUtxos
.stream()
.sorted(comparator)
.map(whirlpoolUtxo -> new ApiUtxo(whirlpoolUtxo))
.map(whirlpoolUtxo -> new ApiUtxo(whirlpoolUtxo, mixsTargetMin))
.collect(Collectors.toList());
this.balance =
whirlpoolUtxos.stream().mapToLong(whirlpoolUtxo -> whirlpoolUtxo.getUtxo().value).sum();
......
......@@ -12,7 +12,7 @@ public class ApiWalletStateResponse {
private int nbQueued;
private Collection<ApiUtxo> threads;
public ApiWalletStateResponse(MixingState mixingState) {
public ApiWalletStateResponse(MixingState mixingState, int mixsTargetMin) {
this.started = mixingState.isStarted();
this.nbMixing = mixingState.getNbMixing();
this.nbQueued = mixingState.getNbQueued();
......@@ -20,7 +20,7 @@ public class ApiWalletStateResponse {
mixingState
.getUtxosMixing()
.stream()
.map(whirlpoolUtxo -> new ApiUtxo(whirlpoolUtxo))
.map(whirlpoolUtxo -> new ApiUtxo(whirlpoolUtxo, mixsTargetMin))
.collect(Collectors.toList());
}
......
......@@ -35,15 +35,25 @@ public class ApiWalletUtxosResponse {
// last confirmed
return Ints.compare(o1.getUtxo().confirmations, o2.getUtxo().confirmations);
};
int mixsTargetMin = whirlpoolWallet.getConfig().getMixsTarget();
this.deposit =
new ApiWallet(
whirlpoolWallet.getUtxosDeposit(), whirlpoolWallet.getZpubDeposit(), comparator);
whirlpoolWallet.getUtxosDeposit(),
whirlpoolWallet.getZpubDeposit(),
comparator,
mixsTargetMin);
this.premix =
new ApiWallet(
whirlpoolWallet.getUtxosPremix(), whirlpoolWallet.getZpubPremix(), comparator);
whirlpoolWallet.getUtxosPremix(),
whirlpoolWallet.getZpubPremix(),
comparator,
mixsTargetMin);
this.postmix =
new ApiWallet(
whirlpoolWallet.getUtxosPostmix(), whirlpoolWallet.getZpubPostmix(), comparator);
whirlpoolWallet.getUtxosPostmix(),
whirlpoolWallet.getZpubPostmix(),
comparator,
mixsTargetMin);
}
public ApiWallet getDeposit() {
......
......@@ -122,7 +122,7 @@ public class CliStatusOrchestrator extends AbstractOrchestrator {
try {
log.info("⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿");
log.info("⣿ " + account + " UTXOS:");
ClientUtils.logWhirlpoolUtxos(utxos);
ClientUtils.logWhirlpoolUtxos(utxos, cliConfig.getMix().getMixsTarget());
} catch (Exception e) {
log.error("", e);
......
package com.samourai.whirlpool.cli.utils;
import ch.qos.logback.classic.Level;
import com.samourai.tor.client.JavaTorConnexion;
import com.samourai.whirlpool.cli.beans.CliProxy;
import com.samourai.whirlpool.cli.beans.CliProxyProtocol;
import com.samourai.whirlpool.cli.services.CliTorClientService;
import com.samourai.whirlpool.client.exception.NotifiableException;
import com.samourai.whirlpool.client.utils.ClientUtils;
import com.samourai.whirlpool.client.utils.LogbackUtils;
import java.io.Console;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
......@@ -204,4 +206,17 @@ public class CliUtils {
}
return lines;
}
public static void setLogLevel(boolean isDebug, boolean isDebugClient) {
Level whirlpoolLevel = isDebug ? Level.DEBUG : Level.INFO;
Level whirlpoolClientLevel = isDebugClient ? Level.DEBUG : Level.INFO;
ClientUtils.setLogLevel(whirlpoolLevel, whirlpoolClientLevel);
LogbackUtils.setLogLevel(
"com.msopentech.thali.toronionproxy", org.slf4j.event.Level.WARN.toString());
LogbackUtils.setLogLevel(
"com.msopentech.thali.java.toronionproxy", org.slf4j.event.Level.WARN.toString());
LogbackUtils.setLogLevel("org.springframework.web", org.slf4j.event.Level.INFO.toString());
LogbackUtils.setLogLevel("org.apache.http.impl.conn", org.slf4j.event.Level.INFO.toString());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment