-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: transform
url
arg into a flag (#138)
* chore(loadtest): url is now a flag instead of an arg * chore: rename url flag into rpc-endpoint like cast * chore: gen doc * chore: update doc and test script * chore: rename `rpc-endpoint` into `rpc-url` * chore: move `ValidateUrl` to `util` pkg * chore: same thing for monitor cmd * chore: update doc * chore: same thing for `rpcfuzz` * chore: clean up * chore: more clean up * chore: remove url arg from uniswapv3 loadtest cmd * chore: gen doc * chore: add zerolog setup * chore: update usage
- Loading branch information
Showing
16 changed files
with
387 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package monitor | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/maticnetwork/polygon-cli/util" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
//go:embed usage.md | ||
usage string | ||
|
||
// flags | ||
rpcUrl string | ||
batchSizeValue string | ||
intervalStr string | ||
) | ||
|
||
// MonitorCmd represents the monitor command | ||
var MonitorCmd = &cobra.Command{ | ||
Use: "monitor", | ||
Short: "Monitor blocks using a JSON-RPC endpoint.", | ||
Long: usage, | ||
Args: cobra.NoArgs, | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return checkFlags() | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return monitor(cmd.Context()) | ||
}, | ||
} | ||
|
||
func init() { | ||
MonitorCmd.PersistentFlags().StringVarP(&rpcUrl, "rpc-url", "r", "http://localhost:8545", "The RPC endpoint url") | ||
MonitorCmd.PersistentFlags().StringVarP(&batchSizeValue, "batch-size", "b", "auto", "Number of requests per batch") | ||
MonitorCmd.PersistentFlags().StringVarP(&intervalStr, "interval", "i", "5s", "Amount of time between batch block rpc calls") | ||
} | ||
|
||
func checkFlags() (err error) { | ||
// Check rpc-url flag. | ||
if err = util.ValidateUrl(rpcUrl); err != nil { | ||
return | ||
} | ||
|
||
// Check interval duration flag. | ||
interval, err = time.ParseDuration(intervalStr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Check batch-size flag. | ||
if batchSizeValue == "auto" { | ||
batchSize = -1 | ||
} else { | ||
batchSize, err = strconv.Atoi(batchSizeValue) | ||
if batchSize == 0 { | ||
return fmt.Errorf("batch-size can't be equal to zero") | ||
} | ||
if err != nil { | ||
// Failed to convert to int, handle the error | ||
return fmt.Errorf("batch-size needs to be an integer") | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.