From b6b8542caff9849302490b9524d0bbd75daa3304 Mon Sep 17 00:00:00 2001 From: Anthony De Meulemeester Date: Fri, 2 Mar 2018 16:49:10 +0100 Subject: [PATCH] Compiler (#37) * refactored structs so the scope is not needed anymore + fix passing struct in func arguments. * implemented byte arrays and added runtime tests * Added sc examples in compiler README + added quick nested if test. * Updated README * Changed import paths to interop layer --- VERSION | 2 +- pkg/smartcontract/.keep | 0 pkg/vm/compiler/README.md | 4 ++-- pkg/vm/compiler/tests/runtime_test.go | 12 ++++++------ pkg/vm/compiler/tests/storage_test.go | 2 +- pkg/{ => vm}/smartcontract/runtime/runtime.go | 2 +- pkg/{ => vm}/smartcontract/storage/storage.go | 0 pkg/vm/smartcontract/types/block.go | 9 +++++++++ pkg/vm/syscall.go | 2 +- 9 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 pkg/smartcontract/.keep rename pkg/{ => vm}/smartcontract/runtime/runtime.go (93%) rename pkg/{ => vm}/smartcontract/storage/storage.go (100%) create mode 100644 pkg/vm/smartcontract/types/block.go diff --git a/VERSION b/VERSION index 5a03fb737..885415662 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.20.0 +0.21.0 diff --git a/pkg/smartcontract/.keep b/pkg/smartcontract/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/pkg/vm/compiler/README.md b/pkg/vm/compiler/README.md index e5d4e2949..89bd55f94 100644 --- a/pkg/vm/compiler/README.md +++ b/pkg/vm/compiler/README.md @@ -66,8 +66,8 @@ func Main() bool { package mytoken import ( - "github.com/CityOfZion/neo-go/pkg/smartcontract/runtime" - "github.com/CityOfZion/neo-go/pkg/smartcontract/storage" + "github.com/CityOfZion/neo-go/pkg/vm/smartcontract/runtime" + "github.com/CityOfZion/neo-go/pkg/vm/smartcontract/storage" ) var owner = []byte{0xaf, 0x12, 0xa8, 0x68, 0x7b, 0x14, 0x94, 0x8b, 0xc4, 0xa0, 0x08, 0x12, 0x8a, 0x55, 0x0a, 0x63, 0x69, 0x5b, 0xc1, 0xa5} diff --git a/pkg/vm/compiler/tests/runtime_test.go b/pkg/vm/compiler/tests/runtime_test.go index b1cadced7..498122270 100644 --- a/pkg/vm/compiler/tests/runtime_test.go +++ b/pkg/vm/compiler/tests/runtime_test.go @@ -6,7 +6,7 @@ var runtimeTestCases = []testCase{ ` package foo - import "github.com/CityOfZion/neo-go/pkg/smartcontract/runtime" + import "github.com/CityOfZion/neo-go/pkg/vm/smartcontract/runtime" func Main() bool { runtime.Notify("hello") @@ -20,7 +20,7 @@ var runtimeTestCases = []testCase{ ` package foo - import "github.com/CityOfZion/neo-go/pkg/smartcontract/runtime" + import "github.com/CityOfZion/neo-go/pkg/vm/smartcontract/runtime" func Main() bool { runtime.Log("hello you there!") @@ -34,7 +34,7 @@ var runtimeTestCases = []testCase{ ` package foo - import "github.com/CityOfZion/neo-go/pkg/smartcontract/runtime" + import "github.com/CityOfZion/neo-go/pkg/vm/smartcontract/runtime" func Main() int { t := runtime.GetTime() @@ -48,7 +48,7 @@ var runtimeTestCases = []testCase{ ` package foo - import "github.com/CityOfZion/neo-go/pkg/smartcontract/runtime" + import "github.com/CityOfZion/neo-go/pkg/vm/smartcontract/runtime" func Main() int { trigger := runtime.GetTrigger() @@ -68,7 +68,7 @@ var runtimeTestCases = []testCase{ ` package foo - import "github.com/CityOfZion/neo-go/pkg/smartcontract/runtime" + import "github.com/CityOfZion/neo-go/pkg/vm/smartcontract/runtime" func Main() int { owner := []byte{0xaf, 0x12, 0xa8, 0x68, 0x7b, 0x14, 0x94, 0x8b, 0xc4, 0xa0, 0x08, 0x12, 0x8a, 0x55, 0x0a, 0x63, 0x69, 0x5b, 0xc1, 0xa5} @@ -86,7 +86,7 @@ var runtimeTestCases = []testCase{ ` package foo - import "github.com/CityOfZion/neo-go/pkg/smartcontract/runtime" + import "github.com/CityOfZion/neo-go/pkg/vm/smartcontract/runtime" func Main() int { block := runtime.GetCurrentBlock() diff --git a/pkg/vm/compiler/tests/storage_test.go b/pkg/vm/compiler/tests/storage_test.go index a9de43359..d0d30d5bf 100644 --- a/pkg/vm/compiler/tests/storage_test.go +++ b/pkg/vm/compiler/tests/storage_test.go @@ -6,7 +6,7 @@ var storageTestCases = []testCase{ ` package foo - import "github.com/CityOfZion/neo-go/pkg/smartcontract/storage" + import "github.com/CityOfZion/neo-go/pkg/vm/smartcontract/storage" func Main() int { ctx := storage.GetContext() diff --git a/pkg/smartcontract/runtime/runtime.go b/pkg/vm/smartcontract/runtime/runtime.go similarity index 93% rename from pkg/smartcontract/runtime/runtime.go rename to pkg/vm/smartcontract/runtime/runtime.go index 92aa42e7e..cd3312840 100644 --- a/pkg/smartcontract/runtime/runtime.go +++ b/pkg/vm/smartcontract/runtime/runtime.go @@ -1,6 +1,6 @@ package runtime -import "github.com/CityOfZion/neo-go/pkg/smartcontract/types" +import "github.com/CityOfZion/neo-go/pkg/vm/smartcontract/types" // CheckWitness verifies if the invoker is the owner of the contract. func CheckWitness(hash []byte) bool { diff --git a/pkg/smartcontract/storage/storage.go b/pkg/vm/smartcontract/storage/storage.go similarity index 100% rename from pkg/smartcontract/storage/storage.go rename to pkg/vm/smartcontract/storage/storage.go diff --git a/pkg/vm/smartcontract/types/block.go b/pkg/vm/smartcontract/types/block.go new file mode 100644 index 000000000..928449db6 --- /dev/null +++ b/pkg/vm/smartcontract/types/block.go @@ -0,0 +1,9 @@ +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 +} diff --git a/pkg/vm/syscall.go b/pkg/vm/syscall.go index e5b1bab67..e3416dd3b 100644 --- a/pkg/vm/syscall.go +++ b/pkg/vm/syscall.go @@ -1,6 +1,6 @@ package vm -// Syscalls is a mapping between the syscall function name +// Syscalls are a mapping between the syscall function name // and the registerd VM interop API. var Syscalls = map[string]string{ // Storage API