File vm_callback.go
has 1172 lines of code (exceeds 500 allowed). Consider refactoring. Open
package contract
/*
#cgo CFLAGS: -I${SRCDIR}/../libtool/include/luajit-2.1
#cgo LDFLAGS: ${SRCDIR}/../libtool/lib/libluajit-5.1.a -lm
Function luaDeployContract
has a Cognitive Complexity of 48 (exceeds 20 allowed). Consider refactoring. Open
func luaDeployContract(
L *LState,
service C.int,
contract *C.char,
args *C.char,
- 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
Function luaDeployContract
has 136 lines of code (exceeds 50 allowed). Consider refactoring. Open
func luaDeployContract(
L *LState,
service C.int,
contract *C.char,
args *C.char,
Function luaSendAmount
has a Cognitive Complexity of 43 (exceeds 20 allowed). Consider refactoring. Open
func luaSendAmount(L *LState, service C.int, contractId *C.char, amount *C.char) *C.char {
ctx := contexts[service]
if ctx == nil {
return C.CString("[Contract.LuaSendAmount] contract state not found")
- 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
Function luaSendAmount
has 102 lines of code (exceeds 50 allowed). Consider refactoring. Open
func luaSendAmount(L *LState, service C.int, contractId *C.char, amount *C.char) *C.char {
ctx := contexts[service]
if ctx == nil {
return C.CString("[Contract.LuaSendAmount] contract state not found")
Function luaCallContract
has 91 lines of code (exceeds 50 allowed). Consider refactoring. Open
func luaCallContract(L *LState, service C.int, contractId *C.char, fname *C.char, args *C.char,
amount *C.char, gas uint64) (C.int, *C.char) {
fnameStr := C.GoString(fname)
argsStr := C.GoString(args)
Function luaGovernance
has 90 lines of code (exceeds 50 allowed). Consider refactoring. Open
func luaGovernance(L *LState, service C.int, gType C.char, arg *C.char) *C.char {
ctx := contexts[service]
if ctx == nil {
return C.CString("[Contract.LuaGovernance] contract state not found")
Function luaGetDB
has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring. Open
func luaGetDB(L *LState, service C.int, key unsafe.Pointer, keyLen C.int, blkno *C.char) (*C.char, *C.char) {
ctx := contexts[service]
if ctx == nil {
return nil, C.CString("[System.LuaGetDB] contract state not found")
}
- 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
Function luaDeployContract
has 23 return statements (exceeds 4 allowed). Open
func luaDeployContract(
L *LState,
service C.int,
contract *C.char,
args *C.char,
Function luaGovernance
has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring. Open
func luaGovernance(L *LState, service C.int, gType C.char, arg *C.char) *C.char {
ctx := contexts[service]
if ctx == nil {
return C.CString("[Contract.LuaGovernance] contract state not found")
- 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
Function luaDelegateCallContract
has 67 lines of code (exceeds 50 allowed). Consider refactoring. Open
func luaDelegateCallContract(L *LState, service C.int, contractId *C.char,
fname *C.char, args *C.char, gas uint64) (C.int, *C.char) {
contractIdStr := C.GoString(contractId)
fnameStr := C.GoString(fname)
argsStr := C.GoString(args)
Function luaECVerify
has 65 lines of code (exceeds 50 allowed). Consider refactoring. Open
func luaECVerify(L *LState, service C.int, msg *C.char, sig *C.char, addr *C.char) (C.int, *C.char) {
bMsg, err := decodeHex(C.GoString(msg))
if err != nil {
return -1, C.CString("[Contract.LuaEcVerify] invalid message format: " + err.Error())
}
Function luaSendAmount
has 17 return statements (exceeds 4 allowed). Open
func luaSendAmount(L *LState, service C.int, contractId *C.char, amount *C.char) *C.char {
ctx := contexts[service]
if ctx == nil {
return C.CString("[Contract.LuaSendAmount] contract state not found")
Function luaCallContract
has 13 return statements (exceeds 4 allowed). Open
func luaCallContract(L *LState, service C.int, contractId *C.char, fname *C.char, args *C.char,
amount *C.char, gas uint64) (C.int, *C.char) {
fnameStr := C.GoString(fname)
argsStr := C.GoString(args)
Function luaGetDB
has 12 return statements (exceeds 4 allowed). Open
func luaGetDB(L *LState, service C.int, key unsafe.Pointer, keyLen C.int, blkno *C.char) (*C.char, *C.char) {
ctx := contexts[service]
if ctx == nil {
return nil, C.CString("[System.LuaGetDB] contract state not found")
}
Function luaECVerify
has 11 return statements (exceeds 4 allowed). Open
func luaECVerify(L *LState, service C.int, msg *C.char, sig *C.char, addr *C.char) (C.int, *C.char) {
bMsg, err := decodeHex(C.GoString(msg))
if err != nil {
return -1, C.CString("[Contract.LuaEcVerify] invalid message format: " + err.Error())
}
Function luaCallContract
has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring. Open
func luaCallContract(L *LState, service C.int, contractId *C.char, fname *C.char, args *C.char,
amount *C.char, gas uint64) (C.int, *C.char) {
fnameStr := C.GoString(fname)
argsStr := C.GoString(args)
- 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
Function luaECVerify
has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring. Open
func luaECVerify(L *LState, service C.int, msg *C.char, sig *C.char, addr *C.char) (C.int, *C.char) {
bMsg, err := decodeHex(C.GoString(msg))
if err != nil {
return -1, C.CString("[Contract.LuaEcVerify] invalid message format: " + err.Error())
}
- 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
Function luaGetDB
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
func luaGetDB(L *LState, service C.int, key unsafe.Pointer, keyLen C.int, blkno *C.char) (*C.char, *C.char) {
ctx := contexts[service]
if ctx == nil {
return nil, C.CString("[System.LuaGetDB] contract state not found")
}
Function luaGovernance
has 10 return statements (exceeds 4 allowed). Open
func luaGovernance(L *LState, service C.int, gType C.char, arg *C.char) *C.char {
ctx := contexts[service]
if ctx == nil {
return C.CString("[Contract.LuaGovernance] contract state not found")
Function luaDelegateCallContract
has 10 return statements (exceeds 4 allowed). Open
func luaDelegateCallContract(L *LState, service C.int, contractId *C.char,
fname *C.char, args *C.char, gas uint64) (C.int, *C.char) {
contractIdStr := C.GoString(contractId)
fnameStr := C.GoString(fname)
argsStr := C.GoString(args)
Avoid deeply nested control flow statements. Open
if err != nil {
return nil, C.CString("[System.LuaGetDB] failed to get snapshot state variable in contract")
}
Avoid deeply nested control flow statements. Open
if varProof.Inclusion {
if len(varProof.GetValue()) == 0 {
return nil, nil
}
return C.CString(string(varProof.GetValue())), nil
Function luaSetDB
has 5 return statements (exceeds 4 allowed). Open
func luaSetDB(L *LState, service C.int, key unsafe.Pointer, keyLen C.int, value *C.char) *C.char {
ctx := contexts[service]
if ctx == nil {
return C.CString("[System.LuaSetDB] contract state not found")
}
Function luaGetBalance
has 5 return statements (exceeds 4 allowed). Open
func luaGetBalance(L *LState, service C.int, contractId *C.char) (*C.char, *C.char) {
ctx := contexts[service]
if contractId == nil {
return C.CString(ctx.curContract.callState.ctrState.GetBalanceBigInt().String()), nil
}
Function luaDelDB
has 5 return statements (exceeds 4 allowed). 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")
}
Function luaEvent
has 5 return statements (exceeds 4 allowed). Open
func luaEvent(L *LState, service C.int, eventName *C.char, args *C.char) *C.char {
ctx := contexts[service]
if ctx.isQuery == true || ctx.nestedView > 0 {
return C.CString("[Contract.Event] event not permitted in query")
}
Function getAddressNameResolved
has 5 return statements (exceeds 4 allowed). 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 {
Function LuaGetDbHandleSnap
has 5 return statements (exceeds 4 allowed). Open
func LuaGetDbHandleSnap(service C.int, snap *C.char) *C.char {
stateSet := contexts[service]
curContract := stateSet.curContract
callState := curContract.callState
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ctx.traceFile != nil {
_, _ = ctx.traceFile.WriteString(fmt.Sprintf("[GOVERNANCE]aid(%s)\n", aid.String()))
_, _ = ctx.traceFile.WriteString(fmt.Sprintf("snapshot set %d\n", seq))
_, _ = ctx.traceFile.WriteString(fmt.Sprintf("unstaking : %s\n", amountBig.String()))
_, _ = ctx.traceFile.WriteString(fmt.Sprintf("After sender: %s receiver: %s\n",
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 159.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ctx.traceFile != nil {
_, _ = ctx.traceFile.WriteString(fmt.Sprintf("[GOVERNANCE]aid(%s)\n", aid.String()))
_, _ = ctx.traceFile.WriteString(fmt.Sprintf("snapshot set %d\n", seq))
_, _ = ctx.traceFile.WriteString(fmt.Sprintf("staking : %s\n", amountBig.String()))
_, _ = ctx.traceFile.WriteString(fmt.Sprintf("After sender: %s receiver: %s\n",
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 159.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76