diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c6092c1..78225a6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,152 +1,152 @@ -name: Build - -on: - pull_request: - branches: - - master - types: [opened, synchronize] - paths-ignore: - - 'scripts/**' - - '**/*.md' - push: - # Build for the master branch. - branches: - - master - release: - # Publish released commit as Docker `latest` and `git_revision` images. - types: - - published - workflow_dispatch: - inputs: - ref: - description: 'Ref to build CLI for Ubuntu and Windows Server Core [default: latest master; examples: v0.92.0, 0a4ff9d3e4a9ab432fd5812eb18c98e03b5a7432]' - required: false - default: '' - push_image: - description: 'Push images to DockerHub [default: false; examples: true, false]' - required: false - default: 'false' - use_latest_tag: - description: 'Use `latest` tag while pushing images to DockerHub (applied to Ubuntu image only) [default: false; examples: true, false]' - required: false - default: 'false' - -jobs: - build_cli: - name: Build CLI - runs-on: ${{matrix.os.name}} - strategy: - matrix: - os: [{ name: ubuntu-latest, bin-name: linux }, { name: windows-latest, bin-name: windows }, { name: macos-latest, bin-name: darwin }] - arch: [amd64, arm64] - exclude: - - os: { name: windows-latest, bin-name: windows } - arch: 'arm64' - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.inputs.ref }} - # Allows to fetch all history for all branches and tags. Need this for proper versioning. - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.25' - - - name: Build CLI - run: make build - env: - GOARCH: ${{ matrix.arch }} - - - name: Rename CLI binary - run: mv ./bin/neo-go* ./bin/neo-go-${{ matrix.os.bin-name }}-${{ matrix.arch }}${{ (matrix.os.bin-name == 'windows' && '.exe') || '' }} - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: neo-go-${{ matrix.os.bin-name }}-${{ matrix.arch }} - path: ./bin/neo-go* - if-no-files-found: error - - - name: Attach binary to the release as an asset - if: ${{ github.event_name == 'release' }} - run: gh release upload ${{ github.event.release.tag_name }} ./bin/neo-go-${{ matrix.os.bin-name }}-${{ matrix.arch }}${{ (matrix.os.bin-name == 'windows' && '.exe') || '' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - build_image: - needs: build_cli - name: Build and push docker image - runs-on: ubuntu-latest - if: ${{ github.event_name != 'pull_request' }} - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.inputs.ref }} - fetch-depth: 0 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to DockerHub - if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: Set vars - id: setvars - run: make gh-docker-vars >> $GITHUB_OUTPUT - - - name: Set latest tag - id: setlatest - if: ${{ (github.event_name == 'release' && github.event.release.target_commitish == 'master') || (github.event_name == 'workflow_dispatch' && github.event.inputs.use_latest_tag == 'true') }} - run: echo "latest=,${{ steps.setvars.outputs.repo }}:latest" >> $GITHUB_OUTPUT - - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: . - push: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} - platforms: linux/amd64,linux/arm64 - build-args: | - REPO=github.com/${{ github.repository }} - VERSION=${{ steps.setvars.outputs.version }} - tags: ${{ steps.setvars.outputs.repo }}:${{ steps.setvars.outputs.version }}${{ steps.setvars.outputs.suffix }}${{ steps.setlatest.outputs.latest }} - - build_image_wsc: - needs: build_cli - name: Build and push docker image (Windows Server Core) - runs-on: windows-latest - if: ${{ github.event_name != 'pull_request' }} - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.inputs.ref }} - fetch-depth: 0 - - # For proper `deps` make target execution. - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.25' - - - name: Login to DockerHub - if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: Build Docker image - run: make image - - - name: Push image to registry - if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} - run: make image-push +name: Build + +on: + pull_request: + branches: + - master + types: [opened, synchronize] + paths-ignore: + - 'scripts/**' + - '**/*.md' + push: + # Build for the master branch. + branches: + - master + release: + # Publish released commit as Docker `latest` and `git_revision` images. + types: + - published + workflow_dispatch: + inputs: + ref: + description: 'Ref to build CLI for Ubuntu and Windows Server Core [default: latest master; examples: v0.92.0, 0a4ff9d3e4a9ab432fd5812eb18c98e03b5a7432]' + required: false + default: '' + push_image: + description: 'Push images to DockerHub [default: false; examples: true, false]' + required: false + default: 'false' + use_latest_tag: + description: 'Use `latest` tag while pushing images to DockerHub (applied to Ubuntu image only) [default: false; examples: true, false]' + required: false + default: 'false' + +jobs: + build_cli: + name: Build CLI + runs-on: ${{matrix.os.name}} + strategy: + matrix: + os: [{ name: ubuntu-latest, bin-name: linux }, { name: windows-latest, bin-name: windows }, { name: macos-latest, bin-name: darwin }] + arch: [amd64, arm64] + exclude: + - os: { name: windows-latest, bin-name: windows } + arch: 'arm64' + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.ref }} + # Allows to fetch all history for all branches and tags. Need this for proper versioning. + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.25' + + - name: Build CLI + run: make build + env: + GOARCH: ${{ matrix.arch }} + + - name: Rename CLI binary + run: mv ./bin/neo-go* ./bin/neo-go-${{ matrix.os.bin-name }}-${{ matrix.arch }}${{ (matrix.os.bin-name == 'windows' && '.exe') || '' }} + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: neo-go-${{ matrix.os.bin-name }}-${{ matrix.arch }} + path: ./bin/neo-go* + if-no-files-found: error + + - name: Attach binary to the release as an asset + if: ${{ github.event_name == 'release' }} + run: gh release upload ${{ github.event.release.tag_name }} ./bin/neo-go-${{ matrix.os.bin-name }}-${{ matrix.arch }}${{ (matrix.os.bin-name == 'windows' && '.exe') || '' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + build_image: + needs: build_cli + name: Build and push docker image + runs-on: ubuntu-latest + if: ${{ github.event_name != 'pull_request' }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.ref }} + fetch-depth: 0 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Set vars + id: setvars + run: make gh-docker-vars >> $GITHUB_OUTPUT + + - name: Set latest tag + id: setlatest + if: ${{ (github.event_name == 'release' && github.event.release.target_commitish == 'master') || (github.event_name == 'workflow_dispatch' && github.event.inputs.use_latest_tag == 'true') }} + run: echo "latest=,${{ steps.setvars.outputs.repo }}:latest" >> $GITHUB_OUTPUT + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} + platforms: linux/amd64,linux/arm64 + build-args: | + REPO=github.com/${{ github.repository }} + VERSION=${{ steps.setvars.outputs.version }} + tags: ${{ steps.setvars.outputs.repo }}:${{ steps.setvars.outputs.version }}${{ steps.setvars.outputs.suffix }}${{ steps.setlatest.outputs.latest }} + + build_image_wsc: + needs: build_cli + name: Build and push docker image (Windows Server Core) + runs-on: windows-latest + if: ${{ github.event_name != 'pull_request' }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.ref }} + fetch-depth: 0 + + # For proper `deps` make target execution. + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.25' + + - name: Login to DockerHub + if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Build Docker image + run: make image + + - name: Push image to registry + if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} + run: make image-push diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 07e63e5..6c135e9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,197 +1,197 @@ -name: Tests - -on: - push: - branches: [ master ] - pull_request: - branches: - - master - types: [opened, synchronize] - paths-ignore: - - 'scripts/*.sh' - - '**/*.md' - workflow_dispatch: - -jobs: - lint: - name: 'Lint: NeoGo' - uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master - - lint_examples: - name: 'Lint: examples (${{ matrix.contract }})' - uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master - - strategy: - fail-fast: false - matrix: - contract: [ 'engine', 'events', 'iterator', 'nft-d', 'nft-nd', 'nft-nd-nns', 'oracle', - 'runtime', 'storage', 'timer', 'token', 'zkp/cubic_circuit', 'zkp/xor_compat'] - with: - workdir: examples/${{ matrix.contract }} - - lint_scripts: - name: 'Lint: scripts' - uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master - with: - workdir: scripts - - lint_interops: - name: 'Lint: interop' - uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master - with: - workdir: pkg/interop - - gomodcheck: - name: Check internal dependencies - runs-on: ubuntu-slim - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Check dependencies - run: | - ./scripts/check_deps.sh - - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - - name: Check go.mod is tidy - run: | - go mod tidy - if [[ $(git diff --name-only go.* | grep '' -c) != 0 ]]; then - echo "go mod tidy should be executed before the merge, following packages are unused or out of date:"; - git diff go.*; - exit 1; - fi - - codegencheck: - name: Check code generated with 'go generate' is up-to-date - runs-on: ubuntu-slim - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - - - name: Install stringer - run: go install golang.org/x/tools/cmd/stringer@latest - - - name: Run go generate - run: go generate ./... - - - name: Check that autogenerated code is up-to-date - run: | - if [[ $(git diff --name-only | grep '' -c) != 0 ]]; then - echo "Fresh version of autogenerated code should be committed for the following files:"; - git diff --name-only; - exit 1; - fi - - codeql: - name: CodeQL - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - language: [ 'go' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v3 - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 - - test_cover: - name: Coverage - runs-on: ubuntu-latest - - env: - CGO_ENABLED: 0 - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - submodules: 'true' - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.25' - cache: true - - - name: Write coverage profile - run: DISABLE_NEOTEST_COVER=1 go test -timeout 15m -v ./... -coverprofile=./coverage.txt -covermode=atomic -coverpkg=./pkg...,./cli/... - - - name: Upload coverage results to Codecov - uses: codecov/codecov-action@v4 - with: - fail_ci_if_error: true # if something is wrong on uploading codecov results, then this job will fail - files: ./coverage.txt - slug: nspcc-dev/neo-go - token: ${{ secrets.CODECOV_TOKEN }} - verbose: true - - tests: - name: Run tests - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - go_versions: [ '1.24', '1.25' ] - exclude: - # Only latest Go version for Windows and MacOS. - - os: windows-latest - go_versions: '1.24' - - os: macos-latest - go_versions: '1.24' - # Exclude latest Go version for Ubuntu as Coverage uses it. - - os: ubuntu-latest - go_versions: '1.25' - fail-fast: false - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - submodules: 'true' - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '${{ matrix.go_versions }}' - - - name: Run tests - run: go test -timeout 15m -v -race ./... +name: Tests + +on: + push: + branches: [ master ] + pull_request: + branches: + - master + types: [opened, synchronize] + paths-ignore: + - 'scripts/*.sh' + - '**/*.md' + workflow_dispatch: + +jobs: + lint: + name: 'Lint: NeoGo' + uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master + + lint_examples: + name: 'Lint: examples (${{ matrix.contract }})' + uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master + + strategy: + fail-fast: false + matrix: + contract: [ 'engine', 'events', 'iterator', 'nft-d', 'nft-nd', 'nft-nd-nns', 'oracle', + 'runtime', 'storage', 'timer', 'token', 'zkp/cubic_circuit', 'zkp/xor_compat'] + with: + workdir: examples/${{ matrix.contract }} + + lint_scripts: + name: 'Lint: scripts' + uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master + with: + workdir: scripts + + lint_interops: + name: 'Lint: interop' + uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master + with: + workdir: pkg/interop + + gomodcheck: + name: Check internal dependencies + runs-on: ubuntu-slim + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Check dependencies + run: | + ./scripts/check_deps.sh + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + - name: Check go.mod is tidy + run: | + go mod tidy + if [[ $(git diff --name-only go.* | grep '' -c) != 0 ]]; then + echo "go mod tidy should be executed before the merge, following packages are unused or out of date:"; + git diff go.*; + exit 1; + fi + + codegencheck: + name: Check code generated with 'go generate' is up-to-date + runs-on: ubuntu-slim + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: Install stringer + run: go install golang.org/x/tools/cmd/stringer@latest + + - name: Run go generate + run: go generate ./... + + - name: Check that autogenerated code is up-to-date + run: | + if [[ $(git diff --name-only | grep '' -c) != 0 ]]; then + echo "Fresh version of autogenerated code should be committed for the following files:"; + git diff --name-only; + exit 1; + fi + + codeql: + name: CodeQL + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + + test_cover: + name: Coverage + runs-on: ubuntu-latest + + env: + CGO_ENABLED: 0 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: 'true' + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.25' + cache: true + + - name: Write coverage profile + run: DISABLE_NEOTEST_COVER=1 go test -timeout 15m -v ./... -coverprofile=./coverage.txt -covermode=atomic -coverpkg=./pkg...,./cli/... + + - name: Upload coverage results to Codecov + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true # if something is wrong on uploading codecov results, then this job will fail + files: ./coverage.txt + slug: nspcc-dev/neo-go + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + + tests: + name: Run tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + go_versions: [ '1.24', '1.25' ] + exclude: + # Only latest Go version for Windows and MacOS. + - os: windows-latest + go_versions: '1.24' + - os: macos-latest + go_versions: '1.24' + # Exclude latest Go version for Ubuntu as Coverage uses it. + - os: ubuntu-latest + go_versions: '1.25' + fail-fast: false + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: 'true' + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '${{ matrix.go_versions }}' + + - name: Run tests + run: go test -timeout 15m -v -race ./... diff --git a/cli/smartcontract/rpcbindings/notifications/rpcbindings/extended/rpcbindings_test.go b/cli/smartcontract/rpcbindings/notifications/rpcbindings/extended/rpcbindings_test.go old mode 100755 new mode 100644 index 8c473c9..b796512 --- a/cli/smartcontract/rpcbindings/notifications/rpcbindings/extended/rpcbindings_test.go +++ b/cli/smartcontract/rpcbindings/notifications/rpcbindings/extended/rpcbindings_test.go @@ -1,746 +1,746 @@ -// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. - -// Package structs contains RPC wrappers for Notifications contract. -package structs - -import ( - "errors" - "fmt" - "github.com/tutus-one/tutus-chain/pkg/core/transaction" - "github.com/tutus-one/tutus-chain/pkg/neorpc/result" - "github.com/tutus-one/tutus-chain/pkg/smartcontract" - "github.com/tutus-one/tutus-chain/pkg/util" - "github.com/tutus-one/tutus-chain/pkg/vm/stackitem" - "math/big" - "unicode/utf8" -) - -// Hash contains contract hash. -var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x0} - -// CrazyStruct is a contract-specific crazyStruct type used by its methods. -type CrazyStruct struct { - I *big.Int - B bool -} - -// SimpleStruct is a contract-specific simpleStruct type used by its methods. -type SimpleStruct struct { - I *big.Int -} - -// ComplicatedNameEvent represents "! complicated name %$#" event emitted by the contract. -type ComplicatedNameEvent struct { - ComplicatedParam string -} - -// SomeMapEvent represents "SomeMap" event emitted by the contract. -type SomeMapEvent struct { - M map[*big.Int]map[string][]util.Uint160 -} - -// SomeStructEvent represents "SomeStruct" event emitted by the contract. -type SomeStructEvent struct { - S *CrazyStruct -} - -// SomeArrayEvent represents "SomeArray" event emitted by the contract. -type SomeArrayEvent struct { - A [][]*big.Int -} - -// SomeUnexportedFieldEvent represents "SomeUnexportedField" event emitted by the contract. -type SomeUnexportedFieldEvent struct { - S *SimpleStruct -} - -// Actor is used by Contract to call state-changing methods. -type Actor interface { - MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) - MakeRun(script []byte) (*transaction.Transaction, error) - MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) - MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) - SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) - SendRun(script []byte) (util.Uint256, uint32, error) -} - -// Contract implements all contract methods. -type Contract struct { - actor Actor - hash util.Uint160 -} - -// New creates an instance of Contract using Hash and the given Actor. -func New(actor Actor) *Contract { - var hash = Hash - return &Contract{actor, hash} -} - -// Array creates a transaction invoking `array` method of the contract. -// This transaction is signed and immediately sent to the network. -// The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) Array() (util.Uint256, uint32, error) { - return c.actor.SendCall(c.hash, "array") -} - -// ArrayTransaction creates a transaction invoking `array` method of the contract. -// This transaction is signed, but not sent to the network, instead it's -// returned to the caller. -func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) { - return c.actor.MakeCall(c.hash, "array") -} - -// ArrayUnsigned creates a transaction invoking `array` method of the contract. -// This transaction is not signed, it's simply returned to the caller. -// Any fields of it that do not affect fees can be changed (ValidUntilBlock, -// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) { - return c.actor.MakeUnsignedCall(c.hash, "array", nil) -} - -// CrazyMap creates a transaction invoking `crazyMap` method of the contract. -// This transaction is signed and immediately sent to the network. -// The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) CrazyMap() (util.Uint256, uint32, error) { - return c.actor.SendCall(c.hash, "crazyMap") -} - -// CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract. -// This transaction is signed, but not sent to the network, instead it's -// returned to the caller. -func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) { - return c.actor.MakeCall(c.hash, "crazyMap") -} - -// CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract. -// This transaction is not signed, it's simply returned to the caller. -// Any fields of it that do not affect fees can be changed (ValidUntilBlock, -// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) { - return c.actor.MakeUnsignedCall(c.hash, "crazyMap", nil) -} - -// Main creates a transaction invoking `main` method of the contract. -// This transaction is signed and immediately sent to the network. -// The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) Main() (util.Uint256, uint32, error) { - return c.actor.SendCall(c.hash, "main") -} - -// MainTransaction creates a transaction invoking `main` method of the contract. -// This transaction is signed, but not sent to the network, instead it's -// returned to the caller. -func (c *Contract) MainTransaction() (*transaction.Transaction, error) { - return c.actor.MakeCall(c.hash, "main") -} - -// MainUnsigned creates a transaction invoking `main` method of the contract. -// This transaction is not signed, it's simply returned to the caller. -// Any fields of it that do not affect fees can be changed (ValidUntilBlock, -// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) MainUnsigned() (*transaction.Transaction, error) { - return c.actor.MakeUnsignedCall(c.hash, "main", nil) -} - -// Struct creates a transaction invoking `struct` method of the contract. -// This transaction is signed and immediately sent to the network. -// The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) Struct() (util.Uint256, uint32, error) { - return c.actor.SendCall(c.hash, "struct") -} - -// StructTransaction creates a transaction invoking `struct` method of the contract. -// This transaction is signed, but not sent to the network, instead it's -// returned to the caller. -func (c *Contract) StructTransaction() (*transaction.Transaction, error) { - return c.actor.MakeCall(c.hash, "struct") -} - -// StructUnsigned creates a transaction invoking `struct` method of the contract. -// This transaction is not signed, it's simply returned to the caller. -// Any fields of it that do not affect fees can be changed (ValidUntilBlock, -// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) StructUnsigned() (*transaction.Transaction, error) { - return c.actor.MakeUnsignedCall(c.hash, "struct", nil) -} - -// UnexportedField creates a transaction invoking `unexportedField` method of the contract. -// This transaction is signed and immediately sent to the network. -// The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) UnexportedField() (util.Uint256, uint32, error) { - return c.actor.SendCall(c.hash, "unexportedField") -} - -// UnexportedFieldTransaction creates a transaction invoking `unexportedField` method of the contract. -// This transaction is signed, but not sent to the network, instead it's -// returned to the caller. -func (c *Contract) UnexportedFieldTransaction() (*transaction.Transaction, error) { - return c.actor.MakeCall(c.hash, "unexportedField") -} - -// UnexportedFieldUnsigned creates a transaction invoking `unexportedField` method of the contract. -// This transaction is not signed, it's simply returned to the caller. -// Any fields of it that do not affect fees can be changed (ValidUntilBlock, -// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) UnexportedFieldUnsigned() (*transaction.Transaction, error) { - return c.actor.MakeUnsignedCall(c.hash, "unexportedField", nil) -} - -// itemToCrazyStruct converts stack item into *CrazyStruct. -// NULL item is returned as nil pointer without error. -func itemToCrazyStruct(item stackitem.Item, err error) (*CrazyStruct, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(CrazyStruct) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *CrazyStruct is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&CrazyStruct{}) - -// Ensure *CrazyStruct is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&CrazyStruct{}) - -// FromStackItem retrieves fields of CrazyStruct from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *CrazyStruct) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 2 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.I, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field I: %w", err) - } - - index++ - res.B, err = arr[index].TryBool() - if err != nil { - return fmt.Errorf("field B: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing CrazyStruct. -// It implements [stackitem.Convertible] interface. -func (res *CrazyStruct) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 2) - ) - itm, err = (*stackitem.BigInteger)(res.I), error(nil) - if err != nil { - return nil, fmt.Errorf("field I: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewBool(res.B), error(nil) - if err != nil { - return nil, fmt.Errorf("field B: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing CrazyStruct. -// It implements [smartcontract.Convertible] interface so that CrazyStruct -// could be used with invokers. -func (res *CrazyStruct) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 2) - ) - prm, err = smartcontract.NewParameterFromValue(res.I) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field I: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.B) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field B: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToSimpleStruct converts stack item into *SimpleStruct. -// NULL item is returned as nil pointer without error. -func itemToSimpleStruct(item stackitem.Item, err error) (*SimpleStruct, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(SimpleStruct) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *SimpleStruct is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&SimpleStruct{}) - -// Ensure *SimpleStruct is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&SimpleStruct{}) - -// FromStackItem retrieves fields of SimpleStruct from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *SimpleStruct) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.I, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field I: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing SimpleStruct. -// It implements [stackitem.Convertible] interface. -func (res *SimpleStruct) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 1) - ) - itm, err = (*stackitem.BigInteger)(res.I), error(nil) - if err != nil { - return nil, fmt.Errorf("field I: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing SimpleStruct. -// It implements [smartcontract.Convertible] interface so that SimpleStruct -// could be used with invokers. -func (res *SimpleStruct) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 1) - ) - prm, err = smartcontract.NewParameterFromValue(res.I) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field I: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// ComplicatedNameEventsFromApplicationLog retrieves a set of all emitted events -// with "! complicated name %$#" name from the provided [result.ApplicationLog]. -func ComplicatedNameEventsFromApplicationLog(log *result.ApplicationLog) ([]*ComplicatedNameEvent, error) { - if log == nil { - return nil, errors.New("nil application log") - } - - var res []*ComplicatedNameEvent - for i, ex := range log.Executions { - for j, e := range ex.Events { - if e.Name != "! complicated name %$#" { - continue - } - event := new(ComplicatedNameEvent) - err := event.FromStackItem(e.Item) - if err != nil { - return nil, fmt.Errorf("failed to deserialize ComplicatedNameEvent from stackitem (execution #%d, event #%d): %w", i, j, err) - } - res = append(res, event) - } - } - - return res, nil -} - -// FromStackItem converts provided [stackitem.Array] to ComplicatedNameEvent or -// returns an error if it's not possible to do to so. -func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error { - if item == nil { - return errors.New("nil item") - } - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - e.ComplicatedParam, 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[index]) - if err != nil { - return fmt.Errorf("field ComplicatedParam: %w", err) - } - - return nil -} - -// SomeMapEventsFromApplicationLog retrieves a set of all emitted events -// with "SomeMap" name from the provided [result.ApplicationLog]. -func SomeMapEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeMapEvent, error) { - if log == nil { - return nil, errors.New("nil application log") - } - - var res []*SomeMapEvent - for i, ex := range log.Executions { - for j, e := range ex.Events { - if e.Name != "SomeMap" { - continue - } - event := new(SomeMapEvent) - err := event.FromStackItem(e.Item) - if err != nil { - return nil, fmt.Errorf("failed to deserialize SomeMapEvent from stackitem (execution #%d, event #%d): %w", i, j, err) - } - res = append(res, event) - } - } - - return res, nil -} - -// FromStackItem converts provided [stackitem.Array] to SomeMapEvent or -// returns an error if it's not possible to do to so. -func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error { - if item == nil { - return errors.New("nil item") - } - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - e.M, err = 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) { - 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 - }(m[i].Value) - if err != nil { - return nil, fmt.Errorf("value %d: %w", i, err) - } - res[k] = v - } - return res, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field M: %w", err) - } - - return nil -} - -// SomeStructEventsFromApplicationLog retrieves a set of all emitted events -// with "SomeStruct" name from the provided [result.ApplicationLog]. -func SomeStructEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeStructEvent, error) { - if log == nil { - return nil, errors.New("nil application log") - } - - var res []*SomeStructEvent - for i, ex := range log.Executions { - for j, e := range ex.Events { - if e.Name != "SomeStruct" { - continue - } - event := new(SomeStructEvent) - err := event.FromStackItem(e.Item) - if err != nil { - return nil, fmt.Errorf("failed to deserialize SomeStructEvent from stackitem (execution #%d, event #%d): %w", i, j, err) - } - res = append(res, event) - } - } - - return res, nil -} - -// FromStackItem converts provided [stackitem.Array] to SomeStructEvent or -// returns an error if it's not possible to do to so. -func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error { - if item == nil { - return errors.New("nil item") - } - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - e.S, err = itemToCrazyStruct(arr[index], nil) - if err != nil { - return fmt.Errorf("field S: %w", err) - } - - return nil -} - -// SomeArrayEventsFromApplicationLog retrieves a set of all emitted events -// with "SomeArray" name from the provided [result.ApplicationLog]. -func SomeArrayEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeArrayEvent, error) { - if log == nil { - return nil, errors.New("nil application log") - } - - var res []*SomeArrayEvent - for i, ex := range log.Executions { - for j, e := range ex.Events { - if e.Name != "SomeArray" { - continue - } - event := new(SomeArrayEvent) - err := event.FromStackItem(e.Item) - if err != nil { - return nil, fmt.Errorf("failed to deserialize SomeArrayEvent from stackitem (execution #%d, event #%d): %w", i, j, err) - } - res = append(res, event) - } - } - - return res, nil -} - -// FromStackItem converts provided [stackitem.Array] to SomeArrayEvent or -// returns an error if it's not possible to do to so. -func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error { - if item == nil { - return errors.New("nil item") - } - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - e.A, err = func(item stackitem.Item) ([][]*big.Int, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make([][]*big.Int, len(arr)) - for i := range res { - res[i], err = func(item stackitem.Item) ([]*big.Int, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make([]*big.Int, len(arr)) - for i := range res { - res[i], err = arr[i].TryInteger() - 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[index]) - if err != nil { - return fmt.Errorf("field A: %w", err) - } - - return nil -} - -// SomeUnexportedFieldEventsFromApplicationLog retrieves a set of all emitted events -// with "SomeUnexportedField" name from the provided [result.ApplicationLog]. -func SomeUnexportedFieldEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeUnexportedFieldEvent, error) { - if log == nil { - return nil, errors.New("nil application log") - } - - var res []*SomeUnexportedFieldEvent - for i, ex := range log.Executions { - for j, e := range ex.Events { - if e.Name != "SomeUnexportedField" { - continue - } - event := new(SomeUnexportedFieldEvent) - err := event.FromStackItem(e.Item) - if err != nil { - return nil, fmt.Errorf("failed to deserialize SomeUnexportedFieldEvent from stackitem (execution #%d, event #%d): %w", i, j, err) - } - res = append(res, event) - } - } - - return res, nil -} - -// FromStackItem converts provided [stackitem.Array] to SomeUnexportedFieldEvent or -// returns an error if it's not possible to do to so. -func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error { - if item == nil { - return errors.New("nil item") - } - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - e.S, err = itemToSimpleStruct(arr[index], nil) - if err != nil { - return fmt.Errorf("field S: %w", err) - } - - return nil -} +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. + +// Package structs contains RPC wrappers for Notifications contract. +package structs + +import ( + "errors" + "fmt" + "github.com/tutus-one/tutus-chain/pkg/core/transaction" + "github.com/tutus-one/tutus-chain/pkg/neorpc/result" + "github.com/tutus-one/tutus-chain/pkg/smartcontract" + "github.com/tutus-one/tutus-chain/pkg/util" + "github.com/tutus-one/tutus-chain/pkg/vm/stackitem" + "math/big" + "unicode/utf8" +) + +// Hash contains contract hash. +var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x0} + +// CrazyStruct is a contract-specific crazyStruct type used by its methods. +type CrazyStruct struct { + I *big.Int + B bool +} + +// SimpleStruct is a contract-specific simpleStruct type used by its methods. +type SimpleStruct struct { + I *big.Int +} + +// ComplicatedNameEvent represents "! complicated name %$#" event emitted by the contract. +type ComplicatedNameEvent struct { + ComplicatedParam string +} + +// SomeMapEvent represents "SomeMap" event emitted by the contract. +type SomeMapEvent struct { + M map[*big.Int]map[string][]util.Uint160 +} + +// SomeStructEvent represents "SomeStruct" event emitted by the contract. +type SomeStructEvent struct { + S *CrazyStruct +} + +// SomeArrayEvent represents "SomeArray" event emitted by the contract. +type SomeArrayEvent struct { + A [][]*big.Int +} + +// SomeUnexportedFieldEvent represents "SomeUnexportedField" event emitted by the contract. +type SomeUnexportedFieldEvent struct { + S *SimpleStruct +} + +// Actor is used by Contract to call state-changing methods. +type Actor interface { + MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) + MakeRun(script []byte) (*transaction.Transaction, error) + MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) + MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) + SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) + SendRun(script []byte) (util.Uint256, uint32, error) +} + +// Contract implements all contract methods. +type Contract struct { + actor Actor + hash util.Uint160 +} + +// New creates an instance of Contract using Hash and the given Actor. +func New(actor Actor) *Contract { + var hash = Hash + return &Contract{actor, hash} +} + +// Array creates a transaction invoking `array` method of the contract. +// This transaction is signed and immediately sent to the network. +// The values returned are its hash, ValidUntilBlock value and error if any. +func (c *Contract) Array() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "array") +} + +// ArrayTransaction creates a transaction invoking `array` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "array") +} + +// ArrayUnsigned creates a transaction invoking `array` method of the contract. +// This transaction is not signed, it's simply returned to the caller. +// Any fields of it that do not affect fees can be changed (ValidUntilBlock, +// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. +func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "array", nil) +} + +// CrazyMap creates a transaction invoking `crazyMap` method of the contract. +// This transaction is signed and immediately sent to the network. +// The values returned are its hash, ValidUntilBlock value and error if any. +func (c *Contract) CrazyMap() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "crazyMap") +} + +// CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "crazyMap") +} + +// CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract. +// This transaction is not signed, it's simply returned to the caller. +// Any fields of it that do not affect fees can be changed (ValidUntilBlock, +// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. +func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "crazyMap", nil) +} + +// Main creates a transaction invoking `main` method of the contract. +// This transaction is signed and immediately sent to the network. +// The values returned are its hash, ValidUntilBlock value and error if any. +func (c *Contract) Main() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "main") +} + +// MainTransaction creates a transaction invoking `main` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) MainTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "main") +} + +// MainUnsigned creates a transaction invoking `main` method of the contract. +// This transaction is not signed, it's simply returned to the caller. +// Any fields of it that do not affect fees can be changed (ValidUntilBlock, +// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. +func (c *Contract) MainUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "main", nil) +} + +// Struct creates a transaction invoking `struct` method of the contract. +// This transaction is signed and immediately sent to the network. +// The values returned are its hash, ValidUntilBlock value and error if any. +func (c *Contract) Struct() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "struct") +} + +// StructTransaction creates a transaction invoking `struct` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) StructTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "struct") +} + +// StructUnsigned creates a transaction invoking `struct` method of the contract. +// This transaction is not signed, it's simply returned to the caller. +// Any fields of it that do not affect fees can be changed (ValidUntilBlock, +// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. +func (c *Contract) StructUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "struct", nil) +} + +// UnexportedField creates a transaction invoking `unexportedField` method of the contract. +// This transaction is signed and immediately sent to the network. +// The values returned are its hash, ValidUntilBlock value and error if any. +func (c *Contract) UnexportedField() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "unexportedField") +} + +// UnexportedFieldTransaction creates a transaction invoking `unexportedField` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) UnexportedFieldTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "unexportedField") +} + +// UnexportedFieldUnsigned creates a transaction invoking `unexportedField` method of the contract. +// This transaction is not signed, it's simply returned to the caller. +// Any fields of it that do not affect fees can be changed (ValidUntilBlock, +// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. +func (c *Contract) UnexportedFieldUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "unexportedField", nil) +} + +// itemToCrazyStruct converts stack item into *CrazyStruct. +// NULL item is returned as nil pointer without error. +func itemToCrazyStruct(item stackitem.Item, err error) (*CrazyStruct, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(CrazyStruct) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *CrazyStruct is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&CrazyStruct{}) + +// Ensure *CrazyStruct is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&CrazyStruct{}) + +// FromStackItem retrieves fields of CrazyStruct from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *CrazyStruct) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.I, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field I: %w", err) + } + + index++ + res.B, err = arr[index].TryBool() + if err != nil { + return fmt.Errorf("field B: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing CrazyStruct. +// It implements [stackitem.Convertible] interface. +func (res *CrazyStruct) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 2) + ) + itm, err = (*stackitem.BigInteger)(res.I), error(nil) + if err != nil { + return nil, fmt.Errorf("field I: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewBool(res.B), error(nil) + if err != nil { + return nil, fmt.Errorf("field B: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing CrazyStruct. +// It implements [smartcontract.Convertible] interface so that CrazyStruct +// could be used with invokers. +func (res *CrazyStruct) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 2) + ) + prm, err = smartcontract.NewParameterFromValue(res.I) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field I: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.B) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field B: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToSimpleStruct converts stack item into *SimpleStruct. +// NULL item is returned as nil pointer without error. +func itemToSimpleStruct(item stackitem.Item, err error) (*SimpleStruct, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(SimpleStruct) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *SimpleStruct is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&SimpleStruct{}) + +// Ensure *SimpleStruct is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&SimpleStruct{}) + +// FromStackItem retrieves fields of SimpleStruct from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *SimpleStruct) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.I, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field I: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing SimpleStruct. +// It implements [stackitem.Convertible] interface. +func (res *SimpleStruct) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 1) + ) + itm, err = (*stackitem.BigInteger)(res.I), error(nil) + if err != nil { + return nil, fmt.Errorf("field I: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing SimpleStruct. +// It implements [smartcontract.Convertible] interface so that SimpleStruct +// could be used with invokers. +func (res *SimpleStruct) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 1) + ) + prm, err = smartcontract.NewParameterFromValue(res.I) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field I: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// ComplicatedNameEventsFromApplicationLog retrieves a set of all emitted events +// with "! complicated name %$#" name from the provided [result.ApplicationLog]. +func ComplicatedNameEventsFromApplicationLog(log *result.ApplicationLog) ([]*ComplicatedNameEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*ComplicatedNameEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "! complicated name %$#" { + continue + } + event := new(ComplicatedNameEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize ComplicatedNameEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to ComplicatedNameEvent or +// returns an error if it's not possible to do to so. +func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.ComplicatedParam, 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[index]) + if err != nil { + return fmt.Errorf("field ComplicatedParam: %w", err) + } + + return nil +} + +// SomeMapEventsFromApplicationLog retrieves a set of all emitted events +// with "SomeMap" name from the provided [result.ApplicationLog]. +func SomeMapEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeMapEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*SomeMapEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "SomeMap" { + continue + } + event := new(SomeMapEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize SomeMapEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to SomeMapEvent or +// returns an error if it's not possible to do to so. +func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.M, err = 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) { + 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 + }(m[i].Value) + if err != nil { + return nil, fmt.Errorf("value %d: %w", i, err) + } + res[k] = v + } + return res, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field M: %w", err) + } + + return nil +} + +// SomeStructEventsFromApplicationLog retrieves a set of all emitted events +// with "SomeStruct" name from the provided [result.ApplicationLog]. +func SomeStructEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeStructEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*SomeStructEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "SomeStruct" { + continue + } + event := new(SomeStructEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize SomeStructEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to SomeStructEvent or +// returns an error if it's not possible to do to so. +func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.S, err = itemToCrazyStruct(arr[index], nil) + if err != nil { + return fmt.Errorf("field S: %w", err) + } + + return nil +} + +// SomeArrayEventsFromApplicationLog retrieves a set of all emitted events +// with "SomeArray" name from the provided [result.ApplicationLog]. +func SomeArrayEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeArrayEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*SomeArrayEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "SomeArray" { + continue + } + event := new(SomeArrayEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize SomeArrayEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to SomeArrayEvent or +// returns an error if it's not possible to do to so. +func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.A, err = func(item stackitem.Item) ([][]*big.Int, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([][]*big.Int, len(arr)) + for i := range res { + res[i], err = func(item stackitem.Item) ([]*big.Int, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([]*big.Int, len(arr)) + for i := range res { + res[i], err = arr[i].TryInteger() + 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[index]) + if err != nil { + return fmt.Errorf("field A: %w", err) + } + + return nil +} + +// SomeUnexportedFieldEventsFromApplicationLog retrieves a set of all emitted events +// with "SomeUnexportedField" name from the provided [result.ApplicationLog]. +func SomeUnexportedFieldEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeUnexportedFieldEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*SomeUnexportedFieldEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "SomeUnexportedField" { + continue + } + event := new(SomeUnexportedFieldEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize SomeUnexportedFieldEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to SomeUnexportedFieldEvent or +// returns an error if it's not possible to do to so. +func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.S, err = itemToSimpleStruct(arr[index], nil) + if err != nil { + return fmt.Errorf("field S: %w", err) + } + + return nil +} diff --git a/cli/smartcontract/rpcbindings/notifications/rpcbindings/guessed/rpcbindings_test.go b/cli/smartcontract/rpcbindings/notifications/rpcbindings/guessed/rpcbindings_test.go old mode 100755 new mode 100644 index ad87c14..c15e730 --- a/cli/smartcontract/rpcbindings/notifications/rpcbindings/guessed/rpcbindings_test.go +++ b/cli/smartcontract/rpcbindings/notifications/rpcbindings/guessed/rpcbindings_test.go @@ -1,759 +1,759 @@ -// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. - -// Package structs contains RPC wrappers for Notifications contract. -package structs - -import ( - "errors" - "fmt" - "github.com/tutus-one/tutus-chain/pkg/core/transaction" - "github.com/tutus-one/tutus-chain/pkg/neorpc/result" - "github.com/tutus-one/tutus-chain/pkg/smartcontract" - "github.com/tutus-one/tutus-chain/pkg/util" - "github.com/tutus-one/tutus-chain/pkg/vm/stackitem" - "math/big" - "unicode/utf8" -) - -// Hash contains contract hash. -var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x0} - -// Unnamed is a contract-specific unnamed type used by its methods. -type Unnamed struct { - I *big.Int - B bool -} - -// UnnamedX is a contract-specific unnamedX type used by its methods. -type UnnamedX struct { - I *big.Int -} - -// ComplicatedNameEvent represents "! complicated name %$#" event emitted by the contract. -type ComplicatedNameEvent struct { - ComplicatedParam string -} - -// SomeMapEvent represents "SomeMap" event emitted by the contract. -type SomeMapEvent struct { - M map[*big.Int][]map[string][]util.Uint160 -} - -// SomeStructEvent represents "SomeStruct" event emitted by the contract. -type SomeStructEvent struct { - S *Unnamed -} - -// SomeArrayEvent represents "SomeArray" event emitted by the contract. -type SomeArrayEvent struct { - A [][]*big.Int -} - -// SomeUnexportedFieldEvent represents "SomeUnexportedField" event emitted by the contract. -type SomeUnexportedFieldEvent struct { - S *UnnamedX -} - -// Actor is used by Contract to call state-changing methods. -type Actor interface { - MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) - MakeRun(script []byte) (*transaction.Transaction, error) - MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) - MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) - SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) - SendRun(script []byte) (util.Uint256, uint32, error) -} - -// Contract implements all contract methods. -type Contract struct { - actor Actor - hash util.Uint160 -} - -// New creates an instance of Contract using Hash and the given Actor. -func New(actor Actor) *Contract { - var hash = Hash - return &Contract{actor, hash} -} - -// Array creates a transaction invoking `array` method of the contract. -// This transaction is signed and immediately sent to the network. -// The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) Array() (util.Uint256, uint32, error) { - return c.actor.SendCall(c.hash, "array") -} - -// ArrayTransaction creates a transaction invoking `array` method of the contract. -// This transaction is signed, but not sent to the network, instead it's -// returned to the caller. -func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) { - return c.actor.MakeCall(c.hash, "array") -} - -// ArrayUnsigned creates a transaction invoking `array` method of the contract. -// This transaction is not signed, it's simply returned to the caller. -// Any fields of it that do not affect fees can be changed (ValidUntilBlock, -// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) { - return c.actor.MakeUnsignedCall(c.hash, "array", nil) -} - -// CrazyMap creates a transaction invoking `crazyMap` method of the contract. -// This transaction is signed and immediately sent to the network. -// The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) CrazyMap() (util.Uint256, uint32, error) { - return c.actor.SendCall(c.hash, "crazyMap") -} - -// CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract. -// This transaction is signed, but not sent to the network, instead it's -// returned to the caller. -func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) { - return c.actor.MakeCall(c.hash, "crazyMap") -} - -// CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract. -// This transaction is not signed, it's simply returned to the caller. -// Any fields of it that do not affect fees can be changed (ValidUntilBlock, -// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) { - return c.actor.MakeUnsignedCall(c.hash, "crazyMap", nil) -} - -// Main creates a transaction invoking `main` method of the contract. -// This transaction is signed and immediately sent to the network. -// The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) Main() (util.Uint256, uint32, error) { - return c.actor.SendCall(c.hash, "main") -} - -// MainTransaction creates a transaction invoking `main` method of the contract. -// This transaction is signed, but not sent to the network, instead it's -// returned to the caller. -func (c *Contract) MainTransaction() (*transaction.Transaction, error) { - return c.actor.MakeCall(c.hash, "main") -} - -// MainUnsigned creates a transaction invoking `main` method of the contract. -// This transaction is not signed, it's simply returned to the caller. -// Any fields of it that do not affect fees can be changed (ValidUntilBlock, -// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) MainUnsigned() (*transaction.Transaction, error) { - return c.actor.MakeUnsignedCall(c.hash, "main", nil) -} - -// Struct creates a transaction invoking `struct` method of the contract. -// This transaction is signed and immediately sent to the network. -// The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) Struct() (util.Uint256, uint32, error) { - return c.actor.SendCall(c.hash, "struct") -} - -// StructTransaction creates a transaction invoking `struct` method of the contract. -// This transaction is signed, but not sent to the network, instead it's -// returned to the caller. -func (c *Contract) StructTransaction() (*transaction.Transaction, error) { - return c.actor.MakeCall(c.hash, "struct") -} - -// StructUnsigned creates a transaction invoking `struct` method of the contract. -// This transaction is not signed, it's simply returned to the caller. -// Any fields of it that do not affect fees can be changed (ValidUntilBlock, -// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) StructUnsigned() (*transaction.Transaction, error) { - return c.actor.MakeUnsignedCall(c.hash, "struct", nil) -} - -// UnexportedField creates a transaction invoking `unexportedField` method of the contract. -// This transaction is signed and immediately sent to the network. -// The values returned are its hash, ValidUntilBlock value and error if any. -func (c *Contract) UnexportedField() (util.Uint256, uint32, error) { - return c.actor.SendCall(c.hash, "unexportedField") -} - -// UnexportedFieldTransaction creates a transaction invoking `unexportedField` method of the contract. -// This transaction is signed, but not sent to the network, instead it's -// returned to the caller. -func (c *Contract) UnexportedFieldTransaction() (*transaction.Transaction, error) { - return c.actor.MakeCall(c.hash, "unexportedField") -} - -// UnexportedFieldUnsigned creates a transaction invoking `unexportedField` method of the contract. -// This transaction is not signed, it's simply returned to the caller. -// Any fields of it that do not affect fees can be changed (ValidUntilBlock, -// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. -func (c *Contract) UnexportedFieldUnsigned() (*transaction.Transaction, error) { - return c.actor.MakeUnsignedCall(c.hash, "unexportedField", nil) -} - -// itemToUnnamed converts stack item into *Unnamed. -// NULL item is returned as nil pointer without error. -func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(Unnamed) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *Unnamed is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&Unnamed{}) - -// Ensure *Unnamed is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&Unnamed{}) - -// FromStackItem retrieves fields of Unnamed from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *Unnamed) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 2 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.I, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field I: %w", err) - } - - index++ - res.B, err = arr[index].TryBool() - if err != nil { - return fmt.Errorf("field B: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing Unnamed. -// It implements [stackitem.Convertible] interface. -func (res *Unnamed) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 2) - ) - itm, err = (*stackitem.BigInteger)(res.I), error(nil) - if err != nil { - return nil, fmt.Errorf("field I: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewBool(res.B), error(nil) - if err != nil { - return nil, fmt.Errorf("field B: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing Unnamed. -// It implements [smartcontract.Convertible] interface so that Unnamed -// could be used with invokers. -func (res *Unnamed) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 2) - ) - prm, err = smartcontract.NewParameterFromValue(res.I) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field I: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.B) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field B: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToUnnamedX converts stack item into *UnnamedX. -// NULL item is returned as nil pointer without error. -func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(UnnamedX) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *UnnamedX is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&UnnamedX{}) - -// Ensure *UnnamedX is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&UnnamedX{}) - -// FromStackItem retrieves fields of UnnamedX from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *UnnamedX) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.I, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field I: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing UnnamedX. -// It implements [stackitem.Convertible] interface. -func (res *UnnamedX) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 1) - ) - itm, err = (*stackitem.BigInteger)(res.I), error(nil) - if err != nil { - return nil, fmt.Errorf("field I: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing UnnamedX. -// It implements [smartcontract.Convertible] interface so that UnnamedX -// could be used with invokers. -func (res *UnnamedX) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 1) - ) - prm, err = smartcontract.NewParameterFromValue(res.I) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field I: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// ComplicatedNameEventsFromApplicationLog retrieves a set of all emitted events -// with "! complicated name %$#" name from the provided [result.ApplicationLog]. -func ComplicatedNameEventsFromApplicationLog(log *result.ApplicationLog) ([]*ComplicatedNameEvent, error) { - if log == nil { - return nil, errors.New("nil application log") - } - - var res []*ComplicatedNameEvent - for i, ex := range log.Executions { - for j, e := range ex.Events { - if e.Name != "! complicated name %$#" { - continue - } - event := new(ComplicatedNameEvent) - err := event.FromStackItem(e.Item) - if err != nil { - return nil, fmt.Errorf("failed to deserialize ComplicatedNameEvent from stackitem (execution #%d, event #%d): %w", i, j, err) - } - res = append(res, event) - } - } - - return res, nil -} - -// FromStackItem converts provided [stackitem.Array] to ComplicatedNameEvent or -// returns an error if it's not possible to do to so. -func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error { - if item == nil { - return errors.New("nil item") - } - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - e.ComplicatedParam, 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[index]) - if err != nil { - return fmt.Errorf("field ComplicatedParam: %w", err) - } - - return nil -} - -// SomeMapEventsFromApplicationLog retrieves a set of all emitted events -// with "SomeMap" name from the provided [result.ApplicationLog]. -func SomeMapEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeMapEvent, error) { - if log == nil { - return nil, errors.New("nil application log") - } - - var res []*SomeMapEvent - for i, ex := range log.Executions { - for j, e := range ex.Events { - if e.Name != "SomeMap" { - continue - } - event := new(SomeMapEvent) - err := event.FromStackItem(e.Item) - if err != nil { - return nil, fmt.Errorf("failed to deserialize SomeMapEvent from stackitem (execution #%d, event #%d): %w", i, j, err) - } - res = append(res, event) - } - } - - return res, nil -} - -// FromStackItem converts provided [stackitem.Array] to SomeMapEvent or -// returns an error if it's not possible to do to so. -func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error { - if item == nil { - return errors.New("nil item") - } - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - e.M, err = 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 - }(arr[index]) - if err != nil { - return fmt.Errorf("field M: %w", err) - } - - return nil -} - -// SomeStructEventsFromApplicationLog retrieves a set of all emitted events -// with "SomeStruct" name from the provided [result.ApplicationLog]. -func SomeStructEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeStructEvent, error) { - if log == nil { - return nil, errors.New("nil application log") - } - - var res []*SomeStructEvent - for i, ex := range log.Executions { - for j, e := range ex.Events { - if e.Name != "SomeStruct" { - continue - } - event := new(SomeStructEvent) - err := event.FromStackItem(e.Item) - if err != nil { - return nil, fmt.Errorf("failed to deserialize SomeStructEvent from stackitem (execution #%d, event #%d): %w", i, j, err) - } - res = append(res, event) - } - } - - return res, nil -} - -// FromStackItem converts provided [stackitem.Array] to SomeStructEvent or -// returns an error if it's not possible to do to so. -func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error { - if item == nil { - return errors.New("nil item") - } - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - e.S, err = itemToUnnamed(arr[index], nil) - if err != nil { - return fmt.Errorf("field S: %w", err) - } - - return nil -} - -// SomeArrayEventsFromApplicationLog retrieves a set of all emitted events -// with "SomeArray" name from the provided [result.ApplicationLog]. -func SomeArrayEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeArrayEvent, error) { - if log == nil { - return nil, errors.New("nil application log") - } - - var res []*SomeArrayEvent - for i, ex := range log.Executions { - for j, e := range ex.Events { - if e.Name != "SomeArray" { - continue - } - event := new(SomeArrayEvent) - err := event.FromStackItem(e.Item) - if err != nil { - return nil, fmt.Errorf("failed to deserialize SomeArrayEvent from stackitem (execution #%d, event #%d): %w", i, j, err) - } - res = append(res, event) - } - } - - return res, nil -} - -// FromStackItem converts provided [stackitem.Array] to SomeArrayEvent or -// returns an error if it's not possible to do to so. -func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error { - if item == nil { - return errors.New("nil item") - } - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - e.A, err = func(item stackitem.Item) ([][]*big.Int, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make([][]*big.Int, len(arr)) - for i := range res { - res[i], err = func(item stackitem.Item) ([]*big.Int, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make([]*big.Int, len(arr)) - for i := range res { - res[i], err = arr[i].TryInteger() - 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[index]) - if err != nil { - return fmt.Errorf("field A: %w", err) - } - - return nil -} - -// SomeUnexportedFieldEventsFromApplicationLog retrieves a set of all emitted events -// with "SomeUnexportedField" name from the provided [result.ApplicationLog]. -func SomeUnexportedFieldEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeUnexportedFieldEvent, error) { - if log == nil { - return nil, errors.New("nil application log") - } - - var res []*SomeUnexportedFieldEvent - for i, ex := range log.Executions { - for j, e := range ex.Events { - if e.Name != "SomeUnexportedField" { - continue - } - event := new(SomeUnexportedFieldEvent) - err := event.FromStackItem(e.Item) - if err != nil { - return nil, fmt.Errorf("failed to deserialize SomeUnexportedFieldEvent from stackitem (execution #%d, event #%d): %w", i, j, err) - } - res = append(res, event) - } - } - - return res, nil -} - -// FromStackItem converts provided [stackitem.Array] to SomeUnexportedFieldEvent or -// returns an error if it's not possible to do to so. -func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error { - if item == nil { - return errors.New("nil item") - } - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - e.S, err = itemToUnnamedX(arr[index], nil) - if err != nil { - return fmt.Errorf("field S: %w", err) - } - - return nil -} +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. + +// Package structs contains RPC wrappers for Notifications contract. +package structs + +import ( + "errors" + "fmt" + "github.com/tutus-one/tutus-chain/pkg/core/transaction" + "github.com/tutus-one/tutus-chain/pkg/neorpc/result" + "github.com/tutus-one/tutus-chain/pkg/smartcontract" + "github.com/tutus-one/tutus-chain/pkg/util" + "github.com/tutus-one/tutus-chain/pkg/vm/stackitem" + "math/big" + "unicode/utf8" +) + +// Hash contains contract hash. +var Hash = util.Uint160{0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x0} + +// Unnamed is a contract-specific unnamed type used by its methods. +type Unnamed struct { + I *big.Int + B bool +} + +// UnnamedX is a contract-specific unnamedX type used by its methods. +type UnnamedX struct { + I *big.Int +} + +// ComplicatedNameEvent represents "! complicated name %$#" event emitted by the contract. +type ComplicatedNameEvent struct { + ComplicatedParam string +} + +// SomeMapEvent represents "SomeMap" event emitted by the contract. +type SomeMapEvent struct { + M map[*big.Int][]map[string][]util.Uint160 +} + +// SomeStructEvent represents "SomeStruct" event emitted by the contract. +type SomeStructEvent struct { + S *Unnamed +} + +// SomeArrayEvent represents "SomeArray" event emitted by the contract. +type SomeArrayEvent struct { + A [][]*big.Int +} + +// SomeUnexportedFieldEvent represents "SomeUnexportedField" event emitted by the contract. +type SomeUnexportedFieldEvent struct { + S *UnnamedX +} + +// Actor is used by Contract to call state-changing methods. +type Actor interface { + MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) + MakeRun(script []byte) (*transaction.Transaction, error) + MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) + MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error) + SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) + SendRun(script []byte) (util.Uint256, uint32, error) +} + +// Contract implements all contract methods. +type Contract struct { + actor Actor + hash util.Uint160 +} + +// New creates an instance of Contract using Hash and the given Actor. +func New(actor Actor) *Contract { + var hash = Hash + return &Contract{actor, hash} +} + +// Array creates a transaction invoking `array` method of the contract. +// This transaction is signed and immediately sent to the network. +// The values returned are its hash, ValidUntilBlock value and error if any. +func (c *Contract) Array() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "array") +} + +// ArrayTransaction creates a transaction invoking `array` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) ArrayTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "array") +} + +// ArrayUnsigned creates a transaction invoking `array` method of the contract. +// This transaction is not signed, it's simply returned to the caller. +// Any fields of it that do not affect fees can be changed (ValidUntilBlock, +// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. +func (c *Contract) ArrayUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "array", nil) +} + +// CrazyMap creates a transaction invoking `crazyMap` method of the contract. +// This transaction is signed and immediately sent to the network. +// The values returned are its hash, ValidUntilBlock value and error if any. +func (c *Contract) CrazyMap() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "crazyMap") +} + +// CrazyMapTransaction creates a transaction invoking `crazyMap` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) CrazyMapTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "crazyMap") +} + +// CrazyMapUnsigned creates a transaction invoking `crazyMap` method of the contract. +// This transaction is not signed, it's simply returned to the caller. +// Any fields of it that do not affect fees can be changed (ValidUntilBlock, +// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. +func (c *Contract) CrazyMapUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "crazyMap", nil) +} + +// Main creates a transaction invoking `main` method of the contract. +// This transaction is signed and immediately sent to the network. +// The values returned are its hash, ValidUntilBlock value and error if any. +func (c *Contract) Main() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "main") +} + +// MainTransaction creates a transaction invoking `main` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) MainTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "main") +} + +// MainUnsigned creates a transaction invoking `main` method of the contract. +// This transaction is not signed, it's simply returned to the caller. +// Any fields of it that do not affect fees can be changed (ValidUntilBlock, +// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. +func (c *Contract) MainUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "main", nil) +} + +// Struct creates a transaction invoking `struct` method of the contract. +// This transaction is signed and immediately sent to the network. +// The values returned are its hash, ValidUntilBlock value and error if any. +func (c *Contract) Struct() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "struct") +} + +// StructTransaction creates a transaction invoking `struct` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) StructTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "struct") +} + +// StructUnsigned creates a transaction invoking `struct` method of the contract. +// This transaction is not signed, it's simply returned to the caller. +// Any fields of it that do not affect fees can be changed (ValidUntilBlock, +// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. +func (c *Contract) StructUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "struct", nil) +} + +// UnexportedField creates a transaction invoking `unexportedField` method of the contract. +// This transaction is signed and immediately sent to the network. +// The values returned are its hash, ValidUntilBlock value and error if any. +func (c *Contract) UnexportedField() (util.Uint256, uint32, error) { + return c.actor.SendCall(c.hash, "unexportedField") +} + +// UnexportedFieldTransaction creates a transaction invoking `unexportedField` method of the contract. +// This transaction is signed, but not sent to the network, instead it's +// returned to the caller. +func (c *Contract) UnexportedFieldTransaction() (*transaction.Transaction, error) { + return c.actor.MakeCall(c.hash, "unexportedField") +} + +// UnexportedFieldUnsigned creates a transaction invoking `unexportedField` method of the contract. +// This transaction is not signed, it's simply returned to the caller. +// Any fields of it that do not affect fees can be changed (ValidUntilBlock, +// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. +func (c *Contract) UnexportedFieldUnsigned() (*transaction.Transaction, error) { + return c.actor.MakeUnsignedCall(c.hash, "unexportedField", nil) +} + +// itemToUnnamed converts stack item into *Unnamed. +// NULL item is returned as nil pointer without error. +func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(Unnamed) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *Unnamed is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&Unnamed{}) + +// Ensure *Unnamed is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&Unnamed{}) + +// FromStackItem retrieves fields of Unnamed from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *Unnamed) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.I, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field I: %w", err) + } + + index++ + res.B, err = arr[index].TryBool() + if err != nil { + return fmt.Errorf("field B: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing Unnamed. +// It implements [stackitem.Convertible] interface. +func (res *Unnamed) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 2) + ) + itm, err = (*stackitem.BigInteger)(res.I), error(nil) + if err != nil { + return nil, fmt.Errorf("field I: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewBool(res.B), error(nil) + if err != nil { + return nil, fmt.Errorf("field B: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing Unnamed. +// It implements [smartcontract.Convertible] interface so that Unnamed +// could be used with invokers. +func (res *Unnamed) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 2) + ) + prm, err = smartcontract.NewParameterFromValue(res.I) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field I: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.B) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field B: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToUnnamedX converts stack item into *UnnamedX. +// NULL item is returned as nil pointer without error. +func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(UnnamedX) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *UnnamedX is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&UnnamedX{}) + +// Ensure *UnnamedX is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&UnnamedX{}) + +// FromStackItem retrieves fields of UnnamedX from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *UnnamedX) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.I, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field I: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing UnnamedX. +// It implements [stackitem.Convertible] interface. +func (res *UnnamedX) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 1) + ) + itm, err = (*stackitem.BigInteger)(res.I), error(nil) + if err != nil { + return nil, fmt.Errorf("field I: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing UnnamedX. +// It implements [smartcontract.Convertible] interface so that UnnamedX +// could be used with invokers. +func (res *UnnamedX) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 1) + ) + prm, err = smartcontract.NewParameterFromValue(res.I) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field I: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// ComplicatedNameEventsFromApplicationLog retrieves a set of all emitted events +// with "! complicated name %$#" name from the provided [result.ApplicationLog]. +func ComplicatedNameEventsFromApplicationLog(log *result.ApplicationLog) ([]*ComplicatedNameEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*ComplicatedNameEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "! complicated name %$#" { + continue + } + event := new(ComplicatedNameEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize ComplicatedNameEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to ComplicatedNameEvent or +// returns an error if it's not possible to do to so. +func (e *ComplicatedNameEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.ComplicatedParam, 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[index]) + if err != nil { + return fmt.Errorf("field ComplicatedParam: %w", err) + } + + return nil +} + +// SomeMapEventsFromApplicationLog retrieves a set of all emitted events +// with "SomeMap" name from the provided [result.ApplicationLog]. +func SomeMapEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeMapEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*SomeMapEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "SomeMap" { + continue + } + event := new(SomeMapEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize SomeMapEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to SomeMapEvent or +// returns an error if it's not possible to do to so. +func (e *SomeMapEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.M, err = 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 + }(arr[index]) + if err != nil { + return fmt.Errorf("field M: %w", err) + } + + return nil +} + +// SomeStructEventsFromApplicationLog retrieves a set of all emitted events +// with "SomeStruct" name from the provided [result.ApplicationLog]. +func SomeStructEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeStructEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*SomeStructEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "SomeStruct" { + continue + } + event := new(SomeStructEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize SomeStructEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to SomeStructEvent or +// returns an error if it's not possible to do to so. +func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.S, err = itemToUnnamed(arr[index], nil) + if err != nil { + return fmt.Errorf("field S: %w", err) + } + + return nil +} + +// SomeArrayEventsFromApplicationLog retrieves a set of all emitted events +// with "SomeArray" name from the provided [result.ApplicationLog]. +func SomeArrayEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeArrayEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*SomeArrayEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "SomeArray" { + continue + } + event := new(SomeArrayEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize SomeArrayEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to SomeArrayEvent or +// returns an error if it's not possible to do to so. +func (e *SomeArrayEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.A, err = func(item stackitem.Item) ([][]*big.Int, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([][]*big.Int, len(arr)) + for i := range res { + res[i], err = func(item stackitem.Item) ([]*big.Int, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([]*big.Int, len(arr)) + for i := range res { + res[i], err = arr[i].TryInteger() + 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[index]) + if err != nil { + return fmt.Errorf("field A: %w", err) + } + + return nil +} + +// SomeUnexportedFieldEventsFromApplicationLog retrieves a set of all emitted events +// with "SomeUnexportedField" name from the provided [result.ApplicationLog]. +func SomeUnexportedFieldEventsFromApplicationLog(log *result.ApplicationLog) ([]*SomeUnexportedFieldEvent, error) { + if log == nil { + return nil, errors.New("nil application log") + } + + var res []*SomeUnexportedFieldEvent + for i, ex := range log.Executions { + for j, e := range ex.Events { + if e.Name != "SomeUnexportedField" { + continue + } + event := new(SomeUnexportedFieldEvent) + err := event.FromStackItem(e.Item) + if err != nil { + return nil, fmt.Errorf("failed to deserialize SomeUnexportedFieldEvent from stackitem (execution #%d, event #%d): %w", i, j, err) + } + res = append(res, event) + } + } + + return res, nil +} + +// FromStackItem converts provided [stackitem.Array] to SomeUnexportedFieldEvent or +// returns an error if it's not possible to do to so. +func (e *SomeUnexportedFieldEvent) FromStackItem(item *stackitem.Array) error { + if item == nil { + return errors.New("nil item") + } + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + e.S, err = itemToUnnamedX(arr[index], nil) + if err != nil { + return fmt.Errorf("field S: %w", err) + } + + return nil +} diff --git a/cli/smartcontract/rpcbindings/structs/rpcbindings/dynamic_hash/rpcbindings_test.go b/cli/smartcontract/rpcbindings/structs/rpcbindings/dynamic_hash/rpcbindings_test.go old mode 100755 new mode 100644 index 6838c08..5d58b3d --- a/cli/smartcontract/rpcbindings/structs/rpcbindings/dynamic_hash/rpcbindings_test.go +++ b/cli/smartcontract/rpcbindings/structs/rpcbindings/dynamic_hash/rpcbindings_test.go @@ -1,2860 +1,2860 @@ -// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. - -// Package structs contains RPC wrappers for Types contract. -package structs - -import ( - "crypto/elliptic" - "errors" - "fmt" - "github.com/tutus-one/tutus-chain/pkg/crypto/keys" - "github.com/tutus-one/tutus-chain/pkg/neorpc/result" - "github.com/tutus-one/tutus-chain/pkg/rpcclient/unwrap" - "github.com/tutus-one/tutus-chain/pkg/smartcontract" - "github.com/tutus-one/tutus-chain/pkg/util" - "github.com/tutus-one/tutus-chain/pkg/vm/stackitem" - "math/big" - "unicode/utf8" -) - -// LedgerBlock is a contract-specific ledger.Block type used by its methods. -type LedgerBlock struct { - Hash util.Uint256 - Version *big.Int - PrevHash util.Uint256 - MerkleRoot util.Uint256 - Timestamp *big.Int - Nonce *big.Int - Index *big.Int - PrimaryIndex *big.Int - NextConsensus util.Uint160 - TransactionsLength *big.Int -} - -// LedgerTransaction is a contract-specific ledger.Transaction type used by its methods. -type LedgerTransaction struct { - Hash util.Uint256 - Version *big.Int - Nonce *big.Int - Sender util.Uint160 - SysFee *big.Int - NetFee *big.Int - ValidUntilBlock *big.Int - Script []byte -} - -// ManagementABI is a contract-specific management.ABI type used by its methods. -type ManagementABI struct { - Methods []*ManagementMethod - Events []*ManagementEvent -} - -// ManagementContract is a contract-specific management.Contract type used by its methods. -type ManagementContract struct { - ID *big.Int - UpdateCounter *big.Int - Hash util.Uint160 - NEF []byte - Manifest *ManagementManifest -} - -// ManagementEvent is a contract-specific management.Event type used by its methods. -type ManagementEvent struct { - Name string - Params []*ManagementParameter -} - -// ManagementGroup is a contract-specific management.Group type used by its methods. -type ManagementGroup struct { - PublicKey *keys.PublicKey - Signature []byte -} - -// ManagementManifest is a contract-specific management.Manifest type used by its methods. -type ManagementManifest struct { - Name string - Groups []*ManagementGroup - Features map[string]string - SupportedStandards []string - ABI *ManagementABI - Permissions []*ManagementPermission - Trusts []util.Uint160 - Extra any -} - -// ManagementMethod is a contract-specific management.Method type used by its methods. -type ManagementMethod struct { - Name string - Params []*ManagementParameter - ReturnType *big.Int - Offset *big.Int - Safe bool -} - -// ManagementParameter is a contract-specific management.Parameter type used by its methods. -type ManagementParameter struct { - Name string - Type *big.Int -} - -// ManagementPermission is a contract-specific management.Permission type used by its methods. -type ManagementPermission struct { - Contract util.Uint160 - Methods []string -} - -// StructsInternal is a contract-specific structs.Internal type used by its methods. -type StructsInternal struct { - Bool bool - Int *big.Int - Bytes []byte - String string - H160 util.Uint160 - H256 util.Uint256 - PK *keys.PublicKey - PubKey *keys.PublicKey - Sign []byte - ArrOfBytes [][]byte - ArrOfH160 []util.Uint160 - Map map[*big.Int]keys.PublicKeys - Struct *StructsInternal - UnexportedField *big.Int -} - -// Invoker is used by ContractReader to call various safe methods. -type Invoker interface { - Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) -} - -// 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} -} - -// Block invokes `block` method of contract. -func (c *ContractReader) Block(b *LedgerBlock) (*LedgerBlock, error) { - return itemToLedgerBlock(unwrap.Item(c.invoker.Call(c.hash, "block", b))) -} - -// Contract invokes `contract` method of contract. -func (c *ContractReader) Contract(mc *ManagementContract) (*ManagementContract, error) { - return itemToManagementContract(unwrap.Item(c.invoker.Call(c.hash, "contract", mc))) -} - -// Struct invokes `struct` method of contract. -func (c *ContractReader) Struct(s *StructsInternal) (*StructsInternal, error) { - return itemToStructsInternal(unwrap.Item(c.invoker.Call(c.hash, "struct", s))) -} - -// Transaction invokes `transaction` method of contract. -func (c *ContractReader) Transaction(t *LedgerTransaction) (*LedgerTransaction, error) { - return itemToLedgerTransaction(unwrap.Item(c.invoker.Call(c.hash, "transaction", t))) -} - -// itemToLedgerBlock converts stack item into *LedgerBlock. -// NULL item is returned as nil pointer without error. -func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(LedgerBlock) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *LedgerBlock is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&LedgerBlock{}) - -// Ensure *LedgerBlock is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&LedgerBlock{}) - -// FromStackItem retrieves fields of LedgerBlock from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *LedgerBlock) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 10 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.Hash, err = func(item stackitem.Item) (util.Uint256, error) { - b, err := item.TryBytes() - if err != nil { - return util.Uint256{}, err - } - u, err := util.Uint256DecodeBytesBE(b) - if err != nil { - return util.Uint256{}, err - } - return u, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field Hash: %w", err) - } - - index++ - res.Version, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field Version: %w", err) - } - - index++ - res.PrevHash, err = func(item stackitem.Item) (util.Uint256, error) { - b, err := item.TryBytes() - if err != nil { - return util.Uint256{}, err - } - u, err := util.Uint256DecodeBytesBE(b) - if err != nil { - return util.Uint256{}, err - } - return u, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field PrevHash: %w", err) - } - - index++ - res.MerkleRoot, err = func(item stackitem.Item) (util.Uint256, error) { - b, err := item.TryBytes() - if err != nil { - return util.Uint256{}, err - } - u, err := util.Uint256DecodeBytesBE(b) - if err != nil { - return util.Uint256{}, err - } - return u, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field MerkleRoot: %w", err) - } - - index++ - res.Timestamp, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field Timestamp: %w", err) - } - - index++ - res.Nonce, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field Nonce: %w", err) - } - - index++ - res.Index, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field Index: %w", err) - } - - index++ - res.PrimaryIndex, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field PrimaryIndex: %w", err) - } - - index++ - res.NextConsensus, err = func(item stackitem.Item) (util.Uint160, error) { - b, err := item.TryBytes() - if err != nil { - return util.Uint160{}, err - } - u, err := util.Uint160DecodeBytesBE(b) - if err != nil { - return util.Uint160{}, err - } - return u, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field NextConsensus: %w", err) - } - - index++ - res.TransactionsLength, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field TransactionsLength: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing LedgerBlock. -// It implements [stackitem.Convertible] interface. -func (res *LedgerBlock) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 10) - ) - itm, err = stackitem.NewByteArray(res.Hash.BytesBE()), error(nil) - if err != nil { - return nil, fmt.Errorf("field Hash: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.Version), error(nil) - if err != nil { - return nil, fmt.Errorf("field Version: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.PrevHash.BytesBE()), error(nil) - if err != nil { - return nil, fmt.Errorf("field PrevHash: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.MerkleRoot.BytesBE()), error(nil) - if err != nil { - return nil, fmt.Errorf("field MerkleRoot: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.Timestamp), error(nil) - if err != nil { - return nil, fmt.Errorf("field Timestamp: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.Nonce), error(nil) - if err != nil { - return nil, fmt.Errorf("field Nonce: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.Index), error(nil) - if err != nil { - return nil, fmt.Errorf("field Index: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.PrimaryIndex), error(nil) - if err != nil { - return nil, fmt.Errorf("field PrimaryIndex: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.NextConsensus.BytesBE()), error(nil) - if err != nil { - return nil, fmt.Errorf("field NextConsensus: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.TransactionsLength), error(nil) - if err != nil { - return nil, fmt.Errorf("field TransactionsLength: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing LedgerBlock. -// It implements [smartcontract.Convertible] interface so that LedgerBlock -// could be used with invokers. -func (res *LedgerBlock) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 10) - ) - prm, err = smartcontract.NewParameterFromValue(res.Hash) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Hash: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Version) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Version: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.PrevHash) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field PrevHash: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.MerkleRoot) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field MerkleRoot: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Timestamp) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Timestamp: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Nonce) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Nonce: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Index) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Index: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.PrimaryIndex) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field PrimaryIndex: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.NextConsensus) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field NextConsensus: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.TransactionsLength) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field TransactionsLength: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToLedgerTransaction converts stack item into *LedgerTransaction. -// NULL item is returned as nil pointer without error. -func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(LedgerTransaction) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *LedgerTransaction is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&LedgerTransaction{}) - -// Ensure *LedgerTransaction is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&LedgerTransaction{}) - -// FromStackItem retrieves fields of LedgerTransaction from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 8 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.Hash, err = func(item stackitem.Item) (util.Uint256, error) { - b, err := item.TryBytes() - if err != nil { - return util.Uint256{}, err - } - u, err := util.Uint256DecodeBytesBE(b) - if err != nil { - return util.Uint256{}, err - } - return u, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field Hash: %w", err) - } - - index++ - res.Version, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field Version: %w", err) - } - - index++ - res.Nonce, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field Nonce: %w", err) - } - - index++ - res.Sender, err = func(item stackitem.Item) (util.Uint160, error) { - b, err := item.TryBytes() - if err != nil { - return util.Uint160{}, err - } - u, err := util.Uint160DecodeBytesBE(b) - if err != nil { - return util.Uint160{}, err - } - return u, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field Sender: %w", err) - } - - index++ - res.SysFee, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field SysFee: %w", err) - } - - index++ - res.NetFee, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field NetFee: %w", err) - } - - index++ - res.ValidUntilBlock, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field ValidUntilBlock: %w", err) - } - - index++ - res.Script, err = arr[index].TryBytes() - if err != nil { - return fmt.Errorf("field Script: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing LedgerTransaction. -// It implements [stackitem.Convertible] interface. -func (res *LedgerTransaction) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 8) - ) - itm, err = stackitem.NewByteArray(res.Hash.BytesBE()), error(nil) - if err != nil { - return nil, fmt.Errorf("field Hash: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.Version), error(nil) - if err != nil { - return nil, fmt.Errorf("field Version: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.Nonce), error(nil) - if err != nil { - return nil, fmt.Errorf("field Nonce: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.Sender.BytesBE()), error(nil) - if err != nil { - return nil, fmt.Errorf("field Sender: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.SysFee), error(nil) - if err != nil { - return nil, fmt.Errorf("field SysFee: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.NetFee), error(nil) - if err != nil { - return nil, fmt.Errorf("field NetFee: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.ValidUntilBlock), error(nil) - if err != nil { - return nil, fmt.Errorf("field ValidUntilBlock: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.Script), error(nil) - if err != nil { - return nil, fmt.Errorf("field Script: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing LedgerTransaction. -// It implements [smartcontract.Convertible] interface so that LedgerTransaction -// could be used with invokers. -func (res *LedgerTransaction) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 8) - ) - prm, err = smartcontract.NewParameterFromValue(res.Hash) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Hash: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Version) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Version: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Nonce) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Nonce: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Sender) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Sender: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.SysFee) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field SysFee: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.NetFee) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field NetFee: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.ValidUntilBlock) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field ValidUntilBlock: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Script) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Script: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToManagementABI converts stack item into *ManagementABI. -// NULL item is returned as nil pointer without error. -func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(ManagementABI) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *ManagementABI is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&ManagementABI{}) - -// Ensure *ManagementABI is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&ManagementABI{}) - -// FromStackItem retrieves fields of ManagementABI from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *ManagementABI) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 2 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.Methods, err = func(item stackitem.Item) ([]*ManagementMethod, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make([]*ManagementMethod, len(arr)) - for i := range res { - res[i], err = itemToManagementMethod(arr[i], nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - } - return res, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field Methods: %w", err) - } - - index++ - res.Events, err = func(item stackitem.Item) ([]*ManagementEvent, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make([]*ManagementEvent, len(arr)) - for i := range res { - res[i], err = itemToManagementEvent(arr[i], nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - } - return res, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field Events: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing ManagementABI. -// It implements [stackitem.Convertible] interface. -func (res *ManagementABI) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 2) - ) - itm, err = func(in []*ManagementMethod) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var items = make([]stackitem.Item, 0, len(in)) - for i, v := range in { - itm, err := v.ToStackItem() - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - items = append(items, itm) - } - return stackitem.NewArray(items), nil - }(res.Methods) - if err != nil { - return nil, fmt.Errorf("field Methods: %w", err) - } - items = append(items, itm) - - itm, err = func(in []*ManagementEvent) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var items = make([]stackitem.Item, 0, len(in)) - for i, v := range in { - itm, err := v.ToStackItem() - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - items = append(items, itm) - } - return stackitem.NewArray(items), nil - }(res.Events) - if err != nil { - return nil, fmt.Errorf("field Events: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing ManagementABI. -// It implements [smartcontract.Convertible] interface so that ManagementABI -// could be used with invokers. -func (res *ManagementABI) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 2) - ) - prm, err = func(in []*ManagementMethod) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.Parameter, 0, len(in)) - for i, v := range in { - prm, err := v.ToSCParameter() - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) - } - prms = append(prms, prm) - } - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil - }(res.Methods) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Methods: %w", err) - } - prms = append(prms, prm) - - prm, err = func(in []*ManagementEvent) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.Parameter, 0, len(in)) - for i, v := range in { - prm, err := v.ToSCParameter() - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) - } - prms = append(prms, prm) - } - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil - }(res.Events) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Events: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToManagementContract converts stack item into *ManagementContract. -// NULL item is returned as nil pointer without error. -func itemToManagementContract(item stackitem.Item, err error) (*ManagementContract, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(ManagementContract) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *ManagementContract is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&ManagementContract{}) - -// Ensure *ManagementContract is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&ManagementContract{}) - -// FromStackItem retrieves fields of ManagementContract from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *ManagementContract) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 5 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.ID, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field ID: %w", err) - } - - index++ - res.UpdateCounter, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field UpdateCounter: %w", err) - } - - index++ - res.Hash, err = func(item stackitem.Item) (util.Uint160, error) { - b, err := item.TryBytes() - if err != nil { - return util.Uint160{}, err - } - u, err := util.Uint160DecodeBytesBE(b) - if err != nil { - return util.Uint160{}, err - } - return u, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field Hash: %w", err) - } - - index++ - res.NEF, err = arr[index].TryBytes() - if err != nil { - return fmt.Errorf("field NEF: %w", err) - } - - index++ - res.Manifest, err = itemToManagementManifest(arr[index], nil) - if err != nil { - return fmt.Errorf("field Manifest: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing ManagementContract. -// It implements [stackitem.Convertible] interface. -func (res *ManagementContract) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 5) - ) - itm, err = (*stackitem.BigInteger)(res.ID), error(nil) - if err != nil { - return nil, fmt.Errorf("field ID: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.UpdateCounter), error(nil) - if err != nil { - return nil, fmt.Errorf("field UpdateCounter: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.Hash.BytesBE()), error(nil) - if err != nil { - return nil, fmt.Errorf("field Hash: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.NEF), error(nil) - if err != nil { - return nil, fmt.Errorf("field NEF: %w", err) - } - items = append(items, itm) - - itm, err = res.Manifest.ToStackItem() - if err != nil { - return nil, fmt.Errorf("field Manifest: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing ManagementContract. -// It implements [smartcontract.Convertible] interface so that ManagementContract -// could be used with invokers. -func (res *ManagementContract) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 5) - ) - prm, err = smartcontract.NewParameterFromValue(res.ID) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field ID: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.UpdateCounter) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field UpdateCounter: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Hash) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Hash: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.NEF) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field NEF: %w", err) - } - prms = append(prms, prm) - - prm, err = res.Manifest.ToSCParameter() - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Manifest: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToManagementEvent converts stack item into *ManagementEvent. -// NULL item is returned as nil pointer without error. -func itemToManagementEvent(item stackitem.Item, err error) (*ManagementEvent, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(ManagementEvent) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *ManagementEvent is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&ManagementEvent{}) - -// Ensure *ManagementEvent is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&ManagementEvent{}) - -// FromStackItem retrieves fields of ManagementEvent from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *ManagementEvent) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 2 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.Name, 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[index]) - if err != nil { - return fmt.Errorf("field Name: %w", err) - } - - index++ - res.Params, err = func(item stackitem.Item) ([]*ManagementParameter, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make([]*ManagementParameter, len(arr)) - for i := range res { - res[i], err = itemToManagementParameter(arr[i], nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - } - return res, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field Params: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing ManagementEvent. -// It implements [stackitem.Convertible] interface. -func (res *ManagementEvent) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 2) - ) - itm, err = stackitem.NewByteArray([]byte(res.Name)), error(nil) - if err != nil { - return nil, fmt.Errorf("field Name: %w", err) - } - items = append(items, itm) - - itm, err = func(in []*ManagementParameter) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var items = make([]stackitem.Item, 0, len(in)) - for i, v := range in { - itm, err := v.ToStackItem() - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - items = append(items, itm) - } - return stackitem.NewArray(items), nil - }(res.Params) - if err != nil { - return nil, fmt.Errorf("field Params: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing ManagementEvent. -// It implements [smartcontract.Convertible] interface so that ManagementEvent -// could be used with invokers. -func (res *ManagementEvent) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 2) - ) - prm, err = smartcontract.NewParameterFromValue(res.Name) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Name: %w", err) - } - prms = append(prms, prm) - - prm, err = func(in []*ManagementParameter) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.Parameter, 0, len(in)) - for i, v := range in { - prm, err := v.ToSCParameter() - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) - } - prms = append(prms, prm) - } - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil - }(res.Params) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Params: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToManagementGroup converts stack item into *ManagementGroup. -// NULL item is returned as nil pointer without error. -func itemToManagementGroup(item stackitem.Item, err error) (*ManagementGroup, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(ManagementGroup) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *ManagementGroup is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&ManagementGroup{}) - -// Ensure *ManagementGroup is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&ManagementGroup{}) - -// FromStackItem retrieves fields of ManagementGroup from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *ManagementGroup) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 2 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.PublicKey, err = func(item stackitem.Item) (*keys.PublicKey, error) { - b, err := item.TryBytes() - if err != nil { - return nil, err - } - k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256()) - if err != nil { - return nil, err - } - return k, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field PublicKey: %w", err) - } - - index++ - res.Signature, err = arr[index].TryBytes() - if err != nil { - return fmt.Errorf("field Signature: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing ManagementGroup. -// It implements [stackitem.Convertible] interface. -func (res *ManagementGroup) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 2) - ) - itm, err = stackitem.NewByteArray(res.PublicKey.Bytes()), error(nil) - if err != nil { - return nil, fmt.Errorf("field PublicKey: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.Signature), error(nil) - if err != nil { - return nil, fmt.Errorf("field Signature: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing ManagementGroup. -// It implements [smartcontract.Convertible] interface so that ManagementGroup -// could be used with invokers. -func (res *ManagementGroup) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 2) - ) - prm, err = smartcontract.NewParameterFromValue(res.PublicKey) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field PublicKey: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Signature) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Signature: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToManagementManifest converts stack item into *ManagementManifest. -// NULL item is returned as nil pointer without error. -func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManifest, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(ManagementManifest) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *ManagementManifest is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&ManagementManifest{}) - -// Ensure *ManagementManifest is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&ManagementManifest{}) - -// FromStackItem retrieves fields of ManagementManifest from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *ManagementManifest) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 8 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.Name, 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[index]) - if err != nil { - return fmt.Errorf("field Name: %w", err) - } - - index++ - res.Groups, err = func(item stackitem.Item) ([]*ManagementGroup, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make([]*ManagementGroup, len(arr)) - for i := range res { - res[i], err = itemToManagementGroup(arr[i], nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - } - return res, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field Groups: %w", err) - } - - index++ - res.Features, err = 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 - }(arr[index]) - if err != nil { - return fmt.Errorf("field Features: %w", err) - } - - index++ - res.SupportedStandards, 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[index]) - if err != nil { - return fmt.Errorf("field SupportedStandards: %w", err) - } - - index++ - res.ABI, err = itemToManagementABI(arr[index], nil) - if err != nil { - return fmt.Errorf("field ABI: %w", err) - } - - index++ - res.Permissions, err = func(item stackitem.Item) ([]*ManagementPermission, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make([]*ManagementPermission, len(arr)) - for i := range res { - res[i], err = itemToManagementPermission(arr[i], nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - } - return res, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field Permissions: %w", err) - } - - index++ - res.Trusts, 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 - }(arr[index]) - if err != nil { - return fmt.Errorf("field Trusts: %w", err) - } - - index++ - res.Extra, err = arr[index].Value(), error(nil) - if err != nil { - return fmt.Errorf("field Extra: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing ManagementManifest. -// It implements [stackitem.Convertible] interface. -func (res *ManagementManifest) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 8) - ) - itm, err = stackitem.NewByteArray([]byte(res.Name)), error(nil) - if err != nil { - return nil, fmt.Errorf("field Name: %w", err) - } - items = append(items, itm) - - itm, err = func(in []*ManagementGroup) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var items = make([]stackitem.Item, 0, len(in)) - for i, v := range in { - itm, err := v.ToStackItem() - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - items = append(items, itm) - } - return stackitem.NewArray(items), nil - }(res.Groups) - if err != nil { - return nil, fmt.Errorf("field Groups: %w", err) - } - items = append(items, itm) - - itm, err = func(in map[string]string) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var m = stackitem.NewMap() - for k, v := range in { - iKey, err := stackitem.NewByteArray([]byte(k)), error(nil) - if err != nil { - return nil, fmt.Errorf("key %v: %w", k, err) - } - iVal, err := stackitem.NewByteArray([]byte(v)), error(nil) - if err != nil { - return nil, fmt.Errorf("key %v, wrong value: %w", k, err) - } - m.Add(iKey, iVal) - } - return m, nil - }(res.Features) - if err != nil { - return nil, fmt.Errorf("field Features: %w", err) - } - items = append(items, itm) - - itm, err = func(in []string) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var items = make([]stackitem.Item, 0, len(in)) - for i, v := range in { - itm, err := stackitem.NewByteArray([]byte(v)), error(nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - items = append(items, itm) - } - return stackitem.NewArray(items), nil - }(res.SupportedStandards) - if err != nil { - return nil, fmt.Errorf("field SupportedStandards: %w", err) - } - items = append(items, itm) - - itm, err = res.ABI.ToStackItem() - if err != nil { - return nil, fmt.Errorf("field ABI: %w", err) - } - items = append(items, itm) - - itm, err = func(in []*ManagementPermission) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var items = make([]stackitem.Item, 0, len(in)) - for i, v := range in { - itm, err := v.ToStackItem() - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - items = append(items, itm) - } - return stackitem.NewArray(items), nil - }(res.Permissions) - if err != nil { - return nil, fmt.Errorf("field Permissions: %w", err) - } - items = append(items, itm) - - itm, err = func(in []util.Uint160) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var items = make([]stackitem.Item, 0, len(in)) - for i, v := range in { - itm, err := stackitem.NewByteArray(v.BytesBE()), error(nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - items = append(items, itm) - } - return stackitem.NewArray(items), nil - }(res.Trusts) - if err != nil { - return nil, fmt.Errorf("field Trusts: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.TryMake(res.Extra) - if err != nil { - return nil, fmt.Errorf("field Extra: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing ManagementManifest. -// It implements [smartcontract.Convertible] interface so that ManagementManifest -// could be used with invokers. -func (res *ManagementManifest) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 8) - ) - prm, err = smartcontract.NewParameterFromValue(res.Name) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Name: %w", err) - } - prms = append(prms, prm) - - prm, err = func(in []*ManagementGroup) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.Parameter, 0, len(in)) - for i, v := range in { - prm, err := v.ToSCParameter() - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) - } - prms = append(prms, prm) - } - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil - }(res.Groups) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Groups: %w", err) - } - prms = append(prms, prm) - - prm, err = func(in map[string]string) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.ParameterPair, 0, len(in)) - for k, v := range in { - iKey, err := smartcontract.NewParameterFromValue(k) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("key %v: %w", k, err) - } - iVal, err := smartcontract.NewParameterFromValue(v) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("key %v, wrong value: %w", k, err) - } - prms = append(prms, smartcontract.ParameterPair{Key: iKey, Value: iVal}) - } - return smartcontract.Parameter{Type: smartcontract.MapType, Value: prms}, nil - }(res.Features) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Features: %w", err) - } - prms = append(prms, prm) - - prm, err = func(in []string) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.Parameter, 0, len(in)) - for i, v := range in { - prm, err := smartcontract.NewParameterFromValue(v) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) - } - prms = append(prms, prm) - } - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil - }(res.SupportedStandards) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field SupportedStandards: %w", err) - } - prms = append(prms, prm) - - prm, err = res.ABI.ToSCParameter() - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field ABI: %w", err) - } - prms = append(prms, prm) - - prm, err = func(in []*ManagementPermission) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.Parameter, 0, len(in)) - for i, v := range in { - prm, err := v.ToSCParameter() - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) - } - prms = append(prms, prm) - } - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil - }(res.Permissions) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Permissions: %w", err) - } - prms = append(prms, prm) - - prm, err = func(in []util.Uint160) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.Parameter, 0, len(in)) - for i, v := range in { - prm, err := smartcontract.NewParameterFromValue(v) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) - } - prms = append(prms, prm) - } - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil - }(res.Trusts) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Trusts: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Extra) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Extra: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToManagementMethod converts stack item into *ManagementMethod. -// NULL item is returned as nil pointer without error. -func itemToManagementMethod(item stackitem.Item, err error) (*ManagementMethod, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(ManagementMethod) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *ManagementMethod is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&ManagementMethod{}) - -// Ensure *ManagementMethod is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&ManagementMethod{}) - -// FromStackItem retrieves fields of ManagementMethod from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *ManagementMethod) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 5 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.Name, 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[index]) - if err != nil { - return fmt.Errorf("field Name: %w", err) - } - - index++ - res.Params, err = func(item stackitem.Item) ([]*ManagementParameter, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make([]*ManagementParameter, len(arr)) - for i := range res { - res[i], err = itemToManagementParameter(arr[i], nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - } - return res, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field Params: %w", err) - } - - index++ - res.ReturnType, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field ReturnType: %w", err) - } - - index++ - res.Offset, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field Offset: %w", err) - } - - index++ - res.Safe, err = arr[index].TryBool() - if err != nil { - return fmt.Errorf("field Safe: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing ManagementMethod. -// It implements [stackitem.Convertible] interface. -func (res *ManagementMethod) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 5) - ) - itm, err = stackitem.NewByteArray([]byte(res.Name)), error(nil) - if err != nil { - return nil, fmt.Errorf("field Name: %w", err) - } - items = append(items, itm) - - itm, err = func(in []*ManagementParameter) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var items = make([]stackitem.Item, 0, len(in)) - for i, v := range in { - itm, err := v.ToStackItem() - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - items = append(items, itm) - } - return stackitem.NewArray(items), nil - }(res.Params) - if err != nil { - return nil, fmt.Errorf("field Params: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.ReturnType), error(nil) - if err != nil { - return nil, fmt.Errorf("field ReturnType: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.Offset), error(nil) - if err != nil { - return nil, fmt.Errorf("field Offset: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewBool(res.Safe), error(nil) - if err != nil { - return nil, fmt.Errorf("field Safe: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing ManagementMethod. -// It implements [smartcontract.Convertible] interface so that ManagementMethod -// could be used with invokers. -func (res *ManagementMethod) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 5) - ) - prm, err = smartcontract.NewParameterFromValue(res.Name) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Name: %w", err) - } - prms = append(prms, prm) - - prm, err = func(in []*ManagementParameter) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.Parameter, 0, len(in)) - for i, v := range in { - prm, err := v.ToSCParameter() - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) - } - prms = append(prms, prm) - } - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil - }(res.Params) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Params: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.ReturnType) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field ReturnType: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Offset) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Offset: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Safe) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Safe: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToManagementParameter converts stack item into *ManagementParameter. -// NULL item is returned as nil pointer without error. -func itemToManagementParameter(item stackitem.Item, err error) (*ManagementParameter, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(ManagementParameter) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *ManagementParameter is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&ManagementParameter{}) - -// Ensure *ManagementParameter is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&ManagementParameter{}) - -// FromStackItem retrieves fields of ManagementParameter from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *ManagementParameter) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 2 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.Name, 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[index]) - if err != nil { - return fmt.Errorf("field Name: %w", err) - } - - index++ - res.Type, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field Type: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing ManagementParameter. -// It implements [stackitem.Convertible] interface. -func (res *ManagementParameter) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 2) - ) - itm, err = stackitem.NewByteArray([]byte(res.Name)), error(nil) - if err != nil { - return nil, fmt.Errorf("field Name: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.Type), error(nil) - if err != nil { - return nil, fmt.Errorf("field Type: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing ManagementParameter. -// It implements [smartcontract.Convertible] interface so that ManagementParameter -// could be used with invokers. -func (res *ManagementParameter) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 2) - ) - prm, err = smartcontract.NewParameterFromValue(res.Name) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Name: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Type) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Type: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToManagementPermission converts stack item into *ManagementPermission. -// NULL item is returned as nil pointer without error. -func itemToManagementPermission(item stackitem.Item, err error) (*ManagementPermission, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(ManagementPermission) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *ManagementPermission is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&ManagementPermission{}) - -// Ensure *ManagementPermission is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&ManagementPermission{}) - -// FromStackItem retrieves fields of ManagementPermission from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *ManagementPermission) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 2 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.Contract, err = func(item stackitem.Item) (util.Uint160, error) { - b, err := item.TryBytes() - if err != nil { - return util.Uint160{}, err - } - u, err := util.Uint160DecodeBytesBE(b) - if err != nil { - return util.Uint160{}, err - } - return u, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field Contract: %w", err) - } - - index++ - res.Methods, 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[index]) - if err != nil { - return fmt.Errorf("field Methods: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing ManagementPermission. -// It implements [stackitem.Convertible] interface. -func (res *ManagementPermission) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 2) - ) - itm, err = stackitem.NewByteArray(res.Contract.BytesBE()), error(nil) - if err != nil { - return nil, fmt.Errorf("field Contract: %w", err) - } - items = append(items, itm) - - itm, err = func(in []string) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var items = make([]stackitem.Item, 0, len(in)) - for i, v := range in { - itm, err := stackitem.NewByteArray([]byte(v)), error(nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - items = append(items, itm) - } - return stackitem.NewArray(items), nil - }(res.Methods) - if err != nil { - return nil, fmt.Errorf("field Methods: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing ManagementPermission. -// It implements [smartcontract.Convertible] interface so that ManagementPermission -// could be used with invokers. -func (res *ManagementPermission) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 2) - ) - prm, err = smartcontract.NewParameterFromValue(res.Contract) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Contract: %w", err) - } - prms = append(prms, prm) - - prm, err = func(in []string) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.Parameter, 0, len(in)) - for i, v := range in { - prm, err := smartcontract.NewParameterFromValue(v) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) - } - prms = append(prms, prm) - } - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil - }(res.Methods) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Methods: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToStructsInternal converts stack item into *StructsInternal. -// NULL item is returned as nil pointer without error. -func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(StructsInternal) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *StructsInternal is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&StructsInternal{}) - -// Ensure *StructsInternal is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&StructsInternal{}) - -// FromStackItem retrieves fields of StructsInternal from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *StructsInternal) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 14 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.Bool, err = arr[index].TryBool() - if err != nil { - return fmt.Errorf("field Bool: %w", err) - } - - index++ - res.Int, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field Int: %w", err) - } - - index++ - res.Bytes, err = arr[index].TryBytes() - if err != nil { - return fmt.Errorf("field Bytes: %w", err) - } - - index++ - res.String, 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[index]) - if err != nil { - return fmt.Errorf("field String: %w", err) - } - - index++ - res.H160, err = func(item stackitem.Item) (util.Uint160, error) { - b, err := item.TryBytes() - if err != nil { - return util.Uint160{}, err - } - u, err := util.Uint160DecodeBytesBE(b) - if err != nil { - return util.Uint160{}, err - } - return u, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field H160: %w", err) - } - - index++ - res.H256, err = func(item stackitem.Item) (util.Uint256, error) { - b, err := item.TryBytes() - if err != nil { - return util.Uint256{}, err - } - u, err := util.Uint256DecodeBytesBE(b) - if err != nil { - return util.Uint256{}, err - } - return u, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field H256: %w", err) - } - - index++ - res.PK, err = func(item stackitem.Item) (*keys.PublicKey, error) { - b, err := item.TryBytes() - if err != nil { - return nil, err - } - k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256()) - if err != nil { - return nil, err - } - return k, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field PK: %w", err) - } - - index++ - res.PubKey, err = func(item stackitem.Item) (*keys.PublicKey, error) { - b, err := item.TryBytes() - if err != nil { - return nil, err - } - k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256()) - if err != nil { - return nil, err - } - return k, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field PubKey: %w", err) - } - - index++ - res.Sign, err = arr[index].TryBytes() - if err != nil { - return fmt.Errorf("field Sign: %w", err) - } - - index++ - res.ArrOfBytes, err = func(item stackitem.Item) ([][]byte, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make([][]byte, len(arr)) - for i := range res { - res[i], err = arr[i].TryBytes() - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - } - return res, nil - }(arr[index]) - if err != nil { - return fmt.Errorf("field ArrOfBytes: %w", err) - } - - index++ - res.ArrOfH160, 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 - }(arr[index]) - if err != nil { - return fmt.Errorf("field ArrOfH160: %w", err) - } - - index++ - res.Map, err = func(item stackitem.Item) (map[*big.Int]keys.PublicKeys, 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]keys.PublicKeys) - 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) (keys.PublicKeys, error) { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return nil, errors.New("not an array") - } - res := make(keys.PublicKeys, len(arr)) - for i := range res { - res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) { - b, err := item.TryBytes() - if err != nil { - return nil, err - } - k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256()) - if err != nil { - return nil, err - } - return k, nil - }(arr[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[index]) - if err != nil { - return fmt.Errorf("field Map: %w", err) - } - - index++ - res.Struct, err = itemToStructsInternal(arr[index], nil) - if err != nil { - return fmt.Errorf("field Struct: %w", err) - } - - index++ - res.UnexportedField, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field UnexportedField: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing StructsInternal. -// It implements [stackitem.Convertible] interface. -func (res *StructsInternal) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 14) - ) - itm, err = stackitem.NewBool(res.Bool), error(nil) - if err != nil { - return nil, fmt.Errorf("field Bool: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.Int), error(nil) - if err != nil { - return nil, fmt.Errorf("field Int: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.Bytes), error(nil) - if err != nil { - return nil, fmt.Errorf("field Bytes: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray([]byte(res.String)), error(nil) - if err != nil { - return nil, fmt.Errorf("field String: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.H160.BytesBE()), error(nil) - if err != nil { - return nil, fmt.Errorf("field H160: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.H256.BytesBE()), error(nil) - if err != nil { - return nil, fmt.Errorf("field H256: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.PK.Bytes()), error(nil) - if err != nil { - return nil, fmt.Errorf("field PK: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.PubKey.Bytes()), error(nil) - if err != nil { - return nil, fmt.Errorf("field PubKey: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewByteArray(res.Sign), error(nil) - if err != nil { - return nil, fmt.Errorf("field Sign: %w", err) - } - items = append(items, itm) - - itm, err = func(in [][]byte) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var items = make([]stackitem.Item, 0, len(in)) - for i, v := range in { - itm, err := stackitem.NewByteArray(v), error(nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - items = append(items, itm) - } - return stackitem.NewArray(items), nil - }(res.ArrOfBytes) - if err != nil { - return nil, fmt.Errorf("field ArrOfBytes: %w", err) - } - items = append(items, itm) - - itm, err = func(in []util.Uint160) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var items = make([]stackitem.Item, 0, len(in)) - for i, v := range in { - itm, err := stackitem.NewByteArray(v.BytesBE()), error(nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - items = append(items, itm) - } - return stackitem.NewArray(items), nil - }(res.ArrOfH160) - if err != nil { - return nil, fmt.Errorf("field ArrOfH160: %w", err) - } - items = append(items, itm) - - itm, err = func(in map[*big.Int]keys.PublicKeys) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var m = stackitem.NewMap() - for k, v := range in { - iKey, err := (*stackitem.BigInteger)(k), error(nil) - if err != nil { - return nil, fmt.Errorf("key %v: %w", k, err) - } - iVal, err := func(in keys.PublicKeys) (stackitem.Item, error) { - if in == nil { - return stackitem.Null{}, nil - } - - var items = make([]stackitem.Item, 0, len(in)) - for i, v := range in { - itm, err := stackitem.NewByteArray(v.Bytes()), error(nil) - if err != nil { - return nil, fmt.Errorf("item %d: %w", i, err) - } - items = append(items, itm) - } - return stackitem.NewArray(items), nil - }(v) - if err != nil { - return nil, fmt.Errorf("key %v, wrong value: %w", k, err) - } - m.Add(iKey, iVal) - } - return m, nil - }(res.Map) - if err != nil { - return nil, fmt.Errorf("field Map: %w", err) - } - items = append(items, itm) - - itm, err = res.Struct.ToStackItem() - if err != nil { - return nil, fmt.Errorf("field Struct: %w", err) - } - items = append(items, itm) - - itm, err = (*stackitem.BigInteger)(res.UnexportedField), error(nil) - if err != nil { - return nil, fmt.Errorf("field UnexportedField: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing StructsInternal. -// It implements [smartcontract.Convertible] interface so that StructsInternal -// could be used with invokers. -func (res *StructsInternal) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 14) - ) - prm, err = smartcontract.NewParameterFromValue(res.Bool) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Bool: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Int) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Int: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Bytes) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Bytes: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.String) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field String: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.H160) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field H160: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.H256) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field H256: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.PK) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field PK: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.PubKey) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field PubKey: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.Sign) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Sign: %w", err) - } - prms = append(prms, prm) - - prm, err = func(in [][]byte) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.Parameter, 0, len(in)) - for i, v := range in { - prm, err := smartcontract.NewParameterFromValue(v) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) - } - prms = append(prms, prm) - } - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil - }(res.ArrOfBytes) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field ArrOfBytes: %w", err) - } - prms = append(prms, prm) - - prm, err = func(in []util.Uint160) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.Parameter, 0, len(in)) - for i, v := range in { - prm, err := smartcontract.NewParameterFromValue(v) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) - } - prms = append(prms, prm) - } - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil - }(res.ArrOfH160) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field ArrOfH160: %w", err) - } - prms = append(prms, prm) - - prm, err = func(in map[*big.Int]keys.PublicKeys) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.ParameterPair, 0, len(in)) - for k, v := range in { - iKey, err := smartcontract.NewParameterFromValue(k) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("key %v: %w", k, err) - } - iVal, err := func(in keys.PublicKeys) (smartcontract.Parameter, error) { - if in == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var prms = make([]smartcontract.Parameter, 0, len(in)) - for i, v := range in { - prm, err := smartcontract.NewParameterFromValue(v) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) - } - prms = append(prms, prm) - } - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil - }(v) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("key %v, wrong value: %w", k, err) - } - prms = append(prms, smartcontract.ParameterPair{Key: iKey, Value: iVal}) - } - return smartcontract.Parameter{Type: smartcontract.MapType, Value: prms}, nil - }(res.Map) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Map: %w", err) - } - prms = append(prms, prm) - - prm, err = res.Struct.ToSCParameter() - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field Struct: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.UnexportedField) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field UnexportedField: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. + +// Package structs contains RPC wrappers for Types contract. +package structs + +import ( + "crypto/elliptic" + "errors" + "fmt" + "github.com/tutus-one/tutus-chain/pkg/crypto/keys" + "github.com/tutus-one/tutus-chain/pkg/neorpc/result" + "github.com/tutus-one/tutus-chain/pkg/rpcclient/unwrap" + "github.com/tutus-one/tutus-chain/pkg/smartcontract" + "github.com/tutus-one/tutus-chain/pkg/util" + "github.com/tutus-one/tutus-chain/pkg/vm/stackitem" + "math/big" + "unicode/utf8" +) + +// LedgerBlock is a contract-specific ledger.Block type used by its methods. +type LedgerBlock struct { + Hash util.Uint256 + Version *big.Int + PrevHash util.Uint256 + MerkleRoot util.Uint256 + Timestamp *big.Int + Nonce *big.Int + Index *big.Int + PrimaryIndex *big.Int + NextConsensus util.Uint160 + TransactionsLength *big.Int +} + +// LedgerTransaction is a contract-specific ledger.Transaction type used by its methods. +type LedgerTransaction struct { + Hash util.Uint256 + Version *big.Int + Nonce *big.Int + Sender util.Uint160 + SysFee *big.Int + NetFee *big.Int + ValidUntilBlock *big.Int + Script []byte +} + +// ManagementABI is a contract-specific management.ABI type used by its methods. +type ManagementABI struct { + Methods []*ManagementMethod + Events []*ManagementEvent +} + +// ManagementContract is a contract-specific management.Contract type used by its methods. +type ManagementContract struct { + ID *big.Int + UpdateCounter *big.Int + Hash util.Uint160 + NEF []byte + Manifest *ManagementManifest +} + +// ManagementEvent is a contract-specific management.Event type used by its methods. +type ManagementEvent struct { + Name string + Params []*ManagementParameter +} + +// ManagementGroup is a contract-specific management.Group type used by its methods. +type ManagementGroup struct { + PublicKey *keys.PublicKey + Signature []byte +} + +// ManagementManifest is a contract-specific management.Manifest type used by its methods. +type ManagementManifest struct { + Name string + Groups []*ManagementGroup + Features map[string]string + SupportedStandards []string + ABI *ManagementABI + Permissions []*ManagementPermission + Trusts []util.Uint160 + Extra any +} + +// ManagementMethod is a contract-specific management.Method type used by its methods. +type ManagementMethod struct { + Name string + Params []*ManagementParameter + ReturnType *big.Int + Offset *big.Int + Safe bool +} + +// ManagementParameter is a contract-specific management.Parameter type used by its methods. +type ManagementParameter struct { + Name string + Type *big.Int +} + +// ManagementPermission is a contract-specific management.Permission type used by its methods. +type ManagementPermission struct { + Contract util.Uint160 + Methods []string +} + +// StructsInternal is a contract-specific structs.Internal type used by its methods. +type StructsInternal struct { + Bool bool + Int *big.Int + Bytes []byte + String string + H160 util.Uint160 + H256 util.Uint256 + PK *keys.PublicKey + PubKey *keys.PublicKey + Sign []byte + ArrOfBytes [][]byte + ArrOfH160 []util.Uint160 + Map map[*big.Int]keys.PublicKeys + Struct *StructsInternal + UnexportedField *big.Int +} + +// Invoker is used by ContractReader to call various safe methods. +type Invoker interface { + Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) +} + +// 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} +} + +// Block invokes `block` method of contract. +func (c *ContractReader) Block(b *LedgerBlock) (*LedgerBlock, error) { + return itemToLedgerBlock(unwrap.Item(c.invoker.Call(c.hash, "block", b))) +} + +// Contract invokes `contract` method of contract. +func (c *ContractReader) Contract(mc *ManagementContract) (*ManagementContract, error) { + return itemToManagementContract(unwrap.Item(c.invoker.Call(c.hash, "contract", mc))) +} + +// Struct invokes `struct` method of contract. +func (c *ContractReader) Struct(s *StructsInternal) (*StructsInternal, error) { + return itemToStructsInternal(unwrap.Item(c.invoker.Call(c.hash, "struct", s))) +} + +// Transaction invokes `transaction` method of contract. +func (c *ContractReader) Transaction(t *LedgerTransaction) (*LedgerTransaction, error) { + return itemToLedgerTransaction(unwrap.Item(c.invoker.Call(c.hash, "transaction", t))) +} + +// itemToLedgerBlock converts stack item into *LedgerBlock. +// NULL item is returned as nil pointer without error. +func itemToLedgerBlock(item stackitem.Item, err error) (*LedgerBlock, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(LedgerBlock) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *LedgerBlock is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&LedgerBlock{}) + +// Ensure *LedgerBlock is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&LedgerBlock{}) + +// FromStackItem retrieves fields of LedgerBlock from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *LedgerBlock) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 10 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.Hash, err = func(item stackitem.Item) (util.Uint256, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint256{}, err + } + u, err := util.Uint256DecodeBytesBE(b) + if err != nil { + return util.Uint256{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Hash: %w", err) + } + + index++ + res.Version, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Version: %w", err) + } + + index++ + res.PrevHash, err = func(item stackitem.Item) (util.Uint256, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint256{}, err + } + u, err := util.Uint256DecodeBytesBE(b) + if err != nil { + return util.Uint256{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field PrevHash: %w", err) + } + + index++ + res.MerkleRoot, err = func(item stackitem.Item) (util.Uint256, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint256{}, err + } + u, err := util.Uint256DecodeBytesBE(b) + if err != nil { + return util.Uint256{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field MerkleRoot: %w", err) + } + + index++ + res.Timestamp, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Timestamp: %w", err) + } + + index++ + res.Nonce, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Nonce: %w", err) + } + + index++ + res.Index, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Index: %w", err) + } + + index++ + res.PrimaryIndex, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field PrimaryIndex: %w", err) + } + + index++ + res.NextConsensus, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field NextConsensus: %w", err) + } + + index++ + res.TransactionsLength, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field TransactionsLength: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing LedgerBlock. +// It implements [stackitem.Convertible] interface. +func (res *LedgerBlock) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 10) + ) + itm, err = stackitem.NewByteArray(res.Hash.BytesBE()), error(nil) + if err != nil { + return nil, fmt.Errorf("field Hash: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.Version), error(nil) + if err != nil { + return nil, fmt.Errorf("field Version: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.PrevHash.BytesBE()), error(nil) + if err != nil { + return nil, fmt.Errorf("field PrevHash: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.MerkleRoot.BytesBE()), error(nil) + if err != nil { + return nil, fmt.Errorf("field MerkleRoot: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.Timestamp), error(nil) + if err != nil { + return nil, fmt.Errorf("field Timestamp: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.Nonce), error(nil) + if err != nil { + return nil, fmt.Errorf("field Nonce: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.Index), error(nil) + if err != nil { + return nil, fmt.Errorf("field Index: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.PrimaryIndex), error(nil) + if err != nil { + return nil, fmt.Errorf("field PrimaryIndex: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.NextConsensus.BytesBE()), error(nil) + if err != nil { + return nil, fmt.Errorf("field NextConsensus: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.TransactionsLength), error(nil) + if err != nil { + return nil, fmt.Errorf("field TransactionsLength: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing LedgerBlock. +// It implements [smartcontract.Convertible] interface so that LedgerBlock +// could be used with invokers. +func (res *LedgerBlock) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 10) + ) + prm, err = smartcontract.NewParameterFromValue(res.Hash) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Hash: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Version) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Version: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.PrevHash) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field PrevHash: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.MerkleRoot) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field MerkleRoot: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Timestamp) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Timestamp: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Nonce) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Nonce: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Index) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Index: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.PrimaryIndex) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field PrimaryIndex: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.NextConsensus) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field NextConsensus: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.TransactionsLength) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field TransactionsLength: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToLedgerTransaction converts stack item into *LedgerTransaction. +// NULL item is returned as nil pointer without error. +func itemToLedgerTransaction(item stackitem.Item, err error) (*LedgerTransaction, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(LedgerTransaction) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *LedgerTransaction is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&LedgerTransaction{}) + +// Ensure *LedgerTransaction is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&LedgerTransaction{}) + +// FromStackItem retrieves fields of LedgerTransaction from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *LedgerTransaction) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 8 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.Hash, err = func(item stackitem.Item) (util.Uint256, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint256{}, err + } + u, err := util.Uint256DecodeBytesBE(b) + if err != nil { + return util.Uint256{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Hash: %w", err) + } + + index++ + res.Version, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Version: %w", err) + } + + index++ + res.Nonce, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Nonce: %w", err) + } + + index++ + res.Sender, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Sender: %w", err) + } + + index++ + res.SysFee, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field SysFee: %w", err) + } + + index++ + res.NetFee, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field NetFee: %w", err) + } + + index++ + res.ValidUntilBlock, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field ValidUntilBlock: %w", err) + } + + index++ + res.Script, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field Script: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing LedgerTransaction. +// It implements [stackitem.Convertible] interface. +func (res *LedgerTransaction) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 8) + ) + itm, err = stackitem.NewByteArray(res.Hash.BytesBE()), error(nil) + if err != nil { + return nil, fmt.Errorf("field Hash: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.Version), error(nil) + if err != nil { + return nil, fmt.Errorf("field Version: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.Nonce), error(nil) + if err != nil { + return nil, fmt.Errorf("field Nonce: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.Sender.BytesBE()), error(nil) + if err != nil { + return nil, fmt.Errorf("field Sender: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.SysFee), error(nil) + if err != nil { + return nil, fmt.Errorf("field SysFee: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.NetFee), error(nil) + if err != nil { + return nil, fmt.Errorf("field NetFee: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.ValidUntilBlock), error(nil) + if err != nil { + return nil, fmt.Errorf("field ValidUntilBlock: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.Script), error(nil) + if err != nil { + return nil, fmt.Errorf("field Script: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing LedgerTransaction. +// It implements [smartcontract.Convertible] interface so that LedgerTransaction +// could be used with invokers. +func (res *LedgerTransaction) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 8) + ) + prm, err = smartcontract.NewParameterFromValue(res.Hash) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Hash: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Version) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Version: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Nonce) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Nonce: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Sender) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Sender: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.SysFee) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field SysFee: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.NetFee) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field NetFee: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.ValidUntilBlock) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field ValidUntilBlock: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Script) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Script: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToManagementABI converts stack item into *ManagementABI. +// NULL item is returned as nil pointer without error. +func itemToManagementABI(item stackitem.Item, err error) (*ManagementABI, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(ManagementABI) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *ManagementABI is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&ManagementABI{}) + +// Ensure *ManagementABI is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&ManagementABI{}) + +// FromStackItem retrieves fields of ManagementABI from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *ManagementABI) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.Methods, err = func(item stackitem.Item) ([]*ManagementMethod, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([]*ManagementMethod, len(arr)) + for i := range res { + res[i], err = itemToManagementMethod(arr[i], nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + } + return res, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Methods: %w", err) + } + + index++ + res.Events, err = func(item stackitem.Item) ([]*ManagementEvent, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([]*ManagementEvent, len(arr)) + for i := range res { + res[i], err = itemToManagementEvent(arr[i], nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + } + return res, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Events: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing ManagementABI. +// It implements [stackitem.Convertible] interface. +func (res *ManagementABI) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 2) + ) + itm, err = func(in []*ManagementMethod) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var items = make([]stackitem.Item, 0, len(in)) + for i, v := range in { + itm, err := v.ToStackItem() + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + items = append(items, itm) + } + return stackitem.NewArray(items), nil + }(res.Methods) + if err != nil { + return nil, fmt.Errorf("field Methods: %w", err) + } + items = append(items, itm) + + itm, err = func(in []*ManagementEvent) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var items = make([]stackitem.Item, 0, len(in)) + for i, v := range in { + itm, err := v.ToStackItem() + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + items = append(items, itm) + } + return stackitem.NewArray(items), nil + }(res.Events) + if err != nil { + return nil, fmt.Errorf("field Events: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing ManagementABI. +// It implements [smartcontract.Convertible] interface so that ManagementABI +// could be used with invokers. +func (res *ManagementABI) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 2) + ) + prm, err = func(in []*ManagementMethod) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.Parameter, 0, len(in)) + for i, v := range in { + prm, err := v.ToSCParameter() + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) + } + prms = append(prms, prm) + } + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil + }(res.Methods) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Methods: %w", err) + } + prms = append(prms, prm) + + prm, err = func(in []*ManagementEvent) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.Parameter, 0, len(in)) + for i, v := range in { + prm, err := v.ToSCParameter() + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) + } + prms = append(prms, prm) + } + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil + }(res.Events) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Events: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToManagementContract converts stack item into *ManagementContract. +// NULL item is returned as nil pointer without error. +func itemToManagementContract(item stackitem.Item, err error) (*ManagementContract, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(ManagementContract) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *ManagementContract is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&ManagementContract{}) + +// Ensure *ManagementContract is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&ManagementContract{}) + +// FromStackItem retrieves fields of ManagementContract from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *ManagementContract) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 5 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.ID, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field ID: %w", err) + } + + index++ + res.UpdateCounter, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field UpdateCounter: %w", err) + } + + index++ + res.Hash, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Hash: %w", err) + } + + index++ + res.NEF, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field NEF: %w", err) + } + + index++ + res.Manifest, err = itemToManagementManifest(arr[index], nil) + if err != nil { + return fmt.Errorf("field Manifest: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing ManagementContract. +// It implements [stackitem.Convertible] interface. +func (res *ManagementContract) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 5) + ) + itm, err = (*stackitem.BigInteger)(res.ID), error(nil) + if err != nil { + return nil, fmt.Errorf("field ID: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.UpdateCounter), error(nil) + if err != nil { + return nil, fmt.Errorf("field UpdateCounter: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.Hash.BytesBE()), error(nil) + if err != nil { + return nil, fmt.Errorf("field Hash: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.NEF), error(nil) + if err != nil { + return nil, fmt.Errorf("field NEF: %w", err) + } + items = append(items, itm) + + itm, err = res.Manifest.ToStackItem() + if err != nil { + return nil, fmt.Errorf("field Manifest: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing ManagementContract. +// It implements [smartcontract.Convertible] interface so that ManagementContract +// could be used with invokers. +func (res *ManagementContract) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 5) + ) + prm, err = smartcontract.NewParameterFromValue(res.ID) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field ID: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.UpdateCounter) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field UpdateCounter: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Hash) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Hash: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.NEF) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field NEF: %w", err) + } + prms = append(prms, prm) + + prm, err = res.Manifest.ToSCParameter() + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Manifest: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToManagementEvent converts stack item into *ManagementEvent. +// NULL item is returned as nil pointer without error. +func itemToManagementEvent(item stackitem.Item, err error) (*ManagementEvent, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(ManagementEvent) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *ManagementEvent is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&ManagementEvent{}) + +// Ensure *ManagementEvent is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&ManagementEvent{}) + +// FromStackItem retrieves fields of ManagementEvent from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *ManagementEvent) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.Name, 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[index]) + if err != nil { + return fmt.Errorf("field Name: %w", err) + } + + index++ + res.Params, err = func(item stackitem.Item) ([]*ManagementParameter, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([]*ManagementParameter, len(arr)) + for i := range res { + res[i], err = itemToManagementParameter(arr[i], nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + } + return res, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Params: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing ManagementEvent. +// It implements [stackitem.Convertible] interface. +func (res *ManagementEvent) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 2) + ) + itm, err = stackitem.NewByteArray([]byte(res.Name)), error(nil) + if err != nil { + return nil, fmt.Errorf("field Name: %w", err) + } + items = append(items, itm) + + itm, err = func(in []*ManagementParameter) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var items = make([]stackitem.Item, 0, len(in)) + for i, v := range in { + itm, err := v.ToStackItem() + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + items = append(items, itm) + } + return stackitem.NewArray(items), nil + }(res.Params) + if err != nil { + return nil, fmt.Errorf("field Params: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing ManagementEvent. +// It implements [smartcontract.Convertible] interface so that ManagementEvent +// could be used with invokers. +func (res *ManagementEvent) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 2) + ) + prm, err = smartcontract.NewParameterFromValue(res.Name) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Name: %w", err) + } + prms = append(prms, prm) + + prm, err = func(in []*ManagementParameter) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.Parameter, 0, len(in)) + for i, v := range in { + prm, err := v.ToSCParameter() + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) + } + prms = append(prms, prm) + } + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil + }(res.Params) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Params: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToManagementGroup converts stack item into *ManagementGroup. +// NULL item is returned as nil pointer without error. +func itemToManagementGroup(item stackitem.Item, err error) (*ManagementGroup, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(ManagementGroup) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *ManagementGroup is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&ManagementGroup{}) + +// Ensure *ManagementGroup is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&ManagementGroup{}) + +// FromStackItem retrieves fields of ManagementGroup from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *ManagementGroup) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.PublicKey, err = func(item stackitem.Item) (*keys.PublicKey, error) { + b, err := item.TryBytes() + if err != nil { + return nil, err + } + k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256()) + if err != nil { + return nil, err + } + return k, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field PublicKey: %w", err) + } + + index++ + res.Signature, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field Signature: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing ManagementGroup. +// It implements [stackitem.Convertible] interface. +func (res *ManagementGroup) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 2) + ) + itm, err = stackitem.NewByteArray(res.PublicKey.Bytes()), error(nil) + if err != nil { + return nil, fmt.Errorf("field PublicKey: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.Signature), error(nil) + if err != nil { + return nil, fmt.Errorf("field Signature: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing ManagementGroup. +// It implements [smartcontract.Convertible] interface so that ManagementGroup +// could be used with invokers. +func (res *ManagementGroup) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 2) + ) + prm, err = smartcontract.NewParameterFromValue(res.PublicKey) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field PublicKey: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Signature) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Signature: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToManagementManifest converts stack item into *ManagementManifest. +// NULL item is returned as nil pointer without error. +func itemToManagementManifest(item stackitem.Item, err error) (*ManagementManifest, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(ManagementManifest) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *ManagementManifest is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&ManagementManifest{}) + +// Ensure *ManagementManifest is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&ManagementManifest{}) + +// FromStackItem retrieves fields of ManagementManifest from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *ManagementManifest) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 8 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.Name, 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[index]) + if err != nil { + return fmt.Errorf("field Name: %w", err) + } + + index++ + res.Groups, err = func(item stackitem.Item) ([]*ManagementGroup, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([]*ManagementGroup, len(arr)) + for i := range res { + res[i], err = itemToManagementGroup(arr[i], nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + } + return res, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Groups: %w", err) + } + + index++ + res.Features, err = 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 + }(arr[index]) + if err != nil { + return fmt.Errorf("field Features: %w", err) + } + + index++ + res.SupportedStandards, 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[index]) + if err != nil { + return fmt.Errorf("field SupportedStandards: %w", err) + } + + index++ + res.ABI, err = itemToManagementABI(arr[index], nil) + if err != nil { + return fmt.Errorf("field ABI: %w", err) + } + + index++ + res.Permissions, err = func(item stackitem.Item) ([]*ManagementPermission, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([]*ManagementPermission, len(arr)) + for i := range res { + res[i], err = itemToManagementPermission(arr[i], nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + } + return res, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Permissions: %w", err) + } + + index++ + res.Trusts, 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 + }(arr[index]) + if err != nil { + return fmt.Errorf("field Trusts: %w", err) + } + + index++ + res.Extra, err = arr[index].Value(), error(nil) + if err != nil { + return fmt.Errorf("field Extra: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing ManagementManifest. +// It implements [stackitem.Convertible] interface. +func (res *ManagementManifest) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 8) + ) + itm, err = stackitem.NewByteArray([]byte(res.Name)), error(nil) + if err != nil { + return nil, fmt.Errorf("field Name: %w", err) + } + items = append(items, itm) + + itm, err = func(in []*ManagementGroup) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var items = make([]stackitem.Item, 0, len(in)) + for i, v := range in { + itm, err := v.ToStackItem() + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + items = append(items, itm) + } + return stackitem.NewArray(items), nil + }(res.Groups) + if err != nil { + return nil, fmt.Errorf("field Groups: %w", err) + } + items = append(items, itm) + + itm, err = func(in map[string]string) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var m = stackitem.NewMap() + for k, v := range in { + iKey, err := stackitem.NewByteArray([]byte(k)), error(nil) + if err != nil { + return nil, fmt.Errorf("key %v: %w", k, err) + } + iVal, err := stackitem.NewByteArray([]byte(v)), error(nil) + if err != nil { + return nil, fmt.Errorf("key %v, wrong value: %w", k, err) + } + m.Add(iKey, iVal) + } + return m, nil + }(res.Features) + if err != nil { + return nil, fmt.Errorf("field Features: %w", err) + } + items = append(items, itm) + + itm, err = func(in []string) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var items = make([]stackitem.Item, 0, len(in)) + for i, v := range in { + itm, err := stackitem.NewByteArray([]byte(v)), error(nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + items = append(items, itm) + } + return stackitem.NewArray(items), nil + }(res.SupportedStandards) + if err != nil { + return nil, fmt.Errorf("field SupportedStandards: %w", err) + } + items = append(items, itm) + + itm, err = res.ABI.ToStackItem() + if err != nil { + return nil, fmt.Errorf("field ABI: %w", err) + } + items = append(items, itm) + + itm, err = func(in []*ManagementPermission) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var items = make([]stackitem.Item, 0, len(in)) + for i, v := range in { + itm, err := v.ToStackItem() + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + items = append(items, itm) + } + return stackitem.NewArray(items), nil + }(res.Permissions) + if err != nil { + return nil, fmt.Errorf("field Permissions: %w", err) + } + items = append(items, itm) + + itm, err = func(in []util.Uint160) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var items = make([]stackitem.Item, 0, len(in)) + for i, v := range in { + itm, err := stackitem.NewByteArray(v.BytesBE()), error(nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + items = append(items, itm) + } + return stackitem.NewArray(items), nil + }(res.Trusts) + if err != nil { + return nil, fmt.Errorf("field Trusts: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.TryMake(res.Extra) + if err != nil { + return nil, fmt.Errorf("field Extra: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing ManagementManifest. +// It implements [smartcontract.Convertible] interface so that ManagementManifest +// could be used with invokers. +func (res *ManagementManifest) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 8) + ) + prm, err = smartcontract.NewParameterFromValue(res.Name) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Name: %w", err) + } + prms = append(prms, prm) + + prm, err = func(in []*ManagementGroup) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.Parameter, 0, len(in)) + for i, v := range in { + prm, err := v.ToSCParameter() + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) + } + prms = append(prms, prm) + } + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil + }(res.Groups) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Groups: %w", err) + } + prms = append(prms, prm) + + prm, err = func(in map[string]string) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.ParameterPair, 0, len(in)) + for k, v := range in { + iKey, err := smartcontract.NewParameterFromValue(k) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("key %v: %w", k, err) + } + iVal, err := smartcontract.NewParameterFromValue(v) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("key %v, wrong value: %w", k, err) + } + prms = append(prms, smartcontract.ParameterPair{Key: iKey, Value: iVal}) + } + return smartcontract.Parameter{Type: smartcontract.MapType, Value: prms}, nil + }(res.Features) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Features: %w", err) + } + prms = append(prms, prm) + + prm, err = func(in []string) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.Parameter, 0, len(in)) + for i, v := range in { + prm, err := smartcontract.NewParameterFromValue(v) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) + } + prms = append(prms, prm) + } + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil + }(res.SupportedStandards) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field SupportedStandards: %w", err) + } + prms = append(prms, prm) + + prm, err = res.ABI.ToSCParameter() + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field ABI: %w", err) + } + prms = append(prms, prm) + + prm, err = func(in []*ManagementPermission) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.Parameter, 0, len(in)) + for i, v := range in { + prm, err := v.ToSCParameter() + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) + } + prms = append(prms, prm) + } + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil + }(res.Permissions) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Permissions: %w", err) + } + prms = append(prms, prm) + + prm, err = func(in []util.Uint160) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.Parameter, 0, len(in)) + for i, v := range in { + prm, err := smartcontract.NewParameterFromValue(v) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) + } + prms = append(prms, prm) + } + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil + }(res.Trusts) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Trusts: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Extra) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Extra: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToManagementMethod converts stack item into *ManagementMethod. +// NULL item is returned as nil pointer without error. +func itemToManagementMethod(item stackitem.Item, err error) (*ManagementMethod, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(ManagementMethod) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *ManagementMethod is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&ManagementMethod{}) + +// Ensure *ManagementMethod is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&ManagementMethod{}) + +// FromStackItem retrieves fields of ManagementMethod from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *ManagementMethod) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 5 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.Name, 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[index]) + if err != nil { + return fmt.Errorf("field Name: %w", err) + } + + index++ + res.Params, err = func(item stackitem.Item) ([]*ManagementParameter, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([]*ManagementParameter, len(arr)) + for i := range res { + res[i], err = itemToManagementParameter(arr[i], nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + } + return res, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Params: %w", err) + } + + index++ + res.ReturnType, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field ReturnType: %w", err) + } + + index++ + res.Offset, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Offset: %w", err) + } + + index++ + res.Safe, err = arr[index].TryBool() + if err != nil { + return fmt.Errorf("field Safe: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing ManagementMethod. +// It implements [stackitem.Convertible] interface. +func (res *ManagementMethod) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 5) + ) + itm, err = stackitem.NewByteArray([]byte(res.Name)), error(nil) + if err != nil { + return nil, fmt.Errorf("field Name: %w", err) + } + items = append(items, itm) + + itm, err = func(in []*ManagementParameter) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var items = make([]stackitem.Item, 0, len(in)) + for i, v := range in { + itm, err := v.ToStackItem() + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + items = append(items, itm) + } + return stackitem.NewArray(items), nil + }(res.Params) + if err != nil { + return nil, fmt.Errorf("field Params: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.ReturnType), error(nil) + if err != nil { + return nil, fmt.Errorf("field ReturnType: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.Offset), error(nil) + if err != nil { + return nil, fmt.Errorf("field Offset: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewBool(res.Safe), error(nil) + if err != nil { + return nil, fmt.Errorf("field Safe: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing ManagementMethod. +// It implements [smartcontract.Convertible] interface so that ManagementMethod +// could be used with invokers. +func (res *ManagementMethod) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 5) + ) + prm, err = smartcontract.NewParameterFromValue(res.Name) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Name: %w", err) + } + prms = append(prms, prm) + + prm, err = func(in []*ManagementParameter) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.Parameter, 0, len(in)) + for i, v := range in { + prm, err := v.ToSCParameter() + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) + } + prms = append(prms, prm) + } + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil + }(res.Params) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Params: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.ReturnType) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field ReturnType: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Offset) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Offset: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Safe) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Safe: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToManagementParameter converts stack item into *ManagementParameter. +// NULL item is returned as nil pointer without error. +func itemToManagementParameter(item stackitem.Item, err error) (*ManagementParameter, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(ManagementParameter) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *ManagementParameter is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&ManagementParameter{}) + +// Ensure *ManagementParameter is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&ManagementParameter{}) + +// FromStackItem retrieves fields of ManagementParameter from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *ManagementParameter) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.Name, 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[index]) + if err != nil { + return fmt.Errorf("field Name: %w", err) + } + + index++ + res.Type, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Type: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing ManagementParameter. +// It implements [stackitem.Convertible] interface. +func (res *ManagementParameter) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 2) + ) + itm, err = stackitem.NewByteArray([]byte(res.Name)), error(nil) + if err != nil { + return nil, fmt.Errorf("field Name: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.Type), error(nil) + if err != nil { + return nil, fmt.Errorf("field Type: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing ManagementParameter. +// It implements [smartcontract.Convertible] interface so that ManagementParameter +// could be used with invokers. +func (res *ManagementParameter) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 2) + ) + prm, err = smartcontract.NewParameterFromValue(res.Name) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Name: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Type) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Type: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToManagementPermission converts stack item into *ManagementPermission. +// NULL item is returned as nil pointer without error. +func itemToManagementPermission(item stackitem.Item, err error) (*ManagementPermission, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(ManagementPermission) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *ManagementPermission is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&ManagementPermission{}) + +// Ensure *ManagementPermission is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&ManagementPermission{}) + +// FromStackItem retrieves fields of ManagementPermission from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *ManagementPermission) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.Contract, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field Contract: %w", err) + } + + index++ + res.Methods, 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[index]) + if err != nil { + return fmt.Errorf("field Methods: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing ManagementPermission. +// It implements [stackitem.Convertible] interface. +func (res *ManagementPermission) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 2) + ) + itm, err = stackitem.NewByteArray(res.Contract.BytesBE()), error(nil) + if err != nil { + return nil, fmt.Errorf("field Contract: %w", err) + } + items = append(items, itm) + + itm, err = func(in []string) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var items = make([]stackitem.Item, 0, len(in)) + for i, v := range in { + itm, err := stackitem.NewByteArray([]byte(v)), error(nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + items = append(items, itm) + } + return stackitem.NewArray(items), nil + }(res.Methods) + if err != nil { + return nil, fmt.Errorf("field Methods: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing ManagementPermission. +// It implements [smartcontract.Convertible] interface so that ManagementPermission +// could be used with invokers. +func (res *ManagementPermission) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 2) + ) + prm, err = smartcontract.NewParameterFromValue(res.Contract) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Contract: %w", err) + } + prms = append(prms, prm) + + prm, err = func(in []string) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.Parameter, 0, len(in)) + for i, v := range in { + prm, err := smartcontract.NewParameterFromValue(v) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) + } + prms = append(prms, prm) + } + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil + }(res.Methods) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Methods: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToStructsInternal converts stack item into *StructsInternal. +// NULL item is returned as nil pointer without error. +func itemToStructsInternal(item stackitem.Item, err error) (*StructsInternal, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(StructsInternal) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *StructsInternal is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&StructsInternal{}) + +// Ensure *StructsInternal is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&StructsInternal{}) + +// FromStackItem retrieves fields of StructsInternal from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *StructsInternal) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 14 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.Bool, err = arr[index].TryBool() + if err != nil { + return fmt.Errorf("field Bool: %w", err) + } + + index++ + res.Int, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field Int: %w", err) + } + + index++ + res.Bytes, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field Bytes: %w", err) + } + + index++ + res.String, 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[index]) + if err != nil { + return fmt.Errorf("field String: %w", err) + } + + index++ + res.H160, err = func(item stackitem.Item) (util.Uint160, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint160{}, err + } + u, err := util.Uint160DecodeBytesBE(b) + if err != nil { + return util.Uint160{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field H160: %w", err) + } + + index++ + res.H256, err = func(item stackitem.Item) (util.Uint256, error) { + b, err := item.TryBytes() + if err != nil { + return util.Uint256{}, err + } + u, err := util.Uint256DecodeBytesBE(b) + if err != nil { + return util.Uint256{}, err + } + return u, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field H256: %w", err) + } + + index++ + res.PK, err = func(item stackitem.Item) (*keys.PublicKey, error) { + b, err := item.TryBytes() + if err != nil { + return nil, err + } + k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256()) + if err != nil { + return nil, err + } + return k, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field PK: %w", err) + } + + index++ + res.PubKey, err = func(item stackitem.Item) (*keys.PublicKey, error) { + b, err := item.TryBytes() + if err != nil { + return nil, err + } + k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256()) + if err != nil { + return nil, err + } + return k, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field PubKey: %w", err) + } + + index++ + res.Sign, err = arr[index].TryBytes() + if err != nil { + return fmt.Errorf("field Sign: %w", err) + } + + index++ + res.ArrOfBytes, err = func(item stackitem.Item) ([][]byte, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make([][]byte, len(arr)) + for i := range res { + res[i], err = arr[i].TryBytes() + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + } + return res, nil + }(arr[index]) + if err != nil { + return fmt.Errorf("field ArrOfBytes: %w", err) + } + + index++ + res.ArrOfH160, 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 + }(arr[index]) + if err != nil { + return fmt.Errorf("field ArrOfH160: %w", err) + } + + index++ + res.Map, err = func(item stackitem.Item) (map[*big.Int]keys.PublicKeys, 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]keys.PublicKeys) + 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) (keys.PublicKeys, error) { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return nil, errors.New("not an array") + } + res := make(keys.PublicKeys, len(arr)) + for i := range res { + res[i], err = func(item stackitem.Item) (*keys.PublicKey, error) { + b, err := item.TryBytes() + if err != nil { + return nil, err + } + k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256()) + if err != nil { + return nil, err + } + return k, nil + }(arr[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[index]) + if err != nil { + return fmt.Errorf("field Map: %w", err) + } + + index++ + res.Struct, err = itemToStructsInternal(arr[index], nil) + if err != nil { + return fmt.Errorf("field Struct: %w", err) + } + + index++ + res.UnexportedField, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field UnexportedField: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing StructsInternal. +// It implements [stackitem.Convertible] interface. +func (res *StructsInternal) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 14) + ) + itm, err = stackitem.NewBool(res.Bool), error(nil) + if err != nil { + return nil, fmt.Errorf("field Bool: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.Int), error(nil) + if err != nil { + return nil, fmt.Errorf("field Int: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.Bytes), error(nil) + if err != nil { + return nil, fmt.Errorf("field Bytes: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray([]byte(res.String)), error(nil) + if err != nil { + return nil, fmt.Errorf("field String: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.H160.BytesBE()), error(nil) + if err != nil { + return nil, fmt.Errorf("field H160: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.H256.BytesBE()), error(nil) + if err != nil { + return nil, fmt.Errorf("field H256: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.PK.Bytes()), error(nil) + if err != nil { + return nil, fmt.Errorf("field PK: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.PubKey.Bytes()), error(nil) + if err != nil { + return nil, fmt.Errorf("field PubKey: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewByteArray(res.Sign), error(nil) + if err != nil { + return nil, fmt.Errorf("field Sign: %w", err) + } + items = append(items, itm) + + itm, err = func(in [][]byte) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var items = make([]stackitem.Item, 0, len(in)) + for i, v := range in { + itm, err := stackitem.NewByteArray(v), error(nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + items = append(items, itm) + } + return stackitem.NewArray(items), nil + }(res.ArrOfBytes) + if err != nil { + return nil, fmt.Errorf("field ArrOfBytes: %w", err) + } + items = append(items, itm) + + itm, err = func(in []util.Uint160) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var items = make([]stackitem.Item, 0, len(in)) + for i, v := range in { + itm, err := stackitem.NewByteArray(v.BytesBE()), error(nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + items = append(items, itm) + } + return stackitem.NewArray(items), nil + }(res.ArrOfH160) + if err != nil { + return nil, fmt.Errorf("field ArrOfH160: %w", err) + } + items = append(items, itm) + + itm, err = func(in map[*big.Int]keys.PublicKeys) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var m = stackitem.NewMap() + for k, v := range in { + iKey, err := (*stackitem.BigInteger)(k), error(nil) + if err != nil { + return nil, fmt.Errorf("key %v: %w", k, err) + } + iVal, err := func(in keys.PublicKeys) (stackitem.Item, error) { + if in == nil { + return stackitem.Null{}, nil + } + + var items = make([]stackitem.Item, 0, len(in)) + for i, v := range in { + itm, err := stackitem.NewByteArray(v.Bytes()), error(nil) + if err != nil { + return nil, fmt.Errorf("item %d: %w", i, err) + } + items = append(items, itm) + } + return stackitem.NewArray(items), nil + }(v) + if err != nil { + return nil, fmt.Errorf("key %v, wrong value: %w", k, err) + } + m.Add(iKey, iVal) + } + return m, nil + }(res.Map) + if err != nil { + return nil, fmt.Errorf("field Map: %w", err) + } + items = append(items, itm) + + itm, err = res.Struct.ToStackItem() + if err != nil { + return nil, fmt.Errorf("field Struct: %w", err) + } + items = append(items, itm) + + itm, err = (*stackitem.BigInteger)(res.UnexportedField), error(nil) + if err != nil { + return nil, fmt.Errorf("field UnexportedField: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing StructsInternal. +// It implements [smartcontract.Convertible] interface so that StructsInternal +// could be used with invokers. +func (res *StructsInternal) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 14) + ) + prm, err = smartcontract.NewParameterFromValue(res.Bool) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Bool: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Int) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Int: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Bytes) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Bytes: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.String) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field String: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.H160) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field H160: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.H256) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field H256: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.PK) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field PK: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.PubKey) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field PubKey: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.Sign) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Sign: %w", err) + } + prms = append(prms, prm) + + prm, err = func(in [][]byte) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.Parameter, 0, len(in)) + for i, v := range in { + prm, err := smartcontract.NewParameterFromValue(v) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) + } + prms = append(prms, prm) + } + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil + }(res.ArrOfBytes) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field ArrOfBytes: %w", err) + } + prms = append(prms, prm) + + prm, err = func(in []util.Uint160) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.Parameter, 0, len(in)) + for i, v := range in { + prm, err := smartcontract.NewParameterFromValue(v) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) + } + prms = append(prms, prm) + } + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil + }(res.ArrOfH160) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field ArrOfH160: %w", err) + } + prms = append(prms, prm) + + prm, err = func(in map[*big.Int]keys.PublicKeys) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.ParameterPair, 0, len(in)) + for k, v := range in { + iKey, err := smartcontract.NewParameterFromValue(k) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("key %v: %w", k, err) + } + iVal, err := func(in keys.PublicKeys) (smartcontract.Parameter, error) { + if in == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var prms = make([]smartcontract.Parameter, 0, len(in)) + for i, v := range in { + prm, err := smartcontract.NewParameterFromValue(v) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("item %d: %w", i, err) + } + prms = append(prms, prm) + } + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil + }(v) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("key %v, wrong value: %w", k, err) + } + prms = append(prms, smartcontract.ParameterPair{Key: iKey, Value: iVal}) + } + return smartcontract.Parameter{Type: smartcontract.MapType, Value: prms}, nil + }(res.Map) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Map: %w", err) + } + prms = append(prms, prm) + + prm, err = res.Struct.ToSCParameter() + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field Struct: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.UnexportedField) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field UnexportedField: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} diff --git a/cli/smartcontract/rpcbindings/types/rpcbindings/dynamic_hash/rpcbindings_test.go b/cli/smartcontract/rpcbindings/types/rpcbindings/dynamic_hash/rpcbindings_test.go old mode 100755 new mode 100644 index 233a773..80261e9 --- a/cli/smartcontract/rpcbindings/types/rpcbindings/dynamic_hash/rpcbindings_test.go +++ b/cli/smartcontract/rpcbindings/types/rpcbindings/dynamic_hash/rpcbindings_test.go @@ -1,563 +1,563 @@ -// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. - -// Package types contains RPC wrappers for Types contract. -package types - -import ( - "errors" - "fmt" - "github.com/tutus-one/tutus-chain/pkg/crypto/keys" - "github.com/tutus-one/tutus-chain/pkg/neorpc/result" - "github.com/tutus-one/tutus-chain/pkg/rpcclient/unwrap" - "github.com/tutus-one/tutus-chain/pkg/smartcontract" - "github.com/tutus-one/tutus-chain/pkg/util" - "github.com/tutus-one/tutus-chain/pkg/vm/stackitem" - "math/big" - "unicode/utf8" -) - -// Unnamed is a contract-specific unnamed type used by its methods. -type Unnamed struct { - I *big.Int -} - -// UnnamedX is a contract-specific unnamedX type used by its methods. -type UnnamedX struct { - I *big.Int - B bool -} - -// 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)) -} - -// UnnamedStructs invokes `unnamedStructs` method of contract. -func (c *ContractReader) UnnamedStructs() (*Unnamed, error) { - return itemToUnnamed(unwrap.Item(c.invoker.Call(c.hash, "unnamedStructs"))) -} - -// UnnamedStructsX invokes `unnamedStructsX` method of contract. -func (c *ContractReader) UnnamedStructsX() (*UnnamedX, error) { - return itemToUnnamedX(unwrap.Item(c.invoker.Call(c.hash, "unnamedStructsX"))) -} - -// itemToUnnamed converts stack item into *Unnamed. -// NULL item is returned as nil pointer without error. -func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(Unnamed) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *Unnamed is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&Unnamed{}) - -// Ensure *Unnamed is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&Unnamed{}) - -// FromStackItem retrieves fields of Unnamed from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *Unnamed) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 1 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.I, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field I: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing Unnamed. -// It implements [stackitem.Convertible] interface. -func (res *Unnamed) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 1) - ) - itm, err = (*stackitem.BigInteger)(res.I), error(nil) - if err != nil { - return nil, fmt.Errorf("field I: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing Unnamed. -// It implements [smartcontract.Convertible] interface so that Unnamed -// could be used with invokers. -func (res *Unnamed) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 1) - ) - prm, err = smartcontract.NewParameterFromValue(res.I) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field I: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} - -// itemToUnnamedX converts stack item into *UnnamedX. -// NULL item is returned as nil pointer without error. -func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) { - if err != nil { - return nil, err - } - _, null := item.(stackitem.Null) - if null { - return nil, nil - } - var res = new(UnnamedX) - err = res.FromStackItem(item) - return res, err -} - -// Ensure *UnnamedX is a proper [stackitem.Convertible]. -var _ = stackitem.Convertible(&UnnamedX{}) - -// Ensure *UnnamedX is a proper [smartcontract.Convertible]. -var _ = smartcontract.Convertible(&UnnamedX{}) - -// FromStackItem retrieves fields of UnnamedX from the given -// [stackitem.Item] or returns an error if it's not possible to do to so. -// It implements [stackitem.Convertible] interface. -func (res *UnnamedX) FromStackItem(item stackitem.Item) error { - arr, ok := item.Value().([]stackitem.Item) - if !ok { - return errors.New("not an array") - } - if len(arr) != 2 { - return errors.New("wrong number of structure elements") - } - - var ( - index = -1 - err error - ) - index++ - res.I, err = arr[index].TryInteger() - if err != nil { - return fmt.Errorf("field I: %w", err) - } - - index++ - res.B, err = arr[index].TryBool() - if err != nil { - return fmt.Errorf("field B: %w", err) - } - - return nil -} - -// ToStackItem creates [stackitem.Item] representing UnnamedX. -// It implements [stackitem.Convertible] interface. -func (res *UnnamedX) ToStackItem() (stackitem.Item, error) { - if res == nil { - return stackitem.Null{}, nil - } - - var ( - err error - itm stackitem.Item - items = make([]stackitem.Item, 0, 2) - ) - itm, err = (*stackitem.BigInteger)(res.I), error(nil) - if err != nil { - return nil, fmt.Errorf("field I: %w", err) - } - items = append(items, itm) - - itm, err = stackitem.NewBool(res.B), error(nil) - if err != nil { - return nil, fmt.Errorf("field B: %w", err) - } - items = append(items, itm) - - return stackitem.NewStruct(items), nil -} - -// ToSCParameter creates [smartcontract.Parameter] representing UnnamedX. -// It implements [smartcontract.Convertible] interface so that UnnamedX -// could be used with invokers. -func (res *UnnamedX) ToSCParameter() (smartcontract.Parameter, error) { - if res == nil { - return smartcontract.Parameter{Type: smartcontract.AnyType}, nil - } - - var ( - err error - prm smartcontract.Parameter - prms = make([]smartcontract.Parameter, 0, 2) - ) - prm, err = smartcontract.NewParameterFromValue(res.I) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field I: %w", err) - } - prms = append(prms, prm) - - prm, err = smartcontract.NewParameterFromValue(res.B) - if err != nil { - return smartcontract.Parameter{}, fmt.Errorf("field B: %w", err) - } - prms = append(prms, prm) - - return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil -} +// Code generated by neo-go contract generate-rpcwrapper --manifest --out [--hash ] [--config ]; DO NOT EDIT. + +// Package types contains RPC wrappers for Types contract. +package types + +import ( + "errors" + "fmt" + "github.com/tutus-one/tutus-chain/pkg/crypto/keys" + "github.com/tutus-one/tutus-chain/pkg/neorpc/result" + "github.com/tutus-one/tutus-chain/pkg/rpcclient/unwrap" + "github.com/tutus-one/tutus-chain/pkg/smartcontract" + "github.com/tutus-one/tutus-chain/pkg/util" + "github.com/tutus-one/tutus-chain/pkg/vm/stackitem" + "math/big" + "unicode/utf8" +) + +// Unnamed is a contract-specific unnamed type used by its methods. +type Unnamed struct { + I *big.Int +} + +// UnnamedX is a contract-specific unnamedX type used by its methods. +type UnnamedX struct { + I *big.Int + B bool +} + +// 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)) +} + +// UnnamedStructs invokes `unnamedStructs` method of contract. +func (c *ContractReader) UnnamedStructs() (*Unnamed, error) { + return itemToUnnamed(unwrap.Item(c.invoker.Call(c.hash, "unnamedStructs"))) +} + +// UnnamedStructsX invokes `unnamedStructsX` method of contract. +func (c *ContractReader) UnnamedStructsX() (*UnnamedX, error) { + return itemToUnnamedX(unwrap.Item(c.invoker.Call(c.hash, "unnamedStructsX"))) +} + +// itemToUnnamed converts stack item into *Unnamed. +// NULL item is returned as nil pointer without error. +func itemToUnnamed(item stackitem.Item, err error) (*Unnamed, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(Unnamed) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *Unnamed is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&Unnamed{}) + +// Ensure *Unnamed is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&Unnamed{}) + +// FromStackItem retrieves fields of Unnamed from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *Unnamed) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 1 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.I, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field I: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing Unnamed. +// It implements [stackitem.Convertible] interface. +func (res *Unnamed) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 1) + ) + itm, err = (*stackitem.BigInteger)(res.I), error(nil) + if err != nil { + return nil, fmt.Errorf("field I: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing Unnamed. +// It implements [smartcontract.Convertible] interface so that Unnamed +// could be used with invokers. +func (res *Unnamed) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 1) + ) + prm, err = smartcontract.NewParameterFromValue(res.I) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field I: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} + +// itemToUnnamedX converts stack item into *UnnamedX. +// NULL item is returned as nil pointer without error. +func itemToUnnamedX(item stackitem.Item, err error) (*UnnamedX, error) { + if err != nil { + return nil, err + } + _, null := item.(stackitem.Null) + if null { + return nil, nil + } + var res = new(UnnamedX) + err = res.FromStackItem(item) + return res, err +} + +// Ensure *UnnamedX is a proper [stackitem.Convertible]. +var _ = stackitem.Convertible(&UnnamedX{}) + +// Ensure *UnnamedX is a proper [smartcontract.Convertible]. +var _ = smartcontract.Convertible(&UnnamedX{}) + +// FromStackItem retrieves fields of UnnamedX from the given +// [stackitem.Item] or returns an error if it's not possible to do to so. +// It implements [stackitem.Convertible] interface. +func (res *UnnamedX) FromStackItem(item stackitem.Item) error { + arr, ok := item.Value().([]stackitem.Item) + if !ok { + return errors.New("not an array") + } + if len(arr) != 2 { + return errors.New("wrong number of structure elements") + } + + var ( + index = -1 + err error + ) + index++ + res.I, err = arr[index].TryInteger() + if err != nil { + return fmt.Errorf("field I: %w", err) + } + + index++ + res.B, err = arr[index].TryBool() + if err != nil { + return fmt.Errorf("field B: %w", err) + } + + return nil +} + +// ToStackItem creates [stackitem.Item] representing UnnamedX. +// It implements [stackitem.Convertible] interface. +func (res *UnnamedX) ToStackItem() (stackitem.Item, error) { + if res == nil { + return stackitem.Null{}, nil + } + + var ( + err error + itm stackitem.Item + items = make([]stackitem.Item, 0, 2) + ) + itm, err = (*stackitem.BigInteger)(res.I), error(nil) + if err != nil { + return nil, fmt.Errorf("field I: %w", err) + } + items = append(items, itm) + + itm, err = stackitem.NewBool(res.B), error(nil) + if err != nil { + return nil, fmt.Errorf("field B: %w", err) + } + items = append(items, itm) + + return stackitem.NewStruct(items), nil +} + +// ToSCParameter creates [smartcontract.Parameter] representing UnnamedX. +// It implements [smartcontract.Convertible] interface so that UnnamedX +// could be used with invokers. +func (res *UnnamedX) ToSCParameter() (smartcontract.Parameter, error) { + if res == nil { + return smartcontract.Parameter{Type: smartcontract.AnyType}, nil + } + + var ( + err error + prm smartcontract.Parameter + prms = make([]smartcontract.Parameter, 0, 2) + ) + prm, err = smartcontract.NewParameterFromValue(res.I) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field I: %w", err) + } + prms = append(prms, prm) + + prm, err = smartcontract.NewParameterFromValue(res.B) + if err != nil { + return smartcontract.Parameter{}, fmt.Errorf("field B: %w", err) + } + prms = append(prms, prm) + + return smartcontract.Parameter{Type: smartcontract.ArrayType, Value: prms}, nil +} diff --git a/cli/smartcontract/testdata/deploy/update.manifest.json b/cli/smartcontract/testdata/deploy/update.manifest.json old mode 100755 new mode 100644 index 5fcf685..c792eeb --- a/cli/smartcontract/testdata/deploy/update.manifest.json +++ b/cli/smartcontract/testdata/deploy/update.manifest.json @@ -1 +1 @@ -{"name":"Test deploy","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":15,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"checkSenderWitness","offset":201,"parameters":[],"returntype":"Void","safe":false},{"name":"fail","offset":186,"parameters":[],"returntype":"Void","safe":false},{"name":"getValueUpdated","offset":294,"parameters":[],"returntype":"String","safe":false},{"name":"getValueWithKey","offset":343,"parameters":[{"name":"key","type":"String"}],"returntype":"String","safe":false},{"name":"testFind","offset":368,"parameters":[{"name":"f","type":"InteropInterface"}],"returntype":"Array","safe":false},{"name":"update","offset":238,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"0xfffdc93764dbaddd97c48f252a53ea4643faa3fd","methods":["update"]}],"supportedstandards":[],"trusts":[],"extra":null} +{"name":"Test deploy","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":15,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"checkSenderWitness","offset":201,"parameters":[],"returntype":"Void","safe":false},{"name":"fail","offset":186,"parameters":[],"returntype":"Void","safe":false},{"name":"getValueUpdated","offset":294,"parameters":[],"returntype":"String","safe":false},{"name":"getValueWithKey","offset":343,"parameters":[{"name":"key","type":"String"}],"returntype":"String","safe":false},{"name":"testFind","offset":368,"parameters":[{"name":"f","type":"InteropInterface"}],"returntype":"Array","safe":false},{"name":"update","offset":238,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"0xfffdc93764dbaddd97c48f252a53ea4643faa3fd","methods":["update"]}],"supportedstandards":[],"trusts":[],"extra":null} diff --git a/cli/smartcontract/testdata/verify.bindings.yml b/cli/smartcontract/testdata/verify.bindings.yml old mode 100755 new mode 100644 index b63bacb..46799ab --- a/cli/smartcontract/testdata/verify.bindings.yml +++ b/cli/smartcontract/testdata/verify.bindings.yml @@ -1,297 +1,297 @@ -package: testdata -hash: "0x0000000000000000000000000000000000000000" -overrides: - burnGas.gas: int - call: any - call.args: '[]any' - call.f: any - call.method: string - call.scriptHash: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 - callWithToken: any - callWithToken.args: '[]any' - callWithToken.flags: int - callWithToken.method: string - callWithToken.scriptHash: string - callWithTokenNoRet.args: '[]any' - callWithTokenNoRet.flags: int - callWithTokenNoRet.method: string - callWithTokenNoRet.scriptHash: string - checkWitness: bool - checkWitness.hashOrKey: '[]byte' - createMultisigAccount: '[]byte' - createMultisigAccount.m: int - createMultisigAccount.pubs: '[]github.com/tutus-one/tutus-chain/pkg/interop.PublicKey' - createStandardAccount: '[]byte' - createStandardAccount.pub: github.com/tutus-one/tutus-chain/pkg/interop.PublicKey - currentHash: github.com/tutus-one/tutus-chain/pkg/interop.Hash256 - currentIndex: int - currentSigners: '[]github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.TransactionSigner' - equals: bool - equals.b: any - gasLeft: int - getAddressVersion: int - getBlock: '*github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.Block' - getBlock.indexOrHash: any - getCallFlags: any - getCallingScriptHash: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 - getEntryScriptHash: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 - getExecutingScriptHash: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 - getInvocationCounter: int - getNetwork: int - getNotifications: '[][]any' - getNotifications.h: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 - getRandom: int - getScriptContainer: '*github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.Transaction' - getTime: int - getTransaction: '*github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.Transaction' - getTransaction.hash: github.com/tutus-one/tutus-chain/pkg/interop.Hash256 - getTransactionFromBlock: '*github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.Transaction' - getTransactionFromBlock.indexOrHash: any - getTransactionFromBlock.txIndex: int - getTransactionHeight: int - getTransactionHeight.hash: github.com/tutus-one/tutus-chain/pkg/interop.Hash256 - getTransactionSigners: '[]github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.TransactionSigner' - getTransactionSigners.hash: github.com/tutus-one/tutus-chain/pkg/interop.Hash256 - getTransactionVMState: int - getTransactionVMState.hash: github.com/tutus-one/tutus-chain/pkg/interop.Hash256 - getTrigger: int - loadScript: any - loadScript.args: '[]any' - loadScript.f: any - loadScript.script: '[]byte' - log.message: string - notify.args: '[]any' - notify.name: string - onNEP11Payment.amount: int - onNEP11Payment.data: any - onNEP11Payment.from: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 - onNEP11Payment.token: '[]byte' - onNEP17Payment.amount: int - onNEP17Payment.data: any - onNEP17Payment.from: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 - opcode0NoReturn.op: string - opcode1: any - opcode1NoReturn.arg: any - opcode1NoReturn.op: string - opcode1.arg: any - opcode1.op: string - opcode2: any - opcode2NoReturn.arg1: any - opcode2NoReturn.arg2: any - opcode2NoReturn.op: string - opcode2.arg1: any - opcode2.arg2: any - opcode2.op: string - opcode3: any - opcode3.arg1: any - opcode3.arg2: any - opcode3.arg3: any - opcode3.op: string - platform: '[]byte' - syscall0: any - syscall0NoReturn.name: string - syscall0.name: string - syscall1: any - syscall1NoReturn.arg: any - syscall1NoReturn.name: string - syscall1.arg: any - syscall1.name: string - syscall2: any - syscall2NoReturn.arg1: any - syscall2NoReturn.arg2: any - syscall2NoReturn.name: string - syscall2.arg1: any - syscall2.arg2: any - syscall2.name: string - syscall3: any - syscall3NoReturn.arg1: any - syscall3NoReturn.arg2: any - syscall3NoReturn.arg3: any - syscall3NoReturn.name: string - syscall3.arg1: any - syscall3.arg2: any - syscall3.arg3: any - syscall3.name: string - syscall4: any - syscall4NoReturn.arg1: any - syscall4NoReturn.arg2: any - syscall4NoReturn.arg3: any - syscall4NoReturn.arg4: any - syscall4NoReturn.name: string - syscall4.arg1: any - syscall4.arg2: any - syscall4.arg3: any - syscall4.arg4: any - syscall4.name: string - toBlockSR: '*github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.BlockSR' - verify: bool -namedtypes: - ledger.Block: - base: Array - name: ledger.Block - fields: - - field: Hash - base: Hash256 - - field: Version - base: Integer - - field: PrevHash - base: Hash256 - - field: MerkleRoot - base: Hash256 - - field: Timestamp - base: Integer - - field: Nonce - base: Integer - - field: Index - base: Integer - - field: NextConsensus - base: Hash160 - - field: TransactionsLength - base: Integer - ledger.BlockSR: - base: Array - name: ledger.BlockSR - fields: - - field: Hash - base: Hash256 - - field: Version - base: Integer - - field: PrevHash - base: Hash256 - - field: MerkleRoot - base: Hash256 - - field: Timestamp - base: Integer - - field: Nonce - base: Integer - - field: Index - base: Integer - - field: NextConsensus - base: Hash160 - - field: TransactionsLength - base: Integer - - field: PrevStateRoot - base: Hash256 - ledger.Transaction: - base: Array - name: ledger.Transaction - fields: - - field: Hash - base: Hash256 - - field: Version - base: Integer - - field: Nonce - base: Integer - - field: Sender - base: Hash160 - - field: SysFee - base: Integer - - field: NetFee - base: Integer - - field: ValidUntilBlock - base: Integer - - field: Script - base: ByteArray - ledger.TransactionSigner: - base: Array - name: ledger.TransactionSigner - fields: - - field: Account - base: Hash160 - - field: Scopes - base: Integer - - field: AllowedContracts - base: Array - value: - base: Hash160 - - field: AllowedGroups - base: Array - value: - base: PublicKey - - field: Rules - base: Array - value: - base: Array - name: ledger.WitnessRule - ledger.WitnessCondition: - base: Array - name: ledger.WitnessCondition - fields: - - field: Type - base: Integer - - field: Value - base: Any - ledger.WitnessRule: - base: Array - name: ledger.WitnessRule - fields: - - field: Action - base: Integer - - field: Condition - base: Array - name: ledger.WitnessCondition -types: - call.args: - base: Array - value: - base: Any - call.f: - base: InteropInterface - interface: iterator - callWithToken.args: - base: Array - value: - base: Any - callWithTokenNoRet.args: - base: Array - value: - base: Any - createMultisigAccount.pubs: - base: Array - value: - base: PublicKey - currentSigners: - base: Array - value: - base: Array - name: ledger.TransactionSigner - getBlock: - base: Array - name: ledger.Block - getCallFlags: - base: InteropInterface - interface: iterator - getNotifications: - base: Array - value: - base: Array - value: - base: Any - getScriptContainer: - base: Array - name: ledger.Transaction - getTransaction: - base: Array - name: ledger.Transaction - getTransactionFromBlock: - base: Array - name: ledger.Transaction - getTransactionSigners: - base: Array - value: - base: Array - name: ledger.TransactionSigner - loadScript.args: - base: Array - value: - base: Any - loadScript.f: - base: InteropInterface - interface: iterator - notify.args: - base: Array - value: - base: Any - toBlockSR: - base: Array - name: ledger.BlockSR +package: testdata +hash: "0x0000000000000000000000000000000000000000" +overrides: + burnGas.gas: int + call: any + call.args: '[]any' + call.f: any + call.method: string + call.scriptHash: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 + callWithToken: any + callWithToken.args: '[]any' + callWithToken.flags: int + callWithToken.method: string + callWithToken.scriptHash: string + callWithTokenNoRet.args: '[]any' + callWithTokenNoRet.flags: int + callWithTokenNoRet.method: string + callWithTokenNoRet.scriptHash: string + checkWitness: bool + checkWitness.hashOrKey: '[]byte' + createMultisigAccount: '[]byte' + createMultisigAccount.m: int + createMultisigAccount.pubs: '[]github.com/tutus-one/tutus-chain/pkg/interop.PublicKey' + createStandardAccount: '[]byte' + createStandardAccount.pub: github.com/tutus-one/tutus-chain/pkg/interop.PublicKey + currentHash: github.com/tutus-one/tutus-chain/pkg/interop.Hash256 + currentIndex: int + currentSigners: '[]github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.TransactionSigner' + equals: bool + equals.b: any + gasLeft: int + getAddressVersion: int + getBlock: '*github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.Block' + getBlock.indexOrHash: any + getCallFlags: any + getCallingScriptHash: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 + getEntryScriptHash: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 + getExecutingScriptHash: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 + getInvocationCounter: int + getNetwork: int + getNotifications: '[][]any' + getNotifications.h: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 + getRandom: int + getScriptContainer: '*github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.Transaction' + getTime: int + getTransaction: '*github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.Transaction' + getTransaction.hash: github.com/tutus-one/tutus-chain/pkg/interop.Hash256 + getTransactionFromBlock: '*github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.Transaction' + getTransactionFromBlock.indexOrHash: any + getTransactionFromBlock.txIndex: int + getTransactionHeight: int + getTransactionHeight.hash: github.com/tutus-one/tutus-chain/pkg/interop.Hash256 + getTransactionSigners: '[]github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.TransactionSigner' + getTransactionSigners.hash: github.com/tutus-one/tutus-chain/pkg/interop.Hash256 + getTransactionVMState: int + getTransactionVMState.hash: github.com/tutus-one/tutus-chain/pkg/interop.Hash256 + getTrigger: int + loadScript: any + loadScript.args: '[]any' + loadScript.f: any + loadScript.script: '[]byte' + log.message: string + notify.args: '[]any' + notify.name: string + onNEP11Payment.amount: int + onNEP11Payment.data: any + onNEP11Payment.from: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 + onNEP11Payment.token: '[]byte' + onNEP17Payment.amount: int + onNEP17Payment.data: any + onNEP17Payment.from: github.com/tutus-one/tutus-chain/pkg/interop.Hash160 + opcode0NoReturn.op: string + opcode1: any + opcode1NoReturn.arg: any + opcode1NoReturn.op: string + opcode1.arg: any + opcode1.op: string + opcode2: any + opcode2NoReturn.arg1: any + opcode2NoReturn.arg2: any + opcode2NoReturn.op: string + opcode2.arg1: any + opcode2.arg2: any + opcode2.op: string + opcode3: any + opcode3.arg1: any + opcode3.arg2: any + opcode3.arg3: any + opcode3.op: string + platform: '[]byte' + syscall0: any + syscall0NoReturn.name: string + syscall0.name: string + syscall1: any + syscall1NoReturn.arg: any + syscall1NoReturn.name: string + syscall1.arg: any + syscall1.name: string + syscall2: any + syscall2NoReturn.arg1: any + syscall2NoReturn.arg2: any + syscall2NoReturn.name: string + syscall2.arg1: any + syscall2.arg2: any + syscall2.name: string + syscall3: any + syscall3NoReturn.arg1: any + syscall3NoReturn.arg2: any + syscall3NoReturn.arg3: any + syscall3NoReturn.name: string + syscall3.arg1: any + syscall3.arg2: any + syscall3.arg3: any + syscall3.name: string + syscall4: any + syscall4NoReturn.arg1: any + syscall4NoReturn.arg2: any + syscall4NoReturn.arg3: any + syscall4NoReturn.arg4: any + syscall4NoReturn.name: string + syscall4.arg1: any + syscall4.arg2: any + syscall4.arg3: any + syscall4.arg4: any + syscall4.name: string + toBlockSR: '*github.com/tutus-one/tutus-chain/pkg/interop/native/ledger.BlockSR' + verify: bool +namedtypes: + ledger.Block: + base: Array + name: ledger.Block + fields: + - field: Hash + base: Hash256 + - field: Version + base: Integer + - field: PrevHash + base: Hash256 + - field: MerkleRoot + base: Hash256 + - field: Timestamp + base: Integer + - field: Nonce + base: Integer + - field: Index + base: Integer + - field: NextConsensus + base: Hash160 + - field: TransactionsLength + base: Integer + ledger.BlockSR: + base: Array + name: ledger.BlockSR + fields: + - field: Hash + base: Hash256 + - field: Version + base: Integer + - field: PrevHash + base: Hash256 + - field: MerkleRoot + base: Hash256 + - field: Timestamp + base: Integer + - field: Nonce + base: Integer + - field: Index + base: Integer + - field: NextConsensus + base: Hash160 + - field: TransactionsLength + base: Integer + - field: PrevStateRoot + base: Hash256 + ledger.Transaction: + base: Array + name: ledger.Transaction + fields: + - field: Hash + base: Hash256 + - field: Version + base: Integer + - field: Nonce + base: Integer + - field: Sender + base: Hash160 + - field: SysFee + base: Integer + - field: NetFee + base: Integer + - field: ValidUntilBlock + base: Integer + - field: Script + base: ByteArray + ledger.TransactionSigner: + base: Array + name: ledger.TransactionSigner + fields: + - field: Account + base: Hash160 + - field: Scopes + base: Integer + - field: AllowedContracts + base: Array + value: + base: Hash160 + - field: AllowedGroups + base: Array + value: + base: PublicKey + - field: Rules + base: Array + value: + base: Array + name: ledger.WitnessRule + ledger.WitnessCondition: + base: Array + name: ledger.WitnessCondition + fields: + - field: Type + base: Integer + - field: Value + base: Any + ledger.WitnessRule: + base: Array + name: ledger.WitnessRule + fields: + - field: Action + base: Integer + - field: Condition + base: Array + name: ledger.WitnessCondition +types: + call.args: + base: Array + value: + base: Any + call.f: + base: InteropInterface + interface: iterator + callWithToken.args: + base: Array + value: + base: Any + callWithTokenNoRet.args: + base: Array + value: + base: Any + createMultisigAccount.pubs: + base: Array + value: + base: PublicKey + currentSigners: + base: Array + value: + base: Array + name: ledger.TransactionSigner + getBlock: + base: Array + name: ledger.Block + getCallFlags: + base: InteropInterface + interface: iterator + getNotifications: + base: Array + value: + base: Array + value: + base: Any + getScriptContainer: + base: Array + name: ledger.Transaction + getTransaction: + base: Array + name: ledger.Transaction + getTransactionFromBlock: + base: Array + name: ledger.Transaction + getTransactionSigners: + base: Array + value: + base: Array + name: ledger.TransactionSigner + loadScript.args: + base: Array + value: + base: Any + loadScript.f: + base: InteropInterface + interface: iterator + notify.args: + base: Array + value: + base: Any + toBlockSR: + base: Array + name: ledger.BlockSR diff --git a/cli/smartcontract/testdata/verify.manifest.json b/cli/smartcontract/testdata/verify.manifest.json old mode 100755 new mode 100644 index d6363f7..2e0cbec --- a/cli/smartcontract/testdata/verify.manifest.json +++ b/cli/smartcontract/testdata/verify.manifest.json @@ -1 +1 @@ -{"name":"verify","abi":{"methods":[{"name":"verify","offset":0,"parameters":[],"returntype":"Boolean","safe":false},{"name":"onNEP17Payment","offset":5,"parameters":[{"name":"from","type":"ByteArray"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false}],"events":[{"name":"Hello world!","parameters":[{"name":"args","type":"Array"}]}]},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null,"features":{}} +{"name":"verify","abi":{"methods":[{"name":"verify","offset":0,"parameters":[],"returntype":"Boolean","safe":false},{"name":"onNEP17Payment","offset":5,"parameters":[{"name":"from","type":"ByteArray"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false}],"events":[{"name":"Hello world!","parameters":[{"name":"args","type":"Array"}]}]},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null,"features":{}} diff --git a/cli/smartcontract/testdata/verify.nef b/cli/smartcontract/testdata/verify.nef old mode 100755 new mode 100644 diff --git a/cli/smartcontract/testdata/verifyrpc/verify.manifest.json b/cli/smartcontract/testdata/verifyrpc/verify.manifest.json old mode 100755 new mode 100644 index 221dce8..e074756 --- a/cli/smartcontract/testdata/verifyrpc/verify.manifest.json +++ b/cli/smartcontract/testdata/verifyrpc/verify.manifest.json @@ -1,80 +1,80 @@ -{ - "groups" : [], - "extra" : null, - "supportedstandards" : [], - "name" : "verify", - "trusts" : [], - "features": {}, - "permissions" : [ - { - "methods" : "*", - "contract" : "*" - } - ], - "abi" : { - "methods" : [ - { - "safe" : false, - "offset" : 0, - "parameters" : [], - "name" : "verify", - "returntype" : "Boolean" - }, - { - "returntype" : "Void", - "safe" : false, - "offset" : 5, - "parameters" : [ - { - "type" : "Hash160", - "name" : "from" - }, - { - "type" : "Integer", - "name" : "amount" - }, - { - "type" : "Any", - "name" : "data" - } - ], - "name" : "onNEP17Payment" - }, - { - "returntype" : "Void", - "safe" : false, - "offset" : 5, - "parameters" : [ - { - "type" : "Hash160", - "name" : "from" - }, - { - "type" : "Integer", - "name" : "amount" - }, - { - "type" : "ByteArray", - "name" : "tokenId" - }, - { - "type" : "Any", - "name" : "data" - } - ], - "name" : "onNEP11Payment" - } - ], - "events" : [ - { - "parameters" : [ - { - "type" : "Array", - "name" : "args" - } - ], - "name" : "Hello world!" - } - ] - } -} +{ + "groups" : [], + "extra" : null, + "supportedstandards" : [], + "name" : "verify", + "trusts" : [], + "features": {}, + "permissions" : [ + { + "methods" : "*", + "contract" : "*" + } + ], + "abi" : { + "methods" : [ + { + "safe" : false, + "offset" : 0, + "parameters" : [], + "name" : "verify", + "returntype" : "Boolean" + }, + { + "returntype" : "Void", + "safe" : false, + "offset" : 5, + "parameters" : [ + { + "type" : "Hash160", + "name" : "from" + }, + { + "type" : "Integer", + "name" : "amount" + }, + { + "type" : "Any", + "name" : "data" + } + ], + "name" : "onNEP17Payment" + }, + { + "returntype" : "Void", + "safe" : false, + "offset" : 5, + "parameters" : [ + { + "type" : "Hash160", + "name" : "from" + }, + { + "type" : "Integer", + "name" : "amount" + }, + { + "type" : "ByteArray", + "name" : "tokenId" + }, + { + "type" : "Any", + "name" : "data" + } + ], + "name" : "onNEP11Payment" + } + ], + "events" : [ + { + "parameters" : [ + { + "type" : "Array", + "name" : "args" + } + ], + "name" : "Hello world!" + } + ] + } +} diff --git a/scripts/check_deps.sh b/scripts/check_deps.sh old mode 100755 new mode 100644 index 9d8b1d8..c287c12 --- a/scripts/check_deps.sh +++ b/scripts/check_deps.sh @@ -1,35 +1,35 @@ -#!/bin/sh - -die() { - echo "$*" - exit 1 -} - -find -name go.mod -print0 | - xargs -0 -n1 grep -o 'pkg/interop v\S*' | - uniq | wc -l | - xargs -I{} -n1 [ 1 -eq {} ] || - die "Different versions for dependencies in go.mod" - -INTEROP_COMMIT="$(sed -E -n -e 's/.*pkg\/interop.+-.+-(\w+)/\1/ p' go.mod)" -git merge-base --is-ancestor "$INTEROP_COMMIT" HEAD || - die "pkg/interop commit $INTEROP_COMMIT was not found in git" - -for dir in examples/*/; do - if [ -z "${dir#*zkp/}" ]; then - continue - fi - - INTEROP_COMMIT="$(sed -E -n -e 's/.*pkg\/interop.+-.+-(\w+)/\1/ p' "$dir/go.mod")" - git merge-base --is-ancestor "$INTEROP_COMMIT" HEAD || - die "$dir: pkg/interop commit $INTEROP_COMMIT was not found in git" - - if [ -z "${dir#*nft-nd-nns/}" ]; then - NEO_GO_COMMIT="$(sed -E -n -e 's/.*neo-go\s.+-.+-(\w+)/\1/ p' "$dir/go.mod")" - if [ -z "$NEO_GO_COMMIT" ]; then - NEO_GO_COMMIT="$(sed -E -n -e 's/.*neo-go\s(\w+)/\1/ p' "$dir/go.mod")" - fi - git merge-base --is-ancestor "$NEO_GO_COMMIT" HEAD || - die "$dir: neo-go commit $NEO_GO_COMMIT was not found in git" - fi -done +#!/bin/sh + +die() { + echo "$*" + exit 1 +} + +find -name go.mod -print0 | + xargs -0 -n1 grep -o 'pkg/interop v\S*' | + uniq | wc -l | + xargs -I{} -n1 [ 1 -eq {} ] || + die "Different versions for dependencies in go.mod" + +INTEROP_COMMIT="$(sed -E -n -e 's/.*pkg\/interop.+-.+-(\w+)/\1/ p' go.mod)" +git merge-base --is-ancestor "$INTEROP_COMMIT" HEAD || + die "pkg/interop commit $INTEROP_COMMIT was not found in git" + +for dir in examples/*/; do + if [ -z "${dir#*zkp/}" ]; then + continue + fi + + INTEROP_COMMIT="$(sed -E -n -e 's/.*pkg\/interop.+-.+-(\w+)/\1/ p' "$dir/go.mod")" + git merge-base --is-ancestor "$INTEROP_COMMIT" HEAD || + die "$dir: pkg/interop commit $INTEROP_COMMIT was not found in git" + + if [ -z "${dir#*nft-nd-nns/}" ]; then + NEO_GO_COMMIT="$(sed -E -n -e 's/.*neo-go\s.+-.+-(\w+)/\1/ p' "$dir/go.mod")" + if [ -z "$NEO_GO_COMMIT" ]; then + NEO_GO_COMMIT="$(sed -E -n -e 's/.*neo-go\s(\w+)/\1/ p' "$dir/go.mod")" + fi + git merge-base --is-ancestor "$NEO_GO_COMMIT" HEAD || + die "$dir: neo-go commit $NEO_GO_COMMIT was not found in git" + fi +done diff --git a/scripts/update_deps.sh b/scripts/update_deps.sh old mode 100755 new mode 100644 index 4b939af..06ac373 --- a/scripts/update_deps.sh +++ b/scripts/update_deps.sh @@ -1,29 +1,29 @@ -#!/bin/sh - -if [ -z "$1" ]; then - echo "Usage: ./update_deps.sh " - exit 1 -fi - -REV="$1" -root="$(git rev-parse --show-toplevel)" - -cd "$root" || exit 1 -go get github.com/nspcc-dev/neo-go/pkg/interop@"$REV" -go mod tidy - -for dir in "$root"/examples/*/; do - cd "$dir" || exit 1 - go get github.com/nspcc-dev/neo-go/pkg/interop@"$REV" - go mod tidy -done - -for dir in "$root"/examples/zkp/*/; do - cd "$dir" || exit 1 - go get github.com/nspcc-dev/neo-go/pkg/interop@"$REV" - go mod tidy -done - -cd "$root"/internal/contracts/oracle_contract || exit 1 -go get github.com/nspcc-dev/neo-go/pkg/interop@"$REV" -go mod tidy +#!/bin/sh + +if [ -z "$1" ]; then + echo "Usage: ./update_deps.sh " + exit 1 +fi + +REV="$1" +root="$(git rev-parse --show-toplevel)" + +cd "$root" || exit 1 +go get github.com/nspcc-dev/neo-go/pkg/interop@"$REV" +go mod tidy + +for dir in "$root"/examples/*/; do + cd "$dir" || exit 1 + go get github.com/nspcc-dev/neo-go/pkg/interop@"$REV" + go mod tidy +done + +for dir in "$root"/examples/zkp/*/; do + cd "$dir" || exit 1 + go get github.com/nspcc-dev/neo-go/pkg/interop@"$REV" + go mod tidy +done + +cd "$root"/internal/contracts/oracle_contract || exit 1 +go get github.com/nspcc-dev/neo-go/pkg/interop@"$REV" +go mod tidy