github.com/KiraCore/sekai@v0.3.43/x/tokens/proposal_handler.go (about) 1 package tokens 2 3 import ( 4 kiratypes "github.com/KiraCore/sekai/types" 5 "github.com/KiraCore/sekai/x/gov/types" 6 "github.com/KiraCore/sekai/x/tokens/keeper" 7 tokenstypes "github.com/KiraCore/sekai/x/tokens/types" 8 sdk "github.com/cosmos/cosmos-sdk/types" 9 ) 10 11 type ApplyUpsertTokenAliasProposalHandler struct { 12 keeper keeper.Keeper 13 } 14 15 func NewApplyUpsertTokenAliasProposalHandler(keeper keeper.Keeper) *ApplyUpsertTokenAliasProposalHandler { 16 return &ApplyUpsertTokenAliasProposalHandler{ 17 keeper: keeper, 18 } 19 } 20 21 func (a ApplyUpsertTokenAliasProposalHandler) ProposalType() string { 22 return kiratypes.ProposalTypeUpsertTokenAlias 23 } 24 25 func (a ApplyUpsertTokenAliasProposalHandler) Apply(ctx sdk.Context, proposalID uint64, proposal types.Content, slash sdk.Dec) error { 26 p := proposal.(*tokenstypes.ProposalUpsertTokenAlias) 27 28 alias := tokenstypes.NewTokenAlias(p.Symbol, p.Name, p.Icon, p.Decimals, p.Denoms, p.Invalidated) 29 return a.keeper.UpsertTokenAlias(ctx, *alias) 30 } 31 32 type ApplyUpsertTokenRatesProposalHandler struct { 33 keeper keeper.Keeper 34 } 35 36 func NewApplyUpsertTokenRatesProposalHandler(keeper keeper.Keeper) *ApplyUpsertTokenRatesProposalHandler { 37 return &ApplyUpsertTokenRatesProposalHandler{keeper: keeper} 38 } 39 40 func (a ApplyUpsertTokenRatesProposalHandler) ProposalType() string { 41 return kiratypes.ProposalTypeUpsertTokenRates 42 } 43 44 func (a ApplyUpsertTokenRatesProposalHandler) Apply(ctx sdk.Context, proposalID uint64, proposal types.Content, slash sdk.Dec) error { 45 p := proposal.(*tokenstypes.ProposalUpsertTokenRates) 46 47 rate := tokenstypes.NewTokenRate(p.Denom, p.Rate, p.FeePayments, p.StakeCap, p.StakeMin, p.StakeToken, p.Invalidated) 48 return a.keeper.UpsertTokenRate(ctx, *rate) 49 } 50 51 type ApplyWhiteBlackChangeProposalHandler struct { 52 keeper keeper.Keeper 53 } 54 55 func NewApplyWhiteBlackChangeProposalHandler(keeper keeper.Keeper) *ApplyWhiteBlackChangeProposalHandler { 56 return &ApplyWhiteBlackChangeProposalHandler{keeper: keeper} 57 } 58 59 func (a ApplyWhiteBlackChangeProposalHandler) ProposalType() string { 60 return kiratypes.ProposalTypeTokensWhiteBlackChange 61 } 62 63 func (a ApplyWhiteBlackChangeProposalHandler) Apply(ctx sdk.Context, proposalID uint64, proposal types.Content, slash sdk.Dec) error { 64 p := proposal.(*tokenstypes.ProposalTokensWhiteBlackChange) 65 66 if p.IsBlacklist { 67 if p.IsAdd { 68 a.keeper.AddTokensToBlacklist(ctx, p.Tokens) 69 } else { 70 a.keeper.RemoveTokensFromBlacklist(ctx, p.Tokens) 71 } 72 } else { 73 if p.IsAdd { 74 a.keeper.AddTokensToWhitelist(ctx, p.Tokens) 75 } else { 76 a.keeper.RemoveTokensFromWhitelist(ctx, p.Tokens) 77 } 78 } 79 return nil 80 }