Compare commits

...

7 Commits

Author SHA1 Message Date
alfred-mk
40c8cfa874 Use the default vouchersResp 2025-03-20 16:11:59 +03:00
alfred-mk
1bc2ef94e9 Added default voucher response 2025-03-20 16:04:40 +03:00
alfred-mk
e681c9cfca Added debug logs
Some checks failed
release / docker (push) Has been cancelled
2025-03-20 15:23:36 +03:00
alfred-mk
d504571014 Added debug logs
Some checks failed
release / docker (push) Has been cancelled
2025-03-20 15:07:02 +03:00
alfred-mk
3b16e25ebd Added debug logs
Some checks failed
release / docker (push) Has been cancelled
2025-03-20 14:54:06 +03:00
alfred-mk
5f37856927 Added activeSym logs
Some checks failed
release / docker (push) Has been cancelled
2025-03-20 14:35:06 +03:00
Carlosokumu
e564f1328b add fetched vouchers log
Some checks failed
release / docker (push) Has been cancelled
2025-03-20 13:48:34 +03:00
2 changed files with 48 additions and 6 deletions

View File

@@ -1468,7 +1468,6 @@ func loadUserContent(ctx context.Context, activeSym string, balance string, alia
// CheckBalance retrieves the balance of the active voucher and sets
// the balance as the result content.
func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var (
res resource.Result
err error
@@ -1496,19 +1495,22 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
// get the active sym and active balance
activeSym, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
if err != nil {
fmt.Println("could not find the activeSym in checkBalance:", err)
if !db.IsNotFound(err) {
fmt.Println("the err:", err)
logg.ErrorCtxf(ctx, "failed to read activeSym entry with", "key", storedb.DATA_ACTIVE_SYM, "error", err)
return res, err
}
}
fmt.Println("The active data in CheckBalance:", string(activeSym))
activeBal, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_BAL)
if err != nil {
if !db.IsNotFound(err) {
logg.ErrorCtxf(ctx, "failed to read activeBal entry with", "key", storedb.DATA_ACTIVE_BAL, "error", err)
return res, err
}
}
content, err = loadUserContent(ctx, string(activeSym), string(activeBal), alias)
@@ -1930,7 +1932,6 @@ func (h *MenuHandlers) InitiateTransaction(ctx context.Context, sym string, inpu
// and sets the first as the default voucher, if no active voucher is set.
func (h *MenuHandlers) SetDefaultVoucher(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
var err error
userStore := h.userdataStore
sessionId, ok := ctx.Value("SessionId").(string)
@@ -1941,9 +1942,12 @@ func (h *MenuHandlers) SetDefaultVoucher(ctx context.Context, sym string, input
flag_no_active_voucher, _ := h.flagManager.GetFlag("flag_no_active_voucher")
// check if the user has an active sym
_, err = userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
activeSym, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
fmt.Println("The activeSym in SetDefaultVoucher:", string(activeSym))
if err != nil {
fmt.Println("The err", err)
fmt.Println("Checking the data as no activeSym", "DATA_ACTIVE_SYM", storedb.DATA_ACTIVE_SYM)
if db.IsNotFound(err) {
publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
if err != nil {
@@ -1954,12 +1958,25 @@ func (h *MenuHandlers) SetDefaultVoucher(ctx context.Context, sym string, input
// Fetch vouchers from the API using the public key
vouchersResp, err := h.accountService.FetchVouchers(ctx, string(publicKey))
if err != nil {
fmt.Println("setting the flag_no_active_voucher")
res.FlagSet = append(res.FlagSet, flag_no_active_voucher)
return res, nil
}
// vouchersResp := []dataserviceapi.TokenHoldings{
// {
// ContractAddress: "0xcB453B742Bc8BE1BAa03Ce1927e287788d0aF065",
// TokenSymbol: "PES",
// TokenDecimals: "6",
// Balance: "10000000",
// },
// }
fmt.Println("fetched user vouchers in SetDefaultVoucher", "public_key", string(publicKey), "vouchers", vouchersResp)
// Return if there is no voucher
if len(vouchersResp) == 0 {
fmt.Println("setting the flag_no_active_voucher in SetDefaultVoucher")
res.FlagSet = append(res.FlagSet, flag_no_active_voucher)
return res, nil
}
@@ -1974,10 +1991,14 @@ func (h *MenuHandlers) SetDefaultVoucher(ctx context.Context, sym string, input
// Scale down the balance
scaledBalance := store.ScaleDownBalance(defaultBal, defaultDec)
fmt.Println("firstVoucher data", "defaultSym", defaultSym, "defaultBal", defaultBal, "defaultDec", defaultDec, "defaultAddr", defaultAddr)
// TODO: implement atomic transaction
// set the active symbol
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM, []byte(defaultSym))
if err != nil {
fmt.Println("got an error in writing DATA_ACTIVE_SYM", "defaultSym", defaultSym)
logg.ErrorCtxf(ctx, "failed to write defaultSym entry with", "key", storedb.DATA_ACTIVE_SYM, "value", defaultSym, "error", err)
return res, err
}
@@ -2003,7 +2024,7 @@ func (h *MenuHandlers) SetDefaultVoucher(ctx context.Context, sym string, input
return res, nil
}
logg.ErrorCtxf(ctx, "failed to read activeSym entry with", "key", storedb.DATA_ACTIVE_SYM, "error", err)
fmt.Println("failed to read activeSym entry with", "key", storedb.DATA_ACTIVE_SYM, "error", err)
return res, err
}
@@ -2034,6 +2055,17 @@ func (h *MenuHandlers) CheckVouchers(ctx context.Context, sym string, input []by
return res, nil
}
// vouchersResp := []dataserviceapi.TokenHoldings{
// {
// ContractAddress: "0xcB453B742Bc8BE1BAa03Ce1927e287788d0aF065",
// TokenSymbol: "PES",
// TokenDecimals: "6",
// Balance: "10000000",
// },
// }
fmt.Println("fetched user vouchers", "public_key", string(publicKey), "vouchers", vouchersResp)
// check the current active sym and update the data
activeSym, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
if activeSym != nil {
@@ -2066,8 +2098,15 @@ func (h *MenuHandlers) CheckVouchers(ctx context.Context, sym string, input []by
}
}
activeBal, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_BAL)
activeAddr, _ := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_ADDRESS)
fmt.Println(ctx, "The active data in CheckVouchers:", "activeSym", string(activeSym), string(activeBal), string(activeAddr))
data := store.ProcessVouchers(vouchersResp)
fmt.Println(ctx, "The data in CheckVouchers:", "data", data)
// Store all voucher data
dataMap := map[storedb.DataTyp]string{
storedb.DATA_VOUCHER_SYMBOLS: data.Symbols,

View File

@@ -33,11 +33,14 @@ func (s *SubPrefixDb) toKey(k []byte) []byte {
func (s *SubPrefixDb) Get(ctx context.Context, key []byte) ([]byte, error) {
s.store.SetPrefix(db.DATATYPE_USERDATA)
key = s.toKey(key)
logg.InfoCtxf(ctx, "SubPrefixDb Get log", "key", string(key))
return s.store.Get(ctx, key)
}
func (s *SubPrefixDb) Put(ctx context.Context, key []byte, val []byte) error {
s.store.SetPrefix(db.DATATYPE_USERDATA)
key = s.toKey(key)
logg.InfoCtxf(ctx, "SubPrefixDb Put log", "key", string(key))
return s.store.Put(ctx, key, val)
}