mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-02 20:36:44 +00:00
apply Craig's feedback
- use V2__Whirlpool.sql - allow pools list & tx0 preview without seed - filter DataSource wallet for refresh
This commit is contained in:
parent
050c4fc31e
commit
4577a64ad5
4 changed files with 43 additions and 23 deletions
|
@ -7,9 +7,7 @@ import com.samourai.wallet.api.backend.beans.UnspentOutput;
|
|||
import com.samourai.wallet.hd.HD_Wallet;
|
||||
import com.samourai.wallet.hd.HD_WalletFactoryGeneric;
|
||||
import com.samourai.whirlpool.client.event.*;
|
||||
import com.samourai.whirlpool.client.tx0.Tx0;
|
||||
import com.samourai.whirlpool.client.tx0.Tx0Config;
|
||||
import com.samourai.whirlpool.client.tx0.Tx0Preview;
|
||||
import com.samourai.whirlpool.client.tx0.*;
|
||||
import com.samourai.whirlpool.client.wallet.WhirlpoolEventService;
|
||||
import com.samourai.whirlpool.client.wallet.WhirlpoolWallet;
|
||||
import com.samourai.whirlpool.client.wallet.WhirlpoolWalletConfig;
|
||||
|
@ -17,6 +15,7 @@ import com.samourai.whirlpool.client.wallet.WhirlpoolWalletService;
|
|||
import com.samourai.whirlpool.client.wallet.beans.*;
|
||||
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.pool.PoolData;
|
||||
import com.samourai.whirlpool.client.wallet.data.utxo.UtxoSupplier;
|
||||
import com.samourai.whirlpool.client.wallet.data.utxoConfig.UtxoConfig;
|
||||
import com.samourai.whirlpool.client.whirlpool.ServerApi;
|
||||
|
@ -40,6 +39,7 @@ import com.sparrowwallet.sparrow.event.WhirlpoolMixSuccessEvent;
|
|||
import com.sparrowwallet.sparrow.wallet.UtxoEntry;
|
||||
import com.sparrowwallet.sparrow.whirlpool.dataPersister.SparrowDataPersister;
|
||||
import com.sparrowwallet.sparrow.whirlpool.dataSource.SparrowDataSource;
|
||||
import com.sparrowwallet.sparrow.whirlpool.dataSource.SparrowMinerFeeSupplier;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
|
@ -98,19 +98,21 @@ public class Whirlpool {
|
|||
}
|
||||
|
||||
public Collection<Pool> getPools() throws Exception {
|
||||
WhirlpoolWallet whirlpoolWallet = getWhirlpoolWallet();
|
||||
return whirlpoolWallet.getPoolSupplier().getPools();
|
||||
Tx0ParamService tx0ParamService = getTx0ParamService();
|
||||
PoolData poolData = new PoolData(config.getServerApi().fetchPools(), tx0ParamService);
|
||||
return poolData.getPools();
|
||||
}
|
||||
|
||||
public Tx0Preview getTx0Preview(Pool pool, Collection<UnspentOutput> utxos) throws Exception {
|
||||
WhirlpoolWallet whirlpoolWallet = getWhirlpoolWallet();
|
||||
|
||||
Tx0Config tx0Config = new Tx0Config();
|
||||
tx0Config.setChangeWallet(WhirlpoolAccount.BADBANK);
|
||||
Tx0FeeTarget tx0FeeTarget = Tx0FeeTarget.BLOCKS_4;
|
||||
Tx0FeeTarget mixFeeTarget = Tx0FeeTarget.BLOCKS_4;
|
||||
|
||||
return whirlpoolWallet.tx0Preview(pool, tx0Config, utxos, tx0FeeTarget, mixFeeTarget);
|
||||
Tx0ParamService tx0ParamService = getTx0ParamService();
|
||||
|
||||
Tx0Service tx0Service = new Tx0Service(config);
|
||||
return tx0Service.tx0Preview(utxos, tx0Config, tx0ParamService.getTx0Param(pool, tx0FeeTarget, mixFeeTarget));
|
||||
}
|
||||
|
||||
public Tx0 broadcastTx0(Pool pool, Collection<BlockTransactionHashIndex> utxos) throws Exception {
|
||||
|
@ -131,6 +133,17 @@ public class Whirlpool {
|
|||
return whirlpoolWallet.tx0(whirlpoolUtxos, pool, tx0Config, tx0FeeTarget, mixFeeTarget);
|
||||
}
|
||||
|
||||
private Tx0ParamService getTx0ParamService() {
|
||||
try {
|
||||
SparrowMinerFeeSupplier minerFeeSupplier = SparrowMinerFeeSupplier.getInstance();
|
||||
return new Tx0ParamService(minerFeeSupplier, config);
|
||||
} catch(Exception e) {
|
||||
log.error("Error fetching miner fees", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setHDWallet(String walletId, Wallet wallet) {
|
||||
if(wallet.isEncrypted()) {
|
||||
throw new IllegalStateException("Wallet cannot be encrypted");
|
||||
|
|
|
@ -25,8 +25,8 @@ import com.sparrowwallet.drongo.wallet.WalletNode;
|
|||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.event.NewBlockEvent;
|
||||
import com.sparrowwallet.sparrow.event.NewWalletTransactionsEvent;
|
||||
import com.sparrowwallet.sparrow.event.WalletAddressesChangedEvent;
|
||||
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
|
||||
import com.sparrowwallet.sparrow.net.ElectrumServer;
|
||||
import com.sparrowwallet.sparrow.whirlpool.Whirlpool;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -37,12 +37,17 @@ import java.util.*;
|
|||
public class SparrowDataSource extends WalletResponseDataSource {
|
||||
private static final Logger log = LoggerFactory.getLogger(SparrowDataSource.class);
|
||||
|
||||
private final String walletIdentifierPrefix;
|
||||
|
||||
public SparrowDataSource(
|
||||
WhirlpoolWallet whirlpoolWallet,
|
||||
HD_Wallet bip44w,
|
||||
DataPersister dataPersister)
|
||||
throws Exception {
|
||||
super(whirlpoolWallet, bip44w, dataPersister);
|
||||
|
||||
// prefix matching <prefix>:master, :Premix, :Postmix
|
||||
this.walletIdentifierPrefix = getWhirlpoolWallet().getWalletIdentifier().replace(":master", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -187,21 +192,13 @@ public class SparrowDataSource extends WalletResponseDataSource {
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
public void newWalletTransactions(NewWalletTransactionsEvent event) {
|
||||
try {
|
||||
refresh();
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
public void walletHistoryChanged(WalletHistoryChangedEvent event) {
|
||||
refreshWallet(event.getWalletId());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void walletAddressesChanged(WalletAddressesChangedEvent event) {
|
||||
try {
|
||||
refresh();
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
refreshWallet(event.getWalletId());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
@ -212,4 +209,15 @@ public class SparrowDataSource extends WalletResponseDataSource {
|
|||
log.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshWallet(String eventWalletId) {
|
||||
try {
|
||||
// match <prefix>:master, :Premix, :Postmix
|
||||
if (eventWalletId.startsWith(walletIdentifierPrefix)) {
|
||||
refresh();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
create table utxoMixData (id identity not null, hash binary(32) not null, poolId varchar(32), mixesDone integer not null default 0, forwarding bigint, wallet bigint not null);
|
||||
drop table if exists utxoMixData;
|
||||
create table utxoMixData (id identity not null, hash binary(32) not null, mixesDone integer not null default 0, expired bigint, wallet bigint not null);
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
drop table if exists utxoMixData;
|
||||
create table utxoMixData (id identity not null, hash binary(32) not null, mixesDone integer not null default 0, expired bigint, wallet bigint not null);
|
Loading…
Reference in a new issue