aergoio/aergo

View on GitHub
contract/system/validation.go

Summary

Maintainability
C
1 day
Test Coverage
B
82%

Function ValidateSystemTx has a Cognitive Complexity of 48 (exceeds 20 allowed). Consider refactoring.
Open

func ValidateSystemTx(account []byte, txBody *types.TxBody, sender *state.AccountState,
    scs *statedb.ContractState, blockInfo *types.BlockHeaderInfo) (*SystemContext, error) {
    var ci types.CallInfo
    if err := json.Unmarshal(txBody.Payload, &ci); err != nil {
        return nil, types.ErrTxInvalidPayload
Severity: Minor
Found in contract/system/validation.go - About 4 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

Function ValidateSystemTx has 88 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func ValidateSystemTx(account []byte, txBody *types.TxBody, sender *state.AccountState,
    scs *statedb.ContractState, blockInfo *types.BlockHeaderInfo) (*SystemContext, error) {
    var ci types.CallInfo
    if err := json.Unmarshal(txBody.Payload, &ci); err != nil {
        return nil, types.ErrTxInvalidPayload
Severity: Major
Found in contract/system/validation.go - About 2 hrs to fix

    Function ValidateSystemTx has 18 return statements (exceeds 4 allowed).
    Open

    func ValidateSystemTx(account []byte, txBody *types.TxBody, sender *state.AccountState,
        scs *statedb.ContractState, blockInfo *types.BlockHeaderInfo) (*SystemContext, error) {
        var ci types.CallInfo
        if err := json.Unmarshal(txBody.Payload, &ci); err != nil {
            return nil, types.ErrTxInvalidPayload
    Severity: Major
    Found in contract/system/validation.go - About 1 hr to fix

      Function validateForUnstaking has 5 return statements (exceeds 4 allowed).
      Open

      func validateForUnstaking(account []byte, txBody *types.TxBody, scs *statedb.ContractState, blockNo uint64) (*types.Staking, error) {
          staked, err := checkStakingBefore(account, scs)
          if err != nil {
              return nil, types.ErrMustStakeBeforeUnstake
          }
      Severity: Major
      Found in contract/system/validation.go - About 35 mins to fix

        There are no issues that match your filters.

        Category
        Status