@@ -19,11 +19,16 @@ func (k *Keeper) HandleMsgCreatePlan(ctx sdk.Context, msg *v3.MsgCreatePlanReque
1919 return nil , err
2020 }
2121
22- // Ensure provider exists in the state
23- if ! k .HasProvider (ctx , provAddr ) {
22+ // Verify the provider exists and is in an active state
23+ provider , found := k .GetProvider (ctx , provAddr )
24+ if ! found {
2425 return nil , types .NewErrorProviderNotFound (provAddr )
2526 }
2627
28+ if ! provider .Status .Equal (v1base .StatusActive ) {
29+ return nil , types .NewErrorInvalidProviderStatus (provAddr , provider .Status )
30+ }
31+
2732 // Construct the new plan with an incremented ID and inactive status
2833 count := k .GetPlanCount (ctx )
2934 plan := v3.Plan {
@@ -76,16 +81,6 @@ func (k *Keeper) HandleMsgLinkNode(ctx sdk.Context, msg *v3.MsgLinkNodeRequest)
7681 return nil , err
7782 }
7883
79- // Ensure the node exists and is active
80- node , found := k .GetNode (ctx , nodeAddr )
81- if ! found {
82- return nil , types .NewErrorNodeNotFound (nodeAddr )
83- }
84-
85- if ! node .Status .Equal (v1base .StatusActive ) {
86- return nil , types .NewErrorInvalidNodeStatus (nodeAddr , node .Status )
87- }
88-
8984 // Prevent duplicate node linkage for the same plan
9085 if k .HasNodeForPlan (ctx , plan .ID , nodeAddr ) {
9186 return nil , types .NewErrorDuplicateNodeForPlan (plan .ID , nodeAddr )
@@ -111,7 +106,7 @@ func (k *Keeper) HandleMsgLinkNode(ctx sdk.Context, msg *v3.MsgLinkNodeRequest)
111106 & v3.EventLinkNode {
112107 PlanID : plan .ID ,
113108 ProvAddress : plan .ProvAddress ,
114- NodeAddress : node . Address ,
109+ NodeAddress : nodeAddr . String () ,
115110 },
116111 )
117112
@@ -182,6 +177,23 @@ func (k *Keeper) HandleMsgUpdatePlanStatus(ctx sdk.Context, msg *v3.MsgUpdatePla
182177 return nil , types .NewErrorUnauthorized (msg .From )
183178 }
184179
180+ if msg .Status .Equal (v1base .StatusActive ) {
181+ provAddr , err := base .ProvAddressFromBech32 (plan .ProvAddress )
182+ if err != nil {
183+ return nil , err
184+ }
185+
186+ // Ensure provider exists and is currently active
187+ provider , found := k .GetProvider (ctx , provAddr )
188+ if ! found {
189+ return nil , types .NewErrorProviderNotFound (provAddr )
190+ }
191+
192+ if ! provider .Status .Equal (v1base .StatusActive ) {
193+ return nil , types .NewErrorInvalidProviderStatus (provAddr , provider .Status )
194+ }
195+ }
196+
185197 // Remove old status index if transitioning state
186198 if msg .Status .Equal (v1base .StatusActive ) {
187199 if plan .Status .Equal (v1base .StatusInactive ) {
0 commit comments