Skip to content

Commit 75448b0

Browse files
authored
fix: metadata not mandatory anymore, will be filled with standard values 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.
1 parent 454cc4b commit 75448b0

File tree

6 files changed

+45
-30
lines changed

6 files changed

+45
-30
lines changed

api/src/main/java/org/cardanofoundation/rosetta/api/block/model/entity/ProtocolParams.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,18 @@ public static ProtocolParams fromJSONObject(JSONObject shelleyJsonObject) {
9494
p.setMaxBlockSize(shelleyProtocolParams.getInt("maxBlockBodySize"));
9595
p.setMaxTxSize(shelleyProtocolParams.getInt("maxTxSize"));
9696
p.setMaxBlockHeaderSize(shelleyProtocolParams.getInt("maxBlockHeaderSize"));
97-
p.setKeyDeposit(shelleyProtocolParams.getBigInteger("keyDeposit"));
98-
p.setPoolDeposit(shelleyProtocolParams.getBigInteger("poolDeposit"));
97+
p.setKeyDeposit(BigInteger.valueOf(shelleyProtocolParams.getLong("keyDeposit")));
98+
p.setPoolDeposit(BigInteger.valueOf(shelleyProtocolParams.getLong("poolDeposit")));
9999
p.setNOpt(shelleyProtocolParams.getInt("nOpt"));
100-
p.setDecentralisationParam(shelleyProtocolParams.getBigDecimal("decentralisationParam"));
100+
p.setDecentralisationParam(
101+
BigDecimal.valueOf(shelleyProtocolParams.getLong("decentralisationParam")));
101102
p.setExtraEntropy(shelleyProtocolParams.getJSONObject("extraEntropy").getString("tag"));
102103
JSONObject protolVersion = shelleyProtocolParams.getJSONObject("protocolVersion");
103104
p.setProtocolMajorVer(protolVersion.getInt("major"));
104105
p.setProtocolMinorVer(protolVersion.getInt("minor"));
105-
p.setMinUtxo(shelleyProtocolParams.getBigInteger("minUTxOValue"));
106-
p.setMinPoolCost(shelleyProtocolParams.getBigInteger("minPoolCost"));
107-
p.setAdaPerUtxoByte(shelleyProtocolParams.getBigInteger("minFeeA"));
106+
p.setMinUtxo(BigInteger.valueOf(shelleyProtocolParams.getLong("minUTxOValue")));
107+
p.setMinPoolCost(BigInteger.valueOf(shelleyProtocolParams.getLong("minPoolCost")));
108+
p.setAdaPerUtxoByte(BigInteger.valueOf(shelleyProtocolParams.getLong("minFeeA")));
108109

109110
return p;
110111
}

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,21 @@ public ConstructionPreprocessResponse constructionPreprocessService(
7373
ConstructionPreprocessRequest constructionPreprocessRequest) {
7474

7575
NetworkIdentifier networkIdentifier = constructionPreprocessRequest.getNetworkIdentifier();
76-
ConstructionPreprocessMetadata metadata = constructionPreprocessRequest.getMetadata();
76+
Optional<ConstructionPreprocessMetadata> metadata = Optional.ofNullable(
77+
constructionPreprocessRequest.getMetadata());
78+
Double relativeTtl;
79+
DepositParameters depositParameters;
80+
if(metadata.isPresent()) {
81+
relativeTtl = cardanoService.checkOrReturnDefaultTtl(metadata.get().getRelativeTtl());
82+
depositParameters = Optional.ofNullable(metadata.get().getDepositParameters()).orElse(cardanoService.getDepositParameters());
83+
} else {
84+
relativeTtl = Constants.DEFAULT_RELATIVE_TTL;
85+
depositParameters = cardanoService.getDepositParameters();
86+
}
7787

78-
Double relativeTtl = cardanoService.checkOrReturnDefaultTtl(metadata.getRelativeTtl());
7988
Double transactionSize = cardanoService.calculateTxSize(
8089
NetworkIdentifierType.findByName(networkIdentifier.getNetwork()),
81-
constructionPreprocessRequest.getOperations(), 0,
82-
metadata.getDepositParameters());
90+
constructionPreprocessRequest.getOperations(), 0, depositParameters);
8391
Map<String, Double> response = Map.of(Constants.RELATIVE_TTL, relativeTtl,
8492
Constants.TRANSACTION_SIZE,
8593
transactionSize);
@@ -110,40 +118,36 @@ public ConstructionMetadataResponse constructionMetadataService(
110118
@Override
111119
public ConstructionPayloadsResponse constructionPayloadsService(
112120
ConstructionPayloadsRequest constructionPayloadsRequest) {
113-
int ttl = constructionPayloadsRequest.getMetadata().getTtl();
121+
114122
List<Operation> operations = constructionPayloadsRequest.getOperations();
115123

116124
checkOperationsHaveIdentifier(operations);
117125

118126
NetworkIdentifierType networkIdentifier = NetworkIdentifierType.findByName(constructionPayloadsRequest.getNetworkIdentifier().getNetwork());
119127
log.info(operations + "[constuctionPayloads] Operations about to be processed");
120-
121-
ProtocolParameters protocolParameters = constructionPayloadsRequest.getMetadata()
122-
.getProtocolParameters();
123-
String keyDeposit;
124-
String poolDeposit;
125-
// TODO need to convert OpenAPI ProcotolParameters to domain ProtocolParams. Then merge with the one from indexer/config
126-
if(protocolParameters != null) {
127-
keyDeposit = protocolParameters.getKeyDeposit();
128-
poolDeposit = protocolParameters.getPoolDeposit();
128+
Optional<ConstructionPayloadsRequestMetadata> metadata = Optional.ofNullable(
129+
constructionPayloadsRequest.getMetadata());
130+
int ttl;
131+
DepositParameters depositParameters;
132+
if(metadata.isPresent()) {
133+
ttl = cardanoService.checkOrReturnDefaultTtl(metadata.get().getTtl()).intValue();
134+
depositParameters = Optional.ofNullable(metadata.get().getProtocolParameters()).map(protocolParameters -> new DepositParameters(protocolParameters.getKeyDeposit(), protocolParameters.getPoolDeposit())).orElse(cardanoService.getDepositParameters());
129135
} else {
130-
ProtocolParams protocolParametersFromIndexerAndConfig = ledgerService.findProtocolParametersFromIndexerAndConfig();
131-
keyDeposit = protocolParametersFromIndexerAndConfig.getKeyDeposit().toString();
132-
poolDeposit = protocolParametersFromIndexerAndConfig.getPoolDeposit().toString();
136+
ttl = Constants.DEFAULT_RELATIVE_TTL.intValue();
137+
depositParameters = cardanoService.getDepositParameters();
133138
}
134139

135-
UnsignedTransaction unsignedTransaction = null;
140+
UnsignedTransaction unsignedTransaction;
136141
try {
137142
unsignedTransaction = cardanoService.createUnsignedTransaction(
138143
networkIdentifier, operations, ttl,
139-
new DepositParameters(keyDeposit,
140-
poolDeposit));
144+
depositParameters);
141145
} catch (IOException | CborSerializationException | AddressExcepion | CborException e) {
142146
throw ExceptionFactory.cantCreateUnsignedTransactionFromBytes();
143147
}
144148
List<SigningPayload> payloads = cardanoService.constructPayloadsForTransactionBody(
145149
unsignedTransaction.hash(), unsignedTransaction.addresses());
146-
String unsignedTransactionString = null;
150+
String unsignedTransactionString;
147151
try {
148152
unsignedTransactionString = CborEncodeUtil.encodeExtraData(
149153
unsignedTransaction.bytes(),

api/src/main/java/org/cardanofoundation/rosetta/common/services/CardanoService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ ProcessOperations convertRosettaOperations(NetworkIdentifierType networkIdentifi
6262
UnsignedTransaction createUnsignedTransaction(NetworkIdentifierType networkIdentifier, List<Operation> operations, int ttl, DepositParameters depositParameters) throws IOException, CborSerializationException, AddressExcepion, CborException;
6363

6464
String submitTransaction(String signedTransaction);
65+
DepositParameters getDepositParameters();
6566
}

api/src/main/java/org/cardanofoundation/rosetta/common/services/impl/CardanoServiceImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,4 +509,15 @@ public String submitTransaction(String signedTransaction) throws ApiException {
509509
}
510510
}
511511

512+
/**
513+
* Returns the deposit parameters for the network fetched from the protocolparameters
514+
* @return Depositparameters including key- and pooldeposit
515+
*/
516+
@Override
517+
public DepositParameters getDepositParameters() {
518+
ProtocolParams protocolParametersFromIndexerAndConfig = ledgerDataProviderService.findProtocolParametersFromIndexerAndConfig();
519+
return new DepositParameters(protocolParametersFromIndexerAndConfig.getKeyDeposit().toString(),
520+
protocolParametersFromIndexerAndConfig.getPoolDeposit().toString());
521+
}
522+
512523
}

api/src/main/resources/rosetta-specifications-1.4.15/api.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,8 +1988,7 @@
19881988
"type": "object",
19891989
"required": [
19901990
"network_identifier",
1991-
"operations",
1992-
"metadata"
1991+
"operations"
19931992
],
19941993
"properties": {
19951994
"network_identifier": {

api/src/main/resources/rosetta-specifications-1.4.15/api.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,6 @@ components:
13421342
required:
13431343
- network_identifier
13441344
- operations
1345-
- metadata
13461345
properties:
13471346
network_identifier:
13481347
$ref: '#/components/schemas/NetworkIdentifier'

0 commit comments

Comments
 (0)