Skip to content

Commit b5e9c41

Browse files
committed
chore: use context.Context instead sdk.Context in oracle GetQuotePrice method
1 parent 60804d2 commit b5e9c41

File tree

12 files changed

+30
-15
lines changed

12 files changed

+30
-15
lines changed

types/v1/price.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v1
22

33
import (
4+
"context"
45
"errors"
56
"fmt"
67
"sort"
@@ -11,7 +12,7 @@ import (
1112
)
1213

1314
// QuotePriceFunc defines a function signature for converting a base price to a quote price.
14-
type QuotePriceFunc func(ctx sdk.Context, basePrice sdk.DecCoin) (sdk.Coin, error)
15+
type QuotePriceFunc func(ctx context.Context, basePrice sdk.DecCoin) (sdk.Coin, error)
1516

1617
// NewPriceFromString parses a string like "denom:base,quote" into a Price.
1718
func NewPriceFromString(s string) (Price, error) {
@@ -217,7 +218,7 @@ func (p Price) Sub(v Price) Price {
217218
}
218219

219220
// UpdateQuoteValue applies a pricing function to compute a new quote value from the base.
220-
func (p Price) UpdateQuoteValue(ctx sdk.Context, fn QuotePriceFunc) (Price, error) {
221+
func (p Price) UpdateQuoteValue(ctx context.Context, fn QuotePriceFunc) (Price, error) {
221222
// If BaseValue is zero, return the original Price
222223
if p.BaseValue.IsZero() {
223224
return p, nil

x/lease/keeper/alias.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package keeper
22

33
import (
4+
"context"
5+
46
sdk "github.com/cosmos/cosmos-sdk/types"
57

68
base "github.com/sentinel-official/sentinelhub/v12/types"
@@ -44,7 +46,7 @@ func (k *Keeper) GetNode(ctx sdk.Context, addr base.NodeAddress) (nodetypes.Node
4446
return k.node.GetNode(ctx, addr)
4547
}
4648

47-
func (k *Keeper) QuotePriceFunc(ctx sdk.Context, price sdk.DecCoin) (sdk.Coin, error) {
49+
func (k *Keeper) GetQuotePrice(ctx context.Context, price sdk.DecCoin) (sdk.Coin, error) {
4850
return k.oracle.GetQuotePrice(ctx, price)
4951
}
5052

x/lease/keeper/expected.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package keeper
22

33
import (
4+
"context"
5+
46
sdk "github.com/cosmos/cosmos-sdk/types"
57
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
68

@@ -29,7 +31,7 @@ type NodeKeeper interface {
2931
}
3032

3133
type OracleKeeper interface {
32-
GetQuotePrice(ctx sdk.Context, price sdk.DecCoin) (sdk.Coin, error)
34+
GetQuotePrice(ctx context.Context, price sdk.DecCoin) (sdk.Coin, error)
3335
}
3436

3537
type PlanKeeper interface {

x/lease/keeper/msg_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (k *Keeper) HandleMsgRenewLease(ctx sdk.Context, msg *v1.MsgRenewLeaseReque
132132
}
133133

134134
// Convert price to current quote value; fail on error
135-
price, err = price.UpdateQuoteValue(ctx, k.QuotePriceFunc)
135+
price, err = price.UpdateQuoteValue(sdk.WrapSDKContext(ctx), k.GetQuotePrice)
136136
if err != nil {
137137
return nil, err
138138
}
@@ -257,7 +257,7 @@ func (k *Keeper) HandleMsgStartLease(ctx sdk.Context, msg *v1.MsgStartLeaseReque
257257
}
258258

259259
// Adjust the price using a quote function; handle any error
260-
price, err = price.UpdateQuoteValue(ctx, k.QuotePriceFunc)
260+
price, err = price.UpdateQuoteValue(sdk.WrapSDKContext(ctx), k.GetQuotePrice)
261261
if err != nil {
262262
return nil, err
263263
}

x/node/keeper/alias.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package keeper
22

33
import (
4+
"context"
45
"time"
56

67
"cosmossdk.io/math"
@@ -50,7 +51,7 @@ func (k *Keeper) SubtractDeposit(ctx sdk.Context, addr sdk.AccAddress, coin sdk.
5051
return k.deposit.SubtractDeposit(ctx, addr, sdk.NewCoins(coin))
5152
}
5253

53-
func (k *Keeper) QuotePriceFunc(ctx sdk.Context, price sdk.DecCoin) (sdk.Coin, error) {
54+
func (k *Keeper) GetQuotePrice(ctx context.Context, price sdk.DecCoin) (sdk.Coin, error) {
5455
return k.oracle.GetQuotePrice(ctx, price)
5556
}
5657

x/node/keeper/expected.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package keeper
22

33
import (
4+
"context"
45
"time"
56

67
"cosmossdk.io/math"
@@ -35,7 +36,7 @@ type LeaseKeeper interface {
3536
}
3637

3738
type OracleKeeper interface {
38-
GetQuotePrice(ctx sdk.Context, price sdk.DecCoin) (sdk.Coin, error)
39+
GetQuotePrice(ctx context.Context, price sdk.DecCoin) (sdk.Coin, error)
3940
}
4041

4142
type SessionKeeper interface {

x/node/keeper/msg_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (k *Keeper) HandleMsgStartSession(ctx sdk.Context, msg *v3.MsgStartSessionR
236236
}
237237

238238
// Adjust price using current quote mechanism
239-
price, err = price.UpdateQuoteValue(ctx, k.QuotePriceFunc)
239+
price, err = price.UpdateQuoteValue(sdk.WrapSDKContext(ctx), k.GetQuotePrice)
240240
if err != nil {
241241
return nil, err
242242
}

x/oracle/keeper/asset.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package keeper
22

33
import (
4+
"context"
5+
46
sdk "github.com/cosmos/cosmos-sdk/types"
57
ibchost "github.com/cosmos/ibc-go/v7/modules/core/24-host"
68
protobuf "github.com/gogo/protobuf/types"
@@ -122,7 +124,9 @@ func (k *Keeper) GetAssetForPacket(ctx sdk.Context, portID, channelID string, se
122124

123125
// GetQuotePrice retrieves a quote for a given DecCoin, applying asset pricing if available.
124126
// If the asset for the given denomination is not found, it returns an error.
125-
func (k *Keeper) GetQuotePrice(ctx sdk.Context, basePrice sdk.DecCoin) (sdk.Coin, error) {
127+
func (k *Keeper) GetQuotePrice(c context.Context, basePrice sdk.DecCoin) (sdk.Coin, error) {
128+
ctx := sdk.UnwrapSDKContext(c)
129+
126130
// Retrieve the asset associated with the coin denomination.
127131
asset, found := k.GetAsset(ctx, basePrice.Denom)
128132
if !found {

x/subscription/keeper/alias.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package keeper
22

33
import (
4+
"context"
45
"time"
56

67
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -35,7 +36,7 @@ func (k *Keeper) HasNodeForPlan(ctx sdk.Context, id uint64, addr base.NodeAddres
3536
return k.node.HasNodeForPlan(ctx, id, addr)
3637
}
3738

38-
func (k *Keeper) QuotePriceFunc(ctx sdk.Context, price sdk.DecCoin) (sdk.Coin, error) {
39+
func (k *Keeper) GetQuotePrice(ctx context.Context, price sdk.DecCoin) (sdk.Coin, error) {
3940
return k.oracle.GetQuotePrice(ctx, price)
4041
}
4142

x/subscription/keeper/expected.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package keeper
22

33
import (
4+
"context"
45
"time"
56

67
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -35,7 +36,7 @@ type NodeKeeper interface {
3536
}
3637

3738
type OracleKeeper interface {
38-
GetQuotePrice(ctx sdk.Context, price sdk.DecCoin) (sdk.Coin, error)
39+
GetQuotePrice(ctx context.Context, price sdk.DecCoin) (sdk.Coin, error)
3940
}
4041

4142
type PlanKeeper interface {

0 commit comments

Comments
 (0)