micw/server/repository/repo.go
2024-11-13 22:10:13 +01:00

42 lines
1.5 KiB
Go

package repository
import (
"context"
"github.com/jackc/pgx/v5/pgxpool"
e "mic-wallet/server/repository/entities"
)
type IBlocksRepository interface {
NewBLock(ctx context.Context, opts e.NewBlockOpts) (blockID int64, err error)
FinishBlock(ctx context.Context, opts e.BlockFinishedOpts) (err error)
GetBlock(ctx context.Context, id int64) (block *e.Block, err error)
GetBlockByHash(ctx context.Context, hash string) (block *e.Block, err error)
GetLastFinishedBlock(ctx context.Context) (block *e.Block, err error)
}
type ITransactionsRepository interface {
GetLastTransactionHash(ctx context.Context) ([]byte, error)
AddTransaction(ctx context.Context, opts e.NewTransactionOpts) (transaction *e.Transaction, err error)
GetTransaction(ctx context.Context, txID int64) (tx e.Transaction, err error)
GetUserIncomingTransactions(
ctx context.Context, userPubKey string, orderAsc bool, limit int, offset int) ([]e.Transaction, error)
GetUserOutcomingTransactions(
ctx context.Context, userPubKey string, orderAsc bool, limit int, offset int) ([]e.Transaction, error)
GetUserTransactions(
ctx context.Context, userPubKey string, orderAsc bool, limit int, offset int) ([]e.Transaction, error)
GetTransactions(
ctx context.Context, orderAsc bool, limit int, offset int) ([]e.Transaction, error)
}
type Repository struct {
ITransactionsRepository
IBlocksRepository
}
func NewRepository(db *pgxpool.Pool) *Repository {
return &Repository{
ITransactionsRepository: &TransactionRepository{DB: db},
IBlocksRepository: &BlocksRepository{DB: db},
}
}