Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves a lot of things #3895

Merged
merged 9 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 13 additions & 25 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,47 @@
name: BuildAndTest
on: [pull_request, workflow_dispatch]

env:
CHIFRA_PATH: src/apps/chifra
# Go Version
GO_VERSION: ^1.22

GO_VERSION: 1.22
jobs:
Lint:
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v4
-
uses: actions/setup-go@v5
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
cache-dependency-path: ${{ env.CHIFRA_PATH }}/go.sum
-
name: golangci-lint
- name: Generate go.work file
run: |
./scripts/go-work-sync.sh
- name: golangci-lint
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: v1.54.2

# Optional: working directory, useful for monorepos
version: v1.61.0
working-directory: ${{ env.CHIFRA_PATH }}

# Optional: set location of the config file (if it is not in the root directory)
args: --timeout=5m --verbose --out-format=colored-line-number
Build:
needs: Lint
runs-on: ubuntu-20.04
steps:
-
name: Checkout TrueBlocks repo
- name: Checkout TrueBlocks repo
uses: actions/checkout@v4
-
name: Use a certain version of go
- name: Use a certain version of go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
-
name: Install prerequistes
- name: Install prerequistes
run: |
sudo apt-mark hold grub-efi-amd64-signed
sudo apt-get update --fix-missing
sudo apt-get upgrade
sudo apt-get install build-essential git cmake
sudo apt-get install python3 tree jq
sudo apt-get install libcurl3-dev
-
name: Run basic golang unit tests
- name: Run basic golang unit tests
run: |
mkdir -p build
cd build
Expand All @@ -68,8 +57,7 @@ jobs:
needs: Build
runs-on: ubuntu-latest
steps:
-
name: Run tests remotely
- name: Run tests remotely
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TESTING_HOST }}
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ jobs:
- name: golangci-lint
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: v1.54.2
# Optional: working directory, useful for monorepos
version: v1.61.0
working-directory: src/apps/chifra
# Optional: golangci-lint command line arguments.
args: --timeout=5m --verbose --out-format=colored-line-number

# Optional: show only new issues if it's a pull request. The default value is `false`.
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ gh issue list --search "created:>2024-09-22 is:open is:issue sort:created-desc"

**chifra daemon**

- Deprecated `chifra daemon --api`, no replacement,
- Deprecated `chifra daemon --api`, no replacement,
- Deprecated `chifra daemon --scrape`, use `chifra scrape` instead
- Deprecated `chifra daemon --monitor`, use `chifra monitors --watch` instead.

Expand Down
2 changes: 1 addition & 1 deletion MIGRATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ and then removing the folders presented. Do this only if your data is prior to v
| v0.25.0 | [Multi Chain](https://github.com/TrueBlocks/trueblocks-core/blob/develop/src/other/migrations/README-v0.25.0.md) | 2022/02/22 | Adds `--chain` option to all commands. Now supports any EVM-based chain. |
| v0.18.0 | [Better Neighbors](https://github.com/TrueBlocks/trueblocks-core/blob/develop/src/other/migrations/README-v0.18.0.md) | 2021/12/10 | Cleans up `chifra export --neighbors` output<br />- Corrects incorrect headers in .txt and .csv export. |
| v0.17.0 | [Updated API and SDK](https://github.com/TrueBlocks/trueblocks-core/blob/develop/src/other/migrations/README-v0.17.0.md) | 2021/11/23 | Creates TypeScript SDK and forces all API endpoint options to camelCase. |
| v0.14.0 | [Go Version of Chifra](https://github.com/TrueBlocks/trueblocks-core/blob/develop/src/other/migrations/README-v0.14.0.md) | 2021/10/03 | Ports chifra command line to golang<br />- Breaking change to --verbose flag. |
| v0.14.0 | [goLang version of Chifra](https://github.com/TrueBlocks/trueblocks-core/blob/develop/src/other/migrations/README-v0.14.0.md) | 2021/10/03 | Ports chifra command line to golang<br />- Breaking change to --verbose flag. |
| v0.12.1 | [New Folder Structure](https://github.com/TrueBlocks/trueblocks-core/blob/develop/src/other/migrations/README-v0.12.1.md) | 2021/09/01 | Adds support for Erigon<br />- Moves most executables to private path. |
| v0.11.3 | [London Hard Fork Migration](https://github.com/TrueBlocks/trueblocks-core/blob/develop/src/other/migrations/README-v0.11.3.md) | 2021/08/20 | Support for cache file format change due to London hard fork. |
| v0.9.0 | [Configuration File Migration](https://github.com/TrueBlocks/trueblocks-core/blob/develop/src/other/migrations/README-v0.09.0.md) | 2021/06/02 | Moves configuration file locations. |
2 changes: 1 addition & 1 deletion docs
2 changes: 1 addition & 1 deletion node
Submodule node updated 2 files
+2 −1 go.mod
+4 −4 go.sum
3 changes: 2 additions & 1 deletion scripts/go-work-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ find . -type f -name 'go.mod' | while read -r modfile; do
isGoMaker="[ "$moddir" == "./src/dev_tools/goMaker" ]"
isNode="[ "$moddir" == "./node" ]"
isFourbyte="[ "$moddir" == "./examples/four_bytes" ]"
isIndexMan="[ "$moddir" == "./src/dev_tools/indexManager" ]"
isSimple="[ "$moddir" == "./examples/simple" ]"

if $isGoMaker || $isNode || $isFourbyte; then
go get github.com/btcsuite/btcd 2> /dev/null
fi

if ! $isSdk && ! $isChifra && ! $isGoMaker; then
if ! $isSdk && ! $isChifra && ! $isGoMaker && ! $isFourbyte && ! $isIndexMan; then
go get github.com/TrueBlocks/trueblocks-sdk/v3@latest
fi
if ! $isSimple && ! $isChifra; then
Expand Down
2 changes: 1 addition & 1 deletion sdk
Submodule sdk updated 2 files
+1 −1 go.mod
+4 −4 go.sum
5 changes: 3 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ if (NOT GO_VERSION_MATCH)
endif()
set(GO_MAJOR_VERSION ${CMAKE_MATCH_1})
set(GO_MINOR_VERSION ${CMAKE_MATCH_2})
# Go Version
if (GO_MAJOR_VERSION LESS 1 OR (GO_MAJOR_VERSION EQUAL 1 AND GO_MINOR_VERSION LESS 22))
message(STATUS "${CColor}The build failed.${COff}")
message(STATUS "${CColor}Found ${GO_VERSION_OUTPUT}. Version 1.22 or higher is required.${COff}")
message(STATUS "${CColor}Found ${GO_VERSION_OUTPUT}. Go Version 1.22 or higher is required.${COff}")
message(STATUS "${CColor}Please install or update Go from https://golang.org/doc/install.${COff}")
return()
else()
Expand All @@ -59,7 +60,7 @@ set(CMAKE_INSTALL_PREFIX "/usr/local/" CACHE PATH "Default install directory")
set(REPO_DIR ${CMAKE_SOURCE_DIR}/..)
set(SCRIPTS_DIR ${REPO_DIR}/scripts)

add_custom_target(lint COMMAND "golangci-lint" "run" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/apps/chifra")
add_custom_target(lint COMMAND "golangci-lint" "run" "--out-format=colored-line-number" "--path-prefix=src/apps/chifra" "--timeout=5m" "./..." WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/apps/chifra")
add_custom_target(generate COMMAND ${BIN_DIR}/goMaker WORKING_DIRECTORY ${REPO_DIR})
add_custom_target(test-all COMMAND ${SCRIPTS_DIR}/test-all.sh WORKING_DIRECTORY ${REPO_DIR}/build)
add_custom_target(examples ALL COMMAND ${SCRIPTS_DIR}/build-examples.sh WORKING_DIRECTORY ${REPO_DIR})
Expand Down
3 changes: 2 additions & 1 deletion src/apps/chifra/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package cmd

import (
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -42,7 +43,7 @@ func ErrFunc(cmd *cobra.Command, errMsg error) error {
} else {
msg = "\n \033[31m" + msg + "\033[0m\n"
}
return fmt.Errorf(msg)
return errors.New(msg)
}

func UsageWithNotes(notes string) string {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/gorilla/websocket v1.5.0
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-ipfs-api v0.6.1
github.com/panjf2000/ants/v2 v2.7.0
github.com/panjf2000/ants/v2 v2.10.0
github.com/pelletier/go-toml/v2 v2.2.2
github.com/spf13/cobra v1.7.0
github.com/wealdtech/go-ens/v3 v3.5.2
Expand Down
8 changes: 4 additions & 4 deletions src/apps/chifra/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.0.3-0.20180606204148-bd9c31933947/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/panjf2000/ants/v2 v2.7.0 h1:Y3Bgpfo9HDkBoHNVFbMfY5mAvi5TAA17y3HbzQ74p5Y=
github.com/panjf2000/ants/v2 v2.7.0/go.mod h1:KIBmYG9QQX5U2qzFP/yQJaq/nSb6rahS9iEHkrCMgM8=
github.com/panjf2000/ants/v2 v2.10.0 h1:zhRg1pQUtkyRiOFo2Sbqwjp0GfBNo9cUY2/Grpx1p+8=
github.com/panjf2000/ants/v2 v2.10.0/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I=
github.com/paulbellamy/ratecounter v0.2.0/go.mod h1:Hfx1hDpSGoqxkVVpBi/IlYD7kChlfo5C6hzIHwPqfFE=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
Expand Down Expand Up @@ -651,7 +651,7 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
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.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
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=
Expand Down Expand Up @@ -818,7 +818,7 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
3 changes: 2 additions & 1 deletion src/apps/chifra/internal/chunks/handle_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package chunksPkg

import (
"encoding/binary"
"errors"
"fmt"
"io"
"strings"
Expand Down Expand Up @@ -46,7 +47,7 @@ func (opts *ChunksOptions) HandleAddresses(rCtx *output.RenderCtx, blockNums []b
msg = fmt.Sprintf("index file %s does not exist. Warnings turned off...", path)
}
if msg != "" {
errorChan <- fmt.Errorf(msg)
errorChan <- errors.New(msg)
}
been_here++
return true, nil
Expand Down
23 changes: 12 additions & 11 deletions src/apps/chifra/internal/scrape/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/configtypes"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc"
Expand All @@ -34,17 +35,17 @@ import (

// ScrapeOptions provides all command options for the chifra scrape command.
type ScrapeOptions struct {
BlockCnt uint64 `json:"blockCnt,omitempty"` // Maximum number of blocks to process per pass
Sleep float64 `json:"sleep,omitempty"` // Seconds to sleep between scraper passes
Publisher string `json:"publisher,omitempty"` // For some query options, the publisher of the index
Touch base.Blknum `json:"touch,omitempty"` // First block to visit when scraping (snapped back to most recent snap_to_grid mark)
RunCount uint64 `json:"runCount,omitempty"` // Run the scraper this many times, then quit
DryRun bool `json:"dryRun,omitempty"` // Show the configuration that would be applied if run,no changes are made
Notify bool `json:"notify,omitempty"` // Enable the notify feature
Settings config.ScrapeSettings `json:"settings,omitempty"` // Configuration items for the scrape
Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options
Conn *rpc.Connection `json:"conn,omitempty"` // The connection to the RPC server
BadFlag error `json:"badFlag,omitempty"` // An error flag if needed
BlockCnt uint64 `json:"blockCnt,omitempty"` // Maximum number of blocks to process per pass
Sleep float64 `json:"sleep,omitempty"` // Seconds to sleep between scraper passes
Publisher string `json:"publisher,omitempty"` // For some query options, the publisher of the index
Touch base.Blknum `json:"touch,omitempty"` // First block to visit when scraping (snapped back to most recent snap_to_grid mark)
RunCount uint64 `json:"runCount,omitempty"` // Run the scraper this many times, then quit
DryRun bool `json:"dryRun,omitempty"` // Show the configuration that would be applied if run,no changes are made
Notify bool `json:"notify,omitempty"` // Enable the notify feature
Settings configtypes.ScrapeSettings `json:"settings,omitempty"` // Configuration items for the scrape
Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options
Conn *rpc.Connection `json:"conn,omitempty"` // The connection to the RPC server
BadFlag error `json:"badFlag,omitempty"` // An error flag if needed
// EXISTING_CODE
PublisherAddr base.Address `json:"-"`
// EXISTING_CODE
Expand Down
5 changes: 3 additions & 2 deletions src/apps/chifra/internal/status/handle_modes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package statusPkg

import (
"context"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -130,9 +131,9 @@ func (opts *StatusOptions) HandleModes(rCtx *output.RenderCtx) error {
if totalRecords == 0 {
str := ""
for _, m := range opts.Modes {
str += fmt.Sprintf("%s ", m)
str += m + " "
}
errorChan <- fmt.Errorf("no files were found in the [" + strings.Trim(str, " ") + "] caches")
errorChan <- errors.New("no files were found in the [" + strings.Trim(str, " ") + "] caches")
return
}

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/base/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (a Address) String() string {

// Format is used by Stringer don't remove
func (a Address) Format(s fmt.State, c rune) {
s.Write([]byte(a.Hex()))
_, _ = s.Write([]byte(a.Hex()))
}

// MarshalText is used by Stringer don't remove
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/base/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (h *Hash) String() string {

// Format is used by Stringer don't remove
func (h Hash) Format(s fmt.State, c rune) {
s.Write([]byte(h.Hex()))
_, _ = s.Write([]byte(h.Hex()))
}

// MarshalText is used by Stringer don't remove
Expand Down
20 changes: 5 additions & 15 deletions src/apps/chifra/pkg/config/chainGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,17 @@

package config

type chainGroup struct {
Chain string `toml:"chain,omitempty"`
ChainId string `toml:"chainId"`
IpfsGateway string `toml:"ipfsGateway,omitempty"`
KeyEndpoint string `toml:"keyEndpoint,omitempty"`
LocalExplorer string `toml:"localExplorer,omitempty"`
RemoteExplorer string `toml:"remoteExplorer,omitempty"`
RpcProvider string `toml:"rpcProvider"`
Symbol string `toml:"symbol"`
Scrape ScrapeSettings `toml:"scrape"`
}
import "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/configtypes"

// GetChain returns the chain for a given chain
func GetChain(chain string) chainGroup {
func GetChain(chain string) configtypes.ChainGroup {
return GetRootConfig().Chains[chain]
}

// GetChains returns a list of all chains configured in the config file. Note, there is no "official"
// list. Users may add their own chains.
func GetChains() []chainGroup {
chainArray := make([]chainGroup, 0, len(GetRootConfig().Chains))
func GetChains() []configtypes.ChainGroup {
chainArray := make([]configtypes.ChainGroup, 0, len(GetRootConfig().Chains))
for _, v := range GetRootConfig().Chains {
chainArray = append(chainArray, v)
}
Expand All @@ -33,5 +23,5 @@ func GetChains() []chainGroup {

// IsChainConfigured returns true if the chain is configured in the config file.
func IsChainConfigured(needle string) bool {
return GetRootConfig().Chains != nil && GetRootConfig().Chains[needle] != chainGroup{}
return GetRootConfig().Chains != nil && GetRootConfig().Chains[needle] != configtypes.ChainGroup{}
}
Loading
Loading