Skip to content

Commit e45595f

Browse files
author
Mateusz Czeladka
committed
feat: token registry integration into Rosetta API part 12.
1 parent 62c3740 commit e45595f

File tree

8 files changed

+93
-222
lines changed

8 files changed

+93
-222
lines changed

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ docker exec rosetta tail -f /logs/indexer.log
7575
- Controller implementations in `api/{domain}/controller/` implement generated interfaces
7676
- Always use @Nullable annotation in case of optional fields for function methods parameter inputs and outputs, records, DTOs, and entities
7777
- Avoid if { return } else {} , if we already have a return statement, we can just return the value, no need for else block
78+
- Use @NotNull annotation everywhere where we can be sure that value will not be null, use @Nullable in case value can be null sometimes
79+
- Considering that we will have @NotNull and @Nullable annotations, just put nulls checks only when you actually need it, if a field / property is annotated with @NonNull, there is no need for a null check in the code
7880

7981
### Database Architecture
8082
- **Hibernate JPA** for standard ORM operations

api/src/main/java/org/cardanofoundation/rosetta/api/account/model/domain/Utxo.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package org.cardanofoundation.rosetta.api.account.model.domain;
22

3-
import java.util.List;
4-
53
import lombok.AllArgsConstructor;
64
import lombok.Builder;
75
import lombok.Data;
86
import lombok.NoArgsConstructor;
97

8+
import javax.validation.constraints.NotNull;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
1012
@Data
1113
@AllArgsConstructor
1214
@NoArgsConstructor
@@ -16,7 +18,10 @@ public class Utxo {
1618
private String txHash;
1719
private Integer outputIndex;
1820
private String ownerAddr;
19-
private List<Amt> amounts;
21+
22+
@NotNull
23+
@Builder.Default
24+
private List<Amt> amounts = new ArrayList<>();
2025

2126
public Utxo(String txHash, Integer outputIndex) {
2227
this.txHash = txHash;

api/src/main/java/org/cardanofoundation/rosetta/api/account/service/LedgerAccountServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public List<Utxo> findUtxoByAddressAndCurrency(String address, List<CurrencyRequ
6767
private Utxo createUtxoModel(List<CurrencyRequest> currencies, AddressUtxoEntity entity) {
6868
Utxo utxo = addressUtxoEntityToUtxo.toDto(entity);
6969
utxo.setAmounts(getAmts(currencies, entity));
70+
7071
return utxo;
7172
}
7273

api/src/main/java/org/cardanofoundation/rosetta/api/common/service/TokenRegistryService.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import org.cardanofoundation.rosetta.api.account.model.domain.Utxo;
66
import org.cardanofoundation.rosetta.api.block.model.domain.BlockTx;
77
import org.cardanofoundation.rosetta.api.common.model.Asset;
8-
import org.openapitools.client.model.Amount;
98
import org.openapitools.client.model.BlockTransaction;
109
import org.openapitools.client.model.CurrencyMetadataResponse;
1110
import org.openapitools.client.model.Operation;
1211

12+
import lombok.NonNull;
13+
import javax.annotation.Nullable;
14+
import javax.validation.constraints.NotNull;
1315
import java.util.List;
1416
import java.util.Map;
1517
import java.util.Set;
@@ -26,50 +28,50 @@ public interface TokenRegistryService {
2628
* @param assets Set of Asset objects containing policyId and optional assetName
2729
* @return Map of Asset -> CurrencyMetadataResponse with metadata (always returns at least policyId)
2830
*/
29-
Map<Asset, CurrencyMetadataResponse> getTokenMetadataBatch(Set<Asset> assets);
31+
Map<Asset, CurrencyMetadataResponse> getTokenMetadataBatch(@NotNull Set<Asset> assets);
3032

3133
/**
3234
* Extract all native token assets from a BlockTx (inputs and outputs)
3335
* @param blockTx The block transaction to extract assets from
3436
* @return Set of unique Asset objects found in the transaction
3537
*/
36-
Set<Asset> extractAssetsFromBlockTx(BlockTx blockTx);
38+
Set<Asset> extractAssetsFromBlockTx(@NonNull BlockTx blockTx);
3739

3840
/**
3941
* Extract all native token assets from a list of BlockTransaction objects
4042
* @param transactions List of BlockTransaction objects from search results
4143
* @return Set of unique Asset objects found across all transactions
4244
*/
43-
Set<Asset> extractAssetsFromBlockTransactions(List<BlockTransaction> transactions);
45+
Set<Asset> extractAssetsFromBlockTransactions(@NotNull List<BlockTransaction> transactions);
4446

4547
/**
4648
* Extract assets from a list of Amt objects (utility method)
4749
* @param amounts List of amounts potentially containing native tokens
4850
* @return Set of unique Asset objects (excludes ADA/lovelace)
4951
*/
50-
Set<Asset> extractAssetsFromAmounts(List<Amt> amounts);
52+
Set<Asset> extractAssetsFromAmounts(@NonNull List<Amt> amounts);
5153

5254
/**
5355
* Extract assets from a list of Operation objects
5456
* @param operations List of operations potentially containing native tokens
5557
* @return Set of unique Asset objects found in operation amounts
5658
*/
57-
Set<Asset> extractAssetsFromOperations(List<Operation> operations);
59+
Set<Asset> extractAssetsFromOperations(@NotNull List<Operation> operations);
5860

5961
/**
6062
* Convenience method to extract assets and fetch metadata for a BlockTx in one call
6163
* @param blockTx The block transaction to process
6264
* @return Map of Asset -> CurrencyMetadataResponse with metadata
6365
*/
64-
Map<Asset, CurrencyMetadataResponse> fetchMetadataForBlockTx(BlockTx blockTx);
66+
Map<Asset, CurrencyMetadataResponse> fetchMetadataForBlockTx(@NotNull BlockTx blockTx);
6567

6668
/**
6769
* Convenience method to extract assets and fetch metadata for BlockTransactions in one call
6870
* @param transactions List of BlockTransaction objects from search results
6971
* @return Map of Asset -> CurrencyMetadataResponse with metadata
7072
*/
71-
Map<Asset, CurrencyMetadataResponse> fetchMetadataForBlockTransactions(List<BlockTransaction> transactions);
72-
73+
Map<Asset, CurrencyMetadataResponse> fetchMetadataForBlockTransactions(@NotNull List<BlockTransaction> transactions);
74+
7375
/**
7476
* Convenience method to extract assets and fetch metadata for a list of BlockTx objects in one call.
7577
* This method handles the common pattern of processing multiple transactions and fetching their metadata
@@ -78,20 +80,20 @@ public interface TokenRegistryService {
7880
* @param blockTxList List of BlockTx objects to process
7981
* @return Map of Asset -> CurrencyMetadataResponse with metadata (empty map if no native tokens)
8082
*/
81-
Map<Asset, CurrencyMetadataResponse> fetchMetadataForBlockTxList(List<BlockTx> blockTxList);
83+
Map<Asset, CurrencyMetadataResponse> fetchMetadataForBlockTxList(@NotNull List<BlockTx> blockTxList);
8284

8385
/**
8486
* Extract all native token assets from AddressBalance list and fetch metadata in a single batch call
8587
* @param balances List of address balances potentially containing native tokens
8688
* @return Map of Asset -> CurrencyMetadataResponse with metadata
8789
*/
88-
Map<Asset, CurrencyMetadataResponse> fetchMetadataForAddressBalances(List<AddressBalance> balances);
90+
Map<Asset, CurrencyMetadataResponse> fetchMetadataForAddressBalances(@NotNull List<AddressBalance> balances);
8991

9092
/**
9193
* Extract all native token assets from UTXO list and fetch metadata in a single batch call
9294
* @param utxos List of UTXOs potentially containing native tokens
9395
* @return Map of Asset -> CurrencyMetadataResponse with metadata
9496
*/
95-
Map<Asset, CurrencyMetadataResponse> fetchMetadataForUtxos(List<Utxo> utxos);
97+
Map<Asset, CurrencyMetadataResponse> fetchMetadataForUtxos(@NotNull List<Utxo> utxos);
9698

9799
}

0 commit comments

Comments
 (0)