mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 13:26:44 +00:00
Merge pull request #1333 from zeroleak/whirlpool-1.0.0-beta23
upgrade to whirlpool 1.0.1
This commit is contained in:
commit
a4991064af
4 changed files with 30 additions and 15 deletions
|
@ -124,8 +124,8 @@ dependencies {
|
||||||
exclude group: 'org.slf4j'
|
exclude group: 'org.slf4j'
|
||||||
}
|
}
|
||||||
implementation('com.sparrowwallet.bokmakierie:bokmakierie:1.0')
|
implementation('com.sparrowwallet.bokmakierie:bokmakierie:1.0')
|
||||||
implementation('io.samourai.code.whirlpool:whirlpool-client:1.0.0-beta13')
|
implementation('io.samourai.code.whirlpool:whirlpool-client:1.0.1')
|
||||||
implementation('io.samourai.code.wallet:java-http-client:2.0.0-beta4')
|
implementation('io.samourai.code.wallet:java-http-client:2.0.0')
|
||||||
implementation('io.reactivex.rxjava2:rxjava:2.2.15')
|
implementation('io.reactivex.rxjava2:rxjava:2.2.15')
|
||||||
implementation('io.reactivex.rxjava2:rxjavafx:2.2.2')
|
implementation('io.reactivex.rxjava2:rxjavafx:2.2.2')
|
||||||
implementation('org.apache.commons:commons-lang3:3.7')
|
implementation('org.apache.commons:commons-lang3:3.7')
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class HttpClientService extends JettyHttpClientService {
|
||||||
private static final int REQUEST_TIMEOUT = 120000;
|
private static final int REQUEST_TIMEOUT = 120000;
|
||||||
|
|
||||||
public HttpClientService(HostAndPort torProxy) {
|
public HttpClientService(HostAndPort torProxy) {
|
||||||
super(REQUEST_TIMEOUT, ClientUtils.USER_AGENT, new HttpProxySupplier(torProxy));
|
super(REQUEST_TIMEOUT, new HttpProxySupplier(torProxy));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T requestJson(String url, Class<T> responseType, Map<String, String> headers) throws Exception {
|
public <T> T requestJson(String url, Class<T> responseType, Map<String, String> headers) throws Exception {
|
||||||
|
@ -60,7 +60,6 @@ public class HttpClientService extends JettyHttpClientService {
|
||||||
protected Task<Boolean> createTask() {
|
protected Task<Boolean> createTask() {
|
||||||
return new Task<>() {
|
return new Task<>() {
|
||||||
protected Boolean call() throws Exception {
|
protected Boolean call() throws Exception {
|
||||||
ThreadUtil.getInstance().getExecutorService().shutdown();
|
|
||||||
httpClientService.stop();
|
httpClientService.stop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.google.common.eventbus.Subscribe;
|
||||||
import com.samourai.soroban.client.SorobanConfig;
|
import com.samourai.soroban.client.SorobanConfig;
|
||||||
import com.samourai.wallet.api.backend.beans.UnspentOutput;
|
import com.samourai.wallet.api.backend.beans.UnspentOutput;
|
||||||
import com.samourai.wallet.bipFormat.BIP_FORMAT;
|
import com.samourai.wallet.bipFormat.BIP_FORMAT;
|
||||||
|
import com.samourai.wallet.bipWallet.WalletSupplier;
|
||||||
import com.samourai.wallet.constants.BIP_WALLETS;
|
import com.samourai.wallet.constants.BIP_WALLETS;
|
||||||
import com.samourai.wallet.constants.SamouraiAccount;
|
import com.samourai.wallet.constants.SamouraiAccount;
|
||||||
import com.samourai.wallet.constants.SamouraiNetwork;
|
import com.samourai.wallet.constants.SamouraiNetwork;
|
||||||
|
@ -15,7 +16,7 @@ import com.samourai.whirlpool.client.event.*;
|
||||||
import com.samourai.whirlpool.client.mix.handler.IPostmixHandler;
|
import com.samourai.whirlpool.client.mix.handler.IPostmixHandler;
|
||||||
import com.samourai.whirlpool.client.tx0.Tx0;
|
import com.samourai.whirlpool.client.tx0.Tx0;
|
||||||
import com.samourai.whirlpool.client.tx0.Tx0Config;
|
import com.samourai.whirlpool.client.tx0.Tx0Config;
|
||||||
import com.samourai.whirlpool.client.tx0.Tx0PreviewService;
|
import com.samourai.whirlpool.client.tx0.Tx0Info;
|
||||||
import com.samourai.whirlpool.client.tx0.Tx0Previews;
|
import com.samourai.whirlpool.client.tx0.Tx0Previews;
|
||||||
import com.samourai.whirlpool.client.wallet.WhirlpoolEventService;
|
import com.samourai.whirlpool.client.wallet.WhirlpoolEventService;
|
||||||
import com.samourai.whirlpool.client.wallet.WhirlpoolWallet;
|
import com.samourai.whirlpool.client.wallet.WhirlpoolWallet;
|
||||||
|
@ -45,6 +46,7 @@ import com.sparrowwallet.sparrow.whirlpool.dataSource.SparrowChainSupplier;
|
||||||
import com.sparrowwallet.sparrow.whirlpool.dataSource.SparrowDataSource;
|
import com.sparrowwallet.sparrow.whirlpool.dataSource.SparrowDataSource;
|
||||||
import com.sparrowwallet.sparrow.whirlpool.dataSource.SparrowMinerFeeSupplier;
|
import com.sparrowwallet.sparrow.whirlpool.dataSource.SparrowMinerFeeSupplier;
|
||||||
import com.sparrowwallet.sparrow.whirlpool.dataSource.SparrowPostmixHandler;
|
import com.sparrowwallet.sparrow.whirlpool.dataSource.SparrowPostmixHandler;
|
||||||
|
import io.reactivex.Single;
|
||||||
import io.reactivex.rxjavafx.schedulers.JavaFxScheduler;
|
import io.reactivex.rxjavafx.schedulers.JavaFxScheduler;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
@ -129,12 +131,17 @@ public class Whirlpool {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tx0Previews getTx0Previews(Collection<UnspentOutput> utxos) throws Exception {
|
public Tx0Previews getTx0Previews(Collection<UnspentOutput> utxos) throws Exception {
|
||||||
|
// TODO keep tx0Info for reusing it later on another TX0 preview or TX0 broadcast
|
||||||
|
// it should be refreshed after each successful TX0 broadcast
|
||||||
|
Tx0Info tx0Info = fetchTx0Info();
|
||||||
|
|
||||||
// preview all pools
|
// preview all pools
|
||||||
Tx0Config tx0Config = computeTx0Config();
|
Tx0Config tx0Config = computeTx0Config(tx0Info);
|
||||||
return AsyncUtil.getInstance().blockingGet(getWhirlpoolInfo().tx0Previews(tx0Config, utxos));
|
return tx0Info.tx0Previews(tx0Config, utxos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tx0 broadcastTx0(Pool pool, Collection<BlockTransactionHashIndex> utxos) throws Exception {
|
public Tx0 broadcastTx0(Pool pool, Collection<BlockTransactionHashIndex> utxos) throws Exception {
|
||||||
|
// TODO no need to instanciate WhirlpoolWallet, you just need walletSupplier & utxoSupplier
|
||||||
WhirlpoolWallet whirlpoolWallet = getWhirlpoolWallet();
|
WhirlpoolWallet whirlpoolWallet = getWhirlpoolWallet();
|
||||||
whirlpoolWallet.startAsync().subscribeOn(Schedulers.io()).observeOn(JavaFxScheduler.platform());
|
whirlpoolWallet.startAsync().subscribeOn(Schedulers.io()).observeOn(JavaFxScheduler.platform());
|
||||||
UtxoSupplier utxoSupplier = whirlpoolWallet.getUtxoSupplier();
|
UtxoSupplier utxoSupplier = whirlpoolWallet.getUtxoSupplier();
|
||||||
|
@ -144,15 +151,24 @@ public class Whirlpool {
|
||||||
throw new IllegalStateException("Failed to find UTXOs in Whirlpool wallet");
|
throw new IllegalStateException("Failed to find UTXOs in Whirlpool wallet");
|
||||||
}
|
}
|
||||||
|
|
||||||
Tx0Config tx0Config = computeTx0Config();
|
// TODO reuse tx0Info from TX0 preview to speed up the process
|
||||||
return whirlpoolWallet.tx0(whirlpoolUtxos, pool, tx0Config);
|
Tx0Info tx0Info = fetchTx0Info();
|
||||||
|
|
||||||
|
WalletSupplier walletSupplier = whirlpoolWallet.getWalletSupplier();
|
||||||
|
Tx0Config tx0Config = computeTx0Config(tx0Info);
|
||||||
|
return tx0Info.tx0(walletSupplier, utxoSupplier, whirlpoolUtxos, pool, tx0Config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Tx0Config computeTx0Config() {
|
private Tx0Info fetchTx0Info() throws Exception {
|
||||||
CoordinatorSupplier coordinatorSupplier = getWhirlpoolInfo().getCoordinatorSupplier();
|
return AsyncUtil.getInstance().blockingGet(
|
||||||
Tx0PreviewService tx0PreviewService = getWhirlpoolInfo().getTx0PreviewService();
|
Single.fromCallable(() -> getWhirlpoolInfo().fetchTx0Info(getScode()))
|
||||||
Collection<Pool> pools = coordinatorSupplier.getPools();
|
.subscribeOn(Schedulers.io()).observeOn(JavaFxScheduler.platform()));
|
||||||
return new Tx0Config(tx0PreviewService, pools, tx0FeeTarget, mixFeeTarget, SamouraiAccount.BADBANK);
|
}
|
||||||
|
|
||||||
|
private Tx0Config computeTx0Config(Tx0Info tx0Info) {
|
||||||
|
Tx0Config tx0Config = tx0Info.getTx0Config(tx0FeeTarget, mixFeeTarget);
|
||||||
|
tx0Config.setChangeWallet(SamouraiAccount.BADBANK);
|
||||||
|
return tx0Config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHDWallet(String walletId, Wallet wallet) {
|
public void setHDWallet(String walletId, Wallet wallet) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class SparrowUtxoConfigPersister extends UtxoConfigPersisterFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, UtxoConfigPersisted> utxoConfigs = wallet.getUtxoMixes().entrySet().stream()
|
Map<String, UtxoConfigPersisted> utxoConfigs = wallet.getUtxoMixes().entrySet().stream()
|
||||||
.collect(Collectors.toMap(entry -> entry.getKey().toString(), entry -> new UtxoConfigPersisted(entry.getValue().getMixesDone(), entry.getValue().getExpired(), false, null),
|
.collect(Collectors.toMap(entry -> entry.getKey().toString(), entry -> new UtxoConfigPersisted(entry.getValue().getMixesDone(), entry.getValue().getExpired()),
|
||||||
(u, v) -> { throw new IllegalStateException("Duplicate utxo config hashes"); },
|
(u, v) -> { throw new IllegalStateException("Duplicate utxo config hashes"); },
|
||||||
ConcurrentHashMap::new));
|
ConcurrentHashMap::new));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue