From c8b14d1376f702e52bdf8c4f3c6da011a817a9d9 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 7 Nov 2023 13:55:49 +0300 Subject: [PATCH] [#48] frostfsid: Generate wrappers Signed-off-by: Denis Kirillov --- rpcclient/frostfsid/client.go | 1823 ++++++++++++++++++++++++++++++++- 1 file changed, 1800 insertions(+), 23 deletions(-) diff --git a/rpcclient/frostfsid/client.go b/rpcclient/frostfsid/client.go index 03b1369..5367e76 100644 --- a/rpcclient/frostfsid/client.go +++ b/rpcclient/frostfsid/client.go @@ -4,14 +4,103 @@ package identity import ( + "crypto/elliptic" + "errors" + "fmt" "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" "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" "math/big" + "unicode/utf8" ) +// CreateSubjectEvent represents "CreateSubject" event emitted by the contract. +type CreateSubjectEvent struct { + SubjectAddress util.Uint160 +} + +// AddSubjectKeyEvent represents "AddSubjectKey" event emitted by the contract. +type AddSubjectKeyEvent struct { + SubjectAddress util.Uint160 + SubjectKey *keys.PublicKey +} + +// RemoveSubjectKeyEvent represents "RemoveSubjectKey" event emitted by the contract. +type RemoveSubjectKeyEvent struct { + SubjectAddress util.Uint160 + SubjectKey *keys.PublicKey +} + +// SetSubjectNameEvent represents "SetSubjectName" event emitted by the contract. +type SetSubjectNameEvent struct { + SubjectAddress util.Uint160 + Name string +} + +// SetSubjectKVEvent represents "SetSubjectKV" event emitted by the contract. +type SetSubjectKVEvent struct { + SubjectAddress util.Uint160 + Key string + Value string +} + +// DeleteSubjectKVEvent represents "DeleteSubjectKV" event emitted by the contract. +type DeleteSubjectKVEvent struct { + SubjectAddress util.Uint160 + Key string +} + +// DeleteSubjectEvent represents "DeleteSubject" event emitted by the contract. +type DeleteSubjectEvent struct { + SubjectAddress util.Uint160 +} + +// CreateNamespaceEvent represents "CreateNamespace" event emitted by the contract. +type CreateNamespaceEvent struct { + Namespace string +} + +// AddSubjectToNamespaceEvent represents "AddSubjectToNamespace" event emitted by the contract. +type AddSubjectToNamespaceEvent struct { + SubjectAddress util.Uint160 + Namespace string +} + +// RemoveSubjectFromNamespaceEvent represents "RemoveSubjectFromNamespace" event emitted by the contract. +type RemoveSubjectFromNamespaceEvent struct { + SubjectAddress util.Uint160 + Namespace string +} + +// CreateGroupEvent represents "CreateGroup" event emitted by the contract. +type CreateGroupEvent struct { + Namespace string + Group string +} + +// AddSubjectToGroupEvent represents "AddSubjectToGroup" event emitted by the contract. +type AddSubjectToGroupEvent struct { + SubjectAddress util.Uint160 + Namespace string + Group string +} + +// RemoveSubjectFromGroupEvent represents "RemoveSubjectFromGroup" event emitted by the contract. +type RemoveSubjectFromGroupEvent struct { + SubjectAddress util.Uint160 + Namespace string + Group string +} + +// DeleteGroupEvent represents "DeleteGroup" event emitted by the contract. +type DeleteGroupEvent struct { + Namespace string + Group string +} + // Invoker is used by ContractReader to call various safe methods. type Invoker interface { Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) @@ -52,58 +141,669 @@ func New(actor Actor, hash util.Uint160) *Contract { return &Contract{ContractReader{actor, hash}, actor, hash} } -// Key invokes `key` method of contract. -func (c *ContractReader) Key(owner []byte) ([]stackitem.Item, error) { - return unwrap.Array(c.invoker.Call(c.hash, "key", owner)) -} - // Version invokes `version` method of contract. func (c *ContractReader) Version() (*big.Int, error) { return unwrap.BigInt(c.invoker.Call(c.hash, "version")) } -// AddKey creates a transaction invoking `addKey` method of the contract. +// 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) AddKey(owner []byte, keys []any) (util.Uint256, uint32, error) { - return c.actor.SendCall(c.hash, "addKey", owner, keys) +func (c *Contract) AddOwner(addr util.Uint160) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "addOwner", addr) } -// AddKeyTransaction creates a transaction invoking `addKey` method of the contract. +// 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) AddKeyTransaction(owner []byte, keys []any) (*transaction.Transaction, error) { - return c.actor.MakeCall(c.hash, "addKey", owner, keys) +func (c *Contract) AddOwnerTransaction(addr util.Uint160) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "addOwner", addr) } -// AddKeyUnsigned creates a transaction invoking `addKey` method of the contract. +// 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) AddKeyUnsigned(owner []byte, keys []any) (*transaction.Transaction, error) { - return c.actor.MakeUnsignedCall(c.hash, "addKey", nil, owner, keys) +func (c *Contract) AddOwnerUnsigned(addr util.Uint160) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "addOwner", nil, addr) } -// RemoveKey creates a transaction invoking `removeKey` method of the contract. +// 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. -func (c *Contract) RemoveKey(owner []byte, keys []any) (util.Uint256, uint32, error) { - return c.actor.SendCall(c.hash, "removeKey", owner, keys) +func (c *Contract) AddSubjectKey(addr util.Uint160, key *keys.PublicKey) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "addSubjectKey", addr, key) } -// RemoveKeyTransaction creates a transaction invoking `removeKey` method of the contract. +// AddSubjectKeyTransaction creates a transaction invoking `addSubjectKey` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. -func (c *Contract) RemoveKeyTransaction(owner []byte, keys []any) (*transaction.Transaction, error) { - return c.actor.MakeCall(c.hash, "removeKey", owner, keys) +func (c *Contract) AddSubjectKeyTransaction(addr util.Uint160, key *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "addSubjectKey", addr, key) } -// RemoveKeyUnsigned creates a transaction invoking `removeKey` method of the contract. +// AddSubjectKeyUnsigned creates a transaction invoking `addSubjectKey` 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) RemoveKeyUnsigned(owner []byte, keys []any) (*transaction.Transaction, error) { - return c.actor.MakeUnsignedCall(c.hash, "removeKey", nil, owner, keys) +func (c *Contract) AddSubjectKeyUnsigned(addr util.Uint160, key *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "addSubjectKey", nil, addr, key) +} + +// AddSubjectToGroup creates a transaction invoking `addSubjectToGroup` 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) AddSubjectToGroup(addr util.Uint160, group string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "addSubjectToGroup", addr, group) +} + +// AddSubjectToGroupTransaction creates a transaction invoking `addSubjectToGroup` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) AddSubjectToGroupTransaction(addr util.Uint160, group string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "addSubjectToGroup", addr, group) +} + +// AddSubjectToGroupUnsigned creates a transaction invoking `addSubjectToGroup` 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) AddSubjectToGroupUnsigned(addr util.Uint160, group string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "addSubjectToGroup", nil, addr, group) +} + +// AddSubjectToNamespace creates a transaction invoking `addSubjectToNamespace` 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) AddSubjectToNamespace(addr util.Uint160, ns string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "addSubjectToNamespace", addr, ns) +} + +// AddSubjectToNamespaceTransaction creates a transaction invoking `addSubjectToNamespace` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) AddSubjectToNamespaceTransaction(addr util.Uint160, ns string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "addSubjectToNamespace", addr, ns) +} + +// AddSubjectToNamespaceUnsigned creates a transaction invoking `addSubjectToNamespace` 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) AddSubjectToNamespaceUnsigned(addr util.Uint160, ns string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "addSubjectToNamespace", nil, addr, ns) +} + +// 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. +func (c *Contract) CreateGroup(ns string, group string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "createGroup", ns, group) +} + +// CreateGroupTransaction creates a transaction invoking `createGroup` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) CreateGroupTransaction(ns string, group string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "createGroup", ns, group) +} + +// CreateGroupUnsigned creates a transaction invoking `createGroup` 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) CreateGroupUnsigned(ns string, group string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "createGroup", nil, ns, group) +} + +// CreateNamespace creates a transaction invoking `createNamespace` 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) CreateNamespace(ns string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "createNamespace", ns) +} + +// CreateNamespaceTransaction creates a transaction invoking `createNamespace` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) CreateNamespaceTransaction(ns string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "createNamespace", ns) +} + +// CreateNamespaceUnsigned creates a transaction invoking `createNamespace` 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) CreateNamespaceUnsigned(ns string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "createNamespace", nil, ns) +} + +// CreateSubject creates a transaction invoking `createSubject` 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) CreateSubject(key *keys.PublicKey) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "createSubject", key) +} + +// CreateSubjectTransaction creates a transaction invoking `createSubject` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) CreateSubjectTransaction(key *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "createSubject", key) +} + +// CreateSubjectUnsigned creates a transaction invoking `createSubject` 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) CreateSubjectUnsigned(key *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "createSubject", nil, key) +} + +// DeleteGroup creates a transaction invoking `deleteGroup` 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) DeleteGroup(ns string, group string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "deleteGroup", ns, group) +} + +// DeleteGroupTransaction creates a transaction invoking `deleteGroup` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) DeleteGroupTransaction(ns string, group string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "deleteGroup", ns, group) +} + +// DeleteGroupUnsigned creates a transaction invoking `deleteGroup` 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) DeleteGroupUnsigned(ns string, group string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "deleteGroup", nil, ns, group) +} + +// 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. +func (c *Contract) DeleteSubject(addr util.Uint160) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "deleteSubject", addr) +} + +// DeleteSubjectTransaction creates a transaction invoking `deleteSubject` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) DeleteSubjectTransaction(addr util.Uint160) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "deleteSubject", addr) +} + +// DeleteSubjectUnsigned creates a transaction invoking `deleteSubject` 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) DeleteSubjectUnsigned(addr util.Uint160) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "deleteSubject", nil, addr) +} + +// DeleteSubjectKV creates a transaction invoking `deleteSubjectKV` 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) DeleteSubjectKV(addr util.Uint160, key string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "deleteSubjectKV", addr, key) +} + +// DeleteSubjectKVTransaction creates a transaction invoking `deleteSubjectKV` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) DeleteSubjectKVTransaction(addr util.Uint160, key string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "deleteSubjectKV", addr, key) +} + +// DeleteSubjectKVUnsigned creates a transaction invoking `deleteSubjectKV` 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) DeleteSubjectKVUnsigned(addr util.Uint160, key string) (*transaction.Transaction, error) { + 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, group string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "getGroup", ns, group) +} + +// 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, group string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "getGroup", ns, group) +} + +// 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, group string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "getGroup", nil, ns, group) +} + +// 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, group string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "getGroupExtended", ns, group) +} + +// 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, group string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "getGroupExtended", ns, group) +} + +// 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, group string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "getGroupExtended", nil, ns, group) +} + +// 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, group string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "listGroupSubjects", ns, group) +} + +// 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, group string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "listGroupSubjects", ns, group) +} + +// 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, group string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "listGroupSubjects", nil, ns, group) +} + +// 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. +func (c *Contract) RemoveSubjectFromGroup(addr util.Uint160, ns string, group string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "removeSubjectFromGroup", addr, ns, group) +} + +// RemoveSubjectFromGroupTransaction creates a transaction invoking `removeSubjectFromGroup` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) RemoveSubjectFromGroupTransaction(addr util.Uint160, ns string, group string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "removeSubjectFromGroup", addr, ns, group) +} + +// RemoveSubjectFromGroupUnsigned creates a transaction invoking `removeSubjectFromGroup` 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) RemoveSubjectFromGroupUnsigned(addr util.Uint160, ns string, group string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "removeSubjectFromGroup", nil, addr, ns, group) +} + +// RemoveSubjectFromNamespace creates a transaction invoking `removeSubjectFromNamespace` 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) RemoveSubjectFromNamespace(addr util.Uint160) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "removeSubjectFromNamespace", addr) +} + +// RemoveSubjectFromNamespaceTransaction creates a transaction invoking `removeSubjectFromNamespace` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) RemoveSubjectFromNamespaceTransaction(addr util.Uint160) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "removeSubjectFromNamespace", addr) +} + +// RemoveSubjectFromNamespaceUnsigned creates a transaction invoking `removeSubjectFromNamespace` 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) RemoveSubjectFromNamespaceUnsigned(addr util.Uint160) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "removeSubjectFromNamespace", nil, addr) +} + +// RemoveSubjectKey creates a transaction invoking `removeSubjectKey` 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) RemoveSubjectKey(addr util.Uint160, key *keys.PublicKey) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "removeSubjectKey", addr, key) +} + +// RemoveSubjectKeyTransaction creates a transaction invoking `removeSubjectKey` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) RemoveSubjectKeyTransaction(addr util.Uint160, key *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "removeSubjectKey", addr, key) +} + +// RemoveSubjectKeyUnsigned creates a transaction invoking `removeSubjectKey` 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) RemoveSubjectKeyUnsigned(addr util.Uint160, key *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "removeSubjectKey", nil, addr, key) +} + +// SetSubjectKV creates a transaction invoking `setSubjectKV` 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) SetSubjectKV(addr util.Uint160, key string, val string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "setSubjectKV", addr, key, val) +} + +// SetSubjectKVTransaction creates a transaction invoking `setSubjectKV` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) SetSubjectKVTransaction(addr util.Uint160, key string, val string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "setSubjectKV", addr, key, val) +} + +// SetSubjectKVUnsigned creates a transaction invoking `setSubjectKV` 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) SetSubjectKVUnsigned(addr util.Uint160, key string, val string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "setSubjectKV", nil, addr, key, val) +} + +// SetSubjectName creates a transaction invoking `setSubjectName` 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) SetSubjectName(addr util.Uint160, name string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "setSubjectName", addr, name) +} + +// SetSubjectNameTransaction creates a transaction invoking `setSubjectName` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) SetSubjectNameTransaction(addr util.Uint160, name string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "setSubjectName", addr, name) +} + +// SetSubjectNameUnsigned creates a transaction invoking `setSubjectName` 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) SetSubjectNameUnsigned(addr util.Uint160, name string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "setSubjectName", nil, addr, name) } // Update creates a transaction invoking `update` method of the contract. @@ -127,3 +827,1080 @@ func (c *Contract) UpdateTransaction(script []byte, manifest []byte, data any) ( func (c *Contract) UpdateUnsigned(script []byte, manifest []byte, data any) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(c.hash, "update", nil, script, manifest, data) } + +// CreateSubjectEventsFromApplicationLog retrieves a set of all emitted events +// with "CreateSubject" name from the provided [result.ApplicationLog]. +func CreateSubjectEventsFromApplicationLog(log *result.ApplicationLog) ([]*CreateSubjectEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*CreateSubjectEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "CreateSubject" { + continue + } + event := new(CreateSubjectEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize CreateSubjectEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to CreateSubjectEvent or +// returns an error if it's not possible to do to so. +func (e *CreateSubjectEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.SubjectAddress, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectAddress: %w", err) + } + + return nil +} + +// AddSubjectKeyEventsFromApplicationLog retrieves a set of all emitted events +// with "AddSubjectKey" name from the provided [result.ApplicationLog]. +func AddSubjectKeyEventsFromApplicationLog(log *result.ApplicationLog) ([]*AddSubjectKeyEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*AddSubjectKeyEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "AddSubjectKey" { + continue + } + event := new(AddSubjectKeyEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize AddSubjectKeyEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to AddSubjectKeyEvent or +// returns an error if it's not possible to do to so. +func (e *AddSubjectKeyEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.SubjectAddress, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectAddress: %w", err) + } + + index++ + e.SubjectKey, err = func(item stackitem.Item) (*keys.PublicKey, error) { + b, err := item.TryBytes() + if err != nil { + return nil, err + } + k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256()) + if err != nil { + return nil, err + } + return k, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectKey: %w", err) + } + + return nil +} + +// RemoveSubjectKeyEventsFromApplicationLog retrieves a set of all emitted events +// with "RemoveSubjectKey" name from the provided [result.ApplicationLog]. +func RemoveSubjectKeyEventsFromApplicationLog(log *result.ApplicationLog) ([]*RemoveSubjectKeyEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*RemoveSubjectKeyEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "RemoveSubjectKey" { + continue + } + event := new(RemoveSubjectKeyEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize RemoveSubjectKeyEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to RemoveSubjectKeyEvent or +// returns an error if it's not possible to do to so. +func (e *RemoveSubjectKeyEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.SubjectAddress, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectAddress: %w", err) + } + + index++ + e.SubjectKey, err = func(item stackitem.Item) (*keys.PublicKey, error) { + b, err := item.TryBytes() + if err != nil { + return nil, err + } + k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256()) + if err != nil { + return nil, err + } + return k, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectKey: %w", err) + } + + return nil +} + +// SetSubjectNameEventsFromApplicationLog retrieves a set of all emitted events +// with "SetSubjectName" name from the provided [result.ApplicationLog]. +func SetSubjectNameEventsFromApplicationLog(log *result.ApplicationLog) ([]*SetSubjectNameEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*SetSubjectNameEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "SetSubjectName" { + continue + } + event := new(SetSubjectNameEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize SetSubjectNameEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to SetSubjectNameEvent or +// returns an error if it's not possible to do to so. +func (e *SetSubjectNameEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.SubjectAddress, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectAddress: %w", err) + } + + index++ + e.Name, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Name: %w", err) + } + + return nil +} + +// SetSubjectKVEventsFromApplicationLog retrieves a set of all emitted events +// with "SetSubjectKV" name from the provided [result.ApplicationLog]. +func SetSubjectKVEventsFromApplicationLog(log *result.ApplicationLog) ([]*SetSubjectKVEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*SetSubjectKVEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "SetSubjectKV" { + continue + } + event := new(SetSubjectKVEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize SetSubjectKVEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to SetSubjectKVEvent or +// returns an error if it's not possible to do to so. +func (e *SetSubjectKVEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 3 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.SubjectAddress, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectAddress: %w", err) + } + + index++ + e.Key, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Key: %w", err) + } + + index++ + e.Value, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Value: %w", err) + } + + return nil +} + +// DeleteSubjectKVEventsFromApplicationLog retrieves a set of all emitted events +// with "DeleteSubjectKV" name from the provided [result.ApplicationLog]. +func DeleteSubjectKVEventsFromApplicationLog(log *result.ApplicationLog) ([]*DeleteSubjectKVEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*DeleteSubjectKVEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "DeleteSubjectKV" { + continue + } + event := new(DeleteSubjectKVEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize DeleteSubjectKVEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to DeleteSubjectKVEvent or +// returns an error if it's not possible to do to so. +func (e *DeleteSubjectKVEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.SubjectAddress, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectAddress: %w", err) + } + + index++ + e.Key, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Key: %w", err) + } + + return nil +} + +// DeleteSubjectEventsFromApplicationLog retrieves a set of all emitted events +// with "DeleteSubject" name from the provided [result.ApplicationLog]. +func DeleteSubjectEventsFromApplicationLog(log *result.ApplicationLog) ([]*DeleteSubjectEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*DeleteSubjectEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "DeleteSubject" { + continue + } + event := new(DeleteSubjectEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize DeleteSubjectEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to DeleteSubjectEvent or +// returns an error if it's not possible to do to so. +func (e *DeleteSubjectEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.SubjectAddress, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectAddress: %w", err) + } + + return nil +} + +// CreateNamespaceEventsFromApplicationLog retrieves a set of all emitted events +// with "CreateNamespace" name from the provided [result.ApplicationLog]. +func CreateNamespaceEventsFromApplicationLog(log *result.ApplicationLog) ([]*CreateNamespaceEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*CreateNamespaceEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "CreateNamespace" { + continue + } + event := new(CreateNamespaceEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize CreateNamespaceEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to CreateNamespaceEvent or +// returns an error if it's not possible to do to so. +func (e *CreateNamespaceEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.Namespace, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Namespace: %w", err) + } + + return nil +} + +// AddSubjectToNamespaceEventsFromApplicationLog retrieves a set of all emitted events +// with "AddSubjectToNamespace" name from the provided [result.ApplicationLog]. +func AddSubjectToNamespaceEventsFromApplicationLog(log *result.ApplicationLog) ([]*AddSubjectToNamespaceEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*AddSubjectToNamespaceEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "AddSubjectToNamespace" { + continue + } + event := new(AddSubjectToNamespaceEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize AddSubjectToNamespaceEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to AddSubjectToNamespaceEvent or +// returns an error if it's not possible to do to so. +func (e *AddSubjectToNamespaceEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.SubjectAddress, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectAddress: %w", err) + } + + index++ + e.Namespace, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Namespace: %w", err) + } + + return nil +} + +// RemoveSubjectFromNamespaceEventsFromApplicationLog retrieves a set of all emitted events +// with "RemoveSubjectFromNamespace" name from the provided [result.ApplicationLog]. +func RemoveSubjectFromNamespaceEventsFromApplicationLog(log *result.ApplicationLog) ([]*RemoveSubjectFromNamespaceEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*RemoveSubjectFromNamespaceEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "RemoveSubjectFromNamespace" { + continue + } + event := new(RemoveSubjectFromNamespaceEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize RemoveSubjectFromNamespaceEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to RemoveSubjectFromNamespaceEvent or +// returns an error if it's not possible to do to so. +func (e *RemoveSubjectFromNamespaceEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.SubjectAddress, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectAddress: %w", err) + } + + index++ + e.Namespace, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Namespace: %w", err) + } + + return nil +} + +// CreateGroupEventsFromApplicationLog retrieves a set of all emitted events +// with "CreateGroup" name from the provided [result.ApplicationLog]. +func CreateGroupEventsFromApplicationLog(log *result.ApplicationLog) ([]*CreateGroupEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*CreateGroupEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "CreateGroup" { + continue + } + event := new(CreateGroupEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize CreateGroupEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to CreateGroupEvent or +// returns an error if it's not possible to do to so. +func (e *CreateGroupEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.Namespace, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Namespace: %w", err) + } + + index++ + e.Group, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Group: %w", err) + } + + return nil +} + +// AddSubjectToGroupEventsFromApplicationLog retrieves a set of all emitted events +// with "AddSubjectToGroup" name from the provided [result.ApplicationLog]. +func AddSubjectToGroupEventsFromApplicationLog(log *result.ApplicationLog) ([]*AddSubjectToGroupEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*AddSubjectToGroupEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "AddSubjectToGroup" { + continue + } + event := new(AddSubjectToGroupEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize AddSubjectToGroupEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to AddSubjectToGroupEvent or +// returns an error if it's not possible to do to so. +func (e *AddSubjectToGroupEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 3 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.SubjectAddress, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectAddress: %w", err) + } + + index++ + e.Namespace, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Namespace: %w", err) + } + + index++ + e.Group, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Group: %w", err) + } + + return nil +} + +// RemoveSubjectFromGroupEventsFromApplicationLog retrieves a set of all emitted events +// with "RemoveSubjectFromGroup" name from the provided [result.ApplicationLog]. +func RemoveSubjectFromGroupEventsFromApplicationLog(log *result.ApplicationLog) ([]*RemoveSubjectFromGroupEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*RemoveSubjectFromGroupEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "RemoveSubjectFromGroup" { + continue + } + event := new(RemoveSubjectFromGroupEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize RemoveSubjectFromGroupEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to RemoveSubjectFromGroupEvent or +// returns an error if it's not possible to do to so. +func (e *RemoveSubjectFromGroupEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 3 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.SubjectAddress, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field SubjectAddress: %w", err) + } + + index++ + e.Namespace, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Namespace: %w", err) + } + + index++ + e.Group, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Group: %w", err) + } + + return nil +} + +// DeleteGroupEventsFromApplicationLog retrieves a set of all emitted events +// with "DeleteGroup" name from the provided [result.ApplicationLog]. +func DeleteGroupEventsFromApplicationLog(log *result.ApplicationLog) ([]*DeleteGroupEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*DeleteGroupEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "DeleteGroup" { + continue + } + event := new(DeleteGroupEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize DeleteGroupEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to DeleteGroupEvent or +// returns an error if it's not possible to do to so. +func (e *DeleteGroupEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.Namespace, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Namespace: %w", err) + } + + index++ + e.Group, err = func(item stackitem.Item) (string, error) { + b, err := item.TryBytes() + if err != nil { + return "", err + } + if !utf8.Valid(b) { + return "", errors.New("not a UTF-8 string") + } + return string(b), nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Group: %w", err) + } + + return nil +}