Skip to content

Commit

Permalink
chore: remove code related to old account balance processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-HuyLe3a committed Mar 7, 2024
1 parent affdc6e commit 27e873b
Show file tree
Hide file tree
Showing 26 changed files with 60 additions and 2,283 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.

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);
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package org.cardanofoundation.ledgersync.service;

import org.cardanofoundation.ledgersync.consumercommon.entity.StakeAddress;
import org.cardanofoundation.ledgersync.consumercommon.entity.Tx;
import org.cardanofoundation.ledgersync.aggregate.AggregatedAddressBalance;

import java.util.Collection;
import java.util.Map;

public interface AddressBalanceService {

/**
* Handle all addresses' balances
*
* @param aggregatedAddressBalanceMap a map with key is address string (Base58 or Bech32 form) and
* value is its aggregated balance
* @param stakeAddressMap a map with key is raw stake address hex and value is the
* respective stake address entity
* @param txMap a map with key is tx hash and value is the respective tx
* entity
*/
void handleAddressBalance(
Map<String, AggregatedAddressBalance> aggregatedAddressBalanceMap,
Map<String, StakeAddress> stakeAddressMap, Map<String, Tx> txMap);

/**
* Rollback address balances stats
*
* @param txs txs being rolled back
*/
void rollbackAddressBalances(Collection<Tx> txs);
}
//package org.cardanofoundation.ledgersync.service;
//
//import org.cardanofoundation.ledgersync.consumercommon.entity.StakeAddress;
//import org.cardanofoundation.ledgersync.consumercommon.entity.Tx;
//import org.cardanofoundation.ledgersync.aggregate.AggregatedAddressBalance;
//
//import java.util.Collection;
//import java.util.Map;
//
//public interface AddressBalanceService {
//
// /**
// * Handle all addresses' balances
// *
// * @param aggregatedAddressBalanceMap a map with key is address string (Base58 or Bech32 form) and
// * value is its aggregated balance
// * @param stakeAddressMap a map with key is raw stake address hex and value is the
// * respective stake address entity
// * @param txMap a map with key is tx hash and value is the respective tx
// * entity
// */
// void handleAddressBalance(
// Map<String, AggregatedAddressBalance> aggregatedAddressBalanceMap,
// Map<String, StakeAddress> stakeAddressMap, Map<String, Tx> txMap);
//
// /**
// * Rollback address balances stats
// *
// * @param txs txs being rolled back
// */
// void rollbackAddressBalances(Collection<Tx> txs);
//}
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
package org.cardanofoundation.ledgersync.service;


import com.bloxbean.cardano.client.api.util.AssetUtil;
import com.bloxbean.cardano.yaci.core.util.HexUtil;
import lombok.RequiredArgsConstructor;
import org.cardanofoundation.ledgersync.aggregate.AggregatedAddress;
import org.cardanofoundation.ledgersync.aggregate.AggregatedAddressBalance;
import org.cardanofoundation.ledgersync.aggregate.AggregatedBlock;
import org.cardanofoundation.ledgersync.aggregate.AggregatedTxOut;
import org.cardanofoundation.ledgersync.util.LedgerSyncAssetUtil;

import java.math.BigInteger;
import java.util.List;

import static com.bloxbean.cardano.yaci.core.util.Constants.LOVELACE;

@RequiredArgsConstructor
public abstract class BlockAggregatorService<T> // NOSONAR
Expand All @@ -31,48 +20,4 @@ public abstract class BlockAggregatorService<T> // NOSONAR
*/
public abstract AggregatedBlock aggregateBlock(T block);

/**
* This method iterates between all aggregated tx out and map it to
* aggregated address balance data
*
* @param aggregatedTxOuts all aggregated tx outs within a tx
* @param txHash tx hash of tx where the aggregated tx outs associate with
*/
public void mapAggregatedTxOutsToAddressBalanceMap(
List<AggregatedTxOut> aggregatedTxOuts, String txHash) {
// Iterate between all aggregated tx out
aggregatedTxOuts.forEach(aggregatedTxOut -> {
// Get aggregated block address
AggregatedAddress aggregatedAddress = aggregatedTxOut.getAddress();

// Get address string (Base58 or Bech32) from aggregated address
String address = aggregatedAddress.getAddress();

// Get address's native amount
BigInteger nativeAmount = aggregatedTxOut.getNativeAmount();

// Get aggregated address balance data
AggregatedAddressBalance aggregatedAddressBalance =
blockDataService.getAggregatedAddressBalanceFromAddress(address);

/*
* Because the native amount in process is output, it is added to
* existing balance record
*/
aggregatedAddressBalance.addNativeBalance(txHash, nativeAmount);

// Add multi-asset balances
aggregatedTxOut.getAmounts().stream()
.filter(amount -> !LOVELACE.equals(amount.getAssetName()))
.forEach(amount -> {
//byte[] assetName = amount.getAssetName();
String assetName = amount.getAssetName();
String policyId = amount.getPolicyId();
String assetNameAsHex = HexUtil.encodeHexString(amount.getAssetNameBytes(), true);
String fingerprint = AssetUtil.calculateFingerPrint(policyId, assetNameAsHex);
BigInteger quantity = amount.getQuantity();
aggregatedAddressBalance.addAssetBalance(txHash, fingerprint, quantity);
});
});
}
}
Loading

0 comments on commit 27e873b

Please sign in to comment.