Search in sources :

Example 1 with CallbackNotifier

use of dev.bwt.libbwt.daemon.CallbackNotifier in project sparrow by sparrowwallet.

the class Bwt method start.

private void start(Collection<Wallet> wallets, CallbackNotifier callback) {
    List<Wallet> validWallets = wallets.stream().filter(Wallet::isValid).collect(Collectors.toList());
    Set<String> outputDescriptors = new LinkedHashSet<>();
    for (Wallet wallet : validWallets) {
        OutputDescriptor receiveOutputDescriptor = OutputDescriptor.getOutputDescriptor(wallet, KeyPurpose.RECEIVE);
        outputDescriptors.add(receiveOutputDescriptor.toString(false, false));
        OutputDescriptor changeOutputDescriptor = OutputDescriptor.getOutputDescriptor(wallet, KeyPurpose.CHANGE);
        outputDescriptors.add(changeOutputDescriptor.toString(false, false));
    }
    int rescanSince = validWallets.stream().filter(wallet -> wallet.getBirthDate() != null).mapToInt(wallet -> (int) (wallet.getBirthDate().getTime() / 1000)).min().orElse(-1);
    int gapLimit = validWallets.stream().filter(wallet -> wallet.getGapLimit() > 0).mapToInt(Wallet::getGapLimit).max().orElse(Wallet.DEFAULT_LOOKAHEAD);
    boolean forceRescan = false;
    for (Wallet wallet : validWallets) {
        Date txBirthDate = wallet.getTransactions().values().stream().map(BlockTransactionHash::getDate).filter(Objects::nonNull).min(Date::compareTo).orElse(null);
        if ((wallet.getBirthDate() != null && txBirthDate != null && wallet.getBirthDate().before(txBirthDate)) || (txBirthDate == null && wallet.getStoredBlockHeight() != null && wallet.getStoredBlockHeight() == 0)) {
            forceRescan = true;
        }
    }
    start(outputDescriptors, rescanSince, forceRescan, gapLimit, callback);
}
Also used : java.util(java.util) Wallet(com.sparrowwallet.drongo.wallet.Wallet) LoggerFactory(org.slf4j.LoggerFactory) Config(com.sparrowwallet.sparrow.io.Config) InetAddress(java.net.InetAddress) Task(javafx.concurrent.Task) CallbackNotifier(dev.bwt.libbwt.daemon.CallbackNotifier) Gson(com.google.gson.Gson) Duration(java.time.Duration) OutputDescriptor(com.sparrowwallet.drongo.OutputDescriptor) Logger(org.slf4j.Logger) com.sparrowwallet.sparrow.event(com.sparrowwallet.sparrow.event) IOException(java.io.IOException) Service(javafx.concurrent.Service) SerializedName(com.google.gson.annotations.SerializedName) HostAndPort(com.google.common.net.HostAndPort) BlockTransactionHash(com.sparrowwallet.drongo.wallet.BlockTransactionHash) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) NativeBwtDaemon(dev.bwt.libbwt.daemon.NativeBwtDaemon) Platform(javafx.application.Platform) AppServices(com.sparrowwallet.sparrow.AppServices) KeyPurpose(com.sparrowwallet.drongo.KeyPurpose) Network(com.sparrowwallet.drongo.Network) EventManager(com.sparrowwallet.sparrow.EventManager) OutputDescriptor(com.sparrowwallet.drongo.OutputDescriptor) Wallet(com.sparrowwallet.drongo.wallet.Wallet)

Aggregations

HostAndPort (com.google.common.net.HostAndPort)1 Gson (com.google.gson.Gson)1 SerializedName (com.google.gson.annotations.SerializedName)1 KeyPurpose (com.sparrowwallet.drongo.KeyPurpose)1 Network (com.sparrowwallet.drongo.Network)1 OutputDescriptor (com.sparrowwallet.drongo.OutputDescriptor)1 BlockTransactionHash (com.sparrowwallet.drongo.wallet.BlockTransactionHash)1 Wallet (com.sparrowwallet.drongo.wallet.Wallet)1 AppServices (com.sparrowwallet.sparrow.AppServices)1 EventManager (com.sparrowwallet.sparrow.EventManager)1 com.sparrowwallet.sparrow.event (com.sparrowwallet.sparrow.event)1 Config (com.sparrowwallet.sparrow.io.Config)1 CallbackNotifier (dev.bwt.libbwt.daemon.CallbackNotifier)1 NativeBwtDaemon (dev.bwt.libbwt.daemon.NativeBwtDaemon)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Duration (java.time.Duration)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1