-
Notifications
You must be signed in to change notification settings - Fork 179
fix: update get tss address query #4560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,68 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strconv" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/client" | ||
| "github.com/cosmos/cosmos-sdk/client/flags" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/zeta-chain/node/pkg/chains" | ||
| "github.com/zeta-chain/node/x/observer/types" | ||
| ) | ||
|
|
||
| // btcNetworks lists all supported Bitcoin networks for TSS address display. | ||
| var btcNetworks = []struct { | ||
| Name string | ||
| ChainID int64 | ||
| }{ | ||
| {"mainnet", chains.BitcoinMainnet.ChainId}, | ||
| {"testnet3", chains.BitcoinTestnet.ChainId}, | ||
| {"signet", chains.BitcoinSignetTestnet.ChainId}, | ||
| {"testnet4", chains.BitcoinTestnet4.ChainId}, | ||
| {"regtest", chains.BitcoinRegtest.ChainId}, | ||
| } | ||
|
|
||
| func CmdGetTssAddress() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "get-tss-address [bitcoinChainId]]", | ||
| Use: "get-tss-address [bitcoinChainId]", | ||
| Short: "Query current tss address", | ||
| Args: cobra.MaximumNArgs(1), | ||
| Long: `Query current TSS addresses for EVM, Sui, and Bitcoin. | ||
|
|
||
| Without arguments, prints the EVM and Sui addresses once, and the Bitcoin address for all | ||
| supported networks (mainnet, testnet3, signet, testnet4, regtest). | ||
|
|
||
| With a bitcoinChainId argument, prints only the Bitcoin address for that specific chain. | ||
|
|
||
| Examples: | ||
| zetacored query observer get-tss-address | ||
| zetacored query observer get-tss-address 18333`, | ||
| Args: cobra.MaximumNArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
| clientCtx, err := client.GetClientQueryContext(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| queryClient := types.NewQueryClient(clientCtx) | ||
| params := &types.QueryGetTssAddressRequest{} | ||
|
|
||
| // If a specific chain ID is provided, use the original single-query behavior | ||
| if len(args) == 1 { | ||
| bitcoinChainID, err := strconv.ParseInt(args[0], 10, 64) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| params.BitcoinChainId = bitcoinChainID | ||
| } | ||
|
|
||
| res, err := queryClient.GetTssAddress(cmd.Context(), params) | ||
| if err != nil { | ||
| return err | ||
| res, err := queryClient.GetTssAddress(cmd.Context(), &types.QueryGetTssAddressRequest{ | ||
| BitcoinChainId: bitcoinChainID, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return clientCtx.PrintProto(res) | ||
| } | ||
|
|
||
| return clientCtx.PrintProto(res) | ||
| // No args: print EVM/Sui once, then BTC for all networks | ||
| return printAllTSSAddresses(cmd, queryClient) | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -44,6 +71,36 @@ func CmdGetTssAddress() *cobra.Command { | |
| return cmd | ||
| } | ||
|
|
||
| // printAllTSSAddresses queries TSS addresses for all BTC networks and prints them. | ||
| func printAllTSSAddresses(cmd *cobra.Command, queryClient types.QueryClient) error { | ||
| // Query with first BTC network to get EVM and Sui addresses | ||
| first := btcNetworks[0] | ||
| res, err := queryClient.GetTssAddress(cmd.Context(), &types.QueryGetTssAddressRequest{ | ||
| BitcoinChainId: first.ChainID, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| fmt.Printf("eth: %s\n", res.Eth) | ||
| fmt.Printf("sui: %s\n", res.Sui) | ||
| fmt.Printf("btc (%s, %d): %s\n", first.Name, first.ChainID, res.Btc) | ||
|
|
||
| // Query remaining BTC networks | ||
| for _, net := range btcNetworks[1:] { | ||
| btcRes, err := queryClient.GetTssAddress(cmd.Context(), &types.QueryGetTssAddressRequest{ | ||
| BitcoinChainId: net.ChainID, | ||
| }) | ||
| if err != nil { | ||
| fmt.Printf("btc (%s, %d): error: %v\n", net.Name, net.ChainID, err) | ||
| continue | ||
| } | ||
| fmt.Printf("btc (%s, %d): %s\n", net.Name, net.ChainID, btcRes.Btc) | ||
|
Comment on lines
+75
to
+98
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, locate and examine the file
find . -name "query_get_tss_address.go" -type fRepository: zeta-chain/node Length of output: 107 🏁 Script executed: # Read the file to see the actual code and context
cat -n x/observer/client/cli/query_get_tss_address.go | head -120Repository: zeta-chain/node Length of output: 4519 🏁 Script executed: # Search for other CLI query functions to see the pattern used for output
rg "OutOrStdout\|Printf" x/observer/client/cli/ -n -A 2 -B 2 | head -100Repository: zeta-chain/node Length of output: 41 🏁 Script executed: # Check for Cobra usage patterns in this CLI directory
fd "\.go$" x/observer/client/cli/ -x grep -l "cmd.Out" {} \;Repository: zeta-chain/node Length of output: 41 🏁 Script executed: # Search for output patterns in CLI queries
rg "Print|Printf|OutOrStdout|cmd\.Out" x/observer/client/cli/ --type go -n | head -50Repository: zeta-chain/node Length of output: 2848 🏁 Script executed: # Check other query commands in the same directory
find x/observer/client/cli -name "query_*.go" -type fRepository: zeta-chain/node Length of output: 716 🏁 Script executed: # Look at how other commands handle output - check a few similar query files
cat -n x/observer/client/cli/query.go | head -100Repository: zeta-chain/node Length of output: 1697 🏁 Script executed: # Check if clientCtx.PrintProto is the standard pattern used elsewhere
rg "clientCtx\.Print|PrintProto" x/observer/client/cli/ --type go -n -B 2 -A 2 | head -80Repository: zeta-chain/node Length of output: 4093 Make the no-arg path use the same output layer as the single-chain branch. Lines 85–98 use direct 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| return nil | ||
|
Comment on lines
+89
to
+101
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not return success after partial network failures. Lines 94-96 downgrade per-network query failures to text and continue, but Line 101 still returns 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| func CmdGetTssAddressByFinalizedZetaHeight() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "get-historical-tss-address [finalizedZetaHeight] [bitcoinChainId]", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Help text does not match the single-chain behavior.
Line 36 says this mode prints only the Bitcoin address, but Lines 55-61 still print the full query response. Please either narrow the output or update the help text to describe the actual behavior.
Suggested wording
Also applies to: 55-61
🤖 Prompt for AI Agents