contract/vm_dummy/vm_dummy.go
File vm_dummy.go
has 599 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
package vm_dummy
// helper functions
import (
"context"
Function contractFrame
has 71 lines of code (exceeds 50 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)
Function contractFrame
has 11 return statements (exceeds 4 allowed). 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)
Method DummyChain.Query
has 7 return statements (exceeds 4 allowed). Open
Open
func (bc *DummyChain) Query(contract_name, queryInfo, expectedErr string, expectedRvs ...string) error {
cState, err := statedb.OpenContractStateAccount(contract.StrHash(contract_name), bc.sdb.GetStateDB())
if err != nil {
return err
}
Method luaTxCall.run
has 7 return statements (exceeds 4 allowed). Open
Open
func (l *luaTxCall) run(execCtx context.Context, bs *state.BlockState, bc *DummyChain, bi *types.BlockHeaderInfo, receiptTx db.Transaction) error {
err := contractFrame(l, bs, bc, receiptTx,
func(sender, contractV *state.AccountState, contractId types.AccountID, eContractState *statedb.ContractState) (string, []*types.Event, *big.Int, error) {
ctx := contract.NewVmContext(execCtx, bs, bc, sender, contractV, eContractState, sender.ID(), l.Hash(), bi, "", true, false, contractV.State().SqlRecoveryPoint, contract.BlockFactory, l.amount(), math.MaxUint64, l.feeDelegate)
Method DummyChain.QueryOnly
has 6 return statements (exceeds 4 allowed). Open
Open
func (bc *DummyChain) QueryOnly(contract_name, queryInfo string, expectedErr string) (bool, string, error) {
cState, err := statedb.OpenContractStateAccount(contract.StrHash(contract_name), bc.sdb.GetStateDB())
if err != nil {
return false, "", err
}
Method luaTxSend.run
has 5 return statements (exceeds 4 allowed). Open
Open
func (l *luaTxSend) run(execCtx context.Context, bs *state.BlockState, bc *DummyChain, bi *types.BlockHeaderInfo, receiptTx db.Transaction) error {
senderID := types.ToAccountID(l.sender)
receiverID := types.ToAccountID(l.receiver)
if senderID == receiverID {
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"