mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-24 09:25:21 +00:00
Merge pull request #795 from nspcc-dev/feature/find_storage_example
examples: expand storage smartcontract with find() usage example
This commit is contained in:
commit
d4622768d1
3 changed files with 28 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
package storagecontract
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
)
|
||||
|
||||
|
@ -33,7 +34,20 @@ func Main(operation string, args []interface{}) interface{} {
|
|||
return true
|
||||
}
|
||||
|
||||
// TODO: storage.Find()
|
||||
// Returns an array of key-value pairs with key that matched the passed value
|
||||
if operation == "find" {
|
||||
if checkArgs(args, 1) {
|
||||
value := args[0].([]byte)
|
||||
iter := storage.Find(ctx, value)
|
||||
result := []string{}
|
||||
for iterator.Next(iter) {
|
||||
val := iterator.Value(iter)
|
||||
key := iterator.Key(iter)
|
||||
result = append(result, key.(string)+":"+val.(string))
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -86,6 +86,8 @@ var syscalls = map[string]map[string]string{
|
|||
"Create": "Neo.Iterator.Create",
|
||||
"Key": "Neo.Iterator.Key",
|
||||
"Keys": "Neo.Iterator.Keys",
|
||||
"Next": "Neo.Iterator.Next",
|
||||
"Value": "Neo.Iterator.Value",
|
||||
"Values": "Neo.Iterator.Values",
|
||||
},
|
||||
}
|
||||
|
|
|
@ -22,6 +22,17 @@ func Keys(it Iterator) []interface{} {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Next advances the iterator, return true if it is was successful
|
||||
// and false otherwise.
|
||||
func Next(it Iterator) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Value returns the current iterator value.
|
||||
func Value(it Iterator) interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Values returns the iterator values.
|
||||
func Values(it Iterator) []interface{} {
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue