-
Notifications
You must be signed in to change notification settings - Fork 13
/
keeper.go
56 lines (44 loc) · 1.47 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
package keeper
import (
"fmt"
"cosmossdk.io/collections"
"cosmossdk.io/core/address"
storetypes "cosmossdk.io/core/store"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/hyle-org/hyle/x/zktx"
)
type Keeper struct {
cdc codec.BinaryCodec
addressCodec address.Codec
// authority is the address capable of executing a MsgUpdateParams and other authority-gated message.
// typically, this should be the x/gov module account.
authority string
// state management
Schema collections.Schema
Params collections.Item[zktx.Params]
Contracts collections.Map[string, zktx.Contract]
}
// NewKeeper creates a new Keeper instance
func NewKeeper(cdc codec.BinaryCodec, addressCodec address.Codec, storeService storetypes.KVStoreService, authority string) Keeper {
if _, err := addressCodec.StringToBytes(authority); err != nil {
panic(fmt.Errorf("invalid authority address: %w", err))
}
sb := collections.NewSchemaBuilder(storeService)
k := Keeper{
cdc: cdc,
addressCodec: addressCodec,
authority: authority,
Params: collections.NewItem(sb, zktx.ParamsKey, "params", codec.CollValue[zktx.Params](cdc)),
Contracts: collections.NewMap(sb, zktx.ContractNameKey, "contracts", collections.StringKey, codec.CollValue[zktx.Contract](cdc)),
}
schema, err := sb.Build()
if err != nil {
panic(err)
}
k.Schema = schema
return k
}
// GetAuthority returns the module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}