bind session id for aliases,soft code voucher balance

This commit is contained in:
Carlosokumu 2025-01-20 20:11:08 +03:00
parent 8a47d1d674
commit ed549cba70
Signed by: carlos
GPG Key ID: 7BD6BC8160A5C953

View File

@ -33,6 +33,7 @@ const (
hashLen int = 32 hashLen int = 32
defaultDecimals = 6 defaultDecimals = 6
zeroAddress string = "0x0000000000000000000000000000000000000000" zeroAddress string = "0x0000000000000000000000000000000000000000"
defaultVoucherBalance float64 = 500.00
) )
type Tx struct { type Tx struct {
@ -105,7 +106,6 @@ type DevAccountService struct {
defaultAccount string defaultAccount string
emitterFunc event.EmitterFunc emitterFunc event.EmitterFunc
pfx []byte pfx []byte
// accountsSession map[string]string
} }
func NewDevAccountService(ctx context.Context, ss storage.StorageService) *DevAccountService { func NewDevAccountService(ctx context.Context, ss storage.StorageService) *DevAccountService {
@ -342,13 +342,17 @@ func (das *DevAccountService) saveAlias(ctx context.Context, alias map[string]st
if das.db == nil { if das.db == nil {
return fmt.Errorf("Db cannot be nil") return fmt.Errorf("Db cannot be nil")
} }
sessionId, ok := ctx.Value("SessionId").(string)
if !ok {
return fmt.Errorf("unresolved session id")
}
for k, v := range alias { for k, v := range alias {
k_ := das.prefixKeyFor("alias", k) k_ := das.prefixKeyFor("alias", k)
v_, err := json.Marshal(v) v_, err := json.Marshal(v)
if err != nil { if err != nil {
return err return err
} }
das.db.SetSession("") das.db.SetSession(sessionId)
das.db.SetPrefix(db.DATATYPE_USERDATA) das.db.SetPrefix(db.DATATYPE_USERDATA)
return das.db.Put(ctx, []byte(k_), v_) return das.db.Put(ctx, []byte(k_), v_)
} }
@ -431,7 +435,7 @@ func (das *DevAccountService) FetchVouchers(ctx context.Context, publicKey strin
ContractAddress: voucher.Address, ContractAddress: voucher.Address,
TokenSymbol: voucher.Symbol, TokenSymbol: voucher.Symbol,
TokenDecimals: strconv.Itoa(voucher.Decimals), TokenDecimals: strconv.Itoa(voucher.Decimals),
Balance: strconv.Itoa(500), Balance: strconv.Itoa(int(defaultVoucherBalance)),
}) })
} }