From 6532dd89f42a59327a30a8531dfc13e270411f17 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Sat, 7 Jun 2025 04:40:51 +0300 Subject: [PATCH] add pool related helper functions, for storing, reading and updating pool data --- store/pools.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/store/pools.go b/store/pools.go index 1e01329..0cf918d 100644 --- a/store/pools.go +++ b/store/pools.go @@ -91,3 +91,52 @@ func MatchPool(input, names, symbols, addresses string) (name, symbol, address s } return } + +// StoreTemporaryPool saves pool metadata as temporary entries in the DataStore. +func StoreTemporaryPool(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.PoolDetails) error { + tempData := fmt.Sprintf("%s,%s,%s", data.PoolName, data.PoolSymbol, data.PoolContractAdrress) + + if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tempData)); err != nil { + return err + } + + return nil +} + +// GetTemporaryPoolData retrieves temporary pool metadata from the DataStore. +func GetTemporaryPoolData(ctx context.Context, store DataStore, sessionId string) (*dataserviceapi.PoolDetails, error) { + temp_data, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE) + if err != nil { + return nil, err + } + + values := strings.SplitN(string(temp_data), ",", 3) + + data := &dataserviceapi.PoolDetails{} + + data.PoolName = values[0] + data.PoolSymbol = values[1] + data.PoolContractAdrress = values[2] + + return data, nil +} + +// UpdatePoolData updates the active pool data in the DataStore. +func UpdatePoolData(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.PoolDetails) error { + logg.TraceCtxf(ctx, "dtal", "data", data) + // Active pool data entry + activeEntries := map[storedb.DataTyp][]byte{ + storedb.DATA_ACTIVE_POOL_NAME: []byte(data.PoolName), + storedb.DATA_ACTIVE_POOL_SYM: []byte(data.PoolSymbol), + storedb.DATA_ACTIVE_POOL_ADDRESS: []byte(data.PoolContractAdrress), + } + + // Write active data + for key, value := range activeEntries { + if err := store.WriteEntry(ctx, sessionId, key, value); err != nil { + return err + } + } + + return nil +} \ No newline at end of file