-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from bloxbean/account_balance
feat(account/utxo): Run time account balance aggregation support
- Loading branch information
Showing
22 changed files
with
410 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...unt/src/main/java/com/bloxbean/cardano/yaci/store/account/service/UtxoAccountService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.bloxbean.cardano.yaci.store.account.service; | ||
|
||
import com.bloxbean.cardano.yaci.store.client.utxo.UtxoClient; | ||
import com.bloxbean.cardano.yaci.store.common.domain.Utxo; | ||
import com.bloxbean.cardano.yaci.store.utxo.domain.Amount; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.math.BigInteger; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class UtxoAccountService { | ||
private final UtxoClient utxoClient; | ||
|
||
public List<Amount> getAmountsAtAddress(String address) { | ||
int page = 0; | ||
|
||
Map<String, Amount> amountMap = new HashMap<>(); | ||
while (true) { | ||
List<Utxo> utxos = utxoClient.getUtxoByAddress(address, page, 100); | ||
if (utxos == null || utxos.size() == 0) | ||
break; | ||
|
||
utxos.stream() | ||
.flatMap(utxo -> utxo.getAmount().stream()) | ||
.forEach(utxoAmt -> { | ||
Amount existingAmount = amountMap.get(utxoAmt.getUnit()); | ||
if(existingAmount == null) { | ||
Amount newAmount = new Amount(utxoAmt.getUnit(), utxoAmt.getQuantity()); | ||
amountMap.put(utxoAmt.getUnit(), newAmount); | ||
} else { | ||
BigInteger newQty = existingAmount.getQuantity().add(utxoAmt.getQuantity()); | ||
existingAmount.setQuantity(newQty); | ||
} | ||
}); | ||
|
||
page++; | ||
} | ||
|
||
return new ArrayList<>(amountMap.values()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
|
||
██ ██ █████ ██████ ██ ███████ ████████ ██████ ██████ ███████ | ||
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ | ||
████ ███████ ██ ██ ███████ ██ ██ ██ ██████ █████ | ||
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ | ||
██ ██ ██ ██████ ██ ███████ ██ ██████ ██ ██ ███████ | ||
A BloxBean Project | ||
|
||
|
||
██ ██ ████████ ██ ██ ██████ ██ ███ ██ ██████ ███████ ██ ██ ███████ ██████ | ||
██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ | ||
██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ █████ ███ █████ ██████ | ||
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ | ||
██████ ██ ██ ██ ██████ ██ ██ ████ ██████ ███████ ██ ██ ███████ ██ ██ | ||
|
32 changes: 32 additions & 0 deletions
32
...nts/client/src/main/java/com/bloxbean/cardano/yaci/store/client/utxo/DummyUtxoClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.bloxbean.cardano.yaci.store.client.utxo; | ||
|
||
import com.bloxbean.cardano.yaci.store.common.domain.AddressUtxo; | ||
import com.bloxbean.cardano.yaci.store.common.domain.Utxo; | ||
import com.bloxbean.cardano.yaci.store.common.domain.UtxoKey; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Slf4j | ||
public class DummyUtxoClient implements UtxoClient { | ||
public DummyUtxoClient() { | ||
log.warn("Dummy Utxo Client Configured >>>>>>>>"); | ||
} | ||
|
||
@Override | ||
public List<AddressUtxo> getUtxosByIds(List<UtxoKey> utxoIds) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public Optional<AddressUtxo> getUtxoById(UtxoKey utxoId) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public List<Utxo> getUtxoByAddress(String address, int page, int count) { | ||
return Collections.emptyList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ents/common/src/main/java/com/bloxbean/cardano/yaci/store/common/util/Bech32Prefixes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.bloxbean.cardano.yaci.store.common.util; | ||
|
||
public class Bech32Prefixes { | ||
public static final String ADDR_PREFIX = "addr"; | ||
public static final String STAKE_ADDR_PREFIX = "stake"; | ||
public static final String ADDR_VKEY_HASH_PREFIX = "addr_vkh"; | ||
public static final String STAKE_ADDR_VKEY_HASH_PREFIX = "stake_vkh"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.