DeFiCh/jellyfish

View on GitHub

Showing 358 of 388 total issues

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

function validateScript (script: Script): boolean {
  return script.stack.length === 2 &&
    script.stack[0].type === OP_CODES.OP_16.type &&
    script.stack[1].type === 'OP_PUSHDATA' && (script.stack[1] as OP_PUSHDATA).length() === 20
}
Severity: Major
Found in packages/jellyfish-address/src/eth.ts and 2 other locations - About 2 hrs to fix
packages/jellyfish-address/src/script/P2WPKH.ts on lines 5..9
packages/jellyfish-address/src/script/P2WSH.ts on lines 5..9

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

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

function isScriptP2WSH (script: Script): boolean {
  return script.stack.length === 2 &&
    script.stack[0].type === OP_CODES.OP_0.type &&
    script.stack[1].type === 'OP_PUSHDATA' && (script.stack[1] as OP_PUSHDATA).length() === 32
}
Severity: Major
Found in packages/jellyfish-address/src/script/P2WSH.ts and 2 other locations - About 2 hrs to fix
packages/jellyfish-address/src/eth.ts on lines 9..13
packages/jellyfish-address/src/script/P2WPKH.ts on lines 5..9

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

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

  static compactSize (getter: () => number, setter: (data: number) => void): BufferComposer {
    return {
      fromBuffer: (buffer: SmartBuffer): void => {
        setter(readCompactSize(buffer))
      },
Severity: Major
Found in packages/jellyfish-buffer/src/Composer.ts and 1 other location - About 2 hrs to fix
packages/jellyfish-buffer/src/Composer.ts on lines 542..551

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

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

  static varInt (getter: () => number, setter: (data: number) => void): BufferComposer {
    return {
      fromBuffer: (buffer: SmartBuffer): void => {
        setter(readVarInt(buffer))
      },
Severity: Major
Found in packages/jellyfish-buffer/src/Composer.ts and 1 other location - About 2 hrs to fix
packages/jellyfish-buffer/src/Composer.ts on lines 525..534

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

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

  static to (net: NetworkName | Network, h160: string): P2SH {
    if (h160.length !== Base58Address.DATA_HEX_LENGTH) {
      throw new Error('InvalidDataLength')
    }

Severity: Major
Found in packages/jellyfish-address/src/p2sh.ts and 1 other location - About 2 hrs to fix
packages/jellyfish-address/src/p2pkh.ts on lines 36..44

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

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

  static to (net: NetworkName | Network, h160: string): P2PKH {
    if (h160.length !== Base58Address.DATA_HEX_LENGTH) {
      throw new Error('InvalidDataLength')
    }

Severity: Major
Found in packages/jellyfish-address/src/p2pkh.ts and 1 other location - About 2 hrs to fix
packages/jellyfish-address/src/p2sh.ts on lines 36..44

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

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

  async index (block: RawBlock): Promise<void> {
    if (block.masternode !== undefined) {
      const mn = await this.masternodeMapper.get(block.masternode)
      if (mn !== undefined) {
        await this.masternodeMapper.put({ ...mn, mintedBlocks: mn.mintedBlocks + 1 })
Severity: Major
Found in apps/whale-api/src/module.indexer/model/block.minted.ts and 1 other location - About 2 hrs to fix
apps/whale-api/src/module.indexer/model/block.minted.ts on lines 22..29

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

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

  async invalidate (block: RawBlock): Promise<void> {
    if (block.masternode !== undefined) {
      const mn = await this.masternodeMapper.get(block.masternode)
      if (mn !== undefined) {
        await this.masternodeMapper.put({ ...mn, mintedBlocks: mn.mintedBlocks - 1 })
Severity: Major
Found in apps/whale-api/src/module.indexer/model/block.minted.ts and 1 other location - About 2 hrs to fix
apps/whale-api/src/module.indexer/model/block.minted.ts on lines 13..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 110.

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 class CTokenPayback extends ComposableBuffer<TokenPayback> {
  composers (tp: TokenPayback): BufferComposer[] {
    return [
      ComposableBuffer.varInt(() => tp.dToken, v => tp.dToken = v),
      ComposableBuffer.compactSizeArray(() => tp.amounts, v => tp.amounts = v, v => new CTokenBalance(v))
Severity: Major
Found in packages/jellyfish-transaction/src/script/dftx/dftx_loans.ts and 1 other location - About 2 hrs to fix
packages/jellyfish-transaction/src/script/dftx/dftx_price.ts on lines 49..56

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

  composers (tm: TokenMint): BufferComposer[] {
    return [
      ComposableBuffer.compactSizeArray(() => tm.balances, v => tm.balances = v, v => new CTokenBalance(v)),
      ComposableBuffer.single<Script>(() => tm.to, v => tm.to = v, v => new CScript(v))
    ]
Severity: Major
Found in packages/jellyfish-transaction/src/script/dftx/dftx_token.ts and 1 other location - About 2 hrs to fix
packages/jellyfish-transaction/src/script/dftx/dftx_pool.ts on lines 99..104

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

  composers (p: PoolAddLiquidity): BufferComposer[] {
    return [
      ComposableBuffer.compactSizeArray(() => p.from, v => p.from = v, v => new CScriptBalances(v)),
      ComposableBuffer.single<Script>(() => p.shareAddress, v => p.shareAddress = v, v => new CScript(v))
    ]
Severity: Major
Found in packages/jellyfish-transaction/src/script/dftx/dftx_pool.ts and 1 other location - About 2 hrs to fix
packages/jellyfish-transaction/src/script/dftx/dftx_token.ts on lines 23..28

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

export class CTokenPrice extends ComposableBuffer<TokenPrice> {
  composers (sb: TokenPrice): BufferComposer[] {
    return [
      ComposableBuffer.compactSizeUtf8BE(() => sb.token, v => sb.token = v),
      ComposableBuffer.compactSizeArray(() => sb.prices, v => sb.prices = v, v => new CTokenAmount(v))
Severity: Major
Found in packages/jellyfish-transaction/src/script/dftx/dftx_price.ts and 1 other location - About 2 hrs to fix
packages/jellyfish-transaction/src/script/dftx/dftx_loans.ts on lines 233..240

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

File place.auction.bid.spec.ts has 258 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { NestFastifyApplication } from '@nestjs/platform-fastify'
import { TestingGroup, Testing } from '@defichain/jellyfish-testing'
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { createTestingApp, stopTestingApp, waitForIndexedHeight } from '../../../e2e.module'
import { VaultAuctionHistoryMapper } from '../../../module.model/vault.auction.batch.history'

    Blockchain has 21 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class Blockchain {
      private readonly client: ApiClient
    
      constructor (client: ApiClient) {
        this.client = client
    Severity: Minor
    Found in packages/jellyfish-api-core/src/category/blockchain.ts - About 2 hrs to fix

      StatsController has 21 functions (exceeds 20 allowed). Consider refactoring.
      Open

      @Controller('/stats')
      export class StatsController {
        constructor (
          protected readonly blockMapper: BlockMapper,
          protected readonly priceTickerMapper: PriceTickerMapper,
      Severity: Minor
      Found in apps/whale-api/src/module.api/stats.controller.ts - About 2 hrs to fix

        Account has 21 functions (exceeds 20 allowed). Consider refactoring.
        Open

        export class Account {
          private readonly client: ApiClient
        
          constructor (client: ApiClient) {
            this.client = client
        Severity: Minor
        Found in packages/jellyfish-api-core/src/category/account.ts - About 2 hrs to fix

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

            async getCachedEvmRpcUrl (): Promise<string> {
              if (this.cachedEvmRpcUrl === undefined) {
                const port = await this.getEvmRpcPort()
                const user = this.startOptions!.user!
                const password = this.startOptions!.password!
          Severity: Major
          Found in packages/testcontainers/src/containers/DeFiDContainer.ts and 1 other location - About 2 hrs to fix
          packages/testcontainers/src/containers/DeFiDContainer.ts on lines 135..143

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

          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

            async getCachedRpcUrl (): Promise<string> {
              if (this.cachedRpcUrl === undefined) {
                const port = await this.getRpcPort()
                const user = this.startOptions!.user!
                const password = this.startOptions!.password!
          Severity: Major
          Found in packages/testcontainers/src/containers/DeFiDContainer.ts and 1 other location - About 2 hrs to fix
          packages/testcontainers/src/containers/DeFiDContainer.ts on lines 145..153

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

          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 loan.ts has 255 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import { ApiClient, token } from '..'
          import {
            AuctionPagination,
            CloseVault,
            CreateVault,
          Severity: Minor
          Found in packages/jellyfish-api-core/src/category/loan.ts - About 2 hrs to fix

            Function update has 53 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              async update (
                updateMasternode: UpdateMasternode,
                changeScript: Script,
                collateral?: {
                  txid: string
              Severity
              Category
              Status
              Source
              Language