-
Notifications
You must be signed in to change notification settings - Fork 206
/
store.go
58 lines (50 loc) · 2.1 KB
/
store.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
package keeper
import (
"github.com/NibiruChain/collections"
sdkcodec "github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
devgastypes "github.com/NibiruChain/nibiru/x/devgas/v1/types"
)
type DevGasIndexes struct {
// Deployer MultiIndex:
// - indexing key (IK): deployer address
// - primary key (PK): contract address
// - value (V): Dev gas struct
Deployer collections.MultiIndex[string, string, devgastypes.FeeShare]
// Withdrawer MultiIndex:
// - indexing key (IK): withdrawer address
// - primary key (PK): contract address
// - value (V): Dev gas struct
Withdrawer collections.MultiIndex[string, string, devgastypes.FeeShare]
}
func (idxs DevGasIndexes) IndexerList() []collections.Indexer[string, devgastypes.FeeShare] {
return []collections.Indexer[string, devgastypes.FeeShare]{
idxs.Deployer, idxs.Withdrawer,
}
}
func NewDevGasStore(
storeKey storetypes.StoreKey, cdc sdkcodec.BinaryCodec,
) collections.IndexedMap[string, devgastypes.FeeShare, DevGasIndexes] {
primaryKeyEncoder := collections.StringKeyEncoder
valueEncoder := collections.ProtoValueEncoder[devgastypes.FeeShare](cdc)
var namespace collections.Namespace = devgastypes.KeyPrefixFeeShare
var namespaceDeployerIdx collections.Namespace = devgastypes.KeyPrefixDeployer
var namespaceWithdrawerIdx collections.Namespace = devgastypes.KeyPrefixWithdrawer
return collections.NewIndexedMap[string, devgastypes.FeeShare](
storeKey, namespace, primaryKeyEncoder, valueEncoder,
DevGasIndexes{
Deployer: collections.NewMultiIndex[string, string, devgastypes.FeeShare](
storeKey, namespaceDeployerIdx,
collections.StringKeyEncoder, // index key (IK)
collections.StringKeyEncoder, // primary key (PK)
func(v devgastypes.FeeShare) string { return v.DeployerAddress },
),
Withdrawer: collections.NewMultiIndex[string, string, devgastypes.FeeShare](
storeKey, namespaceWithdrawerIdx,
collections.StringKeyEncoder, // index key (IK)
collections.StringKeyEncoder, // primary key (PK)
func(v devgastypes.FeeShare) string { return v.WithdrawerAddress },
),
},
)
}