github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/cli/smartcontract/testdata/nonepiter/iter.go (about)

     1  // Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT.
     2  
     3  // Package nonnepxxcontractwithiterators contains RPC wrappers for Non-NEPXX contract with iterators contract.
     4  package nonnepxxcontractwithiterators
     5  
     6  import (
     7  	"github.com/google/uuid"
     8  	"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
     9  	"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
    10  	"github.com/nspcc-dev/neo-go/pkg/util"
    11  	"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
    12  )
    13  
    14  // Hash contains contract hash.
    15  var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x0}
    16  
    17  // Invoker is used by ContractReader to call various safe methods.
    18  type Invoker interface {
    19  	Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
    20  	CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error)
    21  	TerminateSession(sessionID uuid.UUID) error
    22  	TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error)
    23  }
    24  
    25  // ContractReader implements safe contract methods.
    26  type ContractReader struct {
    27  	invoker Invoker
    28  	hash    util.Uint160
    29  }
    30  
    31  // NewReader creates an instance of ContractReader using Hash and the given Invoker.
    32  func NewReader(invoker Invoker) *ContractReader {
    33  	var hash = Hash
    34  	return &ContractReader{invoker, hash}
    35  }
    36  
    37  // Tokens invokes `tokens` method of contract.
    38  func (c *ContractReader) Tokens() (uuid.UUID, result.Iterator, error) {
    39  	return unwrap.SessionIterator(c.invoker.Call(c.hash, "tokens"))
    40  }
    41  
    42  // TokensExpanded is similar to Tokens (uses the same contract
    43  // method), but can be useful if the server used doesn't support sessions and
    44  // doesn't expand iterators. It creates a script that will get the specified
    45  // number of result items from the iterator right in the VM and return them to
    46  // you. It's only limited by VM stack and GAS available for RPC invocations.
    47  func (c *ContractReader) TokensExpanded(_numOfIteratorItems int) ([]stackitem.Item, error) {
    48  	return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "tokens", _numOfIteratorItems))
    49  }
    50  
    51  // GetAllRecords invokes `getAllRecords` method of contract.
    52  func (c *ContractReader) GetAllRecords(name string) (uuid.UUID, result.Iterator, error) {
    53  	return unwrap.SessionIterator(c.invoker.Call(c.hash, "getAllRecords", name))
    54  }
    55  
    56  // GetAllRecordsExpanded is similar to GetAllRecords (uses the same contract
    57  // method), but can be useful if the server used doesn't support sessions and
    58  // doesn't expand iterators. It creates a script that will get the specified
    59  // number of result items from the iterator right in the VM and return them to
    60  // you. It's only limited by VM stack and GAS available for RPC invocations.
    61  func (c *ContractReader) GetAllRecordsExpanded(name string, _numOfIteratorItems int) ([]stackitem.Item, error) {
    62  	return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "getAllRecords", _numOfIteratorItems, name))
    63  }