lbryio/chainquery

View on GitHub

Showing 107 of 112 total issues

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

func newVideoStreamClaim() (*c.StakeHelper, error) {
    streamClaim := new(pb.Claim_Stream)
    stream := new(pb.Stream)
    video := new(pb.Stream_Video)
    video.Video = new(pb.Video)
Severity: Major
Found in e2e/claim.go and 1 other location - About 1 hr to fix
e2e/claim.go on lines 40..55

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

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

func newImageStreamClaim() (*c.StakeHelper, error) {
    streamClaim := new(pb.Claim_Stream)
    stream := new(pb.Stream)
    image := new(pb.Stream_Image)
    image.Image = new(pb.Image)
Severity: Major
Found in e2e/claim.go and 1 other location - About 1 hr to fix
e2e/claim.go on lines 57..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 144.

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

    if dataPushType == opPushdata1 {
        valueBytesToRead = int(script[claimidEnd+1])
        valueStart = claimidEnd + 2
    } else if dataPushType == opPushdata2 {
        valueStart = claimidEnd + 3
Severity: Major
Found in lbrycrd/script.go and 1 other location - About 1 hr to fix
lbrycrd/script.go on lines 154..163

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

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

    if dataPushType == opPushdata1 {
        valueBytesToRead = int(script[nameEnd+1])
        valueStart = nameEnd + 2
    } else if dataPushType == opPushdata2 {
        valueStart = nameEnd + 3
Severity: Major
Found in lbrycrd/script.go and 1 other location - About 1 hr to fix
lbrycrd/script.go on lines 247..256

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

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 SyncTransactionValue has 53 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func SyncTransactionValue() (int64, error) {

    transactionTbl := model.TableNames.Transaction
    transactionAddressTbl := model.TableNames.TransactionAddress
    blockTbl := model.TableNames.Block
Severity: Minor
Found in daemon/jobs/valuesync.go - About 1 hr to fix

Function updateSpentClaims has 53 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func updateSpentClaims() error {
    var lastProcessed uint64
    for {
        //Claims without updates
        claims, newLastProcessed, err := getSpentClaimsToUpdate(false, lastProcessed)
Severity: Minor
Found in daemon/jobs/claimtriesync.go - About 1 hr to fix

Function setClaimAddresses has 53 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func setClaimAddresses() {
    type claimForClaimAddress struct {
        ID              uint64 `boil:"id"`
        ScriptPubKeyHex string `boil:"script_pub_key_hex"`
        ClaimAddress    string `boil:"claim_address"`
Severity: Minor
Found in daemon/upgrademanager/script.go - About 1 hr to fix

Function processClaimUpdateScript has 51 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func processClaimUpdateScript(script *[]byte, vout model.Output, tx model.Transaction, blockHeight uint64) (name string, claimID string, pubkeyscript []byte, err error) {
    name, claimID, value, pubkeyscript, err := lbrycrd.ParseClaimUpdateScript(*script)
    if err != nil {
        err := errors.Prefix("Claim update processing error", err)
        return name, claimID, pubkeyscript, err
Severity: Minor
Found in daemon/processing/claim.go - About 1 hr to fix

Function setChannelMetadata has 51 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func setChannelMetadata(claim *model.Claim, channel pb.Channel) {
    claim.Type.SetValid(global.ChannelClaimType)
    if channel.GetCover() != nil {
        c := channel.GetCover()
        if c.GetName() != "" {
Severity: Minor
Found in daemon/processing/claim.go - About 1 hr to fix

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

func (txDC *txDebitCredits) subtract(address string, value float64) {
    txDC.mutex.Lock()
    if txDC.addrDCMap[address] == nil {
        addrDC := addrDebitCredits{}
        txDC.addrDCMap[address] = &addrDC
Severity: Major
Found in daemon/processing/transaction.go and 1 other location - About 1 hr to fix
daemon/processing/transaction.go on lines 125..133

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

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 ProcessVout has 10 return statements (exceeds 4 allowed).
Open

func ProcessVout(jsonVout *lbrycrd.Vout, tx *m.Transaction, txDC *txDebitCredits, blockHeight uint64) error {
    defer metrics.Processing(time.Now(), "vout")
    vout := &m.Output{}
    foundVout := ds.GetOutput(tx.Hash, uint(jsonVout.N))
    if foundVout != nil {
Severity: Major
Found in daemon/processing/outpoint.go - About 1 hr to fix

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

func (txDC *txDebitCredits) add(address string, value float64) {
    txDC.mutex.Lock()
    if txDC.addrDCMap[address] == nil {
        addrDC := addrDebitCredits{}
        txDC.addrDCMap[address] = &addrDC
Severity: Major
Found in daemon/processing/transaction.go and 1 other location - About 1 hr to fix
daemon/processing/transaction.go on lines 115..123

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

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 ProcessVin has 10 return statements (exceeds 4 allowed).
Open

func ProcessVin(jsonVin *lbrycrd.Vin, tx *m.Transaction, txDC *txDebitCredits, n uint64) error {
    defer metrics.Processing(time.Now(), "vin")
    isVinCoinbase := len(jsonVin.Coinbase) > 0
    vin := &m.Input{
        TransactionID:   tx.ID,
Severity: Major
Found in daemon/processing/outpoint.go - About 1 hr to fix

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

func getAddressFromP2PKH(hexstring string) (string, error) {
    hexstringBytes, err := hex.DecodeString(hexstring)
    if err != nil {
        return "", err
    }
Severity: Major
Found in lbrycrd/script.go and 4 other locations - About 55 mins to fix
lbrycrd/script.go on lines 349..365
lbrycrd/script.go on lines 385..401
lbrycrd/script.go on lines 403..419
lbrycrd/script.go on lines 421..437

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

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

func getAddressFromP2PK(hexstring string) (string, error) {
    hexstringBytes, err := hex.DecodeString(hexstring)
    if err != nil {
        return "", err
    }
Severity: Major
Found in lbrycrd/script.go and 4 other locations - About 55 mins to fix
lbrycrd/script.go on lines 367..383
lbrycrd/script.go on lines 385..401
lbrycrd/script.go on lines 403..419
lbrycrd/script.go on lines 421..437

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

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

func getAddressFromP2SH(hexstring string) (string, error) {
    hexstringBytes, err := hex.DecodeString(hexstring)
    if err != nil {
        return "", err
    }
Severity: Major
Found in lbrycrd/script.go and 4 other locations - About 55 mins to fix
lbrycrd/script.go on lines 349..365
lbrycrd/script.go on lines 367..383
lbrycrd/script.go on lines 403..419
lbrycrd/script.go on lines 421..437

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

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

func getAddressFromP2WSH(hexstring string) (string, error) {
    witnessProgram, err := hex.DecodeString(hexstring)
    if err != nil {
        return "", err
    }
Severity: Major
Found in lbrycrd/script.go and 4 other locations - About 55 mins to fix
lbrycrd/script.go on lines 349..365
lbrycrd/script.go on lines 367..383
lbrycrd/script.go on lines 385..401
lbrycrd/script.go on lines 403..419

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

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

func getAddressFromP2WPKH(hexstring string) (string, error) {
    witnessProgram, err := hex.DecodeString(hexstring)
    if err != nil {
        return "", err
    }
Severity: Major
Found in lbrycrd/script.go and 4 other locations - About 55 mins to fix
lbrycrd/script.go on lines 349..365
lbrycrd/script.go on lines 367..383
lbrycrd/script.go on lines 385..401
lbrycrd/script.go on lines 421..437

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

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

func setStreamMetadata(claim *model.Claim, stream pb.Stream) {
    claim.Type.SetValid(global.StreamClaimType)
    if stream.GetAuthor() != "" {
        claim.Author.SetValid(stream.GetAuthor())
    }
Severity: Minor
Found in daemon/processing/claim.go - About 55 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

Function fixOutputs has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
Open

func fixOutputs() error {
    wg := sync.WaitGroup{}
    spentClaimsChan := make(chan *model.Claim, 100)
    errorsChan := make(chan error, runtime.NumCPU())
    c := model.ClaimColumns
Severity: Minor
Found in daemon/jobs/outputfixsync.go - About 55 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

Severity
Category
Status
Source
Language