Skip to content

Commit

Permalink
feat: add query qgb evm address by valoper address command (backport #…
Browse files Browse the repository at this point in the history
…2524) (#2527)

This is an automatic backport of pull request #2524 done by
[Mergify](https://mergify.com).


---


<details>
<summary>Mergify commands and options</summary>

<br />

More conditions and actions can be found in the
[documentation](https://docs.mergify.com/).

You can also trigger Mergify actions by commenting on this pull request:

- `@Mergifyio refresh` will re-evaluate the rules
- `@Mergifyio rebase` will rebase this PR on its base branch
- `@Mergifyio update` will merge the base branch into this PR
- `@Mergifyio backport <destination>` will backport this PR on
`<destination>` branch

Additionally, on Mergify [dashboard](https://dashboard.mergify.com) you
can:

- look at your merge queues
- generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com
</details>

Co-authored-by: CHAMI Rachid <[email protected]>
  • Loading branch information
mergify[bot] and rach-id authored Sep 18, 2023
1 parent cc93118 commit 36d908c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 30 additions & 1 deletion x/qgb/client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func GetQueryCmd() *cobra.Command {
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdQueryAttestationByNonce())
cmd.AddCommand(CmdQueryAttestationByNonce(), CmdQueryEVMAddress())

return cmd
}
Expand Down Expand Up @@ -76,6 +76,35 @@ func CmdQueryAttestationByNonce() *cobra.Command {
return cmd
}

func CmdQueryEVMAddress() *cobra.Command {
cmd := &cobra.Command{
Use: "evm <validator_valoper_address>",
Short: "query the evm address corresponding to a validator bech32 valoper address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.EVMAddress(
cmd.Context(),
&types.QueryEVMAddressRequest{ValidatorAddress: args[0]},
)
if err != nil {
return err
}
if res.EvmAddress == "" {
return types.ErrEVMAddressNotFound
}
fmt.Println(res.EvmAddress)
return nil
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// unmarshallAttestation unmarshal a wrapper protobuf `Any` type to an `AttestationRequestI`.
func unmarshallAttestation(attestation *codectypes.Any) (types.AttestationRequestI, error) {
var unmarshalledAttestation types.AttestationRequestI
Expand Down
1 change: 1 addition & 0 deletions x/qgb/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ var (
ErrUnknownAttestationType = errors.Register(ModuleName, 35, "unknown attestation type")
ErrEVMAddressNotHex = errors.Register(ModuleName, 36, "the provided evm address is not a valid hex address")
ErrEVMAddressAlreadyExists = errors.Register(ModuleName, 37, "the provided evm address already exists")
ErrEVMAddressNotFound = errors.Register(ModuleName, 38, "EVM address not found")
)

0 comments on commit 36d908c

Please sign in to comment.