oceanprotocol/ocean.js

View on GitHub
src/contracts/Datatoken.ts

Summary

Maintainability
F
1 wk
Test Coverage
A
93%

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

    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

      Function createFixedRate has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        public async createFixedRate<G extends boolean = false>(
          dtAddress: string,
          address: string,
          fixedRateParams: FreCreationParams,
          estimateGas?: G
      Severity: Minor
      Found in src/contracts/Datatoken.ts - About 1 hr to fix

        Function createDispenser has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          public async createDispenser<G extends boolean = false>(
            dtAddress: string,
            address: string,
            dispenserAddress: string,
            dispenserParams: DispenserParams,
        Severity: Minor
        Found in src/contracts/Datatoken.ts - About 1 hr to fix

          Function startOrder has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public async startOrder<G extends boolean = false>(
              dtAddress: string,
              consumer: string,
              serviceIndex: number,
              providerFees: ProviderFees,
          Severity: Minor
          Found in src/contracts/Datatoken.ts - About 1 hr to fix

            Function mint has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              public async mint<G extends boolean = false>(
                dtAddress: string,
                address: string,
                amount: string,
                toAddress?: string,
            Severity: Minor
            Found in src/contracts/Datatoken.ts - About 25 mins 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

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

              public async addPaymentManager<G extends boolean = false>(
                dtAddress: string,
                address: string,
                paymentManager: string,
                estimateGas?: G
            Severity: Major
            Found in src/contracts/Datatoken.ts and 2 other locations - About 1 day to fix
            src/contracts/Datatoken.ts on lines 287..311
            src/contracts/Datatoken.ts on lines 357..381

            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 199.

            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 3 locations. Consider refactoring.
            Open

              public async removePaymentManager<G extends boolean = false>(
                dtAddress: string,
                address: string,
                paymentManager: string,
                estimateGas?: G
            Severity: Major
            Found in src/contracts/Datatoken.ts and 2 other locations - About 1 day to fix
            src/contracts/Datatoken.ts on lines 287..311
            src/contracts/Datatoken.ts on lines 322..346

            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 199.

            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 3 locations. Consider refactoring.
            Open

              public async removeMinter<G extends boolean = false>(
                dtAddress: string,
                address: string,
                minter: string,
                estimateGas?: G
            Severity: Major
            Found in src/contracts/Datatoken.ts and 2 other locations - About 1 day to fix
            src/contracts/Datatoken.ts on lines 322..346
            src/contracts/Datatoken.ts on lines 357..381

            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 199.

            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 transferWei<G extends boolean = false>(
                dtAddress: string,
                toAddress: string,
                amount: string,
                estimateGas?: G
            Severity: Major
            Found in src/contracts/Datatoken.ts and 1 other location - About 3 hrs to fix
            src/contracts/Datatoken.ts on lines 545..565

            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 109.

            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 reuseOrder<G extends boolean = false>(
                dtAddress: string,
                orderTxId: string,
                providerFees: ProviderFees,
                estimateGas?: G
            Severity: Major
            Found in src/contracts/Datatoken.ts and 1 other location - About 3 hrs to fix
            src/contracts/Datatoken.ts on lines 465..485

            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 109.

            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 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 676..680

            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 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 698..705

            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 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 789..793

            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 800..804

            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 4 locations. Consider refactoring.
            Open

              public async getName(dtAddress: string): Promise<string> {
                const dtContract = this.getContract(dtAddress)
                const name = await dtContract.name()
                return name
              }
            Severity: Major
            Found in src/contracts/Datatoken.ts and 3 other locations - About 1 hr to fix
            src/contracts/Datatoken.ts on lines 429..433
            src/contracts/Datatoken.ts on lines 756..760
            src/contracts/Datatoken.ts on lines 778..782

            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 61.

            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 4 locations. Consider refactoring.
            Open

              public async getPaymentCollector(dtAddress: string): Promise<string> {
                const dtContract = this.getContract(dtAddress)
                const paymentCollector = await dtContract.getPaymentCollector()
                return paymentCollector
              }
            Severity: Major
            Found in src/contracts/Datatoken.ts and 3 other locations - About 1 hr to fix
            src/contracts/Datatoken.ts on lines 756..760
            src/contracts/Datatoken.ts on lines 767..771
            src/contracts/Datatoken.ts on lines 778..782

            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 61.

            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 4 locations. Consider refactoring.
            Open

              public async getSymbol(dtAddress: string): Promise<string> {
                const dtContract = this.getContract(dtAddress)
                const symbol = await dtContract.symbol()
                return symbol
              }
            Severity: Major
            Found in src/contracts/Datatoken.ts and 3 other locations - About 1 hr to fix
            src/contracts/Datatoken.ts on lines 429..433
            src/contracts/Datatoken.ts on lines 767..771
            src/contracts/Datatoken.ts on lines 778..782

            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 61.

            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 4 locations. Consider refactoring.
            Open

              public async getNFTAddress(dtAddress: string): Promise<string> {
                const dtContract = this.getContract(dtAddress)
                const nftAddress = await dtContract.getERC721Address()
                return nftAddress
              }
            Severity: Major
            Found in src/contracts/Datatoken.ts and 3 other locations - About 1 hr to fix
            src/contracts/Datatoken.ts on lines 429..433
            src/contracts/Datatoken.ts on lines 756..760
            src/contracts/Datatoken.ts on lines 767..771

            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 61.

            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 getDecimals(dtAddress: string): Promise<number> {
                const dtContract = this.getContract(dtAddress)
                const decimals = await dtContract.decimals()
                return decimals
              }
            Severity: Major
            Found in src/contracts/Datatoken.ts and 1 other location - About 1 hr to fix
            src/contracts/Datatoken.ts on lines 745..749

            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 61.

            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 getId(dtAddress: string): Promise<number> {
                const dtContract = this.getContract(dtAddress)
                const id = await dtContract.getId()
                return id
              }
            Severity: Major
            Found in src/contracts/Datatoken.ts and 1 other location - About 1 hr to fix
            src/contracts/Datatoken.ts on lines 734..738

            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 61.

            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

            There are no issues that match your filters.

            Category
            Status