4747import java .util .concurrent .TimeUnit ;
4848import java .util .function .BiFunction ;
4949
50+ import static com .iexec .commons .poco .encoding .AssetDataEncoder .getAssetAddressFromReceipt ;
5051import static com .iexec .commons .poco .tee .TeeEnclaveConfiguration .buildEnclaveConfigurationFromJsonString ;
5152import static com .iexec .commons .poco .utils .BytesUtils .isNonZeroedBytes32 ;
5253import static org .web3j .tx .TransactionManager .DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH ;
@@ -212,8 +213,8 @@ public WorkerpoolRegistry getWorkerpoolRegistryContract(ContractGasProvider cont
212213 * ERC721 mint method to retrieve workerpool address
213214 * tokenId is the generic form of workerpoolAddress
214215 *
215- * @param name workerpool name
216- * @param secondsTimeout await workerpool deployment for couple seconds
216+ * @param name workerpool name
217+ * @param secondsTimeout await workerpool deployment for couple seconds
217218 * @param secondsPollingInterval check if workerpool is deployed every couple seconds
218219 * @return workerpool address (e.g.: 0x95ba540ca3c2dfd52a7e487a03e1358dfe9441ce)
219220 */
@@ -251,13 +252,7 @@ public String createWorkerpool(String name, int secondsTimeout, int secondsPolli
251252 return "" ;
252253 }
253254
254- String workerpoolAddress = WorkerpoolRegistry .getTransferEvents (createWorkerpoolReceipt )
255- .stream ()
256- .findFirst ()
257- .map (event -> event .tokenId ) // workerpool is an ERC721
258- .map (Address ::new )
259- .map (Address ::toString )
260- .orElse ("" );
255+ String workerpoolAddress = getAssetAddressFromReceipt (createWorkerpoolReceipt );
261256
262257 if (StringUtils .isEmpty (workerpoolAddress )) {
263258 log .error ("Failed to extract workerpool address" + paramsPrinter ,
@@ -299,7 +294,7 @@ public String createWorkerpool(String name) {
299294 * This method to predict workerpool address without deploying it
300295 *
301296 * @param owner workerpool owner
302- * @param name workerpool name
297+ * @param name workerpool name
303298 * @return workerpool address (e.g.: 0x95ba540ca3c2dfd52a7e487a03e1358dfe9441ce)
304299 */
305300 public String predictWorkerpool (String owner , String name ) {
@@ -379,12 +374,12 @@ public AppRegistry getAppRegistryContract(ContractGasProvider contractGasProvide
379374 * ERC721 mint method to retrieve app address
380375 * tokenId is the generic form of appAddress
381376 *
382- * @param name app name
383- * @param multiAddress app url
384- * @param type app type
385- * @param checksum app sha256 checksum
386- * @param mrEnclave app mrEnclave
387- * @param secondsTimeout await app deployment for couple seconds
377+ * @param name app name
378+ * @param multiAddress app url
379+ * @param type app type
380+ * @param checksum app sha256 checksum
381+ * @param mrEnclave app mrEnclave
382+ * @param secondsTimeout await app deployment for couple seconds
388383 * @param secondsPollingInterval check if app is deployed every couple seconds
389384 * @return app address (e.g.: 0x95ba540ca3c2dfd52a7e487a03e1358dfe9441ce)
390385 */
@@ -426,13 +421,7 @@ public String createApp(String name, String multiAddress, String type,
426421 return "" ;
427422 }
428423
429- String appAddress = AppRegistry .getTransferEvents (createAppReceipt )
430- .stream ()
431- .findFirst ()
432- .map (event -> event .tokenId ) // app is an ERC721
433- .map (Address ::new )
434- .map (Address ::toString )
435- .orElse ("" );
424+ String appAddress = getAssetAddressFromReceipt (createAppReceipt );
436425
437426 if (StringUtils .isEmpty (appAddress )) {
438427 log .error ("Failed to extract app address" + paramsPrinter ,
@@ -463,11 +452,11 @@ public String createApp(String name, String multiAddress, String type,
463452 /**
464453 * Default method for creating app
465454 *
466- * @param name app name
455+ * @param name app name
467456 * @param multiAddress app url
468- * @param type app type
469- * @param checksum app sha256 checksum
470- * @param mrEnclave app mrEnclave
457+ * @param type app type
458+ * @param checksum app sha256 checksum
459+ * @param mrEnclave app mrEnclave
471460 * @return app address (e.g.: 0x95ba540ca3c2dfd52a7e487a03e1358dfe9441ce)
472461 */
473462 public String createApp (String name , String multiAddress , String type ,
@@ -478,10 +467,10 @@ public String createApp(String name, String multiAddress, String type,
478467 /**
479468 * This method to predict app address without deploying it
480469 *
481- * @param owner app owner
482- * @param name app name
470+ * @param owner app owner
471+ * @param name app name
483472 * @param multiAddress app url
484- * @param checksum app sha256 checksum
473+ * @param checksum app sha256 checksum
485474 * @return app address (e.g.: 0x95ba540ca3c2dfd52a7e487a03e1358dfe9441ce)
486475 */
487476 public String predictApp (String owner , String name , String multiAddress , String type ,
@@ -569,10 +558,10 @@ public DatasetRegistry getDatasetRegistryContract(ContractGasProvider contractGa
569558 * ERC721 mint method to retrieve dataset address
570559 * tokenId is the generic form of datasetAddress
571560 *
572- * @param name dataset name
573- * @param multiAddress dataset url
574- * @param checksum dataset sha256 checksum
575- * @param secondsTimeout await dataset deployment for couple seconds
561+ * @param name dataset name
562+ * @param multiAddress dataset url
563+ * @param checksum dataset sha256 checksum
564+ * @param secondsTimeout await dataset deployment for couple seconds
576565 * @param secondsPollingInterval check if dataset is deployed every couple seconds
577566 * @return dataset address (e.g.: 0x95ba540ca3c2dfd52a7e487a03e1358dfe9441ce)
578567 */
@@ -618,13 +607,7 @@ public String createDataset(String name, String multiAddress, String checksum,
618607 return "" ;
619608 }
620609
621- String datasetAddress = DatasetRegistry .getTransferEvents (createDatasetReceipt )
622- .stream ()
623- .findFirst ()
624- .map (event -> event .tokenId ) // dataset is an ERC721
625- .map (Address ::new )
626- .map (Address ::toString )
627- .orElse ("" );
610+ String datasetAddress = getAssetAddressFromReceipt (createDatasetReceipt );
628611
629612 if (StringUtils .isEmpty (datasetAddress )) {
630613 log .error ("Failed to extract dataset address" + paramsPrinter ,
@@ -655,9 +638,9 @@ public String createDataset(String name, String multiAddress, String checksum,
655638 /**
656639 * Default method for creating dataset
657640 *
658- * @param name dataset name
641+ * @param name dataset name
659642 * @param multiAddress dataset url
660- * @param checksum dataset sha256 checksum
643+ * @param checksum dataset sha256 checksum
661644 * @return dataset address (e.g.: 0x95ba540ca3c2dfd52a7e487a03e1358dfe9441ce)
662645 */
663646 public String createDataset (String name , String multiAddress , String checksum ) {
@@ -667,10 +650,10 @@ public String createDataset(String name, String multiAddress, String checksum) {
667650 /**
668651 * This method to predict dataset address without deploying it
669652 *
670- * @param owner dataset owner
671- * @param name dataset name
653+ * @param owner dataset owner
654+ * @param name dataset name
672655 * @param multiAddress dataset url
673- * @param checksum dataset sha256 checksum
656+ * @param checksum dataset sha256 checksum
674657 * @return dataset address (e.g.: 0x95ba540ca3c2dfd52a7e487a03e1358dfe9441ce)
675658 */
676659 public String predictDataset (String owner , String name , String multiAddress ,
@@ -713,8 +696,8 @@ public String predictDataset(String owner, String name, String multiAddress,
713696 * Retrieves on-chain deal with a retryer
714697 *
715698 * @param chainDealId deal ID
716- * @param retryDelay delay between retries in ms
717- * @param maxRetry number of maximum retry
699+ * @param retryDelay delay between retries in ms
700+ * @param maxRetry number of maximum retry
718701 * @return optional ChainDeal
719702 */
720703 public Optional <ChainDeal > repeatGetChainDeal (String chainDealId ,
@@ -730,7 +713,7 @@ public Optional<ChainDeal> repeatGetChainDeal(String chainDealId,
730713
731714 /**
732715 * Retrieves on-chain deal with its blockchain ID
733- *
716+ * <p>
734717 * Note:
735718 * If `start time` is invalid, it is likely a blockchain issue. In this case,
736719 * in order to protect workflows based on top of it, the deal won't be
@@ -782,8 +765,8 @@ public Optional<ChainDeal> getChainDeal(String chainDealId) {
782765 * Retrieve on-chain task with a retryer
783766 *
784767 * @param chainTaskId task ID
785- * @param retryDelay delay between retries in ms
786- * @param maxRetry number of maximum retry
768+ * @param retryDelay delay between retries in ms
769+ * @param maxRetry number of maximum retry
787770 * @return optional ChainTask
788771 */
789772 public Optional <ChainTask > repeatGetChainTask (String chainTaskId ,
@@ -839,7 +822,7 @@ public Optional<ChainContribution> getChainContribution(String chainTaskId,
839822
840823 /**
841824 * Retrieves on-chain category with its blockchain ID
842- *
825+ * <p>
843826 * Note:
844827 * If `max execution time` is invalid, it is likely a blockchain issue.
845828 * In this case,in order to protect workflows based on top of it, the category
@@ -859,7 +842,7 @@ public Optional<ChainCategory> getChainCategory(long id) {
859842 );
860843 if (chainCategory .getMaxExecutionTime () <= 0 ) {
861844 log .error ("Category max execution time should be greater than zero " +
862- "(likely a blockchain issue) [categoryId:{}, maxExecutionTime:{}]" ,
845+ "(likely a blockchain issue) [categoryId:{}, maxExecutionTime:{}]" ,
863846 id , chainCategory .getMaxExecutionTime ());
864847 return Optional .empty ();
865848 }
0 commit comments