Skip to content

Commit

Permalink
feat: chain explorer TUI (#57)
Browse files Browse the repository at this point in the history
* wip ui for explorer

* md renderer

* container ui

* panel key handler

* inputs

* block info

* txn support

* keys references

* reorg files

* fix: linter issues

* truncate very long words

* docs

* tidy deps

* chore: reenable cache
  • Loading branch information
hanchon authored Sep 7, 2024
1 parent 557ecf0 commit 24990fb
Show file tree
Hide file tree
Showing 20 changed files with 830 additions and 53 deletions.
20 changes: 12 additions & 8 deletions cmd/playground/explorer/start.go → cmd/playground/explorer/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (

"github.com/hanchon/hanchond/playground/evmos"
"github.com/hanchon/hanchond/playground/explorer"
"github.com/hanchon/hanchond/playground/explorer/explorerui"
"github.com/hanchon/hanchond/playground/sql"
"github.com/spf13/cobra"
)

// represents the query command
var startCmd = &cobra.Command{
Use: "start",
// ui represents the query command
var uiCmd = &cobra.Command{
Use: "ui",
Args: cobra.ExactArgs(0),
Short: "Start the node explorer",
Run: func(cmd *cobra.Command, _ []string) {
Expand All @@ -31,16 +32,19 @@ var startCmd = &cobra.Command{

// TODO: move the newFromDB to cosmos daemon
e := evmos.NewEvmosFromDB(queries, nodeID)

// TODO: support mainnet and testnet endpoints
ex := explorer.NewLocalExplorerClient(e.Ports.P8545, e.Ports.P1317, e.HomeDir)
if err := ex.ProcessMissingBlocks(int64(startingHeight)); err != nil {
fmt.Println("error getting missing blocks: ", err.Error())

p := explorerui.CreateExplorerTUI(startingHeight, ex)
if _, err := p.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
os.Exit(0)
},
}

func init() {
ExplorerCmd.AddCommand(startCmd)
startCmd.Flags().Int("starting-height", 1, "Starting height to index the chain.")
ExplorerCmd.AddCommand(uiCmd)
uiCmd.Flags().Int("starting-height", 1, "Starting height to index the chain.")
}
11 changes: 0 additions & 11 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ var rootCmd = &cobra.Command{
Long: `Stop re-writing the same scripts one million times`,
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
Expand All @@ -26,16 +24,7 @@ func Execute() {
}

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.hanchond.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

rootCmd.AddCommand(convert.ConvertCmd)
rootCmd.AddCommand(playground.PlaygroundCmd)
}
29 changes: 29 additions & 0 deletions docs/pages/hanchond/playground/explorer/ui.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Block Explorer

The command `playground explorer ui` can be used to run the terminal block explorer.

```bash
hanchond playground explorer ui
```

:::info
The `--node` flag can be used to select RPC provider.

The `--starting-height` flag can be used to start indexing from a height different from 1.
:::

## Features:

- Indexes all the blocks
- Indexes all the transactions
- Gets the block information using the Cosmos and Ethereum endpoints
- Get the transaction Cosmos information
- Get the transaction Ethereum information

## Screenshots:

![Syncing](https://i.imgur.com/4KAlwZp.png)

![Blocks](https://i.imgur.com/kmvCGBN.png)

![Transactions](https://i.imgur.com/mh2a5Mn.png)
37 changes: 31 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module github.com/hanchon/hanchond
go 1.22.2

require (
github.com/charmbracelet/bubbles v0.19.0
github.com/charmbracelet/bubbletea v1.1.0
github.com/charmbracelet/glamour v0.8.0
github.com/charmbracelet/lipgloss v0.13.0
github.com/cosmos/cosmos-sdk v0.47.12
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go/v7 v7.6.0
Expand All @@ -13,7 +17,7 @@ require (
github.com/miguelmota/go-ethereum-hdwallet v0.1.1
github.com/spf13/cobra v1.8.1
github.com/valyala/fasthttp v1.55.0
golang.org/x/crypto v0.24.0
golang.org/x/crypto v0.25.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/text v0.16.0
)
Expand All @@ -31,8 +35,12 @@ require (
github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/alecthomas/chroma/v2 v2.14.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd // indirect
Expand All @@ -42,6 +50,9 @@ require (
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/charmbracelet/x/ansi v0.2.3 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/errors v1.10.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
Expand All @@ -62,8 +73,10 @@ require (
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
Expand All @@ -78,6 +91,7 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
Expand All @@ -99,14 +113,21 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.8.5 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/petermattis/goid v0.0.0-20230518223814-80aa455d8761 // indirect
Expand All @@ -118,9 +139,11 @@ require (
github.com/prometheus/procfs v0.11.0 // indirect
github.com/prometheus/tsdb v0.10.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sahilm/fuzzy v0.1.1 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
Expand All @@ -141,15 +164,17 @@ require (
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/yuin/goldmark v1.7.4 // indirect
github.com/yuin/goldmark-emoji v1.0.3 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.22.0 // indirect
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
Expand Down
Loading

0 comments on commit 24990fb

Please sign in to comment.