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

decoding stuff #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions pkg/core/db/models.go

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

21 changes: 21 additions & 0 deletions pkg/core/db/sql/migrations/00015_entity_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- +migrate Up
create table if not exists core_plays(
rowid serial primary key,
user_id text not null,
track_id text not null,

-- future fields
listener_address text not null,
cid text not null,

city text not null,
country text not null,
region text not null,
signer text not null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content node that served the play

signature text not null,
block bigint not null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tx

created_at timestamptz not null
)

-- +migrate Down
drop table if exists core_plays;
4 changes: 4 additions & 0 deletions pkg/core/db/sql/writes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ where block_height = $3 and address = $4;
-- name: InsertFailedStorageProof :exec
insert into storage_proofs (block_height, address, status)
values ($1, $2, 'fail');

-- name: InsertPlayRecord :exec
insert into core_plays (user_id, track_id, listener_address, cid, city, country, region, signer, signature, block, created_at)
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) on conflict do nothing;
36 changes: 36 additions & 0 deletions pkg/core/db/writes.sql.go

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

11 changes: 11 additions & 0 deletions pkg/core/server/plays.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"

"github.com/AudiusProject/audiusd/pkg/core/db"
"github.com/AudiusProject/audiusd/pkg/core/gen/core_proto"
)

Expand All @@ -22,5 +23,15 @@ func (s *Server) finalizePlayTransaction(ctx context.Context, stx *core_proto.Si
return nil, errors.New("invalid play tx")
}

for _, play := range tx.Plays {
if err := s.getDb().InsertPlayRecord(ctx, db.InsertPlayRecordParams{
TrackID: tx.,
UserID: tx.UserId,
}); err != nil {
s.logger.Errorf("error inserting play record: %v", err)
}

}

return tx, nil
}