interop: move into pkg/interop, replace pkg/vm/api

neo-storm has developed more wrappers for syscall APIs, so they can and should
be used as a drop-in replacement for pkg/vm/api. Moving it out of vm, as it's
not exactly related to the VM itself.
This commit is contained in:
Roman Khimov 2019-08-15 19:41:51 +03:00
parent 7cd91610df
commit a1e3655560
38 changed files with 58 additions and 281 deletions

View file

@ -28,7 +28,7 @@ var (
// %s is parsed to be the smartContractName
smartContractTmpl = `package %s
import "github.com/CityOfZion/neo-storm/interop/runtime"
import "github.com/CityOfZion/neo-go/pkg/interop/runtime"
func Main(op string, args []interface{}) {
runtime.Notify("Hello world!")

View file

@ -1,8 +1,8 @@
package engine_contract
import (
"github.com/CityOfZion/neo-storm/interop/engine"
"github.com/CityOfZion/neo-storm/interop/runtime"
"github.com/CityOfZion/neo-go/pkg/interop/engine"
"github.com/CityOfZion/neo-go/pkg/interop/runtime"
)
func Main() bool {

View file

@ -1,9 +1,9 @@
package iterator_contract
import (
"github.com/CityOfZion/neo-storm/interop/iterator"
"github.com/CityOfZion/neo-storm/interop/runtime"
"github.com/CityOfZion/neo-storm/interop/storage"
"github.com/CityOfZion/neo-go/pkg/interop/iterator"
"github.com/CityOfZion/neo-go/pkg/interop/runtime"
"github.com/CityOfZion/neo-go/pkg/interop/storage"
)
func Main() bool {

View file

@ -1,8 +1,8 @@
package runtime_contract
import (
"github.com/CityOfZion/neo-storm/interop/runtime"
"github.com/CityOfZion/neo-storm/interop/util"
"github.com/CityOfZion/neo-go/pkg/interop/runtime"
"github.com/CityOfZion/neo-go/pkg/interop/util"
)
// Check if the invoker of the contract is the specified owner

View file

@ -1,7 +1,7 @@
package storage_contract
import (
"github.com/CityOfZion/neo-storm/interop/storage"
"github.com/CityOfZion/neo-go/pkg/interop/storage"
)
func Main(operation string, args []interface{}) interface{} {

View file

@ -1,9 +1,9 @@
package tokensale
import (
"github.com/CityOfZion/neo-go/pkg/vm/api/runtime"
"github.com/CityOfZion/neo-go/pkg/vm/api/storage"
"github.com/CityOfZion/neo-go/pkg/vm/api/util"
"github.com/CityOfZion/neo-go/pkg/interop/runtime"
"github.com/CityOfZion/neo-go/pkg/interop/storage"
"github.com/CityOfZion/neo-go/pkg/interop/util"
)
const (

View file

@ -1,10 +1,10 @@
package nep5
import (
"github.com/CityOfZion/neo-storm/interop/engine"
"github.com/CityOfZion/neo-storm/interop/runtime"
"github.com/CityOfZion/neo-storm/interop/storage"
"github.com/CityOfZion/neo-storm/interop/util"
"github.com/CityOfZion/neo-go/pkg/interop/engine"
"github.com/CityOfZion/neo-go/pkg/interop/runtime"
"github.com/CityOfZion/neo-go/pkg/interop/storage"
"github.com/CityOfZion/neo-go/pkg/interop/util"
)
// Token holds all token info

View file

@ -1,10 +1,10 @@
package token_contract
import (
"github.com/CityOfZion/neo-storm/examples/token/nep5"
"github.com/CityOfZion/neo-go/examples/token/nep5"
"github.com/CityOfZion/neo-storm/interop/storage"
"github.com/CityOfZion/neo-storm/interop/util"
"github.com/CityOfZion/neo-go/pkg/interop/storage"
"github.com/CityOfZion/neo-go/pkg/interop/util"
)
const (

View file

@ -1,7 +1,7 @@
package account
// Package account provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// Account stubs a NEO account type.
type Account struct{}

View file

@ -1,7 +1,7 @@
package asset
// Package asset provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// Asset stubs a NEO asset type.
type Asset struct{}

View file

@ -1,7 +1,7 @@
package attribute
// Package attribute provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// Attribute stubs a NEO transaction attribute type.
type Attribute struct{}

View file

@ -1,9 +1,9 @@
package block
import "github.com/CityOfZion/neo-storm/interop/transaction"
import "github.com/CityOfZion/neo-go/pkg/interop/transaction"
// Package block provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// Block stubs a NEO block type.
type Block struct{}

View file

@ -1,16 +1,16 @@
package blockchain
import (
"github.com/CityOfZion/neo-storm/interop/account"
"github.com/CityOfZion/neo-storm/interop/asset"
"github.com/CityOfZion/neo-storm/interop/block"
"github.com/CityOfZion/neo-storm/interop/contract"
"github.com/CityOfZion/neo-storm/interop/header"
"github.com/CityOfZion/neo-storm/interop/transaction"
"github.com/CityOfZion/neo-go/pkg/interop/account"
"github.com/CityOfZion/neo-go/pkg/interop/asset"
"github.com/CityOfZion/neo-go/pkg/interop/block"
"github.com/CityOfZion/neo-go/pkg/interop/contract"
"github.com/CityOfZion/neo-go/pkg/interop/header"
"github.com/CityOfZion/neo-go/pkg/interop/transaction"
)
// Package blockchain provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// GetHeight returns the height of te block recorded in the current execution scope.
func GetHeight() int {

View file

@ -1,9 +1,9 @@
package contract
import "github.com/CityOfZion/neo-storm/interop/storage"
import "github.com/CityOfZion/neo-go/pkg/interop/storage"
// Package contract provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// Contract stubs a NEO contract type.
type Contract struct{}

View file

@ -1,7 +1,7 @@
package crypto
// Package crypto provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// SHA1 computes the sha1 hash of b.
func SHA1(b []byte) []byte {

View file

@ -1,9 +1,9 @@
package engine
import "github.com/CityOfZion/neo-storm/interop/transaction"
import "github.com/CityOfZion/neo-go/pkg/interop/transaction"
// Package engine provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// GetScriptContainer returns the transaction that is in the execution context.
func GetScriptContainer() transaction.Transaction {

View file

@ -1,7 +1,7 @@
package enumerator
// Package enumerator provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// TODO: Check enumerator use cases and add them to the examples folder.

View file

@ -1,7 +1,7 @@
package header
// Package header provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// Header stubs a NEO block header type.
type Header struct{}

View file

@ -1,7 +1,7 @@
package input
// Package input provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// Input stubs the input of a NEO transaction.
type Input struct{}

View file

@ -1,7 +1,7 @@
package iterator
// Package iterator provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// Iterator stubs a NEO iterator object type.
type Iterator struct{}

View file

@ -1,7 +1,7 @@
package output
// Package output provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// Output stubs the output of a NEO transaction.
type Output struct{}

View file

@ -1,7 +1,7 @@
package runtime
// Package runtime provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// CheckWitness verifies if the given hash is the invoker of the contract.
func CheckWitness(hash []byte) bool {

View file

@ -1,9 +1,9 @@
package storage
import "github.com/CityOfZion/neo-storm/interop/iterator"
import "github.com/CityOfZion/neo-go/pkg/interop/iterator"
// Package storage provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// Context represents the storage context
type Context struct{}

View file

@ -1,13 +1,13 @@
package transaction
import (
"github.com/CityOfZion/neo-storm/interop/attribute"
"github.com/CityOfZion/neo-storm/interop/input"
"github.com/CityOfZion/neo-storm/interop/output"
"github.com/CityOfZion/neo-go/pkg/interop/attribute"
"github.com/CityOfZion/neo-go/pkg/interop/input"
"github.com/CityOfZion/neo-go/pkg/interop/output"
)
// Package transaction provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// smart contracts that are written in the neo-go framework.
// Transaction stubs a NEO transaction type.
type Transaction struct{}

View file

@ -117,7 +117,7 @@ You can invoke smart contracts with arguments. Take the following ***roll the di
```
package rollthedice
import "github.com/CityOfZion/neo-go/pkg/vm/api/runtime"
import "github.com/CityOfZion/neo-go/pkg/interop/runtime"
func Main(method string, args []interface{}) int {
if method == "rollDice" {

View file

@ -1,31 +0,0 @@
package asset
import "github.com/CityOfZion/neo-go/pkg/core"
// GetAssetID returns the id of the given asset.
func GetAssetID(asset *core.AssetState) []byte { return nil }
// TODO: Verify if we need to return a uint8 here.
// GetAssetType returns the type of the given asset.
func GetAssetType(asset *core.AssetState) uint8 { return 0x00 }
// GetAmount returns the amount of the given asset.
func GetAmount(asset *core.AssetState) uint64 { return 0 }
// GetAvailable returns the available amount of the given asset.
func GetAvailable(asset *core.AssetState) uint64 { return 0 }
// GetPrecision returns the precision the given asset.
func GetPrecision(asset *core.AssetState) uint8 { return 0 }
// GetOwner returns the owner the given asset.
func GetOwner(asset *core.AssetState) []byte { return nil }
// GetIssuer returns the issuer the given asset.
func GetIssuer(asset *core.AssetState) []byte { return nil }
// Create a new asset specified by the given parameters.
func Create(typ uint8, name string, amount uint64, owner, admin, issuer []byte) {}
// Renew the given asset for the given x years.
func Renew(asset *core.AssetState, years uint32) {}

View file

@ -1,41 +0,0 @@
package block
import (
"github.com/CityOfZion/neo-go/pkg/core"
"github.com/CityOfZion/neo-go/pkg/core/transaction"
)
// GetTransactionCount returns the number of transactions that are recorded in
// the given block.
func GetTransactionCount(block *core.Block) int { return 0 }
// GetTransactions returns a list of transactions that are recorded in this block.
func GetTransactions(block *core.Block) []*transaction.Transaction { return nil }
// GetIndex returns the index of the given block.
func GetIndex(block *core.Block) uint32 { return 0 }
// GetHash returns the hash of the given block.
func GetHash(block *core.Block) []byte { return nil }
// GetHash returns the version of the given block.
func GetVersion(block *core.Block) uint32 { return 0 }
// GetHash returns the previous hash of the given block.
func GetPrevHash(block *core.Block) []byte { return nil }
// GetHash returns the merkle root of the given block.
func GetMerkleRoot(block *core.Block) []byte { return nil }
// GetHash returns the timestamp of the given block.
func GetTimestamp(block *core.Block) uint32 { return 0 }
// GetHash returns the next validator address of the given block.
func GetNextConsensus(block *core.Block) []byte { return nil }
// GetConsensusData returns the consensus data of the given block.
func GetConsensusData(block *core.Block) uint64 { return 0 }
// GetTransaction returns a specific transaction that is recorded in the given block
// by the given index.
func GetTransaction(block *core.Block, index int) *transaction.Transaction { return nil }

View file

@ -1,21 +0,0 @@
package crypto
// SHA1 computes the sha1 hash of b.
func SHA1(b []byte) []byte {
return nil
}
// SHA256 computes the sha256 hash of b.
func SHA256(b []byte) []byte {
return nil
}
// Hash160 ..
func Hash160(b []byte) []byte {
return nil
}
// Hash256 ..
func Hash256(b []byte) []byte {
return nil
}

View file

@ -1,24 +0,0 @@
package header
import "github.com/CityOfZion/neo-go/pkg/core"
// GetIndex returns the index of the given header.
func GetIndex(header *core.Header) uint32 { return 0 }
// GetHash returns the hash of the given header.
func GetHash(header *core.Header) []byte { return nil }
// GetHash returns the version of the given header.
func GetVersion(header *core.Header) uint32 { return 0 }
// GetHash returns the previous hash of the given header.
func GetPrevHash(header *core.Header) []byte { return nil }
// GetHash returns the merkle root of the given header.
func GetMerkleRoot(header *core.Header) []byte { return nil }
// GetHash returns the timestamp of the given header.
func GetTimestamp(header *core.Header) uint32 { return 0 }
// GetHash returns the next validator address of the given header.
func GetNextConsensus(header *core.Header) []byte { return nil }

View file

@ -1,45 +0,0 @@
package runtime
// CheckWitness verifies if the invoker is the owner of the contract.
func CheckWitness(hash []byte) bool {
return true
}
// GetTime returns the timestamp of the most recent block.
func GetTime() int {
return 0
}
// Notify an event to the VM.
func Notify(arg interface{}) int {
return 0
}
// Log instructs the VM to log the given message.
func Log(message string) {}
// Application returns the application trigger type.
func Application() byte {
return 0x10
}
// Verification returns the verification trigger type.
func Verification() byte {
return 0x00
}
// GetTrigger return the current trigger type. The return in this function
// doesn't really mather, this is just an interop placeholder.
func GetTrigger() interface{} {
return 0
}
// Serialize serializes and item into a bytearray.
func Serialize(item interface{}) []byte {
return nil
}
// Deserialize an item from a bytearray.
func Deserialize(b []byte) interface{} {
return nil
}

View file

@ -1,19 +0,0 @@
package storage
// Context represents the storage context.
type Context interface{}
// GetContext returns the storage context.
func GetContext() interface{} { return nil }
// Put stores a value in to the storage.
func Put(ctx interface{}, key interface{}, value interface{}) {}
// Get returns the value from the storage.
func Get(ctx interface{}, key interface{}) interface{} { return 0 }
// Delete removes a stored key value pair.
func Delete(ctx interface{}, key interface{}) {}
// Find entries somewhat matching the given key.
func Find(ctx interface{}, key interface{}) interface{} { return 0 }

View file

@ -1,27 +0,0 @@
package transaction
import "github.com/CityOfZion/neo-go/pkg/core/transaction"
// GetType returns the type of the given transaction.
// TODO: Double check if the type returned should be of type uint8.
func GetType(tx *transaction.Transaction) uint8 { return 0x00 }
// GetTXHash returns the hash of the given transaction.
func GetTXHash(tx *transaction.Transaction) []byte { return nil }
// GetAttributes returns the attributes of the given transaction.
func GetAttributes(tx *transaction.Transaction) []*transaction.Attribute { return nil }
// GetInputs returns the inputs of the given transaction.
func GetInputs(tx *transaction.Transaction) []*transaction.Input { return nil }
// GetOutputs returns the outputs of the given transaction.
func GetOutputs(tx *transaction.Transaction) []*transaction.Output { return nil }
// TODO: What does this return as data type?
// GetReferences returns the outputs of the given transaction.
// func GetReferences(tx *transaction.Transaction) { }
// TODO: What does this return as data type?
// GetUnspentCoins returns the unspent coins of the given transaction.
// func GetUnspentCoins(tx *transaction.Transaction) { }

View file

@ -1,9 +0,0 @@
package types
// Block represents a block in the blockchain.
type Block struct{}
// Index returns the height of the block.
func (b Block) Index() int {
return 0
}

View file

@ -1,6 +0,0 @@
package util
// FromAddress returns the underlying bytes from the given address string.
func FromAddress(address string) []byte {
return nil
}

View file

@ -118,8 +118,8 @@ Will output something like:
package mycontract
import (
"github.com/CityOfZion/neo-go/pkg/vm/api/runtime"
"github.com/CityOfZion/neo-go/pkg/vm/api/util"
"github.com/CityOfZion/neo-go/pkg/interop/runtime"
"github.com/CityOfZion/neo-go/pkg/interop/util"
)
var owner = util.FromAddress("AJX1jGfj3qPBbpAKjY527nPbnrnvSx9nCg")
@ -142,8 +142,8 @@ func Main() bool {
package mytoken
import (
"github.com/CityOfZion/neo-go/pkg/vm/api/runtime"
"github.com/CityOfZion/neo-go/pkg/vm/api/storage"
"github.com/CityOfZion/neo-go/pkg/interop/runtime"
"github.com/CityOfZion/neo-go/pkg/interop/storage"
)
var owner = util.FromAddress("AJX1jGfj3qPBbpAKjY527nPbnrnvSx9nCg")

View file

@ -8,7 +8,7 @@ func TestStoragePutGet(t *testing.T) {
src := `
package foo
import "github.com/CityOfZion/neo-go/pkg/vm/api/storage"
import "github.com/CityOfZion/neo-go/pkg/interop/storage"
func Main() string {
ctx := storage.GetContext()

View file

@ -8,7 +8,7 @@ func TestSHA256(t *testing.T) {
src := `
package foo
import (
"github.com/CityOfZion/neo-go/pkg/vm/api/crypto"
"github.com/CityOfZion/neo-go/pkg/interop/crypto"
)
func Main() []byte {
src := []byte{0x97}
@ -23,7 +23,7 @@ func TestSHA1(t *testing.T) {
src := `
package foo
import (
"github.com/CityOfZion/neo-go/pkg/vm/api/crypto"
"github.com/CityOfZion/neo-go/pkg/interop/crypto"
)
func Main() []byte {
src := []byte{0x97}
@ -38,7 +38,7 @@ func TestHash160(t *testing.T) {
src := `
package foo
import (
"github.com/CityOfZion/neo-go/pkg/vm/api/crypto"
"github.com/CityOfZion/neo-go/pkg/interop/crypto"
)
func Main() []byte {
src := []byte{0x97}
@ -53,7 +53,7 @@ func TestHash256(t *testing.T) {
src := `
package foo
import (
"github.com/CityOfZion/neo-go/pkg/vm/api/crypto"
"github.com/CityOfZion/neo-go/pkg/interop/crypto"
)
func Main() []byte {
src := []byte{0x97}