forked from AstraProtocol/astra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
total_fee_burn.go
37 lines (31 loc) · 1007 Bytes
/
total_fee_burn.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
package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dungtt-astra/astra/v3/x/feeburn/types"
)
// GetTotalFeeBurn returns the total fee already burn.
// The returned amount is measured in config.BaseDenom (i.e, aastra).
func (k Keeper) GetTotalFeeBurn(ctx sdk.Context) sdk.Dec {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.KeyPrefixTotalFeeBurn)
if len(bz) == 0 {
return sdk.ZeroDec()
}
var totalFeeBurn sdk.Dec
err := totalFeeBurn.Unmarshal(bz)
if err != nil {
panic(fmt.Errorf("unable to unmarshal totalFeeBurn value: %w", err))
}
return totalFeeBurn
}
// SetTotalFeeBurn sets the current totalFeeBurn.
// totalFeeBurn must be converted to config.BaseDenom (i.e, aastra).
func (k Keeper) SetTotalFeeBurn(ctx sdk.Context, totalFeeBurn sdk.Dec) {
bz, err := totalFeeBurn.Marshal()
if err != nil {
panic(fmt.Errorf("unable to marshal amount value: %w", err))
}
store := ctx.KVStore(k.storeKey)
store.Set(types.KeyPrefixTotalFeeBurn, bz)
}