-
Notifications
You must be signed in to change notification settings - Fork 0
/
prestakingKeeper.go
63 lines (52 loc) · 1.81 KB
/
prestakingKeeper.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
package keeper
import (
"fmt"
"github.com/ci123chain/ci123chain/pkg/abci/codec"
sdk "github.com/ci123chain/ci123chain/pkg/abci/types"
"github.com/ci123chain/ci123chain/pkg/account"
"github.com/ci123chain/ci123chain/pkg/params"
"github.com/ci123chain/ci123chain/pkg/pre_staking/types"
"github.com/ci123chain/ci123chain/pkg/staking/keeper"
"github.com/ci123chain/ci123chain/pkg/supply"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
)
type PreStakingKeeper struct {
storeKey sdk.StoreKey
cdc *codec.Codec
AccountKeeper account.AccountKeeper
SupplyKeeper supply.Keeper
StakingKeeper keeper.StakingKeeper
paramstore params.Subspace
cdb dbm.DB
}
func NewPreStakingKeeper(cdc *codec.Codec, key sdk.StoreKey, ak account.AccountKeeper, sk supply.Keeper, stakingKeeper keeper.StakingKeeper,
ps params.Subspace, cdb dbm.DB) PreStakingKeeper{
return PreStakingKeeper{
storeKey:key,
cdc: cdc,
AccountKeeper: ak,
SupplyKeeper: sk,
StakingKeeper:stakingKeeper,
paramstore: ps,
cdb: cdb,
}
}
func (ps PreStakingKeeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
func (ps PreStakingKeeper) SetAccountPreStaking(ctx sdk.Context, delegator sdk.AccAddress, amount sdk.Int) {
store := ctx.KVStore(ps.storeKey)
bz := ps.cdc.MustMarshalBinaryLengthPrefixed(sdk.IntProto{Int:amount})
store.Set(types.GetPreStakingKey(delegator), bz)
}
func (ps PreStakingKeeper) GetAccountPreStaking(ctx sdk.Context, delegator sdk.AccAddress) sdk.Int {
store := ctx.KVStore(ps.storeKey)
bz := store.Get(types.GetPreStakingKey(delegator))
if bz == nil {
return sdk.ZeroInt()
}
ip := sdk.IntProto{}
ps.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &ip)
return ip.Int
}