0g-chain/x/wrapped-a0gi-base/keeper/keeper.go

70 lines
1.9 KiB
Go
Raw Normal View History

2025-01-07 09:23:01 +00:00
package keeper
import (
2025-01-08 04:58:14 +00:00
"math/big"
"github.com/0glabs/0g-chain/x/wrapped-a0gi-base/types"
2025-01-07 09:23:01 +00:00
"github.com/cosmos/cosmos-sdk/codec"
2025-01-08 04:58:14 +00:00
"github.com/ethereum/go-ethereum/common"
2025-01-07 09:23:01 +00:00
2025-01-08 04:58:14 +00:00
precisebankkeeper "github.com/0glabs/0g-chain/x/precisebank/keeper"
"github.com/cosmos/cosmos-sdk/store/prefix"
2025-01-07 09:23:01 +00:00
storetypes "github.com/cosmos/cosmos-sdk/store/types"
2025-01-08 04:58:14 +00:00
sdk "github.com/cosmos/cosmos-sdk/types"
2025-01-07 09:23:01 +00:00
)
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
2025-01-08 04:58:14 +00:00
pbkeeper precisebankkeeper.Keeper
2025-01-07 09:23:01 +00:00
authority string // the address capable of changing signers params. Should be the gov module account
}
// NewKeeper creates a new wrapped a0gi base keeper instance
func NewKeeper(
storeKey storetypes.StoreKey,
cdc codec.BinaryCodec,
2025-01-08 04:58:14 +00:00
pbkeeper precisebankkeeper.Keeper,
2025-01-07 09:23:01 +00:00
authority string,
) Keeper {
return Keeper{
storeKey: storeKey,
cdc: cdc,
2025-01-08 04:58:14 +00:00
pbkeeper: pbkeeper,
2025-01-07 09:23:01 +00:00
authority: authority,
}
}
2025-01-08 04:58:14 +00:00
func (k Keeper) SetWA0GIAddress(ctx sdk.Context, addr common.Address) {
store := ctx.KVStore(k.storeKey)
store.Set(types.WA0GIKey, addr.Bytes())
}
func (k Keeper) GetWA0GIAddress(ctx sdk.Context) []byte {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.WA0GIKey)
return bz
}
2025-01-20 06:36:02 +00:00
func (k Keeper) setMinterSupply(ctx sdk.Context, account common.Address, supply types.Supply) error {
2025-01-08 04:58:14 +00:00
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.MinterSupplyKeyPrefix)
2025-01-20 06:36:02 +00:00
bz := k.cdc.MustMarshal(&supply)
store.Set(account.Bytes(), bz)
2025-01-08 04:58:14 +00:00
return nil
}
2025-01-20 06:36:02 +00:00
func (k Keeper) getMinterSupply(ctx sdk.Context, account common.Address) (types.Supply, error) {
2025-01-08 04:58:14 +00:00
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.MinterSupplyKeyPrefix)
bz := store.Get(account.Bytes())
2025-01-20 06:36:02 +00:00
if bz == nil {
return types.Supply{
Cap: big.NewInt(0).Bytes(),
InitialSupply: big.NewInt(0).Bytes(),
Supply: big.NewInt(0).Bytes(),
}, nil
}
var supply types.Supply
k.cdc.MustUnmarshal(bz, &supply)
return supply, nil
2025-01-08 04:58:14 +00:00
}