Showing 1,051 of 1,052 total issues
Method SignVerifier.isExistInMempool
has 5 return statements (exceeds 4 allowed). Open
Open
func (sv *SignVerifier) isExistInMempool(comm component.IComponentRequester, tx *types.Tx) (bool, error) {
if !sv.useMempool {
return false, nil
}
Method ChainService.addBlockInternal
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func (cs *ChainService) addBlockInternal(newBlock *types.Block, usedBState *state.BlockState, peerID types.PeerID) (err error, cache bool) {
if !cs.VerifyTimestamp(newBlock) {
return &ErrBlock{
err: errBlockTimestamp,
block: &types.BlockInfo{
- 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 ChainWorker.Receive
has 5 return statements (exceeds 4 allowed). Open
Open
func (cw *ChainWorker) Receive(context actor.Context) {
var sdb *statedb.StateDB
getAccProof := func(sdb *statedb.StateDB, account, root []byte, compressed bool) (*types.AccountProof, error) {
address, err := getAddressNameResolved(sdb, account)
Method Web3APIv1.GetAccountVotes
has 5 return statements (exceeds 4 allowed). Open
Open
func (api *Web3APIv1) GetAccountVotes() (handler http.Handler, ok bool) {
values, err := url.ParseQuery(api.request.URL.RawQuery)
if err != nil {
return commonResponseHandler(&types.Empty{}, err), true
}
Method ChainDB.ResetWAL
has 5 return statements (exceeds 4 allowed). Open
Open
func (cdb *ChainDB) ResetWAL(hardStateInfo *types.HardStateInfo) error {
if hardStateInfo == nil {
return ErrNilHardState
}
Method vpr.equals
has 5 return statements (exceeds 4 allowed). Open
Open
func (v *vpr) equals(rhs *vpr) bool {
if !reflect.DeepEqual(v.getTotalPower(), rhs.getTotalPower()) {
return false
}
Method PeerMapService.onConnect
has 5 return statements (exceeds 4 allowed). Open
Open
func (pms *PeerMapService) onConnect(s types.Stream) {
defer s.Close()
peerID := s.Conn().RemotePeer()
remoteIP, port, err := types.GetIPPortFromMultiaddr(s.Conn().RemoteMultiaddr())
if err != nil {
Method ChainService.getAccountVote
has 5 return statements (exceeds 4 allowed). Open
Open
func (cs *ChainService) getAccountVote(addr []byte) (*types.AccountVoteInfo, error) {
if cs.GetType() != consensus.ConsensusDPOS {
return nil, ErrNotSupportedConsensus
}
Method Web3APIv1.CommitTX
has 5 return statements (exceeds 4 allowed). Open
Open
func (api *Web3APIv1) CommitTX() (handler http.Handler, ok bool) {
body, err := io.ReadAll(api.request.Body)
if err != nil {
return commonResponseHandler(&types.Empty{}, err), true
}
Method PRPCServer.AddBLEntry
has 5 return statements (exceeds 4 allowed). Open
Open
func (rs *PRPCServer) AddBLEntry(ctx context.Context, entInfo *types.AddEntryParams) (*types.SingleString, error) {
ret := &types.SingleString{}
if len(entInfo.PeerID) == 0 && len(entInfo.Cidr) == 0 && len(entInfo.Address) == 0 {
ret.Value = "at least one flags is required"
Method Core.init
has 5 return statements (exceeds 4 allowed). Open
Open
func (core *Core) init(dbType string, dataDir string, testModeOn bool, forceResetHeight types.BlockNo) error {
// init chaindb
if err := core.cdb.Init(dbType, dataDir); err != nil {
logger.Fatal().Err(err).Msg("failed to initialize chaindb")
return err
Function newVoteCmd
has 5 return statements (exceeds 4 allowed). Open
Open
func newVoteCmd(ctx *SystemContext) (sysCmd, error) {
var (
scs = ctx.scs
err error
Method litetree.restoreRecoveryPoint
has 5 return statements (exceeds 4 allowed). Open
Open
func (db *litetree) restoreRecoveryPoint(stateRp uint64) error {
lastRp := db.recoveryPoint()
if sqlLgr.IsDebugEnabled() {
sqlLgr.Debug().Str("db_name", db.name).
Uint64("state_rp", stateRp).
Function resolveFunction
has 5 return statements (exceeds 4 allowed). Open
Open
func resolveFunction(contractState *statedb.ContractState, bs *state.BlockState, name string, constructor bool) (*types.Function, error) {
abi, err := GetABI(contractState, bs)
if err != nil {
return nil, err
}
Function getAddressNameResolved
has 5 return statements (exceeds 4 allowed). Open
Open
func getAddressNameResolved(account string, bs *state.BlockState) ([]byte, error) {
accountLen := len(account)
if accountLen == types.EncodedAddressLength {
return types.DecodeAddress(account)
} else if accountLen == types.NameLength {
Method FilterInfo.ValidateCheck
has 5 return statements (exceeds 4 allowed). Open
Open
func (fi *FilterInfo) ValidateCheck(to uint64) error {
if fi.ContractAddress == nil {
return errors.New("invalid contractAddress:" + string(fi.ContractAddress))
}
if len(fi.ContractAddress) < AddressLength {
Method executor.commitCalledContract
has 5 return statements (exceeds 4 allowed). Open
Open
func (ce *executor) commitCalledContract() error {
ctx := ce.ctx
if ctx == nil || ctx.callState == nil {
return nil
Function luaDelDB
has 5 return statements (exceeds 4 allowed). Open
Open
func luaDelDB(L *LState, service C.int, key unsafe.Pointer, keyLen C.int) *C.char {
ctx := contexts[service]
if ctx == nil {
return C.CString("[System.LuaDelDB] contract state not found")
}
Method Syncer.handleFinderResult
has 5 return statements (exceeds 4 allowed). Open
Open
func (syncer *Syncer) handleFinderResult(msg *message.FinderResult) error {
logger.Debug().Msg("syncer received finder result message")
if err := chain.TestDebugger.Check(chain.DEBUG_SYNCER_CRASH, 0, nil); err != nil {
chain.TestDebugger.Unset(chain.DEBUG_SYNCER_CRASH)
Function contractFrame
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func contractFrame(l luaTxContract, bs *state.BlockState, cdb contract.ChainAccessor, receiptTx db.Transaction,
run func(s, c *state.AccountState, id types.AccountID, cs *statedb.ContractState) (string, []*types.Event, *big.Int, error)) error {
creatorId := types.ToAccountID(l.sender())
creatorState, err := state.GetAccountState(l.sender(), bs.StateDB)
- 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"