@@ -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 (),
0 commit comments