@@ -51,6 +51,7 @@ import {
5151 WriteReportRequestSchema ,
5252} from '@cre/generated/capabilities/blockchain/evm/v1alpha/client_pb'
5353import {
54+ type CapabilityRestrictionJson ,
5455 type ReportResponse ,
5556 type ReportResponseJson ,
5657 ReportResponseSchema ,
@@ -519,3 +520,110 @@ class ClientLogTrigger implements Trigger<Log, Log> {
519520 return rawOutput
520521 }
521522}
523+ export class ClientRestrictor {
524+ constructor ( private readonly ChainSelector : bigint ) { }
525+
526+ limitCallContract ( maxCalls : number ) : CapabilityRestrictionJson {
527+ // Include all labels in capability ID for routing when specified
528+ const capabilityId = `${ ClientCapability . CAPABILITY_NAME } :ChainSelector:${ this . ChainSelector } @${ ClientCapability . CAPABILITY_VERSION } `
529+
530+ return {
531+ method : {
532+ id : capabilityId ,
533+ method : 'CallContract' ,
534+ maxCalls,
535+ } ,
536+ }
537+ }
538+
539+ limitFilterLogs ( maxCalls : number ) : CapabilityRestrictionJson {
540+ // Include all labels in capability ID for routing when specified
541+ const capabilityId = `${ ClientCapability . CAPABILITY_NAME } :ChainSelector:${ this . ChainSelector } @${ ClientCapability . CAPABILITY_VERSION } `
542+
543+ return {
544+ method : {
545+ id : capabilityId ,
546+ method : 'FilterLogs' ,
547+ maxCalls,
548+ } ,
549+ }
550+ }
551+
552+ limitBalanceAt ( maxCalls : number ) : CapabilityRestrictionJson {
553+ // Include all labels in capability ID for routing when specified
554+ const capabilityId = `${ ClientCapability . CAPABILITY_NAME } :ChainSelector:${ this . ChainSelector } @${ ClientCapability . CAPABILITY_VERSION } `
555+
556+ return {
557+ method : {
558+ id : capabilityId ,
559+ method : 'BalanceAt' ,
560+ maxCalls,
561+ } ,
562+ }
563+ }
564+
565+ limitEstimateGas ( maxCalls : number ) : CapabilityRestrictionJson {
566+ // Include all labels in capability ID for routing when specified
567+ const capabilityId = `${ ClientCapability . CAPABILITY_NAME } :ChainSelector:${ this . ChainSelector } @${ ClientCapability . CAPABILITY_VERSION } `
568+
569+ return {
570+ method : {
571+ id : capabilityId ,
572+ method : 'EstimateGas' ,
573+ maxCalls,
574+ } ,
575+ }
576+ }
577+
578+ limitGetTransactionByHash ( maxCalls : number ) : CapabilityRestrictionJson {
579+ // Include all labels in capability ID for routing when specified
580+ const capabilityId = `${ ClientCapability . CAPABILITY_NAME } :ChainSelector:${ this . ChainSelector } @${ ClientCapability . CAPABILITY_VERSION } `
581+
582+ return {
583+ method : {
584+ id : capabilityId ,
585+ method : 'GetTransactionByHash' ,
586+ maxCalls,
587+ } ,
588+ }
589+ }
590+
591+ limitGetTransactionReceipt ( maxCalls : number ) : CapabilityRestrictionJson {
592+ // Include all labels in capability ID for routing when specified
593+ const capabilityId = `${ ClientCapability . CAPABILITY_NAME } :ChainSelector:${ this . ChainSelector } @${ ClientCapability . CAPABILITY_VERSION } `
594+
595+ return {
596+ method : {
597+ id : capabilityId ,
598+ method : 'GetTransactionReceipt' ,
599+ maxCalls,
600+ } ,
601+ }
602+ }
603+
604+ limitHeaderByNumber ( maxCalls : number ) : CapabilityRestrictionJson {
605+ // Include all labels in capability ID for routing when specified
606+ const capabilityId = `${ ClientCapability . CAPABILITY_NAME } :ChainSelector:${ this . ChainSelector } @${ ClientCapability . CAPABILITY_VERSION } `
607+
608+ return {
609+ method : {
610+ id : capabilityId ,
611+ method : 'HeaderByNumber' ,
612+ maxCalls,
613+ } ,
614+ }
615+ }
616+
617+ limitWriteReport ( maxCalls : number ) : CapabilityRestrictionJson {
618+ // Include all labels in capability ID for routing when specified
619+ const capabilityId = `${ ClientCapability . CAPABILITY_NAME } :ChainSelector:${ this . ChainSelector } @${ ClientCapability . CAPABILITY_VERSION } `
620+
621+ return {
622+ method : {
623+ id : capabilityId ,
624+ method : 'WriteReport' ,
625+ maxCalls,
626+ } ,
627+ }
628+ }
629+ }
0 commit comments