lbryio/chainquery

View on GitHub

Showing 107 of 112 total issues

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

func ClaimEvent(claim *model.Claim, tx model.Transaction, claimData *c.StakeHelper) {
    values := url.Values{}
    values.Add("claim_id", claim.ClaimID)
    values.Add("name", claim.Name)
    if !claim.Type.IsZero() {
Severity: Minor
Found in notifications/events.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 ValidateChainRange has 8 return statements (exceeds 4 allowed).
Open

func ValidateChainRange(from, to *uint64) ([]BlockData, error) {

    if from == nil {
        start := uint64(0)
        from = &start
Severity: Major
Found in daemon/jobs/chainvalidation.go - About 50 mins to fix

Function ClaimTrieSync has 8 return statements (exceeds 4 allowed).
Open

func ClaimTrieSync() {
    metrics.JobLoad.WithLabelValues("claimtrie_sync").Inc()
    defer metrics.JobLoad.WithLabelValues("claimtrie_sync").Dec()
    defer metrics.Job(time.Now(), "claimtrie_sync")
    defer func() {
Severity: Major
Found in daemon/jobs/claimtriesync.go - About 50 mins to fix

Function readCompactSize has 8 return statements (exceeds 4 allowed).
Open

func readCompactSize(bs *bytes.Buffer) (uint64, []byte, error) {
    var readBuf []byte
    bSize := make([]byte, 1)
    _, err := bs.Read(bSize)
    if err != nil {
Severity: Major
Found in lbrycrd/script.go - About 50 mins to fix

Function createUpdateVinAddresses has 7 return statements (exceeds 4 allowed).
Open

func createUpdateVinAddresses(tx *model.Transaction, inputs *[]lbrycrd.Vin, blockSeconds uint64) (map[string]uint64, error) {
    addressIDMap := make(map[string]uint64)
    for _, input := range *inputs {
        srcOutput := datastore.GetOutput(input.TxID, uint(input.Vout))
        if srcOutput == nil {
Severity: Major
Found in daemon/processing/address.go - About 45 mins to fix

Function ProcessTx has 7 return statements (exceeds 4 allowed).
Open

func ProcessTx(jsonTx *lbrycrd.TxRawResult, blockTime uint64, blockHeight uint64) error {
    defer metrics.Processing(time.Now(), "transaction")
    defer util.TimeTrack(time.Now(), "processTx "+jsonTx.Txid+" -- ", "daemonprofile")

    //Save transaction before the id is used anywhere else otherwise it will be 0
Severity: Major
Found in daemon/processing/transaction.go - About 45 mins to fix

Function GetPubKeyScriptFromClaimPKS has 7 return statements (exceeds 4 allowed).
Open

func GetPubKeyScriptFromClaimPKS(script []byte) (pubkeyscript []byte, err error) {
    if IsClaimScript(script) {
        if IsClaimNameScript(script) {
            _, _, pubkeyscript, err = ParseClaimNameScript(script)
            if err != nil {
Severity: Major
Found in lbrycrd/script.go - About 45 mins to fix

Function processClaimNameScript has 7 return statements (exceeds 4 allowed).
Open

func processClaimNameScript(script *[]byte, vout model.Output, tx model.Transaction, blockHeight uint64) (name string, claimid string, pkscript []byte, err error) {
    claimid, err = util.ClaimIDFromOutpoint(vout.TransactionHash, int(vout.Vout))
    if err != nil {
        return name, "", pkscript, err
    }
Severity: Major
Found in daemon/processing/claim.go - About 45 mins to fix

Function SyncName has 7 return statements (exceeds 4 allowed).
Open

func SyncName(r *http.Request) api.Response {

    params := struct {
        Name string
        Key  string
Severity: Major
Found in apiactions/processing.go - About 45 mins to fix

Method chainSyncStatus.alignVout has 7 return statements (exceeds 4 allowed).
Open

func (c *chainSyncStatus) alignVout(v lbrycrd.Vout) error {
    colsToUpdate := make([]string, 0)
    if c.Vout.Value.Float64 != v.Value {
        c.Vout.Value.SetValid(v.Value)
        colsToUpdate = append(colsToUpdate, model.OutputColumns.Value)
Severity: Major
Found in daemon/jobs/chainsync.go - About 45 mins to fix

Function RunBlockProcessing has 7 return statements (exceeds 4 allowed).
Open

func RunBlockProcessing(stopper *stop.Group, height uint64) uint64 {
    defer metrics.Processing(time.Now(), "block")
    defer util.TimeTrack(time.Now(), "runBlockProcessing", "daemonprofile")
    if height == 0 {
        err := processGenesisBlock()
Severity: Major
Found in daemon/processing/block.go - About 45 mins to fix

Function SyncClaimCntInChannel has 7 return statements (exceeds 4 allowed).
Open

func SyncClaimCntInChannel() error {
    latestBlock, err := model.Blocks(qm.Select(model.BlockColumns.Height), qm.OrderBy(model.BlockColumns.Height+" DESC")).OneG()
    if err != nil {
        return errors.Prefix(syncClaimsInChannel, err)
    }
Severity: Major
Found in daemon/jobs/valuesync.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                if err != nil {
                    return err
                }
Severity: Major
Found in daemon/jobs/chainsync.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                if len(value) > 0 {
                    s, err := stake.DecodeSupportBytes(value, global.BlockChainName)
                    if err != nil {
                        return err
                    }
Severity: Major
Found in daemon/jobs/chainsync.go - About 45 mins to fix

Function setClaimAddresses has a Cognitive Complexity of 23 (exceeds 20 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 45 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

Avoid deeply nested control flow statements.
Open

    } else if txscript.IsPayToWitnessScriptHash(script) {
        return p2WSH
    }
Severity: Major
Found in lbrycrd/script.go - About 45 mins to fix

Method chainSyncStatus.processNextBlock has 7 return statements (exceeds 4 allowed).
Open

func (c *chainSyncStatus) processNextBlock() error {
    c.LastHeight = c.LastHeight + 1
    blockHash, err := lbrycrd.LBRYcrdClient.GetBlockHash(c.LastHeight)
    if err != nil {
        return c.recordAndReturnError(c.LastHeight, "lbrycrd-getblockhash", err)
Severity: Major
Found in daemon/jobs/chainsync.go - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

            if err != nil {
                return
            }
Severity: Major
Found in lbrycrd/script.go - About 45 mins to fix

Function AutoUpdateAction has 7 return statements (exceeds 4 allowed).
Open

func AutoUpdateAction(r *http.Request) api.Response {
    err := travis.ValidateSignature(true, r)
    if err != nil {
        logrus.Error(err)
        return api.Response{Error: err, Status: http.StatusBadRequest}
Severity: Major
Found in apiactions/default.go - About 45 mins to fix

Function saveUnknownClaim has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

func saveUnknownClaim(name string, claimid string, isUpdate bool, value []byte, vout model.Output, tx model.Transaction) {
Severity: Minor
Found in daemon/processing/claim.go - About 45 mins to fix
Severity
Category
Status
Source
Language