-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #370 from icon-project/feat/new-api-sockets
feat: socket apis for admin dashboard support.
- Loading branch information
Showing
27 changed files
with
1,137 additions
and
566 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
type DebugState struct { | ||
*dbState | ||
app *appState | ||
chain string | ||
fromHeight uint64 | ||
toHeight uint64 | ||
} | ||
|
||
func newDebugState(a *appState) *DebugState { | ||
db := newDBState() | ||
return &DebugState{ | ||
app: a, | ||
dbState: db, | ||
} | ||
} | ||
|
||
func debugCmd(a *appState) *cobra.Command { | ||
state := newDebugState(a) | ||
debug := &cobra.Command{ | ||
Use: "debug", | ||
Short: "Commands for troubleshooting the relayer", | ||
Aliases: []string{"dbg"}, | ||
Example: strings.TrimSpace(fmt.Sprintf(`$ %s dbg [command]`, appName)), | ||
} | ||
|
||
heightCmd := &cobra.Command{ | ||
Use: "height", | ||
Short: "Get latest height of the chain", | ||
} | ||
heightCmd.AddCommand(state.getLatestHeight(a)) | ||
|
||
blockCmd := &cobra.Command{ | ||
Use: "block", | ||
Short: "Get latest processed block of the chain", | ||
} | ||
blockCmd.AddCommand(state.getLatestProcessedBlock(a)) | ||
|
||
queryCmd := &cobra.Command{ | ||
Use: "query", | ||
Short: "Query block range", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
client, err := state.getSocket(a) | ||
if err != nil { | ||
return err | ||
} | ||
defer client.Close() | ||
if state.server != nil { | ||
defer state.server.Close() | ||
} | ||
res, err := client.QueryBlockRange(state.chain, state.fromHeight, state.toHeight) | ||
if err != nil { | ||
return err | ||
} | ||
printLabels("Chain", "Sn", "Event Type", "height", "data") | ||
for _, msg := range res.Msgs { | ||
printValues(state.chain, msg.Sn.Text(10), msg.EventType, msg.MessageHeight, hex.EncodeToString(msg.Data)) | ||
} | ||
return nil | ||
}, | ||
} | ||
queryCmd.Flags().StringVar(&state.chain, "chain", "", "Chain ID") | ||
queryCmd.Flags().Uint64Var(&state.fromHeight, "from_height", 0, "From Height") | ||
queryCmd.Flags().Uint64Var(&state.toHeight, "to_height", 0, "To height") | ||
queryCmd.MarkFlagsRequiredTogether("chain", "from_height", "to_height") | ||
debug.AddCommand(heightCmd, blockCmd, queryCmd) | ||
|
||
return debug | ||
} | ||
|
||
func (c *DebugState) getLatestHeight(app *appState) *cobra.Command { | ||
getLatestHeight := &cobra.Command{ | ||
Use: "get", | ||
Short: "Get the latest chain height", | ||
Aliases: []string{"g"}, | ||
Example: strings.TrimSpace(fmt.Sprintf(`$ %s dbg height get --chain [chain-id]`, appName)), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
client, err := c.getSocket(app) | ||
if err != nil { | ||
return err | ||
} | ||
defer client.Close() | ||
if c.server != nil { | ||
defer c.server.Close() | ||
} | ||
res, err := client.GetLatestHeight(c.chain) | ||
if err != nil { | ||
return err | ||
} | ||
printLabels("Chain", "Latest Chain Height") | ||
printValues(c.chain, res.Height) | ||
return nil | ||
}, | ||
} | ||
getLatestHeight.Flags().StringVar(&c.chain, "chain", "", "Chain ID") | ||
getLatestHeight.MarkFlagRequired("chain") | ||
return getLatestHeight | ||
} | ||
|
||
func (c *DebugState) getLatestProcessedBlock(app *appState) *cobra.Command { | ||
getLatestHeight := &cobra.Command{ | ||
Use: "get", | ||
Short: "Get the last processed block height", | ||
Aliases: []string{"g"}, | ||
Example: strings.TrimSpace(fmt.Sprintf(`$ %s dbg block get --chain [chain-id]`, appName)), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
client, err := c.getSocket(app) | ||
if err != nil { | ||
return err | ||
} | ||
defer client.Close() | ||
if c.server != nil { | ||
defer c.server.Close() | ||
} | ||
res, err := client.GetBlock(c.chain) | ||
if err != nil { | ||
fmt.Println(err) | ||
return err | ||
} | ||
printLabels("Chain", "Last Processed Block") | ||
for _, block := range res { | ||
printValues(block.Chain, block.CheckPointHeight) | ||
} | ||
return nil | ||
}, | ||
} | ||
getLatestHeight.Flags().StringVar(&c.chain, "chain", "", "Chain ID") | ||
return getLatestHeight | ||
} |
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
Oops, something went wrong.