Skip to content

Commit

Permalink
v2 implementation using fabric-protos-go-apiv2
Browse files Browse the repository at this point in the history
The v2 implementation retains wire-level compatibility with Fabric but
does include the following breaking changes:

- Chaincode implementation that make direct use of fabric-protos-go will
  experience protocol buffer namespace conflicts (as described in
  https://protobuf.dev/reference/go/faq/). Any use of fabric-protos-go
  must be replaced by fabric-protos-go-apiv2.
- The Chaincode interface and Stub now use only pointers to protocol buffer
  messages in their API. Chaincode implementation must provide matching
  Init and Invoke methods.

Signed-off-by: Mark S. Lewis <[email protected]>
  • Loading branch information
bestbeforetoday committed Jun 7, 2024
1 parent 0431f70 commit 0aef6e9
Show file tree
Hide file tree
Showing 38 changed files with 7,701 additions and 19 deletions.
53 changes: 34 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,44 @@ name: fabric-chaincode-go

on:
workflow_dispatch:
workflow_call:
pull_request:
branches:
- main
- release-*

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.21.x
- uses: actions/checkout@v2
with:
fetch-depth: 1
clean: true
- name: install Tools
run: |
pushd ci/tools
go install golang.org/x/lint/golint
go install golang.org/x/tools/cmd/goimports
popd
- name: Vet and lint
run: ci/scripts/lint.sh
- name: Run tests
run: go test -race ./...
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: install Tools
working-directory: ci/tools
run: |
go install golang.org/x/lint/golint
go install golang.org/x/tools/cmd/goimports
- name: Vet and lint
run: ci/scripts/lint.sh
- name: Run tests
run: go test -race ./...

build-v2:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Generate mocks
run: make generate
- name: Staticcheck
run: make staticcheck
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
working-directory: v2
- name: Unit test
run: make unit-test
10 changes: 10 additions & 0 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Scheduled build

on:
schedule:
- cron: "42 2 * * 0"
workflow_dispatch:

jobs:
main:
uses: ./.github/workflows/build.yml
25 changes: 25 additions & 0 deletions .github/workflows/vulnerability-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "Security vulnerability scan"

on:
schedule:
- cron: "27 3 * * *"
workflow_dispatch:

jobs:
scan:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- v1
- v2
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
check-latest: true
- name: Scan
run: make scan-${{ matrix.target }}
18 changes: 18 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://golangci-lint.run/usage/configuration/

run:
timeout: 5m

linters:
disable-all: true
enable:
- errcheck
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- misspell
- typecheck
- unused
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# SPDX-License-Identifier: Apache-2.0
#

base_dir := $(patsubst %/,%,$(dir $(realpath $(lastword $(MAKEFILE_LIST)))))

v2_dir := $(base_dir)/v2

go_bin_dir := $(shell go env GOPATH)/bin

.PHONY: unit-test
unit-test:
cd '$(v2_dir)' && \
go test -timeout 10s -race -coverprofile=cover.out ./...

.PHONY: generate
generate:
go install github.com/maxbrunsfeld/counterfeiter/v6@latest
cd '$(v2_dir)' && \
go generate ./...

.PHONY: lint
lint: staticcheck golangci-lint

.PHONY: staticcheck
staticcheck:
go install honnef.co/go/tools/cmd/staticcheck@latest
cd '$(v2_dir)' && \
staticcheck -f stylish ./...

.PHONY: install-golangci-lint
install-golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b '$(go_bin_dir)'

$(go_bin_dir)/golangci-lint:
$(MAKE) install-golangci-lint

.PHONY: golangci-lint
golangci-lint: $(go_bin_dir)/golangci-lint
cd '$(v2_dir)' && \
golangci-lint run

.PHONY: scan-v2
scan-v2:
go install golang.org/x/vuln/cmd/govulncheck@latest
cd '$(v2_dir)' && \
govulncheck ./...

.PHONY: scan-v1
scan-v1:
go install golang.org/x/vuln/cmd/govulncheck@latest
cd '$(base_dir)' && \
govulncheck ./...
1 change: 1 addition & 0 deletions v2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cover.out
6 changes: 6 additions & 0 deletions v2/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright the Hyperledger Fabric contributors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

// Package chaincode contains the code necessary for chaincode to interact
// with a Hyperledger Fabric peer.
package chaincode
22 changes: 22 additions & 0 deletions v2/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module github.com/hyperledger/fabric-chaincode-go/v2

go 1.21

require (
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
34 changes: 34 additions & 0 deletions v2/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3 h1:Xpd6fzG/KjAOHJsq7EQXY2l+qi/y8muxBaY7R6QWABk=
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3/go.mod h1:2pq0ui6ZWA0cC8J+eCErgnMDCS1kPOEYVY+06ZAK0qE=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit 0aef6e9

Please sign in to comment.