Skip to content

Commit

Permalink
chore: initialize project
Browse files Browse the repository at this point in the history
  • Loading branch information
kallydev committed Nov 15, 2023
0 parents commit d65c743
Show file tree
Hide file tree
Showing 61 changed files with 2,909 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
target-branch: "main"
19 changes: 19 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Lint
on:
push:
pull_request:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: "1.21"
- uses: actions/checkout@v3
- name: GolangCI Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
18 changes: 18 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Test
on:
push:
pull_request:

jobs:
test:
name: Test
runs-on: self-hosted
steps:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: "1.21"
- name: Checkout
uses: actions/checkout@v3
- name: Test
run: make test
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
### Visual Studio Code
.vscode/*


### JetBrains
.idea/*

!.idea/icon.svg
!.idea/rss3-node.iml

### Linux

### Go template
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Go workspace file
go.work

### macOS
.DS_Store

### Project
/build/*
32 changes: 32 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
run:
timeout: 10m

linters:
enable:
# Enabled by default
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
# Disabled by default
- asasalint
- asciicheck
- bodyclose
- errorlint
- gci
- gocyclo
- gosec
- makezero
- noctx
- paralleltest
- prealloc
- reassign
- revive
- whitespace
- wsl

issues:
max-issues-per-linter: 0 # Unlimited
max-same-issues: 0 # Unlimited
19 changes: 19 additions & 0 deletions .idea/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions .idea/rss3-node.iml

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

14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/golangci/golangci-lint
rev: v1.55.2
hooks:
- id: golangci-lint
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.42.1
hooks:
- id: commitizen
8 changes: 8 additions & 0 deletions .run/build.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
<makefile filename="$PROJECT_DIR$/Makefile" target="build" workingDirectory="" arguments="">
<envs />
</makefile>
<method v="2" />
</configuration>
</component>
8 changes: 8 additions & 0 deletions .run/image.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="image" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
<makefile filename="$PROJECT_DIR$/Makefile" target="image" workingDirectory="" arguments="">
<envs />
</makefile>
<method v="2" />
</configuration>
</component>
8 changes: 8 additions & 0 deletions .run/lint.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="lint" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
<makefile filename="$PROJECT_DIR$/Makefile" target="lint" workingDirectory="" arguments="">
<envs />
</makefile>
<method v="2" />
</configuration>
</component>
8 changes: 8 additions & 0 deletions .run/run.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="run" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
<makefile filename="$PROJECT_DIR$/Makefile" target="run" workingDirectory="" arguments="">
<envs />
</makefile>
<method v="2" />
</configuration>
</component>
8 changes: 8 additions & 0 deletions .run/test.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="test" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
<makefile filename="$PROJECT_DIR$/Makefile" target="test" workingDirectory="" arguments="">
<envs />
</makefile>
<method v="2" />
</configuration>
</component>
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @polebug @kallydev
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:1.21.3-alpine AS builder

WORKDIR /root/rss3-node

COPY . .

RUN apk add --no-cache git make gcc libc-dev

RUN CGO_ENABLED=1 make build

FROM alpine:3.18.4 AS runner

WORKDIR /root/rss3-node

RUN apk add --no-cache ca-certificates tzdata

COPY --from=builder /root/rss3-node/build/rss3-node .

ENTRYPOINT ["./rss3-node"]
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
VERSION=$(shell git describe --tags --abbrev=0)
COMMIT=$(shell git rev-parse --short HEAD)

ifeq ($(VERSION),)
VERSION="0.0.0"
endif

generate:
go generate ./...

lint: generate
go mod tidy
go run github.com/golangci/golangci-lint/cmd/[email protected] run

test:
go test -cover -v ./...

.PHONY: build
build: generate
mkdir -p ./build
go build \
-ldflags "-X github.com/naturalselectionlabs/rss3-node/internal/constant.Version=$(VERSION) -X github.com/naturalselectionlabs/rss3-node/internal/constant.Commit=$(COMMIT)" \
-o ./build/rss3-node ./cmd

image: generate
docker build \
--tag naturalselectionlabs/rss3-node:$(VERSION) \
.

run: generate
ENVIRONMENT=development go run ./cmd
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# RSS3 Node
57 changes: 57 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"context"
"fmt"

"github.com/naturalselectionlabs/rss3-node/internal/config"
"github.com/naturalselectionlabs/rss3-node/internal/config/flag"
"github.com/naturalselectionlabs/rss3-node/internal/constant"
"github.com/naturalselectionlabs/rss3-node/internal/node"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
)

var command = cobra.Command{
Use: constant.Name,
Version: constant.BuildVersion(),
SilenceUsage: true,
SilenceErrors: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
return viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, _ []string) error {
config, err := config.Setup(viper.GetString(flag.KeyConfig))
if err != nil {
return fmt.Errorf("setup config file: %w", err)
}

server, err := node.NewServer(config.Node)
if err != nil {
return fmt.Errorf("build node server: %w", err)
}

return server.Run(cmd.Context())
},
}

func initializeLogger() {
if viper.GetString(config.Environment) == config.EnvironmentDevelopment {
zap.ReplaceGlobals(zap.Must(zap.NewDevelopment()))
} else {
zap.ReplaceGlobals(zap.Must(zap.NewProduction()))
}
}

func init() {
initializeLogger()

command.PersistentFlags().String(flag.KeyConfig, "./deploy/config.development.yaml", "config file path")
}

func main() {
if err := command.ExecuteContext(context.Background()); err != nil {
zap.L().Fatal("execute command", zap.Error(err))
}
}
5 changes: 5 additions & 0 deletions deploy/config.development.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
environment: development
node:
network: arweave
chain: mainnet
endpoint: https://ethereum.blockpi.network/v1/rpc/public
62 changes: 62 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module github.com/naturalselectionlabs/rss3-node

go 1.21

require (
github.com/ethereum/go-ethereum v1.13.5
github.com/samber/lo v1.38.1
github.com/shopspring/decimal v1.3.1
github.com/sourcegraph/conc v0.3.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.26.0
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/bits-and-blooms/bitset v1.7.0 // indirect
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/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.15.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading

0 comments on commit d65c743

Please sign in to comment.