mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 13:26:44 +00:00
Merge pull request #198 from zeroleak/whirlpool-client-0.23.30-early5
update to whirlpool-client 0.23.31
This commit is contained in:
commit
1c1099217b
4 changed files with 28 additions and 42 deletions
|
@ -16,7 +16,7 @@ import com.samourai.whirlpool.client.wallet.WhirlpoolWalletService;
|
||||||
import com.samourai.whirlpool.client.wallet.beans.*;
|
import com.samourai.whirlpool.client.wallet.beans.*;
|
||||||
import com.samourai.whirlpool.client.wallet.data.dataPersister.DataPersisterFactory;
|
import com.samourai.whirlpool.client.wallet.data.dataPersister.DataPersisterFactory;
|
||||||
import com.samourai.whirlpool.client.wallet.data.dataSource.DataSourceFactory;
|
import com.samourai.whirlpool.client.wallet.data.dataSource.DataSourceFactory;
|
||||||
import com.samourai.whirlpool.client.wallet.data.pool.PoolData;
|
import com.samourai.whirlpool.client.wallet.data.pool.ExpirablePoolSupplier;
|
||||||
import com.samourai.whirlpool.client.wallet.data.utxo.UtxoSupplier;
|
import com.samourai.whirlpool.client.wallet.data.utxo.UtxoSupplier;
|
||||||
import com.samourai.whirlpool.client.wallet.data.utxoConfig.UtxoConfig;
|
import com.samourai.whirlpool.client.wallet.data.utxoConfig.UtxoConfig;
|
||||||
import com.samourai.whirlpool.client.whirlpool.ServerApi;
|
import com.samourai.whirlpool.client.whirlpool.ServerApi;
|
||||||
|
@ -25,7 +25,6 @@ import com.sparrowwallet.drongo.ExtendedKey;
|
||||||
import com.sparrowwallet.drongo.KeyPurpose;
|
import com.sparrowwallet.drongo.KeyPurpose;
|
||||||
import com.sparrowwallet.drongo.Network;
|
import com.sparrowwallet.drongo.Network;
|
||||||
import com.sparrowwallet.drongo.Utils;
|
import com.sparrowwallet.drongo.Utils;
|
||||||
import com.sparrowwallet.drongo.policy.PolicyType;
|
|
||||||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||||
import com.sparrowwallet.drongo.protocol.Sha256Hash;
|
import com.sparrowwallet.drongo.protocol.Sha256Hash;
|
||||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||||
|
@ -69,6 +68,9 @@ public class Whirlpool {
|
||||||
private final TorClientService torClientService;
|
private final TorClientService torClientService;
|
||||||
private final WhirlpoolWalletService whirlpoolWalletService;
|
private final WhirlpoolWalletService whirlpoolWalletService;
|
||||||
private final WhirlpoolWalletConfig config;
|
private final WhirlpoolWalletConfig config;
|
||||||
|
private Tx0ParamService tx0ParamService;
|
||||||
|
private ExpirablePoolSupplier poolSupplier;
|
||||||
|
private Tx0Service tx0Service;
|
||||||
private HD_Wallet hdWallet;
|
private HD_Wallet hdWallet;
|
||||||
private String walletId;
|
private String walletId;
|
||||||
private String mixToWalletId;
|
private String mixToWalletId;
|
||||||
|
@ -84,6 +86,9 @@ public class Whirlpool {
|
||||||
|
|
||||||
this.whirlpoolWalletService = new WhirlpoolWalletService();
|
this.whirlpoolWalletService = new WhirlpoolWalletService();
|
||||||
this.config = computeWhirlpoolWalletConfig(torProxy);
|
this.config = computeWhirlpoolWalletConfig(torProxy);
|
||||||
|
this.tx0ParamService = new Tx0ParamService(SparrowMinerFeeSupplier.getInstance(), config);
|
||||||
|
this.poolSupplier = new ExpirablePoolSupplier(config.getRefreshPoolsDelay(), config.getServerApi(), tx0ParamService);
|
||||||
|
this.tx0Service = new Tx0Service(config);
|
||||||
|
|
||||||
WhirlpoolEventService.getInstance().register(this);
|
WhirlpoolEventService.getInstance().register(this);
|
||||||
}
|
}
|
||||||
|
@ -98,26 +103,23 @@ public class Whirlpool {
|
||||||
|
|
||||||
WhirlpoolWalletConfig whirlpoolWalletConfig = new WhirlpoolWalletConfig(dataSourceFactory, httpClientService, stompClientService, torClientService, serverApi, whirlpoolServer.getParams(), false);
|
WhirlpoolWalletConfig whirlpoolWalletConfig = new WhirlpoolWalletConfig(dataSourceFactory, httpClientService, stompClientService, torClientService, serverApi, whirlpoolServer.getParams(), false);
|
||||||
whirlpoolWalletConfig.setDataPersisterFactory(dataPersisterFactory);
|
whirlpoolWalletConfig.setDataPersisterFactory(dataPersisterFactory);
|
||||||
|
whirlpoolWalletConfig.setPartner("SPARROW");
|
||||||
return whirlpoolWalletConfig;
|
return whirlpoolWalletConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Pool> getPools() throws Exception {
|
public Collection<Pool> getPools() throws Exception {
|
||||||
Tx0ParamService tx0ParamService = getTx0ParamService();
|
this.poolSupplier.load();
|
||||||
PoolData poolData = new PoolData(config.getServerApi().fetchPools(), tx0ParamService);
|
return poolSupplier.getPools();
|
||||||
return poolData.getPools();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tx0Preview getTx0Preview(Pool pool, Collection<UnspentOutput> utxos) throws Exception {
|
public Tx0Preview getTx0Preview(Pool pool, Collection<UnspentOutput> utxos) throws Exception {
|
||||||
Tx0Config tx0Config = new Tx0Config();
|
// preview all pools
|
||||||
tx0Config.setChangeWallet(WhirlpoolAccount.BADBANK);
|
Tx0Config tx0Config = computeTx0Config();
|
||||||
Tx0FeeTarget tx0FeeTarget = Tx0FeeTarget.BLOCKS_4;
|
Tx0Previews tx0Previews = tx0Service.tx0Previews(utxos, tx0Config);
|
||||||
Tx0FeeTarget mixFeeTarget = Tx0FeeTarget.BLOCKS_4;
|
|
||||||
|
|
||||||
Tx0ParamService tx0ParamService = getTx0ParamService();
|
// pool preview
|
||||||
|
String poolId = pool.getPoolId();
|
||||||
Tx0Service tx0Service = new Tx0Service(config);
|
return tx0Previews.getTx0Preview(poolId);
|
||||||
return tx0Service.tx0Preview(utxos, tx0Config, tx0ParamService.getTx0Param(pool, tx0FeeTarget, mixFeeTarget));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tx0 broadcastTx0(Pool pool, Collection<BlockTransactionHashIndex> utxos) throws Exception {
|
public Tx0 broadcastTx0(Pool pool, Collection<BlockTransactionHashIndex> utxos) throws Exception {
|
||||||
|
@ -130,17 +132,14 @@ 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 = new Tx0Config();
|
Tx0Config tx0Config = computeTx0Config();
|
||||||
tx0Config.setChangeWallet(WhirlpoolAccount.BADBANK);
|
return whirlpoolWallet.tx0(whirlpoolUtxos, pool, tx0Config);
|
||||||
Tx0FeeTarget tx0FeeTarget = Tx0FeeTarget.BLOCKS_4;
|
|
||||||
Tx0FeeTarget mixFeeTarget = Tx0FeeTarget.BLOCKS_4;
|
|
||||||
|
|
||||||
return whirlpoolWallet.tx0(whirlpoolUtxos, pool, tx0Config, tx0FeeTarget, mixFeeTarget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Tx0ParamService getTx0ParamService() {
|
private Tx0Config computeTx0Config() {
|
||||||
SparrowMinerFeeSupplier minerFeeSupplier = SparrowMinerFeeSupplier.getInstance();
|
Tx0FeeTarget tx0FeeTarget = Tx0FeeTarget.BLOCKS_4;
|
||||||
return new Tx0ParamService(minerFeeSupplier, config);
|
Tx0FeeTarget mixFeeTarget = Tx0FeeTarget.BLOCKS_4;
|
||||||
|
return new Tx0Config(tx0ParamService, poolSupplier, tx0FeeTarget, mixFeeTarget, WhirlpoolAccount.BADBANK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHDWallet(String walletId, Wallet wallet) {
|
public void setHDWallet(String walletId, Wallet wallet) {
|
||||||
|
|
|
@ -158,9 +158,8 @@ public class SparrowDataSource extends WalletResponseDataSource {
|
||||||
walletResponse.info.latest_block.time = AppServices.getLatestBlockHeader() == null ? 1 : AppServices.getLatestBlockHeader().getTime();
|
walletResponse.info.latest_block.time = AppServices.getLatestBlockHeader() == null ? 1 : AppServices.getLatestBlockHeader().getTime();
|
||||||
|
|
||||||
walletResponse.info.fees = new LinkedHashMap<>();
|
walletResponse.info.fees = new LinkedHashMap<>();
|
||||||
MinerFee minerFee = getMinerFeeSupplier().getValue();
|
|
||||||
for(MinerFeeTarget target : MinerFeeTarget.values()) {
|
for(MinerFeeTarget target : MinerFeeTarget.values()) {
|
||||||
walletResponse.info.fees.put(target.getValue(), minerFee.get(target));
|
walletResponse.info.fees.put(target.getValue(), getMinerFeeSupplier().getFee(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
return walletResponse;
|
return walletResponse;
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package com.sparrowwallet.sparrow.whirlpool.dataSource;
|
package com.sparrowwallet.sparrow.whirlpool.dataSource;
|
||||||
|
|
||||||
import com.samourai.wallet.api.backend.MinerFee;
|
|
||||||
import com.samourai.wallet.api.backend.MinerFeeTarget;
|
import com.samourai.wallet.api.backend.MinerFeeTarget;
|
||||||
import com.samourai.whirlpool.client.wallet.data.minerFee.MinerFeeSupplier;
|
import com.samourai.whirlpool.client.wallet.data.minerFee.MinerFeeSupplier;
|
||||||
import com.sparrowwallet.sparrow.AppServices;
|
import com.sparrowwallet.sparrow.AppServices;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class SparrowMinerFeeSupplier implements MinerFeeSupplier {
|
public class SparrowMinerFeeSupplier implements MinerFeeSupplier {
|
||||||
private static final int FALLBACK_FEE_RATE = 75;
|
private static final int FALLBACK_FEE_RATE = 75;
|
||||||
|
@ -30,15 +32,6 @@ public class SparrowMinerFeeSupplier implements MinerFeeSupplier {
|
||||||
return getMinimumFeeForTarget(Integer.parseInt(feeTarget.getValue()));
|
return getMinimumFeeForTarget(Integer.parseInt(feeTarget.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public MinerFee getValue() {
|
|
||||||
Map<String, Integer> fees = new LinkedHashMap<>();
|
|
||||||
for (MinerFeeTarget minerFeeTarget : MinerFeeTarget.values()) {
|
|
||||||
fees.put(minerFeeTarget.getValue(), getFee(minerFeeTarget));
|
|
||||||
}
|
|
||||||
return new MinerFee(fees);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Integer getMinimumFeeForTarget(int targetBlocks) {
|
private Integer getMinimumFeeForTarget(int targetBlocks) {
|
||||||
List<Map.Entry<Integer, Double>> feeRates = new ArrayList<>(AppServices.getTargetBlockFeeRates().entrySet());
|
List<Map.Entry<Integer, Double>> feeRates = new ArrayList<>(AppServices.getTargetBlockFeeRates().entrySet());
|
||||||
Collections.reverse(feeRates);
|
Collections.reverse(feeRates);
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class SparrowWalletStateSupplier implements WalletStateSupplier {
|
||||||
private final WhirlpoolClientConfig config;
|
private final WhirlpoolClientConfig config;
|
||||||
private IIndexHandler externalIndexHandler;
|
private IIndexHandler externalIndexHandler;
|
||||||
|
|
||||||
public SparrowWalletStateSupplier(String walletId, WhirlpoolClientConfig config) throws Exception {
|
public SparrowWalletStateSupplier(String walletId, WhirlpoolClientConfig config) {
|
||||||
this.walletId = walletId;
|
this.walletId = walletId;
|
||||||
this.indexHandlerWallets = new LinkedHashMap<>();
|
this.indexHandlerWallets = new LinkedHashMap<>();
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
@ -89,11 +89,6 @@ public class SparrowWalletStateSupplier implements WalletStateSupplier {
|
||||||
// nothing required
|
// nothing required
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setWalletIndex(WhirlpoolAccount whirlpoolAccount, AddressType addressType, Chain chain, int i) throws Exception {
|
|
||||||
// nothing required
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load() throws Exception {
|
public void load() throws Exception {
|
||||||
// nothing required
|
// nothing required
|
||||||
|
|
Loading…
Reference in a new issue