Skip to content

Commit

Permalink
Jesse/monitor 2 (#177)
Browse files Browse the repository at this point in the history
* monitor 2.0

* consolidate information in one ui container

* fix sparklines

* add views in explorer mode

* changes to explorer view

* remove empty ui blocks

* refractor code

* lint error

* lint errors

* page up and down block select

* update monitor block range

* loading blocks when no row is selected

* working monitor page down

* set provisional upper and lower block

* lint

* default adjustment

* make gen

* make gen-doc

* fix table for tx in explorer

* safe batch size logic

* bindings

* bindings again

* final binding changes

* remove log file

* fix g

* fix page down lag and fix auti batch resize

* add transaction preview

* add transaction page

* add transaction page

* reciept page all good
  • Loading branch information
gatsbyz authored Jan 3, 2024
1 parent 0b50d8d commit aec91f8
Show file tree
Hide file tree
Showing 12 changed files with 840 additions and 459 deletions.
54 changes: 40 additions & 14 deletions cmd/monitor/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
_ "embed"
"fmt"
"strconv"
"sync"
"time"

"github.com/maticnetwork/polygon-cli/util"
Expand All @@ -19,20 +20,51 @@ var (
batchSizeValue string
blockCacheLimit int
intervalStr string

defaultBatchSize = 100
)

// MonitorCmd represents the monitor command
type SafeBatchSize struct {
value int
auto bool // true if batchSize should be set automatically based on the UI
mutex sync.RWMutex
}

func (s *SafeBatchSize) Set(value int, auto bool) {
s.mutex.Lock()
defer s.mutex.Unlock()
s.value = value
s.auto = auto
}

func (s *SafeBatchSize) Get() int {
s.mutex.RLock()
defer s.mutex.RUnlock()
return s.value
}

func (s *SafeBatchSize) Auto() bool {
s.mutex.RLock()
defer s.mutex.RUnlock()
return s.auto
}

var MonitorCmd = &cobra.Command{
Use: "monitor",
Short: "Monitor blocks using a JSON-RPC endpoint.",
Long: usage,
Args: cobra.NoArgs,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// By default, hide logs from `polycli monitor`.
verbosityFlag := cmd.Flag("verbosity")
if verbosityFlag != nil && !verbosityFlag.Changed {
util.SetLogLevel(int(util.Silent))
}
prettyFlag := cmd.Flag("pretty-logs")
if prettyFlag != nil && prettyFlag.Value.String() == "true" {
return util.SetLogMode(util.Console)
}
return nil
},
PreRunE: func(cmd *cobra.Command, args []string) error {
return checkFlags()
Expand All @@ -45,34 +77,28 @@ var MonitorCmd = &cobra.Command{
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().IntVarP(&blockCacheLimit, "cache-limit", "c", 100, "Number of cached blocks for the LRU block data structure (Min 100)")
MonitorCmd.PersistentFlags().IntVarP(&blockCacheLimit, "cache-limit", "c", 200, "Number of cached blocks for the LRU block data structure (Min 100)")
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
batchSize.Set(defaultBatchSize, true) // -1 value and true for auto mode
} 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")
batchSizeInt, err := strconv.Atoi(batchSizeValue)
if batchSizeInt == 0 || err != nil {
return fmt.Errorf("invalid batch-size provided")
}
batchSize.Set(batchSizeInt, false) // specific value and false for auto mode
}

// Check batch-size flag.
Expand Down
Loading

0 comments on commit aec91f8

Please sign in to comment.