-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: tax module start using KVStoreService
- Loading branch information
Showing
12 changed files
with
109 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,80 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Nolus-Protocol/nolus-core/x/tax/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// GetParams get all parameters as types.Params. | ||
func (k Keeper) GetParams(ctx sdk.Context) (p types.Params) { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get(types.ParamsKey) | ||
if bz == nil { | ||
func (k Keeper) GetParams(ctx context.Context) types.Params { | ||
store := k.storeService.OpenKVStore(ctx) | ||
|
||
var p types.Params | ||
b, err := store.Get(types.ParamsKey) | ||
if err != nil { | ||
// TODO panic("error getting stored tax params") | ||
return p | ||
} | ||
|
||
k.cdc.MustUnmarshal(bz, &p) | ||
k.cdc.MustUnmarshal(b, &p) | ||
return p | ||
} | ||
|
||
// SetParams set the params. | ||
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { | ||
func (k Keeper) SetParams(ctx context.Context, params types.Params) error { | ||
if err := params.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
store := ctx.KVStore(k.storeKey) | ||
bz := k.cdc.MustMarshal(¶ms) | ||
store.Set(types.ParamsKey, bz) | ||
store := k.storeService.OpenKVStore(ctx) | ||
b := k.cdc.MustMarshal(¶ms) | ||
|
||
if err := store.Set(types.ParamsKey, b); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// FeeRate returns the fee rate. | ||
func (k Keeper) FeeRate(ctx sdk.Context) (res int32) { | ||
var p types.Params | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get(types.ParamsKey) | ||
if bz == nil { | ||
func (k Keeper) FeeRate(ctx context.Context) int32 { | ||
store := k.storeService.OpenKVStore(ctx) | ||
|
||
b, err := store.Get(types.ParamsKey) | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
k.cdc.MustUnmarshal(bz, &p) | ||
var p types.Params | ||
k.cdc.MustUnmarshal(b, &p) | ||
return p.FeeRate | ||
} | ||
|
||
// ContractAddress returns the contract address. | ||
func (k Keeper) ContractAddress(ctx sdk.Context) (res string) { | ||
var p types.Params | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get(types.ParamsKey) | ||
if bz == nil { | ||
func (k Keeper) ContractAddress(ctx context.Context) string { | ||
store := k.storeService.OpenKVStore(ctx) | ||
|
||
b, err := store.Get(types.ParamsKey) | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
k.cdc.MustUnmarshal(bz, &p) | ||
var p types.Params | ||
k.cdc.MustUnmarshal(b, &p) | ||
return p.ContractAddress | ||
} | ||
|
||
// BseDenom returns the base denom. | ||
func (k Keeper) BaseDenom(ctx sdk.Context) (res string) { | ||
var p types.Params | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get(types.ParamsKey) | ||
if bz == nil { | ||
func (k Keeper) BaseDenom(ctx context.Context) string { | ||
store := k.storeService.OpenKVStore(ctx) | ||
|
||
b, err := store.Get(types.ParamsKey) | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
k.cdc.MustUnmarshal(bz, &p) | ||
var p types.Params | ||
k.cdc.MustUnmarshal(b, &p) | ||
return p.BaseDenom | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.