use of com.samourai.whirlpool.client.wallet.data.utxoConfig.UtxoConfigPersisted in project sparrow by sparrowwallet.
the class SparrowUtxoConfigPersister method doWrite.
@Override
protected void doWrite(UtxoConfigData data) throws Exception {
Wallet wallet = getWallet();
if (wallet == null) {
// Wallet is already closed
return;
}
Map<String, UtxoConfigPersisted> currentData = new HashMap<>(data.getUtxoConfigs());
Map<Sha256Hash, UtxoMixData> changedUtxoMixes = currentData.entrySet().stream().collect(Collectors.toMap(entry -> Sha256Hash.wrap(entry.getKey()), entry -> new UtxoMixData(entry.getValue().getMixsDone(), entry.getValue().getExpired()), (u, v) -> {
throw new IllegalStateException("Duplicate utxo config hashes");
}, HashMap::new));
MapDifference<Sha256Hash, UtxoMixData> mapDifference = Maps.difference(changedUtxoMixes, wallet.getUtxoMixes());
Map<Sha256Hash, UtxoMixData> removedUtxoMixes = mapDifference.entriesOnlyOnRight();
wallet.getUtxoMixes().putAll(changedUtxoMixes);
wallet.getUtxoMixes().keySet().removeAll(removedUtxoMixes.keySet());
if (!changedUtxoMixes.isEmpty() || !removedUtxoMixes.isEmpty()) {
EventManager.get().post(new WalletUtxoMixesChangedEvent(wallet, changedUtxoMixes, removedUtxoMixes));
}
}
use of com.samourai.whirlpool.client.wallet.data.utxoConfig.UtxoConfigPersisted in project sparrow by sparrowwallet.
the class SparrowUtxoConfigPersister method read.
@Override
public synchronized UtxoConfigData read() throws Exception {
Wallet wallet = getWallet();
if (wallet == null) {
throw new IllegalStateException("Can't find wallet with walletId " + walletId);
}
Map<String, UtxoConfigPersisted> utxoConfigs = wallet.getUtxoMixes().entrySet().stream().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");
}, HashMap::new));
return new UtxoConfigData(utxoConfigs);
}
Aggregations