Skip to content

Commit

Permalink
Merge pull request #5 from PFC-developer/v50
Browse files Browse the repository at this point in the history
V50 - update to use SDKv50
  • Loading branch information
PFC-developer authored Dec 22, 2023
2 parents 846185c + ebb2375 commit 3265030
Show file tree
Hide file tree
Showing 49 changed files with 11,701 additions and 538 deletions.
15 changes: 15 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
55 changes: 55 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: golangci-lint
on:
push:
branches:
- master
- main
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.55

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --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 all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
15 changes: 15 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on: [push, pull_request]
name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.21.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- run: go test ./...
160 changes: 120 additions & 40 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,124 @@
run:
tests: true
timeout: 10m

linters:
disable-all: true
enable:
- exportloopref
- errcheck
- gci
- goconst
- gocritic
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- staticcheck
- thelper
- typecheck
- stylecheck
- revive
- typecheck
- tenv
- unconvert
# Prefer unparam over revive's unused param. It is more thorough in its checking.
- unparam
- unused
- misspell

issues:
exclude-rules:
- text: ST1003
linters:
- stylecheck
- text: 'differs only by capitalization to method'
linters:
- revive
- text: 'Use of weak random number generator'
linters:
- gosec
- linters:
- staticcheck
text: "SA1019:" # silence errors on usage of deprecated funcs

max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
gocritic:
disabled-checks:
- ifElseChain
gosec:
excludes:
- G402
- G404
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- blank # blank imports
- dot # dot imports
- prefix(cosmossdk.io)
- prefix(github.com/cosmos/cosmos-sdk)
- prefix(github.com/cometbft/cometbft)
- prefix(github.com/cosmos/ibc-go)
- prefix(github.com/pfc-developer/cosmos-exporter)
custom-order: true
revive:
enable-all-rules: true
# Do NOT whine about the following, full explanation found in:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#description-of-available-rules
rules:
- name: var-declaration
- name: use-any
disabled: true

linters:
enable-all: true
disable:
- prealloc
- lll
- dupl
- funlen
- wsl
- gomnd
- unparam
- goerr113
- nestif
- errcheck
- golint
- scopelint
- maligned
- interfacer
- wrapcheck
- varnamelen
- tagliatelle
- exhaustivestruct
- gomoddirectives
- ireturn
- nlreturn
- cyclop
- errorlint
- noctx
- gocognit
- gocyclo
- promlinter
- gochecknoglobals
- name: if-return
disabled: true
- name: max-public-structs
disabled: true
- name: cognitive-complexity
disabled: true
- name: argument-limit
disabled: true
- name: cyclomatic
disabled: true
- name: file-header
disabled: true
- name: function-length
disabled: true
- name: function-result-limit
disabled: true
- name: line-length-limit
disabled: true
- name: flag-parameter
disabled: true
- name: add-constant
disabled: true
- name: empty-lines
disabled: true
- name: banned-characters
disabled: true
- name: get-return
disabled: true
- name: deep-exit
disabled: true
- name: confusing-results
disabled: true
- name: unused-parameter
disabled: true
- name: modifies-value-receiver
disabled: true
- name: early-return
disabled: true
- name: confusing-naming
disabled: true
- name: var-naming
disabled: true
- name: defer
disabled: true
# Disabled in favour of unparam.
- name: unused-parameter
disabled: true
- name: unhandled-error
disabled: false
arguments:
- 'fmt.Printf'
- 'fmt.Print'
- 'fmt.Println'
- 'myFunction'
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20-alpine AS builder
FROM golang:1.21-alpine AS builder

COPY . /app

Expand Down
22 changes: 14 additions & 8 deletions cmd/cosmos-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ package main

import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"net/http"
"os"

"github.com/rs/zerolog"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"main/pkg/exporter"
"net/http"
"os"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/pfc-developer/cosmos-exporter/pkg/exporter"
)

var config exporter.ServiceConfig
var log = zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout}).With().Timestamp().Logger()
var (
config exporter.ServiceConfig
log = zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout}).With().Timestamp().Logger()
)

var rootCmd = &cobra.Command{
Use: "cosmos-exporter",
Expand Down Expand Up @@ -124,9 +129,10 @@ func Execute(_ *cobra.Command, _ []string) {
})
*/
log.Info().Str("address", config.ListenAddress).Msg("Listening")
err = http.ListenAndServe(config.ListenAddress, nil)
err = http.ListenAndServe(config.ListenAddress, nil) // #nosec
if err != nil {
log.Fatal().Err(err).Msg("Could not start application")
log.Error().Err(err).Msg("Could not start application")
return
}
}

Expand Down
18 changes: 10 additions & 8 deletions cmd/inj-cosmos-exporter/Injective.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ package main
import (
"encoding/json"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/rs/zerolog"
"main/pkg/exporter"
"net/http"
"strconv"
"sync"
Expand All @@ -15,6 +12,11 @@ import (
"github.com/google/uuid"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/zerolog"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/pfc-developer/cosmos-exporter/pkg/exporter"
)

/*
Expand Down Expand Up @@ -68,16 +70,15 @@ type LastClaimEvent struct {
EventHeight string `json:"ethereum_event_height"`
}

func getInjMetrics(wg *sync.WaitGroup, sublogger *zerolog.Logger, metrics *InjMetrics, _ *exporter.Service, _ *exporter.ServiceConfig, orchestratorAddress sdk.AccAddress) {

func doInjMetrics(wg *sync.WaitGroup, sublogger *zerolog.Logger, metrics *InjMetrics, _ *exporter.Service, _ *exporter.ServiceConfig, orchestratorAddress sdk.AccAddress) {
wg.Add(1)
go func() {
defer wg.Done()
sublogger.Debug().Msg("Started querying LCD peggy module state")
queryStart := time.Now()

requestURL := fmt.Sprintf("%s/peggy/v1/module_state", LCD)
response, err := http.Get(requestURL)
response, err := http.Get(requestURL) // #nosec
if err != nil {
sublogger.Error().
Err(err).
Expand Down Expand Up @@ -114,7 +115,7 @@ func getInjMetrics(wg *sync.WaitGroup, sublogger *zerolog.Logger, metrics *InjMe
queryStart := time.Now()

requestURL := fmt.Sprintf("%s/peggy/v1/oracle/event/%s", LCD, orchestratorAddress.String())
response, err := http.Get(requestURL)
response, err := http.Get(requestURL) // #nosec
if err != nil {
sublogger.Error().
Err(err).
Expand Down Expand Up @@ -152,6 +153,7 @@ func getInjMetrics(wg *sync.WaitGroup, sublogger *zerolog.Logger, metrics *InjMe
metrics.lastClaimedEvent.WithLabelValues("event_height").Add(eventHeight)
}()
}

func InjMetricHandler(w http.ResponseWriter, r *http.Request, s *exporter.Service) {
requestStart := time.Now()

Expand All @@ -173,7 +175,7 @@ func InjMetricHandler(w http.ResponseWriter, r *http.Request, s *exporter.Servic

var wg sync.WaitGroup

getInjMetrics(&wg, &sublogger, injMetrics, s, s.Config, myAddress)
doInjMetrics(&wg, &sublogger, injMetrics, s, s.Config, myAddress)

wg.Wait()

Expand Down
Loading

0 comments on commit 3265030

Please sign in to comment.