Skip to content

Commit

Permalink
fix: fix issue with incorrect transaction size and ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Czeladka authored and matiwinnetou committed Feb 27, 2025
1 parent 7ace666 commit 0c60fd8
Show file tree
Hide file tree
Showing 48 changed files with 846 additions and 472 deletions.
1 change: 0 additions & 1 deletion .env.IntegrationTest
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,3 @@ YACI_HTTP_BASE_URL=http://localhost:9095/api/v1
YACI_INDEXER_PORT=9095
HTTP_CONNECT_TIMEOUT_SECONDS=5
HTTP_REQUEST_TIMEOUT_SECONDS=5

1 change: 0 additions & 1 deletion .env.docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ INDEXER_DOCKER_IMAGE_TAG=main
PRUNING_ENABLED=false

YACI_SPRING_PROFILES=postgres,n2c-socket
YACI_INDEXER_PORT=9095
# database profiles: h2, h2-testData, postgres
MEMPOOL_ENABLED=false

Expand Down
5 changes: 5 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>

<dependency>
<groupId>org.cardanofoundation</groupId>
<artifactId>cf-cardano-conversions-java</artifactId>
</dependency>

<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public CommonsRequestLoggingFilter logFilter() {
filter.setMaxPayloadLength(10000);
filter.setIncludeHeaders(false);
filter.setAfterMessagePrefix("REQUEST DATA: \n");

return filter;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class AccountApiImplementation implements AccountApi {
public ResponseEntity<AccountBalanceResponse> accountBalance(
@Valid @RequestBody AccountBalanceRequest accountBalanceRequest) {
if(offlineMode) {
throw ExceptionFactory.NotSupportedInOfflineMode();
throw ExceptionFactory.notSupportedInOfflineMode();
}
networkService.verifyNetworkRequest(accountBalanceRequest.getNetworkIdentifier());

Expand All @@ -43,7 +43,7 @@ public ResponseEntity<AccountBalanceResponse> accountBalance(
public ResponseEntity<AccountCoinsResponse> accountCoins(
@Valid @RequestBody AccountCoinsRequest accountCoinsRequest) {
if(offlineMode) {
throw ExceptionFactory.NotSupportedInOfflineMode();
throw ExceptionFactory.notSupportedInOfflineMode();
}
networkService.verifyNetworkRequest(accountCoinsRequest.getNetworkIdentifier());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class BlockApiImpl implements BlockApi {
@Override
public ResponseEntity<BlockResponse> block(@RequestBody BlockRequest blockRequest) {
if(offlineMode) {
throw ExceptionFactory.NotSupportedInOfflineMode();
throw ExceptionFactory.notSupportedInOfflineMode();
}
networkService.verifyNetworkRequest(blockRequest.getNetworkIdentifier());

Expand All @@ -52,7 +52,7 @@ public ResponseEntity<BlockResponse> block(@RequestBody BlockRequest blockReques
public ResponseEntity<BlockTransactionResponse> blockTransaction(
@RequestBody BlockTransactionRequest blockReq) {
if(offlineMode) {
throw ExceptionFactory.NotSupportedInOfflineMode();
throw ExceptionFactory.notSupportedInOfflineMode();
}
networkService.verifyNetworkRequest(blockReq.getNetworkIdentifier());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.bloxbean.cardano.client.exception.CborDeserializationException;
import com.bloxbean.cardano.client.exception.CborSerializationException;
import org.openapitools.client.api.ConstructionApi;
import org.openapitools.client.model.*;

Expand Down Expand Up @@ -48,8 +50,8 @@ public ResponseEntity<TransactionIdentifierResponse> constructionHash(@RequestBo

@Override
public ResponseEntity<ConstructionMetadataResponse> constructionMetadata(@RequestBody ConstructionMetadataRequest constructionMetadataRequest) {
if(offlineMode) {
throw ExceptionFactory.NotSupportedInOfflineMode();
if (offlineMode) {
throw ExceptionFactory.notSupportedInOfflineMode();
}
networkService.verifyNetworkRequest(constructionMetadataRequest.getNetworkIdentifier());
return ResponseEntity.ok(constructionApiService.constructionMetadataService(constructionMetadataRequest));
Expand All @@ -66,7 +68,13 @@ public ResponseEntity<ConstructionPayloadsResponse> constructionPayloads(@Reques
networkService.verifyNetworkRequest(constructionPayloadsRequest.getNetworkIdentifier());
constructionApiService.verifyProtocolParameters(constructionPayloadsRequest);

return ResponseEntity.ok(constructionApiService.constructionPayloadsService(constructionPayloadsRequest));
try {
return ResponseEntity.ok(constructionApiService.constructionPayloadsService(constructionPayloadsRequest));
} catch (CborDeserializationException | CborSerializationException e) {
log.error("Error in constructionPayloads", e);

throw ExceptionFactory.unspecifiedError("Error in constructionPayloads");
}
}

@Override
Expand All @@ -78,7 +86,7 @@ public ResponseEntity<ConstructionPreprocessResponse> constructionPreprocess(@Re
@Override
public ResponseEntity<TransactionIdentifierResponse> constructionSubmit(@RequestBody ConstructionSubmitRequest constructionSubmitRequest) {
if(offlineMode) {
throw ExceptionFactory.NotSupportedInOfflineMode();
throw ExceptionFactory.notSupportedInOfflineMode();
}
networkService.verifyNetworkRequest(constructionSubmitRequest.getNetworkIdentifier());
return ResponseEntity.ok(constructionApiService.constructionSubmitService(constructionSubmitRequest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@


import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import java.util.Set;

import co.nstant.in.cbor.CborException;
Expand Down Expand Up @@ -36,13 +34,12 @@ public interface CardanoConstructionService {
TransactionParsed parseTransaction(Network network, String transaction, boolean signed);

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);

Integer calculateTxSize(Network network, List<Operation> operations, int ttl, DepositParameters depositParameters);
Integer calculateTxSize(Network network, List<Operation> operations, long ttl);

String buildTransaction(String unsignedTransaction,
List<Signatures> signaturesList, String transactionMetadata);
Expand All @@ -53,13 +50,12 @@ TransactionWitnessSet getWitnessesForTransaction(
List<SigningPayload> constructPayloadsForTransactionBody(String transactionBodyHash,
Set<String> addresses);

Long calculateFee(List<BigInteger> inputAmounts, List<BigInteger> outputAmounts,
List<BigInteger> withdrawalAmounts, Map<String, Double> depositsSumMap);

ProcessOperations convertRosettaOperations(Network network,
List<Operation> operations) throws IOException;

UnsignedTransaction createUnsignedTransaction(Network network, List<Operation> operations, int ttl, DepositParameters depositParameters) throws IOException, CborSerializationException, AddressExcepion, CborException;
UnsignedTransaction createUnsignedTransaction(Network network, List<Operation> operations, long ttl, Long calculatedFee) throws IOException, CborSerializationException, AddressExcepion, CborException;

UnsignedTransaction createUnsignedTransaction(Network network, List<Operation> operations, long ttl) throws IOException, CborSerializationException, AddressExcepion, CborException;

String submitTransaction(String signedTransaction);
DepositParameters getDepositParameters();
Expand All @@ -68,4 +64,5 @@ ProcessOperations convertRosettaOperations(Network network,

String getCardanoAddress(AddressType addressType, PublicKey stakingCredential,
PublicKey publicKey, NetworkEnum networkEnum);

}
Loading

0 comments on commit 0c60fd8

Please sign in to comment.