forked from Qortal/qortal
Removed transaction caching. Can be reintroduced later.
This commit is contained in:
parent
d1f24d45da
commit
9804eccbf0
@ -33,7 +33,6 @@ import org.qortal.utils.Amounts;
|
|||||||
import org.qortal.utils.BitTwiddling;
|
import org.qortal.utils.BitTwiddling;
|
||||||
|
|
||||||
import com.google.common.hash.HashCode;
|
import com.google.common.hash.HashCode;
|
||||||
import org.qortal.utils.NTP;
|
|
||||||
|
|
||||||
/** Bitcoin-like (Bitcoin, Litecoin, etc.) support */
|
/** Bitcoin-like (Bitcoin, Litecoin, etc.) support */
|
||||||
public abstract class Bitcoiny implements ForeignBlockchain {
|
public abstract class Bitcoiny implements ForeignBlockchain {
|
||||||
@ -48,12 +47,6 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
|||||||
|
|
||||||
protected final NetworkParameters params;
|
protected final NetworkParameters params;
|
||||||
|
|
||||||
/** Cache recent transactions to speed up subsequent lookups */
|
|
||||||
protected List<SimpleTransaction> transactionsCache;
|
|
||||||
protected Long transactionsCacheTimestamp;
|
|
||||||
protected String transactionsCacheXpub;
|
|
||||||
protected static long TRANSACTIONS_CACHE_TIMEOUT = 2 * 60 * 1000L; // 2 minutes
|
|
||||||
|
|
||||||
/** Keys that have been previously marked as fully spent,<br>
|
/** Keys that have been previously marked as fully spent,<br>
|
||||||
* i.e. keys with transactions but with no unspent outputs. */
|
* i.e. keys with transactions but with no unspent outputs. */
|
||||||
protected final Set<ECKey> spentKeys = Collections.synchronizedSet(new HashSet<>());
|
protected final Set<ECKey> spentKeys = Collections.synchronizedSet(new HashSet<>());
|
||||||
@ -350,17 +343,6 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
|||||||
|
|
||||||
public List<SimpleTransaction> getWalletTransactions(String key58) throws ForeignBlockchainException {
|
public List<SimpleTransaction> getWalletTransactions(String key58) throws ForeignBlockchainException {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// Serve from the cache if it's recent, and matches this xpub
|
|
||||||
if (Objects.equals(transactionsCacheXpub, key58)) {
|
|
||||||
if (transactionsCache != null && transactionsCacheTimestamp != null) {
|
|
||||||
Long now = NTP.getTime();
|
|
||||||
boolean isCacheStale = (now != null && now - transactionsCacheTimestamp >= TRANSACTIONS_CACHE_TIMEOUT);
|
|
||||||
if (!isCacheStale) {
|
|
||||||
return transactionsCache;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Context.propagate(bitcoinjContext);
|
Context.propagate(bitcoinjContext);
|
||||||
|
|
||||||
Wallet wallet = walletFromDeterministicKey58(key58);
|
Wallet wallet = walletFromDeterministicKey58(key58);
|
||||||
@ -423,13 +405,9 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
|||||||
Comparator<SimpleTransaction> newestTimestampFirstComparator = Comparator.comparingInt(SimpleTransaction::getTimestamp).reversed();
|
Comparator<SimpleTransaction> newestTimestampFirstComparator = Comparator.comparingInt(SimpleTransaction::getTimestamp).reversed();
|
||||||
|
|
||||||
// Update cache and return
|
// Update cache and return
|
||||||
transactionsCacheTimestamp = NTP.getTime();
|
return walletTransactions.stream()
|
||||||
transactionsCacheXpub = key58;
|
|
||||||
transactionsCache = walletTransactions.stream()
|
|
||||||
.map(t -> convertToSimpleTransaction(t, keySet))
|
.map(t -> convertToSimpleTransaction(t, keySet))
|
||||||
.sorted(newestTimestampFirstComparator).collect(Collectors.toList());
|
.sorted(newestTimestampFirstComparator).collect(Collectors.toList());
|
||||||
|
|
||||||
return transactionsCache;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user