Skip to content

Commit

Permalink
feat: add renewal price policy for subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
ironman0x7b2 committed Dec 13, 2024
1 parent 7b0f324 commit 76d3a34
Show file tree
Hide file tree
Showing 20 changed files with 566 additions and 359 deletions.
3 changes: 2 additions & 1 deletion proto/sentinel/plan/v3/msg.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sentinel.plan.v3;

import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";
import "sentinel/types/v1/renewal.proto";
import "sentinel/types/v1/status.proto";

option go_package = "github.com/sentinel-official/hub/v12/x/plan/types/v3";
Expand Down Expand Up @@ -42,7 +43,7 @@ message MsgStartSessionRequest {
string from = 1;
uint64 id = 2 [(gogoproto.customname) = "ID"];
string denom = 3;
bool renewable = 4;
sentinel.types.v1.RenewalPricePolicy renewal_price_policy = 4;
string node_address = 5;
}

Expand Down
8 changes: 5 additions & 3 deletions proto/sentinel/subscription/v3/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ message EventCreate {
uint64 plan_id = 2 [(gogoproto.customname) = "PlanID"];
string acc_address = 3;
string prov_address = 4;
string price = 5;
string base_price = 5;
string quote_price = 6;
}

message EventCreateSession {
Expand All @@ -44,14 +45,15 @@ message EventRenew {
uint64 plan_id = 2 [(gogoproto.customname) = "PlanID"];
string acc_address = 3;
string prov_address = 4;
string price = 5;
string base_price = 5;
string quote_price = 6;
}

message EventUpdate {
uint64 id = 1 [(gogoproto.customname) = "ID"];
uint64 plan_id = 2 [(gogoproto.customname) = "PlanID"];
string acc_address = 3;
bool renewable = 4;
string renewal_price_policy = 4;
sentinel.types.v1.Status status = 5;
string inactive_at = 6;
string status_at = 7;
Expand Down
5 changes: 3 additions & 2 deletions proto/sentinel/subscription/v3/msg.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sentinel.subscription.v3;

import "gogoproto/gogo.proto";
import "sentinel/subscription/v2/params.proto";
import "sentinel/types/v1/renewal.proto";

option go_package = "github.com/sentinel-official/hub/v12/x/subscription/types/v3";
option (gogoproto.equal_all) = false;
Expand Down Expand Up @@ -33,13 +34,13 @@ message MsgStartSubscriptionRequest {
string from = 1;
uint64 id = 2 [(gogoproto.customname) = "ID"];
string denom = 3;
bool renewable = 4;
sentinel.types.v1.RenewalPricePolicy renewal_price_policy = 4;
}

message MsgUpdateSubscriptionRequest {
string from = 1;
uint64 id = 2 [(gogoproto.customname) = "ID"];
bool renewable = 3;
sentinel.types.v1.RenewalPricePolicy renewal_price_policy = 3;
}

message MsgStartSessionRequest {
Expand Down
12 changes: 7 additions & 5 deletions proto/sentinel/subscription/v3/subscription.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package sentinel.subscription.v3;
import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "sentinel/types/v1/renewal.proto";
import "sentinel/types/v1/status.proto";

option go_package = "github.com/sentinel-official/hub/v12/x/subscription/types/v3";
Expand All @@ -14,14 +15,15 @@ message Subscription {
uint64 id = 1 [(gogoproto.customname) = "ID"];
string acc_address = 2;
uint64 plan_id = 3 [(gogoproto.customname) = "PlanID"];
cosmos.base.v1beta1.Coin price = 4 [(gogoproto.nullable) = false];
bool renewable = 5;
sentinel.types.v1.Status status = 6;
google.protobuf.Timestamp inactive_at = 7 [
cosmos.base.v1beta1.DecCoin base_price = 4 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin quote_price = 5 [(gogoproto.nullable) = false];
sentinel.types.v1.RenewalPricePolicy renewal_price_policy = 6;
sentinel.types.v1.Status status = 7;
google.protobuf.Timestamp inactive_at = 8 [
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true
];
google.protobuf.Timestamp status_at = 8 [
google.protobuf.Timestamp status_at = 9 [
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true
];
Expand Down
2 changes: 1 addition & 1 deletion x/lease/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func txUpdateLease() *cobra.Command {
}

flags.AddTxFlagsToCmd(cmd)
cmd.Flags().Bool(flagRenewalPricePolicy, false, "Specify the lease renewal price policy")
cmd.Flags().String(flagRenewalPricePolicy, "", "Specify the lease renewal price policy")

return cmd
}
2 changes: 1 addition & 1 deletion x/lease/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (k *Keeper) handleLeaseRenewals(ctx sdk.Context) {
// Execute the handler to process the lease renewal
resp, err := handler(cc, msg)
if err != nil {
k.Logger(cc).Error("Failed to handle lease renewal", "id", item.ID, "error", err)
k.Logger(cc).Error("Failed to handle lease renewal", "id", item.ID, "message", err)
return false
}

Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (k *Keeper) BeginBlock(ctx sdk.Context) {
// Send the GetProtoRevPool query packet over IBC.
sequence, err := k.SendQueryPacket(ctx, channelCap, portID, channelID, uint64(timeout), req)
if err != nil {
k.Logger(ctx).Error("Failed to send query packet", "asset", item.Denom, "error", err)
k.Logger(ctx).Error("Failed to send query packet", "asset", item.Denom, "message", err)
return false
}

Expand Down
8 changes: 4 additions & 4 deletions x/plan/keeper/msg_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ func (k *Keeper) HandleMsgUpdatePlanStatus(ctx sdk.Context, msg *v3.MsgUpdatePla

func (k *Keeper) HandleMsgStartSession(ctx sdk.Context, msg *v3.MsgStartSessionRequest) (*v3.MsgStartSessionResponse, error) {
subscriptionReq := &subscriptiontypes.MsgStartSubscriptionRequest{
From: msg.From,
ID: msg.ID,
Denom: msg.Denom,
Renewable: msg.Renewable,
From: msg.From,
ID: msg.ID,
Denom: msg.Denom,
RenewalPricePolicy: msg.RenewalPricePolicy,
}

subscriptionResp, err := k.subscription.HandleMsgStartSubscription(ctx, subscriptionReq)
Expand Down
15 changes: 9 additions & 6 deletions x/plan/types/v3/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ func (m *MsgUpdatePlanStatusRequest) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{from.Bytes()}
}

func NewMsgStartSessionRequest(from sdk.AccAddress, id uint64, denom string, renewable bool, nodeAddr base.NodeAddress) *MsgStartSessionRequest {
func NewMsgStartSessionRequest(from sdk.AccAddress, id uint64, denom string, renewalPricePolicy v1base.RenewalPricePolicy, nodeAddr base.NodeAddress) *MsgStartSessionRequest {
return &MsgStartSessionRequest{
From: from.String(),
ID: id,
Denom: denom,
Renewable: renewable,
NodeAddress: nodeAddr.String(),
From: from.String(),
ID: id,
Denom: denom,
RenewalPricePolicy: renewalPricePolicy,
NodeAddress: nodeAddr.String(),
}
}

Expand All @@ -195,6 +195,9 @@ func (m *MsgStartSessionRequest) ValidateBasic() error {
return sdkerrors.Wrap(types.ErrInvalidMessage, err.Error())
}
}
if !m.RenewalPricePolicy.IsValid() {
return sdkerrors.Wrap(types.ErrInvalidMessage, "renewal_price_policy must be valid")
}
if m.NodeAddress == "" {
return sdkerrors.Wrap(types.ErrInvalidMessage, "node_address cannot be empty")
}
Expand Down
116 changes: 56 additions & 60 deletions x/plan/types/v3/msg.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions x/subscription/client/cli/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cli

import (
"github.com/spf13/pflag"

v1base "github.com/sentinel-official/hub/v12/types/v1"
)

const (
flagDenom = "denom"
flagRenewalPricePolicy = "renewal-price-policy"
)

func GetRenewalPricePolicy(flags *pflag.FlagSet) (v1base.RenewalPricePolicy, error) {
s, err := flags.GetString(flagRenewalPricePolicy)
if err != nil {
return v1base.RenewalPricePolicyUnspecified, err
}
if s == "" {
return v1base.RenewalPricePolicyUnspecified, nil
}

return v1base.RenewalPricePolicyFromString(s), nil
}
Loading

0 comments on commit 76d3a34

Please sign in to comment.