2023-11-07 10:58:16 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/commonclient"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
2023-12-15 14:04:54 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
2023-11-07 10:58:16 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
2023-12-15 14:04:54 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/notary"
|
2023-11-07 10:58:16 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
Client struct {
|
|
|
|
act *actor.Actor
|
|
|
|
acc *wallet.Account
|
|
|
|
contract util.Uint160
|
|
|
|
}
|
|
|
|
|
|
|
|
Options struct {
|
2023-12-15 14:04:54 +00:00
|
|
|
ProxyContract util.Uint160
|
2023-11-07 10:58:16 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
Subject struct {
|
|
|
|
PrimaryKey *keys.PublicKey
|
|
|
|
AdditionalKeys keys.PublicKeys
|
|
|
|
Namespace string
|
|
|
|
Name string
|
|
|
|
KV map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
SubjectExtended struct {
|
|
|
|
PrimaryKey *keys.PublicKey
|
|
|
|
AdditionalKeys keys.PublicKeys
|
|
|
|
Namespace string
|
|
|
|
Name string
|
|
|
|
KV map[string]string
|
|
|
|
Groups []*Group
|
|
|
|
}
|
|
|
|
|
|
|
|
Namespace struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
NamespaceExtended struct {
|
|
|
|
Name string
|
|
|
|
GroupsCount int64
|
|
|
|
SubjectsCount int64
|
|
|
|
}
|
|
|
|
|
|
|
|
Group struct {
|
2023-11-09 08:01:17 +00:00
|
|
|
ID int64
|
2023-11-07 10:58:16 +00:00
|
|
|
Name string
|
|
|
|
Namespace string
|
2023-11-09 08:01:17 +00:00
|
|
|
KV map[string]string
|
2023-11-07 10:58:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GroupExtended struct {
|
2023-11-09 08:01:17 +00:00
|
|
|
ID int64
|
2023-11-07 10:58:16 +00:00
|
|
|
Name string
|
|
|
|
Namespace string
|
2023-11-09 08:01:17 +00:00
|
|
|
KV map[string]string
|
2023-11-07 10:58:16 +00:00
|
|
|
SubjectsCount int64
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-11-09 08:01:17 +00:00
|
|
|
IAMPathKey = "iam-path"
|
|
|
|
IAMARNKey = "iam-arn"
|
|
|
|
IAMCreatedTimeKey = "ctime"
|
|
|
|
IAMModifiedTimeKey = "mtime"
|
2023-11-07 10:58:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const iteratorBatchSize = 100
|
|
|
|
|
|
|
|
const (
|
2023-11-28 08:47:12 +00:00
|
|
|
getAdminMethod = "getAdmin"
|
|
|
|
setAdminMethod = "setAdmin"
|
|
|
|
clearAdminMethod = "clearAdmin"
|
2023-11-07 10:58:16 +00:00
|
|
|
|
|
|
|
versionMethod = "version"
|
|
|
|
|
|
|
|
createSubjectMethod = "createSubject"
|
|
|
|
getSubjectMethod = "getSubject"
|
|
|
|
getSubjectExtendedMethod = "getSubjectExtended"
|
|
|
|
listSubjectsMethod = "listSubjects"
|
|
|
|
addSubjectKeyMethod = "addSubjectKey"
|
|
|
|
removeSubjectKeyMethod = "removeSubjectKey"
|
|
|
|
getSubjectByKeyMethod = "getSubjectByKey"
|
2023-12-07 12:02:57 +00:00
|
|
|
getSubjectByNameMethod = "getSubjectByName"
|
2023-11-07 10:58:16 +00:00
|
|
|
getSubjectKeyByNameMethod = "getSubjectKeyByName"
|
|
|
|
setSubjectKVMethod = "setSubjectKV"
|
|
|
|
setSubjectNameMethod = "setSubjectName"
|
|
|
|
deleteSubjectKVMethod = "deleteSubjectKV"
|
|
|
|
deleteSubjectMethod = "deleteSubject"
|
|
|
|
|
2023-12-07 09:23:18 +00:00
|
|
|
createNamespaceMethod = "createNamespace"
|
|
|
|
getNamespaceMethod = "getNamespace"
|
|
|
|
getNamespaceExtendedMethod = "getNamespaceExtended"
|
|
|
|
listNamespacesMethod = "listNamespaces"
|
|
|
|
listNamespaceSubjectsMethod = "listNamespaceSubjects"
|
2023-11-07 10:58:16 +00:00
|
|
|
|
|
|
|
createGroupMethod = "createGroup"
|
|
|
|
getGroupMethod = "getGroup"
|
|
|
|
getGroupExtendedMethod = "getGroupExtended"
|
2023-11-09 08:01:17 +00:00
|
|
|
getGroupIDByNameMethod = "getGroupIDByName"
|
|
|
|
setGroupNameMethod = "setGroupName"
|
|
|
|
setGroupKVMethod = "setGroupKV"
|
|
|
|
deleteGroupKVMethod = "deleteGroupKV"
|
2023-11-07 10:58:16 +00:00
|
|
|
listGroupsMethod = "listGroups"
|
|
|
|
addSubjectToGroupMethod = "addSubjectToGroup"
|
|
|
|
removeSubjectFromGroupMethod = "removeSubjectFromGroup"
|
|
|
|
listGroupSubjectsMethod = "listGroupSubjects"
|
|
|
|
deleteGroupMethod = "deleteGroup"
|
|
|
|
)
|
|
|
|
|
2023-12-15 14:04:54 +00:00
|
|
|
// New creates a new Client. Options can be empty.
|
|
|
|
func New(ra actor.RPCActor, acc *wallet.Account, contract util.Uint160, opt Options) (*Client, error) {
|
|
|
|
signers := []actor.SignerAccount{{
|
|
|
|
Signer: transaction.Signer{
|
|
|
|
Account: acc.Contract.ScriptHash(),
|
|
|
|
Scopes: transaction.CalledByEntry,
|
|
|
|
},
|
|
|
|
Account: acc,
|
|
|
|
}}
|
|
|
|
|
|
|
|
if !opt.ProxyContract.Equals(util.Uint160{}) {
|
|
|
|
signers = append([]actor.SignerAccount{{
|
|
|
|
Signer: transaction.Signer{
|
|
|
|
Account: opt.ProxyContract,
|
|
|
|
Scopes: transaction.CustomContracts,
|
|
|
|
AllowedContracts: []util.Uint160{contract},
|
|
|
|
},
|
|
|
|
Account: notary.FakeContractAccount(opt.ProxyContract),
|
|
|
|
}}, signers...)
|
|
|
|
}
|
|
|
|
|
|
|
|
act, err := actor.New(ra, signers)
|
2023-11-07 10:58:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("init actor: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Client{
|
|
|
|
act: act,
|
|
|
|
acc: acc,
|
|
|
|
contract: contract,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// StartTx inits transaction.
|
|
|
|
func (c Client) StartTx() *commonclient.Transaction {
|
|
|
|
return commonclient.NewTransaction(c.contract)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendTx sends provided transaction to blockchain.
|
|
|
|
func (c Client) SendTx(txn *commonclient.Transaction) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
txBytes, err := txn.Bytes()
|
|
|
|
if err != nil {
|
|
|
|
return util.Uint256{}, 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.act.SendRun(txBytes)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Version returns version of contract.
|
|
|
|
func (c Client) Version() (int64, error) {
|
|
|
|
return unwrap.Int64(c.act.Call(c.contract, versionMethod))
|
|
|
|
}
|
|
|
|
|
2023-11-28 08:47:12 +00:00
|
|
|
// SetAdmin sets address that can perform write operations on contract.
|
2023-11-07 10:58:16 +00:00
|
|
|
// Must be invoked by committee.
|
2023-11-28 08:47:12 +00:00
|
|
|
func (c Client) SetAdmin(owner util.Uint160) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.SetAdminCall(owner)
|
2023-11-07 10:58:16 +00:00
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
2023-11-28 08:47:12 +00:00
|
|
|
// SetAdminCall provides args for SetAdmin to use in commonclient.Transaction.
|
|
|
|
func (c Client) SetAdminCall(owner util.Uint160) (method string, args []any) {
|
|
|
|
return setAdminMethod, []any{owner}
|
2023-11-07 10:58:16 +00:00
|
|
|
}
|
|
|
|
|
2023-11-28 08:47:12 +00:00
|
|
|
// ClearAdmin removes address that can perform write operations on contract.
|
2023-11-07 10:58:16 +00:00
|
|
|
// Must be invoked by committee.
|
2023-11-28 08:47:12 +00:00
|
|
|
func (c Client) ClearAdmin() (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.ClearAdminCall()
|
2023-11-07 10:58:16 +00:00
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
2023-11-28 08:47:12 +00:00
|
|
|
// ClearAdminCall provides args for ClearAdmin to use in commonclient.Transaction.
|
|
|
|
func (c Client) ClearAdminCall() (method string, args []any) {
|
|
|
|
return clearAdminMethod, nil
|
2023-11-07 10:58:16 +00:00
|
|
|
}
|
|
|
|
|
2023-11-28 08:47:12 +00:00
|
|
|
// GetAdmin returns address that can perform write operations on contract.
|
|
|
|
// Second return values is true iff admin is set.
|
|
|
|
func (c Client) GetAdmin() (util.Uint160, bool, error) {
|
|
|
|
item, err := unwrap.Item(c.act.Call(c.contract, getAdminMethod))
|
|
|
|
if err != nil {
|
|
|
|
return util.Uint160{}, false, err
|
|
|
|
}
|
|
|
|
if item.Value() == nil {
|
|
|
|
return util.Uint160{}, false, nil
|
|
|
|
}
|
|
|
|
bs, err := item.TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return util.Uint160{}, true, err
|
|
|
|
}
|
|
|
|
u, err := util.Uint160DecodeBytesBE(bs)
|
|
|
|
return u, true, err
|
2023-11-07 10:58:16 +00:00
|
|
|
}
|
|
|
|
|
2023-12-07 09:23:18 +00:00
|
|
|
// CreateSubject creates new subject using public key and namespace.
|
2023-11-07 10:58:16 +00:00
|
|
|
// Must be invoked by contract owner.
|
2023-12-07 09:23:18 +00:00
|
|
|
func (c Client) CreateSubject(ns string, key *keys.PublicKey) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.CreateSubjectCall(ns, key)
|
2023-11-07 10:58:16 +00:00
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateSubjectCall provides args for CreateSubject to use in commonclient.Transaction.
|
2023-12-07 09:23:18 +00:00
|
|
|
func (c Client) CreateSubjectCall(ns string, key *keys.PublicKey) (method string, args []any) {
|
|
|
|
return createSubjectMethod, []any{ns, key.Bytes()}
|
2023-11-07 10:58:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetSubject gets subject by address.
|
|
|
|
func (c Client) GetSubject(addr util.Uint160) (*Subject, error) {
|
|
|
|
items, err := unwrap.Array(c.act.Call(c.contract, getSubjectMethod, addr))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseSubject(items)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetSubjectExtended gets extended subject by address.
|
|
|
|
func (c Client) GetSubjectExtended(addr util.Uint160) (*SubjectExtended, error) {
|
|
|
|
items, err := unwrap.Array(c.act.Call(c.contract, getSubjectExtendedMethod, addr))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseSubjectExtended(items)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListSubjects gets all subjects.
|
|
|
|
func (c Client) ListSubjects() ([]util.Uint160, error) {
|
|
|
|
return unwrapArrayOfUint160(commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listSubjectsMethod))
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddSubjectKey adds extra public key to subject.
|
|
|
|
// Must be invoked by contract owner.
|
|
|
|
func (c Client) AddSubjectKey(addr util.Uint160, key *keys.PublicKey) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.AddSubjectKeyCall(addr, key)
|
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddSubjectKeyCall provides args for AddSubjectKey to use in commonclient.Transaction.
|
|
|
|
func (c Client) AddSubjectKeyCall(addr util.Uint160, key *keys.PublicKey) (method string, args []any) {
|
|
|
|
return addSubjectKeyMethod, []any{addr, key.Bytes()}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveSubjectKey removes extra public key from subject.
|
|
|
|
// Must be invoked by contract owner.
|
|
|
|
func (c Client) RemoveSubjectKey(addr util.Uint160, key *keys.PublicKey) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.RemoveSubjectKeyCall(addr, key)
|
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveSubjectKeyCall provides args for RemoveSubjectKey to use in commonclient.Transaction.
|
|
|
|
func (c Client) RemoveSubjectKeyCall(addr util.Uint160, key *keys.PublicKey) (method string, args []any) {
|
|
|
|
return removeSubjectKeyMethod, []any{addr, key.Bytes()}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSubjectKV updates subject kv map.
|
|
|
|
// Must be invoked by contract owner.
|
2023-11-09 08:01:17 +00:00
|
|
|
// You can use some predefined key constants: IAMPathKey, IAMARNKey, IAMCreatedTimeKey, IAMModifiedTimeKey.
|
2023-11-07 10:58:16 +00:00
|
|
|
func (c Client) SetSubjectKV(addr util.Uint160, key, val string) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.SetSubjectKVCall(addr, key, val)
|
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
2023-11-09 08:01:17 +00:00
|
|
|
// SetSubjectKVCall provides args for SetSubjectKV to use in commonclient.Transaction.
|
2023-11-07 10:58:16 +00:00
|
|
|
func (c Client) SetSubjectKVCall(addr util.Uint160, key, val string) (method string, args []any) {
|
|
|
|
return setSubjectKVMethod, []any{addr, key, val}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSubjectName updates subject name.
|
|
|
|
// Must be invoked by contract owner.
|
|
|
|
func (c Client) SetSubjectName(addr util.Uint160, name string) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.SetSubjectNameCall(addr, name)
|
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
2023-11-09 08:01:17 +00:00
|
|
|
// SetSubjectNameCall provides args for SetSubjectName to use in commonclient.Transaction.
|
2023-11-07 10:58:16 +00:00
|
|
|
func (c Client) SetSubjectNameCall(addr util.Uint160, name string) (method string, args []any) {
|
|
|
|
return setSubjectNameMethod, []any{addr, name}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteSubjectKV removes subject kv map.
|
|
|
|
// Must be invoked by contract owner.
|
|
|
|
func (c Client) DeleteSubjectKV(addr util.Uint160, key string) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.DeleteSubjectKVCall(addr, key)
|
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
2023-11-09 08:01:17 +00:00
|
|
|
// DeleteSubjectKVCall provides args for DeleteSubjectKV to use in commonclient.Transaction.
|
2023-11-07 10:58:16 +00:00
|
|
|
func (c Client) DeleteSubjectKVCall(addr util.Uint160, key string) (method string, args []any) {
|
|
|
|
return deleteSubjectKVMethod, []any{addr, key}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetSubjectByKey gets subject by its primary or additional keys.
|
|
|
|
func (c Client) GetSubjectByKey(key *keys.PublicKey) (*Subject, error) {
|
|
|
|
items, err := unwrap.Array(c.act.Call(c.contract, getSubjectByKeyMethod, key.Bytes()))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseSubject(items)
|
|
|
|
}
|
|
|
|
|
2023-12-07 12:02:57 +00:00
|
|
|
// GetSubjectByName gets subject by its name (namespace scope).
|
|
|
|
func (c Client) GetSubjectByName(namespace, subjectName string) (*Subject, error) {
|
|
|
|
items, err := unwrap.Array(c.act.Call(c.contract, getSubjectByNameMethod, namespace, subjectName))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseSubject(items)
|
|
|
|
}
|
|
|
|
|
2023-11-07 10:58:16 +00:00
|
|
|
// GetSubjectKeyByName gets subject public key by its name (namespace scope).
|
|
|
|
func (c Client) GetSubjectKeyByName(namespace, subjectName string) (*keys.PublicKey, error) {
|
|
|
|
return unwrap.PublicKey(c.act.Call(c.contract, getSubjectKeyByNameMethod, namespace, subjectName))
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteSubject delete subject and removes it from related namespaces and groups.
|
|
|
|
// Must be invoked by contract owner.
|
|
|
|
func (c Client) DeleteSubject(addr util.Uint160) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.DeleteSubjectCall(addr)
|
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteSubjectCall provides args for DeleteSubject to use in commonclient.Transaction.
|
|
|
|
func (c Client) DeleteSubjectCall(addr util.Uint160) (method string, args []any) {
|
|
|
|
return deleteSubjectMethod, []any{addr}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateNamespace create new namespace.
|
|
|
|
// Must be invoked by contract owner.
|
|
|
|
func (c Client) CreateNamespace(namespace string) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.CreateNamespaceCall(namespace)
|
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateNamespaceCall provides args for CreateNamespace to use in commonclient.Transaction.
|
|
|
|
func (c Client) CreateNamespaceCall(namespace string) (method string, args []any) {
|
|
|
|
return createNamespaceMethod, []any{namespace}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetNamespace gets namespace.
|
|
|
|
func (c Client) GetNamespace(namespace string) (*Namespace, error) {
|
|
|
|
items, err := unwrap.Array(c.act.Call(c.contract, getNamespaceMethod, namespace))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseNamespace(items)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetNamespaceExtended gets extended namespace.
|
|
|
|
func (c Client) GetNamespaceExtended(namespace string) (*NamespaceExtended, error) {
|
|
|
|
items, err := unwrap.Array(c.act.Call(c.contract, getNamespaceExtendedMethod, namespace))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseNamespaceExtended(items)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListNamespaces gets all namespaces.
|
|
|
|
func (c Client) ListNamespaces() ([]*Namespace, error) {
|
|
|
|
items, err := commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listNamespacesMethod)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseNamespaces(items)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListNamespaceSubjects gets all subjects from namespace.
|
|
|
|
func (c Client) ListNamespaceSubjects(namespace string) ([]util.Uint160, error) {
|
|
|
|
return unwrapArrayOfUint160(commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listNamespaceSubjectsMethod, namespace))
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateGroup creates a new group in specific namespace.
|
|
|
|
// Must be invoked by contract owner.
|
|
|
|
func (c Client) CreateGroup(namespace, group string) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.CreateGroupCall(namespace, group)
|
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateGroupCall provides args for CreateGroup to use in commonclient.Transaction.
|
|
|
|
func (c Client) CreateGroupCall(namespace, group string) (method string, args []any) {
|
|
|
|
return createGroupMethod, []any{namespace, group}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetGroup gets group.
|
2023-11-09 08:01:17 +00:00
|
|
|
func (c Client) GetGroup(namespace string, groupID int64) (*Group, error) {
|
|
|
|
items, err := unwrap.Array(c.act.Call(c.contract, getGroupMethod, namespace, groupID))
|
2023-11-07 10:58:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseGroup(items)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetGroupExtended gets extended group.
|
2023-11-09 08:01:17 +00:00
|
|
|
func (c Client) GetGroupExtended(namespace string, groupID int64) (*GroupExtended, error) {
|
|
|
|
items, err := unwrap.Array(c.act.Call(c.contract, getGroupExtendedMethod, namespace, groupID))
|
2023-11-07 10:58:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseGroupExtended(items)
|
|
|
|
}
|
|
|
|
|
2023-11-09 08:01:17 +00:00
|
|
|
// SetGroupName updates subject name.
|
|
|
|
// Must be invoked by contract owner.
|
|
|
|
func (c Client) SetGroupName(namespace string, groupID int64, name string) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.SetGroupNameCall(namespace, groupID, name)
|
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGroupNameCall provides args for SetGroupName to use in commonclient.Transaction.
|
|
|
|
func (c Client) SetGroupNameCall(namespace string, groupID int64, name string) (method string, args []any) {
|
|
|
|
return setGroupNameMethod, []any{namespace, groupID, name}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGroupKV updates group kv map.
|
|
|
|
// Must be invoked by contract owner.
|
|
|
|
// You can use some predefined key constants: IAMPathKey, IAMARNKey, IAMCreatedTimeKey, IAMModifiedTimeKey.
|
|
|
|
func (c Client) SetGroupKV(namespace string, groupID int64, key, val string) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.SetGroupKVCall(namespace, groupID, key, val)
|
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGroupKVCall provides args for SetGroupKV to use in commonclient.Transaction.
|
|
|
|
func (c Client) SetGroupKVCall(namespace string, groupID int64, key, val string) (method string, args []any) {
|
|
|
|
return setGroupKVMethod, []any{namespace, groupID, key, val}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteGroupKV removes group kv map.
|
|
|
|
// Must be invoked by contract owner.
|
|
|
|
func (c Client) DeleteGroupKV(namespace string, groupID int64, key string) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.DeleteGroupKVCall(namespace, groupID, key)
|
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteGroupKVCall provides args for DeleteGroupKV to use in commonclient.Transaction.
|
|
|
|
func (c Client) DeleteGroupKVCall(namespace string, groupID int64, key string) (method string, args []any) {
|
|
|
|
return deleteGroupKVMethod, []any{namespace, groupID, key}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetGroupIDByName gets group id its name (namespace scope).
|
|
|
|
func (c Client) GetGroupIDByName(namespace, groupName string) (int64, error) {
|
|
|
|
return unwrap.Int64(c.act.Call(c.contract, getGroupIDByNameMethod, namespace, groupName))
|
|
|
|
}
|
|
|
|
|
2023-11-07 10:58:16 +00:00
|
|
|
// ListGroups gets all groups in specific namespace.
|
|
|
|
func (c Client) ListGroups(namespace string) ([]*Group, error) {
|
|
|
|
items, err := commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listGroupsMethod, namespace)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseGroups(items)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddSubjectToGroup adds a new subject to group.
|
|
|
|
// Must be invoked by contract owner.
|
2023-11-09 08:01:17 +00:00
|
|
|
func (c Client) AddSubjectToGroup(addr util.Uint160, groupID int64) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.AddSubjectToGroupCall(addr, groupID)
|
2023-11-07 10:58:16 +00:00
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddSubjectToGroupCall provides args for AddSubjectToGroup to use in commonclient.Transaction.
|
2023-11-09 08:01:17 +00:00
|
|
|
func (c Client) AddSubjectToGroupCall(addr util.Uint160, groupID int64) (method string, args []any) {
|
|
|
|
return addSubjectToGroupMethod, []any{addr, groupID}
|
2023-11-07 10:58:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveSubjectFromGroup removes subject from group.
|
|
|
|
// Must be invoked by contract owner.
|
2023-11-09 08:01:17 +00:00
|
|
|
func (c Client) RemoveSubjectFromGroup(addr util.Uint160, groupID int64) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.RemoveSubjectFromGroupCall(addr, groupID)
|
2023-11-07 10:58:16 +00:00
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveSubjectFromGroupCall provides args for RemoveSubjectFromGroup to use in commonclient.Transaction.
|
2023-11-09 08:01:17 +00:00
|
|
|
func (c Client) RemoveSubjectFromGroupCall(addr util.Uint160, groupID int64) (method string, args []any) {
|
|
|
|
return removeSubjectFromGroupMethod, []any{addr, groupID}
|
2023-11-07 10:58:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListGroupSubjects gets all subjects in specific group.
|
2023-11-09 08:01:17 +00:00
|
|
|
func (c Client) ListGroupSubjects(namespace string, groupID int64) ([]util.Uint160, error) {
|
|
|
|
return unwrapArrayOfUint160(commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listGroupSubjectsMethod, namespace, groupID))
|
2023-11-07 10:58:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteGroup deletes group.
|
|
|
|
// Must be invoked by contract owner.
|
2023-11-09 08:01:17 +00:00
|
|
|
func (c Client) DeleteGroup(namespace string, groupID int64) (tx util.Uint256, vub uint32, err error) {
|
|
|
|
method, args := c.DeleteGroupCall(namespace, groupID)
|
2023-11-07 10:58:16 +00:00
|
|
|
return c.act.SendCall(c.contract, method, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteGroupCall provides args for DeleteGroup to use in commonclient.Transaction.
|
2023-11-09 08:01:17 +00:00
|
|
|
func (c Client) DeleteGroupCall(namespace string, groupID int64) (method string, args []any) {
|
|
|
|
return deleteGroupMethod, []any{namespace, groupID}
|
2023-11-07 10:58:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListNonEmptyNamespaces gets namespaces that contain at least one subject.
|
|
|
|
func (c Client) ListNonEmptyNamespaces() ([]string, error) {
|
|
|
|
namespaces, err := c.ListNamespaces()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var res []string
|
|
|
|
|
|
|
|
for _, namespace := range namespaces {
|
|
|
|
nsExt, err := c.GetNamespaceExtended(namespace.Name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if nsExt.SubjectsCount > 0 {
|
|
|
|
res = append(res, nsExt.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait invokes underlying wait method on actor.Actor.
|
2023-12-07 12:02:57 +00:00
|
|
|
// Notice that "already exists" err value is treated as an error by this routine unlike actor.Waiter.
|
2023-11-07 10:58:16 +00:00
|
|
|
func (c Client) Wait(tx util.Uint256, vub uint32, err error) (*state.AppExecResult, error) {
|
2023-12-07 12:02:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-11-07 10:58:16 +00:00
|
|
|
return c.act.Wait(tx, vub, err)
|
|
|
|
}
|
|
|
|
|
2023-12-07 12:02:57 +00:00
|
|
|
// Waiter returns underlying actor.Waiter.
|
|
|
|
func (c Client) Waiter() actor.Waiter {
|
|
|
|
return c.act
|
|
|
|
}
|
|
|
|
|
2023-11-09 08:01:17 +00:00
|
|
|
// ParseGroupID fetch groupID from stack after creating group method invocation.
|
|
|
|
func (c Client) ParseGroupID(res *state.AppExecResult, err error) (int64, error) {
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return unwrap.Int64(makeResFromAppExec(res))
|
|
|
|
}
|
|
|
|
|
2023-11-07 10:58:16 +00:00
|
|
|
// ListNonEmptyGroups gets groups that contain at least one subject.
|
|
|
|
func (c Client) ListNonEmptyGroups(namespace string) ([]string, error) {
|
|
|
|
groups, err := c.ListGroups(namespace)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var res []string
|
|
|
|
|
|
|
|
for _, group := range groups {
|
2023-11-09 08:01:17 +00:00
|
|
|
groupExt, err := c.GetGroupExtended(namespace, group.ID)
|
2023-11-07 10:58:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if groupExt.SubjectsCount > 0 {
|
|
|
|
res = append(res, groupExt.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func unwrapArrayOfUint160(items []stackitem.Item, err error) ([]util.Uint160, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return unwrap.ArrayOfUint160(makeValidRes(stackitem.NewArray(items)))
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeValidRes(item stackitem.Item) (*result.Invoke, error) {
|
|
|
|
return &result.Invoke{
|
|
|
|
Stack: []stackitem.Item{item},
|
|
|
|
State: vmstate.Halt.String(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-11-09 08:01:17 +00:00
|
|
|
func makeResFromAppExec(res *state.AppExecResult) (*result.Invoke, error) {
|
|
|
|
return &result.Invoke{
|
|
|
|
Stack: res.Stack,
|
|
|
|
State: res.VMState.String(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-11-07 10:58:16 +00:00
|
|
|
func parseSubject(structArr []stackitem.Item) (*Subject, error) {
|
|
|
|
if len(structArr) < 5 {
|
|
|
|
return nil, errors.New("invalid response subject struct")
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
subj Subject
|
|
|
|
)
|
|
|
|
|
|
|
|
subj.PrimaryKey, err = unwrap.PublicKey(makeValidRes(structArr[0]))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !structArr[1].Equals(stackitem.Null{}) {
|
|
|
|
subj.AdditionalKeys, err = unwrap.ArrayOfPublicKeys(makeValidRes(structArr[1]))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !structArr[2].Equals(stackitem.Null{}) {
|
|
|
|
subj.Namespace, err = unwrap.UTF8String(makeValidRes(structArr[2]))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !structArr[2].Equals(stackitem.Null{}) {
|
|
|
|
subj.Name, err = unwrap.UTF8String(makeValidRes(structArr[3]))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
subj.KV, err = parseMap(structArr[4])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &subj, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseSubjectExtended(structArr []stackitem.Item) (*SubjectExtended, error) {
|
|
|
|
if len(structArr) < 6 {
|
|
|
|
return nil, errors.New("invalid response subject extended struct")
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
subj SubjectExtended
|
|
|
|
)
|
|
|
|
|
|
|
|
subj.PrimaryKey, err = unwrap.PublicKey(makeValidRes(structArr[0]))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !structArr[1].Equals(stackitem.Null{}) {
|
|
|
|
subj.AdditionalKeys, err = unwrap.ArrayOfPublicKeys(makeValidRes(structArr[1]))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBytes, err := structArr[2].TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
subj.Namespace = string(nsBytes)
|
|
|
|
|
|
|
|
nameBytes, err := structArr[3].TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
subj.Name = string(nameBytes)
|
|
|
|
|
|
|
|
subj.KV, err = parseMap(structArr[4])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !structArr[5].Equals(stackitem.Null{}) {
|
|
|
|
groupItems, ok := structArr[5].Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("invalid groups field")
|
|
|
|
}
|
|
|
|
|
|
|
|
subj.Groups, err = parseGroups(groupItems)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &subj, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseMap(item stackitem.Item) (map[string]string, error) {
|
|
|
|
if item.Equals(stackitem.Null{}) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
metaMap, err := unwrap.Map(makeValidRes(item))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
meta, ok := metaMap.Value().([]stackitem.MapElement)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("invalid map type")
|
|
|
|
}
|
|
|
|
|
|
|
|
res := make(map[string]string, len(meta))
|
|
|
|
for _, element := range meta {
|
|
|
|
key, err := element.Key.TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
val, err := element.Value.TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
res[string(key)] = string(val)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseNamespace(structArr []stackitem.Item) (*Namespace, error) {
|
|
|
|
if len(structArr) < 1 {
|
|
|
|
return nil, errors.New("invalid response namespace struct")
|
|
|
|
}
|
|
|
|
|
|
|
|
name, err := structArr[0].TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Namespace{Name: string(name)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseNamespaceExtended(structArr []stackitem.Item) (*NamespaceExtended, error) {
|
|
|
|
if len(structArr) < 3 {
|
|
|
|
return nil, errors.New("invalid response namespace extended struct")
|
|
|
|
}
|
|
|
|
|
|
|
|
name, err := structArr[0].TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
groupCount, err := structArr[1].TryInteger()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
subjectCount, err := structArr[2].TryInteger()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &NamespaceExtended{
|
|
|
|
Name: string(name),
|
|
|
|
GroupsCount: groupCount.Int64(),
|
|
|
|
SubjectsCount: subjectCount.Int64(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseNamespaces(items []stackitem.Item) ([]*Namespace, error) {
|
|
|
|
var err error
|
|
|
|
res := make([]*Namespace, len(items))
|
|
|
|
|
|
|
|
for i := 0; i < len(items); i++ {
|
|
|
|
arr, ok := items[i].Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("invalid namespace type")
|
|
|
|
}
|
|
|
|
res[i], err = parseNamespace(arr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseGroup(structArr []stackitem.Item) (*Group, error) {
|
2023-11-09 08:01:17 +00:00
|
|
|
if len(structArr) < 4 {
|
2023-11-07 10:58:16 +00:00
|
|
|
return nil, errors.New("invalid response group struct")
|
|
|
|
}
|
|
|
|
|
2023-11-09 08:01:17 +00:00
|
|
|
groupID, err := structArr[0].TryInteger()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
name, err := structArr[1].TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace, err := structArr[2].TryBytes()
|
2023-11-07 10:58:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-11-09 08:01:17 +00:00
|
|
|
kvs, err := parseMap(structArr[3])
|
2023-11-07 10:58:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Group{
|
2023-11-09 08:01:17 +00:00
|
|
|
ID: groupID.Int64(),
|
2023-11-07 10:58:16 +00:00
|
|
|
Name: string(name),
|
|
|
|
Namespace: string(namespace),
|
2023-11-09 08:01:17 +00:00
|
|
|
KV: kvs,
|
2023-11-07 10:58:16 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseGroupExtended(structArr []stackitem.Item) (*GroupExtended, error) {
|
2023-11-09 08:01:17 +00:00
|
|
|
if len(structArr) < 5 {
|
2023-11-07 10:58:16 +00:00
|
|
|
return nil, errors.New("invalid response group extended struct")
|
|
|
|
}
|
|
|
|
|
2023-11-09 08:01:17 +00:00
|
|
|
groupID, err := structArr[0].TryInteger()
|
2023-11-07 10:58:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-11-09 08:01:17 +00:00
|
|
|
name, err := structArr[1].TryBytes()
|
2023-11-07 10:58:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-11-09 08:01:17 +00:00
|
|
|
namespace, err := structArr[2].TryBytes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
kvs, err := parseMap(structArr[3])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
subjectCount, err := structArr[4].TryInteger()
|
2023-11-07 10:58:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &GroupExtended{
|
2023-11-09 08:01:17 +00:00
|
|
|
ID: groupID.Int64(),
|
2023-11-07 10:58:16 +00:00
|
|
|
Name: string(name),
|
|
|
|
Namespace: string(namespace),
|
2023-11-09 08:01:17 +00:00
|
|
|
KV: kvs,
|
2023-11-07 10:58:16 +00:00
|
|
|
SubjectsCount: subjectCount.Int64(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseGroups(items []stackitem.Item) ([]*Group, error) {
|
|
|
|
var err error
|
|
|
|
res := make([]*Group, len(items))
|
|
|
|
|
|
|
|
for i := 0; i < len(items); i++ {
|
|
|
|
arr, ok := items[i].Value().([]stackitem.Item)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("invalid group type")
|
|
|
|
}
|
|
|
|
res[i], err = parseGroup(arr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|