mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 03:41:34 +00:00
examples: expand storage smartcontract with find() usage example
closes #364
This commit is contained in:
parent
37cb60a0b5
commit
0a5298b3ee
1 changed files with 15 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
package storagecontract
|
package storagecontract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,7 +34,20 @@ func Main(operation string, args []interface{}) interface{} {
|
||||||
return true
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue