Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactoring and auth #4

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 39 additions & 23 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/spec/components/schemas/Balance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ allOf:
properties:
amount:
type: integer
format: uint64
description: Amount of points
example: 580
is_verified:
Expand Down
1 change: 1 addition & 0 deletions docs/spec/components/schemas/Event.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ allOf:
$ref: '#/components/schemas/EventMeta'
points_amount:
type: integer
format: uint64
description: |
How many points were accrued. Required only for `claimed` events.
This is necessary, as the reward might change over time, while
Expand Down
1 change: 1 addition & 0 deletions docs/spec/components/schemas/EventStaticMeta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ properties:
example: get_poh
reward:
type: integer
format: uint64
description: Reward amount in points
example: 50
title:
Expand Down
1 change: 1 addition & 0 deletions docs/spec/components/schemas/PointPrice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ allOf:
properties:
urmo:
type: integer
format: uint64
description: Amount of `urmo` tokens for one point
example: 1000
1 change: 1 addition & 0 deletions docs/spec/components/schemas/Withdraw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ allOf:
properties:
amount:
type: integer
format: uint64
description: Amount of points to withdraw
example: 580
address:
Expand Down
1 change: 1 addition & 0 deletions docs/spec/components/schemas/Withdrawal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ allOf:
properties:
amount:
type: integer
format: uint64
description: Amount of points withdrawn
example: 580
address:
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ info:
title: rarime-points-svc
description: ''
servers:
- url: 'https://api.demo.tokend.io'
- url: 'https://api.stage.rarime.com'
description: TokenD Developer Environment
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/rarimo/rarime-points-svc

go 1.21.3
go 1.22

require (
github.com/Masterminds/squirrel v1.4.0
Expand All @@ -11,7 +11,7 @@ require (
github.com/go-co-op/gocron/v2 v2.2.2
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/iden3/go-iden3-core/v2 v2.0.4
github.com/rarimo/rarime-auth-svc v0.0.1-rc9
github.com/rarimo/auth-svc v1.0.0-rc2
github.com/rarimo/saver-grpc-lib v1.0.0
github.com/rubenv/sql-migrate v1.6.1
gitlab.com/distributed_lab/ape v1.7.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1216,12 +1216,12 @@ github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJf
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ=
github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc=
github.com/rarimo/auth-svc v1.0.0-rc2 h1:6w+T8xFZwi5gc2x8FlObnfMEij2zlNQZDNSdaBLY2iw=
github.com/rarimo/auth-svc v1.0.0-rc2/go.mod h1:XtPIuJABJ3QNmhcpmJRlQrxuagPfpIWwFbY0j5SakFg=
github.com/rarimo/broadcaster-svc v1.0.2 h1:ExQcjjWCRP5+POLDlZHrTD1ffUsBH+Dgv5FAgcP3BXc=
github.com/rarimo/broadcaster-svc v1.0.2/go.mod h1:lYIHy+X4IqQt4eBdtMN/V352H3EV0/gO8G+32SFwUWI=
github.com/rarimo/cosmos-sdk v0.46.7 h1:jU2PiWzc+19SF02cXM0O0puKPeH1C6Q6t2lzJ9s1ejc=
github.com/rarimo/cosmos-sdk v0.46.7/go.mod h1:fqKqz39U5IlEFb4nbQ72951myztsDzFKKDtffYJ63nk=
github.com/rarimo/rarime-auth-svc v0.0.1-rc9 h1:JZfq1q3WaaLwa8ICk8RHEx4+ojl/JBE8N5zJ/uHZUwM=
github.com/rarimo/rarime-auth-svc v0.0.1-rc9/go.mod h1:48c8FsJixnLeWx8F8MDy79FvhU1r0oTU11mwP3JPngQ=
github.com/rarimo/saver-grpc-lib v1.0.0 h1:MGUVjYg7unmodYczVsLqlqZNkT4CIgKqdo6aQtL1qdE=
github.com/rarimo/saver-grpc-lib v1.0.0/go.mod h1:DpugWK5B7Hi0bdC3MPe/9FD2zCxaRwsyykdwxtF1Zgg=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
Expand Down
2 changes: 1 addition & 1 deletion internal/assets/migrations/001_initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ AS $$ BEGIN NEW.updated_at = EXTRACT('EPOCH' FROM NOW()); RETURN NEW; END; $$;
CREATE TABLE IF NOT EXISTS balances
(
did text PRIMARY KEY,
amount integer not null default 0,
amount bigint not null default 0,
created_at integer not null default EXTRACT('EPOCH' FROM NOW()),
updated_at integer not null default EXTRACT('EPOCH' FROM NOW()),
passport_hash text UNIQUE,
Expand Down
4 changes: 2 additions & 2 deletions internal/config/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config

import (
"github.com/rarimo/rarime-auth-svc/pkg/auth"
"github.com/rarimo/auth-svc/pkg/auth"
"github.com/rarimo/rarime-points-svc/internal/data/evtypes"
"github.com/rarimo/rarime-points-svc/internal/service/workers/sbtcheck"
"github.com/rarimo/saver-grpc-lib/broadcaster"
Expand All @@ -22,7 +22,7 @@ type Config interface {
evtypes.EventTypeser
sbtcheck.SbtChecker

PointPrice() int32
PointPrice() uint64
}

type config struct {
Expand Down
6 changes: 3 additions & 3 deletions internal/config/point_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"gitlab.com/distributed_lab/kit/kv"
)

func (c *config) PointPrice() int32 {
func (c *config) PointPrice() uint64 {
return c.pointPrice.Do(func() interface{} {
var cfg struct {
PointPriceURMO int32 `fig:"point_price_urmo,required"`
PointPriceURMO uint64 `fig:"point_price_urmo,required"`
}

err := figure.Out(&cfg).
Expand All @@ -21,5 +21,5 @@ func (c *config) PointPrice() int32 {
}

return cfg.PointPriceURMO
}).(int32)
}).(uint64)
}
4 changes: 2 additions & 2 deletions internal/data/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type Balance struct {
DID string `db:"did"`
Amount int32 `db:"amount"`
Amount uint64 `db:"amount"`
CreatedAt int32 `db:"created_at"`
UpdatedAt int32 `db:"updated_at"`
PassportHash sql.NullString `db:"passport_hash"`
Expand All @@ -20,7 +20,7 @@ type Balance struct {
type BalancesQ interface {
New() BalancesQ
Insert(did string) error
UpdateAmountBy(points int32) error
UpdateAmountBy(points uint64) error
SetPassport(hash string, exp time.Time) error

Page(*pgdb.OffsetPageParams) BalancesQ
Expand Down
19 changes: 9 additions & 10 deletions internal/data/events.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package data

import (
"database/sql"
"encoding/json"

"gitlab.com/distributed_lab/kit/pgdb"
Expand All @@ -20,14 +19,14 @@ func (s EventStatus) String() string {
}

type Event struct {
ID string `db:"id"`
UserDID string `db:"user_did"`
Type string `db:"type"`
Status EventStatus `db:"status"`
CreatedAt int32 `db:"created_at"`
UpdatedAt int32 `db:"updated_at"`
Meta Jsonb `db:"meta"`
PointsAmount sql.NullInt32 `db:"points_amount"`
ID string `db:"id"`
UserDID string `db:"user_did"`
Type string `db:"type"`
Status EventStatus `db:"status"`
CreatedAt int32 `db:"created_at"`
UpdatedAt int32 `db:"updated_at"`
Meta Jsonb `db:"meta"`
PointsAmount *uint64 `db:"points_amount"`
}

// ReopenableEvent is a pair that is sufficient to build a new open event with a specific type for a user
Expand All @@ -39,7 +38,7 @@ type ReopenableEvent struct {
type EventsQ interface {
New() EventsQ
Insert(...Event) error
Update(status EventStatus, meta json.RawMessage, points *int32) (*Event, error)
Update(status EventStatus, meta json.RawMessage, points *uint64) (*Event, error)
Transaction(func() error) error

Page(*pgdb.CursorPageParams) EventsQ
Expand Down
2 changes: 1 addition & 1 deletion internal/data/evtypes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (c *config) EventTypes() Types {
Types []struct {
Name string `fig:"name,required"`
Description string `fig:"description,required"`
Reward int32 `fig:"reward,required"`
Reward uint64 `fig:"reward,required"`
Title string `fig:"title,required"`
Frequency Frequency `fig:"frequency,required"`
ExpiresAt *time.Time `fig:"expires_at"`
Expand Down
2 changes: 1 addition & 1 deletion internal/data/pg/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (q *balances) Insert(did string) error {
return nil
}

func (q *balances) UpdateAmountBy(points int32) error {
func (q *balances) UpdateAmountBy(points uint64) error {
olegfomenko marked this conversation as resolved.
Show resolved Hide resolved
stmt := q.updater.Set("amount", squirrel.Expr("amount + ?", points))

if err := q.db.Exec(stmt); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/data/pg/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ func (q *events) Insert(events ...data.Event) error {
return nil
}

func (q *events) Update(status data.EventStatus, meta json.RawMessage, points *int32) (*data.Event, error) {
func (q *events) Update(status data.EventStatus, meta json.RawMessage, points *uint64) (*data.Event, error) {
umap := map[string]any{
"status": status,
}
if len(meta) != 0 {
umap["meta"] = meta
}
if points != nil {
umap["points_amount"] = sql.NullInt32{Int32: *points, Valid: true}
umap["points_amount"] = points
}

var res data.Event
Expand Down
2 changes: 1 addition & 1 deletion internal/data/withdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
type Withdrawal struct {
ID string `db:"id"`
UserDID string `db:"user_did"`
Amount int32 `db:"amount"`
Amount uint64 `db:"amount"`
Address string `db:"address"`
CreatedAt int32 `db:"created_at"`
}
Expand Down
Loading
Loading