stellar/js-stellar-base

View on GitHub

Showing 111 of 111 total issues

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

  interface PathPaymentStrictSend
    extends BaseOperation<OperationType.PathPaymentStrictSend> {
    sendAsset: Asset;
    sendAmount: string;
    destination: string;
Severity: Major
Found in types/index.d.ts and 1 other location - About 1 hr to fix
types/index.d.ts on lines 702..710

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

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

  interface PathPaymentStrictReceive
    extends BaseOperation<OperationType.PathPaymentStrictReceive> {
    sendAsset: Asset;
    sendMax: string;
    destination: string;
Severity: Major
Found in types/index.d.ts and 1 other location - About 1 hr to fix
types/index.d.ts on lines 715..723

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

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

export async function authorizeEntry(
  entry,
  signer,
  validUntilLedgerSeq,
  networkPassphrase = Networks.FUTURENET
Severity: Minor
Found in src/auth.js - About 1 hr to fix

    Function calculateChecksum has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function calculateChecksum(payload) {
      const crcTable = [
        0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108,
        0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210,
        0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b,
    Severity: Minor
    Found in src/strkey.js - About 1 hr to fix

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

            case xdr.EnvelopeType.envelopeTypeTx():
              envelope = new xdr.TransactionEnvelope.envelopeTypeTx(
                new xdr.TransactionV1Envelope({
                  tx: xdr.Transaction.fromXDR(rawTx), // make a copy of tx
                  signatures
      Severity: Major
      Found in src/transaction.js and 1 other location - About 1 hr to fix
      src/transaction.js on lines 295..302

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

      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

            case xdr.EnvelopeType.envelopeTypeTxV0():
              envelope = new xdr.TransactionEnvelope.envelopeTypeTxV0(
                new xdr.TransactionV0Envelope({
                  tx: xdr.TransactionV0.fromXDR(rawTx), // make a copy of tx
                  signatures
      Severity: Major
      Found in src/transaction.js and 1 other location - About 1 hr to fix
      src/transaction.js on lines 303..310

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

      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

              case xdr.LedgerEntryType.liquidityPool().name: {
                result.type = 'revokeLiquidityPoolSponsorship';
                result.liquidityPoolId = ledgerKey
                  .liquidityPool()
                  .liquidityPoolId()
      Severity: Major
      Found in src/operation.js and 1 other location - About 1 hr to fix
      src/operation.js on lines 579..586

      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

              case xdr.LedgerEntryType.claimableBalance().name: {
                result.type = 'revokeClaimableBalanceSponsorship';
                result.balanceId = ledgerKey
                  .claimableBalance()
                  .balanceId()
      Severity: Major
      Found in src/operation.js and 1 other location - About 1 hr to fix
      src/operation.js on lines 587..594

      Duplicated Code

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

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

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

      Tuning

      This issue has a mass of 67.

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

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

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

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

      Refactorings

      Further Reading

      Function isValid has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      function isValid(versionByteName, encoded) {
        if (typeof encoded !== 'string') {
          return false;
        }
      
      
      Severity: Minor
      Found in src/strkey.js - About 1 hr to fix

      Cognitive Complexity

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

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

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

      Further reading

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

      export function setTrustLineFlags(opts = {}) {
        const attributes = {};
      
        if (typeof opts.flags !== 'object' || Object.keys(opts.flags).length === 0) {
          throw new Error('opts.flags must be a map of boolean flags to modify');
      Severity: Minor
      Found in src/operations/set_trustline_flags.js - About 1 hr to fix

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

          interface PathPaymentStrictSend extends BaseOptions {
            sendAsset: Asset;
            sendAmount: string;
            destination: string;
            destAsset: Asset;
        Severity: Major
        Found in types/index.d.ts and 1 other location - About 1 hr to fix
        types/index.d.ts on lines 448..455

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

        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

          interface PathPaymentStrictReceive extends BaseOptions {
            sendAsset: Asset;
            sendMax: string;
            destination: string;
            destAsset: Asset;
        Severity: Major
        Found in types/index.d.ts and 1 other location - About 1 hr to fix
        types/index.d.ts on lines 456..463

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

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

        export function best_r(rawNumber) {
          let number = new BigNumber(rawNumber);
          let a;
          let f;
          const fractions = [
        Severity: Minor
        Found in src/util/continued_fraction.js - About 1 hr to fix

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

            interface ManageBuyOffer extends BaseOperation<OperationType.ManageBuyOffer> {
              selling: Asset;
              buying: Asset;
              buyAmount: string;
              price: string;
          Severity: Major
          Found in types/index.d.ts and 1 other location - About 1 hr to fix
          types/index.d.ts on lines 679..686

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

          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

            interface ManageSellOffer
              extends BaseOperation<OperationType.ManageSellOffer> {
              selling: Asset;
              buying: Asset;
              amount: string;
          Severity: Major
          Found in types/index.d.ts and 1 other location - About 1 hr to fix
          types/index.d.ts on lines 691..697

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

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

          function checkFastSigningNode() {
            // NOTE: we use commonjs style require here because es6 imports
            // can only occur at the top level.  thanks, obama.
            let sodium;
            try {
          Severity: Minor
          Found in src/signing.js - About 1 hr to fix

            Function createCustomContract has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function createCustomContract(opts) {
              const salt = Buffer.from(opts.salt || getSalty());
            
              if (!opts.wasmHash || opts.wasmHash.length !== 32) {
                throw new TypeError(
            Severity: Minor
            Found in src/operations/invoke_host_function.js - About 1 hr to fix

              Function pathPaymentStrictReceive has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function pathPaymentStrictReceive(opts) {
                switch (true) {
                  case !opts.sendAsset:
                    throw new Error('Must specify a send asset');
                  case !this.isValidAmount(opts.sendMax):
              Severity: Minor
              Found in src/operations/path_payment_strict_receive.js - About 1 hr to fix

                Function pathPaymentStrictSend has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export function pathPaymentStrictSend(opts) {
                  switch (true) {
                    case !opts.sendAsset:
                      throw new Error('Must specify a send asset');
                    case !this.isValidAmount(opts.sendAmount):
                Severity: Minor
                Found in src/operations/path_payment_strict_send.js - About 1 hr to fix

                  Function allowTrust has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export function allowTrust(opts) {
                    if (!StrKey.isValidEd25519PublicKey(opts.trustor)) {
                      throw new Error('trustor is invalid');
                    }
                    const attributes = {};
                  Severity: Minor
                  Found in src/operations/allow_trust.js - About 1 hr to fix
                    Severity
                    Category
                    Status
                    Source
                    Language