Skip to content

Commit

Permalink
RA-92: Changed output data from Double to Integer to maintain consist…
Browse files Browse the repository at this point in the history
…ency
  • Loading branch information
Gennadii-T committed May 8, 2024
1 parent cf30a02 commit 3e72391
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ConstructionPreprocessResponse constructionPreprocessService(
NetworkIdentifier networkIdentifier = constructionPreprocessRequest.getNetworkIdentifier();
Optional<ConstructionPreprocessMetadata> metadata = Optional.ofNullable(
constructionPreprocessRequest.getMetadata());
Double relativeTtl;
int relativeTtl;
DepositParameters depositParameters;
if(metadata.isPresent()) {
relativeTtl = cardanoService.checkOrReturnDefaultTtl(metadata.get().getRelativeTtl());
Expand All @@ -87,10 +87,10 @@ public ConstructionPreprocessResponse constructionPreprocessService(
depositParameters = cardanoService.getDepositParameters();
}

Double transactionSize = cardanoService.calculateTxSize(
int transactionSize = cardanoService.calculateTxSize(
NetworkIdentifierType.findByName(networkIdentifier.getNetwork()),
constructionPreprocessRequest.getOperations(), 0, depositParameters);
Map<String, Double> response = Map.of(Constants.RELATIVE_TTL, relativeTtl,
Map<String, Integer> response = Map.of(Constants.RELATIVE_TTL, relativeTtl,
Constants.TRANSACTION_SIZE,
transactionSize);
return new ConstructionPreprocessResponse(response, null);
Expand Down Expand Up @@ -133,10 +133,10 @@ public ConstructionPayloadsResponse constructionPayloadsService(
int ttl;
DepositParameters depositParameters;
if(metadata.isPresent()) {
ttl = cardanoService.checkOrReturnDefaultTtl(metadata.get().getTtl()).intValue();
ttl = cardanoService.checkOrReturnDefaultTtl(metadata.get().getTtl());
depositParameters = Optional.ofNullable(metadata.get().getProtocolParameters()).map(protocolParameters -> new DepositParameters(protocolParameters.getKeyDeposit(), protocolParameters.getPoolDeposit())).orElse(cardanoService.getDepositParameters());
} else {
ttl = Constants.DEFAULT_RELATIVE_TTL.intValue();
ttl = Constants.DEFAULT_RELATIVE_TTL;
depositParameters = cardanoService.getDepositParameters();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public interface CardanoService {
TransactionParsed parseTransaction(NetworkIdentifierType networkIdentifierType,
String transaction, boolean signed);

Double checkOrReturnDefaultTtl(Integer relativeTtl);
Integer checkOrReturnDefaultTtl(Integer relativeTtl);
Long updateTxSize(Long previousTxSize, Long previousTtl, Long updatedTtl);
Long calculateTxMinimumFee(Long transactionSize, ProtocolParams protocolParameters);

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

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

String buildTransaction(String unsignedTransaction,
List<Signatures> signaturesList, String transactionMetadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public TransactionParsed parseTransaction(NetworkIdentifierType networkIdentifie
}

@Override
public Double checkOrReturnDefaultTtl(Integer relativeTtl) {
return relativeTtl == null ? Constants.DEFAULT_RELATIVE_TTL : relativeTtl.doubleValue();
public Integer checkOrReturnDefaultTtl(Integer relativeTtl) {
return relativeTtl == null ? Constants.DEFAULT_RELATIVE_TTL : relativeTtl;
}

@Override
Expand Down Expand Up @@ -195,7 +195,7 @@ public Signatures signatureProcessor(EraAddressType eraAddressType, AddressType
}

@Override
public Double calculateTxSize(NetworkIdentifierType networkIdentifierType,
public Integer calculateTxSize(NetworkIdentifierType networkIdentifierType,
List<Operation> operations, int ttl, DepositParameters depositParameters) {
UnsignedTransaction unsignedTransaction;
try {
Expand All @@ -220,7 +220,7 @@ public Double calculateTxSize(NetworkIdentifierType networkIdentifierType,

String transaction = buildTransaction(unsignedTransaction.bytes(), signaturesList,
unsignedTransaction.metadata());
return ((double) transaction.length() / 2);
return (transaction.length() / 2);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private Constants() {
public static final String MAINNET = "Mainnet";
public static final String VALID_CURVE_TYPE = CurveType.EDWARDS25519.getValue();
public static final int PUBLIC_KEY_BYTES_LENGTH = 64;
public static final Double DEFAULT_RELATIVE_TTL = 1000.0;
public static final Integer DEFAULT_RELATIVE_TTL = 1000;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void simplePreprocessTest()

ConstructionPreprocessResponse constructionPreprocessResponse = constructionApiService.constructionPreprocessService(
preprocessRequest);
Map<String, Double> options = (Map<String, Double>)constructionPreprocessResponse.getOptions();
Map<String, Integer> options = (Map<String, Integer>)constructionPreprocessResponse.getOptions();
assertEquals(1000, options.get("relative_ttl"));
assertEquals(224, options.get("transaction_size"));
}
Expand All @@ -52,7 +52,7 @@ public void twoWithdrawalsTest()

ConstructionPreprocessResponse constructionPreprocessResponse = constructionApiService.constructionPreprocessService(
preprocessRequest);
Map<String, Double> options = (Map<String, Double>)constructionPreprocessResponse.getOptions();
Map<String, Integer> options = (Map<String, Integer>)constructionPreprocessResponse.getOptions();
assertEquals(100, options.get("relative_ttl"));
assertEquals(399, options.get("transaction_size"));
}
Expand All @@ -65,7 +65,7 @@ public void poolRegistrationTest()

ConstructionPreprocessResponse constructionPreprocessResponse = constructionApiService.constructionPreprocessService(
preprocessRequest);
Map<String, Double> options = (Map<String, Double>)constructionPreprocessResponse.getOptions();
Map<String, Integer> options = (Map<String, Integer>)constructionPreprocessResponse.getOptions();
assertEquals(100, options.get("relative_ttl"));
assertEquals(921, options.get("transaction_size"));
}
Expand Down

0 comments on commit 3e72391

Please sign in to comment.