Documentation
¶
Overview ¶
Package counter implements buffered position-based editing of byte slices.
Package mock provides lightweight contract call tracing and logging
Index ¶
- Variables
- func AddGasConsumption(packageName string, code []byte) ([]byte, error)
- func AddMockEnterExit(packageName string, code []byte) ([]byte, error)
- func ConsumeGas(amount int64)
- func Enter(contract string, function string)
- func Exit(contract string, function string)
- func GetCaller() core.Address
- func GetCurrentContract() core.Address
- func GetGas() int64
- func GetUsedGas() int64
- func InitGas(initialGas int64)
- func RefundGas(amount int64)
- func ResetGas(initialGas int64)
- type Buffer
- type CallTraceGenerator
Constants ¶
This section is empty.
Variables ¶
var ( GasImportPath = "github.com/govm-net/vm/mock" GasPackageNickName = "" GasPackageName = "mock" GasConsumeGasFunc = "ConsumeGas" )
Functions ¶
func AddGasConsumption ¶
AddGasConsumption adds gas consumption tracking to the code
func AddMockEnterExit ¶ added in v0.1.4
AddMockEnterExit adds mock.Enter/Exit to exported functions
func GetCaller ¶
GetCaller returns the address of the contract that called the current contract This correctly handles the case where a contract calls its own functions Returns an empty address if there's no caller (e.g., top-level call)
func GetCurrentContract ¶
GetCurrentContract returns the address of the currently executing contract Returns an empty address if the call stack is empty
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
A Buffer is a queue of edits to apply to a given byte slice.
func NewBuffer ¶
NewBuffer returns a new buffer to accumulate changes to an initial data slice. The returned buffer maintains a reference to the data, so the caller must ensure the data is not modified until after the Buffer is done being used.
type CallTraceGenerator ¶ added in v0.1.5
var DefaultTraceGenerator CallTraceGenerator = func(packageName, funcName string) []ast.Stmt { enterStmt := &ast.ExprStmt{ X: &ast.CallExpr{ Fun: &ast.SelectorExpr{ X: ast.NewIdent(GasPackageName), Sel: ast.NewIdent("Enter"), }, Args: []ast.Expr{ &ast.BasicLit{ Kind: token.STRING, Value: `"` + packageName + `"`, }, &ast.BasicLit{ Kind: token.STRING, Value: `"` + funcName + `"`, }, }, }, } exitStmt := &ast.DeferStmt{ Call: &ast.CallExpr{ Fun: &ast.SelectorExpr{ X: ast.NewIdent(GasPackageName), Sel: ast.NewIdent("Exit"), }, Args: []ast.Expr{ &ast.BasicLit{ Kind: token.STRING, Value: `"` + packageName + `"`, }, &ast.BasicLit{ Kind: token.STRING, Value: `"` + funcName + `"`, }, }, }, } return []ast.Stmt{enterStmt, exitStmt} }