Skip to content

Commit

Permalink
Feat: CLI account-locked-duration (#1292)
Browse files Browse the repository at this point in the history
* Add panic guard, bug fix

* Add AccountLockedDuration RPC service

* Add AccountLockedDuration Request & Response Messages

* Generated protofiles for x/lockup, added AccountLockedDuration RPC, Request, and Response

* Update CLI Request & Response for account-locked-duration

* Add account_locked_duration to querier types

* Add comments & Update lockup keeper iterator to include AccountLockIteratorDuration method.

* Add GetAccountLockedDuration to lockup store and use new iterator

* Fix method comment namiing

* Add missing AccountLockedDuration method to grpc_query.go/

* Add documentation for rpc AccountLockedDuration

* Fixed weird rebase error.

* Refactored Keeper into Querier

* Readd GetCmdAccountLockedDuration to QueryTree

* Fix occurred mispelling to satisfy linter

* Update x/lockup/client/cli/query.go

Co-authored-by: Aleksandr Bezobchuk <[email protected]>

* Update x/lockup/client/cli/query.go

Co-authored-by: Roman <[email protected]>

* Update x/lockup/keeper/grpc_query.go

Co-authored-by: Roman <[email protected]>

* Update x/lockup/keeper/iterator.go

Co-authored-by: Roman <[email protected]>

* Update x/lockup/keeper/store.go

Co-authored-by: Roman <[email protected]>

* Update x/lockup/keeper/store.go

Co-authored-by: Roman <[email protected]>

* Remove TODOs.

* Add PR to changelog Unreleased

* Fix initialization order of interatorDuration.

* Add example address to long description of GetCmdAccountUnlockingCoins query.

* Fixed Bech32 address in long description and function call.

* Swap Long for Example

* Update CHANGELOG

* Add example for GetCmdAccountLockedDuration

* Remove example from wrong function

* Fix comment for AccountLockIteratorShorterThanDuration

Co-authored-by: ValarDragon <[email protected]>
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: Roman <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
  • Loading branch information
5 people authored Apr 27, 2022
1 parent a56fe51 commit ad7d5de
Show file tree
Hide file tree
Showing 10 changed files with 765 additions and 106 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1262](https://github.com/osmosis-labs/osmosis/pull/1262) Add a `forceprune` command to the binaries, that prunes golevelDB data better.
* [#1244](https://github.com/osmosis-labs/osmosis/pull/1244) Refactor `x/gamm`'s `ExitSwapExternAmountOut`.
* [#1107](https://github.com/osmosis-labs/osmosis/pull/1107) Update to wasmvm v0.24.0, re-enabling building on M1 macs!

* [#1292](https://github.com/osmosis-labs/osmosis/pull/1292) CLI account-locked-duration
*
### Minor improvements & Bug Fixes

* [#1335](https://github.com/osmosis-labs/osmosis/pull/1335) Add utility for deriving total orderings from partial orderings.
Expand Down Expand Up @@ -112,7 +113,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
* [#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 @@ -290,7 +291,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}";
}

// 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 {
string owner = 1 [ (gogoproto.moretags) = "yaml:\"owner\"" ];
google.protobuf.Duration duration = 2 [
(gogoproto.stdduration) = true,
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"duration\""
];
};
message AccountLockedDurationResponse {
repeated PeriodLock locks = 1 [ (gogoproto.nullable) = false ];
};

message AccountLockedLongerDurationNotUnlockingOnlyRequest {
string owner = 1 [ (gogoproto.moretags) = "yaml:\"owner\"" ];
google.protobuf.Duration duration = 2 [
Expand Down
42 changes: 42 additions & 0 deletions 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 @@ -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",
Example: strings.TrimSpace(
fmt.Sprintf(`Query account locked records with a specific duration.
Example:
$ %s query lockup account-locked-duration osmo1yl6hdjhmkf37639730gffanpzndzdpmhxy9ep3 604800s
`,
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})
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 an iterator used for getting all locks by account shorter than the specified duration.
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
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

0 comments on commit ad7d5de

Please sign in to comment.