Compare commits
No commits in common. "c548ea0700b85fd2b1f0d99afd8af0fa47c768f7" and "916ac11585c580bf045b616a5279503a8741f6d9" have entirely different histories.
c548ea0700
...
916ac11585
@ -119,7 +119,7 @@ func (h *MenuHandlers) CalculateCreditAndDebt(ctx context.Context, sym string, i
|
||||
l.AddDomain("default")
|
||||
|
||||
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||
flag_no_stable_vouchers, _ := h.flagManager.GetFlag("flag_no_stable_vouchers")
|
||||
flag_no_pay_debt_vouchers, _ := h.flagManager.GetFlag("flag_no_pay_debt_vouchers")
|
||||
|
||||
// default response
|
||||
res.FlagReset = append(res.FlagReset, flag_api_call_error)
|
||||
@ -161,11 +161,11 @@ func (h *MenuHandlers) CalculateCreditAndDebt(ctx context.Context, sym string, i
|
||||
|
||||
// No stable vouchers → cannot pay debt
|
||||
if len(filteredSwappableVouchers) == 0 {
|
||||
res.FlagSet = append(res.FlagSet, flag_no_stable_vouchers)
|
||||
res.FlagSet = append(res.FlagSet, flag_no_pay_debt_vouchers)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
res.FlagReset = append(res.FlagReset, flag_no_stable_vouchers)
|
||||
res.FlagReset = append(res.FlagReset, flag_no_pay_debt_vouchers)
|
||||
|
||||
// Process stable vouchers for later use
|
||||
data := store.ProcessVouchers(filteredSwappableVouchers)
|
||||
|
||||
@ -1,220 +0,0 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.defalsify.org/vise.git/resource"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
"gopkg.in/leonelquinteros/gotext.v1"
|
||||
)
|
||||
|
||||
// GetPoolDepositVouchers returns a list of stable coins
|
||||
func (h *MenuHandlers) GetPoolDepositVouchers(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
|
||||
code := codeFromCtx(ctx)
|
||||
l := gotext.NewLocale(translationDir, code)
|
||||
l.AddDomain("default")
|
||||
|
||||
userStore := h.userdataStore
|
||||
|
||||
// Read stable vouchers from the store
|
||||
voucherData, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_STABLE_VOUCHER_SYMBOLS)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to read stable voucherData entires with", "key", storedb.DATA_STABLE_VOUCHER_SYMBOLS, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
if len(voucherData) == 0 {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
voucherBalances, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_STABLE_VOUCHER_BALANCES)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to read stable voucherData entires with", "key", storedb.DATA_STABLE_VOUCHER_BALANCES, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
formattedVoucherList := store.FormatVoucherList(ctx, string(voucherData), string(voucherBalances))
|
||||
finalOutput := strings.Join(formattedVoucherList, "\n")
|
||||
|
||||
res.Content = l.Get("Select number or symbol from your vouchers:\n%s", finalOutput)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// PoolDepositMaxAmount returns the balance of the selected voucher
|
||||
func (h *MenuHandlers) PoolDepositMaxAmount(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
|
||||
code := codeFromCtx(ctx)
|
||||
l := gotext.NewLocale(translationDir, code)
|
||||
l.AddDomain("default")
|
||||
|
||||
flag_incorrect_voucher, _ := h.flagManager.GetFlag("flag_incorrect_voucher")
|
||||
|
||||
res.FlagReset = append(res.FlagReset, flag_incorrect_voucher)
|
||||
|
||||
inputStr := string(input)
|
||||
if inputStr == "0" || inputStr == "99" || inputStr == "88" || inputStr == "98" {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
userStore := h.userdataStore
|
||||
metadata, err := store.GetStableVoucherData(ctx, userStore, sessionId, inputStr)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("failed to retrieve swap to voucher data: %v", err)
|
||||
}
|
||||
if metadata == nil {
|
||||
res.FlagSet = append(res.FlagSet, flag_incorrect_voucher)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Store the pool deposit voucher data
|
||||
if err := store.StoreTemporaryVoucher(ctx, h.userdataStore, sessionId, metadata); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on StoreTemporaryVoucher", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Format the balance amount to 2 decimal places
|
||||
formattedBalance, _ := store.TruncateDecimalString(string(metadata.Balance), 2)
|
||||
|
||||
res.Content = l.Get("Maximum amount: %s %s\nEnter amount:", formattedBalance, metadata.TokenSymbol)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ConfirmPoolDeposit displays the pool deposit preview for a PIN confirmation
|
||||
func (h *MenuHandlers) ConfirmPoolDeposit(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
|
||||
inputStr := string(input)
|
||||
if inputStr == "0" {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
flag_invalid_amount, _ := h.flagManager.GetFlag("flag_invalid_amount")
|
||||
|
||||
res.FlagReset = append(res.FlagReset, flag_invalid_amount)
|
||||
|
||||
code := codeFromCtx(ctx)
|
||||
l := gotext.NewLocale(translationDir, code)
|
||||
l.AddDomain("default")
|
||||
|
||||
userStore := h.userdataStore
|
||||
|
||||
poolDepositVoucher, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
maxValue, err := strconv.ParseFloat(poolDepositVoucher.Balance, 64)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "Failed to convert the swapMaxAmount to a float", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
inputAmount, err := strconv.ParseFloat(inputStr, 64)
|
||||
if err != nil || inputAmount > maxValue || inputAmount < 0.1 {
|
||||
res.FlagSet = append(res.FlagSet, flag_invalid_amount)
|
||||
res.Content = inputStr
|
||||
return res, nil
|
||||
}
|
||||
|
||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_AMOUNT, []byte(inputStr))
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to write pool deposit amount entry with", "key", storedb.DATA_AMOUNT, "value", inputStr, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Resolve active pool
|
||||
_, activePoolName, err := h.resolveActivePoolDetails(ctx, sessionId)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.Content = l.Get(
|
||||
"You will deposit %s %s into %s\n",
|
||||
inputStr, poolDepositVoucher.TokenSymbol, activePoolName,
|
||||
)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// InitiatePoolDeposit calls the pool deposit API
|
||||
func (h *MenuHandlers) InitiatePoolDeposit(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
var err error
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
|
||||
flag_account_authorized, _ := h.flagManager.GetFlag("flag_account_authorized")
|
||||
|
||||
code := codeFromCtx(ctx)
|
||||
l := gotext.NewLocale(translationDir, code)
|
||||
l.AddDomain("default")
|
||||
|
||||
// Resolve active pool
|
||||
activePoolAddress, activePoolName, err := h.resolveActivePoolDetails(ctx, sessionId)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
poolDepositVoucher, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
poolDepositdata, err := store.ReadTransactionData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
finalAmountStr, err := store.ParseAndScaleAmount(poolDepositdata.Amount, poolDepositVoucher.TokenDecimals)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Call pool deposit API
|
||||
r, err := h.accountService.PoolDeposit(ctx, finalAmountStr, poolDepositdata.PublicKey, string(activePoolAddress), poolDepositVoucher.TokenAddress)
|
||||
if err != nil {
|
||||
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
||||
res.Content = l.Get("Your request failed. Please try again later.")
|
||||
logg.ErrorCtxf(ctx, "failed on pool deposit", "error", err)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
trackingId := r.TrackingId
|
||||
logg.InfoCtxf(ctx, "Pool deposit", "trackingId", trackingId)
|
||||
|
||||
res.Content = l.Get(
|
||||
"Your request has been sent. You will receive an SMS when %s %s has been deposited into %s.",
|
||||
poolDepositdata.Amount,
|
||||
poolDepositVoucher.TokenSymbol,
|
||||
activePoolName,
|
||||
)
|
||||
|
||||
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
||||
return res, nil
|
||||
}
|
||||
@ -585,7 +585,7 @@ func (h *MenuHandlers) ValidateAmount(ctx context.Context, sym string, input []b
|
||||
return res, nil
|
||||
}
|
||||
|
||||
if inputAmount > balanceValue || inputAmount < 0.1{
|
||||
if inputAmount > balanceValue {
|
||||
res.FlagSet = append(res.FlagSet, flag_invalid_amount)
|
||||
res.Content = amountStr
|
||||
return res, nil
|
||||
|
||||
@ -16,8 +16,7 @@ import (
|
||||
// ManageVouchers retrieves the token holdings from the API using the "PublicKey" and
|
||||
// 1. sets the first as the default voucher if no active voucher is set.
|
||||
// 2. Stores list of vouchers
|
||||
// 3. Stores list of filtered stable vouchers
|
||||
// 4. updates the balance of the active voucher
|
||||
// 3. updates the balance of the active voucher
|
||||
func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
userStore := h.userdataStore
|
||||
@ -30,7 +29,6 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
||||
|
||||
flag_no_active_voucher, _ := h.flagManager.GetFlag("flag_no_active_voucher")
|
||||
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||
flag_no_stable_vouchers, _ := h.flagManager.GetFlag("flag_no_stable_vouchers")
|
||||
|
||||
publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
|
||||
if err != nil {
|
||||
@ -172,41 +170,6 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
||||
}
|
||||
}
|
||||
|
||||
// Filter stable vouchers
|
||||
filteredStableVouchers := make([]dataserviceapi.TokenHoldings, 0)
|
||||
for _, v := range vouchersResp {
|
||||
|
||||
if isStableVoucher(v.TokenAddress) {
|
||||
filteredStableVouchers = append(filteredStableVouchers, v)
|
||||
}
|
||||
}
|
||||
|
||||
// No stable vouchers
|
||||
if len(filteredStableVouchers) == 0 {
|
||||
res.FlagSet = append(res.FlagSet, flag_no_stable_vouchers)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
res.FlagReset = append(res.FlagReset, flag_no_stable_vouchers)
|
||||
|
||||
// Process stable vouchers for later use
|
||||
stableVoucherData := store.ProcessVouchers(filteredStableVouchers)
|
||||
|
||||
stableVoucherDataMap := map[storedb.DataTyp]string{
|
||||
storedb.DATA_STABLE_VOUCHER_SYMBOLS: stableVoucherData.Symbols,
|
||||
storedb.DATA_STABLE_VOUCHER_BALANCES: stableVoucherData.Balances,
|
||||
storedb.DATA_STABLE_VOUCHER_DECIMALS: stableVoucherData.Decimals,
|
||||
storedb.DATA_STABLE_VOUCHER_ADDRESSES: stableVoucherData.Addresses,
|
||||
}
|
||||
|
||||
// Write data entries
|
||||
for key, value := range stableVoucherDataMap {
|
||||
if err := userStore.WriteEntry(ctx, sessionId, key, []byte(value)); err != nil {
|
||||
logg.ErrorCtxf(ctx, "Failed to write data entry for sessionId: %s", sessionId, "key", key, "error", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
|
||||
@ -150,10 +150,6 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
||||
ls.DbRs.AddLocalFunc("calculate_max_pay_debt", appHandlers.CalculateMaxPayDebt)
|
||||
ls.DbRs.AddLocalFunc("confirm_debt_removal", appHandlers.ConfirmDebtRemoval)
|
||||
ls.DbRs.AddLocalFunc("initiate_pay_debt", appHandlers.InitiatePayDebt)
|
||||
ls.DbRs.AddLocalFunc("get_pool_deposit_vouchers", appHandlers.GetPoolDepositVouchers)
|
||||
ls.DbRs.AddLocalFunc("pool_deposit_max_amount", appHandlers.PoolDepositMaxAmount)
|
||||
ls.DbRs.AddLocalFunc("confirm_pool_deposit", appHandlers.ConfirmPoolDeposit)
|
||||
ls.DbRs.AddLocalFunc("initiate_pool_deposit", appHandlers.InitiatePoolDeposit)
|
||||
|
||||
ls.first = appHandlers.Init
|
||||
|
||||
|
||||
@ -1 +0,0 @@
|
||||
Pool deposit
|
||||
@ -1 +0,0 @@
|
||||
Weka kwa bwawa
|
||||
@ -1 +0,0 @@
|
||||
Amount {{.confirm_pool_deposit}} is invalid, please try again:
|
||||
@ -1,7 +0,0 @@
|
||||
MAP confirm_pool_deposit
|
||||
RELOAD reset_transaction_amount
|
||||
MOUT retry 1
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP _ 1
|
||||
INCMP quit 9
|
||||
@ -1 +0,0 @@
|
||||
Kiwango {{.confirm_pool_deposit}} sio sahihi, tafadhali weka tena:
|
||||
@ -32,7 +32,7 @@ msgid "Symbol: %s\nBalance: %s"
|
||||
msgstr "Sarafu: %s\nSalio: %s"
|
||||
|
||||
msgid "Your request has been sent. You will receive an SMS when your %s %s has been swapped for %s."
|
||||
msgstr "Ombi lako limetumwa. Utapokea ujumbe wakati %s %s yako itakapobadilishwa kuwa %s."
|
||||
msgstr "Ombi lako limetumwa. Utapokea SMS wakati %s %s yako itakapobadilishwa kuwa %s."
|
||||
|
||||
msgid "%s balance: %s\n"
|
||||
msgstr "%s salio: %s\n"
|
||||
@ -84,9 +84,3 @@ msgstr "Sarafu yako %s ishachaguliwa"
|
||||
|
||||
msgid "Select number or symbol from your vouchers:\n%s"
|
||||
msgstr "Chagua nambari au ishara kutoka kwa sarafu zako:\n%s"
|
||||
|
||||
msgid "You will deposit %s %s into %s\n"
|
||||
msgstr "Utaweka %s %s kwenye %s\n"
|
||||
|
||||
msgid "Your request has been sent. You will receive an SMS when %s %s has been deposited into %s."
|
||||
msgstr "Ombi lako limetumwa. Utapokea ujumbe wakati %s %s itawekwa kwenye %s."
|
||||
@ -3,16 +3,14 @@ RELOAD calc_credit_debt
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
MAP calc_credit_debt
|
||||
MOUT pay_debt 1
|
||||
MOUT deposit 2
|
||||
MOUT get_mpesa 3
|
||||
MOUT send_mpesa 4
|
||||
MOUT get_mpesa 2
|
||||
MOUT send_mpesa 3
|
||||
MOUT back 0
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP ^ 0
|
||||
INCMP pay_debt 1
|
||||
INCMP pool_deposit 2
|
||||
INCMP get_mpesa 3
|
||||
INCMP send_mpesa 4
|
||||
INCMP get_mpesa 2
|
||||
INCMP send_mpesa 3
|
||||
INCMP quit 9
|
||||
INCMP . *
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
CATCH no_voucher flag_no_active_voucher 1
|
||||
CATCH no_stable_voucher flag_no_stable_vouchers 1
|
||||
CATCH no_stable_voucher flag_no_pay_debt_vouchers 1
|
||||
LOAD calculate_max_pay_debt 0
|
||||
RELOAD calculate_max_pay_debt
|
||||
MAP calculate_max_pay_debt
|
||||
|
||||
@ -1 +0,0 @@
|
||||
{{.get_pool_deposit_vouchers}}
|
||||
@ -1,17 +0,0 @@
|
||||
CATCH no_voucher flag_no_active_voucher 1
|
||||
CATCH no_stable_voucher flag_no_stable_vouchers 1
|
||||
LOAD get_pool_deposit_vouchers 0
|
||||
MAP get_pool_deposit_vouchers
|
||||
MOUT back 0
|
||||
MOUT quit 99
|
||||
MNEXT next 88
|
||||
MPREV prev 98
|
||||
HALT
|
||||
INCMP > 88
|
||||
INCMP < 98
|
||||
INCMP _ 0
|
||||
INCMP quit 99
|
||||
LOAD pool_deposit_max_amount 120
|
||||
RELOAD pool_deposit_max_amount
|
||||
CATCH . flag_incorrect_voucher 1
|
||||
INCMP pool_deposit_amount *
|
||||
@ -1 +0,0 @@
|
||||
{{.pool_deposit_max_amount}}
|
||||
@ -1,10 +0,0 @@
|
||||
LOAD reset_transaction_amount 10
|
||||
RELOAD reset_transaction_amount
|
||||
MAP pool_deposit_max_amount
|
||||
MOUT back 0
|
||||
HALT
|
||||
LOAD confirm_pool_deposit 140
|
||||
RELOAD confirm_pool_deposit
|
||||
CATCH invalid_pool_deposit_amount flag_invalid_amount 1
|
||||
INCMP _ 0
|
||||
INCMP pool_deposit_confirmation *
|
||||
@ -1,2 +0,0 @@
|
||||
{{.confirm_pool_deposit}}
|
||||
Please enter your PIN to confirm:
|
||||
@ -1,10 +0,0 @@
|
||||
MAP confirm_pool_deposit
|
||||
MOUT back 0
|
||||
MOUT quit 9
|
||||
HALT
|
||||
LOAD authorize_account 6
|
||||
RELOAD authorize_account
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
INCMP _ 0
|
||||
INCMP quit 9
|
||||
INCMP pool_deposit_initiated *
|
||||
@ -1,2 +0,0 @@
|
||||
{{.confirm_pool_deposit}}
|
||||
Tafadhali weka PIN yako kudhibitisha:
|
||||
@ -1,4 +0,0 @@
|
||||
LOAD reset_incorrect_pin 6
|
||||
CATCH _ flag_account_authorized 0
|
||||
LOAD initiate_pool_deposit 0
|
||||
HALT
|
||||
@ -36,4 +36,4 @@ flag,flag_incorrect_pool,42,this is set when the user selects an invalid pool
|
||||
flag,flag_low_swap_amount,43,this is set when the swap max limit is less than 0.1
|
||||
flag,flag_alias_unavailable,44,this is set when the preferred alias is not available
|
||||
flag,flag_swap_transaction,45,this is set when the transaction will involve performing a swap
|
||||
flag,flag_no_stable_vouchers,46,this is set when the user does not have a stable voucher
|
||||
flag,flag_no_pay_debt_vouchers,46,this is set when the user does not have a stable voucher to pay debt
|
||||
|
||||
|
@ -104,14 +104,7 @@ const (
|
||||
DATA_VOUCHER_DECIMALS
|
||||
// List of voucher EVM addresses for vouchers valid in the user context.
|
||||
DATA_VOUCHER_ADDRESSES
|
||||
// List of stable voucher symbols in the user context.
|
||||
DATA_STABLE_VOUCHER_SYMBOLS
|
||||
// List of stable voucher decimal counts for vouchers valid in the user context.
|
||||
DATA_STABLE_VOUCHER_BALANCES
|
||||
// List of stable voucher decimal counts for vouchers valid in the user context.
|
||||
DATA_STABLE_VOUCHER_DECIMALS
|
||||
// List of stable voucher EVM addresses for vouchers valid in the user context.
|
||||
DATA_STABLE_VOUCHER_ADDRESSES
|
||||
// List of senders for valid transactions in the user context.
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@ -120,43 +120,6 @@ func GetVoucherData(ctx context.Context, store DataStore, sessionId string, inpu
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetStableVoucherData retrieves and matches stable voucher data
|
||||
func GetStableVoucherData(ctx context.Context, store DataStore, sessionId string, input string) (*dataserviceapi.TokenHoldings, error) {
|
||||
keys := []storedb.DataTyp{
|
||||
storedb.DATA_STABLE_VOUCHER_SYMBOLS,
|
||||
storedb.DATA_STABLE_VOUCHER_BALANCES,
|
||||
storedb.DATA_STABLE_VOUCHER_DECIMALS,
|
||||
storedb.DATA_STABLE_VOUCHER_ADDRESSES,
|
||||
}
|
||||
data := make(map[storedb.DataTyp]string)
|
||||
|
||||
for _, key := range keys {
|
||||
value, err := store.ReadEntry(ctx, sessionId, key)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get data key %x: %v", key, err)
|
||||
}
|
||||
data[key] = string(value)
|
||||
}
|
||||
|
||||
symbol, balance, decimal, address := MatchVoucher(input,
|
||||
data[storedb.DATA_STABLE_VOUCHER_SYMBOLS],
|
||||
data[storedb.DATA_STABLE_VOUCHER_BALANCES],
|
||||
data[storedb.DATA_STABLE_VOUCHER_DECIMALS],
|
||||
data[storedb.DATA_STABLE_VOUCHER_ADDRESSES],
|
||||
)
|
||||
|
||||
if symbol == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return &dataserviceapi.TokenHoldings{
|
||||
TokenSymbol: string(symbol),
|
||||
Balance: string(balance),
|
||||
TokenDecimals: string(decimal),
|
||||
TokenAddress: string(address),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// MatchVoucher finds the matching voucher symbol, balance, decimals and contract address based on the input.
|
||||
func MatchVoucher(input, symbols, balances, decimals, addresses string) (symbol, balance, decimal, address string) {
|
||||
symList := strings.Split(symbols, "\n")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user