Skip to content

Commit

Permalink
Fix missing AiTrainerPayments
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Nov 7, 2023
1 parent eb663bc commit 67249cc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 32 deletions.
7 changes: 2 additions & 5 deletions cmd/honey-tracker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import (
"fmt"
"os"

"github.com/streamingfast/bstream"

"github.com/spf13/cobra"
"github.com/streamingfast/bstream"
"github.com/streamingfast/cli/sflags"

"go.uber.org/zap"

"github.com/streamingfast/honey-tracker/data"
"github.com/streamingfast/logging"
sink "github.com/streamingfast/substreams-sink"
"github.com/streamingfast/substreams/client"
"go.uber.org/zap"
)

var RootCmd = &cobra.Command{
Expand Down
45 changes: 20 additions & 25 deletions data/db.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package data

import (
pb "github.com/streamingfast/honey-tracker/data/pb/hivemapper/v1"
sink "github.com/streamingfast/substreams-sink"
pbsubstreams "github.com/streamingfast/substreams/pb/sf/substreams/v1"
)

type DB interface {
Init() error

BeginTransaction() error
CommitTransaction() error
RollbackTransaction() error

HandleClock(clock *pbsubstreams.Clock) (dbBlockID int64, err error)
HandleInitializedAccount(dbBlockID int64, initializedAccount []*pb.InitializedAccount) error
HandleRegularDriverPayments(dbBlockID int64, payments []*pb.RegularDriverPayment) error
HandleAiPayments(dbBlockID int64, payments []*pb.AiTrainerPayment) error
HandleSplitPayments(dbBlockID int64, splitPayments []*pb.TokenSplittingPayment) error
HandleNoneSplitPayments(dbBlockID int64, payments []*pb.NoSplitPayment) error
HandleTransfers(dbBlockID int64, transfers []*pb.Transfer) error
HandleMints(dbBlockID int64, mints []*pb.Mint) error
HandleBurns(dbBlockID int64, burns []*pb.Burn) error
StoreCursor(cursor *sink.Cursor) error
FetchCursor() (*sink.Cursor, error)
}
//type DB interface {
// Init() error
//
// BeginTransaction() error
// CommitTransaction() error
// RollbackTransaction() error
//
// HandleClock(clock *pbsubstreams.Clock) (dbBlockID int64, err error)
// HandleInitializedAccount(dbBlockID int64, initializedAccount []*pb.InitializedAccount) error
// HandleRegularDriverPayments(dbBlockID int64, payments []*pb.RegularDriverPayment) error
// HandleAiPayments(dbBlockID int64, payments []*pb.AiTrainerPayment) error
// HandleSplitPayments(dbBlockID int64, splitPayments []*pb.TokenSplittingPayment) error
// HandleNoneSplitPayments(dbBlockID int64, payments []*pb.NoSplitPayment) error
// HandleTransfers(dbBlockID int64, transfers []*pb.Transfer) error
// HandleMints(dbBlockID int64, mints []*pb.Mint) error
// HandleBurns(dbBlockID int64, burns []*pb.Burn) error
// StoreCursor(cursor *sink.Cursor) error
// FetchCursor() (*sink.Cursor, error)
// HandleAITrainerPayments(dbBlockID int64, payments []*pb.AiTrainerPayment) error
//}
20 changes: 20 additions & 0 deletions data/psql.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,26 @@ func (p *Psql) HandleMints(dbBlockID int64, mints []*pb.Mint) error {
}
return nil
}
func (p *Psql) HandleAITrainerPayments(dbBlockID int64, payments []*pb.AiTrainerPayment) error {
for _, payment := range payments {
dbTransactionID, err := p.handleTransaction(dbBlockID, payment.Mint.TrxHash)
if err != nil {
return fmt.Errorf("inserting transaction: %w", err)
}

mintDbID, err := p.insertMint(dbTransactionID, payment.Mint)
if err != nil {
return fmt.Errorf("inserting mint: %w", err)
}

_, err = p.tx.Exec("INSERT INTO hivemapper.ai_payments (mint_id) VALUES ($1) RETURNING id", mintDbID)
if err != nil {
return fmt.Errorf("inserting payment: %w", err)
}
}

return nil
}

func (p *Psql) insertBurns(dbTransactionID int64, burn *pb.Burn) (dbMintID int64, err error) {
row := p.tx.QueryRow("INSERT INTO hivemapper.burns (transaction_id, from_address, amount) VALUES ($1, $2, $3) RETURNING id", dbTransactionID, burn.From, burn.Amount)
Expand Down
8 changes: 6 additions & 2 deletions data/sinker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
type Sinker struct {
logger *zap.Logger
*sink.Sinker
db DB
db *Psql
lastClock *v1.Clock
blockSecCount int64
}

func NewSinker(logger *zap.Logger, sink *sink.Sinker, db DB) *Sinker {
func NewSinker(logger *zap.Logger, sink *sink.Sinker, db *Psql) *Sinker {
return &Sinker{
logger: logger,
Sinker: sink,
Expand Down Expand Up @@ -116,6 +116,10 @@ func (s *Sinker) HandleBlockScopedData(ctx context.Context, data *pbsubstreamsrp
return fmt.Errorf("handle payments: %w", err)
}

if err := s.db.HandleAITrainerPayments(dbBlockID, moduleOutput.AiTrainerPayments); err != nil {
return fmt.Errorf("handle AiTrainerPayments: %w", err)
}

if err := s.db.HandleSplitPayments(dbBlockID, moduleOutput.TokenSplittingPayments); err != nil {
return fmt.Errorf("handle split payments: %w", err)
}
Expand Down

0 comments on commit 67249cc

Please sign in to comment.