mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 09:29:38 +00:00
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:
parent
3fc25e1431
commit
55966c7e07
5 changed files with 85 additions and 2 deletions
18
examples/iterator/iterator.go
Normal file
18
examples/iterator/iterator.go
Normal 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
|
||||
}
|
29
interop/enumerator/enumerator.go
Normal file
29
interop/enumerator/enumerator.go
Normal 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{}
|
||||
}
|
28
interop/iterator/iterator.go
Normal file
28
interop/iterator/iterator.go
Normal 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
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package storage
|
||||
|
||||
import "github.com/CityOfZion/neo-storm/interop/iterator"
|
||||
|
||||
// Package storage provides function signatures that can be used inside
|
||||
// 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
|
||||
func Delete(ctx Context, key interface{}) {}
|
||||
|
||||
// Find values stored on keys partially matching given key
|
||||
func Find(ctx Context, key interface{}) interface{} { return 0 }
|
||||
// Find returns an iterator.Iterator over the keys that matched the given key.
|
||||
func Find(ctx Context, key interface{}) iterator.Iterator { return iterator.Iterator{} }
|
||||
|
|
|
@ -81,4 +81,10 @@ var syscalls = map[string]map[string]string{
|
|||
"GetEntryScriptHash": "System.ExecutionEngine.GetEntryScriptHash",
|
||||
"GetExecutingScriptHash": "System.ExecutionEngine.GetExecutingScriptHash",
|
||||
},
|
||||
"iterator": {
|
||||
"Create": "Neo.Iterator.Create",
|
||||
"Key": "Neo.Iterator.Key",
|
||||
"Keys": "Neo.Iterator.Keys",
|
||||
"Values": "Neo.Iterator.Values",
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue