Draft of iterator and enumerator (CityOfZion/neo-storm#26)

* Draft of iterator and enumerator

* Added iterator API to the syscall mapping

* Added draft of the enumerator.go file

* Added enumerator interop API.

* Updated the changelog

Imported from CityOfZion/neo-storm (156093318b8612e810965bb1ea26e1babfb46cdd).
This commit is contained in:
Anthony De Meulemeester 2018-08-31 10:23:57 +02:00 committed by Roman Khimov
parent 3fc25e1431
commit 55966c7e07
5 changed files with 85 additions and 2 deletions

View file

@ -0,0 +1,18 @@
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"
)
func Main() bool {
iter := storage.Find(storage.GetContext(), []byte("foo"))
values := iterator.Values(iter)
keys := iterator.Keys(iter)
runtime.Notify("found storage values", values)
runtime.Notify("found storage keys", keys)
return true
}

View file

@ -0,0 +1,29 @@
package enumerator
// Package enumerator provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// TODO: Check enumerator use cases and add them to the examples folder.
// Enumerator stubs a NEO enumerator type.
type Enumerator struct{}
// Create creates a new enumerator from the given items.
func Create(items []interface{}) Enumerator {
return Enumerator{}
}
// Next returns the next item in the iteration.
func Next(e Enumerator) interface{} {
return nil
}
// Value returns the enumerator value.
func Value(e Enumerator) interface{} {
return nil
}
// Concat concats the 2 given enumerators.
func Concat(a, b Enumerator) Enumerator {
return Enumerator{}
}

View file

@ -0,0 +1,28 @@
package iterator
// Package iterator provides function signatures that can be used inside
// smart contracts that are written in the neo-storm framework.
// Iterator stubs a NEO iterator object type.
type Iterator struct{}
// Create creates an iterator from the given items.
func Create(items []interface{}) Iterator {
return Iterator{}
}
// TODO: Better description for this.
// Key returns the iterator key.
func Key(it Iterator) interface{} {
return nil
}
// Keys returns the iterator keys.
func Keys(it Iterator) []interface{} {
return nil
}
// Values returns the iterator values.
func Values(it Iterator) []interface{} {
return nil
}

View file

@ -1,5 +1,7 @@
package storage package storage
import "github.com/CityOfZion/neo-storm/interop/iterator"
// Package storage provides function signatures that can be used inside // 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-storm framework.
@ -18,5 +20,5 @@ func Get(ctx Context, key interface{}) interface{} { return 0 }
// Delete key value pair from storage // Delete key value pair from storage
func Delete(ctx Context, key interface{}) {} func Delete(ctx Context, key interface{}) {}
// Find values stored on keys partially matching given key // Find returns an iterator.Iterator over the keys that matched the given key.
func Find(ctx Context, key interface{}) interface{} { return 0 } func Find(ctx Context, key interface{}) iterator.Iterator { return iterator.Iterator{} }

View file

@ -81,4 +81,10 @@ var syscalls = map[string]map[string]string{
"GetEntryScriptHash": "System.ExecutionEngine.GetEntryScriptHash", "GetEntryScriptHash": "System.ExecutionEngine.GetEntryScriptHash",
"GetExecutingScriptHash": "System.ExecutionEngine.GetExecutingScriptHash", "GetExecutingScriptHash": "System.ExecutionEngine.GetExecutingScriptHash",
}, },
"iterator": {
"Create": "Neo.Iterator.Create",
"Key": "Neo.Iterator.Key",
"Keys": "Neo.Iterator.Keys",
"Values": "Neo.Iterator.Values",
},
} }