MCPcopy Create free account
hub / github.com/Sifchain/sifnode / ModifyPmtpRates

Method ModifyPmtpRates

x/clp/keeper/msg_server.go:214–273  ·  view source on GitHub ↗
(goCtx context.Context, msg *types.MsgModifyPmtpRates)

Source from the content-addressed store, hash-verified

212}
213
214func (k msgServer) ModifyPmtpRates(goCtx context.Context, msg *types.MsgModifyPmtpRates) (*types.MsgModifyPmtpRatesResponse, error) {
215 ctx := sdk.UnwrapSDKContext(goCtx)
216 response := &types.MsgModifyPmtpRatesResponse{}
217 signer, err := sdk.AccAddressFromBech32(msg.Signer)
218 if err != nil {
219 return response, err
220 }
221 if !k.adminKeeper.IsAdminAccount(ctx, admintypes.AdminType_PMTPREWARDS, signer) {
222 return response, errors.Wrap(types.ErrNotEnoughPermissions, fmt.Sprintf("Sending Account : %s", msg.Signer))
223 }
224 params := k.GetPmtpParams(ctx)
225 rateParams := k.GetPmtpRateParams(ctx)
226
227 // Set Block Rate is needed only if no policy is presently executing
228 if !types.StringCompare(msg.BlockRate, "") && !k.IsInsidePmtpWindow(ctx) {
229 blockRate, err := sdk.NewDecFromStr(msg.BlockRate)
230 if err != nil {
231 return response, err
232 }
233 rateParams.PmtpPeriodBlockRate = blockRate
234 }
235
236 // Set Running Rate if Needed only if no policy is presently executing
237 if !types.StringCompare(msg.RunningRate, "") && !k.IsInsidePmtpWindow(ctx) {
238 runningRate, err := sdk.NewDecFromStr(msg.RunningRate)
239 if err != nil {
240 return response, err
241 }
242 rateParams.PmtpCurrentRunningRate = runningRate
243 // inter policy rate should always equal running rate between policies
244 rateParams.PmtpInterPolicyRate = runningRate
245 }
246 k.SetPmtpRateParams(ctx, rateParams)
247 events := sdk.EmptyEvents()
248 // End Policy If Needed , returns if not policy is presently
249 if msg.EndPolicy && k.IsInsidePmtpWindow(ctx) {
250 params.PmtpPeriodEndBlock = ctx.BlockHeight()
251 k.SetPmtpParams(ctx, params)
252 k.SetPmtpEpoch(ctx, types.PmtpEpoch{
253 EpochCounter: 0,
254 BlockCounter: 0,
255 })
256 k.SetPmtpInterPolicyRate(ctx, rateParams.PmtpCurrentRunningRate)
257 events = events.AppendEvents(sdk.Events{
258 sdk.NewEvent(
259 types.EventTypeEndPmtpPolicy,
260 sdk.NewAttribute(types.AttributeKeyPmtpPolicyParams, params.String()),
261 sdk.NewAttribute(types.AttributeKeyPmtpRateParams, rateParams.String()),
262 sdk.NewAttribute(types.AttributeKeyHeight, strconv.FormatInt(ctx.BlockHeight(), 10)),
263 ),
264 sdk.NewEvent(
265 sdk.EventTypeMessage,
266 sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
267 sdk.NewAttribute(sdk.AttributeKeySender, msg.Signer),
268 ),
269 })
270 }
271 ctx.EventManager().EmitEvents(events)

Callers

nothing calls this directly

Calls 10

StringCompareFunction · 0.92
IsInsidePmtpWindowMethod · 0.80
SetPmtpRateParamsMethod · 0.80
SetPmtpParamsMethod · 0.80
SetPmtpEpochMethod · 0.80
IsAdminAccountMethod · 0.65
GetPmtpParamsMethod · 0.65
GetPmtpRateParamsMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected