neoneo-go/pkg/vm/interop.go
Anthony De Meulemeester 931388b687
Cross platform virtual machine implementation (#60)
* 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
2018-03-30 18:15:06 +02:00

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)
}