forked from TrueCloudLab/frostfs-contract
207 lines
7.7 KiB
Go
207 lines
7.7 KiB
Go
// Package reputation contains RPC wrappers for Reputation contract.
|
|
//
|
|
// Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <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
|
|
}
|