2023-03-08 07:49:09 +01:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
2023-04-11 12:14:49 +02:00
|
|
|
func (s *PgStore) ActivateAccount(
|
|
|
|
ctx context.Context,
|
|
|
|
publicAddress string,
|
|
|
|
) error {
|
|
|
|
if _, err := s.db.Exec(
|
|
|
|
ctx,
|
|
|
|
s.queries.ActivateAccount,
|
|
|
|
publicAddress,
|
|
|
|
); err != nil {
|
|
|
|
return err
|
2023-03-08 07:49:09 +01:00
|
|
|
}
|
|
|
|
|
2023-04-11 12:14:49 +02:00
|
|
|
return nil
|
2023-03-08 07:49:09 +01:00
|
|
|
}
|
|
|
|
|
2023-04-11 12:14:49 +02:00
|
|
|
func (s *PgStore) GetAccountStatus(
|
|
|
|
ctx context.Context,
|
|
|
|
publicAddress string,
|
|
|
|
) (bool, int, error) {
|
2023-03-08 07:49:09 +01:00
|
|
|
var (
|
2023-04-11 12:14:49 +02:00
|
|
|
accountActive bool
|
|
|
|
gasQuota int
|
2023-03-08 07:49:09 +01:00
|
|
|
)
|
|
|
|
|
2023-04-11 12:14:49 +02:00
|
|
|
if err := s.db.QueryRow(
|
2023-03-08 07:49:09 +01:00
|
|
|
ctx,
|
2023-04-11 12:14:49 +02:00
|
|
|
s.queries.GetAccountStatus,
|
2023-03-08 07:49:09 +01:00
|
|
|
publicAddress,
|
2023-04-11 12:14:49 +02:00
|
|
|
).Scan(
|
|
|
|
&accountActive,
|
|
|
|
&gasQuota,
|
2023-03-08 07:49:09 +01:00
|
|
|
); err != nil {
|
2023-04-11 12:14:49 +02:00
|
|
|
return false, 0, err
|
2023-03-08 07:49:09 +01:00
|
|
|
}
|
|
|
|
|
2023-04-11 12:14:49 +02:00
|
|
|
return accountActive, gasQuota, nil
|
2023-03-08 07:49:09 +01:00
|
|
|
}
|
|
|
|
|
2023-04-11 12:14:49 +02:00
|
|
|
func (s *PgStore) DecrGasQuota(
|
|
|
|
ctx context.Context,
|
|
|
|
publicAddress string,
|
|
|
|
) error {
|
2023-03-08 07:49:09 +01:00
|
|
|
if _, err := s.db.Exec(
|
|
|
|
ctx,
|
2023-04-11 12:14:49 +02:00
|
|
|
s.queries.DecrGasQuota,
|
2023-03-08 07:49:09 +01:00
|
|
|
publicAddress,
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-04-11 12:14:49 +02:00
|
|
|
func (s *PgStore) ResetGasQuota(
|
|
|
|
ctx context.Context,
|
|
|
|
publicAddress string,
|
|
|
|
) error {
|
2023-03-08 07:49:09 +01:00
|
|
|
if _, err := s.db.Exec(
|
|
|
|
ctx,
|
2023-04-11 12:14:49 +02:00
|
|
|
s.queries.ResetGasQuota,
|
2023-03-08 07:49:09 +01:00
|
|
|
publicAddress,
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|