[#29] container: Return all available containers in List(nil)
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
6abe334676
commit
62448ecdd6
1 changed files with 21 additions and 0 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/engine"
|
"github.com/nspcc-dev/neo-go/pkg/interop/engine"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/util"
|
"github.com/nspcc-dev/neo-go/pkg/interop/util"
|
||||||
|
@ -38,6 +39,8 @@ const (
|
||||||
balanceContractKey = "balanceScriptHash"
|
balanceContractKey = "balanceScriptHash"
|
||||||
netmapContractKey = "netmapScriptHash"
|
netmapContractKey = "netmapScriptHash"
|
||||||
containerFeeKey = "ContainerFee"
|
containerFeeKey = "ContainerFee"
|
||||||
|
|
||||||
|
containerIDSize = 32 // SHA256 size
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -189,6 +192,10 @@ func Owner(containerID []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func List(owner []byte) [][]byte {
|
func List(owner []byte) [][]byte {
|
||||||
|
if len(owner) == 0 {
|
||||||
|
return getAllContainers(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
var list [][]byte
|
var list [][]byte
|
||||||
|
|
||||||
owners := getList(ctx, ownersKey)
|
owners := getList(ctx, ownersKey)
|
||||||
|
@ -385,6 +392,20 @@ func getList(ctx storage.Context, key interface{}) [][]byte {
|
||||||
return [][]byte{}
|
return [][]byte{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAllContainers(ctx storage.Context) [][]byte {
|
||||||
|
var list [][]byte
|
||||||
|
|
||||||
|
it := storage.Find(ctx, []byte{})
|
||||||
|
for iterator.Next(it) {
|
||||||
|
key := iterator.Key(it).([]byte)
|
||||||
|
if len(key) == containerIDSize {
|
||||||
|
list = append(list, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
func getBallots(ctx storage.Context) []ballot {
|
func getBallots(ctx storage.Context) []ballot {
|
||||||
data := storage.Get(ctx, voteKey)
|
data := storage.Get(ctx, voteKey)
|
||||||
if data != nil {
|
if data != nil {
|
||||||
|
|
Loading…
Reference in a new issue