Skip to content

Commit

Permalink
Merge pull request #15 from coinbase/depend-on-bsr
Browse files Browse the repository at this point in the history
This PR modifies the code generation process to depend on BSR registries rather than depending on protos directly in the same repo. This allows us to remove the protos files from this repo and simplify the overall `buf` workflow.
  • Loading branch information
ProfMoo authored Apr 23, 2024
2 parents 19ae468 + 05475e7 commit f6a83e9
Show file tree
Hide file tree
Showing 40 changed files with 1,257 additions and 2,150 deletions.
126 changes: 126 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Options for analysis running.
run:
# Which dirs to skip: issues from them won't be reported.
# Can use regexp here: `generated.*`, regexp is applied on full path,
# including the path prefix if one is set.
# Default value is empty list,
# but default dirs are skipped independently of this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work on Windows.
skip-dirs:
- vendor
- gen

linters:
enable-all: true

# Disable specific linter
# https://golangci-lint.run/usage/linters/#disabled-by-default
disable:
- dupl
- lll
- interfacer
- exhaustivestruct
- nosnakecase
- scopelint
- ifshort
- golint
- deadcode
- varcheck
- structcheck
- maligned
- wrapcheck
- varnamelen
- funlen
- gomoddirectives
- gocognit
- testpackage
- paralleltest
- nestif
- cyclop
- maintidx
- gomnd
- gochecknoglobals
- gocritic
- godox
- forbidigo
- exhaustruct
- contextcheck
- ireturn
- goerr113
- depguard

linters-settings:
exhaustive:
# Program elements to check for exhaustiveness.
# Default: [ switch ]
check:
- switch
- map
godot:
# Comments to be checked: `declarations`, `toplevel`, or `all`.
# Default: declarations
scope: declarations
# Check that each sentence starts with a capital letter.
# Default: false
capital: true
misspell:
# Correct spellings using locale preferences for US or UK.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
# Default is to use a neutral variety of English.
locale: US
nolintlint:
# Enable to require an explanation of nonzero length after each nolint directive.
# Default: false
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed.
# Default: false
require-specific: true
predeclared:
# Include method names and field names (i.e., qualified names) in checks.
# Default: false
q: true
tagliatelle:
# Check the struct tag name case.
case:
# Use the struct field name to check the name of the struct tag.
# Default: false
use-field-name: true
# `camel` is used for `json` and `yaml`, and `header` is used for `header` (can be overridden)
# Default: {}
rules:
# Any struct tag type can be used.
# Support string case: `camel`, `pascal`, `kebab`, `snake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`, `header`
json: camel
yaml: camel
xml: camel
bson: camel
avro: snake
mapstructure: kebab
gci:
# Section configuration to compare against.
# Section names are case-insensitive and may contain parameters in ().
# The default order of sections is `standard > default > custom > blank > dot`,
# If `custom-order` is `true`, it follows the order of `sections` option.
# Default: ["standard", "default"]
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(go.mongodb.org)
- prefix(google.golang.org)
- prefix(gopkg.in)
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
# Skip generated files.
# Default: true
skip-generated: true
# Enable custom order of sections.
# If `true`, make the section order the same as the order of `sections`.
# Default: false
custom-order: true
gofumpt:
# Module path which contains the source code being formatted.
# Default: ""
module-path: github.com/coinbase/staking-client-library-go
# Choose whether to use the extra rules.
# Default: false
extra-rules: true
83 changes: 83 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#
# Tool Prerequisites Check
# This ensures that you have the necessary executables installed to run this makefile.
#

BUILD_PREREQUISITES = git go buf protoc-gen-go protoc-gen-go-grpc protoc-gen-csf protoc-gen-grpc-gateway protoc-gen-go-aip mockery
VALIDATION_PREREQUISITES = golangci-lint

#
# Informational Targets
# These rarely change, and only serve to print out helpful details about this makefile.
#

.PHONY: usage
usage:
@ echo "Usage: make [`cat Makefile | grep "^[A-z\%\-]*:" | awk '{print $$1}' | sed "s/://g" | sed "s/%/[1-3]/g" | xargs`]"

#
# Functional Targets
# These serve specific purposes for the build/release of this client.
#

.PHONY: install_prerequisites
install_prerequisites: # Install build prerequisites
@ scripts/install-go-tools.sh
@ scripts/install-go-validation-tools.sh

.PHONY: clean
clean:
@ rm -rf gen/*
@ rm -rf docs/openapi/*

.PHONY: build_deps
build_deps:
@ printf $(foreach exec,$(BUILD_PREREQUISITES), \
$(if $(shell which $(exec)),"", \
$(error "No $(exec) in PATH. Prerequisites are: $(BUILD_PREREQUISITES)")))

.PHONY: validation_deps
validation_deps:
@ printf $(foreach exec,$(VALIDATION_PREREQUISITES), \
$(if $(shell which $(exec)),"", \
$(error "No $(exec) in PATH. Prerequisites are: $(VALIDATION_PREREQUISITES)")))

.PHONY: buf_gen
buf_gen:
@ buf generate --template protos/buf.gen.orchestration.yaml buf.build/cdp/orchestration --path coinbase/staking/orchestration/v1
@ buf generate --template protos/buf.gen.rewards.yaml buf.build/cdp/rewards --path coinbase/staking/rewards/v1

# We don't need internal snippets and test files generated by gapic plugin.
# w.r.t the internal/snippets folder, gapic provides an option to supply an option to omit generating them here:
# https://github.com/googleapis/gapic-generator-go?tab=readme-ov-file#invocation
# but unfortunately, the option doesn't work and is likely to be removed, per this issue:
# https://github.com/googleapis/gapic-generator-go/issues/1332
@ rm -rf gen/client/coinbase/staking/orchestration/v1/internal
@ rm -rf gen/client/coinbase/staking/rewards/v1/internal
@ rm -rf gen/client/coinbase/staking/orchestration/v1/*test.go
@ rm -rf gen/client/coinbase/staking/rewards/v1/*test.go

.PHONY: gen
gen: install_prerequisites build_deps clean buf_gen

.PHONY: build
build:
@ go build -o bin/cosmos_list_rewards examples/cosmos/list-rewards/main.go
@ go build -o bin/ethereum/create_and_process_workflow examples/ethereum/create-and-process-workflow/main.go
@ go build -o bin/ethereum/create_workflow examples/ethereum/create-workflow/main.go
@ go build -o bin/ethereum/list_rewards examples/ethereum/list-rewards/main.go
@ go build -o bin/ethereum/list_stakes examples/ethereum/list-stakes/main.go
@ go build -o bin/example examples/hello-world/main.go
@ go build -o bin/list_workflows examples/list-workflows/main.go
@ go build -o bin/solana/solana_list_rewards examples/solana/list-rewards/main.go
@ go build -o bin/solana/solana_create_workflow examples/solana/create-workflow/main.go

.PHONY: lint
lint: validation_deps
@ printf "\nLint App\n"
@ golangci-lint run --timeout 3m ./...

.PHONY: lintfix
lintfix: validation_deps
@ printf "\nFixing Lint Issues\n"
@ golangci-lint run --timeout 3m --fix ./...
67 changes: 66 additions & 1 deletion docs/openapi/orchestration.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,39 @@
"amount"
]
},
"v1EthereumNativeStakeParameters": {
"type": "object",
"properties": {
"withdrawalAddress": {
"type": "string",
"title": "Ethereum address used to withdrawal funds"
},
"feeRecipient": {
"type": "string",
"title": "Ethereum address used to accumulate fees"
},
"amount": {
"$ref": "#/definitions/v1Amount",
"title": "Amount of ETH to stake in increments of 32"
}
},
"title": "Ethereum: Native Stake Parameters",
"required": [
"withdrawalAddress",
"feeRecipient",
"amount"
]
},
"v1EthereumStakingParameters": {
"type": "object",
"properties": {
"nativeStakeParameters": {
"$ref": "#/definitions/v1EthereumNativeStakeParameters",
"title": "Native staking parameters"
}
},
"title": "Ethereum: Staking Parameters"
},
"v1ListActionsResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1084,6 +1117,28 @@
},
"description": "A Protocol resource (e.g. ethereum_kiln, solana etc.)."
},
"v1ProvisionInfraStepOutput": {
"type": "object",
"properties": {
"state": {
"$ref": "#/definitions/v1ProvisionInfraStepOutputState",
"description": "The state of the provision infra step.",
"readOnly": true
}
},
"description": "The details for an infrastructure provision request."
},
"v1ProvisionInfraStepOutputState": {
"type": "string",
"enum": [
"STATE_UNSPECIFIED",
"STATE_IN_PROGRESS",
"STATE_COMPLETED",
"STATE_FAILED"
],
"default": "STATE_UNSPECIFIED",
"description": "State defines an enumeration of states for provisioning infra.\n\n - STATE_UNSPECIFIED: Unspecified step state.\n - STATE_IN_PROGRESS: Provision step is in-progress.\n - STATE_COMPLETED: Provision step completed.\n - STATE_FAILED: Provision step failed."
},
"v1SolanaClaimStakeParameters": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1402,6 +1457,10 @@
"$ref": "#/definitions/v1EthereumKilnStakingParameters",
"description": "EthereumKiln staking parameters."
},
"ethereumStakingParameters": {
"$ref": "#/definitions/v1EthereumStakingParameters",
"description": "Ethereum staking parameters."
},
"state": {
"$ref": "#/definitions/v1WorkflowState",
"description": "The current state of the workflow.",
Expand Down Expand Up @@ -1445,7 +1504,8 @@
"required": [
"action",
"solanaStakingParameters",
"ethereumKilnStakingParameters"
"ethereumKilnStakingParameters",
"ethereumStakingParameters"
]
},
"v1WorkflowState": {
Expand Down Expand Up @@ -1478,6 +1538,11 @@
"$ref": "#/definitions/v1WaitStepOutput",
"description": "The waiting details for any kind like how many checkpoints away for unbonding etc.",
"readOnly": true
},
"provisionInfraStepOutput": {
"$ref": "#/definitions/v1ProvisionInfraStepOutput",
"description": "The details for provisioned infrastructure.",
"readOnly": true
}
},
"description": "The information for a step in the workflow.",
Expand Down
7 changes: 7 additions & 0 deletions docs/openapi/rewards.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@
"in": "query",
"required": false,
"type": "string"
},
{
"name": "orderBy",
"description": "The order in which to sort the results.\n[AIP-132](https://google.aip.dev/132) compliant order_by field.\nThe default behavior, if not supplied, is 'evaluation_time desc'.\nExample(s):\n* 'evaluation_time desc', which returns Stakes starting with the most recent.\n* 'evaluation_time asc', which returns Stakes starting with the oldest available.\n* 'evaluation_time', which returns Stakes starting with the oldest available.",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
Expand Down
3 changes: 3 additions & 0 deletions gen/client/coinbase/staking/rewards/v1/reward_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions gen/go/coinbase/staking/orchestration/v1/action.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions gen/go/coinbase/staking/orchestration/v1/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions gen/go/coinbase/staking/orchestration/v1/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f6a83e9

Please sign in to comment.