lash/export-to-term #157

Merged
lash merged 92 commits from lash/export-to-term into master 2024-11-04 13:54:59 +01:00
3 changed files with 28 additions and 29 deletions
Showing only changes of commit 4bf56c525f - Show all commits

View File

@ -1,4 +1,4 @@
package utils package common
import ( import (
"context" "context"
@ -6,7 +6,6 @@ import (
"strings" "strings"
"git.grassecon.net/urdt/ussd/internal/storage" "git.grassecon.net/urdt/ussd/internal/storage"
"git.grassecon.net/urdt/ussd/common"
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
) )
@ -96,13 +95,13 @@ func MatchVoucher(input, symbols, balances, decimals, addresses string) (symbol,
return return
} }
// StoreTemporaryVoucher saves voucher metadata as temporary entries in the common.DataStore. // StoreTemporaryVoucher saves voucher metadata as temporary entries in the DataStore.
func StoreTemporaryVoucher(ctx context.Context, store common.DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error { func StoreTemporaryVoucher(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error {
entries := map[common.DataTyp][]byte{ entries := map[DataTyp][]byte{
common.DATA_TEMPORARY_SYM: []byte(data.TokenSymbol), DATA_TEMPORARY_SYM: []byte(data.TokenSymbol),
common.DATA_TEMPORARY_BAL: []byte(data.Balance), DATA_TEMPORARY_BAL: []byte(data.Balance),
common.DATA_TEMPORARY_DECIMAL: []byte(data.TokenDecimals), DATA_TEMPORARY_DECIMAL: []byte(data.TokenDecimals),
common.DATA_TEMPORARY_ADDRESS: []byte(data.ContractAddress), DATA_TEMPORARY_ADDRESS: []byte(data.ContractAddress),
} }
for key, value := range entries { for key, value := range entries {
@ -113,13 +112,13 @@ func StoreTemporaryVoucher(ctx context.Context, store common.DataStore, sessionI
return nil return nil
} }
// GetTemporaryVoucherData retrieves temporary voucher metadata from the common.DataStore. // GetTemporaryVoucherData retrieves temporary voucher metadata from the DataStore.
func GetTemporaryVoucherData(ctx context.Context, store common.DataStore, sessionId string) (*dataserviceapi.TokenHoldings, error) { func GetTemporaryVoucherData(ctx context.Context, store DataStore, sessionId string) (*dataserviceapi.TokenHoldings, error) {
keys := []common.DataTyp{ keys := []DataTyp{
common.DATA_TEMPORARY_SYM, DATA_TEMPORARY_SYM,
common.DATA_TEMPORARY_BAL, DATA_TEMPORARY_BAL,
common.DATA_TEMPORARY_DECIMAL, DATA_TEMPORARY_DECIMAL,
common.DATA_TEMPORARY_ADDRESS, DATA_TEMPORARY_ADDRESS,
} }
data := &dataserviceapi.TokenHoldings{} data := &dataserviceapi.TokenHoldings{}
@ -141,14 +140,14 @@ func GetTemporaryVoucherData(ctx context.Context, store common.DataStore, sessio
return data, nil return data, nil
} }
// UpdateVoucherData sets the active voucher data and clears the temporary voucher data in the common.DataStore. // UpdateVoucherData sets the active voucher data and clears the temporary voucher data in the DataStore.
func UpdateVoucherData(ctx context.Context, store common.DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error { func UpdateVoucherData(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error {
// Active voucher data entries // Active voucher data entries
activeEntries := map[common.DataTyp][]byte{ activeEntries := map[DataTyp][]byte{
common.DATA_ACTIVE_SYM: []byte(data.TokenSymbol), DATA_ACTIVE_SYM: []byte(data.TokenSymbol),
common.DATA_ACTIVE_BAL: []byte(data.Balance), DATA_ACTIVE_BAL: []byte(data.Balance),
common.DATA_ACTIVE_DECIMAL: []byte(data.TokenDecimals), DATA_ACTIVE_DECIMAL: []byte(data.TokenDecimals),
common.DATA_ACTIVE_ADDRESS: []byte(data.ContractAddress), DATA_ACTIVE_ADDRESS: []byte(data.ContractAddress),
} }
// Write active data // Write active data

View File

@ -1,4 +1,4 @@
package utils package common
import ( import (
"context" "context"

View File

@ -1117,7 +1117,7 @@ func (h *Handlers) CheckVouchers(ctx context.Context, sym string, input []byte)
return res, nil return res, nil
} }
data := utils.ProcessVouchers(vouchersResp) data := common.ProcessVouchers(vouchersResp)
// Store all voucher data // Store all voucher data
dataMap := map[string]string{ dataMap := map[string]string{
@ -1167,7 +1167,7 @@ func (h *Handlers) ViewVoucher(ctx context.Context, sym string, input []byte) (r
return res, nil return res, nil
} }
metadata, err := utils.GetVoucherData(ctx, h.prefixDb, inputStr) metadata, err := common.GetVoucherData(ctx, h.prefixDb, inputStr)
if err != nil { if err != nil {
return res, fmt.Errorf("failed to retrieve voucher data: %v", err) return res, fmt.Errorf("failed to retrieve voucher data: %v", err)
} }
@ -1177,7 +1177,7 @@ func (h *Handlers) ViewVoucher(ctx context.Context, sym string, input []byte) (r
return res, nil return res, nil
} }
if err := utils.StoreTemporaryVoucher(ctx, h.userdataStore, sessionId, metadata); err != nil { if err := common.StoreTemporaryVoucher(ctx, h.userdataStore, sessionId, metadata); err != nil {
return res, err return res, err
} }
@ -1198,13 +1198,13 @@ func (h *Handlers) SetVoucher(ctx context.Context, sym string, input []byte) (re
// Get temporary data // Get temporary data
tempData, err := utils.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId) tempData, err := common.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
if err != nil { if err != nil {
return res, err return res, err
} }
// Set as active and clear temporary data // Set as active and clear temporary data
if err := utils.UpdateVoucherData(ctx, h.userdataStore, sessionId, tempData); err != nil { if err := common.UpdateVoucherData(ctx, h.userdataStore, sessionId, tempData); err != nil {
return res, err return res, err
} }