Skip to content

Commit

Permalink
fix: fixed wrong hash on hash endpoint due to wrong deserialization a…
Browse files Browse the repository at this point in the history
…nd serialization (#247)
  • Loading branch information
Kammerlo authored Oct 15, 2024
1 parent 52e45fa commit 79812f0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
public interface CardanoConstructionService {


String getHashOfSignedTransaction(String signedTransaction);
Array decodeTransaction(String encoded);
Long calculateTtl(Long ttlOffset);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,6 @@ public Integer checkOrReturnDefaultTtl(Integer relativeTtl) {
return relativeTtl == null ? Constants.DEFAULT_RELATIVE_TTL : relativeTtl;
}

@Override
public String getHashOfSignedTransaction(String signedTransaction) {
try {
log.info("[getHashOfSignedTransaction] About to hash signed transaction {}",
signedTransaction);
byte[] signedTransactionBytes = HexUtil.decodeHexString(signedTransaction);
log.info(
"[getHashOfSignedTransaction] About to parse transaction from signed transaction bytes");
Transaction parsed = Transaction.deserialize(signedTransactionBytes);
log.info("[getHashOfSignedTransaction] Returning transaction hash");
TransactionBody body = parsed.getBody();
byte[] hashBuffer;
if (body == null || CborSerializationUtil.serialize(body.serialize()) == null) {
hashBuffer = null;
} else {
hashBuffer = Blake2bUtil.blake2bHash256(CborSerializationUtil.serialize(body.serialize()));
}
return HexUtil.encodeHexString(hashBuffer);
} catch (Exception error) {
log.error("{} [getHashOfSignedTransaction] There was an error parsing signed transaction",
error.getMessage());
throw ExceptionFactory.parseSignedTransactionError();
}
}

@Override
public Array decodeTransaction(String encoded) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.bloxbean.cardano.client.common.model.Network;
import com.bloxbean.cardano.client.exception.AddressExcepion;
import com.bloxbean.cardano.client.exception.CborSerializationException;
import com.bloxbean.cardano.client.transaction.util.TransactionUtil;
import com.bloxbean.cardano.client.util.HexUtil;
import org.openapitools.client.model.AccountIdentifier;
import org.openapitools.client.model.ConstructionCombineRequest;
import org.openapitools.client.model.ConstructionCombineResponse;
Expand Down Expand Up @@ -227,8 +229,8 @@ public TransactionIdentifierResponse constructionHashService(
Array array = cardanoConstructionService.decodeTransaction(
constructionHashRequest.getSignedTransaction());
log.info("[constructionHash] About to get hash of signed transaction");
String transactionHash = cardanoConstructionService.getHashOfSignedTransaction(
((UnicodeString) array.getDataItems().getFirst()).getString());
byte[] signedTransactionBytes = HexUtil.decodeHexString(((UnicodeString) array.getDataItems().getFirst()).getString());
String transactionHash = TransactionUtil.getTxHash(signedTransactionBytes);
log.info("[constructionHash] About to return hash of signed transaction");
return new TransactionIdentifierResponse(new TransactionIdentifier(transactionHash), null);
}
Expand Down

0 comments on commit 79812f0

Please sign in to comment.