37
37
import org .cardanofoundation .rosetta .common .util .Constants ;
38
38
import org .cardanofoundation .rosetta .common .util .OperationParseUtil ;
39
39
import org .cardanofoundation .rosetta .common .util .ValidateParseUtil ;
40
- import org .jetbrains . annotations . NotNull ;
40
+ import org .openapitools . client . model . AccountIdentifier ;
41
41
import org .openapitools .client .model .DepositParameters ;
42
42
import org .openapitools .client .model .Operation ;
43
+ import org .openapitools .client .model .SignatureType ;
44
+ import org .openapitools .client .model .SigningPayload ;
45
+ import org .jetbrains .annotations .NotNull ;
43
46
import org .springframework .stereotype .Service ;
44
47
45
48
import java .io .IOException ;
46
49
import java .math .BigInteger ;
47
- import java .security .InvalidKeyException ;
48
- import java .security .NoSuchAlgorithmException ;
49
- import java .security .SignatureException ;
50
- import java .security .spec .InvalidKeySpecException ;
51
50
import java .util .ArrayList ;
52
51
import java .util .HashMap ;
53
52
import java .util .HashSet ;
54
53
import java .util .List ;
55
54
import java .util .Map ;
56
- import java .util .Objects ;
57
55
import java .util .Set ;
58
56
59
57
import static java .math .BigInteger .valueOf ;
@@ -136,7 +134,7 @@ public Signatures signatureProcessor(EraAddressType eraAddressType, AddressType
136
134
@ Override
137
135
public Double calculateTxSize (NetworkIdentifierType networkIdentifierType , List <Operation > operations , int ttl , DepositParameters depositParameters ) throws IOException , CborException , AddressExcepion , CborSerializationException {
138
136
UnsignedTransaction unsignedTransaction = createUnsignedTransaction (networkIdentifierType , operations , ttl , !ObjectUtils .isEmpty (depositParameters ) ? depositParameters : new DepositParameters (Constants .DEFAULT_KEY_DEPOSIT .toString (), Constants .DEFAULT_POOL_DEPOSIT .toString ()));
139
- List <Signatures > signaturesList = (unsignedTransaction .getAddresses ()).stream ().map (address -> {
137
+ List <Signatures > signaturesList = (unsignedTransaction .addresses ()).stream ().map (address -> {
140
138
EraAddressType eraAddressType = CardanoAddressUtil .getEraAddressType (address );
141
139
if (eraAddressType != null ) {
142
140
return signatureProcessor (eraAddressType , null , address );
@@ -148,7 +146,7 @@ public Double calculateTxSize(NetworkIdentifierType networkIdentifierType, List<
148
146
throw ExceptionFactory .invalidAddressError (address );
149
147
}).toList ();
150
148
151
- String transaction = buildTransaction (unsignedTransaction .getBytes (), signaturesList , unsignedTransaction .getMetadata ());
149
+ String transaction = buildTransaction (unsignedTransaction .bytes (), signaturesList , unsignedTransaction .metadata ());
152
150
return ((double ) transaction .length () / 2 );
153
151
154
152
}
@@ -241,7 +239,8 @@ public TransactionWitnessSet getWitnessesForTransaction(List<Signatures> signatu
241
239
}
242
240
}
243
241
244
- private UnsignedTransaction createUnsignedTransaction (NetworkIdentifierType networkIdentifierType , List <Operation > operations , int ttl , DepositParameters depositParameters ) throws IOException , CborSerializationException , AddressExcepion , CborException {
242
+ @ Override
243
+ public UnsignedTransaction createUnsignedTransaction (NetworkIdentifierType networkIdentifierType , List <Operation > operations , int ttl , DepositParameters depositParameters ) throws IOException , CborSerializationException , AddressExcepion , CborException {
245
244
log .info ("[createUnsignedTransaction] About to create an unsigned transaction with {} operations" , operations .size ());
246
245
ProcessOperationsReturn processOperationsReturnDto = processOperations (networkIdentifierType , operations , depositParameters );
247
246
@@ -268,13 +267,21 @@ private UnsignedTransaction createUnsignedTransaction(NetworkIdentifierType netw
268
267
String transactionBytes = HexUtil .encodeHexString (com .bloxbean .cardano .yaci .core .util .CborSerializationUtil .serialize (mapCbor ));
269
268
log .info ("[createUnsignedTransaction] Hashing transaction body" );
270
269
String bodyHash = com .bloxbean .cardano .client .util .HexUtil .encodeHexString (Blake2bUtil .blake2bHash256 (CborSerializationUtil .serialize (mapCbor )));
271
- UnsignedTransaction toReturn = new UnsignedTransaction (HexUtil .encodeHexString (HexUtil .decodeHexString (bodyHash )), transactionBytes , processOperationsReturnDto .getAddresses (), null );
270
+ UnsignedTransaction toReturn = new UnsignedTransaction (
271
+ HexUtil .encodeHexString (HexUtil .decodeHexString (bodyHash )),
272
+ transactionBytes ,
273
+ processOperationsReturnDto .getAddresses (),
274
+ getHexEncodedAuxiliaryMetadataArray (processOperationsReturnDto ));
275
+ log .info (toReturn + "[createUnsignedTransaction] Returning unsigned transaction, hash to sign and addresses that will sign hash" );
276
+ return toReturn ;
277
+ }
278
+
279
+ private static String getHexEncodedAuxiliaryMetadataArray (ProcessOperationsReturn processOperationsReturnDto ) throws CborSerializationException , CborException {
272
280
if (!ObjectUtils .isEmpty (processOperationsReturnDto .getVoteRegistrationMetadata ())) {
273
281
Array array = getArrayOfAuxiliaryData (processOperationsReturnDto );
274
- toReturn . setMetadata ( HexUtil .encodeHexString (CborSerializationUtil .serialize (array ) ));
282
+ return HexUtil .encodeHexString (CborSerializationUtil .serialize (array ));
275
283
}
276
- log .info (toReturn + "[createUnsignedTransaction] Returning unsigned transaction, hash to sign and addresses that will sign hash" );
277
- return toReturn ;
284
+ return null ;
278
285
}
279
286
280
287
@ NotNull
@@ -287,6 +294,14 @@ private static Array getArrayOfAuxiliaryData(ProcessOperationsReturn processOper
287
294
return array ;
288
295
}
289
296
297
+ @ Override
298
+ public List <SigningPayload > constructPayloadsForTransactionBody (String transactionBodyHash ,
299
+ Set <String > addresses ) {
300
+ return addresses .stream ().map (
301
+ address -> new SigningPayload (null , new AccountIdentifier (address , null , null ), transactionBodyHash ,
302
+ SignatureType .ED25519 )).toList ();
303
+ }
304
+
290
305
private ProcessOperationsReturn processOperations (NetworkIdentifierType networkIdentifierType , List <Operation > operations , DepositParameters depositParameters ) throws IOException {
291
306
ProcessOperations result = convertRosettaOperations (networkIdentifierType , operations );
292
307
double refundsSum = result .getStakeKeyDeRegistrationsCount () * Long .parseLong (depositParameters .getKeyDeposit ());
0 commit comments