-
Notifications
You must be signed in to change notification settings - Fork 169
/
admins.go
50 lines (38 loc) · 1.26 KB
/
admins.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
package keeper
import (
"github.com/cosmos/gogoproto/proto"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/CosmosContracts/juno/v19/x/tokenfactory/types"
)
// GetAuthorityMetadata returns the authority metadata for a specific denom
func (k Keeper) GetAuthorityMetadata(ctx sdk.Context, denom string) (types.DenomAuthorityMetadata, error) {
bz := k.GetDenomPrefixStore(ctx, denom).Get([]byte(types.DenomAuthorityMetadataKey))
metadata := types.DenomAuthorityMetadata{}
err := proto.Unmarshal(bz, &metadata)
if err != nil {
return types.DenomAuthorityMetadata{}, err
}
return metadata, nil
}
// setAuthorityMetadata stores authority metadata for a specific denom
func (k Keeper) setAuthorityMetadata(ctx sdk.Context, denom string, metadata types.DenomAuthorityMetadata) error {
err := metadata.Validate()
if err != nil {
return err
}
store := k.GetDenomPrefixStore(ctx, denom)
bz, err := proto.Marshal(&metadata)
if err != nil {
return err
}
store.Set([]byte(types.DenomAuthorityMetadataKey), bz)
return nil
}
func (k Keeper) setAdmin(ctx sdk.Context, denom string, admin string) error {
metadata, err := k.GetAuthorityMetadata(ctx, denom)
if err != nil {
return err
}
metadata.Admin = admin
return k.setAuthorityMetadata(ctx, denom, metadata)
}