Skip to content

Commit db06968

Browse files
committed
feat: only provider can subscribe to a private subscription plan
1 parent bf8b80a commit db06968

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

x/subscription/keeper/msg_handler.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,26 @@ func (k *Keeper) HandleMsgStartSubscription(ctx sdk.Context, msg *v3.MsgStartSub
255255
return nil, types.NewErrorInvalidPlanStatus(plan.ID, plan.Status)
256256
}
257257

258-
price, found := plan.Price(msg.Denom)
259-
if !found {
260-
return nil, types.NewErrorPriceNotFound(msg.Denom)
258+
accAddr, err := sdk.AccAddressFromBech32(msg.From)
259+
if err != nil {
260+
return nil, err
261261
}
262262

263-
price, err := price.UpdateQuoteValue(ctx, k.QuotePriceFunc)
263+
provAddr, err := base.ProvAddressFromBech32(plan.ProvAddress)
264264
if err != nil {
265265
return nil, err
266266
}
267267

268-
accAddr, err := sdk.AccAddressFromBech32(msg.From)
268+
if plan.IsPrivate() && !accAddr.Equals(provAddr) {
269+
return nil, types.NewErrorUnauthorized(msg.From)
270+
}
271+
272+
price, found := plan.Price(msg.Denom)
273+
if !found {
274+
return nil, types.NewErrorPriceNotFound(msg.Denom)
275+
}
276+
277+
price, err = price.UpdateQuoteValue(ctx, k.QuotePriceFunc)
269278
if err != nil {
270279
return nil, err
271280
}
@@ -291,11 +300,6 @@ func (k *Keeper) HandleMsgStartSubscription(ctx sdk.Context, msg *v3.MsgStartSub
291300
return nil, err
292301
}
293302

294-
provAddr, err := base.ProvAddressFromBech32(plan.ProvAddress)
295-
if err != nil {
296-
return nil, err
297-
}
298-
299303
payment := totalPayment.Sub(reward)
300304
if err := k.SendCoin(ctx, accAddr, provAddr.Bytes(), payment); err != nil {
301305
return nil, err

0 commit comments

Comments
 (0)