cli: allow dynamic RPC binding contract hash

Close #3006 and make a light base for #3007.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2023-05-11 13:25:45 +03:00
parent 50fad8455f
commit f97eaddfd1
16 changed files with 2216 additions and 191 deletions

View file

@ -29,9 +29,8 @@ var generatorFlags = []cli.Flag{
Usage: "Output of the compiled wrapper", Usage: "Output of the compiled wrapper",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "hash", Name: "hash",
Required: true, Usage: "Smart-contract hash",
Usage: "Smart-contract hash",
}, },
} }
@ -53,21 +52,29 @@ var generateRPCWrapperCmd = cli.Command{
} }
func contractGenerateWrapper(ctx *cli.Context) error { func contractGenerateWrapper(ctx *cli.Context) error {
return contractGenerateSomething(ctx, binding.Generate) return contractGenerateSomething(ctx, binding.Generate, false)
} }
func contractGenerateRPCWrapper(ctx *cli.Context) error { func contractGenerateRPCWrapper(ctx *cli.Context) error {
return contractGenerateSomething(ctx, rpcbinding.Generate) return contractGenerateSomething(ctx, rpcbinding.Generate, true)
} }
// contractGenerateSomething reads generator parameters and calls the given callback. // contractGenerateSomething reads generator parameters and calls the given callback.
func contractGenerateSomething(ctx *cli.Context, cb func(binding.Config) error) error { func contractGenerateSomething(ctx *cli.Context, cb func(binding.Config) error, allowEmptyHash bool) error {
if err := cmdargs.EnsureNone(ctx); err != nil { if err := cmdargs.EnsureNone(ctx); err != nil {
return err return err
} }
h, err := util.Uint160DecodeStringLE(strings.TrimPrefix(ctx.String("hash"), "0x")) var (
if err != nil { h util.Uint160
return cli.NewExitError(fmt.Errorf("invalid contract hash: %w", err), 1) err error
)
if hStr := ctx.String("hash"); len(hStr) != 0 {
h, err = util.Uint160DecodeStringLE(strings.TrimPrefix(hStr, "0x"))
if err != nil {
return cli.NewExitError(fmt.Errorf("invalid contract hash: %w", err), 1)
}
} else if !allowEmptyHash {
return cli.NewExitError("contract hash must be provided via --hash flag", 1)
} }
m, _, err := readManifest(ctx.String("manifest"), h) m, _, err := readManifest(ctx.String("manifest"), h)
if err != nil { if err != nil {

View file

@ -3,6 +3,7 @@ package smartcontract
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -309,16 +310,18 @@ type Invoker interface {
// ContractReader implements safe contract methods. // ContractReader implements safe contract methods.
type ContractReader struct { type ContractReader struct {
invoker Invoker invoker Invoker
hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.
func NewReader(invoker Invoker) *ContractReader { func NewReader(invoker Invoker) *ContractReader {
return &ContractReader{invoker} var hash = Hash
return &ContractReader{invoker, hash}
} }
// Get invokes `+"`get`"+` method of contract. // Get invokes `+"`get`"+` method of contract.
func (c *ContractReader) Get() (*big.Int, error) { func (c *ContractReader) Get() (*big.Int, error) {
return unwrap.BigInt(c.invoker.Call(Hash, "get")) return unwrap.BigInt(c.invoker.Call(c.hash, "get"))
} }
`, string(data)) `, string(data))
} }
@ -379,17 +382,20 @@ func TestAssistedRPCBindings(t *testing.T) {
app := cli.NewApp() app := cli.NewApp()
app.Commands = NewCommands() app.Commands = NewCommands()
var checkBinding = func(source string, guessEventTypes bool, suffix ...string) { var checkBinding = func(source string, hasDefinedHash bool, guessEventTypes bool, suffix ...string) {
testName := source testName := source
if len(suffix) != 0 { if len(suffix) != 0 {
testName += suffix[0] testName += suffix[0]
} }
testName += fmt.Sprintf(", predefined hash: %t", hasDefinedHash)
t.Run(testName, func(t *testing.T) { t.Run(testName, func(t *testing.T) {
configFile := filepath.Join(source, "config.yml") configFile := filepath.Join(source, "config.yml")
expectedFile := filepath.Join(source, "rpcbindings.out") expectedFile := filepath.Join(source, "rpcbindings.out")
if len(suffix) != 0 { if len(suffix) != 0 {
configFile = filepath.Join(source, "config"+suffix[0]+".yml") configFile = filepath.Join(source, "config"+suffix[0]+".yml")
expectedFile = filepath.Join(source, "rpcbindings"+suffix[0]+".out") expectedFile = filepath.Join(source, "rpcbindings"+suffix[0]+".out")
} else if !hasDefinedHash {
expectedFile = filepath.Join(source, "rpcbindings_dynamic_hash.out")
} }
manifestF := filepath.Join(tmpDir, "manifest.json") manifestF := filepath.Join(tmpDir, "manifest.json")
bindingF := filepath.Join(tmpDir, "binding.yml") bindingF := filepath.Join(tmpDir, "binding.yml")
@ -405,15 +411,18 @@ func TestAssistedRPCBindings(t *testing.T) {
cmd = append(cmd, "--guess-eventtypes") cmd = append(cmd, "--guess-eventtypes")
} }
require.NoError(t, app.Run(cmd)) require.NoError(t, app.Run(cmd))
outFile := filepath.Join(tmpDir, "out.go")
require.NoError(t, app.Run([]string{"", "contract", "generate-rpcwrapper", cmds := []string{"", "contract", "generate-rpcwrapper",
"--config", bindingF, "--config", bindingF,
"--manifest", manifestF, "--manifest", manifestF,
"--out", outFile, "--out", expectedFile,
"--hash", "0x00112233445566778899aabbccddeeff00112233", }
})) if hasDefinedHash {
cmds = append(cmds, "--hash", "0x00112233445566778899aabbccddeeff00112233")
}
require.NoError(t, app.Run(cmds))
data, err := os.ReadFile(outFile) data, err := os.ReadFile(expectedFile)
require.NoError(t, err) require.NoError(t, err)
data = bytes.ReplaceAll(data, []byte("\r"), []byte{}) // Windows. data = bytes.ReplaceAll(data, []byte("\r"), []byte{}) // Windows.
if rewriteExpectedOutputs { if rewriteExpectedOutputs {
@ -427,11 +436,13 @@ func TestAssistedRPCBindings(t *testing.T) {
}) })
} }
checkBinding(filepath.Join("testdata", "types"), false) for _, hasDefinedHash := range []bool{true, false} {
checkBinding(filepath.Join("testdata", "structs"), false) checkBinding(filepath.Join("testdata", "types"), hasDefinedHash, false)
checkBinding(filepath.Join("testdata", "notifications"), false) checkBinding(filepath.Join("testdata", "structs"), hasDefinedHash, false)
checkBinding(filepath.Join("testdata", "notifications"), false, "_extended") }
checkBinding(filepath.Join("testdata", "notifications"), true, "_guessed") checkBinding(filepath.Join("testdata", "notifications"), true, false)
checkBinding(filepath.Join("testdata", "notifications"), true, false, "_extended")
checkBinding(filepath.Join("testdata", "notifications"), true, true, "_guessed")
require.False(t, rewriteExpectedOutputs) require.False(t, rewriteExpectedOutputs)
} }

View file

@ -25,6 +25,7 @@ type Actor interface {
type ContractReader struct { type ContractReader struct {
nep17.TokenReader nep17.TokenReader
invoker Invoker invoker Invoker
hash util.Uint160
} }
// Contract implements all contract methods. // Contract implements all contract methods.
@ -32,15 +33,18 @@ type Contract struct {
ContractReader ContractReader
nep17.TokenWriter nep17.TokenWriter
actor Actor actor Actor
hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.
func NewReader(invoker Invoker) *ContractReader { func NewReader(invoker Invoker) *ContractReader {
return &ContractReader{*nep17.NewReader(invoker, Hash), invoker} var hash = Hash
return &ContractReader{*nep17.NewReader(invoker, hash), invoker, hash}
} }
// New creates an instance of Contract using Hash and the given Actor. // New creates an instance of Contract using Hash and the given Actor.
func New(actor Actor) *Contract { func New(actor Actor) *Contract {
var nep17t = nep17.New(actor, Hash) var hash = Hash
return &Contract{ContractReader{nep17t.TokenReader, actor}, nep17t.TokenWriter, actor} var nep17t = nep17.New(actor, hash)
return &Contract{ContractReader{nep17t.TokenReader, actor, hash}, nep17t.TokenWriter, actor, hash}
} }

View file

@ -56,6 +56,7 @@ type Actor interface {
type ContractReader struct { type ContractReader struct {
nep11.NonDivisibleReader nep11.NonDivisibleReader
invoker Invoker invoker Invoker
hash util.Uint160
} }
// Contract implements all contract methods. // Contract implements all contract methods.
@ -63,22 +64,25 @@ type Contract struct {
ContractReader ContractReader
nep11.BaseWriter nep11.BaseWriter
actor Actor actor Actor
hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.
func NewReader(invoker Invoker) *ContractReader { func NewReader(invoker Invoker) *ContractReader {
return &ContractReader{*nep11.NewNonDivisibleReader(invoker, Hash), invoker} var hash = Hash
return &ContractReader{*nep11.NewNonDivisibleReader(invoker, hash), invoker, hash}
} }
// New creates an instance of Contract using Hash and the given Actor. // New creates an instance of Contract using Hash and the given Actor.
func New(actor Actor) *Contract { func New(actor Actor) *Contract {
var nep11ndt = nep11.NewNonDivisible(actor, Hash) var hash = Hash
return &Contract{ContractReader{nep11ndt.NonDivisibleReader, actor}, nep11ndt.BaseWriter, actor} var nep11ndt = nep11.NewNonDivisible(actor, hash)
return &Contract{ContractReader{nep11ndt.NonDivisibleReader, actor, hash}, nep11ndt.BaseWriter, actor, hash}
} }
// Roots invokes `roots` method of contract. // Roots invokes `roots` method of contract.
func (c *ContractReader) Roots() (uuid.UUID, result.Iterator, error) { func (c *ContractReader) Roots() (uuid.UUID, result.Iterator, error) {
return unwrap.SessionIterator(c.invoker.Call(Hash, "roots")) return unwrap.SessionIterator(c.invoker.Call(c.hash, "roots"))
} }
// RootsExpanded is similar to Roots (uses the same contract // RootsExpanded is similar to Roots (uses the same contract
@ -87,27 +91,27 @@ func (c *ContractReader) Roots() (uuid.UUID, result.Iterator, error) {
// number of result items from the iterator right in the VM and return them to // 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. // you. It's only limited by VM stack and GAS available for RPC invocations.
func (c *ContractReader) RootsExpanded(_numOfIteratorItems int) ([]stackitem.Item, error) { func (c *ContractReader) RootsExpanded(_numOfIteratorItems int) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.CallAndExpandIterator(Hash, "roots", _numOfIteratorItems)) return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "roots", _numOfIteratorItems))
} }
// GetPrice invokes `getPrice` method of contract. // GetPrice invokes `getPrice` method of contract.
func (c *ContractReader) GetPrice(length *big.Int) (*big.Int, error) { func (c *ContractReader) GetPrice(length *big.Int) (*big.Int, error) {
return unwrap.BigInt(c.invoker.Call(Hash, "getPrice", length)) return unwrap.BigInt(c.invoker.Call(c.hash, "getPrice", length))
} }
// IsAvailable invokes `isAvailable` method of contract. // IsAvailable invokes `isAvailable` method of contract.
func (c *ContractReader) IsAvailable(name string) (bool, error) { func (c *ContractReader) IsAvailable(name string) (bool, error) {
return unwrap.Bool(c.invoker.Call(Hash, "isAvailable", name)) return unwrap.Bool(c.invoker.Call(c.hash, "isAvailable", name))
} }
// GetRecord invokes `getRecord` method of contract. // GetRecord invokes `getRecord` method of contract.
func (c *ContractReader) GetRecord(name string, typev *big.Int) (string, error) { func (c *ContractReader) GetRecord(name string, typev *big.Int) (string, error) {
return unwrap.UTF8String(c.invoker.Call(Hash, "getRecord", name, typev)) return unwrap.UTF8String(c.invoker.Call(c.hash, "getRecord", name, typev))
} }
// GetAllRecords invokes `getAllRecords` method of contract. // GetAllRecords invokes `getAllRecords` method of contract.
func (c *ContractReader) GetAllRecords(name string) (uuid.UUID, result.Iterator, error) { func (c *ContractReader) GetAllRecords(name string) (uuid.UUID, result.Iterator, error) {
return unwrap.SessionIterator(c.invoker.Call(Hash, "getAllRecords", name)) return unwrap.SessionIterator(c.invoker.Call(c.hash, "getAllRecords", name))
} }
// GetAllRecordsExpanded is similar to GetAllRecords (uses the same contract // GetAllRecordsExpanded is similar to GetAllRecords (uses the same contract
@ -116,26 +120,26 @@ func (c *ContractReader) GetAllRecords(name string) (uuid.UUID, result.Iterator,
// number of result items from the iterator right in the VM and return them to // 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. // you. It's only limited by VM stack and GAS available for RPC invocations.
func (c *ContractReader) GetAllRecordsExpanded(name string, _numOfIteratorItems int) ([]stackitem.Item, error) { func (c *ContractReader) GetAllRecordsExpanded(name string, _numOfIteratorItems int) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.CallAndExpandIterator(Hash, "getAllRecords", _numOfIteratorItems, name)) return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "getAllRecords", _numOfIteratorItems, name))
} }
// Resolve invokes `resolve` method of contract. // Resolve invokes `resolve` method of contract.
func (c *ContractReader) Resolve(name string, typev *big.Int) (string, error) { func (c *ContractReader) Resolve(name string, typev *big.Int) (string, error) {
return unwrap.UTF8String(c.invoker.Call(Hash, "resolve", name, typev)) return unwrap.UTF8String(c.invoker.Call(c.hash, "resolve", name, typev))
} }
// Update creates a transaction invoking `update` method of the contract. // Update creates a transaction invoking `update` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Update(nef []byte, manifest string) (util.Uint256, uint32, error) { func (c *Contract) Update(nef []byte, manifest string) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "update", nef, manifest) return c.actor.SendCall(c.hash, "update", nef, manifest)
} }
// UpdateTransaction creates a transaction invoking `update` method of the contract. // UpdateTransaction creates a transaction invoking `update` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) UpdateTransaction(nef []byte, manifest string) (*transaction.Transaction, error) { func (c *Contract) UpdateTransaction(nef []byte, manifest string) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "update", nef, manifest) return c.actor.MakeCall(c.hash, "update", nef, manifest)
} }
// UpdateUnsigned creates a transaction invoking `update` method of the contract. // UpdateUnsigned creates a transaction invoking `update` method of the contract.
@ -143,21 +147,21 @@ func (c *Contract) UpdateTransaction(nef []byte, manifest string) (*transaction.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) UpdateUnsigned(nef []byte, manifest string) (*transaction.Transaction, error) { func (c *Contract) UpdateUnsigned(nef []byte, manifest string) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "update", nil, nef, manifest) return c.actor.MakeUnsignedCall(c.hash, "update", nil, nef, manifest)
} }
// AddRoot creates a transaction invoking `addRoot` method of the contract. // AddRoot creates a transaction invoking `addRoot` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) AddRoot(root string) (util.Uint256, uint32, error) { func (c *Contract) AddRoot(root string) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "addRoot", root) return c.actor.SendCall(c.hash, "addRoot", root)
} }
// AddRootTransaction creates a transaction invoking `addRoot` method of the contract. // AddRootTransaction creates a transaction invoking `addRoot` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) AddRootTransaction(root string) (*transaction.Transaction, error) { func (c *Contract) AddRootTransaction(root string) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "addRoot", root) return c.actor.MakeCall(c.hash, "addRoot", root)
} }
// AddRootUnsigned creates a transaction invoking `addRoot` method of the contract. // AddRootUnsigned creates a transaction invoking `addRoot` method of the contract.
@ -165,21 +169,21 @@ func (c *Contract) AddRootTransaction(root string) (*transaction.Transaction, er
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) AddRootUnsigned(root string) (*transaction.Transaction, error) { func (c *Contract) AddRootUnsigned(root string) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "addRoot", nil, root) return c.actor.MakeUnsignedCall(c.hash, "addRoot", nil, root)
} }
// SetPrice creates a transaction invoking `setPrice` method of the contract. // SetPrice creates a transaction invoking `setPrice` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) SetPrice(priceList []any) (util.Uint256, uint32, error) { func (c *Contract) SetPrice(priceList []any) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "setPrice", priceList) return c.actor.SendCall(c.hash, "setPrice", priceList)
} }
// SetPriceTransaction creates a transaction invoking `setPrice` method of the contract. // SetPriceTransaction creates a transaction invoking `setPrice` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) SetPriceTransaction(priceList []any) (*transaction.Transaction, error) { func (c *Contract) SetPriceTransaction(priceList []any) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "setPrice", priceList) return c.actor.MakeCall(c.hash, "setPrice", priceList)
} }
// SetPriceUnsigned creates a transaction invoking `setPrice` method of the contract. // SetPriceUnsigned creates a transaction invoking `setPrice` method of the contract.
@ -187,11 +191,11 @@ func (c *Contract) SetPriceTransaction(priceList []any) (*transaction.Transactio
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) SetPriceUnsigned(priceList []any) (*transaction.Transaction, error) { func (c *Contract) SetPriceUnsigned(priceList []any) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "setPrice", nil, priceList) return c.actor.MakeUnsignedCall(c.hash, "setPrice", nil, priceList)
} }
func scriptForRegister(name string, owner util.Uint160) ([]byte, error) { func scriptForRegister(name string, owner util.Uint160) ([]byte, error) {
return smartcontract.CreateCallWithAssertScript(Hash, "register", name, owner) return smartcontract.CreateCallWithAssertScript(c.hash, "register", name, owner)
} }
// Register creates a transaction invoking `register` method of the contract. // Register creates a transaction invoking `register` method of the contract.
@ -232,14 +236,14 @@ func (c *Contract) RegisterUnsigned(name string, owner util.Uint160) (*transacti
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Renew(name string) (util.Uint256, uint32, error) { func (c *Contract) Renew(name string) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "renew", name) return c.actor.SendCall(c.hash, "renew", name)
} }
// RenewTransaction creates a transaction invoking `renew` method of the contract. // RenewTransaction creates a transaction invoking `renew` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) RenewTransaction(name string) (*transaction.Transaction, error) { func (c *Contract) RenewTransaction(name string) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "renew", name) return c.actor.MakeCall(c.hash, "renew", name)
} }
// RenewUnsigned creates a transaction invoking `renew` method of the contract. // RenewUnsigned creates a transaction invoking `renew` method of the contract.
@ -247,21 +251,21 @@ func (c *Contract) RenewTransaction(name string) (*transaction.Transaction, erro
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) RenewUnsigned(name string) (*transaction.Transaction, error) { func (c *Contract) RenewUnsigned(name string) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "renew", nil, name) return c.actor.MakeUnsignedCall(c.hash, "renew", nil, name)
} }
// Renew_2 creates a transaction invoking `renew` method of the contract. // Renew_2 creates a transaction invoking `renew` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Renew_2(name string, years *big.Int) (util.Uint256, uint32, error) { func (c *Contract) Renew_2(name string, years *big.Int) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "renew", name, years) return c.actor.SendCall(c.hash, "renew", name, years)
} }
// Renew_2Transaction creates a transaction invoking `renew` method of the contract. // Renew_2Transaction creates a transaction invoking `renew` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) Renew_2Transaction(name string, years *big.Int) (*transaction.Transaction, error) { func (c *Contract) Renew_2Transaction(name string, years *big.Int) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "renew", name, years) return c.actor.MakeCall(c.hash, "renew", name, years)
} }
// Renew_2Unsigned creates a transaction invoking `renew` method of the contract. // Renew_2Unsigned creates a transaction invoking `renew` method of the contract.
@ -269,21 +273,21 @@ func (c *Contract) Renew_2Transaction(name string, years *big.Int) (*transaction
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) Renew_2Unsigned(name string, years *big.Int) (*transaction.Transaction, error) { func (c *Contract) Renew_2Unsigned(name string, years *big.Int) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "renew", nil, name, years) return c.actor.MakeUnsignedCall(c.hash, "renew", nil, name, years)
} }
// SetAdmin creates a transaction invoking `setAdmin` method of the contract. // SetAdmin creates a transaction invoking `setAdmin` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // 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) { func (c *Contract) SetAdmin(name string, admin util.Uint160) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "setAdmin", name, admin) return c.actor.SendCall(c.hash, "setAdmin", name, admin)
} }
// SetAdminTransaction creates a transaction invoking `setAdmin` method of the contract. // SetAdminTransaction creates a transaction invoking `setAdmin` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) SetAdminTransaction(name string, admin util.Uint160) (*transaction.Transaction, error) { func (c *Contract) SetAdminTransaction(name string, admin util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "setAdmin", name, admin) return c.actor.MakeCall(c.hash, "setAdmin", name, admin)
} }
// SetAdminUnsigned creates a transaction invoking `setAdmin` method of the contract. // SetAdminUnsigned creates a transaction invoking `setAdmin` method of the contract.
@ -291,21 +295,21 @@ func (c *Contract) SetAdminTransaction(name string, admin util.Uint160) (*transa
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) SetAdminUnsigned(name string, admin util.Uint160) (*transaction.Transaction, error) { func (c *Contract) SetAdminUnsigned(name string, admin util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "setAdmin", nil, name, admin) return c.actor.MakeUnsignedCall(c.hash, "setAdmin", nil, name, admin)
} }
// SetRecord creates a transaction invoking `setRecord` method of the contract. // SetRecord creates a transaction invoking `setRecord` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) SetRecord(name string, typev *big.Int, data string) (util.Uint256, uint32, error) { func (c *Contract) SetRecord(name string, typev *big.Int, data string) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "setRecord", name, typev, data) return c.actor.SendCall(c.hash, "setRecord", name, typev, data)
} }
// SetRecordTransaction creates a transaction invoking `setRecord` method of the contract. // SetRecordTransaction creates a transaction invoking `setRecord` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) SetRecordTransaction(name string, typev *big.Int, data string) (*transaction.Transaction, error) { func (c *Contract) SetRecordTransaction(name string, typev *big.Int, data string) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "setRecord", name, typev, data) return c.actor.MakeCall(c.hash, "setRecord", name, typev, data)
} }
// SetRecordUnsigned creates a transaction invoking `setRecord` method of the contract. // SetRecordUnsigned creates a transaction invoking `setRecord` method of the contract.
@ -313,21 +317,21 @@ func (c *Contract) SetRecordTransaction(name string, typev *big.Int, data string
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) SetRecordUnsigned(name string, typev *big.Int, data string) (*transaction.Transaction, error) { func (c *Contract) SetRecordUnsigned(name string, typev *big.Int, data string) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "setRecord", nil, name, typev, data) return c.actor.MakeUnsignedCall(c.hash, "setRecord", nil, name, typev, data)
} }
// DeleteRecord creates a transaction invoking `deleteRecord` method of the contract. // DeleteRecord creates a transaction invoking `deleteRecord` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) DeleteRecord(name string, typev *big.Int) (util.Uint256, uint32, error) { func (c *Contract) DeleteRecord(name string, typev *big.Int) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "deleteRecord", name, typev) return c.actor.SendCall(c.hash, "deleteRecord", name, typev)
} }
// DeleteRecordTransaction creates a transaction invoking `deleteRecord` method of the contract. // DeleteRecordTransaction creates a transaction invoking `deleteRecord` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) DeleteRecordTransaction(name string, typev *big.Int) (*transaction.Transaction, error) { func (c *Contract) DeleteRecordTransaction(name string, typev *big.Int) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "deleteRecord", name, typev) return c.actor.MakeCall(c.hash, "deleteRecord", name, typev)
} }
// DeleteRecordUnsigned creates a transaction invoking `deleteRecord` method of the contract. // DeleteRecordUnsigned creates a transaction invoking `deleteRecord` method of the contract.
@ -335,7 +339,7 @@ func (c *Contract) DeleteRecordTransaction(name string, typev *big.Int) (*transa
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) DeleteRecordUnsigned(name string, typev *big.Int) (*transaction.Transaction, error) { func (c *Contract) DeleteRecordUnsigned(name string, typev *big.Int) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "deleteRecord", nil, name, typev) return c.actor.MakeUnsignedCall(c.hash, "deleteRecord", nil, name, typev)
} }
// SetAdminEventsFromApplicationLog retrieves a set of all emitted events // SetAdminEventsFromApplicationLog retrieves a set of all emitted events

View file

@ -48,6 +48,7 @@ type Actor interface {
type ContractReader struct { type ContractReader struct {
nep17.TokenReader nep17.TokenReader
invoker Invoker invoker Invoker
hash util.Uint160
} }
// Contract implements all contract methods. // Contract implements all contract methods.
@ -55,51 +56,54 @@ type Contract struct {
ContractReader ContractReader
nep17.TokenWriter nep17.TokenWriter
actor Actor actor Actor
hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.
func NewReader(invoker Invoker) *ContractReader { func NewReader(invoker Invoker) *ContractReader {
return &ContractReader{*nep17.NewReader(invoker, Hash), invoker} var hash = Hash
return &ContractReader{*nep17.NewReader(invoker, hash), invoker, hash}
} }
// New creates an instance of Contract using Hash and the given Actor. // New creates an instance of Contract using Hash and the given Actor.
func New(actor Actor) *Contract { func New(actor Actor) *Contract {
var nep17t = nep17.New(actor, Hash) var hash = Hash
return &Contract{ContractReader{nep17t.TokenReader, actor}, nep17t.TokenWriter, actor} var nep17t = nep17.New(actor, hash)
return &Contract{ContractReader{nep17t.TokenReader, actor, hash}, nep17t.TokenWriter, actor, hash}
} }
// Cap invokes `cap` method of contract. // Cap invokes `cap` method of contract.
func (c *ContractReader) Cap() (*big.Int, error) { func (c *ContractReader) Cap() (*big.Int, error) {
return unwrap.BigInt(c.invoker.Call(Hash, "cap")) return unwrap.BigInt(c.invoker.Call(c.hash, "cap"))
} }
// GetMinter invokes `getMinter` method of contract. // GetMinter invokes `getMinter` method of contract.
func (c *ContractReader) GetMinter() (*keys.PublicKey, error) { func (c *ContractReader) GetMinter() (*keys.PublicKey, error) {
return unwrap.PublicKey(c.invoker.Call(Hash, "getMinter")) return unwrap.PublicKey(c.invoker.Call(c.hash, "getMinter"))
} }
// GetOwner invokes `getOwner` method of contract. // GetOwner invokes `getOwner` method of contract.
func (c *ContractReader) GetOwner() (util.Uint160, error) { func (c *ContractReader) GetOwner() (util.Uint160, error) {
return unwrap.Uint160(c.invoker.Call(Hash, "getOwner")) return unwrap.Uint160(c.invoker.Call(c.hash, "getOwner"))
} }
// TotalMinted invokes `totalMinted` method of contract. // TotalMinted invokes `totalMinted` method of contract.
func (c *ContractReader) TotalMinted() (*big.Int, error) { func (c *ContractReader) TotalMinted() (*big.Int, error) {
return unwrap.BigInt(c.invoker.Call(Hash, "totalMinted")) return unwrap.BigInt(c.invoker.Call(c.hash, "totalMinted"))
} }
// ChangeMinter creates a transaction invoking `changeMinter` method of the contract. // ChangeMinter creates a transaction invoking `changeMinter` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) ChangeMinter(newMinter *keys.PublicKey) (util.Uint256, uint32, error) { func (c *Contract) ChangeMinter(newMinter *keys.PublicKey) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "changeMinter", newMinter) return c.actor.SendCall(c.hash, "changeMinter", newMinter)
} }
// ChangeMinterTransaction creates a transaction invoking `changeMinter` method of the contract. // ChangeMinterTransaction creates a transaction invoking `changeMinter` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) ChangeMinterTransaction(newMinter *keys.PublicKey) (*transaction.Transaction, error) { func (c *Contract) ChangeMinterTransaction(newMinter *keys.PublicKey) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "changeMinter", newMinter) return c.actor.MakeCall(c.hash, "changeMinter", newMinter)
} }
// ChangeMinterUnsigned creates a transaction invoking `changeMinter` method of the contract. // ChangeMinterUnsigned creates a transaction invoking `changeMinter` method of the contract.
@ -107,21 +111,21 @@ func (c *Contract) ChangeMinterTransaction(newMinter *keys.PublicKey) (*transact
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) ChangeMinterUnsigned(newMinter *keys.PublicKey) (*transaction.Transaction, error) { func (c *Contract) ChangeMinterUnsigned(newMinter *keys.PublicKey) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "changeMinter", nil, newMinter) return c.actor.MakeUnsignedCall(c.hash, "changeMinter", nil, newMinter)
} }
// ChangeOwner creates a transaction invoking `changeOwner` method of the contract. // ChangeOwner creates a transaction invoking `changeOwner` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) ChangeOwner(newOwner util.Uint160) (util.Uint256, uint32, error) { func (c *Contract) ChangeOwner(newOwner util.Uint160) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "changeOwner", newOwner) return c.actor.SendCall(c.hash, "changeOwner", newOwner)
} }
// ChangeOwnerTransaction creates a transaction invoking `changeOwner` method of the contract. // ChangeOwnerTransaction creates a transaction invoking `changeOwner` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) ChangeOwnerTransaction(newOwner util.Uint160) (*transaction.Transaction, error) { func (c *Contract) ChangeOwnerTransaction(newOwner util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "changeOwner", newOwner) return c.actor.MakeCall(c.hash, "changeOwner", newOwner)
} }
// ChangeOwnerUnsigned creates a transaction invoking `changeOwner` method of the contract. // ChangeOwnerUnsigned creates a transaction invoking `changeOwner` method of the contract.
@ -129,21 +133,21 @@ func (c *Contract) ChangeOwnerTransaction(newOwner util.Uint160) (*transaction.T
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) ChangeOwnerUnsigned(newOwner util.Uint160) (*transaction.Transaction, error) { func (c *Contract) ChangeOwnerUnsigned(newOwner util.Uint160) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "changeOwner", nil, newOwner) return c.actor.MakeUnsignedCall(c.hash, "changeOwner", nil, newOwner)
} }
// Destroy creates a transaction invoking `destroy` method of the contract. // Destroy creates a transaction invoking `destroy` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Destroy() (util.Uint256, uint32, error) { func (c *Contract) Destroy() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "destroy") return c.actor.SendCall(c.hash, "destroy")
} }
// DestroyTransaction creates a transaction invoking `destroy` method of the contract. // DestroyTransaction creates a transaction invoking `destroy` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) DestroyTransaction() (*transaction.Transaction, error) { func (c *Contract) DestroyTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "destroy") return c.actor.MakeCall(c.hash, "destroy")
} }
// DestroyUnsigned creates a transaction invoking `destroy` method of the contract. // DestroyUnsigned creates a transaction invoking `destroy` method of the contract.
@ -151,21 +155,21 @@ func (c *Contract) DestroyTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) DestroyUnsigned() (*transaction.Transaction, error) { func (c *Contract) DestroyUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "destroy", nil) return c.actor.MakeUnsignedCall(c.hash, "destroy", nil)
} }
// MaxSupply creates a transaction invoking `maxSupply` method of the contract. // MaxSupply creates a transaction invoking `maxSupply` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) MaxSupply() (util.Uint256, uint32, error) { func (c *Contract) MaxSupply() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "maxSupply") return c.actor.SendCall(c.hash, "maxSupply")
} }
// MaxSupplyTransaction creates a transaction invoking `maxSupply` method of the contract. // MaxSupplyTransaction creates a transaction invoking `maxSupply` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) MaxSupplyTransaction() (*transaction.Transaction, error) { func (c *Contract) MaxSupplyTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "maxSupply") return c.actor.MakeCall(c.hash, "maxSupply")
} }
// MaxSupplyUnsigned creates a transaction invoking `maxSupply` method of the contract. // MaxSupplyUnsigned creates a transaction invoking `maxSupply` method of the contract.
@ -173,21 +177,21 @@ func (c *Contract) MaxSupplyTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) MaxSupplyUnsigned() (*transaction.Transaction, error) { func (c *Contract) MaxSupplyUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "maxSupply", nil) return c.actor.MakeUnsignedCall(c.hash, "maxSupply", nil)
} }
// Mint creates a transaction invoking `mint` method of the contract. // Mint creates a transaction invoking `mint` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Mint(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data any) (util.Uint256, uint32, error) { func (c *Contract) Mint(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data any) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "mint", from, to, amount, swapId, signature, data) return c.actor.SendCall(c.hash, "mint", from, to, amount, swapId, signature, data)
} }
// MintTransaction creates a transaction invoking `mint` method of the contract. // MintTransaction creates a transaction invoking `mint` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) MintTransaction(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data any) (*transaction.Transaction, error) { func (c *Contract) MintTransaction(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data any) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "mint", from, to, amount, swapId, signature, data) return c.actor.MakeCall(c.hash, "mint", from, to, amount, swapId, signature, data)
} }
// MintUnsigned creates a transaction invoking `mint` method of the contract. // MintUnsigned creates a transaction invoking `mint` method of the contract.
@ -195,21 +199,21 @@ func (c *Contract) MintTransaction(from util.Uint160, to util.Uint160, amount *b
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) MintUnsigned(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data any) (*transaction.Transaction, error) { func (c *Contract) MintUnsigned(from util.Uint160, to util.Uint160, amount *big.Int, swapId *big.Int, signature []byte, data any) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "mint", nil, from, to, amount, swapId, signature, data) return c.actor.MakeUnsignedCall(c.hash, "mint", nil, from, to, amount, swapId, signature, data)
} }
// Update creates a transaction invoking `update` method of the contract. // Update creates a transaction invoking `update` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Update(nef []byte, manifest []byte) (util.Uint256, uint32, error) { func (c *Contract) Update(nef []byte, manifest []byte) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "update", nef, manifest) return c.actor.SendCall(c.hash, "update", nef, manifest)
} }
// UpdateTransaction creates a transaction invoking `update` method of the contract. // UpdateTransaction creates a transaction invoking `update` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) UpdateTransaction(nef []byte, manifest []byte) (*transaction.Transaction, error) { func (c *Contract) UpdateTransaction(nef []byte, manifest []byte) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "update", nef, manifest) return c.actor.MakeCall(c.hash, "update", nef, manifest)
} }
// UpdateUnsigned creates a transaction invoking `update` method of the contract. // UpdateUnsigned creates a transaction invoking `update` method of the contract.
@ -217,21 +221,21 @@ func (c *Contract) UpdateTransaction(nef []byte, manifest []byte) (*transaction.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) UpdateUnsigned(nef []byte, manifest []byte) (*transaction.Transaction, error) { func (c *Contract) UpdateUnsigned(nef []byte, manifest []byte) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "update", nil, nef, manifest) return c.actor.MakeUnsignedCall(c.hash, "update", nil, nef, manifest)
} }
// UpdateCap creates a transaction invoking `updateCap` method of the contract. // UpdateCap creates a transaction invoking `updateCap` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) UpdateCap(newCap *big.Int) (util.Uint256, uint32, error) { func (c *Contract) UpdateCap(newCap *big.Int) (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "updateCap", newCap) return c.actor.SendCall(c.hash, "updateCap", newCap)
} }
// UpdateCapTransaction creates a transaction invoking `updateCap` method of the contract. // UpdateCapTransaction creates a transaction invoking `updateCap` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) UpdateCapTransaction(newCap *big.Int) (*transaction.Transaction, error) { func (c *Contract) UpdateCapTransaction(newCap *big.Int) (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "updateCap", newCap) return c.actor.MakeCall(c.hash, "updateCap", newCap)
} }
// UpdateCapUnsigned creates a transaction invoking `updateCap` method of the contract. // UpdateCapUnsigned creates a transaction invoking `updateCap` method of the contract.
@ -239,7 +243,7 @@ func (c *Contract) UpdateCapTransaction(newCap *big.Int) (*transaction.Transacti
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) UpdateCapUnsigned(newCap *big.Int) (*transaction.Transaction, error) { func (c *Contract) UpdateCapUnsigned(newCap *big.Int) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "updateCap", nil, newCap) return c.actor.MakeUnsignedCall(c.hash, "updateCap", nil, newCap)
} }
// OnMintEventsFromApplicationLog retrieves a set of all emitted events // OnMintEventsFromApplicationLog retrieves a set of all emitted events

View file

@ -23,16 +23,18 @@ type Invoker interface {
// ContractReader implements safe contract methods. // ContractReader implements safe contract methods.
type ContractReader struct { type ContractReader struct {
invoker Invoker invoker Invoker
hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.
func NewReader(invoker Invoker) *ContractReader { func NewReader(invoker Invoker) *ContractReader {
return &ContractReader{invoker} var hash = Hash
return &ContractReader{invoker, hash}
} }
// Tokens invokes `tokens` method of contract. // Tokens invokes `tokens` method of contract.
func (c *ContractReader) Tokens() (uuid.UUID, result.Iterator, error) { func (c *ContractReader) Tokens() (uuid.UUID, result.Iterator, error) {
return unwrap.SessionIterator(c.invoker.Call(Hash, "tokens")) return unwrap.SessionIterator(c.invoker.Call(c.hash, "tokens"))
} }
// TokensExpanded is similar to Tokens (uses the same contract // TokensExpanded is similar to Tokens (uses the same contract
@ -41,12 +43,12 @@ func (c *ContractReader) Tokens() (uuid.UUID, result.Iterator, error) {
// number of result items from the iterator right in the VM and return them to // 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. // you. It's only limited by VM stack and GAS available for RPC invocations.
func (c *ContractReader) TokensExpanded(_numOfIteratorItems int) ([]stackitem.Item, error) { func (c *ContractReader) TokensExpanded(_numOfIteratorItems int) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.CallAndExpandIterator(Hash, "tokens", _numOfIteratorItems)) return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "tokens", _numOfIteratorItems))
} }
// GetAllRecords invokes `getAllRecords` method of contract. // GetAllRecords invokes `getAllRecords` method of contract.
func (c *ContractReader) GetAllRecords(name string) (uuid.UUID, result.Iterator, error) { func (c *ContractReader) GetAllRecords(name string) (uuid.UUID, result.Iterator, error) {
return unwrap.SessionIterator(c.invoker.Call(Hash, "getAllRecords", name)) return unwrap.SessionIterator(c.invoker.Call(c.hash, "getAllRecords", name))
} }
// GetAllRecordsExpanded is similar to GetAllRecords (uses the same contract // GetAllRecordsExpanded is similar to GetAllRecords (uses the same contract
@ -55,5 +57,5 @@ func (c *ContractReader) GetAllRecords(name string) (uuid.UUID, result.Iterator,
// number of result items from the iterator right in the VM and return them to // 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. // you. It's only limited by VM stack and GAS available for RPC invocations.
func (c *ContractReader) GetAllRecordsExpanded(name string, _numOfIteratorItems int) ([]stackitem.Item, error) { func (c *ContractReader) GetAllRecordsExpanded(name string, _numOfIteratorItems int) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.CallAndExpandIterator(Hash, "getAllRecords", _numOfIteratorItems, name)) return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "getAllRecords", _numOfIteratorItems, name))
} }

View file

@ -110,25 +110,27 @@ type Actor interface {
// Contract implements all contract methods. // Contract implements all contract methods.
type Contract struct { type Contract struct {
actor Actor actor Actor
hash util.Uint160
} }
// New creates an instance of Contract using Hash and the given Actor. // New creates an instance of Contract using Hash and the given Actor.
func New(actor Actor) *Contract { func New(actor Actor) *Contract {
return &Contract{actor} var hash = Hash
return &Contract{actor, hash}
} }
// Array creates a transaction invoking `array` method of the contract. // Array creates a transaction invoking `array` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Array() (util.Uint256, uint32, error) { func (c *Contract) Array() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "array") return c.actor.SendCall(c.hash, "array")
} }
// ArrayTransaction creates a transaction invoking `array` method of the contract. // ArrayTransaction creates a transaction invoking `array` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) { func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "array") return c.actor.MakeCall(c.hash, "array")
} }
// ArrayUnsigned creates a transaction invoking `array` method of the contract. // ArrayUnsigned creates a transaction invoking `array` method of the contract.
@ -136,21 +138,21 @@ func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) { func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "array", nil) return c.actor.MakeUnsignedCall(c.hash, "array", nil)
} }
// CrazyMap creates a transaction invoking `crazyMap` method of the contract. // CrazyMap creates a transaction invoking `crazyMap` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) CrazyMap() (util.Uint256, uint32, error) { func (c *Contract) CrazyMap() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "crazyMap") return c.actor.SendCall(c.hash, "crazyMap")
} }
// CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract. // CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) { func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "crazyMap") return c.actor.MakeCall(c.hash, "crazyMap")
} }
// CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract. // CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract.
@ -158,21 +160,21 @@ func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) { func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "crazyMap", nil) return c.actor.MakeUnsignedCall(c.hash, "crazyMap", nil)
} }
// Main creates a transaction invoking `main` method of the contract. // Main creates a transaction invoking `main` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Main() (util.Uint256, uint32, error) { func (c *Contract) Main() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "main") return c.actor.SendCall(c.hash, "main")
} }
// MainTransaction creates a transaction invoking `main` method of the contract. // MainTransaction creates a transaction invoking `main` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) MainTransaction() (*transaction.Transaction, error) { func (c *Contract) MainTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "main") return c.actor.MakeCall(c.hash, "main")
} }
// MainUnsigned creates a transaction invoking `main` method of the contract. // MainUnsigned creates a transaction invoking `main` method of the contract.
@ -180,21 +182,21 @@ func (c *Contract) MainTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) MainUnsigned() (*transaction.Transaction, error) { func (c *Contract) MainUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "main", nil) return c.actor.MakeUnsignedCall(c.hash, "main", nil)
} }
// Struct creates a transaction invoking `struct` method of the contract. // Struct creates a transaction invoking `struct` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Struct() (util.Uint256, uint32, error) { func (c *Contract) Struct() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "struct") return c.actor.SendCall(c.hash, "struct")
} }
// StructTransaction creates a transaction invoking `struct` method of the contract. // StructTransaction creates a transaction invoking `struct` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) StructTransaction() (*transaction.Transaction, error) { func (c *Contract) StructTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "struct") return c.actor.MakeCall(c.hash, "struct")
} }
// StructUnsigned creates a transaction invoking `struct` method of the contract. // StructUnsigned creates a transaction invoking `struct` method of the contract.
@ -202,7 +204,7 @@ func (c *Contract) StructTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) StructUnsigned() (*transaction.Transaction, error) { func (c *Contract) StructUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "struct", nil) return c.actor.MakeUnsignedCall(c.hash, "struct", nil)
} }
// itemToLedgerBlock converts stack item into *LedgerBlock. // itemToLedgerBlock converts stack item into *LedgerBlock.

View file

@ -116,25 +116,27 @@ type Actor interface {
// Contract implements all contract methods. // Contract implements all contract methods.
type Contract struct { type Contract struct {
actor Actor actor Actor
hash util.Uint160
} }
// New creates an instance of Contract using Hash and the given Actor. // New creates an instance of Contract using Hash and the given Actor.
func New(actor Actor) *Contract { func New(actor Actor) *Contract {
return &Contract{actor} var hash = Hash
return &Contract{actor, hash}
} }
// Array creates a transaction invoking `array` method of the contract. // Array creates a transaction invoking `array` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Array() (util.Uint256, uint32, error) { func (c *Contract) Array() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "array") return c.actor.SendCall(c.hash, "array")
} }
// ArrayTransaction creates a transaction invoking `array` method of the contract. // ArrayTransaction creates a transaction invoking `array` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) { func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "array") return c.actor.MakeCall(c.hash, "array")
} }
// ArrayUnsigned creates a transaction invoking `array` method of the contract. // ArrayUnsigned creates a transaction invoking `array` method of the contract.
@ -142,21 +144,21 @@ func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) { func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "array", nil) return c.actor.MakeUnsignedCall(c.hash, "array", nil)
} }
// CrazyMap creates a transaction invoking `crazyMap` method of the contract. // CrazyMap creates a transaction invoking `crazyMap` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) CrazyMap() (util.Uint256, uint32, error) { func (c *Contract) CrazyMap() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "crazyMap") return c.actor.SendCall(c.hash, "crazyMap")
} }
// CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract. // CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) { func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "crazyMap") return c.actor.MakeCall(c.hash, "crazyMap")
} }
// CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract. // CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract.
@ -164,21 +166,21 @@ func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) { func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "crazyMap", nil) return c.actor.MakeUnsignedCall(c.hash, "crazyMap", nil)
} }
// Main creates a transaction invoking `main` method of the contract. // Main creates a transaction invoking `main` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Main() (util.Uint256, uint32, error) { func (c *Contract) Main() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "main") return c.actor.SendCall(c.hash, "main")
} }
// MainTransaction creates a transaction invoking `main` method of the contract. // MainTransaction creates a transaction invoking `main` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) MainTransaction() (*transaction.Transaction, error) { func (c *Contract) MainTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "main") return c.actor.MakeCall(c.hash, "main")
} }
// MainUnsigned creates a transaction invoking `main` method of the contract. // MainUnsigned creates a transaction invoking `main` method of the contract.
@ -186,21 +188,21 @@ func (c *Contract) MainTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) MainUnsigned() (*transaction.Transaction, error) { func (c *Contract) MainUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "main", nil) return c.actor.MakeUnsignedCall(c.hash, "main", nil)
} }
// Struct creates a transaction invoking `struct` method of the contract. // Struct creates a transaction invoking `struct` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Struct() (util.Uint256, uint32, error) { func (c *Contract) Struct() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "struct") return c.actor.SendCall(c.hash, "struct")
} }
// StructTransaction creates a transaction invoking `struct` method of the contract. // StructTransaction creates a transaction invoking `struct` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) StructTransaction() (*transaction.Transaction, error) { func (c *Contract) StructTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "struct") return c.actor.MakeCall(c.hash, "struct")
} }
// StructUnsigned creates a transaction invoking `struct` method of the contract. // StructUnsigned creates a transaction invoking `struct` method of the contract.
@ -208,7 +210,7 @@ func (c *Contract) StructTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) StructUnsigned() (*transaction.Transaction, error) { func (c *Contract) StructUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "struct", nil) return c.actor.MakeUnsignedCall(c.hash, "struct", nil)
} }
// itemToCrazyStruct converts stack item into *CrazyStruct. // itemToCrazyStruct converts stack item into *CrazyStruct.

View file

@ -116,25 +116,27 @@ type Actor interface {
// Contract implements all contract methods. // Contract implements all contract methods.
type Contract struct { type Contract struct {
actor Actor actor Actor
hash util.Uint160
} }
// New creates an instance of Contract using Hash and the given Actor. // New creates an instance of Contract using Hash and the given Actor.
func New(actor Actor) *Contract { func New(actor Actor) *Contract {
return &Contract{actor} var hash = Hash
return &Contract{actor, hash}
} }
// Array creates a transaction invoking `array` method of the contract. // Array creates a transaction invoking `array` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Array() (util.Uint256, uint32, error) { func (c *Contract) Array() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "array") return c.actor.SendCall(c.hash, "array")
} }
// ArrayTransaction creates a transaction invoking `array` method of the contract. // ArrayTransaction creates a transaction invoking `array` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) { func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "array") return c.actor.MakeCall(c.hash, "array")
} }
// ArrayUnsigned creates a transaction invoking `array` method of the contract. // ArrayUnsigned creates a transaction invoking `array` method of the contract.
@ -142,21 +144,21 @@ func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) { func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "array", nil) return c.actor.MakeUnsignedCall(c.hash, "array", nil)
} }
// CrazyMap creates a transaction invoking `crazyMap` method of the contract. // CrazyMap creates a transaction invoking `crazyMap` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) CrazyMap() (util.Uint256, uint32, error) { func (c *Contract) CrazyMap() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "crazyMap") return c.actor.SendCall(c.hash, "crazyMap")
} }
// CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract. // CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) { func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "crazyMap") return c.actor.MakeCall(c.hash, "crazyMap")
} }
// CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract. // CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract.
@ -164,21 +166,21 @@ func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) { func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "crazyMap", nil) return c.actor.MakeUnsignedCall(c.hash, "crazyMap", nil)
} }
// Main creates a transaction invoking `main` method of the contract. // Main creates a transaction invoking `main` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Main() (util.Uint256, uint32, error) { func (c *Contract) Main() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "main") return c.actor.SendCall(c.hash, "main")
} }
// MainTransaction creates a transaction invoking `main` method of the contract. // MainTransaction creates a transaction invoking `main` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) MainTransaction() (*transaction.Transaction, error) { func (c *Contract) MainTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "main") return c.actor.MakeCall(c.hash, "main")
} }
// MainUnsigned creates a transaction invoking `main` method of the contract. // MainUnsigned creates a transaction invoking `main` method of the contract.
@ -186,21 +188,21 @@ func (c *Contract) MainTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) MainUnsigned() (*transaction.Transaction, error) { func (c *Contract) MainUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "main", nil) return c.actor.MakeUnsignedCall(c.hash, "main", nil)
} }
// Struct creates a transaction invoking `struct` method of the contract. // Struct creates a transaction invoking `struct` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Struct() (util.Uint256, uint32, error) { func (c *Contract) Struct() (util.Uint256, uint32, error) {
return c.actor.SendCall(Hash, "struct") return c.actor.SendCall(c.hash, "struct")
} }
// StructTransaction creates a transaction invoking `struct` method of the contract. // StructTransaction creates a transaction invoking `struct` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) StructTransaction() (*transaction.Transaction, error) { func (c *Contract) StructTransaction() (*transaction.Transaction, error) {
return c.actor.MakeCall(Hash, "struct") return c.actor.MakeCall(c.hash, "struct")
} }
// StructUnsigned creates a transaction invoking `struct` method of the contract. // StructUnsigned creates a transaction invoking `struct` method of the contract.
@ -208,7 +210,7 @@ func (c *Contract) StructTransaction() (*transaction.Transaction, error) {
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) StructUnsigned() (*transaction.Transaction, error) { func (c *Contract) StructUnsigned() (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(Hash, "struct", nil) return c.actor.MakeUnsignedCall(c.hash, "struct", nil)
} }
// itemToLedgerBlock converts stack item into *LedgerBlock. // itemToLedgerBlock converts stack item into *LedgerBlock.

View file

@ -162,31 +162,33 @@ type Invoker interface {
// ContractReader implements safe contract methods. // ContractReader implements safe contract methods.
type ContractReader struct { type ContractReader struct {
invoker Invoker invoker Invoker
hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.
func NewReader(invoker Invoker) *ContractReader { func NewReader(invoker Invoker) *ContractReader {
return &ContractReader{invoker} var hash = Hash
return &ContractReader{invoker, hash}
} }
// Block invokes `block` method of contract. // Block invokes `block` method of contract.
func (c *ContractReader) Block(b *LedgerBlock) (*LedgerBlock, error) { func (c *ContractReader) Block(b *LedgerBlock) (*LedgerBlock, error) {
return itemToLedgerBlock(unwrap.Item(c.invoker.Call(Hash, "block", b))) return itemToLedgerBlock(unwrap.Item(c.invoker.Call(c.hash, "block", b)))
} }
// Contract invokes `contract` method of contract. // Contract invokes `contract` method of contract.
func (c *ContractReader) Contract(mc *ManagementContract) (*ManagementContract, error) { func (c *ContractReader) Contract(mc *ManagementContract) (*ManagementContract, error) {
return itemToManagementContract(unwrap.Item(c.invoker.Call(Hash, "contract", mc))) return itemToManagementContract(unwrap.Item(c.invoker.Call(c.hash, "contract", mc)))
} }
// Struct invokes `struct` method of contract. // Struct invokes `struct` method of contract.
func (c *ContractReader) Struct(s *StructsInternal) (*StructsInternal, error) { func (c *ContractReader) Struct(s *StructsInternal) (*StructsInternal, error) {
return itemToStructsInternal(unwrap.Item(c.invoker.Call(Hash, "struct", s))) return itemToStructsInternal(unwrap.Item(c.invoker.Call(c.hash, "struct", s)))
} }
// Transaction invokes `transaction` method of contract. // Transaction invokes `transaction` method of contract.
func (c *ContractReader) Transaction(t *LedgerTransaction) (*LedgerTransaction, error) { func (c *ContractReader) Transaction(t *LedgerTransaction) (*LedgerTransaction, error) {
return itemToLedgerTransaction(unwrap.Item(c.invoker.Call(Hash, "transaction", t))) return itemToLedgerTransaction(unwrap.Item(c.invoker.Call(c.hash, "transaction", t)))
} }
// itemToLedgerBlock converts stack item into *LedgerBlock. // itemToLedgerBlock converts stack item into *LedgerBlock.

File diff suppressed because it is too large Load diff

View file

@ -24,11 +24,13 @@ type Invoker interface {
// ContractReader implements safe contract methods. // ContractReader implements safe contract methods.
type ContractReader struct { type ContractReader struct {
invoker Invoker invoker Invoker
hash util.Uint160
} }
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using Hash and the given Invoker.
func NewReader(invoker Invoker) *ContractReader { func NewReader(invoker Invoker) *ContractReader {
return &ContractReader{invoker} var hash = Hash
return &ContractReader{invoker, hash}
} }
// AAAStrings invokes `aAAStrings` method of contract. // AAAStrings invokes `aAAStrings` method of contract.
@ -86,7 +88,7 @@ func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) {
} }
return res, nil return res, nil
} (item) } (item)
} (unwrap.Item(c.invoker.Call(Hash, "aAAStrings", s))) } (unwrap.Item(c.invoker.Call(c.hash, "aAAStrings", s)))
} }
// Any invokes `any` method of contract. // Any invokes `any` method of contract.
@ -96,7 +98,7 @@ func (c *ContractReader) Any(a any) (any, error) {
return nil, err return nil, err
} }
return item.Value(), error(nil) return item.Value(), error(nil)
} (unwrap.Item(c.invoker.Call(Hash, "any", a))) } (unwrap.Item(c.invoker.Call(c.hash, "any", a)))
} }
// AnyMaps invokes `anyMaps` method of contract. // AnyMaps invokes `anyMaps` method of contract.
@ -124,27 +126,27 @@ func (c *ContractReader) AnyMaps(m map[*big.Int]any) (map[*big.Int]any, error) {
} }
return res, nil return res, nil
} (item) } (item)
} (unwrap.Item(c.invoker.Call(Hash, "anyMaps", m))) } (unwrap.Item(c.invoker.Call(c.hash, "anyMaps", m)))
} }
// Bool invokes `bool` method of contract. // Bool invokes `bool` method of contract.
func (c *ContractReader) Bool(b bool) (bool, error) { func (c *ContractReader) Bool(b bool) (bool, error) {
return unwrap.Bool(c.invoker.Call(Hash, "bool", b)) return unwrap.Bool(c.invoker.Call(c.hash, "bool", b))
} }
// Bools invokes `bools` method of contract. // Bools invokes `bools` method of contract.
func (c *ContractReader) Bools(b []bool) ([]bool, error) { func (c *ContractReader) Bools(b []bool) ([]bool, error) {
return unwrap.ArrayOfBools(c.invoker.Call(Hash, "bools", b)) return unwrap.ArrayOfBools(c.invoker.Call(c.hash, "bools", b))
} }
// Bytes invokes `bytes` method of contract. // Bytes invokes `bytes` method of contract.
func (c *ContractReader) Bytes(b []byte) ([]byte, error) { func (c *ContractReader) Bytes(b []byte) ([]byte, error) {
return unwrap.Bytes(c.invoker.Call(Hash, "bytes", b)) return unwrap.Bytes(c.invoker.Call(c.hash, "bytes", b))
} }
// Bytess invokes `bytess` method of contract. // Bytess invokes `bytess` method of contract.
func (c *ContractReader) Bytess(b [][]byte) ([][]byte, error) { func (c *ContractReader) Bytess(b [][]byte) ([][]byte, error) {
return unwrap.ArrayOfBytes(c.invoker.Call(Hash, "bytess", b)) return unwrap.ArrayOfBytes(c.invoker.Call(c.hash, "bytess", b))
} }
// CrazyMaps invokes `crazyMaps` method of contract. // CrazyMaps invokes `crazyMaps` method of contract.
@ -235,37 +237,37 @@ func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (
} }
return res, nil return res, nil
} (item) } (item)
} (unwrap.Item(c.invoker.Call(Hash, "crazyMaps", m))) } (unwrap.Item(c.invoker.Call(c.hash, "crazyMaps", m)))
} }
// Hash160 invokes `hash160` method of contract. // Hash160 invokes `hash160` method of contract.
func (c *ContractReader) Hash160(h util.Uint160) (util.Uint160, error) { func (c *ContractReader) Hash160(h util.Uint160) (util.Uint160, error) {
return unwrap.Uint160(c.invoker.Call(Hash, "hash160", h)) return unwrap.Uint160(c.invoker.Call(c.hash, "hash160", h))
} }
// Hash160s invokes `hash160s` method of contract. // Hash160s invokes `hash160s` method of contract.
func (c *ContractReader) Hash160s(h []util.Uint160) ([]util.Uint160, error) { func (c *ContractReader) Hash160s(h []util.Uint160) ([]util.Uint160, error) {
return unwrap.ArrayOfUint160(c.invoker.Call(Hash, "hash160s", h)) return unwrap.ArrayOfUint160(c.invoker.Call(c.hash, "hash160s", h))
} }
// Hash256 invokes `hash256` method of contract. // Hash256 invokes `hash256` method of contract.
func (c *ContractReader) Hash256(h util.Uint256) (util.Uint256, error) { func (c *ContractReader) Hash256(h util.Uint256) (util.Uint256, error) {
return unwrap.Uint256(c.invoker.Call(Hash, "hash256", h)) return unwrap.Uint256(c.invoker.Call(c.hash, "hash256", h))
} }
// Hash256s invokes `hash256s` method of contract. // Hash256s invokes `hash256s` method of contract.
func (c *ContractReader) Hash256s(h []util.Uint256) ([]util.Uint256, error) { func (c *ContractReader) Hash256s(h []util.Uint256) ([]util.Uint256, error) {
return unwrap.ArrayOfUint256(c.invoker.Call(Hash, "hash256s", h)) return unwrap.ArrayOfUint256(c.invoker.Call(c.hash, "hash256s", h))
} }
// Int invokes `int` method of contract. // Int invokes `int` method of contract.
func (c *ContractReader) Int(i *big.Int) (*big.Int, error) { func (c *ContractReader) Int(i *big.Int) (*big.Int, error) {
return unwrap.BigInt(c.invoker.Call(Hash, "int", i)) return unwrap.BigInt(c.invoker.Call(c.hash, "int", i))
} }
// Ints invokes `ints` method of contract. // Ints invokes `ints` method of contract.
func (c *ContractReader) Ints(i []*big.Int) ([]*big.Int, error) { func (c *ContractReader) Ints(i []*big.Int) ([]*big.Int, error) {
return unwrap.ArrayOfBigInts(c.invoker.Call(Hash, "ints", i)) return unwrap.ArrayOfBigInts(c.invoker.Call(c.hash, "ints", i))
} }
// Maps invokes `maps` method of contract. // Maps invokes `maps` method of contract.
@ -311,35 +313,35 @@ func (c *ContractReader) Maps(m map[string]string) (map[string]string, error) {
} }
return res, nil return res, nil
} (item) } (item)
} (unwrap.Item(c.invoker.Call(Hash, "maps", m))) } (unwrap.Item(c.invoker.Call(c.hash, "maps", m)))
} }
// PublicKey invokes `publicKey` method of contract. // PublicKey invokes `publicKey` method of contract.
func (c *ContractReader) PublicKey(k *keys.PublicKey) (*keys.PublicKey, error) { func (c *ContractReader) PublicKey(k *keys.PublicKey) (*keys.PublicKey, error) {
return unwrap.PublicKey(c.invoker.Call(Hash, "publicKey", k)) return unwrap.PublicKey(c.invoker.Call(c.hash, "publicKey", k))
} }
// PublicKeys invokes `publicKeys` method of contract. // PublicKeys invokes `publicKeys` method of contract.
func (c *ContractReader) PublicKeys(k keys.PublicKeys) (keys.PublicKeys, error) { func (c *ContractReader) PublicKeys(k keys.PublicKeys) (keys.PublicKeys, error) {
return unwrap.ArrayOfPublicKeys(c.invoker.Call(Hash, "publicKeys", k)) return unwrap.ArrayOfPublicKeys(c.invoker.Call(c.hash, "publicKeys", k))
} }
// Signature invokes `signature` method of contract. // Signature invokes `signature` method of contract.
func (c *ContractReader) Signature(s []byte) ([]byte, error) { func (c *ContractReader) Signature(s []byte) ([]byte, error) {
return unwrap.Bytes(c.invoker.Call(Hash, "signature", s)) return unwrap.Bytes(c.invoker.Call(c.hash, "signature", s))
} }
// Signatures invokes `signatures` method of contract. // Signatures invokes `signatures` method of contract.
func (c *ContractReader) Signatures(s [][]byte) ([][]byte, error) { func (c *ContractReader) Signatures(s [][]byte) ([][]byte, error) {
return unwrap.ArrayOfBytes(c.invoker.Call(Hash, "signatures", s)) return unwrap.ArrayOfBytes(c.invoker.Call(c.hash, "signatures", s))
} }
// String invokes `string` method of contract. // String invokes `string` method of contract.
func (c *ContractReader) String(s string) (string, error) { func (c *ContractReader) String(s string) (string, error) {
return unwrap.UTF8String(c.invoker.Call(Hash, "string", s)) return unwrap.UTF8String(c.invoker.Call(c.hash, "string", s))
} }
// Strings invokes `strings` method of contract. // Strings invokes `strings` method of contract.
func (c *ContractReader) Strings(s []string) ([]string, error) { func (c *ContractReader) Strings(s []string) ([]string, error) {
return unwrap.ArrayOfUTF8Strings(c.invoker.Call(Hash, "strings", s)) return unwrap.ArrayOfUTF8Strings(c.invoker.Call(c.hash, "strings", s))
} }

View file

@ -0,0 +1,343 @@
// Package types contains RPC wrappers for Types contract.
package types
import (
"errors"
"fmt"
"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"
"unicode/utf8"
)
// Invoker is used by ContractReader to call various safe methods.
type Invoker interface {
Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
}
// ContractReader implements safe contract methods.
type ContractReader struct {
invoker Invoker
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}
}
// AAAStrings invokes `aAAStrings` method of contract.
func (c *ContractReader) AAAStrings(s [][][]string) ([][][]string, error) {
return func (item stackitem.Item, err error) ([][][]string, error) {
if err != nil {
return nil, err
}
return func (item stackitem.Item) ([][][]string, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([][][]string, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) ([][]string, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([][]string, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) ([]string, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([]string, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
return "", err
}
if !utf8.Valid(b) {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (item)
} (unwrap.Item(c.invoker.Call(c.hash, "aAAStrings", s)))
}
// Any invokes `any` method of contract.
func (c *ContractReader) Any(a any) (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, "any", a)))
}
// AnyMaps invokes `anyMaps` method of contract.
func (c *ContractReader) AnyMaps(m map[*big.Int]any) (map[*big.Int]any, error) {
return func (item stackitem.Item, err error) (map[*big.Int]any, error) {
if err != nil {
return nil, err
}
return func (item stackitem.Item) (map[*big.Int]any, error) {
m, ok := item.Value().([]stackitem.MapElement)
if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String())
}
res := make(map[*big.Int]any)
for i := range m {
k, err := m[i].Key.TryInteger()
if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err)
}
v, err := m[i].Value.Value(), error(nil)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (item)
} (unwrap.Item(c.invoker.Call(c.hash, "anyMaps", m)))
}
// Bool invokes `bool` method of contract.
func (c *ContractReader) Bool(b bool) (bool, error) {
return unwrap.Bool(c.invoker.Call(c.hash, "bool", b))
}
// Bools invokes `bools` method of contract.
func (c *ContractReader) Bools(b []bool) ([]bool, error) {
return unwrap.ArrayOfBools(c.invoker.Call(c.hash, "bools", b))
}
// Bytes invokes `bytes` method of contract.
func (c *ContractReader) Bytes(b []byte) ([]byte, error) {
return unwrap.Bytes(c.invoker.Call(c.hash, "bytes", b))
}
// Bytess invokes `bytess` method of contract.
func (c *ContractReader) Bytess(b [][]byte) ([][]byte, error) {
return unwrap.ArrayOfBytes(c.invoker.Call(c.hash, "bytess", b))
}
// CrazyMaps invokes `crazyMaps` method of contract.
func (c *ContractReader) CrazyMaps(m map[*big.Int][]map[string][]util.Uint160) (map[*big.Int][]map[string][]util.Uint160, error) {
return func (item stackitem.Item, err error) (map[*big.Int][]map[string][]util.Uint160, error) {
if err != nil {
return nil, err
}
return func (item stackitem.Item) (map[*big.Int][]map[string][]util.Uint160, error) {
m, ok := item.Value().([]stackitem.MapElement)
if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String())
}
res := make(map[*big.Int][]map[string][]util.Uint160)
for i := range m {
k, err := m[i].Key.TryInteger()
if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err)
}
v, err := func (item stackitem.Item) ([]map[string][]util.Uint160, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([]map[string][]util.Uint160, len(arr))
for i := range res {
res[i], err = func (item stackitem.Item) (map[string][]util.Uint160, error) {
m, ok := item.Value().([]stackitem.MapElement)
if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String())
}
res := make(map[string][]util.Uint160)
for i := range m {
k, err := func (item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
return "", err
}
if !utf8.Valid(b) {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (m[i].Key)
if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err)
}
v, err := func (item stackitem.Item) ([]util.Uint160, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([]util.Uint160, len(arr))
for i := range res {
res[i], 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[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (arr[i])
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (item)
} (unwrap.Item(c.invoker.Call(c.hash, "crazyMaps", m)))
}
// Hash160 invokes `hash160` method of contract.
func (c *ContractReader) Hash160(h util.Uint160) (util.Uint160, error) {
return unwrap.Uint160(c.invoker.Call(c.hash, "hash160", h))
}
// Hash160s invokes `hash160s` method of contract.
func (c *ContractReader) Hash160s(h []util.Uint160) ([]util.Uint160, error) {
return unwrap.ArrayOfUint160(c.invoker.Call(c.hash, "hash160s", h))
}
// Hash256 invokes `hash256` method of contract.
func (c *ContractReader) Hash256(h util.Uint256) (util.Uint256, error) {
return unwrap.Uint256(c.invoker.Call(c.hash, "hash256", h))
}
// Hash256s invokes `hash256s` method of contract.
func (c *ContractReader) Hash256s(h []util.Uint256) ([]util.Uint256, error) {
return unwrap.ArrayOfUint256(c.invoker.Call(c.hash, "hash256s", h))
}
// Int invokes `int` method of contract.
func (c *ContractReader) Int(i *big.Int) (*big.Int, error) {
return unwrap.BigInt(c.invoker.Call(c.hash, "int", i))
}
// Ints invokes `ints` method of contract.
func (c *ContractReader) Ints(i []*big.Int) ([]*big.Int, error) {
return unwrap.ArrayOfBigInts(c.invoker.Call(c.hash, "ints", i))
}
// Maps invokes `maps` method of contract.
func (c *ContractReader) Maps(m map[string]string) (map[string]string, error) {
return func (item stackitem.Item, err error) (map[string]string, error) {
if err != nil {
return nil, err
}
return func (item stackitem.Item) (map[string]string, error) {
m, ok := item.Value().([]stackitem.MapElement)
if !ok {
return nil, fmt.Errorf("%s is not a map", item.Type().String())
}
res := make(map[string]string)
for i := range m {
k, err := func (item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
return "", err
}
if !utf8.Valid(b) {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (m[i].Key)
if err != nil {
return nil, fmt.Errorf("key %d: %w", i, err)
}
v, err := func (item stackitem.Item) (string, error) {
b, err := item.TryBytes()
if err != nil {
return "", err
}
if !utf8.Valid(b) {
return "", errors.New("not a UTF-8 string")
}
return string(b), nil
} (m[i].Value)
if err != nil {
return nil, fmt.Errorf("value %d: %w", i, err)
}
res[k] = v
}
return res, nil
} (item)
} (unwrap.Item(c.invoker.Call(c.hash, "maps", m)))
}
// PublicKey invokes `publicKey` method of contract.
func (c *ContractReader) PublicKey(k *keys.PublicKey) (*keys.PublicKey, error) {
return unwrap.PublicKey(c.invoker.Call(c.hash, "publicKey", k))
}
// PublicKeys invokes `publicKeys` method of contract.
func (c *ContractReader) PublicKeys(k keys.PublicKeys) (keys.PublicKeys, error) {
return unwrap.ArrayOfPublicKeys(c.invoker.Call(c.hash, "publicKeys", k))
}
// Signature invokes `signature` method of contract.
func (c *ContractReader) Signature(s []byte) ([]byte, error) {
return unwrap.Bytes(c.invoker.Call(c.hash, "signature", s))
}
// Signatures invokes `signatures` method of contract.
func (c *ContractReader) Signatures(s [][]byte) ([][]byte, error) {
return unwrap.ArrayOfBytes(c.invoker.Call(c.hash, "signatures", s))
}
// String invokes `string` method of contract.
func (c *ContractReader) String(s string) (string, error) {
return unwrap.UTF8String(c.invoker.Call(c.hash, "string", s))
}
// Strings invokes `strings` method of contract.
func (c *ContractReader) Strings(s []string) ([]string, error) {
return unwrap.ArrayOfUTF8Strings(c.invoker.Call(c.hash, "strings", s))
}

View file

@ -32,15 +32,17 @@ type Actor interface {
// Contract implements all contract methods. // Contract implements all contract methods.
type Contract struct { type Contract struct {
actor Actor actor Actor
hash util.Uint160
} }
// New creates an instance of Contract using Hash and the given Actor. // New creates an instance of Contract using Hash and the given Actor.
func New(actor Actor) *Contract { func New(actor Actor) *Contract {
return &Contract{actor} var hash = Hash
return &Contract{actor, hash}
} }
func scriptForVerify() ([]byte, error) { func scriptForVerify() ([]byte, error) {
return smartcontract.CreateCallWithAssertScript(Hash, "verify") return smartcontract.CreateCallWithAssertScript(c.hash, "verify")
} }
// Verify creates a transaction invoking `verify` method of the contract. // Verify creates a transaction invoking `verify` method of the contract.

View file

@ -48,8 +48,10 @@ const Hash = "{{ .Hash }}"
type ( type (
// Config contains parameter for the generated binding. // Config contains parameter for the generated binding.
Config struct { Config struct {
Package string `yaml:"package,omitempty"` Package string `yaml:"package,omitempty"`
Manifest *manifest.Manifest `yaml:"-"` Manifest *manifest.Manifest `yaml:"-"`
// Hash denotes the contract hash and is allowed to be empty for RPC bindings
// generation (if not provided by the user).
Hash util.Uint160 `yaml:"hash,omitempty"` Hash util.Uint160 `yaml:"hash,omitempty"`
Overrides map[string]Override `yaml:"overrides,omitempty"` Overrides map[string]Override `yaml:"overrides,omitempty"`
CallFlags map[string]callflag.CallFlag `yaml:"callflags,omitempty"` CallFlags map[string]callflag.CallFlag `yaml:"callflags,omitempty"`
@ -169,9 +171,11 @@ func scTypeToGo(name string, typ smartcontract.ParamType, cfg *Config) (string,
// and type conversion function. It assumes manifest to be present in the // and type conversion function. It assumes manifest to be present in the
// configuration and assumes it to be correct (passing IsValid check). // configuration and assumes it to be correct (passing IsValid check).
func TemplateFromManifest(cfg Config, scTypeConverter func(string, smartcontract.ParamType, *Config) (string, string)) ContractTmpl { func TemplateFromManifest(cfg Config, scTypeConverter func(string, smartcontract.ParamType, *Config) (string, string)) ContractTmpl {
hStr := "" var hStr string
for _, b := range cfg.Hash.BytesBE() { if !cfg.Hash.Equals(util.Uint160{}) {
hStr += fmt.Sprintf("\\x%02x", b) for _, b := range cfg.Hash.BytesBE() {
hStr += fmt.Sprintf("\\x%02x", b)
}
} }
ctr := ContractTmpl{ ctr := ContractTmpl{

View file

@ -11,6 +11,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract/binding" "github.com/nspcc-dev/neo-go/pkg/smartcontract/binding"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest/standard" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest/standard"
"github.com/nspcc-dev/neo-go/pkg/util"
) )
// The set of constants containing parts of RPC binding template. Each block of code // The set of constants containing parts of RPC binding template. Each block of code
@ -39,10 +40,10 @@ func (c *ContractReader) {{.Name}}({{range $index, $arg := .Arguments -}}
} }
return {{addIndent (etTypeConverter .ExtendedReturn "item") "\t"}} return {{addIndent (etTypeConverter .ExtendedReturn "item") "\t"}}
} ( {{- end -}} {{if .ItemTo -}} itemTo{{ .ItemTo }}( {{- end -}} } ( {{- end -}} {{if .ItemTo -}} itemTo{{ .ItemTo }}( {{- end -}}
unwrap.{{.Unwrapper}}(c.invoker.Call(Hash, "{{ .NameABI }}" unwrap.{{.Unwrapper}}(c.invoker.Call(c.hash, "{{ .NameABI }}"
{{- range $arg := .Arguments -}}, {{.Name}}{{end -}} )) {{- if or .ItemTo (eq .Unwrapper "Item") -}} ) {{- end}} {{- range $arg := .Arguments -}}, {{.Name}}{{end -}} )) {{- if or .ItemTo (eq .Unwrapper "Item") -}} ) {{- end}}
{{- else -}} (*result.Invoke, error) { {{- else -}} (*result.Invoke, error) {
c.invoker.Call(Hash, "{{ .NameABI }}" c.invoker.Call(c.hash, "{{ .NameABI }}"
{{- range $arg := .Arguments -}}, {{.Name}}{{end}}) {{- range $arg := .Arguments -}}, {{.Name}}{{end}})
{{- end}} {{- end}}
} }
@ -53,7 +54,7 @@ func (c *ContractReader) {{.Name}}({{range $index, $arg := .Arguments -}}
// number of result items from the iterator right in the VM and return them to // 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. // you. It's only limited by VM stack and GAS available for RPC invocations.
func (c *ContractReader) {{.Name}}Expanded({{range $index, $arg := .Arguments}}{{.Name}} {{.Type}}, {{end}}_numOfIteratorItems int) ([]stackitem.Item, error) { func (c *ContractReader) {{.Name}}Expanded({{range $index, $arg := .Arguments}}{{.Name}} {{.Type}}, {{end}}_numOfIteratorItems int) ([]stackitem.Item, error) {
return unwrap.Array(c.invoker.CallAndExpandIterator(Hash, "{{.NameABI}}", _numOfIteratorItems{{range $arg := .Arguments}}, {{.Name}}{{end}})) return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "{{.NameABI}}", _numOfIteratorItems{{range $arg := .Arguments}}, {{.Name}}{{end}}))
} }
{{ end }}{{ end }}` {{ end }}{{ end }}`
methodDefinition = `{{ define "METHOD" }}{{ if eq .ReturnType "bool"}} methodDefinition = `{{ define "METHOD" }}{{ if eq .ReturnType "bool"}}
@ -61,7 +62,7 @@ func scriptFor{{.Name}}({{range $index, $arg := .Arguments -}}
{{- if ne $index 0}}, {{end}} {{- if ne $index 0}}, {{end}}
{{- .Name}} {{.Type}} {{- .Name}} {{.Type}}
{{- end}}) ([]byte, error) { {{- end}}) ([]byte, error) {
return smartcontract.CreateCallWithAssertScript(Hash, "{{ .NameABI }}"{{- range $index, $arg := .Arguments -}}, {{.Name}}{{end}}) return smartcontract.CreateCallWithAssertScript(c.hash, "{{ .NameABI }}"{{- range $index, $arg := .Arguments -}}, {{.Name}}{{end}})
} }
{{ end }} {{ end }}
// {{.Name}} {{.Comment}} // {{.Name}} {{.Comment}}
@ -71,7 +72,7 @@ func (c *Contract) {{.Name}}({{range $index, $arg := .Arguments -}}
{{- if ne $index 0}}, {{end}} {{- if ne $index 0}}, {{end}}
{{- .Name}} {{.Type}} {{- .Name}} {{.Type}}
{{- end}}) (util.Uint256, uint32, error) { {{- end}}) (util.Uint256, uint32, error) {
{{if ne .ReturnType "bool"}}return c.actor.SendCall(Hash, "{{ .NameABI }}" {{if ne .ReturnType "bool"}}return c.actor.SendCall(c.hash, "{{ .NameABI }}"
{{- range $index, $arg := .Arguments -}}, {{.Name}}{{end}}){{else}}script, err := scriptFor{{.Name}}({{- range $index, $arg := .Arguments -}}{{- if ne $index 0}}, {{end}}{{.Name}}{{end}}) {{- range $index, $arg := .Arguments -}}, {{.Name}}{{end}}){{else}}script, err := scriptFor{{.Name}}({{- range $index, $arg := .Arguments -}}{{- if ne $index 0}}, {{end}}{{.Name}}{{end}})
if err != nil { if err != nil {
return util.Uint256{}, 0, err return util.Uint256{}, 0, err
@ -86,7 +87,7 @@ func (c *Contract) {{.Name}}Transaction({{range $index, $arg := .Arguments -}}
{{- if ne $index 0}}, {{end}} {{- if ne $index 0}}, {{end}}
{{- .Name}} {{.Type}} {{- .Name}} {{.Type}}
{{- end}}) (*transaction.Transaction, error) { {{- end}}) (*transaction.Transaction, error) {
{{if ne .ReturnType "bool"}}return c.actor.MakeCall(Hash, "{{ .NameABI }}" {{if ne .ReturnType "bool"}}return c.actor.MakeCall(c.hash, "{{ .NameABI }}"
{{- range $index, $arg := .Arguments -}}, {{.Name}}{{end}}){{else}}script, err := scriptFor{{.Name}}({{- range $index, $arg := .Arguments -}}{{- if ne $index 0}}, {{end}}{{.Name}}{{end}}) {{- range $index, $arg := .Arguments -}}, {{.Name}}{{end}}){{else}}script, err := scriptFor{{.Name}}({{- range $index, $arg := .Arguments -}}{{- if ne $index 0}}, {{end}}{{.Name}}{{end}})
if err != nil { if err != nil {
return nil, err return nil, err
@ -102,7 +103,7 @@ func (c *Contract) {{.Name}}Unsigned({{range $index, $arg := .Arguments -}}
{{- if ne $index 0}}, {{end}} {{- if ne $index 0}}, {{end}}
{{- .Name}} {{.Type}} {{- .Name}} {{.Type}}
{{- end}}) (*transaction.Transaction, error) { {{- end}}) (*transaction.Transaction, error) {
{{if ne .ReturnType "bool"}}return c.actor.MakeUnsignedCall(Hash, "{{ .NameABI }}", nil {{if ne .ReturnType "bool"}}return c.actor.MakeUnsignedCall(c.hash, "{{ .NameABI }}", nil
{{- range $index, $arg := .Arguments -}}, {{.Name}}{{end}}){{else}}script, err := scriptFor{{.Name}}({{- range $index, $arg := .Arguments -}}{{- if ne $index 0}}, {{end}}{{.Name}}{{end}}) {{- range $index, $arg := .Arguments -}}, {{.Name}}{{end}}){{else}}script, err := scriptFor{{.Name}}({{- range $index, $arg := .Arguments -}}{{- if ne $index 0}}, {{end}}{{.Name}}{{end}})
if err != nil { if err != nil {
return nil, err return nil, err
@ -117,10 +118,11 @@ package {{.PackageName}}
import ( import (
{{range $m := .Imports}} "{{ $m }}" {{range $m := .Imports}} "{{ $m }}"
{{end}}) {{end}})
{{if len .Hash}}
// Hash contains contract hash. // Hash contains contract hash.
var Hash = {{ .Hash }} var Hash = {{ .Hash }}
{{ range $name, $typ := .NamedTypes }} {{end -}}
{{- range $name, $typ := .NamedTypes }}
// {{toTypeName $name}} is a contract-specific {{$name}} type used by its methods. // {{toTypeName $name}} is a contract-specific {{$name}} type used by its methods.
type {{toTypeName $name}} struct { type {{toTypeName $name}} struct {
{{- range $m := $typ.Fields}} {{- range $m := $typ.Fields}}
@ -175,6 +177,7 @@ type ContractReader struct {
{{if .IsNep17}}nep17.TokenReader {{if .IsNep17}}nep17.TokenReader
{{end -}} {{end -}}
invoker Invoker invoker Invoker
hash util.Uint160
} }
{{end -}} {{end -}}
{{- if .HasWriter}} {{- if .HasWriter}}
@ -189,37 +192,44 @@ type Contract struct {
{{if .IsNep17}}nep17.TokenWriter {{if .IsNep17}}nep17.TokenWriter
{{end -}} {{end -}}
actor Actor actor Actor
hash util.Uint160
} }
{{end -}} {{end -}}
{{- if .HasReader}} {{- if .HasReader}}
// NewReader creates an instance of ContractReader using Hash and the given Invoker. // NewReader creates an instance of ContractReader using {{if len .Hash -}}Hash{{- else -}}provided contract hash{{- end}} and the given Invoker.
func NewReader(invoker Invoker) *ContractReader { func NewReader(invoker Invoker{{- if not (len .Hash) -}}, hash util.Uint160{{- end -}}) *ContractReader {
{{if len .Hash -}}
var hash = Hash
{{end -}}
return &ContractReader{ return &ContractReader{
{{- if .IsNep11D}}*nep11.NewDivisibleReader(invoker, Hash), {{end}} {{- if .IsNep11D}}*nep11.NewDivisibleReader(invoker, hash), {{end}}
{{- if .IsNep11ND}}*nep11.NewNonDivisibleReader(invoker, Hash), {{end}} {{- if .IsNep11ND}}*nep11.NewNonDivisibleReader(invoker, hash), {{end}}
{{- if .IsNep17}}*nep17.NewReader(invoker, Hash), {{end -}} {{- if .IsNep17}}*nep17.NewReader(invoker, hash), {{end -}}
invoker} invoker, hash}
} }
{{end -}} {{end -}}
{{- if .HasWriter}} {{- if .HasWriter}}
// New creates an instance of Contract using Hash and the given Actor. // New creates an instance of Contract using {{if len .Hash -}}Hash{{- else -}}provided contract hash{{- end}} and the given Actor.
func New(actor Actor) *Contract { func New(actor Actor{{- if not (len .Hash) -}}, hash util.Uint160{{- end -}}) *Contract {
{{if .IsNep11D}}var nep11dt = nep11.NewDivisible(actor, Hash) {{if len .Hash -}}
var hash = Hash
{{end -}} {{end -}}
{{if .IsNep11ND}}var nep11ndt = nep11.NewNonDivisible(actor, Hash) {{if .IsNep11D}}var nep11dt = nep11.NewDivisible(actor, hash)
{{end -}} {{end -}}
{{if .IsNep17}}var nep17t = nep17.New(actor, Hash) {{if .IsNep11ND}}var nep11ndt = nep11.NewNonDivisible(actor, hash)
{{end -}}
{{if .IsNep17}}var nep17t = nep17.New(actor, hash)
{{end -}} {{end -}}
return &Contract{ return &Contract{
{{- if .HasReader}}ContractReader{ {{- if .HasReader}}ContractReader{
{{- if .IsNep11D}}nep11dt.DivisibleReader, {{end -}} {{- if .IsNep11D}}nep11dt.DivisibleReader, {{end -}}
{{- if .IsNep11ND}}nep11ndt.NonDivisibleReader, {{end -}} {{- if .IsNep11ND}}nep11ndt.NonDivisibleReader, {{end -}}
{{- if .IsNep17}}nep17t.TokenReader, {{end -}} {{- if .IsNep17}}nep17t.TokenReader, {{end -}}
actor}, {{end -}} actor, hash}, {{end -}}
{{- if .IsNep11D}}nep11dt.DivisibleWriter, {{end -}} {{- if .IsNep11D}}nep11dt.DivisibleWriter, {{end -}}
{{- if .IsNep11ND}}nep11ndt.BaseWriter, {{end -}} {{- if .IsNep11ND}}nep11ndt.BaseWriter, {{end -}}
{{- if .IsNep17}}nep17t.TokenWriter, {{end -}} {{- if .IsNep17}}nep17t.TokenWriter, {{end -}}
actor} actor, hash}
} }
{{end -}} {{end -}}
{{- range $m := .SafeMethods }}{{template "SAFEMETHOD" $m }}{{ end -}} {{- range $m := .SafeMethods }}{{template "SAFEMETHOD" $m }}{{ end -}}
@ -660,7 +670,9 @@ func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]st
for i := range ctr.Imports { for i := range ctr.Imports {
imports[ctr.Imports[i]] = struct{}{} imports[ctr.Imports[i]] = struct{}{}
} }
ctr.Hash = fmt.Sprintf("%#v", cfg.Hash) if !cfg.Hash.Equals(util.Uint160{}) {
ctr.Hash = fmt.Sprintf("%#v", cfg.Hash)
}
for i := 0; i < len(ctr.Methods); i++ { for i := 0; i < len(ctr.Methods); i++ {
abim := cfg.Manifest.ABI.GetMethod(ctr.Methods[i].NameABI, len(ctr.Methods[i].Arguments)) abim := cfg.Manifest.ABI.GetMethod(ctr.Methods[i].NameABI, len(ctr.Methods[i].Arguments))
if abim.Safe { if abim.Safe {