Skip to content

Commit

Permalink
fix: metadata not mandatory anymore, will be filled with standard val…
Browse files Browse the repository at this point in the history
…ues if not set. (#116)

* fix: metadata not mandatory anymore, will be filled with standard values if not set.

* fix: metadata for payload not mandatory anymore, will be filled with standard values if not set.
  • Loading branch information
Kammerlo authored Apr 10, 2024
1 parent 454cc4b commit 75448b0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,18 @@ public static ProtocolParams fromJSONObject(JSONObject shelleyJsonObject) {
p.setMaxBlockSize(shelleyProtocolParams.getInt("maxBlockBodySize"));
p.setMaxTxSize(shelleyProtocolParams.getInt("maxTxSize"));
p.setMaxBlockHeaderSize(shelleyProtocolParams.getInt("maxBlockHeaderSize"));
p.setKeyDeposit(shelleyProtocolParams.getBigInteger("keyDeposit"));
p.setPoolDeposit(shelleyProtocolParams.getBigInteger("poolDeposit"));
p.setKeyDeposit(BigInteger.valueOf(shelleyProtocolParams.getLong("keyDeposit")));
p.setPoolDeposit(BigInteger.valueOf(shelleyProtocolParams.getLong("poolDeposit")));
p.setNOpt(shelleyProtocolParams.getInt("nOpt"));
p.setDecentralisationParam(shelleyProtocolParams.getBigDecimal("decentralisationParam"));
p.setDecentralisationParam(
BigDecimal.valueOf(shelleyProtocolParams.getLong("decentralisationParam")));
p.setExtraEntropy(shelleyProtocolParams.getJSONObject("extraEntropy").getString("tag"));
JSONObject protolVersion = shelleyProtocolParams.getJSONObject("protocolVersion");
p.setProtocolMajorVer(protolVersion.getInt("major"));
p.setProtocolMinorVer(protolVersion.getInt("minor"));
p.setMinUtxo(shelleyProtocolParams.getBigInteger("minUTxOValue"));
p.setMinPoolCost(shelleyProtocolParams.getBigInteger("minPoolCost"));
p.setAdaPerUtxoByte(shelleyProtocolParams.getBigInteger("minFeeA"));
p.setMinUtxo(BigInteger.valueOf(shelleyProtocolParams.getLong("minUTxOValue")));
p.setMinPoolCost(BigInteger.valueOf(shelleyProtocolParams.getLong("minPoolCost")));
p.setAdaPerUtxoByte(BigInteger.valueOf(shelleyProtocolParams.getLong("minFeeA")));

return p;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,21 @@ public ConstructionPreprocessResponse constructionPreprocessService(
ConstructionPreprocessRequest constructionPreprocessRequest) {

NetworkIdentifier networkIdentifier = constructionPreprocessRequest.getNetworkIdentifier();
ConstructionPreprocessMetadata metadata = constructionPreprocessRequest.getMetadata();
Optional<ConstructionPreprocessMetadata> metadata = Optional.ofNullable(
constructionPreprocessRequest.getMetadata());
Double relativeTtl;
DepositParameters depositParameters;
if(metadata.isPresent()) {
relativeTtl = cardanoService.checkOrReturnDefaultTtl(metadata.get().getRelativeTtl());
depositParameters = Optional.ofNullable(metadata.get().getDepositParameters()).orElse(cardanoService.getDepositParameters());
} else {
relativeTtl = Constants.DEFAULT_RELATIVE_TTL;
depositParameters = cardanoService.getDepositParameters();
}

Double relativeTtl = cardanoService.checkOrReturnDefaultTtl(metadata.getRelativeTtl());
Double transactionSize = cardanoService.calculateTxSize(
NetworkIdentifierType.findByName(networkIdentifier.getNetwork()),
constructionPreprocessRequest.getOperations(), 0,
metadata.getDepositParameters());
constructionPreprocessRequest.getOperations(), 0, depositParameters);
Map<String, Double> response = Map.of(Constants.RELATIVE_TTL, relativeTtl,
Constants.TRANSACTION_SIZE,
transactionSize);
Expand Down Expand Up @@ -110,40 +118,36 @@ public ConstructionMetadataResponse constructionMetadataService(
@Override
public ConstructionPayloadsResponse constructionPayloadsService(
ConstructionPayloadsRequest constructionPayloadsRequest) {
int ttl = constructionPayloadsRequest.getMetadata().getTtl();

List<Operation> operations = constructionPayloadsRequest.getOperations();

checkOperationsHaveIdentifier(operations);

NetworkIdentifierType networkIdentifier = NetworkIdentifierType.findByName(constructionPayloadsRequest.getNetworkIdentifier().getNetwork());
log.info(operations + "[constuctionPayloads] Operations about to be processed");

ProtocolParameters protocolParameters = constructionPayloadsRequest.getMetadata()
.getProtocolParameters();
String keyDeposit;
String poolDeposit;
// TODO need to convert OpenAPI ProcotolParameters to domain ProtocolParams. Then merge with the one from indexer/config
if(protocolParameters != null) {
keyDeposit = protocolParameters.getKeyDeposit();
poolDeposit = protocolParameters.getPoolDeposit();
Optional<ConstructionPayloadsRequestMetadata> metadata = Optional.ofNullable(
constructionPayloadsRequest.getMetadata());
int ttl;
DepositParameters depositParameters;
if(metadata.isPresent()) {
ttl = cardanoService.checkOrReturnDefaultTtl(metadata.get().getTtl()).intValue();
depositParameters = Optional.ofNullable(metadata.get().getProtocolParameters()).map(protocolParameters -> new DepositParameters(protocolParameters.getKeyDeposit(), protocolParameters.getPoolDeposit())).orElse(cardanoService.getDepositParameters());
} else {
ProtocolParams protocolParametersFromIndexerAndConfig = ledgerService.findProtocolParametersFromIndexerAndConfig();
keyDeposit = protocolParametersFromIndexerAndConfig.getKeyDeposit().toString();
poolDeposit = protocolParametersFromIndexerAndConfig.getPoolDeposit().toString();
ttl = Constants.DEFAULT_RELATIVE_TTL.intValue();
depositParameters = cardanoService.getDepositParameters();
}

UnsignedTransaction unsignedTransaction = null;
UnsignedTransaction unsignedTransaction;
try {
unsignedTransaction = cardanoService.createUnsignedTransaction(
networkIdentifier, operations, ttl,
new DepositParameters(keyDeposit,
poolDeposit));
depositParameters);
} catch (IOException | CborSerializationException | AddressExcepion | CborException e) {
throw ExceptionFactory.cantCreateUnsignedTransactionFromBytes();
}
List<SigningPayload> payloads = cardanoService.constructPayloadsForTransactionBody(
unsignedTransaction.hash(), unsignedTransaction.addresses());
String unsignedTransactionString = null;
String unsignedTransactionString;
try {
unsignedTransactionString = CborEncodeUtil.encodeExtraData(
unsignedTransaction.bytes(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ ProcessOperations convertRosettaOperations(NetworkIdentifierType networkIdentifi
UnsignedTransaction createUnsignedTransaction(NetworkIdentifierType networkIdentifier, List<Operation> operations, int ttl, DepositParameters depositParameters) throws IOException, CborSerializationException, AddressExcepion, CborException;

String submitTransaction(String signedTransaction);
DepositParameters getDepositParameters();
}
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,15 @@ public String submitTransaction(String signedTransaction) throws ApiException {
}
}

/**
* Returns the deposit parameters for the network fetched from the protocolparameters
* @return Depositparameters including key- and pooldeposit
*/
@Override
public DepositParameters getDepositParameters() {
ProtocolParams protocolParametersFromIndexerAndConfig = ledgerDataProviderService.findProtocolParametersFromIndexerAndConfig();
return new DepositParameters(protocolParametersFromIndexerAndConfig.getKeyDeposit().toString(),
protocolParametersFromIndexerAndConfig.getPoolDeposit().toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1988,8 +1988,7 @@
"type": "object",
"required": [
"network_identifier",
"operations",
"metadata"
"operations"
],
"properties": {
"network_identifier": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,6 @@ components:
required:
- network_identifier
- operations
- metadata
properties:
network_identifier:
$ref: '#/components/schemas/NetworkIdentifier'
Expand Down

0 comments on commit 75448b0

Please sign in to comment.