Commit 97c519c7 authored by zeroleak's avatar zeroleak
Browse files

cleanup + avoid SamouraiApi reinstanciation

parent 550c019d
package com.samourai.whirlpool.cli.config;
import com.samourai.api.client.BackendServer;
import com.samourai.api.client.SamouraiApi;
import com.samourai.http.client.IHttpClient;
import com.samourai.stomp.client.IStompClientService;
import com.samourai.wallet.util.FormatsUtilGeneric;
......@@ -24,7 +25,8 @@ public class CliConfig extends CliConfigFile {
public WhirlpoolWalletConfig computeWhirlpoolWalletConfig(
IHttpClient httpClient,
IStompClientService stompClientService,
WhirlpoolWalletPersistHandler persistHandler) {
WhirlpoolWalletPersistHandler persistHandler,
SamouraiApi samouraiApi) {
// check valid
if (autoAggregatePostmix && StringUtils.isEmpty(autoTx0PoolId)) {
......@@ -32,16 +34,18 @@ public class CliConfig extends CliConfigFile {
}
WhirlpoolWalletConfig config =
super.computeWhirlpoolWalletConfig(httpClient, stompClientService, persistHandler);
super.computeWhirlpoolWalletConfig(
httpClient, stompClientService, persistHandler, samouraiApi);
config.setAutoTx0PoolId(autoTx0PoolId);
return config;
}
public String computeBackendUrl() {
boolean isTestnet = FormatsUtilGeneric.getInstance().isTestNet(getServer().getParams());
BackendServer backendServer = isTestnet ? BackendServer.TESTNET : BackendServer.MAINNET;
BackendServer backendServer = BackendServer.get(isTestnet);
boolean useOnion = getTor() && getTorConfig().isOnionBackend();
return backendServer.getBackendUrl(useOnion);
String backendUrl = backendServer.getBackendUrl(useOnion);
return backendUrl;
}
public boolean isAutoAggregatePostmix() {
......
package com.samourai.whirlpool.cli.config;
import com.samourai.api.client.SamouraiApi;
import com.samourai.http.client.IHttpClient;
import com.samourai.stomp.client.IStompClientService;
import com.samourai.whirlpool.cli.beans.CliProxy;
......@@ -14,6 +15,7 @@ import java.util.Map;
import java.util.Optional;
import javax.validation.constraints.NotEmpty;
import org.apache.logging.log4j.util.Strings;
import org.bitcoinj.core.NetworkParameters;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
......@@ -319,18 +321,20 @@ public abstract class CliConfigFile {
public String computeServerUrl() {
boolean useOnion = tor && torConfig.onionServer;
String serverUrl = server.computeServerUrl(useOnion);
String serverUrl = server.getServerUrl(useOnion);
return serverUrl;
}
public WhirlpoolWalletConfig computeWhirlpoolWalletConfig(
protected WhirlpoolWalletConfig computeWhirlpoolWalletConfig(
IHttpClient httpClient,
IStompClientService stompClientService,
WhirlpoolWalletPersistHandler persistHandler) {
WhirlpoolWalletPersistHandler persistHandler,
SamouraiApi samouraiApi) {
String serverUrl = computeServerUrl();
NetworkParameters params = server.getParams();
WhirlpoolWalletConfig config =
new WhirlpoolWalletConfig(
httpClient, stompClientService, persistHandler, serverUrl, server);
httpClient, stompClientService, persistHandler, serverUrl, params, samouraiApi);
if (!Strings.isEmpty(scode)) {
config.setScode(scode);
}
......
......@@ -49,6 +49,7 @@ public class CliWalletService extends WhirlpoolWalletService {
private JavaHttpClient httpClient;
private JavaStompClientService stompClientService;
private CliTorClientService cliTorClientService;
private SamouraiApiService samouraiApiService;
// available when wallet is opened
private CliWallet sessionWallet = null;
......@@ -60,7 +61,8 @@ public class CliWalletService extends WhirlpoolWalletService {
WalletAggregateService walletAggregateService,
JavaHttpClient httpClient,
JavaStompClientService stompClientService,
CliTorClientService cliTorClientService) {
CliTorClientService cliTorClientService,
SamouraiApiService samouraiApiService) {
super();
this.cliConfig = cliConfig;
this.cliConfigService = cliConfigService;
......@@ -69,6 +71,7 @@ public class CliWalletService extends WhirlpoolWalletService {
this.httpClient = httpClient;
this.stompClientService = stompClientService;
this.cliTorClientService = cliTorClientService;
this.samouraiApiService = samouraiApiService;
}
public CliWallet openWallet(String seedPassphrase) throws Exception {
......@@ -118,7 +121,8 @@ public class CliWalletService extends WhirlpoolWalletService {
// open wallet
WhirlpoolWalletPersistHandler persistHandler = computePersistHandler(walletIdentifier);
WhirlpoolWalletConfig whirlpoolWalletConfig =
cliConfig.computeWhirlpoolWalletConfig(httpClient, stompClientService, persistHandler);
cliConfig.computeWhirlpoolWalletConfig(
httpClient, stompClientService, persistHandler, samouraiApiService);
WhirlpoolWallet whirlpoolWallet = openWallet(whirlpoolWalletConfig, bip84w);
this.sessionWallet =
new CliWallet(
......@@ -227,7 +231,8 @@ public class CliWalletService extends WhirlpoolWalletService {
public Pools listPools(CliConfig cliConfig) throws Exception {
WhirlpoolWalletConfig config =
cliConfig.computeWhirlpoolWalletConfig(httpClient, stompClientService, null);
cliConfig.computeWhirlpoolWalletConfig(
httpClient, stompClientService, null, samouraiApiService);
return config.newClient().fetchPools();
}
}
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