Skip to content

Commit b12db08

Browse files
matiwinnetouMateusz Czeladka
andauthored
refactor: remove assetName (#619)
Co-authored-by: Mateusz Czeladka <mateusz.czeladka@cardanofoundation.org>
1 parent 4ade4c0 commit b12db08

File tree

9 files changed

+18
-27
lines changed

9 files changed

+18
-27
lines changed

api/src/main/java/org/cardanofoundation/rosetta/api/account/mapper/AccountMapperUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public List<Coin> mapUtxosToCoins(List<Utxo> utxos,
7676
Amt adaAsset = utxo.getAmounts().stream()
7777
.filter(amt -> Constants.LOVELACE.equals(amt.getUnit()))
7878
.findFirst()
79-
.orElseGet(() -> new Amt(null, null, Constants.ADA, BigInteger.ZERO));
79+
.orElseGet(() -> new Amt(null, Constants.ADA, BigInteger.ZERO));
80+
8081
String coinIdentifier = "%s:%d".formatted(utxo.getTxHash(), utxo.getOutputIndex());
8182

8283
return Coin.builder()

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ public class Amt implements Serializable {
2323
private String unit; // subject = policyId + hex(assetName)
2424
private String policyId;
2525

26-
// TODO avoid using assetName field for now
27-
// TODO ASCI in case of CIP-26 and bech32 in case of CIP-68, actually it should always be ASCII and never bech32
28-
@Deprecated
29-
// consider removing
30-
private String assetName;
31-
3226
private BigInteger quantity;
3327

28+
/**
29+
* Returns symbol as hex
30+
*
31+
* unit (subject) = policyId(hex) + symbol(hex)
32+
*/
33+
@Nullable
34+
public String getAssetNameAsHex() {
35+
return getSymbolHex();
36+
}
37+
3438
/**
3539
* Returns symbol as hex
3640
*
@@ -45,10 +49,4 @@ public String getSymbolHex() {
4549
return unit.replace(policyId, "");
4650
}
4751

48-
@Deprecated
49-
// TODO avoid using assetName field for now
50-
public String getAssetName() {
51-
return assetName;
52-
}
53-
5452
}

api/src/test/java/org/cardanofoundation/rosetta/api/account/mapper/AccountMapperUtilTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ private Amt createAmt(String policyId, String assetName, BigInteger quantity) {
512512
private Amt createAmt(String policyId, String assetName, BigInteger quantity, String unit) {
513513
return Amt.builder()
514514
.policyId(policyId)
515-
.assetName(assetName)
516515
.quantity(quantity)
517516
.unit(unit != null ? unit : (policyId != null ? policyId + assetName : assetName))
518517
.build();

api/src/test/java/org/cardanofoundation/rosetta/api/account/service/AccountServiceImplTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ void getAccountCoinsWithCurrenciesPositiveTest() {
344344
when(utxo.getTxHash()).thenReturn("txHash");
345345
when(utxo.getOutputIndex()).thenReturn(1);
346346
when(utxo.getAmounts()).thenReturn(
347-
Collections.singletonList(new Amt(LOVELACE, "", LOVELACE, BigInteger.valueOf(1000L))));
347+
Collections.singletonList(new Amt(LOVELACE, null, BigInteger.valueOf(1000L))));
348348
when(accountCoinsRequest.getAccountIdentifier()).thenReturn(accountIdentifier);
349349
when(accountCoinsRequest.getCurrencies()).thenReturn(Collections.singletonList(currency));
350350
when(accountIdentifier.getAddress()).thenReturn(accountAddress);
@@ -369,7 +369,7 @@ void getAccountCoinsWithNullCurrenciesPositiveTest() {
369369
when(utxo.getTxHash()).thenReturn("txHash");
370370
when(utxo.getOutputIndex()).thenReturn(1);
371371
when(utxo.getAmounts()).thenReturn(
372-
Collections.singletonList(new Amt(LOVELACE, "", LOVELACE, BigInteger.valueOf(1000L))));
372+
Collections.singletonList(new Amt(LOVELACE, null, BigInteger.valueOf(1000L))));
373373
when(accountCoinsRequest.getAccountIdentifier()).thenReturn(accountIdentifier);
374374
when(accountCoinsRequest.getCurrencies()).thenReturn(null);
375375
when(accountIdentifier.getAddress()).thenReturn(accountAddress);

api/src/test/java/org/cardanofoundation/rosetta/api/block/mapper/BlockToBlockResponseTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ void mapToBlockResponse_test_invalidTransaction() {
4141
.blockNo(1L)
4242
.inputs(
4343
List.of(Utxo.builder().txHash("Hash").outputIndex(0).ownerAddr("Owner").amounts(List.of(
44-
Amt.builder().unit(unit).policyId(policyId).assetName("tAda").quantity(BigInteger.valueOf(10L)).build()))
44+
Amt.builder().unit(unit).policyId(policyId).quantity(BigInteger.valueOf(10L)).build()))
4545
.build()))
4646
.outputs(
4747
List.of(Utxo.builder().txHash("Hash").outputIndex(0).ownerAddr("Owner").amounts(List.of(
48-
Amt.builder().unit(unit).policyId(policyId).assetName("tAda").quantity(BigInteger.valueOf(10L)).build()))
48+
Amt.builder().unit(unit).policyId(policyId).quantity(BigInteger.valueOf(10L)).build()))
4949
.build()))
5050
.build();
5151

api/src/test/java/org/cardanofoundation/rosetta/api/block/mapper/BlockTxToBlockTxResponseTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ private Utxo newUtxo() {
7272

7373
private static Amt newAmt() {
7474
return Amt.builder()
75-
.assetName("assetName1")
7675
.policyId("policyId1")
7776
.quantity(BigInteger.ONE)
7877
.unit("unit1")

api/src/test/java/org/cardanofoundation/rosetta/api/block/mapper/BlockTxToRosettaTransactionTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ private Utxo newUtxoOut() {
425425

426426
private static Amt newAdaAmt() {
427427
return Amt.builder()
428-
.assetName(Constants.LOVELACE)
429428
.quantity(BigInteger.TEN)
430429
.unit(Constants.LOVELACE)
431430
.build();
@@ -435,7 +434,6 @@ private static Amt newTokenAmt() {
435434
String policyId = "policyId1";
436435
String symbol = "assetName1";
437436
return Amt.builder()
438-
.assetName("assetName1")
439437
.policyId(policyId)
440438
.quantity(BigInteger.ONE)
441439
.unit(policyId + symbol)

api/src/test/java/org/cardanofoundation/rosetta/api/block/mapper/TransactionMapperUtilsTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ void mapToOperationMetaDataSpentAmountTest() {
243243

244244
List<Amt> amtList = Arrays.asList(
245245
Amt.builder()
246-
.assetName(assetName)
247246
.policyId(policyId)
248247
.quantity(BigInteger.valueOf(1000))
249248
.unit(policyId + assetName)
@@ -299,7 +298,6 @@ private static Amt newAmt(int policy, int number, boolean isLovelace) {
299298
String unit = isLovelace ? Constants.LOVELACE : policyId + symbol;
300299

301300
return Amt.builder()
302-
.assetName(isLovelace ? Constants.LOVELACE : "assetName" + number)
303301
.policyId(policyId)
304302
.quantity(BigInteger.ONE)
305303
.unit(unit)
@@ -310,7 +308,6 @@ private static Amt newAmtWithCustomName(String policyId, String assetName, boole
310308
String unit = isLovelace ? Constants.LOVELACE : policyId + assetName;
311309

312310
return Amt.builder()
313-
.assetName(isLovelace ? Constants.LOVELACE : assetName)
314311
.policyId(policyId)
315312
.quantity(BigInteger.ONE)
316313
.unit(unit)

api/src/test/java/org/cardanofoundation/rosetta/api/common/service/TokenRegistryServiceImplTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,11 +1112,10 @@ private Utxo createUtxoWithAmounts(List<Amt> amounts) {
11121112
return Utxo.builder().amounts(amounts).build();
11131113
}
11141114

1115-
private Amt createAmt(String assetName, String policyId, String unit) {
1115+
private Amt createAmt(String unit, String policyId, String lovelaceOrUnit) {
11161116
return Amt.builder()
1117-
.assetName(assetName)
11181117
.policyId(policyId)
1119-
.unit(unit)
1118+
.unit(lovelaceOrUnit)
11201119
.quantity(BigDecimal.valueOf(1000000).toBigInteger())
11211120
.build();
11221121
}

0 commit comments

Comments
 (0)