mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-01-12 08:34:28 +08:00
* feat: recover nodesale module. * fix: refactored. * fix: fix table type. * fix: add entity * fix: bug UTC time. * ci: try to tidy before testing * ci: touch result file * ci: use echo to create new file * fix: try to skip test in ci * fix: remove os.Exit * fix: handle error * feat: add todo note * fix: Cannot run nodesale test because qtx is not initiated. * fix: 50% chance public key compare incorrectly. * fix: more consistent SQL * fix: sanity refactor. * fix: remove unused code. * fix: move last_block_default to config file. * fix: minor mistakes. * fix: * fix: refactor * fix: refactor * fix: delegate tx hash not record into db. * refactor: prepare for moving integration tests. * refactor: convert to unit tests. * fix: change to using input values since output values deducted fee. * feat: add extra unit test. * fix: wrong timestamp format. * fix: handle block timeout = 0 --------- Co-authored-by: Gaze <gazenw@users.noreply.github.com>
62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
package nodesale
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/btcsuite/btcd/rpcclient"
|
|
"github.com/gaze-network/indexer-network/core/datasources"
|
|
"github.com/gaze-network/indexer-network/core/indexer"
|
|
"github.com/gaze-network/indexer-network/internal/config"
|
|
"github.com/gaze-network/indexer-network/internal/postgres"
|
|
"github.com/gaze-network/indexer-network/modules/nodesale/api/httphandler"
|
|
repository "github.com/gaze-network/indexer-network/modules/nodesale/repository/postgres"
|
|
"github.com/gaze-network/indexer-network/pkg/logger"
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/samber/do/v2"
|
|
)
|
|
|
|
var NODESALE_MAGIC = []byte{0x6e, 0x73, 0x6f, 0x70}
|
|
|
|
const (
|
|
Version = "v0.0.1-alpha"
|
|
)
|
|
|
|
func New(injector do.Injector) (indexer.IndexerWorker, error) {
|
|
ctx := do.MustInvoke[context.Context](injector)
|
|
conf := do.MustInvoke[config.Config](injector)
|
|
|
|
btcClient := do.MustInvoke[*rpcclient.Client](injector)
|
|
datasource := datasources.NewBitcoinNode(btcClient)
|
|
|
|
pg, err := postgres.NewPool(ctx, conf.Modules.NodeSale.Postgres)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Can't create postgres connection : %w", err)
|
|
}
|
|
var cleanupFuncs []func(context.Context) error
|
|
cleanupFuncs = append(cleanupFuncs, func(ctx context.Context) error {
|
|
pg.Close()
|
|
return nil
|
|
})
|
|
repository := repository.NewRepository(pg)
|
|
|
|
processor := &Processor{
|
|
NodeSaleDg: repository,
|
|
BtcClient: datasource,
|
|
Network: conf.Network,
|
|
cleanupFuncs: cleanupFuncs,
|
|
lastBlockDefault: conf.Modules.NodeSale.LastBlockDefault,
|
|
}
|
|
|
|
httpServer := do.MustInvoke[*fiber.App](injector)
|
|
nodeSaleHandler := httphandler.New(repository)
|
|
if err := nodeSaleHandler.Mount(httpServer); err != nil {
|
|
return nil, fmt.Errorf("Can't mount nodesale API : %w", err)
|
|
}
|
|
logger.InfoContext(ctx, "Mounted nodesale HTTP handler")
|
|
|
|
indexer := indexer.New(processor, datasource)
|
|
logger.InfoContext(ctx, "NodeSale module started.")
|
|
return indexer, nil
|
|
}
|