DeFiCh/jellyfish

View on GitHub

Showing 358 of 388 total issues

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

  expect(histories).toStrictEqual(
    [
      {
        id: `${oracleId}-${height1}-${oracleId}`,
        sort: `${HexEncoder.encodeHeight(height1)}${oracleId}`,
apps/whale-api/src/module.indexer/model/dftx/appointed.oracle.spec.ts on lines 61..78

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

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

  expect(histories).toStrictEqual(
    [
      {
        id: `${oracleId}-${height}-${oracleId}`,
        sort: `${HexEncoder.encodeHeight(height)}${oracleId}`,
apps/whale-api/src/module.indexer/model/dftx/remove.oracle.spec.ts on lines 53..70

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

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

File stats.controller.ts has 304 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Controller, Get, Inject, NotFoundException } from '@nestjs/common'
import { BurnData, RewardDistributionData, StatsData, SupplyData } from '@defichain/whale-api-client/dist/api/stats'
import { SemaphoreCache } from '@defichain-apps/libs/caches'
import { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc'
import { BlockMapper } from '../module.model/block'
Severity: Minor
Found in apps/whale-api/src/module.api/stats.controller.ts - About 3 hrs to fix

    File token.controller.spec.ts has 296 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { Test, TestingModule } from '@nestjs/testing'
    import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
    import { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc'
    import { parseDATSymbol, TokenController } from './token.controller'
    import { createPoolPair, createToken } from '@defichain/testing'
    Severity: Minor
    Found in apps/whale-api/src/module.api/token.controller.spec.ts - About 3 hrs to fix

      File blockchain.ts has 294 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import BigNumber from 'bignumber.js'
      import { ApiClient } from '../.'
      
      /**
       * Blockchain RPCs for DeFi Blockchain
      Severity: Minor
      Found in packages/jellyfish-api-core/src/category/blockchain.ts - About 3 hrs to fix

        File specifications.ts has 294 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import { Database, SortOrder } from '../database'
        import { PartitionMapping, PartitionSortMapping } from './_model'
        import { PARTITION_SORTS, PARTITIONS } from './_fixtures'
        
        /**
        Severity: Minor
        Found in apps/whale-api/src/module.database/database.spec/specifications.ts - About 3 hrs to fix

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

            try {
              const decodedBech32 = fromBech32(address)
          
              const p2wpkh = fromBech32P2WPKH(decodedBech32, network)
              if (p2wpkh !== undefined) {
          Severity: Major
          Found in packages/jellyfish-address/src/script/index.ts and 1 other location - About 3 hrs to fix
          packages/jellyfish-address/src/script/index.ts on lines 77..100

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

          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

            try {
              const decodedBase58Check = fromBase58Check(address)
          
              const p2pkh = fromBase58CheckP2PKH(decodedBase58Check, network)
              if (p2pkh !== undefined) {
          Severity: Major
          Found in packages/jellyfish-address/src/script/index.ts and 1 other location - About 3 hrs to fix
          packages/jellyfish-address/src/script/index.ts on lines 52..75

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

          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

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

            async waitForIndexedTimestamp (container: MasterNodeRegTestContainer, timestamp: number, timeout: number = 30000): Promise<void> {
              await waitForExpect(async () => {
                await container.generate(1)
                const height = await container.call('getblockcount')
                const stats = await container.call('getblockstats', [height])
          Severity: Major
          Found in packages/whale-api-client/__tests__/stub.service.ts and 1 other location - About 2 hrs to fix
          apps/whale-api/src/e2e.module.ts on lines 99..106

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

          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

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

          export async function waitForIndexedTimestamp (container: MasterNodeRegTestContainer, timestamp: number, timeout: number = 30000): Promise<void> {
            await waitForExpect(async () => {
              await container.generate(1)
              const height = await container.call('getblockcount')
              const stats = await container.call('getblockstats', [height])
          Severity: Major
          Found in apps/whale-api/src/e2e.module.ts and 1 other location - About 2 hrs to fix
          packages/whale-api-client/__tests__/stub.service.ts on lines 51..58

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

          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 list has 72 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            list (): SetCollateralToken[] {
              return [
                {
                  token: 'DFI',
                  fixedIntervalPriceId: 'DFI/USD',
          Severity: Major
          Found in apps/playground-api/src/setups/setup.loan.collateral.ts - About 2 hrs to fix

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

              @Get('/:txid/vins')
              async getVins (@Param('txid') txid: string, @Query() query: PaginationQuery): Promise<ApiPagedResponse<TransactionVin>> {
                const vin = await this.transactionVinMapper.query(txid, query.size, query.next)
            
                return ApiPagedResponse.of(vin, query.size, vout => {
            Severity: Major
            Found in apps/whale-api/src/module.api/transaction.controller.ts and 2 other locations - About 2 hrs to fix
            apps/whale-api/src/module.api/price.controller.ts on lines 41..50
            apps/whale-api/src/module.api/price.controller.ts on lines 52..61

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

            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

              @Get('/:key/feed/active')
              async getFeedActive (
                @Param('key') key: string,
                  @Query() query: PaginationQuery
              ): Promise<ApiPagedResponse<OraclePriceActive>> {
            Severity: Major
            Found in apps/whale-api/src/module.api/price.controller.ts and 2 other locations - About 2 hrs to fix
            apps/whale-api/src/module.api/price.controller.ts on lines 41..50
            apps/whale-api/src/module.api/transaction.controller.ts on lines 34..41

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

            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

              @Get('/:key/feed')
              async getFeed (
                @Param('key') key: string,
                  @Query() query: PaginationQuery
              ): Promise<ApiPagedResponse<OraclePriceAggregated>> {
            Severity: Major
            Found in apps/whale-api/src/module.api/price.controller.ts and 2 other locations - About 2 hrs to fix
            apps/whale-api/src/module.api/price.controller.ts on lines 52..61
            apps/whale-api/src/module.api/transaction.controller.ts on lines 34..41

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

            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 index has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
            Open

              async index (block: RawBlock): Promise<void> {
                const records: Record<string, ScriptAggregation> = {}
            
                function findScriptAggregation (hex: string, type: string): ScriptAggregation {
                  const hid = HexEncoder.asSHA256(hex)
            Severity: Minor
            Found in apps/whale-api/src/module.indexer/model/script.aggregation.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

            File dftx.ts has 280 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import { SmartBuffer } from 'smart-buffer'
            import { BufferComposer, ComposableBuffer } from '@defichain/jellyfish-buffer'
            import {
              AccountToAccount,
              AccountToUtxos,
            Severity: Minor
            Found in packages/jellyfish-transaction/src/script/dftx/dftx.ts - About 2 hrs to fix

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

                  try {
                    const result = await this.rpcClient.poolpair.getPoolPair(`${a}-${b}`, true)
                    if (Object.values(result).length > 0) {
                      return Object.values(result)[0]
                    }
              Severity: Major
              Found in apps/whale-api/src/module.api/poolpair.service.ts and 1 other location - About 2 hrs to fix
              apps/whale-api/src/module.api/poolpair.service.ts on lines 62..71

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

              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

                  try {
                    const result = await this.rpcClient.poolpair.getPoolPair(`${b}-${a}`, true)
                    if (Object.values(result).length > 0) {
                      return Object.values(result)[0]
                    }
              Severity: Major
              Found in apps/whale-api/src/module.api/poolpair.service.ts and 1 other location - About 2 hrs to fix
              apps/whale-api/src/module.api/poolpair.service.ts on lines 51..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 118.

              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

                @Get('listtokens')
                async listTokens (
                  @Query('network', NetworkValidationPipe) network: SupportedNetwork = 'mainnet',
                  @Query('id') tokenId: string
                ): Promise<{ [key: string]: LegacyTokenData }> {
              Severity: Major
              Found in apps/legacy-api/src/controllers/TokenController.ts and 1 other location - About 2 hrs to fix
              apps/legacy-api/src/controllers/PoolPairController.ts on lines 30..43

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

              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 function fromScriptP2WSH (script: Script, network: NetworkName): string | undefined {
                if (!isScriptP2WSH(script)) {
                  return undefined
                }
              
              
              Severity: Major
              Found in packages/jellyfish-address/src/script/P2WSH.ts and 1 other location - About 2 hrs to fix
              packages/jellyfish-address/src/script/P2WPKH.ts on lines 11..20

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

              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