diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8af0d42 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# Top-most EditorConfig file +root = true + +# Unix-style line endings +[*] +end_of_line = lf +trim_trailing_whitespace = true + +# Indentation settings +[*.{sh,yaml,json}] +indent_style = space +indent_size = 2 + +# Trim trailing whitespace +[{makefile,Makefile,go}] +indent_style = tab diff --git a/.github/changelog-builder.json b/.github/changelog-builder.json new file mode 100644 index 0000000..594421d --- /dev/null +++ b/.github/changelog-builder.json @@ -0,0 +1,207 @@ +{ + "categories": [ + { + "title": "## ๐Ÿš€ Features", + "labels": [ + "feature", + "feat" + ], + "rules": [ + { + "on_property": "branch", + "pattern": "^(feat|feature)/.+", + "flags": "igu" + }, + { + "on_property": "title", + "pattern": "^(feat|feature): .+", + "flags": "igu" + } + ] + }, + { + "title": "## ๐Ÿ› Fixes", + "labels": [ + "fix", + "bug", + "bugfix" + ], + "rules": [ + { + "on_property": "branch", + "pattern": "^(fix|bug|bugfix)/.+", + "flags": "igu" + }, + { + "on_property": "title", + "pattern": "^(fix|bug|bugfix): .+", + "flags": "igu" + } + ] + }, + { + "title": "## ๐Ÿงช CI", + "labels": [ + "test", + "ci", + "build" + ], + "rules": [ + { + "on_property": "branch", + "pattern": "^(test|ci|build)/.+", + "flags": "igu" + }, + { + "on_property": "title", + "pattern": "^(test|ci|build): .+", + "flags": "igu" + } + ] + }, + { + "title": "## ๐Ÿ’ฌ Miscellaneous", + "labels": [ + "other", + "chore", + "misc" + ], + "rules": [ + { + "on_property": "branch", + "pattern": "^(other|chore|misc)/.+", + "flags": "igu" + }, + { + "on_property": "title", + "pattern": "^(other|chore|misc): .+", + "flags": "igu" + } + ] + }, + { + "title": "## ๐Ÿ“ฆ Dependencies", + "labels": [ + "dependencies", + "deps", + "dep" + ], + "rules": [ + { + "on_property": "branch", + "pattern": "^(deps|dep|dependencies)/.+", + "flags": "igu" + }, + { + "on_property": "title", + "pattern": "^(deps|dep|dependencies): .+", + "flags": "igu" + } + ] + }, + { + "title": "## ๐Ÿ“ Documentation", + "labels": [ + "docs", + "documentation" + ], + "rules": [ + { + "on_property": "branch", + "pattern": "^(docs|documentation)/.+", + "flags": "igu" + }, + { + "on_property": "title", + "pattern": "^(docs|documentation): .+", + "flags": "igu" + } + ] + }, + { + "title": "## ๐Ÿ”ง Refactoring", + "labels": [ + "refactor", + "refactory", + "refactoring" + ], + "rules": [ + { + "on_property": "branch", + "pattern": "^(refactor|refactory|refactoring)/.+", + "flags": "igu" + }, + { + "on_property": "title", + "pattern": "^(refactor|refactory|refactoring): .+", + "flags": "igu" + } + ] + }, + { + "title": "## ๐Ÿงน Cleanup", + "labels": [ + "cleanup", + "clean" + ], + "rules": [ + { + "on_property": "branch", + "pattern": "^(cleanup|clean)/.+", + "flags": "igu" + }, + { + "on_property": "title", + "pattern": "^(cleanup|clean): .+", + "flags": "igu" + } + ] + }, + { + "title": "## ๐Ÿšจ Breaking Changes", + "labels": [ + "breaking", + "breaking-change", + "breaking-changes", + "breaking change", + "breaking changes" + ], + "rules": [ + { + "on_property": "branch", + "pattern": "^(breaking|breaking-change|breaking-changes|breaking change|breaking changes)/.+", + "flags": "igu" + }, + { + "on_property": "title", + "pattern": "^(breaking|breaking-change|breaking-changes|breaking change|breaking changes): .+", + "flags": "igu" + } + ] + } + ], + "label_extractor": [ + { + "pattern": "(.+) (.+)", + "on_property": "title", + "target": "$1", + "flags": "gu" + }, + { + "pattern": "(.+)\\/(.+)", + "target": "$1", + "flags": "igu", + "on_property": "branch", + "method": "match" + } + ], + "ignore_labels": [ + "ignore" + ], + "sort": "ASC", + "template": "${{RELEASE_DIFF}}\n${{CHANGELOG}}", + "pr_template": "- ${{TITLE}} (#${{NUMBER}}) @${{AUTHOR}}", + "empty_template": "- no changes", + "max_pull_requests": 1000, + "max_back_track_time_days": 1000 +} \ No newline at end of file diff --git a/.github/labeler.yaml b/.github/labeler.yaml new file mode 100644 index 0000000..f2bfb9a --- /dev/null +++ b/.github/labeler.yaml @@ -0,0 +1,73 @@ +# https://github.com/srvaroa/labeler +version: 1 +issues: true +labels: + - label: "XS" + size: { below: 10 } + - label: "S" + size: { above: 10, below: 50 } + - label: "M" + size: { above: 50, below: 200 } + - label: "L" + size: { above: 200, below: 500 } + - label: "XL" + size: { above: 500, below: 1000} + - label: "XXL" + size: { above: 1000 } + + - label: WIP + title: (?mi)\W*(wip|in progress)\W* + + - label: mergeable + mergeable: true + + - label: bug + title: (?mi)^\s*(bugfix|fix|bug)\W + - label: bug + branch: (?mi)^(bugfix|fix|bug)/ + + - label: feature + title: (?mi)^\s*(feature|feat)\W + - label: feature + branch: (?mi)^(feature|feat)/ + + - label: breaking + title: (?mi)^\s*(breaking)\W + + - label: dependencies + title: (?mi)^\s*(dependencies|deps|dep)\W + - label: dependencies + branch: (?mi)^(dependencies|deps|dep)/ + - label: dependencies + files: + - go.mod + - go.sum + + - label: refactory + title: (?mi)^\s*(refactory|refactor)\W + - label: refactory + branch: (?mi)^(refactory|refactor)/ + + - label: documentation + title: (?mi)^\s*(documentation|docs|doc)\W + - label: documentation + branch: (?mi)^(documentation|docs|doc)/ + + - label: chore + title: (?mi)^\s*(chore|misc)\W + - label: chore + branch: (?mi)^(chore|misc)/ + + - label: ci + title: "(?mi)(ci|deploy):" + - label: ci + branch: (?mi)^(ci|deploy)/ + - label: ci + files: + - \.github/.* + - Dockerfile + + - label: release + title: (?mi)^\s*(release|releasing)\W + - label: release + branch: (?mi)^(release|releasing)\W diff --git a/.github/workflows/labeler.yaml b/.github/workflows/labeler.yaml new file mode 100644 index 0000000..4886bfd --- /dev/null +++ b/.github/workflows/labeler.yaml @@ -0,0 +1,18 @@ +name: label issues and PRs + +on: + - pull_request + - issues + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: run labeler + uses: srvaroa/labeler@master + with: + config_path: .github/labeler.yaml + use_local_config: false + fail_on_error: false + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..39154d6 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,61 @@ +name: lint + +on: + push: + branches: + - master + pull_request: + +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + golangci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: check if any go files changed + id: changed-files + uses: tj-actions/changed-files@v44 + with: + files: | + go.sum + *.go + **/*.go + - uses: actions/setup-go@v4 + if: steps.changed-files.outputs.any_changed == 'true' + with: + go-version: ^1.21 + - name: run golangci-lint + if: steps.changed-files.outputs.any_changed == 'true' + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest + + args: --timeout=5m + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..a99a382 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,91 @@ +name: release + +on: + push: + tags: ["*"] + workflow_dispatch: + +permissions: + contents: write + packages: write + pull-requests: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + GHCR_REPO: ghcr.io/${{ github.repository_owner }}/arbctl + +jobs: + release-image: + runs-on: "ubuntu-latest" + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: login to ghcr + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: set up docker buildx + id: docker-builder + uses: docker/setup-buildx-action@v3 + + - name: docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.GHCR_REPO }} + tags: | + type=ref,event=branch + type=ref,event=branch,suffix=-${{ github.run_number }} + type=ref,event=tag + type=ref,event=pr + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} + type=sha,format=short,prefix= + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }} + + - name: build with cache and push images + uses: docker/build-push-action@v3 + id: docker_build + with: + context: . + builder: ${{ steps.docker-builder.outputs.name }} + push: ${{ github.event_name != 'pull_request' }} + cache-from: | + type=registry,ref=${{ env.GHCR_REPO }}:latest + tags: ${{ steps.meta.outputs.tags }} + + make-release: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: build changelog + id: changelog + uses: mikepenz/release-changelog-builder-action@v3 + with: + configuration: .github/changelog-builder.json + ignorePreReleases: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: make release + uses: ncipollo/release-action@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + body: | + ${{ steps.changelog.outputs.changelog }} + allowUpdates: true + prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') || contains(github.ref, 'pre') }} + draft: true diff --git a/.gitignore b/.gitignore index 6f6f5e6..ca50249 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,24 @@ # Go workspace file go.work go.work.sum + +# Develop tools +.idea/ +*.swp + +# Dependency directories (remove the comment below to include it) +vendor/ + +# Go workspace file +go.work + +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# OS General +Thumbs.db +.DS_Store + +bin/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7f09055 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM golang:1.22 AS builder + +ARG GOPROXY + +WORKDIR /src +COPY go.mod go.sum /src/ +RUN --mount=type=secret,id=git_config,target=/root/.gitconfig \ + --mount=type=secret,id=git_credentials,target=/root/.config/git/credentials \ + --mount=type=secret,id=gh_hosts,target=/root/.config/gh/hosts.yml \ + go mod download -x + +COPY . /src + +RUN --mount=type=secret,id=git_config,target=/root/.gitconfig \ + --mount=type=secret,id=git_credentials,target=/root/.config/git/credentials \ + --mount=type=secret,id=gh_hosts,target=/root/.config/gh/hosts.yml \ + make build + +FROM ubuntu:22.04 + +RUN apt-get update && apt-get install -y \ + ca-certificates \ + curl \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /src/bin /usr/local/bin + +CMD ["/usr/local/bin/arbctl"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..51f0f28 --- /dev/null +++ b/Makefile @@ -0,0 +1,108 @@ +IMG ?= arbctl:latest + +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) +ifeq (,$(shell go env GOBIN)) +GOBIN=$(shell go env GOPATH)/bin +else +GOBIN=$(shell go env GOBIN) +endif + +ARCH=$(shell uname -m) +ifeq (x86_64, $(ARCH)) + ARCH=amd64 +else ifeq (aarch64, $(ARCH)) + ARCH=arm64 +endif +OS=$(shell uname -s) +os=$(shell uname -s | tr '[:upper:]' '[:lower:]') +GOHOSTOS:=$(shell go env GOHOSTOS) +GOPATH:=$(shell go env GOPATH) +VERSION=$(shell git describe --tags --always) + +# Setting SHELL to bash allows bash commands to be executed by recipes. +# Options are set to exit when a recipe line exits non-zero or a piped command fails. +SHELL = /usr/bin/env bash -o pipefail +.SHELLFLAGS = -ec + +LOCALBIN ?= bin +ABS_LOCALBIN=$(shell pwd)/$(LOCALBIN) +export PATH := $(ABS_LOCALBIN):$(PATH) + +ENSURE_DEPS=$(shell pwd)/scripts/ensure-deps.sh +## Tool Binaries +GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint +LINTER ?= $(GOLANGCI_LINT) +ABIGEN ?= $(LOCALBIN)/abigen + +ifeq ($(GOHOSTOS), windows) + #the `find.exe` is different from `find` in bash/shell. + #to see https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find. + #changed to use git-bash.exe to run find cli or other cli friendly, caused of every developer has a Git. + #Git_Bash= $(subst cmd\,bin\bash.exe,$(dir $(shell where git))) + Git_Bash=$(subst \,/,$(subst cmd\,bin\bash.exe,$(dir $(shell where git)))) + INTERNAL_PROTO_FILES=$(shell $(Git_Bash) -c "find internal -name *.proto") + API_PROTO_FILES=$(shell $(Git_Bash) -c "find api -name *.proto") +else + INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) + API_PROTO_FILES=$(shell find api -name *.proto) +endif + +.PHONY: all +all: build + +##@ General + +# The help target prints out all targets with their descriptions organized +# beneath their categories. The categories are represented by '##@' and the +# target descriptions by '##'. The awk commands is responsible for reading the +# entire set of makefiles included in this invocation, looking for lines of the +# file as xyz: ## something, and then pretty-format the target and help. Then, +# if there's a line with ##@ something, that gets pretty-printed as a category. +# More info on the usage of ANSI control characters for terminal formatting: +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters +# More info on the awk command: +# http://linuxcommand.org/lc3_adv_awk.php + +.PHONY: help +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + +.PHONY: lint +lint: $(LINTER) ## Lint code + $(LINTER) run -v + +##@ Build + +.PHONY: build +build: ## Build binary. + mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./... + +# If you wish built the manager image targeting other platforms you can use the --platform flag. +# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it. +# More info: https://docs.docker.com/develop/develop-images/build_enhancements/ +.PHONY: image +image: ## Build docker image with local proxy setting + docker build . --progress=plain -t ${IMG} --build-arg GOPROXY=$(shell go env GOPROXY) + +##@ Build Dependencies +$(LOCALBIN): + mkdir -p $(LOCALBIN) + +ENSURE_DEPS: $(LOCALBIN) $(ENSURE_DEPS) + scripts/ensure-deps.sh + +$(LINTER): ENSURE_DEPS +$(ABIGEN): ENSURE_DEPS + +.PHONY: deps +deps: $(LOCALBIN) $(LINTER) $(ABIGEN) ## Install binary dependencies + +##@ Code Generation +.PHONY: generate +generate: deps ## Generate go files by go generate + go mod tidy + go generate ./... + +.PHONY: generate-all +generate-all: ## Generate all files + make config diff --git a/cmd/arbctl/commands/root.go b/cmd/arbctl/commands/root.go new file mode 100644 index 0000000..adf53cd --- /dev/null +++ b/cmd/arbctl/commands/root.go @@ -0,0 +1,22 @@ +package commands + +import ( + "os" + + "github.com/urfave/cli" +) + +var app = cli.NewApp() + +func init() { + app.Name = "arbctl" + app.Usage = "Cli tool to interact with the Arbitrum chain" + app.Commands = []cli.Command{} +} + +func Run(args ...string) error { + if len(args) == 0 { + args = os.Args + } + return app.Run(args) +} diff --git a/cmd/arbctl/main.go b/cmd/arbctl/main.go new file mode 100644 index 0000000..af59b80 --- /dev/null +++ b/cmd/arbctl/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "os" + + "github.com/renlulu/arbitrum-orbit-sdk-go/cmd/arbctl/commands" + "github.com/urfave/cli" +) + +func main() { + err := commands.Run() + if err != nil { + _, _ = os.Stderr.WriteString(err.Error() + "\n") + exitCode := 1 + if exitCoder, ok := err.(cli.ExitCoder); ok { + exitCode = exitCoder.ExitCode() + } + os.Exit(exitCode) + } +} diff --git a/go.mod b/go.mod index bdbb9bf..725fd23 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,10 @@ module github.com/renlulu/arbitrum-orbit-sdk-go go 1.22.2 -require github.com/ethereum/go-ethereum v1.14.5 +require ( + github.com/ethereum/go-ethereum v1.14.5 + github.com/urfave/cli v1.22.15 +) require ( github.com/Microsoft/go-winio v0.6.2 // indirect @@ -11,6 +14,7 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect github.com/consensys/bavard v0.1.13 // indirect github.com/consensys/gnark-crypto v0.12.1 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect github.com/deckarep/golang-set/v2 v2.6.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect @@ -21,6 +25,7 @@ require ( github.com/gorilla/websocket v1.4.2 // indirect github.com/holiman/uint256 v1.2.4 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect github.com/supranational/blst v0.3.11 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect diff --git a/go.sum b/go.sum index e6831c6..9b4d5cd 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,4 @@ +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= @@ -32,12 +33,13 @@ github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/Yj github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M= github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY= -github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c h1:uQYC5Z1mdLRPrZhHjHxufI8+2UG/i25QG92j0Er9p6I= github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= github.com/crate-crypto/go-kzg-4844 v1.0.0 h1:TsSgHwrkTKecKJ4kadtHi4b3xHW5dCFUDFnUp1TsawI= github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM= @@ -143,8 +145,15 @@ github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1 github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +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= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= @@ -155,6 +164,8 @@ github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+F github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= +github.com/urfave/cli v1.22.15 h1:nuqt+pdC/KqswQKhETJjo7pvn/k4xMUxgW6liI7XpnM= +github.com/urfave/cli v1.22.15/go.mod h1:wSan1hmo5zeyLGBjRJbzRTNk8gwoYa2B9n4q9dmRIc0= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= @@ -178,10 +189,12 @@ golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= diff --git a/pkg/bindings/gen.go b/pkg/bindings/gen.go index 4ab495c..996e76b 100644 --- a/pkg/bindings/gen.go +++ b/pkg/bindings/gen.go @@ -1,3 +1,3 @@ package bindings -//go:generate bash -c "abigen --abi RollupCreator.abi --pkg bindings --type RollupCreator --out RollupCreator.go" +//go:generate abigen --abi RollupCreator.abi --pkg bindings --type RollupCreator --out RollupCreator.go diff --git a/scripts/ensure-deps.sh b/scripts/ensure-deps.sh new file mode 100755 index 0000000..c6172b2 --- /dev/null +++ b/scripts/ensure-deps.sh @@ -0,0 +1,137 @@ +#!/bin/bash -e +if [[ $DEBUG == "true" ]]; then + set -x +fi + +# https://go.dev/dl +GO_VERSION="1.22" +# https://github.com/golangci/golangci-lint/releases +GOLANGCI_LINT_VERSION="1.59.1" +# https://github.com/ethereum/go-ethereum/releases +GETH_VERSION=1.14.5 +ABIGEN_VERSION=$GETH_VERSION + +# directory variables +TMPDIR=${TMPDIR:-/tmp} +READLINK=$([[ $OSTYPE == 'darwin'* ]] && echo 'greadlink' || echo 'readlink') +script_path=$($READLINK -f "${BASH_SOURCE:-$0}") +SCRIPTS_ROOT=$(dirname $script_path) +REPO_ROOT=$(dirname $SCRIPTS_ROOT) +BIN=$REPO_ROOT/bin +export GOBIN=$BIN +export PATH=$BIN:$PATH + +# executable variables +GOLANGCI_LINT=$BIN/golangci-lint +ABIGEN=$BIN/abigen + +info() { + echo -e "\033[1;32m$@\033[0m" +} + +error() { + echo -e "\033[1;31m$@\033[0m" +} + +fatal() { + error "$@" + exit 1 +} + +must_executable() { + executable=$1 + message=$2 + if ! command -v $1 &>/dev/null; then + fatal "$message" + fi +} + +# ensure basic tools +ensure_tools() { + # ensure go + must_executable go "[deps:go] go not found" + go_version=$(go version | awk '{print $3}') + # if VER is not prefixed with GO_VERSION + if [[ "$go_version" != "go${GO_VERSION}."* ]]; then + fatal "[deps:go] go version $go_version is not ${GO_VERSION}.*" + fi + # ensure curl exist + must_executable curl "[deps:curl] curl not found" + # unzip + must_executable unzip "[deps:unzip] unzip not found" + # git + must_executable git "[deps:git] git not found" +} +ensure_tools + +# machine variables +# https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63 +GOHOSTOS=$(go env GOHOSTOS) # darwin, linux, windows +GOHOSTARCH=$(go env GOHOSTARCH) # amd64, arm64, 386 + +ensure_bin_dir() { + mkdir -p $BIN +} + +er() { + # echo and run + info "[RUN] $@" + $@ +} + +# golangci-lint +golangci_lint_version() { + $GOLANGCI_LINT --version | awk '{print $4}' +} + +install_golangci_lint() { + ensure_bin_dir + # https://golangci-lint.run/welcome/install/#local-installation + info "[RUN] curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b $BIN v${GOLANGCI_LINT_VERSION}" + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b $BIN v${GOLANGCI_LINT_VERSION} + info "[deps] golangci-lint $(golangci_lint_version) installed" +} + +ensure_golangci_lint() { + if [[ ! -x $GOLANGCI_LINT ]]; then + info "golangci-lint not found, installing..." + install_golangci_lint + elif [[ $(golangci_lint_version) != "${GOLANGCI_LINT_VERSION}" ]]; then + info "golangci-lint version mismatch, found $(golangci_lint_version), installing $GOLANGCI_LINT_VERSION..." + install_golangci_lint + else + info "[deps] golangci-lint $(golangci_lint_version) found" + fi + touch $GOLANGCI_LINT +} + +# abigen +# abigen version 1.14.5-stable +abigen_version() { + $ABIGEN --version | awk '{print $3}' | cut -d'-' -f1 +} + +install_abigen() { + ensure_bin_dir + # https://geth.ethereum.org/docs/interface/go-ethereum-abigen/ + er go install github.com/ethereum/go-ethereum/cmd/abigen@v${ABIGEN_VERSION} + info "[deps] abigen $(abigen_version) installed" +} + +ensure_abigen() { + if [[ ! -x $ABIGEN ]]; then + info "abigen not found, installing..." + install_abigen + elif [[ $(abigen_version) != "${ABIGEN_VERSION}" ]]; then + info "abigen version mismatch, found $(abigen_version), installing $ABIGEN_VERSION..." + install_abigen + else + info "[deps] abigen $(abigen_version) found" + fi +} + +# main +ensure_golangci_lint +ensure_abigen + +info "[deps] all dependencies installed and updated"