Skip to content

Commit

Permalink
Add get block command (#104)
Browse files Browse the repository at this point in the history
* outline of sudo commands

* sequencer commands defaults and utils refactor

* add fee asset commands

* add ibc relayer commands, refactor commands and sub commands

* add mint command

* add sudo address change command, update existing sudo commands to have fixed args for required inputs

* refactor directories

* move sudo package

* add validator update command

* command description updates

* file renaming and small logging message updates

* small internal sequencer file cleanup

* move default sequencer id to cmd package

* add get block command

* cleanup from main merge

* bump dependencies, fix typos
  • Loading branch information
sambukowski committed Jun 12, 2024
1 parent 30efe51 commit ca8036c
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 123 deletions.
56 changes: 56 additions & 0 deletions cmd/sequencer/block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package sequencer

import (
"strconv"

"github.com/astria/astria-cli-go/cmd"
"github.com/astria/astria-cli-go/internal/sequencer"
"github.com/astria/astria-cli-go/internal/ui"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// blockCmd represents the block command
var blockCmd = &cobra.Command{
Use: "block [height]",
Short: "Get sequencer block at specified height.",
Args: cobra.ExactArgs(1),
Run: blockCmdHandler,
}

func init() {
SequencerCmd.AddCommand(blockCmd)

flagHandler := cmd.CreateCliFlagHandler(blockCmd, cmd.EnvPrefix)
flagHandler.BindStringPFlag("sequencer-url", "u", DefaultSequencerURL, "The URL of the sequencer to retrieve the block from.")
flagHandler.BindBoolFlag("json", false, "Output the block in JSON format.")
}

func blockCmdHandler(c *cobra.Command, args []string) {
flagHandler := cmd.CreateCliFlagHandler(c, cmd.EnvPrefix)
url := flagHandler.GetValue("sequencer-url")
printJSON := flagHandler.GetValue("json") == "true"

h := args[0]
height, err := strconv.ParseInt(h, 10, 64)
if err != nil {
log.WithError(err).Error("Error parsing block height to int64")
panic(err)
}

opts := sequencer.BlockOpts{
SequencerURL: url,
BlockHeight: height,
}
block, err := sequencer.GetBlock(opts)
if err != nil {
log.WithError(err)
return
}

printer := ui.ResultsPrinter{
Data: block,
PrintJSON: printJSON,
}
printer.Render()
}
57 changes: 31 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ module github.com/astria/astria-cli-go
go 1.22.2

require (
buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.1-20240528191859-2caf2e8901b3.1
buf.build/gen/go/astria/protocol-apis/protocolbuffers/go v1.34.1-20240528191859-59fd0d703e09.1
buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.2-20240607202648-0eefaac9f5b8.2
buf.build/gen/go/astria/protocol-apis/protocolbuffers/go v1.34.2-20240609195145-373c666381d1.2
github.com/99designs/keyring v1.2.2
github.com/astriaorg/go-sequencer-client v0.4.0
github.com/astriaorg/go-sequencer-client v0.4.1
github.com/gdamore/tcell/v2 v2.7.4
github.com/pelletier/go-toml/v2 v2.2.2
github.com/pterm/pterm v0.12.79
github.com/rivo/tview v0.0.0-20240505185119-ed116790de0f
github.com/rivo/tview v0.0.0-20240524063012-037df494fb76
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
golang.org/x/crypto v0.23.0
golang.org/x/crypto v0.24.0
)

require (
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
)

require (
Expand All @@ -27,15 +32,15 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft v0.38.7 // indirect
github.com/cometbft/cometbft v0.38.7
github.com/cometbft/cometbft-db v0.12.0 // indirect
github.com/containerd/console v1.0.4 // indirect
github.com/cosmos/gogoproto v1.4.12 // indirect
github.com/cosmos/gogoproto v1.5.0 // indirect
github.com/danieljoos/wincred v1.2.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
Expand All @@ -45,7 +50,7 @@ require (
github.com/dvsekhvalnov/jose2go v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gdamore/encoding v1.0.1 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/getsentry/sentry-go v0.28.1 // indirect
github.com/go-kit/kit v0.13.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
Expand All @@ -59,34 +64,34 @@ require (
github.com/google/flatbuffers v24.3.25+incompatible // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gorilla/websocket v1.5.2 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.8.14 // indirect
github.com/linxGnu/grocksdb v1.9.1 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/petermattis/goid v0.0.0-20240503122002-4b96552b8156 // indirect
github.com/petermattis/goid v0.0.0-20240607163614-bb94eb51e7a7 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.14.0 // indirect
github.com/prometheus/common v0.54.0 // indirect
github.com/prometheus/procfs v0.15.1 // 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.12.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
Expand All @@ -95,19 +100,19 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.etcd.io/bbolt v1.4.0-alpha.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240509183442-62759503f434 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.1 // indirect
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240610135401-a8a62080eff3 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit ca8036c

Please sign in to comment.