/
admin_keeper.go
74 lines (59 loc) · 1.67 KB
/
admin_keeper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package keeper
import (
"github.com/gogo/protobuf/proto"
"github.com/osmosis-labs/osmosis/v11/x/lockup/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Relock unlock previous lockID and create a new lock with newCoins with same duration and endtime.
func (ak AdminKeeper) Relock(ctx sdk.Context, lockID uint64, newCoins sdk.Coins) error {
lock, err := ak.GetLockByID(ctx, lockID)
if err != nil {
return err
}
owner, err := sdk.AccAddressFromBech32(lock.Owner)
if err != nil {
return err
}
// send original coins back to owner
if err := ak.bk.SendCoinsFromModuleToAccount(ctx, types.ModuleName, owner, lock.Coins); err != nil {
return err
}
// lock newCoins into module account
if err := ak.bk.SendCoinsFromAccountToModule(ctx, owner, types.ModuleName, newCoins); err != nil {
return err
}
// replace to new coins
lock.Coins = newCoins
// reset lock record inside store
store := ctx.KVStore(ak.storeKey)
bz, err := proto.Marshal(lock)
if err != nil {
return err
}
store.Set(lockStoreKey(lockID), bz)
return nil
}
// BreakLock unlock a lockID without considering time with admin privilege.
func (ak AdminKeeper) BreakLock(ctx sdk.Context, lockID uint64) error {
lock, err := ak.GetLockByID(ctx, lockID)
if err != nil {
return err
}
owner, err := sdk.AccAddressFromBech32(lock.Owner)
if err != nil {
return err
}
// send coins back to owner
if err := ak.bk.SendCoinsFromModuleToAccount(ctx, types.ModuleName, owner, lock.Coins); err != nil {
return err
}
ak.deleteLock(ctx, lockID)
refKeys, err := lockRefKeys(*lock)
if err != nil {
return err
}
for _, refKey := range refKeys {
ak.deleteLockRefByKey(ctx, refKey, lockID)
}
return nil
}