From e8978413a5bfe294801108ba95a97054f4cb3311 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 26 Feb 2025 13:10:15 +0300 Subject: [PATCH] added pool db processing --- store/db/db.go | 9 +++++++++ store/pools.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 store/pools.go diff --git a/store/db/db.go b/store/db/db.go index 10f360a..923d0b7 100644 --- a/store/db/db.go +++ b/store/db/db.go @@ -101,6 +101,15 @@ const ( DATA_TRANSACTIONS = 1024 + iota ) +const ( + // List of voucher symbols in the top pools context. + DATA_POOL_NAMES = 2048 + iota + // List of symbols in the top pools context. + DATA_POOL_SYMBOLS + // List of contact addresses in the top pools context + DATA_POOL_ADDRESSES +) + var ( logg = logging.NewVanilla().WithDomain("urdt-common") ) diff --git a/store/pools.go b/store/pools.go new file mode 100644 index 0000000..f21ee30 --- /dev/null +++ b/store/pools.go @@ -0,0 +1,33 @@ +package store + +import ( + "fmt" + "strings" + + dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" +) + +// PoolsMetadata helps organize data fields +type PoolsMetadata struct { + PoolNames string + PoolSymbols string + PoolContractAdrresses string +} + +// ProcessPools converts pools into formatted strings +func ProcessPools(pools []dataserviceapi.PoolDetails) PoolsMetadata { + var data PoolsMetadata + var poolNames, poolSymbols, poolContractAdrresses []string + + for i, p := range pools { + poolNames = append(poolNames, fmt.Sprintf("%d:%s", i+1, p.PoolName)) + poolSymbols = append(poolSymbols, fmt.Sprintf("%d:%s", i+1, p.PoolSymbol)) + poolContractAdrresses = append(poolContractAdrresses, fmt.Sprintf("%d:%s", i+1, p.PoolContractAdrress)) + } + + data.PoolNames = strings.Join(poolNames, "\n") + data.PoolSymbols = strings.Join(poolSymbols, "\n") + data.PoolContractAdrresses = strings.Join(poolContractAdrresses, "\n") + + return data +}