mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-14 03:26:45 +01:00
Introduce io.bitsquare.btc.UserAgent
This makes things generally more explicit and reduces the number of String arguments in the WalletFacade constructor.
This commit is contained in:
parent
b10958e790
commit
8f8866da6a
4 changed files with 63 additions and 20 deletions
|
@ -18,6 +18,7 @@
|
||||||
package io.bitsquare.app;
|
package io.bitsquare.app;
|
||||||
|
|
||||||
import io.bitsquare.BitsquareException;
|
import io.bitsquare.BitsquareException;
|
||||||
|
import io.bitsquare.btc.UserAgent;
|
||||||
import io.bitsquare.btc.WalletFacade;
|
import io.bitsquare.btc.WalletFacade;
|
||||||
import io.bitsquare.persistence.Persistence;
|
import io.bitsquare.persistence.Persistence;
|
||||||
|
|
||||||
|
@ -71,10 +72,12 @@ public class BitsquareEnvironment extends StandardEnvironment {
|
||||||
private PropertySource<?> defaultProperties(String appName) {
|
private PropertySource<?> defaultProperties(String appName) {
|
||||||
return new PropertiesPropertySource(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {{
|
return new PropertiesPropertySource(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {{
|
||||||
setProperty(APP_NAME_KEY, appName);
|
setProperty(APP_NAME_KEY, appName);
|
||||||
|
|
||||||
|
setProperty(UserAgent.NAME_KEY, appName);
|
||||||
|
setProperty(UserAgent.VERSION_KEY, "0.1");
|
||||||
|
|
||||||
setProperty(WalletFacade.DIR_KEY, AppDirectory.dir(appName).toString());
|
setProperty(WalletFacade.DIR_KEY, AppDirectory.dir(appName).toString());
|
||||||
setProperty(WalletFacade.PREFIX_KEY, appName);
|
setProperty(WalletFacade.PREFIX_KEY, appName);
|
||||||
setProperty(WalletFacade.USERAGENT_NAME_KEY, appName);
|
|
||||||
setProperty(WalletFacade.USERAGENT_VERSION_KEY, "0.1");
|
|
||||||
|
|
||||||
setProperty(Persistence.DIR_KEY, AppDirectory.dir(appName).toString());
|
setProperty(Persistence.DIR_KEY, AppDirectory.dir(appName).toString());
|
||||||
setProperty(Persistence.PREFIX_KEY, appName + "_pref");
|
setProperty(Persistence.PREFIX_KEY, appName + "_pref");
|
||||||
|
|
|
@ -31,7 +31,6 @@ import java.io.File;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
import static com.google.inject.name.Names.named;
|
import static com.google.inject.name.Names.named;
|
||||||
import static io.bitsquare.btc.WalletFacade.*;
|
|
||||||
|
|
||||||
public class BitcoinModule extends BitsquareModule {
|
public class BitcoinModule extends BitsquareModule {
|
||||||
|
|
||||||
|
@ -44,14 +43,18 @@ public class BitcoinModule extends BitsquareModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
|
bind(NetworkParameters.class).toInstance(network());
|
||||||
|
bind(FeePolicy.class).asEagerSingleton();
|
||||||
|
|
||||||
|
bindConstant().annotatedWith(named(UserAgent.NAME_KEY)).to(env.getRequiredProperty(UserAgent.NAME_KEY));
|
||||||
|
bindConstant().annotatedWith(named(UserAgent.VERSION_KEY)).to(env.getRequiredProperty(UserAgent.VERSION_KEY));
|
||||||
|
bind(UserAgent.class).asEagerSingleton();
|
||||||
|
|
||||||
File walletDir = new File(env.getRequiredProperty(WalletFacade.DIR_KEY));
|
File walletDir = new File(env.getRequiredProperty(WalletFacade.DIR_KEY));
|
||||||
bind(File.class).annotatedWith(named(WalletFacade.DIR_KEY)).toInstance(walletDir);
|
bind(File.class).annotatedWith(named(WalletFacade.DIR_KEY)).toInstance(walletDir);
|
||||||
bindConstant().annotatedWith(named(WalletFacade.PREFIX_KEY)).to(env.getRequiredProperty(WalletFacade.PREFIX_KEY));
|
bindConstant().annotatedWith(named(WalletFacade.PREFIX_KEY)).to(env.getRequiredProperty(WalletFacade.PREFIX_KEY));
|
||||||
bindConstant().annotatedWith(named(USERAGENT_NAME_KEY)).to(env.getRequiredProperty(USERAGENT_NAME_KEY));
|
|
||||||
bindConstant().annotatedWith(named(USERAGENT_VERSION_KEY)).to(env.getRequiredProperty(USERAGENT_VERSION_KEY));
|
|
||||||
bind(NetworkParameters.class).toInstance(network());
|
|
||||||
bind(FeePolicy.class).asEagerSingleton();
|
|
||||||
bind(WalletFacade.class).asEagerSingleton();
|
bind(WalletFacade.class).asEagerSingleton();
|
||||||
|
|
||||||
bind(BlockChainFacade.class).asEagerSingleton();
|
bind(BlockChainFacade.class).asEagerSingleton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
44
src/main/java/io/bitsquare/btc/UserAgent.java
Normal file
44
src/main/java/io/bitsquare/btc/UserAgent.java
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Bitsquare.
|
||||||
|
*
|
||||||
|
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.bitsquare.btc;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
public class UserAgent {
|
||||||
|
public static final String NAME_KEY = "useragent.name";
|
||||||
|
public static final String VERSION_KEY = "useragent.version";
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final String version;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public UserAgent(@Named(NAME_KEY) String name, @Named(VERSION_KEY) String version) {
|
||||||
|
this.name = name;
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -97,8 +97,6 @@ public class WalletFacade {
|
||||||
|
|
||||||
public static final String DIR_KEY = "wallet.dir";
|
public static final String DIR_KEY = "wallet.dir";
|
||||||
public static final String PREFIX_KEY = "wallet.prefix";
|
public static final String PREFIX_KEY = "wallet.prefix";
|
||||||
public static final String USERAGENT_NAME_KEY = "bitcoin.useragent.name";
|
|
||||||
public static final String USERAGENT_VERSION_KEY = "bitcoin.useragent.version";
|
|
||||||
|
|
||||||
private final List<AddressConfidenceListener> addressConfidenceListeners = new CopyOnWriteArrayList<>();
|
private final List<AddressConfidenceListener> addressConfidenceListeners = new CopyOnWriteArrayList<>();
|
||||||
private final List<TxConfidenceListener> txConfidenceListeners = new CopyOnWriteArrayList<>();
|
private final List<TxConfidenceListener> txConfidenceListeners = new CopyOnWriteArrayList<>();
|
||||||
|
@ -111,8 +109,7 @@ public class WalletFacade {
|
||||||
private final Persistence persistence;
|
private final Persistence persistence;
|
||||||
private final File walletDir;
|
private final File walletDir;
|
||||||
private final String walletPrefix;
|
private final String walletPrefix;
|
||||||
private final String userAgentName;
|
private final UserAgent userAgent;
|
||||||
private final String userAgentVersion;
|
|
||||||
|
|
||||||
private WalletAppKit walletAppKit;
|
private WalletAppKit walletAppKit;
|
||||||
private Wallet wallet;
|
private Wallet wallet;
|
||||||
|
@ -126,20 +123,16 @@ public class WalletFacade {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public WalletFacade(NetworkParameters params, FeePolicy feePolicy,
|
public WalletFacade(NetworkParameters params, FeePolicy feePolicy, CryptoFacade cryptoFacade,
|
||||||
CryptoFacade cryptoFacade, Persistence persistence,
|
Persistence persistence, UserAgent userAgent,
|
||||||
@Named(DIR_KEY) File walletDir,
|
@Named(DIR_KEY) File walletDir, @Named(PREFIX_KEY) String walletPrefix) {
|
||||||
@Named(PREFIX_KEY) String walletPrefix,
|
|
||||||
@Named(USERAGENT_NAME_KEY) String userAgentName,
|
|
||||||
@Named(USERAGENT_VERSION_KEY) String userAgentVersion) {
|
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.feePolicy = feePolicy;
|
this.feePolicy = feePolicy;
|
||||||
this.cryptoFacade = cryptoFacade;
|
this.cryptoFacade = cryptoFacade;
|
||||||
this.persistence = persistence;
|
this.persistence = persistence;
|
||||||
this.walletDir = walletDir;
|
this.walletDir = walletDir;
|
||||||
this.walletPrefix = walletPrefix;
|
this.walletPrefix = walletPrefix;
|
||||||
this.userAgentName = userAgentName;
|
this.userAgent = userAgent;
|
||||||
this.userAgentVersion = userAgentVersion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,7 +203,7 @@ public class WalletFacade {
|
||||||
|
|
||||||
walletAppKit.setDownloadListener(downloadListener)
|
walletAppKit.setDownloadListener(downloadListener)
|
||||||
.setBlockingStartup(false)
|
.setBlockingStartup(false)
|
||||||
.setUserAgent(userAgentName, userAgentVersion);
|
.setUserAgent(userAgent.getName(), userAgent.getVersion());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// TODO restore from DeterministicSeed
|
// TODO restore from DeterministicSeed
|
||||||
|
|
Loading…
Add table
Reference in a new issue