Skip to content

Commit bad9217

Browse files
authored
Merge branch 'main' into feat/RA-60-Single-docker-container
2 parents c4c7d6a + 0c758f7 commit bad9217

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

api/src/main/java/org/cardanofoundation/rosetta/api/construction/service/CardanoConstructionService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ public interface CardanoConstructionService {
3535
TransactionParsed parseTransaction(NetworkIdentifierType networkIdentifierType,
3636
String transaction, boolean signed);
3737

38-
Double checkOrReturnDefaultTtl(Integer relativeTtl);
38+
Integer checkOrReturnDefaultTtl(Integer relativeTtl);
3939
Long updateTxSize(Long previousTxSize, Long previousTtl, Long updatedTtl);
4040
Long calculateTxMinimumFee(Long transactionSize, ProtocolParams protocolParameters);
4141

4242
Signatures signatureProcessor(EraAddressType eraAddressType, AddressType addressType,
4343
String address);
4444

45-
Double calculateTxSize(NetworkIdentifierType networkIdentifierType, List<Operation> operations, int ttl, DepositParameters depositParameters);
45+
Integer calculateTxSize(NetworkIdentifierType networkIdentifierType, List<Operation> operations, int ttl, DepositParameters depositParameters);
4646

4747
String buildTransaction(String unsignedTransaction,
4848
List<Signatures> signaturesList, String transactionMetadata);

api/src/main/java/org/cardanofoundation/rosetta/api/construction/service/CardanoConstructionServiceImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public TransactionParsed parseTransaction(NetworkIdentifierType networkIdentifie
112112
}
113113

114114
@Override
115-
public Double checkOrReturnDefaultTtl(Integer relativeTtl) {
116-
return relativeTtl == null ? Constants.DEFAULT_RELATIVE_TTL : relativeTtl.doubleValue();
115+
public Integer checkOrReturnDefaultTtl(Integer relativeTtl) {
116+
return relativeTtl == null ? Constants.DEFAULT_RELATIVE_TTL : relativeTtl;
117117
}
118118

119119
@Override
@@ -194,7 +194,7 @@ public Signatures signatureProcessor(EraAddressType eraAddressType, AddressType
194194
}
195195

196196
@Override
197-
public Double calculateTxSize(NetworkIdentifierType networkIdentifierType,
197+
public Integer calculateTxSize(NetworkIdentifierType networkIdentifierType,
198198
List<Operation> operations, int ttl, DepositParameters depositParameters) {
199199
UnsignedTransaction unsignedTransaction;
200200
try {
@@ -219,7 +219,9 @@ public Double calculateTxSize(NetworkIdentifierType networkIdentifierType,
219219

220220
String transaction = buildTransaction(unsignedTransaction.bytes(), signaturesList,
221221
unsignedTransaction.metadata());
222-
return ((double) transaction.length() / 2);
222+
// the String transaction represents Hex encoded bytes of the transaction.
223+
// To get the size of the transaction in bytes, we need to divide the length by two. Because every Hex character represents 4 bits.
224+
return (transaction.length() / 2);
223225

224226
}
225227

api/src/main/java/org/cardanofoundation/rosetta/api/construction/service/ConstructionApiServiceImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public ConstructionPreprocessResponse constructionPreprocessService(
100100
NetworkIdentifier networkIdentifier = constructionPreprocessRequest.getNetworkIdentifier();
101101
Optional<ConstructionPreprocessMetadata> metadata = Optional.ofNullable(
102102
constructionPreprocessRequest.getMetadata());
103-
Double relativeTtl;
103+
int relativeTtl;
104104
DepositParameters depositParameters;
105105
if (metadata.isPresent()) {
106106
relativeTtl = cardanoConstructionService.checkOrReturnDefaultTtl(
@@ -112,10 +112,10 @@ public ConstructionPreprocessResponse constructionPreprocessService(
112112
depositParameters = cardanoConstructionService.getDepositParameters();
113113
}
114114

115-
Double transactionSize = cardanoConstructionService.calculateTxSize(
115+
int transactionSize = cardanoConstructionService.calculateTxSize(
116116
NetworkIdentifierType.findByName(networkIdentifier.getNetwork()),
117117
constructionPreprocessRequest.getOperations(), 0, depositParameters);
118-
Map<String, Double> response = Map.of(Constants.RELATIVE_TTL, relativeTtl,
118+
Map<String, Integer> response = Map.of(Constants.RELATIVE_TTL, relativeTtl,
119119
Constants.TRANSACTION_SIZE,
120120
transactionSize);
121121
return new ConstructionPreprocessResponse(response, null);
@@ -160,13 +160,13 @@ public ConstructionPayloadsResponse constructionPayloadsService(
160160
int ttl;
161161
DepositParameters depositParameters;
162162
if (metadata.isPresent()) {
163-
ttl = cardanoConstructionService.checkOrReturnDefaultTtl(metadata.get().getTtl()).intValue();
163+
ttl = cardanoConstructionService.checkOrReturnDefaultTtl(metadata.get().getTtl());
164164
depositParameters = Optional.ofNullable(metadata.get().getProtocolParameters()).map(
165165
protocolParameters -> new DepositParameters(protocolParameters.getKeyDeposit(),
166166
protocolParameters.getPoolDeposit())).orElse(
167167
cardanoConstructionService.getDepositParameters());
168168
} else {
169-
ttl = Constants.DEFAULT_RELATIVE_TTL.intValue();
169+
ttl = Constants.DEFAULT_RELATIVE_TTL;
170170
depositParameters = cardanoConstructionService.getDepositParameters();
171171
}
172172

api/src/main/java/org/cardanofoundation/rosetta/common/util/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private Constants() {
5454
public static final String MAINNET = "Mainnet";
5555
public static final String VALID_CURVE_TYPE = CurveType.EDWARDS25519.getValue();
5656
public static final int PUBLIC_KEY_BYTES_LENGTH = 64;
57-
public static final Double DEFAULT_RELATIVE_TTL = 1000.0;
57+
public static final Integer DEFAULT_RELATIVE_TTL = 1000;
5858

5959
public static final String EMPTY_HEX = "\\x";
6060

api/src/test/java/org/cardanofoundation/rosetta/api/construction/service/PreprocessApiTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private void assertPreprocessRequest(String constructionPayloadFile, int expecte
5252

5353
ConstructionPreprocessResponse constructionPreprocessResponse = constructionApiService.constructionPreprocessService(
5454
preprocessRequest);
55-
Map<String, Double> options = (Map<String, Double>) constructionPreprocessResponse.getOptions();
55+
Map<String, Integer> options = (Map<String, Integer>) constructionPreprocessResponse.getOptions();
5656
assertEquals(expectedTtl, options.get("relative_ttl"));
5757
assertEquals(expectedTransactionSize, options.get("transaction_size"));
5858
}

0 commit comments

Comments
 (0)