github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/cli/smartcontract/testdata/nex/nex.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 nextoken contains RPC wrappers for NEX Token contract.
     4  package nextoken
     5  
     6  import (
     7  	"errors"
     8  	"fmt"
     9  	"github.com/nspcc-dev/neo-go/pkg/core/transaction"
    10  	"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
    11  	"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
    12  	"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17"
    13  	"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
    14  	"github.com/nspcc-dev/neo-go/pkg/util"
    15  	"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
    16  	"math/big"
    17  )
    18  
    19  // Hash contains contract hash.
    20  var Hash = util.Uint160{0xa8, 0x1a, 0xa1, 0xf0, 0x4b, 0xf, 0xdc, 0x4a, 0xa2, 0xce, 0xd5, 0xbf, 0xc6, 0x22, 0xcf, 0xe8, 0x9, 0x7f, 0xa6, 0xa2}
    21  
    22  // OnMintEvent represents "OnMint" event emitted by the contract.
    23  type OnMintEvent struct {
    24  	From   util.Uint160
    25  	To     util.Uint160
    26  	Amount *big.Int
    27  	SwapId *big.Int
    28  }
    29  
    30  // Invoker is used by ContractReader to call various safe methods.
    31  type Invoker interface {
    32  	nep17.Invoker
    33  }
    34  
    35  // Actor is used by Contract to call state-changing methods.
    36  type Actor interface {
    37  	Invoker
    38  
    39  	nep17.Actor
    40  
    41  	MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error)
    42  	MakeRun(script []byte) (*transaction.Transaction, error)
    43  	MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error)
    44  	MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error)
    45  	SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error)
    46  	SendRun(script []byte) (util.Uint256, uint32, error)
    47  }
    48  
    49  // ContractReader implements safe contract methods.
    50  type ContractReader struct {
    51  	nep17.TokenReader
    52  	invoker Invoker
    53  	hash    util.Uint160
    54  }
    55  
    56  // Contract implements all contract methods.
    57  type Contract struct {
    58  	ContractReader
    59  	nep17.TokenWriter
    60  	actor Actor
    61  	hash  util.Uint160
    62  }
    63  
    64  // NewReader creates an instance of ContractReader using Hash and the given Invoker.
    65  func NewReader(invoker Invoker) *ContractReader {
    66  	var hash = Hash
    67  	return &ContractReader{*nep17.NewReader(invoker, hash), invoker, hash}
    68  }
    69  
    70  // New creates an instance of Contract using Hash and the given Actor.
    71  func New(actor Actor) *Contract {
    72  	var hash = Hash
    73  	var nep17t = nep17.New(actor, hash)
    74  	return &Contract{ContractReader{nep17t.TokenReader, actor, hash}, nep17t.TokenWriter, actor, hash}
    75  }
    76  
    77  // Cap invokes `cap` method of contract.
    78  func (c *ContractReader) Cap() (*big.Int, error) {
    79  	return unwrap.BigInt(c.invoker.Call(c.hash, "cap"))
    80  }
    81  
    82  // GetMinter invokes `getMinter` method of contract.
    83  func (c *ContractReader) GetMinter() (*keys.PublicKey, error) {
    84  	return unwrap.PublicKey(c.invoker.Call(c.hash, "getMinter"))
    85  }
    86  
    87  // GetOwner invokes `getOwner` method of contract.
    88  func (c *ContractReader) GetOwner() (util.Uint160, error) {
    89  	return unwrap.Uint160(c.invoker.Call(c.hash, "getOwner"))
    90  }
    91  
    92  // TotalMinted invokes `totalMinted` method of contract.
    93  func (c *ContractReader) TotalMinted() (*big.Int, error) {
    94  	return unwrap.BigInt(c.invoker.Call(c.hash, "totalMinted"))
    95  }
    96  
    97  // ChangeMinter creates a transaction invoking `changeMinter` method of the contract.
    98  // This transaction is signed and immediately sent to the network.
    99  // The values returned are its hash, ValidUntilBlock value and error if any.
   100  func (c *Contract) ChangeMinter(newMinter *keys.PublicKey) (util.Uint256, uint32, error) {
   101  	return c.actor.SendCall(c.hash, "changeMinter", newMinter)
   102  }
   103  
   104  // ChangeMinterTransaction creates a transaction invoking `changeMinter` method of the contract.
   105  // This transaction is signed, but not sent to the network, instead it's
   106  // returned to the caller.
   107  func (c *Contract) ChangeMinterTransaction(newMinter *keys.PublicKey) (*transaction.Transaction, error) {
   108  	return c.actor.MakeCall(c.hash, "changeMinter", newMinter)
   109  }
   110  
   111  // ChangeMinterUnsigned creates a transaction invoking `changeMinter` method of the contract.
   112  // This transaction is not signed, it's simply returned to the caller.
   113  // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
   114  // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
   115  func (c *Contract) ChangeMinterUnsigned(newMinter *keys.PublicKey) (*transaction.Transaction, error) {
   116  	return c.actor.MakeUnsignedCall(c.hash, "changeMinter", nil, newMinter)
   117  }
   118  
   119  // ChangeOwner creates a transaction invoking `changeOwner` method of the contract.
   120  // This transaction is signed and immediately sent to the network.
   121  // The values returned are its hash, ValidUntilBlock value and error if any.
   122  func (c *Contract) ChangeOwner(newOwner util.Uint160) (util.Uint256, uint32, error) {
   123  	return c.actor.SendCall(c.hash, "changeOwner", newOwner)
   124  }
   125  
   126  // ChangeOwnerTransaction creates a transaction invoking `changeOwner` method of the contract.
   127  // This transaction is signed, but not sent to the network, instead it's
   128  // returned to the caller.
   129  func (c *Contract) ChangeOwnerTransaction(newOwner util.Uint160) (*transaction.Transaction, error) {
   130  	return c.actor.MakeCall(c.hash, "changeOwner", newOwner)
   131  }
   132  
   133  // ChangeOwnerUnsigned creates a transaction invoking `changeOwner` method of the contract.
   134  // This transaction is not signed, it's simply returned to the caller.
   135  // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
   136  // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
   137  func (c *Contract) ChangeOwnerUnsigned(newOwner util.Uint160) (*transaction.Transaction, error) {
   138  	return c.actor.MakeUnsignedCall(c.hash, "changeOwner", nil, newOwner)
   139  }
   140  
   141  // Destroy creates a transaction invoking `destroy` method of the contract.
   142  // This transaction is signed and immediately sent to the network.
   143  // The values returned are its hash, ValidUntilBlock value and error if any.
   144  func (c *Contract) Destroy() (util.Uint256, uint32, error) {
   145  	return c.actor.SendCall(c.hash, "destroy")
   146  }
   147  
   148  // DestroyTransaction creates a transaction invoking `destroy` method of the contract.
   149  // This transaction is signed, but not sent to the network, instead it's
   150  // returned to the caller.
   151  func (c *Contract) DestroyTransaction() (*transaction.Transaction, error) {
   152  	return c.actor.MakeCall(c.hash, "destroy")
   153  }
   154  
   155  // DestroyUnsigned creates a transaction invoking `destroy` method of the contract.
   156  // This transaction is not signed, it's simply returned to the caller.
   157  // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
   158  // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
   159  func (c *Contract) DestroyUnsigned() (*transaction.Transaction, error) {
   160  	return c.actor.MakeUnsignedCall(c.hash, "destroy", nil)
   161  }
   162  
   163  // MaxSupply creates a transaction invoking `maxSupply` method of the contract.
   164  // This transaction is signed and immediately sent to the network.
   165  // The values returned are its hash, ValidUntilBlock value and error if any.
   166  func (c *Contract) MaxSupply() (util.Uint256, uint32, error) {
   167  	return c.actor.SendCall(c.hash, "maxSupply")
   168  }
   169  
   170  // MaxSupplyTransaction creates a transaction invoking `maxSupply` method of the contract.
   171  // This transaction is signed, but not sent to the network, instead it's
   172  // returned to the caller.
   173  func (c *Contract) MaxSupplyTransaction() (*transaction.Transaction, error) {
   174  	return c.actor.MakeCall(c.hash, "maxSupply")
   175  }
   176  
   177  // MaxSupplyUnsigned creates a transaction invoking `maxSupply` method of the contract.
   178  // This transaction is not signed, it's simply returned to the caller.
   179  // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
   180  // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
   181  func (c *Contract) MaxSupplyUnsigned() (*transaction.Transaction, error) {
   182  	return c.actor.MakeUnsignedCall(c.hash, "maxSupply", nil)
   183  }
   184  
   185  // Mint creates a transaction invoking `mint` method of the contract.
   186  // This transaction is signed and immediately sent to the network.
   187  // The values returned are its hash, ValidUntilBlock value and error if any.
   188  func (c *Contract) Mint(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data any) (util.Uint256, uint32, error) {
   189  	return c.actor.SendCall(c.hash, "mint", from, to, amount, swapId, signature, data)
   190  }
   191  
   192  // MintTransaction creates a transaction invoking `mint` method of the contract.
   193  // This transaction is signed, but not sent to the network, instead it's
   194  // returned to the caller.
   195  func (c *Contract) MintTransaction(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data any) (*transaction.Transaction, error) {
   196  	return c.actor.MakeCall(c.hash, "mint", from, to, amount, swapId, signature, data)
   197  }
   198  
   199  // MintUnsigned creates a transaction invoking `mint` method of the contract.
   200  // This transaction is not signed, it's simply returned to the caller.
   201  // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
   202  // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
   203  func (c *Contract) MintUnsigned(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data any) (*transaction.Transaction, error) {
   204  	return c.actor.MakeUnsignedCall(c.hash, "mint", nil, from, to, amount, swapId, signature, data)
   205  }
   206  
   207  // Update creates a transaction invoking `update` method of the contract.
   208  // This transaction is signed and immediately sent to the network.
   209  // The values returned are its hash, ValidUntilBlock value and error if any.
   210  func (c *Contract) Update(nef []byte, manifest []byte) (util.Uint256, uint32, error) {
   211  	return c.actor.SendCall(c.hash, "update", nef, manifest)
   212  }
   213  
   214  // UpdateTransaction creates a transaction invoking `update` method of the contract.
   215  // This transaction is signed, but not sent to the network, instead it's
   216  // returned to the caller.
   217  func (c *Contract) UpdateTransaction(nef []byte, manifest []byte) (*transaction.Transaction, error) {
   218  	return c.actor.MakeCall(c.hash, "update", nef, manifest)
   219  }
   220  
   221  // UpdateUnsigned creates a transaction invoking `update` method of the contract.
   222  // This transaction is not signed, it's simply returned to the caller.
   223  // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
   224  // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
   225  func (c *Contract) UpdateUnsigned(nef []byte, manifest []byte) (*transaction.Transaction, error) {
   226  	return c.actor.MakeUnsignedCall(c.hash, "update", nil, nef, manifest)
   227  }
   228  
   229  // UpdateCap creates a transaction invoking `updateCap` method of the contract.
   230  // This transaction is signed and immediately sent to the network.
   231  // The values returned are its hash, ValidUntilBlock value and error if any.
   232  func (c *Contract) UpdateCap(newCap *big.Int) (util.Uint256, uint32, error) {
   233  	return c.actor.SendCall(c.hash, "updateCap", newCap)
   234  }
   235  
   236  // UpdateCapTransaction creates a transaction invoking `updateCap` method of the contract.
   237  // This transaction is signed, but not sent to the network, instead it's
   238  // returned to the caller.
   239  func (c *Contract) UpdateCapTransaction(newCap *big.Int) (*transaction.Transaction, error) {
   240  	return c.actor.MakeCall(c.hash, "updateCap", newCap)
   241  }
   242  
   243  // UpdateCapUnsigned creates a transaction invoking `updateCap` method of the contract.
   244  // This transaction is not signed, it's simply returned to the caller.
   245  // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
   246  // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
   247  func (c *Contract) UpdateCapUnsigned(newCap *big.Int) (*transaction.Transaction, error) {
   248  	return c.actor.MakeUnsignedCall(c.hash, "updateCap", nil, newCap)
   249  }
   250  
   251  // OnMintEventsFromApplicationLog retrieves a set of all emitted events
   252  // with "OnMint" name from the provided [result.ApplicationLog].
   253  func OnMintEventsFromApplicationLog(log *result.ApplicationLog) ([]*OnMintEvent, error) {
   254  	if log == nil {
   255  		return nil, errors.New("nil application log")
   256  	}
   257  
   258  	var res []*OnMintEvent
   259  	for i, ex := range log.Executions {
   260  		for j, e := range ex.Events {
   261  			if e.Name != "OnMint" {
   262  				continue
   263  			}
   264  			event := new(OnMintEvent)
   265  			err := event.FromStackItem(e.Item)
   266  			if err != nil {
   267  				return nil, fmt.Errorf("failed to deserialize OnMintEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
   268  			}
   269  			res = append(res, event)
   270  		}
   271  	}
   272  
   273  	return res, nil
   274  }
   275  
   276  // FromStackItem converts provided [stackitem.Array] to OnMintEvent or
   277  // returns an error if it's not possible to do to so.
   278  func (e *OnMintEvent) FromStackItem(item *stackitem.Array) error {
   279  	if item == nil {
   280  		return errors.New("nil item")
   281  	}
   282  	arr, ok := item.Value().([]stackitem.Item)
   283  	if !ok {
   284  		return errors.New("not an array")
   285  	}
   286  	if len(arr) != 4 {
   287  		return errors.New("wrong number of structure elements")
   288  	}
   289  
   290  	var (
   291  		index = -1
   292  		err   error
   293  	)
   294  	index++
   295  	e.From, err = func(item stackitem.Item) (util.Uint160, error) {
   296  		b, err := item.TryBytes()
   297  		if err != nil {
   298  			return util.Uint160{}, err
   299  		}
   300  		u, err := util.Uint160DecodeBytesBE(b)
   301  		if err != nil {
   302  			return util.Uint160{}, err
   303  		}
   304  		return u, nil
   305  	}(arr[index])
   306  	if err != nil {
   307  		return fmt.Errorf("field From: %w", err)
   308  	}
   309  
   310  	index++
   311  	e.To, err = func(item stackitem.Item) (util.Uint160, error) {
   312  		b, err := item.TryBytes()
   313  		if err != nil {
   314  			return util.Uint160{}, err
   315  		}
   316  		u, err := util.Uint160DecodeBytesBE(b)
   317  		if err != nil {
   318  			return util.Uint160{}, err
   319  		}
   320  		return u, nil
   321  	}(arr[index])
   322  	if err != nil {
   323  		return fmt.Errorf("field To: %w", err)
   324  	}
   325  
   326  	index++
   327  	e.Amount, err = arr[index].TryInteger()
   328  	if err != nil {
   329  		return fmt.Errorf("field Amount: %w", err)
   330  	}
   331  
   332  	index++
   333  	e.SwapId, err = arr[index].TryInteger()
   334  	if err != nil {
   335  		return fmt.Errorf("field SwapId: %w", err)
   336  	}
   337  
   338  	return nil
   339  }