Skip to content

Commit

Permalink
Merge pull request #500 from jshufro/jms/v2/actions
Browse files Browse the repository at this point in the history
Enable build ci. Enable staticcheck, ineffassign, gosimple, unused linters and fix their errors
  • Loading branch information
jclapis authored Apr 21, 2024
2 parents 095c674 + ea7a83a commit 9a237d9
Show file tree
Hide file tree
Showing 33 changed files with 34 additions and 376 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# For now, Smart Node will only enforce goimports linting
args: --disable-all --enable goimports
# For now, Smart Node will enforce everything except errcheck
args: --disable errcheck

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
Expand Down
5 changes: 3 additions & 2 deletions rocketpool-cli/client/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
dt "github.com/docker/docker/api/types"
dtc "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
dti "github.com/docker/docker/api/types/image"
)

// Get the current Docker image used by the given container
Expand Down Expand Up @@ -114,7 +115,7 @@ func (c *Client) DeleteImage(imageName string) error {
return err
}
// TODO: handle the response here
_, err = d.ImageRemove(context.Background(), imageName, dt.ImageRemoveOptions{})
_, err = d.ImageRemove(context.Background(), imageName, dti.RemoveOptions{})
return err
}

Expand Down Expand Up @@ -210,7 +211,7 @@ func (c *Client) GetAllDockerImages() ([]DockerImage, error) {
return nil, err
}

imageList, err := d.ImageList(context.Background(), dt.ImageListOptions{All: true})
imageList, err := d.ImageList(context.Background(), dti.ListOptions{All: true})
if err != nil {
return nil, fmt.Errorf("error getting image details: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion rocketpool-cli/client/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (c *Client) InstallService(verbose bool, noDeps bool, version string, path
func (c *Client) InstallUpdateTracker(verbose bool, version string, useLocalInstaller bool) error {
// Get installation script flags
flags := []string{
"-v", fmt.Sprintf("%s", shellescape.Quote(version)),
"-v", shellescape.Quote(version),
}

var script []byte
Expand Down
14 changes: 0 additions & 14 deletions rocketpool-cli/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"

"github.com/alessio/shellescape"
"github.com/rocket-pool/node-manager-core/api/types"
"github.com/rocket-pool/smartnode/v2/shared/config"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -98,16 +97,3 @@ func SaveConfig(cfg *config.SmartNodeConfig, directory string, filename string)

return nil
}

// Parse and augment the status of a client into a human-readable format
func getClientStatusString(clientStatus types.ClientStatus) string {
if clientStatus.IsSynced {
return "synced and ready"
}

if clientStatus.IsWorking {
return fmt.Sprintf("syncing (%.2f%%)", SyncRatioToPercent(clientStatus.SyncProgress))
}

return fmt.Sprintf("unavailable (%s)", clientStatus.Error)
}
79 changes: 0 additions & 79 deletions rocketpool-cli/commands/node/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/goccy/go-json"
"github.com/mitchellh/go-homedir"
"github.com/rocket-pool/node-manager-core/beacon"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v2"

"github.com/rocket-pool/node-manager-core/eth"
nmc_utils "github.com/rocket-pool/node-manager-core/utils"
"github.com/rocket-pool/node-manager-core/utils/math"
"github.com/rocket-pool/smartnode/v2/rocketpool-cli/client"
"github.com/rocket-pool/smartnode/v2/rocketpool-cli/utils"
"github.com/rocket-pool/smartnode/v2/rocketpool-cli/utils/tx"
"github.com/rocket-pool/smartnode/v2/shared/config"
"github.com/rocket-pool/smartnode/v2/shared/types/api"
)

const (
Expand Down Expand Up @@ -199,7 +193,6 @@ func promptTimezone() string {
// Prompt for country
country := ""
for {
timezone = ""
country = utils.Prompt("Please enter a country / continent from the list above:", "^.+$", "Please enter a country / continent from the list above:")

exists := false
Expand Down Expand Up @@ -259,7 +252,6 @@ func promptTimezone() string {
// Prompt for region
region := ""
for {
timezone = ""
region = utils.Prompt("Please enter a region from the list above:", "^.+$", "Please enter a region from the list above:")

exists := false
Expand Down Expand Up @@ -328,77 +320,6 @@ func promptMinNodeFee(networkCurrentNodeFee, networkMinNodeFee float64) float64

}

// Prompt for the password to a solo validator key as part of migration
func promptForSoloKeyPassword(cfg *config.SmartNodeConfig, pubkey beacon.ValidatorPubkey) (string, error) {

// Check for the custom key directory
customKeyDir, err := homedir.Expand(cfg.GetCustomKeyPath())
if err != nil {
return "", fmt.Errorf("error expanding custom keys directory: %w", err)
}
info, err := os.Stat(customKeyDir)
if os.IsNotExist(err) || !info.IsDir() {
return "", nil
}

// Get the custom keystore files
files, err := os.ReadDir(customKeyDir)
if err != nil {
return "", fmt.Errorf("error enumerating custom keystores: %w", err)
}
if len(files) == 0 {
return "", nil
}

// Get the pubkeys for the custom keystores
pubkeyPasswords := map[string]string{}
for _, file := range files {
// Read the file
bytes, err := os.ReadFile(filepath.Join(customKeyDir, file.Name()))
if err != nil {
return "", fmt.Errorf("error reading custom keystore %s: %w", file.Name(), err)
}

// Deserialize it
keystore := api.ValidatorKeystore{}
err = json.Unmarshal(bytes, &keystore)
if err != nil {
return "", fmt.Errorf("error deserializing custom keystore %s: %w", file.Name(), err)
}

if keystore.Pubkey == pubkey {
// Found it, prompt for the password
password := utils.PromptPassword(
fmt.Sprintf("Please enter the password that the keystore for %s was encrypted with:", pubkey.Hex()), "^.*$", "",
)

formattedPubkey := strings.ToUpper(nmc_utils.RemovePrefix(pubkey.Hex()))
pubkeyPasswords[formattedPubkey] = password

fmt.Println()
break
}
}

if len(pubkeyPasswords) == 0 {
return "", fmt.Errorf("couldn't find the keystore for validator %s in the custom-keys directory; if you want to import this key into the Smart Node stack, you will need to put its keystore file into custom-keys first", pubkey.HexWithPrefix())
}

// Store it in the file
fileBytes, err := yaml.Marshal(pubkeyPasswords)
if err != nil {
return "", fmt.Errorf("error serializing keystore passwords file: %w", err)
}
passwordFile := cfg.GetCustomKeyPasswordFilePath()
err = os.WriteFile(passwordFile, fileBytes, 0600)
if err != nil {
return "", fmt.Errorf("error writing keystore passwords file: %w", err)
}

return passwordFile, nil

}

func SwapRpl(c *cli.Context, rp *client.Client, amountWei *big.Int) error {
// Get the TX
response, err := rp.Api.Node.SwapRpl(amountWei)
Expand Down
3 changes: 1 addition & 2 deletions rocketpool-cli/commands/odao/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ func getProposals(c *cli.Context, stateFilter string) error {
if bytes.Equal(proposal.ProposerAddress.Bytes(), member.Address.Bytes()) {
fmt.Printf("%d: %s - Proposed by: %s (%s)\n", proposal.ID, proposal.Message, member.ID, proposal.ProposerAddress)
printed = true
break
}
printed = true
break
}
if !printed {
fmt.Printf("%d: %s - Proposed by: %s (no longer on the Oracle DAO)\n", proposal.ID, proposal.Message, proposal.ProposerAddress)
Expand Down
2 changes: 2 additions & 0 deletions rocketpool-cli/commands/service/config/cfg-form.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type parameterizedFormItem struct {
item tview.FormItem
}

/*
func registerEnableCheckbox(param *config.Parameter[bool], checkbox *tview.Checkbox, form *Form, items []*parameterizedFormItem) {
checkbox.SetChangedFunc(func(checked bool) {
param.Value = checked
Expand All @@ -29,6 +30,7 @@ func registerEnableCheckbox(param *config.Parameter[bool], checkbox *tview.Check
}
})
}
*/

// Create a list of form items based on a set of parameters
func createParameterizedFormItems(params []config.IParameter, descriptionBox *tview.TextView) []*parameterizedFormItem {
Expand Down
6 changes: 0 additions & 6 deletions rocketpool-cli/commands/service/config/pseudomodal.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ type Pseudomodal struct {

// The currently selected form (for vertical layouts)
selected int

// A fixed width for the description box (0 for auto)
descriptionWidth int

// The collection of descriptions for each button, to be displayed in the description box
buttonDescriptions []string
}

// NewPseudomodal returns a new modal message window.
Expand Down
7 changes: 0 additions & 7 deletions rocketpool-cli/commands/service/config/review-native-page.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ import (
// Constants
const reviewNativePageID string = "review-native-settings"

// The changed settings review page
type ReviewNativePage struct {
md *mainDisplay
changedSettings []*config.ChangedSection
page *page
}

// Create a page to review any changes
func NewReviewNativePage(md *mainDisplay, oldConfig *snCfg.SmartNodeConfig, newConfig *snCfg.SmartNodeConfig) *ReviewPage {
var changedSettings []*config.ChangedSection
Expand Down
37 changes: 0 additions & 37 deletions rocketpool-cli/commands/service/config/step-random-bn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,6 @@ import (
const randomBnPrysmID string = "step-random-bn-prysm"
const randomBnID string = "step-random-bn"

func createRandomPrysmStep(wiz *wizard, currentStep int, totalSteps int, goodOptions []*config.ParameterOption[config.BeaconNode]) *choiceWizardStep {
helperText := "You have been randomly assigned to Prysm for your Beacon Node.\n\n[orange]NOTE: Prysm currently has a very high representation of the Beacon Chain. For the health of the network and the overall safety of your funds, please consider choosing a client with a lower representation. Please visit https://clientdiversity.org to learn more."

show := func(modal *choiceModalLayout) {
wiz.md.setPage(modal.page)
modal.focus(0)
}

done := func(buttonIndex int, buttonLabel string) {
if buttonIndex == 0 {
selectRandomBn(goodOptions, false, wiz, currentStep, totalSteps)
} else {
wiz.checkpointSyncProviderModal.show()
}
}

back := func() {
wiz.localBnModal.show()
}

return newChoiceStep(
wiz,
currentStep,
totalSteps,
helperText,
[]string{"Choose Another Random Client", "Keep Prysm"},
[]string{},
76,
"Beacon Node > Selection",
DirectionalModalHorizontal,
show,
done,
back,
randomBnPrysmID,
)
}

func createRandomBnStep(wiz *wizard, currentStep int, totalSteps int, goodOptions []*config.ParameterOption[config.BeaconNode]) *choiceWizardStep {
var selectedClientName string
selectedClient := wiz.md.Config.LocalBeaconClient.BeaconNode.Value
Expand Down
4 changes: 0 additions & 4 deletions rocketpool-cli/commands/service/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@ type settingsPage interface {
handleLayoutChanged()
getPage() *page
}

type wizardStep interface {
show()
}
1 change: 0 additions & 1 deletion rocketpool-cli/commands/service/config/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type wizard struct {
// Step 5 - BN settings
localBnModal *choiceWizardStep
localBnRandomModal *choiceWizardStep
localBnRandomPrysmModal *choiceWizardStep
localBnPrysmWarning *choiceWizardStep
localBnTekuWarning *choiceWizardStep
checkpointSyncProviderModal *textBoxWizardStep
Expand Down
6 changes: 0 additions & 6 deletions rocketpool-cli/commands/service/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"math"
"strings"
"time"

"github.com/urfave/cli/v2"

Expand All @@ -22,11 +21,6 @@ func SyncRatioToPercent(in float64) float64 {
// TODO: INCORPORATE THIS
}

// Settings
const (
ethClientRecentBlockThreshold time.Duration = 5 * time.Minute
)

func printClientStatus(status *types.ClientStatus, name string) {

if status.Error != "" {
Expand Down
2 changes: 1 addition & 1 deletion rocketpool-cli/commands/wallet/bip39/mnemonic-validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (mv *MnemonicValidator) Filled() bool {

func (mv *MnemonicValidator) Finalize() (string, error) {

if mv.Filled() == false {
if !mv.Filled() {
return "", errors.New("Not enough words were entered.")
}

Expand Down
11 changes: 0 additions & 11 deletions rocketpool-cli/commands/wallet/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,3 @@ func promptForCustomKeyPasswords(cfg *config.SmartNodeConfig, testOnly bool) (st

return passwordFile, nil
}

// Deletes the custom key password file
func deleteCustomKeyPasswordFile(passwordFile string) error {
_, err := os.Stat(passwordFile)
if os.IsNotExist(err) {
return nil
}

err = os.Remove(passwordFile)
return err
}
2 changes: 1 addition & 1 deletion rocketpool-cli/rocketpool-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ ______ _ _ ______ _

err := validateFlags(c)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
fmt.Fprint(os.Stderr, err.Error())
os.Exit(1)
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ type minipoolCanChangeCredsContext struct {

mnemonic string
minipoolAddress common.Address
mpMgr *minipool.MinipoolManager
mpv3 *minipool.MinipoolV3
}

Expand Down
4 changes: 0 additions & 4 deletions rocketpool-daemon/api/node/get-snapshot-proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/gorilla/mux"
batch "github.com/rocket-pool/batch-query"
"github.com/rocket-pool/rocketpool-go/v2/node"
"github.com/rocket-pool/rocketpool-go/v2/rocketpool"

"github.com/rocket-pool/node-manager-core/api/server"
"github.com/rocket-pool/node-manager-core/api/types"
Expand Down Expand Up @@ -49,10 +47,8 @@ func (f *nodeGetSnapshotProposalsContextFactory) RegisterRoute(router *mux.Route

type nodeGetSnapshotProposalsContext struct {
handler *NodeHandler
rp *rocketpool.RocketPool

activeOnly bool
node *node.Node
}

func (c *nodeGetSnapshotProposalsContext) PrepareData(data *api.NodeGetSnapshotProposalsData, opts *bind.TransactOpts) (types.ResponseStatus, error) {
Expand Down
5 changes: 0 additions & 5 deletions rocketpool-daemon/api/node/get-snapshot-voting-power.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/gorilla/mux"
"github.com/rocket-pool/rocketpool-go/v2/node"
"github.com/rocket-pool/rocketpool-go/v2/rocketpool"

"github.com/rocket-pool/node-manager-core/api/server"
"github.com/rocket-pool/node-manager-core/api/types"
Expand Down Expand Up @@ -41,9 +39,6 @@ func (f *nodeGetSnapshotVotingPowerContextFactory) RegisterRoute(router *mux.Rou

type nodeGetSnapshotVotingPowerContext struct {
handler *NodeHandler
rp *rocketpool.RocketPool

node *node.Node
}

func (c *nodeGetSnapshotVotingPowerContext) PrepareData(data *api.NodeGetSnapshotVotingPowerData, opts *bind.TransactOpts) (types.ResponseStatus, error) {
Expand Down
Loading

0 comments on commit 9a237d9

Please sign in to comment.