931388b687
* Virtual machine for the NEO blockhain. * fixed big.Int numeric operation pointer issue. * added appcall * Added README for vm package. * removed main.go * started VM cli (prompt) integration * added support for printing the stack. * moved cli to vm package * fixed vet errors * updated readme * added more test for VM and fixed some edge cases. * bumped version -> 0.37.0
32 lines
732 B
Go
32 lines
732 B
Go
package vm
|
|
|
|
import "fmt"
|
|
|
|
// InteropFunc allows to hook into the VM.
|
|
type InteropFunc func(vm *VM) error
|
|
|
|
// InteropService
|
|
type InteropService struct {
|
|
mapping map[string]InteropFunc
|
|
}
|
|
|
|
// NewInteropService returns a new InteropService object.
|
|
func NewInteropService() *InteropService {
|
|
return &InteropService{
|
|
mapping: map[string]InteropFunc{},
|
|
}
|
|
}
|
|
|
|
// Register any API to the interop service.
|
|
func (i *InteropService) Register(api string, fun InteropFunc) {
|
|
i.mapping[api] = fun
|
|
}
|
|
|
|
// Call will invoke the service mapped to the given api.
|
|
func (i *InteropService) Call(api []byte, vm *VM) error {
|
|
fun, ok := i.mapping[string(api)]
|
|
if !ok {
|
|
return fmt.Errorf("api (%s) not in interop mapping", api)
|
|
}
|
|
return fun(vm)
|
|
}
|