add-pool-selection #79
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user