-
Notifications
You must be signed in to change notification settings - Fork 191
/
trade_route.go
53 lines (44 loc) · 1.84 KB
/
trade_route.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package keeper
import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/Stride-Labs/stride/v17/x/stakeibc/types"
)
// SetTradeRoute set a specific tradeRoute in the store
func (k Keeper) SetTradeRoute(ctx sdk.Context, tradeRoute types.TradeRoute) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.TradeRouteKeyPrefix))
key := tradeRoute.GetKey()
b := k.cdc.MustMarshal(&tradeRoute)
store.Set(key, b)
}
// GetTradeRoute returns a tradeRoute from its start and end denoms
// The start and end denom's are in their native format (e.g. uusdc and udydx)
func (k Keeper) GetTradeRoute(ctx sdk.Context, rewardDenom string, hostDenom string) (val types.TradeRoute, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.TradeRouteKeyPrefix))
key := types.TradeRouteKeyFromDenoms(rewardDenom, hostDenom)
b := store.Get(key)
if len(b) == 0 {
return val, false
}
k.cdc.MustUnmarshal(b, &val)
return val, true
}
// RemoveTradeRoute removes a tradeRoute from the store
// The start and end denom's are in their native format (e.g. uusdc and udydx)
func (k Keeper) RemoveTradeRoute(ctx sdk.Context, rewardDenom string, hostDenom string) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.TradeRouteKeyPrefix))
key := types.TradeRouteKeyFromDenoms(rewardDenom, hostDenom)
store.Delete(key)
}
// GetAllTradeRoute returns all tradeRoutes
func (k Keeper) GetAllTradeRoutes(ctx sdk.Context) (list []types.TradeRoute) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.TradeRouteKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte{})
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var val types.TradeRoute
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}
return
}