-
Notifications
You must be signed in to change notification settings - Fork 0
/
keeper.go
88 lines (73 loc) · 2.63 KB
/
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package keeper
import (
"fmt"
nftkeeper "github.com/UptickNetwork/uptick/x/collection/keeper"
ibcnfttransferkeeper "github.com/bianjieai/nft-transfer/keeper"
ibcnfttransfertypes "github.com/bianjieai/nft-transfer/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/UptickNetwork/wasm-nft-convert/types"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
)
// Keeper of this module maintains collections of cw721.
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
paramstore paramtypes.Subspace
accountKeeper types.AccountKeeper
nftKeeper nftkeeper.Keeper
cwKeeper wasmkeeper.Keeper
cwPermissionedKeeper *wasmkeeper.PermissionedKeeper
ics4Wrapper porttypes.ICS4Wrapper
ibcKeeper ibcnfttransferkeeper.Keeper
}
// NewKeeper creates new instances of the cw721 Keeper
func NewKeeper(storeKey storetypes.StoreKey,
cdc codec.BinaryCodec,
ps paramtypes.Subspace,
ak types.AccountKeeper,
nk nftkeeper.Keeper,
ek wasmkeeper.Keeper,
pk *wasmkeeper.PermissionedKeeper,
ik ibcnfttransferkeeper.Keeper) Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
ps = ps.WithKeyTable(types.ParamKeyTable())
}
return Keeper{
storeKey: storeKey,
cdc: cdc,
paramstore: ps,
accountKeeper: ak,
nftKeeper: nk,
cwKeeper: ek,
cwPermissionedKeeper: pk,
ibcKeeper: ik,
}
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
// SetICS4Wrapper sets the ICS4 wrapper to the keeper.
// It panics if already set
func (k *Keeper) SetICS4Wrapper(ics4Wrapper porttypes.ICS4Wrapper) {
if k.ics4Wrapper != nil {
panic("ICS4 wrapper already set")
}
k.ics4Wrapper = ics4Wrapper
}
func (k *Keeper) GetVoucherClassID(port string, channel string, classId string) string {
// since SendPacket did not prefix the classID, we must prefix classID here
classPrefix := ibcnfttransfertypes.GetClassPrefix(port, channel)
// NOTE: sourcePrefix contains the trailing "/"
prefixedClassID := classPrefix + classId
// construct the class trace from the full raw classID
classTrace := ibcnfttransfertypes.ParseClassTrace(prefixedClassID)
voucherClassID := classTrace.IBCClassID()
return voucherClassID
}