@@ -73,13 +73,21 @@ public ConstructionPreprocessResponse constructionPreprocessService(
73
73
ConstructionPreprocessRequest constructionPreprocessRequest ) {
74
74
75
75
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
+ }
77
87
78
- Double relativeTtl = cardanoService .checkOrReturnDefaultTtl (metadata .getRelativeTtl ());
79
88
Double transactionSize = cardanoService .calculateTxSize (
80
89
NetworkIdentifierType .findByName (networkIdentifier .getNetwork ()),
81
- constructionPreprocessRequest .getOperations (), 0 ,
82
- metadata .getDepositParameters ());
90
+ constructionPreprocessRequest .getOperations (), 0 , depositParameters );
83
91
Map <String , Double > response = Map .of (Constants .RELATIVE_TTL , relativeTtl ,
84
92
Constants .TRANSACTION_SIZE ,
85
93
transactionSize );
@@ -110,40 +118,36 @@ public ConstructionMetadataResponse constructionMetadataService(
110
118
@ Override
111
119
public ConstructionPayloadsResponse constructionPayloadsService (
112
120
ConstructionPayloadsRequest constructionPayloadsRequest ) {
113
- int ttl = constructionPayloadsRequest . getMetadata (). getTtl ();
121
+
114
122
List <Operation > operations = constructionPayloadsRequest .getOperations ();
115
123
116
124
checkOperationsHaveIdentifier (operations );
117
125
118
126
NetworkIdentifierType networkIdentifier = NetworkIdentifierType .findByName (constructionPayloadsRequest .getNetworkIdentifier ().getNetwork ());
119
127
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 ());
129
135
} 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 ();
133
138
}
134
139
135
- UnsignedTransaction unsignedTransaction = null ;
140
+ UnsignedTransaction unsignedTransaction ;
136
141
try {
137
142
unsignedTransaction = cardanoService .createUnsignedTransaction (
138
143
networkIdentifier , operations , ttl ,
139
- new DepositParameters (keyDeposit ,
140
- poolDeposit ));
144
+ depositParameters );
141
145
} catch (IOException | CborSerializationException | AddressExcepion | CborException e ) {
142
146
throw ExceptionFactory .cantCreateUnsignedTransactionFromBytes ();
143
147
}
144
148
List <SigningPayload > payloads = cardanoService .constructPayloadsForTransactionBody (
145
149
unsignedTransaction .hash (), unsignedTransaction .addresses ());
146
- String unsignedTransactionString = null ;
150
+ String unsignedTransactionString ;
147
151
try {
148
152
unsignedTransactionString = CborEncodeUtil .encodeExtraData (
149
153
unsignedTransaction .bytes (),
0 commit comments