Skip to content
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

feat: mapped accounts #436

Merged
merged 31 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (s *AppTestSuite) initTestZone() {
BaseDenom: "uatom",
MultiSend: false,
LiquidityModule: true,
Is_118: true,
}
s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone)

Expand All @@ -94,6 +95,7 @@ func (s *AppTestSuite) initTestZone() {
BaseDenom: "uatom",
MultiSend: false,
LiquidityModule: false,
Is_118: true,
}
s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone)

Expand All @@ -106,6 +108,7 @@ func (s *AppTestSuite) initTestZone() {
BaseDenom: "uosmo",
MultiSend: false,
LiquidityModule: true,
Is_118: true,
}
s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone)
// uni-5 zone
Expand All @@ -117,6 +120,7 @@ func (s *AppTestSuite) initTestZone() {
BaseDenom: "ujunox",
MultiSend: false,
LiquidityModule: true,
Is_118: true,
}
s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone)

Expand Down
134 changes: 134 additions & 0 deletions docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,136 @@ paths:
type: string
tags:
- Msg
/quicksilver/interchainstaking/v1/mapped_addresses/{address}:
get:
summary: >-
MappedAccounts provides data on the mapped accounts for a given user
over different host chains.
operationId: MappedAccounts
responses:
'200':
description: A successful response.
schema:
type: object
properties:
RemoteAddressMap:
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:
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: address
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
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
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/zone/{chain_id}:
get:
summary: Zone provides meta data on a specific zone.
Expand Down Expand Up @@ -2607,6 +2737,8 @@ paths:
type: boolean
return_to_sender:
type: boolean
is_118:
type: boolean
stats:
type: object
properties:
Expand Down Expand Up @@ -2888,6 +3020,8 @@ paths:
type: boolean
return_to_sender:
type: boolean
is_118:
type: boolean
stats:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ message Zone {
bool unbonding_enabled = 25;
bool deposits_enabled = 26;
bool return_to_sender = 27;
bool is_118 = 28;
}

message ICAAccount {
Expand Down
15 changes: 15 additions & 0 deletions proto/quicksilver/interchainstaking/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ service Query {
"/quicksilver/interchainstaking/v1/zones/"
"{chain_id}/redelegation_records";
}

// 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}";
}
}

message Statistics {
Expand Down Expand Up @@ -184,3 +189,13 @@ message QueryRedelegationRecordsResponse {
repeated RedelegationRecord redelegations = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

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;
}
15 changes: 15 additions & 0 deletions utils/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ func GenerateRandomHash() []byte {
func GenerateRandomHashAsHex() string {
return hex.EncodeToString(GenerateRandomHash())
}

// GenerateRandomBytes returns securely generated random bytes.
// It will return an error if the system's secure random
// number generator fails to function correctly, in which
// case the caller should not continue.
func GenerateRandomBytes(n int) ([]byte, error) {
b := make([]byte, n)
_, err := rand.Read(b)
// Note that err == nil only if we read len(b) bytes.
if err != nil {
return nil, err
}

return b, nil
}
1 change: 1 addition & 0 deletions x/airdrop/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (s *KeeperTestSuite) initTestZone() {
AccountPrefix: "cosmos",
LocalDenom: "uqatom",
BaseDenom: "uatom",
Is_118: true,
}

s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone)
Expand Down
3 changes: 3 additions & 0 deletions x/claimsmanager/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (s *KeeperTestSuite) initTestZone() {
UnbondingEnabled: false,
LiquidityModule: true,
Decimals: 6,
Is_118: true,
}
s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone)

Expand All @@ -93,6 +94,7 @@ func (s *KeeperTestSuite) initTestZone() {
UnbondingEnabled: false,
LiquidityModule: true,
Decimals: 6,
Is_118: true,
}
s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone)

Expand All @@ -107,6 +109,7 @@ func (s *KeeperTestSuite) initTestZone() {
UnbondingEnabled: false,
LiquidityModule: true,
Decimals: 6,
Is_118: true,
}
s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone)
}
2 changes: 2 additions & 0 deletions x/interchainstaking/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
Tvl: sdk.ZeroDec(),
UnbondingPeriod: 0,
MessagesPerTx: 0,
Is_118: true,
}
zone.Validators = append(zone.Validators,
&types.Validator{ValoperAddress: "cosmosvaloper14lultfckehtszvzw4ehu0apvsr77afvyju5zzy", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000), Score: sdk.ZeroDec()},
Expand Down Expand Up @@ -163,6 +164,7 @@ func (s *IntegrationTestSuite) ZonesEqual(zoneA, zoneB types.Zone) bool {
for i := range zoneA.Validators {
s.Require().Equal(zoneA.Validators[i], zoneB.Validators[i])
}
s.Require().Equal(zoneA.Is_118, zoneB.Is_118)

return true
}
Expand Down
35 changes: 35 additions & 0 deletions x/interchainstaking/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func GetQueryCmd() *cobra.Command {
GetCmdZones(),
GetDelegatorIntentCmd(),
GetDepositAccountCmd(),
GetMappedAccountsCmd(),
)

return cmd
Expand Down Expand Up @@ -144,3 +145,37 @@ func GetDepositAccountCmd() *cobra.Command {

return cmd
}

// GetMappedAccountsCmd returns the mapped account for the given address.
func GetMappedAccountsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "mapped-accounts [address]",
Short: "Query mapped accounts for a given address.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

// args
address := args[0]

queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryMappedAccountsRequest{
Address: address,
}

res, err := queryClient.MappedAccounts(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
Loading