Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile: generate RPC bindings #345

Merged
merged 5 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/config/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
issues:
exclude-rules:
- path: ./rpc
linters:
- unused # RPC bindings are allowed to contain some unused convertors.
17 changes: 15 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --config=.github/workflows/config/.golangci.yml

tests:
name: Tests
Expand All @@ -38,7 +39,7 @@ jobs:
run: go test -v ./...

build:
name: Build
name: Build contracts and RPC bindings
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -52,5 +53,17 @@ jobs:
with:
go-version: '${{ matrix.go_versions }}'

- name: Compile contracts
- name: Clear built RPC bindings
run: make mr_proper

- name: Compile contracts and build RPC bindings
run: make build

- name: Check that fresh version of RPC bindings is committed (for minimum supported Go version only)
if: ${{ matrix.go_versions == '1.18' }}
run: |
if [[ $(git diff --name-only | grep '^rpc/*' -c) != 0 ]]; then
echo "Fresh version of RPC bindings should be committed for the following contracts:";
git diff --name-only;
exit 1;
fi
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*.avm
*.nef
*.manifest.json
bindings_config.yml
config.json
/vendor/
.idea
Expand Down
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ Changelog for NeoFS Contract
## [Unreleased]

### Added
- bump minimum required go version up to 1.18
- bump minimum required go version up to 1.18 (#346)
- RPC bindings generation (#345)

### Updated

### Removed
- old unused (notary-disabled) events
- old unused (notary-disabled) events (#341)

### Fixed
- migration of non-notary network to notarized one with stale votes
- migration of non-notary network to notarized one with stale votes (#333)

### Updating from v0.17.0

Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export GOBIN ?= $(shell pwd)/bin
export CGO_ENABLED=0
NEOGO ?= $(GOBIN)/cli
VERSION ?= $(shell git describe --tags --dirty --match "v*" --always --abbrev=8 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")
NEOGOORIGMOD = github.com/nspcc-dev/neo-go
NEOGOORIGMOD = github.com/nspcc-dev/neo-go@v0.101.5-0.20230802075307-afa4530c7d73
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnnaShaleva, since that is a temporary use, do we need an issue for that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be an issue to upgrade to 0.102.0 anyway. Can be created now, doesn't matter much.

NEOGOMOD = $(shell go list -f '{{.Path}}' -m $(NEOGOORIGMOD))
NEOGOVER = $(shell go list -f '{{.Version}}' -m $(NEOGOORIGMOD) | tr -d v)

Expand All @@ -31,7 +31,9 @@ nns_sc = nns

define sc_template
$(2)$(1)/$(1)_contract.nef: $(2)$(1)/$(1)_contract.go
$(NEOGO) contract compile -i $(2)$(1) -c $(if $(2),$(2),$(1)/)config.yml -m $(2)$(1)/config.json -o $(2)$(1)/$(1)_contract.nef
$(NEOGO) contract compile -i $(2)$(1) -c $(if $(2),$(2),$(1)/)config.yml -m $(2)$(1)/config.json -o $(2)$(1)/$(1)_contract.nef --bindings $(2)$(1)/bindings_config.yml
mkdir -p rpc/$(1)
$(NEOGO) contract generate-rpcwrapper -o rpc/$(1)/rpcbinding.go -m $(2)$(1)/config.json --config $(2)$(1)/bindings_config.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, btw, should be handled by the Makefile. Makefile is not a shell script, it's all about targets, dependencies and the way they're produced.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the only question I wasn't able to fix. Could you, please, review one more time and point out how to create a proper make target depending on all these rpc/... bindings?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it for now.


$(if $(2),$(2)$(1)/$(1)_contract.go: alphabet/alphabet.go alphabet/alphabet.tpl
go run alphabet/alphabet.go
Expand All @@ -57,6 +59,8 @@ test:
clean:
find . -name '*.nef' -exec rm -rf {} \;
find . -name 'config.json' -exec rm -rf {} \;
find . -name 'bindings_config.yml' -exec rm -rf {} \;
find . -name 'rpc' -type d -prune -exec rm -rf {} \;
rm -rf ./bin/

mr_proper: clean
Expand Down
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,21 @@ Sidechain contracts:

To compile smart contracts you need:

- [neo-go](https://github.com/nspcc-dev/neo-go) >= 0.99.2
- [neo-go](https://github.com/nspcc-dev/neo-go) >= 0.102.0

## Compilation

To build and compile smart contract, run `make all` command. Compiled contracts
`*_contract.nef` and manifest `config.json` files are placed in the
corresponding directories.
corresponding directories. Generated RPC binding files `rpcbinding.go` are
placed in the corresponding `rpc` directories.

```
$ make all
/home/user/go/bin/cli contract compile -i alphabet -c alphabet/config.yml -m alphabet/config.json -o alphabet/alphabet_contract.nef
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved
/home/user/go/bin/cli contract compile -i audit -c audit/config.yml -m audit/config.json -o audit/audit_contract.nef
/home/user/go/bin/cli contract compile -i balance -c balance/config.yml -m balance/config.json -o balance/balance_contract.nef
/home/user/go/bin/cli contract compile -i container -c container/config.yml -m container/config.json -o container/container_contract.nef
/home/user/go/bin/cli contract compile -i neofsid -c neofsid/config.yml -m neofsid/config.json -o neofsid/neofsid_contract.nef
/home/user/go/bin/cli contract compile -i netmap -c netmap/config.yml -m netmap/config.json -o netmap/netmap_contract.nef
/home/user/go/bin/cli contract compile -i proxy -c proxy/config.yml -m proxy/config.json -o proxy/proxy_contract.nef
/home/user/go/bin/cli contract compile -i reputation -c reputation/config.yml -m reputation/config.json -o reputation/reputation_contract.nef
/home/user/go/bin/cli contract compile -i subnet -c subnet/config.yml -m subnet/config.json -o subnet/subnet_contract.nef
/home/user/go/bin/cli contract compile -i nns -c nns/config.yml -m nns/config.json -o nns/nns_contract.nef
/home/user/go/bin/cli contract compile -i neofs -c neofs/config.yml -m neofs/config.json -o neofs/neofs_contract.nef
/home/user/go/bin/cli contract compile -i processing -c processing/config.yml -m processing/config.json -o processing/processing_contract.nef
/home/user/go/bin/cli contract compile -i alphabet -c alphabet/config.yml -m alphabet/config.json -o alphabet/alphabet_contract.nef --bindings alphabet/bindings_config.yml
mkdir -p rpc/alphabet
/home/user/go/bin/cli contract generate-rpcwrapper -o rpc/alphabet/rpcbinding.go -m alphabet/config.json --config alphabet/bindings_config.yml
...
```

You can specify path to the `neo-go` binary with `NEOGO` environment variable:
Expand Down
12 changes: 12 additions & 0 deletions neofs/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,30 @@ events:
type: ByteArray
- name: keys
type: Array
extendedtype:
base: Array
value:
base: PublicKey
- name: Unbind
parameters:
- name: user
type: ByteArray
- name: keys
type: Array
extendedtype:
base: Array
value:
base: PublicKey
- name: AlphabetUpdate
parameters:
- name: id
type: ByteArray
- name: alphabet
type: Array
extendedtype:
base: Array
value:
base: PublicKey
- name: SetConfig
parameters:
- name: id
Expand Down
Loading
Loading