From 901d5a4083a9453abea8b2d29f2929d20b0711eb Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 24 Oct 2023 19:51:22 +0300 Subject: [PATCH] [#47] Generate RPC bindings to contracts Signed-off-by: Evgenii Stratonikov --- Makefile | 12 + rpcclient/alphabet/client.go | 138 ++++++ rpcclient/audit/client.go | 128 +++++ rpcclient/balance/client.go | 549 +++++++++++++++++++++ rpcclient/container/client.go | 661 +++++++++++++++++++++++++ rpcclient/frostfs/client.go | 851 +++++++++++++++++++++++++++++++++ rpcclient/frostfsid/client.go | 129 +++++ rpcclient/netmap/client.go | 629 ++++++++++++++++++++++++ rpcclient/nns/client.go | 336 +++++++++++++ rpcclient/processing/client.go | 84 ++++ rpcclient/proxy/client.go | 84 ++++ rpcclient/reputation/client.go | 207 ++++++++ 12 files changed, 3808 insertions(+) create mode 100644 rpcclient/alphabet/client.go create mode 100644 rpcclient/audit/client.go create mode 100644 rpcclient/balance/client.go create mode 100644 rpcclient/container/client.go create mode 100644 rpcclient/frostfs/client.go create mode 100644 rpcclient/frostfsid/client.go create mode 100644 rpcclient/netmap/client.go create mode 100644 rpcclient/nns/client.go create mode 100644 rpcclient/processing/client.go create mode 100644 rpcclient/proxy/client.go create mode 100644 rpcclient/reputation/client.go diff --git a/Makefile b/Makefile index b80cddc..48bed61 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ alphabet_sc = alphabet morph_sc = audit balance container frostfsid netmap proxy reputation mainnet_sc = frostfs processing nns_sc = nns +all_sc = $(alphabet_sc) $(morph_sc) $(mainnet_sc) $(nns_sc) define sc_template $(2)$(1)/$(1)_contract.nef: $(2)$(1)/$(1)_contract.go @@ -49,6 +50,17 @@ neo-go: @go list -f '{{.Path}}/...@{{.Version}}' -m github.com/nspcc-dev/neo-go \ | xargs go install -v +generate-wrapper.%: + @mkdir -p ./rpcclient/$* + @# Note, that bindings file is currently missing: is can be emitted by compiler, + @# but this leads to a large amount of code duplication. It can be written by hand, + @# in case we need to override the type of some variables. + @# --config $*/$*.bindings.yml + @# Unfortunately, primitive integer types are not yet supported. + $(NEOGO) contract generate-rpcwrapper --manifest=$*/config.json --out ./rpcclient/$*/client.go + +generate-wrappers: build $(foreach sc,$(all_sc),generate-wrapper.$(sc)) + test: @go test ./tests/... diff --git a/rpcclient/alphabet/client.go b/rpcclient/alphabet/client.go new file mode 100644 index 0000000..fd16f5a --- /dev/null +++ b/rpcclient/alphabet/client.go @@ -0,0 +1,138 @@ +// Package alphabet contains RPC wrappers for Alphabet contract. +// +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. +package alphabet + +import ( + "github.com/nspcc-dev/neo-go/pkg/core/transaction" + "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" + "math/big" +) + +// Invoker is used by ContractReader to call various safe methods. +type Invoker interface { + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, 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} +} + +// Gas invokes `gas` method of contract. +func (c *ContractReader) Gas() (*big.Int, error) { + return unwrap.BigInt(c.invoker.Call(c.hash, "gas")) +} + +// Name invokes `name` method of contract. +func (c *ContractReader) Name() (string, error) { + return unwrap.UTF8String(c.invoker.Call(c.hash, "name")) +} + +// Neo invokes `neo` method of contract. +func (c *ContractReader) Neo() (*big.Int, error) { + return unwrap.BigInt(c.invoker.Call(c.hash, "neo")) +} + +// Version invokes `version` method of contract. +func (c *ContractReader) Version() (*big.Int, error) { + return unwrap.BigInt(c.invoker.Call(c.hash, "version")) +} + +// Emit creates a transaction invoking `emit` 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) Emit() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "emit") +} + +// EmitTransaction creates a transaction invoking `emit` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) EmitTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "emit") +} + +// EmitUnsigned creates a transaction invoking `emit` 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) EmitUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "emit", nil) +} + +// 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) +} + +// Vote creates a transaction invoking `vote` 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) Vote(epoch *big.Int, candidates []any) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "vote", epoch, candidates) +} + +// VoteTransaction creates a transaction invoking `vote` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) VoteTransaction(epoch *big.Int, candidates []any) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "vote", epoch, candidates) +} + +// VoteUnsigned creates a transaction invoking `vote` 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) VoteUnsigned(epoch *big.Int, candidates []any) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "vote", nil, epoch, candidates) +} diff --git a/rpcclient/audit/client.go b/rpcclient/audit/client.go new file mode 100644 index 0000000..8bb7a66 --- /dev/null +++ b/rpcclient/audit/client.go @@ -0,0 +1,128 @@ +// Package audit contains RPC wrappers for Audit contract. +// +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. +package audit + +import ( + "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" +) + +// Invoker is used by ContractReader to call various safe methods. +type Invoker interface { + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, 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} +} + +// Get invokes `get` method of contract. +func (c *ContractReader) Get(id []byte) ([]byte, error) { + return unwrap.Bytes(c.invoker.Call(c.hash, "get", id)) +} + +// List invokes `list` method of contract. +func (c *ContractReader) List() ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "list")) +} + +// ListByCID invokes `listByCID` method of contract. +func (c *ContractReader) ListByCID(epoch *big.Int, cid []byte) ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "listByCID", epoch, cid)) +} + +// ListByEpoch invokes `listByEpoch` method of contract. +func (c *ContractReader) ListByEpoch(epoch *big.Int) ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "listByEpoch", epoch)) +} + +// ListByNode invokes `listByNode` method of contract. +func (c *ContractReader) ListByNode(epoch *big.Int, cid []byte, key *keys.PublicKey) ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "listByNode", epoch, cid, key)) +} + +// Version invokes `version` method of contract. +func (c *ContractReader) Version() (*big.Int, error) { + return unwrap.BigInt(c.invoker.Call(c.hash, "version")) +} + +// 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(rawAuditResult []byte) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "put", rawAuditResult) +} + +// 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(rawAuditResult []byte) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "put", rawAuditResult) +} + +// 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(rawAuditResult []byte) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "put", nil, rawAuditResult) +} + +// 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) +} diff --git a/rpcclient/balance/client.go b/rpcclient/balance/client.go new file mode 100644 index 0000000..54b2bf6 --- /dev/null +++ b/rpcclient/balance/client.go @@ -0,0 +1,549 @@ +// Package balance contains RPC wrappers for Balance contract. +// +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. +package balance + +import ( + "errors" + "fmt" + "github.com/nspcc-dev/neo-go/pkg/core/transaction" + "github.com/nspcc-dev/neo-go/pkg/neorpc/result" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17" + "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" +) + +// LockEvent represents "Lock" event emitted by the contract. +type LockEvent struct { + TxID []byte + From util.Uint160 + To util.Uint160 + Amount *big.Int + Until *big.Int +} + +// TransferXEvent represents "TransferX" event emitted by the contract. +type TransferXEvent struct { + From util.Uint160 + To util.Uint160 + Amount *big.Int + Details []byte +} + +// MintEvent represents "Mint" event emitted by the contract. +type MintEvent struct { + To util.Uint160 + Amount *big.Int +} + +// BurnEvent represents "Burn" event emitted by the contract. +type BurnEvent struct { + From util.Uint160 + Amount *big.Int +} + +// Invoker is used by ContractReader to call various safe methods. +type Invoker interface { + nep17.Invoker +} + +// Actor is used by Contract to call state-changing methods. +type Actor interface { + Invoker + + nep17.Actor + + 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 { + nep17.TokenReader + invoker Invoker + hash util.Uint160 +} + +// Contract implements all contract methods. +type Contract struct { + ContractReader + nep17.TokenWriter + 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{*nep17.NewReader(invoker, hash), invoker, hash} +} + +// New creates an instance of Contract using provided contract hash and the given Actor. +func New(actor Actor, hash util.Uint160) *Contract { + var nep17t = nep17.New(actor, hash) + return &Contract{ContractReader{nep17t.TokenReader, actor, hash}, nep17t.TokenWriter, actor, hash} +} + +// Version invokes `version` method of contract. +func (c *ContractReader) Version() (*big.Int, error) { + return unwrap.BigInt(c.invoker.Call(c.hash, "version")) +} + +// Burn creates a transaction invoking `burn` 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) Burn(from util.Uint160, amount *big.Int, txDetails []byte) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "burn", from, amount, txDetails) +} + +// BurnTransaction creates a transaction invoking `burn` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) BurnTransaction(from util.Uint160, amount *big.Int, txDetails []byte) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "burn", from, amount, txDetails) +} + +// BurnUnsigned creates a transaction invoking `burn` 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) BurnUnsigned(from util.Uint160, amount *big.Int, txDetails []byte) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "burn", nil, from, amount, txDetails) +} + +// Lock creates a transaction invoking `lock` 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) Lock(txDetails []byte, from util.Uint160, to util.Uint160, amount *big.Int, until *big.Int) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "lock", txDetails, from, to, amount, until) +} + +// LockTransaction creates a transaction invoking `lock` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) LockTransaction(txDetails []byte, from util.Uint160, to util.Uint160, amount *big.Int, until *big.Int) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "lock", txDetails, from, to, amount, until) +} + +// LockUnsigned creates a transaction invoking `lock` 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) LockUnsigned(txDetails []byte, from util.Uint160, to util.Uint160, amount *big.Int, until *big.Int) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "lock", nil, txDetails, from, to, amount, until) +} + +// Mint creates a transaction invoking `mint` 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) Mint(to util.Uint160, amount *big.Int, txDetails []byte) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "mint", to, amount, txDetails) +} + +// MintTransaction creates a transaction invoking `mint` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) MintTransaction(to util.Uint160, amount *big.Int, txDetails []byte) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "mint", to, amount, txDetails) +} + +// MintUnsigned creates a transaction invoking `mint` 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) MintUnsigned(to util.Uint160, amount *big.Int, txDetails []byte) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "mint", nil, to, amount, txDetails) +} + +// 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) +} + +// TransferX creates a transaction invoking `transferX` 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) TransferX(from util.Uint160, to util.Uint160, amount *big.Int, details []byte) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "transferX", from, to, amount, details) +} + +// TransferXTransaction creates a transaction invoking `transferX` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) TransferXTransaction(from util.Uint160, to util.Uint160, amount *big.Int, details []byte) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "transferX", from, to, amount, details) +} + +// TransferXUnsigned creates a transaction invoking `transferX` 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) TransferXUnsigned(from util.Uint160, to util.Uint160, amount *big.Int, details []byte) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "transferX", nil, from, to, amount, details) +} + +// 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) +} + +// LockEventsFromApplicationLog retrieves a set of all emitted events +// with "Lock" name from the provided [result.ApplicationLog]. +func LockEventsFromApplicationLog(log *result.ApplicationLog) ([]*LockEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*LockEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "Lock" { + continue + } + event := new(LockEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize LockEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to LockEvent or +// returns an error if it's not possible to do to so. +func (e *LockEvent) 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) != 5 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.TxID, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field TxID: %w", err) + } + + index++ + e.From, 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 From: %w", err) + } + + index++ + e.To, 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 To: %w", err) + } + + index++ + e.Amount, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Amount: %w", err) + } + + index++ + e.Until, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Until: %w", err) + } + + return nil +} + +// TransferXEventsFromApplicationLog retrieves a set of all emitted events +// with "TransferX" name from the provided [result.ApplicationLog]. +func TransferXEventsFromApplicationLog(log *result.ApplicationLog) ([]*TransferXEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*TransferXEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "TransferX" { + continue + } + event := new(TransferXEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize TransferXEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to TransferXEvent or +// returns an error if it's not possible to do to so. +func (e *TransferXEvent) 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) != 4 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.From, 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 From: %w", err) + } + + index++ + e.To, 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 To: %w", err) + } + + index++ + e.Amount, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Amount: %w", err) + } + + index++ + e.Details, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field Details: %w", err) + } + + return nil +} + +// MintEventsFromApplicationLog retrieves a set of all emitted events +// with "Mint" name from the provided [result.ApplicationLog]. +func MintEventsFromApplicationLog(log *result.ApplicationLog) ([]*MintEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*MintEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "Mint" { + continue + } + event := new(MintEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize MintEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to MintEvent or +// returns an error if it's not possible to do to so. +func (e *MintEvent) 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.To, 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 To: %w", err) + } + + index++ + e.Amount, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Amount: %w", err) + } + + return nil +} + +// BurnEventsFromApplicationLog retrieves a set of all emitted events +// with "Burn" name from the provided [result.ApplicationLog]. +func BurnEventsFromApplicationLog(log *result.ApplicationLog) ([]*BurnEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*BurnEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "Burn" { + continue + } + event := new(BurnEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize BurnEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to BurnEvent or +// returns an error if it's not possible to do to so. +func (e *BurnEvent) 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.From, 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 From: %w", err) + } + + index++ + e.Amount, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Amount: %w", err) + } + + return nil +} diff --git a/rpcclient/container/client.go b/rpcclient/container/client.go new file mode 100644 index 0000000..5625f0e --- /dev/null +++ b/rpcclient/container/client.go @@ -0,0 +1,661 @@ +// Package container contains RPC wrappers for Container contract. +// +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. +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 []byte +} + +// 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 []byte, 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 []byte, 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 []byte, 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) +} + +// 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 = arr[index].TryBytes() + 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 +} diff --git a/rpcclient/frostfs/client.go b/rpcclient/frostfs/client.go new file mode 100644 index 0000000..a5184df --- /dev/null +++ b/rpcclient/frostfs/client.go @@ -0,0 +1,851 @@ +// Package frostfs contains RPC wrappers for FrostFS contract. +// +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. +package frostfs + +import ( + "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" +) + +// DepositEvent represents "Deposit" event emitted by the contract. +type DepositEvent struct { + From util.Uint160 + Amount *big.Int + Receiver util.Uint160 + TxHash util.Uint256 +} + +// WithdrawEvent represents "Withdraw" event emitted by the contract. +type WithdrawEvent struct { + User util.Uint160 + Amount *big.Int + TxHash util.Uint256 +} + +// ChequeEvent represents "Cheque" event emitted by the contract. +type ChequeEvent struct { + Id []byte + User util.Uint160 + Amount *big.Int + LockAccount []byte +} + +// BindEvent represents "Bind" event emitted by the contract. +type BindEvent struct { + User []byte + Keys []any +} + +// UnbindEvent represents "Unbind" event emitted by the contract. +type UnbindEvent struct { + User []byte + Keys []any +} + +// AlphabetUpdateEvent represents "AlphabetUpdate" event emitted by the contract. +type AlphabetUpdateEvent struct { + Id []byte + Alphabet []any +} + +// SetConfigEvent represents "SetConfig" event emitted by the contract. +type SetConfigEvent struct { + Id []byte + Key []byte + Value []byte +} + +// Invoker is used by ContractReader to call various safe methods. +type Invoker interface { + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, 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} +} + +// AlphabetAddress invokes `alphabetAddress` method of contract. +func (c *ContractReader) AlphabetAddress() (util.Uint160, error) { + return unwrap.Uint160(c.invoker.Call(c.hash, "alphabetAddress")) +} + +// Config invokes `config` method of contract. +func (c *ContractReader) Config(key []byte) (any, error) { + return func(item stackitem.Item, err error) (any, error) { + if err != nil { + return nil, err + } + return item.Value(), error(nil) + }(unwrap.Item(c.invoker.Call(c.hash, "config", key))) +} + +// InnerRingCandidates invokes `innerRingCandidates` method of contract. +func (c *ContractReader) InnerRingCandidates() ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "innerRingCandidates")) +} + +// ListConfig invokes `listConfig` method of contract. +func (c *ContractReader) ListConfig() ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "listConfig")) +} + +// Version invokes `version` method of contract. +func (c *ContractReader) Version() (*big.Int, error) { + return unwrap.BigInt(c.invoker.Call(c.hash, "version")) +} + +// Bind creates a transaction invoking `bind` 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) Bind(user []byte, keys []any) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "bind", user, keys) +} + +// BindTransaction creates a transaction invoking `bind` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) BindTransaction(user []byte, keys []any) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "bind", user, keys) +} + +// BindUnsigned creates a transaction invoking `bind` 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) BindUnsigned(user []byte, keys []any) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "bind", nil, user, keys) +} + +// Cheque creates a transaction invoking `cheque` 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) Cheque(id []byte, user util.Uint160, amount *big.Int, lockAcc []byte) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "cheque", id, user, amount, lockAcc) +} + +// ChequeTransaction creates a transaction invoking `cheque` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) ChequeTransaction(id []byte, user util.Uint160, amount *big.Int, lockAcc []byte) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "cheque", id, user, amount, lockAcc) +} + +// ChequeUnsigned creates a transaction invoking `cheque` 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) ChequeUnsigned(id []byte, user util.Uint160, amount *big.Int, lockAcc []byte) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "cheque", nil, id, user, amount, lockAcc) +} + +// InnerRingCandidateAdd creates a transaction invoking `innerRingCandidateAdd` 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) InnerRingCandidateAdd(key *keys.PublicKey) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "innerRingCandidateAdd", key) +} + +// InnerRingCandidateAddTransaction creates a transaction invoking `innerRingCandidateAdd` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) InnerRingCandidateAddTransaction(key *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "innerRingCandidateAdd", key) +} + +// InnerRingCandidateAddUnsigned creates a transaction invoking `innerRingCandidateAdd` 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) InnerRingCandidateAddUnsigned(key *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "innerRingCandidateAdd", nil, key) +} + +// InnerRingCandidateRemove creates a transaction invoking `innerRingCandidateRemove` 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) InnerRingCandidateRemove(key *keys.PublicKey) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "innerRingCandidateRemove", key) +} + +// InnerRingCandidateRemoveTransaction creates a transaction invoking `innerRingCandidateRemove` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) InnerRingCandidateRemoveTransaction(key *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "innerRingCandidateRemove", key) +} + +// InnerRingCandidateRemoveUnsigned creates a transaction invoking `innerRingCandidateRemove` 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) InnerRingCandidateRemoveUnsigned(key *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "innerRingCandidateRemove", nil, key) +} + +// SetConfig creates a transaction invoking `setConfig` 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) SetConfig(id []byte, key []byte, val []byte) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "setConfig", id, key, val) +} + +// SetConfigTransaction creates a transaction invoking `setConfig` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) SetConfigTransaction(id []byte, key []byte, val []byte) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "setConfig", id, key, val) +} + +// SetConfigUnsigned creates a transaction invoking `setConfig` 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) SetConfigUnsigned(id []byte, key []byte, val []byte) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "setConfig", nil, id, key, val) +} + +// Unbind creates a transaction invoking `unbind` 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) Unbind(user []byte, keys []any) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "unbind", user, keys) +} + +// UnbindTransaction creates a transaction invoking `unbind` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) UnbindTransaction(user []byte, keys []any) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "unbind", user, keys) +} + +// UnbindUnsigned creates a transaction invoking `unbind` 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) UnbindUnsigned(user []byte, keys []any) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "unbind", nil, user, keys) +} + +// 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) +} + +// Withdraw creates a transaction invoking `withdraw` 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) Withdraw(user util.Uint160, amount *big.Int) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "withdraw", user, amount) +} + +// WithdrawTransaction creates a transaction invoking `withdraw` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) WithdrawTransaction(user util.Uint160, amount *big.Int) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "withdraw", user, amount) +} + +// WithdrawUnsigned creates a transaction invoking `withdraw` 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) WithdrawUnsigned(user util.Uint160, amount *big.Int) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "withdraw", nil, user, amount) +} + +// DepositEventsFromApplicationLog retrieves a set of all emitted events +// with "Deposit" name from the provided [result.ApplicationLog]. +func DepositEventsFromApplicationLog(log *result.ApplicationLog) ([]*DepositEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*DepositEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "Deposit" { + continue + } + event := new(DepositEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize DepositEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to DepositEvent or +// returns an error if it's not possible to do to so. +func (e *DepositEvent) 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) != 4 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.From, 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 From: %w", err) + } + + index++ + e.Amount, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Amount: %w", err) + } + + index++ + e.Receiver, 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 Receiver: %w", err) + } + + index++ + e.TxHash, 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 TxHash: %w", err) + } + + return nil +} + +// WithdrawEventsFromApplicationLog retrieves a set of all emitted events +// with "Withdraw" name from the provided [result.ApplicationLog]. +func WithdrawEventsFromApplicationLog(log *result.ApplicationLog) ([]*WithdrawEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*WithdrawEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "Withdraw" { + continue + } + event := new(WithdrawEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize WithdrawEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to WithdrawEvent or +// returns an error if it's not possible to do to so. +func (e *WithdrawEvent) 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.User, 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 User: %w", err) + } + + index++ + e.Amount, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Amount: %w", err) + } + + index++ + e.TxHash, 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 TxHash: %w", err) + } + + return nil +} + +// ChequeEventsFromApplicationLog retrieves a set of all emitted events +// with "Cheque" name from the provided [result.ApplicationLog]. +func ChequeEventsFromApplicationLog(log *result.ApplicationLog) ([]*ChequeEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*ChequeEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "Cheque" { + continue + } + event := new(ChequeEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize ChequeEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to ChequeEvent or +// returns an error if it's not possible to do to so. +func (e *ChequeEvent) 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) != 4 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.Id, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field Id: %w", err) + } + + index++ + e.User, 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 User: %w", err) + } + + index++ + e.Amount, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Amount: %w", err) + } + + index++ + e.LockAccount, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field LockAccount: %w", err) + } + + return nil +} + +// BindEventsFromApplicationLog retrieves a set of all emitted events +// with "Bind" name from the provided [result.ApplicationLog]. +func BindEventsFromApplicationLog(log *result.ApplicationLog) ([]*BindEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*BindEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "Bind" { + continue + } + event := new(BindEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize BindEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to BindEvent or +// returns an error if it's not possible to do to so. +func (e *BindEvent) 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.User, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field User: %w", err) + } + + index++ + e.Keys, err = func(item stackitem.Item) ([]any, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([]any, len(arr)) + for i := range res { + res[i], err = arr[i].Value(), error(nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + } + return res, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Keys: %w", err) + } + + return nil +} + +// UnbindEventsFromApplicationLog retrieves a set of all emitted events +// with "Unbind" name from the provided [result.ApplicationLog]. +func UnbindEventsFromApplicationLog(log *result.ApplicationLog) ([]*UnbindEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*UnbindEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "Unbind" { + continue + } + event := new(UnbindEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize UnbindEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to UnbindEvent or +// returns an error if it's not possible to do to so. +func (e *UnbindEvent) 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.User, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field User: %w", err) + } + + index++ + e.Keys, err = func(item stackitem.Item) ([]any, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([]any, len(arr)) + for i := range res { + res[i], err = arr[i].Value(), error(nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + } + return res, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Keys: %w", err) + } + + return nil +} + +// AlphabetUpdateEventsFromApplicationLog retrieves a set of all emitted events +// with "AlphabetUpdate" name from the provided [result.ApplicationLog]. +func AlphabetUpdateEventsFromApplicationLog(log *result.ApplicationLog) ([]*AlphabetUpdateEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*AlphabetUpdateEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "AlphabetUpdate" { + continue + } + event := new(AlphabetUpdateEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize AlphabetUpdateEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to AlphabetUpdateEvent or +// returns an error if it's not possible to do to so. +func (e *AlphabetUpdateEvent) 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.Id, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field Id: %w", err) + } + + index++ + e.Alphabet, err = func(item stackitem.Item) ([]any, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([]any, len(arr)) + for i := range res { + res[i], err = arr[i].Value(), error(nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + } + return res, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Alphabet: %w", err) + } + + return nil +} + +// SetConfigEventsFromApplicationLog retrieves a set of all emitted events +// with "SetConfig" name from the provided [result.ApplicationLog]. +func SetConfigEventsFromApplicationLog(log *result.ApplicationLog) ([]*SetConfigEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*SetConfigEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "SetConfig" { + continue + } + event := new(SetConfigEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize SetConfigEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to SetConfigEvent or +// returns an error if it's not possible to do to so. +func (e *SetConfigEvent) 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.Id, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field Id: %w", err) + } + + index++ + e.Key, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field Key: %w", err) + } + + index++ + e.Value, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field Value: %w", err) + } + + return nil +} diff --git a/rpcclient/frostfsid/client.go b/rpcclient/frostfsid/client.go new file mode 100644 index 0000000..03b1369 --- /dev/null +++ b/rpcclient/frostfsid/client.go @@ -0,0 +1,129 @@ +// Package identity contains RPC wrappers for Identity contract. +// +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. +package identity + +import ( + "github.com/nspcc-dev/neo-go/pkg/core/transaction" + "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" +) + +// Invoker is used by ContractReader to call various safe methods. +type Invoker interface { + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, 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} +} + +// 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. +// 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) +} + +// AddKeyTransaction creates a transaction invoking `addKey` 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) +} + +// AddKeyUnsigned creates a transaction invoking `addKey` 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) +} + +// RemoveKey creates a transaction invoking `removeKey` 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) +} + +// RemoveKeyTransaction creates a transaction invoking `removeKey` 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) +} + +// RemoveKeyUnsigned creates a transaction invoking `removeKey` 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) +} + +// 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) +} diff --git a/rpcclient/netmap/client.go b/rpcclient/netmap/client.go new file mode 100644 index 0000000..ed207a1 --- /dev/null +++ b/rpcclient/netmap/client.go @@ -0,0 +1,629 @@ +// Package netmap contains RPC wrappers for Netmap contract. +// +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. +package netmap + +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" +) + +// AddPeerEvent represents "AddPeer" event emitted by the contract. +type AddPeerEvent struct { + NodeInfo []byte +} + +// AddPeerSuccessEvent represents "AddPeerSuccess" event emitted by the contract. +type AddPeerSuccessEvent struct { + PublicKey *keys.PublicKey +} + +// UpdateStateEvent represents "UpdateState" event emitted by the contract. +type UpdateStateEvent struct { + State *big.Int + PublicKey *keys.PublicKey +} + +// UpdateStateSuccessEvent represents "UpdateStateSuccess" event emitted by the contract. +type UpdateStateSuccessEvent struct { + PublicKey *keys.PublicKey + State *big.Int +} + +// NewEpochEvent represents "NewEpoch" event emitted by the contract. +type NewEpochEvent 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) +} + +// 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} +} + +// Config invokes `config` method of contract. +func (c *ContractReader) Config(key []byte) (any, error) { + return func(item stackitem.Item, err error) (any, error) { + if err != nil { + return nil, err + } + return item.Value(), error(nil) + }(unwrap.Item(c.invoker.Call(c.hash, "config", key))) +} + +// Epoch invokes `epoch` method of contract. +func (c *ContractReader) Epoch() (*big.Int, error) { + return unwrap.BigInt(c.invoker.Call(c.hash, "epoch")) +} + +// ListConfig invokes `listConfig` method of contract. +func (c *ContractReader) ListConfig() ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "listConfig")) +} + +// Netmap invokes `netmap` method of contract. +func (c *ContractReader) Netmap() ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "netmap")) +} + +// NetmapCandidates invokes `netmapCandidates` method of contract. +func (c *ContractReader) NetmapCandidates() ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "netmapCandidates")) +} + +// Snapshot invokes `snapshot` method of contract. +func (c *ContractReader) Snapshot(diff *big.Int) ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "snapshot", diff)) +} + +// SnapshotByEpoch invokes `snapshotByEpoch` method of contract. +func (c *ContractReader) SnapshotByEpoch(epoch *big.Int) ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "snapshotByEpoch", epoch)) +} + +// Version invokes `version` method of contract. +func (c *ContractReader) Version() (*big.Int, error) { + return unwrap.BigInt(c.invoker.Call(c.hash, "version")) +} + +// AddPeer creates a transaction invoking `addPeer` 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) AddPeer(nodeInfo []byte) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "addPeer", nodeInfo) +} + +// AddPeerTransaction creates a transaction invoking `addPeer` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) AddPeerTransaction(nodeInfo []byte) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "addPeer", nodeInfo) +} + +// AddPeerUnsigned creates a transaction invoking `addPeer` 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) AddPeerUnsigned(nodeInfo []byte) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "addPeer", nil, nodeInfo) +} + +// AddPeerIR creates a transaction invoking `addPeerIR` 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) AddPeerIR(nodeInfo []byte) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "addPeerIR", nodeInfo) +} + +// AddPeerIRTransaction creates a transaction invoking `addPeerIR` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) AddPeerIRTransaction(nodeInfo []byte) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "addPeerIR", nodeInfo) +} + +// AddPeerIRUnsigned creates a transaction invoking `addPeerIR` 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) AddPeerIRUnsigned(nodeInfo []byte) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "addPeerIR", nil, nodeInfo) +} + +// LastEpochBlock creates a transaction invoking `lastEpochBlock` 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) LastEpochBlock() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "lastEpochBlock") +} + +// LastEpochBlockTransaction creates a transaction invoking `lastEpochBlock` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) LastEpochBlockTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "lastEpochBlock") +} + +// LastEpochBlockUnsigned creates a transaction invoking `lastEpochBlock` 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) LastEpochBlockUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "lastEpochBlock", nil) +} + +// 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) +} + +// SetConfig creates a transaction invoking `setConfig` 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) SetConfig(id []byte, key []byte, val []byte) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "setConfig", id, key, val) +} + +// SetConfigTransaction creates a transaction invoking `setConfig` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) SetConfigTransaction(id []byte, key []byte, val []byte) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "setConfig", id, key, val) +} + +// SetConfigUnsigned creates a transaction invoking `setConfig` 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) SetConfigUnsigned(id []byte, key []byte, val []byte) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "setConfig", nil, id, key, val) +} + +// 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) +} + +// UpdateSnapshotCount creates a transaction invoking `updateSnapshotCount` 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) UpdateSnapshotCount(count *big.Int) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "updateSnapshotCount", count) +} + +// UpdateSnapshotCountTransaction creates a transaction invoking `updateSnapshotCount` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) UpdateSnapshotCountTransaction(count *big.Int) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "updateSnapshotCount", count) +} + +// UpdateSnapshotCountUnsigned creates a transaction invoking `updateSnapshotCount` 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) UpdateSnapshotCountUnsigned(count *big.Int) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "updateSnapshotCount", nil, count) +} + +// UpdateState creates a transaction invoking `updateState` 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) UpdateState(state *big.Int, publicKey *keys.PublicKey) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "updateState", state, publicKey) +} + +// UpdateStateTransaction creates a transaction invoking `updateState` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) UpdateStateTransaction(state *big.Int, publicKey *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "updateState", state, publicKey) +} + +// UpdateStateUnsigned creates a transaction invoking `updateState` 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) UpdateStateUnsigned(state *big.Int, publicKey *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "updateState", nil, state, publicKey) +} + +// UpdateStateIR creates a transaction invoking `updateStateIR` 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) UpdateStateIR(state *big.Int, publicKey *keys.PublicKey) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "updateStateIR", state, publicKey) +} + +// UpdateStateIRTransaction creates a transaction invoking `updateStateIR` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) UpdateStateIRTransaction(state *big.Int, publicKey *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "updateStateIR", state, publicKey) +} + +// UpdateStateIRUnsigned creates a transaction invoking `updateStateIR` 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) UpdateStateIRUnsigned(state *big.Int, publicKey *keys.PublicKey) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "updateStateIR", nil, state, publicKey) +} + +// AddPeerEventsFromApplicationLog retrieves a set of all emitted events +// with "AddPeer" name from the provided [result.ApplicationLog]. +func AddPeerEventsFromApplicationLog(log *result.ApplicationLog) ([]*AddPeerEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*AddPeerEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "AddPeer" { + continue + } + event := new(AddPeerEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize AddPeerEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to AddPeerEvent or +// returns an error if it's not possible to do to so. +func (e *AddPeerEvent) 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.NodeInfo, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field NodeInfo: %w", err) + } + + return nil +} + +// AddPeerSuccessEventsFromApplicationLog retrieves a set of all emitted events +// with "AddPeerSuccess" name from the provided [result.ApplicationLog]. +func AddPeerSuccessEventsFromApplicationLog(log *result.ApplicationLog) ([]*AddPeerSuccessEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*AddPeerSuccessEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "AddPeerSuccess" { + continue + } + event := new(AddPeerSuccessEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize AddPeerSuccessEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to AddPeerSuccessEvent or +// returns an error if it's not possible to do to so. +func (e *AddPeerSuccessEvent) 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.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 +} + +// UpdateStateEventsFromApplicationLog retrieves a set of all emitted events +// with "UpdateState" name from the provided [result.ApplicationLog]. +func UpdateStateEventsFromApplicationLog(log *result.ApplicationLog) ([]*UpdateStateEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*UpdateStateEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "UpdateState" { + continue + } + event := new(UpdateStateEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize UpdateStateEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to UpdateStateEvent or +// returns an error if it's not possible to do to so. +func (e *UpdateStateEvent) 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.State, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field State: %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 +} + +// UpdateStateSuccessEventsFromApplicationLog retrieves a set of all emitted events +// with "UpdateStateSuccess" name from the provided [result.ApplicationLog]. +func UpdateStateSuccessEventsFromApplicationLog(log *result.ApplicationLog) ([]*UpdateStateSuccessEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*UpdateStateSuccessEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "UpdateStateSuccess" { + continue + } + event := new(UpdateStateSuccessEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize UpdateStateSuccessEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to UpdateStateSuccessEvent or +// returns an error if it's not possible to do to so. +func (e *UpdateStateSuccessEvent) 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.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) + } + + index++ + e.State, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field State: %w", err) + } + + return nil +} + +// NewEpochEventsFromApplicationLog retrieves a set of all emitted events +// with "NewEpoch" name from the provided [result.ApplicationLog]. +func NewEpochEventsFromApplicationLog(log *result.ApplicationLog) ([]*NewEpochEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*NewEpochEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "NewEpoch" { + continue + } + event := new(NewEpochEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize NewEpochEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to NewEpochEvent or +// returns an error if it's not possible to do to so. +func (e *NewEpochEvent) 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 +} diff --git a/rpcclient/nns/client.go b/rpcclient/nns/client.go new file mode 100644 index 0000000..553b75e --- /dev/null +++ b/rpcclient/nns/client.go @@ -0,0 +1,336 @@ +// Package nameservice contains RPC wrappers for NameService contract. +// +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. +package nameservice + +import ( + "github.com/google/uuid" + "github.com/nspcc-dev/neo-go/pkg/core/transaction" + "github.com/nspcc-dev/neo-go/pkg/neorpc/result" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap" + "github.com/nspcc-dev/neo-go/pkg/smartcontract" + "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" + "math/big" +) + +// Invoker is used by ContractReader to call various safe methods. +type Invoker interface { + nep11.Invoker +} + +// Actor is used by Contract to call state-changing methods. +type Actor interface { + Invoker + + nep11.Actor + + 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 { + nep11.NonDivisibleReader + invoker Invoker + hash util.Uint160 +} + +// Contract implements all contract methods. +type Contract struct { + ContractReader + nep11.BaseWriter + 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{*nep11.NewNonDivisibleReader(invoker, hash), invoker, hash} +} + +// New creates an instance of Contract using provided contract hash and the given Actor. +func New(actor Actor, hash util.Uint160) *Contract { + var nep11ndt = nep11.NewNonDivisible(actor, hash) + return &Contract{ContractReader{nep11ndt.NonDivisibleReader, actor, hash}, nep11ndt.BaseWriter, actor, hash} +} + +// GetPrice invokes `getPrice` method of contract. +func (c *ContractReader) GetPrice() (*big.Int, error) { + return unwrap.BigInt(c.invoker.Call(c.hash, "getPrice")) +} + +// GetRecords invokes `getRecords` method of contract. +func (c *ContractReader) GetRecords(name string, typ *big.Int) ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "getRecords", name, typ)) +} + +// IsAvailable invokes `isAvailable` method of contract. +func (c *ContractReader) IsAvailable(name string) (bool, error) { + return unwrap.Bool(c.invoker.Call(c.hash, "isAvailable", name)) +} + +// Resolve invokes `resolve` method of contract. +func (c *ContractReader) Resolve(name string, typ *big.Int) ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "resolve", name, typ)) +} + +// Roots invokes `roots` method of contract. +func (c *ContractReader) Roots() (uuid.UUID, result.Iterator, error) { + return unwrap.SessionIterator(c.invoker.Call(c.hash, "roots")) +} + +// RootsExpanded is similar to Roots (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) RootsExpanded(_numOfIteratorItems int) ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "roots", _numOfIteratorItems)) +} + +// Version invokes `version` method of contract. +func (c *ContractReader) Version() (*big.Int, error) { + return unwrap.BigInt(c.invoker.Call(c.hash, "version")) +} + +// AddRecord creates a transaction invoking `addRecord` 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) AddRecord(name string, typ *big.Int, data string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "addRecord", name, typ, data) +} + +// AddRecordTransaction creates a transaction invoking `addRecord` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) AddRecordTransaction(name string, typ *big.Int, data string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "addRecord", name, typ, data) +} + +// AddRecordUnsigned creates a transaction invoking `addRecord` 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) AddRecordUnsigned(name string, typ *big.Int, data string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "addRecord", nil, name, typ, data) +} + +// DeleteRecords creates a transaction invoking `deleteRecords` 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) DeleteRecords(name string, typ *big.Int) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "deleteRecords", name, typ) +} + +// DeleteRecordsTransaction creates a transaction invoking `deleteRecords` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) DeleteRecordsTransaction(name string, typ *big.Int) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "deleteRecords", name, typ) +} + +// DeleteRecordsUnsigned creates a transaction invoking `deleteRecords` 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) DeleteRecordsUnsigned(name string, typ *big.Int) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "deleteRecords", nil, name, typ) +} + +// GetAllRecords creates a transaction invoking `getAllRecords` 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) GetAllRecords(name string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "getAllRecords", name) +} + +// GetAllRecordsTransaction creates a transaction invoking `getAllRecords` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) GetAllRecordsTransaction(name string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "getAllRecords", name) +} + +// GetAllRecordsUnsigned creates a transaction invoking `getAllRecords` 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) GetAllRecordsUnsigned(name string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "getAllRecords", nil, name) +} + +func (c *Contract) scriptForRegister(name string, owner util.Uint160, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) ([]byte, error) { + return smartcontract.CreateCallWithAssertScript(c.hash, "register", name, owner, email, refresh, retry, expire, ttl) +} + +// Register creates a transaction invoking `register` 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) Register(name string, owner util.Uint160, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) (util.Uint256, uint32, error) { + script, err := c.scriptForRegister(name, owner, email, refresh, retry, expire, ttl) + if err != nil { + return util.Uint256{}, 0, err + } + return c.actor.SendRun(script) +} + +// RegisterTransaction creates a transaction invoking `register` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) RegisterTransaction(name string, owner util.Uint160, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) (*transaction.Transaction, error) { + script, err := c.scriptForRegister(name, owner, email, refresh, retry, expire, ttl) + if err != nil { + return nil, err + } + return c.actor.MakeRun(script) +} + +// RegisterUnsigned creates a transaction invoking `register` 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) RegisterUnsigned(name string, owner util.Uint160, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) (*transaction.Transaction, error) { + script, err := c.scriptForRegister(name, owner, email, refresh, retry, expire, ttl) + if err != nil { + return nil, err + } + return c.actor.MakeUnsignedRun(script, nil) +} + +// Renew creates a transaction invoking `renew` 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) Renew(name string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "renew", name) +} + +// RenewTransaction creates a transaction invoking `renew` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) RenewTransaction(name string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "renew", name) +} + +// RenewUnsigned creates a transaction invoking `renew` 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) RenewUnsigned(name string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "renew", nil, name) +} + +// SetAdmin creates a transaction invoking `setAdmin` method of the contract. +// This transaction is signed and immediately sent to the network. +// The values returned are its hash, ValidUntilBlock value and error if any. +func (c *Contract) SetAdmin(name string, admin util.Uint160) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "setAdmin", name, 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(name string, admin util.Uint160) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "setAdmin", name, 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(name string, admin util.Uint160) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "setAdmin", nil, name, admin) +} + +// SetPrice creates a transaction invoking `setPrice` 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) SetPrice(price *big.Int) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "setPrice", price) +} + +// SetPriceTransaction creates a transaction invoking `setPrice` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) SetPriceTransaction(price *big.Int) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "setPrice", price) +} + +// SetPriceUnsigned creates a transaction invoking `setPrice` 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) SetPriceUnsigned(price *big.Int) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "setPrice", nil, price) +} + +// SetRecord creates a transaction invoking `setRecord` 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) SetRecord(name string, typ *big.Int, id *big.Int, data string) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "setRecord", name, typ, id, data) +} + +// SetRecordTransaction creates a transaction invoking `setRecord` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) SetRecordTransaction(name string, typ *big.Int, id *big.Int, data string) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "setRecord", name, typ, id, data) +} + +// SetRecordUnsigned creates a transaction invoking `setRecord` 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) SetRecordUnsigned(name string, typ *big.Int, id *big.Int, data string) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "setRecord", nil, name, typ, id, data) +} + +// 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(nef []byte, manifest string, data any) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "update", nef, 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(nef []byte, manifest string, data any) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "update", nef, 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(nef []byte, manifest string, data any) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "update", nil, nef, manifest, data) +} + +// UpdateSOA creates a transaction invoking `updateSOA` 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) UpdateSOA(name string, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "updateSOA", name, email, refresh, retry, expire, ttl) +} + +// UpdateSOATransaction creates a transaction invoking `updateSOA` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) UpdateSOATransaction(name string, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "updateSOA", name, email, refresh, retry, expire, ttl) +} + +// UpdateSOAUnsigned creates a transaction invoking `updateSOA` 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) UpdateSOAUnsigned(name string, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "updateSOA", nil, name, email, refresh, retry, expire, ttl) +} diff --git a/rpcclient/processing/client.go b/rpcclient/processing/client.go new file mode 100644 index 0000000..e0ba398 --- /dev/null +++ b/rpcclient/processing/client.go @@ -0,0 +1,84 @@ +// Package multisignatureprocessing contains RPC wrappers for Multi Signature Processing contract. +// +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. +package multisignatureprocessing + +import ( + "github.com/nspcc-dev/neo-go/pkg/core/transaction" + "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" + "math/big" +) + +// Invoker is used by ContractReader to call various safe methods. +type Invoker interface { + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, 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} +} + +// Verify invokes `verify` method of contract. +func (c *ContractReader) Verify() (bool, error) { + return unwrap.Bool(c.invoker.Call(c.hash, "verify")) +} + +// Version invokes `version` method of contract. +func (c *ContractReader) Version() (*big.Int, error) { + return unwrap.BigInt(c.invoker.Call(c.hash, "version")) +} + +// 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) +} diff --git a/rpcclient/proxy/client.go b/rpcclient/proxy/client.go new file mode 100644 index 0000000..10acfda --- /dev/null +++ b/rpcclient/proxy/client.go @@ -0,0 +1,84 @@ +// Package notaryproxy contains RPC wrappers for Notary Proxy contract. +// +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. +package notaryproxy + +import ( + "github.com/nspcc-dev/neo-go/pkg/core/transaction" + "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" + "math/big" +) + +// Invoker is used by ContractReader to call various safe methods. +type Invoker interface { + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, 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} +} + +// Verify invokes `verify` method of contract. +func (c *ContractReader) Verify() (bool, error) { + return unwrap.Bool(c.invoker.Call(c.hash, "verify")) +} + +// Version invokes `version` method of contract. +func (c *ContractReader) Version() (*big.Int, error) { + return unwrap.BigInt(c.invoker.Call(c.hash, "version")) +} + +// 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) +} diff --git a/rpcclient/reputation/client.go b/rpcclient/reputation/client.go new file mode 100644 index 0000000..3a495cb --- /dev/null +++ b/rpcclient/reputation/client.go @@ -0,0 +1,207 @@ +// Package reputation contains RPC wrappers for Reputation contract. +// +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. +package reputation + +import ( + "errors" + "fmt" + "github.com/nspcc-dev/neo-go/pkg/core/transaction" + "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" +) + +// ReputationPutEvent represents "reputationPut" event emitted by the contract. +type ReputationPutEvent struct { + Epoch *big.Int + PeerID []byte + Value []byte +} + +// Invoker is used by ContractReader to call various safe methods. +type Invoker interface { + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, 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} +} + +// Get invokes `get` method of contract. +func (c *ContractReader) Get(epoch *big.Int, peerID []byte) ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "get", epoch, peerID)) +} + +// GetByID invokes `getByID` method of contract. +func (c *ContractReader) GetByID(id []byte) ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "getByID", id)) +} + +// ListByEpoch invokes `listByEpoch` method of contract. +func (c *ContractReader) ListByEpoch(epoch *big.Int) ([]stackitem.Item, error) { + return unwrap.Array(c.invoker.Call(c.hash, "listByEpoch", epoch)) +} + +// 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(epoch *big.Int, peerID []byte, value []byte) (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "put", epoch, peerID, value) +} + +// 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(epoch *big.Int, peerID []byte, value []byte) (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "put", epoch, peerID, value) +} + +// 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(epoch *big.Int, peerID []byte, value []byte) (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "put", nil, epoch, peerID, value) +} + +// 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) +} + +// Version creates a transaction invoking `version` 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) Version() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "version") +} + +// VersionTransaction creates a transaction invoking `version` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) VersionTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "version") +} + +// VersionUnsigned creates a transaction invoking `version` 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) VersionUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "version", nil) +} + +// ReputationPutEventsFromApplicationLog retrieves a set of all emitted events +// with "reputationPut" name from the provided [result.ApplicationLog]. +func ReputationPutEventsFromApplicationLog(log *result.ApplicationLog) ([]*ReputationPutEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*ReputationPutEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "reputationPut" { + continue + } + event := new(ReputationPutEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize ReputationPutEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to ReputationPutEvent or +// returns an error if it's not possible to do to so. +func (e *ReputationPutEvent) 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.Epoch, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Epoch: %w", err) + } + + index++ + e.PeerID, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field PeerID: %w", err) + } + + index++ + e.Value, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field Value: %w", err) + } + + return nil +}