@@ -315,8 +315,6 @@ export class Commands {
315315 return ;
316316 }
317317
318- // TODO: check valid maxJobDuration
319-
320318 const computeEnvID = args [ 3 ] ;
321319 // NO chainId needed anymore (is not part of ComputeEnvironment spec anymore)
322320 // const chainComputeEnvs = computeEnvs[computeEnvID]; // was algoDdo.chainId
@@ -374,6 +372,20 @@ export class Commands {
374372 ) ;
375373 return ;
376374 }
375+ if ( maxJobDuration < 0 ) {
376+ console . error (
377+ "Error initializing Provider for the compute job using dataset DID " +
378+ args [ 1 ] +
379+ " and algorithm DID " +
380+ args [ 2 ] +
381+ " because maxJobDuration is less than 0. It should be in seconds."
382+ ) ;
383+ return ;
384+ }
385+ let supportedMaxJobDuration : number = maxJobDuration ;
386+ if ( maxJobDuration > computeEnv . maxJobDuration ) {
387+ supportedMaxJobDuration = computeEnv . maxJobDuration ;
388+ }
377389 const paymentToken = args [ 5 ]
378390 if ( ! paymentToken ) {
379391 console . error (
@@ -385,6 +397,31 @@ export class Commands {
385397 ) ;
386398 return ;
387399 }
400+ const chainId = await this . signer . getChainId ( )
401+ if ( ! computeEnv . fees . keys ( ) . includes ( chainId ) ) {
402+ console . error (
403+ "Error starting paid compute using dataset DID " +
404+ args [ 1 ] +
405+ " and algorithm DID " +
406+ args [ 2 ] +
407+ " because chainId is not supported by compute environment. " +
408+ args [ 3 ] +
409+ ". Supported chain IDs: " +
410+ computeEnv . fees . keys ( )
411+ ) ;
412+ return ;
413+ }
414+ if ( computeEnv . fees [ chainId ] . feeToken !== paymentToken ) {
415+ console . error (
416+ "Error initializing Provider for the compute job using dataset DID " +
417+ args [ 1 ] +
418+ " and algorithm DID " +
419+ args [ 2 ] +
420+ " because paymentToken is not supported by this environment " +
421+ args [ 3 ]
422+ ) ;
423+ return ;
424+ }
388425 const resources = args [ 6 ] // resources object should be stringified in cli when calling initializeCompute
389426 if ( ! resources ) {
390427 console . error (
@@ -396,16 +433,22 @@ export class Commands {
396433 ) ;
397434 return ;
398435 }
436+ const parsedResources = JSON . parse ( resources ) ;
437+ // for (const resource of parsedResources) {
438+ // if (resource.amount > computeEnv.resources[resource.id].amount) {
439+
440+ // }
441+ // }
399442 const providerInitializeComputeJob =
400443 await ProviderInstance . initializeCompute (
401444 assets ,
402445 algo ,
403446 computeEnv . id ,
404447 paymentToken ,
405- maxJobDuration ,
448+ supportedMaxJobDuration ,
406449 providerURI ,
407450 this . signer , // V1 was this.signer.getAddress()
408- JSON . parse ( resources )
451+ parsedResources
409452 ) ;
410453 if (
411454 ! providerInitializeComputeJob ||
@@ -594,7 +637,6 @@ export class Commands {
594637 }
595638 }
596639 // payment check
597- // TODO: check valid maxJobDuration
598640 const maxJobDuration = Number ( args [ 5 ] )
599641 if ( ! maxJobDuration ) {
600642 console . error (
@@ -606,21 +648,61 @@ export class Commands {
606648 ) ;
607649 return ;
608650 }
651+ if ( maxJobDuration < 0 ) {
652+ console . error (
653+ "Error starting paid compute using dataset DID " +
654+ args [ 1 ] +
655+ " and algorithm DID " +
656+ args [ 2 ] +
657+ " because maxJobDuration is less than 0. It should be in seconds."
658+ ) ;
659+ return ;
660+ }
661+ let supportedMaxJobDuration : number = maxJobDuration ;
662+ if ( maxJobDuration > computeEnv . maxJobDuration ) {
663+ supportedMaxJobDuration = computeEnv . maxJobDuration ;
664+ }
665+ const chainId = await this . signer . getChainId ( )
609666 const paymentToken = args [ 6 ]
610667 if ( ! paymentToken ) {
611668 console . error (
612- "Error initializing Provider for the compute job using dataset DID " +
669+ "Error starting paid compute using dataset DID " +
613670 args [ 1 ] +
614671 " and algorithm DID " +
615672 args [ 2 ] +
616673 " because paymentToken was not provided."
617674 ) ;
618675 return ;
619676 }
677+ if ( ! computeEnv . fees . keys ( ) . includes ( chainId ) ) {
678+ console . error (
679+ "Error starting paid compute using dataset DID " +
680+ args [ 1 ] +
681+ " and algorithm DID " +
682+ args [ 2 ] +
683+ " because chainId is not supported by compute environment. " +
684+ args [ 3 ] +
685+ ". Supported chain IDs: " +
686+ computeEnv . fees . keys ( )
687+ ) ;
688+ return ;
689+ }
690+
691+ if ( computeEnv . fees [ chainId ] . feeToken !== paymentToken ) {
692+ console . error (
693+ "Error starting paid compute using dataset DID " +
694+ args [ 1 ] +
695+ " and algorithm DID " +
696+ args [ 2 ] +
697+ " because paymentToken is not supported by this environment " +
698+ args [ 3 ]
699+ ) ;
700+ return ;
701+ }
620702 const resources = args [ 7 ] // resources object should be stringified in cli when calling initializeCompute
621703 if ( ! resources ) {
622704 console . error (
623- "Error initializing Provider for the compute job using dataset DID " +
705+ "Error starting paid compute using dataset DID " +
624706 args [ 1 ] +
625707 " and algorithm DID " +
626708 args [ 2 ] +
@@ -634,7 +716,7 @@ export class Commands {
634716 algo ,
635717 computeEnv . id ,
636718 paymentToken ,
637- maxJobDuration ,
719+ supportedMaxJobDuration ,
638720 providerURI ,
639721 this . signer , // V1 was this.signer.getAddress()
640722 JSON . parse ( resources )
0 commit comments