Small fixes for frostfsid, policy contracts #55

Merged
fyrchik merged 9 commits from fyrchik/frostfs-contract:frostfsid-admin into master 2024-09-04 19:51:17 +00:00
10 changed files with 339 additions and 478 deletions

View file

@ -28,7 +28,7 @@ nns_sc = nns
all_sc = $(alphabet_sc) $(morph_sc) $(mainnet_sc) $(nns_sc)
define sc_template
$(2)$(1)/$(1)_contract.nef: $(2)$(1)/$(1)_contract.go
$(2)$(1)/$(1)_contract.nef: $(2)$(1)/$(1)_contract.go $(2)$(1)/config.yml
$(NEOGO) contract compile -i $(2)$(1) -c $(if $(2),$(2),$(1)/)config.yml -m $(2)$(1)/config.json -o $(2)$(1)/$(1)_contract.nef
$(if $(2),$(2)$(1)/$(1)_contract.go: alphabet/alphabet.go alphabet/alphabet.tpl

View file

@ -82,9 +82,9 @@ const (
const iteratorBatchSize = 100
const (
addOwnerMethod = "addOwner"
deleteOwnerMethod = "deleteOwner"
listOwnersMethod = "listOwners"
getAdminMethod = "getAdmin"
setAdminMethod = "setAdmin"
clearAdminMethod = "clearAdmin"
versionMethod = "version"
@ -157,33 +157,46 @@ func (c Client) Version() (int64, error) {
return unwrap.Int64(c.act.Call(c.contract, versionMethod))
}
// AddOwner adds new address that can perform write operations on contract.
// SetAdmin sets address that can perform write operations on contract.
// Must be invoked by committee.
func (c Client) AddOwner(owner util.Uint160) (tx util.Uint256, vub uint32, err error) {
method, args := c.AddOwnerCall(owner)
func (c Client) SetAdmin(owner util.Uint160) (tx util.Uint256, vub uint32, err error) {
method, args := c.SetAdminCall(owner)
return c.act.SendCall(c.contract, method, args...)
}
// AddOwnerCall provides args for AddOwner to use in commonclient.Transaction.
func (c Client) AddOwnerCall(owner util.Uint160) (method string, args []any) {
return addOwnerMethod, []any{owner}
// 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}
}
// DeleteOwner removes address from list of that can perform write operations on contract.
// ClearAdmin removes address that can perform write operations on contract.
// Must be invoked by committee.
func (c Client) DeleteOwner(owner util.Uint160) (tx util.Uint256, vub uint32, err error) {
method, args := c.DeleteOwnerCall(owner)
func (c Client) ClearAdmin() (tx util.Uint256, vub uint32, err error) {
method, args := c.ClearAdminCall()
return c.act.SendCall(c.contract, method, args...)
}
// DeleteOwnerCall provides args for DeleteOwner to use in commonclient.Transaction.
func (c Client) DeleteOwnerCall(owner util.Uint160) (method string, args []any) {
return deleteOwnerMethod, []any{owner}
// ClearAdminCall provides args for ClearAdmin to use in commonclient.Transaction.
func (c Client) ClearAdminCall() (method string, args []any) {
return clearAdminMethod, nil
}
// ListOwners returns list of address that can perform write operations on contract.
func (c Client) ListOwners() ([]util.Uint160, error) {
return unwrapArrayOfUint160(commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listOwnersMethod))
// 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
}
// CreateSubject creates new subject using public key.

View file

@ -1,5 +1,21 @@
name: "Identity"
safemethods: ["version"]
safemethods:
- "getAdmin"
- "getGroup"
- "getGroupExtended"
- "getGroupIDByName"
- "getNamespace"
- "getNamespaceExtended"
- "getSubject"
- "getSubjectExtended"
- "getSubjectByKey"
- "getSubjectKeyByName"
- "listGroups"
- "listGroupSubjects"
- "listNamespaces"
- "listNamespaceSubjects"
- "listSubjects"
- "version"
permissions:
- methods: ["update"]
events:

View file

@ -58,7 +58,7 @@ type (
)
const (
ownerKeysPrefix = 'o'
adminKey = 'o'
subjectKeysPrefix = 's'
additionalKeysPrefix = 'a'
namespaceKeysPrefix = 'n'
@ -74,14 +74,14 @@ func _deploy(data any, isUpdate bool) {
ctx := storage.GetContext()
args := data.(struct {
owners []interop.Hash160
admin interop.Hash160
})
for _, owner := range args.owners {
if len(owner) != interop.Hash160Len {
panic("incorrect length of owner addresses")
if args.admin != nil {
if len(args.admin) != interop.Hash160Len {
panic("incorrect length of owner address")
}
storage.Put(ctx, ownerKey(owner), []byte{1})
storage.Put(ctx, adminKey, args.admin)
}
storage.Put(ctx, groupCounterKey, 0)
@ -89,27 +89,27 @@ func _deploy(data any, isUpdate bool) {
runtime.Log("frostfsid contract initialized")
}
func AddOwner(addr interop.Hash160) {
func SetAdmin(addr interop.Hash160) {
ctx := storage.GetContext()
if !common.HasUpdateAccess() {
panic("not witnessed")
}
storage.Put(ctx, ownerKey(addr), []byte{1})
storage.Put(ctx, adminKey, addr)
}
func DeleteOwner(addr interop.Hash160) {
func ClearAdmin() {
ctx := storage.GetContext()
if !common.HasUpdateAccess() {
panic("not witnessed")
}
storage.Delete(ctx, ownerKey(addr))
storage.Delete(ctx, adminKey)
}
func ListOwners() iterator.Iterator {
func GetAdmin() interop.Hash160 {
ctx := storage.GetReadOnlyContext()
return storage.Find(ctx, []byte{ownerKeysPrefix}, storage.KeysOnly|storage.RemovePrefix)
return storage.Get(ctx, adminKey).(interop.Hash160)
}
// Update method updates contract source code and manifest. It can be invoked
@ -815,12 +815,12 @@ func DeleteGroup(ns string, groupID int) {
}
func checkContractOwner(ctx storage.Context) {
it := storage.Find(ctx, []byte{ownerKeysPrefix}, storage.KeysOnly|storage.RemovePrefix)
for iterator.Next(it) {
owner := iterator.Value(it).([]byte)
if runtime.CheckWitness(owner) {
addr := storage.Get(ctx, adminKey)
if addr != nil && runtime.CheckWitness(addr.(interop.Hash160)) {
return
}
if common.HasUpdateAccess() {
return
}
panic("not witnessed")
}
@ -905,10 +905,6 @@ func setNamespaceGroupName(ctx storage.Context, gr Group) {
}
}
func ownerKey(owner interop.Hash160) []byte {
return append([]byte{ownerKeysPrefix}, owner...)
}
func subjectKey(key interop.PublicKey) []byte {
addr := contract.CreateStandardAccount(key)
return subjectKeyFromAddr(addr)
@ -930,6 +926,7 @@ func subjectAdditionalPrefix(additionalKey interop.PublicKey) []byte {
func namespaceKey(ns string) []byte {
return namespaceKeyFromHash(ripemd160Hash(ns))
}
func namespaceKeyFromHash(ns []byte) []byte {
return append([]byte{namespaceKeysPrefix}, ns...)
}

View file

@ -23,9 +23,9 @@ const (
)
const (
// ErrNotAutorized is returned when the none of the transaction signers
// ErrNotAuthorized is returned when the none of the transaction signers
// belongs to the list of autorized keys.
ErrNotAutorized = "none of the signers is not autorized to change the contract"
ErrNotAuthorized = "none of the signers is authorized to change the contract"
)
// _deploy function sets up initial list of inner ring public keys.
@ -42,25 +42,20 @@ func _deploy(data any, isUpdate bool) {
if len(args.Admin) != 20 {
panic("invaliad admin hash length")
}
storage.Put(ctx, ownerKey(args.Admin), []byte{1})
storage.Put(ctx, []byte{ownerKeyPrefix}, args.Admin)
}
}
func ownerKey(sender interop.Hash160) []byte {
return append([]byte{ownerKeyPrefix}, sender...)
}
func checkAuthorization(ctx storage.Context) {
if runtime.CheckWitness(common.AlphabetAddress()) {
return
}
admin := getAdmin(ctx)
if admin != nil && runtime.CheckWitness(admin) {
return
}
if runtime.CheckWitness(common.AlphabetAddress()) {
return
}
panic(ErrNotAutorized)
panic(ErrNotAuthorized)
}
func SetAdmin(addr interop.Hash160) {
@ -79,14 +74,14 @@ func getAdmin(ctx storage.Context) interop.Hash160 {
return storage.Get(ctx, []byte{ownerKeyPrefix}).(interop.Hash160)
}
func storageKey(prefix Kind, entityName, name string) []byte {
func storageKey(prefix Kind, entityName string, name []byte) []byte {
ln := len(entityName)
key := append([]byte{byte(prefix)}, byte(ln&0xFF), byte(ln>>8))
key = append(key, entityName...)
return append(key, name...)
}
func AddChain(entity Kind, entityName, name string, chain []byte) {
func AddChain(entity Kind, entityName string, name []byte, chain []byte) {
ctx := storage.GetContext()
checkAuthorization(ctx)
@ -94,7 +89,7 @@ func AddChain(entity Kind, entityName, name string, chain []byte) {
storage.Put(ctx, key, chain)
}
func GetChain(entity Kind, entityName, name string) []byte {
func GetChain(entity Kind, entityName string, name []byte) []byte {
ctx := storage.GetReadOnlyContext()
key := storageKey(entity, entityName, name)
data := storage.Get(ctx, key).([]byte)
@ -105,7 +100,7 @@ func GetChain(entity Kind, entityName, name string) []byte {
return data
}
func RemoveChain(entity Kind, entityName string, name string) {
func RemoveChain(entity Kind, entityName string, name []byte) {
ctx := storage.GetContext()
checkAuthorization(ctx)
@ -113,7 +108,7 @@ func RemoveChain(entity Kind, entityName string, name string) {
storage.Delete(ctx, key)
}
func RemoveChainsByPrefix(entity Kind, entityName string, name string) {
func RemoveChainsByPrefix(entity Kind, entityName string, name []byte) {
ctx := storage.GetContext()
checkAuthorization(ctx)
@ -126,7 +121,7 @@ func RemoveChainsByPrefix(entity Kind, entityName string, name string) {
// ListChains lists all chains for the namespace by prefix.
// container may be empty.
func ListChains(namespace, container, name string) [][]byte {
func ListChains(namespace, container string, name []byte) [][]byte {
result := ListChainsByPrefix(Namespace, namespace, name)
if container != "" {
@ -137,7 +132,7 @@ func ListChains(namespace, container, name string) [][]byte {
}
// ListChainsByPrefix list all chains for the provided kind and entity by prefix.
func ListChainsByPrefix(entity Kind, entityName, prefix string) [][]byte {
func ListChainsByPrefix(entity Kind, entityName string, prefix []byte) [][]byte {
ctx := storage.GetReadOnlyContext()
result := [][]byte{}

View file

@ -7,6 +7,7 @@ import (
"crypto/elliptic"
"errors"
"fmt"
"github.com/google/uuid"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
@ -126,6 +127,9 @@ type DeleteGroupEvent struct {
// Invoker is used by ContractReader to call various safe methods.
type Invoker interface {
Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error)
TerminateSession(sessionID uuid.UUID) error
TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error)
}
// Actor is used by Contract to call state-changing methods.
@ -163,33 +167,131 @@ func New(actor Actor, hash util.Uint160) *Contract {
return &Contract{ContractReader{actor, hash}, actor, hash}
}
// GetAdmin invokes `getAdmin` method of contract.
func (c *ContractReader) GetAdmin() (util.Uint160, error) {
return unwrap.Uint160(c.invoker.Call(c.hash, "getAdmin"))
}
// GetGroup invokes `getGroup` method of contract.
func (c *ContractReader) GetGroup(ns string, groupID *big.Int) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.Call(c.hash, "getGroup", ns, groupID))
}
// GetGroupExtended invokes `getGroupExtended` method of contract.
func (c *ContractReader) GetGroupExtended(ns string, groupID *big.Int) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.Call(c.hash, "getGroupExtended", ns, groupID))
}
// GetGroupIDByName invokes `getGroupIDByName` method of contract.
func (c *ContractReader) GetGroupIDByName(ns string, name string) (*big.Int, error) {
return unwrap.BigInt(c.invoker.Call(c.hash, "getGroupIDByName", ns, name))
}
// GetNamespace invokes `getNamespace` method of contract.
func (c *ContractReader) GetNamespace(ns string) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.Call(c.hash, "getNamespace", ns))
}
// GetNamespaceExtended invokes `getNamespaceExtended` method of contract.
func (c *ContractReader) GetNamespaceExtended(ns string) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.Call(c.hash, "getNamespaceExtended", ns))
}
// GetSubject invokes `getSubject` method of contract.
func (c *ContractReader) GetSubject(addr util.Uint160) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.Call(c.hash, "getSubject", addr))
}
// GetSubjectByKey invokes `getSubjectByKey` method of contract.
func (c *ContractReader) GetSubjectByKey(key *keys.PublicKey) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.Call(c.hash, "getSubjectByKey", key))
}
// GetSubjectExtended invokes `getSubjectExtended` method of contract.
func (c *ContractReader) GetSubjectExtended(addr util.Uint160) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.Call(c.hash, "getSubjectExtended", addr))
}
// GetSubjectKeyByName invokes `getSubjectKeyByName` method of contract.
func (c *ContractReader) GetSubjectKeyByName(ns string, name string) (*keys.PublicKey, error) {
return unwrap.PublicKey(c.invoker.Call(c.hash, "getSubjectKeyByName", ns, name))
}
// ListGroupSubjects invokes `listGroupSubjects` method of contract.
func (c *ContractReader) ListGroupSubjects(ns string, groupID *big.Int) (uuid.UUID, result.Iterator, error) {
return unwrap.SessionIterator(c.invoker.Call(c.hash, "listGroupSubjects", ns, groupID))
}
// ListGroupSubjectsExpanded is similar to ListGroupSubjects (uses the same contract
// method), but can be useful if the server used doesn't support sessions and
// doesn't expand iterators. It creates a script that will get the specified
// number of result items from the iterator right in the VM and return them to
// you. It's only limited by VM stack and GAS available for RPC invocations.
func (c *ContractReader) ListGroupSubjectsExpanded(ns string, groupID *big.Int, _numOfIteratorItems int) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "listGroupSubjects", _numOfIteratorItems, ns, groupID))
}
// ListGroups invokes `listGroups` method of contract.
func (c *ContractReader) ListGroups(ns string) (uuid.UUID, result.Iterator, error) {
return unwrap.SessionIterator(c.invoker.Call(c.hash, "listGroups", ns))
}
// ListGroupsExpanded is similar to ListGroups (uses the same contract
// method), but can be useful if the server used doesn't support sessions and
// doesn't expand iterators. It creates a script that will get the specified
// number of result items from the iterator right in the VM and return them to
// you. It's only limited by VM stack and GAS available for RPC invocations.
func (c *ContractReader) ListGroupsExpanded(ns string, _numOfIteratorItems int) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "listGroups", _numOfIteratorItems, ns))
}
// ListNamespaceSubjects invokes `listNamespaceSubjects` method of contract.
func (c *ContractReader) ListNamespaceSubjects(ns string) (uuid.UUID, result.Iterator, error) {
return unwrap.SessionIterator(c.invoker.Call(c.hash, "listNamespaceSubjects", ns))
}
// ListNamespaceSubjectsExpanded is similar to ListNamespaceSubjects (uses the same contract
// method), but can be useful if the server used doesn't support sessions and
// doesn't expand iterators. It creates a script that will get the specified
// number of result items from the iterator right in the VM and return them to
// you. It's only limited by VM stack and GAS available for RPC invocations.
func (c *ContractReader) ListNamespaceSubjectsExpanded(ns string, _numOfIteratorItems int) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "listNamespaceSubjects", _numOfIteratorItems, ns))
}
// ListNamespaces invokes `listNamespaces` method of contract.
func (c *ContractReader) ListNamespaces() (uuid.UUID, result.Iterator, error) {
return unwrap.SessionIterator(c.invoker.Call(c.hash, "listNamespaces"))
}
// ListNamespacesExpanded is similar to ListNamespaces (uses the same contract
// method), but can be useful if the server used doesn't support sessions and
// doesn't expand iterators. It creates a script that will get the specified
// number of result items from the iterator right in the VM and return them to
// you. It's only limited by VM stack and GAS available for RPC invocations.
func (c *ContractReader) ListNamespacesExpanded(_numOfIteratorItems int) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "listNamespaces", _numOfIteratorItems))
}
// ListSubjects invokes `listSubjects` method of contract.
func (c *ContractReader) ListSubjects() (uuid.UUID, result.Iterator, error) {
return unwrap.SessionIterator(c.invoker.Call(c.hash, "listSubjects"))
}
// ListSubjectsExpanded is similar to ListSubjects (uses the same contract
// method), but can be useful if the server used doesn't support sessions and
// doesn't expand iterators. It creates a script that will get the specified
// number of result items from the iterator right in the VM and return them to
// you. It's only limited by VM stack and GAS available for RPC invocations.
func (c *ContractReader) ListSubjectsExpanded(_numOfIteratorItems int) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "listSubjects", _numOfIteratorItems))
}
// Version invokes `version` method of contract.
func (c *ContractReader) Version() (*big.Int, error) {
return unwrap.BigInt(c.invoker.Call(c.hash, "version"))
}
// AddOwner creates a transaction invoking `addOwner` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) AddOwner(addr util.Uint160) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "addOwner", addr)
}
// AddOwnerTransaction creates a transaction invoking `addOwner` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) AddOwnerTransaction(addr util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "addOwner", addr)
}
// AddOwnerUnsigned creates a transaction invoking `addOwner` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) AddOwnerUnsigned(addr util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "addOwner", nil, addr)
}
// AddSubjectKey creates a transaction invoking `addSubjectKey` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
@ -256,6 +358,28 @@ func (c *Contract) AddSubjectToNamespaceUnsigned(addr util.Uint160, ns string) (
return c.actor.MakeUnsignedCall(c.hash, "addSubjectToNamespace", nil, addr, ns)
}
// ClearAdmin creates a transaction invoking `clearAdmin` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) ClearAdmin() (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "clearAdmin")
}
// ClearAdminTransaction creates a transaction invoking `clearAdmin` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) ClearAdminTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "clearAdmin")
}
// ClearAdminUnsigned creates a transaction invoking `clearAdmin` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) ClearAdminUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "clearAdmin", nil)
}
// CreateGroup creates a transaction invoking `createGroup` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
@ -366,28 +490,6 @@ func (c *Contract) DeleteGroupKVUnsigned(ns string, groupID *big.Int, key string
return c.actor.MakeUnsignedCall(c.hash, "deleteGroupKV", nil, ns, groupID, key)
}
// DeleteOwner creates a transaction invoking `deleteOwner` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) DeleteOwner(addr util.Uint160) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "deleteOwner", addr)
}
// DeleteOwnerTransaction creates a transaction invoking `deleteOwner` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) DeleteOwnerTransaction(addr util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "deleteOwner", addr)
}
// DeleteOwnerUnsigned creates a transaction invoking `deleteOwner` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) DeleteOwnerUnsigned(addr util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "deleteOwner", nil, addr)
}
// DeleteSubject creates a transaction invoking `deleteSubject` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
@ -432,336 +534,6 @@ func (c *Contract) DeleteSubjectKVUnsigned(addr util.Uint160, key string) (*tran
return c.actor.MakeUnsignedCall(c.hash, "deleteSubjectKV", nil, addr, key)
}
// GetGroup creates a transaction invoking `getGroup` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) GetGroup(ns string, groupID *big.Int) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "getGroup", ns, groupID)
}
// GetGroupTransaction creates a transaction invoking `getGroup` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) GetGroupTransaction(ns string, groupID *big.Int) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "getGroup", ns, groupID)
}
// GetGroupUnsigned creates a transaction invoking `getGroup` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) GetGroupUnsigned(ns string, groupID *big.Int) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "getGroup", nil, ns, groupID)
}
// GetGroupExtended creates a transaction invoking `getGroupExtended` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) GetGroupExtended(ns string, groupID *big.Int) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "getGroupExtended", ns, groupID)
}
// GetGroupExtendedTransaction creates a transaction invoking `getGroupExtended` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) GetGroupExtendedTransaction(ns string, groupID *big.Int) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "getGroupExtended", ns, groupID)
}
// GetGroupExtendedUnsigned creates a transaction invoking `getGroupExtended` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) GetGroupExtendedUnsigned(ns string, groupID *big.Int) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "getGroupExtended", nil, ns, groupID)
}
// GetGroupIDByName creates a transaction invoking `getGroupIDByName` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) GetGroupIDByName(ns string, name string) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "getGroupIDByName", ns, name)
}
// GetGroupIDByNameTransaction creates a transaction invoking `getGroupIDByName` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) GetGroupIDByNameTransaction(ns string, name string) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "getGroupIDByName", ns, name)
}
// GetGroupIDByNameUnsigned creates a transaction invoking `getGroupIDByName` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) GetGroupIDByNameUnsigned(ns string, name string) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "getGroupIDByName", nil, ns, name)
}
// GetNamespace creates a transaction invoking `getNamespace` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) GetNamespace(ns string) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "getNamespace", ns)
}
// GetNamespaceTransaction creates a transaction invoking `getNamespace` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) GetNamespaceTransaction(ns string) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "getNamespace", ns)
}
// GetNamespaceUnsigned creates a transaction invoking `getNamespace` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) GetNamespaceUnsigned(ns string) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "getNamespace", nil, ns)
}
// GetNamespaceExtended creates a transaction invoking `getNamespaceExtended` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) GetNamespaceExtended(ns string) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "getNamespaceExtended", ns)
}
// GetNamespaceExtendedTransaction creates a transaction invoking `getNamespaceExtended` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) GetNamespaceExtendedTransaction(ns string) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "getNamespaceExtended", ns)
}
// GetNamespaceExtendedUnsigned creates a transaction invoking `getNamespaceExtended` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) GetNamespaceExtendedUnsigned(ns string) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "getNamespaceExtended", nil, ns)
}
// GetSubject creates a transaction invoking `getSubject` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) GetSubject(addr util.Uint160) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "getSubject", addr)
}
// GetSubjectTransaction creates a transaction invoking `getSubject` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) GetSubjectTransaction(addr util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "getSubject", addr)
}
// GetSubjectUnsigned creates a transaction invoking `getSubject` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) GetSubjectUnsigned(addr util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "getSubject", nil, addr)
}
// GetSubjectByKey creates a transaction invoking `getSubjectByKey` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) GetSubjectByKey(key *keys.PublicKey) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "getSubjectByKey", key)
}
// GetSubjectByKeyTransaction creates a transaction invoking `getSubjectByKey` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) GetSubjectByKeyTransaction(key *keys.PublicKey) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "getSubjectByKey", key)
}
// GetSubjectByKeyUnsigned creates a transaction invoking `getSubjectByKey` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) GetSubjectByKeyUnsigned(key *keys.PublicKey) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "getSubjectByKey", nil, key)
}
// GetSubjectExtended creates a transaction invoking `getSubjectExtended` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) GetSubjectExtended(addr util.Uint160) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "getSubjectExtended", addr)
}
// GetSubjectExtendedTransaction creates a transaction invoking `getSubjectExtended` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) GetSubjectExtendedTransaction(addr util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "getSubjectExtended", addr)
}
// GetSubjectExtendedUnsigned creates a transaction invoking `getSubjectExtended` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) GetSubjectExtendedUnsigned(addr util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "getSubjectExtended", nil, addr)
}
// GetSubjectKeyByName creates a transaction invoking `getSubjectKeyByName` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) GetSubjectKeyByName(ns string, name string) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "getSubjectKeyByName", ns, name)
}
// GetSubjectKeyByNameTransaction creates a transaction invoking `getSubjectKeyByName` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) GetSubjectKeyByNameTransaction(ns string, name string) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "getSubjectKeyByName", ns, name)
}
// GetSubjectKeyByNameUnsigned creates a transaction invoking `getSubjectKeyByName` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) GetSubjectKeyByNameUnsigned(ns string, name string) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "getSubjectKeyByName", nil, ns, name)
}
// ListGroupSubjects creates a transaction invoking `listGroupSubjects` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) ListGroupSubjects(ns string, groupID *big.Int) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "listGroupSubjects", ns, groupID)
}
// ListGroupSubjectsTransaction creates a transaction invoking `listGroupSubjects` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) ListGroupSubjectsTransaction(ns string, groupID *big.Int) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "listGroupSubjects", ns, groupID)
}
// ListGroupSubjectsUnsigned creates a transaction invoking `listGroupSubjects` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) ListGroupSubjectsUnsigned(ns string, groupID *big.Int) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "listGroupSubjects", nil, ns, groupID)
}
// ListGroups creates a transaction invoking `listGroups` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) ListGroups(ns string) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "listGroups", ns)
}
// ListGroupsTransaction creates a transaction invoking `listGroups` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) ListGroupsTransaction(ns string) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "listGroups", ns)
}
// ListGroupsUnsigned creates a transaction invoking `listGroups` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) ListGroupsUnsigned(ns string) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "listGroups", nil, ns)
}
// ListNamespaceSubjects creates a transaction invoking `listNamespaceSubjects` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) ListNamespaceSubjects(ns string) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "listNamespaceSubjects", ns)
}
// ListNamespaceSubjectsTransaction creates a transaction invoking `listNamespaceSubjects` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) ListNamespaceSubjectsTransaction(ns string) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "listNamespaceSubjects", ns)
}
// ListNamespaceSubjectsUnsigned creates a transaction invoking `listNamespaceSubjects` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) ListNamespaceSubjectsUnsigned(ns string) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "listNamespaceSubjects", nil, ns)
}
// ListNamespaces creates a transaction invoking `listNamespaces` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) ListNamespaces() (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "listNamespaces")
}
// ListNamespacesTransaction creates a transaction invoking `listNamespaces` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) ListNamespacesTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "listNamespaces")
}
// ListNamespacesUnsigned creates a transaction invoking `listNamespaces` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) ListNamespacesUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "listNamespaces", nil)
}
// ListOwners creates a transaction invoking `listOwners` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) ListOwners() (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "listOwners")
}
// ListOwnersTransaction creates a transaction invoking `listOwners` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) ListOwnersTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "listOwners")
}
// ListOwnersUnsigned creates a transaction invoking `listOwners` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) ListOwnersUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "listOwners", nil)
}
// ListSubjects creates a transaction invoking `listSubjects` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) ListSubjects() (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "listSubjects")
}
// ListSubjectsTransaction creates a transaction invoking `listSubjects` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) ListSubjectsTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "listSubjects")
}
// ListSubjectsUnsigned creates a transaction invoking `listSubjects` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) ListSubjectsUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "listSubjects", nil)
}
// RemoveSubjectFromGroup creates a transaction invoking `removeSubjectFromGroup` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
@ -828,6 +600,28 @@ func (c *Contract) RemoveSubjectKeyUnsigned(addr util.Uint160, key *keys.PublicK
return c.actor.MakeUnsignedCall(c.hash, "removeSubjectKey", nil, addr, key)
}
// SetAdmin creates a transaction invoking `setAdmin` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) SetAdmin(addr util.Uint160) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "setAdmin", addr)
}
// SetAdminTransaction creates a transaction invoking `setAdmin` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) SetAdminTransaction(addr util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "setAdmin", addr)
}
// SetAdminUnsigned creates a transaction invoking `setAdmin` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) SetAdminUnsigned(addr util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "setAdmin", nil, addr)
}
// SetGroupKV creates a transaction invoking `setGroupKV` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.

View file

@ -52,32 +52,37 @@ func New(actor Actor, hash util.Uint160) *Contract {
return &Contract{ContractReader{actor, hash}, actor, hash}
}
// GetAdmin invokes `getAdmin` method of contract.
func (c *ContractReader) GetAdmin() (util.Uint160, error) {
return unwrap.Uint160(c.invoker.Call(c.hash, "getAdmin"))
}
// GetChain invokes `getChain` method of contract.
func (c *ContractReader) GetChain(entity *big.Int, entityName string, name string) ([]byte, error) {
func (c *ContractReader) GetChain(entity *big.Int, entityName string, name []byte) ([]byte, error) {
return unwrap.Bytes(c.invoker.Call(c.hash, "getChain", entity, entityName, name))
}
// ListChains invokes `listChains` method of contract.
func (c *ContractReader) ListChains(namespace string, container string, name string) ([]stackitem.Item, error) {
func (c *ContractReader) ListChains(namespace string, container string, name []byte) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.Call(c.hash, "listChains", namespace, container, name))
}
// ListChainsByPrefix invokes `listChainsByPrefix` method of contract.
func (c *ContractReader) ListChainsByPrefix(entity *big.Int, entityName string, prefix string) ([]stackitem.Item, error) {
func (c *ContractReader) ListChainsByPrefix(entity *big.Int, entityName string, prefix []byte) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.Call(c.hash, "listChainsByPrefix", entity, entityName, prefix))
}
// AddChain creates a transaction invoking `addChain` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) AddChain(entity *big.Int, entityName string, name string, chain []byte) (util.Uint256, uint32, error) {
func (c *Contract) AddChain(entity *big.Int, entityName string, name []byte, chain []byte) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "addChain", entity, entityName, name, chain)
}
// AddChainTransaction creates a transaction invoking `addChain` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) AddChainTransaction(entity *big.Int, entityName string, name string, chain []byte) (*transaction.Transaction, error) {
func (c *Contract) AddChainTransaction(entity *big.Int, entityName string, name []byte, chain []byte) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "addChain", entity, entityName, name, chain)
}
@ -85,21 +90,21 @@ func (c *Contract) AddChainTransaction(entity *big.Int, entityName string, name
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) AddChainUnsigned(entity *big.Int, entityName string, name string, chain []byte) (*transaction.Transaction, error) {
func (c *Contract) AddChainUnsigned(entity *big.Int, entityName string, name []byte, chain []byte) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "addChain", nil, entity, entityName, name, chain)
}
// RemoveChain creates a transaction invoking `removeChain` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) RemoveChain(entity *big.Int, entityName string, name string) (util.Uint256, uint32, error) {
func (c *Contract) RemoveChain(entity *big.Int, entityName string, name []byte) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "removeChain", entity, entityName, name)
}
// RemoveChainTransaction creates a transaction invoking `removeChain` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) RemoveChainTransaction(entity *big.Int, entityName string, name string) (*transaction.Transaction, error) {
func (c *Contract) RemoveChainTransaction(entity *big.Int, entityName string, name []byte) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "removeChain", entity, entityName, name)
}
@ -107,21 +112,21 @@ func (c *Contract) RemoveChainTransaction(entity *big.Int, entityName string, na
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) RemoveChainUnsigned(entity *big.Int, entityName string, name string) (*transaction.Transaction, error) {
func (c *Contract) RemoveChainUnsigned(entity *big.Int, entityName string, name []byte) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "removeChain", nil, entity, entityName, name)
}
// RemoveChainsByPrefix creates a transaction invoking `removeChainsByPrefix` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) RemoveChainsByPrefix(entity *big.Int, entityName string, name string) (util.Uint256, uint32, error) {
func (c *Contract) RemoveChainsByPrefix(entity *big.Int, entityName string, name []byte) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "removeChainsByPrefix", entity, entityName, name)
}
// RemoveChainsByPrefixTransaction creates a transaction invoking `removeChainsByPrefix` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) RemoveChainsByPrefixTransaction(entity *big.Int, entityName string, name string) (*transaction.Transaction, error) {
func (c *Contract) RemoveChainsByPrefixTransaction(entity *big.Int, entityName string, name []byte) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "removeChainsByPrefix", entity, entityName, name)
}
@ -129,6 +134,28 @@ func (c *Contract) RemoveChainsByPrefixTransaction(entity *big.Int, entityName s
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) RemoveChainsByPrefixUnsigned(entity *big.Int, entityName string, name string) (*transaction.Transaction, error) {
func (c *Contract) RemoveChainsByPrefixUnsigned(entity *big.Int, entityName string, name []byte) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "removeChainsByPrefix", nil, entity, entityName, name)
}
// SetAdmin creates a transaction invoking `setAdmin` method of the contract.
// This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) SetAdmin(addr util.Uint160) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "setAdmin", addr)
}
// SetAdminTransaction creates a transaction invoking `setAdmin` method of the contract.
// This transaction is signed, but not sent to the network, instead it's
// returned to the caller.
func (c *Contract) SetAdminTransaction(addr util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "setAdmin", addr)
}
// SetAdminUnsigned creates a transaction invoking `setAdmin` method of the contract.
// This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) SetAdminUnsigned(addr util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "setAdmin", nil, addr)
}

View file

@ -76,19 +76,19 @@ func TestFrostFSID_Client_ContractOwnersManagement(t *testing.T) {
defaultOwnerAddress := ffsid.base.owner.ScriptHash()
_, newOwnerAddress := newKey(t)
checkListOwnersClient(t, ffsid.cli, defaultOwnerAddress)
checkAdminClient(t, ffsid.cli, defaultOwnerAddress)
_, _, err := ffsid.cli.AddOwner(newOwnerAddress)
_, _, err := ffsid.cli.SetAdmin(newOwnerAddress)
require.ErrorContains(t, err, "not witnessed")
committeeInvoker.Invoke(t, stackitem.Null{}, addOwnerMethod, newOwnerAddress)
committeeInvoker.Invoke(t, stackitem.Null{}, setAdminMethod, newOwnerAddress)
checkListOwnersClient(t, ffsid.cli, defaultOwnerAddress, newOwnerAddress)
checkAdminClient(t, ffsid.cli, newOwnerAddress)
_, _, err = ffsid.cli.DeleteOwner(newOwnerAddress)
_, _, err = ffsid.cli.ClearAdmin()
require.ErrorContains(t, err, "not witnessed")
committeeInvoker.Invoke(t, stackitem.Null{}, deleteOwnerMethod, newOwnerAddress)
committeeInvoker.Invoke(t, stackitem.Null{}, clearAdminMethod)
checkListOwnersClient(t, ffsid.cli, defaultOwnerAddress)
checkAdminClient(t, ffsid.cli)
}
func newKey(t *testing.T) (*keys.PrivateKey, util.Uint160) {
@ -97,10 +97,13 @@ func newKey(t *testing.T) (*keys.PrivateKey, util.Uint160) {
return key, key.PublicKey().GetScriptHash()
}
func checkListOwnersClient(t *testing.T, cli *client.Client, owners ...util.Uint160) {
addresses, err := cli.ListOwners()
func checkAdminClient(t *testing.T, cli *client.Client, owners ...util.Uint160) {
address, isSet, err := cli.GetAdmin()
require.NoError(t, err)
require.ElementsMatch(t, addresses, owners)
require.Equal(t, len(owners) > 0, isSet)
if isSet {
require.Equal(t, owners[0], address)
}
}
func TestFrostFSID_Client_SubjectManagement(t *testing.T) {

View file

@ -23,9 +23,9 @@ import (
const frostfsidPath = "../frostfsid"
const (
addOwnerMethod = "addOwner"
deleteOwnerMethod = "deleteOwner"
listOwnersMethod = "listOwners"
setAdminMethod = "setAdmin"
getAdminMethod = "getAdmin"
clearAdminMethod = "clearAdmin"
createSubjectMethod = "createSubject"
getSubjectMethod = "getSubject"
@ -97,7 +97,7 @@ func newSigner(t *testing.T, c *neotest.ContractInvoker, acc *wallet.Account) ne
func deployFrostFSIDContract(t *testing.T, e *neotest.Executor, contractOwner util.Uint160) util.Uint160 {
args := make([]any, 5)
args[0] = []any{contractOwner}
args[0] = contractOwner
c := neotest.CompileFile(t, e.CommitteeHash, frostfsidPath, path.Join(frostfsidPath, "config.yml"))
e.DeployContract(t, c, args)
@ -130,30 +130,48 @@ func TestFrostFSID_ContractOwnersManagement(t *testing.T) {
invokerHash := invoker.Signers[0].ScriptHash()
committeeInvoker := f.CommitteeInvoker()
checkListOwners(t, anonInvoker, invokerHash)
checkOwner(t, anonInvoker, invokerHash)
anonInvoker.InvokeFail(t, notWitnessedError, createNamespaceMethod, "namespace")
invoker.Invoke(t, stackitem.Null{}, createNamespaceMethod, "namespace")
invoker.InvokeFail(t, notWitnessedError, addOwnerMethod, anonInvokerHash)
committeeInvoker.Invoke(t, stackitem.Null{}, addOwnerMethod, anonInvokerHash)
t.Run("setAdmin is only allowed for committee", func(t *testing.T) {
invoker.InvokeFail(t, notWitnessedError, setAdminMethod, anonInvokerHash)
})
t.Run("replace owner", func(t *testing.T) {
committeeInvoker.Invoke(t, stackitem.Null{}, setAdminMethod, anonInvokerHash)
checkOwner(t, anonInvoker, anonInvokerHash)
invoker.InvokeFail(t, notWitnessedError, createNamespaceMethod, "namespace2")
anonInvoker.Invoke(t, stackitem.Null{}, createNamespaceMethod, "namespace2")
})
t.Run("remove owner", func(t *testing.T) {
committeeInvoker.Invoke(t, stackitem.Null{}, clearAdminMethod)
checkOwner(t, anonInvoker)
checkListOwners(t, anonInvoker, invokerHash, anonInvokerHash)
anonInvoker.InvokeFail(t, notWitnessedError, deleteOwnerMethod, anonInvokerHash)
committeeInvoker.Invoke(t, stackitem.Null{}, deleteOwnerMethod, anonInvokerHash)
invoker.InvokeFail(t, notWitnessedError, createNamespaceMethod, "namespace3")
anonInvoker.InvokeFail(t, notWitnessedError, createNamespaceMethod, "namespace3")
checkListOwners(t, anonInvoker, invokerHash)
})
}
func checkListOwners(t *testing.T, invoker *neotest.ContractInvoker, expectedAddresses ...util.Uint160) {
s, err := invoker.TestInvoke(t, listOwnersMethod)
func checkOwner(t *testing.T, invoker *neotest.ContractInvoker, owner ...util.Uint160) {
if len(owner) > 1 {
require.Fail(t, "invalid testcase")
}
s, err := invoker.TestInvoke(t, getAdminMethod)
require.NoError(t, err)
addresses, err := unwrap.ArrayOfUint160(makeValidRes(stackitem.NewArray(readIteratorAll(s))), nil)
require.Equal(t, 1, s.Len(), "unexpected number items on stack")
if len(owner) == 0 {
_, isMissing := s.Pop().Item().(stackitem.Null)
require.True(t, isMissing)
return
}
bs, err := s.Pop().Item().TryBytes()
require.NoError(t, err)
require.ElementsMatch(t, addresses, expectedAddresses)
require.Equal(t, bs, owner[0].BytesBE())
}
func TestFrostFSID_SubjectManagement(t *testing.T) {
@ -254,7 +272,6 @@ func TestFrostFSID_SubjectManagement(t *testing.T) {
require.NoError(t, err)
require.Len(t, addresses, 2)
require.ElementsMatch(t, addresses, []util.Uint160{subjKeyAddr, newSubjKey.PublicKey().GetScriptHash()})
})
anonInvoker.InvokeFail(t, notWitnessedError, deleteSubjectMethod, subjKeyAddr)
@ -359,7 +376,6 @@ func TestFrostFSIS_GroupNameRelatedInvariants(t *testing.T) {
invoker.InvokeFail(t, "not available", createGroupMethod, ns1, groupName2)
invoker.Invoke(t, stackitem.Make(3), createGroupMethod, ns2, groupName2)
// Check that we cannot find group id by name for group that was removed
invoker.Invoke(t, stackitem.Null{}, deleteGroupMethod, ns1, groupID2)
s, err = invoker.TestInvoke(t, getGroupIDByNameMethod, ns1, groupName2)
@ -369,7 +385,7 @@ func TestFrostFSIS_GroupNameRelatedInvariants(t *testing.T) {
invoker.Invoke(t, stackitem.Make(4), createGroupMethod, ns1, groupName2)
// Check that after group renaming its id cannot be found by old name
newGroupName:= "new"
newGroupName := "new"
invoker.Invoke(t, stackitem.Null{}, setGroupNameMethod, ns1, groupID1, newGroupName)
s, err = invoker.TestInvoke(t, getGroupIDByNameMethod, ns1, groupName1)
checkGroupIDResult(t, s, err, -1)

View file

@ -81,7 +81,7 @@ func TestAutorization(t *testing.T) {
c := e.WithSigners(s)
args := []any{policy.Container, "cnr1", "ingress:myrule3", []byte("opaque")}
c.InvokeFail(t, policy.ErrNotAutorized, "addChain", args...)
c.InvokeFail(t, policy.ErrNotAuthorized, "addChain", args...)
e.Invoke(t, stackitem.Null{}, "setAdmin", s.ScriptHash())
e.Invoke(t, stackitem.NewBuffer(s.ScriptHash().BytesBE()), "getAdmin")