-
Notifications
You must be signed in to change notification settings - Fork 0
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
Audit branch #2
base: main
Are you sure you want to change the base?
Audit branch #2
Conversation
|
|
internal/eth/sendtx.go
Outdated
|
||
// init initializes the defaultTimeout variable by reading the DEFAULT_TIMEOUT | ||
// environment variable. If not set or invalid, it defaults to 15 seconds. | ||
func init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest creating a service struct in which you set all the necessary options that are known at the time of creation and will not change (e.g. default timeout, rpcurl, etc.) and fields that must maintain some state (e.g. logger, ethclient, httpclient, etc.). Then attach existing functions to this structure. This will result in fewer parameters in these methods and avoid global state. Your code will also be easier to mock and test.
) | ||
|
||
// Define flag names as constants | ||
const ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this, I'd suggest doing the following:
var (
bidderAddressFlag := &cli.StringFlag{
Name: "bidder-address",
Usage: "Address of the bidder",
EnvVars: []string{"BIDDER_ADDRESS"},
Value: "mev-commit-bidder:13524",
},
// other flags...
)
// Now below you can do:
c.String(bidderAddressFlag.Name)
main.go
Outdated
&cli.StringFlag{ | ||
Name: FlagEnv, | ||
Usage: "Path to .env file", | ||
EnvVars: []string{"ENV_FILE"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using some sort of prefix (maybe PRECONF_BOT
) for all env variables to avoid collisions or so that they already exist.
Value: 15, // Default to 15 seconds | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The c.Context
should be used as parent context in all places where you create a new context. This will help you shutdown the app gracefully.
sendBundle
functioncontext.Background()
withcontext.WithTimeout