mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-04-28 11:45:34 +08:00
fix: add entity
This commit is contained in:
@@ -3,26 +3,28 @@ package datagateway
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/gaze-network/indexer-network/modules/nodesale/internal/entity"
|
||||
)
|
||||
|
||||
type NodesaleDataGateway interface {
|
||||
BeginNodesaleTx(ctx context.Context) (NodesaleDataGatewayWithTx, error)
|
||||
AddBlock(ctx context.Context, arg Block) error
|
||||
GetBlock(ctx context.Context, blockHeight int64) (*Block, error)
|
||||
GetLastProcessedBlock(ctx context.Context) (*Block, error)
|
||||
AddBlock(ctx context.Context, arg entity.Block) error
|
||||
GetBlock(ctx context.Context, blockHeight int64) (*entity.Block, error)
|
||||
GetLastProcessedBlock(ctx context.Context) (*entity.Block, error)
|
||||
RemoveBlockFrom(ctx context.Context, fromBlock int64) (int64, error)
|
||||
RemoveEventsFromBlock(ctx context.Context, fromBlock int64) (int64, error)
|
||||
ClearDelegate(ctx context.Context) (int64, error)
|
||||
GetNodes(ctx context.Context, arg GetNodesParams) ([]Node, error)
|
||||
GetNodes(ctx context.Context, arg GetNodesParams) ([]entity.Node, error)
|
||||
AddEvent(ctx context.Context, arg AddEventParams) error
|
||||
SetDelegates(ctx context.Context, arg SetDelegatesParams) (int64, error)
|
||||
AddNodesale(ctx context.Context, arg AddNodesaleParams) error
|
||||
GetNodesale(ctx context.Context, arg GetNodesaleParams) ([]NodeSale, error)
|
||||
GetNodesByOwner(ctx context.Context, arg GetNodesByOwnerParams) ([]Node, error)
|
||||
GetNodesale(ctx context.Context, arg GetNodesaleParams) ([]entity.NodeSale, error)
|
||||
GetNodesByOwner(ctx context.Context, arg GetNodesByOwnerParams) ([]entity.Node, error)
|
||||
AddNode(ctx context.Context, arg AddNodeParams) error
|
||||
GetNodeCountByTierIndex(ctx context.Context, arg GetNodeCountByTierIndexParams) ([]GetNodeCountByTierIndexRow, error)
|
||||
GetNodesByPubkey(ctx context.Context, arg GetNodesByPubkeyParams) ([]Node, error)
|
||||
GetEventsByWallet(ctx context.Context, walletAddress string) ([]Event, error)
|
||||
GetNodesByPubkey(ctx context.Context, arg GetNodesByPubkeyParams) ([]entity.Node, error)
|
||||
GetEventsByWallet(ctx context.Context, walletAddress string) ([]entity.Event, error)
|
||||
}
|
||||
|
||||
type NodesaleDataGatewayWithTx interface {
|
||||
@@ -30,12 +32,6 @@ type NodesaleDataGatewayWithTx interface {
|
||||
Tx
|
||||
}
|
||||
|
||||
type Block struct {
|
||||
BlockHeight int64
|
||||
BlockHash string
|
||||
Module string
|
||||
}
|
||||
|
||||
type GetNodesParams struct {
|
||||
SaleBlock int64
|
||||
SaleTxIndex int32
|
||||
@@ -117,42 +113,3 @@ type GetNodesByPubkeyParams struct {
|
||||
OwnerPublicKey string
|
||||
DelegatedTo string
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
SaleBlock int64
|
||||
SaleTxIndex int32
|
||||
NodeID int32
|
||||
TierIndex int32
|
||||
DelegatedTo string
|
||||
OwnerPublicKey string
|
||||
PurchaseTxHash string
|
||||
DelegateTxHash string
|
||||
}
|
||||
|
||||
type NodeSale struct {
|
||||
BlockHeight int64
|
||||
TxIndex int32
|
||||
Name string
|
||||
StartsAt time.Time
|
||||
EndsAt time.Time
|
||||
Tiers [][]byte
|
||||
SellerPublicKey string
|
||||
MaxPerAddress int32
|
||||
DeployTxHash string
|
||||
MaxDiscountPercentage int32
|
||||
SellerWallet string
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
TxHash string
|
||||
BlockHeight int64
|
||||
TxIndex int32
|
||||
WalletAddress string
|
||||
Valid bool
|
||||
Action int32
|
||||
RawMessage []byte
|
||||
ParsedMessage []byte
|
||||
BlockTimestamp time.Time
|
||||
BlockHash string
|
||||
Metadata []byte
|
||||
}
|
||||
|
||||
48
modules/nodesale/internal/entity/entity.go
Normal file
48
modules/nodesale/internal/entity/entity.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type Block struct {
|
||||
BlockHeight int64
|
||||
BlockHash string
|
||||
Module string
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
SaleBlock int64
|
||||
SaleTxIndex int32
|
||||
NodeID int32
|
||||
TierIndex int32
|
||||
DelegatedTo string
|
||||
OwnerPublicKey string
|
||||
PurchaseTxHash string
|
||||
DelegateTxHash string
|
||||
}
|
||||
|
||||
type NodeSale struct {
|
||||
BlockHeight int64
|
||||
TxIndex int32
|
||||
Name string
|
||||
StartsAt time.Time
|
||||
EndsAt time.Time
|
||||
Tiers [][]byte
|
||||
SellerPublicKey string
|
||||
MaxPerAddress int32
|
||||
DeployTxHash string
|
||||
MaxDiscountPercentage int32
|
||||
SellerWallet string
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
TxHash string
|
||||
BlockHeight int64
|
||||
TxIndex int32
|
||||
WalletAddress string
|
||||
Valid bool
|
||||
Action int32
|
||||
RawMessage []byte
|
||||
ParsedMessage []byte
|
||||
BlockTimestamp time.Time
|
||||
BlockHash string
|
||||
Metadata []byte
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/gaze-network/indexer-network/core/datasources"
|
||||
"github.com/gaze-network/indexer-network/modules/nodesale/datagateway"
|
||||
"github.com/gaze-network/indexer-network/modules/nodesale/internal/entity"
|
||||
"github.com/gaze-network/indexer-network/modules/nodesale/protobuf"
|
||||
)
|
||||
|
||||
@@ -178,7 +179,7 @@ func (p *Processor) Process(ctx context.Context, inputs []*types.Block) error {
|
||||
}()
|
||||
|
||||
// write block
|
||||
err = qtx.AddBlock(ctx, datagateway.Block{
|
||||
err = qtx.AddBlock(ctx, entity.Block{
|
||||
BlockHeight: block.Header.Height,
|
||||
BlockHash: block.Header.Hash.String(),
|
||||
Module: p.Name(),
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/gaze-network/indexer-network/core/types"
|
||||
"github.com/gaze-network/indexer-network/modules/nodesale/datagateway"
|
||||
"github.com/gaze-network/indexer-network/modules/nodesale/internal/entity"
|
||||
"github.com/gaze-network/indexer-network/modules/nodesale/protobuf"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/proto"
|
||||
@@ -46,7 +47,7 @@ func (p *Processor) processPurchase(ctx context.Context, qtx datagateway.Nodesal
|
||||
}
|
||||
}
|
||||
|
||||
var deploy *datagateway.NodeSale
|
||||
var deploy *entity.NodeSale
|
||||
if valid {
|
||||
// check node existed
|
||||
deploys, err := qtx.GetNodesale(ctx, datagateway.GetNodesaleParams{
|
||||
@@ -192,7 +193,7 @@ func (p *Processor) processPurchase(ctx context.Context, qtx datagateway.Nodesal
|
||||
}
|
||||
}
|
||||
|
||||
var buyerOwnedNodes []datagateway.Node
|
||||
var buyerOwnedNodes []entity.Node
|
||||
if valid {
|
||||
var err error
|
||||
// check node limit
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/gaze-network/indexer-network/internal/postgres"
|
||||
"github.com/gaze-network/indexer-network/modules/nodesale/datagateway"
|
||||
"github.com/gaze-network/indexer-network/modules/nodesale/internal/entity"
|
||||
"github.com/gaze-network/indexer-network/modules/nodesale/repository/postgres/gen"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
@@ -25,7 +26,7 @@ func NewRepository(db postgres.DB) *Repository {
|
||||
}
|
||||
}
|
||||
|
||||
func (repo *Repository) AddBlock(ctx context.Context, arg datagateway.Block) error {
|
||||
func (repo *Repository) AddBlock(ctx context.Context, arg entity.Block) error {
|
||||
err := repo.queries.AddBlock(ctx, gen.AddBlockParams{
|
||||
BlockHeight: arg.BlockHeight,
|
||||
BlockHash: arg.BlockHash,
|
||||
@@ -38,24 +39,24 @@ func (repo *Repository) AddBlock(ctx context.Context, arg datagateway.Block) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *Repository) GetBlock(ctx context.Context, blockHeight int64) (*datagateway.Block, error) {
|
||||
func (repo *Repository) GetBlock(ctx context.Context, blockHeight int64) (*entity.Block, error) {
|
||||
block, err := repo.queries.GetBlock(ctx, blockHeight)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Cannot get block")
|
||||
}
|
||||
return &datagateway.Block{
|
||||
return &entity.Block{
|
||||
BlockHeight: block.BlockHeight,
|
||||
BlockHash: block.BlockHash,
|
||||
Module: block.Module,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (repo *Repository) GetLastProcessedBlock(ctx context.Context) (*datagateway.Block, error) {
|
||||
func (repo *Repository) GetLastProcessedBlock(ctx context.Context) (*entity.Block, error) {
|
||||
block, err := repo.queries.GetLastProcessedBlock(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Cannot get last processed block")
|
||||
}
|
||||
return &datagateway.Block{
|
||||
return &entity.Block{
|
||||
BlockHeight: block.BlockHeight,
|
||||
BlockHash: block.BlockHash,
|
||||
Module: block.Module,
|
||||
@@ -86,7 +87,7 @@ func (repo *Repository) ClearDelegate(ctx context.Context) (int64, error) {
|
||||
return affected, nil
|
||||
}
|
||||
|
||||
func (repo *Repository) GetNodes(ctx context.Context, arg datagateway.GetNodesParams) ([]datagateway.Node, error) {
|
||||
func (repo *Repository) GetNodes(ctx context.Context, arg datagateway.GetNodesParams) ([]entity.Node, error) {
|
||||
nodes, err := repo.queries.GetNodes(ctx, gen.GetNodesParams{
|
||||
SaleBlock: arg.SaleBlock,
|
||||
SaleTxIndex: arg.SaleTxIndex,
|
||||
@@ -95,8 +96,8 @@ func (repo *Repository) GetNodes(ctx context.Context, arg datagateway.GetNodesPa
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Cannot get nodes")
|
||||
}
|
||||
return lo.Map(nodes, func(item gen.Node, index int) datagateway.Node {
|
||||
return datagateway.Node{
|
||||
return lo.Map(nodes, func(item gen.Node, index int) entity.Node {
|
||||
return entity.Node{
|
||||
SaleBlock: item.SaleBlock,
|
||||
SaleTxIndex: item.SaleTxIndex,
|
||||
NodeID: item.NodeID,
|
||||
@@ -162,7 +163,7 @@ func (repo *Repository) AddNodesale(ctx context.Context, arg datagateway.AddNode
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *Repository) GetNodesale(ctx context.Context, arg datagateway.GetNodesaleParams) ([]datagateway.NodeSale, error) {
|
||||
func (repo *Repository) GetNodesale(ctx context.Context, arg datagateway.GetNodesaleParams) ([]entity.NodeSale, error) {
|
||||
nodesales, err := repo.queries.GetNodesale(ctx, gen.GetNodesaleParams{
|
||||
BlockHeight: arg.BlockHeight,
|
||||
TxIndex: arg.TxIndex,
|
||||
@@ -171,8 +172,8 @@ func (repo *Repository) GetNodesale(ctx context.Context, arg datagateway.GetNode
|
||||
return nil, errors.Wrap(err, "Cannot get nodesale")
|
||||
}
|
||||
|
||||
return lo.Map(nodesales, func(item gen.NodeSale, index int) datagateway.NodeSale {
|
||||
return datagateway.NodeSale{
|
||||
return lo.Map(nodesales, func(item gen.NodeSale, index int) entity.NodeSale {
|
||||
return entity.NodeSale{
|
||||
BlockHeight: item.BlockHeight,
|
||||
TxIndex: item.TxIndex,
|
||||
Name: item.Name,
|
||||
@@ -188,7 +189,7 @@ func (repo *Repository) GetNodesale(ctx context.Context, arg datagateway.GetNode
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (repo *Repository) GetNodesByOwner(ctx context.Context, arg datagateway.GetNodesByOwnerParams) ([]datagateway.Node, error) {
|
||||
func (repo *Repository) GetNodesByOwner(ctx context.Context, arg datagateway.GetNodesByOwnerParams) ([]entity.Node, error) {
|
||||
nodes, err := repo.queries.GetNodesByOwner(ctx, gen.GetNodesByOwnerParams{
|
||||
SaleBlock: arg.SaleBlock,
|
||||
SaleTxIndex: arg.SaleTxIndex,
|
||||
@@ -197,8 +198,8 @@ func (repo *Repository) GetNodesByOwner(ctx context.Context, arg datagateway.Get
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Cannot get nodes by owner")
|
||||
}
|
||||
return lo.Map(nodes, func(item gen.Node, index int) datagateway.Node {
|
||||
return datagateway.Node{
|
||||
return lo.Map(nodes, func(item gen.Node, index int) entity.Node {
|
||||
return entity.Node{
|
||||
SaleBlock: item.SaleBlock,
|
||||
SaleTxIndex: item.SaleTxIndex,
|
||||
NodeID: item.NodeID,
|
||||
@@ -246,7 +247,7 @@ func (repo *Repository) GetNodeCountByTierIndex(ctx context.Context, arg datagat
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (repo *Repository) GetNodesByPubkey(ctx context.Context, arg datagateway.GetNodesByPubkeyParams) ([]datagateway.Node, error) {
|
||||
func (repo *Repository) GetNodesByPubkey(ctx context.Context, arg datagateway.GetNodesByPubkeyParams) ([]entity.Node, error) {
|
||||
nodes, err := repo.queries.GetNodesByPubkey(ctx, gen.GetNodesByPubkeyParams{
|
||||
SaleBlock: arg.SaleBlock,
|
||||
SaleTxIndex: arg.SaleTxIndex,
|
||||
@@ -256,8 +257,8 @@ func (repo *Repository) GetNodesByPubkey(ctx context.Context, arg datagateway.Ge
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Cannot get nodes by public key")
|
||||
}
|
||||
return lo.Map(nodes, func(item gen.Node, index int) datagateway.Node {
|
||||
return datagateway.Node{
|
||||
return lo.Map(nodes, func(item gen.Node, index int) entity.Node {
|
||||
return entity.Node{
|
||||
SaleBlock: item.SaleBlock,
|
||||
SaleTxIndex: item.SaleTxIndex,
|
||||
NodeID: item.NodeID,
|
||||
@@ -270,13 +271,13 @@ func (repo *Repository) GetNodesByPubkey(ctx context.Context, arg datagateway.Ge
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (repo *Repository) GetEventsByWallet(ctx context.Context, walletAddress string) ([]datagateway.Event, error) {
|
||||
func (repo *Repository) GetEventsByWallet(ctx context.Context, walletAddress string) ([]entity.Event, error) {
|
||||
events, err := repo.queries.GetEventsByWallet(ctx, walletAddress)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "cannot get events by wallet")
|
||||
}
|
||||
return lo.Map(events, func(item gen.Event, index int) datagateway.Event {
|
||||
return datagateway.Event{
|
||||
return lo.Map(events, func(item gen.Event, index int) entity.Event {
|
||||
return entity.Event{
|
||||
TxHash: item.TxHash,
|
||||
BlockHeight: item.BlockHeight,
|
||||
TxIndex: item.TxIndex,
|
||||
|
||||
Reference in New Issue
Block a user