Skip to content

Commit

Permalink
add some logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kroggen committed Oct 29, 2024
1 parent 0b34675 commit f458255
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions contract/internal_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package contract

import (
"encoding/json"
"log"
"sync"

"github.com/aergoio/aergo/v2/internal/enc/base58"
Expand Down Expand Up @@ -44,14 +43,14 @@ func getCurrentCall(ctx *vmContext, callDepth int32) *InternalCall {
opCall := &ctx.internalOpsCall
for {
if opCall == nil {
log.Printf("no call found at depth %d", depth)
ctrLgr.Printf("no call found at depth %d", depth)
break
}
if depth == callDepth {
return opCall
}
if len(opCall.Operations) == 0 {
log.Printf("no operations found at depth %d", depth)
ctrLgr.Printf("no operations found at depth %d", depth)
break
}
opCall = opCall.Operations[len(opCall.Operations)-1].Call
Expand All @@ -65,6 +64,8 @@ func logOperation(ctx *vmContext, amount string, operation string, args ...strin
return 0
}

ctrLgr.Printf("logOperation: depth: %d, amount: %s, operation: %s, args: %v", ctx.callDepth, amount, operation, args)

opsLock.Lock()
defer opsLock.Unlock()

Expand All @@ -82,7 +83,7 @@ func logOperation(ctx *vmContext, amount string, operation string, args ...strin

opCall := getCurrentCall(ctx, ctx.callDepth)
if opCall == nil {
log.Printf("no call found")
ctrLgr.Printf("no call found")
return 0
}
// add the operation to the list
Expand All @@ -96,6 +97,8 @@ func logOperationResult(ctx *vmContext, operationId int64, result string) {
return
}

ctrLgr.Printf("logOperationResult: depth: %d, operationId: %d, result: %s", ctx.callDepth, operationId, result)

opsLock.Lock()
defer opsLock.Unlock()

Expand All @@ -113,17 +116,19 @@ func logOperationResult(ctx *vmContext, operationId int64, result string) {
}
}

log.Printf("no operation found with ID %d to store result", operationId)
ctrLgr.Printf("no operation found with ID %d to store result", operationId)
}

func logInternalCall(ctx *vmContext, contract string, function string, args []interface{}) error {
if doNotLog(ctx) {
return nil
}

ctrLgr.Printf("logInternalCall: depth: %d, contract: %s, function: %s, args: %s", ctx.callDepth, contract, function, argsToJson(args))

opCall := getCurrentCall(ctx, ctx.callDepth-1)
if opCall == nil {
log.Printf("no call found")
ctrLgr.Printf("no call found")
return nil
}

Expand All @@ -141,6 +146,7 @@ func logInternalCall(ctx *vmContext, contract string, function string, args []in
}

func logFirstCall(ctx *vmContext, contract string, function string, args []interface{}) {
ctrLgr.Printf("logFirstCall: depth: %d, contract: %s, function: %s, args: %s", ctx.callDepth, contract, function, argsToJson(args))
ctx.internalOpsCall.Contract = contract
ctx.internalOpsCall.Function = function
ctx.internalOpsCall.Args = args
Expand All @@ -154,6 +160,17 @@ func logCall(ctx *vmContext, contract string, function string, args []interface{
}
}

func argsToJson(argsList []interface{}) (string) {
if argsList == nil {
return ""
}
args, err := json.Marshal(argsList)
if err != nil {
return ""
}
return string(args)
}

func getInternalOperations(ctx *vmContext) string {
if doNotLog(ctx) {
return ""
Expand All @@ -172,7 +189,7 @@ func getInternalOperations(ctx *vmContext) string {

data, err := json.Marshal(internalOps)
if err != nil {
log.Fatal("Failed to marshal operations:", err)
ctrLgr.Fatal().Err(err).Msg("Failed to marshal operations")
return ""
}

Expand Down

0 comments on commit f458255

Please sign in to comment.