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: CLI account-locked-duration #1292

Merged
merged 32 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7d39255
Add panic guard, bug fix
ValarDragon Feb 27, 2022
7323906
Add AccountLockedDuration RPC service
CmpHDL Apr 18, 2022
85f1c3c
Add AccountLockedDuration Request & Response Messages
CmpHDL Apr 18, 2022
c728281
Generated protofiles for x/lockup, added AccountLockedDuration RPC, R…
CmpHDL Apr 18, 2022
38d1180
Update CLI Request & Response for account-locked-duration
CmpHDL Apr 18, 2022
3fbb784
Add account_locked_duration to querier types
CmpHDL Apr 18, 2022
3c6c6d1
Add comments & Update lockup keeper iterator to include AccountLockIt…
CmpHDL Apr 19, 2022
4728be4
Add GetAccountLockedDuration to lockup store and use new iterator
CmpHDL Apr 19, 2022
5a4d7a1
Fix method comment namiing
CmpHDL Apr 19, 2022
e8bf393
Add missing AccountLockedDuration method to grpc_query.go/
CmpHDL Apr 19, 2022
93fd8c3
Add documentation for rpc AccountLockedDuration
CmpHDL Apr 19, 2022
d09b708
Fixed weird rebase error.
CmpHDL Apr 19, 2022
7a830c6
Refactored Keeper into Querier
CmpHDL Apr 19, 2022
5a15cd5
Readd GetCmdAccountLockedDuration to QueryTree
CmpHDL Apr 19, 2022
df3b68f
Fix occurred mispelling to satisfy linter
CmpHDL Apr 19, 2022
316fe43
Update x/lockup/client/cli/query.go
CmpHDL Apr 20, 2022
1108c1a
Update x/lockup/client/cli/query.go
CmpHDL Apr 20, 2022
066727f
Update x/lockup/keeper/grpc_query.go
CmpHDL Apr 20, 2022
9bd7ff6
Update x/lockup/keeper/iterator.go
CmpHDL Apr 20, 2022
dfe4272
Update x/lockup/keeper/store.go
CmpHDL Apr 20, 2022
50b1acc
Update x/lockup/keeper/store.go
CmpHDL Apr 20, 2022
5d31a26
Remove TODOs.
CmpHDL Apr 20, 2022
e92923d
Add PR to changelog Unreleased
CmpHDL Apr 20, 2022
fe85f63
Fix initialization order of interatorDuration.
CmpHDL Apr 20, 2022
c08a216
Add example address to long description of GetCmdAccountUnlockingCoin…
CmpHDL Apr 23, 2022
44350e1
Fixed Bech32 address in long description and function call.
CmpHDL Apr 25, 2022
da8ce5f
Swap Long for Example
CmpHDL Apr 25, 2022
2678e1b
Update CHANGELOG
CmpHDL Apr 25, 2022
d635e43
Add example for GetCmdAccountLockedDuration
CmpHDL Apr 26, 2022
ad523ac
Remove example from wrong function
CmpHDL Apr 26, 2022
ce4a764
Fix comment for AccountLockIteratorShorterThanDuration
CmpHDL Apr 26, 2022
77891d4
Merge branch 'main' into 7.0.2-T756
czarcas7ic Apr 27, 2022
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
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

* [#1292](https://github.com/osmosis-labs/osmosis/pull/1292) Feat: CLI account-locked-duration
CmpHDL marked this conversation as resolved.
Show resolved Hide resolved

### Features

* [#1244](https://github.com/osmosis-labs/osmosis/pull/1244) Refactor `x/gamm`'s `ExitSwapExternAmountOut`.
Expand Down Expand Up @@ -107,7 +109,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Minor improvements & Bug Fixes

* [#1022](https://github.com/osmosis-labs/osmosis/pull/1022) upgrade iavl to v0.17.3-osmo-v4 - fix state export at an old height
CmpHDL marked this conversation as resolved.
Show resolved Hide resolved
* [#988](https://github.com/osmosis-labs/osmosis/pull/988) Make `SuperfluidUndelegationsByDelegator` query also return synthetic locks
* [#988](https://github.com/osmosis-labs/osmosis/pull/988) Make `SuperfluidUndelegationsByDelegator` query also return synthetic locks
* [#984](https://github.com/osmosis-labs/osmosis/pull/984) Add wasm support to Dockerfile

## [v7.0.2 - Carbon](https://github.com/osmosis-labs/osmosis/releases/tag/v7.0.2)
Expand Down Expand Up @@ -285,7 +287,7 @@ Upgrade instructions for node operators can be found [here](https://github.com/o
* [\#610](https://github.com/osmosis-labs/osmosis/pull/610) Upgrade to Cosmos SDK v0.44.x
* Numerous large updates, such as making module accounts be 32 bytes, Rosetta support, etc.
* Adds & integrates the [Authz module](https://github.com/cosmos/cosmos-sdk/tree/master/x/authz/spec)
See: [SDK v0.43.0 Release Notes](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.43.0) For more details
See: [SDK v0.43.0 Release Notes](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.43.0) For more details
* [\#610](https://github.com/osmosis-labs/osmosis/pull/610) Upgrade to IBC-v2
* [\#560](https://github.com/osmosis-labs/osmosis/pull/560) Implements Osmosis [prop32](https://www.mintscan.io/osmosis/proposals/32) -- clawing back the final 20% of unclaimed osmo and ion airdrop.
* [\#394](https://github.com/osmosis-labs/osmosis/pull/394) Allow whitelisted tx fee tokens based on conversion rate to OSMO
Expand Down
20 changes: 20 additions & 0 deletions proto/osmosis/lockup/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ service Query {
option (google.api.http).get =
"/osmosis/lockup/v1beta1/account_locked_longer_duration/{owner}";
}

// Returns account locked records with a specific duration
rpc AccountLockedDuration(AccountLockedDurationRequest)
returns (AccountLockedDurationResponse) {
option (google.api.http).get =
"/osmosis/lockup/v1beta1/account_locked_duration/{owner}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since AccountLockedDurationRequest defines the query params, is there a point in having {owner} as part of the resource URL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on this? AccountLockedPastTimeDenom, AccountLockedPastTimeNotUnlockingOnlyRequest, and most of the locked RPC commands have the {owner} within the resource URL, I had assumed it was for the address parameter and maintained practice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexanderbez I'm not very familiar with this RPC library - does it make sense for us to create an issue and remove potentially redundant {owner}?

Copy link
Member

@mattverse mattverse Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These urls are mostly used in front end, but we definitely don't need to have them both in the request url and the request itself. However, I don't know if it's worth changing considering the fact that all the urls and queries in the frontend would have to be updated along as well

}

// Returns account locked records with longer duration excluding tokens
// started unlocking
rpc AccountLockedLongerDurationNotUnlockingOnly(
Expand Down Expand Up @@ -243,6 +251,18 @@ message AccountLockedLongerDurationResponse {
repeated PeriodLock locks = 1 [ (gogoproto.nullable) = false ];
};

message AccountLockedDurationRequest {
CmpHDL marked this conversation as resolved.
Show resolved Hide resolved
string owner = 1 [ (gogoproto.moretags) = "yaml:\"owner\"" ];
google.protobuf.Duration duration = 2 [
(gogoproto.stdduration) = true,
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"duration\""
];
};
message AccountLockedDurationResponse {
CmpHDL marked this conversation as resolved.
Show resolved Hide resolved
repeated PeriodLock locks = 1 [ (gogoproto.nullable) = false ];
};

message AccountLockedLongerDurationNotUnlockingOnlyRequest {
string owner = 1 [ (gogoproto.moretags) = "yaml:\"owner\"" ];
google.protobuf.Duration duration = 2 [
Expand Down
44 changes: 43 additions & 1 deletion x/lockup/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
GetCmdTotalLockedByDenom(),
GetCmdOutputLocksJson(),
GetCmdSyntheticLockupsByLockupID(),
GetCmdAccountLockedDuration(),
)

return cmd
Expand Down Expand Up @@ -170,7 +171,7 @@ func GetCmdAccountUnlockingCoins() *cobra.Command {
fmt.Sprintf(`Query account's unlocking coins.

Example:
$ %s query lockup account-unlocking-coins <address>
$ %s query lockup account-unlocking-coins osmo1yl6hdjhmkf37639730gffanpzndzdpmhxy9ep3
`,
version.AppName,
),
Expand Down Expand Up @@ -535,6 +536,47 @@ $ %s query lockup account-locked-longer-duration <address> <duration>
return cmd
}

// GetCmdAccountLockedDuration returns account locked records with a specific duration.
func GetCmdAccountLockedDuration() *cobra.Command {
cmd := &cobra.Command{
Use: "account-locked-duration <address> <duration>",
Short: "Query account locked records with a specific duration",
Long: strings.TrimSpace(
fmt.Sprintf(`Query account locked records with a specific duration.
Example:
$ %s query lockup account-locked-duration <address> <duration>
CmpHDL marked this conversation as resolved.
Show resolved Hide resolved
CmpHDL marked this conversation as resolved.
Show resolved Hide resolved
`,
version.AppName,
),
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

duration, err := time.ParseDuration(args[1])
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.AccountLockedDuration(cmd.Context(), &types.AccountLockedDurationRequest{Owner: args[0], Duration: duration})
CmpHDL marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdAccountLockedLongerDurationNotUnlockingOnly returns account locked records with longer duration from unlocking only queue.
func GetCmdAccountLockedLongerDurationNotUnlockingOnly() *cobra.Command {
cmd := &cobra.Command{
Expand Down
20 changes: 20 additions & 0 deletions x/lockup/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,26 @@ func (q Querier) AccountLockedLongerDurationDenom(goCtx context.Context, req *ty
return &types.AccountLockedLongerDurationDenomResponse{Locks: locks}, nil
}

// AccountLockedDuration returns the account locked with the specified duration.
func (q Querier) AccountLockedDuration(goCtx context.Context, req *types.AccountLockedDurationRequest) (*types.AccountLockedDurationResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}

ctx := sdk.UnwrapSDKContext(goCtx)

owner, err := sdk.AccAddressFromBech32(req.Owner)
if err != nil {
return nil, err
}

locks := q.Keeper.GetAccountLockedDuration(ctx, owner, req.Duration)
return &types.AccountLockedDurationResponse{Locks: locks}, nil
}

// AccountLockedPastTimeNotUnlockingOnly Returns locked records of an account with unlock time beyond timestamp excluding tokens started unlocking.
func (q Querier) AccountLockedPastTimeNotUnlockingOnly(goCtx context.Context, req *types.AccountLockedPastTimeNotUnlockingOnlyRequest) (*types.AccountLockedPastTimeNotUnlockingOnlyResponse, error) {
if req == nil {
Expand Down
10 changes: 8 additions & 2 deletions x/lockup/keeper/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func (k Keeper) iteratorBeforeTime(ctx sdk.Context, prefix []byte, maxTime time.
}

func (k Keeper) iteratorDuration(ctx sdk.Context, prefix []byte, duration time.Duration) sdk.Iterator {
store := ctx.KVStore(k.storeKey)
durationKey := getDurationKey(duration)
key := combineKeys(prefix, durationKey)
store := ctx.KVStore(k.storeKey)
return sdk.KVStorePrefixIterator(store, key)
}

Expand Down Expand Up @@ -148,7 +148,13 @@ func (k Keeper) AccountLockIteratorLongerDuration(ctx sdk.Context, isUnlocking b
return k.iteratorLongerDuration(ctx, combineKeys(unlockingPrefix, types.KeyPrefixAccountLockDuration, addr), duration)
}

// AccountLockIteratorShorterThanDuration returns iterator used for getting all locks by account longer than duration.
// AccountLockIteratorDuration returns an iterator used for getting all locks for a given account, isUnlocking, and specific duration.
func (k Keeper) AccountLockIteratorDuration(ctx sdk.Context, isUnlocking bool, addr sdk.AccAddress, duration time.Duration) sdk.Iterator {
unlockingPrefix := unlockingPrefix(isUnlocking)
return k.iteratorDuration(ctx, combineKeys(unlockingPrefix, types.KeyPrefixAccountLockDuration, addr), duration)
}

// AccountLockIteratorShorterThanDuration returns iterator used for getting all locks by account longer than duration
CmpHDL marked this conversation as resolved.
Show resolved Hide resolved
func (k Keeper) AccountLockIteratorShorterThanDuration(ctx sdk.Context, isUnlocking bool, addr sdk.AccAddress, duration time.Duration) sdk.Iterator {
unlockingPrefix := unlockingPrefix(isUnlocking)
return k.iteratorShorterDuration(ctx, combineKeys(unlockingPrefix, types.KeyPrefixAccountLockDuration, addr), duration)
Expand Down
10 changes: 9 additions & 1 deletion x/lockup/keeper/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,15 @@ func (k Keeper) GetAccountLockedLongerDuration(ctx sdk.Context, addr sdk.AccAddr
return combineLocks(notUnlockings, unlockings)
}

// GetAccountLockedLongerDurationNotUnlockingOnly Returns account locked with duration longer than specified.
// GetAccountLockedDuration returns locks with a specific duration for a given account.
func (k Keeper) GetAccountLockedDuration(ctx sdk.Context, addr sdk.AccAddress, duration time.Duration) []types.PeriodLock {
// it does not matter started unlocking or not for duration query
unlockedLocks := k.getLocksFromIterator(ctx, k.AccountLockIteratorDuration(ctx, true, addr, duration))
lockedLocks := k.getLocksFromIterator(ctx, k.AccountLockIteratorDuration(ctx, false, addr, duration))
return combineLocks(unlockedLocks, lockedLocks)
}

// GetAccountLockedLongerDurationNotUnlockingOnly Returns account locked with duration longer than specified
CmpHDL marked this conversation as resolved.
Show resolved Hide resolved
func (k Keeper) GetAccountLockedLongerDurationNotUnlockingOnly(ctx sdk.Context, addr sdk.AccAddress, duration time.Duration) []types.PeriodLock {
return k.getLocksFromIterator(ctx, k.AccountLockIteratorLongerDuration(ctx, false, addr, duration))
}
Expand Down
3 changes: 3 additions & 0 deletions x/lockup/spec/07_queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ service Query {
rpc AccountLockedLongerDurationNotUnlockingOnly(AccountLockedLongerDurationNotUnlockingOnlyRequest) returns (AccountLockedLongerDurationNotUnlockingOnlyResponse) {}
// Returns account's locked records for a denom with longer duration
rpc AccountLockedLongerDurationDenom(AccountLockedLongerDurationDenomRequest) returns (AccountLockedLongerDurationDenomResponse);

// Returns account locked records with a specific duration
rpc AccountLockedDuration(AccountLockedDurationRequest) returns (AccountLockedDurationResponse);
}
```
1 change: 1 addition & 0 deletions x/lockup/types/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ const (
QueryLockedByID = "locked_by_id"
QueryAccountLockedLongerDuration = "account_locked_longer_than_duration"
QueryAccountLockedLongerDurationDenom = "account_locked_longer_than_duration_denom"
QueryAccountLockedDuration = "account_locked_duration"
)
Loading