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

Fix proto enum TokenizeShareLockStatus #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 13 additions & 6 deletions proto/staking/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -450,19 +450,26 @@ message QueryTotalLiquidStakedResponse {
}

// QueryTokenizeShareLockInfo queries the tokenize share lock information
// associated with given account
// associated with given account.
message QueryTokenizeShareLockInfo {
string address = 1;
}
// QueryTokenizeShareLockInfoResponse is the response from the
// QueryTokenizeShareLockInfo query
// QueryTokenizeShareLockInfo query.
message QueryTokenizeShareLockInfoResponse{
string status = 1;
string expiration_time = 2;
}

// TokenizeShareLockStatus represents status of an account's tokenize share lock.
enum TokenizeShareLockStatus {
LOCKED = 0;
UNLOCKED = 1;
LOCK_EXPIRING = 2;
}
option (gogoproto.goproto_enum_prefix) = false;
// An empty value is not allowed.
TOKENIZE_SHARE_LOCK_STATUS_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "ShareLockStatusNil"];
// Status means cannot tokenize shares.
TOKENIZE_SHARE_LOCK_STATUS_LOCKED = 1 [(gogoproto.enumvalue_customname) = "ShareLockStatusLocked"];
// Status means cannot tokenize shares.
TOKENIZE_SHARE_LOCK_STATUS_UNLOCKED = 2 [(gogoproto.enumvalue_customname) = "ShareLockStatusUnlocked"];
// Status when lock is queued for unlocking.
TOKENIZE_SHARE_LOCK_STATUS_LOCK_EXPIRING = 3 [(gogoproto.enumvalue_customname) = "ShareLockStatusLockExpiring"];
}
6 changes: 3 additions & 3 deletions x/staking/keeper/liquid_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,16 @@ func (k Keeper) GetTokenizeSharesLock(ctx sdk.Context, address sdk.AccAddress) (
key := types.GetTokenizeSharesLockKey(address)
bz := store.Get(key)
if len(bz) == 0 {
return types.TokenizeShareLockStatus_UNLOCKED, time.Time{}
return types.ShareLockStatusUnlocked, time.Time{}
}
unlockTime, err := sdk.ParseTimeBytes(bz)
if err != nil {
panic(err)
}
if unlockTime.IsZero() {
return types.TokenizeShareLockStatus_LOCKED, time.Time{}
return types.ShareLockStatusLocked, time.Time{}
}
return types.TokenizeShareLockStatus_LOCK_EXPIRING, unlockTime
return types.ShareLockStatusLockExpiring, unlockTime
}

// Stores a list of addresses pending tokenize share unlocking at the same time
Expand Down
6 changes: 3 additions & 3 deletions x/staking/keeper/liquid_stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,9 @@ func TestTokenizeSharesLock(t *testing.T) {
addresses := simapp.AddTestAddrs(app, ctx, 2, sdk.NewInt(1))
addressA, addressB := addresses[0], addresses[1]

unlocked := types.TokenizeShareLockStatus_UNLOCKED.String()
locked := types.TokenizeShareLockStatus_LOCKED.String()
lockExpiring := types.TokenizeShareLockStatus_LOCK_EXPIRING.String()
unlocked := types.ShareLockStatusUnlocked.String()
locked := types.ShareLockStatusLocked.String()
lockExpiring := types.ShareLockStatusLockExpiring.String()

// Confirm both accounts start unlocked
status, _ := app.StakingKeeper.GetTokenizeSharesLock(ctx, addressA)
Expand Down
12 changes: 6 additions & 6 deletions x/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,10 @@ func (k msgServer) TokenizeShares(goCtx context.Context, msg *types.MsgTokenizeS

// Check if the delegator has disabled tokenization
lockStatus, unlockTime := k.GetTokenizeSharesLock(ctx, delegatorAddress)
if lockStatus == types.TokenizeShareLockStatus_LOCKED {
if lockStatus == types.ShareLockStatusLocked {
return nil, types.ErrTokenizeSharesDisabledForAccount
}
if lockStatus == types.TokenizeShareLockStatus_LOCK_EXPIRING {
if lockStatus == types.ShareLockStatusLockExpiring {
return nil, types.ErrTokenizeSharesDisabledForAccount.Wrapf("tokenization will be allowed at %s", unlockTime)
}

Expand Down Expand Up @@ -941,12 +941,12 @@ func (k msgServer) DisableTokenizeShares(goCtx context.Context, msg *types.MsgDi

// If tokenized shares is already disabled, alert the user
lockStatus, completionTime := k.GetTokenizeSharesLock(ctx, delegator)
if lockStatus == types.TokenizeShareLockStatus_LOCKED {
if lockStatus == types.ShareLockStatusLocked {
return nil, types.ErrTokenizeSharesAlreadyDisabledForAccount
}

// If the tokenized shares lock is expiring, remove the pending unlock from the queue
if lockStatus == types.TokenizeShareLockStatus_LOCK_EXPIRING {
if lockStatus == types.ShareLockStatusLockExpiring {
k.CancelTokenizeShareLockExpiration(ctx, delegator, completionTime)
}

Expand All @@ -966,10 +966,10 @@ func (k msgServer) EnableTokenizeShares(goCtx context.Context, msg *types.MsgEna

// If tokenized shares aren't current disabled, alert the user
lockStatus, unlockTime := k.GetTokenizeSharesLock(ctx, delegator)
if lockStatus == types.TokenizeShareLockStatus_UNLOCKED {
if lockStatus == types.ShareLockStatusUnlocked {
return nil, types.ErrTokenizeSharesAlreadyEnabledForAccount
}
if lockStatus == types.TokenizeShareLockStatus_LOCK_EXPIRING {
if lockStatus == types.ShareLockStatusLockExpiring {
return nil, types.ErrTokenizeSharesAlreadyEnabledForAccount.Wrapf(
"tokenize shares re-enablement already in progress, ending at %s", unlockTime)
}
Expand Down
Loading