Skip to content

Commit

Permalink
use bech32 addresses for mapped address queries; resolves #1719 (#1766)
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-bowman authored Dec 3, 2024
1 parent fe73f54 commit 2be465f
Show file tree
Hide file tree
Showing 6 changed files with 925 additions and 363 deletions.
133 changes: 47 additions & 86 deletions docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2733,7 +2733,9 @@ paths:
get:
summary: >-
ClaimedPercentageByClaimType provides data on the claimed percentage of
a given claim type in a given zone
a
given claim type in a given zone
operationId: ClaimedPercentageByClaimType
responses:
'200':
Expand Down Expand Up @@ -2846,7 +2848,7 @@ paths:
type: string
tags:
- QueryInterchainStaking
/quicksilver/interchainstaking/v1/mapped_addresses/{address}:
/quicksilver/interchainstaking/v1/mapped_addresses/local/{address}:
get:
summary: >-
MappedAccounts provides data on the mapped accounts for a given user
Expand All @@ -2860,39 +2862,10 @@ paths:
schema:
type: object
properties:
RemoteAddressMap:
remote_address_map:
type: object
additionalProperties:
type: string
format: byte
pagination:
type: object
properties:
next_key:
type: string
format: byte
description: |-
next_key is the key to be passed to PageRequest.key to
query the next page most efficiently. It will be empty if
there are no more results.
total:
type: string
format: uint64
title: >-
total is total number of results available if
PageRequest.count_total
was set, its value is undefined otherwise
description: >-
PageResponse is to be embedded in gRPC response messages where
the
corresponding request message has used PageRequest.
message SomeResponse {
repeated Bar results = 1;
PageResponse page = 2;
}
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -2920,62 +2893,50 @@ paths:
in: path
required: true
type: string
- name: pagination.key
description: |-
key is a value returned in PageResponse.next_key to begin
querying the next page most efficiently. Only one of offset or key
should be set.
in: query
required: false
type: string
format: byte
- name: pagination.offset
description: >-
offset is a numeric offset that can be used when key is unavailable.
It is less efficient than using key. Only one of offset or key
should
be set.
in: query
required: false
tags:
- QueryInterchainStaking
/quicksilver/interchainstaking/v1/mapped_addresses/remote/{chain_id}/{remote_address}:
get:
operationId: InverseMappedAccounts
responses:
'200':
description: A successful response.
schema:
type: object
properties:
local_address:
type: string
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: chain_id
in: path
required: true
type: string
format: uint64
- name: pagination.limit
description: >-
limit is the total number of results to be returned in the result
page.
If left empty it will default to a value to be set by each app.
in: query
required: false
- name: remote_address
in: path
required: true
type: string
format: uint64
- name: pagination.count_total
description: >-
count_total is set to true to indicate that the result set should
include
a count of the total number of items available for pagination in
UIs.
count_total is only respected when offset is used. It is ignored
when key
is set.
in: query
required: false
type: boolean
- name: pagination.reverse
description: >-
reverse is set to true if results are to be returned in the
descending order.
Since: cosmos-sdk 0.43
in: query
required: false
type: boolean
tags:
- QueryInterchainStaking
/quicksilver/interchainstaking/v1/users/{user_address}/withdrawal_records:
Expand Down
28 changes: 22 additions & 6 deletions proto/quicksilver/interchainstaking/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,26 @@ service Query {
// MappedAccounts provides data on the mapped accounts for a given user over
// different host chains.
rpc MappedAccounts(QueryMappedAccountsRequest) returns (QueryMappedAccountsResponse) {
option (google.api.http).get = "/quicksilver/interchainstaking/v1/mapped_addresses/{address}";
option (google.api.http).get = "/quicksilver/interchainstaking/v1/mapped_addresses/local/{address}";
}

rpc InverseMappedAccounts(QueryInverseMappedAccountsRequest) returns (QueryInverseMappedAccountsResponse) {
option (google.api.http).get =
"/quicksilver/interchainstaking/v1/"
"mapped_addresses/remote/{chain_id}/{remote_address}";
}

// CLaimedPercentage provides data on the claimed percentage for a given zone
rpc ClaimedPercentage(QueryClaimedPercentageRequest) returns (QueryClaimedPercentageResponse) {
option (google.api.http).get = "/quicksilver/interchainstaking/v1/claimed_percentage/{chain_id}";
}

// ClaimedPercentageByClaimType provides data on the claimed percentage of a given claim type in a given zone
// ClaimedPercentageByClaimType provides data on the claimed percentage of a
// given claim type in a given zone
rpc ClaimedPercentageByClaimType(QueryClaimedPercentageRequest) returns (QueryClaimedPercentageResponse) {
option (google.api.http).get = "/quicksilver/interchainstaking/v1/claimed_percentage/{chain_id}/{claim_type}";
option (google.api.http).get =
"/quicksilver/interchainstaking/v1/"
"claimed_percentage/{chain_id}/{claim_type}";
}
}

Expand Down Expand Up @@ -283,12 +292,19 @@ message QueryRedelegationRecordsResponse {

message QueryMappedAccountsRequest {
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

message QueryMappedAccountsResponse {
map<string, bytes> RemoteAddressMap = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
map<string, string> remote_address_map = 1 [(gogoproto.nullable) = false];
}

message QueryInverseMappedAccountsRequest {
string remote_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string chain_id = 2;
}

message QueryInverseMappedAccountsResponse {
string local_address = 1;
}

message QueryDenyListRequest {
Expand Down
37 changes: 35 additions & 2 deletions x/interchainstaking/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,20 +339,53 @@ func (k *Keeper) MappedAccounts(c context.Context, req *types.QueryMappedAccount

ctx := sdk.UnwrapSDKContext(c)

remoteAddressMap := make(map[string][]byte)
remoteAddressMap := make(map[string]string)
addrBytes, err := addressutils.AccAddressFromBech32(req.Address, sdk.GetConfig().GetBech32AccountAddrPrefix())
if err != nil {
return nil, status.Error(codes.InvalidArgument, "Invalid Address")
}

k.IterateUserMappedAccounts(ctx, addrBytes, func(index int64, chainID string, remoteAddressBytes sdk.AccAddress) (stop bool) {
remoteAddressMap[chainID] = remoteAddressBytes
zone, found := k.GetZone(ctx, chainID)
if !found {
return false
}
encodedAddress, err := addressutils.EncodeAddressToBech32(zone.AccountPrefix, remoteAddressBytes)
if err != nil {
return false
}
remoteAddressMap[zone.ChainId] = encodedAddress
return false
})

return &types.QueryMappedAccountsResponse{RemoteAddressMap: remoteAddressMap}, nil
}

func (k *Keeper) InverseMappedAccounts(c context.Context, req *types.QueryInverseMappedAccountsRequest) (*types.QueryInverseMappedAccountsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(c)

zone, found := k.GetZone(ctx, req.ChainId)
if !found {
return nil, status.Error(codes.NotFound, fmt.Sprintf("no zone found matching %s", req.ChainId))
}

addrBytes, err := addressutils.AccAddressFromBech32(req.RemoteAddress, zone.AccountPrefix)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "Invalid Address")
}

localAddress, ok := k.GetLocalAddressMap(ctx, addrBytes, req.ChainId)
if !ok {
return nil, status.Error(codes.NotFound, fmt.Sprintf("no local address found matching %s", req.ChainId))
}

return &types.QueryInverseMappedAccountsResponse{LocalAddress: localAddress.String()}, nil
}

func (k *Keeper) ValidatorDenyList(c context.Context, req *types.QueryDenyListRequest) (*types.QueryDenyListResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
Expand Down
Loading

0 comments on commit 2be465f

Please sign in to comment.