Showing 1,051 of 1,052 total issues
Method Web3APIv1.GetBlock
has 5 return statements (exceeds 4 allowed). Open
Open
func (api *Web3APIv1) GetBlock() (handler http.Handler, ok bool) {
values, err := url.ParseQuery(api.request.URL.RawQuery)
if err != nil {
return commonResponseHandler(&types.Empty{}, err), true
}
Method Trie.verifyInclusionC
has 5 return statements (exceeds 4 allowed). Open
Open
func (s *Trie) verifyInclusionC(bitmap, key, leafHash []byte, ap [][]byte, length, keyIndex, apIndex int) []byte {
if keyIndex == length {
return leafHash
}
if bitIsSet(key, keyIndex) {
Method Trie.loadCache
has 5 return statements (exceeds 4 allowed). Open
Open
func (s *Trie) loadCache(root []byte, batch [][]byte, iBatch, height int, ch chan<- (error)) {
if height < s.CacheHeightLimit || len(root) == 0 {
ch <- nil
return
}
Function CalculateMerkleTree
has 5 return statements (exceeds 4 allowed). Open
Open
func CalculateMerkleTree(entries []MerkleEntry) [][]byte {
var merkles [][]byte
entriesLen := len(entries)
if entriesLen == 0 {
Method ChainDB.dropBlock
has 5 return statements (exceeds 4 allowed). Open
Open
func (cdb *ChainDB) dropBlock(dropNo types.BlockNo) error {
logger.Info().Uint64("no", dropNo).Msg("drop block")
dbTx := cdb.NewTx()
defer dbTx.Discard()
Method topVoters.dump
has 5 return statements (exceeds 4 allowed). Open
Open
func (tv *topVoters) dump(w io.Writer, topN int) error {
if tv == nil {
fmt.Fprintf(w, "nothing to dump!")
return nil
}
Function getCore
has 5 return statements (exceeds 4 allowed). Open
Open
func getCore(dataDir string) *chain.Core {
// if initpath is feeded, gaurantee initpath is accessible directory
fi, err := os.Stat(dataDir)
if err == nil && !fi.IsDir() {
fmt.Printf("%s is not a directory\n", dataDir)
Method ChainVerifier.VerifyChain
has 5 return statements (exceeds 4 allowed). Open
Open
func (cv *ChainVerifier) VerifyChain() error {
var (
err error
block *types.Block
)
Method ChainService.executeBlock
has 5 return statements (exceeds 4 allowed). Open
Open
func (cs *ChainService) executeBlock(bstate *state.BlockState, block *types.Block) error {
// Caution: block must belong to the main chain.
logger.Debug().Str("hash", block.ID()).Uint64("no", block.GetHeader().BlockNo).Msg("start to execute")
var (
Method ChainService.getStaking
has 5 return statements (exceeds 4 allowed). Open
Open
func (cs *ChainService) getStaking(addr []byte) (*types.Staking, error) {
if cs.GetType() != consensus.ConsensusDPOS {
return nil, ErrNotSupportedConsensus
}
Method Web3APIv1.GetBlockTransactionCount
has 5 return statements (exceeds 4 allowed). Open
Open
func (api *Web3APIv1) GetBlockTransactionCount() (handler http.Handler, ok bool) {
values, err := url.ParseQuery(api.request.URL.RawQuery)
if err != nil {
return commonResponseHandler(&types.Empty{}, err), true
}
Method deployContract.parse
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *deployContract) parse(args string) (string, *big.Int, string, string, string, error) {
splitArgs := context.SplitSpaceAndAccent(args, false)
if len(splitArgs) < 4 {
return "", nil, "", "", "", fmt.Errorf("need 4 arguments. usage: %s", c.Usage())
}
Function runQueryCmd
has 5 return statements (exceeds 4 allowed). Open
Open
func runQueryCmd(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
contract, err := types.DecodeAddress(args[0])
if err != nil {
Function execVote
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func execVote(cmd *cobra.Command, args []string) {
account, err := types.DecodeAddress(address)
if err != nil {
cmd.Printf("Failed: %s\n", err.Error())
return
- Read upRead up
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
Method Web3APIv1.GetState
has 5 return statements (exceeds 4 allowed). Open
Open
func (api *Web3APIv1) GetState() (handler http.Handler, ok bool) {
values, err := url.ParseQuery(api.request.URL.RawQuery)
if err != nil {
return commonResponseHandler(&types.Empty{}, err), true
}
Method ChainService.listEvents
has 5 return statements (exceeds 4 allowed). Open
Open
func (cs *ChainService) listEvents(filter *types.FilterInfo) ([]*types.Event, error) {
from := filter.Blockfrom
to := filter.Blockto
if filter.RecentBlockCnt > 0 {
Method Web3APIv1.GetBlockMetadata
has 5 return statements (exceeds 4 allowed). Open
Open
func (api *Web3APIv1) GetBlockMetadata() (handler http.Handler, ok bool) {
values, err := url.ParseQuery(api.request.URL.RawQuery)
if err != nil {
return commonResponseHandler(&types.Empty{}, err), true
}
Function execSendTX
has 5 return statements (exceeds 4 allowed). Open
Open
func execSendTX(cmd *cobra.Command, args []string) error {
account, err := types.DecodeAddress(from)
if err != nil {
return errors.New("Wrong address in --from flag\n" + err.Error())
}
Function validateForUnstaking
has 5 return statements (exceeds 4 allowed). Open
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
}
Function newVprCmd
has 5 return statements (exceeds 4 allowed). Open
Open
func newVprCmd(ctx *SystemContext, vr *VoteResult) *vprCmd {
cmd := &vprCmd{SystemContext: ctx, voteResult: vr}
if vprLogger.IsDebugEnabled() {
vprLogger.Debug().