Skip to content

Commit

Permalink
batch 2 of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Nov 12, 2024
1 parent 9ffe420 commit a66341b
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 117 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ issues:
- errcheck
- dupl
- gosec
- gocritic
- path-except: _test\.go
linters:
- forbidigo
18 changes: 9 additions & 9 deletions cmd/stakercli/daemon/daemoncommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ var withdrawableTransactionsCmd = cli.Command{

func checkHealth(ctx *cli.Context) error {
daemonAddress := ctx.String(stakingDaemonAddressFlag)
client, err := dc.NewStakerServiceJsonRPCClient(daemonAddress)
client, err := dc.NewStakerServiceJSONRPCClient(daemonAddress)
if err != nil {
return err
}
Expand All @@ -260,7 +260,7 @@ func checkHealth(ctx *cli.Context) error {

func listOutputs(ctx *cli.Context) error {
daemonAddress := ctx.String(stakingDaemonAddressFlag)
client, err := dc.NewStakerServiceJsonRPCClient(daemonAddress)
client, err := dc.NewStakerServiceJSONRPCClient(daemonAddress)
if err != nil {
return err
}
Expand All @@ -280,7 +280,7 @@ func listOutputs(ctx *cli.Context) error {

func babylonFinalityProviders(ctx *cli.Context) error {
daemonAddress := ctx.String(stakingDaemonAddressFlag)
client, err := dc.NewStakerServiceJsonRPCClient(daemonAddress)
client, err := dc.NewStakerServiceJSONRPCClient(daemonAddress)
if err != nil {
return err
}
Expand Down Expand Up @@ -312,7 +312,7 @@ func babylonFinalityProviders(ctx *cli.Context) error {

func stake(ctx *cli.Context) error {
daemonAddress := ctx.String(stakingDaemonAddressFlag)
client, err := dc.NewStakerServiceJsonRPCClient(daemonAddress)
client, err := dc.NewStakerServiceJSONRPCClient(daemonAddress)
if err != nil {
return err
}
Expand All @@ -337,7 +337,7 @@ func stake(ctx *cli.Context) error {

func unstake(ctx *cli.Context) error {
daemonAddress := ctx.String(stakingDaemonAddressFlag)
client, err := dc.NewStakerServiceJsonRPCClient(daemonAddress)
client, err := dc.NewStakerServiceJSONRPCClient(daemonAddress)
if err != nil {
return err
}
Expand All @@ -358,7 +358,7 @@ func unstake(ctx *cli.Context) error {

func unbond(ctx *cli.Context) error {
daemonAddress := ctx.String(stakingDaemonAddressFlag)
client, err := dc.NewStakerServiceJsonRPCClient(daemonAddress)
client, err := dc.NewStakerServiceJSONRPCClient(daemonAddress)
if err != nil {
return err
}
Expand All @@ -379,7 +379,7 @@ func unbond(ctx *cli.Context) error {

func stakingDetails(ctx *cli.Context) error {
daemonAddress := ctx.String(stakingDaemonAddressFlag)
client, err := dc.NewStakerServiceJsonRPCClient(daemonAddress)
client, err := dc.NewStakerServiceJSONRPCClient(daemonAddress)
if err != nil {
return err
}
Expand All @@ -400,7 +400,7 @@ func stakingDetails(ctx *cli.Context) error {

func listStakingTransactions(ctx *cli.Context) error {
daemonAddress := ctx.String(stakingDaemonAddressFlag)
client, err := dc.NewStakerServiceJsonRPCClient(daemonAddress)
client, err := dc.NewStakerServiceJSONRPCClient(daemonAddress)
if err != nil {
return err
}
Expand Down Expand Up @@ -432,7 +432,7 @@ func listStakingTransactions(ctx *cli.Context) error {

func withdrawableTransactions(ctx *cli.Context) error {
daemonAddress := ctx.String(stakingDaemonAddressFlag)
client, err := dc.NewStakerServiceJsonRPCClient(daemonAddress)
client, err := dc.NewStakerServiceJSONRPCClient(daemonAddress)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/stakercli/transaction/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func genSchnorPubKeyHex(t *testing.T) string {
return hex.EncodeToString(schnorr.SerializePubKey(btcPub))
}

func appRunWithOutput(r *rand.Rand, t *testing.T, app *cli.App, arguments []string) (output string) {
func appRunWithOutput(r *rand.Rand, t *testing.T, app *cli.App, arguments []string) string {
outPut := filepath.Join(t.TempDir(), fmt.Sprintf("%s-out.txt", datagen.GenRandomHexStr(r, 10)))
outPutFile, err := os.Create(outPut)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/stakerd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func main() {
defer pprof.StopCPUProfile()
}

dbBackend, err := scfg.GetDbBackend(cfg.DBConfig)
dbBackend, err := scfg.GetDBBackend(cfg.DBConfig)

if err != nil {
err = fmt.Errorf("failed to load db backend: %w", err)
Expand Down
14 changes: 7 additions & 7 deletions itest/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ type TestManager struct {
MinerAddr btcutil.Address
wg *sync.WaitGroup
serviceAddress string
StakerClient *dc.StakerServiceJsonRPCClient
StakerClient *dc.StakerServiceJSONRPCClient
CovenantPrivKeys []*btcec.PrivateKey
BitcoindHandler *BitcoindTestHandler
TestRpcClient *rpcclient.Client
Expand Down Expand Up @@ -298,7 +298,7 @@ func StartManager(
require.NoError(t, err)
cfg.DBConfig.DBPath = dbTempDir

dbbackend, err := stakercfg.GetDbBackend(cfg.DBConfig)
dbbackend, err := stakercfg.GetDBBackend(cfg.DBConfig)
require.NoError(t, err)

m := metrics.NewStakerMetrics()
Expand Down Expand Up @@ -346,7 +346,7 @@ func StartManager(
// Wait for the server to start
time.Sleep(3 * time.Second)

stakerClient, err := dc.NewStakerServiceJsonRPCClient("tcp://" + addressString)
stakerClient, err := dc.NewStakerServiceJSONRPCClient("tcp://" + addressString)
require.NoError(t, err)

return &TestManager{
Expand Down Expand Up @@ -398,7 +398,7 @@ func (tm *TestManager) RestartAppWithAction(t *testing.T, ctx context.Context, c
logger.SetLevel(logrus.DebugLevel)
logger.Out = os.Stdout

dbbackend, err := stakercfg.GetDbBackend(tm.Config.DBConfig)
dbbackend, err := stakercfg.GetDBBackend(tm.Config.DBConfig)
require.NoError(t, err)
m := metrics.NewStakerMetrics()
stakerApp, err := staker.NewStakerAppFromConfig(tm.Config, logger, zapLogger, dbbackend, m)
Expand Down Expand Up @@ -426,7 +426,7 @@ func (tm *TestManager) RestartAppWithAction(t *testing.T, ctx context.Context, c
tm.wg = &wg
tm.Db = dbbackend
tm.Sa = stakerApp
stakerClient, err := dc.NewStakerServiceJsonRPCClient("tcp://" + tm.serviceAddress)
stakerClient, err := dc.NewStakerServiceJSONRPCClient("tcp://" + tm.serviceAddress)
require.NoError(t, err)
tm.StakerClient = stakerClient
}
Expand Down Expand Up @@ -1757,7 +1757,7 @@ func TestBitcoindWalletRpcApi(t *testing.T) {
scfg.ActiveNetParams = chaincfg.RegressionNetParams

// Create wallet controller the same way as in staker program
wc, err := walletcontroller.NewRpcWalletController(&scfg)
wc, err := walletcontroller.NewRPCWalletController(&scfg)
require.NoError(t, err)

outputs, err := wc.ListOutputs(true)
Expand Down Expand Up @@ -1825,7 +1825,7 @@ func TestBitcoindWalletBip322Signing(t *testing.T) {
segwitAddress, err := c.GetNewAddress("")
require.NoError(t, err)

controller, err := walletcontroller.NewRpcWalletController(cfg)
controller, err := walletcontroller.NewRPCWalletController(cfg)
require.NoError(t, err)

err = controller.UnlockWallet(30)
Expand Down
2 changes: 1 addition & 1 deletion staker/stakerapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func NewStakerAppFromConfig(
) (*StakerApp, error) {
// TODO: If we want to support multiple wallet types, this is most probably the place to decide
// on concrete implementation
walletClient, err := walletcontroller.NewRpcWalletController(config)
walletClient, err := walletcontroller.NewRPCWalletController(config)
if err != nil {
return nil, err
}
Expand Down
14 changes: 8 additions & 6 deletions stakercfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func DefaultWalletRPCConfig() WalletRPCConfig {
}
}

type JsonRpcServerConfig struct {
type JSONRPCServerConfig struct {
RawRPCListeners []string `long:"rpclisten" description:"Add an interface/port/socket to listen for RPC connections"`
}

Expand Down Expand Up @@ -166,7 +166,7 @@ type Config struct {

MetricsConfig *MetricsConfig `group:"metricsconfig" namespace:"metricsconfig"`

JsonRPCServerConfig *JsonRpcServerConfig
JSONRPCServerConfig *JSONRPCServerConfig

ActiveNetParams chaincfg.Params

Expand Down Expand Up @@ -337,6 +337,8 @@ func LoadConfig() (*Config, *logrus.Logger, *zap.Logger, error) {
// ValidateConfig check the given configuration to be sane. This makes sure no
// illegal values or combination of values are set. All file system paths are
// normalized. The cleaned up config is returned on success.
//
//nolint:gocyclo
func ValidateConfig(cfg Config) (*Config, error) {
// If the provided stakerd directory is not the default, we'll modify the
// path to all of the files and directories that will live within it.
Expand Down Expand Up @@ -491,10 +493,10 @@ func ValidateConfig(cfg Config) (*Config, error) {

// At least one RPCListener is required. So listen on localhost per
// default.
if len(cfg.JsonRPCServerConfig.RawRPCListeners) == 0 {
if len(cfg.JSONRPCServerConfig.RawRPCListeners) == 0 {
addr := fmt.Sprintf("localhost:%d", DefaultRPCPort)
cfg.JsonRPCServerConfig.RawRPCListeners = append(
cfg.JsonRPCServerConfig.RawRPCListeners, addr,
cfg.JSONRPCServerConfig.RawRPCListeners = append(
cfg.JSONRPCServerConfig.RawRPCListeners, addr,
)
}

Expand All @@ -507,7 +509,7 @@ func ValidateConfig(cfg Config) (*Config, error) {
// Add default port to all RPC listener addresses if needed and remove
// duplicate addresses.
cfg.RPCListeners, err = lncfg.NormalizeAddresses(
cfg.JsonRPCServerConfig.RawRPCListeners, strconv.Itoa(DefaultRPCPort),
cfg.JSONRPCServerConfig.RawRPCListeners, strconv.Itoa(DefaultRPCPort),
net.ResolveTCPAddr,
)

Expand Down
2 changes: 1 addition & 1 deletion stakercfg/dbcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func DBConfigToBoltBackenCondfig(db *DBConfig) kvdb.BoltBackendConfig {
}
}

func GetDbBackend(cfg *DBConfig) (kvdb.Backend, error) {
func GetDBBackend(cfg *DBConfig) (kvdb.Backend, error) {
boltConfig := DBConfigToBoltBackenCondfig(cfg)
return kvdb.GetBoltBackend(&boltConfig)
}
1 change: 0 additions & 1 deletion stakercfg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func ReadCertFile(rawCert string, certFilePath string) ([]byte, error) {
return nil, err
}
return rpcCert, nil

}
certFile, err := os.Open(certFilePath)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions stakerdb/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package stakerdb
import "errors"

var (
// ErrCorruptedTransactionsDb For some reason, db on disk representation have changed
ErrCorruptedTransactionsDb = errors.New("transactions db is corrupted")
// ErrCorruptedTransactionsDB For some reason, db on disk representation have changed
ErrCorruptedTransactionsDB = errors.New("transactions db is corrupted")

// ErrTransactionNotFound The transaction we try update is not found in db
ErrTransactionNotFound = errors.New("transaction not found")
Expand Down
1 change: 0 additions & 1 deletion stakerdb/paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type paginator struct {
// in pages.
func newPaginator(c kvdb.RCursor, reversed bool,
indexOffset, totalItems uint64) paginator {

return paginator{
cursor: c,
reversed: reversed,
Expand Down
Loading

0 comments on commit a66341b

Please sign in to comment.