github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/order/keeper/disk_cache_keeper.go (about) 1 package keeper 2 3 import ( 4 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 5 "github.com/fibonacci-chain/fbc/x/common" 6 "github.com/fibonacci-chain/fbc/x/order/types" 7 ) 8 9 // =============================================== 10 11 // SetBlockOrderNum sets BlockOrderNum to keeper 12 // BlockOrderNum means OrderNum at a given BlockHeight 13 func (k Keeper) SetBlockOrderNum(ctx sdk.Context, blockHeight int64, orderNum int64) { 14 store := ctx.KVStore(k.orderStoreKey) 15 key := types.GetOrderNumPerBlockKey(blockHeight) 16 store.Set(key, common.Int64ToBytes(orderNum)) 17 } 18 19 // DropBlockOrderNum deletes OrderNum from keeper 20 func (k Keeper) DropBlockOrderNum(ctx sdk.Context, blockHeight int64) { 21 store := ctx.KVStore(k.orderStoreKey) 22 key := types.GetOrderNumPerBlockKey(blockHeight) 23 store.Delete(key) 24 } 25 26 // =============================================== 27 28 // SetExpireBlockHeight sets ExpireBlockHeight to keeper 29 // ExpireBlockHeight means a slice of expired height that need to be solved 30 func (k Keeper) SetExpireBlockHeight(ctx sdk.Context, blockHeight int64, expireBlockHeight []int64) { 31 store := ctx.KVStore(k.orderStoreKey) 32 key := types.GetExpireBlockHeightKey(blockHeight) 33 store.Set(key, k.cdc.MustMarshalBinaryBare(expireBlockHeight)) 34 } 35 36 // DropExpireBlockHeight deletes ExpireBlockHeight from keeper 37 func (k Keeper) DropExpireBlockHeight(ctx sdk.Context, blockHeight int64) { 38 store := ctx.KVStore(k.orderStoreKey) 39 key := types.GetExpireBlockHeightKey(blockHeight) 40 store.Delete(key) 41 } 42 43 // =============================================== 44 // nolint 45 func (k Keeper) SetOrder(ctx sdk.Context, orderID string, order *types.Order) { 46 store := ctx.KVStore(k.orderStoreKey) 47 store.Set(types.GetOrderKey(orderID), k.cdc.MustMarshalBinaryBare(order)) 48 } 49 50 // nolint 51 func (k Keeper) DropOrder(ctx sdk.Context, orderID string) { 52 store := ctx.KVStore(k.orderStoreKey) 53 store.Delete(types.GetOrderKey(orderID)) 54 } 55 56 // =============================================== 57 // nolint 58 func (k Keeper) StoreDepthBook(ctx sdk.Context, product string, depthBook *types.DepthBook) { 59 store := ctx.KVStore(k.orderStoreKey) 60 if depthBook == nil || len(depthBook.Items) == 0 { 61 store.Delete(types.GetDepthBookKey(product)) 62 } else { 63 store.Set(types.GetDepthBookKey(product), k.cdc.MustMarshalBinaryBare(depthBook)) // 64 } 65 } 66 67 // =============================================== 68 // LastPrice means the latest transaction price of a given Product 69 // nolint 70 func (k Keeper) SetLastPrice(ctx sdk.Context, product string, price sdk.Dec) { 71 store := ctx.KVStore(k.orderStoreKey) 72 store.Set(types.GetPriceKey(product), k.cdc.MustMarshalBinaryBare(price)) 73 k.diskCache.setLastPrice(product, price) 74 } 75 76 // =============================================== 77 // nolint 78 func (k Keeper) StoreOrderIDsMap(ctx sdk.Context, key string, orderIDs []string) { 79 store := ctx.KVStore(k.orderStoreKey) 80 if len(orderIDs) == 0 { 81 store.Delete(types.GetOrderIDsKey(key)) 82 } else { 83 store.Set(types.GetOrderIDsKey(key), k.cdc.MustMarshalJSON(orderIDs)) //StoreOrderIDsMap 84 } 85 } 86 87 // =============================================== 88 // 7. 89 90 //func (k Keeper) updateStoreProductLockMap(ctx sdk.Context, lockMap *types.ProductLockMap) { 91 // store := ctx.KVStore(k.otherStoreKey) 92 // bz, _ := json.Marshal(lockMap) 93 // store.Set([]byte("productLockMap"), bz) 94 //} 95 // 96 // 97 98 // =============================================== 99 // LastExpiredBlockHeight means that the block height of his expired height 100 // list has been processed by expired recently 101 // nolint 102 func (k Keeper) SetLastExpiredBlockHeight(ctx sdk.Context, expiredBlockHeight int64) { 103 store := ctx.KVStore(k.orderStoreKey) 104 store.Set(types.LastExpiredBlockHeightKey, common.Int64ToBytes(expiredBlockHeight)) //lastExpiredBlockHeight 105 } 106 107 // =============================================== 108 // OpenOrderNum means the number of orders currently in the open state 109 // nolint 110 func (k Keeper) setOpenOrderNum(ctx sdk.Context, orderNum int64) { 111 store := ctx.KVStore(k.orderStoreKey) 112 store.Set(types.OpenOrderNumKey, common.Int64ToBytes(orderNum)) //openOrderNum 113 } 114 115 // =============================================== 116 // StoreOrderNum means the number of orders currently stored 117 // nolint 118 func (k Keeper) setStoreOrderNum(ctx sdk.Context, orderNum int64) { 119 store := ctx.KVStore(k.orderStoreKey) 120 store.Set(types.StoreOrderNumKey, common.Int64ToBytes(orderNum)) //StoreOrderNum 121 } 122 123 // =============================================== 124 125 // SetLastClosedOrderIDs sets closed order ids in this block 126 func (k Keeper) SetLastClosedOrderIDs(ctx sdk.Context, orderIDs []string) { 127 store := ctx.KVStore(k.orderStoreKey) 128 if len(orderIDs) == 0 { 129 store.Delete(types.RecentlyClosedOrderIDsKey) 130 } 131 store.Set(types.RecentlyClosedOrderIDsKey, k.cdc.MustMarshalJSON(orderIDs)) //recentlyClosedOrderIDs 132 } 133 134 // SetOrderIDs sets OrderIDs to diskCache 135 func (k Keeper) SetOrderIDs(key string, orderIDs []string) { 136 k.diskCache.setOrderIDs(key, orderIDs) 137 } 138 139 // GetProductsFromDepthBookMap gets products from DepthBookMap in diskCache 140 func (k Keeper) GetProductsFromDepthBookMap() []string { 141 return k.diskCache.getProductsFromDepthBookMap() 142 }