@@ -15,24 +15,7 @@ import {IexecEscrow} from "./IexecEscrow.v8.sol";
1515import {IexecPocoCommon} from "./IexecPocoCommon.sol " ;
1616import {SignatureVerifier} from "./SignatureVerifier.v8.sol " ;
1717
18- struct Matching {
19- bytes32 apporderHash;
20- address appOwner;
21- bytes32 datasetorderHash;
22- address datasetOwner;
23- bytes32 workerpoolorderHash;
24- address workerpoolOwner;
25- bytes32 requestorderHash;
26- bool hasDataset;
27- }
28-
29- contract IexecPoco1Facet is
30- IexecPoco1 ,
31- FacetBase ,
32- IexecEscrow ,
33- SignatureVerifier ,
34- IexecPocoCommon
35- {
18+ contract IexecPoco1Facet is IexecPoco1 , FacetBase , IexecEscrow , SignatureVerifier , IexecPocoCommon {
3619 using Math for uint256 ;
3720 using IexecLibOrders_v5 for IexecLibOrders_v5.AppOrder;
3821 using IexecLibOrders_v5 for IexecLibOrders_v5.DatasetOrder;
@@ -387,4 +370,71 @@ contract IexecPoco1Facet is
387370
388371 return dealid;
389372 }
373+
374+ /**
375+ * @notice Public view function to check if a dataset order is compatible with a deal.
376+ * This function performs all the necessary checks to verify dataset order compatibility with a deal.
377+ *
378+ * @param datasetOrder The dataset order to verify
379+ * @param dealid The deal ID to check against
380+ * @return true if the dataset order is compatible with the deal, false otherwise
381+ */
382+ function isDatasetCompatibleWithDeal (
383+ IexecLibOrders_v5.DatasetOrder calldata datasetOrder ,
384+ bytes32 dealid
385+ ) external view override returns (bool ) {
386+ PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage ();
387+
388+ // Check if deal exists
389+ //TODO: check
390+ IexecLibCore_v5.Deal storage deal = $.m_deals[dealid];
391+ if (deal.requester == address (0 )) {
392+ return false ;
393+ }
394+
395+ // Check if deal dataset is address 0 (no dataset in deal)
396+ if (deal.dataset.pointer != address (0 )) {
397+ return false ;
398+ }
399+
400+ // Check dataset order owner signature (including presign and EIP1271)
401+ bytes32 datasetOrderHash = _toTypedDataHash (datasetOrder.hash ());
402+ address datasetOwner = IERC5313 (datasetOrder.dataset).owner ();
403+ if (! _verifySignatureOrPresignature (datasetOwner, datasetOrderHash, datasetOrder.sign)) {
404+ return false ; // Invalid signature
405+ }
406+
407+ // Check if dataset order is not fully consumed
408+ if ($.m_consumed[datasetOrderHash] >= datasetOrder.volume) {
409+ return false ;
410+ }
411+
412+ // Check if deal app is allowed by dataset order apprestrict (including whitelist)
413+ if (! _isAccountAuthorizedByRestriction (datasetOrder.apprestrict, deal.app.pointer)) {
414+ return false ;
415+ }
416+
417+ // Check if deal workerpool is allowed by dataset order workerpoolrestrict (including whitelist)
418+ if (
419+ ! _isAccountAuthorizedByRestriction (
420+ datasetOrder.workerpoolrestrict,
421+ deal.workerpool.pointer
422+ )
423+ ) {
424+ return false ;
425+ }
426+
427+ // Check if deal requester is allowed by dataset order requesterrestrict (including whitelist)
428+ if (! _isAccountAuthorizedByRestriction (datasetOrder.requesterrestrict, deal.requester)) {
429+ return false ;
430+ }
431+
432+ // Check if deal tag fulfills all the tag bits of the dataset order
433+ if ((deal.tag & datasetOrder.tag) != datasetOrder.tag) {
434+ return false ;
435+ }
436+
437+ // All checks passed
438+ return true ;
439+ }
390440}
0 commit comments