Skip to content

Commit 6e50a79

Browse files
committed
protobuf refactoring
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent bfc8bf7 commit 6e50a79

342 files changed

Lines changed: 8443 additions & 4453 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.yml

Lines changed: 27 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,42 @@
11
version: "2"
22
linters:
33
enable:
4+
- asasalint # Check for pass []any as any in variadic func(...any).
45
- canonicalheader # Canonicalheader checks whether net/http.Header uses canonical header. [auto-fix]
6+
- copyloopvar # A linter detects places where loop variables are copied. [fast, auto-fix]
7+
- depguard # Go linter that checks if package imports are in a list of acceptable packages. [fast]
58
- dupword # Checks for duplicate words in the source code. [fast, auto-fix]
9+
- durationcheck # Check for two durations multiplied together.
610
- errorlint # Find code that can cause problems with the error wrapping scheme introduced in Go 1.13. [auto-fix]
711
- exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. [auto-fix]
812
- ginkgolinter # Enforces standards of using ginkgo and gomega. [auto-fix]
913
- goheader # Check if file header matches to pattern. [fast, auto-fix]
14+
- gosec # Inspects source code for security problems.
1015
- govet # Vet examines Go source code and reports suspicious constructs. It is roughly the same as 'go vet' and uses its passes. [auto-fix]
1116
- importas # Enforces consistent import aliases. [auto-fix]
17+
- intrange # Intrange is a linter to find places where for loops could make use of an integer range. [auto-fix]
18+
- loggercheck # Checks key value pairs for common logger libraries (kitlog,klog,logr,slog,zap).
1219
- mirror # Reports wrong mirror patterns of bytes/strings usage. [auto-fix]
1320
- misspell # Finds commonly misspelled English words. [fast, auto-fix]
1421
- nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). [fast, auto-fix]
22+
- nilerr # Find the code that returns nil even if it checks that the error is not nil.
23+
- nilnesserr # Reports constructs that checks for err != nil, but returns a different nil value error.
24+
- nlreturn # Checks for a new line before return and branch statements to increase code clarity. [fast, auto-fix]
1525
- nolintlint # Reports ill-formed or insufficient nolint directives. [fast, auto-fix]
26+
- perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. [auto-fix]
27+
- reassign # Checks that package variables are not reassigned.
1628
- sloglint # Ensure consistent code style when using log/slog. [auto-fix]
29+
- spancheck # Checks for mistakes with OpenTelemetry/Census spans.
1730
- staticcheck # It's the set of rules from staticcheck. [auto-fix]
31+
- tagalign # Check that struct tags are well aligned. [fast, auto-fix]
32+
- testifylint # Checks usage of github.com/stretchr/testify. [auto-fix]
33+
- thelper # Thelper detects tests helpers which do not start with the t.Helper() method.
34+
- unconvert # Remove unnecessary type conversions.
1835
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. [fast, auto-fix]
1936
- usetesting # Reports uses of functions with replacement inside the testing package. [auto-fix]
37+
- wastedassign # Finds wasted assignment statements.
2038
- whitespace # Whitespace is a linter that checks for unnecessary newlines at the start and end of functions, if, for, etc. [fast, auto-fix]
21-
- copyloopvar # A linter detects places where loop variables are copied. [fast, auto-fix]
22-
# - err113 # Check errors handling expressions. [auto-fix]
23-
# - fatcontext # Detects nested contexts in loops and function literals. [auto-fix]
24-
# - gocritic # Provides diagnostics that check for bugs, performance and style issues. [auto-fix]
25-
# - iface # Detect the incorrect use of interfaces, helping developers avoid interface pollution. [auto-fix]
26-
- intrange # Intrange is a linter to find places where for loops could make use of an integer range. [auto-fix]
27-
- nlreturn # Checks for a new line before return and branch statements to increase code clarity. [fast, auto-fix]
28-
- perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. [auto-fix]
29-
# - protogetter # Reports direct reads from proto message fields when getters should be used. [auto-fix]
30-
# - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [auto-fix]
31-
- tagalign # Check that struct tags are well aligned. [fast, auto-fix]
32-
- testifylint # Checks usage of github.com/stretchr/testify. [auto-fix]
33-
# - wsl_v5 # Add or remove empty lines. [auto-fix]
34-
# - containedctx
35-
# - contextcheck
36-
- depguard
37-
# - dupl
38-
# - errname
39-
- errorlint
40-
# - fatcontext
41-
# - forcetypeassert
42-
- ginkgolinter
43-
# - gocognit
44-
# - goconst
45-
# - gocritic
46-
# - godot
47-
- gosec
48-
# - intrange
49-
# - ireturn
50-
# - lll
51-
# - maintidx
52-
- mirror
53-
- misspell
54-
- nilerr
55-
- nilnesserr
56-
- nolintlint
57-
# - paralleltest
58-
# - prealloc
59-
# - promlinter
60-
# - revive
61-
# - rowserrcheck
62-
# - sqlclosecheck
63-
# - testifylint
64-
- thelper
65-
- unconvert
66-
# - unparam
67-
- usetesting
68-
- wastedassign
69-
- whitespace
70-
- govet
71-
# - staticcheck
72-
- canonicalheader
73-
# - copyloopvar
74-
- dupword
75-
# - err113
76-
- exptostd
77-
- goheader
78-
- importas
79-
# - intrange
80-
- nakedret
81-
- sloglint
82-
- usestdlibvars
83-
# wrapcheck is not working as expected. It is categorizing internal packages as external.
84-
#- wrapcheck
39+
- zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg`.
8540
settings:
8641
depguard:
8742
rules:
@@ -91,19 +46,13 @@ linters:
9146
desc: github.com/pkg/errors is no longer maintained
9247
errcheck:
9348
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
94-
# Such cases aren't reported by default.
95-
# Default: false
9649
check-type-assertions: false
9750
errorlint:
9851
# Check whether fmt.Errorf uses the %w verb for formatting errors.
99-
# See the https://github.com/polyfloyd/go-errorlint for caveats.
100-
# Default: true
10152
errorf: true
10253
# Check for plain type assertions and type switches.
103-
# Default: true
10454
asserts: false
10555
# Check for plain error comparisons.
106-
# Default: true
10756
comparison: true
10857
fatcontext:
10958
check-struct-pointers: true
@@ -118,7 +67,6 @@ linters:
11867
disable:
11968
- fieldalignment
12069
# Enable all analyzers.
121-
# Default: false
12270
enable-all: false
12371
iface:
12472
enable:
@@ -141,8 +89,6 @@ linters:
14189
- github.com/prometheus/client_golang/prometheus.Histogram
14290
lll:
14391
# Max line length, lines longer will be reported.
144-
# '\t' is counted as 1 character by default, and can be changed with the tab-width option.
145-
# Default: 120.
14692
line-length: 240
14793
maintidx:
14894
under: 20
@@ -191,18 +137,11 @@ linters:
191137
- github.com/jackc/pgx/v4
192138
wrapcheck:
193139
# An array of strings specifying additional substrings of signatures to ignore.
194-
# Unlike 'ignoreSigs', this option extends the default set (or the set specified in 'ignoreSigs') without replacing it entirely.
195-
# This allows you to add specific signatures to the ignore list
196-
# while retaining the defaults or any items in 'ignoreSigs'.
197-
# Default: []
198140
extra-ignore-sigs:
199141
- .CustomError(
200142
- .SpecificWrap(
201143

202144
# An array of strings that specify substrings of signatures to ignore.
203-
# If this set, it will override the default set of ignored signatures.
204-
# See https://github.com/tomarrell/wrapcheck#configuration for more information.
205-
# Default: [".Errorf(", "errors.New(", "errors.Unwrap(", "errors.Join(", ".Wrap(", ".Wrapf(", ".WithMessage(", ".WithMessagef(", ".WithStack("]
206145
ignore-sigs:
207146
- errors.New(
208147
- errors.Newf(
@@ -211,36 +150,15 @@ linters:
211150
- .Wrap(
212151
- .Wrapf(
213152
- status.Error(
214-
- .Wait() # The error reported by errorgroup.Wait() (external) actually
215-
# originates from the internal code.
153+
- .Wait() # The error reported by errorgroup.Wait() (external) actually originates from the internal code.
216154
# An array of strings that specify regular expressions of signatures to ignore.
217-
# Default: []
218155
ignore-sig-regexps:
219156
- \.New.*Error\(
220-
# An array of strings that specify globs of packages to ignore.
221-
# Default: []
222-
ignore-package-globs:
223-
- github.ibm.com/decentralized-trust-research/scalable-committer/utils/grpcerror
224-
# An array of strings that specify regular expressions of interfaces to ignore.
225-
# Default: []
226-
# ignoreInterfaceRegexps:
227-
# - ^(?i)c(?-i)ach(ing|e)
228157
exclusions:
229-
# Mode of the generated files analysis.
230-
#
231-
# - `strict`: sources are excluded by strictly following the Go generated file convention.
232-
# Source files that have lines matching only the following regular expression will be excluded: `^// Code generated .* DO NOT EDIT\.$`
233-
# This line must appear before the first non-comment, non-blank text in the file.
234-
# https://go.dev/s/generatedcode
235-
# - `lax`: sources are excluded if they contain lines like `autogenerated file`, `code generated`, `do not edit`, etc.
236-
# - `disable`: disable the generated files exclusion.
237-
#
238-
# Default: lax
239-
generated: lax
240-
# Log a warning if an exclusion rule is unused.
241-
# Default: false
242-
warn-unused: true
243-
# Predefined exclusion rules.
244-
# Default: []
245-
presets:
246-
- common-false-positives
158+
# Mode of the generated files analysis.
159+
generated: lax
160+
# Log a warning if an exclusion rule is unused.
161+
warn-unused: true
162+
# Predefined exclusion rules.
163+
presets:
164+
- common-false-positives

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,15 @@ docs-serve:
257257
.PHONY: docs-build
258258
# Build the static documentation site for production
259259
docs-build:
260-
mkdocs build --strict
260+
mkdocs build --strict
261+
262+
.PHONY: protos-format
263+
protos-format: ## Run buf format to fix protobuf files
264+
@echo "Fixing protobuf formatting..."
265+
@buf format -w
266+
267+
.PHONY: protos
268+
# generate protobuf files
269+
protos:
270+
@echo "Generating protobuf files..."
271+
@buf generate

buf.gen.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: v2
2+
plugins:
3+
- local: protoc-gen-go
4+
out: .
5+
opt:
6+
- module=github.com/hyperledger-labs/fabric-token-sdk

buf.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: v2
2+
modules:
3+
- path: token/core/fabtoken/protos/v1
4+
- path: token/core/zkatdlog/nogh/protos/v1
5+
- path: token/driver/protos/v1
6+
- path: token/services/identity/x509/crypto/protos/v1
7+
- path: token/services/identity/idemix/crypto/protos
8+
lint:
9+
use:
10+
- STANDARD
11+
- PACKAGE_DIRECTORY_MATCH
12+
- PACKAGE_VERSION_SUFFIX
13+
- FIELD_LOWER_SNAKE_CASE
14+
- ENUM_ZERO_VALUE_SUFFIX
15+
- ENUM_VALUE_PREFIX
16+
- COMMENTS # Enforce documentation standards
17+
except:
18+
- PACKAGE_DIRECTORY_MATCH
19+
- PACKAGE_SAME_GO_PACKAGE
20+
ignore:
21+
- token/services/identity/idemix/crypto/protos/idemix_config.proto
22+
breaking:
23+
use:
24+
- FILE

checks.mk

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
.PHONY: checks
2-
checks: licensecheck gofmt goimports govet misspell ineffassign staticcheck
2+
checks: licensecheck gofmt goimports govet misspell ineffassign staticcheck protos-lint buf-format
33

44
.PHONY: licensecheck
55
licensecheck:
66
@echo Running license check
7-
@find . -path './.git' -prune -o -name '*.go' -print | xargs addlicense -check || (echo "Missing license headers"; exit 1)
7+
@find . -path './.git' -prune -o -name '*.go' -not -name '*.pb.go' -print | xargs addlicense -check || (echo "Missing license headers"; exit 1)
88

99
.PHONY: gofmt
1010
gofmt:
1111
@echo Running gofmt
1212
@{ \
13-
OUTPUT="$$(find . -path './.git' -prune -o -name '*.go' -print | xargs gofmt -l -s || true)"; \
13+
OUTPUT="$$(find . -path './.git' -prune -o -name '*.go' -not -name '*.pb.go' -print | xargs gofmt -l -s || true)"; \
1414
if [ -n "$$OUTPUT" ]; then \
1515
echo "The following gofmt issues were flagged:"; \
1616
echo "$$OUTPUT"; \
@@ -23,7 +23,7 @@ gofmt:
2323
goimports:
2424
@echo Running goimports
2525
@{ \
26-
OUTPUT="$$(find . -path './.git' -prune -o -name '*.go' -print | xargs goimports -l || true)"; \
26+
OUTPUT="$$(find . -path './.git' -prune -o -name '*.go' -not -name '*.pb.go' -print | xargs goimports -l || true)"; \
2727
if [ -n "$$OUTPUT" ]; then \
2828
echo "The following files contain goimports errors"; \
2929
echo "$$OUTPUT"; \
@@ -71,6 +71,12 @@ ineffassign:
7171
@echo Running ineffassign
7272
@ineffassign $(shell go list -f '{{.Dir}}' ./...)
7373

74+
.PHONY: protos-lint
75+
protos-lint:
76+
@echo "Linting protobuf files..."
77+
@buf lint
7478

75-
76-
79+
.PHONY: buf-format
80+
buf-format:
81+
@echo "Checking protobuf formatting..."
82+
@buf format -d --exit-code

cmd/tokengen/cobra/pp/fabtokenv1/gen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var (
3333
// Auditors is the list of auditor MSP directories containing the corresponding auditor certificate.
3434
Auditors []string
3535
// Version allows the caller of tokengen to override the version number put in the public parameters.
36-
Version uint
36+
Version uint32
3737
// Extras allows the caller to add extra parameters to the public parameters.
3838
Extras []string
3939
)
@@ -46,7 +46,7 @@ func Cmd() *cobra.Command {
4646
flags.BoolVarP(&GenerateCCPackage, "cc", "", false, "generate chaincode package")
4747
flags.StringSliceVarP(&Auditors, "auditors", "a", nil, "list of auditor MSP directories containing the corresponding auditor certificate")
4848
flags.StringSliceVarP(&Issuers, "issuers", "s", nil, "list of issuer MSP directories containing the corresponding issuer certificate")
49-
flags.UintVarP(&Version, "version", "v", 0, "allows the caller of tokengen to override the version number put in the public params")
49+
flags.Uint32VarP(&Version, "version", "v", 0, "allows the caller of tokengen to override the version number put in the public params")
5050
flags.StringArrayVarP(&Extras, "extra", "x", []string{}, "extra data in key=value format, where value is the path to a file containing the data to load and store in the key")
5151

5252
return cobraCommand

cmd/tokengen/cobra/pp/zkatdlognoghv1/gen.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type GeneratorArgs struct {
3939
// Aries is a flag to indicate that aries should be used as backend for idemix
4040
Aries bool
4141
// Version allows the caller of tokengen to override the version number put in the public params
42-
Version uint
42+
Version uint32
4343
}
4444

4545
var (
@@ -59,7 +59,7 @@ var (
5959
// Aries is a flag to indicate that aries should be used as backend for idemix
6060
Aries bool
6161
// Version allows the caller of tokengen to override the version number put in the public params
62-
Version uint
62+
Version uint32
6363
// Extras allows the caller to add extra parameters to the public parameters
6464
Extras []string
6565
)
@@ -75,7 +75,7 @@ func Cmd() *cobra.Command {
7575
flags.StringVarP(&IdemixMSPDir, "idemix", "i", "", "idemix msp dir")
7676
flags.Uint64VarP(&BitLength, "bits", "b", 64, "bits is used to define the maximum quantity a token can contain")
7777
flags.BoolVarP(&Aries, "aries", "r", false, "flag to indicate that aries should be used as backend for idemix")
78-
flags.UintVarP(&Version, "version", "v", 0, "allows the caller of tokengen to override the version number put in the public params")
78+
flags.Uint32VarP(&Version, "version", "v", 0, "allows the caller of tokengen to override the version number put in the public params")
7979
flags.StringArrayVarP(&Extras, "extra", "x", []string{}, "extra data in key=value format, where value is the path to a file containing the data to load and store in the key")
8080

8181
return cobraCommand

cmd/tokengen/cobra/pp/zkatdlognoghv1/update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type UpdateArgs struct {
3333
// Auditors is the list of auditor MSP directories containing the corresponding auditor certificate
3434
Auditors []string
3535
// Version allows the caller of tokengen to override the version number put in the public params
36-
Version uint
36+
Version uint32
3737
}
3838

3939
// UpdateCmd returns the Cobra Command for updating public parameters.
@@ -44,7 +44,7 @@ func UpdateCmd() *cobra.Command {
4444
flags.StringVarP(&OutputDir, "output", "o", ".", "output folder")
4545
flags.StringSliceVarP(&Auditors, "auditors", "a", nil, "list of auditor MSP directories containing the corresponding auditor certificate")
4646
flags.StringSliceVarP(&Issuers, "issuers", "s", nil, "list of issuer MSP directories containing the corresponding issuer certificate")
47-
flags.UintVarP(&Version, "version", "v", 0, "allows the caller of tokengen to override the version number put in the public params")
47+
flags.Uint32VarP(&Version, "version", "v", 0, "allows the caller of tokengen to override the version number put in the public params")
4848
flags.StringArrayVarP(&Extras, "extra", "x", []string{}, "extra data in key=value format, where is the path to a file containing the data to load and store in the key")
4949

5050
return cmd

0 commit comments

Comments
 (0)