oceanprotocol/ocean.js

View on GitHub

Showing 193 of 201 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  public async getPermissions(
    dtAddress: string,
    address: string
  ): Promise<DatatokenRoles> {
    const dtContract = this.getContract(dtAddress)
Severity: Major
Found in src/contracts/Datatoken.ts and 1 other location - About 1 hr to fix
src/contracts/NFT.ts on lines 700..704

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 69.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  public async getAllowlistContract(dtAddress: string): Promise<string> {
    const dtContract = this.getContract(dtAddress, this.getDefaultAbi())
    const allowList = await dtContract.getAllowListContract()
    return allowList
  }
Severity: Major
Found in src/contracts/Datatoken4.ts and 1 other location - About 1 hr to fix
src/contracts/Datatoken4.ts on lines 56..60

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 69.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Consider simplifying this complex logical expression.
Open

  if (feeHistory.maxPriorityFeePerGas) {
    let aggressiveFeePriorityFeePerGas = feeHistory.maxPriorityFeePerGas.toString()
    let aggressiveFeePerGas = feeHistory.maxFeePerGas.toString()
    if (gasFeeMultiplier > 1) {
      aggressiveFeePriorityFeePerGas = Math.round(
Severity: Critical
Found in src/utils/ContractUtils.ts - About 1 hr to fix

    Function initializeCompute has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      public async initializeCompute(
        assets: ComputeAsset[],
        algorithm: ComputeAlgorithm,
        computeEnv: string,
        validUntil: number,
    Severity: Minor
    Found in src/services/Provider.ts - About 1 hr to fix

      Function getErcCreationParams has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private async getErcCreationParams(dtParams: DatatokenCreateParams): Promise<any> {
          let name: string, symbol: string
          // Generate name & symbol if not present
          if (!dtParams.name || !dtParams.symbol) {
            ;({ name, symbol } = generateDtName())
      Severity: Minor
      Found in src/contracts/NFTFactory.ts - About 1 hr to fix

        Function initialize has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          public async initialize(
            did: string,
            serviceId: string,
            fileIndex: number,
            consumerAddress: string,
        Severity: Minor
        Found in src/services/Provider.ts - About 1 hr to fix

          Function createAsset has 13 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            name: string,
            symbol: string,
            owner: Signer,
            assetUrl: any, // files object
            templateIDorAddress: string | number, // If string, it's template address , otherwise, it's templateId
          Severity: Major
          Found in src/utils/Assets.ts - About 1 hr to fix

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

              public async isDatatokenDeployer(
                nftAddress: string,
                address: string
              ): Promise<boolean> {
                const nftContract = this.getContract(nftAddress)
            Severity: Major
            Found in src/contracts/NFT.ts and 1 other location - About 1 hr to fix
            src/contracts/Datatoken.ts on lines 798..802

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 67.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

              public async isDatatokenDeployer(dtAddress: string, address: string): Promise<boolean> {
                const dtContract = this.getContract(dtAddress)
                const isDatatokenDeployer = await dtContract.isERC20Deployer(address)
                return isDatatokenDeployer
              }
            Severity: Major
            Found in src/contracts/Datatoken.ts and 1 other location - About 1 hr to fix
            src/contracts/NFT.ts on lines 722..729

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 67.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Function waitForAqua has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

              public async waitForAqua(
                did: string,
                txid?: string,
                signal?: AbortSignal
              ): Promise<Asset> {
            Severity: Minor
            Found in src/services/Aquarius.ts - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function getErcCreationParams has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

              private async getErcCreationParams(dtParams: DatatokenCreateParams): Promise<any> {
                let name: string, symbol: string
                // Generate name & symbol if not present
                if (!dtParams.name || !dtParams.symbol) {
                  ;({ name, symbol } = generateDtName())
            Severity: Minor
            Found in src/contracts/NFTFactory.ts - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function checkDidFiles has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              public async checkDidFiles(
                did: string,
                serviceId: string,
                providerUri: string,
                withChecksum: boolean = false,
            Severity: Minor
            Found in src/services/Provider.ts - About 1 hr to fix

              Function deployAccessListContract has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                public async deployAccessListContract<G extends boolean = false>(
                  nameAccessList: string,
                  symbolAccessList: string,
                  tokenURI: string[],
                  transferable: boolean = false,
              Severity: Minor
              Found in src/contracts/AccessListFactory.ts - About 1 hr to fix

                Function orderAsset has 12 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                  asset: Asset,
                  consumerAccount: Signer,
                  config: Config,
                  datatoken: Datatoken,
                  providerUrl?: string,
                Severity: Major
                Found in src/utils/OrderUtils.ts - About 1 hr to fix

                  Function getConfig has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    public getConfig(network: string | number, infuraProjectId?: string): Config {
                      const filterBy = typeof network === 'string' ? 'network' : 'chainId'
                  
                      let config = configHelperNetworks.find((c) => c[filterBy] === network)
                  
                  
                  Severity: Minor
                  Found in src/config/ConfigHelper.ts - About 1 hr to fix

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                    export interface GraphqlQuery {
                      type: 'graphql'
                    
                      /**
                       * @type {number}
                    Severity: Major
                    Found in src/@types/File.ts and 1 other location - About 1 hr to fix
                    src/@types/File.ts on lines 7..33

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 64.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                    export interface UrlFile {
                      type: 'url'
                    
                      /**
                       * File index.
                    Severity: Major
                    Found in src/@types/File.ts and 1 other location - About 1 hr to fix
                    src/@types/File.ts on lines 34..59

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 64.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Function getComputeEnvironments has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      public async getComputeEnvironments(
                        providerUri: string,
                        signal?: AbortSignal
                      ): Promise<{ [chainId: number]: ComputeEnvironment[] }> {
                        const providerEndpoints = await this.getEndpoints(providerUri)
                    Severity: Minor
                    Found in src/services/Provider.ts - About 1 hr to fix

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                        public async getDispensers(dtAddress: string): Promise<any[]> {
                          const dtContract = this.getContract(dtAddress)
                          const dispensers = await dtContract.getDispensers()
                          return dispensers
                        }
                      Severity: Major
                      Found in src/contracts/Datatoken.ts and 1 other location - About 1 hr to fix
                      src/contracts/Datatoken.ts on lines 775..779

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 63.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                        public async getFixedRates(dtAddress: string): Promise<any[]> {
                          const dtContract = this.getContract(dtAddress)
                          const fixedRates = await dtContract.getFixedRates()
                          return fixedRates
                        }
                      Severity: Major
                      Found in src/contracts/Datatoken.ts and 1 other location - About 1 hr to fix
                      src/contracts/Datatoken.ts on lines 786..790

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 63.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Severity
                      Category
                      Status
                      Source
                      Language