Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
Move logger to comand PreRun
Browse files Browse the repository at this point in the history
  • Loading branch information
nmlinaric committed Nov 2, 2021
1 parent 3b27177 commit cf13449
Show file tree
Hide file tree
Showing 31 changed files with 141 additions and 72 deletions.
5 changes: 5 additions & 0 deletions chains/evm/cli/account/generate-key-pair.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package account

import (
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/ChainSafe/chainbridge-core/crypto/secp256k1"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand All @@ -11,6 +12,10 @@ var generateKeyPairCmd = &cobra.Command{
Short: "Generate bridge keystore (Secp256k1)",
Long: "The generate subcommand is used to generate the bridge keystore. If no options are specified, a Secp256k1 key will be made.",
RunE: generateKeyPair,
PreRun: func(cmd *cobra.Command, args []string) {
confirmTransfer(cmd, args)
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
}

func generateKeyPair(cmd *cobra.Command, args []string) error {
Expand Down
12 changes: 8 additions & 4 deletions chains/evm/cli/account/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ChainSafe/chainbridge-core/chains/evm/calls"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/utils"
"github.com/ChainSafe/chainbridge-core/chains/evm/evmclient"
"github.com/ChainSafe/chainbridge-core/chains/evm/evmgaspricer"
Expand All @@ -19,10 +20,13 @@ import (
)

var transferBaseCurrencyCmd = &cobra.Command{
Use: "transfer",
Short: "Transfer base currency",
Long: "The generate subcommand is used to transfer the base currency",
PreRun: confirmTransfer,
Use: "transfer",
Short: "Transfer base currency",
Long: "The generate subcommand is used to transfer the base currency",
PreRun: func(cmd *cobra.Command, args []string) {
confirmTransfer(cmd, args)
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
txFabric := evmtransaction.NewTransaction
return TransferBaseCurrency(cmd, args, txFabric, &evmgaspricer.LondonGasPriceDeterminant{})
Expand Down
8 changes: 5 additions & 3 deletions chains/evm/cli/admin/add-admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package admin

import (
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/writer"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
Expand All @@ -11,7 +11,10 @@ var addAdminCmd = &cobra.Command{
Use: "add-admin",
Short: "Add a new admin",
Long: "Add a new admin",
Run: addAdmin,
PreRun: func(cmd *cobra.Command, args []string) {
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
Run: addAdmin,
}

func init() {
Expand All @@ -25,7 +28,6 @@ func addAdmin(cmd *cobra.Command, args []string) {
Adding admin
Admin address: %s
Bridge address: %s`, Admin, Bridge)
writer.WriteCliDataToFile(cmd)
}

/*
Expand Down
6 changes: 4 additions & 2 deletions chains/evm/cli/admin/add-relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/ChainSafe/chainbridge-core/chains/evm/calls"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/utils"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/writer"
"github.com/ChainSafe/chainbridge-core/chains/evm/evmclient"
"github.com/ChainSafe/chainbridge-core/chains/evm/evmgaspricer"
"github.com/ChainSafe/chainbridge-core/chains/evm/evmtransaction"
Expand All @@ -22,6 +22,9 @@ var addRelayerCmd = &cobra.Command{
Use: "add-relayer",
Short: "Add a new relayer",
Long: "Add a new relayer",
PreRun: func(cmd *cobra.Command, args []string) {
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
return AddRelayerEVMCMD(cmd, args, evmtransaction.NewTransaction, &evmgaspricer.LondonGasPriceDeterminant{})
},
Expand Down Expand Up @@ -94,6 +97,5 @@ Bridge address: %s`, Relayer, Bridge)
log.Info().Msgf("%s added as relayer", relayerAddr)
return err
}
writer.WriteCliDataToFile(cmd)
return nil
}
6 changes: 4 additions & 2 deletions chains/evm/cli/admin/is-relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/ChainSafe/chainbridge-core/chains/evm/calls"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/writer"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/ChainSafe/chainbridge-core/chains/evm/evmclient"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -18,6 +18,9 @@ var isRelayerCmd = &cobra.Command{
Use: "is-relayer",
Short: "Check if an address is registered as a relayer",
Long: "Check if an address is registered as a relayer",
PreRun: func(cmd *cobra.Command, args []string) {
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
return IsRelayer(cmd, args)
},
Expand Down Expand Up @@ -111,6 +114,5 @@ func IsRelayer(cmd *cobra.Command, args []string) error {
} else {
log.Info().Msgf("Address %s is relayer", relayerAddr.String())
}
writer.WriteCliDataToFile(cmd)
return nil
}
8 changes: 5 additions & 3 deletions chains/evm/cli/admin/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package admin

import (
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/writer"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
Expand All @@ -11,7 +11,10 @@ var pauseCmd = &cobra.Command{
Use: "pause",
Short: "Pause deposits and proposals",
Long: "Pause deposits and proposals",
Run: pause,
PreRun: func(cmd *cobra.Command, args []string) {
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
Run: pause,
}

func init() {
Expand All @@ -23,7 +26,6 @@ func pause(cmd *cobra.Command, args []string) {
log.Debug().Msgf(`
Pausing
Bridge address: %s`, Bridge)
writer.WriteCliDataToFile(cmd)
}

/*
Expand Down
8 changes: 5 additions & 3 deletions chains/evm/cli/admin/remove-admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package admin

import (
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/writer"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
Expand All @@ -11,7 +11,10 @@ var removeAdminCmd = &cobra.Command{
Use: "remove-admin",
Short: "Remove an existing admin",
Long: "Remove an existing admin",
Run: removeAdmin,
PreRun: func(cmd *cobra.Command, args []string) {
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
Run: removeAdmin,
}

func init() {
Expand All @@ -26,7 +29,6 @@ func removeAdmin(cmd *cobra.Command, args []string) {
Removing admin
Admin address: %s
Bridge address: %s`, Admin, Bridge)
writer.WriteCliDataToFile(cmd)
}

/*
Expand Down
8 changes: 5 additions & 3 deletions chains/evm/cli/admin/remove-relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package admin

import (
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/writer"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
Expand All @@ -11,7 +11,10 @@ var removeRelayerCmd = &cobra.Command{
Use: "remove-relayer",
Short: "Remove a relayer",
Long: "Remove a relayer",
Run: removeRelayer,
PreRun: func(cmd *cobra.Command, args []string) {
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
Run: removeRelayer,
}

func init() {
Expand All @@ -25,7 +28,6 @@ func removeRelayer(cmd *cobra.Command, args []string) {
Removing relayer
Relayer address: %s
Bridge address: %s`, Relayer, Bridge)
writer.WriteCliDataToFile(cmd)
}

/*
Expand Down
6 changes: 4 additions & 2 deletions chains/evm/cli/admin/set-deposit-nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/ChainSafe/chainbridge-core/chains/evm/calls"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/utils"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/writer"
"github.com/ChainSafe/chainbridge-core/chains/evm/evmclient"
"github.com/ChainSafe/chainbridge-core/chains/evm/evmgaspricer"
"github.com/ChainSafe/chainbridge-core/chains/evm/evmtransaction"
Expand All @@ -22,6 +22,9 @@ var setDepositNonceCmd = &cobra.Command{
Long: `Set the deposit nonce
This nonce cannot be less than what is currently stored in the contract`,
PreRun: func(cmd *cobra.Command, args []string) {
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
txFabric := evmtransaction.NewTransaction
return SetDepositNonceEVMCMD(cmd, args, txFabric, &evmgaspricer.LondonGasPriceDeterminant{})
Expand Down Expand Up @@ -92,6 +95,5 @@ Bridge Address: %s`, DomainID, DepositNonce, Bridge)
return err
}
log.Info().Msgf("[domain ID: %v] successfully set nonce: %v at address: %s", DomainID, DepositNonce, bridgeAddr.String())
writer.WriteCliDataToFile(cmd)
return nil
}
8 changes: 5 additions & 3 deletions chains/evm/cli/admin/set-fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package admin

import (
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/writer"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
Expand All @@ -11,7 +11,10 @@ var setFeeCmd = &cobra.Command{
Use: "set-fee",
Short: "Set a new fee for deposits",
Long: "Set a new fee for deposits",
Run: setFee,
PreRun: func(cmd *cobra.Command, args []string) {
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
Run: setFee,
}

func init() {
Expand All @@ -25,7 +28,6 @@ func setFee(cmd *cobra.Command, args []string) {
Setting new fee
Fee amount: %s
Bridge address: %s`, Fee, Bridge)
writer.WriteCliDataToFile(cmd)
}

/*
Expand Down
6 changes: 5 additions & 1 deletion chains/evm/cli/admin/set-threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package admin

import (
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
Expand All @@ -10,7 +11,10 @@ var setThresholdCmd = &cobra.Command{
Use: "set-threshold",
Short: "Set a new relayer vote threshold",
Long: "Set a new relayer vote threshold",
Run: setThreshold,
PreRun: func(cmd *cobra.Command, args []string) {
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
Run: setThreshold,
}

func init() {
Expand Down
8 changes: 5 additions & 3 deletions chains/evm/cli/admin/unpause.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package admin

import (
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/writer"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
Expand All @@ -11,7 +11,10 @@ var unpauseCmd = &cobra.Command{
Use: "unpause",
Short: "Unpause deposits and proposals",
Long: "Unpause deposits and proposals",
Run: unpause,
PreRun: func(cmd *cobra.Command, args []string) {
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
Run: unpause,
}

func init() {
Expand All @@ -23,7 +26,6 @@ func unpause(cmd *cobra.Command, args []string) {
log.Debug().Msgf(`
Unpausing
Bridge address: %s`, Bridge)
writer.WriteCliDataToFile(cmd)
}

/*
Expand Down
8 changes: 5 additions & 3 deletions chains/evm/cli/admin/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package admin

import (
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/writer"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
Expand All @@ -11,7 +11,10 @@ var withdrawCmd = &cobra.Command{
Use: "withdraw",
Short: "Withdraw tokens from the handler contract",
Long: "Withdraw tokens from the handler contract",
Run: withdraw,
PreRun: func(cmd *cobra.Command, args []string) {
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
Run: withdraw,
}

func init() {
Expand All @@ -35,7 +38,6 @@ Handler: %s
Token: %s
Recipient: %s
Decimals: %v`, Amount, TokenID, Bridge, Handler, Token, Recipient, Decimals)
writer.WriteCliDataToFile(cmd)
}

/*
Expand Down
8 changes: 5 additions & 3 deletions chains/evm/cli/bridge/cancel-proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package bridge

import (
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/writer"
"github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
Expand All @@ -11,7 +11,10 @@ var cancelProposalCmd = &cobra.Command{
Use: "cancel-proposal",
Short: "Cancel an expired proposal",
Long: "Cancel an expired proposal",
Run: cancelProposal,
PreRun: func(cmd *cobra.Command, args []string) {
logger.LoggerMetadata(cmd.Name(), cmd.Flags())
},
Run: cancelProposal,
}

func init() {
Expand All @@ -31,7 +34,6 @@ Chain ID: %d
Deposit nonce: %d
DataHash: %s
`, Bridge, DomainID, DepositNonce, DataHash)
writer.WriteCliDataToFile(cmd)
}

/*
Expand Down
Loading

0 comments on commit cf13449

Please sign in to comment.