2023-03-07 11:25:42 -08:00
|
|
|
package transactions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-03-15 12:52:50 -07:00
|
|
|
"fmt"
|
2023-03-07 11:25:42 -08:00
|
|
|
|
2023-03-15 12:52:50 -07:00
|
|
|
"github.com/wormhole-foundation/wormhole-explorer/api/types"
|
|
|
|
"github.com/wormhole-foundation/wormhole/sdk/vaa"
|
2023-03-07 11:25:42 -08:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Service struct {
|
|
|
|
repo *Repository
|
|
|
|
logger *zap.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewService create a new Service.
|
|
|
|
func NewService(repo *Repository, logger *zap.Logger) *Service {
|
|
|
|
return &Service{repo: repo, logger: logger.With(zap.String("module", "TransactionService"))}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTransactionCount get the last transactions.
|
|
|
|
func (s *Service) GetTransactionCount(ctx context.Context, q *TransactionCountQuery) ([]TransactionCountResult, error) {
|
|
|
|
return s.repo.GetTransactionCount(ctx, q)
|
|
|
|
}
|
|
|
|
|
2023-04-20 12:01:10 -07:00
|
|
|
func (s *Service) GetScorecards(ctx context.Context) (*Scorecards, error) {
|
|
|
|
return s.repo.GetScorecards(ctx)
|
|
|
|
}
|
|
|
|
|
2023-03-07 11:25:42 -08:00
|
|
|
// GetChainActivity get chain activity.
|
|
|
|
func (s *Service) GetChainActivity(ctx context.Context, q *ChainActivityQuery) ([]ChainActivityResult, error) {
|
|
|
|
return s.repo.FindChainActivity(ctx, q)
|
|
|
|
}
|
2023-03-15 12:52:50 -07:00
|
|
|
|
|
|
|
// FindGlobalTransactionByID find a global transaction by id.
|
|
|
|
func (s *Service) FindGlobalTransactionByID(ctx context.Context, chainID vaa.ChainID, emitter *types.Address, seq string) (*GlobalTransactionDoc, error) {
|
2023-03-16 11:42:34 -07:00
|
|
|
key := fmt.Sprintf("%d/%s/%s", chainID, emitter.Hex(), seq)
|
2023-03-15 12:52:50 -07:00
|
|
|
q := GlobalTransactionQuery{
|
|
|
|
id: key}
|
|
|
|
return s.repo.FindGlobalTransactionByID(ctx, q)
|
|
|
|
}
|