oceanprotocol/ocean.js

View on GitHub

Showing 61 of 177 total issues

File Provider.ts has 748 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import fetch from 'cross-fetch'
import { ethers, Signer, providers } from 'ethers'
import { LoggerInstance } from '../utils'
import {
  Arweave,
Severity: Major
Found in src/services/Provider.ts - About 1 day to fix

    File Datatoken.ts has 584 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { ethers, Signer } from 'ethers'
    import Decimal from 'decimal.js'
    import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
    import ERC20TemplateEnterprise from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json'
    import { amountToUnits, sendTx, ZERO_ADDRESS } from '../utils'
    Severity: Major
    Found in src/contracts/Datatoken.ts - About 1 day to fix

      File NFT.ts has 492 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import { BigNumber, ethers } from 'ethers'
      import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json'
      import { generateDtName, sendTx, getEventFromTx } from '../utils'
      import {
        MetadataProof,
      Severity: Minor
      Found in src/contracts/NFT.ts - About 7 hrs to fix

        File FixedRateExchange.ts has 488 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import FixedRateExchangeAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json'
        import { sendTx, ZERO_ADDRESS } from '../utils'
        import {
          PriceAndFees,
          FeesInfo,
        Severity: Minor
        Found in src/contracts/FixedRateExchange.ts - About 7 hrs to fix

          Function orderAsset has 178 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export async function orderAsset(
            asset: Asset,
            consumerAccount: Signer,
            config: Config,
            datatoken: Datatoken,
          Severity: Major
          Found in src/utils/OrderUtils.ts - About 7 hrs to fix

            Function orderAsset has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
            Open

            export async function orderAsset(
              asset: Asset,
              consumerAccount: Signer,
              config: Config,
              datatoken: Datatoken,
            Severity: Minor
            Found in src/utils/OrderUtils.ts - About 6 hrs 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

            File NFTFactory.ts has 415 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import { BigNumber } from 'ethers'
            import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json'
            import {
              generateDtName,
              ZERO_ADDRESS,
            Severity: Minor
            Found in src/contracts/NFTFactory.ts - About 5 hrs to fix

              Datatoken has 34 functions (exceeds 20 allowed). Consider refactoring.
              Open

              export class Datatoken extends SmartContract {
                public abiEnterprise: AbiItem[]
                public nft: Nft
              
                getDefaultAbi() {
              Severity: Minor
              Found in src/contracts/Datatoken.ts - About 4 hrs to fix

                FixedRateExchange has 30 functions (exceeds 20 allowed). Consider refactoring.
                Open

                export class FixedRateExchange extends SmartContractWithAddress {
                  getDefaultAbi() {
                    return FixedRateExchangeAbi.abi as AbiItem[]
                  }
                
                
                Severity: Minor
                Found in src/contracts/FixedRateExchange.ts - About 3 hrs to fix

                  Function getAddressesFromEnv has 79 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    public getAddressesFromEnv(network: string, customAddresses?: any): Partial<Config> {
                      // use the defaults first
                      let configAddresses: Partial<Config>
                      // load from custom addresses structure
                      if (customAddresses && customAddresses[network]) {
                  Severity: Major
                  Found in src/config/ConfigHelper.ts - About 3 hrs to fix

                    Nft has 24 functions (exceeds 20 allowed). Consider refactoring.
                    Open

                    export class Nft extends SmartContract {
                      getDefaultAbi() {
                        return ERC721Template.abi as AbiItem[]
                      }
                    
                    
                    Severity: Minor
                    Found in src/contracts/NFT.ts - About 2 hrs to fix

                      NftFactory has 23 functions (exceeds 20 allowed). Consider refactoring.
                      Open

                      export class NftFactory extends SmartContractWithAddress {
                        getDefaultAbi() {
                          return ERC721Factory.abi as AbiItem[]
                        }
                      
                      
                      Severity: Minor
                      Found in src/contracts/NFTFactory.ts - About 2 hrs to fix

                        Function sendTx has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                        Open

                        export async function sendTx(
                          estGas: BigNumber,
                          signer: Signer,
                          gasFeeMultiplier: number,
                          functionToSend: ContractFunction,
                        Severity: Minor
                        Found in src/utils/ContractUtils.ts - About 2 hrs 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

                        Provider has 22 functions (exceeds 20 allowed). Consider refactoring.
                        Open

                        export class Provider {
                          /**
                           * Returns the provider endpoints
                           * @param {string} providerUri - the provider url
                           * @return {Promise<any>}
                        Severity: Minor
                        Found in src/services/Provider.ts - About 2 hrs to fix

                          Function computeStart has 58 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            public async computeStart(
                              providerUri: string,
                              consumer: Signer,
                              computeEnv: string,
                              dataset: ComputeAsset,
                          Severity: Major
                          Found in src/services/Provider.ts - About 2 hrs to fix

                            Function computeStop has 56 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                              public async computeStop(
                                did: string,
                                consumerAddress: string,
                                jobId: string,
                                providerUri: string,
                            Severity: Major
                            Found in src/services/Provider.ts - About 2 hrs to fix

                              Function computeDelete has 55 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                public async computeDelete(
                                  did: string,
                                  consumer: Signer,
                                  jobId: string,
                                  providerUri: string,
                              Severity: Major
                              Found in src/services/Provider.ts - About 2 hrs to fix

                                File ConfigHelper.ts has 258 lines of code (exceeds 250 allowed). Consider refactoring.
                                Open

                                // eslint-disable-next-line import/no-named-default
                                import { default as DefaultContractsAddresses } from '@oceanprotocol/contracts/addresses/address.json'
                                import fs from 'fs'
                                import { Config } from '.'
                                import { LoggerInstance } from '../utils'
                                Severity: Minor
                                Found in src/config/ConfigHelper.ts - About 2 hrs to fix

                                  Function sendTx has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  export async function sendTx(
                                    estGas: BigNumber,
                                    signer: Signer,
                                    gasFeeMultiplier: number,
                                    functionToSend: ContractFunction,
                                  Severity: Minor
                                  Found in src/utils/ContractUtils.ts - About 1 hr to fix

                                    Function computeStatus has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                      public async computeStatus(
                                        providerUri: string,
                                        consumerAddress: string,
                                        jobId?: string,
                                        did?: string,
                                    Severity: Minor
                                    Found in src/services/Provider.ts - About 1 hr to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language