// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. // Package container contains RPC wrappers for Container contract. package container 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" "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" ) // PutSuccessEvent represents "PutSuccess" event emitted by the contract. type PutSuccessEvent struct { ContainerID util.Uint256 PublicKey *keys.PublicKey } // DeleteSuccessEvent represents "DeleteSuccess" event emitted by the contract. type DeleteSuccessEvent struct { ContainerID util.Uint256 } // SetEACLSuccessEvent represents "SetEACLSuccess" event emitted by the contract. type SetEACLSuccessEvent struct { ContainerID []byte PublicKey *keys.PublicKey } // StartEstimationEvent represents "StartEstimation" event emitted by the contract. type StartEstimationEvent struct { Epoch *big.Int } // StopEstimationEvent represents "StopEstimation" event emitted by the contract. type StopEstimationEvent struct { Epoch *big.Int } // 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. type Actor interface { Invoker MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) MakeRun(script []byte) (*transaction.Transaction, error) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) SendRun(script []byte) (util.Uint256, uint32, error) } // ContractReader implements safe contract methods. type ContractReader struct { invoker Invoker hash util.Uint160 } // Contract implements all contract methods. type Contract struct { ContractReader actor Actor hash util.Uint160 } // NewReader creates an instance of ContractReader using provided contract hash and the given Invoker. func NewReader(invoker Invoker, hash util.Uint160) *ContractReader { return &ContractReader{invoker, hash} } // New creates an instance of Contract using provided contract hash and the given Actor. func New(actor Actor, hash util.Uint160) *Contract { return &Contract{ContractReader{actor, hash}, actor, hash} } // ContainersOf invokes `containersOf` method of contract. func (c *ContractReader) ContainersOf(owner []byte) (uuid.UUID, result.Iterator, error) { return unwrap.SessionIterator(c.invoker.Call(c.hash, "containersOf", owner)) } // ContainersOfExpanded is similar to ContainersOf (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) ContainersOfExpanded(owner []byte, _numOfIteratorItems int) ([]stackitem.Item, error) { return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "containersOf", _numOfIteratorItems, owner)) } // Count invokes `count` method of contract. func (c *ContractReader) Count() (*big.Int, error) { return unwrap.BigInt(c.invoker.Call(c.hash, "count")) } // DeletionInfo invokes `deletionInfo` method of contract. func (c *ContractReader) DeletionInfo(containerID []byte) ([]stackitem.Item, error) { return unwrap.Array(c.invoker.Call(c.hash, "deletionInfo", containerID)) } // EACL invokes `eACL` method of contract. func (c *ContractReader) EACL(containerID []byte) ([]stackitem.Item, error) { return unwrap.Array(c.invoker.Call(c.hash, "eACL", containerID)) } // Get invokes `get` method of contract. func (c *ContractReader) Get(containerID []byte) ([]stackitem.Item, error) { return unwrap.Array(c.invoker.Call(c.hash, "get", containerID)) } // GetContainerSize invokes `getContainerSize` method of contract. func (c *ContractReader) GetContainerSize(id []byte) ([]stackitem.Item, error) { return unwrap.Array(c.invoker.Call(c.hash, "getContainerSize", id)) } // IterateContainerSizes invokes `iterateContainerSizes` method of contract. func (c *ContractReader) IterateContainerSizes(epoch *big.Int) (uuid.UUID, result.Iterator, error) { return unwrap.SessionIterator(c.invoker.Call(c.hash, "iterateContainerSizes", epoch)) } // IterateContainerSizesExpanded is similar to IterateContainerSizes (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) IterateContainerSizesExpanded(epoch *big.Int, _numOfIteratorItems int) ([]stackitem.Item, error) { return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "iterateContainerSizes", _numOfIteratorItems, epoch)) } // List invokes `list` method of contract. func (c *ContractReader) List(owner []byte) ([]stackitem.Item, error) { return unwrap.Array(c.invoker.Call(c.hash, "list", owner)) } // ListContainerSizes invokes `listContainerSizes` method of contract. func (c *ContractReader) ListContainerSizes(epoch *big.Int) ([]stackitem.Item, error) { return unwrap.Array(c.invoker.Call(c.hash, "listContainerSizes", epoch)) } // Owner invokes `owner` method of contract. func (c *ContractReader) Owner(containerID []byte) ([]byte, error) { return unwrap.Bytes(c.invoker.Call(c.hash, "owner", containerID)) } // Version invokes `version` method of contract. func (c *ContractReader) Version() (*big.Int, error) { return unwrap.BigInt(c.invoker.Call(c.hash, "version")) } // Delete creates a transaction invoking `delete` 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) Delete(containerID util.Uint256, signature []byte, publicKey *keys.PublicKey, token []byte) (util.Uint256, uint32, error) { return c.actor.SendCall(c.hash, "delete", containerID, signature, publicKey, token) } // DeleteTransaction creates a transaction invoking `delete` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. func (c *Contract) DeleteTransaction(containerID util.Uint256, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) { return c.actor.MakeCall(c.hash, "delete", containerID, signature, publicKey, token) } // DeleteUnsigned creates a transaction invoking `delete` 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) DeleteUnsigned(containerID util.Uint256, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(c.hash, "delete", nil, containerID, signature, publicKey, token) } // NewEpoch creates a transaction invoking `newEpoch` 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) NewEpoch(epochNum *big.Int) (util.Uint256, uint32, error) { return c.actor.SendCall(c.hash, "newEpoch", epochNum) } // NewEpochTransaction creates a transaction invoking `newEpoch` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. func (c *Contract) NewEpochTransaction(epochNum *big.Int) (*transaction.Transaction, error) { return c.actor.MakeCall(c.hash, "newEpoch", epochNum) } // NewEpochUnsigned creates a transaction invoking `newEpoch` 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) NewEpochUnsigned(epochNum *big.Int) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(c.hash, "newEpoch", nil, epochNum) } // Put creates a transaction invoking `put` 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) Put(container []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (util.Uint256, uint32, error) { return c.actor.SendCall(c.hash, "put", container, signature, publicKey, token) } // PutTransaction creates a transaction invoking `put` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. func (c *Contract) PutTransaction(container []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) { return c.actor.MakeCall(c.hash, "put", container, signature, publicKey, token) } // PutUnsigned creates a transaction invoking `put` 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) PutUnsigned(container []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(c.hash, "put", nil, container, signature, publicKey, token) } // PutContainerSize creates a transaction invoking `putContainerSize` 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) PutContainerSize(epoch *big.Int, cid []byte, usedSize *big.Int, pubKey *keys.PublicKey) (util.Uint256, uint32, error) { return c.actor.SendCall(c.hash, "putContainerSize", epoch, cid, usedSize, pubKey) } // PutContainerSizeTransaction creates a transaction invoking `putContainerSize` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. func (c *Contract) PutContainerSizeTransaction(epoch *big.Int, cid []byte, usedSize *big.Int, pubKey *keys.PublicKey) (*transaction.Transaction, error) { return c.actor.MakeCall(c.hash, "putContainerSize", epoch, cid, usedSize, pubKey) } // PutContainerSizeUnsigned creates a transaction invoking `putContainerSize` 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) PutContainerSizeUnsigned(epoch *big.Int, cid []byte, usedSize *big.Int, pubKey *keys.PublicKey) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(c.hash, "putContainerSize", nil, epoch, cid, usedSize, pubKey) } // PutNamed creates a transaction invoking `putNamed` 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) PutNamed(container []byte, signature []byte, publicKey *keys.PublicKey, token []byte, name string, zone string) (util.Uint256, uint32, error) { return c.actor.SendCall(c.hash, "putNamed", container, signature, publicKey, token, name, zone) } // PutNamedTransaction creates a transaction invoking `putNamed` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. func (c *Contract) PutNamedTransaction(container []byte, signature []byte, publicKey *keys.PublicKey, token []byte, name string, zone string) (*transaction.Transaction, error) { return c.actor.MakeCall(c.hash, "putNamed", container, signature, publicKey, token, name, zone) } // PutNamedUnsigned creates a transaction invoking `putNamed` 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) PutNamedUnsigned(container []byte, signature []byte, publicKey *keys.PublicKey, token []byte, name string, zone string) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(c.hash, "putNamed", nil, container, signature, publicKey, token, name, zone) } // 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(admin util.Uint160) (util.Uint256, uint32, error) { return c.actor.SendCall(c.hash, "setAdmin", admin) } // 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(admin util.Uint160) (*transaction.Transaction, error) { return c.actor.MakeCall(c.hash, "setAdmin", admin) } // 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(admin util.Uint160) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(c.hash, "setAdmin", nil, admin) } // SetEACL creates a transaction invoking `setEACL` 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) SetEACL(eACL []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (util.Uint256, uint32, error) { return c.actor.SendCall(c.hash, "setEACL", eACL, signature, publicKey, token) } // SetEACLTransaction creates a transaction invoking `setEACL` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. func (c *Contract) SetEACLTransaction(eACL []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) { return c.actor.MakeCall(c.hash, "setEACL", eACL, signature, publicKey, token) } // SetEACLUnsigned creates a transaction invoking `setEACL` 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) SetEACLUnsigned(eACL []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(c.hash, "setEACL", nil, eACL, signature, publicKey, token) } // StartContainerEstimation creates a transaction invoking `startContainerEstimation` 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) StartContainerEstimation(epoch *big.Int) (util.Uint256, uint32, error) { return c.actor.SendCall(c.hash, "startContainerEstimation", epoch) } // StartContainerEstimationTransaction creates a transaction invoking `startContainerEstimation` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. func (c *Contract) StartContainerEstimationTransaction(epoch *big.Int) (*transaction.Transaction, error) { return c.actor.MakeCall(c.hash, "startContainerEstimation", epoch) } // StartContainerEstimationUnsigned creates a transaction invoking `startContainerEstimation` 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) StartContainerEstimationUnsigned(epoch *big.Int) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(c.hash, "startContainerEstimation", nil, epoch) } // StopContainerEstimation creates a transaction invoking `stopContainerEstimation` 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) StopContainerEstimation(epoch *big.Int) (util.Uint256, uint32, error) { return c.actor.SendCall(c.hash, "stopContainerEstimation", epoch) } // StopContainerEstimationTransaction creates a transaction invoking `stopContainerEstimation` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. func (c *Contract) StopContainerEstimationTransaction(epoch *big.Int) (*transaction.Transaction, error) { return c.actor.MakeCall(c.hash, "stopContainerEstimation", epoch) } // StopContainerEstimationUnsigned creates a transaction invoking `stopContainerEstimation` 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) StopContainerEstimationUnsigned(epoch *big.Int) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(c.hash, "stopContainerEstimation", nil, epoch) } // Update creates a transaction invoking `update` 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) Update(script []byte, manifest []byte, data any) (util.Uint256, uint32, error) { return c.actor.SendCall(c.hash, "update", script, manifest, data) } // UpdateTransaction creates a transaction invoking `update` method of the contract. // This transaction is signed, but not sent to the network, instead it's // returned to the caller. func (c *Contract) UpdateTransaction(script []byte, manifest []byte, data any) (*transaction.Transaction, error) { return c.actor.MakeCall(c.hash, "update", script, manifest, data) } // UpdateUnsigned creates a transaction invoking `update` 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) UpdateUnsigned(script []byte, manifest []byte, data any) (*transaction.Transaction, error) { return c.actor.MakeUnsignedCall(c.hash, "update", nil, script, manifest, data) } // PutSuccessEventsFromApplicationLog retrieves a set of all emitted events // with "PutSuccess" name from the provided [result.ApplicationLog]. func PutSuccessEventsFromApplicationLog(log *result.ApplicationLog) ([]*PutSuccessEvent, error) { if log == nil { return nil, errors.New("nil application log") } var res []*PutSuccessEvent for i, ex := range log.Executions { for j, e := range ex.Events { if e.Name != "PutSuccess" { continue } event := new(PutSuccessEvent) err := event.FromStackItem(e.Item) if err != nil { return nil, fmt.Errorf("failed to deserialize PutSuccessEvent from stackitem (execution #%d, event #%d): %w", i, j, err) } res = append(res, event) } } return res, nil } // FromStackItem converts provided [stackitem.Array] to PutSuccessEvent or // returns an error if it's not possible to do to so. func (e *PutSuccessEvent) 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.ContainerID, err = func(item stackitem.Item) (util.Uint256, error) { b, err := item.TryBytes() if err != nil { return util.Uint256{}, err } u, err := util.Uint256DecodeBytesBE(b) if err != nil { return util.Uint256{}, err } return u, nil }(arr[index]) if err != nil { return fmt.Errorf("field ContainerID: %w", err) } index++ e.PublicKey, 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 PublicKey: %w", err) } return nil } // DeleteSuccessEventsFromApplicationLog retrieves a set of all emitted events // with "DeleteSuccess" name from the provided [result.ApplicationLog]. func DeleteSuccessEventsFromApplicationLog(log *result.ApplicationLog) ([]*DeleteSuccessEvent, error) { if log == nil { return nil, errors.New("nil application log") } var res []*DeleteSuccessEvent for i, ex := range log.Executions { for j, e := range ex.Events { if e.Name != "DeleteSuccess" { continue } event := new(DeleteSuccessEvent) err := event.FromStackItem(e.Item) if err != nil { return nil, fmt.Errorf("failed to deserialize DeleteSuccessEvent from stackitem (execution #%d, event #%d): %w", i, j, err) } res = append(res, event) } } return res, nil } // FromStackItem converts provided [stackitem.Array] to DeleteSuccessEvent or // returns an error if it's not possible to do to so. func (e *DeleteSuccessEvent) 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.ContainerID, err = func(item stackitem.Item) (util.Uint256, error) { b, err := item.TryBytes() if err != nil { return util.Uint256{}, err } u, err := util.Uint256DecodeBytesBE(b) if err != nil { return util.Uint256{}, err } return u, nil }(arr[index]) if err != nil { return fmt.Errorf("field ContainerID: %w", err) } return nil } // SetEACLSuccessEventsFromApplicationLog retrieves a set of all emitted events // with "SetEACLSuccess" name from the provided [result.ApplicationLog]. func SetEACLSuccessEventsFromApplicationLog(log *result.ApplicationLog) ([]*SetEACLSuccessEvent, error) { if log == nil { return nil, errors.New("nil application log") } var res []*SetEACLSuccessEvent for i, ex := range log.Executions { for j, e := range ex.Events { if e.Name != "SetEACLSuccess" { continue } event := new(SetEACLSuccessEvent) err := event.FromStackItem(e.Item) if err != nil { return nil, fmt.Errorf("failed to deserialize SetEACLSuccessEvent from stackitem (execution #%d, event #%d): %w", i, j, err) } res = append(res, event) } } return res, nil } // FromStackItem converts provided [stackitem.Array] to SetEACLSuccessEvent or // returns an error if it's not possible to do to so. func (e *SetEACLSuccessEvent) 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.ContainerID, err = arr[index].TryBytes() if err != nil { return fmt.Errorf("field ContainerID: %w", err) } index++ e.PublicKey, 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 PublicKey: %w", err) } return nil } // StartEstimationEventsFromApplicationLog retrieves a set of all emitted events // with "StartEstimation" name from the provided [result.ApplicationLog]. func StartEstimationEventsFromApplicationLog(log *result.ApplicationLog) ([]*StartEstimationEvent, error) { if log == nil { return nil, errors.New("nil application log") } var res []*StartEstimationEvent for i, ex := range log.Executions { for j, e := range ex.Events { if e.Name != "StartEstimation" { continue } event := new(StartEstimationEvent) err := event.FromStackItem(e.Item) if err != nil { return nil, fmt.Errorf("failed to deserialize StartEstimationEvent from stackitem (execution #%d, event #%d): %w", i, j, err) } res = append(res, event) } } return res, nil } // FromStackItem converts provided [stackitem.Array] to StartEstimationEvent or // returns an error if it's not possible to do to so. func (e *StartEstimationEvent) 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.Epoch, err = arr[index].TryInteger() if err != nil { return fmt.Errorf("field Epoch: %w", err) } return nil } // StopEstimationEventsFromApplicationLog retrieves a set of all emitted events // with "StopEstimation" name from the provided [result.ApplicationLog]. func StopEstimationEventsFromApplicationLog(log *result.ApplicationLog) ([]*StopEstimationEvent, error) { if log == nil { return nil, errors.New("nil application log") } var res []*StopEstimationEvent for i, ex := range log.Executions { for j, e := range ex.Events { if e.Name != "StopEstimation" { continue } event := new(StopEstimationEvent) err := event.FromStackItem(e.Item) if err != nil { return nil, fmt.Errorf("failed to deserialize StopEstimationEvent from stackitem (execution #%d, event #%d): %w", i, j, err) } res = append(res, event) } } return res, nil } // FromStackItem converts provided [stackitem.Array] to StopEstimationEvent or // returns an error if it's not possible to do to so. func (e *StopEstimationEvent) 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.Epoch, err = arr[index].TryInteger() if err != nil { return fmt.Errorf("field Epoch: %w", err) } return nil }