Skip to content

Commit

Permalink
chore: remove code related to old account balance processing (#141)
Browse files Browse the repository at this point in the history
* chore: remove code related to old account balance processing

* chore: remove AddressTxBalanceProjection.java

* chore: remove CustomAddressTokenBalanceRepository.java and CustomAddressTokenBalanceRepositoryImpl.java

* chore: remove unused entities, unused fields in entities and related code

* chore: add migration script to remove old account balance related tables, columns

* chore: update unit test
  • Loading branch information
Sotatek-HuyLe3a authored Mar 12, 2024
1 parent 7ad53e7 commit 601564d
Show file tree
Hide file tree
Showing 43 changed files with 39 additions and 2,822 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class AggregatedBatchBlockData {

// Key is address (Bech32 or Base58 format)
Map<String, AggregatedAddressBalance> aggregatedAddressBalanceMap;

// Key is stake address hex, value is first appeared tx hash
Map<String, String> stakeAddressTxHashMap;

Expand All @@ -32,7 +29,6 @@ public class AggregatedBatchBlockData {
Map<String, AggregatedBlock> aggregatedBlockMap;

public AggregatedBatchBlockData() {
aggregatedAddressBalanceMap = new ConcurrentHashMap<>();
stakeAddressTxHashMap = new ConcurrentHashMap<>();
notMintedAssetFingerprintTxHashSet = new LinkedHashSet<>();
fingerprintFirstAppearedMap = new ConcurrentHashMap<>();
Expand All @@ -42,7 +38,6 @@ public AggregatedBatchBlockData() {

// This method must be called every batch saving
public void clear() {
aggregatedAddressBalanceMap.clear();
stakeAddressTxHashMap.clear();
notMintedAssetFingerprintTxHashSet.clear();
fingerprintFirstAppearedMap.clear();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.cardanofoundation.ledgersync.repository;

import org.cardanofoundation.ledgersync.consumercommon.entity.Epoch;
import org.cardanofoundation.ledgersync.projection.UniqueAccountTxCountProjection;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -22,22 +21,6 @@ public interface EpochRepository extends JpaRepository<Epoch, Long> {

Optional<Epoch> findFirstByOrderByNoDesc();

@Query("""
SELECT
(CASE
WHEN a.stakeAddress IS NULL THEN a.address
ELSE CAST(a.stakeAddress.id AS STRING)
END) AS account,
COUNT(atb) AS txCount
FROM Block b
JOIN Tx tx ON tx.block = b
JOIN AddressTxBalance atb on atb.tx = tx
JOIN Address a ON atb.address = a
WHERE b.epochNo = :epochNo
GROUP BY account
""")
List<UniqueAccountTxCountProjection> findUniqueAccountsInEpoch(@Param("epochNo") Integer epochNo);

@Query("""
SELECT e.no FROM Epoch e WHERE e.maxSlot = :maxSlot AND e.no > :lastEpochParam ORDER BY e.no
""")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package org.cardanofoundation.ledgersync.repository;

import org.cardanofoundation.ledgersync.consumercommon.entity.MultiAsset;
import org.cardanofoundation.ledgersync.consumercommon.entity.Tx;
import org.cardanofoundation.ledgersync.projection.MultiAssetTotalVolumeProjection;
import org.cardanofoundation.ledgersync.projection.MultiAssetTxCountProjection;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -24,19 +19,4 @@ public interface MultiAssetRepository extends JpaRepository<MultiAsset, Long> {
*/
@Transactional(readOnly = true)
List<MultiAsset> findMultiAssetsByFingerprintIn(Collection<String> fingerprints);

@Query("SELECT at.multiAsset.id AS identId, "
+ "COUNT(DISTINCT at.tx) as txCount "
+ "FROM AddressToken at "
+ "WHERE at.tx IN (:txs) "
+ "GROUP BY at.multiAsset")
List<MultiAssetTxCountProjection> getMultiAssetTxCountByTxs(@Param("txs") Collection<Tx> txs);

@Query("SELECT at.multiAsset.id as identId,"
+ "SUM(at.balance) as totalVolume "
+ "FROM AddressToken at "
+ "WHERE at.tx IN (:txs) AND at.balance > 0"
+ "GROUP BY at.multiAsset")
List<MultiAssetTotalVolumeProjection> getMultiAssetTotalVolumeByTxs(
@Param("txs") Collection<Tx> txs);
}
Loading

0 comments on commit 601564d

Please sign in to comment.